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