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