X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fwgl%2Fglcontext.cpp;h=68088970ac13cab32cd856a2a23980d838ad3bf7;hb=0d205a19dc087768da1e803d8dfde27f12cb9d99;hp=6c378a6f195979a659b5a075bf3a5909b3008b12;hpb=018da17591533b034d6bf018d2a9ac640007575e;p=libs%2Fgui.git diff --git a/source/graphics/wgl/glcontext.cpp b/source/graphics/wgl/glcontext.cpp index 6c378a6..6808897 100644 --- a/source/graphics/wgl/glcontext.cpp +++ b/source/graphics/wgl/glcontext.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -6,6 +7,16 @@ using namespace std; +namespace { + +template +T get_proc(const char *name) +{ + return reinterpret_cast(reinterpret_cast(wglGetProcAddress(name))); +} + +} + namespace Msp { namespace Graphics { @@ -44,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(wglGetProcAddress("wglCreateContextAttribs")); + ContextHandle fake_context = wglCreateContext(dc); + wglMakeCurrent(dc, fake_context); + + PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = get_proc("wglCreateContextAttribsARB"); if(!wglCreateContextAttribs) throw unsupported_gl_mode(opts); @@ -56,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); @@ -67,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); @@ -85,10 +110,10 @@ GLContext::~GLContext() void GLContext::set_swap_interval(unsigned i) { - PFNWGLSWAPINTERVALEXTPROC func = reinterpret_cast(wglGetProcAddress("wglSwapIntervalEXT")); - if(!func) + PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = get_proc("wglSwapIntervalEXT"); + if(!wglSwapInterval) throw runtime_error("wglSwapIntervalEXT not found"); - func(i); + wglSwapInterval(i); } void GLContext::swap_buffers()