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