diff options
author | David Robillard <d@drobilla.net> | 2016-07-28 15:33:40 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2016-07-28 15:33:40 -0400 |
commit | bc0c5c6393569ecb0d97fcfb02116452126a4da0 (patch) | |
tree | d6b8fd9f9b0afc771e4753f0c7c89e814d24d76f /pugl | |
parent | 7f04b9b003cbc3889c4cf904fce96499a633799c (diff) | |
download | pugl-bc0c5c6393569ecb0d97fcfb02116452126a4da0.tar.gz pugl-bc0c5c6393569ecb0d97fcfb02116452126a4da0.tar.bz2 pugl-bc0c5c6393569ecb0d97fcfb02116452126a4da0.zip |
Clean up GL attributes and simplify configuration
Diffstat (limited to 'pugl')
-rw-r--r-- | pugl/pugl_x11.c | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index 26e52b8..94827f3 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -50,6 +50,34 @@ # define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif +#ifdef PUGL_HAVE_GL + +/** Attributes for double-buffered RGBA. */ +static int attrListDbl[] = { + GLX_RGBA, + GLX_DOUBLEBUFFER , True, + GLX_RED_SIZE , 4, + GLX_GREEN_SIZE , 4, + GLX_BLUE_SIZE , 4, + GLX_DEPTH_SIZE , 16, + None +}; + +/** Attributes for single-buffered RGBA. */ +static int attrListSgl[] = { + GLX_RGBA, + GLX_DOUBLEBUFFER , False, + GLX_RED_SIZE , 4, + GLX_GREEN_SIZE , 4, + GLX_BLUE_SIZE , 4, + GLX_DEPTH_SIZE , 16, + None +}; + +/** Null-terminated list of attributes in order of preference. */ +static int* attrLists[] = { attrListDbl, attrListSgl, NULL }; + +#endif // PUGL_HAVE_GL struct PuglInternalsImpl { Display* display; @@ -63,7 +91,7 @@ struct PuglInternalsImpl { #endif #ifdef PUGL_HAVE_GL GLXContext ctx; - Bool doubleBuffered; + int doubleBuffered; #endif }; @@ -81,26 +109,8 @@ getVisual(PuglView* view) #ifdef PUGL_HAVE_GL if (view->ctx_type == PUGL_GL) { - // Try to create double-buffered visual - int double_attrs[] = { GLX_RGBA, GLX_DOUBLEBUFFER, - GLX_RED_SIZE, 4, - GLX_GREEN_SIZE, 4, - GLX_BLUE_SIZE, 4, - GLX_DEPTH_SIZE, 16, - None }; - vi = glXChooseVisual(impl->display, impl->screen, double_attrs); - if (!vi) { - // Failed, create single-buffered visual - int single_attrs[] = { GLX_RGBA, - GLX_RED_SIZE, 4, - GLX_GREEN_SIZE, 4, - GLX_BLUE_SIZE, 4, - GLX_DEPTH_SIZE, 16, - None }; - vi = glXChooseVisual(impl->display, impl->screen, single_attrs); - impl->doubleBuffered = False; - } else { - impl->doubleBuffered = True; + for (int* attr = *attrLists; !vi && *attr; ++attr) { + vi = glXChooseVisual(impl->display, impl->screen, attr); } } #endif @@ -124,6 +134,7 @@ createContext(PuglView* view, XVisualInfo* vi) #ifdef PUGL_HAVE_GL if (view->ctx_type == PUGL_GL) { impl->ctx = glXCreateContext(impl->display, vi, 0, GL_TRUE); + glXGetConfig(impl->display, vi, GLX_DOUBLEBUFFER, &impl->doubleBuffered); } #endif #ifdef PUGL_HAVE_CAIRO |