Windows QPA/GL: Fix build with MinGW/g++ 8.1 x64

Fix warnings about invalid function type casts (return types
conflicting with the PROC returned by wglGetProcAddress()) like:

qwindowsglcontext.cpp:1250:138: error: cast between incompatible function types from 'PROC' {aka 'long long int (*)()'} to 'GLenum (*)()' {aka 'unsigned int (*)()'} [-Werror=cast-function-type]
         m_getGraphicsResetStatus = (GLenum (APIENTRY *)()) QOpenGLStaticContext::opengl32.wglGetProcAddress("glGetGraphicsResetStatusARB");

by introducing nested casts.

Task-number: QTBUG-68742
Task-number: QTQAINFRA-2095
Change-Id: I7c51836f2b9f7e2a6fa17c5108d59b23c42fb99d
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
This commit is contained in:
Friedemann Kleint 2018-06-22 10:05:23 +02:00
parent 6f53c2bc96
commit a8a0dffd1f
3 changed files with 49 additions and 25 deletions

View File

@ -153,9 +153,11 @@ QT_BEGIN_NAMESPACE
QWindowsOpengl32DLL QOpenGLStaticContext::opengl32;
FARPROC QWindowsOpengl32DLL::resolve(const char *name)
QFunctionPointer QWindowsOpengl32DLL::resolve(const char *name)
{
return m_lib ? ::GetProcAddress(m_lib, name) : nullptr;
return m_lib
? reinterpret_cast<QFunctionPointer>(::GetProcAddress(m_lib, name))
: nullptr;
}
bool QWindowsOpengl32DLL::init(bool softwareRendering)
@ -977,12 +979,18 @@ QOpenGLStaticContext::QOpenGLStaticContext() :
extensionNames(QOpenGLStaticContext::getGlString(GL_EXTENSIONS)),
extensions(0),
defaultFormat(QWindowsOpenGLContextFormat::current()),
wglGetPixelFormatAttribIVARB((WglGetPixelFormatAttribIVARB)QOpenGLStaticContext::opengl32.wglGetProcAddress("wglGetPixelFormatAttribivARB")),
wglChoosePixelFormatARB((WglChoosePixelFormatARB)QOpenGLStaticContext::opengl32.wglGetProcAddress("wglChoosePixelFormatARB")),
wglCreateContextAttribsARB((WglCreateContextAttribsARB)QOpenGLStaticContext::opengl32.wglGetProcAddress("wglCreateContextAttribsARB")),
wglSwapInternalExt((WglSwapInternalExt)QOpenGLStaticContext::opengl32.wglGetProcAddress("wglSwapIntervalEXT")),
wglGetSwapInternalExt((WglGetSwapInternalExt)QOpenGLStaticContext::opengl32.wglGetProcAddress("wglGetSwapIntervalEXT")),
wglGetExtensionsStringARB((WglGetExtensionsStringARB)QOpenGLStaticContext::opengl32.wglGetProcAddress("wglGetExtensionsStringARB"))
wglGetPixelFormatAttribIVARB(reinterpret_cast<WglGetPixelFormatAttribIVARB>(
reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("wglGetPixelFormatAttribivARB")))),
wglChoosePixelFormatARB(reinterpret_cast<WglChoosePixelFormatARB>(
reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("wglChoosePixelFormatARB")))),
wglCreateContextAttribsARB(reinterpret_cast<WglCreateContextAttribsARB>(
reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("wglCreateContextAttribsARB")))),
wglSwapInternalExt(reinterpret_cast<WglSwapInternalExt>(
reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("wglSwapIntervalEXT")))),
wglGetSwapInternalExt(reinterpret_cast<WglGetSwapInternalExt>(
reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("wglGetSwapIntervalEXT")))),
wglGetExtensionsStringARB(reinterpret_cast<WglGetExtensionsStringARB>(
reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("wglGetExtensionsStringARB"))))
{
if (extensionNames.startsWith(SAMPLE_BUFFER_EXTENSION " ")
|| extensionNames.indexOf(" " SAMPLE_BUFFER_EXTENSION " ") != -1)
@ -1231,7 +1239,8 @@ bool QWindowsGLContext::updateObtainedParams(HDC hdc, int *obtainedSwapInterval)
hasRobustness = exts && strstr(exts, "GL_ARB_robustness");
} else {
typedef const GLubyte * (APIENTRY *glGetStringi_t)(GLenum, GLuint);
glGetStringi_t glGetStringi = (glGetStringi_t) QOpenGLStaticContext::opengl32.wglGetProcAddress("glGetStringi");
glGetStringi_t glGetStringi = reinterpret_cast<glGetStringi_t>(
reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("glGetStringi")));
if (glGetStringi) {
GLint n = 0;
QOpenGLStaticContext::opengl32.glGetIntegerv(GL_NUM_EXTENSIONS, &n);
@ -1244,8 +1253,10 @@ bool QWindowsGLContext::updateObtainedParams(HDC hdc, int *obtainedSwapInterval)
}
}
}
if (hasRobustness)
m_getGraphicsResetStatus = (GLenum (APIENTRY *)()) QOpenGLStaticContext::opengl32.wglGetProcAddress("glGetGraphicsResetStatusARB");
if (hasRobustness) {
m_getGraphicsResetStatus = reinterpret_cast<GlGetGraphicsResetStatusArbType>(
reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress("glGetGraphicsResetStatusARB")));
}
QOpenGLStaticContext::opengl32.wglMakeCurrent(prevSurface, prevContext);
return true;
@ -1369,16 +1380,17 @@ QFunctionPointer QWindowsGLContext::getProcAddress(const char *procName)
// Even though we use QFunctionPointer, it does not mean the function can be called.
// It will need to be cast to the proper function type with the correct calling
// convention. QFunctionPointer is nothing more than a glorified void* here.
PROC procAddress = QOpenGLStaticContext::opengl32.wglGetProcAddress(procName);
QFunctionPointer procAddress = reinterpret_cast<QFunctionPointer>(QOpenGLStaticContext::opengl32.wglGetProcAddress(procName));
// We support AllGLFunctionsQueryable, which means this function must be able to
// return a function pointer even for functions that are in GL.h and exported
// normally from opengl32.dll. wglGetProcAddress() is not guaranteed to work for such
// functions, however in QT_OPENGL_DYNAMIC builds QOpenGLFunctions will just blindly
// call into here for _any_ OpenGL function.
if (!procAddress || procAddress == reinterpret_cast<PROC>(0x1) || procAddress == reinterpret_cast<PROC>(0x2)
|| procAddress == reinterpret_cast<PROC>(0x3) || procAddress == reinterpret_cast<PROC>(-1))
if (procAddress == nullptr || reinterpret_cast<quintptr>(procAddress) < 4u
|| procAddress == reinterpret_cast<QFunctionPointer>(-1)) {
procAddress = QOpenGLStaticContext::opengl32.resolve(procName);
}
if (QWindowsContext::verbose > 1)
qCDebug(lcQpaGl) << __FUNCTION__ << procName << QOpenGLStaticContext::opengl32.wglGetCurrentContext() << "returns" << procAddress;

View File

@ -122,7 +122,7 @@ struct QWindowsOpengl32DLL
void (APIENTRY * glGetIntegerv)(GLenum pname, GLint* params);
const GLubyte * (APIENTRY * glGetString)(GLenum name);
FARPROC resolve(const char *name);
QFunctionPointer resolve(const char *name);
private:
HMODULE m_lib;
bool m_nonOpengl32;
@ -217,6 +217,8 @@ public:
void *nativeContext() const override { return m_renderingContext; }
private:
typedef GLenum (APIENTRY *GlGetGraphicsResetStatusArbType)();
inline void releaseDCs();
bool updateObtainedParams(HDC hdc, int *obtainedSwapInterval = 0);
@ -230,7 +232,7 @@ private:
bool m_extensionsUsed;
int m_swapInterval;
bool m_ownsContext;
GLenum (APIENTRY * m_getGraphicsResetStatus)();
GlGetGraphicsResetStatusArbType m_getGraphicsResetStatus;
bool m_lost;
};
#endif

View File

@ -283,16 +283,21 @@ QWindowsOpenGLTester::Renderers QWindowsOpenGLTester::supportedRenderers()
bool QWindowsOpenGLTester::testDesktopGL()
{
#if !defined(QT_NO_OPENGL)
typedef HGLRC (WINAPI *CreateContextType)(HDC);
typedef BOOL (WINAPI *DeleteContextType)(HGLRC);
typedef BOOL (WINAPI *MakeCurrentType)(HDC, HGLRC);
typedef PROC (WINAPI *WglGetProcAddressType)(LPCSTR);
HMODULE lib = 0;
HWND wnd = 0;
HDC dc = 0;
HGLRC context = 0;
LPCTSTR className = L"qtopengltest";
HGLRC (WINAPI * CreateContext)(HDC dc) = 0;
BOOL (WINAPI * DeleteContext)(HGLRC context) = 0;
BOOL (WINAPI * MakeCurrent)(HDC dc, HGLRC context) = 0;
PROC (WINAPI * WGL_GetProcAddress)(LPCSTR name) = 0;
CreateContextType CreateContext = nullptr;
DeleteContextType DeleteContext = nullptr;
MakeCurrentType MakeCurrent = nullptr;
WglGetProcAddressType WGL_GetProcAddress = nullptr;
bool result = false;
@ -300,16 +305,20 @@ bool QWindowsOpenGLTester::testDesktopGL()
// This will typically fail on systems that do not have a real OpenGL driver.
lib = LoadLibraryA("opengl32.dll");
if (lib) {
CreateContext = reinterpret_cast<HGLRC (WINAPI *)(HDC)>(::GetProcAddress(lib, "wglCreateContext"));
CreateContext = reinterpret_cast<CreateContextType>(
reinterpret_cast<QFunctionPointer>(::GetProcAddress(lib, "wglCreateContext")));
if (!CreateContext)
goto cleanup;
DeleteContext = reinterpret_cast<BOOL (WINAPI *)(HGLRC)>(::GetProcAddress(lib, "wglDeleteContext"));
DeleteContext = reinterpret_cast<DeleteContextType>(
reinterpret_cast<QFunctionPointer>(::GetProcAddress(lib, "wglDeleteContext")));
if (!DeleteContext)
goto cleanup;
MakeCurrent = reinterpret_cast<BOOL (WINAPI *)(HDC, HGLRC)>(::GetProcAddress(lib, "wglMakeCurrent"));
MakeCurrent = reinterpret_cast<MakeCurrentType>(
reinterpret_cast<QFunctionPointer>(::GetProcAddress(lib, "wglMakeCurrent")));
if (!MakeCurrent)
goto cleanup;
WGL_GetProcAddress = reinterpret_cast<PROC (WINAPI *)(LPCSTR)>(::GetProcAddress(lib, "wglGetProcAddress"));
WGL_GetProcAddress = reinterpret_cast<WglGetProcAddressType>(
reinterpret_cast<QFunctionPointer>(::GetProcAddress(lib, "wglGetProcAddress")));
if (!WGL_GetProcAddress)
goto cleanup;
@ -356,7 +365,8 @@ bool QWindowsOpenGLTester::testDesktopGL()
// Check the version. If we got 1.x then it's all hopeless and we can stop right here.
typedef const GLubyte * (APIENTRY * GetString_t)(GLenum name);
GetString_t GetString = reinterpret_cast<GetString_t>(::GetProcAddress(lib, "glGetString"));
GetString_t GetString = reinterpret_cast<GetString_t>(
reinterpret_cast<QFunctionPointer>(::GetProcAddress(lib, "glGetString")));
if (GetString) {
if (const char *versionStr = reinterpret_cast<const char *>(GetString(GL_VERSION))) {
const QByteArray version(versionStr);