api_arrayelt.c revision 4a49301e
1/*
2 * Mesa 3-D graphics library
3 * Version:  6.5.1
4 *
5 * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25/* Author:
26 *    Keith Whitwell <keith@tungstengraphics.com>
27 */
28
29#include "glheader.h"
30#include "api_arrayelt.h"
31#include "bufferobj.h"
32#include "context.h"
33#include "imports.h"
34#include "macros.h"
35#include "glapi/dispatch.h"
36
37typedef void (GLAPIENTRY *array_func)( const void * );
38
39typedef struct {
40   const struct gl_client_array *array;
41   int offset;
42} AEarray;
43
44typedef void (GLAPIENTRY *attrib_func)( GLuint indx, const void *data );
45
46typedef struct {
47   const struct gl_client_array *array;
48   attrib_func func;
49   GLuint index;
50} AEattrib;
51
52typedef struct {
53   AEarray arrays[32];
54   AEattrib attribs[VERT_ATTRIB_MAX + 1];
55   GLuint NewState;
56
57   struct gl_buffer_object *vbo[VERT_ATTRIB_MAX];
58   GLuint nr_vbos;
59   GLboolean mapped_vbos;
60
61} AEcontext;
62
63#define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context)
64
65
66/*
67 * Convert GL_BYTE, GL_UNSIGNED_BYTE, .. GL_DOUBLE into an integer
68 * in the range [0, 7].  Luckily these type tokens are sequentially
69 * numbered in gl.h, except for GL_DOUBLE.
70 */
71#define TYPE_IDX(t) ( (t) == GL_DOUBLE ? 7 : (t) & 7 )
72
73
74#if FEATURE_arrayelt
75
76
77static const int ColorFuncs[2][8] = {
78   {
79      _gloffset_Color3bv,
80      _gloffset_Color3ubv,
81      _gloffset_Color3sv,
82      _gloffset_Color3usv,
83      _gloffset_Color3iv,
84      _gloffset_Color3uiv,
85      _gloffset_Color3fv,
86      _gloffset_Color3dv,
87   },
88   {
89      _gloffset_Color4bv,
90      _gloffset_Color4ubv,
91      _gloffset_Color4sv,
92      _gloffset_Color4usv,
93      _gloffset_Color4iv,
94      _gloffset_Color4uiv,
95      _gloffset_Color4fv,
96      _gloffset_Color4dv,
97   },
98};
99
100static const int VertexFuncs[3][8] = {
101   {
102      -1,
103      -1,
104      _gloffset_Vertex2sv,
105      -1,
106      _gloffset_Vertex2iv,
107      -1,
108      _gloffset_Vertex2fv,
109      _gloffset_Vertex2dv,
110   },
111   {
112      -1,
113      -1,
114      _gloffset_Vertex3sv,
115      -1,
116      _gloffset_Vertex3iv,
117      -1,
118      _gloffset_Vertex3fv,
119      _gloffset_Vertex3dv,
120   },
121   {
122      -1,
123      -1,
124      _gloffset_Vertex4sv,
125      -1,
126      _gloffset_Vertex4iv,
127      -1,
128      _gloffset_Vertex4fv,
129      _gloffset_Vertex4dv,
130   },
131};
132
133static const int IndexFuncs[8] = {
134   -1,
135   _gloffset_Indexubv,
136   _gloffset_Indexsv,
137   -1,
138   _gloffset_Indexiv,
139   -1,
140   _gloffset_Indexfv,
141   _gloffset_Indexdv,
142};
143
144static const int NormalFuncs[8] = {
145   _gloffset_Normal3bv,
146   -1,
147   _gloffset_Normal3sv,
148   -1,
149   _gloffset_Normal3iv,
150   -1,
151   _gloffset_Normal3fv,
152   _gloffset_Normal3dv,
153};
154
155/* Note: _gloffset_* for these may not be a compile-time constant. */
156static int SecondaryColorFuncs[8];
157static int FogCoordFuncs[8];
158
159
160/**
161 ** GL_NV_vertex_program
162 **/
163
164/* GL_BYTE attributes */
165
166static void GLAPIENTRY VertexAttrib1NbvNV(GLuint index, const GLbyte *v)
167{
168   CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0])));
169}
170
171static void GLAPIENTRY VertexAttrib1bvNV(GLuint index, const GLbyte *v)
172{
173   CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
174}
175
176static void GLAPIENTRY VertexAttrib2NbvNV(GLuint index, const GLbyte *v)
177{
178   CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]), BYTE_TO_FLOAT(v[1])));
179}
180
181static void GLAPIENTRY VertexAttrib2bvNV(GLuint index, const GLbyte *v)
182{
183   CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
184}
185
186static void GLAPIENTRY VertexAttrib3NbvNV(GLuint index, const GLbyte *v)
187{
188   CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
189					       BYTE_TO_FLOAT(v[1]),
190					       BYTE_TO_FLOAT(v[2])));
191}
192
193static void GLAPIENTRY VertexAttrib3bvNV(GLuint index, const GLbyte *v)
194{
195   CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
196}
197
198static void GLAPIENTRY VertexAttrib4NbvNV(GLuint index, const GLbyte *v)
199{
200   CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
201					       BYTE_TO_FLOAT(v[1]),
202					       BYTE_TO_FLOAT(v[2]),
203					       BYTE_TO_FLOAT(v[3])));
204}
205
206static void GLAPIENTRY VertexAttrib4bvNV(GLuint index, const GLbyte *v)
207{
208   CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
209}
210
211/* GL_UNSIGNED_BYTE attributes */
212
213static void GLAPIENTRY VertexAttrib1NubvNV(GLuint index, const GLubyte *v)
214{
215   CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0])));
216}
217
218static void GLAPIENTRY VertexAttrib1ubvNV(GLuint index, const GLubyte *v)
219{
220   CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
221}
222
223static void GLAPIENTRY VertexAttrib2NubvNV(GLuint index, const GLubyte *v)
224{
225   CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
226					       UBYTE_TO_FLOAT(v[1])));
227}
228
229static void GLAPIENTRY VertexAttrib2ubvNV(GLuint index, const GLubyte *v)
230{
231   CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
232}
233
234static void GLAPIENTRY VertexAttrib3NubvNV(GLuint index, const GLubyte *v)
235{
236   CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
237					       UBYTE_TO_FLOAT(v[1]),
238					       UBYTE_TO_FLOAT(v[2])));
239}
240static void GLAPIENTRY VertexAttrib3ubvNV(GLuint index, const GLubyte *v)
241{
242   CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
243}
244
245static void GLAPIENTRY VertexAttrib4NubvNV(GLuint index, const GLubyte *v)
246{
247   CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
248                                     UBYTE_TO_FLOAT(v[1]),
249                                     UBYTE_TO_FLOAT(v[2]),
250                                     UBYTE_TO_FLOAT(v[3])));
251}
252
253static void GLAPIENTRY VertexAttrib4ubvNV(GLuint index, const GLubyte *v)
254{
255   CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
256}
257
258/* GL_SHORT attributes */
259
260static void GLAPIENTRY VertexAttrib1NsvNV(GLuint index, const GLshort *v)
261{
262   CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0])));
263}
264
265static void GLAPIENTRY VertexAttrib1svNV(GLuint index, const GLshort *v)
266{
267   CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
268}
269
270static void GLAPIENTRY VertexAttrib2NsvNV(GLuint index, const GLshort *v)
271{
272   CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
273					       SHORT_TO_FLOAT(v[1])));
274}
275
276static void GLAPIENTRY VertexAttrib2svNV(GLuint index, const GLshort *v)
277{
278   CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
279}
280
281static void GLAPIENTRY VertexAttrib3NsvNV(GLuint index, const GLshort *v)
282{
283   CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
284			     SHORT_TO_FLOAT(v[1]),
285			     SHORT_TO_FLOAT(v[2])));
286}
287
288static void GLAPIENTRY VertexAttrib3svNV(GLuint index, const GLshort *v)
289{
290   CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
291}
292
293static void GLAPIENTRY VertexAttrib4NsvNV(GLuint index, const GLshort *v)
294{
295   CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
296			     SHORT_TO_FLOAT(v[1]),
297			     SHORT_TO_FLOAT(v[2]),
298			     SHORT_TO_FLOAT(v[3])));
299}
300
301static void GLAPIENTRY VertexAttrib4svNV(GLuint index, const GLshort *v)
302{
303   CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
304}
305
306/* GL_UNSIGNED_SHORT attributes */
307
308static void GLAPIENTRY VertexAttrib1NusvNV(GLuint index, const GLushort *v)
309{
310   CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0])));
311}
312
313static void GLAPIENTRY VertexAttrib1usvNV(GLuint index, const GLushort *v)
314{
315   CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
316}
317
318static void GLAPIENTRY VertexAttrib2NusvNV(GLuint index, const GLushort *v)
319{
320   CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
321			     USHORT_TO_FLOAT(v[1])));
322}
323
324static void GLAPIENTRY VertexAttrib2usvNV(GLuint index, const GLushort *v)
325{
326   CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
327}
328
329static void GLAPIENTRY VertexAttrib3NusvNV(GLuint index, const GLushort *v)
330{
331   CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
332					       USHORT_TO_FLOAT(v[1]),
333					       USHORT_TO_FLOAT(v[2])));
334}
335
336static void GLAPIENTRY VertexAttrib3usvNV(GLuint index, const GLushort *v)
337{
338   CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
339}
340
341static void GLAPIENTRY VertexAttrib4NusvNV(GLuint index, const GLushort *v)
342{
343   CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
344					       USHORT_TO_FLOAT(v[1]),
345					       USHORT_TO_FLOAT(v[2]),
346					       USHORT_TO_FLOAT(v[3])));
347}
348
349static void GLAPIENTRY VertexAttrib4usvNV(GLuint index, const GLushort *v)
350{
351   CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
352}
353
354/* GL_INT attributes */
355
356static void GLAPIENTRY VertexAttrib1NivNV(GLuint index, const GLint *v)
357{
358   CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0])));
359}
360
361static void GLAPIENTRY VertexAttrib1ivNV(GLuint index, const GLint *v)
362{
363   CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
364}
365
366static void GLAPIENTRY VertexAttrib2NivNV(GLuint index, const GLint *v)
367{
368   CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
369					       INT_TO_FLOAT(v[1])));
370}
371
372static void GLAPIENTRY VertexAttrib2ivNV(GLuint index, const GLint *v)
373{
374   CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
375}
376
377static void GLAPIENTRY VertexAttrib3NivNV(GLuint index, const GLint *v)
378{
379   CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
380					       INT_TO_FLOAT(v[1]),
381					       INT_TO_FLOAT(v[2])));
382}
383
384static void GLAPIENTRY VertexAttrib3ivNV(GLuint index, const GLint *v)
385{
386   CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
387}
388
389static void GLAPIENTRY VertexAttrib4NivNV(GLuint index, const GLint *v)
390{
391   CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
392					       INT_TO_FLOAT(v[1]),
393					       INT_TO_FLOAT(v[2]),
394					       INT_TO_FLOAT(v[3])));
395}
396
397static void GLAPIENTRY VertexAttrib4ivNV(GLuint index, const GLint *v)
398{
399   CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
400}
401
402/* GL_UNSIGNED_INT attributes */
403
404static void GLAPIENTRY VertexAttrib1NuivNV(GLuint index, const GLuint *v)
405{
406   CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0])));
407}
408
409static void GLAPIENTRY VertexAttrib1uivNV(GLuint index, const GLuint *v)
410{
411   CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
412}
413
414static void GLAPIENTRY VertexAttrib2NuivNV(GLuint index, const GLuint *v)
415{
416   CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
417					       UINT_TO_FLOAT(v[1])));
418}
419
420static void GLAPIENTRY VertexAttrib2uivNV(GLuint index, const GLuint *v)
421{
422   CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
423}
424
425static void GLAPIENTRY VertexAttrib3NuivNV(GLuint index, const GLuint *v)
426{
427   CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
428					       UINT_TO_FLOAT(v[1]),
429					       UINT_TO_FLOAT(v[2])));
430}
431
432static void GLAPIENTRY VertexAttrib3uivNV(GLuint index, const GLuint *v)
433{
434   CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
435}
436
437static void GLAPIENTRY VertexAttrib4NuivNV(GLuint index, const GLuint *v)
438{
439   CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
440					       UINT_TO_FLOAT(v[1]),
441					       UINT_TO_FLOAT(v[2]),
442					       UINT_TO_FLOAT(v[3])));
443}
444
445static void GLAPIENTRY VertexAttrib4uivNV(GLuint index, const GLuint *v)
446{
447   CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
448}
449
450/* GL_FLOAT attributes */
451
452static void GLAPIENTRY VertexAttrib1fvNV(GLuint index, const GLfloat *v)
453{
454   CALL_VertexAttrib1fvNV(GET_DISPATCH(), (index, v));
455}
456
457static void GLAPIENTRY VertexAttrib2fvNV(GLuint index, const GLfloat *v)
458{
459   CALL_VertexAttrib2fvNV(GET_DISPATCH(), (index, v));
460}
461
462static void GLAPIENTRY VertexAttrib3fvNV(GLuint index, const GLfloat *v)
463{
464   CALL_VertexAttrib3fvNV(GET_DISPATCH(), (index, v));
465}
466
467static void GLAPIENTRY VertexAttrib4fvNV(GLuint index, const GLfloat *v)
468{
469   CALL_VertexAttrib4fvNV(GET_DISPATCH(), (index, v));
470}
471
472/* GL_DOUBLE attributes */
473
474static void GLAPIENTRY VertexAttrib1dvNV(GLuint index, const GLdouble *v)
475{
476   CALL_VertexAttrib1dvNV(GET_DISPATCH(), (index, v));
477}
478
479static void GLAPIENTRY VertexAttrib2dvNV(GLuint index, const GLdouble *v)
480{
481   CALL_VertexAttrib2dvNV(GET_DISPATCH(), (index, v));
482}
483
484static void GLAPIENTRY VertexAttrib3dvNV(GLuint index, const GLdouble *v)
485{
486   CALL_VertexAttrib3dvNV(GET_DISPATCH(), (index, v));
487}
488
489static void GLAPIENTRY VertexAttrib4dvNV(GLuint index, const GLdouble *v)
490{
491   CALL_VertexAttrib4dvNV(GET_DISPATCH(), (index, v));
492}
493
494
495/*
496 * Array [size][type] of VertexAttrib functions
497 */
498static attrib_func AttribFuncsNV[2][4][8] = {
499   {
500      /* non-normalized */
501      {
502         /* size 1 */
503         (attrib_func) VertexAttrib1bvNV,
504         (attrib_func) VertexAttrib1ubvNV,
505         (attrib_func) VertexAttrib1svNV,
506         (attrib_func) VertexAttrib1usvNV,
507         (attrib_func) VertexAttrib1ivNV,
508         (attrib_func) VertexAttrib1uivNV,
509         (attrib_func) VertexAttrib1fvNV,
510         (attrib_func) VertexAttrib1dvNV
511      },
512      {
513         /* size 2 */
514         (attrib_func) VertexAttrib2bvNV,
515         (attrib_func) VertexAttrib2ubvNV,
516         (attrib_func) VertexAttrib2svNV,
517         (attrib_func) VertexAttrib2usvNV,
518         (attrib_func) VertexAttrib2ivNV,
519         (attrib_func) VertexAttrib2uivNV,
520         (attrib_func) VertexAttrib2fvNV,
521         (attrib_func) VertexAttrib2dvNV
522      },
523      {
524         /* size 3 */
525         (attrib_func) VertexAttrib3bvNV,
526         (attrib_func) VertexAttrib3ubvNV,
527         (attrib_func) VertexAttrib3svNV,
528         (attrib_func) VertexAttrib3usvNV,
529         (attrib_func) VertexAttrib3ivNV,
530         (attrib_func) VertexAttrib3uivNV,
531         (attrib_func) VertexAttrib3fvNV,
532         (attrib_func) VertexAttrib3dvNV
533      },
534      {
535         /* size 4 */
536         (attrib_func) VertexAttrib4bvNV,
537         (attrib_func) VertexAttrib4ubvNV,
538         (attrib_func) VertexAttrib4svNV,
539         (attrib_func) VertexAttrib4usvNV,
540         (attrib_func) VertexAttrib4ivNV,
541         (attrib_func) VertexAttrib4uivNV,
542         (attrib_func) VertexAttrib4fvNV,
543         (attrib_func) VertexAttrib4dvNV
544      }
545   },
546   {
547      /* normalized (except for float/double) */
548      {
549         /* size 1 */
550         (attrib_func) VertexAttrib1NbvNV,
551         (attrib_func) VertexAttrib1NubvNV,
552         (attrib_func) VertexAttrib1NsvNV,
553         (attrib_func) VertexAttrib1NusvNV,
554         (attrib_func) VertexAttrib1NivNV,
555         (attrib_func) VertexAttrib1NuivNV,
556         (attrib_func) VertexAttrib1fvNV,
557         (attrib_func) VertexAttrib1dvNV
558      },
559      {
560         /* size 2 */
561         (attrib_func) VertexAttrib2NbvNV,
562         (attrib_func) VertexAttrib2NubvNV,
563         (attrib_func) VertexAttrib2NsvNV,
564         (attrib_func) VertexAttrib2NusvNV,
565         (attrib_func) VertexAttrib2NivNV,
566         (attrib_func) VertexAttrib2NuivNV,
567         (attrib_func) VertexAttrib2fvNV,
568         (attrib_func) VertexAttrib2dvNV
569      },
570      {
571         /* size 3 */
572         (attrib_func) VertexAttrib3NbvNV,
573         (attrib_func) VertexAttrib3NubvNV,
574         (attrib_func) VertexAttrib3NsvNV,
575         (attrib_func) VertexAttrib3NusvNV,
576         (attrib_func) VertexAttrib3NivNV,
577         (attrib_func) VertexAttrib3NuivNV,
578         (attrib_func) VertexAttrib3fvNV,
579         (attrib_func) VertexAttrib3dvNV
580      },
581      {
582         /* size 4 */
583         (attrib_func) VertexAttrib4NbvNV,
584         (attrib_func) VertexAttrib4NubvNV,
585         (attrib_func) VertexAttrib4NsvNV,
586         (attrib_func) VertexAttrib4NusvNV,
587         (attrib_func) VertexAttrib4NivNV,
588         (attrib_func) VertexAttrib4NuivNV,
589         (attrib_func) VertexAttrib4fvNV,
590         (attrib_func) VertexAttrib4dvNV
591      }
592   }
593};
594
595
596/**
597 ** GL_ARB_vertex_program
598 **/
599
600/* GL_BYTE attributes */
601
602static void GLAPIENTRY VertexAttrib1NbvARB(GLuint index, const GLbyte *v)
603{
604   CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0])));
605}
606
607static void GLAPIENTRY VertexAttrib1bvARB(GLuint index, const GLbyte *v)
608{
609   CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
610}
611
612static void GLAPIENTRY VertexAttrib2NbvARB(GLuint index, const GLbyte *v)
613{
614   CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]), BYTE_TO_FLOAT(v[1])));
615}
616
617static void GLAPIENTRY VertexAttrib2bvARB(GLuint index, const GLbyte *v)
618{
619   CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
620}
621
622static void GLAPIENTRY VertexAttrib3NbvARB(GLuint index, const GLbyte *v)
623{
624   CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
625					       BYTE_TO_FLOAT(v[1]),
626					       BYTE_TO_FLOAT(v[2])));
627}
628
629static void GLAPIENTRY VertexAttrib3bvARB(GLuint index, const GLbyte *v)
630{
631   CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
632}
633
634static void GLAPIENTRY VertexAttrib4NbvARB(GLuint index, const GLbyte *v)
635{
636   CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
637					       BYTE_TO_FLOAT(v[1]),
638					       BYTE_TO_FLOAT(v[2]),
639					       BYTE_TO_FLOAT(v[3])));
640}
641
642static void GLAPIENTRY VertexAttrib4bvARB(GLuint index, const GLbyte *v)
643{
644   CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
645}
646
647/* GL_UNSIGNED_BYTE attributes */
648
649static void GLAPIENTRY VertexAttrib1NubvARB(GLuint index, const GLubyte *v)
650{
651   CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0])));
652}
653
654static void GLAPIENTRY VertexAttrib1ubvARB(GLuint index, const GLubyte *v)
655{
656   CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
657}
658
659static void GLAPIENTRY VertexAttrib2NubvARB(GLuint index, const GLubyte *v)
660{
661   CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
662					       UBYTE_TO_FLOAT(v[1])));
663}
664
665static void GLAPIENTRY VertexAttrib2ubvARB(GLuint index, const GLubyte *v)
666{
667   CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
668}
669
670static void GLAPIENTRY VertexAttrib3NubvARB(GLuint index, const GLubyte *v)
671{
672   CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
673					       UBYTE_TO_FLOAT(v[1]),
674					       UBYTE_TO_FLOAT(v[2])));
675}
676static void GLAPIENTRY VertexAttrib3ubvARB(GLuint index, const GLubyte *v)
677{
678   CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
679}
680
681static void GLAPIENTRY VertexAttrib4NubvARB(GLuint index, const GLubyte *v)
682{
683   CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
684                                     UBYTE_TO_FLOAT(v[1]),
685                                     UBYTE_TO_FLOAT(v[2]),
686                                     UBYTE_TO_FLOAT(v[3])));
687}
688
689static void GLAPIENTRY VertexAttrib4ubvARB(GLuint index, const GLubyte *v)
690{
691   CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
692}
693
694/* GL_SHORT attributes */
695
696static void GLAPIENTRY VertexAttrib1NsvARB(GLuint index, const GLshort *v)
697{
698   CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0])));
699}
700
701static void GLAPIENTRY VertexAttrib1svARB(GLuint index, const GLshort *v)
702{
703   CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
704}
705
706static void GLAPIENTRY VertexAttrib2NsvARB(GLuint index, const GLshort *v)
707{
708   CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
709					       SHORT_TO_FLOAT(v[1])));
710}
711
712static void GLAPIENTRY VertexAttrib2svARB(GLuint index, const GLshort *v)
713{
714   CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
715}
716
717static void GLAPIENTRY VertexAttrib3NsvARB(GLuint index, const GLshort *v)
718{
719   CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
720			     SHORT_TO_FLOAT(v[1]),
721			     SHORT_TO_FLOAT(v[2])));
722}
723
724static void GLAPIENTRY VertexAttrib3svARB(GLuint index, const GLshort *v)
725{
726   CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
727}
728
729static void GLAPIENTRY VertexAttrib4NsvARB(GLuint index, const GLshort *v)
730{
731   CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
732			     SHORT_TO_FLOAT(v[1]),
733			     SHORT_TO_FLOAT(v[2]),
734			     SHORT_TO_FLOAT(v[3])));
735}
736
737static void GLAPIENTRY VertexAttrib4svARB(GLuint index, const GLshort *v)
738{
739   CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
740}
741
742/* GL_UNSIGNED_SHORT attributes */
743
744static void GLAPIENTRY VertexAttrib1NusvARB(GLuint index, const GLushort *v)
745{
746   CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0])));
747}
748
749static void GLAPIENTRY VertexAttrib1usvARB(GLuint index, const GLushort *v)
750{
751   CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
752}
753
754static void GLAPIENTRY VertexAttrib2NusvARB(GLuint index, const GLushort *v)
755{
756   CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
757			     USHORT_TO_FLOAT(v[1])));
758}
759
760static void GLAPIENTRY VertexAttrib2usvARB(GLuint index, const GLushort *v)
761{
762   CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
763}
764
765static void GLAPIENTRY VertexAttrib3NusvARB(GLuint index, const GLushort *v)
766{
767   CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
768					       USHORT_TO_FLOAT(v[1]),
769					       USHORT_TO_FLOAT(v[2])));
770}
771
772static void GLAPIENTRY VertexAttrib3usvARB(GLuint index, const GLushort *v)
773{
774   CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
775}
776
777static void GLAPIENTRY VertexAttrib4NusvARB(GLuint index, const GLushort *v)
778{
779   CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
780					       USHORT_TO_FLOAT(v[1]),
781					       USHORT_TO_FLOAT(v[2]),
782					       USHORT_TO_FLOAT(v[3])));
783}
784
785static void GLAPIENTRY VertexAttrib4usvARB(GLuint index, const GLushort *v)
786{
787   CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
788}
789
790/* GL_INT attributes */
791
792static void GLAPIENTRY VertexAttrib1NivARB(GLuint index, const GLint *v)
793{
794   CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0])));
795}
796
797static void GLAPIENTRY VertexAttrib1ivARB(GLuint index, const GLint *v)
798{
799   CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
800}
801
802static void GLAPIENTRY VertexAttrib2NivARB(GLuint index, const GLint *v)
803{
804   CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
805					       INT_TO_FLOAT(v[1])));
806}
807
808static void GLAPIENTRY VertexAttrib2ivARB(GLuint index, const GLint *v)
809{
810   CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
811}
812
813static void GLAPIENTRY VertexAttrib3NivARB(GLuint index, const GLint *v)
814{
815   CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
816					       INT_TO_FLOAT(v[1]),
817					       INT_TO_FLOAT(v[2])));
818}
819
820static void GLAPIENTRY VertexAttrib3ivARB(GLuint index, const GLint *v)
821{
822   CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
823}
824
825static void GLAPIENTRY VertexAttrib4NivARB(GLuint index, const GLint *v)
826{
827   CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
828					       INT_TO_FLOAT(v[1]),
829					       INT_TO_FLOAT(v[2]),
830					       INT_TO_FLOAT(v[3])));
831}
832
833static void GLAPIENTRY VertexAttrib4ivARB(GLuint index, const GLint *v)
834{
835   CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
836}
837
838/* GL_UNSIGNED_INT attributes */
839
840static void GLAPIENTRY VertexAttrib1NuivARB(GLuint index, const GLuint *v)
841{
842   CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0])));
843}
844
845static void GLAPIENTRY VertexAttrib1uivARB(GLuint index, const GLuint *v)
846{
847   CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
848}
849
850static void GLAPIENTRY VertexAttrib2NuivARB(GLuint index, const GLuint *v)
851{
852   CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
853					       UINT_TO_FLOAT(v[1])));
854}
855
856static void GLAPIENTRY VertexAttrib2uivARB(GLuint index, const GLuint *v)
857{
858   CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
859}
860
861static void GLAPIENTRY VertexAttrib3NuivARB(GLuint index, const GLuint *v)
862{
863   CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
864					       UINT_TO_FLOAT(v[1]),
865					       UINT_TO_FLOAT(v[2])));
866}
867
868static void GLAPIENTRY VertexAttrib3uivARB(GLuint index, const GLuint *v)
869{
870   CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
871}
872
873static void GLAPIENTRY VertexAttrib4NuivARB(GLuint index, const GLuint *v)
874{
875   CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
876					       UINT_TO_FLOAT(v[1]),
877					       UINT_TO_FLOAT(v[2]),
878					       UINT_TO_FLOAT(v[3])));
879}
880
881static void GLAPIENTRY VertexAttrib4uivARB(GLuint index, const GLuint *v)
882{
883   CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
884}
885
886/* GL_FLOAT attributes */
887
888static void GLAPIENTRY VertexAttrib1fvARB(GLuint index, const GLfloat *v)
889{
890   CALL_VertexAttrib1fvARB(GET_DISPATCH(), (index, v));
891}
892
893static void GLAPIENTRY VertexAttrib2fvARB(GLuint index, const GLfloat *v)
894{
895   CALL_VertexAttrib2fvARB(GET_DISPATCH(), (index, v));
896}
897
898static void GLAPIENTRY VertexAttrib3fvARB(GLuint index, const GLfloat *v)
899{
900   CALL_VertexAttrib3fvARB(GET_DISPATCH(), (index, v));
901}
902
903static void GLAPIENTRY VertexAttrib4fvARB(GLuint index, const GLfloat *v)
904{
905   CALL_VertexAttrib4fvARB(GET_DISPATCH(), (index, v));
906}
907
908/* GL_DOUBLE attributes */
909
910static void GLAPIENTRY VertexAttrib1dvARB(GLuint index, const GLdouble *v)
911{
912   CALL_VertexAttrib1dvARB(GET_DISPATCH(), (index, v));
913}
914
915static void GLAPIENTRY VertexAttrib2dvARB(GLuint index, const GLdouble *v)
916{
917   CALL_VertexAttrib2dvARB(GET_DISPATCH(), (index, v));
918}
919
920static void GLAPIENTRY VertexAttrib3dvARB(GLuint index, const GLdouble *v)
921{
922   CALL_VertexAttrib3dvARB(GET_DISPATCH(), (index, v));
923}
924
925static void GLAPIENTRY VertexAttrib4dvARB(GLuint index, const GLdouble *v)
926{
927   CALL_VertexAttrib4dvARB(GET_DISPATCH(), (index, v));
928}
929
930
931/*
932 * Array [size][type] of VertexAttrib functions
933 */
934static attrib_func AttribFuncsARB[2][4][8] = {
935   {
936      /* non-normalized */
937      {
938         /* size 1 */
939         (attrib_func) VertexAttrib1bvARB,
940         (attrib_func) VertexAttrib1ubvARB,
941         (attrib_func) VertexAttrib1svARB,
942         (attrib_func) VertexAttrib1usvARB,
943         (attrib_func) VertexAttrib1ivARB,
944         (attrib_func) VertexAttrib1uivARB,
945         (attrib_func) VertexAttrib1fvARB,
946         (attrib_func) VertexAttrib1dvARB
947      },
948      {
949         /* size 2 */
950         (attrib_func) VertexAttrib2bvARB,
951         (attrib_func) VertexAttrib2ubvARB,
952         (attrib_func) VertexAttrib2svARB,
953         (attrib_func) VertexAttrib2usvARB,
954         (attrib_func) VertexAttrib2ivARB,
955         (attrib_func) VertexAttrib2uivARB,
956         (attrib_func) VertexAttrib2fvARB,
957         (attrib_func) VertexAttrib2dvARB
958      },
959      {
960         /* size 3 */
961         (attrib_func) VertexAttrib3bvARB,
962         (attrib_func) VertexAttrib3ubvARB,
963         (attrib_func) VertexAttrib3svARB,
964         (attrib_func) VertexAttrib3usvARB,
965         (attrib_func) VertexAttrib3ivARB,
966         (attrib_func) VertexAttrib3uivARB,
967         (attrib_func) VertexAttrib3fvARB,
968         (attrib_func) VertexAttrib3dvARB
969      },
970      {
971         /* size 4 */
972         (attrib_func) VertexAttrib4bvARB,
973         (attrib_func) VertexAttrib4ubvARB,
974         (attrib_func) VertexAttrib4svARB,
975         (attrib_func) VertexAttrib4usvARB,
976         (attrib_func) VertexAttrib4ivARB,
977         (attrib_func) VertexAttrib4uivARB,
978         (attrib_func) VertexAttrib4fvARB,
979         (attrib_func) VertexAttrib4dvARB
980      }
981   },
982   {
983      /* normalized (except for float/double) */
984      {
985         /* size 1 */
986         (attrib_func) VertexAttrib1NbvARB,
987         (attrib_func) VertexAttrib1NubvARB,
988         (attrib_func) VertexAttrib1NsvARB,
989         (attrib_func) VertexAttrib1NusvARB,
990         (attrib_func) VertexAttrib1NivARB,
991         (attrib_func) VertexAttrib1NuivARB,
992         (attrib_func) VertexAttrib1fvARB,
993         (attrib_func) VertexAttrib1dvARB
994      },
995      {
996         /* size 2 */
997         (attrib_func) VertexAttrib2NbvARB,
998         (attrib_func) VertexAttrib2NubvARB,
999         (attrib_func) VertexAttrib2NsvARB,
1000         (attrib_func) VertexAttrib2NusvARB,
1001         (attrib_func) VertexAttrib2NivARB,
1002         (attrib_func) VertexAttrib2NuivARB,
1003         (attrib_func) VertexAttrib2fvARB,
1004         (attrib_func) VertexAttrib2dvARB
1005      },
1006      {
1007         /* size 3 */
1008         (attrib_func) VertexAttrib3NbvARB,
1009         (attrib_func) VertexAttrib3NubvARB,
1010         (attrib_func) VertexAttrib3NsvARB,
1011         (attrib_func) VertexAttrib3NusvARB,
1012         (attrib_func) VertexAttrib3NivARB,
1013         (attrib_func) VertexAttrib3NuivARB,
1014         (attrib_func) VertexAttrib3fvARB,
1015         (attrib_func) VertexAttrib3dvARB
1016      },
1017      {
1018         /* size 4 */
1019         (attrib_func) VertexAttrib4NbvARB,
1020         (attrib_func) VertexAttrib4NubvARB,
1021         (attrib_func) VertexAttrib4NsvARB,
1022         (attrib_func) VertexAttrib4NusvARB,
1023         (attrib_func) VertexAttrib4NivARB,
1024         (attrib_func) VertexAttrib4NuivARB,
1025         (attrib_func) VertexAttrib4fvARB,
1026         (attrib_func) VertexAttrib4dvARB
1027      }
1028   }
1029};
1030
1031/**********************************************************************/
1032
1033
1034GLboolean _ae_create_context( GLcontext *ctx )
1035{
1036   if (ctx->aelt_context)
1037      return GL_TRUE;
1038
1039   /* These _gloffset_* values may not be compile-time constants */
1040   SecondaryColorFuncs[0] = _gloffset_SecondaryColor3bvEXT;
1041   SecondaryColorFuncs[1] = _gloffset_SecondaryColor3ubvEXT;
1042   SecondaryColorFuncs[2] = _gloffset_SecondaryColor3svEXT;
1043   SecondaryColorFuncs[3] = _gloffset_SecondaryColor3usvEXT;
1044   SecondaryColorFuncs[4] = _gloffset_SecondaryColor3ivEXT;
1045   SecondaryColorFuncs[5] = _gloffset_SecondaryColor3uivEXT;
1046   SecondaryColorFuncs[6] = _gloffset_SecondaryColor3fvEXT;
1047   SecondaryColorFuncs[7] = _gloffset_SecondaryColor3dvEXT;
1048
1049   FogCoordFuncs[0] = -1;
1050   FogCoordFuncs[1] = -1;
1051   FogCoordFuncs[2] = -1;
1052   FogCoordFuncs[3] = -1;
1053   FogCoordFuncs[4] = -1;
1054   FogCoordFuncs[5] = -1;
1055   FogCoordFuncs[6] = _gloffset_FogCoordfvEXT;
1056   FogCoordFuncs[7] = _gloffset_FogCoorddvEXT;
1057
1058   ctx->aelt_context = CALLOC( sizeof(AEcontext) );
1059   if (!ctx->aelt_context)
1060      return GL_FALSE;
1061
1062   AE_CONTEXT(ctx)->NewState = ~0;
1063   return GL_TRUE;
1064}
1065
1066
1067void _ae_destroy_context( GLcontext *ctx )
1068{
1069   if ( AE_CONTEXT( ctx ) ) {
1070      FREE( ctx->aelt_context );
1071      ctx->aelt_context = NULL;
1072   }
1073}
1074
1075static void check_vbo( AEcontext *actx,
1076		       struct gl_buffer_object *vbo )
1077{
1078   if (_mesa_is_bufferobj(vbo) && !_mesa_bufferobj_mapped(vbo)) {
1079      GLuint i;
1080      for (i = 0; i < actx->nr_vbos; i++)
1081	 if (actx->vbo[i] == vbo)
1082	    return;
1083      assert(actx->nr_vbos < VERT_ATTRIB_MAX);
1084      actx->vbo[actx->nr_vbos++] = vbo;
1085   }
1086}
1087
1088
1089/**
1090 * Make a list of per-vertex functions to call for each glArrayElement call.
1091 * These functions access the array data (i.e. glVertex, glColor, glNormal,
1092 * etc).
1093 * Note: this may be called during display list construction.
1094 */
1095static void _ae_update_state( GLcontext *ctx )
1096{
1097   AEcontext *actx = AE_CONTEXT(ctx);
1098   AEarray *aa = actx->arrays;
1099   AEattrib *at = actx->attribs;
1100   GLuint i;
1101   struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
1102
1103   actx->nr_vbos = 0;
1104
1105   /* conventional vertex arrays */
1106   if (arrayObj->Index.Enabled) {
1107      aa->array = &arrayObj->Index;
1108      aa->offset = IndexFuncs[TYPE_IDX(aa->array->Type)];
1109      check_vbo(actx, aa->array->BufferObj);
1110      aa++;
1111   }
1112   if (arrayObj->EdgeFlag.Enabled) {
1113      aa->array = &arrayObj->EdgeFlag;
1114      aa->offset = _gloffset_EdgeFlagv;
1115      check_vbo(actx, aa->array->BufferObj);
1116      aa++;
1117   }
1118   if (arrayObj->Normal.Enabled) {
1119      aa->array = &arrayObj->Normal;
1120      aa->offset = NormalFuncs[TYPE_IDX(aa->array->Type)];
1121      check_vbo(actx, aa->array->BufferObj);
1122      aa++;
1123   }
1124   if (arrayObj->Color.Enabled) {
1125      aa->array = &arrayObj->Color;
1126      aa->offset = ColorFuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
1127      check_vbo(actx, aa->array->BufferObj);
1128      aa++;
1129   }
1130   if (arrayObj->SecondaryColor.Enabled) {
1131      aa->array = &arrayObj->SecondaryColor;
1132      aa->offset = SecondaryColorFuncs[TYPE_IDX(aa->array->Type)];
1133      check_vbo(actx, aa->array->BufferObj);
1134      aa++;
1135   }
1136   if (arrayObj->FogCoord.Enabled) {
1137      aa->array = &arrayObj->FogCoord;
1138      aa->offset = FogCoordFuncs[TYPE_IDX(aa->array->Type)];
1139      check_vbo(actx, aa->array->BufferObj);
1140      aa++;
1141   }
1142   for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
1143      struct gl_client_array *attribArray = &arrayObj->TexCoord[i];
1144      if (attribArray->Enabled) {
1145         /* NOTE: we use generic glVertexAttribNV functions here.
1146          * If we ever remove GL_NV_vertex_program this will have to change.
1147          */
1148         at->array = attribArray;
1149         ASSERT(!at->array->Normalized);
1150         at->func = AttribFuncsNV[at->array->Normalized]
1151                                 [at->array->Size-1]
1152                                 [TYPE_IDX(at->array->Type)];
1153         at->index = VERT_ATTRIB_TEX0 + i;
1154	 check_vbo(actx, at->array->BufferObj);
1155         at++;
1156      }
1157   }
1158
1159   /* generic vertex attribute arrays */
1160   for (i = 1; i < Elements(arrayObj->VertexAttrib); i++) {  /* skip zero! */
1161      struct gl_client_array *attribArray = &arrayObj->VertexAttrib[i];
1162      if (attribArray->Enabled) {
1163         at->array = attribArray;
1164         /* Note: we can't grab the _glapi_Dispatch->VertexAttrib1fvNV
1165          * function pointer here (for float arrays) since the pointer may
1166          * change from one execution of _ae_ArrayElement() to
1167          * the next.  Doing so caused UT to break.
1168          */
1169         if (ctx->VertexProgram._Enabled
1170             && ctx->VertexProgram.Current->IsNVProgram) {
1171            at->func = AttribFuncsNV[at->array->Normalized]
1172                                    [at->array->Size-1]
1173                                    [TYPE_IDX(at->array->Type)];
1174         }
1175         else {
1176            at->func = AttribFuncsARB[at->array->Normalized]
1177                                     [at->array->Size-1]
1178                                     [TYPE_IDX(at->array->Type)];
1179         }
1180         at->index = i;
1181	 check_vbo(actx, at->array->BufferObj);
1182         at++;
1183      }
1184   }
1185
1186   /* finally, vertex position */
1187   if (arrayObj->VertexAttrib[0].Enabled) {
1188      /* Use glVertex(v) instead of glVertexAttrib(0, v) to be sure it's
1189       * issued as the last (provoking) attribute).
1190       */
1191      aa->array = &arrayObj->VertexAttrib[0];
1192      assert(aa->array->Size >= 2); /* XXX fix someday? */
1193      aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
1194      check_vbo(actx, aa->array->BufferObj);
1195      aa++;
1196   }
1197   else if (arrayObj->Vertex.Enabled) {
1198      aa->array = &arrayObj->Vertex;
1199      aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
1200      check_vbo(actx, aa->array->BufferObj);
1201      aa++;
1202   }
1203
1204   check_vbo(actx, ctx->Array.ElementArrayBufferObj);
1205
1206   ASSERT(at - actx->attribs <= VERT_ATTRIB_MAX);
1207   ASSERT(aa - actx->arrays < 32);
1208   at->func = NULL;  /* terminate the list */
1209   aa->offset = -1;  /* terminate the list */
1210
1211   actx->NewState = 0;
1212}
1213
1214void _ae_map_vbos( GLcontext *ctx )
1215{
1216   AEcontext *actx = AE_CONTEXT(ctx);
1217   GLuint i;
1218
1219   if (actx->mapped_vbos)
1220      return;
1221
1222   if (actx->NewState)
1223      _ae_update_state(ctx);
1224
1225   for (i = 0; i < actx->nr_vbos; i++)
1226      ctx->Driver.MapBuffer(ctx,
1227			    GL_ARRAY_BUFFER_ARB,
1228			    GL_DYNAMIC_DRAW_ARB,
1229			    actx->vbo[i]);
1230
1231   if (actx->nr_vbos)
1232      actx->mapped_vbos = GL_TRUE;
1233}
1234
1235void _ae_unmap_vbos( GLcontext *ctx )
1236{
1237   AEcontext *actx = AE_CONTEXT(ctx);
1238   GLuint i;
1239
1240   if (!actx->mapped_vbos)
1241      return;
1242
1243   assert (!actx->NewState);
1244
1245   for (i = 0; i < actx->nr_vbos; i++)
1246      ctx->Driver.UnmapBuffer(ctx,
1247			      GL_ARRAY_BUFFER_ARB,
1248			      actx->vbo[i]);
1249
1250   actx->mapped_vbos = GL_FALSE;
1251}
1252
1253
1254/**
1255 * Called via glArrayElement() and glDrawArrays().
1256 * Issue the glNormal, glVertex, glColor, glVertexAttrib, etc functions
1257 * for all enabled vertex arrays (for elt-th element).
1258 * Note: this may be called during display list construction.
1259 */
1260void GLAPIENTRY _ae_ArrayElement( GLint elt )
1261{
1262   GET_CURRENT_CONTEXT(ctx);
1263   const AEcontext *actx = AE_CONTEXT(ctx);
1264   const AEarray *aa;
1265   const AEattrib *at;
1266   const struct _glapi_table * const disp = GET_DISPATCH();
1267   GLboolean do_map;
1268
1269   if (actx->NewState) {
1270      assert(!actx->mapped_vbos);
1271      _ae_update_state( ctx );
1272   }
1273
1274   do_map = actx->nr_vbos && !actx->mapped_vbos;
1275
1276   /*
1277    */
1278   if (do_map)
1279      _ae_map_vbos(ctx);
1280
1281   /* generic attributes */
1282   for (at = actx->attribs; at->func; at++) {
1283      const GLubyte *src
1284         = ADD_POINTERS(at->array->BufferObj->Pointer, at->array->Ptr)
1285         + elt * at->array->StrideB;
1286      at->func( at->index, src );
1287   }
1288
1289   /* conventional arrays */
1290   for (aa = actx->arrays; aa->offset != -1 ; aa++) {
1291      const GLubyte *src
1292         = ADD_POINTERS(aa->array->BufferObj->Pointer, aa->array->Ptr)
1293         + elt * aa->array->StrideB;
1294      CALL_by_offset( disp, (array_func), aa->offset,
1295		      ((const void *) src) );
1296   }
1297
1298   if (do_map)
1299      _ae_unmap_vbos(ctx);
1300}
1301
1302
1303void _ae_invalidate_state( GLcontext *ctx, GLuint new_state )
1304{
1305   AEcontext *actx = AE_CONTEXT(ctx);
1306
1307
1308   /* Only interested in this subset of mesa state.  Need to prune
1309    * this down as both tnl/ and the drivers can raise statechanges
1310    * for arcane reasons in the middle of seemingly atomic operations
1311    * like DrawElements, over which we'd like to keep a known set of
1312    * arrays and vbo's mapped.
1313    *
1314    * Luckily, neither the drivers nor tnl muck with the state that
1315    * concerns us here:
1316    */
1317   new_state &= _NEW_ARRAY | _NEW_PROGRAM;
1318   if (new_state) {
1319      assert(!actx->mapped_vbos);
1320      actx->NewState |= new_state;
1321   }
1322}
1323
1324
1325void _mesa_install_arrayelt_vtxfmt(struct _glapi_table *disp,
1326                                   const GLvertexformat *vfmt)
1327{
1328   SET_ArrayElement(disp, vfmt->ArrayElement);
1329}
1330
1331
1332#endif /* FEATURE_arrayelt */
1333