OSDN Git Service

8e581c8d9c6806e673d8cc3983f387c3ebe394b5
[android-x86/external-mesa.git] / src / mesa / main / api_arrayelt.c
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  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  * OTHER DEALINGS IN THE SOFTWARE.
24  */
25
26 /**
27  * This file implements the glArrayElement() function.
28  * It involves looking at the format/type of all the enabled vertex arrays
29  * and emitting a list of pointers to functions which set the per-vertex
30  * state for the element/index.
31  */
32
33
34 /* Author:
35  *    Keith Whitwell <keith@tungstengraphics.com>
36  */
37
38 #include "glheader.h"
39 #include "api_arrayelt.h"
40 #include "bufferobj.h"
41 #include "context.h"
42 #include "imports.h"
43 #include "macros.h"
44 #include "mtypes.h"
45 #include "main/dispatch.h"
46
47 typedef void (GLAPIENTRY *array_func)( const void * );
48
49 typedef struct {
50    const struct gl_client_array *array;
51    int offset;
52 } AEarray;
53
54 typedef void (GLAPIENTRY *attrib_func)( GLuint indx, const void *data );
55
56 typedef struct {
57    const struct gl_client_array *array;
58    attrib_func func;
59    GLuint index;
60 } AEattrib;
61
62 typedef struct {
63    AEarray arrays[32];
64    AEattrib attribs[VERT_ATTRIB_MAX + 1];
65    GLuint NewState;
66
67    /* List of VBOs we need to map before executing ArrayElements */
68    struct gl_buffer_object *vbo[VERT_ATTRIB_MAX];
69    GLuint nr_vbos;
70    GLboolean mapped_vbos;  /**< Any currently mapped VBOs? */
71 } AEcontext;
72
73
74 /** Cast wrapper */
75 static INLINE AEcontext *
76 AE_CONTEXT(struct gl_context *ctx)
77 {
78    return (AEcontext *) ctx->aelt_context;
79 }
80
81
82 /*
83  * Convert GL_BYTE, GL_UNSIGNED_BYTE, .. GL_DOUBLE into an integer
84  * in the range [0, 7].  Luckily these type tokens are sequentially
85  * numbered in gl.h, except for GL_DOUBLE.
86  */
87 static INLINE int
88 TYPE_IDX(GLenum t)
89 {
90    return t == GL_DOUBLE ? 7 : t & 7;
91 }
92
93
94 #define NUM_TYPES 8
95
96
97 static const int ColorFuncs[2][NUM_TYPES] = {
98    {
99       _gloffset_Color3bv,
100       _gloffset_Color3ubv,
101       _gloffset_Color3sv,
102       _gloffset_Color3usv,
103       _gloffset_Color3iv,
104       _gloffset_Color3uiv,
105       _gloffset_Color3fv,
106       _gloffset_Color3dv,
107    },
108    {
109       _gloffset_Color4bv,
110       _gloffset_Color4ubv,
111       _gloffset_Color4sv,
112       _gloffset_Color4usv,
113       _gloffset_Color4iv,
114       _gloffset_Color4uiv,
115       _gloffset_Color4fv,
116       _gloffset_Color4dv,
117    },
118 };
119
120 static const int VertexFuncs[3][NUM_TYPES] = {
121    {
122       -1,
123       -1,
124       _gloffset_Vertex2sv,
125       -1,
126       _gloffset_Vertex2iv,
127       -1,
128       _gloffset_Vertex2fv,
129       _gloffset_Vertex2dv,
130    },
131    {
132       -1,
133       -1,
134       _gloffset_Vertex3sv,
135       -1,
136       _gloffset_Vertex3iv,
137       -1,
138       _gloffset_Vertex3fv,
139       _gloffset_Vertex3dv,
140    },
141    {
142       -1,
143       -1,
144       _gloffset_Vertex4sv,
145       -1,
146       _gloffset_Vertex4iv,
147       -1,
148       _gloffset_Vertex4fv,
149       _gloffset_Vertex4dv,
150    },
151 };
152
153 static const int IndexFuncs[NUM_TYPES] = {
154    -1,
155    _gloffset_Indexubv,
156    _gloffset_Indexsv,
157    -1,
158    _gloffset_Indexiv,
159    -1,
160    _gloffset_Indexfv,
161    _gloffset_Indexdv,
162 };
163
164 static const int NormalFuncs[NUM_TYPES] = {
165    _gloffset_Normal3bv,
166    -1,
167    _gloffset_Normal3sv,
168    -1,
169    _gloffset_Normal3iv,
170    -1,
171    _gloffset_Normal3fv,
172    _gloffset_Normal3dv,
173 };
174
175 /* Note: _gloffset_* for these may not be a compile-time constant. */
176 static int SecondaryColorFuncs[NUM_TYPES];
177 static int FogCoordFuncs[NUM_TYPES];
178
179
180 /**
181  ** GL_NV_vertex_program
182  **/
183
184 /* GL_BYTE attributes */
185
186 static void GLAPIENTRY
187 VertexAttrib1NbvNV(GLuint index, const GLbyte *v)
188 {
189    CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0])));
190 }
191
192 static void GLAPIENTRY
193 VertexAttrib1bvNV(GLuint index, const GLbyte *v)
194 {
195    CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
196 }
197
198 static void GLAPIENTRY
199 VertexAttrib2NbvNV(GLuint index, const GLbyte *v)
200 {
201    CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]), BYTE_TO_FLOAT(v[1])));
202 }
203
204 static void GLAPIENTRY
205 VertexAttrib2bvNV(GLuint index, const GLbyte *v)
206 {
207    CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
208 }
209
210 static void GLAPIENTRY
211 VertexAttrib3NbvNV(GLuint index, const GLbyte *v)
212 {
213    CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
214                                                BYTE_TO_FLOAT(v[1]),
215                                                BYTE_TO_FLOAT(v[2])));
216 }
217
218 static void GLAPIENTRY
219 VertexAttrib3bvNV(GLuint index, const GLbyte *v)
220 {
221    CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
222 }
223
224 static void GLAPIENTRY
225 VertexAttrib4NbvNV(GLuint index, const GLbyte *v)
226 {
227    CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
228                                                BYTE_TO_FLOAT(v[1]),
229                                                BYTE_TO_FLOAT(v[2]),
230                                                BYTE_TO_FLOAT(v[3])));
231 }
232
233 static void GLAPIENTRY
234 VertexAttrib4bvNV(GLuint index, const GLbyte *v)
235 {
236    CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
237 }
238
239 /* GL_UNSIGNED_BYTE attributes */
240
241 static void GLAPIENTRY
242 VertexAttrib1NubvNV(GLuint index, const GLubyte *v)
243 {
244    CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0])));
245 }
246
247 static void GLAPIENTRY
248 VertexAttrib1ubvNV(GLuint index, const GLubyte *v)
249 {
250    CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
251 }
252
253 static void GLAPIENTRY
254 VertexAttrib2NubvNV(GLuint index, const GLubyte *v)
255 {
256    CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
257                                           UBYTE_TO_FLOAT(v[1])));
258 }
259
260 static void GLAPIENTRY
261 VertexAttrib2ubvNV(GLuint index, const GLubyte *v)
262 {
263    CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
264 }
265
266 static void GLAPIENTRY
267 VertexAttrib3NubvNV(GLuint index, const GLubyte *v)
268 {
269    CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
270                                                UBYTE_TO_FLOAT(v[1]),
271                                                UBYTE_TO_FLOAT(v[2])));
272 }
273 static void GLAPIENTRY
274 VertexAttrib3ubvNV(GLuint index, const GLubyte *v)
275 {
276    CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0],
277                                           (GLfloat)v[1], (GLfloat)v[2]));
278 }
279
280 static void GLAPIENTRY
281 VertexAttrib4NubvNV(GLuint index, const GLubyte *v)
282 {
283    CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
284                                           UBYTE_TO_FLOAT(v[1]),
285                                           UBYTE_TO_FLOAT(v[2]),
286                                           UBYTE_TO_FLOAT(v[3])));
287 }
288
289 static void GLAPIENTRY
290 VertexAttrib4ubvNV(GLuint index, const GLubyte *v)
291 {
292    CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0],
293                                           (GLfloat)v[1], (GLfloat)v[2],
294                                           (GLfloat)v[3]));
295 }
296
297 /* GL_SHORT attributes */
298
299 static void GLAPIENTRY
300 VertexAttrib1NsvNV(GLuint index, const GLshort *v)
301 {
302    CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0])));
303 }
304
305 static void GLAPIENTRY
306 VertexAttrib1svNV(GLuint index, const GLshort *v)
307 {
308    CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
309 }
310
311 static void GLAPIENTRY
312 VertexAttrib2NsvNV(GLuint index, const GLshort *v)
313 {
314    CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
315                                           SHORT_TO_FLOAT(v[1])));
316 }
317
318 static void GLAPIENTRY
319 VertexAttrib2svNV(GLuint index, const GLshort *v)
320 {
321    CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
322 }
323
324 static void GLAPIENTRY
325 VertexAttrib3NsvNV(GLuint index, const GLshort *v)
326 {
327    CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
328                              SHORT_TO_FLOAT(v[1]),
329                              SHORT_TO_FLOAT(v[2])));
330 }
331
332 static void GLAPIENTRY
333 VertexAttrib3svNV(GLuint index, const GLshort *v)
334 {
335    CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1],
336                                           (GLfloat)v[2]));
337 }
338
339 static void GLAPIENTRY
340 VertexAttrib4NsvNV(GLuint index, const GLshort *v)
341 {
342    CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
343                              SHORT_TO_FLOAT(v[1]),
344                              SHORT_TO_FLOAT(v[2]),
345                              SHORT_TO_FLOAT(v[3])));
346 }
347
348 static void GLAPIENTRY
349 VertexAttrib4svNV(GLuint index, const GLshort *v)
350 {
351    CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1],
352                                           (GLfloat)v[2], (GLfloat)v[3]));
353 }
354
355 /* GL_UNSIGNED_SHORT attributes */
356
357 static void GLAPIENTRY
358 VertexAttrib1NusvNV(GLuint index, const GLushort *v)
359 {
360    CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0])));
361 }
362
363 static void GLAPIENTRY
364 VertexAttrib1usvNV(GLuint index, const GLushort *v)
365 {
366    CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
367 }
368
369 static void GLAPIENTRY
370 VertexAttrib2NusvNV(GLuint index, const GLushort *v)
371 {
372    CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
373                              USHORT_TO_FLOAT(v[1])));
374 }
375
376 static void GLAPIENTRY
377 VertexAttrib2usvNV(GLuint index, const GLushort *v)
378 {
379    CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0],
380                                           (GLfloat)v[1]));
381 }
382
383 static void GLAPIENTRY
384 VertexAttrib3NusvNV(GLuint index, const GLushort *v)
385 {
386    CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
387                                                USHORT_TO_FLOAT(v[1]),
388                                                USHORT_TO_FLOAT(v[2])));
389 }
390
391 static void GLAPIENTRY
392 VertexAttrib3usvNV(GLuint index, const GLushort *v)
393 {
394    CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1],
395                                           (GLfloat)v[2]));
396 }
397
398 static void GLAPIENTRY
399 VertexAttrib4NusvNV(GLuint index, const GLushort *v)
400 {
401    CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
402                                                USHORT_TO_FLOAT(v[1]),
403                                                USHORT_TO_FLOAT(v[2]),
404                                                USHORT_TO_FLOAT(v[3])));
405 }
406
407 static void GLAPIENTRY
408 VertexAttrib4usvNV(GLuint index, const GLushort *v)
409 {
410    CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1],
411                                           (GLfloat)v[2], (GLfloat)v[3]));
412 }
413
414 /* GL_INT attributes */
415
416 static void GLAPIENTRY
417 VertexAttrib1NivNV(GLuint index, const GLint *v)
418 {
419    CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0])));
420 }
421
422 static void GLAPIENTRY
423 VertexAttrib1ivNV(GLuint index, const GLint *v)
424 {
425    CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
426 }
427
428 static void GLAPIENTRY
429 VertexAttrib2NivNV(GLuint index, const GLint *v)
430 {
431    CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
432                                                INT_TO_FLOAT(v[1])));
433 }
434
435 static void GLAPIENTRY
436 VertexAttrib2ivNV(GLuint index, const GLint *v)
437 {
438    CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
439 }
440
441 static void GLAPIENTRY
442 VertexAttrib3NivNV(GLuint index, const GLint *v)
443 {
444    CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
445                                                INT_TO_FLOAT(v[1]),
446                                                INT_TO_FLOAT(v[2])));
447 }
448
449 static void GLAPIENTRY
450 VertexAttrib3ivNV(GLuint index, const GLint *v)
451 {
452    CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1],
453                                           (GLfloat)v[2]));
454 }
455
456 static void GLAPIENTRY
457 VertexAttrib4NivNV(GLuint index, const GLint *v)
458 {
459    CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
460                                           INT_TO_FLOAT(v[1]),
461                                           INT_TO_FLOAT(v[2]),
462                                           INT_TO_FLOAT(v[3])));
463 }
464
465 static void GLAPIENTRY
466 VertexAttrib4ivNV(GLuint index, const GLint *v)
467 {
468    CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1],
469                                           (GLfloat)v[2], (GLfloat)v[3]));
470 }
471
472 /* GL_UNSIGNED_INT attributes */
473
474 static void GLAPIENTRY
475 VertexAttrib1NuivNV(GLuint index, const GLuint *v)
476 {
477    CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0])));
478 }
479
480 static void GLAPIENTRY
481 VertexAttrib1uivNV(GLuint index, const GLuint *v)
482 {
483    CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0]));
484 }
485
486 static void GLAPIENTRY
487 VertexAttrib2NuivNV(GLuint index, const GLuint *v)
488 {
489    CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
490                                           UINT_TO_FLOAT(v[1])));
491 }
492
493 static void GLAPIENTRY
494 VertexAttrib2uivNV(GLuint index, const GLuint *v)
495 {
496    CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0],
497                                           (GLfloat)v[1]));
498 }
499
500 static void GLAPIENTRY
501 VertexAttrib3NuivNV(GLuint index, const GLuint *v)
502 {
503    CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
504                                                UINT_TO_FLOAT(v[1]),
505                                                UINT_TO_FLOAT(v[2])));
506 }
507
508 static void GLAPIENTRY
509 VertexAttrib3uivNV(GLuint index, const GLuint *v)
510 {
511    CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1],
512                                           (GLfloat)v[2]));
513 }
514
515 static void GLAPIENTRY
516 VertexAttrib4NuivNV(GLuint index, const GLuint *v)
517 {
518    CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
519                                                UINT_TO_FLOAT(v[1]),
520                                                UINT_TO_FLOAT(v[2]),
521                                                UINT_TO_FLOAT(v[3])));
522 }
523
524 static void GLAPIENTRY
525 VertexAttrib4uivNV(GLuint index, const GLuint *v)
526 {
527    CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1],
528                                           (GLfloat)v[2], (GLfloat)v[3]));
529 }
530
531 /* GL_FLOAT attributes */
532
533 static void GLAPIENTRY
534 VertexAttrib1fvNV(GLuint index, const GLfloat *v)
535 {
536    CALL_VertexAttrib1fvNV(GET_DISPATCH(), (index, v));
537 }
538
539 static void GLAPIENTRY
540 VertexAttrib2fvNV(GLuint index, const GLfloat *v)
541 {
542    CALL_VertexAttrib2fvNV(GET_DISPATCH(), (index, v));
543 }
544
545 static void GLAPIENTRY
546 VertexAttrib3fvNV(GLuint index, const GLfloat *v)
547 {
548    CALL_VertexAttrib3fvNV(GET_DISPATCH(), (index, v));
549 }
550
551 static void GLAPIENTRY
552 VertexAttrib4fvNV(GLuint index, const GLfloat *v)
553 {
554    CALL_VertexAttrib4fvNV(GET_DISPATCH(), (index, v));
555 }
556
557 /* GL_DOUBLE attributes */
558
559 static void GLAPIENTRY
560 VertexAttrib1dvNV(GLuint index, const GLdouble *v)
561 {
562    CALL_VertexAttrib1dvNV(GET_DISPATCH(), (index, v));
563 }
564
565 static void GLAPIENTRY
566 VertexAttrib2dvNV(GLuint index, const GLdouble *v)
567 {
568    CALL_VertexAttrib2dvNV(GET_DISPATCH(), (index, v));
569 }
570
571 static void GLAPIENTRY
572 VertexAttrib3dvNV(GLuint index, const GLdouble *v)
573 {
574    CALL_VertexAttrib3dvNV(GET_DISPATCH(), (index, v));
575 }
576
577 static void GLAPIENTRY
578 VertexAttrib4dvNV(GLuint index, const GLdouble *v)
579 {
580    CALL_VertexAttrib4dvNV(GET_DISPATCH(), (index, v));
581 }
582
583
584 /*
585  * Array [size][type] of VertexAttrib functions
586  */
587 static attrib_func AttribFuncsNV[2][4][NUM_TYPES] = {
588    {
589       /* non-normalized */
590       {
591          /* size 1 */
592          (attrib_func) VertexAttrib1bvNV,
593          (attrib_func) VertexAttrib1ubvNV,
594          (attrib_func) VertexAttrib1svNV,
595          (attrib_func) VertexAttrib1usvNV,
596          (attrib_func) VertexAttrib1ivNV,
597          (attrib_func) VertexAttrib1uivNV,
598          (attrib_func) VertexAttrib1fvNV,
599          (attrib_func) VertexAttrib1dvNV
600       },
601       {
602          /* size 2 */
603          (attrib_func) VertexAttrib2bvNV,
604          (attrib_func) VertexAttrib2ubvNV,
605          (attrib_func) VertexAttrib2svNV,
606          (attrib_func) VertexAttrib2usvNV,
607          (attrib_func) VertexAttrib2ivNV,
608          (attrib_func) VertexAttrib2uivNV,
609          (attrib_func) VertexAttrib2fvNV,
610          (attrib_func) VertexAttrib2dvNV
611       },
612       {
613          /* size 3 */
614          (attrib_func) VertexAttrib3bvNV,
615          (attrib_func) VertexAttrib3ubvNV,
616          (attrib_func) VertexAttrib3svNV,
617          (attrib_func) VertexAttrib3usvNV,
618          (attrib_func) VertexAttrib3ivNV,
619          (attrib_func) VertexAttrib3uivNV,
620          (attrib_func) VertexAttrib3fvNV,
621          (attrib_func) VertexAttrib3dvNV
622       },
623       {
624          /* size 4 */
625          (attrib_func) VertexAttrib4bvNV,
626          (attrib_func) VertexAttrib4ubvNV,
627          (attrib_func) VertexAttrib4svNV,
628          (attrib_func) VertexAttrib4usvNV,
629          (attrib_func) VertexAttrib4ivNV,
630          (attrib_func) VertexAttrib4uivNV,
631          (attrib_func) VertexAttrib4fvNV,
632          (attrib_func) VertexAttrib4dvNV
633       }
634    },
635    {
636       /* normalized (except for float/double) */
637       {
638          /* size 1 */
639          (attrib_func) VertexAttrib1NbvNV,
640          (attrib_func) VertexAttrib1NubvNV,
641          (attrib_func) VertexAttrib1NsvNV,
642          (attrib_func) VertexAttrib1NusvNV,
643          (attrib_func) VertexAttrib1NivNV,
644          (attrib_func) VertexAttrib1NuivNV,
645          (attrib_func) VertexAttrib1fvNV,
646          (attrib_func) VertexAttrib1dvNV
647       },
648       {
649          /* size 2 */
650          (attrib_func) VertexAttrib2NbvNV,
651          (attrib_func) VertexAttrib2NubvNV,
652          (attrib_func) VertexAttrib2NsvNV,
653          (attrib_func) VertexAttrib2NusvNV,
654          (attrib_func) VertexAttrib2NivNV,
655          (attrib_func) VertexAttrib2NuivNV,
656          (attrib_func) VertexAttrib2fvNV,
657          (attrib_func) VertexAttrib2dvNV
658       },
659       {
660          /* size 3 */
661          (attrib_func) VertexAttrib3NbvNV,
662          (attrib_func) VertexAttrib3NubvNV,
663          (attrib_func) VertexAttrib3NsvNV,
664          (attrib_func) VertexAttrib3NusvNV,
665          (attrib_func) VertexAttrib3NivNV,
666          (attrib_func) VertexAttrib3NuivNV,
667          (attrib_func) VertexAttrib3fvNV,
668          (attrib_func) VertexAttrib3dvNV
669       },
670       {
671          /* size 4 */
672          (attrib_func) VertexAttrib4NbvNV,
673          (attrib_func) VertexAttrib4NubvNV,
674          (attrib_func) VertexAttrib4NsvNV,
675          (attrib_func) VertexAttrib4NusvNV,
676          (attrib_func) VertexAttrib4NivNV,
677          (attrib_func) VertexAttrib4NuivNV,
678          (attrib_func) VertexAttrib4fvNV,
679          (attrib_func) VertexAttrib4dvNV
680       }
681    }
682 };
683
684
685 /**
686  ** GL_ARB_vertex_program
687  **/
688
689 /* GL_BYTE attributes */
690
691 static void GLAPIENTRY
692 VertexAttrib1NbvARB(GLuint index, const GLbyte *v)
693 {
694    CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0])));
695 }
696
697 static void GLAPIENTRY
698 VertexAttrib1bvARB(GLuint index, const GLbyte *v)
699 {
700    CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
701 }
702
703 static void GLAPIENTRY
704 VertexAttrib2NbvARB(GLuint index, const GLbyte *v)
705 {
706    CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]), BYTE_TO_FLOAT(v[1])));
707 }
708
709 static void GLAPIENTRY
710 VertexAttrib2bvARB(GLuint index, const GLbyte *v)
711 {
712    CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1]));
713 }
714
715 static void GLAPIENTRY
716 VertexAttrib3NbvARB(GLuint index, const GLbyte *v)
717 {
718    CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
719                                                BYTE_TO_FLOAT(v[1]),
720                                                BYTE_TO_FLOAT(v[2])));
721 }
722
723 static void GLAPIENTRY
724 VertexAttrib3bvARB(GLuint index, const GLbyte *v)
725 {
726    CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
727 }
728
729 static void GLAPIENTRY
730 VertexAttrib4NbvARB(GLuint index, const GLbyte *v)
731 {
732    CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
733                                                BYTE_TO_FLOAT(v[1]),
734                                                BYTE_TO_FLOAT(v[2]),
735                                                BYTE_TO_FLOAT(v[3])));
736 }
737
738 static void GLAPIENTRY
739 VertexAttrib4bvARB(GLuint index, const GLbyte *v)
740 {
741    CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
742 }
743
744 /* GL_UNSIGNED_BYTE attributes */
745
746 static void GLAPIENTRY
747 VertexAttrib1NubvARB(GLuint index, const GLubyte *v)
748 {
749    CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0])));
750 }
751
752 static void GLAPIENTRY
753 VertexAttrib1ubvARB(GLuint index, const GLubyte *v)
754 {
755    CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
756 }
757
758 static void GLAPIENTRY
759 VertexAttrib2NubvARB(GLuint index, const GLubyte *v)
760 {
761    CALL_VertexAttrib2fARB(GET_DISPATCH(), (index,
762                                            UBYTE_TO_FLOAT(v[0]),
763                                            UBYTE_TO_FLOAT(v[1])));
764 }
765
766 static void GLAPIENTRY
767 VertexAttrib2ubvARB(GLuint index, const GLubyte *v)
768 {
769    CALL_VertexAttrib2fARB(GET_DISPATCH(), (index,
770                                            (GLfloat)v[0], (GLfloat)v[1]));
771 }
772
773 static void GLAPIENTRY
774 VertexAttrib3NubvARB(GLuint index, const GLubyte *v)
775 {
776    CALL_VertexAttrib3fARB(GET_DISPATCH(), (index,
777                                            UBYTE_TO_FLOAT(v[0]),
778                                            UBYTE_TO_FLOAT(v[1]),
779                                            UBYTE_TO_FLOAT(v[2])));
780 }
781 static void GLAPIENTRY
782 VertexAttrib3ubvARB(GLuint index, const GLubyte *v)
783 {
784    CALL_VertexAttrib3fARB(GET_DISPATCH(), (index,
785                                            (GLfloat)v[0],
786                                            (GLfloat)v[1],
787                                            (GLfloat)v[2]));
788 }
789
790 static void GLAPIENTRY
791 VertexAttrib4NubvARB(GLuint index, const GLubyte *v)
792 {
793    CALL_VertexAttrib4fARB(GET_DISPATCH(),
794                           (index,
795                            UBYTE_TO_FLOAT(v[0]),
796                            UBYTE_TO_FLOAT(v[1]),
797                            UBYTE_TO_FLOAT(v[2]),
798                            UBYTE_TO_FLOAT(v[3])));
799 }
800
801 static void GLAPIENTRY
802 VertexAttrib4ubvARB(GLuint index, const GLubyte *v)
803 {
804    CALL_VertexAttrib4fARB(GET_DISPATCH(),
805                           (index,
806                            (GLfloat)v[0], (GLfloat)v[1],
807                            (GLfloat)v[2], (GLfloat)v[3]));
808 }
809
810 /* GL_SHORT attributes */
811
812 static void GLAPIENTRY
813 VertexAttrib1NsvARB(GLuint index, const GLshort *v)
814 {
815    CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0])));
816 }
817
818 static void GLAPIENTRY
819 VertexAttrib1svARB(GLuint index, const GLshort *v)
820 {
821    CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
822 }
823
824 static void GLAPIENTRY
825 VertexAttrib2NsvARB(GLuint index, const GLshort *v)
826 {
827    CALL_VertexAttrib2fARB(GET_DISPATCH(),
828                           (index, SHORT_TO_FLOAT(v[0]),
829                            SHORT_TO_FLOAT(v[1])));
830 }
831
832 static void GLAPIENTRY
833 VertexAttrib2svARB(GLuint index, const GLshort *v)
834 {
835    CALL_VertexAttrib2fARB(GET_DISPATCH(),
836                           (index, (GLfloat)v[0], (GLfloat)v[1]));
837 }
838
839 static void GLAPIENTRY
840 VertexAttrib3NsvARB(GLuint index, const GLshort *v)
841 {
842    CALL_VertexAttrib3fARB(GET_DISPATCH(),
843                           (index,
844                            SHORT_TO_FLOAT(v[0]),
845                            SHORT_TO_FLOAT(v[1]),
846                            SHORT_TO_FLOAT(v[2])));
847 }
848
849 static void GLAPIENTRY
850 VertexAttrib3svARB(GLuint index, const GLshort *v)
851 {
852    CALL_VertexAttrib3fARB(GET_DISPATCH(),
853                           (index,
854                            (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2]));
855 }
856
857 static void GLAPIENTRY
858 VertexAttrib4NsvARB(GLuint index, const GLshort *v)
859 {
860    CALL_VertexAttrib4fARB(GET_DISPATCH(),
861                           (index,
862                            SHORT_TO_FLOAT(v[0]),
863                            SHORT_TO_FLOAT(v[1]),
864                            SHORT_TO_FLOAT(v[2]),
865                            SHORT_TO_FLOAT(v[3])));
866 }
867
868 static void GLAPIENTRY
869 VertexAttrib4svARB(GLuint index, const GLshort *v)
870 {
871    CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1],
872                                            (GLfloat)v[2], (GLfloat)v[3]));
873 }
874
875 /* GL_UNSIGNED_SHORT attributes */
876
877 static void GLAPIENTRY
878 VertexAttrib1NusvARB(GLuint index, const GLushort *v)
879 {
880    CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0])));
881 }
882
883 static void GLAPIENTRY
884 VertexAttrib1usvARB(GLuint index, const GLushort *v)
885 {
886    CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
887 }
888
889 static void GLAPIENTRY
890 VertexAttrib2NusvARB(GLuint index, const GLushort *v)
891 {
892    CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
893                              USHORT_TO_FLOAT(v[1])));
894 }
895
896 static void GLAPIENTRY
897 VertexAttrib2usvARB(GLuint index, const GLushort *v)
898 {
899    CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0],
900                                            (GLfloat)v[1]));
901 }
902
903 static void GLAPIENTRY
904 VertexAttrib3NusvARB(GLuint index, const GLushort *v)
905 {
906    CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
907                                                USHORT_TO_FLOAT(v[1]),
908                                                USHORT_TO_FLOAT(v[2])));
909 }
910
911 static void GLAPIENTRY
912 VertexAttrib3usvARB(GLuint index, const GLushort *v)
913 {
914    CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0],
915                                            (GLfloat)v[1], (GLfloat)v[2]));
916 }
917
918 static void GLAPIENTRY
919 VertexAttrib4NusvARB(GLuint index, const GLushort *v)
920 {
921    CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
922                                                USHORT_TO_FLOAT(v[1]),
923                                                USHORT_TO_FLOAT(v[2]),
924                                                USHORT_TO_FLOAT(v[3])));
925 }
926
927 static void GLAPIENTRY
928 VertexAttrib4usvARB(GLuint index, const GLushort *v)
929 {
930    CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3]));
931 }
932
933 /* GL_INT attributes */
934
935 static void GLAPIENTRY
936 VertexAttrib1NivARB(GLuint index, const GLint *v)
937 {
938    CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0])));
939 }
940
941 static void GLAPIENTRY
942 VertexAttrib1ivARB(GLuint index, const GLint *v)
943 {
944    CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
945 }
946
947 static void GLAPIENTRY
948 VertexAttrib2NivARB(GLuint index, const GLint *v)
949 {
950    CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
951                                                INT_TO_FLOAT(v[1])));
952 }
953
954 static void GLAPIENTRY
955 VertexAttrib2ivARB(GLuint index, const GLint *v)
956 {
957    CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0],
958                                            (GLfloat)v[1]));
959 }
960
961 static void GLAPIENTRY
962 VertexAttrib3NivARB(GLuint index, const GLint *v)
963 {
964    CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
965                                                INT_TO_FLOAT(v[1]),
966                                                INT_TO_FLOAT(v[2])));
967 }
968
969 static void GLAPIENTRY
970 VertexAttrib3ivARB(GLuint index, const GLint *v)
971 {
972    CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0],
973                                            (GLfloat)v[1], (GLfloat)v[2]));
974 }
975
976 static void GLAPIENTRY
977 VertexAttrib4NivARB(GLuint index, const GLint *v)
978 {
979    CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
980                                                INT_TO_FLOAT(v[1]),
981                                                INT_TO_FLOAT(v[2]),
982                                                INT_TO_FLOAT(v[3])));
983 }
984
985 static void GLAPIENTRY
986 VertexAttrib4ivARB(GLuint index, const GLint *v)
987 {
988    CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1],
989                                            (GLfloat)v[2], (GLfloat)v[3]));
990 }
991
992 /* GL_UNSIGNED_INT attributes */
993
994 static void GLAPIENTRY
995 VertexAttrib1NuivARB(GLuint index, const GLuint *v)
996 {
997    CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0])));
998 }
999
1000 static void GLAPIENTRY
1001 VertexAttrib1uivARB(GLuint index, const GLuint *v)
1002 {
1003    CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0]));
1004 }
1005
1006 static void GLAPIENTRY
1007 VertexAttrib2NuivARB(GLuint index, const GLuint *v)
1008 {
1009    CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
1010                                            UINT_TO_FLOAT(v[1])));
1011 }
1012
1013 static void GLAPIENTRY
1014 VertexAttrib2uivARB(GLuint index, const GLuint *v)
1015 {
1016    CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0],
1017                                            (GLfloat)v[1]));
1018 }
1019
1020 static void GLAPIENTRY
1021 VertexAttrib3NuivARB(GLuint index, const GLuint *v)
1022 {
1023    CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
1024                                            UINT_TO_FLOAT(v[1]),
1025                                            UINT_TO_FLOAT(v[2])));
1026 }
1027
1028 static void GLAPIENTRY
1029 VertexAttrib3uivARB(GLuint index, const GLuint *v)
1030 {
1031    CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0],
1032                                            (GLfloat)v[1], (GLfloat)v[2]));
1033 }
1034
1035 static void GLAPIENTRY
1036 VertexAttrib4NuivARB(GLuint index, const GLuint *v)
1037 {
1038    CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
1039                                            UINT_TO_FLOAT(v[1]),
1040                                            UINT_TO_FLOAT(v[2]),
1041                                            UINT_TO_FLOAT(v[3])));
1042 }
1043
1044 static void GLAPIENTRY
1045 VertexAttrib4uivARB(GLuint index, const GLuint *v)
1046 {
1047    CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1],
1048                                            (GLfloat)v[2], (GLfloat)v[3]));
1049 }
1050
1051 /* GL_FLOAT attributes */
1052
1053 static void GLAPIENTRY
1054 VertexAttrib1fvARB(GLuint index, const GLfloat *v)
1055 {
1056    CALL_VertexAttrib1fvARB(GET_DISPATCH(), (index, v));
1057 }
1058
1059 static void GLAPIENTRY
1060 VertexAttrib2fvARB(GLuint index, const GLfloat *v)
1061 {
1062    CALL_VertexAttrib2fvARB(GET_DISPATCH(), (index, v));
1063 }
1064
1065 static void GLAPIENTRY
1066 VertexAttrib3fvARB(GLuint index, const GLfloat *v)
1067 {
1068    CALL_VertexAttrib3fvARB(GET_DISPATCH(), (index, v));
1069 }
1070
1071 static void GLAPIENTRY
1072 VertexAttrib4fvARB(GLuint index, const GLfloat *v)
1073 {
1074    CALL_VertexAttrib4fvARB(GET_DISPATCH(), (index, v));
1075 }
1076
1077 /* GL_DOUBLE attributes */
1078
1079 static void GLAPIENTRY
1080 VertexAttrib1dvARB(GLuint index, const GLdouble *v)
1081 {
1082    CALL_VertexAttrib1dv(GET_DISPATCH(), (index, v));
1083 }
1084
1085 static void GLAPIENTRY
1086 VertexAttrib2dvARB(GLuint index, const GLdouble *v)
1087 {
1088    CALL_VertexAttrib2dv(GET_DISPATCH(), (index, v));
1089 }
1090
1091 static void GLAPIENTRY
1092 VertexAttrib3dvARB(GLuint index, const GLdouble *v)
1093 {
1094    CALL_VertexAttrib3dv(GET_DISPATCH(), (index, v));
1095 }
1096
1097 static void GLAPIENTRY
1098 VertexAttrib4dvARB(GLuint index, const GLdouble *v)
1099 {
1100    CALL_VertexAttrib4dv(GET_DISPATCH(), (index, v));
1101 }
1102
1103
1104 /**
1105  * Integer-valued attributes
1106  */
1107 static void GLAPIENTRY
1108 VertexAttribI1bv(GLuint index, const GLbyte *v)
1109 {
1110    CALL_VertexAttribI1iEXT(GET_DISPATCH(), (index, v[0]));
1111 }
1112
1113 static void GLAPIENTRY
1114 VertexAttribI2bv(GLuint index, const GLbyte *v)
1115 {
1116    CALL_VertexAttribI2iEXT(GET_DISPATCH(), (index, v[0], v[1]));
1117 }
1118
1119 static void GLAPIENTRY
1120 VertexAttribI3bv(GLuint index, const GLbyte *v)
1121 {
1122    CALL_VertexAttribI3iEXT(GET_DISPATCH(), (index, v[0], v[1], v[2]));
1123 }
1124
1125 static void GLAPIENTRY
1126 VertexAttribI4bv(GLuint index, const GLbyte *v)
1127 {
1128    CALL_VertexAttribI4bv(GET_DISPATCH(), (index, v));
1129 }
1130
1131
1132 static void GLAPIENTRY
1133 VertexAttribI1ubv(GLuint index, const GLubyte *v)
1134 {
1135    CALL_VertexAttribI1uiEXT(GET_DISPATCH(), (index, v[0]));
1136 }
1137
1138 static void GLAPIENTRY
1139 VertexAttribI2ubv(GLuint index, const GLubyte *v)
1140 {
1141    CALL_VertexAttribI2uiEXT(GET_DISPATCH(), (index, v[0], v[1]));
1142 }
1143
1144 static void GLAPIENTRY
1145 VertexAttribI3ubv(GLuint index, const GLubyte *v)
1146 {
1147    CALL_VertexAttribI3uiEXT(GET_DISPATCH(), (index, v[0], v[1], v[2]));
1148 }
1149
1150 static void GLAPIENTRY
1151 VertexAttribI4ubv(GLuint index, const GLubyte *v)
1152 {
1153    CALL_VertexAttribI4ubv(GET_DISPATCH(), (index, v));
1154 }
1155
1156
1157
1158 static void GLAPIENTRY
1159 VertexAttribI1sv(GLuint index, const GLshort *v)
1160 {
1161    CALL_VertexAttribI1iEXT(GET_DISPATCH(), (index, v[0]));
1162 }
1163
1164 static void GLAPIENTRY
1165 VertexAttribI2sv(GLuint index, const GLshort *v)
1166 {
1167    CALL_VertexAttribI2iEXT(GET_DISPATCH(), (index, v[0], v[1]));
1168 }
1169
1170 static void GLAPIENTRY
1171 VertexAttribI3sv(GLuint index, const GLshort *v)
1172 {
1173    CALL_VertexAttribI3iEXT(GET_DISPATCH(), (index, v[0], v[1], v[2]));
1174 }
1175
1176 static void GLAPIENTRY
1177 VertexAttribI4sv(GLuint index, const GLshort *v)
1178 {
1179    CALL_VertexAttribI4sv(GET_DISPATCH(), (index, v));
1180 }
1181
1182
1183 static void GLAPIENTRY
1184 VertexAttribI1usv(GLuint index, const GLushort *v)
1185 {
1186    CALL_VertexAttribI1uiEXT(GET_DISPATCH(), (index, v[0]));
1187 }
1188
1189 static void GLAPIENTRY
1190 VertexAttribI2usv(GLuint index, const GLushort *v)
1191 {
1192    CALL_VertexAttribI2uiEXT(GET_DISPATCH(), (index, v[0], v[1]));
1193 }
1194
1195 static void GLAPIENTRY
1196 VertexAttribI3usv(GLuint index, const GLushort *v)
1197 {
1198    CALL_VertexAttribI3uiEXT(GET_DISPATCH(), (index, v[0], v[1], v[2]));
1199 }
1200
1201 static void GLAPIENTRY
1202 VertexAttribI4usv(GLuint index, const GLushort *v)
1203 {
1204    CALL_VertexAttribI4usv(GET_DISPATCH(), (index, v));
1205 }
1206
1207
1208
1209 static void GLAPIENTRY
1210 VertexAttribI1iv(GLuint index, const GLint *v)
1211 {
1212    CALL_VertexAttribI1iEXT(GET_DISPATCH(), (index, v[0]));
1213 }
1214
1215 static void GLAPIENTRY
1216 VertexAttribI2iv(GLuint index, const GLint *v)
1217 {
1218    CALL_VertexAttribI2iEXT(GET_DISPATCH(), (index, v[0], v[1]));
1219 }
1220
1221 static void GLAPIENTRY
1222 VertexAttribI3iv(GLuint index, const GLint *v)
1223 {
1224    CALL_VertexAttribI3iEXT(GET_DISPATCH(), (index, v[0], v[1], v[2]));
1225 }
1226
1227 static void GLAPIENTRY
1228 VertexAttribI4iv(GLuint index, const GLint *v)
1229 {
1230    CALL_VertexAttribI4ivEXT(GET_DISPATCH(), (index, v));
1231 }
1232
1233
1234 static void GLAPIENTRY
1235 VertexAttribI1uiv(GLuint index, const GLuint *v)
1236 {
1237    CALL_VertexAttribI1uiEXT(GET_DISPATCH(), (index, v[0]));
1238 }
1239
1240 static void GLAPIENTRY
1241 VertexAttribI2uiv(GLuint index, const GLuint *v)
1242 {
1243    CALL_VertexAttribI2uiEXT(GET_DISPATCH(), (index, v[0], v[1]));
1244 }
1245
1246 static void GLAPIENTRY
1247 VertexAttribI3uiv(GLuint index, const GLuint *v)
1248 {
1249    CALL_VertexAttribI3uiEXT(GET_DISPATCH(), (index, v[0], v[1], v[2]));
1250 }
1251
1252 static void GLAPIENTRY
1253 VertexAttribI4uiv(GLuint index, const GLuint *v)
1254 {
1255    CALL_VertexAttribI4uivEXT(GET_DISPATCH(), (index, v));
1256 }
1257
1258
1259 /*
1260  * Array [unnormalized/normalized/integer][size][type] of VertexAttrib
1261  * functions
1262  */
1263 static attrib_func AttribFuncsARB[3][4][NUM_TYPES] = {
1264    {
1265       /* non-normalized */
1266       {
1267          /* size 1 */
1268          (attrib_func) VertexAttrib1bvARB,
1269          (attrib_func) VertexAttrib1ubvARB,
1270          (attrib_func) VertexAttrib1svARB,
1271          (attrib_func) VertexAttrib1usvARB,
1272          (attrib_func) VertexAttrib1ivARB,
1273          (attrib_func) VertexAttrib1uivARB,
1274          (attrib_func) VertexAttrib1fvARB,
1275          (attrib_func) VertexAttrib1dvARB
1276       },
1277       {
1278          /* size 2 */
1279          (attrib_func) VertexAttrib2bvARB,
1280          (attrib_func) VertexAttrib2ubvARB,
1281          (attrib_func) VertexAttrib2svARB,
1282          (attrib_func) VertexAttrib2usvARB,
1283          (attrib_func) VertexAttrib2ivARB,
1284          (attrib_func) VertexAttrib2uivARB,
1285          (attrib_func) VertexAttrib2fvARB,
1286          (attrib_func) VertexAttrib2dvARB
1287       },
1288       {
1289          /* size 3 */
1290          (attrib_func) VertexAttrib3bvARB,
1291          (attrib_func) VertexAttrib3ubvARB,
1292          (attrib_func) VertexAttrib3svARB,
1293          (attrib_func) VertexAttrib3usvARB,
1294          (attrib_func) VertexAttrib3ivARB,
1295          (attrib_func) VertexAttrib3uivARB,
1296          (attrib_func) VertexAttrib3fvARB,
1297          (attrib_func) VertexAttrib3dvARB
1298       },
1299       {
1300          /* size 4 */
1301          (attrib_func) VertexAttrib4bvARB,
1302          (attrib_func) VertexAttrib4ubvARB,
1303          (attrib_func) VertexAttrib4svARB,
1304          (attrib_func) VertexAttrib4usvARB,
1305          (attrib_func) VertexAttrib4ivARB,
1306          (attrib_func) VertexAttrib4uivARB,
1307          (attrib_func) VertexAttrib4fvARB,
1308          (attrib_func) VertexAttrib4dvARB
1309       }
1310    },
1311    {
1312       /* normalized (except for float/double) */
1313       {
1314          /* size 1 */
1315          (attrib_func) VertexAttrib1NbvARB,
1316          (attrib_func) VertexAttrib1NubvARB,
1317          (attrib_func) VertexAttrib1NsvARB,
1318          (attrib_func) VertexAttrib1NusvARB,
1319          (attrib_func) VertexAttrib1NivARB,
1320          (attrib_func) VertexAttrib1NuivARB,
1321          (attrib_func) VertexAttrib1fvARB,
1322          (attrib_func) VertexAttrib1dvARB
1323       },
1324       {
1325          /* size 2 */
1326          (attrib_func) VertexAttrib2NbvARB,
1327          (attrib_func) VertexAttrib2NubvARB,
1328          (attrib_func) VertexAttrib2NsvARB,
1329          (attrib_func) VertexAttrib2NusvARB,
1330          (attrib_func) VertexAttrib2NivARB,
1331          (attrib_func) VertexAttrib2NuivARB,
1332          (attrib_func) VertexAttrib2fvARB,
1333          (attrib_func) VertexAttrib2dvARB
1334       },
1335       {
1336          /* size 3 */
1337          (attrib_func) VertexAttrib3NbvARB,
1338          (attrib_func) VertexAttrib3NubvARB,
1339          (attrib_func) VertexAttrib3NsvARB,
1340          (attrib_func) VertexAttrib3NusvARB,
1341          (attrib_func) VertexAttrib3NivARB,
1342          (attrib_func) VertexAttrib3NuivARB,
1343          (attrib_func) VertexAttrib3fvARB,
1344          (attrib_func) VertexAttrib3dvARB
1345       },
1346       {
1347          /* size 4 */
1348          (attrib_func) VertexAttrib4NbvARB,
1349          (attrib_func) VertexAttrib4NubvARB,
1350          (attrib_func) VertexAttrib4NsvARB,
1351          (attrib_func) VertexAttrib4NusvARB,
1352          (attrib_func) VertexAttrib4NivARB,
1353          (attrib_func) VertexAttrib4NuivARB,
1354          (attrib_func) VertexAttrib4fvARB,
1355          (attrib_func) VertexAttrib4dvARB
1356       }
1357    },
1358
1359    {
1360       /* integer-valued */
1361       {
1362          /* size 1 */
1363          (attrib_func) VertexAttribI1bv,
1364          (attrib_func) VertexAttribI1ubv,
1365          (attrib_func) VertexAttribI1sv,
1366          (attrib_func) VertexAttribI1usv,
1367          (attrib_func) VertexAttribI1iv,
1368          (attrib_func) VertexAttribI1uiv,
1369          NULL, /* GL_FLOAT */
1370          NULL  /* GL_DOUBLE */
1371       },
1372       {
1373          /* size 2 */
1374          (attrib_func) VertexAttribI2bv,
1375          (attrib_func) VertexAttribI2ubv,
1376          (attrib_func) VertexAttribI2sv,
1377          (attrib_func) VertexAttribI2usv,
1378          (attrib_func) VertexAttribI2iv,
1379          (attrib_func) VertexAttribI2uiv,
1380          NULL, /* GL_FLOAT */
1381          NULL  /* GL_DOUBLE */
1382       },
1383       {
1384          /* size 3 */
1385          (attrib_func) VertexAttribI3bv,
1386          (attrib_func) VertexAttribI3ubv,
1387          (attrib_func) VertexAttribI3sv,
1388          (attrib_func) VertexAttribI3usv,
1389          (attrib_func) VertexAttribI3iv,
1390          (attrib_func) VertexAttribI3uiv,
1391          NULL, /* GL_FLOAT */
1392          NULL  /* GL_DOUBLE */
1393       },
1394       {
1395          /* size 4 */
1396          (attrib_func) VertexAttribI4bv,
1397          (attrib_func) VertexAttribI4ubv,
1398          (attrib_func) VertexAttribI4sv,
1399          (attrib_func) VertexAttribI4usv,
1400          (attrib_func) VertexAttribI4iv,
1401          (attrib_func) VertexAttribI4uiv,
1402          NULL, /* GL_FLOAT */
1403          NULL  /* GL_DOUBLE */
1404       }
1405    }
1406 };
1407
1408
1409 GLboolean
1410 _ae_create_context(struct gl_context *ctx)
1411 {
1412    if (ctx->aelt_context)
1413       return GL_TRUE;
1414
1415    /* These _gloffset_* values may not be compile-time constants */
1416    SecondaryColorFuncs[0] = _gloffset_SecondaryColor3bv;
1417    SecondaryColorFuncs[1] = _gloffset_SecondaryColor3ubv;
1418    SecondaryColorFuncs[2] = _gloffset_SecondaryColor3sv;
1419    SecondaryColorFuncs[3] = _gloffset_SecondaryColor3usv;
1420    SecondaryColorFuncs[4] = _gloffset_SecondaryColor3iv;
1421    SecondaryColorFuncs[5] = _gloffset_SecondaryColor3uiv;
1422    SecondaryColorFuncs[6] = _gloffset_SecondaryColor3fvEXT;
1423    SecondaryColorFuncs[7] = _gloffset_SecondaryColor3dv;
1424
1425    FogCoordFuncs[0] = -1;
1426    FogCoordFuncs[1] = -1;
1427    FogCoordFuncs[2] = -1;
1428    FogCoordFuncs[3] = -1;
1429    FogCoordFuncs[4] = -1;
1430    FogCoordFuncs[5] = -1;
1431    FogCoordFuncs[6] = _gloffset_FogCoordfvEXT;
1432    FogCoordFuncs[7] = _gloffset_FogCoorddv;
1433
1434    ctx->aelt_context = calloc(1, sizeof(AEcontext));
1435    if (!ctx->aelt_context)
1436       return GL_FALSE;
1437
1438    AE_CONTEXT(ctx)->NewState = ~0;
1439    return GL_TRUE;
1440 }
1441
1442
1443 void
1444 _ae_destroy_context(struct gl_context *ctx)
1445 {
1446    if (AE_CONTEXT(ctx)) {
1447       free(ctx->aelt_context);
1448       ctx->aelt_context = NULL;
1449    }
1450 }
1451
1452
1453 /**
1454  * Check if the given vertex buffer object exists and is not mapped.
1455  * If so, add it to the list of buffers we must map before executing
1456  * an glArrayElement call.
1457  */
1458 static void
1459 check_vbo(AEcontext *actx, struct gl_buffer_object *vbo)
1460 {
1461    if (_mesa_is_bufferobj(vbo) && !_mesa_bufferobj_mapped(vbo)) {
1462       GLuint i;
1463       for (i = 0; i < actx->nr_vbos; i++)
1464          if (actx->vbo[i] == vbo)
1465             return;  /* already in the list, we're done */
1466       assert(actx->nr_vbos < VERT_ATTRIB_MAX);
1467       actx->vbo[actx->nr_vbos++] = vbo;
1468    }
1469 }
1470
1471
1472 /**
1473  * Make a list of per-vertex functions to call for each glArrayElement call.
1474  * These functions access the array data (i.e. glVertex, glColor, glNormal,
1475  * etc).
1476  * Note: this may be called during display list construction.
1477  */
1478 static void
1479 _ae_update_state(struct gl_context *ctx)
1480 {
1481    AEcontext *actx = AE_CONTEXT(ctx);
1482    AEarray *aa = actx->arrays;  /* non-indexed arrays (ex: glNormal) */
1483    AEattrib *at = actx->attribs;  /* indexed arrays (ex: glMultiTexCoord) */
1484    GLuint i;
1485    struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
1486
1487    actx->nr_vbos = 0;
1488
1489    /* conventional vertex arrays */
1490    if (arrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled) {
1491       aa->array = &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX];
1492       aa->offset = IndexFuncs[TYPE_IDX(aa->array->Type)];
1493       check_vbo(actx, aa->array->BufferObj);
1494       aa++;
1495    }
1496    if (arrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled) {
1497       aa->array = &arrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG];
1498       aa->offset = _gloffset_EdgeFlagv;
1499       check_vbo(actx, aa->array->BufferObj);
1500       aa++;
1501    }
1502    if (arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled) {
1503       aa->array = &arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL];
1504       aa->offset = NormalFuncs[TYPE_IDX(aa->array->Type)];
1505       check_vbo(actx, aa->array->BufferObj);
1506       aa++;
1507    }
1508    if (arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled) {
1509       aa->array = &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0];
1510       aa->offset = ColorFuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
1511       check_vbo(actx, aa->array->BufferObj);
1512       aa++;
1513    }
1514    if (arrayObj->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled) {
1515       aa->array = &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR1];
1516       aa->offset = SecondaryColorFuncs[TYPE_IDX(aa->array->Type)];
1517       check_vbo(actx, aa->array->BufferObj);
1518       aa++;
1519    }
1520    if (arrayObj->VertexAttrib[VERT_ATTRIB_FOG].Enabled) {
1521       aa->array = &arrayObj->VertexAttrib[VERT_ATTRIB_FOG];
1522       aa->offset = FogCoordFuncs[TYPE_IDX(aa->array->Type)];
1523       check_vbo(actx, aa->array->BufferObj);
1524       aa++;
1525    }
1526    for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
1527       struct gl_client_array *attribArray =
1528          &arrayObj->VertexAttrib[VERT_ATTRIB_TEX(i)];
1529       if (attribArray->Enabled) {
1530          /* NOTE: we use generic glVertexAttribNV functions here.
1531           * If we ever remove GL_NV_vertex_program this will have to change.
1532           */
1533          at->array = attribArray;
1534          ASSERT(!at->array->Normalized);
1535          at->func = AttribFuncsNV[at->array->Normalized]
1536                                  [at->array->Size-1]
1537                                  [TYPE_IDX(at->array->Type)];
1538          at->index = VERT_ATTRIB_TEX0 + i;
1539          check_vbo(actx, at->array->BufferObj);
1540          at++;
1541       }
1542    }
1543
1544    /* generic vertex attribute arrays */
1545    for (i = 1; i < VERT_ATTRIB_GENERIC_MAX; i++) {  /* skip zero! */
1546       struct gl_client_array *attribArray =
1547          &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(i)];
1548       if (attribArray->Enabled) {
1549          GLint intOrNorm;
1550          at->array = attribArray;
1551          /* Note: we can't grab the _glapi_Dispatch->VertexAttrib1fvNV
1552           * function pointer here (for float arrays) since the pointer may
1553           * change from one execution of _ae_ArrayElement() to
1554           * the next.  Doing so caused UT to break.
1555           */
1556          if (at->array->Integer)
1557             intOrNorm = 2;
1558          else if (at->array->Normalized)
1559             intOrNorm = 1;
1560          else
1561             intOrNorm = 0;
1562
1563          at->func = AttribFuncsARB[intOrNorm]
1564             [at->array->Size-1]
1565             [TYPE_IDX(at->array->Type)];
1566
1567          at->index = i;
1568          check_vbo(actx, at->array->BufferObj);
1569          at++;
1570       }
1571    }
1572
1573    /* finally, vertex position */
1574    if (arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC0].Enabled) {
1575       /* Use glVertex(v) instead of glVertexAttrib(0, v) to be sure it's
1576        * issued as the last (provoking) attribute).
1577        */
1578       aa->array = &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC0];
1579       assert(aa->array->Size >= 2); /* XXX fix someday? */
1580       aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
1581       check_vbo(actx, aa->array->BufferObj);
1582       aa++;
1583    }
1584    else if (arrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled) {
1585       aa->array = &arrayObj->VertexAttrib[VERT_ATTRIB_POS];
1586       aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
1587       check_vbo(actx, aa->array->BufferObj);
1588       aa++;
1589    }
1590
1591    check_vbo(actx, arrayObj->ElementArrayBufferObj);
1592
1593    ASSERT(at - actx->attribs <= VERT_ATTRIB_MAX);
1594    ASSERT(aa - actx->arrays < 32);
1595    at->func = NULL;  /* terminate the list */
1596    aa->offset = -1;  /* terminate the list */
1597
1598    actx->NewState = 0;
1599 }
1600
1601
1602 /**
1603  * Before replaying glArrayElements calls we need to map (for reading) any
1604  * VBOs referenced by the enabled vertex arrays.
1605  */
1606 void
1607 _ae_map_vbos(struct gl_context *ctx)
1608 {
1609    AEcontext *actx = AE_CONTEXT(ctx);
1610    GLuint i;
1611
1612    if (actx->mapped_vbos)
1613       return;
1614
1615    if (actx->NewState)
1616       _ae_update_state(ctx);
1617
1618    for (i = 0; i < actx->nr_vbos; i++)
1619       ctx->Driver.MapBufferRange(ctx, 0,
1620                                  actx->vbo[i]->Size,
1621                                  GL_MAP_READ_BIT,
1622                                  actx->vbo[i]);
1623
1624    if (actx->nr_vbos)
1625       actx->mapped_vbos = GL_TRUE;
1626 }
1627
1628
1629 /**
1630  * Unmap VBOs
1631  */
1632 void
1633 _ae_unmap_vbos(struct gl_context *ctx)
1634 {
1635    AEcontext *actx = AE_CONTEXT(ctx);
1636    GLuint i;
1637
1638    if (!actx->mapped_vbos)
1639       return;
1640
1641    assert (!actx->NewState);
1642
1643    for (i = 0; i < actx->nr_vbos; i++)
1644       ctx->Driver.UnmapBuffer(ctx, actx->vbo[i]);
1645
1646    actx->mapped_vbos = GL_FALSE;
1647 }
1648
1649
1650 /**
1651  * Called via glArrayElement() and glDrawArrays().
1652  * Issue the glNormal, glVertex, glColor, glVertexAttrib, etc functions
1653  * for all enabled vertex arrays (for elt-th element).
1654  * Note: this may be called during display list construction.
1655  */
1656 void GLAPIENTRY
1657 _ae_ArrayElement(GLint elt)
1658 {
1659    GET_CURRENT_CONTEXT(ctx);
1660    const AEcontext *actx = AE_CONTEXT(ctx);
1661    const AEarray *aa;
1662    const AEattrib *at;
1663    const struct _glapi_table * const disp = GET_DISPATCH();
1664    GLboolean do_map;
1665
1666    /* If PrimitiveRestart is enabled and the index is the RestartIndex
1667     * then we call PrimitiveRestartNV and return.
1668     */
1669    if (ctx->Array.PrimitiveRestart && (elt == ctx->Array.RestartIndex)) {
1670       CALL_PrimitiveRestartNV((struct _glapi_table *)disp, ());
1671       return;
1672    }
1673
1674    if (actx->NewState) {
1675       assert(!actx->mapped_vbos);
1676       _ae_update_state(ctx);
1677    }
1678
1679    /* Determine if we need to map/unmap VBOs */
1680    do_map = actx->nr_vbos && !actx->mapped_vbos;
1681
1682    if (do_map)
1683       _ae_map_vbos(ctx);
1684
1685    /* emit generic attribute elements */
1686    for (at = actx->attribs; at->func; at++) {
1687       const GLubyte *src
1688          = ADD_POINTERS(at->array->BufferObj->Pointer, at->array->Ptr)
1689          + elt * at->array->StrideB;
1690       at->func(at->index, src);
1691    }
1692
1693    /* emit conventional arrays elements */
1694    for (aa = actx->arrays; aa->offset != -1 ; aa++) {
1695       const GLubyte *src
1696          = ADD_POINTERS(aa->array->BufferObj->Pointer, aa->array->Ptr)
1697          + elt * aa->array->StrideB;
1698       CALL_by_offset(disp, (array_func), aa->offset, ((const void *) src));
1699    }
1700
1701    if (do_map)
1702       _ae_unmap_vbos(ctx);
1703 }
1704
1705
1706 void
1707 _ae_invalidate_state(struct gl_context *ctx, GLuint new_state)
1708 {
1709    AEcontext *actx = AE_CONTEXT(ctx);
1710
1711    /* Only interested in this subset of mesa state.  Need to prune
1712     * this down as both tnl/ and the drivers can raise statechanges
1713     * for arcane reasons in the middle of seemingly atomic operations
1714     * like DrawElements, over which we'd like to keep a known set of
1715     * arrays and vbo's mapped.
1716     *
1717     * Luckily, neither the drivers nor tnl muck with the state that
1718     * concerns us here:
1719     */
1720    new_state &= _NEW_ARRAY | _NEW_PROGRAM;
1721    if (new_state) {
1722       assert(!actx->mapped_vbos);
1723       actx->NewState |= new_state;
1724    }
1725 }
1726
1727
1728 void
1729 _mesa_install_arrayelt_vtxfmt(struct _glapi_table *disp,
1730                               const GLvertexformat *vfmt)
1731 {
1732    SET_ArrayElement(disp, vfmt->ArrayElement);
1733 }