Added OpenGL 1.4's per-texture LOD bias.
[mesa.git] / src / mesa / main / extensions.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 5.1
4 *
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #include "glheader.h"
27 #include "imports.h"
28 #include "context.h"
29 #include "extensions.h"
30 #include "simple_list.h"
31 #include "mtypes.h"
32
33
34 #define F(x) (int)&(((struct gl_extensions *)0)->x)
35 #define ON GL_TRUE
36 #define OFF GL_FALSE
37
38
39 static const struct {
40 GLboolean enabled;
41 const char *name;
42 int flag_offset;
43 } default_extensions[] = {
44 { OFF, "GL_ARB_depth_texture", F(ARB_depth_texture) },
45 { OFF, "GL_ARB_fragment_program", F(ARB_fragment_program) },
46 { OFF, "GL_ARB_imaging", F(ARB_imaging) },
47 { OFF, "GL_ARB_multisample", F(ARB_multisample) },
48 { OFF, "GL_ARB_multitexture", F(ARB_multitexture) },
49 { OFF, "GL_ARB_occlusion_query", F(ARB_occlusion_query) },
50 { OFF, "GL_ARB_point_parameters", F(EXT_point_parameters) },
51 { OFF, "GL_ARB_point_sprite", F(ARB_point_sprite) },
52 { OFF, "GL_ARB_shadow", F(ARB_shadow) },
53 { OFF, "GL_ARB_shadow_ambient", F(SGIX_shadow_ambient) },
54 { OFF, "GL_ARB_texture_border_clamp", F(ARB_texture_border_clamp) },
55 { OFF, "GL_ARB_texture_compression", F(ARB_texture_compression) },
56 { OFF, "GL_ARB_texture_cube_map", F(ARB_texture_cube_map) },
57 { OFF, "GL_ARB_texture_env_add", F(EXT_texture_env_add) },
58 { OFF, "GL_ARB_texture_env_combine", F(ARB_texture_env_combine) },
59 { OFF, "GL_ARB_texture_env_crossbar", F(ARB_texture_env_crossbar) },
60 { OFF, "GL_ARB_texture_env_dot3", F(ARB_texture_env_dot3) },
61 { OFF, "GL_ARB_texture_mirrored_repeat", F(ARB_texture_mirrored_repeat)},
62 { OFF, "GL_ARB_texture_non_power_of_two", F(ARB_texture_non_power_of_two)},
63 { ON, "GL_ARB_transpose_matrix", 0 },
64 { OFF, "GL_ARB_vertex_buffer_object", F(ARB_vertex_buffer_object) },
65 { OFF, "GL_ARB_vertex_program", F(ARB_vertex_program) },
66 { ON, "GL_ARB_window_pos", F(ARB_window_pos) },
67 { ON, "GL_EXT_abgr", 0 },
68 { ON, "GL_EXT_bgra", 0 },
69 { OFF, "GL_EXT_blend_color", F(EXT_blend_color) },
70 { OFF, "GL_EXT_blend_func_separate", F(EXT_blend_func_separate) },
71 { OFF, "GL_EXT_blend_logic_op", F(EXT_blend_logic_op) },
72 { OFF, "GL_EXT_blend_minmax", F(EXT_blend_minmax) },
73 { OFF, "GL_EXT_blend_subtract", F(EXT_blend_subtract) },
74 { ON, "GL_EXT_clip_volume_hint", 0 },
75 { ON, "GL_EXT_compiled_vertex_array", F(EXT_compiled_vertex_array) },
76 { OFF, "GL_EXT_convolution", F(EXT_convolution) },
77 { ON, "GL_EXT_copy_texture", 0 },
78 { OFF, "GL_EXT_depth_bounds_test", F(EXT_depth_bounds_test) },
79 { ON, "GL_EXT_draw_range_elements", 0 },
80 { OFF, "GL_EXT_fog_coord", F(EXT_fog_coord) },
81 { OFF, "GL_EXT_histogram", F(EXT_histogram) },
82 { OFF, "GL_EXT_multi_draw_arrays", F(EXT_multi_draw_arrays) },
83 { ON, "GL_EXT_packed_pixels", 0 },
84 { OFF, "GL_EXT_paletted_texture", F(EXT_paletted_texture) },
85 { OFF, "GL_EXT_point_parameters", F(EXT_point_parameters) },
86 { ON, "GL_EXT_polygon_offset", 0 },
87 { ON, "GL_EXT_rescale_normal", 0 },
88 { OFF, "GL_EXT_secondary_color", F(EXT_secondary_color) },
89 { ON, "GL_EXT_separate_specular_color", 0 },
90 { OFF, "GL_EXT_shadow_funcs", F(EXT_shadow_funcs) },
91 { OFF, "GL_EXT_shared_texture_palette", F(EXT_shared_texture_palette) },
92 { OFF, "GL_EXT_stencil_two_side", F(EXT_stencil_two_side) },
93 { OFF, "GL_EXT_stencil_wrap", F(EXT_stencil_wrap) },
94 { ON, "GL_EXT_subtexture", 0 },
95 { ON, "GL_EXT_texture", 0 },
96 { ON, "GL_EXT_texture3D", F(EXT_texture3D) },
97 { OFF, "GL_EXT_texture_compression_s3tc", F(EXT_texture_compression_s3tc) },
98 { ON, "GL_EXT_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
99 { OFF, "GL_EXT_texture_env_add", F(EXT_texture_env_add) },
100 { OFF, "GL_EXT_texture_env_combine", F(EXT_texture_env_combine) },
101 { OFF, "GL_EXT_texture_env_dot3", F(EXT_texture_env_dot3) },
102 { OFF, "GL_EXT_texture_filter_anisotropic", F(EXT_texture_filter_anisotropic) },
103 { ON, "GL_EXT_texture_object", 0 },
104 { OFF, "GL_EXT_texture_lod_bias", F(EXT_texture_lod_bias) },
105 { OFF, "GL_EXT_texture_rectangle", F(NV_texture_rectangle) },
106 { ON, "GL_EXT_vertex_array", 0 },
107 { OFF, "GL_EXT_vertex_array_set", F(EXT_vertex_array_set) },
108 { OFF, "GL_3DFX_texture_compression_FXT1", F(TDFX_texture_compression_FXT1) },
109 { OFF, "GL_APPLE_client_storage", F(APPLE_client_storage) },
110 { ON, "GL_APPLE_packed_pixels", 0 },
111 { OFF, "GL_ATI_texture_env_combine3", F(ATI_texture_env_combine3)},
112 { OFF, "GL_ATI_texture_mirror_once", F(ATI_texture_mirror_once)},
113 { OFF, "GL_HP_occlusion_test", F(HP_occlusion_test) },
114 { OFF, "GL_IBM_multimode_draw_arrays", F(IBM_multimode_draw_arrays) },
115 { ON, "GL_IBM_rasterpos_clip", F(IBM_rasterpos_clip) },
116 { OFF, "GL_IBM_texture_mirrored_repeat", F(ARB_texture_mirrored_repeat)},
117 { OFF, "GL_INGR_blend_func_separate", F(EXT_blend_func_separate) },
118 { OFF, "GL_MESA_pack_invert", F(MESA_pack_invert) },
119 { OFF, "GL_MESA_packed_depth_stencil", F(MESA_packed_depth_stencil) },
120 { OFF, "GL_MESA_program_debug", F(MESA_program_debug) },
121 { OFF, "GL_MESA_resize_buffers", F(MESA_resize_buffers) },
122 { OFF, "GL_MESA_ycbcr_texture", F(MESA_ycbcr_texture) },
123 { ON, "GL_MESA_window_pos", F(ARB_window_pos) },
124 { OFF, "GL_NV_blend_square", F(NV_blend_square) },
125 { OFF, "GL_NV_fragment_program", F(NV_fragment_program) },
126 { ON, "GL_NV_light_max_exponent", 0 },
127 { OFF, "GL_NV_point_sprite", F(NV_point_sprite) },
128 { OFF, "GL_NV_texture_rectangle", F(NV_texture_rectangle) },
129 { ON, "GL_NV_texgen_reflection", 0 },
130 { OFF, "GL_NV_vertex_program", F(NV_vertex_program) },
131 { OFF, "GL_NV_vertex_program1_1", F(NV_vertex_program1_1) },
132 { OFF, "GL_SGI_color_matrix", F(SGI_color_matrix) },
133 { OFF, "GL_SGI_color_table", F(SGI_color_table) },
134 { OFF, "GL_SGI_texture_color_table", F(SGI_texture_color_table) },
135 { OFF, "GL_SGIS_generate_mipmap", F(SGIS_generate_mipmap) },
136 { OFF, "GL_SGIS_pixel_texture", F(SGIS_pixel_texture) },
137 { OFF, "GL_SGIS_texture_border_clamp", F(ARB_texture_border_clamp) },
138 { ON, "GL_SGIS_texture_edge_clamp", F(SGIS_texture_edge_clamp) },
139 { ON, "GL_SGIS_texture_lod", 0 },
140 { OFF, "GL_SGIX_depth_texture", F(SGIX_depth_texture) },
141 { OFF, "GL_SGIX_pixel_texture", F(SGIX_pixel_texture) },
142 { OFF, "GL_SGIX_shadow", F(SGIX_shadow) },
143 { OFF, "GL_SGIX_shadow_ambient", F(SGIX_shadow_ambient) },
144 { OFF, "GL_SUN_multi_draw_arrays", F(EXT_multi_draw_arrays) },
145 };
146
147
148
149 /**
150 * Enable all extensions suitable for a software-only renderer.
151 * This is a convenience function used by the XMesa, OSMesa, GGI drivers, etc.
152 */
153 void
154 _mesa_enable_sw_extensions(GLcontext *ctx)
155 {
156 ctx->Extensions.ARB_depth_texture = GL_TRUE;
157 #if FEATURE_ARB_fragment_program
158 ctx->Extensions.ARB_fragment_program = GL_TRUE;
159 #endif
160 ctx->Extensions.ARB_imaging = GL_TRUE;
161 ctx->Extensions.ARB_multitexture = GL_TRUE;
162 #if FEATURE_ARB_occlusion_query
163 ctx->Extensions.ARB_occlusion_query = GL_TRUE;
164 #endif
165 ctx->Extensions.ARB_point_sprite = GL_TRUE;
166 ctx->Extensions.ARB_shadow = GL_TRUE;
167 ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
168 ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
169 ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
170 ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
171 ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
172 ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
173 ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
174 #if FEATURE_ARB_vertex_program
175 /*ctx->Extensions.ARB_vertex_program = GL_TRUE;*/
176 #endif
177 ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
178 ctx->Extensions.ATI_texture_mirror_once = GL_TRUE;
179 ctx->Extensions.EXT_blend_color = GL_TRUE;
180 ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
181 ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
182 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
183 ctx->Extensions.EXT_blend_subtract = GL_TRUE;
184 ctx->Extensions.EXT_convolution = GL_TRUE;
185 ctx->Extensions.EXT_depth_bounds_test = GL_TRUE;
186 ctx->Extensions.EXT_fog_coord = GL_TRUE;
187 ctx->Extensions.EXT_histogram = GL_TRUE;
188 ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;
189 ctx->Extensions.EXT_paletted_texture = GL_TRUE;
190 ctx->Extensions.EXT_point_parameters = GL_TRUE;
191 ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
192 ctx->Extensions.EXT_secondary_color = GL_TRUE;
193 ctx->Extensions.EXT_shared_texture_palette = GL_TRUE;
194 ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
195 ctx->Extensions.EXT_stencil_two_side = GL_TRUE;
196 ctx->Extensions.EXT_texture_env_add = GL_TRUE;
197 ctx->Extensions.EXT_texture_env_combine = GL_TRUE;
198 ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
199 ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
200 ctx->Extensions.HP_occlusion_test = GL_TRUE;
201 ctx->Extensions.IBM_multimode_draw_arrays = GL_TRUE;
202 ctx->Extensions.MESA_pack_invert = GL_TRUE;
203 #if FEATURE_MESA_program_debug
204 ctx->Extensions.MESA_program_debug = GL_TRUE;
205 #endif
206 ctx->Extensions.MESA_resize_buffers = GL_TRUE;
207 ctx->Extensions.MESA_ycbcr_texture = GL_TRUE;
208 ctx->Extensions.NV_blend_square = GL_TRUE;
209 /*ctx->Extensions.NV_light_max_exponent = GL_TRUE;*/
210 ctx->Extensions.NV_point_sprite = GL_TRUE;
211 ctx->Extensions.NV_texture_rectangle = GL_TRUE;
212 /*ctx->Extensions.NV_texgen_reflection = GL_TRUE;*/
213 #if FEATURE_NV_vertex_program
214 ctx->Extensions.NV_vertex_program = GL_TRUE;
215 ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
216 #endif
217 #if FEATURE_NV_fragment_program
218 ctx->Extensions.NV_fragment_program = GL_TRUE;
219 #endif
220 ctx->Extensions.SGI_color_matrix = GL_TRUE;
221 ctx->Extensions.SGI_color_table = GL_TRUE;
222 ctx->Extensions.SGI_texture_color_table = GL_TRUE;
223 ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;
224 ctx->Extensions.SGIS_pixel_texture = GL_TRUE;
225 ctx->Extensions.SGIS_texture_edge_clamp = GL_TRUE;
226 ctx->Extensions.SGIX_depth_texture = GL_TRUE;
227 ctx->Extensions.SGIX_pixel_texture = GL_TRUE;
228 ctx->Extensions.SGIX_shadow = GL_TRUE;
229 ctx->Extensions.SGIX_shadow_ambient = GL_TRUE;
230 }
231
232
233 /**
234 * Enable GL_ARB_imaging and all the EXT extensions that are subsets of it.
235 */
236 void
237 _mesa_enable_imaging_extensions(GLcontext *ctx)
238 {
239 ctx->Extensions.ARB_imaging = GL_TRUE;
240 ctx->Extensions.EXT_blend_color = GL_TRUE;
241 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
242 ctx->Extensions.EXT_blend_subtract = GL_TRUE;
243 ctx->Extensions.EXT_convolution = GL_TRUE;
244 ctx->Extensions.EXT_histogram = GL_TRUE;
245 ctx->Extensions.SGI_color_matrix = GL_TRUE;
246 ctx->Extensions.SGI_color_table = GL_TRUE;
247 }
248
249
250
251 /**
252 * Enable all OpenGL 1.3 features and extensions.
253 * A convenience function to be called by drivers.
254 */
255 void
256 _mesa_enable_1_3_extensions(GLcontext *ctx)
257 {
258 ctx->Extensions.ARB_multisample = GL_TRUE;
259 ctx->Extensions.ARB_multitexture = GL_TRUE;
260 ctx->Extensions.ARB_texture_border_clamp = GL_TRUE;
261 ctx->Extensions.ARB_texture_compression = GL_TRUE;
262 ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
263 ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
264 ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
265 ctx->Extensions.EXT_texture_env_add = GL_TRUE;
266 /*ctx->Extensions.ARB_transpose_matrix = GL_TRUE;*/
267 }
268
269
270
271 /**
272 * Enable all OpenGL 1.4 features and extensions.
273 * A convenience function to be called by drivers.
274 */
275 void
276 _mesa_enable_1_4_extensions(GLcontext *ctx)
277 {
278 ctx->Extensions.ARB_depth_texture = GL_TRUE;
279 ctx->Extensions.ARB_shadow = GL_TRUE;
280 ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
281 ctx->Extensions.ARB_texture_mirrored_repeat = GL_TRUE;
282 ctx->Extensions.ARB_window_pos = GL_TRUE;
283 ctx->Extensions.EXT_blend_color = GL_TRUE;
284 ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
285 ctx->Extensions.EXT_blend_logic_op = GL_TRUE;
286 ctx->Extensions.EXT_blend_minmax = GL_TRUE;
287 ctx->Extensions.EXT_blend_subtract = GL_TRUE;
288 ctx->Extensions.EXT_fog_coord = GL_TRUE;
289 ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE;
290 ctx->Extensions.EXT_point_parameters = GL_TRUE;
291 ctx->Extensions.EXT_secondary_color = GL_TRUE;
292 ctx->Extensions.EXT_stencil_wrap = GL_TRUE;
293 ctx->Extensions.EXT_texture_lod_bias = GL_TRUE;
294 ctx->Extensions.SGIS_generate_mipmap = GL_TRUE;
295 }
296
297
298 /**
299 * Enable all OpenGL 1.5 features and extensions.
300 * A convenience function to be called by drivers.
301 * XXX TENTATIVE!!!
302 */
303 void
304 _mesa_enable_1_5_extensions(GLcontext *ctx)
305 {
306 ctx->Extensions.ARB_occlusion_query = GL_TRUE;
307 ctx->Extensions.ARB_point_sprite = GL_TRUE;
308 ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE;
309 ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE;
310 ctx->Extensions.EXT_shadow_funcs = GL_TRUE;
311 }
312
313
314 /**
315 * Either enable or disable the named extension.
316 */
317 static void
318 set_extension( GLcontext *ctx, const char *name, GLboolean state )
319 {
320 GLboolean *base = (GLboolean *) &ctx->Extensions;
321 GLuint i;
322
323 if (ctx->Extensions.String) {
324 /* The string was already queried - can't change it now! */
325 _mesa_problem(ctx, "Trying to enable/disable extension after glGetString(GL_EXTENSIONS): %s", name);
326 return;
327 }
328
329 for (i = 0 ; i < Elements(default_extensions) ; i++) {
330 if (_mesa_strcmp(default_extensions[i].name, name) == 0) {
331 if (default_extensions[i].flag_offset) {
332 GLboolean *enabled = base + default_extensions[i].flag_offset;
333 *enabled = state;
334 }
335 return;
336 }
337 }
338 _mesa_problem(ctx, "Trying to enable unknown extension: %s", name);
339 }
340
341
342 /**
343 * Enable the named extension.
344 * Typically called by drivers.
345 */
346 void
347 _mesa_enable_extension( GLcontext *ctx, const char *name )
348 {
349 set_extension(ctx, name, GL_TRUE);
350 }
351
352
353 /**
354 * Disable the named extension.
355 * XXX is this really needed???
356 */
357 void
358 _mesa_disable_extension( GLcontext *ctx, const char *name )
359 {
360 set_extension(ctx, name, GL_FALSE);
361 }
362
363
364 /**
365 * Test if the named extension is enabled in this context.
366 */
367 GLboolean
368 _mesa_extension_is_enabled( GLcontext *ctx, const char *name )
369 {
370 const GLboolean *base = (const GLboolean *) &ctx->Extensions;
371 GLuint i;
372
373 for (i = 0 ; i < Elements(default_extensions) ; i++) {
374 if (_mesa_strcmp(default_extensions[i].name, name) == 0) {
375 if (!default_extensions[i].flag_offset)
376 return GL_TRUE;
377 return *(base + default_extensions[i].flag_offset);
378 }
379 }
380 return GL_FALSE;
381 }
382
383
384 /**
385 * Run through the default_extensions array above and set the
386 * ctx->Extensions.ARB/EXT_* flags accordingly.
387 * To be called during context initialization.
388 */
389 void
390 _mesa_init_extensions( GLcontext *ctx )
391 {
392 GLboolean *base = (GLboolean *) &ctx->Extensions;
393 GLuint i;
394
395 for (i = 0 ; i < Elements(default_extensions) ; i++) {
396 if (default_extensions[i].enabled &&
397 default_extensions[i].flag_offset) {
398 *(base + default_extensions[i].flag_offset) = GL_TRUE;
399 }
400 }
401 }
402
403
404 /**
405 * Construct the GL_EXTENSIONS string. Called the first time that
406 * glGetString(GL_EXTENSIONS) is called.
407 */
408 GLubyte *
409 _mesa_make_extension_string( GLcontext *ctx )
410 {
411 const GLboolean *base = (const GLboolean *) &ctx->Extensions;
412 GLuint extStrLen = 0;
413 GLubyte *s;
414 GLuint i;
415
416 /* first, compute length of the extension string */
417 for (i = 0 ; i < Elements(default_extensions) ; i++) {
418 if (!default_extensions[i].flag_offset ||
419 *(base + default_extensions[i].flag_offset)) {
420 extStrLen += _mesa_strlen(default_extensions[i].name) + 1;
421 }
422 }
423 s = _mesa_malloc(extStrLen);
424
425 /* second, build the extension string */
426 extStrLen = 0;
427 for (i = 0 ; i < Elements(default_extensions) ; i++) {
428 if (!default_extensions[i].flag_offset ||
429 *(base + default_extensions[i].flag_offset)) {
430 GLuint len = _mesa_strlen(default_extensions[i].name);
431 _mesa_memcpy(s + extStrLen, default_extensions[i].name, len);
432 extStrLen += len;
433 s[extStrLen] = (GLubyte) ' ';
434 extStrLen++;
435 }
436 }
437 ASSERT(extStrLen > 0);
438
439 s[extStrLen - 1] = 0;
440
441 return s;
442 }