diff --git a/src/msw/glcanvas.cpp b/src/msw/glcanvas.cpp index a942585bff..b5fd506d77 100644 --- a/src/msw/glcanvas.cpp +++ b/src/msw/glcanvas.cpp @@ -147,8 +147,24 @@ wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); #define WGL_CONTEXT_ES_PROFILE_BIT_EXT 0x00000004 #endif -typedef HGLRC(WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) - (HDC hDC, HGLRC hShareContext, const int *attribList); +// This helper function only exists to suppress unavoidable gcc 8 warnings +// about incompatible function casts. +template +inline T wxWGLProcCast(PROC proc) +{ + wxGCC_WARNING_SUPPRESS_CAST_FUNCTION_TYPE() + + return reinterpret_cast(proc); + + wxGCC_WARNING_RESTORE_CAST_FUNCTION_TYPE() +} + +// this macro defines a variable of type "name_t" called "name" and initializes +// it with the pointer to WGL function "name" (which may be NULL) +// +// NB: type name_t must be defined by the code using the macro +#define wxDEFINE_WGL_FUNC(name) \ + name##_t name = wxWGLProcCast(wglGetProcAddress(#name)) // ---------------------------------------------------------------------------- // libraries @@ -580,9 +596,11 @@ wxGLContext::wxGLContext(wxGLCanvas *win, wxCHECK_RET( tempContext, "wglCreateContext failed!" ); wglMakeCurrent(win->GetHDC(), tempContext); - PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB - = (PFNWGLCREATECONTEXTATTRIBSARBPROC) - wglGetProcAddress("wglCreateContextAttribsARB"); + + typedef HGLRC(WINAPI * wglCreateContextAttribsARB_t) + (HDC hDC, HGLRC hShareContext, const int *attribList); + + wxDEFINE_WGL_FUNC(wglCreateContextAttribsARB); wglMakeCurrent(win->GetHDC(), NULL); wglDeleteContext(tempContext); @@ -810,11 +828,6 @@ bool wxGLCanvas::SwapBuffers() } -// this macro defines a variable of type "name_t" called "name" and initializes -// it with the pointer to WGL function "name" (which may be NULL) -#define wxDEFINE_WGL_FUNC(name) \ - name##_t name = (name##_t)wglGetProcAddress(#name) - /* static */ bool wxGLCanvasBase::IsExtensionSupported(const char *extension) {