blob: 288735d3b0ecb9be1ca6959e2b3ba51fb38d0bb1 [file] [log] [blame]
Keith Whitwell4b7d6f22001-06-01 22:22:10 +00001/* $Id: api_arrayelt.c,v 1.3 2001/06/01 22:22:10 keithw 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 Whitwellcab974c2000-12-26 05:09:27 +000027#include "glheader.h"
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000028#include "api_arrayelt.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000029#include "context.h"
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000030#include "mem.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000031#include "macros.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000032#include "mtypes.h"
33
34
35typedef struct {
36 GLint unit;
37 struct gl_client_array *array;
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000038 void (*func)( GLenum, const void * );
39} AEtexarray;
Gareth Hughes22144ab2001-03-12 00:48:37 +000040
Keith Whitwellcab974c2000-12-26 05:09:27 +000041
42typedef struct {
43 struct gl_client_array *array;
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000044 void (*func)( const void * );
45} AEarray;
Keith Whitwellcab974c2000-12-26 05:09:27 +000046
47typedef struct {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000048 AEtexarray texarrays[MAX_TEXTURE_UNITS+1];
49 AEarray arrays[32];
Keith Whitwellcab974c2000-12-26 05:09:27 +000050 GLuint NewState;
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000051} AEcontext;
Keith Whitwellcab974c2000-12-26 05:09:27 +000052
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000053#define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context)
54#define TYPE_IDX(t) ((t) & 0xf)
Keith Whitwellcab974c2000-12-26 05:09:27 +000055
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000056static void (*colorfuncs[2][8])( const void * ) = {
57 { (void (*)( const void * ))glColor3bv,
58 (void (*)( const void * ))glColor3ub,
59 (void (*)( const void * ))glColor3sv,
60 (void (*)( const void * ))glColor3usv,
61 (void (*)( const void * ))glColor3iv,
62 (void (*)( const void * ))glColor3uiv,
63 (void (*)( const void * ))glColor3fv,
64 (void (*)( const void * ))glColor3dv },
Keith Whitwellcab974c2000-12-26 05:09:27 +000065
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000066 { (void (*)( const void * ))glColor4bv,
67 (void (*)( const void * ))glColor4ub,
68 (void (*)( const void * ))glColor4sv,
69 (void (*)( const void * ))glColor4usv,
70 (void (*)( const void * ))glColor4iv,
71 (void (*)( const void * ))glColor4uiv,
72 (void (*)( const void * ))glColor4fv,
73 (void (*)( const void * ))glColor4dv }
Keith Whitwellcab974c2000-12-26 05:09:27 +000074};
75
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000076static void (*vertexfuncs[3][8])( const void * ) = {
77 { 0,
78 0,
79 (void (*)( const void * ))glVertex2sv,
80 0,
81 (void (*)( const void * ))glVertex2iv,
82 0,
83 (void (*)( const void * ))glVertex2fv,
84 (void (*)( const void * ))glVertex2dv },
Keith Whitwellcab974c2000-12-26 05:09:27 +000085
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000086 { 0,
87 0,
88 (void (*)( const void * ))glVertex3sv,
89 0,
90 (void (*)( const void * ))glVertex3iv,
91 0,
92 (void (*)( const void * ))glVertex3fv,
93 (void (*)( const void * ))glVertex3dv },
Keith Whitwellcab974c2000-12-26 05:09:27 +000094
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000095 { 0,
96 0,
97 (void (*)( const void * ))glVertex4sv,
98 0,
99 (void (*)( const void * ))glVertex4iv,
100 0,
101 (void (*)( const void * ))glVertex4fv,
102 (void (*)( const void * ))glVertex4dv }
Keith Whitwellcab974c2000-12-26 05:09:27 +0000103};
104
105
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000106static void (*multitexfuncs[4][8])( GLenum, const void * ) = {
107 { 0,
108 0,
109 (void (*)( GLenum, const void * ))glMultiTexCoord1svARB,
110 0,
111 (void (*)( GLenum, const void * ))glMultiTexCoord1ivARB,
112 0,
113 (void (*)( GLenum, const void * ))glMultiTexCoord1fvARB,
114 (void (*)( GLenum, const void * ))glMultiTexCoord1dvARB },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000115
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000116 { 0,
117 0,
118 (void (*)( GLenum, const void * ))glMultiTexCoord2svARB,
119 0,
120 (void (*)( GLenum, const void * ))glMultiTexCoord2ivARB,
121 0,
122 (void (*)( GLenum, const void * ))glMultiTexCoord2fvARB,
123 (void (*)( GLenum, const void * ))glMultiTexCoord2dvARB },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000124
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000125 { 0,
126 0,
127 (void (*)( GLenum, const void * ))glMultiTexCoord3svARB,
128 0,
129 (void (*)( GLenum, const void * ))glMultiTexCoord3ivARB,
130 0,
131 (void (*)( GLenum, const void * ))glMultiTexCoord3fvARB,
132 (void (*)( GLenum, const void * ))glMultiTexCoord3dvARB },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000133
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000134 { 0,
135 0,
136 (void (*)( GLenum, const void * ))glMultiTexCoord4svARB,
137 0,
138 (void (*)( GLenum, const void * ))glMultiTexCoord4ivARB,
139 0,
140 (void (*)( GLenum, const void * ))glMultiTexCoord4fvARB,
141 (void (*)( GLenum, const void * ))glMultiTexCoord4dvARB }
Keith Whitwellcab974c2000-12-26 05:09:27 +0000142};
143
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000144static void (*indexfuncs[8])( const void * ) = {
145 0,
146 (void (*)( const void * ))glIndexubv,
147 (void (*)( const void * ))glIndexsv,
148 0,
149 (void (*)( const void * ))glIndexiv,
150 0,
151 (void (*)( const void * ))glIndexfv,
152 (void (*)( const void * ))glIndexdv
Keith Whitwellcab974c2000-12-26 05:09:27 +0000153};
154
155
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000156static void (*normalfuncs[8])( const void * ) = {
157 (void (*)( const void * ))glNormal3bv,
158 0,
159 (void (*)( const void * ))glNormal3sv,
160 0,
161 (void (*)( const void * ))glNormal3iv,
162 0,
163 (void (*)( const void * ))glNormal3fv,
164 (void (*)( const void * ))glNormal3dv,
165};
166
167static void (*fogcoordfuncs[8])( const void * ) = {
168 0,
169 0,
170 0,
171 0,
172 0,
173 0,
174 (void (*)( const void * ))glFogCoordfvEXT,
175 (void (*)( const void * ))glFogCoorddvEXT,
176};
177
178static void (*secondarycolorfuncs[8])( const void * ) = {
179 (void (*)( const void * ))glSecondaryColor3bvEXT,
180 (void (*)( const void * ))glSecondaryColor3ubvEXT,
181 (void (*)( const void * ))glSecondaryColor3svEXT,
182 (void (*)( const void * ))glSecondaryColor3usvEXT,
183 (void (*)( const void * ))glSecondaryColor3ivEXT,
184 (void (*)( const void * ))glSecondaryColor3uivEXT,
185 (void (*)( const void * ))glSecondaryColor3fvEXT,
186 (void (*)( const void * ))glSecondaryColor3dvEXT,
187};
188
189
190GLboolean _ae_create_context( GLcontext *ctx )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000191{
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000192 ctx->aelt_context = MALLOC( sizeof(AEcontext) );
193 if (!ctx->aelt_context)
194 return GL_FALSE;
195
196 AE_CONTEXT(ctx)->NewState = ~0;
197 return GL_TRUE;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000198}
199
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000200
201void _ae_destroy_context( GLcontext *ctx )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000202{
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000203 if ( AE_CONTEXT( ctx ) ) {
204 FREE( ctx->aelt_context );
205 ctx->aelt_context = 0;
206 }
207}
208
209
210static void _ae_update_state( GLcontext *ctx )
211{
212 AEcontext *actx = AE_CONTEXT(ctx);
213 AEtexarray *ta = actx->texarrays;
214 AEarray *aa = actx->arrays;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000215 int i;
216
Gareth Hughes22144ab2001-03-12 00:48:37 +0000217 for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
Keith Whitwellcab974c2000-12-26 05:09:27 +0000218 if (ctx->Array.TexCoord[i].Enabled) {
219 ta->unit = i;
220 ta->array = &ctx->Array.TexCoord[i];
221 ta->func = multitexfuncs[ta->array->Size-1][TYPE_IDX(ta->array->Type)];
222 ta++;
223 }
224
225 ta->func = 0;
226
227 if (ctx->Array.Color.Enabled) {
228 aa->array = &ctx->Array.Color;
229 aa->func = colorfuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
230 aa++;
231 }
232
233 if (ctx->Array.Normal.Enabled) {
234 aa->array = &ctx->Array.Normal;
235 aa->func = normalfuncs[TYPE_IDX(aa->array->Type)];
236 aa++;
237 }
238
239 if (ctx->Array.Index.Enabled) {
240 aa->array = &ctx->Array.Index;
241 aa->func = indexfuncs[TYPE_IDX(aa->array->Type)];
242 aa++;
243 }
244
245 if (ctx->Array.EdgeFlag.Enabled) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000246 aa->array = &ctx->Array.EdgeFlag;
247 aa->func = (void (*)( const void * ))glEdgeFlagv;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000248 aa++;
249 }
250
251 if (ctx->Array.FogCoord.Enabled) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000252 aa->array = &ctx->Array.FogCoord;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000253 aa->func = fogcoordfuncs[TYPE_IDX(aa->array->Type)];
254 aa++;
255 }
256
257 if (ctx->Array.SecondaryColor.Enabled) {
258 aa->array = &ctx->Array.SecondaryColor;
259 aa->func = secondarycolorfuncs[TYPE_IDX(aa->array->Type)];
260 aa++;
261 }
262
263 /* Must be last
264 */
265 if (ctx->Array.Vertex.Enabled) {
266 aa->array = &ctx->Array.Vertex;
267 aa->func = vertexfuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
268 aa++;
269 }
270
271 aa->func = 0;
272 actx->NewState = 0;
273}
274
275
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000276void _ae_loopback_array_elt( GLint elt )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000277{
278 GET_CURRENT_CONTEXT(ctx);
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000279 AEcontext *actx = AE_CONTEXT(ctx);
280 AEtexarray *ta;
281 AEarray *aa;
282
283 if (actx->NewState)
284 _ae_update_state( ctx );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000285
286 for (ta = actx->texarrays ; ta->func ; ta++) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000287 ta->func( ta->unit, (char *)ta->array->Ptr + elt * ta->array->StrideB );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000288 }
289
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000290 /* Must be last
291 */
Keith Whitwellcab974c2000-12-26 05:09:27 +0000292 for (aa = actx->arrays ; aa->func ; aa++) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000293 aa->func( (char *)aa->array->Ptr + elt * aa->array->StrideB );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000294 }
295}
296
297
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000298
299void _ae_invalidate_state( GLcontext *ctx, GLuint new_state )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000300{
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000301 AE_CONTEXT(ctx)->NewState |= new_state;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000302}