GL_ARB_vertex_buffer_object working now, at least for non-indexed
[mesa.git] / src / mesa / main / api_arrayelt.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 /* Author:
26 * Keith Whitwell <keith@tungstengraphics.com>
27 */
28
29 #include "glheader.h"
30 #include "api_arrayelt.h"
31 #include "context.h"
32 #include "glapi.h"
33 #include "imports.h"
34 #include "macros.h"
35 #include "mtypes.h"
36
37
38 typedef void (*texarray_func)( GLenum, const void * );
39
40 typedef struct {
41 GLint unit;
42 struct gl_client_array *array;
43 texarray_func func;
44 } AEtexarray;
45
46 typedef void (*array_func)( const void * );
47
48 typedef struct {
49 struct gl_client_array *array;
50 array_func func;
51 } AEarray;
52
53 typedef struct {
54 AEtexarray texarrays[MAX_TEXTURE_COORD_UNITS + 1];
55 AEarray arrays[32];
56 GLuint NewState;
57 } AEcontext;
58
59 #define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context)
60 #define TYPE_IDX(t) ((t) & 0xf)
61
62 static void (*colorfuncs[2][8])( const void * ) = {
63 { (array_func)glColor3bv,
64 (array_func)glColor3ubv,
65 (array_func)glColor3sv,
66 (array_func)glColor3usv,
67 (array_func)glColor3iv,
68 (array_func)glColor3uiv,
69 (array_func)glColor3fv,
70 (array_func)glColor3dv },
71
72 { (array_func)glColor4bv,
73 (array_func)glColor4ubv,
74 (array_func)glColor4sv,
75 (array_func)glColor4usv,
76 (array_func)glColor4iv,
77 (array_func)glColor4uiv,
78 (array_func)glColor4fv,
79 (array_func)glColor4dv }
80 };
81
82 static void (*vertexfuncs[3][8])( const void * ) = {
83 { 0,
84 0,
85 (array_func)glVertex2sv,
86 0,
87 (array_func)glVertex2iv,
88 0,
89 (array_func)glVertex2fv,
90 (array_func)glVertex2dv },
91
92 { 0,
93 0,
94 (array_func)glVertex3sv,
95 0,
96 (array_func)glVertex3iv,
97 0,
98 (array_func)glVertex3fv,
99 (array_func)glVertex3dv },
100
101 { 0,
102 0,
103 (array_func)glVertex4sv,
104 0,
105 (array_func)glVertex4iv,
106 0,
107 (array_func)glVertex4fv,
108 (array_func)glVertex4dv }
109 };
110
111
112 static void (*multitexfuncs[4][8])( GLenum, const void * ) = {
113 { 0,
114 0,
115 (texarray_func)glMultiTexCoord1svARB,
116 0,
117 (texarray_func)glMultiTexCoord1ivARB,
118 0,
119 (texarray_func)glMultiTexCoord1fvARB,
120 (texarray_func)glMultiTexCoord1dvARB },
121
122 { 0,
123 0,
124 (texarray_func)glMultiTexCoord2svARB,
125 0,
126 (texarray_func)glMultiTexCoord2ivARB,
127 0,
128 (texarray_func)glMultiTexCoord2fvARB,
129 (texarray_func)glMultiTexCoord2dvARB },
130
131 { 0,
132 0,
133 (texarray_func)glMultiTexCoord3svARB,
134 0,
135 (texarray_func)glMultiTexCoord3ivARB,
136 0,
137 (texarray_func)glMultiTexCoord3fvARB,
138 (texarray_func)glMultiTexCoord3dvARB },
139
140 { 0,
141 0,
142 (texarray_func)glMultiTexCoord4svARB,
143 0,
144 (texarray_func)glMultiTexCoord4ivARB,
145 0,
146 (texarray_func)glMultiTexCoord4fvARB,
147 (texarray_func)glMultiTexCoord4dvARB }
148 };
149
150 static void (*indexfuncs[8])( const void * ) = {
151 0,
152 (array_func)glIndexubv,
153 (array_func)glIndexsv,
154 0,
155 (array_func)glIndexiv,
156 0,
157 (array_func)glIndexfv,
158 (array_func)glIndexdv
159 };
160
161
162 static void (*normalfuncs[8])( const void * ) = {
163 (array_func)glNormal3bv,
164 0,
165 (array_func)glNormal3sv,
166 0,
167 (array_func)glNormal3iv,
168 0,
169 (array_func)glNormal3fv,
170 (array_func)glNormal3dv,
171 };
172
173
174 /* Wrapper functions in case glSecondaryColor*EXT doesn't exist */
175 static void SecondaryColor3bvEXT(const GLbyte *c)
176 {
177 _glapi_Dispatch->SecondaryColor3bvEXT(c);
178 }
179
180 static void SecondaryColor3ubvEXT(const GLubyte *c)
181 {
182 _glapi_Dispatch->SecondaryColor3ubvEXT(c);
183 }
184
185 static void SecondaryColor3svEXT(const GLshort *c)
186 {
187 _glapi_Dispatch->SecondaryColor3svEXT(c);
188 }
189
190 static void SecondaryColor3usvEXT(const GLushort *c)
191 {
192 _glapi_Dispatch->SecondaryColor3usvEXT(c);
193 }
194
195 static void SecondaryColor3ivEXT(const GLint *c)
196 {
197 _glapi_Dispatch->SecondaryColor3ivEXT(c);
198 }
199
200 static void SecondaryColor3uivEXT(const GLuint *c)
201 {
202 _glapi_Dispatch->SecondaryColor3uivEXT(c);
203 }
204
205 static void SecondaryColor3fvEXT(const GLfloat *c)
206 {
207 _glapi_Dispatch->SecondaryColor3fvEXT(c);
208 }
209
210 static void SecondaryColor3dvEXT(const GLdouble *c)
211 {
212 _glapi_Dispatch->SecondaryColor3dvEXT(c);
213 }
214
215 static void (*secondarycolorfuncs[8])( const void * ) = {
216 (array_func) SecondaryColor3bvEXT,
217 (array_func) SecondaryColor3ubvEXT,
218 (array_func) SecondaryColor3svEXT,
219 (array_func) SecondaryColor3usvEXT,
220 (array_func) SecondaryColor3ivEXT,
221 (array_func) SecondaryColor3uivEXT,
222 (array_func) SecondaryColor3fvEXT,
223 (array_func) SecondaryColor3dvEXT,
224 };
225
226
227 /* Again, wrapper functions in case glSecondaryColor*EXT doesn't exist */
228 static void FogCoordfvEXT(const GLfloat *f)
229 {
230 _glapi_Dispatch->FogCoordfvEXT(f);
231 }
232
233 static void FogCoorddvEXT(const GLdouble *f)
234 {
235 _glapi_Dispatch->FogCoorddvEXT(f);
236 }
237
238 static void (*fogcoordfuncs[8])( const void * ) = {
239 0,
240 0,
241 0,
242 0,
243 0,
244 0,
245 (array_func) FogCoordfvEXT,
246 (array_func) FogCoorddvEXT
247 };
248
249
250
251 GLboolean _ae_create_context( GLcontext *ctx )
252 {
253 ctx->aelt_context = MALLOC( sizeof(AEcontext) );
254 if (!ctx->aelt_context)
255 return GL_FALSE;
256
257 AE_CONTEXT(ctx)->NewState = ~0;
258 return GL_TRUE;
259 }
260
261
262 void _ae_destroy_context( GLcontext *ctx )
263 {
264 if ( AE_CONTEXT( ctx ) ) {
265 FREE( ctx->aelt_context );
266 ctx->aelt_context = 0;
267 }
268 }
269
270
271 static void _ae_update_state( GLcontext *ctx )
272 {
273 AEcontext *actx = AE_CONTEXT(ctx);
274 AEtexarray *ta = actx->texarrays;
275 AEarray *aa = actx->arrays;
276 GLuint i;
277
278 for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++)
279 if (ctx->Array.TexCoord[i].Enabled) {
280 ta->unit = i;
281 ta->array = &ctx->Array.TexCoord[i];
282 ta->func = multitexfuncs[ta->array->Size-1][TYPE_IDX(ta->array->Type)];
283 ta++;
284 }
285
286 ta->func = 0;
287
288 if (ctx->Array.Color.Enabled) {
289 aa->array = &ctx->Array.Color;
290 aa->func = colorfuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
291 aa++;
292 }
293
294 if (ctx->Array.Normal.Enabled) {
295 aa->array = &ctx->Array.Normal;
296 aa->func = normalfuncs[TYPE_IDX(aa->array->Type)];
297 aa++;
298 }
299
300 if (ctx->Array.Index.Enabled) {
301 aa->array = &ctx->Array.Index;
302 aa->func = indexfuncs[TYPE_IDX(aa->array->Type)];
303 aa++;
304 }
305
306 if (ctx->Array.EdgeFlag.Enabled) {
307 aa->array = &ctx->Array.EdgeFlag;
308 aa->func = (array_func)glEdgeFlagv;
309 aa++;
310 }
311
312 if (ctx->Array.FogCoord.Enabled) {
313 aa->array = &ctx->Array.FogCoord;
314 aa->func = fogcoordfuncs[TYPE_IDX(aa->array->Type)];
315 aa++;
316 }
317
318 if (ctx->Array.SecondaryColor.Enabled) {
319 aa->array = &ctx->Array.SecondaryColor;
320 aa->func = secondarycolorfuncs[TYPE_IDX(aa->array->Type)];
321 aa++;
322 }
323
324 /* Must be last
325 */
326 if (ctx->Array.Vertex.Enabled) {
327 aa->array = &ctx->Array.Vertex;
328 aa->func = vertexfuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
329 aa++;
330 }
331
332 aa->func = 0;
333 actx->NewState = 0;
334 }
335
336
337 void _ae_loopback_array_elt( GLint elt )
338 {
339 GET_CURRENT_CONTEXT(ctx);
340 AEcontext *actx = AE_CONTEXT(ctx);
341 AEtexarray *ta;
342 AEarray *aa;
343
344 if (actx->NewState)
345 _ae_update_state( ctx );
346
347 for (ta = actx->texarrays ; ta->func ; ta++) {
348 GLubyte *src = ta->array->BufferObj->Data
349 + (GLuint) ta->array->Ptr
350 + elt * ta->array->StrideB;
351 ta->func( ta->unit + GL_TEXTURE0_ARB, src);
352 }
353
354 /* Must be last
355 */
356 for (aa = actx->arrays ; aa->func ; aa++) {
357 GLubyte *src = aa->array->BufferObj->Data
358 + (GLuint) aa->array->Ptr
359 + elt * aa->array->StrideB;
360 aa->func( src );
361 }
362 }
363
364
365
366 void _ae_invalidate_state( GLcontext *ctx, GLuint new_state )
367 {
368 AE_CONTEXT(ctx)->NewState |= new_state;
369 }