1 /* $Id: api_arrayelt.c,v 1.12 2003/01/14 04:55:45 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
28 * Keith Whitwell <keith@tungstengraphics.com>
32 #include "api_arrayelt.h"
40 typedef void (*texarray_func
)( GLenum
, const void * );
44 struct gl_client_array
*array
;
48 typedef void (*array_func
)( const void * );
51 struct gl_client_array
*array
;
56 AEtexarray texarrays
[MAX_TEXTURE_COORD_UNITS
+ 1];
61 #define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context)
62 #define TYPE_IDX(t) ((t) & 0xf)
64 static void (*colorfuncs
[2][8])( const void * ) = {
65 { (array_func
)glColor3bv
,
66 (array_func
)glColor3ubv
,
67 (array_func
)glColor3sv
,
68 (array_func
)glColor3usv
,
69 (array_func
)glColor3iv
,
70 (array_func
)glColor3uiv
,
71 (array_func
)glColor3fv
,
72 (array_func
)glColor3dv
},
74 { (array_func
)glColor4bv
,
75 (array_func
)glColor4ubv
,
76 (array_func
)glColor4sv
,
77 (array_func
)glColor4usv
,
78 (array_func
)glColor4iv
,
79 (array_func
)glColor4uiv
,
80 (array_func
)glColor4fv
,
81 (array_func
)glColor4dv
}
84 static void (*vertexfuncs
[3][8])( const void * ) = {
87 (array_func
)glVertex2sv
,
89 (array_func
)glVertex2iv
,
91 (array_func
)glVertex2fv
,
92 (array_func
)glVertex2dv
},
96 (array_func
)glVertex3sv
,
98 (array_func
)glVertex3iv
,
100 (array_func
)glVertex3fv
,
101 (array_func
)glVertex3dv
},
105 (array_func
)glVertex4sv
,
107 (array_func
)glVertex4iv
,
109 (array_func
)glVertex4fv
,
110 (array_func
)glVertex4dv
}
114 static void (*multitexfuncs
[4][8])( GLenum
, const void * ) = {
117 (texarray_func
)glMultiTexCoord1svARB
,
119 (texarray_func
)glMultiTexCoord1ivARB
,
121 (texarray_func
)glMultiTexCoord1fvARB
,
122 (texarray_func
)glMultiTexCoord1dvARB
},
126 (texarray_func
)glMultiTexCoord2svARB
,
128 (texarray_func
)glMultiTexCoord2ivARB
,
130 (texarray_func
)glMultiTexCoord2fvARB
,
131 (texarray_func
)glMultiTexCoord2dvARB
},
135 (texarray_func
)glMultiTexCoord3svARB
,
137 (texarray_func
)glMultiTexCoord3ivARB
,
139 (texarray_func
)glMultiTexCoord3fvARB
,
140 (texarray_func
)glMultiTexCoord3dvARB
},
144 (texarray_func
)glMultiTexCoord4svARB
,
146 (texarray_func
)glMultiTexCoord4ivARB
,
148 (texarray_func
)glMultiTexCoord4fvARB
,
149 (texarray_func
)glMultiTexCoord4dvARB
}
152 static void (*indexfuncs
[8])( const void * ) = {
154 (array_func
)glIndexubv
,
155 (array_func
)glIndexsv
,
157 (array_func
)glIndexiv
,
159 (array_func
)glIndexfv
,
160 (array_func
)glIndexdv
164 static void (*normalfuncs
[8])( const void * ) = {
165 (array_func
)glNormal3bv
,
167 (array_func
)glNormal3sv
,
169 (array_func
)glNormal3iv
,
171 (array_func
)glNormal3fv
,
172 (array_func
)glNormal3dv
,
176 /* Wrapper functions in case glSecondaryColor*EXT doesn't exist */
177 static void SecondaryColor3bvEXT(const GLbyte
*c
)
179 _glapi_Dispatch
->SecondaryColor3bvEXT(c
);
182 static void SecondaryColor3ubvEXT(const GLubyte
*c
)
184 _glapi_Dispatch
->SecondaryColor3ubvEXT(c
);
187 static void SecondaryColor3svEXT(const GLshort
*c
)
189 _glapi_Dispatch
->SecondaryColor3svEXT(c
);
192 static void SecondaryColor3usvEXT(const GLushort
*c
)
194 _glapi_Dispatch
->SecondaryColor3usvEXT(c
);
197 static void SecondaryColor3ivEXT(const GLint
*c
)
199 _glapi_Dispatch
->SecondaryColor3ivEXT(c
);
202 static void SecondaryColor3uivEXT(const GLuint
*c
)
204 _glapi_Dispatch
->SecondaryColor3uivEXT(c
);
207 static void SecondaryColor3fvEXT(const GLfloat
*c
)
209 _glapi_Dispatch
->SecondaryColor3fvEXT(c
);
212 static void SecondaryColor3dvEXT(const GLdouble
*c
)
214 _glapi_Dispatch
->SecondaryColor3dvEXT(c
);
217 static void (*secondarycolorfuncs
[8])( const void * ) = {
218 (array_func
) SecondaryColor3bvEXT
,
219 (array_func
) SecondaryColor3ubvEXT
,
220 (array_func
) SecondaryColor3svEXT
,
221 (array_func
) SecondaryColor3usvEXT
,
222 (array_func
) SecondaryColor3ivEXT
,
223 (array_func
) SecondaryColor3uivEXT
,
224 (array_func
) SecondaryColor3fvEXT
,
225 (array_func
) SecondaryColor3dvEXT
,
229 /* Again, wrapper functions in case glSecondaryColor*EXT doesn't exist */
230 static void FogCoordfvEXT(const GLfloat
*f
)
232 _glapi_Dispatch
->FogCoordfvEXT(f
);
235 static void FogCoorddvEXT(const GLdouble
*f
)
237 _glapi_Dispatch
->FogCoorddvEXT(f
);
240 static void (*fogcoordfuncs
[8])( const void * ) = {
247 (array_func
) FogCoordfvEXT
,
248 (array_func
) FogCoorddvEXT
253 GLboolean
_ae_create_context( GLcontext
*ctx
)
255 ctx
->aelt_context
= MALLOC( sizeof(AEcontext
) );
256 if (!ctx
->aelt_context
)
259 AE_CONTEXT(ctx
)->NewState
= ~0;
264 void _ae_destroy_context( GLcontext
*ctx
)
266 if ( AE_CONTEXT( ctx
) ) {
267 FREE( ctx
->aelt_context
);
268 ctx
->aelt_context
= 0;
273 static void _ae_update_state( GLcontext
*ctx
)
275 AEcontext
*actx
= AE_CONTEXT(ctx
);
276 AEtexarray
*ta
= actx
->texarrays
;
277 AEarray
*aa
= actx
->arrays
;
280 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++)
281 if (ctx
->Array
.TexCoord
[i
].Enabled
) {
283 ta
->array
= &ctx
->Array
.TexCoord
[i
];
284 ta
->func
= multitexfuncs
[ta
->array
->Size
-1][TYPE_IDX(ta
->array
->Type
)];
290 if (ctx
->Array
.Color
.Enabled
) {
291 aa
->array
= &ctx
->Array
.Color
;
292 aa
->func
= colorfuncs
[aa
->array
->Size
-3][TYPE_IDX(aa
->array
->Type
)];
296 if (ctx
->Array
.Normal
.Enabled
) {
297 aa
->array
= &ctx
->Array
.Normal
;
298 aa
->func
= normalfuncs
[TYPE_IDX(aa
->array
->Type
)];
302 if (ctx
->Array
.Index
.Enabled
) {
303 aa
->array
= &ctx
->Array
.Index
;
304 aa
->func
= indexfuncs
[TYPE_IDX(aa
->array
->Type
)];
308 if (ctx
->Array
.EdgeFlag
.Enabled
) {
309 aa
->array
= &ctx
->Array
.EdgeFlag
;
310 aa
->func
= (array_func
)glEdgeFlagv
;
314 if (ctx
->Array
.FogCoord
.Enabled
) {
315 aa
->array
= &ctx
->Array
.FogCoord
;
316 aa
->func
= fogcoordfuncs
[TYPE_IDX(aa
->array
->Type
)];
320 if (ctx
->Array
.SecondaryColor
.Enabled
) {
321 aa
->array
= &ctx
->Array
.SecondaryColor
;
322 aa
->func
= secondarycolorfuncs
[TYPE_IDX(aa
->array
->Type
)];
328 if (ctx
->Array
.Vertex
.Enabled
) {
329 aa
->array
= &ctx
->Array
.Vertex
;
330 aa
->func
= vertexfuncs
[aa
->array
->Size
-2][TYPE_IDX(aa
->array
->Type
)];
339 void _ae_loopback_array_elt( GLint elt
)
341 GET_CURRENT_CONTEXT(ctx
);
342 AEcontext
*actx
= AE_CONTEXT(ctx
);
347 _ae_update_state( ctx
);
349 for (ta
= actx
->texarrays
; ta
->func
; ta
++) {
350 ta
->func( ta
->unit
+ GL_TEXTURE0_ARB
, (char *)ta
->array
->Ptr
+ elt
* ta
->array
->StrideB
);
355 for (aa
= actx
->arrays
; aa
->func
; aa
++) {
356 aa
->func( (char *)aa
->array
->Ptr
+ elt
* aa
->array
->StrideB
);
362 void _ae_invalidate_state( GLcontext
*ctx
, GLuint new_state
)
364 AE_CONTEXT(ctx
)->NewState
|= new_state
;