]> git.tdb.fi Git - libs/gui.git/commitdiff
Fix compile errors from function casts in wgl
authorMikko Rasa <tdb@tdb.fi>
Mon, 25 Jan 2021 23:28:33 +0000 (01:28 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 25 Jan 2021 23:28:33 +0000 (01:28 +0200)
Recent gcc versions don't like casting directly between incompatible
function types.

source/graphics/wgl/glcontext.cpp

index ebca3f1912ef9ee67e1570c41ae71e98c5cb281f..68088970ac13cab32cd856a2a23980d838ad3bf7 100644 (file)
@@ -7,6 +7,16 @@
 
 using namespace std;
 
+namespace {
+
+template<typename T>
+T get_proc(const char *name)
+{
+       return reinterpret_cast<T>(reinterpret_cast<void *>(wglGetProcAddress(name)));
+}
+
+}
+
 namespace Msp {
 namespace Graphics {
 
@@ -48,7 +58,7 @@ void GLContext::platform_init(const GLOptions &opts)
                ContextHandle fake_context = wglCreateContext(dc);
                wglMakeCurrent(dc, fake_context);
 
-               PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribsARB"));
+               PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = get_proc<PFNWGLCREATECONTEXTATTRIBSARBPROC>("wglCreateContextAttribsARB");
                if(!wglCreateContextAttribs)
                        throw unsupported_gl_mode(opts);
 
@@ -100,7 +110,7 @@ GLContext::~GLContext()
 
 void GLContext::set_swap_interval(unsigned i)
 {
-       PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = reinterpret_cast<PFNWGLSWAPINTERVALEXTPROC>(wglGetProcAddress("wglSwapIntervalEXT"));
+       PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = get_proc<PFNWGLSWAPINTERVALEXTPROC>("wglSwapIntervalEXT");
        if(!wglSwapInterval)
                throw runtime_error("wglSwapIntervalEXT not found");
        wglSwapInterval(i);