blob: 93ba0b7bc3546cb2b3f7edc09a7793800241d995 [file] [log] [blame]
Gareth Hughes22144ab2001-03-12 00:48:37 +00001/*
2 * Mesa 3-D graphics library
Brian Paul610d5992003-01-14 04:55:45 +00003 * Version: 5.1
Gareth Hughes22144ab2001-03-12 00:48:37 +00004 *
Brian Paul92f97852003-05-01 22:44:02 +00005 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
Gareth Hughes22144ab2001-03-12 00:48:37 +00006 *
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
Keith Whitwellfc00cbe2001-12-20 15:30:45 +000025/* Author:
Brian Paul05a4b372002-10-29 20:28:36 +000026 * Keith Whitwell <keith@tungstengraphics.com>
Keith Whitwellfc00cbe2001-12-20 15:30:45 +000027 */
28
Keith Whitwellcab974c2000-12-26 05:09:27 +000029#include "glheader.h"
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000030#include "api_arrayelt.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000031#include "context.h"
Keith Whitwellfc00cbe2001-12-20 15:30:45 +000032#include "glapi.h"
Brian Paul3c634522002-10-24 23:57:19 +000033#include "imports.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000034#include "macros.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000035#include "mtypes.h"
36
37
Karl Schultzb72902e2004-01-28 22:24:12 +000038typedef void (GLAPIENTRY *texarray_func)( GLenum, const void * );
Gareth Hughes1fb0a432001-12-28 06:28:10 +000039
Keith Whitwellcab974c2000-12-26 05:09:27 +000040typedef struct {
41 GLint unit;
42 struct gl_client_array *array;
Gareth Hughes1fb0a432001-12-28 06:28:10 +000043 texarray_func func;
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000044} AEtexarray;
Gareth Hughes22144ab2001-03-12 00:48:37 +000045
Karl Schultzb72902e2004-01-28 22:24:12 +000046typedef void (GLAPIENTRY *array_func)( const void * );
Keith Whitwellcab974c2000-12-26 05:09:27 +000047
48typedef struct {
49 struct gl_client_array *array;
Gareth Hughes1fb0a432001-12-28 06:28:10 +000050 array_func func;
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000051} AEarray;
Keith Whitwellcab974c2000-12-26 05:09:27 +000052
53typedef struct {
Brian Paul610d5992003-01-14 04:55:45 +000054 AEtexarray texarrays[MAX_TEXTURE_COORD_UNITS + 1];
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000055 AEarray arrays[32];
Keith Whitwellcab974c2000-12-26 05:09:27 +000056 GLuint NewState;
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000057} AEcontext;
Keith Whitwellcab974c2000-12-26 05:09:27 +000058
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000059#define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context)
60#define TYPE_IDX(t) ((t) & 0xf)
Keith Whitwellcab974c2000-12-26 05:09:27 +000061
Karl Schultzb72902e2004-01-28 22:24:12 +000062static void (GLAPIENTRY *colorfuncs[2][8])( const void * ) = {
Gareth Hughes1fb0a432001-12-28 06:28:10 +000063 { (array_func)glColor3bv,
Keith Whitwell306d3fc2002-04-09 16:56:50 +000064 (array_func)glColor3ubv,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000065 (array_func)glColor3sv,
66 (array_func)glColor3usv,
67 (array_func)glColor3iv,
68 (array_func)glColor3uiv,
69 (array_func)glColor3fv,
70 (array_func)glColor3dv },
Keith Whitwellcab974c2000-12-26 05:09:27 +000071
Gareth Hughes1fb0a432001-12-28 06:28:10 +000072 { (array_func)glColor4bv,
Keith Whitwell306d3fc2002-04-09 16:56:50 +000073 (array_func)glColor4ubv,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000074 (array_func)glColor4sv,
75 (array_func)glColor4usv,
76 (array_func)glColor4iv,
77 (array_func)glColor4uiv,
78 (array_func)glColor4fv,
79 (array_func)glColor4dv }
Keith Whitwellcab974c2000-12-26 05:09:27 +000080};
81
Karl Schultzb72902e2004-01-28 22:24:12 +000082static void (GLAPIENTRY *vertexfuncs[3][8])( const void * ) = {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000083 { 0,
84 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000085 (array_func)glVertex2sv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000086 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000087 (array_func)glVertex2iv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000088 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000089 (array_func)glVertex2fv,
90 (array_func)glVertex2dv },
Keith Whitwellcab974c2000-12-26 05:09:27 +000091
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000092 { 0,
93 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000094 (array_func)glVertex3sv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000095 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000096 (array_func)glVertex3iv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000097 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000098 (array_func)glVertex3fv,
99 (array_func)glVertex3dv },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000100
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000101 { 0,
102 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000103 (array_func)glVertex4sv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000104 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000105 (array_func)glVertex4iv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000106 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000107 (array_func)glVertex4fv,
108 (array_func)glVertex4dv }
Keith Whitwellcab974c2000-12-26 05:09:27 +0000109};
110
111
Karl Schultzb72902e2004-01-28 22:24:12 +0000112static void (GLAPIENTRY *multitexfuncs[4][8])( GLenum, const void * ) = {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000113 { 0,
114 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000115 (texarray_func)glMultiTexCoord1svARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000116 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000117 (texarray_func)glMultiTexCoord1ivARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000118 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000119 (texarray_func)glMultiTexCoord1fvARB,
120 (texarray_func)glMultiTexCoord1dvARB },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000121
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000122 { 0,
123 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000124 (texarray_func)glMultiTexCoord2svARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000125 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000126 (texarray_func)glMultiTexCoord2ivARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000127 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000128 (texarray_func)glMultiTexCoord2fvARB,
129 (texarray_func)glMultiTexCoord2dvARB },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000130
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000131 { 0,
132 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000133 (texarray_func)glMultiTexCoord3svARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000134 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000135 (texarray_func)glMultiTexCoord3ivARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000136 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000137 (texarray_func)glMultiTexCoord3fvARB,
138 (texarray_func)glMultiTexCoord3dvARB },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000139
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000140 { 0,
141 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000142 (texarray_func)glMultiTexCoord4svARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000143 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000144 (texarray_func)glMultiTexCoord4ivARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000145 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000146 (texarray_func)glMultiTexCoord4fvARB,
147 (texarray_func)glMultiTexCoord4dvARB }
Keith Whitwellcab974c2000-12-26 05:09:27 +0000148};
149
Karl Schultzb72902e2004-01-28 22:24:12 +0000150static void (GLAPIENTRY *indexfuncs[8])( const void * ) = {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000151 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000152 (array_func)glIndexubv,
153 (array_func)glIndexsv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000154 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000155 (array_func)glIndexiv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000156 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000157 (array_func)glIndexfv,
158 (array_func)glIndexdv
Keith Whitwellcab974c2000-12-26 05:09:27 +0000159};
160
161
Karl Schultzb72902e2004-01-28 22:24:12 +0000162static void (GLAPIENTRY *normalfuncs[8])( const void * ) = {
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000163 (array_func)glNormal3bv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000164 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000165 (array_func)glNormal3sv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000166 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000167 (array_func)glNormal3iv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000168 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000169 (array_func)glNormal3fv,
170 (array_func)glNormal3dv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000171};
172
Brian Paul03c0c2e2002-01-14 16:06:35 +0000173
174/* Wrapper functions in case glSecondaryColor*EXT doesn't exist */
175static void SecondaryColor3bvEXT(const GLbyte *c)
176{
177 _glapi_Dispatch->SecondaryColor3bvEXT(c);
178}
179
180static void SecondaryColor3ubvEXT(const GLubyte *c)
181{
182 _glapi_Dispatch->SecondaryColor3ubvEXT(c);
183}
184
185static void SecondaryColor3svEXT(const GLshort *c)
186{
187 _glapi_Dispatch->SecondaryColor3svEXT(c);
188}
189
190static void SecondaryColor3usvEXT(const GLushort *c)
191{
192 _glapi_Dispatch->SecondaryColor3usvEXT(c);
193}
194
195static void SecondaryColor3ivEXT(const GLint *c)
196{
197 _glapi_Dispatch->SecondaryColor3ivEXT(c);
198}
199
200static void SecondaryColor3uivEXT(const GLuint *c)
201{
202 _glapi_Dispatch->SecondaryColor3uivEXT(c);
203}
204
205static void SecondaryColor3fvEXT(const GLfloat *c)
206{
207 _glapi_Dispatch->SecondaryColor3fvEXT(c);
208}
209
210static void SecondaryColor3dvEXT(const GLdouble *c)
211{
212 _glapi_Dispatch->SecondaryColor3dvEXT(c);
213}
214
Karl Schultzb72902e2004-01-28 22:24:12 +0000215static void (GLAPIENTRY *secondarycolorfuncs[8])( const void * ) = {
Brian Paul03c0c2e2002-01-14 16:06:35 +0000216 (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 */
228static void FogCoordfvEXT(const GLfloat *f)
229{
230 _glapi_Dispatch->FogCoordfvEXT(f);
231}
232
233static void FogCoorddvEXT(const GLdouble *f)
234{
235 _glapi_Dispatch->FogCoorddvEXT(f);
236}
237
Karl Schultzb72902e2004-01-28 22:24:12 +0000238static void (GLAPIENTRY *fogcoordfuncs[8])( const void * ) = {
Brian Paul03c0c2e2002-01-14 16:06:35 +0000239 0,
240 0,
241 0,
242 0,
243 0,
244 0,
245 (array_func) FogCoordfvEXT,
246 (array_func) FogCoorddvEXT
247};
248
249
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000250
251GLboolean _ae_create_context( GLcontext *ctx )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000252{
Keith Whitwellae0eaf92003-11-24 15:23:18 +0000253 if (ctx->aelt_context)
254 return GL_TRUE;
255
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000256 ctx->aelt_context = MALLOC( sizeof(AEcontext) );
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000257 if (!ctx->aelt_context)
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000258 return GL_FALSE;
259
260 AE_CONTEXT(ctx)->NewState = ~0;
261 return GL_TRUE;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000262}
263
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000264
265void _ae_destroy_context( GLcontext *ctx )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000266{
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000267 if ( AE_CONTEXT( ctx ) ) {
268 FREE( ctx->aelt_context );
269 ctx->aelt_context = 0;
270 }
271}
272
273
274static void _ae_update_state( GLcontext *ctx )
275{
276 AEcontext *actx = AE_CONTEXT(ctx);
277 AEtexarray *ta = actx->texarrays;
278 AEarray *aa = actx->arrays;
Brian Pauldb07de02002-04-19 00:23:08 +0000279 GLuint i;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000280
Brian Paul92f97852003-05-01 22:44:02 +0000281 for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++)
Keith Whitwellcab974c2000-12-26 05:09:27 +0000282 if (ctx->Array.TexCoord[i].Enabled) {
283 ta->unit = i;
284 ta->array = &ctx->Array.TexCoord[i];
285 ta->func = multitexfuncs[ta->array->Size-1][TYPE_IDX(ta->array->Type)];
286 ta++;
287 }
288
289 ta->func = 0;
290
291 if (ctx->Array.Color.Enabled) {
292 aa->array = &ctx->Array.Color;
293 aa->func = colorfuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
294 aa++;
295 }
296
297 if (ctx->Array.Normal.Enabled) {
298 aa->array = &ctx->Array.Normal;
299 aa->func = normalfuncs[TYPE_IDX(aa->array->Type)];
300 aa++;
301 }
302
303 if (ctx->Array.Index.Enabled) {
304 aa->array = &ctx->Array.Index;
305 aa->func = indexfuncs[TYPE_IDX(aa->array->Type)];
306 aa++;
307 }
308
309 if (ctx->Array.EdgeFlag.Enabled) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000310 aa->array = &ctx->Array.EdgeFlag;
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000311 aa->func = (array_func)glEdgeFlagv;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000312 aa++;
313 }
314
315 if (ctx->Array.FogCoord.Enabled) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000316 aa->array = &ctx->Array.FogCoord;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000317 aa->func = fogcoordfuncs[TYPE_IDX(aa->array->Type)];
318 aa++;
319 }
320
321 if (ctx->Array.SecondaryColor.Enabled) {
322 aa->array = &ctx->Array.SecondaryColor;
323 aa->func = secondarycolorfuncs[TYPE_IDX(aa->array->Type)];
324 aa++;
325 }
326
327 /* Must be last
328 */
329 if (ctx->Array.Vertex.Enabled) {
330 aa->array = &ctx->Array.Vertex;
331 aa->func = vertexfuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
332 aa++;
333 }
334
335 aa->func = 0;
336 actx->NewState = 0;
337}
338
339
Karl Schultzd6745692003-12-04 20:23:44 +0000340void GLAPIENTRY _ae_loopback_array_elt( GLint elt )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000341{
342 GET_CURRENT_CONTEXT(ctx);
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000343 AEcontext *actx = AE_CONTEXT(ctx);
344 AEtexarray *ta;
345 AEarray *aa;
346
347 if (actx->NewState)
348 _ae_update_state( ctx );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000349
350 for (ta = actx->texarrays ; ta->func ; ta++) {
Brian Paul57d882b2003-09-17 16:06:49 +0000351 GLubyte *src = ta->array->BufferObj->Data
352 + (GLuint) ta->array->Ptr
353 + elt * ta->array->StrideB;
354 ta->func( ta->unit + GL_TEXTURE0_ARB, src);
Keith Whitwellcab974c2000-12-26 05:09:27 +0000355 }
356
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000357 /* Must be last
358 */
Keith Whitwellcab974c2000-12-26 05:09:27 +0000359 for (aa = actx->arrays ; aa->func ; aa++) {
Brian Paul57d882b2003-09-17 16:06:49 +0000360 GLubyte *src = aa->array->BufferObj->Data
361 + (GLuint) aa->array->Ptr
362 + elt * aa->array->StrideB;
363 aa->func( src );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000364 }
365}
366
367
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000368
369void _ae_invalidate_state( GLcontext *ctx, GLuint new_state )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000370{
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000371 AE_CONTEXT(ctx)->NewState |= new_state;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000372}