removed gl_get_proc_address()
[mesa.git] / src / mesa / main / extensions.c
1 /* $Id: extensions.c,v 1.15 1999/12/10 15:13:57 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.3
6 *
7 * Copyright (C) 1999 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 int 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 { ALWAYS_ENABLED, "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 { ALWAYS_ENABLED, "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_OFF, "GL_EXT_vertex_array_set" },
76 { DEFAULT_ON, "GL_EXT_clip_volume_hint" },
77 { DEFAULT_ON, "GL_EXT_texture_env_add" },
78 };
79
80
81 int gl_extensions_add( GLcontext *ctx,
82 int state,
83 const char *name,
84 void (*notify)(void) )
85 {
86 (void) notify;
87
88 if (ctx->Extensions.ext_string == 0)
89 {
90 struct extension *t = MALLOC_STRUCT(extension);
91 t->enabled = state;
92 strncpy(t->name, name, MAX_EXT_NAMELEN);
93 t->name[MAX_EXT_NAMELEN] = 0;
94 t->notify = (void (*)(GLcontext *, GLboolean)) notify;
95 insert_at_tail( ctx->Extensions.ext_list, t );
96 return 0;
97 }
98 return 1;
99 }
100
101
102 static int set_extension( GLcontext *ctx, const char *name, GLuint state )
103 {
104 struct extension *i;
105 foreach( i, ctx->Extensions.ext_list )
106 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0)
107 break;
108
109 if (i == ctx->Extensions.ext_list) return 1;
110
111 if (i->enabled && !(i->enabled & ALWAYS_ENABLED))
112 {
113 if (i->notify) i->notify( ctx, state );
114 i->enabled = state;
115 }
116
117 return 0;
118 }
119
120
121 int gl_extensions_enable( GLcontext *ctx, const char *name )
122 {
123 if (ctx->Extensions.ext_string == 0)
124 return set_extension( ctx, name, 1 );
125 return 1;
126 }
127
128
129 int gl_extensions_disable( GLcontext *ctx, const char *name )
130 {
131 if (ctx->Extensions.ext_string == 0)
132 return set_extension( ctx, name, 0 );
133 return 1;
134 }
135
136
137 /*
138 * Test if the named extension is enabled in this context.
139 */
140 GLboolean gl_extension_is_enabled( GLcontext *ctx, const char *name)
141 {
142 struct extension *i;
143 foreach( i, ctx->Extensions.ext_list )
144 if (strncmp(i->name, name, MAX_EXT_NAMELEN) == 0) {
145 if (i->enabled)
146 return GL_TRUE;
147 else
148 return GL_FALSE;
149 }
150
151 return GL_FALSE;
152 }
153
154
155 void gl_extensions_dtr( GLcontext *ctx )
156 {
157 struct extension *i, *nexti;
158
159 if (ctx->Extensions.ext_string) {
160 FREE( ctx->Extensions.ext_string );
161 ctx->Extensions.ext_string = 0;
162 }
163
164 if (ctx->Extensions.ext_list) {
165 foreach_s( i, nexti, ctx->Extensions.ext_list ) {
166 remove_from_list( i );
167 FREE( i );
168 }
169
170 FREE(ctx->Extensions.ext_list);
171 ctx->Extensions.ext_list = 0;
172 }
173 }
174
175
176 void gl_extensions_ctr( GLcontext *ctx )
177 {
178 GLuint i;
179
180 ctx->Extensions.ext_string = 0;
181 ctx->Extensions.ext_list = MALLOC_STRUCT(extension);
182 make_empty_list( ctx->Extensions.ext_list );
183
184 for (i = 0 ; i < Elements(default_extensions) ; i++) {
185 gl_extensions_add( ctx,
186 default_extensions[i].enabled,
187 default_extensions[i].name,
188 0 );
189 }
190 }
191
192
193 const char *gl_extensions_get_string( GLcontext *ctx )
194 {
195 if (ctx->Extensions.ext_string == 0)
196 {
197 struct extension *i;
198 char *str;
199 GLuint len = 0;
200 foreach (i, ctx->Extensions.ext_list)
201 if (i->enabled)
202 len += strlen(i->name) + 1;
203
204 if (len == 0)
205 return "";
206
207 str = (char *)MALLOC(len * sizeof(char));
208 ctx->Extensions.ext_string = str;
209
210 foreach (i, ctx->Extensions.ext_list)
211 if (i->enabled) {
212 strcpy(str, i->name);
213 str += strlen(str);
214 *str++ = ' ';
215 }
216
217 *(str-1) = 0;
218 }
219
220 return ctx->Extensions.ext_string;
221 }