[MESA]
[reactos.git] / reactos / dll / opengl / mesa / 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 /**
28 * \file
29 * \brief Extension handling
30 */
31
32
33 #include "glheader.h"
34 #include "imports.h"
35 #include "context.h"
36 #include "extensions.h"
37 #include "mfeatures.h"
38 #include "mtypes.h"
39
40 #define ALIGN(value, alignment) (((value) + alignment - 1) & ~(alignment - 1))
41
42 /**
43 * \brief An element of the \c extension_table.
44 */
45 struct extension {
46 /** Name of extension, such as "GL_ARB_depth_clamp". */
47 const char *name;
48
49 /** Offset (in bytes) of the corresponding member in struct gl_extensions. */
50 size_t offset;
51
52 /** Year the extension was proposed or approved. Used to sort the
53 * extension string chronologically. */
54 uint16_t year;
55 };
56
57
58 /**
59 * Given a member \c x of struct gl_extensions, return offset of
60 * \c x in bytes.
61 */
62 #define o(x) offsetof(struct gl_extensions, x)
63
64
65 /**
66 * \brief Table of supported OpenGL extensions for all API's.
67 */
68 static const struct extension extension_table[] = {
69 /* ARB Extensions */
70 { "GL_ARB_ES2_compatibility", o(ARB_ES2_compatibility), 2009 },
71 { "GL_ARB_color_buffer_float", o(ARB_color_buffer_float), 2004 },
72 { "GL_ARB_copy_buffer", o(ARB_copy_buffer), 2008 },
73 { "GL_ARB_conservative_depth", o(ARB_conservative_depth), 2011 },
74 { "GL_ARB_depth_buffer_float", o(ARB_depth_buffer_float), 2008 },
75 { "GL_ARB_draw_buffers", o(dummy_true), 2002 },
76 { "GL_ARB_draw_buffers_blend", o(ARB_draw_buffers_blend), 2009 },
77 { "GL_ARB_fragment_program", o(ARB_fragment_program), 2002 },
78 { "GL_ARB_fragment_program_shadow", o(ARB_fragment_program_shadow), 2003 },
79 { "GL_ARB_fragment_shader", o(ARB_fragment_shader), 2002 },
80 { "GL_ARB_framebuffer_object", o(ARB_framebuffer_object), 2005 },
81 { "GL_ARB_framebuffer_sRGB", o(EXT_framebuffer_sRGB), 1998 },
82 { "GL_ARB_half_float_pixel", o(ARB_half_float_pixel), 2003 },
83 { "GL_ARB_half_float_vertex", o(ARB_half_float_vertex), 2008 },
84 { "GL_ARB_map_buffer_range", o(ARB_map_buffer_range), 2008 },
85 { "GL_ARB_multisample", o(dummy_true), 1994 },
86 { "GL_ARB_multitexture", o(dummy_true), 1998 },
87 { "GL_ARB_pixel_buffer_object", o(EXT_pixel_buffer_object), 2004 },
88 { "GL_ARB_point_parameters", o(EXT_point_parameters), 1997 },
89 { "GL_ARB_point_sprite", o(ARB_point_sprite), 2003 },
90 { "GL_ARB_robustness", o(dummy_true), 2010 },
91 { "GL_ARB_shader_objects", o(ARB_shader_objects), 2002 },
92 { "GL_ARB_shader_stencil_export", o(ARB_shader_stencil_export), 2009 },
93 { "GL_ARB_shader_texture_lod", o(ARB_shader_texture_lod), 2009 },
94 { "GL_ARB_shading_language_100", o(ARB_shading_language_100), 2003 },
95 { "GL_ARB_texture_border_clamp", o(ARB_texture_border_clamp), 2000 },
96 { "GL_ARB_texture_buffer_object", o(ARB_texture_buffer_object), 2008 },
97 { "GL_ARB_texture_compression", o(dummy_true), 2000 },
98 { "GL_ARB_texture_compression_rgtc", o(ARB_texture_compression_rgtc), 2004 },
99 { "GL_ARB_texture_cube_map", o(ARB_texture_cube_map), 1999 },
100 { "GL_ARB_texture_env_add", o(dummy_true), 1999 },
101 { "GL_ARB_texture_env_combine", o(ARB_texture_env_combine), 2001 },
102 { "GL_ARB_texture_env_crossbar", o(ARB_texture_env_crossbar), 2001 },
103 { "GL_ARB_texture_env_dot3", o(ARB_texture_env_dot3), 2001 },
104 { "GL_ARB_texture_float", o(ARB_texture_float), 2004 },
105 { "GL_ARB_texture_mirrored_repeat", o(dummy_true), 2001 },
106 { "GL_ARB_texture_non_power_of_two", o(ARB_texture_non_power_of_two), 2003 },
107 { "GL_ARB_texture_rectangle", o(NV_texture_rectangle), 2004 },
108 { "GL_ARB_texture_rg", o(ARB_texture_rg), 2008 },
109 { "GL_ARB_texture_storage", o(ARB_texture_storage), 2011 },
110 { "GL_ARB_transpose_matrix", o(ARB_transpose_matrix), 1999 },
111 { "GL_ARB_uniform_buffer_object", o(ARB_uniform_buffer_object), 2002 },
112 { "GL_ARB_vertex_array_object", o(ARB_vertex_array_object), 2006 },
113 { "GL_ARB_vertex_buffer_object", o(dummy_true), 2003 },
114 { "GL_ARB_vertex_program", o(ARB_vertex_program), 2002 },
115 { "GL_ARB_vertex_shader", o(ARB_vertex_shader), 2002 },
116 { "GL_ARB_window_pos", o(ARB_window_pos), 2001 },
117 /* EXT extensions */
118 { "GL_EXT_abgr", o(dummy_true), 1995 },
119 { "GL_EXT_bgra", o(dummy_true), 1995 },
120 { "GL_EXT_blend_color", o(EXT_blend_color), 1995 },
121 { "GL_EXT_blend_equation_separate", o(EXT_blend_equation_separate), 2003 },
122 { "GL_EXT_blend_func_separate", o(EXT_blend_func_separate), 1999 },
123 { "GL_EXT_blend_minmax", o(EXT_blend_minmax), 1995 },
124 { "GL_EXT_blend_subtract", o(dummy_true), 1995 },
125 { "GL_EXT_clip_volume_hint", o(EXT_clip_volume_hint), 1996 },
126 { "GL_EXT_compiled_vertex_array", o(EXT_compiled_vertex_array), 1996 },
127 { "GL_EXT_copy_texture", o(dummy_true), 1995 },
128 { "GL_EXT_depth_bounds_test", o(EXT_depth_bounds_test), 2002 },
129 { "GL_EXT_draw_instanced", o(ARB_draw_instanced), 2006 },
130 { "GL_EXT_draw_range_elements", o(EXT_draw_range_elements), 1997 },
131 { "GL_EXT_fog_coord", o(EXT_fog_coord), 1999 },
132 { "GL_EXT_framebuffer_blit", o(EXT_framebuffer_blit), 2005 },
133 { "GL_EXT_framebuffer_multisample", o(EXT_framebuffer_multisample), 2005 },
134 { "GL_EXT_framebuffer_object", o(EXT_framebuffer_object), 2000 },
135 { "GL_EXT_framebuffer_sRGB", o(EXT_framebuffer_sRGB), 1998 },
136 { "GL_EXT_gpu_program_parameters", o(EXT_gpu_program_parameters), 2006 },
137 { "GL_EXT_gpu_shader4", o(EXT_gpu_shader4), 2006 },
138 { "GL_EXT_multi_draw_arrays", o(dummy_true), 1999 },
139 { "GL_EXT_packed_depth_stencil", o(EXT_packed_depth_stencil), 2005 },
140 { "GL_EXT_packed_pixels", o(EXT_packed_pixels), 1997 },
141 { "GL_EXT_pixel_buffer_object", o(EXT_pixel_buffer_object), 2004 },
142 { "GL_EXT_point_parameters", o(EXT_point_parameters), 1997 },
143 { "GL_EXT_polygon_offset", o(dummy_true), 1995 },
144 { "GL_EXT_rescale_normal", o(EXT_rescale_normal), 1997 },
145 { "GL_EXT_secondary_color", o(EXT_secondary_color), 1999 },
146 { "GL_EXT_separate_shader_objects", o(EXT_separate_shader_objects), 2008 },
147 { "GL_EXT_separate_specular_color", o(EXT_separate_specular_color), 1997 },
148 { "GL_EXT_shadow_funcs", o(EXT_shadow_funcs), 2002 },
149 { "GL_EXT_stencil_two_side", o(EXT_stencil_two_side), 2001 },
150 { "GL_EXT_stencil_wrap", o(dummy_true), 2002 },
151 { "GL_EXT_subtexture", o(dummy_true), 1995 },
152 { "GL_EXT_texture3D", o(EXT_texture3D), 1996 },
153 { "GL_EXT_texture_array", o(EXT_texture_array), 2006 },
154 { "GL_EXT_texture_compression_dxt1", o(EXT_texture_compression_s3tc), 2004 },
155 { "GL_EXT_texture_compression_latc", o(EXT_texture_compression_latc), 2006 },
156 { "GL_EXT_texture_compression_rgtc", o(ARB_texture_compression_rgtc), 2004 },
157 { "GL_EXT_texture_compression_s3tc", o(EXT_texture_compression_s3tc), 2000 },
158 { "GL_EXT_texture_cube_map", o(ARB_texture_cube_map), 2001 },
159 { "GL_EXT_texture_edge_clamp", o(dummy_true), 1997 },
160 { "GL_EXT_texture_env_add", o(dummy_true), 1999 },
161 { "GL_EXT_texture_env_combine", o(dummy_true), 2000 },
162 { "GL_EXT_texture_env_dot3", o(EXT_texture_env_dot3), 2000 },
163 { "GL_EXT_texture_filter_anisotropic", o(EXT_texture_filter_anisotropic), 1999 },
164 { "GL_EXT_texture_integer", o(EXT_texture_integer), 2006 },
165 { "GL_EXT_texture_lod_bias", o(dummy_true), 1999 },
166 { "GL_EXT_texture_mirror_clamp", o(EXT_texture_mirror_clamp), 2004 },
167 { "GL_EXT_texture_object", o(dummy_true), 1995 },
168 { "GL_EXT_texture", o(dummy_true), 1996 },
169 { "GL_EXT_texture_rectangle", o(NV_texture_rectangle), 2004 },
170 { "GL_EXT_texture_snorm", o(EXT_texture_snorm), 2009 },
171 { "GL_EXT_texture_sRGB", o(EXT_texture_sRGB), 2004 },
172 { "GL_EXT_vertex_array", o(dummy_true), 1995 },
173
174 /* Vendor extensions */
175 { "GL_3DFX_texture_compression_FXT1", o(TDFX_texture_compression_FXT1), 1999 },
176 { "GL_AMD_conservative_depth", o(ARB_conservative_depth), 2009 },
177 { "GL_AMD_draw_buffers_blend", o(ARB_draw_buffers_blend), 2009 },
178 { "GL_AMD_shader_stencil_export", o(ARB_shader_stencil_export), 2009 },
179 { "GL_APPLE_object_purgeable", o(APPLE_object_purgeable), 2006 },
180 { "GL_APPLE_packed_pixels", o(APPLE_packed_pixels), 2002 },
181 { "GL_APPLE_vertex_array_object", o(APPLE_vertex_array_object), 2002 },
182 { "GL_ATI_blend_equation_separate", o(EXT_blend_equation_separate), 2003 },
183 { "GL_ATI_draw_buffers", o(dummy_true), 2002 },
184 { "GL_ATI_envmap_bumpmap", o(ATI_envmap_bumpmap), 2001 },
185 { "GL_ATI_separate_stencil", o(ATI_separate_stencil), 2006 },
186 { "GL_ATI_texture_compression_3dc", o(ATI_texture_compression_3dc), 2004 },
187 { "GL_ATI_texture_env_combine3", o(ATI_texture_env_combine3), 2002 },
188 { "GL_ATI_texture_float", o(ARB_texture_float), 2002 },
189 { "GL_ATI_texture_mirror_once", o(ATI_texture_mirror_once), 2006 },
190 { "GL_IBM_multimode_draw_arrays", o(IBM_multimode_draw_arrays), 1998 },
191 { "GL_IBM_rasterpos_clip", o(IBM_rasterpos_clip), 1996 },
192 { "GL_IBM_texture_mirrored_repeat", o(dummy_true), 1998 },
193 { "GL_INGR_blend_func_separate", o(EXT_blend_func_separate), 1999 },
194 { "GL_MESA_pack_invert", o(MESA_pack_invert), 2002 },
195 { "GL_MESA_resize_buffers", o(MESA_resize_buffers), 1999 },
196 { "GL_MESA_texture_array", o(MESA_texture_array), 2007 },
197 { "GL_MESA_texture_signed_rgba", o(EXT_texture_snorm), 2009 },
198 { "GL_MESA_window_pos", o(ARB_window_pos), 2000 },
199 { "GL_MESA_ycbcr_texture", o(MESA_ycbcr_texture), 2002 },
200 { "GL_NV_blend_square", o(NV_blend_square), 1999 },
201 { "GL_NV_fog_distance", o(NV_fog_distance), 2001 },
202 { "GL_NV_fragment_program", o(NV_fragment_program), 2001 },
203 { "GL_NV_fragment_program_option", o(NV_fragment_program_option), 2005 },
204 { "GL_NV_light_max_exponent", o(NV_light_max_exponent), 1999 },
205 { "GL_NV_packed_depth_stencil", o(EXT_packed_depth_stencil), 2000 },
206 { "GL_NV_point_sprite", o(NV_point_sprite), 2001 },
207 { "GL_NV_primitive_restart", o(NV_primitive_restart), 2002 },
208 { "GL_NV_texgen_reflection", o(NV_texgen_reflection), 1999 },
209 { "GL_NV_texture_barrier", o(NV_texture_barrier), 2009 },
210 { "GL_NV_texture_env_combine4", o(NV_texture_env_combine4), 1999 },
211 { "GL_NV_texture_rectangle", o(NV_texture_rectangle), 2000 },
212 { "GL_NV_vertex_program1_1", o(NV_vertex_program1_1), 2001 },
213 { "GL_NV_vertex_program", o(NV_vertex_program), 2000 },
214 { "GL_S3_s3tc", o(S3_s3tc), 1999 },
215 { "GL_SGIS_generate_mipmap", o(dummy_true), 1997 },
216 { "GL_SGIS_texture_border_clamp", o(ARB_texture_border_clamp), 1997 },
217 { "GL_SGIS_texture_edge_clamp", o(dummy_true), 1997 },
218 { "GL_SGIS_texture_lod", o(SGIS_texture_lod), 1997 },
219 { "GL_SUN_multi_draw_arrays", o(dummy_true), 1999 },
220
221 { 0, 0, 0},
222 };
223
224
225 /**
226 * Given an extension name, lookup up the corresponding member of struct
227 * gl_extensions and return that member's offset (in bytes). If the name is
228 * not found in the \c extension_table, return 0.
229 *
230 * \param name Name of extension.
231 * \return Offset of member in struct gl_extensions.
232 */
233 static size_t
234 name_to_offset(const char* name)
235 {
236 const struct extension *i;
237
238 if (name == 0)
239 return 0;
240
241 for (i = extension_table; i->name != 0; ++i) {
242 if (strcmp(name, i->name) == 0)
243 return i->offset;
244 }
245
246 return 0;
247 }
248
249
250 /**
251 * \brief Extensions enabled by default.
252 *
253 * These extensions are enabled by _mesa_init_extensions().
254 *
255 * XXX: Should these defaults also apply to GLES?
256 */
257 static const size_t default_extensions[] = {
258 o(ARB_copy_buffer),
259 o(ARB_transpose_matrix),
260 o(ARB_window_pos),
261
262 o(EXT_compiled_vertex_array),
263 o(EXT_draw_range_elements),
264 o(EXT_packed_pixels),
265 o(EXT_rescale_normal),
266 o(EXT_separate_specular_color),
267 o(EXT_texture3D),
268
269 /* Vendor Extensions */
270 o(APPLE_packed_pixels),
271 o(IBM_multimode_draw_arrays),
272 o(IBM_rasterpos_clip),
273 o(NV_light_max_exponent),
274 o(NV_texgen_reflection),
275 o(SGIS_texture_lod),
276
277 0,
278 };
279
280
281 /**
282 * Enable all extensions suitable for a software-only renderer.
283 * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
284 */
285 void
286 _mesa_enable_sw_extensions(struct gl_context *ctx)
287 {
288 /*ctx->Extensions.ARB_copy_buffer = GL_TRUE;*/
289 ctx->Extensions.ARB_draw_instanced = GL_TRUE;
290 #if FEATURE_ARB_fragment_program
291 ctx->Extensions.ARB_fragment_program = GL_TRUE;
292 ctx->Extensions.ARB_fragment_program_shadow = GL_TRUE;
293 #endif
294 #if FEATURE_ARB_fragment_shader
295 ctx->Extensions.ARB_fragment_shader = GL_TRUE;
296 #endif
297 #if FEATURE_ARB_framebuffer_object
298 ctx->Extensions.ARB_framebuffer_object = GL_TRUE;
299 #endif
300 ctx->Extensions.ARB_half_float_pixel = GL_TRUE;
301 ctx->Extensions.ARB_half_float_vertex = GL_TRUE;
302 ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
303 ctx->Extensions.ARB_point_sprite = GL_TRUE;
304 #if FEATURE_ARB_shader_objects
305 ctx->Extensions.ARB_shader_objects = GL_TRUE;
306 ctx->Extensions.EXT_separate_shader_objects = GL_TRUE;
307 #endif
308 #if FEATURE_ARB_shading_language_100
309 ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
310 #endif
311 ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
312 ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
313 ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
314 ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
315 ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
316 /*ctx->Extensions.ARB_texture_float = GL_TRUE;*/
317 ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
318 ctx->Extensions.ARB_texture_rg = GL_TRUE;
319 ctx->Extensions.ARB_texture_compression_rgtc = GL_TRUE;
320 ctx->Extensions.ARB_texture_storage = GL_TRUE;
321 ctx->Extensions.ARB_vertex_array_object = GL_TRUE;
322 #if FEATURE_ARB_vertex_program
323 ctx->Extensions.ARB_vertex_program = GL_TRUE;
324 #endif
325 #if FEATURE_ARB_vertex_shader
326 ctx->Extensions.ARB_vertex_shader = GL_TRUE;
327 #endif
328 ctx->Extensions.APPLE_vertex_array_object = GL_TRUE;
329 #if FEATURE_APPLE_object_purgeable
330 ctx->Extensions.APPLE_object_purgeable = GL_TRUE;
331 #endif
332 ctx->Extensions.ATI_envmap_bumpmap = GL_TRUE;
333 ctx->Extensions.ATI_texture_compression_3dc = GL_TRUE;
334 ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
335 ctx->Extensions.ATI_texture_mirror_once = GL_TRUE;
336 ctx->Extensions.ATI_separate_stencil = GL_TRUE;
337 ctx->Extensions.EXT_blend_color = GL_TRUE;
338 ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
339 ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
340 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
341 ctx->Extensions.EXT_depth_bounds_test = GL_TRUE;
342 ctx->Extensions.EXT_fog_coord = GL_TRUE;
343 #if FEATURE_EXT_framebuffer_object
344 ctx->Extensions.EXT_framebuffer_object = GL_TRUE;
345 #endif
346 #if FEATURE_EXT_framebuffer_blit
347 ctx->Extensions.EXT_framebuffer_blit = GL_TRUE;
348 #endif
349 #if FEATURE_ARB_framebuffer_object
350 ctx->Extensions.EXT_framebuffer_multisample = GL_TRUE;
351 #endif
352 ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
353 #if FEATURE_EXT_pixel_buffer_object
354 ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
355 #endif
356 ctx->Extensions.EXT_point_parameters = GL_TRUE;
357 ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
358 ctx->Extensions.EXT_secondary_color = GL_TRUE;
359 ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
360 ctx->Extensions.EXT_texture_array = GL_TRUE;
361 ctx->Extensions.EXT_texture_compression_latc = GL_TRUE;
362 ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
363 ctx->Extensions.EXT_texture_filter_anisotropic = GL_TRUE;
364 ctx->Extensions.EXT_texture_mirror_clamp = GL_TRUE;
365 #if FEATURE_EXT_texture_sRGB
366 ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
367 #endif
368 /*ctx->Extensions.IBM_multimode_draw_arrays = GL_TRUE;*/
369 ctx->Extensions.MESA_pack_invert = GL_TRUE;
370 ctx->Extensions.MESA_resize_buffers = GL_TRUE;
371 ctx->Extensions.MESA_texture_array = GL_TRUE;
372 ctx->Extensions.MESA_ycbcr_texture = GL_TRUE;
373 ctx->Extensions.NV_blend_square = GL_TRUE;
374 /*ctx->Extensions.NV_light_max_exponent = GL_TRUE;*/
375 ctx->Extensions.NV_point_sprite = GL_TRUE;
376 ctx->Extensions.NV_texture_env_combine4 = GL_TRUE;
377 ctx->Extensions.NV_texture_rectangle = GL_TRUE;
378 /*ctx->Extensions.NV_texgen_reflection = GL_TRUE;*/
379 #if FEATURE_NV_vertex_program
380 ctx->Extensions.NV_vertex_program = GL_TRUE;
381 ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
382 #endif
383 #if FEATURE_NV_fragment_program
384 ctx->Extensions.NV_fragment_program = GL_TRUE;
385 #endif
386 #if FEATURE_NV_fragment_program && FEATURE_ARB_fragment_program
387 ctx->Extensions.NV_fragment_program_option = GL_TRUE;
388 #endif
389 #if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
390 ctx->Extensions.EXT_gpu_program_parameters = GL_TRUE;
391 #endif
392 #if FEATURE_texture_fxt1
393 _mesa_enable_extension(ctx, "GL_3DFX_texture_compression_FXT1");
394 #endif
395 #if FEATURE_texture_s3tc
396 if (ctx->Mesa_DXTn) {
397 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
398 _mesa_enable_extension(ctx, "GL_S3_s3tc");
399 }
400 #endif
401 }
402
403
404 /**
405 * Enable all OpenGL 1.3 features and extensions.
406 * A convenience function to be called by drivers.
407 */
408 void
409 _mesa_enable_1_3_extensions(struct gl_context *ctx)
410 {
411 ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
412 ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
413 ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
414 ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
415 /*ctx->Extensions.ARB_transpose_matrix = GL_TRUE;*/
416 }
417
418
419
420 /**
421 * Enable all OpenGL 1.4 features and extensions.
422 * A convenience function to be called by drivers.
423 */
424 void
425 _mesa_enable_1_4_extensions(struct gl_context *ctx)
426 {
427 ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
428 ctx->Extensions.ARB_window_pos = GL_TRUE;
429 ctx->Extensions.EXT_blend_color = GL_TRUE;
430 ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
431 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
432 ctx->Extensions.EXT_fog_coord = GL_TRUE;
433 ctx->Extensions.EXT_point_parameters = GL_TRUE;
434 ctx->Extensions.EXT_secondary_color = GL_TRUE;
435 }
436
437
438 /**
439 * Enable all OpenGL 1.5 features and extensions.
440 * A convenience function to be called by drivers.
441 */
442 void
443 _mesa_enable_1_5_extensions(struct gl_context *ctx)
444 {
445 ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
446 }
447
448
449 /**
450 * Enable all OpenGL 2.0 features and extensions.
451 * A convenience function to be called by drivers.
452 */
453 void
454 _mesa_enable_2_0_extensions(struct gl_context *ctx)
455 {
456 #if FEATURE_ARB_fragment_shader
457 ctx->Extensions.ARB_fragment_shader = GL_TRUE;
458 #endif
459 ctx->Extensions.ARB_point_sprite = GL_TRUE;
460 ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
461 ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
462 #if FEATURE_ARB_shader_objects
463 ctx->Extensions.ARB_shader_objects = GL_TRUE;
464 #endif
465 #if FEATURE_ARB_shading_language_100
466 ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
467 #endif
468 ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
469 #if FEATURE_ARB_vertex_shader
470 ctx->Extensions.ARB_vertex_shader = GL_TRUE;
471 #endif
472 }
473
474
475 /**
476 * Enable all OpenGL 2.1 features and extensions.
477 * A convenience function to be called by drivers.
478 */
479 void
480 _mesa_enable_2_1_extensions(struct gl_context *ctx)
481 {
482 #if FEATURE_EXT_pixel_buffer_object
483 ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
484 #endif
485 #if FEATURE_EXT_texture_sRGB
486 ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
487 #endif
488 }
489
490
491 /**
492 * Either enable or disable the named extension.
493 * \return GL_TRUE for success, GL_FALSE if invalid extension name
494 */
495 static GLboolean
496 set_extension( struct gl_context *ctx, const char *name, GLboolean state )
497 {
498 size_t offset;
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 offset = name_to_offset(name);
507 if (offset == 0) {
508 _mesa_problem(ctx, "Trying to enable/disable unknown extension %s",
509 name);
510 return GL_FALSE;
511 } else if (offset == o(dummy_true) && state == GL_FALSE) {
512 _mesa_problem(ctx, "Trying to disable a permanently enabled extension: "
513 "%s", name);
514 return GL_FALSE;
515 } else {
516 GLboolean *base = (GLboolean *) &ctx->Extensions;
517 base[offset] = state;
518 return GL_TRUE;
519 }
520 }
521
522
523 /**
524 * Enable the named extension.
525 * Typically called by drivers.
526 */
527 void
528 _mesa_enable_extension( struct gl_context *ctx, const char *name )
529 {
530 if (!set_extension(ctx, name, GL_TRUE))
531 _mesa_problem(ctx, "Trying to enable unknown extension: %s", name);
532 }
533
534
535 /**
536 * Disable the named extension.
537 * XXX is this really needed???
538 */
539 void
540 _mesa_disable_extension( struct gl_context *ctx, const char *name )
541 {
542 if (!set_extension(ctx, name, GL_FALSE))
543 _mesa_problem(ctx, "Trying to disable unknown extension: %s", name);
544 }
545
546
547 /**
548 * Test if the named extension is enabled in this context.
549 */
550 GLboolean
551 _mesa_extension_is_enabled( struct gl_context *ctx, const char *name )
552 {
553 size_t offset;
554 GLboolean *base;
555
556 if (name == 0)
557 return GL_FALSE;
558
559 offset = name_to_offset(name);
560 if (offset == 0)
561 return GL_FALSE;
562 base = (GLboolean *) &ctx->Extensions;
563 return base[offset];
564 }
565
566
567 /**
568 * \brief Apply the \c MESA_EXTENSION_OVERRIDE environment variable.
569 *
570 * \c MESA_EXTENSION_OVERRIDE is a space-separated list of extensions to
571 * enable or disable. The list is processed thus:
572 * - Enable recognized extension names that are prefixed with '+'.
573 * - Disable recognized extension names that are prefixed with '-'.
574 * - Enable recognized extension names that are not prefixed.
575 * - Collect unrecognized extension names in a new string.
576 *
577 * \return Space-separated list of unrecognized extension names (which must
578 * be freed). Does not return \c NULL.
579 */
580 static char *
581 get_extension_override( struct gl_context *ctx )
582 {
583 const char *env_const = _mesa_getenv("MESA_EXTENSION_OVERRIDE");
584 char *env;
585 char *ext;
586 char *extra_exts;
587 int len;
588
589 if (env_const == NULL) {
590 /* Return the empty string rather than NULL. This simplifies the logic
591 * of client functions. */
592 return calloc(4, sizeof(char));
593 }
594
595 /* extra_exts: List of unrecognized extensions. */
596 extra_exts = calloc(ALIGN(strlen(env_const) + 2, 4), sizeof(char));
597
598 /* Copy env_const because strtok() is destructive. */
599 env = strdup(env_const);
600 for (ext = strtok(env, " "); ext != NULL; ext = strtok(NULL, " ")) {
601 int enable;
602 int recognized;
603 switch (ext[0]) {
604 case '+':
605 enable = 1;
606 ++ext;
607 break;
608 case '-':
609 enable = 0;
610 ++ext;
611 break;
612 default:
613 enable = 1;
614 break;
615 }
616 recognized = set_extension(ctx, ext, enable);
617 if (!recognized) {
618 strcat(extra_exts, ext);
619 strcat(extra_exts, " ");
620 }
621 }
622
623 free(env);
624
625 /* Remove trailing space. */
626 len = strlen(extra_exts);
627 if (extra_exts[len - 1] == ' ')
628 extra_exts[len - 1] = '\0';
629
630 return extra_exts;
631 }
632
633
634 /**
635 * \brief Initialize extension tables and enable default extensions.
636 *
637 * This should be called during context initialization.
638 * Note: Sets gl_extensions.dummy_true to true.
639 */
640 void
641 _mesa_init_extensions( struct gl_context *ctx )
642 {
643 GLboolean *base = (GLboolean *) &ctx->Extensions;
644 GLboolean *sentinel = base + o(extension_sentinel);
645 GLboolean *i;
646 const size_t *j;
647
648 /* First, turn all extensions off. */
649 for (i = base; i != sentinel; ++i)
650 *i = GL_FALSE;
651
652 /* Then, selectively turn default extensions on. */
653 ctx->Extensions.dummy_true = GL_TRUE;
654 for (j = default_extensions; *j != 0; ++j)
655 base[*j] = GL_TRUE;
656 }
657
658
659 typedef unsigned short extension_index;
660
661
662 /**
663 * Compare two entries of the extensions table. Sorts first by year,
664 * then by name.
665 *
666 * Arguments are indices into extension_table.
667 */
668 static int
669 extension_compare(const void *p1, const void *p2)
670 {
671 extension_index i1 = * (const extension_index *) p1;
672 extension_index i2 = * (const extension_index *) p2;
673 const struct extension *e1 = &extension_table[i1];
674 const struct extension *e2 = &extension_table[i2];
675 int res;
676
677 res = (int)e1->year - (int)e2->year;
678
679 if (res == 0) {
680 res = strcmp(e1->name, e2->name);
681 }
682
683 return res;
684 }
685
686
687 /**
688 * Construct the GL_EXTENSIONS string. Called the first time that
689 * glGetString(GL_EXTENSIONS) is called.
690 */
691 GLubyte*
692 _mesa_make_extension_string(struct gl_context *ctx)
693 {
694 /* The extension string. */
695 char *exts = 0;
696 /* Length of extension string. */
697 size_t length = 0;
698 /* Number of extensions */
699 unsigned count;
700 /* Indices of the extensions sorted by year */
701 extension_index *extension_indices;
702 /* String of extra extensions. */
703 char *extra_extensions = get_extension_override(ctx);
704 GLboolean *base = (GLboolean *) &ctx->Extensions;
705 const struct extension *i;
706 unsigned j;
707 unsigned maxYear = ~0;
708
709 /* Check if the MESA_EXTENSION_MAX_YEAR env var is set */
710 {
711 const char *env = getenv("MESA_EXTENSION_MAX_YEAR");
712 if (env) {
713 maxYear = atoi(env);
714 _mesa_debug(ctx, "Note: limiting GL extensions to %u or earlier\n",
715 maxYear);
716 }
717 }
718
719 /* Compute length of the extension string. */
720 count = 0;
721 for (i = extension_table; i->name != 0; ++i) {
722 if (base[i->offset] &&
723 i->year <= maxYear) {
724 length += strlen(i->name) + 1; /* +1 for space */
725 ++count;
726 }
727 }
728 if (extra_extensions != NULL)
729 length += 1 + strlen(extra_extensions); /* +1 for space */
730
731 exts = (char *) calloc(ALIGN(length + 1, 4), sizeof(char));
732 if (exts == NULL) {
733 free(extra_extensions);
734 return NULL;
735 }
736
737 extension_indices = malloc(count * sizeof(extension_index));
738 if (extension_indices == NULL) {
739 free(exts);
740 free(extra_extensions);
741 return NULL;
742 }
743
744 /* Sort extensions in chronological order because certain old applications (e.g.,
745 * Quake3 demo) store the extension list in a static size buffer so chronologically
746 * order ensure that the extensions that such applications expect will fit into
747 * that buffer.
748 */
749 j = 0;
750 for (i = extension_table; i->name != 0; ++i) {
751 if (base[i->offset] &&
752 i->year <= maxYear) {
753 extension_indices[j++] = i - extension_table;
754 }
755 }
756 assert(j == count);
757 qsort(extension_indices, count, sizeof *extension_indices, extension_compare);
758
759 /* Build the extension string.*/
760 for (j = 0; j < count; ++j) {
761 i = &extension_table[extension_indices[j]];
762 assert(base[i->offset]);
763 strcat(exts, i->name);
764 strcat(exts, " ");
765 }
766 free(extension_indices);
767 if (extra_extensions != 0) {
768 strcat(exts, extra_extensions);
769 free(extra_extensions);
770 }
771
772 return (GLubyte *) exts;
773 }
774
775 /**
776 * Return number of enabled extensions.
777 */
778 GLuint
779 _mesa_get_extension_count(struct gl_context *ctx)
780 {
781 GLboolean *base;
782 const struct extension *i;
783
784 /* only count once */
785 if (ctx->Extensions.Count != 0)
786 return ctx->Extensions.Count;
787
788 base = (GLboolean *) &ctx->Extensions;
789 for (i = extension_table; i->name != 0; ++i) {
790 if (base[i->offset]) {
791 ctx->Extensions.Count++;
792 }
793 }
794 return ctx->Extensions.Count;
795 }
796
797 /**
798 * Return name of i-th enabled extension
799 */
800 const GLubyte *
801 _mesa_get_enabled_extension(struct gl_context *ctx, GLuint index)
802 {
803 const GLboolean *base;
804 size_t n;
805 const struct extension *i;
806
807 if (index < 0)
808 return NULL;
809
810 base = (GLboolean*) &ctx->Extensions;
811 n = 0;
812 for (i = extension_table; i->name != 0; ++i) {
813 if (n == index && base[i->offset]) {
814 return (GLubyte*) i->name;
815 } else if (base[i->offset]) {
816 ++n;
817 }
818 }
819
820 return NULL;
821 }