add FreeTexImageData hook to help single-copy texturing in drivers
[mesa.git] / src / mesa / main / extensions.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.3
4 *
5 * Copyright (C) 1999-2004 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)(unsigned long)&(((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_shadow", F(ARB_shadow) },
61 { OFF, "GL_ARB_shadow_ambient", F(SGIX_shadow_ambient) },
62 { OFF, "GL_ARB_texture_border_clamp", F(ARB_texture_border_clamp) },
63 { OFF, "GL_ARB_texture_compression", F(ARB_texture_compression) },
64 { OFF, "GL_ARB_texture_cube_map", F(ARB_texture_cube_map) },
65 { OFF, "GL_ARB_texture_env_add", F(EXT_texture_env_add) },
66 { OFF, "GL_ARB_texture_env_combine", F(ARB_texture_env_combine) },
67 { OFF, "GL_ARB_texture_env_crossbar", F(ARB_texture_env_crossbar) },
68 { OFF, "GL_ARB_texture_env_dot3", F(ARB_texture_env_dot3) },
69 { OFF, "GL_MESAX_texture_float", F(ARB_texture_float) },
70 { OFF, "GL_ARB_texture_mirrored_repeat", F(ARB_texture_mirrored_repeat)},
71 { OFF, "GL_ARB_texture_non_power_of_two", F(ARB_texture_non_power_of_two)},
72 { OFF, "GL_ARB_texture_rectangle", F(NV_texture_rectangle) },
73 { ON, "GL_ARB_transpose_matrix", F(ARB_transpose_matrix) },
74 { OFF, "GL_ARB_vertex_buffer_object", F(ARB_vertex_buffer_object) },
75 { OFF, "GL_ARB_vertex_program", F(ARB_vertex_program) },
76 { OFF, "GL_ARB_vertex_shader", F(ARB_vertex_shader) },
77 { ON, "GL_ARB_window_pos", F(ARB_window_pos) },
78 { ON, "GL_EXT_abgr", F(EXT_abgr) },
79 { ON, "GL_EXT_bgra", F(EXT_bgra) },
80 { OFF, "GL_EXT_blend_color", F(EXT_blend_color) },
81 { OFF, "GL_EXT_blend_equation_separate", F(EXT_blend_equation_separate) },
82 { OFF, "GL_EXT_blend_func_separate", F(EXT_blend_func_separate) },
83 { OFF, "GL_EXT_blend_logic_op", F(EXT_blend_logic_op) },
84 { OFF, "GL_EXT_blend_minmax", F(EXT_blend_minmax) },
85 { OFF, "GL_EXT_blend_subtract", F(EXT_blend_subtract) },
86 { ON, "GL_EXT_clip_volume_hint", F(EXT_clip_volume_hint) },
87 { OFF, "GL_EXT_cull_vertex", F(EXT_cull_vertex) },
88 { ON, "GL_EXT_compiled_vertex_array", F(EXT_compiled_vertex_array) },
89 { OFF, "GL_EXT_convolution", F(EXT_convolution) },
90 { ON, "GL_EXT_copy_texture", F(EXT_copy_texture) },
91 { OFF, "GL_EXT_depth_bounds_test", F(EXT_depth_bounds_test) },
92 { ON, "GL_EXT_draw_range_elements", F(EXT_draw_range_elements) },
93 { OFF, "GL_EXT_framebuffer_object", F(EXT_framebuffer_object) },
94 { OFF, "GL_EXT_fog_coord", F(EXT_fog_coord) },
95 { OFF, "GL_EXT_histogram", F(EXT_histogram) },
96 { OFF, "GL_EXT_multi_draw_arrays", F(EXT_multi_draw_arrays) },
97 { ON, "GL_EXT_packed_pixels", F(EXT_packed_pixels) },
98 { OFF, "GL_EXT_paletted_texture", F(EXT_paletted_texture) },
99 { OFF, "GL_EXT_pixel_buffer_object", F(EXT_pixel_buffer_object) },
100 { OFF, "GL_EXT_point_parameters", F(EXT_point_parameters) },
101 { ON, "GL_EXT_polygon_offset", F(EXT_polygon_offset) },
102 { ON, "GL_EXT_rescale_normal", F(EXT_rescale_normal) },
103 { OFF, "GL_EXT_secondary_color", F(EXT_secondary_color) },
104 { ON, "GL_EXT_separate_specular_color", F(EXT_separate_specular_color) },
105 { OFF, "GL_EXT_shadow_funcs", F(EXT_shadow_funcs) },
106 { OFF, "GL_EXT_shared_texture_palette", F(EXT_shared_texture_palette) },
107 { OFF, "GL_EXT_stencil_two_side", F(EXT_stencil_two_side) },
108 { OFF, "GL_EXT_stencil_wrap", F(EXT_stencil_wrap) },
109 { ON, "GL_EXT_subtexture", F(EXT_subtexture) },
110 { ON, "GL_EXT_texture", F(EXT_texture) },
111 { ON, "GL_EXT_texture3D", F(EXT_texture3D) },
112 { OFF, "GL_EXT_texture_compression_s3tc", F(EXT_texture_compression_s3tc) },
113 { ON, "GL_EXT_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
114 { OFF, "GL_EXT_texture_env_add", F(EXT_texture_env_add) },
115 { OFF, "GL_EXT_texture_env_combine", F(EXT_texture_env_combine) },
116 { OFF, "GL_EXT_texture_env_dot3", F(EXT_texture_env_dot3) },
117 { OFF, "GL_EXT_texture_filter_anisotropic", F(EXT_texture_filter_anisotropic) },
118 { OFF, "GL_EXT_texture_lod_bias", F(EXT_texture_lod_bias) },
119 { OFF, "GL_EXT_texture_mirror_clamp", F(EXT_texture_mirror_clamp) },
120 { ON, "GL_EXT_texture_object", F(EXT_texture_object) },
121 { OFF, "GL_EXT_texture_rectangle", F(NV_texture_rectangle) },
122 { ON, "GL_EXT_vertex_array", F(EXT_vertex_array) },
123 { OFF, "GL_EXT_vertex_array_set", F(EXT_vertex_array_set) },
124 { OFF, "GL_3DFX_texture_compression_FXT1", F(TDFX_texture_compression_FXT1) },
125 { OFF, "GL_APPLE_client_storage", F(APPLE_client_storage) },
126 { ON, "GL_APPLE_packed_pixels", F(APPLE_packed_pixels) },
127 { OFF, "GL_ATI_blend_equation_separate", F(EXT_blend_equation_separate) },
128 { OFF, "GL_ATI_texture_env_combine3", F(ATI_texture_env_combine3)},
129 { OFF, "GL_ATI_texture_mirror_once", F(ATI_texture_mirror_once)},
130 { OFF, "GL_ATI_fragment_shader", F(ATI_fragment_shader)},
131 { OFF, "GL_HP_occlusion_test", F(HP_occlusion_test) },
132 { OFF, "GL_IBM_multimode_draw_arrays", F(IBM_multimode_draw_arrays) },
133 { ON, "GL_IBM_rasterpos_clip", F(IBM_rasterpos_clip) },
134 { OFF, "GL_IBM_texture_mirrored_repeat", F(ARB_texture_mirrored_repeat)},
135 { OFF, "GL_INGR_blend_func_separate", F(EXT_blend_func_separate) },
136 { OFF, "GL_MESA_pack_invert", F(MESA_pack_invert) },
137 { OFF, "GL_MESA_packed_depth_stencil", F(MESA_packed_depth_stencil) },
138 { OFF, "GL_MESA_program_debug", F(MESA_program_debug) },
139 { OFF, "GL_MESA_resize_buffers", F(MESA_resize_buffers) },
140 { OFF, "GL_MESA_ycbcr_texture", F(MESA_ycbcr_texture) },
141 { ON, "GL_MESA_window_pos", F(ARB_window_pos) },
142 { OFF, "GL_NV_blend_square", F(NV_blend_square) },
143 { OFF, "GL_NV_fragment_program", F(NV_fragment_program) },
144 { ON, "GL_NV_light_max_exponent", F(NV_light_max_exponent) },
145 { OFF, "GL_NV_point_sprite", F(NV_point_sprite) },
146 { OFF, "GL_NV_texture_rectangle", F(NV_texture_rectangle) },
147 { ON, "GL_NV_texgen_reflection", F(NV_texgen_reflection) },
148 { OFF, "GL_NV_vertex_program", F(NV_vertex_program) },
149 { OFF, "GL_NV_vertex_program1_1", F(NV_vertex_program1_1) },
150 { ON, "GL_OES_read_format", F(OES_read_format) },
151 { OFF, "GL_SGI_color_matrix", F(SGI_color_matrix) },
152 { OFF, "GL_SGI_color_table", F(SGI_color_table) },
153 { OFF, "GL_SGI_texture_color_table", F(SGI_texture_color_table) },
154 { OFF, "GL_SGIS_generate_mipmap", F(SGIS_generate_mipmap) },
155 { OFF, "GL_SGIS_pixel_texture", F(SGIS_pixel_texture) },
156 { OFF, "GL_SGIS_texture_border_clamp", F(ARB_texture_border_clamp) },
157 { ON, "GL_SGIS_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
158 { ON, "GL_SGIS_texture_lod", F(SGIS_texture_lod) },
159 { OFF, "GL_SGIX_depth_texture", F(SGIX_depth_texture) },
160 { OFF, "GL_SGIX_pixel_texture", F(SGIX_pixel_texture) },
161 { OFF, "GL_SGIX_shadow", F(SGIX_shadow) },
162 { OFF, "GL_SGIX_shadow_ambient", F(SGIX_shadow_ambient) },
163 { OFF, "GL_SUN_multi_draw_arrays", F(EXT_multi_draw_arrays) },
164 { OFF, "GL_S3_s3tc", F(S3_s3tc) },
165 };
166
167
168
169 /**
170 * Enable all extensions suitable for a software-only renderer.
171 * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
172 */
173 void
174 _mesa_enable_sw_extensions(GLcontext *ctx)
175 {
176 ctx->Extensions.ARB_depth_texture = GL_TRUE;
177 ctx->Extensions.ARB_draw_buffers = GL_TRUE;
178 #if FEATURE_ARB_fragment_program
179 ctx->Extensions.ARB_fragment_program = GL_TRUE;
180 #endif
181 /*ctx->Extensions.ARB_half_float_pixel = GL_TRUE;*/
182 ctx->Extensions.ARB_imaging = GL_TRUE;
183 ctx->Extensions.ARB_multitexture = GL_TRUE;
184 #if FEATURE_ARB_occlusion_query
185 ctx->Extensions.ARB_occlusion_query = GL_TRUE;
186 #endif
187 ctx->Extensions.ARB_point_sprite = GL_TRUE;
188 ctx->Extensions.ARB_shadow = GL_TRUE;
189 ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
190 ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
191 ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
192 ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
193 ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
194 /*ctx->Extensions.ARB_texture_float = GL_TRUE;*/
195 ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
196 ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
197 #if FEATURE_ARB_vertex_program
198 ctx->Extensions.ARB_vertex_program = GL_TRUE;
199 #endif
200 #if FEATURE_ARB_vertex_buffer_object
201 ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;
202 #endif
203 #if FEATURE_ARB_shader_objects
204 ctx->Extensions.ARB_shader_objects = GL_TRUE;
205 #if FEATURE_ARB_fragment_shader
206 ctx->Extensions.ARB_fragment_shader = GL_TRUE;
207 #endif
208 #if FEATURE_ARB_vertex_shader
209 ctx->Extensions.ARB_vertex_shader = GL_TRUE;
210 #endif
211 #endif
212 #if FEATURE_ATI_fragment_shader
213 ctx->Extensions.ATI_fragment_shader = GL_TRUE;
214 #endif
215 ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
216 ctx->Extensions.ATI_texture_mirror_once = GL_TRUE;
217 ctx->Extensions.EXT_blend_color = GL_TRUE;
218 ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
219 ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
220 ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
221 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
222 ctx->Extensions.EXT_blend_subtract = GL_TRUE;
223 ctx->Extensions.EXT_convolution = GL_TRUE;
224 ctx->Extensions.EXT_depth_bounds_test = GL_TRUE;
225 ctx->Extensions.EXT_fog_coord = GL_TRUE;
226 /*ctx->Extensions.EXT_framebuffer_object = GL_TRUE;*/
227 ctx->Extensions.EXT_histogram = GL_TRUE;
228 ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;
229 ctx->Extensions.EXT_paletted_texture = GL_TRUE;
230 #if FEATURE_EXT_pixel_buffer_object
231 ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
232 #endif
233 ctx->Extensions.EXT_point_parameters = GL_TRUE;
234 ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
235 ctx->Extensions.EXT_secondary_color = GL_TRUE;
236 ctx->Extensions.EXT_shared_texture_palette = GL_TRUE;
237 ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
238 ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
239 ctx->Extensions.EXT_texture_env_add = GL_TRUE;
240 ctx->Extensions.EXT_texture_env_combine = GL_TRUE;
241 ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
242 ctx->Extensions.EXT_texture_mirror_clamp = GL_TRUE;
243 ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
244 ctx->Extensions.HP_occlusion_test = GL_TRUE;
245 ctx->Extensions.IBM_multimode_draw_arrays = GL_TRUE;
246 ctx->Extensions.MESA_pack_invert = GL_TRUE;
247 #if FEATURE_MESA_program_debug
248 ctx->Extensions.MESA_program_debug = GL_TRUE;
249 #endif
250 ctx->Extensions.MESA_resize_buffers = GL_TRUE;
251 ctx->Extensions.MESA_ycbcr_texture = GL_TRUE;
252 ctx->Extensions.NV_blend_square = GL_TRUE;
253 /*ctx->Extensions.NV_light_max_exponent = GL_TRUE;*/
254 ctx->Extensions.NV_point_sprite = GL_TRUE;
255 ctx->Extensions.NV_texture_rectangle = GL_TRUE;
256 /*ctx->Extensions.NV_texgen_reflection = GL_TRUE;*/
257 #if FEATURE_NV_vertex_program
258 ctx->Extensions.NV_vertex_program = GL_TRUE;
259 ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
260 #endif
261 #if FEATURE_NV_fragment_program
262 ctx->Extensions.NV_fragment_program = GL_TRUE;
263 #endif
264 ctx->Extensions.SGI_color_matrix = GL_TRUE;
265 ctx->Extensions.SGI_color_table = GL_TRUE;
266 ctx->Extensions.SGI_texture_color_table = GL_TRUE;
267 ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;
268 ctx->Extensions.SGIS_pixel_texture = GL_TRUE;
269 ctx->Extensions.SGIS_texture_edge_clamp = GL_TRUE;
270 ctx->Extensions.SGIX_depth_texture = GL_TRUE;
271 ctx->Extensions.SGIX_pixel_texture = GL_TRUE;
272 ctx->Extensions.SGIX_shadow = GL_TRUE;
273 ctx->Extensions.SGIX_shadow_ambient = GL_TRUE;
274 }
275
276
277 /**
278 * Enable GL_ARB_imaging and all the EXT extensions that are subsets of it.
279 */
280 void
281 _mesa_enable_imaging_extensions(GLcontext *ctx)
282 {
283 ctx->Extensions.ARB_imaging = GL_TRUE;
284 ctx->Extensions.EXT_blend_color = GL_TRUE;
285 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
286 ctx->Extensions.EXT_blend_subtract = GL_TRUE;
287 ctx->Extensions.EXT_convolution = GL_TRUE;
288 ctx->Extensions.EXT_histogram = GL_TRUE;
289 ctx->Extensions.SGI_color_matrix = GL_TRUE;
290 ctx->Extensions.SGI_color_table = GL_TRUE;
291 }
292
293
294
295 /**
296 * Enable all OpenGL 1.3 features and extensions.
297 * A convenience function to be called by drivers.
298 */
299 void
300 _mesa_enable_1_3_extensions(GLcontext *ctx)
301 {
302 ctx->Extensions.ARB_multisample = GL_TRUE;
303 ctx->Extensions.ARB_multitexture = GL_TRUE;
304 ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
305 ctx->Extensions.ARB_texture_compression = GL_TRUE;
306 ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
307 ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
308 ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
309 ctx->Extensions.EXT_texture_env_add = GL_TRUE;
310 /*ctx->Extensions.ARB_transpose_matrix = GL_TRUE;*/
311 }
312
313
314
315 /**
316 * Enable all OpenGL 1.4 features and extensions.
317 * A convenience function to be called by drivers.
318 */
319 void
320 _mesa_enable_1_4_extensions(GLcontext *ctx)
321 {
322 ctx->Extensions.ARB_depth_texture = GL_TRUE;
323 ctx->Extensions.ARB_shadow = GL_TRUE;
324 ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
325 ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
326 ctx->Extensions.ARB_window_pos = GL_TRUE;
327 ctx->Extensions.EXT_blend_color = GL_TRUE;
328 ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
329 ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
330 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
331 ctx->Extensions.EXT_blend_subtract = GL_TRUE;
332 ctx->Extensions.EXT_fog_coord = GL_TRUE;
333 ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;
334 ctx->Extensions.EXT_point_parameters = GL_TRUE;
335 ctx->Extensions.EXT_secondary_color = GL_TRUE;
336 ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
337 ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
338 ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;
339 }
340
341
342 /**
343 * Enable all OpenGL 1.5 features and extensions.
344 * A convenience function to be called by drivers.
345 */
346 void
347 _mesa_enable_1_5_extensions(GLcontext *ctx)
348 {
349 ctx->Extensions.ARB_occlusion_query = GL_TRUE;
350 ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;
351 ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
352 }
353
354
355 /**
356 * Enable all OpenGL 2.0 features and extensions.
357 * A convenience function to be called by drivers.
358 */
359 void
360 _mesa_enable_2_0_extensions(GLcontext *ctx)
361 {
362 ctx->Extensions.ARB_draw_buffers = GL_TRUE;
363 ctx->Extensions.ARB_point_sprite = GL_TRUE;
364 ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
365 ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
366 #if FEATURE_ARB_shader_objects
367 ctx->Extensions.ARB_shader_objects = GL_TRUE;
368 #if FEATURE_ARB_fragment_shader
369 ctx->Extensions.ARB_fragment_shader = GL_TRUE;
370 #endif
371 #if FEATURE_ARB_vertex_shader
372 ctx->Extensions.ARB_vertex_shader = GL_TRUE;
373 #endif
374 #endif
375 }
376
377
378
379 /**
380 * Either enable or disable the named extension.
381 */
382 static void
383 set_extension( GLcontext *ctx, const char *name, GLboolean state )
384 {
385 GLboolean *base = (GLboolean *) &ctx->Extensions;
386 GLuint i;
387
388 if (ctx->Extensions.String) {
389 /* The string was already queried - can't change it now! */
390 _mesa_problem(ctx, "Trying to enable/disable extension after glGetString(GL_EXTENSIONS): %s", name);
391 return;
392 }
393
394 for (i = 0 ; i < Elements(default_extensions) ; i++) {
395 if (_mesa_strcmp(default_extensions[i].name, name) == 0) {
396 if (default_extensions[i].flag_offset) {
397 GLboolean *enabled = base + default_extensions[i].flag_offset;
398 *enabled = state;
399 }
400 return;
401 }
402 }
403 _mesa_problem(ctx, "Trying to enable unknown extension: %s", name);
404 }
405
406
407 /**
408 * Enable the named extension.
409 * Typically called by drivers.
410 */
411 void
412 _mesa_enable_extension( GLcontext *ctx, const char *name )
413 {
414 set_extension(ctx, name, GL_TRUE);
415 }
416
417
418 /**
419 * Disable the named extension.
420 * XXX is this really needed???
421 */
422 void
423 _mesa_disable_extension( GLcontext *ctx, const char *name )
424 {
425 set_extension(ctx, name, GL_FALSE);
426 }
427
428
429 /**
430 * Test if the named extension is enabled in this context.
431 */
432 GLboolean
433 _mesa_extension_is_enabled( GLcontext *ctx, const char *name )
434 {
435 const GLboolean *base = (const GLboolean *) &ctx->Extensions;
436 GLuint i;
437
438 for (i = 0 ; i < Elements(default_extensions) ; i++) {
439 if (_mesa_strcmp(default_extensions[i].name, name) == 0) {
440 if (!default_extensions[i].flag_offset)
441 return GL_TRUE;
442 return *(base + default_extensions[i].flag_offset);
443 }
444 }
445 return GL_FALSE;
446 }
447
448
449 /**
450 * Run through the default_extensions array above and set the
451 * ctx->Extensions.ARB/EXT_* flags accordingly.
452 * To be called during context initialization.
453 */
454 void
455 _mesa_init_extensions( GLcontext *ctx )
456 {
457 GLboolean *base = (GLboolean *) &ctx->Extensions;
458 GLuint i;
459
460 for (i = 0 ; i < Elements(default_extensions) ; i++) {
461 if (default_extensions[i].enabled &&
462 default_extensions[i].flag_offset) {
463 *(base + default_extensions[i].flag_offset) = GL_TRUE;
464 }
465 }
466 }
467
468
469 /**
470 * Construct the GL_EXTENSIONS string. Called the first time that
471 * glGetString(GL_EXTENSIONS) is called.
472 */
473 GLubyte *
474 _mesa_make_extension_string( GLcontext *ctx )
475 {
476 const GLboolean *base = (const GLboolean *) &ctx->Extensions;
477 GLuint extStrLen = 0;
478 GLubyte *s;
479 GLuint i;
480
481 /* first, compute length of the extension string */
482 for (i = 0 ; i < Elements(default_extensions) ; i++) {
483 if (!default_extensions[i].flag_offset ||
484 *(base + default_extensions[i].flag_offset)) {
485 extStrLen += _mesa_strlen(default_extensions[i].name) + 1;
486 }
487 }
488 s = (GLubyte *) _mesa_malloc(extStrLen);
489
490 /* second, build the extension string */
491 extStrLen = 0;
492 for (i = 0 ; i < Elements(default_extensions) ; i++) {
493 if (!default_extensions[i].flag_offset ||
494 *(base + default_extensions[i].flag_offset)) {
495 GLuint len = _mesa_strlen(default_extensions[i].name);
496 _mesa_memcpy(s + extStrLen, default_extensions[i].name, len);
497 extStrLen += len;
498 s[extStrLen] = (GLubyte) ' ';
499 extStrLen++;
500 }
501 }
502 ASSERT(extStrLen > 0);
503
504 s[extStrLen - 1] = 0;
505
506 return s;
507 }