X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fwgl%2Fglcontext.cpp;h=b0f685b582a835e38b9639073c6da8564b855e32;hb=be455be47a214f8fba1224ef1fb4158a073bc4e3;hp=ebca3f1912ef9ee67e1570c41ae71e98c5cb281f;hpb=4727c8ca14f2d278a74e0abe64b7a31e68238a8a;p=libs%2Fgui.git diff --git a/source/graphics/wgl/glcontext.cpp b/source/graphics/wgl/glcontext.cpp index ebca3f1..b0f685b 100644 --- a/source/graphics/wgl/glcontext.cpp +++ b/source/graphics/wgl/glcontext.cpp @@ -2,11 +2,23 @@ #include #include #include +#include +#include #include "glcontext.h" #include "window_private.h" using namespace std; +namespace { + +template +T get_proc(const char *name) +{ + return reinterpret_cast(reinterpret_cast(wglGetProcAddress(name))); +} + +} + namespace Msp { namespace Graphics { @@ -43,15 +55,30 @@ 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); - PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = reinterpret_cast(wglGetProcAddress("wglCreateContextAttribsARB")); + PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = get_proc("wglCreateContextAttribsARB"); 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) @@ -69,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); @@ -100,7 +127,7 @@ GLContext::~GLContext() void GLContext::set_swap_interval(unsigned i) { - PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = reinterpret_cast(wglGetProcAddress("wglSwapIntervalEXT")); + PFNWGLSWAPINTERVALEXTPROC wglSwapInterval = get_proc("wglSwapIntervalEXT"); if(!wglSwapInterval) throw runtime_error("wglSwapIntervalEXT not found"); wglSwapInterval(i);