X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=progs%2Fxdemos%2Fpbutil.c;h=ce133d012dc6193de7b82dc4d676065e6c3d1715;hb=3673189326e348eb91e354017703fdfd9d6d8184;hp=e82fc6ac59d85aad00c6762e0058e062dd818a94;hpb=14e98b7d7c64c306028121a589cfb68845628ccf;p=mesa.git diff --git a/progs/xdemos/pbutil.c b/progs/xdemos/pbutil.c index e82fc6ac59d..ce133d012dc 100644 --- a/progs/xdemos/pbutil.c +++ b/progs/xdemos/pbutil.c @@ -9,7 +9,6 @@ * to the GLX_SGIX_fbconfig/pbuffer extensions. */ - #include #include #include "pbutil.h" @@ -19,12 +18,12 @@ * Test if we pixel buffers are available for a particular X screen. * Input: dpy - the X display * screen - screen number - * Return: 0 = pixel buffers not available. - * 1 = pixel buffers are available via GLX 1.3. - * 2 = pixel buffers are available via GLX_SGIX_fbconfig/pbuffer. + * Return: 0 = fbconfigs not available. + * 1 = fbconfigs are available via GLX 1.3. + * 2 = fbconfigs and pbuffers are available via GLX_SGIX_fbconfig */ int -QueryPbuffers(Display *dpy, int screen) +QueryFBConfig(Display *dpy, int screen) { #if defined(GLX_VERSION_1_3) { @@ -41,36 +40,55 @@ QueryPbuffers(Display *dpy, int screen) } #endif -#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) /* Try the SGIX extensions */ { char *extensions; extensions = (char *) glXQueryServerString(dpy, screen, GLX_EXTENSIONS); - if (!extensions || - !strstr(extensions,"GLX_SGIX_fbconfig") || - !strstr(extensions,"GLX_SGIX_pbuffer")) { - return 0; + if (extensions && strstr(extensions,"GLX_SGIX_fbconfig")) { + return 2; } - return 2; } -#endif return 0; } +/** + * Test if we pixel buffers are available for a particular X screen. + * Input: dpy - the X display + * screen - screen number + * Return: 0 = pixel buffers not available. + * 1 = pixel buffers are available via GLX 1.3. + * 2 = pixel buffers are available via GLX_SGIX_fbconfig/pbuffer. + */ +int +QueryPbuffers(Display *dpy, int screen) +{ + int ret; + ret = QueryFBConfig(dpy, screen); + if (ret == 2) { + char *extensions; + extensions = (char *) glXQueryServerString(dpy, screen, GLX_EXTENSIONS); + if (extensions && strstr(extensions, "GLX_SGIX_pbuffer")) + return 2; + else + return 0; + } + else + return ret; +} FBCONFIG * ChooseFBConfig(Display *dpy, int screen, const int attribs[], int *nConfigs) { - int pbSupport = QueryPbuffers(dpy, screen); + int fbcSupport = QueryPbuffers(dpy, screen); #if defined(GLX_VERSION_1_3) - if (pbSupport == 1) { + if (fbcSupport == 1) { return glXChooseFBConfig(dpy, screen, attribs, nConfigs); } #endif #if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) - if (pbSupport == 2) { + if (fbcSupport == 2) { return glXChooseFBConfigSGIX(dpy, screen, (int *) attribs, nConfigs); } #endif @@ -81,21 +99,18 @@ ChooseFBConfig(Display *dpy, int screen, const int attribs[], int *nConfigs) FBCONFIG * GetAllFBConfigs(Display *dpy, int screen, int *nConfigs) { - int pbSupport = QueryPbuffers(dpy, screen); + int fbcSupport = QueryFBConfig(dpy, screen); #if defined(GLX_VERSION_1_3) - if (pbSupport == 1) { + if (fbcSupport == 1) { return glXGetFBConfigs(dpy, screen, nConfigs); } #endif #if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) - if (pbSupport == 2) { - /* this *seems* to work, but may not be perfect */ - static int fbAttribs[] = { - GLX_RENDER_TYPE, 0, - GLX_DRAWABLE_TYPE, 0, - None - }; - return glXChooseFBConfigSGIX(dpy, screen, fbAttribs, nConfigs); + if (fbcSupport == 2) { + /* The GLX_SGIX_fbconfig extensions says to pass NULL to get list + * of all available configurations. + */ + return glXChooseFBConfigSGIX(dpy, screen, NULL, nConfigs); } #endif return NULL; @@ -105,14 +120,14 @@ GetAllFBConfigs(Display *dpy, int screen, int *nConfigs) XVisualInfo * GetVisualFromFBConfig(Display *dpy, int screen, FBCONFIG config) { - int pbSupport = QueryPbuffers(dpy, screen); + int fbcSupport = QueryFBConfig(dpy, screen); #if defined(GLX_VERSION_1_3) - if (pbSupport == 1) { + if (fbcSupport == 1) { return glXGetVisualFromFBConfig(dpy, config); } #endif #if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) - if (pbSupport == 2) { + if (fbcSupport == 2) { return glXGetVisualFromFBConfigSGIX(dpy, config); } #endif @@ -134,11 +149,11 @@ GetFBConfigAttrib(Display *dpy, int screen, int attrib ) { - int pbSupport = QueryPbuffers(dpy, screen); + int fbcSupport = QueryFBConfig(dpy, screen); int value = 0; #if defined(GLX_VERSION_1_3) - if (pbSupport == 1) { + if (fbcSupport == 1) { /* ok */ if (glXGetFBConfigAttrib(dpy, config, attrib, &value) != 0) { value = 0; @@ -149,7 +164,7 @@ GetFBConfigAttrib(Display *dpy, int screen, #endif #if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) - if (pbSupport == 2) { + if (fbcSupport == 2) { if (glXGetFBConfigAttribSGIX(dpy, config, attrib, &value) != 0) { value = 0; } @@ -296,6 +311,43 @@ PrintFBConfigInfo(Display *dpy, int screen, FBCONFIG config, Bool horizFormat) +GLXContext +CreateContext(Display *dpy, int screen, FBCONFIG config) +{ + int fbcSupport = QueryFBConfig(dpy, screen); +#if defined(GLX_VERSION_1_3) + if (fbcSupport == 1) { + /* GLX 1.3 */ + GLXContext c; + c = glXCreateNewContext(dpy, config, GLX_RGBA_TYPE, NULL, True); + if (!c) { + /* try indirect */ + c = glXCreateNewContext(dpy, config, GLX_RGBA_TYPE, NULL, False); + } + return c; + } +#endif +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) + if (fbcSupport == 2) { + GLXContext c; + c = glXCreateContextWithConfigSGIX(dpy, config, GLX_RGBA_TYPE_SGIX, NULL, True); + if (!c) { + c = glXCreateContextWithConfigSGIX(dpy, config, GLX_RGBA_TYPE_SGIX, NULL, False); + } + return c; + } +#endif + return 0; +} + + +void +DestroyContext(Display *dpy, GLXContext ctx) +{ + glXDestroyContext(dpy, ctx); +} + + /* This is only used by CreatePbuffer() */ static int XErrorFlag = 0; static int HandleXError(Display *dpy, XErrorEvent *event) @@ -360,6 +412,7 @@ CreatePbuffer(Display *dpy, int screen, FBCONFIG config, pBuffer = None; } + XSync(dpy, False); /* Restore original X error handler */ (void) XSetErrorHandler(oldHandler);