]> git.tdb.fi Git - libs/gui.git/blobdiff - source/graphics/wgl/glcontext.cpp
Add a core profile flag to OpenGL context options
[libs/gui.git] / source / graphics / wgl / glcontext.cpp
index 6c378a6f195979a659b5a075bf3a5909b3008b12..ebca3f1912ef9ee67e1570c41ae71e98c5cb281f 100644 (file)
@@ -1,3 +1,4 @@
+#include <vector>
 #include <windows.h>
 #include <GL/gl.h>
 #include <GL/wglext.h>
@@ -44,7 +45,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 = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribsARB"));
                if(!wglCreateContextAttribs)
                        throw unsupported_gl_mode(opts);
 
@@ -56,6 +60,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);
@@ -67,6 +77,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);
@@ -85,10 +100,10 @@ GLContext::~GLContext()
 
 void GLContext::set_swap_interval(unsigned i)
 {
-       PFNWGLSWAPINTERVALEXTPROC func = reinterpret_cast<PFNWGLSWAPINTERVALEXTPROC>(wglGetProcAddress("wglSwapIntervalEXT"));
-       if(!func)
+       PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = reinterpret_cast<PFNWGLSWAPINTERVALEXTPROC>(wglGetProcAddress("wglSwapIntervalEXT"));
+       if(!wglSwapInterval)
                throw runtime_error("wglSwapIntervalEXT not found");
-       func(i);
+       wglSwapInterval(i);
 }
 
 void GLContext::swap_buffers()