]> git.tdb.fi Git - libs/gui.git/blobdiff - source/graphics/wgl/glcontext.cpp
Fix compile errors from function casts in wgl
[libs/gui.git] / source / graphics / wgl / glcontext.cpp
index 98aabb310abb99f95356a6000f8997587d426ee6..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 {
 
@@ -45,7 +55,10 @@ void GLContext::platform_init(const GLOptions &opts)
        priv = new Private;
        if(opts.forward_compatible || opts.gl_version_major)
        {
-               PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribs"));
+               ContextHandle fake_context = wglCreateContext(dc);
+               wglMakeCurrent(dc, fake_context);
+
+               PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = get_proc<PFNWGLCREATECONTEXTATTRIBSARBPROC>("wglCreateContextAttribsARB");
                if(!wglCreateContextAttribs)
                        throw unsupported_gl_mode(opts);
 
@@ -57,6 +70,12 @@ void GLContext::platform_init(const GLOptions &opts)
                        ctx_attribs.push_back(WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB);
                }
 
+               if(opts.core_profile)
+               {
+                       ctx_attribs.push_back(WGL_CONTEXT_PROFILE_MASK_ARB);
+                       ctx_attribs.push_back(WGL_CONTEXT_CORE_PROFILE_BIT_ARB);
+               }
+
                if(opts.gl_version_major)
                {
                        ctx_attribs.push_back(WGL_CONTEXT_MAJOR_VERSION_ARB);
@@ -68,6 +87,11 @@ void GLContext::platform_init(const GLOptions &opts)
                ctx_attribs.push_back(0);
 
                priv->context = wglCreateContextAttribs(dc, 0, &ctx_attribs[0]);
+               if(!priv->context)
+                       throw unsupported_gl_mode(opts);
+
+               wglMakeCurrent(0, 0);
+               wglDeleteContext(fake_context);
        }
        else
                priv->context = wglCreateContext(dc);
@@ -86,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);