X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fglx%2Fglcontext.cpp;h=34daa08d1ce1e022648626ac9279d1ab771e7f2a;hb=7302a061c57602203895b616bf54d96269c677c6;hp=5f04e3b2fd51e21afbc1c03eac252623df16e1d7;hpb=018da17591533b034d6bf018d2a9ac640007575e;p=libs%2Fgui.git diff --git a/source/graphics/glx/glcontext.cpp b/source/graphics/glx/glcontext.cpp index 5f04e3b..34daa08 100644 --- a/source/graphics/glx/glcontext.cpp +++ b/source/graphics/glx/glcontext.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "glcontext.h" #include "display_private.h" @@ -98,11 +99,32 @@ void GLContext::platform_init(const GLOptions &opts) priv->glxwnd = glXCreateWindow(dpy, fb_configs[0], priv->subwnd, 0); - if(opts.forward_compatible || opts.gl_version_major) + if(opts.forward_compatible || opts.gl_version_major!=GLOptions::DEFAULT_VERSION) { if(!extensions.count("GLX_ARB_create_context") || !extensions.count("GLX_ARB_get_proc_address")) 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) + { + ContextHandle probe_context = glXCreateNewContext(dpy, fb_configs[0], GLX_RGBA_TYPE, 0, true); + glXMakeContextCurrent(dpy, priv->glxwnd, priv->glxwnd, probe_context); + + 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]); + + glXMakeContextCurrent(dpy, 0, 0, 0); + glXDestroyContext(dpy, probe_context); + } + vector ctx_attribs; ctx_attribs.push_back(GLX_RENDER_TYPE); @@ -114,12 +136,18 @@ void GLContext::platform_init(const GLOptions &opts) ctx_attribs.push_back(GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB); } + if(opts.core_profile) + { + ctx_attribs.push_back(GLX_CONTEXT_PROFILE_MASK_ARB); + ctx_attribs.push_back(GLX_CONTEXT_CORE_PROFILE_BIT_ARB); + } + if(opts.gl_version_major) { ctx_attribs.push_back(GLX_CONTEXT_MAJOR_VERSION_ARB); - ctx_attribs.push_back(opts.gl_version_major); + ctx_attribs.push_back(gl_version_major); ctx_attribs.push_back(GLX_CONTEXT_MINOR_VERSION_ARB); - ctx_attribs.push_back(opts.gl_version_minor); + ctx_attribs.push_back(gl_version_minor); } ctx_attribs.push_back(0); @@ -211,10 +239,10 @@ GLContext::~GLContext() void GLContext::set_swap_interval(unsigned i) { const GLubyte *name = reinterpret_cast("glXSwapIntervalEXT"); - PFNGLXSWAPINTERVALEXTPROC func = reinterpret_cast(glXGetProcAddress(name)); - if(!func) + PFNGLXSWAPINTERVALEXTPROC glXSwapInterval = reinterpret_cast(glXGetProcAddress(name)); + if(!glXSwapInterval) throw runtime_error("glXSwapIntervalEXT not found"); - func(display.get_private().display, (priv->glxwnd ? priv->glxwnd : priv->subwnd), i); + glXSwapInterval(display.get_private().display, (priv->glxwnd ? priv->glxwnd : priv->subwnd), i); } void GLContext::swap_buffers()