Fix pow <small> and a very stypid bug with dummy srcs(0 equals to tmp0.x)</small...
[mesa.git] / src / mesa / main / extensions.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #include "glheader.h"
27 #include "imports.h"
28 #include "context.h"
29 #include "extensions.h"
30 #include "simple_list.h"
31 #include "mtypes.h"
32
33
34 #define F(x) (int)(uintptr_t)&(((struct gl_extensions *)0)->x)
35 #define ON GL_TRUE
36 #define OFF GL_FALSE
37
38
39 /*
40 * Note: The GL_MESAX_* extensions are placeholders for future ARB extensions.
41 */
42 static const struct {
43 GLboolean enabled;
44 const char *name;
45 int flag_offset;
46 } default_extensions[] = {
47 { OFF, "GL_ARB_depth_texture", F(ARB_depth_texture) },
48 { OFF, "GL_ARB_draw_buffers", F(ARB_draw_buffers) },
49 { OFF, "GL_ARB_fragment_program", F(ARB_fragment_program) },
50 { OFF, "GL_ARB_fragment_shader", F(ARB_fragment_shader) },
51 { OFF, "GL_MESAX_half_float_pixel", F(ARB_half_float_pixel) },
52 { OFF, "GL_ARB_imaging", F(ARB_imaging) },
53 { OFF, "GL_ARB_multisample", F(ARB_multisample) },
54 { OFF, "GL_ARB_multitexture", F(ARB_multitexture) },
55 { OFF, "GL_ARB_occlusion_query", F(ARB_occlusion_query) },
56 { OFF, "GL_ARB_pixel_buffer_object", F(EXT_pixel_buffer_object) },
57 { OFF, "GL_ARB_point_parameters", F(EXT_point_parameters) },
58 { OFF, "GL_ARB_point_sprite", F(ARB_point_sprite) },
59 { OFF, "GL_ARB_shader_objects", F(ARB_shader_objects) },
60 { OFF, "GL_ARB_shading_language_100", F(ARB_shading_language_100) },
61 { OFF, "GL_ARB_shadow", F(ARB_shadow) },
62 { OFF, "GL_ARB_shadow_ambient", F(SGIX_shadow_ambient) },
63 { OFF, "GL_ARB_texture_border_clamp", F(ARB_texture_border_clamp) },
64 { OFF, "GL_ARB_texture_compression", F(ARB_texture_compression) },
65 { OFF, "GL_ARB_texture_cube_map", F(ARB_texture_cube_map) },
66 { OFF, "GL_ARB_texture_env_add", F(EXT_texture_env_add) },
67 { OFF, "GL_ARB_texture_env_combine", F(ARB_texture_env_combine) },
68 { OFF, "GL_ARB_texture_env_crossbar", F(ARB_texture_env_crossbar) },
69 { OFF, "GL_ARB_texture_env_dot3", F(ARB_texture_env_dot3) },
70 { OFF, "GL_MESAX_texture_float", F(ARB_texture_float) },
71 { OFF, "GL_ARB_texture_mirrored_repeat", F(ARB_texture_mirrored_repeat)},
72 { OFF, "GL_ARB_texture_non_power_of_two", F(ARB_texture_non_power_of_two)},
73 { OFF, "GL_ARB_texture_rectangle", F(NV_texture_rectangle) },
74 { ON, "GL_ARB_transpose_matrix", F(ARB_transpose_matrix) },
75 { OFF, "GL_ARB_vertex_buffer_object", F(ARB_vertex_buffer_object) },
76 { OFF, "GL_ARB_vertex_program", F(ARB_vertex_program) },
77 { OFF, "GL_ARB_vertex_shader", F(ARB_vertex_shader) },
78 { ON, "GL_ARB_window_pos", F(ARB_window_pos) },
79 { ON, "GL_EXT_abgr", F(EXT_abgr) },
80 { ON, "GL_EXT_bgra", F(EXT_bgra) },
81 { OFF, "GL_EXT_blend_color", F(EXT_blend_color) },
82 { OFF, "GL_EXT_blend_equation_separate", F(EXT_blend_equation_separate) },
83 { OFF, "GL_EXT_blend_func_separate", F(EXT_blend_func_separate) },
84 { OFF, "GL_EXT_blend_logic_op", F(EXT_blend_logic_op) },
85 { OFF, "GL_EXT_blend_minmax", F(EXT_blend_minmax) },
86 { OFF, "GL_EXT_blend_subtract", F(EXT_blend_subtract) },
87 { ON, "GL_EXT_clip_volume_hint", F(EXT_clip_volume_hint) },
88 { OFF, "GL_EXT_cull_vertex", F(EXT_cull_vertex) },
89 { ON, "GL_EXT_compiled_vertex_array", F(EXT_compiled_vertex_array) },
90 { OFF, "GL_EXT_convolution", F(EXT_convolution) },
91 { ON, "GL_EXT_copy_texture", F(EXT_copy_texture) },
92 { OFF, "GL_EXT_depth_bounds_test", F(EXT_depth_bounds_test) },
93 { ON, "GL_EXT_draw_range_elements", F(EXT_draw_range_elements) },
94 { OFF, "GL_EXT_framebuffer_object", F(EXT_framebuffer_object) },
95 { OFF, "GL_EXT_framebuffer_blit", F(EXT_framebuffer_blit) },
96 { OFF, "GL_EXT_fog_coord", F(EXT_fog_coord) },
97 { OFF, "GL_EXT_histogram", F(EXT_histogram) },
98 { OFF, "GL_EXT_multi_draw_arrays", F(EXT_multi_draw_arrays) },
99 { ON, "GL_EXT_packed_depth_stencil", F(EXT_packed_depth_stencil) },
100 { ON, "GL_EXT_packed_pixels", F(EXT_packed_pixels) },
101 { OFF, "GL_EXT_paletted_texture", F(EXT_paletted_texture) },
102 { OFF, "GL_EXT_pixel_buffer_object", F(EXT_pixel_buffer_object) },
103 { OFF, "GL_EXT_point_parameters", F(EXT_point_parameters) },
104 { ON, "GL_EXT_polygon_offset", F(EXT_polygon_offset) },
105 { ON, "GL_EXT_rescale_normal", F(EXT_rescale_normal) },
106 { OFF, "GL_EXT_secondary_color", F(EXT_secondary_color) },
107 { ON, "GL_EXT_separate_specular_color", F(EXT_separate_specular_color) },
108 { OFF, "GL_EXT_shadow_funcs", F(EXT_shadow_funcs) },
109 { OFF, "GL_EXT_shared_texture_palette", F(EXT_shared_texture_palette) },
110 { OFF, "GL_EXT_stencil_two_side", F(EXT_stencil_two_side) },
111 { OFF, "GL_EXT_stencil_wrap", F(EXT_stencil_wrap) },
112 { ON, "GL_EXT_subtexture", F(EXT_subtexture) },
113 { ON, "GL_EXT_texture", F(EXT_texture) },
114 { ON, "GL_EXT_texture3D", F(EXT_texture3D) },
115 { OFF, "GL_EXT_texture_compression_s3tc", F(EXT_texture_compression_s3tc) },
116 { ON, "GL_EXT_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
117 { OFF, "GL_EXT_texture_env_add", F(EXT_texture_env_add) },
118 { OFF, "GL_EXT_texture_env_combine", F(EXT_texture_env_combine) },
119 { OFF, "GL_EXT_texture_env_dot3", F(EXT_texture_env_dot3) },
120 { OFF, "GL_EXT_texture_filter_anisotropic", F(EXT_texture_filter_anisotropic) },
121 { OFF, "GL_EXT_texture_lod_bias", F(EXT_texture_lod_bias) },
122 { OFF, "GL_EXT_texture_mirror_clamp", F(EXT_texture_mirror_clamp) },
123 { ON, "GL_EXT_texture_object", F(EXT_texture_object) },
124 { OFF, "GL_EXT_texture_rectangle", F(NV_texture_rectangle) },
125 { OFF, "GL_EXT_timer_query", F(EXT_timer_query) },
126 { ON, "GL_EXT_vertex_array", F(EXT_vertex_array) },
127 { OFF, "GL_EXT_vertex_array_set", F(EXT_vertex_array_set) },
128 { OFF, "GL_3DFX_texture_compression_FXT1", F(TDFX_texture_compression_FXT1) },
129 { OFF, "GL_APPLE_client_storage", F(APPLE_client_storage) },
130 { ON, "GL_APPLE_packed_pixels", F(APPLE_packed_pixels) },
131 { OFF, "GL_ATI_blend_equation_separate", F(EXT_blend_equation_separate) },
132 { OFF, "GL_ATI_texture_env_combine3", F(ATI_texture_env_combine3)},
133 { OFF, "GL_ATI_texture_mirror_once", F(ATI_texture_mirror_once)},
134 { OFF, "GL_ATI_fragment_shader", F(ATI_fragment_shader)},
135 { OFF, "GL_IBM_multimode_draw_arrays", F(IBM_multimode_draw_arrays) },
136 { ON, "GL_IBM_rasterpos_clip", F(IBM_rasterpos_clip) },
137 { OFF, "GL_IBM_texture_mirrored_repeat", F(ARB_texture_mirrored_repeat)},
138 { OFF, "GL_INGR_blend_func_separate", F(EXT_blend_func_separate) },
139 { OFF, "GL_MESA_pack_invert", F(MESA_pack_invert) },
140 { OFF, "GL_MESA_packed_depth_stencil", F(MESA_packed_depth_stencil) },
141 { OFF, "GL_MESA_program_debug", F(MESA_program_debug) },
142 { OFF, "GL_MESA_resize_buffers", F(MESA_resize_buffers) },
143 { OFF, "GL_MESA_ycbcr_texture", F(MESA_ycbcr_texture) },
144 { ON, "GL_MESA_window_pos", F(ARB_window_pos) },
145 { OFF, "GL_NV_blend_square", F(NV_blend_square) },
146 { OFF, "GL_NV_fragment_program", F(NV_fragment_program) },
147 { ON, "GL_NV_light_max_exponent", F(NV_light_max_exponent) },
148 { OFF, "GL_NV_point_sprite", F(NV_point_sprite) },
149 { OFF, "GL_NV_texture_rectangle", F(NV_texture_rectangle) },
150 { ON, "GL_NV_texgen_reflection", F(NV_texgen_reflection) },
151 { OFF, "GL_NV_vertex_program", F(NV_vertex_program) },
152 { OFF, "GL_NV_vertex_program1_1", F(NV_vertex_program1_1) },
153 { ON, "GL_OES_read_format", F(OES_read_format) },
154 { OFF, "GL_SGI_color_matrix", F(SGI_color_matrix) },
155 { OFF, "GL_SGI_color_table", F(SGI_color_table) },
156 { OFF, "GL_SGI_texture_color_table", F(SGI_texture_color_table) },
157 { OFF, "GL_SGIS_generate_mipmap", F(SGIS_generate_mipmap) },
158 { OFF, "GL_SGIS_texture_border_clamp", F(ARB_texture_border_clamp) },
159 { ON, "GL_SGIS_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
160 { ON, "GL_SGIS_texture_lod", F(SGIS_texture_lod) },
161 { OFF, "GL_SGIX_depth_texture", F(SGIX_depth_texture) },
162 { OFF, "GL_SGIX_shadow", F(SGIX_shadow) },
163 { OFF, "GL_SGIX_shadow_ambient", F(SGIX_shadow_ambient) },
164 { OFF, "GL_SUN_multi_draw_arrays", F(EXT_multi_draw_arrays) },
165 { OFF, "GL_S3_s3tc", F(S3_s3tc) },
166 };
167
168
169
170 /**
171 * Enable all extensions suitable for a software-only renderer.
172 * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
173 */
174 void
175 _mesa_enable_sw_extensions(GLcontext *ctx)
176 {
177 ctx->Extensions.ARB_depth_texture = GL_TRUE;
178 ctx->Extensions.ARB_draw_buffers = GL_TRUE;
179 #if FEATURE_ARB_fragment_program
180 ctx->Extensions.ARB_fragment_program = GL_TRUE;
181 #endif
182 #if 0 && FEATURE_ARB_fragment_shader
183 ctx->Extensions.ARB_fragment_shader = GL_TRUE;
184 #endif
185 /*ctx->Extensions.ARB_half_float_pixel = GL_TRUE;*/
186 ctx->Extensions.ARB_imaging = GL_TRUE;
187 ctx->Extensions.ARB_multitexture = GL_TRUE;
188 #if FEATURE_ARB_occlusion_query
189 ctx->Extensions.ARB_occlusion_query = GL_TRUE;
190 #endif
191 ctx->Extensions.ARB_point_sprite = GL_TRUE;
192 #if 0 && FEATURE_ARB_shader_objects
193 ctx->Extensions.ARB_shader_objects = GL_TRUE;
194 #endif
195 #if 0 && FEATURE_ARB_shading_language_100
196 ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
197 #endif
198 ctx->Extensions.ARB_shadow = GL_TRUE;
199 ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
200 ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
201 ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
202 ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
203 ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
204 /*ctx->Extensions.ARB_texture_float = GL_TRUE;*/
205 ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
206 ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
207 #if FEATURE_ARB_vertex_program
208 ctx->Extensions.ARB_vertex_program = GL_TRUE;
209 #endif
210 #if 0 && FEATURE_ARB_vertex_shader
211 ctx->Extensions.ARB_vertex_shader = GL_TRUE;
212 #endif
213 #if FEATURE_ARB_vertex_buffer_object
214 ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;
215 #endif
216 #if FEATURE_ATI_fragment_shader
217 ctx->Extensions.ATI_fragment_shader = GL_TRUE;
218 #endif
219 ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
220 ctx->Extensions.ATI_texture_mirror_once = GL_TRUE;
221 ctx->Extensions.EXT_blend_color = GL_TRUE;
222 ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
223 ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
224 ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
225 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
226 ctx->Extensions.EXT_blend_subtract = GL_TRUE;
227 ctx->Extensions.EXT_convolution = GL_TRUE;
228 ctx->Extensions.EXT_depth_bounds_test = GL_TRUE;
229 ctx->Extensions.EXT_fog_coord = GL_TRUE;
230 #if FEATURE_EXT_framebuffer_object
231 ctx->Extensions.EXT_framebuffer_object = GL_TRUE;
232 ctx->Extensions.EXT_framebuffer_blit = GL_TRUE;
233 #endif
234 ctx->Extensions.EXT_histogram = GL_TRUE;
235 ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;
236 ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
237 ctx->Extensions.EXT_paletted_texture = GL_TRUE;
238 #if FEATURE_EXT_pixel_buffer_object
239 ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
240 #endif
241 ctx->Extensions.EXT_point_parameters = GL_TRUE;
242 ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
243 ctx->Extensions.EXT_secondary_color = GL_TRUE;
244 ctx->Extensions.EXT_shared_texture_palette = GL_TRUE;
245 ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
246 ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
247 ctx->Extensions.EXT_texture_env_add = GL_TRUE;
248 ctx->Extensions.EXT_texture_env_combine = GL_TRUE;
249 ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
250 ctx->Extensions.EXT_texture_mirror_clamp = GL_TRUE;
251 ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
252 ctx->Extensions.IBM_multimode_draw_arrays = GL_TRUE;
253 ctx->Extensions.MESA_pack_invert = GL_TRUE;
254 #if FEATURE_MESA_program_debug
255 ctx->Extensions.MESA_program_debug = GL_TRUE;
256 #endif
257 ctx->Extensions.MESA_resize_buffers = GL_TRUE;
258 ctx->Extensions.MESA_ycbcr_texture = GL_TRUE;
259 ctx->Extensions.NV_blend_square = GL_TRUE;
260 /*ctx->Extensions.NV_light_max_exponent = GL_TRUE;*/
261 ctx->Extensions.NV_point_sprite = GL_TRUE;
262 ctx->Extensions.NV_texture_rectangle = GL_TRUE;
263 /*ctx->Extensions.NV_texgen_reflection = GL_TRUE;*/
264 #if FEATURE_NV_vertex_program
265 ctx->Extensions.NV_vertex_program = GL_TRUE;
266 ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
267 #endif
268 #if FEATURE_NV_fragment_program
269 ctx->Extensions.NV_fragment_program = GL_TRUE;
270 #endif
271 ctx->Extensions.SGI_color_matrix = GL_TRUE;
272 ctx->Extensions.SGI_color_table = GL_TRUE;
273 ctx->Extensions.SGI_texture_color_table = GL_TRUE;
274 ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;
275 ctx->Extensions.SGIS_texture_edge_clamp = GL_TRUE;
276 ctx->Extensions.SGIX_depth_texture = GL_TRUE;
277 ctx->Extensions.SGIX_shadow = GL_TRUE;
278 ctx->Extensions.SGIX_shadow_ambient = GL_TRUE;
279 }
280
281
282 /**
283 * Enable GL_ARB_imaging and all the EXT extensions that are subsets of it.
284 */
285 void
286 _mesa_enable_imaging_extensions(GLcontext *ctx)
287 {
288 ctx->Extensions.ARB_imaging = GL_TRUE;
289 ctx->Extensions.EXT_blend_color = GL_TRUE;
290 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
291 ctx->Extensions.EXT_blend_subtract = GL_TRUE;
292 ctx->Extensions.EXT_convolution = GL_TRUE;
293 ctx->Extensions.EXT_histogram = GL_TRUE;
294 ctx->Extensions.SGI_color_matrix = GL_TRUE;
295 ctx->Extensions.SGI_color_table = GL_TRUE;
296 }
297
298
299
300 /**
301 * Enable all OpenGL 1.3 features and extensions.
302 * A convenience function to be called by drivers.
303 */
304 void
305 _mesa_enable_1_3_extensions(GLcontext *ctx)
306 {
307 ctx->Extensions.ARB_multisample = GL_TRUE;
308 ctx->Extensions.ARB_multitexture = GL_TRUE;
309 ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
310 ctx->Extensions.ARB_texture_compression = GL_TRUE;
311 ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
312 ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
313 ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
314 ctx->Extensions.EXT_texture_env_add = GL_TRUE;
315 /*ctx->Extensions.ARB_transpose_matrix = GL_TRUE;*/
316 }
317
318
319
320 /**
321 * Enable all OpenGL 1.4 features and extensions.
322 * A convenience function to be called by drivers.
323 */
324 void
325 _mesa_enable_1_4_extensions(GLcontext *ctx)
326 {
327 ctx->Extensions.ARB_depth_texture = GL_TRUE;
328 ctx->Extensions.ARB_shadow = GL_TRUE;
329 ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
330 ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
331 ctx->Extensions.ARB_window_pos = GL_TRUE;
332 ctx->Extensions.EXT_blend_color = GL_TRUE;
333 ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
334 ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
335 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
336 ctx->Extensions.EXT_blend_subtract = GL_TRUE;
337 ctx->Extensions.EXT_fog_coord = GL_TRUE;
338 ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;
339 ctx->Extensions.EXT_point_parameters = GL_TRUE;
340 ctx->Extensions.EXT_secondary_color = GL_TRUE;
341 ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
342 ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
343 ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;
344 }
345
346
347 /**
348 * Enable all OpenGL 1.5 features and extensions.
349 * A convenience function to be called by drivers.
350 */
351 void
352 _mesa_enable_1_5_extensions(GLcontext *ctx)
353 {
354 ctx->Extensions.ARB_occlusion_query = GL_TRUE;
355 ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;
356 ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
357 }
358
359
360 /**
361 * Enable all OpenGL 2.0 features and extensions.
362 * A convenience function to be called by drivers.
363 */
364 void
365 _mesa_enable_2_0_extensions(GLcontext *ctx)
366 {
367 ctx->Extensions.ARB_draw_buffers = GL_TRUE;
368 #if 0 && FEATURE_ARB_fragment_shader
369 ctx->Extensions.ARB_fragment_shader = GL_TRUE;
370 #endif
371 ctx->Extensions.ARB_point_sprite = GL_TRUE;
372 ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
373 #if 0 && FEATURE_ARB_shader_objects
374 ctx->Extensions.ARB_shader_objects = GL_TRUE;
375 #endif
376 #if 0 && FEATURE_ARB_shading_language_100
377 ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
378 #endif
379 ctx->Extensions.EXT_stencil_two_side = GL_FALSE; /* yes, turn it off */
380 #if 0 && FEATURE_ARB_vertex_shader
381 ctx->Extensions.ARB_vertex_shader = GL_TRUE;
382 #endif
383 }
384
385
386
387 /**
388 * Either enable or disable the named extension.
389 */
390 static void
391 set_extension( GLcontext *ctx, const char *name, GLboolean state )
392 {
393 GLboolean *base = (GLboolean *) &ctx->Extensions;
394 GLuint i;
395
396 if (ctx->Extensions.String) {
397 /* The string was already queried - can't change it now! */
398 _mesa_problem(ctx, "Trying to enable/disable extension after glGetString(GL_EXTENSIONS): %s", name);
399 return;
400 }
401
402 for (i = 0 ; i < Elements(default_extensions) ; i++) {
403 if (_mesa_strcmp(default_extensions[i].name, name) == 0) {
404 if (default_extensions[i].flag_offset) {
405 GLboolean *enabled = base + default_extensions[i].flag_offset;
406 *enabled = state;
407 }
408 return;
409 }
410 }
411 _mesa_problem(ctx, "Trying to enable unknown extension: %s", name);
412 }
413
414
415 /**
416 * Enable the named extension.
417 * Typically called by drivers.
418 */
419 void
420 _mesa_enable_extension( GLcontext *ctx, const char *name )
421 {
422 set_extension(ctx, name, GL_TRUE);
423 }
424
425
426 /**
427 * Disable the named extension.
428 * XXX is this really needed???
429 */
430 void
431 _mesa_disable_extension( GLcontext *ctx, const char *name )
432 {
433 set_extension(ctx, name, GL_FALSE);
434 }
435
436
437 /**
438 * Test if the named extension is enabled in this context.
439 */
440 GLboolean
441 _mesa_extension_is_enabled( GLcontext *ctx, const char *name )
442 {
443 const GLboolean *base = (const GLboolean *) &ctx->Extensions;
444 GLuint i;
445
446 for (i = 0 ; i < Elements(default_extensions) ; i++) {
447 if (_mesa_strcmp(default_extensions[i].name, name) == 0) {
448 if (!default_extensions[i].flag_offset)
449 return GL_TRUE;
450 return *(base + default_extensions[i].flag_offset);
451 }
452 }
453 return GL_FALSE;
454 }
455
456
457 /**
458 * Run through the default_extensions array above and set the
459 * ctx->Extensions.ARB/EXT_* flags accordingly.
460 * To be called during context initialization.
461 */
462 void
463 _mesa_init_extensions( GLcontext *ctx )
464 {
465 GLboolean *base = (GLboolean *) &ctx->Extensions;
466 GLuint i;
467
468 for (i = 0 ; i < Elements(default_extensions) ; i++) {
469 if (default_extensions[i].enabled &&
470 default_extensions[i].flag_offset) {
471 *(base + default_extensions[i].flag_offset) = GL_TRUE;
472 }
473 }
474 }
475
476
477 /**
478 * Construct the GL_EXTENSIONS string. Called the first time that
479 * glGetString(GL_EXTENSIONS) is called.
480 */
481 GLubyte *
482 _mesa_make_extension_string( GLcontext *ctx )
483 {
484 const GLboolean *base = (const GLboolean *) &ctx->Extensions;
485 GLuint extStrLen = 0;
486 GLubyte *s;
487 GLuint i;
488
489 /* first, compute length of the extension string */
490 for (i = 0 ; i < Elements(default_extensions) ; i++) {
491 if (!default_extensions[i].flag_offset ||
492 *(base + default_extensions[i].flag_offset)) {
493 extStrLen += (GLuint)_mesa_strlen(default_extensions[i].name) + 1;
494 }
495 }
496 s = (GLubyte *) _mesa_malloc(extStrLen);
497
498 /* second, build the extension string */
499 extStrLen = 0;
500 for (i = 0 ; i < Elements(default_extensions) ; i++) {
501 if (!default_extensions[i].flag_offset ||
502 *(base + default_extensions[i].flag_offset)) {
503 GLuint len = (GLuint)_mesa_strlen(default_extensions[i].name);
504 _mesa_memcpy(s + extStrLen, default_extensions[i].name, len);
505 extStrLen += len;
506 s[extStrLen] = (GLubyte) ' ';
507 extStrLen++;
508 }
509 }
510 ASSERT(extStrLen > 0);
511
512 s[extStrLen - 1] = 0;
513
514 return s;
515 }