gles2: Add GL_EXT_texture_format_BGRA8888 support
[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 "mtypes.h"
32
33
34 #define F(x) offsetof(struct gl_extensions, x)
35 #define ON GL_TRUE
36 #define OFF GL_FALSE
37
38
39 /*
40 * Note: The GL_MESAX_* extensions are placeholders for future ARB extensions.
41 */
42 static const struct {
43 GLboolean enabled;
44 const char *name;
45 int flag_offset;
46 } default_extensions[] = {
47 { OFF, "GL_ARB_blend_func_extended", F(ARB_blend_func_extended) },
48 { ON, "GL_ARB_copy_buffer", F(ARB_copy_buffer) },
49 { OFF, "GL_ARB_depth_buffer_float", F(ARB_depth_buffer_float) },
50 { OFF, "GL_ARB_depth_clamp", F(ARB_depth_clamp) },
51 { OFF, "GL_ARB_depth_texture", F(ARB_depth_texture) },
52 { ON, "GL_ARB_draw_buffers", F(ARB_draw_buffers) },
53 { OFF, "GL_ARB_draw_elements_base_vertex", F(ARB_draw_elements_base_vertex) },
54 { OFF, "GL_ARB_draw_instanced", F(ARB_draw_instanced) },
55 { OFF, "GL_ARB_fragment_coord_conventions", F(ARB_fragment_coord_conventions) },
56 { OFF, "GL_ARB_fragment_program", F(ARB_fragment_program) },
57 { OFF, "GL_ARB_fragment_program_shadow", F(ARB_fragment_program_shadow) },
58 { OFF, "GL_ARB_fragment_shader", F(ARB_fragment_shader) },
59 { OFF, "GL_ARB_framebuffer_object", F(ARB_framebuffer_object) },
60 { OFF, "GL_ARB_explicit_attrib_location", F(ARB_explicit_attrib_location) },
61 /* TODO: reenable this when the new GLSL compiler actually supports them */
62 /* { OFF, "GL_ARB_geometry_shader4", F(ARB_geometry_shader4) }, */
63 { OFF, "GL_ARB_half_float_pixel", F(ARB_half_float_pixel) },
64 { OFF, "GL_ARB_half_float_vertex", F(ARB_half_float_vertex) },
65 { OFF, "GL_ARB_instanced_arrays", F(ARB_instanced_arrays) },
66 { OFF, "GL_ARB_map_buffer_range", F(ARB_map_buffer_range) },
67 { ON, "GL_ARB_multisample", F(ARB_multisample) },
68 { OFF, "GL_ARB_multitexture", F(ARB_multitexture) },
69 { OFF, "GL_ARB_occlusion_query", F(ARB_occlusion_query) },
70 { OFF, "GL_ARB_occlusion_query2", F(ARB_occlusion_query2) },
71 { OFF, "GL_ARB_pixel_buffer_object", F(EXT_pixel_buffer_object) },
72 { OFF, "GL_ARB_point_parameters", F(EXT_point_parameters) },
73 { OFF, "GL_ARB_point_sprite", F(ARB_point_sprite) },
74 { OFF, "GL_ARB_provoking_vertex", F(EXT_provoking_vertex) },
75 { OFF, "GL_ARB_sampler_objects", F(ARB_sampler_objects) },
76 { OFF, "GL_ARB_seamless_cube_map", F(ARB_seamless_cube_map) },
77 { OFF, "GL_ARB_shader_objects", F(ARB_shader_objects) },
78 { OFF, "GL_ARB_shading_language_100", F(ARB_shading_language_100) },
79 { OFF, "GL_ARB_shadow", F(ARB_shadow) },
80 { OFF, "GL_ARB_shadow_ambient", F(ARB_shadow_ambient) },
81 { OFF, "GL_ARB_sync", F(ARB_sync) },
82 { OFF, "GL_ARB_texture_border_clamp", F(ARB_texture_border_clamp) },
83 { OFF, "GL_ARB_texture_buffer_object", F(ARB_texture_buffer_object) },
84 { ON, "GL_ARB_texture_compression", F(ARB_texture_compression) },
85 { OFF, "GL_ARB_texture_compression_rgtc", F(ARB_texture_compression_rgtc) },
86 { OFF, "GL_ARB_texture_cube_map", F(ARB_texture_cube_map) },
87 { OFF, "GL_ARB_texture_env_add", F(EXT_texture_env_add) },
88 { OFF, "GL_ARB_texture_env_combine", F(ARB_texture_env_combine) },
89 { OFF, "GL_ARB_texture_env_crossbar", F(ARB_texture_env_crossbar) },
90 { OFF, "GL_ARB_texture_env_dot3", F(ARB_texture_env_dot3) },
91 { OFF, "GL_MESAX_texture_float", F(ARB_texture_float) },
92 { OFF, "GL_ARB_texture_mirrored_repeat", F(ARB_texture_mirrored_repeat)},
93 { OFF, "GL_ARB_texture_multisample", F(ARB_texture_multisample) },
94 { OFF, "GL_ARB_texture_non_power_of_two", F(ARB_texture_non_power_of_two)},
95 { OFF, "GL_ARB_texture_rectangle", F(NV_texture_rectangle) },
96 { OFF, "GL_ARB_texture_rg", F(ARB_texture_rg) },
97 { OFF, "GL_ARB_texture_rgb10_a2ui", F(ARB_texture_rgb10_a2ui) },
98 { OFF, "GL_ARB_texture_swizzle", F(EXT_texture_swizzle) },
99 { ON, "GL_ARB_transpose_matrix", F(ARB_transpose_matrix) },
100 { OFF, "GL_ARB_transform_feedback2", F(ARB_transform_feedback2) },
101 { OFF, "GL_ARB_uniform_buffer_object", F(ARB_uniform_buffer_object) },
102 { OFF, "GL_ARB_vertex_array_bgra", F(EXT_vertex_array_bgra) },
103 { OFF, "GL_ARB_vertex_array_object", F(ARB_vertex_array_object) },
104 { ON, "GL_ARB_vertex_buffer_object", F(ARB_vertex_buffer_object) },
105 { OFF, "GL_ARB_vertex_program", F(ARB_vertex_program) },
106 { OFF, "GL_ARB_vertex_shader", F(ARB_vertex_shader) },
107 { OFF, "GL_ARB_vertex_type_2_10_10_10_rev", F(ARB_vertex_type_2_10_10_10_rev) },
108 { ON, "GL_ARB_window_pos", F(ARB_window_pos) },
109 { ON, "GL_EXT_abgr", F(EXT_abgr) },
110 { ON, "GL_EXT_bgra", F(EXT_bgra) },
111 { OFF, "GL_EXT_blend_color", F(EXT_blend_color) },
112 { OFF, "GL_EXT_blend_equation_separate", F(EXT_blend_equation_separate) },
113 { OFF, "GL_EXT_blend_func_separate", F(EXT_blend_func_separate) },
114 { OFF, "GL_EXT_blend_logic_op", F(EXT_blend_logic_op) },
115 { OFF, "GL_EXT_blend_minmax", F(EXT_blend_minmax) },
116 { OFF, "GL_EXT_blend_subtract", F(EXT_blend_subtract) },
117 { OFF, "GL_EXT_clip_volume_hint", F(EXT_clip_volume_hint) },
118 { ON, "GL_EXT_compiled_vertex_array", F(EXT_compiled_vertex_array) },
119 { ON, "GL_EXT_copy_texture", F(EXT_copy_texture) },
120 { OFF, "GL_EXT_depth_bounds_test", F(EXT_depth_bounds_test) },
121 { OFF, "GL_EXT_draw_buffers2", F(EXT_draw_buffers2) },
122 { OFF, "GL_EXT_draw_instanced", F(ARB_draw_instanced) },
123 { ON, "GL_EXT_draw_range_elements", F(EXT_draw_range_elements) },
124 { OFF, "GL_EXT_framebuffer_blit", F(EXT_framebuffer_blit) },
125 { OFF, "GL_EXT_framebuffer_multisample", F(EXT_framebuffer_multisample) },
126 { OFF, "GL_EXT_framebuffer_object", F(EXT_framebuffer_object) },
127 { OFF, "GL_EXT_framebuffer_sRGB", F(EXT_framebuffer_sRGB) },
128 { OFF, "GL_EXT_fog_coord", F(EXT_fog_coord) },
129 { OFF, "GL_EXT_gpu_program_parameters", F(EXT_gpu_program_parameters) },
130 { ON, "GL_EXT_multi_draw_arrays", F(EXT_multi_draw_arrays) },
131 { OFF, "GL_EXT_packed_depth_stencil", F(EXT_packed_depth_stencil) },
132 { OFF, "GL_EXT_packed_float", F(EXT_packed_float) },
133 { ON, "GL_EXT_packed_pixels", F(EXT_packed_pixels) },
134 { OFF, "GL_EXT_paletted_texture", F(EXT_paletted_texture) },
135 { OFF, "GL_EXT_pixel_buffer_object", F(EXT_pixel_buffer_object) },
136 { OFF, "GL_EXT_point_parameters", F(EXT_point_parameters) },
137 { ON, "GL_EXT_polygon_offset", F(EXT_polygon_offset) },
138 { OFF, "GL_EXT_provoking_vertex", F(EXT_provoking_vertex) },
139 { ON, "GL_EXT_rescale_normal", F(EXT_rescale_normal) },
140 { OFF, "GL_EXT_secondary_color", F(EXT_secondary_color) },
141 { ON, "GL_EXT_separate_specular_color", F(EXT_separate_specular_color) },
142 { OFF, "GL_EXT_shadow_funcs", F(EXT_shadow_funcs) },
143 { OFF, "GL_EXT_shared_texture_palette", F(EXT_shared_texture_palette) },
144 { OFF, "GL_EXT_stencil_two_side", F(EXT_stencil_two_side) },
145 { OFF, "GL_EXT_stencil_wrap", F(EXT_stencil_wrap) },
146 { ON, "GL_EXT_subtexture", F(EXT_subtexture) },
147 { ON, "GL_EXT_texture", F(EXT_texture) },
148 { ON, "GL_EXT_texture3D", F(EXT_texture3D) },
149 { OFF, "GL_EXT_texture_array", F(EXT_texture_array) },
150 { OFF, "GL_EXT_texture_compression_s3tc", F(EXT_texture_compression_s3tc) },
151 { OFF, "GL_EXT_texture_compression_rgtc", F(ARB_texture_compression_rgtc) },
152 { OFF, "GL_EXT_texture_cube_map", F(ARB_texture_cube_map) },
153 { ON, "GL_EXT_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
154 { OFF, "GL_EXT_texture_env_add", F(EXT_texture_env_add) },
155 { OFF, "GL_EXT_texture_env_combine", F(EXT_texture_env_combine) },
156 { OFF, "GL_EXT_texture_env_dot3", F(EXT_texture_env_dot3) },
157 { OFF, "GL_EXT_texture_filter_anisotropic", F(EXT_texture_filter_anisotropic) },
158 { OFF, "GL_EXT_texture_integer", F(EXT_texture_integer) },
159 { OFF, "GL_EXT_texture_lod_bias", F(EXT_texture_lod_bias) },
160 { OFF, "GL_EXT_texture_mirror_clamp", F(EXT_texture_mirror_clamp) },
161 { ON, "GL_EXT_texture_object", F(EXT_texture_object) },
162 { OFF, "GL_EXT_texture_rectangle", F(NV_texture_rectangle) },
163 { OFF, "GL_EXT_texture_shared_exponent", F(EXT_texture_shared_exponent) },
164 { OFF, "GL_EXT_texture_sRGB", F(EXT_texture_sRGB) },
165 { OFF, "GL_EXT_texture_swizzle", F(EXT_texture_swizzle) },
166 { OFF, "GL_EXT_timer_query", F(EXT_timer_query) },
167 { OFF, "GL_EXT_transform_feedback", F(EXT_transform_feedback) },
168 { ON, "GL_EXT_vertex_array", F(EXT_vertex_array) },
169 { OFF, "GL_EXT_vertex_array_bgra", F(EXT_vertex_array_bgra) },
170 { OFF, "GL_EXT_vertex_array_set", F(EXT_vertex_array_set) },
171 { OFF, "GL_3DFX_texture_compression_FXT1", F(TDFX_texture_compression_FXT1) },
172 { OFF, "GL_APPLE_client_storage", F(APPLE_client_storage) },
173 { ON, "GL_APPLE_packed_pixels", F(APPLE_packed_pixels) },
174 { OFF, "GL_APPLE_vertex_array_object", F(APPLE_vertex_array_object) },
175 { OFF, "GL_APPLE_object_purgeable", F(APPLE_object_purgeable) },
176 { OFF, "GL_ATI_blend_equation_separate", F(EXT_blend_equation_separate) },
177 { OFF, "GL_ATI_envmap_bumpmap", F(ATI_envmap_bumpmap) },
178 { OFF, "GL_ATI_texture_env_combine3", F(ATI_texture_env_combine3)},
179 { OFF, "GL_ATI_texture_mirror_once", F(ATI_texture_mirror_once)},
180 { OFF, "GL_ATI_fragment_shader", F(ATI_fragment_shader)},
181 { OFF, "GL_ATI_separate_stencil", F(ATI_separate_stencil)},
182 { ON, "GL_IBM_multimode_draw_arrays", F(IBM_multimode_draw_arrays) },
183 { ON, "GL_IBM_rasterpos_clip", F(IBM_rasterpos_clip) },
184 { OFF, "GL_IBM_texture_mirrored_repeat", F(ARB_texture_mirrored_repeat)},
185 { OFF, "GL_INGR_blend_func_separate", F(EXT_blend_func_separate) },
186 { OFF, "GL_MESA_pack_invert", F(MESA_pack_invert) },
187 { OFF, "GL_MESA_resize_buffers", F(MESA_resize_buffers) },
188 { OFF, "GL_MESA_texture_array", F(MESA_texture_array) },
189 { OFF, "GL_MESA_texture_signed_rgba", F(MESA_texture_signed_rgba) },
190 { OFF, "GL_MESA_ycbcr_texture", F(MESA_ycbcr_texture) },
191 { ON, "GL_MESA_window_pos", F(ARB_window_pos) },
192 { OFF, "GL_NV_blend_square", F(NV_blend_square) },
193 { OFF, "GL_NV_conditional_render", F(NV_conditional_render) },
194 { OFF, "GL_NV_depth_clamp", F(ARB_depth_clamp) },
195 { OFF, "GL_NV_fragment_program", F(NV_fragment_program) },
196 { OFF, "GL_NV_fragment_program_option", F(NV_fragment_program_option) },
197 { ON, "GL_NV_light_max_exponent", F(NV_light_max_exponent) },
198 { OFF, "GL_NV_packed_depth_stencil", F(EXT_packed_depth_stencil) },
199 { OFF, "GL_NV_point_sprite", F(NV_point_sprite) },
200 { OFF, "GL_NV_primitive_restart", F(NV_primitive_restart) },
201 { ON, "GL_NV_texgen_reflection", F(NV_texgen_reflection) },
202 { OFF, "GL_NV_texture_env_combine4", F(NV_texture_env_combine4) },
203 { OFF, "GL_NV_texture_rectangle", F(NV_texture_rectangle) },
204 { OFF, "GL_NV_vertex_program", F(NV_vertex_program) },
205 { OFF, "GL_NV_vertex_program1_1", F(NV_vertex_program1_1) },
206 { ON, "GL_OES_read_format", F(OES_read_format) },
207 { OFF, "GL_SGI_texture_color_table", F(SGI_texture_color_table) },
208 { ON, "GL_SGIS_generate_mipmap", F(SGIS_generate_mipmap) },
209 { OFF, "GL_SGIS_texture_border_clamp", F(ARB_texture_border_clamp) },
210 { ON, "GL_SGIS_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
211 { ON, "GL_SGIS_texture_lod", F(SGIS_texture_lod) },
212 { ON, "GL_SUN_multi_draw_arrays", F(EXT_multi_draw_arrays) },
213 { OFF, "GL_S3_s3tc", F(S3_s3tc) },
214 { OFF, "GL_EXT_texture_format_BGRA8888", F(EXT_texture_format_BGRA8888) },
215 #if FEATURE_OES_EGL_image
216 { OFF, "GL_OES_EGL_image", F(OES_EGL_image) },
217 #endif
218 #if FEATURE_OES_draw_texture
219 { OFF, "GL_OES_draw_texture", F(OES_draw_texture) },
220 #endif /* FEATURE_OES_draw_texture */
221 };
222
223
224
225 /**
226 * Enable all extensions suitable for a software-only renderer.
227 * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
228 */
229 void
230 _mesa_enable_sw_extensions(GLcontext *ctx)
231 {
232 /*ctx->Extensions.ARB_copy_buffer = GL_TRUE;*/
233 ctx->Extensions.ARB_depth_clamp = GL_TRUE;
234 ctx->Extensions.ARB_depth_texture = GL_TRUE;
235 /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/
236 ctx->Extensions.ARB_draw_elements_base_vertex = GL_TRUE;
237 ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE;
238 #if FEATURE_ARB_fragment_program
239 ctx->Extensions.ARB_fragment_program = GL_TRUE;
240 ctx->Extensions.ARB_fragment_program_shadow = GL_TRUE;
241 #endif
242 #if FEATURE_ARB_fragment_shader
243 ctx->Extensions.ARB_fragment_shader = GL_TRUE;
244 #endif
245 #if FEATURE_ARB_framebuffer_object
246 ctx->Extensions.ARB_framebuffer_object = GL_TRUE;
247 #endif
248 #if FEATURE_ARB_geometry_shader4
249 ctx->Extensions.ARB_geometry_shader4 = GL_TRUE;
250 #endif
251 ctx->Extensions.ARB_half_float_pixel = GL_TRUE;
252 ctx->Extensions.ARB_half_float_vertex = GL_TRUE;
253 ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
254 ctx->Extensions.ARB_multitexture = GL_TRUE;
255 #if FEATURE_queryobj
256 ctx->Extensions.ARB_occlusion_query = GL_TRUE;
257 #endif
258 ctx->Extensions.ARB_point_sprite = GL_TRUE;
259 #if FEATURE_ARB_shader_objects
260 ctx->Extensions.ARB_shader_objects = GL_TRUE;
261 #endif
262 #if FEATURE_ARB_shading_language_100
263 ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
264 #endif
265 ctx->Extensions.ARB_shadow = GL_TRUE;
266 ctx->Extensions.ARB_shadow_ambient = GL_TRUE;
267 ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
268 ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
269 ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
270 ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
271 ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
272 /*ctx->Extensions.ARB_texture_float = GL_TRUE;*/
273 ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
274 ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
275 ctx->Extensions.ARB_texture_rg = GL_TRUE;
276 ctx->Extensions.ARB_vertex_array_object = GL_TRUE;
277 #if FEATURE_ARB_vertex_program
278 ctx->Extensions.ARB_vertex_program = GL_TRUE;
279 #endif
280 #if FEATURE_ARB_vertex_shader
281 ctx->Extensions.ARB_vertex_shader = GL_TRUE;
282 #endif
283 #if FEATURE_ARB_vertex_buffer_object
284 /*ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;*/
285 #endif
286 #if FEATURE_ARB_sync
287 ctx->Extensions.ARB_sync = GL_TRUE;
288 #endif
289 ctx->Extensions.APPLE_vertex_array_object = GL_TRUE;
290 #if FEATURE_APPLE_object_purgeable
291 ctx->Extensions.APPLE_object_purgeable = GL_TRUE;
292 #endif
293 ctx->Extensions.ATI_envmap_bumpmap = GL_TRUE;
294 #if FEATURE_ATI_fragment_shader
295 ctx->Extensions.ATI_fragment_shader = GL_TRUE;
296 #endif
297 ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
298 ctx->Extensions.ATI_texture_mirror_once = GL_TRUE;
299 ctx->Extensions.ATI_separate_stencil = GL_TRUE;
300 ctx->Extensions.EXT_blend_color = GL_TRUE;
301 ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
302 ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
303 ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
304 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
305 ctx->Extensions.EXT_blend_subtract = GL_TRUE;
306 ctx->Extensions.EXT_depth_bounds_test = GL_TRUE;
307 ctx->Extensions.EXT_draw_buffers2 = GL_TRUE;
308 ctx->Extensions.EXT_fog_coord = GL_TRUE;
309 #if FEATURE_EXT_framebuffer_object
310 ctx->Extensions.EXT_framebuffer_object = GL_TRUE;
311 #endif
312 #if FEATURE_EXT_framebuffer_blit
313 ctx->Extensions.EXT_framebuffer_blit = GL_TRUE;
314 #endif
315 #if FEATURE_ARB_framebuffer_object
316 ctx->Extensions.EXT_framebuffer_multisample = GL_TRUE;
317 #endif
318 /*ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;*/
319 ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
320 ctx->Extensions.EXT_paletted_texture = GL_TRUE;
321 #if FEATURE_EXT_pixel_buffer_object
322 ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
323 #endif
324 ctx->Extensions.EXT_point_parameters = GL_TRUE;
325 ctx->Extensions.EXT_provoking_vertex = GL_TRUE;
326 ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
327 ctx->Extensions.EXT_secondary_color = GL_TRUE;
328 ctx->Extensions.EXT_shared_texture_palette = GL_TRUE;
329 ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
330 ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
331 ctx->Extensions.EXT_texture_array = GL_TRUE;
332 ctx->Extensions.EXT_texture_env_add = GL_TRUE;
333 ctx->Extensions.EXT_texture_env_combine = GL_TRUE;
334 ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
335 ctx->Extensions.EXT_texture_mirror_clamp = GL_TRUE;
336 ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
337 #if FEATURE_EXT_texture_sRGB
338 ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
339 #endif
340 ctx->Extensions.EXT_texture_swizzle = GL_TRUE;
341 #if FEATURE_EXT_transform_feedback
342 /*ctx->Extensions.EXT_transform_feedback = GL_TRUE;*/
343 #endif
344 ctx->Extensions.EXT_vertex_array_bgra = GL_TRUE;
345 /*ctx->Extensions.IBM_multimode_draw_arrays = GL_TRUE;*/
346 ctx->Extensions.MESA_pack_invert = GL_TRUE;
347 ctx->Extensions.MESA_resize_buffers = GL_TRUE;
348 ctx->Extensions.MESA_texture_array = GL_TRUE;
349 ctx->Extensions.MESA_ycbcr_texture = GL_TRUE;
350 ctx->Extensions.NV_blend_square = GL_TRUE;
351 ctx->Extensions.NV_conditional_render = GL_TRUE;
352 /*ctx->Extensions.NV_light_max_exponent = GL_TRUE;*/
353 ctx->Extensions.NV_point_sprite = GL_TRUE;
354 ctx->Extensions.NV_texture_env_combine4 = GL_TRUE;
355 ctx->Extensions.NV_texture_rectangle = GL_TRUE;
356 /*ctx->Extensions.NV_texgen_reflection = GL_TRUE;*/
357 #if FEATURE_NV_vertex_program
358 ctx->Extensions.NV_vertex_program = GL_TRUE;
359 ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
360 #endif
361 #if FEATURE_NV_fragment_program
362 ctx->Extensions.NV_fragment_program = GL_TRUE;
363 #endif
364 #if FEATURE_NV_fragment_program && FEATURE_ARB_fragment_program
365 ctx->Extensions.NV_fragment_program_option = GL_TRUE;
366 #endif
367 ctx->Extensions.SGI_texture_color_table = GL_TRUE;
368 /*ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;*/
369 ctx->Extensions.SGIS_texture_edge_clamp = GL_TRUE;
370 #if FEATURE_ARB_vertex_program || FEATURE_ARB_fragment_program
371 ctx->Extensions.EXT_gpu_program_parameters = GL_TRUE;
372 #endif
373 #if FEATURE_texture_fxt1
374 _mesa_enable_extension(ctx, "GL_3DFX_texture_compression_FXT1");
375 #endif
376 #if FEATURE_texture_s3tc
377 if (ctx->Mesa_DXTn) {
378 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
379 _mesa_enable_extension(ctx, "GL_S3_s3tc");
380 }
381 #endif
382 }
383
384
385 /**
386 * Enable common EXT extensions in the ARB_imaging subset.
387 */
388 void
389 _mesa_enable_imaging_extensions(GLcontext *ctx)
390 {
391 ctx->Extensions.EXT_blend_color = GL_TRUE;
392 ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
393 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
394 ctx->Extensions.EXT_blend_subtract = GL_TRUE;
395 }
396
397
398
399 /**
400 * Enable all OpenGL 1.3 features and extensions.
401 * A convenience function to be called by drivers.
402 */
403 void
404 _mesa_enable_1_3_extensions(GLcontext *ctx)
405 {
406 /*ctx->Extensions.ARB_multisample = GL_TRUE;*/
407 ctx->Extensions.ARB_multitexture = GL_TRUE;
408 ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
409 /*ctx->Extensions.ARB_texture_compression = GL_TRUE;*/
410 ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
411 ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
412 ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
413 ctx->Extensions.EXT_texture_env_add = GL_TRUE;
414 /*ctx->Extensions.ARB_transpose_matrix = GL_TRUE;*/
415 }
416
417
418
419 /**
420 * Enable all OpenGL 1.4 features and extensions.
421 * A convenience function to be called by drivers.
422 */
423 void
424 _mesa_enable_1_4_extensions(GLcontext *ctx)
425 {
426 ctx->Extensions.ARB_depth_texture = GL_TRUE;
427 ctx->Extensions.ARB_shadow = GL_TRUE;
428 ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
429 ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
430 ctx->Extensions.ARB_window_pos = GL_TRUE;
431 ctx->Extensions.EXT_blend_color = GL_TRUE;
432 ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
433 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
434 ctx->Extensions.EXT_blend_subtract = GL_TRUE;
435 ctx->Extensions.EXT_fog_coord = GL_TRUE;
436 /*ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;*/
437 ctx->Extensions.EXT_point_parameters = GL_TRUE;
438 ctx->Extensions.EXT_secondary_color = GL_TRUE;
439 ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
440 ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
441 /*ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;*/
442 }
443
444
445 /**
446 * Enable all OpenGL 1.5 features and extensions.
447 * A convenience function to be called by drivers.
448 */
449 void
450 _mesa_enable_1_5_extensions(GLcontext *ctx)
451 {
452 ctx->Extensions.ARB_occlusion_query = GL_TRUE;
453 /*ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;*/
454 ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
455 }
456
457
458 /**
459 * Enable all OpenGL 2.0 features and extensions.
460 * A convenience function to be called by drivers.
461 */
462 void
463 _mesa_enable_2_0_extensions(GLcontext *ctx)
464 {
465 /*ctx->Extensions.ARB_draw_buffers = GL_TRUE;*/
466 #if FEATURE_ARB_fragment_shader
467 ctx->Extensions.ARB_fragment_shader = GL_TRUE;
468 #endif
469 ctx->Extensions.ARB_point_sprite = GL_TRUE;
470 ctx->Extensions.EXT_blend_equation_separate = GL_TRUE;
471 ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
472 #if FEATURE_ARB_shader_objects
473 ctx->Extensions.ARB_shader_objects = GL_TRUE;
474 #endif
475 #if FEATURE_ARB_shading_language_100
476 ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
477 #endif
478 ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
479 #if FEATURE_ARB_vertex_shader
480 ctx->Extensions.ARB_vertex_shader = GL_TRUE;
481 #endif
482 }
483
484
485 /**
486 * Enable all OpenGL 2.1 features and extensions.
487 * A convenience function to be called by drivers.
488 */
489 void
490 _mesa_enable_2_1_extensions(GLcontext *ctx)
491 {
492 #if FEATURE_EXT_pixel_buffer_object
493 ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
494 #endif
495 #if FEATURE_EXT_texture_sRGB
496 ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
497 #endif
498 }
499
500
501 /**
502 * Either enable or disable the named extension.
503 * \return GL_TRUE for success, GL_FALSE if invalid extension name
504 */
505 static GLboolean
506 set_extension( GLcontext *ctx, const char *name, GLboolean state )
507 {
508 GLboolean *base = (GLboolean *) &ctx->Extensions;
509 GLuint i;
510
511 if (ctx->Extensions.String) {
512 /* The string was already queried - can't change it now! */
513 _mesa_problem(ctx, "Trying to enable/disable extension after glGetString(GL_EXTENSIONS): %s", name);
514 return GL_FALSE;
515 }
516
517 for (i = 0 ; i < Elements(default_extensions) ; i++) {
518 if (strcmp(default_extensions[i].name, name) == 0) {
519 if (default_extensions[i].flag_offset) {
520 GLboolean *enabled = base + default_extensions[i].flag_offset;
521 *enabled = state;
522 }
523 return GL_TRUE;
524 }
525 }
526 return GL_FALSE;
527 }
528
529
530 /**
531 * Enable the named extension.
532 * Typically called by drivers.
533 */
534 void
535 _mesa_enable_extension( GLcontext *ctx, const char *name )
536 {
537 if (!set_extension(ctx, name, GL_TRUE))
538 _mesa_problem(ctx, "Trying to enable unknown extension: %s", name);
539 }
540
541
542 /**
543 * Disable the named extension.
544 * XXX is this really needed???
545 */
546 void
547 _mesa_disable_extension( GLcontext *ctx, const char *name )
548 {
549 if (!set_extension(ctx, name, GL_FALSE))
550 _mesa_problem(ctx, "Trying to disable unknown extension: %s", name);
551 }
552
553
554 /**
555 * Check if the i-th extension is enabled.
556 */
557 static GLboolean
558 extension_enabled(GLcontext *ctx, GLuint index)
559 {
560 const GLboolean *base = (const GLboolean *) &ctx->Extensions;
561 if (!default_extensions[index].flag_offset ||
562 *(base + default_extensions[index].flag_offset)) {
563 return GL_TRUE;
564 }
565 else {
566 return GL_FALSE;
567 }
568 }
569
570
571 /**
572 * Test if the named extension is enabled in this context.
573 */
574 GLboolean
575 _mesa_extension_is_enabled( GLcontext *ctx, const char *name )
576 {
577 GLuint i;
578
579 for (i = 0 ; i < Elements(default_extensions) ; i++) {
580 if (strcmp(default_extensions[i].name, name) == 0) {
581 return extension_enabled(ctx, i);
582 }
583 }
584 return GL_FALSE;
585 }
586
587
588 /**
589 * Append string 'b' onto string 'a'. Free 'a' and return new string.
590 */
591 static char *
592 append(const char *a, const char *b)
593 {
594 const GLuint aLen = a ? strlen(a) : 0;
595 const GLuint bLen = b ? strlen(b) : 0;
596 char *s = calloc(1, aLen + bLen + 1);
597 if (s) {
598 if (a)
599 memcpy(s, a, aLen);
600 if (b)
601 memcpy(s + aLen, b, bLen);
602 s[aLen + bLen] = '\0';
603 }
604 if (a)
605 free((void *) a);
606 return s;
607 }
608
609
610 /**
611 * Check the MESA_EXTENSION_OVERRIDE env var.
612 * For extension names that are recognized, turn them on. For extension
613 * names that are recognized and prefixed with '-', turn them off.
614 * Return a string of the unknown/leftover names.
615 */
616 static const char *
617 get_extension_override( GLcontext *ctx )
618 {
619 const char *envExt = _mesa_getenv("MESA_EXTENSION_OVERRIDE");
620 char *extraExt = NULL;
621 char ext[1000];
622 GLuint extLen = 0;
623 GLuint i;
624 GLboolean disableExt = GL_FALSE;
625
626 if (!envExt)
627 return NULL;
628
629 for (i = 0; ; i++) {
630 if (envExt[i] == '\0' || envExt[i] == ' ') {
631 /* terminate/process 'ext' if extLen > 0 */
632 if (extLen > 0) {
633 assert(extLen < sizeof(ext));
634 /* enable extension named by 'ext' */
635 ext[extLen] = 0;
636 if (!set_extension(ctx, ext, !disableExt)) {
637 /* unknown extension name, append it to extraExt */
638 if (extraExt) {
639 extraExt = append(extraExt, " ");
640 }
641 extraExt = append(extraExt, ext);
642 }
643 extLen = 0;
644 disableExt = GL_FALSE;
645 }
646 if (envExt[i] == '\0')
647 break;
648 }
649 else if (envExt[i] == '-') {
650 disableExt = GL_TRUE;
651 }
652 else {
653 /* accumulate this non-space character */
654 ext[extLen++] = envExt[i];
655 }
656 }
657
658 return extraExt;
659 }
660
661
662 /**
663 * Run through the default_extensions array above and set the
664 * ctx->Extensions.ARB/EXT_* flags accordingly.
665 * To be called during context initialization.
666 */
667 void
668 _mesa_init_extensions( GLcontext *ctx )
669 {
670 GLboolean *base = (GLboolean *) &ctx->Extensions;
671 GLuint i;
672
673 for (i = 0 ; i < Elements(default_extensions) ; i++) {
674 if (default_extensions[i].enabled &&
675 default_extensions[i].flag_offset) {
676 *(base + default_extensions[i].flag_offset) = GL_TRUE;
677 }
678 }
679 }
680
681
682 /**
683 * Construct the GL_EXTENSIONS string. Called the first time that
684 * glGetString(GL_EXTENSIONS) is called.
685 */
686 static GLubyte *
687 compute_extensions( GLcontext *ctx )
688 {
689 const char *extraExt = get_extension_override(ctx);
690 GLuint extStrLen = 0;
691 char *s;
692 GLuint i;
693
694 /* first, compute length of the extension string */
695 for (i = 0 ; i < Elements(default_extensions) ; i++) {
696 if (extension_enabled(ctx, i)) {
697 extStrLen += (GLuint) strlen(default_extensions[i].name) + 1;
698 }
699 }
700
701 if (extraExt)
702 extStrLen += strlen(extraExt) + 1; /* +1 for space */
703
704 /* allocate the extension string */
705 s = (char *) malloc(extStrLen);
706 if (!s)
707 return NULL;
708
709 /* second, build the extension string */
710 extStrLen = 0;
711 for (i = 0 ; i < Elements(default_extensions) ; i++) {
712 if (extension_enabled(ctx, i)) {
713 GLuint len = (GLuint) strlen(default_extensions[i].name);
714 memcpy(s + extStrLen, default_extensions[i].name, len);
715 extStrLen += len;
716 s[extStrLen] = ' ';
717 extStrLen++;
718 }
719 }
720 ASSERT(extStrLen > 0);
721
722 s[extStrLen - 1] = 0; /* -1 to overwrite trailing the ' ' */
723
724 if (extraExt) {
725 s = append(s, " ");
726 s = append(s, extraExt);
727 }
728
729 return (GLubyte *) s;
730 }
731
732 static size_t
733 append_extension(GLubyte **str, const char *ext)
734 {
735 GLubyte *s = *str;
736 size_t len = strlen(ext);
737
738 if (s) {
739 memcpy(s, ext, len);
740 s[len++] = ' ';
741 s[len] = '\0';
742
743 *str += len;
744 }
745 else {
746 len++;
747 }
748
749 return len;
750 }
751
752
753 static size_t
754 make_extension_string_es1(const GLcontext *ctx, GLubyte *str)
755 {
756 size_t len = 0;
757
758 /* Core additions */
759 len += append_extension(&str, "GL_OES_byte_coordinates");
760 len += append_extension(&str, "GL_OES_fixed_point");
761 len += append_extension(&str, "GL_OES_single_precision");
762 len += append_extension(&str, "GL_OES_matrix_get");
763
764 /* 1.1 required extensions */
765 len += append_extension(&str, "GL_OES_read_format");
766 len += append_extension(&str, "GL_OES_compressed_paletted_texture");
767 len += append_extension(&str, "GL_OES_point_size_array");
768 len += append_extension(&str, "GL_OES_point_sprite");
769
770 /* 1.1 deprecated extensions */
771 len += append_extension(&str, "GL_OES_query_matrix");
772
773 #if FEATURE_OES_draw_texture
774 if (ctx->Extensions.OES_draw_texture)
775 len += append_extension(&str, "GL_OES_draw_texture");
776 #endif
777
778 if (ctx->Extensions.EXT_blend_equation_separate)
779 len += append_extension(&str, "GL_OES_blend_equation_separate");
780 if (ctx->Extensions.EXT_blend_func_separate)
781 len += append_extension(&str, "GL_OES_blend_func_separate");
782 if (ctx->Extensions.EXT_blend_subtract)
783 len += append_extension(&str, "GL_OES_blend_subtract");
784
785 if (ctx->Extensions.EXT_stencil_wrap)
786 len += append_extension(&str, "GL_OES_stencil_wrap");
787
788 if (ctx->Extensions.ARB_texture_cube_map)
789 len += append_extension(&str, "GL_OES_texture_cube_map");
790 if (ctx->Extensions.ARB_texture_env_crossbar)
791 len += append_extension(&str, "GL_OES_texture_env_crossbar");
792 if (ctx->Extensions.ARB_texture_mirrored_repeat)
793 len += append_extension(&str, "GL_OES_texture_mirrored_repeat");
794
795 if (ctx->Extensions.ARB_framebuffer_object) {
796 len += append_extension(&str, "GL_OES_framebuffer_object");
797 len += append_extension(&str, "GL_OES_depth24");
798 len += append_extension(&str, "GL_OES_depth32");
799 len += append_extension(&str, "GL_OES_fbo_render_mipmap");
800 len += append_extension(&str, "GL_OES_rgb8_rgba8");
801 len += append_extension(&str, "GL_OES_stencil1");
802 len += append_extension(&str, "GL_OES_stencil4");
803 len += append_extension(&str, "GL_OES_stencil8");
804 }
805
806 if (ctx->Extensions.EXT_vertex_array)
807 len += append_extension(&str, "GL_OES_element_index_uint");
808 if (ctx->Extensions.ARB_vertex_buffer_object)
809 len += append_extension(&str, "GL_OES_mapbuffer");
810 if (ctx->Extensions.EXT_texture_filter_anisotropic)
811 len += append_extension(&str, "GL_EXT_texture_filter_anisotropic");
812
813 /* some applications check this for NPOT support */
814 if (ctx->Extensions.ARB_texture_non_power_of_two)
815 len += append_extension(&str, "GL_ARB_texture_non_power_of_two");
816
817 if (ctx->Extensions.EXT_texture_compression_s3tc)
818 len += append_extension(&str, "GL_EXT_texture_compression_dxt1");
819 if (ctx->Extensions.EXT_texture_lod_bias)
820 len += append_extension(&str, "GL_EXT_texture_lod_bias");
821 if (ctx->Extensions.EXT_blend_minmax)
822 len += append_extension(&str, "GL_EXT_blend_minmax");
823 if (ctx->Extensions.EXT_multi_draw_arrays)
824 len += append_extension(&str, "GL_EXT_multi_draw_arrays");
825
826 #if FEATURE_OES_EGL_image
827 if (ctx->Extensions.OES_EGL_image)
828 len += append_extension(&str, "GL_OES_EGL_image");
829 #endif
830
831 return len;
832 }
833
834
835 static GLubyte *
836 compute_extensions_es1(const GLcontext *ctx)
837 {
838 GLubyte *s;
839 unsigned int len;
840
841 len = make_extension_string_es1(ctx, NULL);
842 s = malloc(len + 1);
843 if (!s)
844 return NULL;
845 make_extension_string_es1(ctx, s);
846
847 return s;
848 }
849
850 static size_t
851 make_extension_string_es2(const GLcontext *ctx, GLubyte *str)
852 {
853 size_t len = 0;
854
855 len += append_extension(&str, "GL_OES_compressed_paletted_texture");
856
857 if (ctx->Extensions.ARB_framebuffer_object) {
858 len += append_extension(&str, "GL_OES_depth24");
859 len += append_extension(&str, "GL_OES_depth32");
860 len += append_extension(&str, "GL_OES_fbo_render_mipmap");
861 len += append_extension(&str, "GL_OES_rgb8_rgba8");
862 len += append_extension(&str, "GL_OES_stencil1");
863 len += append_extension(&str, "GL_OES_stencil4");
864 }
865
866 if (ctx->Extensions.EXT_vertex_array)
867 len += append_extension(&str, "GL_OES_element_index_uint");
868 if (ctx->Extensions.ARB_vertex_buffer_object)
869 len += append_extension(&str, "GL_OES_mapbuffer");
870
871 if (ctx->Extensions.EXT_texture3D)
872 len += append_extension(&str, "GL_OES_texture_3D");
873 if (ctx->Extensions.ARB_texture_non_power_of_two)
874 len += append_extension(&str, "GL_OES_texture_npot");
875 if (ctx->Extensions.EXT_texture_filter_anisotropic)
876 len += append_extension(&str, "GL_EXT_texture_filter_anisotropic");
877
878 len += append_extension(&str, "GL_EXT_texture_type_2_10_10_10_REV");
879 if (ctx->Extensions.ARB_depth_texture)
880 len += append_extension(&str, "GL_OES_depth_texture");
881 if (ctx->Extensions.EXT_packed_depth_stencil)
882 len += append_extension(&str, "GL_OES_packed_depth_stencil");
883 if (ctx->Extensions.ARB_fragment_shader)
884 len += append_extension(&str, "GL_OES_standard_derivatives");
885
886 if (ctx->Extensions.EXT_texture_compression_s3tc)
887 len += append_extension(&str, "GL_EXT_texture_compression_dxt1");
888 if (ctx->Extensions.EXT_blend_minmax)
889 len += append_extension(&str, "GL_EXT_blend_minmax");
890 if (ctx->Extensions.EXT_multi_draw_arrays)
891 len += append_extension(&str, "GL_EXT_multi_draw_arrays");
892
893 #if FEATURE_OES_EGL_image
894 if (ctx->Extensions.OES_EGL_image)
895 len += append_extension(&str, "GL_OES_EGL_image");
896 #endif
897
898 if (ctx->Extensions.EXT_texture_format_BGRA8888)
899 len += append_extension(&str, "GL_EXT_texture_format_BGRA8888");
900
901 return len;
902 }
903
904 static GLubyte *
905 compute_extensions_es2(GLcontext *ctx)
906 {
907 GLubyte *s;
908 unsigned int len;
909
910 len = make_extension_string_es2(ctx, NULL);
911 s = malloc(len + 1);
912 if (!s)
913 return NULL;
914 make_extension_string_es2(ctx, s);
915
916 return s;
917 }
918
919
920 GLubyte *
921 _mesa_make_extension_string(GLcontext *ctx)
922 {
923 switch (ctx->API) {
924 case API_OPENGL:
925 return compute_extensions(ctx);
926 case API_OPENGLES2:
927 return compute_extensions_es2(ctx);
928 case API_OPENGLES:
929 return compute_extensions_es1(ctx);
930 default:
931 assert(0);
932 return NULL;
933 }
934 }
935
936 /**
937 * Return number of enabled extensions.
938 */
939 GLuint
940 _mesa_get_extension_count(GLcontext *ctx)
941 {
942 GLuint i;
943
944 /* only count once */
945 if (!ctx->Extensions.Count) {
946 for (i = 0; i < Elements(default_extensions); i++) {
947 if (extension_enabled(ctx, i)) {
948 ctx->Extensions.Count++;
949 }
950 }
951 }
952
953 if (0)
954 _mesa_debug(ctx, "%u of %d extensions enabled\n", ctx->Extensions.Count,
955 (int) Elements(default_extensions));
956
957 return ctx->Extensions.Count;
958 }
959
960
961 /**
962 * Return name of i-th enabled extension
963 */
964 const GLubyte *
965 _mesa_get_enabled_extension(GLcontext *ctx, GLuint index)
966 {
967 GLuint i;
968
969 for (i = 0; i < Elements(default_extensions); i++) {
970 if (extension_enabled(ctx, i)) {
971 if (index == 0)
972 return (const GLubyte *) default_extensions[i].name;
973 index--;
974 }
975 }
976
977 return NULL;
978 }