Import the GLX client side library, formerly from xc/lib/GL/glx. Build it
[mesa.git] / src / glx / x11 / glxextensions.c
1 /*
2 * (C) Copyright IBM Corporation 2002, 2004
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file glxextensions.c
27 *
28 * \author Ian Romanick <idr@us.ibm.com>
29 */
30 /* $XFree86: xc/lib/GL/glx/glxextensions.c,v 1.1 2003/09/28 20:15:03 alanh Exp $ */
31
32 #include "glxclient.h"
33 #include <extutil.h>
34 #include <Xext.h>
35 #include <string.h>
36 #include "glapi.h"
37 #include "glxextensions.h"
38 #include "simple_list.h"
39
40 #define SET_BIT(m,b) (m[ (b) / 8 ] |= (1U << ((b) % 8)))
41 #define CLR_BIT(m,b) (m[ (b) / 8 ] &= ~(1U << ((b) % 8)))
42 #define IS_SET(m,b) ((m[ (b) / 8 ] & (1U << ((b) % 8))) != 0)
43 #define CONCAT(a,b) a ## b
44 #define GLX(n) "GLX_" # n, 4 + sizeof( # n ) - 1, CONCAT(n,_bit)
45 #define GL(n) "GL_" # n, 3 + sizeof( # n ) - 1, GL_ ## n ## _bit
46 #define VER(a,b) a, b
47 #define Y 1
48 #define N 0
49 #define EXT_ENABLED(bit,supported) (IS_SET( supported, bit ))
50
51
52 struct extension_info {
53 const char * const name;
54 unsigned name_len;
55
56 unsigned char bit;
57
58 /* This is the lowest version of GLX that "requires" this extension.
59 * For example, GLX 1.3 requires SGIX_fbconfig, SGIX_pbuffer, and
60 * SGI_make_current_read. If the extension is not required by any known
61 * version of GLX, use 0, 0.
62 */
63 unsigned char version_major;
64 unsigned char version_minor;
65 unsigned char client_support;
66 unsigned char direct_support;
67 unsigned char client_only; /** Is the extension client-side only? */
68 unsigned char direct_only; /** Is the extension for direct
69 * contexts only?
70 */
71 };
72
73 static const struct extension_info known_glx_extensions[] = {
74 { GLX(ARB_get_proc_address), VER(1,4), Y, N, Y, N },
75 { GLX(ARB_multisample), VER(1,4), Y, Y, N, N },
76 { GLX(ARB_render_texture), VER(0,0), N, N, N, N },
77 { GLX(ATI_pixel_format_float), VER(0,0), N, N, N, N },
78 { GLX(EXT_import_context), VER(0,0), Y, Y, N, N },
79 { GLX(EXT_visual_info), VER(0,0), Y, Y, N, N },
80 { GLX(EXT_visual_rating), VER(0,0), Y, Y, N, N },
81 { GLX(MESA_agp_offset), VER(0,0), N, N, N, Y }, /* Deprecated */
82 { GLX(MESA_allocate_memory), VER(0,0), Y, N, N, Y },
83 { GLX(MESA_copy_sub_buffer), VER(0,0), N, N, N, N }, /* Deprecated? */
84 { GLX(MESA_pixmap_colormap), VER(0,0), N, N, N, N }, /* Deprecated */
85 { GLX(MESA_release_buffers), VER(0,0), N, N, N, N }, /* Deprecated */
86 { GLX(MESA_set_3dfx_mode), VER(0,0), N, N, N, N }, /* Deprecated */
87 { GLX(MESA_swap_control), VER(0,0), Y, N, N, Y },
88 { GLX(MESA_swap_frame_usage), VER(0,0), Y, N, N, Y },
89 { GLX(NV_float_buffer), VER(0,0), N, N, N, N },
90 { GLX(NV_render_depth_texture), VER(0,0), N, N, N, N },
91 { GLX(NV_render_texture_rectangle), VER(0,0), N, N, N, N },
92 { GLX(NV_vertex_array_range), VER(0,0), N, N, N, Y }, /* Deprecated */
93 { GLX(OML_swap_method), VER(0,0), Y, N, N, N },
94 { GLX(OML_sync_control), VER(0,0), Y, N, N, Y },
95 { GLX(SGI_cushion), VER(0,0), N, N, N, N },
96 { GLX(SGI_make_current_read), VER(1,3), Y, N, N, N },
97 { GLX(SGI_swap_control), VER(0,0), Y, N, N, N },
98 { GLX(SGI_video_sync), VER(0,0), Y, N, N, Y },
99 { GLX(SGIS_blended_overlay), VER(0,0), N, N, N, N },
100 { GLX(SGIS_color_range), VER(0,0), N, N, N, N },
101 { GLX(SGIS_multisample), VER(0,0), Y, Y, N, N },
102 { GLX(SGIX_dm_buffer), VER(0,0), N, N, N, N },
103 { GLX(SGIX_fbconfig), VER(1,3), Y, N, N, N },
104 { GLX(SGIX_pbuffer), VER(1,3), Y, N, N, N },
105 { GLX(SGIX_swap_barrier), VER(0,0), N, N, N, N },
106 { GLX(SGIX_swap_group), VER(0,0), N, N, N, N },
107 { GLX(SGIX_video_resize), VER(0,0), N, N, N, N },
108 { GLX(SGIX_video_source), VER(0,0), N, N, N, N },
109 { GLX(SGIX_visual_select_group), VER(0,0), Y, Y, N, N },
110 { GLX(SUN_get_transparent_index), VER(0,0), N, N, N, N },
111 { NULL }
112 };
113
114 static const struct extension_info known_gl_extensions[] = {
115 { GL(ARB_depth_texture), VER(1,4), Y, N, N, N },
116 { GL(ARB_fragment_program), VER(0,0), N, N, N, N },
117 { GL(ARB_imaging), VER(0,0), Y, N, N, N },
118 { GL(ARB_multisample), VER(1,3), Y, N, N, N },
119 { GL(ARB_multitexture), VER(1,3), Y, N, N, N },
120 { GL(ARB_occlusion_query), VER(1,5), N, N, N, N },
121 { GL(ARB_point_parameters), VER(1,4), Y, N, N, N },
122 { GL(ARB_point_sprite), VER(0,0), Y, N, N, N },
123 { GL(ARB_shadow), VER(1,4), Y, N, N, N },
124 { GL(ARB_shadow_ambient), VER(0,0), Y, N, N, N },
125 { GL(ARB_texture_border_clamp), VER(1,3), Y, N, N, N },
126 { GL(ARB_texture_compression), VER(1,3), N, N, N, N },
127 { GL(ARB_texture_cube_map), VER(1,3), Y, N, N, N },
128 { GL(ARB_texture_env_add), VER(1,3), Y, N, N, N },
129 { GL(ARB_texture_env_combine), VER(1,3), Y, N, N, N },
130 { GL(ARB_texture_env_crossbar), VER(1,4), Y, N, N, N },
131 { GL(ARB_texture_env_dot3), VER(1,3), Y, N, N, N },
132 { GL(ARB_texture_mirrored_repeat), VER(1,4), Y, N, N, N },
133 { GL(ARB_texture_non_power_of_two), VER(1,5), Y, N, N, N },
134 { GL(ARB_transpose_matrix), VER(1,3), Y, N, Y, N },
135 { GL(ARB_vertex_buffer_object), VER(1,5), N, N, N, N },
136 { GL(ARB_window_pos), VER(1,4), Y, N, N, N },
137 { GL(EXT_abgr), VER(0,0), Y, N, N, N },
138 { GL(EXT_bgra), VER(1,2), Y, N, N, N },
139 { GL(EXT_blend_color), VER(1,4), Y, N, N, N },
140 { GL(EXT_blend_equation_separate), VER(0,0), N, N, N, N },
141 { GL(EXT_blend_func_separate), VER(1,4), Y, N, N, N },
142 { GL(EXT_blend_logic_op), VER(1,4), Y, N, N, N },
143 { GL(EXT_blend_minmax), VER(1,4), Y, N, N, N },
144 { GL(EXT_blend_subtract), VER(1,4), Y, N, N, N },
145 { GL(EXT_clip_volume_hint), VER(0,0), Y, N, N, N },
146 { GL(EXT_compiled_vertex_array), VER(0,0), N, N, N, N },
147 { GL(EXT_convolution), VER(0,0), N, N, N, N },
148 { GL(EXT_copy_texture), VER(1,1), Y, N, N, N },
149 { GL(EXT_cull_vertex), VER(0,0), N, N, N, N },
150 { GL(EXT_depth_bounds_test), VER(0,0), N, N, N, N },
151 { GL(EXT_draw_range_elements), VER(1,2), Y, N, Y, N },
152 { GL(EXT_fog_coord), VER(1,4), Y, N, N, N },
153 { GL(EXT_multi_draw_arrays), VER(1,4), Y, N, Y, N },
154 { GL(EXT_packed_pixels), VER(1,2), Y, N, N, N },
155 { GL(EXT_paletted_texture), VER(0,0), Y, N, N, N },
156 { GL(EXT_pixel_buffer_object), VER(0,0), N, N, N, N },
157 { GL(EXT_point_parameters), VER(1,4), Y, N, N, N },
158 { GL(EXT_polygon_offset), VER(1,1), Y, N, N, N },
159 { GL(EXT_rescale_normal), VER(1,2), Y, N, N, N },
160 { GL(EXT_secondary_color), VER(1,4), Y, N, N, N },
161 { GL(EXT_separate_specular_color), VER(1,2), Y, N, N, N },
162 { GL(EXT_shadow_funcs), VER(1,5), Y, N, N, N },
163 { GL(EXT_shared_texture_palette), VER(0,0), Y, N, N, N },
164 { GL(EXT_stencil_two_side), VER(0,0), Y, N, N, N },
165 { GL(EXT_stencil_wrap), VER(1,4), Y, N, N, N },
166 { GL(EXT_subtexture), VER(1,1), Y, N, N, N },
167 { GL(EXT_texture), VER(1,1), Y, N, N, N },
168 { GL(EXT_texture3D), VER(1,2), Y, N, N, N },
169 { GL(EXT_texture_compression_s3tc), VER(0,0), N, N, N, N },
170 { GL(EXT_texture_edge_clamp), VER(1,2), Y, N, N, N },
171 { GL(EXT_texture_env_add), VER(1,3), Y, N, N, N },
172 { GL(EXT_texture_env_combine), VER(1,3), Y, N, N, N },
173 { GL(EXT_texture_env_dot3), VER(0,0), Y, N, N, N },
174 { GL(EXT_texture_filter_anisotropic), VER(0,0), Y, N, N, N },
175 { GL(EXT_texture_lod), VER(1,2), Y, N, N, N },
176 { GL(EXT_texture_lod_bias), VER(1,4), Y, N, N, N },
177 { GL(EXT_texture_mirror_clamp), VER(0,0), Y, N, N, N },
178 { GL(EXT_texture_object), VER(1,1), Y, N, N, N },
179 { GL(EXT_texture_rectangle), VER(0,0), Y, N, N, N },
180 { GL(EXT_vertex_array), VER(0,0), Y, N, N, N },
181 { GL(3DFX_texture_compression_FXT1), VER(0,0), N, N, N, N },
182 { GL(APPLE_packed_pixels), VER(1,2), Y, N, N, N },
183 { GL(APPLE_ycbcr_422), VER(0,0), Y, N, N, N },
184 { GL(ATI_texture_env_combine3), VER(0,0), Y, N, N, N },
185 { GL(ATI_texture_float), VER(0,0), Y, N, N, N },
186 { GL(ATI_texture_mirror_once), VER(0,0), Y, N, N, N },
187 { GL(ATIX_texture_env_combine3), VER(0,0), Y, N, N, N },
188 { GL(HP_convolution_border_modes), VER(0,0), Y, N, N, N },
189
190 /* This is currently removed because there seem to be some problems with
191 * it and the software-only indirect rendering path. At this point, I'm
192 * not sure which side (client or server) has the problem. - idr
193 */
194 { GL(HP_occlusion_test), VER(0,0), N, N, N, N },
195
196 { GL(IBM_cull_vertex), VER(0,0), Y, N, N, N },
197 { GL(IBM_pixel_filter_hint), VER(0,0), Y, N, N, N },
198 { GL(IBM_rasterpos_clip), VER(0,0), Y, N, N, N },
199 { GL(IBM_texture_clamp_nodraw), VER(0,0), Y, N, N, N },
200 { GL(IBM_texture_mirrored_repeat), VER(0,0), Y, N, N, N },
201 { GL(INGR_blend_func_separate), VER(0,0), Y, N, N, N },
202 { GL(INGR_interlace_read), VER(0,0), Y, N, N, N },
203 { GL(MESA_pack_invert), VER(0,0), Y, N, N, N },
204 { GL(MESA_ycbcr_texture), VER(0,0), Y, N, N, N },
205 { GL(NV_blend_square), VER(1,4), Y, N, N, N },
206 { GL(NV_copy_depth_to_color), VER(0,0), Y, N, N, N },
207 { GL(NV_depth_clamp), VER(0,0), Y, N, N, N },
208 { GL(NV_fog_distance), VER(0,0), Y, N, N, N },
209 { GL(NV_light_max_exponent), VER(0,0), Y, N, N, N },
210 { GL(NV_multisample_filter_hint), VER(0,0), Y, N, N, N },
211 { GL(NV_point_sprite), VER(0,0), Y, N, N, N },
212 { GL(NV_texgen_reflection), VER(0,0), Y, N, N, N },
213 { GL(NV_texture_compression_vtc), VER(0,0), N, N, N, N },
214 { GL(NV_texture_env_combine4), VER(0,0), Y, N, N, N },
215 { GL(NV_texture_rectangle), VER(0,0), Y, N, N, N },
216 { GL(SGIS_generate_mipmap), VER(1,4), Y, N, N, N },
217 { GL(SGIS_multisample), VER(0,0), Y, N, N, N },
218 { GL(SGIS_texture_border_clamp), VER(1,3), Y, N, N, N },
219 { GL(SGIS_texture_edge_clamp), VER(1,2), Y, N, N, N },
220 { GL(SGIS_texture_lod), VER(1,2), Y, N, N, N },
221 { GL(SGIX_blend_alpha_minmax), VER(0,0), Y, N, N, N },
222 { GL(SGIX_clipmap), VER(0,0), Y, N, N, N },
223 { GL(SGIX_depth_texture), VER(0,0), Y, N, N, N },
224 { GL(SGIX_fog_offset), VER(0,0), Y, N, N, N },
225 { GL(SGIX_shadow), VER(0,0), Y, N, N, N },
226 { GL(SGIX_shadow_ambient), VER(0,0), Y, N, N, N },
227 { GL(SGIX_texture_coordinate_clamp), VER(0,0), Y, N, N, N },
228 { GL(SGIX_texture_lod_bias), VER(0,0), Y, N, N, N },
229 { GL(SGIX_texture_range), VER(0,0), Y, N, N, N },
230 { GL(SGIX_texture_scale_bias), VER(0,0), Y, N, N, N },
231 { GL(SGIX_vertex_preclip), VER(0,0), Y, N, N, N },
232 { GL(SGIX_vertex_preclip_hint), VER(0,0), Y, N, N, N },
233 { GL(SGIX_ycrcb), VER(0,0), Y, N, N, N },
234 { GL(SUN_convolution_border_modes), VER(0,0), Y, N, N, N },
235 { GL(SUN_multi_draw_arrays), VER(0,0), Y, N, Y, N },
236 { GL(SUN_slice_accum), VER(0,0), Y, N, N, N },
237 { NULL }
238 };
239
240
241 #define __GL_EXT_BYTES ((__NUM_GL_EXTS + 7) / 8)
242
243 /* global bit-fields of available extensions and their characteristics */
244 static unsigned char client_glx_support[8];
245 static unsigned char client_glx_only[8];
246 static unsigned char direct_glx_only[8];
247 static unsigned char client_gl_support[ __GL_EXT_BYTES ];
248 static unsigned char client_gl_only[ __GL_EXT_BYTES ];
249
250 /**
251 * Bits representing the set of extensions that are enabled by default in all
252 * direct rendering drivers.
253 */
254 static unsigned char direct_glx_support[8];
255
256 /**
257 * Highest core GL version that can be supported for indirect rendering.
258 */
259 static unsigned gl_major = 0;
260 static unsigned gl_minor = 0;
261
262 /* client extensions string */
263 static const char * __glXGLXClientExtensions = NULL;
264
265 static void __glXExtensionsCtr( void );
266 static void __glXExtensionsCtrScreen( __GLXscreenConfigs *psc );
267 static void __glXProcessServerString( const struct extension_info * ext,
268 const char * server_string, unsigned char * server_support );
269
270 /**
271 * Set the state of a GLX extension.
272 *
273 * \param name Name of the extension.
274 * \param name_len Length, in characters, of the extension name.
275 * \param state New state (either enabled or disabled) of the extension.
276 * \param supported Table in which the state of the extension is to be set.
277 */
278 static void
279 set_glx_extension( const struct extension_info * ext,
280 const char * name, unsigned name_len, GLboolean state,
281 unsigned char * supported )
282 {
283 unsigned i;
284
285
286 for ( i = 0 ; ext[i].name != NULL ; i++ ) {
287 if ( (name_len == ext[i].name_len)
288 && (strncmp( ext[i].name, name, name_len ) == 0) ) {
289 if ( state ) {
290 SET_BIT( supported, ext[i].bit );
291 }
292 else {
293 CLR_BIT( supported, ext[i].bit );
294 }
295
296 return;
297 }
298 }
299 }
300
301
302 #define NUL '\0'
303 #define SEPARATOR ' '
304
305 /**
306 * Convert the server's extension string to a bit-field.
307 *
308 * \param server_string GLX extension string from the server.
309 * \param server_support Bit-field of supported extensions.
310 */
311 static void
312 __glXProcessServerString( const struct extension_info * ext,
313 const char * server_string,
314 unsigned char * server_support )
315 {
316 unsigned base;
317 unsigned len;
318
319 (void) memset( server_support, 0, sizeof( server_support ) );
320
321 for ( base = 0 ; server_string[ base ] != NUL ; /* empty */ ) {
322 /* Determine the length of the next extension name.
323 */
324 for ( len = 0
325 ; (server_string[ base + len ] != SEPARATOR)
326 && (server_string[ base + len ] != NUL)
327 ; len++ ) {
328 /* empty */
329 }
330
331 /* Set the bit for the extension in the server_support table.
332 */
333 set_glx_extension( ext, & server_string[ base ], len, GL_TRUE,
334 server_support );
335
336
337 /* Advance to the next extension string. This means that we skip
338 * over the previous string and any trialing white-space.
339 */
340 for ( base += len ;
341 (server_string[ base ] == SEPARATOR)
342 && (server_string[ base ] != NUL)
343 ; base++ ) {
344 /* empty */
345 }
346 }
347 }
348
349
350 /**
351 * Enable a named GLX extension on a given screen.
352 * Drivers should not call this function directly. They should instead use
353 * \c glXGetProcAddress to obtain a pointer to the function.
354 *
355 * \param psc Pointer to GLX per-screen record.
356 * \param name Name of the extension to enable.
357 *
358 * \sa glXGetProcAddress
359 *
360 * \since Internal API version 20030813.
361 */
362 void
363 __glXScrEnableExtension( __GLXscreenConfigs *psc, const char * name )
364 {
365 __glXExtensionsCtr();
366 __glXExtensionsCtrScreen(psc);
367 set_glx_extension( known_glx_extensions, name, strlen( name ), GL_TRUE,
368 psc->direct_support );
369 }
370
371
372 /**
373 * Initialize global extension support tables.
374 */
375
376 static void
377 __glXExtensionsCtr( void )
378 {
379 static const char major_table[32] = { 1, 1, 1, 1, 1, 1, 2, };
380 static const char minor_table[32] = { 0, 1, 2, 3, 4, 5, 0, };
381 unsigned i;
382 static GLboolean ext_list_first_time = GL_TRUE;
383 unsigned full_support = ~0;
384
385
386 if ( ext_list_first_time ) {
387 ext_list_first_time = GL_FALSE;
388
389 (void) memset( client_glx_support, 0, sizeof( client_glx_support ) );
390 (void) memset( direct_glx_support, 0, sizeof( direct_glx_support ) );
391 (void) memset( client_glx_only, 0, sizeof( client_glx_only ) );
392 (void) memset( direct_glx_only, 0, sizeof( direct_glx_only ) );
393
394 (void) memset( client_gl_support, 0, sizeof( client_gl_support ) );
395 (void) memset( client_gl_only, 0, sizeof( client_gl_only ) );
396
397 for ( i = 0 ; known_glx_extensions[i].name != NULL ; i++ ) {
398 const unsigned bit = known_glx_extensions[i].bit;
399
400 if ( known_glx_extensions[i].client_support ) {
401 SET_BIT( client_glx_support, bit );
402 }
403
404 if ( known_glx_extensions[i].direct_support ) {
405 SET_BIT( direct_glx_support, bit );
406 }
407
408 if ( known_glx_extensions[i].client_only ) {
409 SET_BIT( client_glx_only, bit );
410 }
411
412 if ( known_glx_extensions[i].direct_only ) {
413 SET_BIT( direct_glx_only, bit );
414 }
415 }
416
417 for ( i = 0 ; known_gl_extensions[i].name != NULL ; i++ ) {
418 const unsigned bit = known_gl_extensions[i].bit;
419
420 if ( known_gl_extensions[i].client_support ) {
421 SET_BIT( client_gl_support, bit );
422 }
423 else if ( known_gl_extensions[i].version_major != 0 ) {
424 /* If an extension that is required for some core GL version is
425 * not supported, clear the bit for that core GL version as well.
426 */
427
428 unsigned ver_bit = (6 * (known_gl_extensions[i].version_major - 1))
429 + (known_gl_extensions[i].version_minor);
430
431 full_support &= ~(1U << ver_bit);
432 }
433
434 if ( known_gl_extensions[i].client_only ) {
435 SET_BIT( client_gl_only, bit );
436 }
437 }
438
439 /* Determine the lowest unsupported core GL version. The version before
440 * that is, therefore, the highest supported core GL version.
441 */
442 for ( i = 0 ; (full_support & (1 << i)) != 0 ; i++ )
443 /* empty */ ;
444
445 i--;
446 gl_major = major_table[i];
447 gl_minor = minor_table[i];
448 #if 0
449 fprintf( stderr, "[%s:%u] Maximum client library version: %u.%u\n",
450 __func__, __LINE__, gl_major, gl_minor );
451 #endif
452 }
453 }
454
455
456 /**
457 * Make sure that per-screen direct-support table is initialized.
458 *
459 * \param psc Pointer to GLX per-screen record.
460 */
461
462 static void
463 __glXExtensionsCtrScreen( __GLXscreenConfigs *psc )
464 {
465 if (psc->ext_list_first_time) {
466 psc->ext_list_first_time = GL_FALSE;
467 (void) memcpy( psc->direct_support, direct_glx_support,
468 sizeof( direct_glx_support ) );
469 }
470 }
471
472
473 /**
474 * Check if a certain extension is enabled on a given screen.
475 *
476 * \param psc Pointer to GLX per-screen record.
477 * \param bit Bit index in the direct-support table.
478 * \returns If the extension bit is enabled for the screen, \c GL_TRUE is
479 * returned. If the extension bit is not enabled or if \c psc is
480 * \c NULL, then \c GL_FALSE is returned.
481 */
482 GLboolean
483 __glXExtensionBitIsEnabled( __GLXscreenConfigs *psc, unsigned bit )
484 {
485 GLboolean enabled = GL_FALSE;
486
487 if ( psc != NULL ) {
488 __glXExtensionsCtr();
489 __glXExtensionsCtrScreen( psc );
490 enabled = EXT_ENABLED( bit, psc->direct_support );
491 }
492
493 return enabled;
494 }
495
496
497 /**
498 * Convert a bit-field to a string of supported extensions.
499 */
500 static char *
501 __glXGetStringFromTable( const struct extension_info * ext,
502 const unsigned char * supported )
503 {
504 unsigned i;
505 unsigned ext_str_len;
506 char * ext_str;
507 char * point;
508
509
510 ext_str_len = 0;
511 for ( i = 0 ; ext[i].name != NULL ; i++ ) {
512 if ( EXT_ENABLED( ext[i].bit, supported ) ) {
513 ext_str_len += ext[i].name_len + 1;
514 }
515 }
516
517 ext_str = Xmalloc( ext_str_len + 1 );
518 if ( ext_str != NULL ) {
519 point = ext_str;
520
521 for ( i = 0 ; ext[i].name != NULL ; i++ ) {
522 if ( EXT_ENABLED( ext[i].bit, supported ) ) {
523 (void) memcpy( point, ext[i].name, ext[i].name_len );
524 point += ext[i].name_len;
525
526 *point = ' ';
527 point++;
528 }
529 }
530
531 *point = '\0';
532 }
533
534 return ext_str;
535 }
536
537
538 /**
539 * Get the string of client library supported extensions.
540 */
541 const char *
542 __glXGetClientExtensions( void )
543 {
544 if ( __glXGLXClientExtensions == NULL ) {
545 __glXExtensionsCtr();
546 __glXGLXClientExtensions = __glXGetStringFromTable( known_glx_extensions,
547 client_glx_support );
548 }
549
550 return __glXGLXClientExtensions;
551 }
552
553
554 /**
555 * Calculate the list of application usable extensions. The resulting
556 * string is stored in \c psc->effectiveGLXexts.
557 *
558 * \param psc Pointer to GLX per-screen record.
559 * \param display_is_direct_capable True if the display is capable of
560 * direct rendering.
561 * \param minor_version GLX minor version from the server.
562 */
563
564 void
565 __glXCalculateUsableExtensions( __GLXscreenConfigs *psc,
566 GLboolean display_is_direct_capable,
567 int minor_version )
568 {
569 unsigned char server_support[8];
570 unsigned char usable[8];
571 unsigned i;
572
573 __glXExtensionsCtr();
574 __glXExtensionsCtrScreen( psc );
575 __glXProcessServerString( known_glx_extensions,
576 psc->serverGLXexts, server_support );
577
578
579 /* This is a hack. Some servers support GLX 1.3 but don't export
580 * all of the extensions implied by GLX 1.3. If the server claims
581 * support for GLX 1.3, enable support for the extensions that can be
582 * "emulated" as well.
583 */
584
585 if ( minor_version >= 3 ) {
586 SET_BIT( server_support, EXT_visual_info_bit );
587 SET_BIT( server_support, EXT_visual_rating_bit );
588 SET_BIT( server_support, SGI_make_current_read_bit );
589 SET_BIT( server_support, SGIX_fbconfig_bit );
590 SET_BIT( server_support, SGIX_pbuffer_bit );
591
592 /* This one is a little iffy. GLX 1.3 doesn't incorporate all of this
593 * extension. However, the only part that is not strictly client-side
594 * is shared. That's the glXQueryContext / glXQueryContextInfoEXT
595 * function.
596 */
597
598 SET_BIT( server_support, EXT_import_context_bit );
599 }
600
601
602 /* An extension is supported if the client-side (i.e., libGL) supports
603 * it and the "server" supports it. In this case that means that either
604 * the true server supports it or it is only for direct-rendering and
605 * the direct rendering driver supports it.
606 *
607 * If the display is not capable of direct rendering, then the extension
608 * is enabled if and only if the client-side library and the server
609 * support it.
610 */
611
612 if ( display_is_direct_capable ) {
613 for ( i = 0 ; i < 8 ; i++ ) {
614 usable[i] = (client_glx_support[i] & client_glx_only[i])
615 | (client_glx_support[i] & psc->direct_support[i] & server_support[i])
616 | (client_glx_support[i] & psc->direct_support[i] & direct_glx_only[i]);
617 }
618 }
619 else {
620 for ( i = 0 ; i < 8 ; i++ ) {
621 usable[i] = (client_glx_support[i] & client_glx_only[i])
622 | (client_glx_support[i] & server_support[i]);
623 }
624 }
625
626 psc->effectiveGLXexts = __glXGetStringFromTable( known_glx_extensions,
627 usable );
628 }
629
630
631 /**
632 * Calculate the list of application usable extensions. The resulting
633 * string is stored in \c gc->extensions.
634 *
635 * \param gc Pointer to GLX context.
636 * \param server_string Extension string from the server.
637 * \param major_version GL major version from the server.
638 * \param minor_version GL minor version from the server.
639 */
640
641 void
642 __glXCalculateUsableGLExtensions( __GLXcontext * gc,
643 const char * server_string,
644 int major_version, int minor_version )
645 {
646 unsigned char server_support[ __GL_EXT_BYTES ];
647 unsigned char usable[ __GL_EXT_BYTES ];
648 unsigned i;
649
650
651 __glXExtensionsCtr();
652
653 (void) memset( server_support, 0, sizeof( server_support ) );
654 __glXProcessServerString( known_gl_extensions, server_string,
655 server_support );
656
657
658 /* Handle lazy servers that don't export all the extensions strings that
659 * are part of the GL core version that they support.
660 */
661
662 for ( i = 0 ; i < __GL_EXT_BYTES ; i++ ) {
663 if ( (known_gl_extensions[i].version_major != 0)
664 && ((major_version > known_gl_extensions[i].version_major)
665 || ((major_version == known_gl_extensions[i].version_major)
666 && (minor_version >= known_gl_extensions[i].version_minor))) ) {
667 SET_BIT( server_support, known_gl_extensions[i].bit );
668 }
669 }
670
671
672 /* An extension is supported if the client-side (i.e., libGL) supports
673 * it and the server supports it or the client-side library supports it
674 * and it only needs client-side support.
675 */
676
677 for ( i = 0 ; i < __GL_EXT_BYTES ; i++ ) {
678 usable[i] = (client_gl_support[i] & client_gl_only[i])
679 | (client_gl_support[i] & server_support[i]);
680 }
681
682 gc->extensions = (unsigned char *)
683 __glXGetStringFromTable( known_gl_extensions, usable );
684 }
685
686
687 /**
688 * Calculates the maximum core GL version that can be supported for indirect
689 * rendering.
690 */
691 void
692 __glXGetGLVersion( int * major_version, int * minor_version )
693 {
694 __glXExtensionsCtr();
695 *major_version = gl_major;
696 *minor_version = gl_minor;
697 }
698
699
700 /**
701 * Get a string representing the set of extensions supported by the client
702 * library. This is currently only used to send the list of extensions
703 * supported by the client to the server.
704 */
705 char *
706 __glXGetClientGLExtensionString( void )
707 {
708 __glXExtensionsCtr();
709 return __glXGetStringFromTable( known_gl_extensions, client_gl_support );
710 }