api_arrayelt.c revision fc00cbe8d1ac48faf345e41a13757a8a1e2e5ebe
1/* $Id: api_arrayelt.c,v 1.4 2001/12/20 15:30:45 keithw Exp $ */
2
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
27/* Author:
28 *    Keith Whitwell <keith_whitwell@yahoo.com>
29 */
30
31#include "glheader.h"
32#include "api_arrayelt.h"
33#include "context.h"
34#include "glapi.h"
35#include "mem.h"
36#include "macros.h"
37#include "mtypes.h"
38
39
40typedef struct {
41   GLint unit;
42   struct gl_client_array *array;
43   void (*func)( GLenum, const void * );
44} AEtexarray;
45
46
47typedef struct {
48   struct gl_client_array *array;
49   void (*func)( const void * );
50} AEarray;
51
52typedef struct {
53   AEtexarray texarrays[MAX_TEXTURE_UNITS+1];
54   AEarray arrays[32];
55   GLuint NewState;
56} AEcontext;
57
58#define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context)
59#define TYPE_IDX(t) ((t) & 0xf)
60
61static 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 },
70
71   { (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 }
79};
80
81static 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 },
90
91   { 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 },
99
100   { 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 }
108};
109
110
111static 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 },
120
121   { 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 },
129
130   { 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 },
138
139   { 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 }
147};
148
149static 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
158};
159
160
161static 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
172static void (*fogcoordfuncs[8])( const void * );
173static void (*secondarycolorfuncs[8])( const void * );
174
175GLboolean _ae_create_context( GLcontext *ctx )
176{
177   static int firsttime = 1;
178
179   ctx->aelt_context = MALLOC( sizeof(AEcontext) );
180   if (!ctx->aelt_context)
181      return GL_FALSE;
182
183
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
204   AE_CONTEXT(ctx)->NewState = ~0;
205   return GL_TRUE;
206}
207
208
209void _ae_destroy_context( GLcontext *ctx )
210{
211   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;
223   int i;
224
225   for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
226      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) {
254      aa->array = &ctx->Array.EdgeFlag;
255      aa->func = (void (*)( const void * ))glEdgeFlagv;
256      aa++;
257   }
258
259   if (ctx->Array.FogCoord.Enabled) {
260      aa->array = &ctx->Array.FogCoord;
261      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
284void _ae_loopback_array_elt( GLint elt )
285{
286   GET_CURRENT_CONTEXT(ctx);
287   AEcontext *actx = AE_CONTEXT(ctx);
288   AEtexarray *ta;
289   AEarray *aa;
290
291   if (actx->NewState)
292      _ae_update_state( ctx );
293
294   for (ta = actx->texarrays ; ta->func ; ta++) {
295      ta->func( ta->unit, (char *)ta->array->Ptr + elt * ta->array->StrideB );
296   }
297
298   /* Must be last
299    */
300   for (aa = actx->arrays ; aa->func ; aa++) {
301      aa->func( (char *)aa->array->Ptr + elt * aa->array->StrideB );
302   }
303}
304
305
306
307void _ae_invalidate_state( GLcontext *ctx, GLuint new_state )
308{
309   AE_CONTEXT(ctx)->NewState |= new_state;
310}
311