blob: f5b3695bfd9b2d61389106aa23621bd4362df472 [file] [log] [blame]
Gareth Hughes1fb0a432001-12-28 06:28:10 +00001/* $Id: api_arrayelt.c,v 1.5 2001/12/28 06:28:10 gareth Exp $ */
Gareth Hughes22144ab2001-03-12 00:48:37 +00002
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 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
Keith Whitwellfc00cbe2001-12-20 15:30:45 +000027/* Author:
28 * Keith Whitwell <keith_whitwell@yahoo.com>
29 */
30
Keith Whitwellcab974c2000-12-26 05:09:27 +000031#include "glheader.h"
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000032#include "api_arrayelt.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000033#include "context.h"
Keith Whitwellfc00cbe2001-12-20 15:30:45 +000034#include "glapi.h"
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000035#include "mem.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000036#include "macros.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000037#include "mtypes.h"
38
39
Gareth Hughes1fb0a432001-12-28 06:28:10 +000040typedef void (*texarray_func)( GLenum, const void * );
41
Keith Whitwellcab974c2000-12-26 05:09:27 +000042typedef struct {
43 GLint unit;
44 struct gl_client_array *array;
Gareth Hughes1fb0a432001-12-28 06:28:10 +000045 texarray_func func;
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000046} AEtexarray;
Gareth Hughes22144ab2001-03-12 00:48:37 +000047
Gareth Hughes1fb0a432001-12-28 06:28:10 +000048typedef void (*array_func)( const void * );
Keith Whitwellcab974c2000-12-26 05:09:27 +000049
50typedef struct {
51 struct gl_client_array *array;
Gareth Hughes1fb0a432001-12-28 06:28:10 +000052 array_func func;
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000053} AEarray;
Keith Whitwellcab974c2000-12-26 05:09:27 +000054
55typedef struct {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000056 AEtexarray texarrays[MAX_TEXTURE_UNITS+1];
57 AEarray arrays[32];
Keith Whitwellcab974c2000-12-26 05:09:27 +000058 GLuint NewState;
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000059} AEcontext;
Keith Whitwellcab974c2000-12-26 05:09:27 +000060
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000061#define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context)
62#define TYPE_IDX(t) ((t) & 0xf)
Keith Whitwellcab974c2000-12-26 05:09:27 +000063
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000064static void (*colorfuncs[2][8])( const void * ) = {
Gareth Hughes1fb0a432001-12-28 06:28:10 +000065 { (array_func)glColor3bv,
66 (array_func)glColor3ub,
67 (array_func)glColor3sv,
68 (array_func)glColor3usv,
69 (array_func)glColor3iv,
70 (array_func)glColor3uiv,
71 (array_func)glColor3fv,
72 (array_func)glColor3dv },
Keith Whitwellcab974c2000-12-26 05:09:27 +000073
Gareth Hughes1fb0a432001-12-28 06:28:10 +000074 { (array_func)glColor4bv,
75 (array_func)glColor4ub,
76 (array_func)glColor4sv,
77 (array_func)glColor4usv,
78 (array_func)glColor4iv,
79 (array_func)glColor4uiv,
80 (array_func)glColor4fv,
81 (array_func)glColor4dv }
Keith Whitwellcab974c2000-12-26 05:09:27 +000082};
83
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000084static void (*vertexfuncs[3][8])( const void * ) = {
85 { 0,
86 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000087 (array_func)glVertex2sv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000088 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000089 (array_func)glVertex2iv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000090 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000091 (array_func)glVertex2fv,
92 (array_func)glVertex2dv },
Keith Whitwellcab974c2000-12-26 05:09:27 +000093
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000094 { 0,
95 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000096 (array_func)glVertex3sv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000097 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +000098 (array_func)glVertex3iv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000099 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000100 (array_func)glVertex3fv,
101 (array_func)glVertex3dv },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000102
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000103 { 0,
104 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000105 (array_func)glVertex4sv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000106 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000107 (array_func)glVertex4iv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000108 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000109 (array_func)glVertex4fv,
110 (array_func)glVertex4dv }
Keith Whitwellcab974c2000-12-26 05:09:27 +0000111};
112
113
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000114static void (*multitexfuncs[4][8])( GLenum, const void * ) = {
115 { 0,
116 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000117 (texarray_func)glMultiTexCoord1svARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000118 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000119 (texarray_func)glMultiTexCoord1ivARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000120 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000121 (texarray_func)glMultiTexCoord1fvARB,
122 (texarray_func)glMultiTexCoord1dvARB },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000123
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000124 { 0,
125 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000126 (texarray_func)glMultiTexCoord2svARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000127 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000128 (texarray_func)glMultiTexCoord2ivARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000129 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000130 (texarray_func)glMultiTexCoord2fvARB,
131 (texarray_func)glMultiTexCoord2dvARB },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000132
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000133 { 0,
134 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000135 (texarray_func)glMultiTexCoord3svARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000136 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000137 (texarray_func)glMultiTexCoord3ivARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000138 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000139 (texarray_func)glMultiTexCoord3fvARB,
140 (texarray_func)glMultiTexCoord3dvARB },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000141
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000142 { 0,
143 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000144 (texarray_func)glMultiTexCoord4svARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000145 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000146 (texarray_func)glMultiTexCoord4ivARB,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000147 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000148 (texarray_func)glMultiTexCoord4fvARB,
149 (texarray_func)glMultiTexCoord4dvARB }
Keith Whitwellcab974c2000-12-26 05:09:27 +0000150};
151
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000152static void (*indexfuncs[8])( const void * ) = {
153 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000154 (array_func)glIndexubv,
155 (array_func)glIndexsv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000156 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000157 (array_func)glIndexiv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000158 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000159 (array_func)glIndexfv,
160 (array_func)glIndexdv
Keith Whitwellcab974c2000-12-26 05:09:27 +0000161};
162
163
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000164static void (*normalfuncs[8])( const void * ) = {
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000165 (array_func)glNormal3bv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000166 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000167 (array_func)glNormal3sv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000168 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000169 (array_func)glNormal3iv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000170 0,
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000171 (array_func)glNormal3fv,
172 (array_func)glNormal3dv,
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000173};
174
Keith Whitwellfc00cbe2001-12-20 15:30:45 +0000175static void (*fogcoordfuncs[8])( const void * );
176static void (*secondarycolorfuncs[8])( const void * );
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000177
178GLboolean _ae_create_context( GLcontext *ctx )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000179{
Keith Whitwellfc00cbe2001-12-20 15:30:45 +0000180 static int firsttime = 1;
181
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000182 ctx->aelt_context = MALLOC( sizeof(AEcontext) );
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000183 if (!ctx->aelt_context)
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000184 return GL_FALSE;
185
Keith Whitwellfc00cbe2001-12-20 15:30:45 +0000186
187 if (firsttime)
188 {
189 firsttime = 0;
190
191 /* Don't really want to use api_compat.h for this, but the
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000192 * rational for using _glapi_get_proc_address is the same.
Keith Whitwellfc00cbe2001-12-20 15:30:45 +0000193 */
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000194 fogcoordfuncs[0] = (array_func) _glapi_get_proc_address("glSecondaryColor3bvEXT");
195 fogcoordfuncs[1] = (array_func) _glapi_get_proc_address("glSecondaryColor3ubvEXT");
196 fogcoordfuncs[2] = (array_func) _glapi_get_proc_address("glSecondaryColor3svEXT");
197 fogcoordfuncs[3] = (array_func) _glapi_get_proc_address("glSecondaryColor3usvEXT");
198 fogcoordfuncs[4] = (array_func) _glapi_get_proc_address("glSecondaryColor3ivEXT");
199 fogcoordfuncs[5] = (array_func) _glapi_get_proc_address("glSecondaryColor3uivEXT");
200 fogcoordfuncs[6] = (array_func) _glapi_get_proc_address("glSecondaryColor3fvEXT");
201 fogcoordfuncs[7] = (array_func) _glapi_get_proc_address("glSecondaryColor3dvEXT");
Keith Whitwellfc00cbe2001-12-20 15:30:45 +0000202
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000203 secondarycolorfuncs[6] = (array_func) _glapi_get_proc_address("glFogCoordfvEXT");
204 secondarycolorfuncs[7] = (array_func) _glapi_get_proc_address("glFogCoorddvEXT");
Keith Whitwellfc00cbe2001-12-20 15:30:45 +0000205 }
206
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000207 AE_CONTEXT(ctx)->NewState = ~0;
208 return GL_TRUE;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000209}
210
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000211
212void _ae_destroy_context( GLcontext *ctx )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000213{
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000214 if ( AE_CONTEXT( ctx ) ) {
215 FREE( ctx->aelt_context );
216 ctx->aelt_context = 0;
217 }
218}
219
220
221static void _ae_update_state( GLcontext *ctx )
222{
223 AEcontext *actx = AE_CONTEXT(ctx);
224 AEtexarray *ta = actx->texarrays;
225 AEarray *aa = actx->arrays;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000226 int i;
227
Gareth Hughes22144ab2001-03-12 00:48:37 +0000228 for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
Keith Whitwellcab974c2000-12-26 05:09:27 +0000229 if (ctx->Array.TexCoord[i].Enabled) {
230 ta->unit = i;
231 ta->array = &ctx->Array.TexCoord[i];
232 ta->func = multitexfuncs[ta->array->Size-1][TYPE_IDX(ta->array->Type)];
233 ta++;
234 }
235
236 ta->func = 0;
237
238 if (ctx->Array.Color.Enabled) {
239 aa->array = &ctx->Array.Color;
240 aa->func = colorfuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
241 aa++;
242 }
243
244 if (ctx->Array.Normal.Enabled) {
245 aa->array = &ctx->Array.Normal;
246 aa->func = normalfuncs[TYPE_IDX(aa->array->Type)];
247 aa++;
248 }
249
250 if (ctx->Array.Index.Enabled) {
251 aa->array = &ctx->Array.Index;
252 aa->func = indexfuncs[TYPE_IDX(aa->array->Type)];
253 aa++;
254 }
255
256 if (ctx->Array.EdgeFlag.Enabled) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000257 aa->array = &ctx->Array.EdgeFlag;
Gareth Hughes1fb0a432001-12-28 06:28:10 +0000258 aa->func = (array_func)glEdgeFlagv;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000259 aa++;
260 }
261
262 if (ctx->Array.FogCoord.Enabled) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000263 aa->array = &ctx->Array.FogCoord;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000264 aa->func = fogcoordfuncs[TYPE_IDX(aa->array->Type)];
265 aa++;
266 }
267
268 if (ctx->Array.SecondaryColor.Enabled) {
269 aa->array = &ctx->Array.SecondaryColor;
270 aa->func = secondarycolorfuncs[TYPE_IDX(aa->array->Type)];
271 aa++;
272 }
273
274 /* Must be last
275 */
276 if (ctx->Array.Vertex.Enabled) {
277 aa->array = &ctx->Array.Vertex;
278 aa->func = vertexfuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
279 aa++;
280 }
281
282 aa->func = 0;
283 actx->NewState = 0;
284}
285
286
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000287void _ae_loopback_array_elt( GLint elt )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000288{
289 GET_CURRENT_CONTEXT(ctx);
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000290 AEcontext *actx = AE_CONTEXT(ctx);
291 AEtexarray *ta;
292 AEarray *aa;
293
294 if (actx->NewState)
295 _ae_update_state( ctx );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000296
297 for (ta = actx->texarrays ; ta->func ; ta++) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000298 ta->func( ta->unit, (char *)ta->array->Ptr + elt * ta->array->StrideB );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000299 }
300
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000301 /* Must be last
302 */
Keith Whitwellcab974c2000-12-26 05:09:27 +0000303 for (aa = actx->arrays ; aa->func ; aa++) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000304 aa->func( (char *)aa->array->Ptr + elt * aa->array->StrideB );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000305 }
306}
307
308
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000309
310void _ae_invalidate_state( GLcontext *ctx, GLuint new_state )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000311{
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000312 AE_CONTEXT(ctx)->NewState |= new_state;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000313}