/** * Create a new pbuffer. */ PUBLIC GLXPbuffer glXCreatePbuffer(Display *dpy, GLXFBConfig config, const int *attrib_list) { return (GLXPbuffer) CreatePbuffer( dpy, (__GLcontextModes *) config, 0, 0, attrib_list, GL_TRUE ); }
/** * Create a new pbuffer. */ PUBLIC GLXPbufferSGIX glXCreateGLXPbufferSGIX(Display * dpy, GLXFBConfigSGIX config, unsigned int width, unsigned int height, int *attrib_list) { return (GLXPbufferSGIX) CreatePbuffer(dpy, (__GLcontextModes *) config, width, height, attrib_list, GL_FALSE); }
/** * Create a new pbuffer. */ _X_EXPORT GLXPbufferSGIX glXCreateGLXPbufferSGIX(Display * dpy, GLXFBConfigSGIX config, unsigned int width, unsigned int height, int *attrib_list) { return (GLXPbufferSGIX) CreatePbuffer(dpy, (struct glx_config *) config, width, height, attrib_list, GL_FALSE); }
/** * Create a new pbuffer. */ PUBLIC GLXPbuffer glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int *attrib_list) { int i, width, height; width = 0; height = 0; WARN_ONCE_GLX_1_3(dpy, __func__); for (i = 0; attrib_list[i * 2]; i++) { switch (attrib_list[i * 2]) { case GLX_PBUFFER_WIDTH: width = attrib_list[i * 2 + 1]; break; case GLX_PBUFFER_HEIGHT: height = attrib_list[i * 2 + 1]; break; } } return (GLXPbuffer) CreatePbuffer(dpy, (__GLcontextModes *) config, width, height, attrib_list, GL_TRUE); }
/** * Create a new pbuffer. */ PUBLIC GLXPbuffer glXCreatePbuffer(Display * dpy, GLXFBConfig config, const int *attrib_list) { int i, width, height; #ifdef GLX_USE_APPLEGL GLXPbuffer result; int errorcode; #endif width = 0; height = 0; WARN_ONCE_GLX_1_3(dpy, __func__); #ifdef GLX_USE_APPLEGL for (i = 0; attrib_list[i]; ++i) { switch (attrib_list[i]) { case GLX_PBUFFER_WIDTH: width = attrib_list[i + 1]; ++i; break; case GLX_PBUFFER_HEIGHT: height = attrib_list[i + 1]; ++i; break; case GLX_LARGEST_PBUFFER: /* This is a hint we should probably handle, but how? */ ++i; break; case GLX_PRESERVED_CONTENTS: /* The contents are always preserved with AppleSGLX with CGL. */ ++i; break; default: return None; } } if (apple_glx_pbuffer_create(dpy, config, width, height, &errorcode, &result)) { /* * apple_glx_pbuffer_create only sets the errorcode to core X11 * errors. */ __glXSendError(dpy, errorcode, 0, X_GLXCreatePbuffer, true); return None; } return result; #else for (i = 0; attrib_list[i * 2]; i++) { switch (attrib_list[i * 2]) { case GLX_PBUFFER_WIDTH: width = attrib_list[i * 2 + 1]; break; case GLX_PBUFFER_HEIGHT: height = attrib_list[i * 2 + 1]; break; } } return (GLXPbuffer) CreatePbuffer(dpy, (__GLcontextModes *) config, width, height, attrib_list, GL_TRUE); #endif }
/** * 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, int screen, FBCONFIG config, Bool horizFormat) { PBUFFER pBuffer; int width=2, height=2; int bufferSize, level, doubleBuffer, stereo, auxBuffers; int redSize, greenSize, blueSize, alphaSize; int depthSize, stencilSize; int accumRedSize, accumBlueSize, accumGreenSize, accumAlphaSize; int sampleBuffers, samples; int drawableType, renderType, xRenderable, xVisual, id; int maxWidth, maxHeight, maxPixels; int optWidth, optHeight; int floatComponents = 0; /* do queries using the GLX 1.3 tokens (same as the SGIX tokens) */ bufferSize = GetFBConfigAttrib(dpy, screen, config, GLX_BUFFER_SIZE); level = GetFBConfigAttrib(dpy, screen, config, GLX_LEVEL); doubleBuffer = GetFBConfigAttrib(dpy, screen, config, GLX_DOUBLEBUFFER); stereo = GetFBConfigAttrib(dpy, screen, config, GLX_STEREO); auxBuffers = GetFBConfigAttrib(dpy, screen, config, GLX_AUX_BUFFERS); redSize = GetFBConfigAttrib(dpy, screen, config, GLX_RED_SIZE); greenSize = GetFBConfigAttrib(dpy, screen, config, GLX_GREEN_SIZE); blueSize = GetFBConfigAttrib(dpy, screen, config, GLX_BLUE_SIZE); alphaSize = GetFBConfigAttrib(dpy, screen, config, GLX_ALPHA_SIZE); depthSize = GetFBConfigAttrib(dpy, screen, config, GLX_DEPTH_SIZE); stencilSize = GetFBConfigAttrib(dpy, screen, config, GLX_STENCIL_SIZE); accumRedSize = GetFBConfigAttrib(dpy, screen, config, GLX_ACCUM_RED_SIZE); accumGreenSize = GetFBConfigAttrib(dpy, screen, config, GLX_ACCUM_GREEN_SIZE); accumBlueSize = GetFBConfigAttrib(dpy, screen, config, GLX_ACCUM_BLUE_SIZE); accumAlphaSize = GetFBConfigAttrib(dpy, screen, config, GLX_ACCUM_ALPHA_SIZE); sampleBuffers = GetFBConfigAttrib(dpy, screen, config, GLX_SAMPLE_BUFFERS); samples = GetFBConfigAttrib(dpy, screen, config, GLX_SAMPLES); drawableType = GetFBConfigAttrib(dpy, screen, config, GLX_DRAWABLE_TYPE); renderType = GetFBConfigAttrib(dpy, screen, config, GLX_RENDER_TYPE); xRenderable = GetFBConfigAttrib(dpy, screen, config, GLX_X_RENDERABLE); xVisual = GetFBConfigAttrib(dpy, screen, config, GLX_X_VISUAL_TYPE); if (!xRenderable || !(drawableType & GLX_WINDOW_BIT_SGIX)) xVisual = -1; id = GetFBConfigAttrib(dpy, screen, config, GLX_FBCONFIG_ID); maxWidth = GetFBConfigAttrib(dpy, screen, config, GLX_MAX_PBUFFER_WIDTH); maxHeight = GetFBConfigAttrib(dpy, screen, config, GLX_MAX_PBUFFER_HEIGHT); maxPixels = GetFBConfigAttrib(dpy, screen, config, GLX_MAX_PBUFFER_PIXELS); #if defined(GLX_SGIX_pbuffer) optWidth = GetFBConfigAttrib(dpy, screen, config, GLX_OPTIMAL_PBUFFER_WIDTH_SGIX); optHeight = GetFBConfigAttrib(dpy, screen, config, GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX); #else optWidth = optHeight = 0; #endif #if defined(GLX_NV_float_buffer) floatComponents = GetFBConfigAttrib(dpy, screen, config, GLX_FLOAT_COMPONENTS_NV); #endif /* See if we can create a pbuffer with this config */ pBuffer = CreatePbuffer(dpy, screen, config, width, height, False, False); if (horizFormat) { printf("0x%-9x ", id); if (xVisual==GLX_STATIC_GRAY) printf("StaticGray "); else if (xVisual==GLX_GRAY_SCALE) printf("GrayScale "); else if (xVisual==GLX_STATIC_COLOR) printf("StaticColor "); else if (xVisual==GLX_PSEUDO_COLOR) printf("PseudoColor "); else if (xVisual==GLX_TRUE_COLOR) printf("TrueColor "); else if (xVisual==GLX_DIRECT_COLOR) printf("DirectColor "); else printf(" -none- "); printf(" %3d %3d %s %s %s %2s ", bufferSize, level, (renderType & GLX_RGBA_BIT_SGIX) ? "y" : ".", (renderType & GLX_COLOR_INDEX_BIT_SGIX) ? "y" : ".", doubleBuffer ? "y" : ".", stereo ? "y" : "."); printf("%2d %2d %2d %2d ", redSize, greenSize, blueSize, alphaSize); printf("%2d %2d ", depthSize, stencilSize); printf("%2d %2d %2d %2d", accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize); printf(" %2d %2d", sampleBuffers, samples); printf(" %s %c", pBuffer ? "y" : ".", ".y"[floatComponents]); printf("\n"); } else { printf("Id 0x%x\n", id); printf(" Buffer Size: %d\n", bufferSize); printf(" Level: %d\n", level); printf(" Double Buffer: %s\n", doubleBuffer ? "yes" : "no"); printf(" Stereo: %s\n", stereo ? "yes" : "no"); printf(" Aux Buffers: %d\n", auxBuffers); printf(" Red Size: %d\n", redSize); printf(" Green Size: %d\n", greenSize); printf(" Blue Size: %d\n", blueSize); printf(" Alpha Size: %d\n", alphaSize); printf(" Depth Size: %d\n", depthSize); printf(" Stencil Size: %d\n", stencilSize); printf(" Accum Red Size: %d\n", accumRedSize); printf(" Accum Green Size: %d\n", accumGreenSize); printf(" Accum Blue Size: %d\n", accumBlueSize); printf(" Accum Alpha Size: %d\n", accumAlphaSize); printf(" Sample Buffers: %d\n", sampleBuffers); printf(" Samples/Pixel: %d\n", samples); printf(" Drawable Types: "); 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(" 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) { DestroyPbuffer(dpy, screen, pBuffer); } }
/* * Create the pbuffer and return a GLXPbufferSGIX handle. */ static GLXPbufferSGIX MakePbuffer( Display *dpy, int screen, int width, int height ) { #define NUM_FB_CONFIGS 4 char fbString[NUM_FB_CONFIGS][100] = { "Single Buffered, depth buffer", "Double Buffered, depth buffer", "Single Buffered, no depth buffer", "Double Buffered, no depth buffer" }; int fbAttribs[NUM_FB_CONFIGS][100] = { { /* Single buffered, with depth buffer */ GLX_RENDER_TYPE_SGIX, GLX_RGBA_BIT_SGIX, GLX_DRAWABLE_TYPE_SGIX, GLX_PIXMAP_BIT_SGIX, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DEPTH_SIZE, 1, GLX_DOUBLEBUFFER, 0, GLX_STENCIL_SIZE, 0, None }, { /* Double buffered, with depth buffer */ GLX_RENDER_TYPE_SGIX, GLX_RGBA_BIT_SGIX, GLX_DRAWABLE_TYPE_SGIX, GLX_PIXMAP_BIT_SGIX, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DEPTH_SIZE, 1, GLX_DOUBLEBUFFER, 1, GLX_STENCIL_SIZE, 0, None }, { /* Single bufferd, without depth buffer */ GLX_RENDER_TYPE_SGIX, GLX_RGBA_BIT_SGIX, GLX_DRAWABLE_TYPE_SGIX, GLX_PIXMAP_BIT_SGIX, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DEPTH_SIZE, 0, GLX_DOUBLEBUFFER, 0, GLX_STENCIL_SIZE, 0, None }, { /* Double bufferd, without depth buffer */ GLX_RENDER_TYPE_SGIX, GLX_RGBA_BIT_SGIX, GLX_DRAWABLE_TYPE_SGIX, GLX_PIXMAP_BIT_SGIX, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DEPTH_SIZE, 0, GLX_DOUBLEBUFFER, 1, GLX_STENCIL_SIZE, 0, None } }; int pbAttribs[] = { GLX_LARGEST_PBUFFER_SGIX, True, GLX_PRESERVED_CONTENTS_SGIX, False, None }; GLXFBConfigSGIX *fbConfigs; GLXPbufferSGIX pBuffer = None; int nConfigs; int i; int attempt; for (attempt=0; attempt<NUM_FB_CONFIGS; attempt++) { /* Get list of possible frame buffer configurations */ fbConfigs = glXChooseFBConfigSGIX(dpy, screen, fbAttribs[attempt], &nConfigs); if (nConfigs==0 || !fbConfigs) { printf("Error: glxChooseFBConfigSGIX failed\n"); XCloseDisplay(dpy); return 0; } #ifdef DEBUG for (i=0;i<nConfigs;i++) { printf("Config %d\n", i); PrintFBConfigInfo(dpy, 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); if (pBuffer) { gFBconfig = fbConfigs[i]; gWidth = width; gHeight = height; break; } } if (pBuffer!=None) { break; } } if (pBuffer) { printf("Using: %s\n", fbString[attempt]); } XFree(fbConfigs); return pBuffer; #undef NUM_FB_CONFIGS }