blob: edfa8e53cf482a0fab942d4fb07cc00fd943d1cf [file] [log] [blame]
Ian Romanick9ac51f52003-06-05 00:50:18 +00001
Gareth Hughes22144ab2001-03-12 00:48:37 +00002/*
3 * Mesa 3-D graphics library
Brian Paul610d5992003-01-14 04:55:45 +00004 * Version: 5.1
Gareth Hughes22144ab2001-03-12 00:48:37 +00005 *
Brian Paul92f97852003-05-01 22:44:02 +00006 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
Gareth Hughes22144ab2001-03-12 00:48:37 +00007 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
Keith Whitwellfc00cbe2001-12-20 15:30:45 +000026/* Author:
Brian Paul05a4b372002-10-29 20:28:36 +000027 * Keith Whitwell <keith@tungstengraphics.com>
Keith Whitwellfc00cbe2001-12-20 15:30:45 +000028 */
29
Keith Whitwellcab974c2000-12-26 05:09:27 +000030#include "glheader.h"
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000031#include "api_arrayelt.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000032#include "context.h"
Keith Whitwellfc00cbe2001-12-20 15:30:45 +000033#include "glapi.h"
Brian Paul3c634522002-10-24 23:57:19 +000034#include "imports.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000035#include "macros.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000036#include "mtypes.h"
37
38
Gareth Hughes1fb0a432001-12-28 06:28:10 +000039typedef void (*texarray_func)( GLenum, const void * );
40
Keith Whitwellcab974c2000-12-26 05:09:27 +000041typedef struct {
42 GLint unit;
43 struct gl_client_array *array;
Gareth Hughes1fb0a432001-12-28 06:28:10 +000044 texarray_func func;
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000045} AEtexarray;
Gareth Hughes22144ab2001-03-12 00:48:37 +000046
Gareth Hughes1fb0a432001-12-28 06:28:10 +000047typedef void (*array_func)( const void * );
Keith Whitwellcab974c2000-12-26 05:09:27 +000048
49typedef struct {
50 struct gl_client_array *array;
Gareth Hughes1fb0a432001-12-28 06:28:10 +000051 array_func func;
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000052} AEarray;
Keith Whitwellcab974c2000-12-26 05:09:27 +000053
54typedef struct {
Brian Paul610d5992003-01-14 04:55:45 +000055 AEtexarray texarrays[MAX_TEXTURE_COORD_UNITS + 1];
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000056 AEarray arrays[32];
Keith Whitwellcab974c2000-12-26 05:09:27 +000057 GLuint NewState;
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000058} AEcontext;
Keith Whitwellcab974c2000-12-26 05:09:27 +000059
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000060#define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context)
61#define TYPE_IDX(t) ((t) & 0xf)
Keith Whitwellcab974c2000-12-26 05:09:27 +000062
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000063static void (*colorfuncs[2][8])( const void * ) = {
Gareth Hughes1fb0a432001-12-28 06:28:10 +000064 { (array_func)glColor3bv,
Keith Whitwell306d3fc2002-04-09 16:56:50 +000065 (array_func)glColor3ubv,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000066 (array_func)glColor3sv,
67 (array_func)glColor3usv,
68 (array_func)glColor3iv,
69 (array_func)glColor3uiv,
70 (array_func)glColor3fv,
71 (array_func)glColor3dv },
Keith Whitwellcab974c2000-12-26 05:09:27 +000072
Gareth Hughes1fb0a432001-12-28 06:28:10 +000073 { (array_func)glColor4bv,
Keith Whitwell306d3fc2002-04-09 16:56:50 +000074 (array_func)glColor4ubv,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000075 (array_func)glColor4sv,
76 (array_func)glColor4usv,
77 (array_func)glColor4iv,
78 (array_func)glColor4uiv,
79 (array_func)glColor4fv,
80 (array_func)glColor4dv }
Keith Whitwellcab974c2000-12-26 05:09:27 +000081};
82
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000083static void (*vertexfuncs[3][8])( const void * ) = {
84 { 0,
85 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000086 (array_func)glVertex2sv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000087 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000088 (array_func)glVertex2iv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000089 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000090 (array_func)glVertex2fv,
91 (array_func)glVertex2dv },
Keith Whitwellcab974c2000-12-26 05:09:27 +000092
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000093 { 0,
94 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000095 (array_func)glVertex3sv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000096 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000097 (array_func)glVertex3iv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000098 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000099 (array_func)glVertex3fv,
100 (array_func)glVertex3dv },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000101
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000102 { 0,
103 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000104 (array_func)glVertex4sv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000105 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000106 (array_func)glVertex4iv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000107 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000108 (array_func)glVertex4fv,
109 (array_func)glVertex4dv }
Keith Whitwellcab974c2000-12-26 05:09:27 +0000110};
111
112
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000113static void (*multitexfuncs[4][8])( GLenum, const void * ) = {
114 { 0,
115 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000116 (texarray_func)glMultiTexCoord1svARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000117 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000118 (texarray_func)glMultiTexCoord1ivARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000119 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000120 (texarray_func)glMultiTexCoord1fvARB,
121 (texarray_func)glMultiTexCoord1dvARB },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000122
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000123 { 0,
124 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000125 (texarray_func)glMultiTexCoord2svARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000126 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000127 (texarray_func)glMultiTexCoord2ivARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000128 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000129 (texarray_func)glMultiTexCoord2fvARB,
130 (texarray_func)glMultiTexCoord2dvARB },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000131
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000132 { 0,
133 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000134 (texarray_func)glMultiTexCoord3svARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000135 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000136 (texarray_func)glMultiTexCoord3ivARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000137 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000138 (texarray_func)glMultiTexCoord3fvARB,
139 (texarray_func)glMultiTexCoord3dvARB },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000140
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000141 { 0,
142 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000143 (texarray_func)glMultiTexCoord4svARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000144 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000145 (texarray_func)glMultiTexCoord4ivARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000146 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000147 (texarray_func)glMultiTexCoord4fvARB,
148 (texarray_func)glMultiTexCoord4dvARB }
Keith Whitwellcab974c2000-12-26 05:09:27 +0000149};
150
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000151static void (*indexfuncs[8])( const void * ) = {
152 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000153 (array_func)glIndexubv,
154 (array_func)glIndexsv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000155 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000156 (array_func)glIndexiv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000157 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000158 (array_func)glIndexfv,
159 (array_func)glIndexdv
Keith Whitwellcab974c2000-12-26 05:09:27 +0000160};
161
162
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000163static void (*normalfuncs[8])( const void * ) = {
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000164 (array_func)glNormal3bv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000165 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000166 (array_func)glNormal3sv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000167 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000168 (array_func)glNormal3iv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000169 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000170 (array_func)glNormal3fv,
171 (array_func)glNormal3dv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000172};
173
Brian Paul03c0c2e2002-01-14 16:06:35 +0000174
175/* Wrapper functions in case glSecondaryColor*EXT doesn't exist */
176static void SecondaryColor3bvEXT(const GLbyte *c)
177{
178 _glapi_Dispatch->SecondaryColor3bvEXT(c);
179}
180
181static void SecondaryColor3ubvEXT(const GLubyte *c)
182{
183 _glapi_Dispatch->SecondaryColor3ubvEXT(c);
184}
185
186static void SecondaryColor3svEXT(const GLshort *c)
187{
188 _glapi_Dispatch->SecondaryColor3svEXT(c);
189}
190
191static void SecondaryColor3usvEXT(const GLushort *c)
192{
193 _glapi_Dispatch->SecondaryColor3usvEXT(c);
194}
195
196static void SecondaryColor3ivEXT(const GLint *c)
197{
198 _glapi_Dispatch->SecondaryColor3ivEXT(c);
199}
200
201static void SecondaryColor3uivEXT(const GLuint *c)
202{
203 _glapi_Dispatch->SecondaryColor3uivEXT(c);
204}
205
206static void SecondaryColor3fvEXT(const GLfloat *c)
207{
208 _glapi_Dispatch->SecondaryColor3fvEXT(c);
209}
210
211static void SecondaryColor3dvEXT(const GLdouble *c)
212{
213 _glapi_Dispatch->SecondaryColor3dvEXT(c);
214}
215
216static void (*secondarycolorfuncs[8])( const void * ) = {
217 (array_func) SecondaryColor3bvEXT,
218 (array_func) SecondaryColor3ubvEXT,
219 (array_func) SecondaryColor3svEXT,
220 (array_func) SecondaryColor3usvEXT,
221 (array_func) SecondaryColor3ivEXT,
222 (array_func) SecondaryColor3uivEXT,
223 (array_func) SecondaryColor3fvEXT,
224 (array_func) SecondaryColor3dvEXT,
225};
226
227
228/* Again, wrapper functions in case glSecondaryColor*EXT doesn't exist */
229static void FogCoordfvEXT(const GLfloat *f)
230{
231 _glapi_Dispatch->FogCoordfvEXT(f);
232}
233
234static void FogCoorddvEXT(const GLdouble *f)
235{
236 _glapi_Dispatch->FogCoorddvEXT(f);
237}
238
239static void (*fogcoordfuncs[8])( const void * ) = {
240 0,
241 0,
242 0,
243 0,
244 0,
245 0,
246 (array_func) FogCoordfvEXT,
247 (array_func) FogCoorddvEXT
248};
249
250
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000251
252GLboolean _ae_create_context( GLcontext *ctx )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000253{
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000254 ctx->aelt_context = MALLOC( sizeof(AEcontext) );
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000255 if (!ctx->aelt_context)
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000256 return GL_FALSE;
257
258 AE_CONTEXT(ctx)->NewState = ~0;
259 return GL_TRUE;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000260}
261
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000262
263void _ae_destroy_context( GLcontext *ctx )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000264{
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000265 if ( AE_CONTEXT( ctx ) ) {
266 FREE( ctx->aelt_context );
267 ctx->aelt_context = 0;
268 }
269}
270
271
272static void _ae_update_state( GLcontext *ctx )
273{
274 AEcontext *actx = AE_CONTEXT(ctx);
275 AEtexarray *ta = actx->texarrays;
276 AEarray *aa = actx->arrays;
Brian Pauldb07de02002-04-19 00:23:08 +0000277 GLuint i;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000278
Brian Paul92f97852003-05-01 22:44:02 +0000279 for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++)
Keith Whitwellcab974c2000-12-26 05:09:27 +0000280 if (ctx->Array.TexCoord[i].Enabled) {
281 ta->unit = i;
282 ta->array = &ctx->Array.TexCoord[i];
283 ta->func = multitexfuncs[ta->array->Size-1][TYPE_IDX(ta->array->Type)];
284 ta++;
285 }
286
287 ta->func = 0;
288
289 if (ctx->Array.Color.Enabled) {
290 aa->array = &ctx->Array.Color;
291 aa->func = colorfuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
292 aa++;
293 }
294
295 if (ctx->Array.Normal.Enabled) {
296 aa->array = &ctx->Array.Normal;
297 aa->func = normalfuncs[TYPE_IDX(aa->array->Type)];
298 aa++;
299 }
300
301 if (ctx->Array.Index.Enabled) {
302 aa->array = &ctx->Array.Index;
303 aa->func = indexfuncs[TYPE_IDX(aa->array->Type)];
304 aa++;
305 }
306
307 if (ctx->Array.EdgeFlag.Enabled) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000308 aa->array = &ctx->Array.EdgeFlag;
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000309 aa->func = (array_func)glEdgeFlagv;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000310 aa++;
311 }
312
313 if (ctx->Array.FogCoord.Enabled) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000314 aa->array = &ctx->Array.FogCoord;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000315 aa->func = fogcoordfuncs[TYPE_IDX(aa->array->Type)];
316 aa++;
317 }
318
319 if (ctx->Array.SecondaryColor.Enabled) {
320 aa->array = &ctx->Array.SecondaryColor;
321 aa->func = secondarycolorfuncs[TYPE_IDX(aa->array->Type)];
322 aa++;
323 }
324
325 /* Must be last
326 */
327 if (ctx->Array.Vertex.Enabled) {
328 aa->array = &ctx->Array.Vertex;
329 aa->func = vertexfuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
330 aa++;
331 }
332
333 aa->func = 0;
334 actx->NewState = 0;
335}
336
337
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000338void _ae_loopback_array_elt( GLint elt )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000339{
340 GET_CURRENT_CONTEXT(ctx);
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000341 AEcontext *actx = AE_CONTEXT(ctx);
342 AEtexarray *ta;
343 AEarray *aa;
344
345 if (actx->NewState)
346 _ae_update_state( ctx );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000347
348 for (ta = actx->texarrays ; ta->func ; ta++) {
Brian Paul4753d602002-06-15 02:38:15 +0000349 ta->func( ta->unit + GL_TEXTURE0_ARB, (char *)ta->array->Ptr + elt * ta->array->StrideB );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000350 }
351
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000352 /* Must be last
353 */
Keith Whitwellcab974c2000-12-26 05:09:27 +0000354 for (aa = actx->arrays ; aa->func ; aa++) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000355 aa->func( (char *)aa->array->Ptr + elt * aa->array->StrideB );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000356 }
357}
358
359
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000360
361void _ae_invalidate_state( GLcontext *ctx, GLuint new_state )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000362{
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000363 AE_CONTEXT(ctx)->NewState |= new_state;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000364}