diff options
author | Brian Paul <[email protected]> | 2005-01-04 00:58:29 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2005-01-04 00:58:29 +0000 |
commit | f72e4424d960b1751845d9e0579e8fdcca93b3d0 (patch) | |
tree | 195eb903de1a6d6c39a72c062a47701355c963d2 /progs | |
parent | e3748eb19ba444f411ad66905dfddbe809225ca0 (diff) |
Use the GLX 1.3 pbuffer/fbconfig functions in preference to the SGIX ones.
Added more functions to pbutil.[ch] to better isolate API differences.
Diffstat (limited to 'progs')
-rw-r--r-- | progs/xdemos/pbdemo.c | 69 | ||||
-rw-r--r-- | progs/xdemos/pbinfo.c | 28 | ||||
-rw-r--r-- | progs/xdemos/pbutil.c | 310 | ||||
-rw-r--r-- | progs/xdemos/pbutil.h | 33 |
4 files changed, 295 insertions, 145 deletions
diff --git a/progs/xdemos/pbdemo.c b/progs/xdemos/pbdemo.c index 88e6a4ff947..efdfdfa4522 100644 --- a/progs/xdemos/pbdemo.c +++ b/progs/xdemos/pbdemo.c @@ -41,22 +41,23 @@ /* Some ugly global vars */ -static GLXFBConfigSGIX gFBconfig = 0; static Display *gDpy = NULL; static int gScreen = 0; -static GLXPbufferSGIX gPBuffer = 0; +static FBCONFIG gFBconfig = 0; +static PBUFFER gPBuffer = 0; static int gWidth, gHeight; +static GLXContext glCtx; /* - * Create the pbuffer and return a GLXPbufferSGIX handle. + * Create the pbuffer and return a GLXPbuffer handle. * * We loop over a list of fbconfigs trying to create * a pixel buffer. We return the first pixel buffer which we successfully * create. */ -static GLXPbufferSGIX +static PBUFFER MakePbuffer( Display *dpy, int screen, int width, int height ) { #define NUM_FB_CONFIGS 4 @@ -69,8 +70,8 @@ MakePbuffer( Display *dpy, int screen, int width, int height ) int fbAttribs[NUM_FB_CONFIGS][100] = { { /* Single buffered, with depth buffer */ - GLX_RENDER_TYPE_SGIX, GLX_RGBA_BIT_SGIX, - GLX_DRAWABLE_TYPE_SGIX, GLX_PBUFFER_BIT_SGIX, + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, @@ -81,8 +82,8 @@ MakePbuffer( Display *dpy, int screen, int width, int height ) }, { /* Double buffered, with depth buffer */ - GLX_RENDER_TYPE_SGIX, GLX_RGBA_BIT_SGIX, - GLX_DRAWABLE_TYPE_SGIX, GLX_PBUFFER_BIT_SGIX, + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, @@ -93,8 +94,8 @@ MakePbuffer( Display *dpy, int screen, int width, int height ) }, { /* Single bufferd, without depth buffer */ - GLX_RENDER_TYPE_SGIX, GLX_RGBA_BIT_SGIX, - GLX_DRAWABLE_TYPE_SGIX, GLX_PBUFFER_BIT_SGIX, + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, @@ -105,8 +106,8 @@ MakePbuffer( Display *dpy, int screen, int width, int height ) }, { /* Double bufferd, without depth buffer */ - GLX_RENDER_TYPE_SGIX, GLX_RGBA_BIT_SGIX, - GLX_DRAWABLE_TYPE_SGIX, GLX_PBUFFER_BIT_SGIX, + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, @@ -116,13 +117,10 @@ MakePbuffer( Display *dpy, int screen, int width, int height ) None } }; - int pbAttribs[] = { - GLX_LARGEST_PBUFFER_SGIX, True, - GLX_PRESERVED_CONTENTS_SGIX, False, - None - }; - GLXFBConfigSGIX *fbConfigs; - GLXPbufferSGIX pBuffer = None; + Bool largest = True; + Bool preserve = False; + FBCONFIG *fbConfigs; + PBUFFER pBuffer = None; int nConfigs; int i; int attempt; @@ -130,23 +128,23 @@ MakePbuffer( Display *dpy, int screen, int width, int height ) for (attempt=0; attempt<NUM_FB_CONFIGS; attempt++) { /* Get list of possible frame buffer configurations */ - fbConfigs = glXChooseFBConfigSGIX(dpy, screen, fbAttribs[attempt], &nConfigs); + fbConfigs = ChooseFBConfig(dpy, screen, fbAttribs[attempt], &nConfigs); if (nConfigs==0 || !fbConfigs) { - printf("Error: glxChooseFBConfigSGIX failed\n"); + printf("Error: glXChooseFBConfig failed\n"); XCloseDisplay(dpy); return 0; } -#ifdef DEBUG +#if 0 /*DEBUG*/ for (i=0;i<nConfigs;i++) { printf("Config %d\n", i); - PrintFBConfigInfo(dpy, fbConfigs[i], 0); + PrintFBConfigInfo(dpy, screen, fbConfigs[i], 0); } #endif /* Create the pbuffer using first fbConfig in the list that works. */ for (i=0;i<nConfigs;i++) { - pBuffer = CreatePbuffer(dpy, fbConfigs[i], width, height, pbAttribs); + pBuffer = CreatePbuffer(dpy, screen, fbConfigs[i], width, height, preserve, largest); if (pBuffer) { gFBconfig = fbConfigs[i]; gWidth = width; @@ -178,9 +176,8 @@ MakePbuffer( Display *dpy, int screen, int width, int height ) static int Setup(int width, int height) { -#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) + int pbSupport; XVisualInfo *visInfo; - GLXContext glCtx; /* Open the X display */ gDpy = XOpenDisplay(NULL); @@ -193,7 +190,14 @@ Setup(int width, int height) gScreen = DefaultScreen(gDpy); /* Test that pbuffers are available */ - if (!QueryPbuffers(gDpy, gScreen)) { + pbSupport = QueryPbuffers(gDpy, gScreen); + if (pbSupport == 1) { + printf("Using GLX 1.3 Pbuffers\n"); + } + else if (pbSupport == 2) { + printf("Using SGIX Pbuffers\n"); + } + else { printf("Error: pbuffers not available on this screen\n"); XCloseDisplay(gDpy); return 0; @@ -208,7 +212,7 @@ Setup(int width, int height) } /* Get corresponding XVisualInfo */ - visInfo = glXGetVisualFromFBConfigSGIX(gDpy, gFBconfig); + visInfo = GetVisualFromFBConfig(gDpy, gScreen, gFBconfig); if (!visInfo) { printf("Error: can't get XVisualInfo from FBconfig\n"); XCloseDisplay(gDpy); @@ -240,11 +244,6 @@ Setup(int width, int height) } return 1; /* Success!! */ -#else - printf("Error: GLX_SGIX_fbconfig and/or GLX_SGIX_pbuffer extensions not" - " available at compile-time.\n"); - return 0; -#endif } @@ -360,7 +359,6 @@ Render(void) int NumBoxes = 100; int i; - InitGL(); glClearColor(0.2, 0.2, 0.9, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -470,9 +468,10 @@ main(int argc, char *argv[]) if (!Setup(width, height)) { return 1; } + InitGL(); Render(); WriteFile(fileName); - glXDestroyGLXPbufferSGIX( gDpy, gPBuffer ); + DestroyPbuffer(gDpy, gScreen, gPBuffer); } return 0; } diff --git a/progs/xdemos/pbinfo.c b/progs/xdemos/pbinfo.c index 948ad9ca22c..d4bc7e80836 100644 --- a/progs/xdemos/pbinfo.c +++ b/progs/xdemos/pbinfo.c @@ -20,18 +20,18 @@ static void PrintConfigs(Display *dpy, int screen, Bool horizFormat) { - GLXFBConfigSGIX *fbConfigs; + FBCONFIG *fbConfigs; int nConfigs; int i; /* Note: you may want to tweek the attribute list to select a different * set of fbconfigs. */ int fbAttribs[] = { - GLX_RENDER_TYPE_SGIX, 0, - GLX_DRAWABLE_TYPE_SGIX, 0, + GLX_RENDER_TYPE, 0, + GLX_DRAWABLE_TYPE, 0, #if 0 - GLX_RENDER_TYPE_SGIX, GLX_RGBA_BIT_SGIX, - GLX_DRAWABLE_TYPE_SGIX, GLX_PIXMAP_BIT_SGIX, + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, @@ -43,17 +43,9 @@ PrintConfigs(Display *dpy, int screen, Bool horizFormat) /* Get list of possible frame buffer configurations */ -#if 0 - /* SGIX method */ - fbConfigs = glXChooseFBConfigSGIX(dpy, screen, fbAttribs, &nConfigs); -#else - /* GLX 1.3 method */ - (void) fbAttribs; - fbConfigs = glXGetFBConfigs(dpy, screen, &nConfigs); -#endif - - if (nConfigs==0 || !fbConfigs) { - printf("Error: glxChooseFBConfigSGIX failed\n"); + fbConfigs = ChooseFBConfig(dpy, screen, fbAttribs, &nConfigs); + if (!nConfigs || !fbConfigs) { + printf("Error: glxChooseFBConfig failed\n"); return; } @@ -61,12 +53,12 @@ PrintConfigs(Display *dpy, int screen, Bool horizFormat) if (horizFormat) { printf(" ID VisualType Depth Lvl RGB CI DB Stereo R G B A"); - printf(" Z S AR AG AB AA MSbufs MSnum Pbuffer\n"); + printf(" Z S AR AG AB AA MSbufs MSnum Pbuffer Float\n"); } /* Print config info */ for (i=0;i<nConfigs;i++) { - PrintFBConfigInfo(dpy, fbConfigs[i], horizFormat); + PrintFBConfigInfo(dpy, screen, fbConfigs[i], horizFormat); } /* free the list */ diff --git a/progs/xdemos/pbutil.c b/progs/xdemos/pbutil.c index 0dd4b409f4a..50456e9f94f 100644 --- a/progs/xdemos/pbutil.c +++ b/progs/xdemos/pbutil.c @@ -3,8 +3,10 @@ * OpenGL pbuffers utility functions. * * Brian Paul - * April 1997 + * Original code: April 1997 * Updated on 5 October 2002 + * Updated again on 3 January 2005 to use GLX 1.3 functions in preference + * to the GLX_SGIX_fbconfig/pbuffer extensions. */ @@ -13,51 +15,140 @@ #include "pbutil.h" - -/* +/** * 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. + * 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) { +#if defined(GLX_VERSION_1_3) + { + /* GLX 1.3 supports pbuffers */ + int glxVersionMajor, glxVersionMinor; + if (!glXQueryVersion(dpy, &glxVersionMajor, &glxVersionMinor)) { + /* GLX not available! */ + return 0; + } + if (glxVersionMajor * 100 + glxVersionMinor >= 103) { + return 1; + } + /* fall-through */ + } +#endif + #if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) - char *extensions; + /* 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; + } + return 2; + } +#endif - extensions = (char *) glXQueryServerString(dpy, screen, GLX_EXTENSIONS); - if (!strstr(extensions,"GLX_SGIX_fbconfig")) { - return 0; + return 0; +} + + + +FBCONFIG * +ChooseFBConfig(Display *dpy, int screen, const int attribs[], int *nConfigs) +{ + int pbSupport = QueryPbuffers(dpy, screen); +#if defined(GLX_VERSION_1_3) + if (pbSupport == 1) { + return glXChooseFBConfig(dpy, screen, attribs, nConfigs); } - if (!strstr(extensions,"GLX_SGIX_pbuffer")) { - return 0; +#endif +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) + if (pbSupport == 2) { + return glXChooseFBConfigSGIX(dpy, screen, (int *) attribs, nConfigs); } - return 1; -#else - return 0; #endif + return NULL; } -#ifdef GLX_SGIX_fbconfig +XVisualInfo * +GetVisualFromFBConfig(Display *dpy, int screen, FBCONFIG config) +{ + int pbSupport = QueryPbuffers(dpy, screen); +#if defined(GLX_VERSION_1_3) + if (pbSupport == 1) { + return glXGetVisualFromFBConfig(dpy, config); + } +#endif +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) + if (pbSupport == 2) { + return glXGetVisualFromFBConfigSGIX(dpy, config); + } +#endif + return NULL; +} -/* +/** + * Either use glXGetFBConfigAttrib() or glXGetFBConfigAttribSGIX() + * to query an fbconfig attribute. + */ +static int +GetFBConfigAttrib(Display *dpy, +#if defined(GLX_VERSION_1_3) + const GLXFBConfig config, +#elif defined(GLX_SGIX_fbconfig) + const GLXFBConfigSGIX config, +#endif + int attrib + ) +{ + int value; + +#if defined(GLX_VERSION_1_3) + int glxVersionMajor, glxVersionMinor; + if (glXQueryVersion(dpy, &glxVersionMajor, &glxVersionMinor) + && glxVersionMajor * 100 + glxVersionMinor >= 103) { + /* ok */ + if (glXGetFBConfigAttrib(dpy, config, attrib, &value) != 0) { + value = 0; + } + return value; + } + /* fall-through */ +#endif + +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) + if (glXGetFBConfigAttribSGIX(dpy, config, attrib, &value) != 0) { + value = 0; + } + return value; +#endif + + return 0; +} + + + +/** * Print parameters for a GLXFBConfig to stdout. * Input: dpy - the X display + * screen - the X screen number * fbConfig - the fbconfig handle * horizFormat - if true, print in horizontal format */ void -PrintFBConfigInfo(Display *dpy, GLXFBConfigSGIX fbConfig, Bool horizFormat) +PrintFBConfigInfo(Display *dpy, int screen, FBCONFIG config, Bool horizFormat) { - int pbAttribs[] = {GLX_LARGEST_PBUFFER_SGIX, True, - GLX_PRESERVED_CONTENTS_SGIX, False, - None}; - GLXPbufferSGIX pBuffer; + PBUFFER pBuffer; int width=2, height=2; int bufferSize, level, doubleBuffer, stereo, auxBuffers; int redSize, greenSize, blueSize, alphaSize; @@ -67,44 +158,49 @@ PrintFBConfigInfo(Display *dpy, GLXFBConfigSGIX fbConfig, Bool horizFormat) int drawableType, renderType, xRenderable, xVisual, id; int maxWidth, maxHeight, maxPixels; int optWidth, optHeight; + int floatComponents; - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_BUFFER_SIZE, &bufferSize); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_LEVEL, &level); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_DOUBLEBUFFER, &doubleBuffer); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_STEREO, &stereo); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_AUX_BUFFERS, &auxBuffers); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_RED_SIZE, &redSize); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_GREEN_SIZE, &greenSize); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_BLUE_SIZE, &blueSize); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_ALPHA_SIZE, &alphaSize); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_DEPTH_SIZE, &depthSize); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_STENCIL_SIZE, &stencilSize); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_ACCUM_RED_SIZE, &accumRedSize); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_ACCUM_GREEN_SIZE, &accumGreenSize); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_ACCUM_BLUE_SIZE, &accumBlueSize); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_ACCUM_ALPHA_SIZE, &accumAlphaSize); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_SAMPLE_BUFFERS_SGIS, &sampleBuffers); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_SAMPLES_SGIS, &samples); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_DRAWABLE_TYPE_SGIX, &drawableType); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_RENDER_TYPE_SGIX, &renderType); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_X_RENDERABLE_SGIX, &xRenderable); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_X_VISUAL_TYPE_EXT, &xVisual); + /* do queries using the GLX 1.3 tokens (same as the SGIX tokens) */ + bufferSize = GetFBConfigAttrib(dpy, config, GLX_BUFFER_SIZE); + level = GetFBConfigAttrib(dpy, config, GLX_LEVEL); + doubleBuffer = GetFBConfigAttrib(dpy, config, GLX_DOUBLEBUFFER); + stereo = GetFBConfigAttrib(dpy, config, GLX_STEREO); + auxBuffers = GetFBConfigAttrib(dpy, config, GLX_AUX_BUFFERS); + redSize = GetFBConfigAttrib(dpy, config, GLX_RED_SIZE); + greenSize = GetFBConfigAttrib(dpy, config, GLX_GREEN_SIZE); + blueSize = GetFBConfigAttrib(dpy, config, GLX_BLUE_SIZE); + alphaSize = GetFBConfigAttrib(dpy, config, GLX_ALPHA_SIZE); + depthSize = GetFBConfigAttrib(dpy, config, GLX_DEPTH_SIZE); + stencilSize = GetFBConfigAttrib(dpy, config, GLX_STENCIL_SIZE); + accumRedSize = GetFBConfigAttrib(dpy, config, GLX_ACCUM_RED_SIZE); + accumGreenSize = GetFBConfigAttrib(dpy, config, GLX_ACCUM_GREEN_SIZE); + accumBlueSize = GetFBConfigAttrib(dpy, config, GLX_ACCUM_BLUE_SIZE); + accumAlphaSize = GetFBConfigAttrib(dpy, config, GLX_ACCUM_ALPHA_SIZE); + sampleBuffers = GetFBConfigAttrib(dpy, config, GLX_SAMPLE_BUFFERS); + samples = GetFBConfigAttrib(dpy, config, GLX_SAMPLES); + drawableType = GetFBConfigAttrib(dpy, config, GLX_DRAWABLE_TYPE); + renderType = GetFBConfigAttrib(dpy, config, GLX_RENDER_TYPE); + xRenderable = GetFBConfigAttrib(dpy, config, GLX_X_RENDERABLE); + xVisual = GetFBConfigAttrib(dpy, config, GLX_X_VISUAL_TYPE); if (!xRenderable || !(drawableType & GLX_WINDOW_BIT_SGIX)) xVisual = -1; - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_FBCONFIG_ID_SGIX, &id); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_MAX_PBUFFER_WIDTH_SGIX, - &maxWidth); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_MAX_PBUFFER_HEIGHT_SGIX, - &maxHeight); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_MAX_PBUFFER_PIXELS_SGIX, - &maxPixels); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_OPTIMAL_PBUFFER_WIDTH_SGIX, - &optWidth); - glXGetFBConfigAttribSGIX(dpy, fbConfig, GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX, - &optHeight); + id = GetFBConfigAttrib(dpy, config, GLX_FBCONFIG_ID); + maxWidth = GetFBConfigAttrib(dpy, config, GLX_MAX_PBUFFER_WIDTH); + maxHeight = GetFBConfigAttrib(dpy, config, GLX_MAX_PBUFFER_HEIGHT); + maxPixels = GetFBConfigAttrib(dpy, config, GLX_MAX_PBUFFER_PIXELS); +#if defined(GLX_SGIX_pbuffer) + optWidth = GetFBConfigAttrib(dpy, config, GLX_OPTIMAL_PBUFFER_WIDTH_SGIX); + optHeight = GetFBConfigAttrib(dpy, config, GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX); +#else + optWidth = optHeight = 0; +#endif +#if defined(GLX_NV_float_buffer) + floatComponents = GetFBConfigAttrib(dpy, config, GLX_FLOAT_COMPONENTS_NV); +#endif - pBuffer = CreatePbuffer(dpy, fbConfig, width, height, pbAttribs); + /* See if we can create a pbuffer with this config */ + pBuffer = CreatePbuffer(dpy, screen, config, width, height, False, False); if (horizFormat) { printf("0x%03x ", id); @@ -125,7 +221,8 @@ PrintFBConfigInfo(Display *dpy, GLXFBConfigSGIX fbConfig, Bool horizFormat) printf("%2d %2d %2d %2d", accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize); printf(" %2d %2d", sampleBuffers, samples); - printf(" %s", pBuffer ? "y" : "n"); + printf(" %s %c", pBuffer ? "y" : "n", + "ny"[floatComponents]); printf("\n"); } else { @@ -148,27 +245,28 @@ PrintFBConfigInfo(Display *dpy, GLXFBConfigSGIX fbConfig, Bool horizFormat) printf(" Sample Buffers: %d\n", sampleBuffers); printf(" Samples/Pixel: %d\n", samples); printf(" Drawable Types: "); - if (drawableType & GLX_WINDOW_BIT_SGIX) printf("Window "); - if (drawableType & GLX_PIXMAP_BIT_SGIX) printf("Pixmap "); - if (drawableType & GLX_PBUFFER_BIT_SGIX) printf("PBuffer"); + if (drawableType & GLX_WINDOW_BIT) printf("Window "); + if (drawableType & GLX_PIXMAP_BIT) printf("Pixmap "); + if (drawableType & GLX_PBUFFER_BIT) printf("PBuffer"); printf("\n"); printf(" Render Types: "); if (renderType & GLX_RGBA_BIT_SGIX) printf("RGBA "); if (renderType & GLX_COLOR_INDEX_BIT_SGIX) printf("CI "); printf("\n"); printf(" X Renderable: %s\n", xRenderable ? "yes" : "no"); - /* - printf(" Max width: %d\n", maxWidth); - printf(" Max height: %d\n", maxHeight); - printf(" Max pixels: %d\n", maxPixels); - printf(" Optimum width: %d\n", optWidth); - printf(" Optimum height: %d\n", optHeight); - */ + printf(" Pbuffer: %s\n", pBuffer ? "yes" : "no"); + printf(" Max Pbuffer width: %d\n", maxWidth); + printf(" Max Pbuffer height: %d\n", maxHeight); + printf(" Max Pbuffer pixels: %d\n", maxPixels); + printf(" Optimum Pbuffer width: %d\n", optWidth); + printf(" Optimum Pbuffer height: %d\n", optHeight); + + printf(" Float Components: %s\n", floatComponents ? "yes" : "no"); } if (pBuffer) { - glXDestroyGLXPbufferSGIX(dpy, pBuffer); + DestroyPbuffer(dpy, screen, pBuffer); } } @@ -176,42 +274,73 @@ PrintFBConfigInfo(Display *dpy, GLXFBConfigSGIX fbConfig, Bool horizFormat) /* This is only used by CreatePbuffer() */ static int XErrorFlag = 0; -static int HandleXError( Display *dpy, XErrorEvent *event ) +static int HandleXError(Display *dpy, XErrorEvent *event) { XErrorFlag = 1; return 0; } -/* +/** * Create a Pbuffer. Use an X error handler to deal with potential * BadAlloc errors. * * Input: dpy - the X display * fbConfig - an FBConfig as returned by glXChooseFBConfigSGIX(). * width, height - size of pixel buffer to request, in pixels. - * pbAttribs - list of pixel buffer attributes as used by - * glXCreateGLXPbufferSGIX(). - * Return: a pixel buffer or None. + * pbAttribs - list of optional pixel buffer attributes + * Return: a Pbuffer or None. */ -GLXPbufferSGIX -CreatePbuffer( Display *dpy, GLXFBConfigSGIX fbConfig, - int width, int height, int *pbAttribs ) +PBUFFER +CreatePbuffer(Display *dpy, int screen, FBCONFIG config, + int width, int height, Bool largest, Bool preserve) { - int (*oldHandler)( Display *, XErrorEvent * ); - GLXPbufferSGIX pBuffer = None; + int (*oldHandler)(Display *, XErrorEvent *); + PBUFFER pBuffer = None; + int pbSupport = QueryPbuffers(dpy, screen); /* Catch X protocol errors with our own error handler */ - oldHandler = XSetErrorHandler( HandleXError ); - + oldHandler = XSetErrorHandler(HandleXError); XErrorFlag = 0; - pBuffer = glXCreateGLXPbufferSGIX(dpy, fbConfig, width, height, pbAttribs); + +#if defined(GLX_VERSION_1_3) + if (pbSupport == 1) { + /* GLX 1.3 */ + int attribs[100], i = 0; + attribs[i++] = GLX_PBUFFER_WIDTH; + attribs[i++] = width; + attribs[i++] = GLX_PBUFFER_HEIGHT; + attribs[i++] = height; + attribs[i++] = GLX_PRESERVED_CONTENTS; + attribs[i++] = preserve; + attribs[i++] = GLX_LARGEST_PBUFFER; + attribs[i++] = largest; + attribs[i++] = 0; + pBuffer = glXCreatePbuffer(dpy, config, attribs); + } + else +#endif +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) + if (pbSupport == 2) { + int attribs[100], i = 0; + attribs[i++] = GLX_PRESERVED_CONTENTS; + attribs[i++] = preserve; + attribs[i++] = GLX_LARGEST_PBUFFER; + attribs[i++] = largest; + attribs[i++] = 0; + pBuffer = glXCreateGLXPbufferSGIX(dpy, config, width, height, attribs); + } + else +#endif + { + pBuffer = None; + } /* Restore original X error handler */ - (void) XSetErrorHandler( oldHandler ); + (void) XSetErrorHandler(oldHandler); /* Return pbuffer (may be None) */ - if (!XErrorFlag && pBuffer!=None) { + if (!XErrorFlag && pBuffer != None) { /*printf("config %d worked!\n", i);*/ return pBuffer; } @@ -221,7 +350,20 @@ CreatePbuffer( Display *dpy, GLXFBConfigSGIX fbConfig, } - -#endif /*GLX_SGIX_fbconfig*/ - - +void +DestroyPbuffer(Display *dpy, int screen, PBUFFER pbuffer) +{ + int pbSupport = QueryPbuffers(dpy, screen); +#if defined(GLX_VERSION_1_3) + if (pbSupport == 1) { + glXDestroyPbuffer(dpy, pbuffer); + return; + } +#endif +#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) + if (pbSupport == 2) { + glXDestroyGLXPbufferSGIX(dpy, pbuffer); + return; + } +#endif +} diff --git a/progs/xdemos/pbutil.h b/progs/xdemos/pbutil.h index d13c969c4c8..68ba8808c2c 100644 --- a/progs/xdemos/pbutil.h +++ b/progs/xdemos/pbutil.h @@ -1,4 +1,3 @@ - /* * OpenGL pbuffers utility functions. * @@ -15,23 +14,41 @@ #include <GL/glx.h> +#if defined(GLX_VERSION_1_3) +#define PBUFFER GLXPbuffer +#define FBCONFIG GLXFBConfig +#elif defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) +#define PBUFFER GLXPbufferSGIX +#define FBCONFIG GLXFBConfigSGIX +#else +#define PBUFFER int +#define FBCONFIG int +#endif + + extern int QueryPbuffers(Display *dpy, int screen); -#ifdef GLX_SGIX_fbconfig +extern void +PrintFBConfigInfo(Display *dpy, int screen, FBCONFIG config, Bool horizFormat); + +extern FBCONFIG * +ChooseFBConfig(Display *dpy, int screen, const int attribs[], int *nConfigs); -extern void -PrintFBConfigInfo(Display *dpy, GLXFBConfigSGIX fbConfig, Bool horizFormat); +extern XVisualInfo * +GetVisualFromFBConfig(Display *dpy, int screen, FBCONFIG config); -extern GLXPbufferSGIX -CreatePbuffer( Display *dpy, GLXFBConfigSGIX fbConfig, - int width, int height, int *pbAttribs ); +extern PBUFFER +CreatePbuffer(Display *dpy, int screen, FBCONFIG config, + int width, int height, Bool preserve, Bool largest); -#endif /*GLX_SGIX_fbconfig*/ + +extern void +DestroyPbuffer(Display *dpy, int screen, PBUFFER pbuffer); #endif /*PBUTIL_H*/ |