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 <X11/extensions/extutil.h>
33 #include <X11/extensions/Xext.h>
34 #include <string.h>
35 #include "glxextensions.h"
36
37 #include "util/driconf.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 Y 1
46 #define N 0
47 #define EXT_ENABLED(bit,supported) (IS_SET( supported, bit ))
48
49
50 struct extension_info
51 {
52 const char *const name;
53 unsigned name_len;
54
55 unsigned char bit;
56
57 /**
58 * The direct-renderer (e.g., i965_dri.so) supports this extension.
59 *
60 * For cases where all of the infrastructure to support the extension is a
61 * required part of the loader/driver interface, this can default to Y.
62 * For most cases, extended functionality, usually in the form of DRI2
63 * extensions, is necessary to support the extension. The loader will set
64 * the flag true if all the requirements are met.
65 *
66 * If the display is capable of direct rendering, ::direct_support is
67 * required for the extension to be enabled.
68 */
69 unsigned char direct_support;
70
71 /**
72 * The extension only functions with direct-rendering contexts
73 *
74 * The extension has no GLX protocol, and, therefore, no explicit
75 * dependency on the server. The functionality is contained entirely in
76 * the client library and the direct renderer. A few of the swap-related
77 * extensions are intended to behave this way.
78 */
79 unsigned char direct_only;
80 };
81
82 /* *INDENT-OFF* */
83 static const struct extension_info known_glx_extensions[] = {
84 { GLX(ARB_context_flush_control), N, N },
85 { GLX(ARB_create_context), N, N },
86 { GLX(ARB_create_context_no_error), N, N },
87 { GLX(ARB_create_context_profile), N, N },
88 { GLX(ARB_create_context_robustness), N, N },
89 { GLX(ARB_fbconfig_float), Y, N },
90 { GLX(ARB_framebuffer_sRGB), Y, N },
91 { GLX(ARB_get_proc_address), N, N },
92 { GLX(ARB_multisample), Y, N },
93 { GLX(EXT_buffer_age), N, Y },
94 { GLX(EXT_create_context_es2_profile), N, N },
95 { GLX(EXT_create_context_es_profile), N, N },
96 { GLX(EXT_fbconfig_packed_float), Y, N },
97 { GLX(EXT_framebuffer_sRGB), Y, N },
98 { GLX(EXT_import_context), Y, N },
99 { GLX(EXT_no_config_context), N, N },
100 { GLX(EXT_swap_control), N, Y },
101 { GLX(EXT_swap_control_tear), N, Y },
102 { GLX(EXT_texture_from_pixmap), N, N },
103 { GLX(EXT_visual_info), Y, N },
104 { GLX(EXT_visual_rating), Y, N },
105 { GLX(ATI_pixel_format_float), N, N },
106 { GLX(INTEL_swap_event), N, N },
107 { GLX(MESA_copy_sub_buffer), N, N },
108 { GLX(MESA_query_renderer), N, Y },
109 { GLX(MESA_swap_control), N, Y },
110 { GLX(NV_float_buffer), N, N },
111 { GLX(OML_swap_method), Y, N },
112 { GLX(OML_sync_control), N, Y },
113 { GLX(SGIS_multisample), Y, N },
114 { GLX(SGIX_fbconfig), Y, N },
115 { GLX(SGIX_pbuffer), Y, N },
116 { GLX(SGIX_visual_select_group), Y, N },
117 { GLX(SGI_make_current_read), N, N },
118 { GLX(SGI_swap_control), N, N },
119 { GLX(SGI_video_sync), N, Y },
120 { NULL }
121 };
122
123 static const struct extension_info known_gl_extensions[] = {
124 { GL(ARB_depth_texture), N, N },
125 { GL(ARB_draw_buffers), N, N },
126 { GL(ARB_fragment_program), N, N },
127 { GL(ARB_fragment_program_shadow), N, N },
128 { GL(ARB_framebuffer_object), N, N },
129 { GL(ARB_imaging), N, N },
130 { GL(ARB_multisample), N, N },
131 { GL(ARB_multitexture), N, N },
132 { GL(ARB_occlusion_query), N, N },
133 { GL(ARB_point_parameters), N, N },
134 { GL(ARB_point_sprite), N, N },
135 { GL(ARB_shadow), N, N },
136 { GL(ARB_shadow_ambient), N, N },
137 { GL(ARB_texture_border_clamp), N, N },
138 { GL(ARB_texture_compression), N, N },
139 { GL(ARB_texture_cube_map), N, N },
140 { GL(ARB_texture_env_add), N, N },
141 { GL(ARB_texture_env_combine), N, N },
142 { GL(ARB_texture_env_crossbar), N, N },
143 { GL(ARB_texture_env_dot3), N, N },
144 { GL(ARB_texture_filter_anisotropic), N, N },
145 { GL(ARB_texture_mirrored_repeat), N, N },
146 { GL(ARB_texture_non_power_of_two), N, N },
147 { GL(ARB_texture_rectangle), N, N },
148 { GL(ARB_texture_rg), N, N },
149 { GL(ARB_transpose_matrix), N, N },
150 { GL(ARB_vertex_program), N, N },
151 { GL(ARB_window_pos), N, N },
152 { GL(EXT_abgr), N, N },
153 { GL(EXT_bgra), N, N },
154 { GL(EXT_blend_color), N, N },
155 { GL(EXT_blend_equation_separate), N, N },
156 { GL(EXT_blend_func_separate), N, N },
157 { GL(EXT_blend_logic_op), N, N },
158 { GL(EXT_blend_minmax), N, N },
159 { GL(EXT_blend_subtract), N, N },
160 { GL(EXT_clip_volume_hint), N, N },
161 { GL(EXT_copy_texture), N, N },
162 { GL(EXT_draw_range_elements), N, N },
163 { GL(EXT_fog_coord), N, N },
164 { GL(EXT_framebuffer_blit), N, N },
165 { GL(EXT_framebuffer_multisample), N, N },
166 { GL(EXT_framebuffer_object), N, N },
167 { GL(EXT_framebuffer_sRGB), N, N },
168 { GL(EXT_multi_draw_arrays), N, N },
169 { GL(EXT_packed_depth_stencil), N, N },
170 { GL(EXT_packed_pixels), N, N },
171 { GL(EXT_paletted_texture), N, N },
172 { GL(EXT_point_parameters), N, N },
173 { GL(EXT_polygon_offset), N, N },
174 { GL(EXT_rescale_normal), N, N },
175 { GL(EXT_secondary_color), N, N },
176 { GL(EXT_separate_specular_color), N, N },
177 { GL(EXT_shadow_funcs), N, N },
178 { GL(EXT_shared_texture_palette), N, N },
179 { GL(EXT_stencil_two_side), N, N },
180 { GL(EXT_stencil_wrap), N, N },
181 { GL(EXT_subtexture), N, N },
182 { GL(EXT_texture), N, N },
183 { GL(EXT_texture3D), N, N },
184 { GL(EXT_texture_compression_dxt1), N, N },
185 { GL(EXT_texture_compression_s3tc), N, N },
186 { GL(EXT_texture_edge_clamp), N, N },
187 { GL(EXT_texture_env_add), N, N },
188 { GL(EXT_texture_env_combine), N, N },
189 { GL(EXT_texture_env_dot3), N, N },
190 { GL(EXT_texture_filter_anisotropic), N, N },
191 { GL(EXT_texture_integer), N, N },
192 { GL(EXT_texture_lod), N, N },
193 { GL(EXT_texture_lod_bias), N, N },
194 { GL(EXT_texture_mirror_clamp), N, N },
195 { GL(EXT_texture_object), N, N },
196 { GL(EXT_texture_rectangle), N, N },
197 { GL(EXT_vertex_array), N, N },
198 { GL(3DFX_texture_compression_FXT1), N, N },
199 { GL(APPLE_packed_pixels), N, N },
200 { GL(APPLE_ycbcr_422), N, N },
201 { GL(ATI_draw_buffers), N, N },
202 { GL(ATI_text_fragment_shader), N, N },
203 { GL(ATI_texture_env_combine3), N, N },
204 { GL(ATI_texture_float), N, N },
205 { GL(ATI_texture_mirror_once), N, N },
206 { GL(ATIX_texture_env_combine3), N, N },
207 { GL(HP_convolution_border_modes), N, N },
208 { GL(HP_occlusion_test), N, N },
209 { GL(IBM_cull_vertex), N, N },
210 { GL(IBM_pixel_filter_hint), N, N },
211 { GL(IBM_rasterpos_clip), N, N },
212 { GL(IBM_texture_clamp_nodraw), N, N },
213 { GL(IBM_texture_mirrored_repeat), N, N },
214 { GL(INGR_blend_func_separate), N, N },
215 { GL(INGR_interlace_read), N, N },
216 { GL(MESA_pack_invert), N, N },
217 { GL(MESA_ycbcr_texture), N, N },
218 { GL(NV_blend_square), N, N },
219 { GL(NV_copy_depth_to_color), N, N },
220 { GL(NV_depth_clamp), N, N },
221 { GL(NV_fog_distance), N, N },
222 { GL(NV_fragment_program), N, N },
223 { GL(NV_fragment_program_option), N, N },
224 { GL(NV_fragment_program2), N, N },
225 { GL(NV_light_max_exponent), N, N },
226 { GL(NV_multisample_filter_hint), N, N },
227 { GL(NV_packed_depth_stencil), N, N },
228 { GL(NV_point_sprite), N, N },
229 { GL(NV_texgen_reflection), N, N },
230 { GL(NV_texture_compression_vtc), N, N },
231 { GL(NV_texture_env_combine4), N, N },
232 { GL(NV_texture_rectangle), N, N },
233 { GL(NV_vertex_program), N, N },
234 { GL(NV_vertex_program1_1), N, N },
235 { GL(NV_vertex_program2), N, N },
236 { GL(NV_vertex_program2_option), N, N },
237 { GL(NV_vertex_program3), N, N },
238 { GL(OES_read_format), N, N },
239 { GL(OES_compressed_paletted_texture), N, N },
240 { GL(SGI_color_matrix), N, N },
241 { GL(SGI_color_table), N, N },
242 { GL(SGI_texture_color_table), N, N },
243 { GL(SGIS_generate_mipmap), N, N },
244 { GL(SGIS_multisample), N, N },
245 { GL(SGIS_texture_border_clamp), N, N },
246 { GL(SGIS_texture_edge_clamp), N, N },
247 { GL(SGIS_texture_lod), N, N },
248 { GL(SGIX_blend_alpha_minmax), N, N },
249 { GL(SGIX_clipmap), N, N },
250 { GL(SGIX_depth_texture), N, N },
251 { GL(SGIX_fog_offset), N, N },
252 { GL(SGIX_shadow), N, N },
253 { GL(SGIX_shadow_ambient), N, N },
254 { GL(SGIX_texture_coordinate_clamp), N, N },
255 { GL(SGIX_texture_lod_bias), N, N },
256 { GL(SGIX_texture_range), N, N },
257 { GL(SGIX_texture_scale_bias), N, N },
258 { GL(SGIX_vertex_preclip), N, N },
259 { GL(SGIX_vertex_preclip_hint), N, N },
260 { GL(SGIX_ycrcb), N, N },
261 { GL(SUN_convolution_border_modes), N, N },
262 { GL(SUN_multi_draw_arrays), N, N },
263 { GL(SUN_slice_accum), N, N },
264 { NULL }
265 };
266 /* *INDENT-ON* */
267
268
269 /* global bit-fields of available extensions and their characteristics */
270 static unsigned char client_glx_only[__GLX_EXT_BYTES];
271 static unsigned char direct_glx_only[__GLX_EXT_BYTES];
272
273 /**
274 * Bits representing the set of extensions that are enabled by default in all
275 * direct rendering drivers.
276 */
277 static unsigned char direct_glx_support[__GLX_EXT_BYTES];
278
279 /* client extensions string */
280 static const char *__glXGLXClientExtensions = NULL;
281
282 static void __glXExtensionsCtr(void);
283 static void __glXExtensionsCtrScreen(struct glx_screen * psc);
284 static void __glXProcessServerString(const struct extension_info *ext,
285 const char *server_string,
286 unsigned char *server_support);
287
288 /**
289 * Find an extension in the list based on its name.
290 *
291 * \param ext List of extensions where to search.
292 * \param name Name of the extension.
293 * \param name_len Length, in characters, of the extension name.
294 */
295 static const struct extension_info *
find_extension(const struct extension_info * ext,const char * name,unsigned name_len)296 find_extension(const struct extension_info *ext, const char *name,
297 unsigned name_len)
298 {
299 unsigned i;
300
301 for (i = 0; ext[i].name != NULL; i++) {
302 if ((name_len == ext[i].name_len)
303 && (strncmp(ext[i].name, name, name_len) == 0)) {
304 return &ext[i];
305 }
306 }
307
308 return NULL;
309 }
310
311 /**
312 * Set the state of a GLX extension.
313 *
314 * \param name Name of the extension.
315 * \param name_len Length, in characters, of the extension name.
316 * \param state New state (either enabled or disabled) of the extension.
317 * \param supported Table in which the state of the extension is to be set.
318 */
319 static void
set_glx_extension(const struct extension_info * ext_list,const char * name,unsigned name_len,GLboolean state,unsigned char * supported)320 set_glx_extension(const struct extension_info *ext_list,
321 const char *name, unsigned name_len, GLboolean state,
322 unsigned char *supported)
323 {
324 const struct extension_info *ext = find_extension(ext_list, name, name_len);
325 if (!ext)
326 return;
327
328 if (state) {
329 SET_BIT(supported, ext->bit);
330 } else {
331 CLR_BIT(supported, ext->bit);
332 }
333 }
334
335
336 #define NUL '\0'
337 #define SEPARATOR ' '
338
339 /**
340 * Convert the server's extension string to a bit-field.
341 *
342 * \param server_string GLX extension string from the server.
343 * \param server_support Bit-field of supported extensions.
344 *
345 * \note
346 * This function is used to process both GLX and GL extension strings. The
347 * bit-fields used to track each of these have different sizes. Therefore,
348 * the data pointed by \c server_support must be preinitialized to zero.
349 */
350 static void
__glXProcessServerString(const struct extension_info * ext,const char * server_string,unsigned char * server_support)351 __glXProcessServerString(const struct extension_info *ext,
352 const char *server_string,
353 unsigned char *server_support)
354 {
355 unsigned base;
356 unsigned len;
357
358 for (base = 0; server_string[base] != NUL; /* empty */ ) {
359 /* Determine the length of the next extension name.
360 */
361 for (len = 0; (server_string[base + len] != SEPARATOR)
362 && (server_string[base + len] != NUL); len++) {
363 /* empty */
364 }
365
366 /* Set the bit for the extension in the server_support table.
367 */
368 set_glx_extension(ext, &server_string[base], len, GL_TRUE,
369 server_support);
370
371
372 /* Advance to the next extension string. This means that we skip
373 * over the previous string and any trialing white-space.
374 */
375 for (base += len; (server_string[base] == SEPARATOR)
376 && (server_string[base] != NUL); base++) {
377 /* empty */
378 }
379 }
380 }
381
382 void
__glXEnableDirectExtension(struct glx_screen * psc,const char * name)383 __glXEnableDirectExtension(struct glx_screen * psc, const char *name)
384 {
385 __glXExtensionsCtr();
386 __glXExtensionsCtrScreen(psc);
387
388 set_glx_extension(known_glx_extensions,
389 name, strlen(name), GL_TRUE, psc->direct_support);
390 }
391
392 static void
__ParseExtensionOverride(struct glx_screen * psc,const struct extension_info * ext_list,unsigned char * force_enable,unsigned char * force_disable,const char * override)393 __ParseExtensionOverride(struct glx_screen *psc,
394 const struct extension_info *ext_list,
395 unsigned char *force_enable,
396 unsigned char *force_disable,
397 const char *override)
398 {
399 const struct extension_info *ext;
400 char *env, *field;
401
402 if (override == NULL)
403 return;
404
405 /* Copy env_const because strtok() is destructive. */
406 env = strdup(override);
407 if (env == NULL)
408 return;
409
410 for (field = strtok(env, " "); field!= NULL; field = strtok(NULL, " ")) {
411 GLboolean enable;
412
413 switch (field[0]) {
414 case '+':
415 enable = GL_TRUE;
416 ++field;
417 break;
418 case '-':
419 enable = GL_FALSE;
420 ++field;
421 break;
422 default:
423 enable = GL_TRUE;
424 break;
425 }
426
427 ext = find_extension(ext_list, field, strlen(field));
428 if (ext) {
429 if (enable)
430 SET_BIT(force_enable, ext->bit);
431 else
432 SET_BIT(force_disable, ext->bit);
433 } else {
434 fprintf(stderr, "WARNING: Trying to %s the unknown extension '%s'\n",
435 enable ? "enable" : "disable", field);
436 }
437 }
438
439 free(env);
440 }
441
442 /**
443 * \brief Parse the list of GLX extensions that the user wants to
444 * force-enable/disable by using \c override, and write the results to the
445 * screen's context.
446 *
447 * \param psc Pointer to GLX per-screen record.
448 * \param override A space-separated list of extensions to enable or disable.
449 * The list is processed thus:
450 * - Enable recognized extension names that are prefixed with '+'.
451 * - Disable recognized extension names that are prefixed with '-'.
452 * - Enable recognized extension names that are not prefixed.
453 */
454 void
__glXParseExtensionOverride(struct glx_screen * psc,const char * override)455 __glXParseExtensionOverride(struct glx_screen *psc, const char *override)
456 {
457 __ParseExtensionOverride(psc, known_glx_extensions, psc->glx_force_enabled,
458 psc->glx_force_disabled, override);
459 }
460
461 /**
462 * \brief Parse the list of GL extensions that the user wants to
463 * force-enable/disable by using \c override, and write the results to the
464 * screen's context.
465 *
466 * \param psc Pointer to GLX per-screen record.
467 * \param override A space-separated list of extensions to enable or disable.
468 * The list is processed thus:
469 * - Enable recognized extension names that are prefixed with '+'.
470 * - Disable recognized extension names that are prefixed with '-'.
471 * - Enable recognized extension names that are not prefixed.
472 */
473 void
__IndirectGlParseExtensionOverride(struct glx_screen * psc,const char * override)474 __IndirectGlParseExtensionOverride(struct glx_screen *psc, const char *override)
475 {
476 __ParseExtensionOverride(psc, known_gl_extensions, psc->gl_force_enabled,
477 psc->gl_force_disabled, override);
478 }
479
480
481 /**
482 * Initialize global extension support tables.
483 */
484
485 static void
__glXExtensionsCtr(void)486 __glXExtensionsCtr(void)
487 {
488 unsigned i;
489 static GLboolean ext_list_first_time = GL_TRUE;
490
491
492 if (ext_list_first_time) {
493 ext_list_first_time = GL_FALSE;
494
495 (void) memset(direct_glx_support, 0, sizeof(direct_glx_support));
496 (void) memset(client_glx_only, 0, sizeof(client_glx_only));
497 (void) memset(direct_glx_only, 0, sizeof(direct_glx_only));
498
499 SET_BIT(client_glx_only, ARB_get_proc_address_bit);
500 for (i = 0; known_glx_extensions[i].name != NULL; i++) {
501 const unsigned bit = known_glx_extensions[i].bit;
502
503 if (known_glx_extensions[i].direct_support) {
504 SET_BIT(direct_glx_support, bit);
505 }
506
507 if (known_glx_extensions[i].direct_only) {
508 SET_BIT(direct_glx_only, bit);
509 }
510 }
511 }
512 }
513
514
515 /**
516 * Make sure that per-screen direct-support table is initialized.
517 *
518 * \param psc Pointer to GLX per-screen record.
519 */
520
521 static void
__glXExtensionsCtrScreen(struct glx_screen * psc)522 __glXExtensionsCtrScreen(struct glx_screen * psc)
523 {
524 if (psc->ext_list_first_time) {
525 psc->ext_list_first_time = GL_FALSE;
526 (void) memcpy(psc->direct_support, direct_glx_support,
527 sizeof(direct_glx_support));
528 (void) memset(psc->glx_force_enabled, 0,
529 sizeof(psc->glx_force_enabled));
530 (void) memset(psc->glx_force_disabled, 0,
531 sizeof(psc->glx_force_disabled));
532 (void) memset(psc->gl_force_enabled, 0,
533 sizeof(psc->gl_force_enabled));
534 (void) memset(psc->gl_force_disabled, 0,
535 sizeof(psc->gl_force_disabled));
536 }
537 }
538
539
540 /**
541 * Check if a certain extension is enabled on a given screen.
542 *
543 * \param psc Pointer to GLX per-screen record.
544 * \param bit Bit index in the direct-support table.
545 * \returns If the extension bit is enabled for the screen, \c GL_TRUE is
546 * returned. If the extension bit is not enabled or if \c psc is
547 * \c NULL, then \c GL_FALSE is returned.
548 */
549 GLboolean
__glXExtensionBitIsEnabled(struct glx_screen * psc,unsigned bit)550 __glXExtensionBitIsEnabled(struct glx_screen * psc, unsigned bit)
551 {
552 GLboolean enabled = GL_FALSE;
553
554 if (psc != NULL) {
555 __glXExtensionsCtr();
556 __glXExtensionsCtrScreen(psc);
557 enabled = EXT_ENABLED(bit, psc->direct_support);
558 }
559
560 return enabled;
561 }
562
563
564 /**
565 * Check if a certain extension is enabled in a given context.
566 *
567 */
568 GLboolean
__glExtensionBitIsEnabled(struct glx_context * gc,unsigned bit)569 __glExtensionBitIsEnabled(struct glx_context *gc, unsigned bit)
570 {
571 GLboolean enabled = GL_FALSE;
572
573 if (gc != NULL) {
574 enabled = EXT_ENABLED(bit, gc->gl_extension_bits);
575 }
576
577 return enabled;
578 }
579
580
581
582 /**
583 * Convert a bit-field to a string of supported extensions.
584 */
585 static char *
__glXGetStringFromTable(const struct extension_info * ext,const unsigned char * filter)586 __glXGetStringFromTable(const struct extension_info *ext,
587 const unsigned char *filter)
588 {
589 unsigned i;
590 unsigned ext_str_len;
591 char *ext_str;
592 char *point;
593
594
595 ext_str_len = 0;
596 for (i = 0; ext[i].name != NULL; i++) {
597 if (!filter || EXT_ENABLED(ext[i].bit, filter)) {
598 ext_str_len += ext[i].name_len + 1;
599 }
600 }
601
602 ext_str = malloc(ext_str_len + 1);
603 if (ext_str != NULL) {
604 point = ext_str;
605
606 for (i = 0; ext[i].name != NULL; i++) {
607 if (!filter || EXT_ENABLED(ext[i].bit, filter)) {
608 (void) memcpy(point, ext[i].name, ext[i].name_len);
609 point += ext[i].name_len;
610
611 *point = ' ';
612 point++;
613 }
614 }
615
616 *point = '\0';
617 }
618
619 return ext_str;
620 }
621
622
623 /**
624 * Get the string of client library supported extensions.
625 */
626 const char *
__glXGetClientExtensions(Display * dpy)627 __glXGetClientExtensions(Display *dpy)
628 {
629 if (__glXGLXClientExtensions == NULL) {
630 __glXExtensionsCtr();
631 __glXGLXClientExtensions = __glXGetStringFromTable(known_glx_extensions,
632 NULL);
633 }
634
635 return __glXGLXClientExtensions;
636 }
637
638
639 /**
640 * Calculate the list of application usable extensions. The resulting
641 * string is stored in \c psc->effectiveGLXexts.
642 *
643 * \param psc Pointer to GLX per-screen record.
644 * \param display_is_direct_capable True if the display is capable of
645 * direct rendering.
646 */
647
648 void
__glXCalculateUsableExtensions(struct glx_screen * psc,GLboolean display_is_direct_capable)649 __glXCalculateUsableExtensions(struct glx_screen * psc,
650 GLboolean display_is_direct_capable)
651 {
652 unsigned char server_support[__GLX_EXT_BYTES];
653 unsigned char usable[__GLX_EXT_BYTES];
654 unsigned i;
655
656 __glXExtensionsCtr();
657 __glXExtensionsCtrScreen(psc);
658
659 (void) memset(server_support, 0, sizeof(server_support));
660 __glXProcessServerString(known_glx_extensions,
661 psc->serverGLXexts, server_support);
662
663
664 /* An extension is supported if the client-side (i.e., libGL) supports
665 * it and the "server" supports it. In this case that means that either
666 * the true server supports it or it is only for direct-rendering and
667 * the direct rendering driver supports it.
668 *
669 * If the display is not capable of direct rendering, then the extension
670 * is enabled if and only if the client-side library and the server
671 * support it.
672 */
673
674 if (display_is_direct_capable) {
675 for (i = 0; i < __GLX_EXT_BYTES; i++) {
676 /* Enable extensions that the client supports that only have a client-side
677 * component.
678 */
679 unsigned char u = client_glx_only[i];
680
681 /* Enable extensions that are supported for direct rendering, and either
682 * are supported by the server or only have a direct-rendering component.
683 */
684 u |= psc->direct_support[i] & (server_support[i] | direct_glx_only[i]);
685
686 /* Finally, apply driconf options to force some extension bits either
687 * enabled or disabled.
688 */
689 u |= psc->glx_force_enabled[i];
690 u &= ~psc->glx_force_disabled[i];
691
692 usable[i] = u;
693 }
694 }
695 else {
696 for (i = 0; i < __GLX_EXT_BYTES; i++) {
697 /* Enable extensions that the client supports that only have a
698 * client-side component.
699 */
700 unsigned char u = client_glx_only[i];
701
702 /* Enable extensions that the client and server both support */
703 u |= server_support[i];
704
705 /* Finally, apply driconf options to force some extension bits either
706 * enabled or disabled.
707 */
708 u |= psc->glx_force_enabled[i];
709 u &= ~psc->glx_force_disabled[i];
710
711 usable[i] = u;
712 }
713 }
714
715 psc->effectiveGLXexts = __glXGetStringFromTable(known_glx_extensions,
716 usable);
717 }
718
719 /**
720 * Calculate the list of application usable extensions. The resulting
721 * string is stored in \c gc->extensions.
722 *
723 * \param gc Pointer to GLX context.
724 * \param server_string Extension string from the server.
725 */
726
727 void
__glXCalculateUsableGLExtensions(struct glx_context * gc,const char * server_string)728 __glXCalculateUsableGLExtensions(struct glx_context * gc,
729 const char *server_string)
730 {
731 struct glx_screen *psc = gc->psc;
732 unsigned char server_support[__GL_EXT_BYTES];
733 unsigned char usable[__GL_EXT_BYTES];
734 unsigned i;
735
736 (void) memset(server_support, 0, sizeof(server_support));
737 __glXProcessServerString(known_gl_extensions, server_string,
738 server_support);
739
740 /* These extensions are wholly inside the client-side indirect code */
741 (void) memset(usable, 0, sizeof(usable));
742 SET_BIT(usable, GL_ARB_transpose_matrix_bit);
743 SET_BIT(usable, GL_EXT_draw_range_elements_bit);
744 SET_BIT(usable, GL_EXT_multi_draw_arrays_bit);
745 SET_BIT(usable, GL_SUN_multi_draw_arrays_bit);
746
747 for (i = 0; i < __GL_EXT_BYTES; i++) {
748 /* Usable if the server supports it, or if it's been forced on */
749 usable[i] = server_support[i] | psc->gl_force_enabled[i];
750
751 /* But not if it's been forced off */
752 usable[i] &= ~psc->gl_force_disabled[i];
753 }
754
755 gc->extensions = (unsigned char *)
756 __glXGetStringFromTable(known_gl_extensions, usable);
757 (void) memcpy(gc->gl_extension_bits, usable, sizeof(usable));
758 }
759
760 /**
761 * Get a string representing the set of extensions supported by the client
762 * library. This is currently only used to send the list of extensions
763 * supported by the client to the server.
764 */
765 char *
__glXGetClientGLExtensionString(void)766 __glXGetClientGLExtensionString(void)
767 {
768 return __glXGetStringFromTable(known_gl_extensions, NULL);
769 }
770