blob: fc2f714bd654fe64bb4cb5d8b8d78a8ef1d33bb5 [file] [log] [blame]
Keith Whitwellfc00cbe2001-12-20 15:30:45 +00001/* $Id: api_arrayelt.c,v 1.4 2001/12/20 15:30:45 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 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
40typedef struct {
41 GLint unit;
42 struct gl_client_array *array;
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000043 void (*func)( GLenum, const void * );
44} AEtexarray;
Gareth Hughes22144ab2001-03-12 00:48:37 +000045
Keith Whitwellcab974c2000-12-26 05:09:27 +000046
47typedef struct {
48 struct gl_client_array *array;
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000049 void (*func)( const void * );
50} AEarray;
Keith Whitwellcab974c2000-12-26 05:09:27 +000051
52typedef struct {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000053 AEtexarray texarrays[MAX_TEXTURE_UNITS+1];
54 AEarray arrays[32];
Keith Whitwellcab974c2000-12-26 05:09:27 +000055 GLuint NewState;
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000056} AEcontext;
Keith Whitwellcab974c2000-12-26 05:09:27 +000057
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000058#define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context)
59#define TYPE_IDX(t) ((t) & 0xf)
Keith Whitwellcab974c2000-12-26 05:09:27 +000060
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000061static void (*colorfuncs[2][8])( const void * ) = {
62 { (void (*)( const void * ))glColor3bv,
63 (void (*)( const void * ))glColor3ub,
64 (void (*)( const void * ))glColor3sv,
65 (void (*)( const void * ))glColor3usv,
66 (void (*)( const void * ))glColor3iv,
67 (void (*)( const void * ))glColor3uiv,
68 (void (*)( const void * ))glColor3fv,
69 (void (*)( const void * ))glColor3dv },
Keith Whitwellcab974c2000-12-26 05:09:27 +000070
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000071 { (void (*)( const void * ))glColor4bv,
72 (void (*)( const void * ))glColor4ub,
73 (void (*)( const void * ))glColor4sv,
74 (void (*)( const void * ))glColor4usv,
75 (void (*)( const void * ))glColor4iv,
76 (void (*)( const void * ))glColor4uiv,
77 (void (*)( const void * ))glColor4fv,
78 (void (*)( const void * ))glColor4dv }
Keith Whitwellcab974c2000-12-26 05:09:27 +000079};
80
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000081static void (*vertexfuncs[3][8])( const void * ) = {
82 { 0,
83 0,
84 (void (*)( const void * ))glVertex2sv,
85 0,
86 (void (*)( const void * ))glVertex2iv,
87 0,
88 (void (*)( const void * ))glVertex2fv,
89 (void (*)( const void * ))glVertex2dv },
Keith Whitwellcab974c2000-12-26 05:09:27 +000090
Keith Whitwell4b7d6f22001-06-01 22:22:10 +000091 { 0,
92 0,
93 (void (*)( const void * ))glVertex3sv,
94 0,
95 (void (*)( const void * ))glVertex3iv,
96 0,
97 (void (*)( const void * ))glVertex3fv,
98 (void (*)( const void * ))glVertex3dv },
Keith Whitwellcab974c2000-12-26 05:09:27 +000099
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000100 { 0,
101 0,
102 (void (*)( const void * ))glVertex4sv,
103 0,
104 (void (*)( const void * ))glVertex4iv,
105 0,
106 (void (*)( const void * ))glVertex4fv,
107 (void (*)( const void * ))glVertex4dv }
Keith Whitwellcab974c2000-12-26 05:09:27 +0000108};
109
110
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000111static void (*multitexfuncs[4][8])( GLenum, const void * ) = {
112 { 0,
113 0,
114 (void (*)( GLenum, const void * ))glMultiTexCoord1svARB,
115 0,
116 (void (*)( GLenum, const void * ))glMultiTexCoord1ivARB,
117 0,
118 (void (*)( GLenum, const void * ))glMultiTexCoord1fvARB,
119 (void (*)( GLenum, const void * ))glMultiTexCoord1dvARB },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000120
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000121 { 0,
122 0,
123 (void (*)( GLenum, const void * ))glMultiTexCoord2svARB,
124 0,
125 (void (*)( GLenum, const void * ))glMultiTexCoord2ivARB,
126 0,
127 (void (*)( GLenum, const void * ))glMultiTexCoord2fvARB,
128 (void (*)( GLenum, const void * ))glMultiTexCoord2dvARB },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000129
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000130 { 0,
131 0,
132 (void (*)( GLenum, const void * ))glMultiTexCoord3svARB,
133 0,
134 (void (*)( GLenum, const void * ))glMultiTexCoord3ivARB,
135 0,
136 (void (*)( GLenum, const void * ))glMultiTexCoord3fvARB,
137 (void (*)( GLenum, const void * ))glMultiTexCoord3dvARB },
Keith Whitwellcab974c2000-12-26 05:09:27 +0000138
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000139 { 0,
140 0,
141 (void (*)( GLenum, const void * ))glMultiTexCoord4svARB,
142 0,
143 (void (*)( GLenum, const void * ))glMultiTexCoord4ivARB,
144 0,
145 (void (*)( GLenum, const void * ))glMultiTexCoord4fvARB,
146 (void (*)( GLenum, const void * ))glMultiTexCoord4dvARB }
Keith Whitwellcab974c2000-12-26 05:09:27 +0000147};
148
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000149static void (*indexfuncs[8])( const void * ) = {
150 0,
151 (void (*)( const void * ))glIndexubv,
152 (void (*)( const void * ))glIndexsv,
153 0,
154 (void (*)( const void * ))glIndexiv,
155 0,
156 (void (*)( const void * ))glIndexfv,
157 (void (*)( const void * ))glIndexdv
Keith Whitwellcab974c2000-12-26 05:09:27 +0000158};
159
160
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000161static void (*normalfuncs[8])( const void * ) = {
162 (void (*)( const void * ))glNormal3bv,
163 0,
164 (void (*)( const void * ))glNormal3sv,
165 0,
166 (void (*)( const void * ))glNormal3iv,
167 0,
168 (void (*)( const void * ))glNormal3fv,
169 (void (*)( const void * ))glNormal3dv,
170};
171
Keith Whitwellfc00cbe2001-12-20 15:30:45 +0000172static void (*fogcoordfuncs[8])( const void * );
173static void (*secondarycolorfuncs[8])( const void * );
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000174
175GLboolean _ae_create_context( GLcontext *ctx )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000176{
Keith Whitwellfc00cbe2001-12-20 15:30:45 +0000177 static int firsttime = 1;
178
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000179 ctx->aelt_context = MALLOC( sizeof(AEcontext) );
180 if (!ctx->aelt_context)
181 return GL_FALSE;
182
Keith Whitwellfc00cbe2001-12-20 15:30:45 +0000183
184 if (firsttime)
185 {
186 firsttime = 0;
187
188 /* Don't really want to use api_compat.h for this, but the
189 * rational for using _glaph_get_proc_address is the same.
190 */
191 fogcoordfuncs[0] = _glapi_get_proc_address("glSecondaryColor3bvEXT");
192 fogcoordfuncs[1] = _glapi_get_proc_address("glSecondaryColor3ubvEXT");
193 fogcoordfuncs[2] = _glapi_get_proc_address("glSecondaryColor3svEXT");
194 fogcoordfuncs[3] = _glapi_get_proc_address("glSecondaryColor3usvEXT");
195 fogcoordfuncs[4] = _glapi_get_proc_address("glSecondaryColor3ivEXT");
196 fogcoordfuncs[5] = _glapi_get_proc_address("glSecondaryColor3uivEXT");
197 fogcoordfuncs[6] = _glapi_get_proc_address("glSecondaryColor3fvEXT");
198 fogcoordfuncs[7] = _glapi_get_proc_address("glSecondaryColor3dvEXT");
199
200 secondarycolorfuncs[6] = _glapi_get_proc_address("glFogCoordfvEXT");
201 secondarycolorfuncs[7] = _glapi_get_proc_address("glFogCoorddvEXT");
202 }
203
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000204 AE_CONTEXT(ctx)->NewState = ~0;
205 return GL_TRUE;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000206}
207
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000208
209void _ae_destroy_context( GLcontext *ctx )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000210{
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000211 if ( AE_CONTEXT( ctx ) ) {
212 FREE( ctx->aelt_context );
213 ctx->aelt_context = 0;
214 }
215}
216
217
218static void _ae_update_state( GLcontext *ctx )
219{
220 AEcontext *actx = AE_CONTEXT(ctx);
221 AEtexarray *ta = actx->texarrays;
222 AEarray *aa = actx->arrays;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000223 int i;
224
Gareth Hughes22144ab2001-03-12 00:48:37 +0000225 for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
Keith Whitwellcab974c2000-12-26 05:09:27 +0000226 if (ctx->Array.TexCoord[i].Enabled) {
227 ta->unit = i;
228 ta->array = &ctx->Array.TexCoord[i];
229 ta->func = multitexfuncs[ta->array->Size-1][TYPE_IDX(ta->array->Type)];
230 ta++;
231 }
232
233 ta->func = 0;
234
235 if (ctx->Array.Color.Enabled) {
236 aa->array = &ctx->Array.Color;
237 aa->func = colorfuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
238 aa++;
239 }
240
241 if (ctx->Array.Normal.Enabled) {
242 aa->array = &ctx->Array.Normal;
243 aa->func = normalfuncs[TYPE_IDX(aa->array->Type)];
244 aa++;
245 }
246
247 if (ctx->Array.Index.Enabled) {
248 aa->array = &ctx->Array.Index;
249 aa->func = indexfuncs[TYPE_IDX(aa->array->Type)];
250 aa++;
251 }
252
253 if (ctx->Array.EdgeFlag.Enabled) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000254 aa->array = &ctx->Array.EdgeFlag;
255 aa->func = (void (*)( const void * ))glEdgeFlagv;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000256 aa++;
257 }
258
259 if (ctx->Array.FogCoord.Enabled) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000260 aa->array = &ctx->Array.FogCoord;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000261 aa->func = fogcoordfuncs[TYPE_IDX(aa->array->Type)];
262 aa++;
263 }
264
265 if (ctx->Array.SecondaryColor.Enabled) {
266 aa->array = &ctx->Array.SecondaryColor;
267 aa->func = secondarycolorfuncs[TYPE_IDX(aa->array->Type)];
268 aa++;
269 }
270
271 /* Must be last
272 */
273 if (ctx->Array.Vertex.Enabled) {
274 aa->array = &ctx->Array.Vertex;
275 aa->func = vertexfuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
276 aa++;
277 }
278
279 aa->func = 0;
280 actx->NewState = 0;
281}
282
283
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000284void _ae_loopback_array_elt( GLint elt )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000285{
286 GET_CURRENT_CONTEXT(ctx);
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000287 AEcontext *actx = AE_CONTEXT(ctx);
288 AEtexarray *ta;
289 AEarray *aa;
290
291 if (actx->NewState)
292 _ae_update_state( ctx );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000293
294 for (ta = actx->texarrays ; ta->func ; ta++) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000295 ta->func( ta->unit, (char *)ta->array->Ptr + elt * ta->array->StrideB );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000296 }
297
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000298 /* Must be last
299 */
Keith Whitwellcab974c2000-12-26 05:09:27 +0000300 for (aa = actx->arrays ; aa->func ; aa++) {
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000301 aa->func( (char *)aa->array->Ptr + elt * aa->array->StrideB );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000302 }
303}
304
305
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000306
307void _ae_invalidate_state( GLcontext *ctx, GLuint new_state )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000308{
Keith Whitwell4b7d6f22001-06-01 22:22:10 +0000309 AE_CONTEXT(ctx)->NewState |= new_state;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000310}