added Window-isms previously in gl.h
[mesa.git] / src / mesa / main / extensions.c
1 /* $Id: extensions.c,v 1.25 2000/05/04 13:48:49 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.3
6 *
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 */
26
27
28 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "context.h"
33 #include "extensions.h"
34 #include "mem.h"
35 #include "simple_list.h"
36 #include "types.h"
37 #endif
38
39
40 #define MAX_EXT_NAMELEN 80
41
42 struct extension {
43 struct extension *next, *prev;
44 GLint enabled;
45 char name[MAX_EXT_NAMELEN+1];
46 void (*notify)( GLcontext *, GLboolean );
47 };
48
49
50
51 static struct { int enabled; const char *name; } default_extensions[] = {
52 { DEFAULT_OFF, "GL_ARB_imaging" },
53 { DEFAULT_ON, "GL_ARB_multitexture" },
54 { ALWAYS_ENABLED, "GL_ARB_tranpose_matrix" },
55 { ALWAYS_ENABLED, "GL_EXT_abgr" },
56 { DEFAULT_ON, "GL_EXT_blend_color" },
57 { DEFAULT_ON, "GL_EXT_blend_logic_op" },
58 { DEFAULT_ON, "GL_EXT_blend_minmax" },
59 { DEFAULT_ON, "GL_EXT_blend_subtract" },
60 { DEFAULT_ON, "GL_EXT_clip_volume_hint" },
61 { DEFAULT_ON, "GL_EXT_compiled_vertex_array" },
62 { DEFAULT_ON, "GL_EXT_histogram" },
63 { DEFAULT_ON, "GL_EXT_paletted_texture" },
64 { DEFAULT_ON, "GL_EXT_point_parameters" },
65 { ALWAYS_ENABLED, "GL_EXT_polygon_offset" },
66 { ALWAYS_ENABLED, "GL_EXT_rescale_normal" },
67 { DEFAULT_ON, "GL_EXT_shared_texture_palette" },
68 { ALWAYS_ENABLED, "GL_EXT_stencil_wrap" },
69 { DEFAULT_ON, "GL_EXT_texture3D" },
70 { DEFAULT_OFF, "GL_EXT_texture_env" },
71 { DEFAULT_ON, "GL_EXT_texture_env_add" },
72 { ALWAYS_ENABLED, "GL_EXT_texture_object" },
73 { DEFAULT_ON, "GL_EXT_texture_lod_bias" },
74 { ALWAYS_ENABLED, "GL_EXT_vertex_array" },
75 { DEFAULT_OFF, "GL_EXT_vertex_array_set" },
76 { DEFAULT_OFF, "GL_HP_occlusion_test" },
77 { DEFAULT_ON, "GL_INGR_blend_func_separate" },
78 { ALWAYS_ENABLED, "GL_MESA_window_pos" },
79 { ALWAYS_ENABLED, "GL_MESA_resize_buffers" },
80 { ALWAYS_ENABLED, "GL_NV_texgen_reflection" },
81 { DEFAULT_ON, "GL_PGI_misc_hints" },
82 { DEFAULT_ON, "GL_SGI_color_matrix" },
83 { DEFAULT_ON, "GL_SGI_color_table" },
84 { DEFAULT_ON, "GL_SGIS_pixel_texture" },
85 { DEFAULT_ON, "GL_SGIS_texture_edge_clamp" },
86 { DEFAULT_ON, "GL_SGIX_pixel_texture" }
87 };
88
89
90 /*
91 * Update the boolean convenience flags in the Extensions struct.
92 */
93 static void
94 update_extension_flags( GLcontext *ctx )
95 {
96 /* Update flags */
97 ctx->Extensions.HaveTextureEnvAdd = gl_extension_is_enabled(ctx, "GL_EXT_texture_env_add");
98 ctx->Extensions.HaveTextureLodBias = gl_extension_is_enabled(ctx, "GL_EXT_texture_lod_bias");
99 ctx->Extensions.HaveHpOcclusionTest = gl_extension_is_enabled(ctx, "GL_HP_occlusion_test");
100 }
101
102
103
104 int gl_extensions_add( GLcontext *ctx,
105 int state,
106 const char *name,
107 void (*notify)(void) )
108 {
109 (void) notify;
110
111 if (ctx->Extensions.ext_string == 0)
112 {
113 struct extension *t = MALLOC_STRUCT(extension);
114 t->enabled = state;
115 strncpy(t->name, name, MAX_EXT_NAMELEN);
116 t->name[MAX_EXT_NAMELEN] = 0;
117 t->notify = (void (*)(GLcontext *, GLboolean)) notify;
118 insert_at_tail( ctx->Extensions.ext_list, t );
119 return 0;
120 }
121 return 1;
122 }
123
124
125 /*
126 * Either enable or disable the named extension.
127 */
128 static int set_extension( GLcontext *ctx, const char *name, GLint state )
129 {
130 struct extension *i;
131 foreach( i, ctx->Extensions.ext_list )
132 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0)
133 break;
134
135 if (i == ctx->Extensions.ext_list)
136 return 1;
137
138 if (!(i->enabled & ALWAYS_ENABLED)) {
139 if (i->notify) i->notify( ctx, state );
140 i->enabled = state;
141 }
142
143 update_extension_flags(ctx);
144
145 return 0;
146 }
147
148
149 int gl_extensions_enable( GLcontext *ctx, const char *name )
150 {
151 if (ctx->Extensions.ext_string == 0)
152 return set_extension( ctx, name, 1 );
153 return 1;
154 }
155
156
157 int gl_extensions_disable( GLcontext *ctx, const char *name )
158 {
159 if (ctx->Extensions.ext_string == 0)
160 return set_extension( ctx, name, 0 );
161 return 1;
162 }
163
164
165 /*
166 * Test if the named extension is enabled in this context.
167 */
168 GLboolean gl_extension_is_enabled( GLcontext *ctx, const char *name)
169 {
170 struct extension *i;
171 foreach( i, ctx->Extensions.ext_list )
172 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0) {
173 if (i->enabled)
174 return GL_TRUE;
175 else
176 return GL_FALSE;
177 }
178
179 return GL_FALSE;
180 }
181
182
183 void gl_extensions_dtr( GLcontext *ctx )
184 {
185 struct extension *i, *nexti;
186
187 if (ctx->Extensions.ext_string) {
188 FREE( ctx->Extensions.ext_string );
189 ctx->Extensions.ext_string = 0;
190 }
191
192 if (ctx->Extensions.ext_list) {
193 foreach_s( i, nexti, ctx->Extensions.ext_list ) {
194 remove_from_list( i );
195 FREE( i );
196 }
197
198 FREE(ctx->Extensions.ext_list);
199 ctx->Extensions.ext_list = 0;
200 }
201 }
202
203
204 void gl_extensions_ctr( GLcontext *ctx )
205 {
206 GLuint i;
207
208 ctx->Extensions.ext_string = 0;
209 ctx->Extensions.ext_list = MALLOC_STRUCT(extension);
210 make_empty_list( ctx->Extensions.ext_list );
211
212 for (i = 0 ; i < Elements(default_extensions) ; i++) {
213 gl_extensions_add( ctx,
214 default_extensions[i].enabled,
215 default_extensions[i].name,
216 0 );
217 }
218 update_extension_flags(ctx);
219 }
220
221
222 const char *gl_extensions_get_string( GLcontext *ctx )
223 {
224 if (ctx->Extensions.ext_string == 0)
225 {
226 struct extension *i;
227 char *str;
228 GLuint len = 0;
229 foreach (i, ctx->Extensions.ext_list)
230 if (i->enabled)
231 len += strlen(i->name) + 1;
232
233 if (len == 0)
234 return "";
235
236 str = (char *)MALLOC(len * sizeof(char));
237 ctx->Extensions.ext_string = str;
238
239 foreach (i, ctx->Extensions.ext_list)
240 if (i->enabled) {
241 strcpy(str, i->name);
242 str += strlen(str);
243 *str++ = ' ';
244 }
245
246 *(str-1) = 0;
247 }
248
249 return ctx->Extensions.ext_string;
250 }