1 /* $Id: extensions.c,v 1.30 2000/05/30 02:28:03 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #include "extensions.h"
35 #include "simple_list.h"
40 #define MAX_EXT_NAMELEN 80
43 struct extension
*next
, *prev
;
45 char name
[MAX_EXT_NAMELEN
+1];
46 void (*notify
)( GLcontext
*, GLboolean
);
51 static struct { int enabled
; const char *name
; } default_extensions
[] = {
52 { DEFAULT_OFF
, "GL_ARB_imaging" }, /* in progress */
53 { DEFAULT_ON
, "GL_ARB_multitexture" },
54 { DEFAULT_OFF
, "GL_ARB_texture_compression" }, /* in progress */
55 { DEFAULT_OFF
, "GL_ARB_texture_cube_map" }, /* in progress */
56 { ALWAYS_ENABLED
, "GL_ARB_tranpose_matrix" },
57 { ALWAYS_ENABLED
, "GL_EXT_abgr" },
58 { DEFAULT_ON
, "GL_EXT_blend_color" },
59 { DEFAULT_ON
, "GL_EXT_blend_func_separate" },
60 { DEFAULT_ON
, "GL_EXT_blend_logic_op" },
61 { DEFAULT_ON
, "GL_EXT_blend_minmax" },
62 { DEFAULT_ON
, "GL_EXT_blend_subtract" },
63 { DEFAULT_ON
, "GL_EXT_clip_volume_hint" },
64 { DEFAULT_OFF
, "GL_EXT_convolution" }, /* in progress */
65 { DEFAULT_ON
, "GL_EXT_compiled_vertex_array" },
66 { DEFAULT_ON
, "GL_EXT_histogram" },
67 { DEFAULT_ON
, "GL_EXT_paletted_texture" },
68 { DEFAULT_ON
, "GL_EXT_point_parameters" },
69 { ALWAYS_ENABLED
, "GL_EXT_polygon_offset" },
70 { ALWAYS_ENABLED
, "GL_EXT_rescale_normal" },
71 { DEFAULT_ON
, "GL_EXT_shared_texture_palette" },
72 { ALWAYS_ENABLED
, "GL_EXT_stencil_wrap" },
73 { DEFAULT_ON
, "GL_EXT_texture3D" },
74 { DEFAULT_OFF
, "GL_EXT_texture_compression_s3tc" },
75 { DEFAULT_OFF
, "GL_EXT_texture_env" },
76 { DEFAULT_ON
, "GL_EXT_texture_env_add" },
77 { ALWAYS_ENABLED
, "GL_EXT_texture_object" },
78 { DEFAULT_ON
, "GL_EXT_texture_lod_bias" },
79 { ALWAYS_ENABLED
, "GL_EXT_vertex_array" },
80 { DEFAULT_OFF
, "GL_EXT_vertex_array_set" },
81 { DEFAULT_OFF
, "GL_HP_occlusion_test" },
82 { DEFAULT_ON
, "GL_INGR_blend_func_separate" },
83 { ALWAYS_ENABLED
, "GL_MESA_window_pos" },
84 { ALWAYS_ENABLED
, "GL_MESA_resize_buffers" },
85 { DEFAULT_OFF
, "GL_NV_blend_square" },
86 { ALWAYS_ENABLED
, "GL_NV_texgen_reflection" },
87 { DEFAULT_ON
, "GL_PGI_misc_hints" },
88 { DEFAULT_ON
, "GL_SGI_color_matrix" },
89 { DEFAULT_ON
, "GL_SGI_color_table" },
90 { DEFAULT_ON
, "GL_SGIS_pixel_texture" },
91 { DEFAULT_ON
, "GL_SGIS_texture_edge_clamp" },
92 { DEFAULT_ON
, "GL_SGIX_pixel_texture" },
93 { DEFAULT_OFF
, "GL_3DFX_texture_compression_FXT1" }
98 * Update the boolean convenience flags in the Extensions struct.
101 update_extension_flags( GLcontext
*ctx
)
104 ctx
->Extensions
.HaveTextureEnvAdd
= gl_extension_is_enabled(ctx
, "GL_EXT_texture_env_add");
105 ctx
->Extensions
.HaveTextureLodBias
= gl_extension_is_enabled(ctx
, "GL_EXT_texture_lod_bias");
106 ctx
->Extensions
.HaveHpOcclusionTest
= gl_extension_is_enabled(ctx
, "GL_HP_occlusion_test");
107 ctx
->Extensions
.HaveTextureCubeMap
= gl_extension_is_enabled(ctx
, "GL_ARB_texture_cube_map");
108 ctx
->Extensions
.HaveTextureCompression
= gl_extension_is_enabled(ctx
, "GL_ARB_texture_compression");
109 ctx
->Extensions
.HaveTextureCompressionS3TC
= gl_extension_is_enabled(ctx
, "GL_EXT_texture_compression_s3tc");
110 ctx
->Extensions
.HaveTextureCompressionFXT1
= gl_extension_is_enabled(ctx
, "GL_3DFX_texture_compression_FXT1");
111 ctx
->Extensions
.HaveBlendSquare
= gl_extension_is_enabled(ctx
, "GL_NV_blend_square");
116 int gl_extensions_add( GLcontext
*ctx
,
119 void (*notify
)(void) )
123 if (ctx
->Extensions
.ext_string
== 0)
125 struct extension
*t
= MALLOC_STRUCT(extension
);
127 strncpy(t
->name
, name
, MAX_EXT_NAMELEN
);
128 t
->name
[MAX_EXT_NAMELEN
] = 0;
129 t
->notify
= (void (*)(GLcontext
*, GLboolean
)) notify
;
130 insert_at_tail( ctx
->Extensions
.ext_list
, t
);
138 * Either enable or disable the named extension.
140 static int set_extension( GLcontext
*ctx
, const char *name
, GLint state
)
143 foreach( i
, ctx
->Extensions
.ext_list
)
144 if (strncmp(i
->name
, name
, MAX_EXT_NAMELEN
) == 0)
147 if (i
== ctx
->Extensions
.ext_list
)
150 if (!(i
->enabled
& ALWAYS_ENABLED
)) {
151 if (i
->notify
) i
->notify( ctx
, state
);
155 update_extension_flags(ctx
);
161 int gl_extensions_enable( GLcontext
*ctx
, const char *name
)
163 if (ctx
->Extensions
.ext_string
== 0)
164 return set_extension( ctx
, name
, 1 );
169 int gl_extensions_disable( GLcontext
*ctx
, const char *name
)
171 if (ctx
->Extensions
.ext_string
== 0)
172 return set_extension( ctx
, name
, 0 );
178 * Test if the named extension is enabled in this context.
180 GLboolean
gl_extension_is_enabled( GLcontext
*ctx
, const char *name
)
183 foreach( i
, ctx
->Extensions
.ext_list
)
184 if (strncmp(i
->name
, name
, MAX_EXT_NAMELEN
) == 0) {
195 void gl_extensions_dtr( GLcontext
*ctx
)
197 struct extension
*i
, *nexti
;
199 if (ctx
->Extensions
.ext_string
) {
200 FREE( ctx
->Extensions
.ext_string
);
201 ctx
->Extensions
.ext_string
= 0;
204 if (ctx
->Extensions
.ext_list
) {
205 foreach_s( i
, nexti
, ctx
->Extensions
.ext_list
) {
206 remove_from_list( i
);
210 FREE(ctx
->Extensions
.ext_list
);
211 ctx
->Extensions
.ext_list
= 0;
216 void gl_extensions_ctr( GLcontext
*ctx
)
220 ctx
->Extensions
.ext_string
= 0;
221 ctx
->Extensions
.ext_list
= MALLOC_STRUCT(extension
);
222 make_empty_list( ctx
->Extensions
.ext_list
);
224 for (i
= 0 ; i
< Elements(default_extensions
) ; i
++) {
225 gl_extensions_add( ctx
,
226 default_extensions
[i
].enabled
,
227 default_extensions
[i
].name
,
230 update_extension_flags(ctx
);
234 const char *gl_extensions_get_string( GLcontext
*ctx
)
236 if (ctx
->Extensions
.ext_string
== 0)
241 foreach (i
, ctx
->Extensions
.ext_list
)
243 len
+= strlen(i
->name
) + 1;
248 str
= (char *)MALLOC(len
* sizeof(char));
249 ctx
->Extensions
.ext_string
= str
;
251 foreach (i
, ctx
->Extensions
.ext_list
)
253 strcpy(str
, i
->name
);
261 return ctx
->Extensions
.ext_string
;