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