X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fwgl%2Fglcontext.cpp;h=3627a17ff286ca6494c2e81cdf7e6f2051208d25;hb=507fa60f32bd3f64840a2cdd1be5d68478432b55;hp=68088970ac13cab32cd856a2a23980d838ad3bf7;hpb=0d205a19dc087768da1e803d8dfde27f12cb9d99;p=libs%2Fgui.git diff --git a/source/graphics/wgl/glcontext.cpp b/source/graphics/wgl/glcontext.cpp index 6808897..3627a17 100644 --- a/source/graphics/wgl/glcontext.cpp +++ b/source/graphics/wgl/glcontext.cpp @@ -1,8 +1,10 @@ +#include "glcontext.h" #include #include #include #include -#include "glcontext.h" +#include +#include #include "window_private.h" using namespace std; @@ -24,7 +26,7 @@ typedef HGLRC ContextHandle; struct GLContext::Private { - ContextHandle context; + ContextHandle context = nullptr; }; @@ -53,7 +55,7 @@ void GLContext::platform_init(const GLOptions &opts) SetPixelFormat(dc, pf_index, &pfd); priv = new Private; - if(opts.forward_compatible || opts.gl_version_major) + if(opts.forward_compatible || opts.gl_version_major!=DEFAULT_VERSION) { ContextHandle fake_context = wglCreateContext(dc); wglMakeCurrent(dc, fake_context); @@ -62,6 +64,21 @@ void GLContext::platform_init(const GLOptions &opts) if(!wglCreateContextAttribs) throw unsupported_gl_mode(opts); + unsigned gl_version_major = opts.gl_version_major; + unsigned gl_version_minor = opts.gl_version_minor; + if(opts.gl_version_major==GLOptions::LATEST_VERSION) + { + const char *gl_ver_ptr = reinterpret_cast(glGetString(GL_VERSION)); + if(!gl_ver_ptr) + throw unsupported_gl_mode(opts); + + string gl_ver = gl_ver_ptr; + vector parts = split(gl_ver.substr(0, gl_ver.find(' ')), '.'); + + gl_version_major = lexical_cast(parts[0]); + gl_version_minor = lexical_cast(parts[1]); + } + vector ctx_attribs; if(opts.forward_compatible) @@ -79,9 +96,9 @@ void GLContext::platform_init(const GLOptions &opts) 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(gl_version_major); ctx_attribs.push_back(WGL_CONTEXT_MINOR_VERSION_ARB); - ctx_attribs.push_back(opts.gl_version_minor); + ctx_attribs.push_back(gl_version_minor); } ctx_attribs.push_back(0); @@ -90,7 +107,7 @@ void GLContext::platform_init(const GLOptions &opts) if(!priv->context) throw unsupported_gl_mode(opts); - wglMakeCurrent(0, 0); + wglMakeCurrent(nullptr, nullptr); wglDeleteContext(fake_context); } else @@ -102,7 +119,7 @@ void GLContext::platform_init(const GLOptions &opts) GLContext::~GLContext() { - wglMakeCurrent(0, 0); + wglMakeCurrent(nullptr, nullptr); wglDeleteContext(priv->context); delete priv;