added GL_SGIX/SGIS_pixel_texture
[mesa.git] / src / mesa / main / extensions.c
1 /* $Id: extensions.c,v 1.22 2000/04/07 16:27:26 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_ON, "GL_EXT_blend_color" },
53 { DEFAULT_OFF, "ARB_imaging" },
54 { DEFAULT_ON, "GL_EXT_blend_minmax" },
55 { DEFAULT_ON, "GL_EXT_blend_logic_op" },
56 { DEFAULT_ON, "GL_EXT_blend_subtract" },
57 { DEFAULT_ON, "GL_EXT_paletted_texture" },
58 { DEFAULT_ON, "GL_EXT_point_parameters" },
59 { ALWAYS_ENABLED, "GL_EXT_polygon_offset" },
60 { ALWAYS_ENABLED, "GL_EXT_vertex_array" },
61 { ALWAYS_ENABLED, "GL_EXT_texture_object" },
62 { DEFAULT_ON, "GL_EXT_texture3D" },
63 { ALWAYS_ENABLED, "GL_MESA_window_pos" },
64 { ALWAYS_ENABLED, "GL_MESA_resize_buffers" },
65 { DEFAULT_ON, "GL_EXT_shared_texture_palette" },
66 { ALWAYS_ENABLED, "GL_EXT_rescale_normal" },
67 { ALWAYS_ENABLED, "GL_EXT_abgr" },
68 { ALWAYS_ENABLED, "GL_SGIS_texture_edge_clamp" },
69 { ALWAYS_ENABLED, "GL_EXT_stencil_wrap" },
70 { DEFAULT_ON, "GL_INGR_blend_func_separate" },
71 { DEFAULT_ON, "GL_ARB_multitexture" },
72 { ALWAYS_ENABLED, "GL_NV_texgen_reflection" },
73 { DEFAULT_ON, "GL_PGI_misc_hints" },
74 { DEFAULT_ON, "GL_EXT_compiled_vertex_array" },
75 { DEFAULT_ON, "GL_EXT_clip_volume_hint" },
76 { DEFAULT_ON, "GL_EXT_texture_env_add" },
77 { ALWAYS_ENABLED, "GL_ARB_tranpose_matrix" },
78 { DEFAULT_OFF, "GL_EXT_vertex_array_set" },
79 { DEFAULT_OFF, "GL_EXT_texture_env" },
80 { DEFAULT_ON, "GL_EXT_texture_lod_bias" },
81 { DEFAULT_OFF, "GL_HP_occlusion_test" },
82 { DEFAULT_ON, "GL_SGIS_pixel_texture" },
83 { DEFAULT_ON, "GL_SGIX_pixel_texture" }
84 };
85
86
87 /*
88 * Update the boolean convenience flags in the Extensions struct.
89 */
90 static void
91 update_extension_flags( GLcontext *ctx )
92 {
93 /* Update flags */
94 ctx->Extensions.HaveTextureEnvAdd = gl_extension_is_enabled(ctx, "GL_EXT_texture_env_add");
95 ctx->Extensions.HaveTextureLodBias = gl_extension_is_enabled(ctx, "GL_EXT_texture_lod_bias");
96 ctx->Extensions.HaveHpOcclusionTest = gl_extension_is_enabled(ctx, "GL_HP_occlusion_test");
97 }
98
99
100
101 int gl_extensions_add( GLcontext *ctx,
102 int state,
103 const char *name,
104 void (*notify)(void) )
105 {
106 (void) notify;
107
108 if (ctx->Extensions.ext_string == 0)
109 {
110 struct extension *t = MALLOC_STRUCT(extension);
111 t->enabled = state;
112 strncpy(t->name, name, MAX_EXT_NAMELEN);
113 t->name[MAX_EXT_NAMELEN] = 0;
114 t->notify = (void (*)(GLcontext *, GLboolean)) notify;
115 insert_at_tail( ctx->Extensions.ext_list, t );
116 return 0;
117 }
118 return 1;
119 }
120
121
122 /*
123 * Either enable or disable the named extension.
124 */
125 static int set_extension( GLcontext *ctx, const char *name, GLint state )
126 {
127 struct extension *i;
128 foreach( i, ctx->Extensions.ext_list )
129 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0)
130 break;
131
132 if (i == ctx->Extensions.ext_list)
133 return 1;
134
135 if (!(i->enabled & ALWAYS_ENABLED)) {
136 if (i->notify) i->notify( ctx, state );
137 i->enabled = state;
138 }
139
140 update_extension_flags(ctx);
141
142 return 0;
143 }
144
145
146 int gl_extensions_enable( GLcontext *ctx, const char *name )
147 {
148 if (ctx->Extensions.ext_string == 0)
149 return set_extension( ctx, name, 1 );
150 return 1;
151 }
152
153
154 int gl_extensions_disable( GLcontext *ctx, const char *name )
155 {
156 if (ctx->Extensions.ext_string == 0)
157 return set_extension( ctx, name, 0 );
158 return 1;
159 }
160
161
162 /*
163 * Test if the named extension is enabled in this context.
164 */
165 GLboolean gl_extension_is_enabled( GLcontext *ctx, const char *name)
166 {
167 struct extension *i;
168 foreach( i, ctx->Extensions.ext_list )
169 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0) {
170 if (i->enabled)
171 return GL_TRUE;
172 else
173 return GL_FALSE;
174 }
175
176 return GL_FALSE;
177 }
178
179
180 void gl_extensions_dtr( GLcontext *ctx )
181 {
182 struct extension *i, *nexti;
183
184 if (ctx->Extensions.ext_string) {
185 FREE( ctx->Extensions.ext_string );
186 ctx->Extensions.ext_string = 0;
187 }
188
189 if (ctx->Extensions.ext_list) {
190 foreach_s( i, nexti, ctx->Extensions.ext_list ) {
191 remove_from_list( i );
192 FREE( i );
193 }
194
195 FREE(ctx->Extensions.ext_list);
196 ctx->Extensions.ext_list = 0;
197 }
198 }
199
200
201 void gl_extensions_ctr( GLcontext *ctx )
202 {
203 GLuint i;
204
205 ctx->Extensions.ext_string = 0;
206 ctx->Extensions.ext_list = MALLOC_STRUCT(extension);
207 make_empty_list( ctx->Extensions.ext_list );
208
209 for (i = 0 ; i < Elements(default_extensions) ; i++) {
210 gl_extensions_add( ctx,
211 default_extensions[i].enabled,
212 default_extensions[i].name,
213 0 );
214 }
215 update_extension_flags(ctx);
216 }
217
218
219 const char *gl_extensions_get_string( GLcontext *ctx )
220 {
221 if (ctx->Extensions.ext_string == 0)
222 {
223 struct extension *i;
224 char *str;
225 GLuint len = 0;
226 foreach (i, ctx->Extensions.ext_list)
227 if (i->enabled)
228 len += strlen(i->name) + 1;
229
230 if (len == 0)
231 return "";
232
233 str = (char *)MALLOC(len * sizeof(char));
234 ctx->Extensions.ext_string = str;
235
236 foreach (i, ctx->Extensions.ext_list)
237 if (i->enabled) {
238 strcpy(str, i->name);
239 str += strlen(str);
240 *str++ = ' ';
241 }
242
243 *(str-1) = 0;
244 }
245
246 return ctx->Extensions.ext_string;
247 }