X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fwgl%2Fglcontext.cpp;h=35ec8e9b1983471f5dd12e476f4a662d2deaa7c4;hb=c703f5b01bf5d7eeb13091e64109b58f5d12f53c;hp=844f7a712c990a1442a7f442c4d50e5034e5b602;hpb=171f2b47008522ad7e950dc67447a08406f4888d;p=libs%2Fgui.git diff --git a/source/graphics/wgl/glcontext.cpp b/source/graphics/wgl/glcontext.cpp index 844f7a7..35ec8e9 100644 --- a/source/graphics/wgl/glcontext.cpp +++ b/source/graphics/wgl/glcontext.cpp @@ -1,8 +1,12 @@ +#include #include #include +#include #include "glcontext.h" #include "window_private.h" +using namespace std; + namespace Msp { namespace Graphics { @@ -39,7 +43,42 @@ 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) + { + ContextHandle fake_context = wglCreateContext(dc); + wglMakeCurrent(dc, fake_context); + + PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = reinterpret_cast(wglGetProcAddress("wglCreateContextAttribsARB")); + if(!wglCreateContextAttribs) + throw unsupported_gl_mode(opts); + + vector 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]); + if(!priv->context) + throw unsupported_gl_mode(opts); + + wglMakeCurrent(0, 0); + wglDeleteContext(fake_context); + } + else + priv->context = wglCreateContext(dc); wglMakeCurrent(dc, priv->context); ReleaseDC(window.get_private().window, dc); @@ -53,6 +92,14 @@ GLContext::~GLContext() delete priv; } +void GLContext::set_swap_interval(unsigned i) +{ + PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = reinterpret_cast(wglGetProcAddress("wglSwapIntervalEXT")); + if(!wglSwapInterval) + throw runtime_error("wglSwapIntervalEXT not found"); + wglSwapInterval(i); +} + void GLContext::swap_buffers() { HDC dc = GetDC(window.get_private().window);