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