Merge branch 'mesa_7_7_branch'
[mesa.git] / src / mesa / main / extensions.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.6
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 #include "glheader.h"
28 #include "imports.h"
29 #include "context.h"
30 #include "extensions.h"
31 #include "simple_list.h"
32 #include "mtypes.h"
33
34
35 #define F(x) offsetof(struct gl_extensions, x)
36 #define ON GL_TRUE
37 #define OFF GL_FALSE
38
39
40 /*
41 * Note: The GL_MESAX_* extensions are placeholders for future ARB extensions.
42 */
43 static const struct {
44 GLboolean enabled;
45 const char *name;
46 int flag_offset;
47 } default_extensions[] = {
48 { OFF, "GL_ARB_copy_buffer", F(ARB_copy_buffer) },
49 { OFF, "GL_ARB_depth_texture", F(ARB_depth_texture) },
50 { OFF, "GL_ARB_depth_clamp", F(ARB_depth_clamp) },
51 { ON, "GL_ARB_draw_buffers", F(ARB_draw_buffers) },
52 { OFF, "GL_ARB_draw_elements_base_vertex", F(ARB_draw_elements_base_vertex) },
53 { OFF, "GL_ARB_fragment_program", F(ARB_fragment_program) },
54 { OFF, "GL_ARB_fragment_program_shadow", F(ARB_fragment_program_shadow) },
55 { OFF, "GL_ARB_fragment_shader", F(ARB_fragment_shader) },
56 { OFF, "GL_ARB_framebuffer_object", F(ARB_framebuffer_object) },
57 { OFF, "GL_ARB_half_float_pixel", F(ARB_half_float_pixel) },
58 { OFF, "GL_ARB_imaging", F(ARB_imaging) },
59 { OFF, "GL_ARB_map_buffer_range", F(ARB_map_buffer_range) },
60 { ON, "GL_ARB_multisample", F(ARB_multisample) },
61 { OFF, "GL_ARB_multitexture", F(ARB_multitexture) },
62 { OFF, "GL_ARB_occlusion_query", F(ARB_occlusion_query) },
63 { OFF, "GL_ARB_pixel_buffer_object", F(EXT_pixel_buffer_object) },
64 { OFF, "GL_ARB_point_parameters", F(EXT_point_parameters) },
65 { OFF, "GL_ARB_point_sprite", F(ARB_point_sprite) },
66 { OFF, "GL_ARB_provoking_vertex", F(EXT_provoking_vertex) },
67 { OFF, "GL_ARB_seamless_cube_map", F(ARB_seamless_cube_map) },
68 { OFF, "GL_ARB_shader_objects", F(ARB_shader_objects) },
69 { OFF, "GL_ARB_shading_language_100", F(ARB_shading_language_100) },
70 { OFF, "GL_ARB_shading_language_120", F(ARB_shading_language_120) },
71 { OFF, "GL_ARB_shadow", F(ARB_shadow) },
72 { OFF, "GL_ARB_shadow_ambient", F(ARB_shadow_ambient) },
73 { OFF, "GL_ARB_sync", F(ARB_sync) },
74 { OFF, "GL_ARB_texture_border_clamp", F(ARB_texture_border_clamp) },
75 { ON, "GL_ARB_texture_compression", F(ARB_texture_compression) },
76 { OFF, "GL_ARB_texture_cube_map", F(ARB_texture_cube_map) },
77 { OFF, "GL_ARB_texture_env_add", F(EXT_texture_env_add) },
78 { OFF, "GL_ARB_texture_env_combine", F(ARB_texture_env_combine) },
79 { OFF, "GL_ARB_texture_env_crossbar", F(ARB_texture_env_crossbar) },
80 { OFF, "GL_ARB_texture_env_dot3", F(ARB_texture_env_dot3) },
81 { OFF, "GL_MESAX_texture_float", F(ARB_texture_float) },
82 { OFF, "GL_ARB_texture_mirrored_repeat", F(ARB_texture_mirrored_repeat)},
83 { OFF, "GL_ARB_texture_non_power_of_two", F(ARB_texture_non_power_of_two)},
84 { OFF, "GL_ARB_texture_rectangle", F(NV_texture_rectangle) },
85 { ON, "GL_ARB_transpose_matrix", F(ARB_transpose_matrix) },
86 { OFF, "GL_ARB_vertex_array_bgra", F(EXT_vertex_array_bgra) },
87 { OFF, "GL_ARB_vertex_array_object", F(ARB_vertex_array_object) },
88 { ON, "GL_ARB_vertex_buffer_object", F(ARB_vertex_buffer_object) },
89 { OFF, "GL_ARB_vertex_program", F(ARB_vertex_program) },
90 { OFF, "GL_ARB_vertex_shader", F(ARB_vertex_shader) },
91 { ON, "GL_ARB_window_pos", F(ARB_window_pos) },
92 { ON, "GL_EXT_abgr", F(EXT_abgr) },
93 { ON, "GL_EXT_bgra", F(EXT_bgra) },
94 { OFF, "GL_EXT_blend_color", F(EXT_blend_color) },
95 { OFF, "GL_EXT_blend_equation_separate", F(EXT_blend_equation_separate) },
96 { OFF, "GL_EXT_blend_func_separate", F(EXT_blend_func_separate) },
97 { OFF, "GL_EXT_blend_logic_op", F(EXT_blend_logic_op) },
98 { OFF, "GL_EXT_blend_minmax", F(EXT_blend_minmax) },
99 { OFF, "GL_EXT_blend_subtract", F(EXT_blend_subtract) },
100 { OFF, "GL_EXT_clip_volume_hint", F(EXT_clip_volume_hint) },
101 { OFF, "GL_EXT_cull_vertex", F(EXT_cull_vertex) },
102 { ON, "GL_EXT_compiled_vertex_array", F(EXT_compiled_vertex_array) },
103 { OFF, "GL_EXT_convolution", F(EXT_convolution) },
104 { ON, "GL_EXT_copy_texture", F(EXT_copy_texture) },
105 { OFF, "GL_EXT_depth_bounds_test", F(EXT_depth_bounds_test) },
106 { OFF, "GL_EXT_draw_buffers2", F(EXT_draw_buffers2) },
107 { ON, "GL_EXT_draw_range_elements", F(EXT_draw_range_elements) },
108 { OFF, "GL_EXT_framebuffer_blit", F(EXT_framebuffer_blit) },
109 { OFF, "GL_EXT_framebuffer_multisample", F(EXT_framebuffer_multisample) },
110 { OFF, "GL_EXT_framebuffer_object", F(EXT_framebuffer_object) },
111 { OFF, "GL_EXT_fog_coord", F(EXT_fog_coord) },
112 { OFF, "GL_EXT_gpu_program_parameters", F(EXT_gpu_program_parameters) },
113 { OFF, "GL_EXT_histogram", F(EXT_histogram) },
114 { ON, "GL_EXT_multi_draw_arrays", F(EXT_multi_draw_arrays) },
115 { OFF, "GL_EXT_packed_depth_stencil", F(EXT_packed_depth_stencil) },
116 { ON, "GL_EXT_packed_pixels", F(EXT_packed_pixels) },
117 { OFF, "GL_EXT_paletted_texture", F(EXT_paletted_texture) },
118 { OFF, "GL_EXT_pixel_buffer_object", F(EXT_pixel_buffer_object) },
119 { OFF, "GL_EXT_point_parameters", F(EXT_point_parameters) },
120 { ON, "GL_EXT_polygon_offset", F(EXT_polygon_offset) },
121 { OFF, "GL_EXT_provoking_vertex", F(EXT_provoking_vertex) },
122 { ON, "GL_EXT_rescale_normal", F(EXT_rescale_normal) },
123 { OFF, "GL_EXT_secondary_color", F(EXT_secondary_color) },
124 { ON, "GL_EXT_separate_specular_color", F(EXT_separate_specular_color) },
125 { OFF, "GL_EXT_shadow_funcs", F(EXT_shadow_funcs) },
126 { OFF, "GL_EXT_shared_texture_palette", F(EXT_shared_texture_palette) },
127 { OFF, "GL_EXT_stencil_two_side", F(EXT_stencil_two_side) },
128 { OFF, "GL_EXT_stencil_wrap", F(EXT_stencil_wrap) },
129 { ON, "GL_EXT_subtexture", F(EXT_subtexture) },
130 { ON, "GL_EXT_texture", F(EXT_texture) },
131 { ON, "GL_EXT_texture3D", F(EXT_texture3D) },
132 { OFF, "GL_EXT_texture_compression_s3tc", F(EXT_texture_compression_s3tc) },
133 { ON, "GL_EXT_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
134 { OFF, "GL_EXT_texture_env_add", F(EXT_texture_env_add) },
135 { OFF, "GL_EXT_texture_env_combine", F(EXT_texture_env_combine) },
136 { OFF, "GL_EXT_texture_env_dot3", F(EXT_texture_env_dot3) },
137 { OFF, "GL_EXT_texture_filter_anisotropic", F(EXT_texture_filter_anisotropic) },
138 { OFF, "GL_EXT_texture_lod_bias", F(EXT_texture_lod_bias) },
139 { OFF, "GL_EXT_texture_mirror_clamp", F(EXT_texture_mirror_clamp) },
140 { ON, "GL_EXT_texture_object", F(EXT_texture_object) },
141 { OFF, "GL_EXT_texture_rectangle", F(NV_texture_rectangle) },
142 { OFF, "GL_EXT_texture_sRGB", F(EXT_texture_sRGB) },
143 { OFF, "GL_EXT_texture_swizzle", F(EXT_texture_swizzle) },
144 { OFF, "GL_EXT_timer_query", F(EXT_timer_query) },
145 { ON, "GL_EXT_vertex_array", F(EXT_vertex_array) },
146 { OFF, "GL_EXT_vertex_array_bgra", F(EXT_vertex_array_bgra) },
147 { OFF, "GL_EXT_vertex_array_set", F(EXT_vertex_array_set) },
148 { OFF, "GL_3DFX_texture_compression_FXT1", F(TDFX_texture_compression_FXT1) },
149 { OFF, "GL_APPLE_client_storage", F(APPLE_client_storage) },
150 { ON, "GL_APPLE_packed_pixels", F(APPLE_packed_pixels) },
151 { OFF, "GL_APPLE_vertex_array_object", F(APPLE_vertex_array_object) },
152 { OFF, "GL_ATI_blend_equation_separate", F(EXT_blend_equation_separate) },
153 { OFF, "GL_ATI_envmap_bumpmap", F(ATI_envmap_bumpmap) },
154 { OFF, "GL_ATI_texture_env_combine3", F(ATI_texture_env_combine3)},
155 { OFF, "GL_ATI_texture_mirror_once", F(ATI_texture_mirror_once)},
156 { OFF, "GL_ATI_fragment_shader", F(ATI_fragment_shader)},
157 { OFF, "GL_ATI_separate_stencil", F(ATI_separate_stencil)},
158 { ON, "GL_IBM_multimode_draw_arrays", F(IBM_multimode_draw_arrays) },
159 { ON, "GL_IBM_rasterpos_clip", F(IBM_rasterpos_clip) },
160 { OFF, "GL_IBM_texture_mirrored_repeat", F(ARB_texture_mirrored_repeat)},
161 { OFF, "GL_INGR_blend_func_separate", F(EXT_blend_func_separate) },
162 { OFF, "GL_MESA_pack_invert", F(MESA_pack_invert) },
163 { OFF, "GL_MESA_packed_depth_stencil", F(MESA_packed_depth_stencil) },
164 { OFF, "GL_MESA_resize_buffers", F(MESA_resize_buffers) },
165 { OFF, "GL_MESA_texture_array", F(MESA_texture_array) },
166 { OFF, "GL_MESA_texture_signed_rgba", F(MESA_texture_signed_rgba) },
167 { OFF, "GL_MESA_ycbcr_texture", F(MESA_ycbcr_texture) },
168 { ON, "GL_MESA_window_pos", F(ARB_window_pos) },
169 { OFF, "GL_NV_blend_square", F(NV_blend_square) },
170 { OFF, "GL_NV_conditional_render", F(NV_conditional_render) },
171 { OFF, "GL_NV_depth_clamp", F(ARB_depth_clamp) },
172 { OFF, "GL_NV_fragment_program", F(NV_fragment_program) },
173 { OFF, "GL_NV_fragment_program_option", F(NV_fragment_program_option) },
174 { ON, "GL_NV_light_max_exponent", F(NV_light_max_exponent) },
175 { OFF, "GL_NV_packed_depth_stencil", F(EXT_packed_depth_stencil) },
176 { OFF, "GL_NV_point_sprite", F(NV_point_sprite) },
177 { OFF, "GL_NV_texture_env_combine4", F(NV_texture_env_combine4) },
178 { OFF, "GL_NV_texture_rectangle", F(NV_texture_rectangle) },
179 { ON, "GL_NV_texgen_reflection", F(NV_texgen_reflection) },
180 { OFF, "GL_NV_vertex_program", F(NV_vertex_program) },
181 { OFF, "GL_NV_vertex_program1_1", F(NV_vertex_program1_1) },
182 { ON, "GL_OES_read_format", F(OES_read_format) },
183 { OFF, "GL_SGI_color_matrix", F(SGI_color_matrix) },
184 { OFF, "GL_SGI_color_table", F(SGI_color_table) },
185 { OFF, "GL_SGI_texture_color_table", F(SGI_texture_color_table) },
186 { OFF, "GL_SGIS_generate_mipmap", F(SGIS_generate_mipmap) },
187 { OFF, "GL_SGIS_texture_border_clamp", F(ARB_texture_border_clamp) },
188 { ON, "GL_SGIS_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
189 { ON, "GL_SGIS_texture_lod", F(SGIS_texture_lod) },
190 { ON, "GL_SUN_multi_draw_arrays", F(EXT_multi_draw_arrays) },
191 { OFF, "GL_S3_s3tc", F(S3_s3tc) },
192 };
193
194
195
196 /**
197 * Enable all extensions suitable for a software-only renderer.
198 * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
199 */
200 void
201 _mesa_enable_sw_extensions(GLcontext *ctx)
202 {
203 ctx->Extensions.ARB_copy_buffer = GL_TRUE;
204 ctx->Extensions.ARB_depth_clamp = GL_TRUE;
205 ctx->Extensions.ARB_depth_texture = GL_TRUE;
206 /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/
207 ctx->Extensions.ARB_draw_elements_base_vertex = GL_TRUE;
208 #if FEATURE_ARB_fragment_program
209 ctx->Extensions.ARB_fragment_program = GL_TRUE;
210 ctx->Extensions.ARB_fragment_program_shadow = GL_TRUE;
211 #endif
212 #if FEATURE_ARB_fragment_shader
213 ctx->Extensions.ARB_fragment_shader = GL_TRUE;
214 #endif
215 #if FEATURE_ARB_framebuffer_object
216 ctx->Extensions.ARB_framebuffer_object = GL_TRUE;
217 #endif
218 ctx->Extensions.ARB_half_float_pixel = GL_TRUE;
219 ctx->Extensions.ARB_imaging = GL_TRUE;
220 ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
221 ctx->Extensions.ARB_multitexture = GL_TRUE;
222 #if FEATURE_queryobj
223 ctx->Extensions.ARB_occlusion_query = GL_TRUE;
224 #endif
225 ctx->Extensions.ARB_point_sprite = GL_TRUE;
226 #if FEATURE_ARB_shader_objects
227 ctx->Extensions.ARB_shader_objects = GL_TRUE;
228 #endif
229 #if FEATURE_ARB_shading_language_100
230 ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
231 #endif
232 #if FEATURE_ARB_shading_language_120
233 ctx->Extensions.ARB_shading_language_120 = GL_TRUE;
234 #endif
235 ctx->Extensions.ARB_shadow = GL_TRUE;
236 ctx->Extensions.ARB_shadow_ambient = GL_TRUE;
237 ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
238 ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
239 ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
240 ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
241 ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
242 /*ctx->Extensions.ARB_texture_float = GL_TRUE;*/
243 ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
244 ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
245 ctx->Extensions.ARB_vertex_array_object = GL_TRUE;
246 #if FEATURE_ARB_vertex_program
247 ctx->Extensions.ARB_vertex_program = GL_TRUE;
248 #endif
249 #if FEATURE_ARB_vertex_shader
250 ctx->Extensions.ARB_vertex_shader = GL_TRUE;
251 #endif
252 #if FEATURE_ARB_vertex_buffer_object
253 /*ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;*/
254 #endif
255 #if FEATURE_ARB_sync
256 ctx->Extensions.ARB_sync = GL_TRUE;
257 #endif
258 ctx->Extensions.APPLE_vertex_array_object = GL_TRUE;
259 ctx->Extensions.ATI_envmap_bumpmap = GL_TRUE;
260 #if FEATURE_ATI_fragment_shader
261 ctx->Extensions.ATI_fragment_shader = GL_TRUE;
262 #endif
263 ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
264 ctx->Extensions.ATI_texture_mirror_once = GL_TRUE;
265 ctx->Extensions.ATI_separate_stencil = GL_TRUE;
266 ctx->Extensions.EXT_blend_color = GL_TRUE;
267 ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
268 ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
269 ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
270 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
271 ctx->Extensions.EXT_blend_subtract = GL_TRUE;
272 ctx->Extensions.EXT_convolution = GL_TRUE;
273 ctx->Extensions.EXT_depth_bounds_test = GL_TRUE;
274 ctx->Extensions.EXT_draw_buffers2 = GL_TRUE;
275 ctx->Extensions.EXT_fog_coord = GL_TRUE;
276 #if FEATURE_EXT_framebuffer_object
277 ctx->Extensions.EXT_framebuffer_object = GL_TRUE;
278 #endif
279 #if FEATURE_EXT_framebuffer_blit
280 ctx->Extensions.EXT_framebuffer_blit = GL_TRUE;
281 #endif
282 #if FEATURE_ARB_framebuffer_object
283 ctx->Extensions.EXT_framebuffer_multisample = GL_TRUE;
284 #endif
285 ctx->Extensions.EXT_histogram = GL_TRUE;
286 /*ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;*/
287 ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
288 ctx->Extensions.EXT_paletted_texture = GL_TRUE;
289 #if FEATURE_EXT_pixel_buffer_object
290 ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
291 #endif
292 ctx->Extensions.EXT_point_parameters = GL_TRUE;
293 ctx->Extensions.EXT_provoking_vertex = GL_TRUE;
294 ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
295 ctx->Extensions.EXT_secondary_color = GL_TRUE;
296 ctx->Extensions.EXT_shared_texture_palette = GL_TRUE;
297 ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
298 ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
299 ctx->Extensions.EXT_texture_env_add = GL_TRUE;
300 ctx->Extensions.EXT_texture_env_combine = GL_TRUE;
301 ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
302 ctx->Extensions.EXT_texture_mirror_clamp = GL_TRUE;
303 ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
304 #if FEATURE_EXT_texture_sRGB
305 ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
306 #endif
307 ctx->Extensions.EXT_texture_swizzle = GL_TRUE;
308 ctx->Extensions.EXT_vertex_array_bgra = GL_TRUE;
309 /*ctx->Extensions.IBM_multimode_draw_arrays = GL_TRUE;*/
310 ctx->Extensions.MESA_pack_invert = GL_TRUE;
311 ctx->Extensions.MESA_resize_buffers = GL_TRUE;
312 ctx->Extensions.MESA_texture_array = GL_TRUE;
313 ctx->Extensions.MESA_ycbcr_texture = GL_TRUE;
314 ctx->Extensions.NV_blend_square = GL_TRUE;
315 ctx->Extensions.NV_conditional_render = GL_TRUE;
316 /*ctx->Extensions.NV_light_max_exponent = GL_TRUE;*/
317 ctx->Extensions.NV_point_sprite = GL_TRUE;
318 ctx->Extensions.NV_texture_env_combine4 = GL_TRUE;
319 ctx->Extensions.NV_texture_rectangle = GL_TRUE;
320 /*ctx->Extensions.NV_texgen_reflection = GL_TRUE;*/
321 #if FEATURE_NV_vertex_program
322 ctx->Extensions.NV_vertex_program = GL_TRUE;
323 ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
324 #endif
325 #if FEATURE_NV_fragment_program
326 ctx->Extensions.NV_fragment_program = GL_TRUE;
327 #endif
328 #if FEATURE_NV_fragment_program && FEATURE_ARB_fragment_program
329 ctx->Extensions.NV_fragment_program_option = GL_TRUE;
330 #endif
331 ctx->Extensions.SGI_color_matrix = GL_TRUE;
332 ctx->Extensions.SGI_color_table = GL_TRUE;
333 ctx->Extensions.SGI_texture_color_table = GL_TRUE;
334 ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;
335 ctx->Extensions.SGIS_texture_edge_clamp = GL_TRUE;
336 #if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
337 ctx->Extensions.EXT_gpu_program_parameters = GL_TRUE;
338 #endif
339 #if FEATURE_texture_fxt1
340 _mesa_enable_extension(ctx, "GL_3DFX_texture_compression_FXT1");
341 #endif
342 #if FEATURE_texture_s3tc
343 if (ctx->Mesa_DXTn) {
344 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
345 _mesa_enable_extension(ctx, "GL_S3_s3tc");
346 }
347 #endif
348 }
349
350
351 /**
352 * Enable GL_ARB_imaging and all the EXT extensions that are subsets of it.
353 */
354 void
355 _mesa_enable_imaging_extensions(GLcontext *ctx)
356 {
357 ctx->Extensions.ARB_imaging = GL_TRUE;
358 ctx->Extensions.EXT_blend_color = GL_TRUE;
359 ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
360 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
361 ctx->Extensions.EXT_blend_subtract = GL_TRUE;
362 ctx->Extensions.EXT_convolution = GL_TRUE;
363 ctx->Extensions.EXT_histogram = GL_TRUE;
364 ctx->Extensions.SGI_color_matrix = GL_TRUE;
365 ctx->Extensions.SGI_color_table = GL_TRUE;
366 }
367
368
369
370 /**
371 * Enable all OpenGL 1.3 features and extensions.
372 * A convenience function to be called by drivers.
373 */
374 void
375 _mesa_enable_1_3_extensions(GLcontext *ctx)
376 {
377 /*ctx->Extensions.ARB_multisample = GL_TRUE;*/
378 ctx->Extensions.ARB_multitexture = GL_TRUE;
379 ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
380 /*ctx->Extensions.ARB_texture_compression = GL_TRUE;*/
381 ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
382 ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
383 ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
384 ctx->Extensions.EXT_texture_env_add = GL_TRUE;
385 /*ctx->Extensions.ARB_transpose_matrix = GL_TRUE;*/
386 }
387
388
389
390 /**
391 * Enable all OpenGL 1.4 features and extensions.
392 * A convenience function to be called by drivers.
393 */
394 void
395 _mesa_enable_1_4_extensions(GLcontext *ctx)
396 {
397 ctx->Extensions.ARB_depth_texture = GL_TRUE;
398 ctx->Extensions.ARB_shadow = GL_TRUE;
399 ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
400 ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
401 ctx->Extensions.ARB_window_pos = GL_TRUE;
402 ctx->Extensions.EXT_blend_color = GL_TRUE;
403 ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
404 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
405 ctx->Extensions.EXT_blend_subtract = GL_TRUE;
406 ctx->Extensions.EXT_fog_coord = GL_TRUE;
407 /*ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;*/
408 ctx->Extensions.EXT_point_parameters = GL_TRUE;
409 ctx->Extensions.EXT_secondary_color = GL_TRUE;
410 ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
411 ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
412 ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;
413 }
414
415
416 /**
417 * Enable all OpenGL 1.5 features and extensions.
418 * A convenience function to be called by drivers.
419 */
420 void
421 _mesa_enable_1_5_extensions(GLcontext *ctx)
422 {
423 ctx->Extensions.ARB_occlusion_query = GL_TRUE;
424 /*ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;*/
425 ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
426 }
427
428
429 /**
430 * Enable all OpenGL 2.0 features and extensions.
431 * A convenience function to be called by drivers.
432 */
433 void
434 _mesa_enable_2_0_extensions(GLcontext *ctx)
435 {
436 /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/
437 #if FEATURE_ARB_fragment_shader
438 ctx->Extensions.ARB_fragment_shader = GL_TRUE;
439 #endif
440 ctx->Extensions.ARB_point_sprite = GL_TRUE;
441 ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
442 ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
443 #if FEATURE_ARB_shader_objects
444 ctx->Extensions.ARB_shader_objects = GL_TRUE;
445 #endif
446 #if FEATURE_ARB_shading_language_100
447 ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
448 #endif
449 ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
450 #if FEATURE_ARB_vertex_shader
451 ctx->Extensions.ARB_vertex_shader = GL_TRUE;
452 #endif
453 }
454
455
456 /**
457 * Enable all OpenGL 2.1 features and extensions.
458 * A convenience function to be called by drivers.
459 */
460 void
461 _mesa_enable_2_1_extensions(GLcontext *ctx)
462 {
463 #if FEATURE_EXT_pixel_buffer_object
464 ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
465 #endif
466 #if FEATURE_EXT_texture_sRGB
467 ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
468 #endif
469 #ifdef FEATURE_ARB_shading_language_120
470 ctx->Extensions.ARB_shading_language_120 = GL_TRUE;
471 #endif
472 }
473
474
475
476 /**
477 * Either enable or disable the named extension.
478 * \return GL_TRUE for success, GL_FALSE if invalid extension name
479 */
480 static GLboolean
481 set_extension( GLcontext *ctx, const char *name, GLboolean state )
482 {
483 GLboolean *base = (GLboolean *) &ctx->Extensions;
484 GLuint i;
485
486 if (ctx->Extensions.String) {
487 /* The string was already queried - can't change it now! */
488 _mesa_problem(ctx, "Trying to enable/disable extension after glGetString(GL_EXTENSIONS): %s", name);
489 return GL_FALSE;
490 }
491
492 for (i = 0 ; i < Elements(default_extensions) ; i++) {
493 if (_mesa_strcmp(default_extensions[i].name, name) == 0) {
494 if (default_extensions[i].flag_offset) {
495 GLboolean *enabled = base + default_extensions[i].flag_offset;
496 *enabled = state;
497 }
498 return GL_TRUE;
499 }
500 }
501 return GL_FALSE;
502 }
503
504
505 /**
506 * Enable the named extension.
507 * Typically called by drivers.
508 */
509 void
510 _mesa_enable_extension( GLcontext *ctx, const char *name )
511 {
512 if (!set_extension(ctx, name, GL_TRUE))
513 _mesa_problem(ctx, "Trying to enable unknown extension: %s", name);
514 }
515
516
517 /**
518 * Disable the named extension.
519 * XXX is this really needed???
520 */
521 void
522 _mesa_disable_extension( GLcontext *ctx, const char *name )
523 {
524 if (!set_extension(ctx, name, GL_FALSE))
525 _mesa_problem(ctx, "Trying to disable unknown extension: %s", name);
526 }
527
528
529 /**
530 * Check if the i-th extension is enabled.
531 */
532 static GLboolean
533 extension_enabled(GLcontext *ctx, GLuint index)
534 {
535 const GLboolean *base = (const GLboolean *) &ctx->Extensions;
536 if (!default_extensions[index].flag_offset ||
537 *(base + default_extensions[index].flag_offset)) {
538 return GL_TRUE;
539 }
540 else {
541 return GL_FALSE;
542 }
543 }
544
545
546 /**
547 * Test if the named extension is enabled in this context.
548 */
549 GLboolean
550 _mesa_extension_is_enabled( GLcontext *ctx, const char *name )
551 {
552 GLuint i;
553
554 for (i = 0 ; i < Elements(default_extensions) ; i++) {
555 if (_mesa_strcmp(default_extensions[i].name, name) == 0) {
556 return extension_enabled(ctx, i);
557 }
558 }
559 return GL_FALSE;
560 }
561
562
563 /**
564 * Append string 'b' onto string 'a'. Free 'a' and return new string.
565 */
566 static char *
567 append(const char *a, const char *b)
568 {
569 const GLuint aLen = a ? _mesa_strlen(a) : 0;
570 const GLuint bLen = b ? _mesa_strlen(b) : 0;
571 char *s = _mesa_calloc(aLen + bLen + 1);
572 if (s) {
573 if (a)
574 _mesa_memcpy(s, a, aLen);
575 if (b)
576 _mesa_memcpy(s + aLen, b, bLen);
577 s[aLen + bLen] = '\0';
578 }
579 if (a)
580 _mesa_free((void *) a);
581 return s;
582 }
583
584
585 /**
586 * Check the MESA_EXTENSION_OVERRIDE env var.
587 * For extension names that are recognized, turn them on. For extension
588 * names that are recognized and prefixed with '-', turn them off.
589 * Return a string of the unknown/leftover names.
590 */
591 static const char *
592 get_extension_override( GLcontext *ctx )
593 {
594 const char *envExt = _mesa_getenv("MESA_EXTENSION_OVERRIDE");
595 char *extraExt = NULL;
596 char ext[1000];
597 GLuint extLen = 0;
598 GLuint i;
599 GLboolean disableExt = GL_FALSE;
600
601 if (!envExt)
602 return NULL;
603
604 for (i = 0; ; i++) {
605 if (envExt[i] == '\0' || envExt[i] == ' ') {
606 /* terminate/process 'ext' if extLen > 0 */
607 if (extLen > 0) {
608 assert(extLen < sizeof(ext));
609 /* enable extension named by 'ext' */
610 ext[extLen] = 0;
611 if (!set_extension(ctx, ext, !disableExt)) {
612 /* unknown extension name, append it to extraExt */
613 if (extraExt) {
614 extraExt = append(extraExt, " ");
615 }
616 extraExt = append(extraExt, ext);
617 }
618 extLen = 0;
619 disableExt = GL_FALSE;
620 }
621 if (envExt[i] == '\0')
622 break;
623 }
624 else if (envExt[i] == '-') {
625 disableExt = GL_TRUE;
626 }
627 else {
628 /* accumulate this non-space character */
629 ext[extLen++] = envExt[i];
630 }
631 }
632
633 return extraExt;
634 }
635
636
637 /**
638 * Run through the default_extensions array above and set the
639 * ctx->Extensions.ARB/EXT_* flags accordingly.
640 * To be called during context initialization.
641 */
642 void
643 _mesa_init_extensions( GLcontext *ctx )
644 {
645 GLboolean *base = (GLboolean *) &ctx->Extensions;
646 GLuint i;
647
648 for (i = 0 ; i < Elements(default_extensions) ; i++) {
649 if (default_extensions[i].enabled &&
650 default_extensions[i].flag_offset) {
651 *(base + default_extensions[i].flag_offset) = GL_TRUE;
652 }
653 }
654 }
655
656
657 /**
658 * Construct the GL_EXTENSIONS string. Called the first time that
659 * glGetString(GL_EXTENSIONS) is called.
660 */
661 GLubyte *
662 _mesa_make_extension_string( GLcontext *ctx )
663 {
664 const char *extraExt = get_extension_override(ctx);
665 GLuint extStrLen = 0;
666 char *s;
667 GLuint i;
668
669 /* first, compute length of the extension string */
670 for (i = 0 ; i < Elements(default_extensions) ; i++) {
671 if (extension_enabled(ctx, i)) {
672 extStrLen += (GLuint)_mesa_strlen(default_extensions[i].name) + 1;
673 }
674 }
675
676 if (extraExt)
677 extStrLen += _mesa_strlen(extraExt) + 1; /* +1 for space */
678
679 /* allocate the extension string */
680 s = (char *) _mesa_malloc(extStrLen);
681 if (!s)
682 return NULL;
683
684 /* second, build the extension string */
685 extStrLen = 0;
686 for (i = 0 ; i < Elements(default_extensions) ; i++) {
687 if (extension_enabled(ctx, i)) {
688 GLuint len = (GLuint)_mesa_strlen(default_extensions[i].name);
689 _mesa_memcpy(s + extStrLen, default_extensions[i].name, len);
690 extStrLen += len;
691 s[extStrLen] = ' ';
692 extStrLen++;
693 }
694 }
695 ASSERT(extStrLen > 0);
696
697 s[extStrLen - 1] = 0; /* -1 to overwrite trailing the ' ' */
698
699 if (extraExt) {
700 s = append(s, " ");
701 s = append(s, extraExt);
702 }
703
704 return (GLubyte *) s;
705 }
706
707
708 /**
709 * Return number of enabled extensions.
710 */
711 GLuint
712 _mesa_get_extension_count(GLcontext *ctx)
713 {
714 GLuint i;
715
716 /* only count once */
717 if (!ctx->Extensions.Count) {
718 for (i = 0; i < Elements(default_extensions); i++) {
719 if (extension_enabled(ctx, i)) {
720 ctx->Extensions.Count++;
721 }
722 }
723 }
724
725 if (0)
726 _mesa_debug(ctx, "%u of %d extensions enabled\n", ctx->Extensions.Count,
727 Elements(default_extensions));
728
729 return ctx->Extensions.Count;
730 }
731
732
733 /**
734 * Return name of i-th enabled extension
735 */
736 const GLubyte *
737 _mesa_get_enabled_extension(GLcontext *ctx, GLuint index)
738 {
739 GLuint i;
740
741 for (i = 0; i < Elements(default_extensions); i++) {
742 if (extension_enabled(ctx, i)) {
743 if (index == 0)
744 return (const GLubyte *) default_extensions[i].name;
745 index--;
746 }
747 }
748
749 return NULL;
750 }