3 * OpenGL pbuffers utility functions.
7 * Updated on 5 October 2002
18 * Test if we pixel buffers are available for a particular X screen.
19 * Input: dpy - the X display
20 * screen - screen number
21 * Return: 0 = pixel buffers not available.
22 * 1 = pixel buffers are available.
25 QueryPbuffers(Display
*dpy
, int screen
)
27 #if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
30 extensions
= (char *) glXQueryServerString(dpy
, screen
, GLX_EXTENSIONS
);
31 if (!strstr(extensions
,"GLX_SGIX_fbconfig")) {
34 if (!strstr(extensions
,"GLX_SGIX_pbuffer")) {
45 #ifdef GLX_SGIX_fbconfig
49 * Print parameters for a GLXFBConfig to stdout.
50 * Input: dpy - the X display
51 * fbConfig - the fbconfig handle
52 * horizFormat - if true, print in horizontal format
55 PrintFBConfigInfo(Display
*dpy
, GLXFBConfigSGIX fbConfig
, Bool horizFormat
)
57 int pbAttribs
[] = {GLX_LARGEST_PBUFFER_SGIX
, True
,
58 GLX_PRESERVED_CONTENTS_SGIX
, False
,
60 GLXPbufferSGIX pBuffer
;
61 int width
=2, height
=2;
62 int bufferSize
, level
, doubleBuffer
, stereo
, auxBuffers
;
63 int redSize
, greenSize
, blueSize
, alphaSize
;
64 int depthSize
, stencilSize
;
65 int accumRedSize
, accumBlueSize
, accumGreenSize
, accumAlphaSize
;
66 int sampleBuffers
, samples
;
67 int drawableType
, renderType
, xRenderable
, xVisual
, id
;
68 int maxWidth
, maxHeight
, maxPixels
;
69 int optWidth
, optHeight
;
71 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_BUFFER_SIZE
, &bufferSize
);
72 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_LEVEL
, &level
);
73 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_DOUBLEBUFFER
, &doubleBuffer
);
74 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_STEREO
, &stereo
);
75 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_AUX_BUFFERS
, &auxBuffers
);
76 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_RED_SIZE
, &redSize
);
77 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_GREEN_SIZE
, &greenSize
);
78 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_BLUE_SIZE
, &blueSize
);
79 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_ALPHA_SIZE
, &alphaSize
);
80 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_DEPTH_SIZE
, &depthSize
);
81 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_STENCIL_SIZE
, &stencilSize
);
82 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_ACCUM_RED_SIZE
, &accumRedSize
);
83 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_ACCUM_GREEN_SIZE
, &accumGreenSize
);
84 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_ACCUM_BLUE_SIZE
, &accumBlueSize
);
85 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_ACCUM_ALPHA_SIZE
, &accumAlphaSize
);
86 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_SAMPLE_BUFFERS_SGIS
, &sampleBuffers
);
87 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_SAMPLES_SGIS
, &samples
);
88 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_DRAWABLE_TYPE_SGIX
, &drawableType
);
89 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_RENDER_TYPE_SGIX
, &renderType
);
90 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_X_RENDERABLE_SGIX
, &xRenderable
);
91 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_X_VISUAL_TYPE_EXT
, &xVisual
);
92 if (!xRenderable
|| !(drawableType
& GLX_WINDOW_BIT_SGIX
))
94 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_FBCONFIG_ID_SGIX
, &id
);
96 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_MAX_PBUFFER_WIDTH_SGIX
,
98 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_MAX_PBUFFER_HEIGHT_SGIX
,
100 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_MAX_PBUFFER_PIXELS_SGIX
,
102 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_OPTIMAL_PBUFFER_WIDTH_SGIX
,
104 glXGetFBConfigAttribSGIX(dpy
, fbConfig
, GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX
,
107 pBuffer
= CreatePbuffer(dpy
, fbConfig
, width
, height
, pbAttribs
);
110 printf("0x%03x ", id
);
111 if (xVisual
==GLX_STATIC_GRAY
) printf("StaticGray ");
112 else if (xVisual
==GLX_GRAY_SCALE
) printf("GrayScale ");
113 else if (xVisual
==GLX_STATIC_COLOR
) printf("StaticColor ");
114 else if (xVisual
==GLX_PSEUDO_COLOR
) printf("PseudoColor ");
115 else if (xVisual
==GLX_TRUE_COLOR
) printf("TrueColor ");
116 else if (xVisual
==GLX_DIRECT_COLOR
) printf("DirectColor ");
117 else printf(" -none- ");
118 printf(" %3d %3d %s %s %s %2s ", bufferSize
, level
,
119 (renderType
& GLX_RGBA_BIT_SGIX
) ? "y" : "n",
120 (renderType
& GLX_COLOR_INDEX_BIT_SGIX
) ? "y" : "n",
121 doubleBuffer
? "y" : "n",
123 printf("%2d %2d %2d %2d ", redSize
, greenSize
, blueSize
, alphaSize
);
124 printf("%2d %2d ", depthSize
, stencilSize
);
125 printf("%2d %2d %2d %2d", accumRedSize
, accumGreenSize
, accumBlueSize
,
127 printf(" %2d %2d", sampleBuffers
, samples
);
128 printf(" %s", pBuffer
? "y" : "n");
132 printf("Id 0x%x\n", id
);
133 printf(" Buffer Size: %d\n", bufferSize
);
134 printf(" Level: %d\n", level
);
135 printf(" Double Buffer: %s\n", doubleBuffer
? "yes" : "no");
136 printf(" Stereo: %s\n", stereo
? "yes" : "no");
137 printf(" Aux Buffers: %d\n", auxBuffers
);
138 printf(" Red Size: %d\n", redSize
);
139 printf(" Green Size: %d\n", greenSize
);
140 printf(" Blue Size: %d\n", blueSize
);
141 printf(" Alpha Size: %d\n", alphaSize
);
142 printf(" Depth Size: %d\n", depthSize
);
143 printf(" Stencil Size: %d\n", stencilSize
);
144 printf(" Accum Red Size: %d\n", accumRedSize
);
145 printf(" Accum Green Size: %d\n", accumGreenSize
);
146 printf(" Accum Blue Size: %d\n", accumBlueSize
);
147 printf(" Accum Alpha Size: %d\n", accumAlphaSize
);
148 printf(" Sample Buffers: %d\n", sampleBuffers
);
149 printf(" Samples/Pixel: %d\n", samples
);
150 printf(" Drawable Types: ");
151 if (drawableType
& GLX_WINDOW_BIT_SGIX
) printf("Window ");
152 if (drawableType
& GLX_PIXMAP_BIT_SGIX
) printf("Pixmap ");
153 if (drawableType
& GLX_PBUFFER_BIT_SGIX
) printf("PBuffer");
155 printf(" Render Types: ");
156 if (renderType
& GLX_RGBA_BIT_SGIX
) printf("RGBA ");
157 if (renderType
& GLX_COLOR_INDEX_BIT_SGIX
) printf("CI ");
159 printf(" X Renderable: %s\n", xRenderable
? "yes" : "no");
161 printf(" Max width: %d\n", maxWidth);
162 printf(" Max height: %d\n", maxHeight);
163 printf(" Max pixels: %d\n", maxPixels);
164 printf(" Optimum width: %d\n", optWidth);
165 printf(" Optimum height: %d\n", optHeight);
167 printf(" Pbuffer: %s\n", pBuffer
? "yes" : "no");
171 glXDestroyGLXPbufferSGIX(dpy
, pBuffer
);
177 /* This is only used by CreatePbuffer() */
178 static int XErrorFlag
= 0;
179 static int HandleXError( Display
*dpy
, XErrorEvent
*event
)
187 * Create a pixel buffer. We loop over the list of fbconfigs trying to create
188 * a pixel buffer. We return the first pixel buffer which we successfully
189 * create. This function hides the ugliness of dealing with BadAlloc X
192 * Input: dpy - the X display
193 * fbConfig - an FBConfig as returned by glXChooseFBConfigSGIX().
194 * width, height - size of pixel buffer to request, in pixels.
195 * pbAttribs - list of pixel buffer attributes as used by
196 * glXCreateGLXPbufferSGIX().
197 * Return: a pixel buffer or None.
200 CreatePbuffer( Display
*dpy
, GLXFBConfigSGIX fbConfig
,
201 int width
, int height
, int *pbAttribs
)
203 int (*oldHandler
)( Display
*, XErrorEvent
* );
204 GLXPbufferSGIX pBuffer
= None
;
206 /* Catch X protocol errors with our own error handler */
207 oldHandler
= XSetErrorHandler( HandleXError
);
210 pBuffer
= glXCreateGLXPbufferSGIX(dpy
, fbConfig
, width
, height
, pbAttribs
);
212 /* Restore original X error handler */
213 (void) XSetErrorHandler( oldHandler
);
215 /* Return pbuffer (may be None) */
216 if (!XErrorFlag
&& pBuffer
!=None
) {
217 /*printf("config %d worked!\n", i);*/
227 #endif /*GLX_SGIX_fbconfig*/