]> git.tdb.fi Git - libs/gui.git/blobdiff - source/graphics/glx/glcontext.cpp
Add support for swap interval control
[libs/gui.git] / source / graphics / glx / glcontext.cpp
index 09a4ef8b6ee0216ab8bdc1573cee9111da19a4d4..46da6d1a231091f6aed597e17e7f0f6eeb65911a 100644 (file)
@@ -22,35 +22,35 @@ struct GLContext::Private
 
 void GLContext::platform_init(const GLOptions &opts)
 {
-       priv = new Private;
-
        vector<int> attribs;
-       
+
        attribs.push_back(GLX_RGBA);
        attribs.push_back(GLX_DEPTH_SIZE);
        attribs.push_back(1);
-       
+
        if(opts.alpha)
        {
                attribs.push_back(GLX_ALPHA_SIZE);
                attribs.push_back(1);
        }
-       
+
        if(opts.stencil)
        {
                attribs.push_back(GLX_STENCIL_SIZE);
                attribs.push_back(1);
        }
-       
+
        if(opts.doublebuffer)
                attribs.push_back(GLX_DOUBLEBUFFER);
-       
+
        if(opts.multisample>0)
        {
                attribs.push_back(GLX_SAMPLE_BUFFERS_ARB);
+               attribs.push_back(1);
+               attribs.push_back(GLX_SAMPLES_ARB);
                attribs.push_back(opts.multisample);
        }
-       
+
        attribs.push_back(0);
 
        DisplayHandle dpy = display.get_private().display;
@@ -58,6 +58,8 @@ void GLContext::platform_init(const GLOptions &opts)
        XVisualInfo *vi = glXChooseVisual(dpy, DefaultScreen(dpy), &attribs.front());
        if(!vi)
                throw unsupported_gl_mode(opts);
+
+       priv = new Private;
        priv->context = glXCreateContext(dpy, vi, 0, true);
 
        XSetWindowAttributes attr;
@@ -82,6 +84,15 @@ GLContext::~GLContext()
        delete priv;
 }
 
+void GLContext::set_swap_interval(unsigned i)
+{
+       const GLubyte *name = reinterpret_cast<const GLubyte *>("glXSwapIntervalEXT");
+       PFNGLXSWAPINTERVALEXTPROC func = reinterpret_cast<PFNGLXSWAPINTERVALEXTPROC>(glXGetProcAddress(name));
+       if(!func)
+               throw runtime_error("glXSwapIntervalEXT not found");
+       func(display.get_private().display, priv->subwnd, i);
+}
+
 void GLContext::swap_buffers()
 {
        glXSwapBuffers(display.get_private().display, priv->subwnd);
@@ -90,7 +101,6 @@ void GLContext::swap_buffers()
 void GLContext::window_resized(unsigned w, unsigned h)
 {
        XMoveResizeWindow(display.get_private().display, priv->subwnd, 0, 0, w, h);
-       glViewport(0, 0, w, h);
 }
 
 } // namespace Graphics