2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Keith Whitwell <keith@tungstengraphics.com>
30 #include "api_arrayelt.h"
38 typedef void (*texarray_func
)( GLenum
, const void * );
42 struct gl_client_array
*array
;
46 typedef void (*array_func
)( const void * );
49 struct gl_client_array
*array
;
54 AEtexarray texarrays
[MAX_TEXTURE_COORD_UNITS
+ 1];
59 #define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context)
60 #define TYPE_IDX(t) ((t) & 0xf)
62 static void (*colorfuncs
[2][8])( const void * ) = {
63 { (array_func
)glColor3bv
,
64 (array_func
)glColor3ubv
,
65 (array_func
)glColor3sv
,
66 (array_func
)glColor3usv
,
67 (array_func
)glColor3iv
,
68 (array_func
)glColor3uiv
,
69 (array_func
)glColor3fv
,
70 (array_func
)glColor3dv
},
72 { (array_func
)glColor4bv
,
73 (array_func
)glColor4ubv
,
74 (array_func
)glColor4sv
,
75 (array_func
)glColor4usv
,
76 (array_func
)glColor4iv
,
77 (array_func
)glColor4uiv
,
78 (array_func
)glColor4fv
,
79 (array_func
)glColor4dv
}
82 static void (*vertexfuncs
[3][8])( const void * ) = {
85 (array_func
)glVertex2sv
,
87 (array_func
)glVertex2iv
,
89 (array_func
)glVertex2fv
,
90 (array_func
)glVertex2dv
},
94 (array_func
)glVertex3sv
,
96 (array_func
)glVertex3iv
,
98 (array_func
)glVertex3fv
,
99 (array_func
)glVertex3dv
},
103 (array_func
)glVertex4sv
,
105 (array_func
)glVertex4iv
,
107 (array_func
)glVertex4fv
,
108 (array_func
)glVertex4dv
}
112 static void (*multitexfuncs
[4][8])( GLenum
, const void * ) = {
115 (texarray_func
)glMultiTexCoord1svARB
,
117 (texarray_func
)glMultiTexCoord1ivARB
,
119 (texarray_func
)glMultiTexCoord1fvARB
,
120 (texarray_func
)glMultiTexCoord1dvARB
},
124 (texarray_func
)glMultiTexCoord2svARB
,
126 (texarray_func
)glMultiTexCoord2ivARB
,
128 (texarray_func
)glMultiTexCoord2fvARB
,
129 (texarray_func
)glMultiTexCoord2dvARB
},
133 (texarray_func
)glMultiTexCoord3svARB
,
135 (texarray_func
)glMultiTexCoord3ivARB
,
137 (texarray_func
)glMultiTexCoord3fvARB
,
138 (texarray_func
)glMultiTexCoord3dvARB
},
142 (texarray_func
)glMultiTexCoord4svARB
,
144 (texarray_func
)glMultiTexCoord4ivARB
,
146 (texarray_func
)glMultiTexCoord4fvARB
,
147 (texarray_func
)glMultiTexCoord4dvARB
}
150 static void (*indexfuncs
[8])( const void * ) = {
152 (array_func
)glIndexubv
,
153 (array_func
)glIndexsv
,
155 (array_func
)glIndexiv
,
157 (array_func
)glIndexfv
,
158 (array_func
)glIndexdv
162 static void (*normalfuncs
[8])( const void * ) = {
163 (array_func
)glNormal3bv
,
165 (array_func
)glNormal3sv
,
167 (array_func
)glNormal3iv
,
169 (array_func
)glNormal3fv
,
170 (array_func
)glNormal3dv
,
174 /* Wrapper functions in case glSecondaryColor*EXT doesn't exist */
175 static void SecondaryColor3bvEXT(const GLbyte
*c
)
177 _glapi_Dispatch
->SecondaryColor3bvEXT(c
);
180 static void SecondaryColor3ubvEXT(const GLubyte
*c
)
182 _glapi_Dispatch
->SecondaryColor3ubvEXT(c
);
185 static void SecondaryColor3svEXT(const GLshort
*c
)
187 _glapi_Dispatch
->SecondaryColor3svEXT(c
);
190 static void SecondaryColor3usvEXT(const GLushort
*c
)
192 _glapi_Dispatch
->SecondaryColor3usvEXT(c
);
195 static void SecondaryColor3ivEXT(const GLint
*c
)
197 _glapi_Dispatch
->SecondaryColor3ivEXT(c
);
200 static void SecondaryColor3uivEXT(const GLuint
*c
)
202 _glapi_Dispatch
->SecondaryColor3uivEXT(c
);
205 static void SecondaryColor3fvEXT(const GLfloat
*c
)
207 _glapi_Dispatch
->SecondaryColor3fvEXT(c
);
210 static void SecondaryColor3dvEXT(const GLdouble
*c
)
212 _glapi_Dispatch
->SecondaryColor3dvEXT(c
);
215 static void (*secondarycolorfuncs
[8])( const void * ) = {
216 (array_func
) SecondaryColor3bvEXT
,
217 (array_func
) SecondaryColor3ubvEXT
,
218 (array_func
) SecondaryColor3svEXT
,
219 (array_func
) SecondaryColor3usvEXT
,
220 (array_func
) SecondaryColor3ivEXT
,
221 (array_func
) SecondaryColor3uivEXT
,
222 (array_func
) SecondaryColor3fvEXT
,
223 (array_func
) SecondaryColor3dvEXT
,
227 /* Again, wrapper functions in case glSecondaryColor*EXT doesn't exist */
228 static void FogCoordfvEXT(const GLfloat
*f
)
230 _glapi_Dispatch
->FogCoordfvEXT(f
);
233 static void FogCoorddvEXT(const GLdouble
*f
)
235 _glapi_Dispatch
->FogCoorddvEXT(f
);
238 static void (*fogcoordfuncs
[8])( const void * ) = {
245 (array_func
) FogCoordfvEXT
,
246 (array_func
) FogCoorddvEXT
251 GLboolean
_ae_create_context( GLcontext
*ctx
)
253 ctx
->aelt_context
= MALLOC( sizeof(AEcontext
) );
254 if (!ctx
->aelt_context
)
257 AE_CONTEXT(ctx
)->NewState
= ~0;
262 void _ae_destroy_context( GLcontext
*ctx
)
264 if ( AE_CONTEXT( ctx
) ) {
265 FREE( ctx
->aelt_context
);
266 ctx
->aelt_context
= 0;
271 static void _ae_update_state( GLcontext
*ctx
)
273 AEcontext
*actx
= AE_CONTEXT(ctx
);
274 AEtexarray
*ta
= actx
->texarrays
;
275 AEarray
*aa
= actx
->arrays
;
278 for (i
= 0 ; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
279 if (ctx
->Array
.TexCoord
[i
].Enabled
) {
281 ta
->array
= &ctx
->Array
.TexCoord
[i
];
282 ta
->func
= multitexfuncs
[ta
->array
->Size
-1][TYPE_IDX(ta
->array
->Type
)];
288 if (ctx
->Array
.Color
.Enabled
) {
289 aa
->array
= &ctx
->Array
.Color
;
290 aa
->func
= colorfuncs
[aa
->array
->Size
-3][TYPE_IDX(aa
->array
->Type
)];
294 if (ctx
->Array
.Normal
.Enabled
) {
295 aa
->array
= &ctx
->Array
.Normal
;
296 aa
->func
= normalfuncs
[TYPE_IDX(aa
->array
->Type
)];
300 if (ctx
->Array
.Index
.Enabled
) {
301 aa
->array
= &ctx
->Array
.Index
;
302 aa
->func
= indexfuncs
[TYPE_IDX(aa
->array
->Type
)];
306 if (ctx
->Array
.EdgeFlag
.Enabled
) {
307 aa
->array
= &ctx
->Array
.EdgeFlag
;
308 aa
->func
= (array_func
)glEdgeFlagv
;
312 if (ctx
->Array
.FogCoord
.Enabled
) {
313 aa
->array
= &ctx
->Array
.FogCoord
;
314 aa
->func
= fogcoordfuncs
[TYPE_IDX(aa
->array
->Type
)];
318 if (ctx
->Array
.SecondaryColor
.Enabled
) {
319 aa
->array
= &ctx
->Array
.SecondaryColor
;
320 aa
->func
= secondarycolorfuncs
[TYPE_IDX(aa
->array
->Type
)];
326 if (ctx
->Array
.Vertex
.Enabled
) {
327 aa
->array
= &ctx
->Array
.Vertex
;
328 aa
->func
= vertexfuncs
[aa
->array
->Size
-2][TYPE_IDX(aa
->array
->Type
)];
337 void _ae_loopback_array_elt( GLint elt
)
339 GET_CURRENT_CONTEXT(ctx
);
340 AEcontext
*actx
= AE_CONTEXT(ctx
);
345 _ae_update_state( ctx
);
347 for (ta
= actx
->texarrays
; ta
->func
; ta
++) {
348 GLubyte
*src
= ta
->array
->BufferObj
->Data
349 + (GLuint
) ta
->array
->Ptr
350 + elt
* ta
->array
->StrideB
;
351 ta
->func( ta
->unit
+ GL_TEXTURE0_ARB
, src
);
356 for (aa
= actx
->arrays
; aa
->func
; aa
++) {
357 GLubyte
*src
= aa
->array
->BufferObj
->Data
358 + (GLuint
) aa
->array
->Ptr
359 + elt
* aa
->array
->StrideB
;
366 void _ae_invalidate_state( GLcontext
*ctx
, GLuint new_state
)
368 AE_CONTEXT(ctx
)->NewState
|= new_state
;