X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fwgl%2Fglcontext.cpp;h=6c378a6f195979a659b5a075bf3a5909b3008b12;hb=018da17591533b034d6bf018d2a9ac640007575e;hp=964dea2b7fba92a66815b7d84e89254c0c840880;hpb=8926837f7e81d0007d8cb94db701c4845a0a01a3;p=libs%2Fgui.git diff --git a/source/graphics/wgl/glcontext.cpp b/source/graphics/wgl/glcontext.cpp index 964dea2..6c378a6 100644 --- a/source/graphics/wgl/glcontext.cpp +++ b/source/graphics/wgl/glcontext.cpp @@ -1,8 +1,11 @@ #include #include +#include #include "glcontext.h" #include "window_private.h" +using namespace std; + namespace Msp { namespace Graphics { @@ -16,8 +19,6 @@ struct GLContext::Private void GLContext::platform_init(const GLOptions &opts) { - priv = new Private; - HDC dc = GetDC(window.get_private().window); PIXELFORMATDESCRIPTOR pfd; @@ -40,7 +41,35 @@ void GLContext::platform_init(const GLOptions &opts) throw unsupported_gl_mode(opts); SetPixelFormat(dc, pf_index, &pfd); - priv->context = wglCreateContext(dc); + priv = new Private; + if(opts.forward_compatible || opts.gl_version_major) + { + PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = reinterpret_cast(wglGetProcAddress("wglCreateContextAttribs")); + 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]); + } + else + priv->context = wglCreateContext(dc); wglMakeCurrent(dc, priv->context); ReleaseDC(window.get_private().window, dc); @@ -54,6 +83,14 @@ GLContext::~GLContext() delete priv; } +void GLContext::set_swap_interval(unsigned i) +{ + PFNWGLSWAPINTERVALEXTPROC func = reinterpret_cast(wglGetProcAddress("wglSwapIntervalEXT")); + if(!func) + throw runtime_error("wglSwapIntervalEXT not found"); + func(i); +} + void GLContext::swap_buffers() { HDC dc = GetDC(window.get_private().window); @@ -61,10 +98,8 @@ void GLContext::swap_buffers() ReleaseDC(window.get_private().window, dc); } -void GLContext::window_resized(unsigned w, unsigned h) -{ - glViewport(0, 0, w, h); -} +void GLContext::window_resized(unsigned, unsigned) +{ } } // namespace Graphics } // namespace Msp