]> git.tdb.fi Git - libs/gui.git/blobdiff - source/graphics/wgl/glcontext.cpp
Add a missing include for GLContext on Windows
[libs/gui.git] / source / graphics / wgl / glcontext.cpp
index 3df83f3119a294fa8472729d95e84451957881a6..98aabb310abb99f95356a6000f8997587d426ee6 100644 (file)
@@ -1,3 +1,4 @@
+#include <vector>
 #include <windows.h>
 #include <GL/gl.h>
 #include <GL/wglext.h>
@@ -42,7 +43,34 @@ void GLContext::platform_init(const GLOptions &opts)
        SetPixelFormat(dc, pf_index, &pfd);
 
        priv = new Private;
-       priv->context = wglCreateContext(dc);
+       if(opts.forward_compatible || opts.gl_version_major)
+       {
+               PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribs"));
+               if(!wglCreateContextAttribs)
+                       throw unsupported_gl_mode(opts);
+
+               vector<int> ctx_attribs;
+
+               if(opts.forward_compatible)
+               {
+                       ctx_attribs.push_back(WGL_CONTEXT_FLAGS_ARB);
+                       ctx_attribs.push_back(WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB);
+               }
+
+               if(opts.gl_version_major)
+               {
+                       ctx_attribs.push_back(WGL_CONTEXT_MAJOR_VERSION_ARB);
+                       ctx_attribs.push_back(opts.gl_version_major);
+                       ctx_attribs.push_back(WGL_CONTEXT_MINOR_VERSION_ARB);
+                       ctx_attribs.push_back(opts.gl_version_minor);
+               }
+
+               ctx_attribs.push_back(0);
+
+               priv->context = wglCreateContextAttribs(dc, 0, &ctx_attribs[0]);
+       }
+       else
+               priv->context = wglCreateContext(dc);
        wglMakeCurrent(dc, priv->context);
 
        ReleaseDC(window.get_private().window, dc);
@@ -58,10 +86,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()