2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Keith Whitwell <keith@tungstengraphics.com>
30 #include "api_arrayelt.h"
34 #include "glapioffsets.h"
37 typedef void (GLAPIENTRY *array_func)( const void * );
40 const struct gl_client_array *array;
44 typedef void (GLAPIENTRY *attrib_func)( GLuint indx, const void *data );
47 const struct gl_client_array *array;
54 AEattrib attribs[VERT_ATTRIB_MAX + 1];
57 struct gl_buffer_object *vbo[VERT_ATTRIB_MAX];
59 GLboolean mapped_vbos;
63 #define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context)
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.
71 #define TYPE_IDX(t) ( (t) == GL_DOUBLE ? 7 : (t) & 7 )
73 static const int ColorFuncs[2][8] = {
96 static const int VertexFuncs[3][8] = {
129 static const int IndexFuncs[8] = {
140 static const int NormalFuncs[8] = {
151 /* Note: _gloffset_* for these may not be a compile-time constant. */
152 static int SecondaryColorFuncs[8];
153 static int FogCoordFuncs[8];
157 ** GL_NV_vertex_program
160 /* GL_BYTE attributes */
162 static void GLAPIENTRY VertexAttrib1NbvNV(GLuint index, const GLbyte *v)
164 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0])));
167 static void GLAPIENTRY VertexAttrib1bvNV(GLuint index, const GLbyte *v)
169 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0]));
172 static void GLAPIENTRY VertexAttrib2NbvNV(GLuint index, const GLbyte *v)
174 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]), BYTE_TO_FLOAT(v[1])));
177 static void GLAPIENTRY VertexAttrib2bvNV(GLuint index, const GLbyte *v)
179 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1]));
182 static void GLAPIENTRY VertexAttrib3NbvNV(GLuint index, const GLbyte *v)
184 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
186 BYTE_TO_FLOAT(v[2])));
189 static void GLAPIENTRY VertexAttrib3bvNV(GLuint index, const GLbyte *v)
191 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2]));
194 static void GLAPIENTRY VertexAttrib4NbvNV(GLuint index, const GLbyte *v)
196 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
199 BYTE_TO_FLOAT(v[3])));
202 static void GLAPIENTRY VertexAttrib4bvNV(GLuint index, const GLbyte *v)
204 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
207 /* GL_UNSIGNED_BYTE attributes */
209 static void GLAPIENTRY VertexAttrib1NubvNV(GLuint index, const GLubyte *v)
211 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0])));
214 static void GLAPIENTRY VertexAttrib1ubvNV(GLuint index, const GLubyte *v)
216 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0]));
219 static void GLAPIENTRY VertexAttrib2NubvNV(GLuint index, const GLubyte *v)
221 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
222 UBYTE_TO_FLOAT(v[1])));
225 static void GLAPIENTRY VertexAttrib2ubvNV(GLuint index, const GLubyte *v)
227 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1]));
230 static void GLAPIENTRY VertexAttrib3NubvNV(GLuint index, const GLubyte *v)
232 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
233 UBYTE_TO_FLOAT(v[1]),
234 UBYTE_TO_FLOAT(v[2])));
236 static void GLAPIENTRY VertexAttrib3ubvNV(GLuint index, const GLubyte *v)
238 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2]));
241 static void GLAPIENTRY VertexAttrib4NubvNV(GLuint index, const GLubyte *v)
243 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
244 UBYTE_TO_FLOAT(v[1]),
245 UBYTE_TO_FLOAT(v[2]),
246 UBYTE_TO_FLOAT(v[3])));
249 static void GLAPIENTRY VertexAttrib4ubvNV(GLuint index, const GLubyte *v)
251 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
254 /* GL_SHORT attributes */
256 static void GLAPIENTRY VertexAttrib1NsvNV(GLuint index, const GLshort *v)
258 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0])));
261 static void GLAPIENTRY VertexAttrib1svNV(GLuint index, const GLshort *v)
263 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0]));
266 static void GLAPIENTRY VertexAttrib2NsvNV(GLuint index, const GLshort *v)
268 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
269 SHORT_TO_FLOAT(v[1])));
272 static void GLAPIENTRY VertexAttrib2svNV(GLuint index, const GLshort *v)
274 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1]));
277 static void GLAPIENTRY VertexAttrib3NsvNV(GLuint index, const GLshort *v)
279 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
280 SHORT_TO_FLOAT(v[1]),
281 SHORT_TO_FLOAT(v[2])));
284 static void GLAPIENTRY VertexAttrib3svNV(GLuint index, const GLshort *v)
286 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2]));
289 static void GLAPIENTRY VertexAttrib4NsvNV(GLuint index, const GLshort *v)
291 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
292 SHORT_TO_FLOAT(v[1]),
293 SHORT_TO_FLOAT(v[2]),
294 SHORT_TO_FLOAT(v[3])));
297 static void GLAPIENTRY VertexAttrib4svNV(GLuint index, const GLshort *v)
299 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
302 /* GL_UNSIGNED_SHORT attributes */
304 static void GLAPIENTRY VertexAttrib1NusvNV(GLuint index, const GLushort *v)
306 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0])));
309 static void GLAPIENTRY VertexAttrib1usvNV(GLuint index, const GLushort *v)
311 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0]));
314 static void GLAPIENTRY VertexAttrib2NusvNV(GLuint index, const GLushort *v)
316 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
317 USHORT_TO_FLOAT(v[1])));
320 static void GLAPIENTRY VertexAttrib2usvNV(GLuint index, const GLushort *v)
322 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1]));
325 static void GLAPIENTRY VertexAttrib3NusvNV(GLuint index, const GLushort *v)
327 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
328 USHORT_TO_FLOAT(v[1]),
329 USHORT_TO_FLOAT(v[2])));
332 static void GLAPIENTRY VertexAttrib3usvNV(GLuint index, const GLushort *v)
334 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2]));
337 static void GLAPIENTRY VertexAttrib4NusvNV(GLuint index, const GLushort *v)
339 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
340 USHORT_TO_FLOAT(v[1]),
341 USHORT_TO_FLOAT(v[2]),
342 USHORT_TO_FLOAT(v[3])));
345 static void GLAPIENTRY VertexAttrib4usvNV(GLuint index, const GLushort *v)
347 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
350 /* GL_INT attributes */
352 static void GLAPIENTRY VertexAttrib1NivNV(GLuint index, const GLint *v)
354 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0])));
357 static void GLAPIENTRY VertexAttrib1ivNV(GLuint index, const GLint *v)
359 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0]));
362 static void GLAPIENTRY VertexAttrib2NivNV(GLuint index, const GLint *v)
364 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
365 INT_TO_FLOAT(v[1])));
368 static void GLAPIENTRY VertexAttrib2ivNV(GLuint index, const GLint *v)
370 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1]));
373 static void GLAPIENTRY VertexAttrib3NivNV(GLuint index, const GLint *v)
375 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
377 INT_TO_FLOAT(v[2])));
380 static void GLAPIENTRY VertexAttrib3ivNV(GLuint index, const GLint *v)
382 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2]));
385 static void GLAPIENTRY VertexAttrib4NivNV(GLuint index, const GLint *v)
387 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
390 INT_TO_FLOAT(v[3])));
393 static void GLAPIENTRY VertexAttrib4ivNV(GLuint index, const GLint *v)
395 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
398 /* GL_UNSIGNED_INT attributes */
400 static void GLAPIENTRY VertexAttrib1NuivNV(GLuint index, const GLuint *v)
402 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0])));
405 static void GLAPIENTRY VertexAttrib1uivNV(GLuint index, const GLuint *v)
407 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0]));
410 static void GLAPIENTRY VertexAttrib2NuivNV(GLuint index, const GLuint *v)
412 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
413 UINT_TO_FLOAT(v[1])));
416 static void GLAPIENTRY VertexAttrib2uivNV(GLuint index, const GLuint *v)
418 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1]));
421 static void GLAPIENTRY VertexAttrib3NuivNV(GLuint index, const GLuint *v)
423 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
425 UINT_TO_FLOAT(v[2])));
428 static void GLAPIENTRY VertexAttrib3uivNV(GLuint index, const GLuint *v)
430 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2]));
433 static void GLAPIENTRY VertexAttrib4NuivNV(GLuint index, const GLuint *v)
435 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
438 UINT_TO_FLOAT(v[3])));
441 static void GLAPIENTRY VertexAttrib4uivNV(GLuint index, const GLuint *v)
443 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
446 /* GL_FLOAT attributes */
448 static void GLAPIENTRY VertexAttrib1fvNV(GLuint index, const GLfloat *v)
450 CALL_VertexAttrib1fvNV(GET_DISPATCH(), (index, v));
453 static void GLAPIENTRY VertexAttrib2fvNV(GLuint index, const GLfloat *v)
455 CALL_VertexAttrib2fvNV(GET_DISPATCH(), (index, v));
458 static void GLAPIENTRY VertexAttrib3fvNV(GLuint index, const GLfloat *v)
460 CALL_VertexAttrib3fvNV(GET_DISPATCH(), (index, v));
463 static void GLAPIENTRY VertexAttrib4fvNV(GLuint index, const GLfloat *v)
465 CALL_VertexAttrib4fvNV(GET_DISPATCH(), (index, v));
468 /* GL_DOUBLE attributes */
470 static void GLAPIENTRY VertexAttrib1dvNV(GLuint index, const GLdouble *v)
472 CALL_VertexAttrib1dvNV(GET_DISPATCH(), (index, v));
475 static void GLAPIENTRY VertexAttrib2dvNV(GLuint index, const GLdouble *v)
477 CALL_VertexAttrib2dvNV(GET_DISPATCH(), (index, v));
480 static void GLAPIENTRY VertexAttrib3dvNV(GLuint index, const GLdouble *v)
482 CALL_VertexAttrib3dvNV(GET_DISPATCH(), (index, v));
485 static void GLAPIENTRY VertexAttrib4dvNV(GLuint index, const GLdouble *v)
487 CALL_VertexAttrib4dvNV(GET_DISPATCH(), (index, v));
492 * Array [size][type] of VertexAttrib functions
494 static attrib_func AttribFuncsNV[2][4][8] = {
499 (attrib_func) VertexAttrib1bvNV,
500 (attrib_func) VertexAttrib1ubvNV,
501 (attrib_func) VertexAttrib1svNV,
502 (attrib_func) VertexAttrib1usvNV,
503 (attrib_func) VertexAttrib1ivNV,
504 (attrib_func) VertexAttrib1uivNV,
505 (attrib_func) VertexAttrib1fvNV,
506 (attrib_func) VertexAttrib1dvNV
510 (attrib_func) VertexAttrib2bvNV,
511 (attrib_func) VertexAttrib2ubvNV,
512 (attrib_func) VertexAttrib2svNV,
513 (attrib_func) VertexAttrib2usvNV,
514 (attrib_func) VertexAttrib2ivNV,
515 (attrib_func) VertexAttrib2uivNV,
516 (attrib_func) VertexAttrib2fvNV,
517 (attrib_func) VertexAttrib2dvNV
521 (attrib_func) VertexAttrib3bvNV,
522 (attrib_func) VertexAttrib3ubvNV,
523 (attrib_func) VertexAttrib3svNV,
524 (attrib_func) VertexAttrib3usvNV,
525 (attrib_func) VertexAttrib3ivNV,
526 (attrib_func) VertexAttrib3uivNV,
527 (attrib_func) VertexAttrib3fvNV,
528 (attrib_func) VertexAttrib3dvNV
532 (attrib_func) VertexAttrib4bvNV,
533 (attrib_func) VertexAttrib4ubvNV,
534 (attrib_func) VertexAttrib4svNV,
535 (attrib_func) VertexAttrib4usvNV,
536 (attrib_func) VertexAttrib4ivNV,
537 (attrib_func) VertexAttrib4uivNV,
538 (attrib_func) VertexAttrib4fvNV,
539 (attrib_func) VertexAttrib4dvNV
543 /* normalized (except for float/double) */
546 (attrib_func) VertexAttrib1NbvNV,
547 (attrib_func) VertexAttrib1NubvNV,
548 (attrib_func) VertexAttrib1NsvNV,
549 (attrib_func) VertexAttrib1NusvNV,
550 (attrib_func) VertexAttrib1NivNV,
551 (attrib_func) VertexAttrib1NuivNV,
552 (attrib_func) VertexAttrib1fvNV,
553 (attrib_func) VertexAttrib1dvNV
557 (attrib_func) VertexAttrib2NbvNV,
558 (attrib_func) VertexAttrib2NubvNV,
559 (attrib_func) VertexAttrib2NsvNV,
560 (attrib_func) VertexAttrib2NusvNV,
561 (attrib_func) VertexAttrib2NivNV,
562 (attrib_func) VertexAttrib2NuivNV,
563 (attrib_func) VertexAttrib2fvNV,
564 (attrib_func) VertexAttrib2dvNV
568 (attrib_func) VertexAttrib3NbvNV,
569 (attrib_func) VertexAttrib3NubvNV,
570 (attrib_func) VertexAttrib3NsvNV,
571 (attrib_func) VertexAttrib3NusvNV,
572 (attrib_func) VertexAttrib3NivNV,
573 (attrib_func) VertexAttrib3NuivNV,
574 (attrib_func) VertexAttrib3fvNV,
575 (attrib_func) VertexAttrib3dvNV
579 (attrib_func) VertexAttrib4NbvNV,
580 (attrib_func) VertexAttrib4NubvNV,
581 (attrib_func) VertexAttrib4NsvNV,
582 (attrib_func) VertexAttrib4NusvNV,
583 (attrib_func) VertexAttrib4NivNV,
584 (attrib_func) VertexAttrib4NuivNV,
585 (attrib_func) VertexAttrib4fvNV,
586 (attrib_func) VertexAttrib4dvNV
593 ** GL_ARB_vertex_program
596 /* GL_BYTE attributes */
598 static void GLAPIENTRY VertexAttrib1NbvARB(GLuint index, const GLbyte *v)
600 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0])));
603 static void GLAPIENTRY VertexAttrib1bvARB(GLuint index, const GLbyte *v)
605 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, v[0]));
608 static void GLAPIENTRY VertexAttrib2NbvARB(GLuint index, const GLbyte *v)
610 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]), BYTE_TO_FLOAT(v[1])));
613 static void GLAPIENTRY VertexAttrib2bvARB(GLuint index, const GLbyte *v)
615 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, v[0], v[1]));
618 static void GLAPIENTRY VertexAttrib3NbvARB(GLuint index, const GLbyte *v)
620 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
622 BYTE_TO_FLOAT(v[2])));
625 static void GLAPIENTRY VertexAttrib3bvARB(GLuint index, const GLbyte *v)
627 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, v[0], v[1], v[2]));
630 static void GLAPIENTRY VertexAttrib4NbvARB(GLuint index, const GLbyte *v)
632 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, BYTE_TO_FLOAT(v[0]),
635 BYTE_TO_FLOAT(v[3])));
638 static void GLAPIENTRY VertexAttrib4bvARB(GLuint index, const GLbyte *v)
640 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
643 /* GL_UNSIGNED_BYTE attributes */
645 static void GLAPIENTRY VertexAttrib1NubvARB(GLuint index, const GLubyte *v)
647 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0])));
650 static void GLAPIENTRY VertexAttrib1ubvARB(GLuint index, const GLubyte *v)
652 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, v[0]));
655 static void GLAPIENTRY VertexAttrib2NubvARB(GLuint index, const GLubyte *v)
657 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
658 UBYTE_TO_FLOAT(v[1])));
661 static void GLAPIENTRY VertexAttrib2ubvARB(GLuint index, const GLubyte *v)
663 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, v[0], v[1]));
666 static void GLAPIENTRY VertexAttrib3NubvARB(GLuint index, const GLubyte *v)
668 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
669 UBYTE_TO_FLOAT(v[1]),
670 UBYTE_TO_FLOAT(v[2])));
672 static void GLAPIENTRY VertexAttrib3ubvARB(GLuint index, const GLubyte *v)
674 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, v[0], v[1], v[2]));
677 static void GLAPIENTRY VertexAttrib4NubvARB(GLuint index, const GLubyte *v)
679 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, UBYTE_TO_FLOAT(v[0]),
680 UBYTE_TO_FLOAT(v[1]),
681 UBYTE_TO_FLOAT(v[2]),
682 UBYTE_TO_FLOAT(v[3])));
685 static void GLAPIENTRY VertexAttrib4ubvARB(GLuint index, const GLubyte *v)
687 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
690 /* GL_SHORT attributes */
692 static void GLAPIENTRY VertexAttrib1NsvARB(GLuint index, const GLshort *v)
694 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0])));
697 static void GLAPIENTRY VertexAttrib1svARB(GLuint index, const GLshort *v)
699 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, v[0]));
702 static void GLAPIENTRY VertexAttrib2NsvARB(GLuint index, const GLshort *v)
704 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
705 SHORT_TO_FLOAT(v[1])));
708 static void GLAPIENTRY VertexAttrib2svARB(GLuint index, const GLshort *v)
710 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, v[0], v[1]));
713 static void GLAPIENTRY VertexAttrib3NsvARB(GLuint index, const GLshort *v)
715 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
716 SHORT_TO_FLOAT(v[1]),
717 SHORT_TO_FLOAT(v[2])));
720 static void GLAPIENTRY VertexAttrib3svARB(GLuint index, const GLshort *v)
722 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, v[0], v[1], v[2]));
725 static void GLAPIENTRY VertexAttrib4NsvARB(GLuint index, const GLshort *v)
727 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, SHORT_TO_FLOAT(v[0]),
728 SHORT_TO_FLOAT(v[1]),
729 SHORT_TO_FLOAT(v[2]),
730 SHORT_TO_FLOAT(v[3])));
733 static void GLAPIENTRY VertexAttrib4svARB(GLuint index, const GLshort *v)
735 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
738 /* GL_UNSIGNED_SHORT attributes */
740 static void GLAPIENTRY VertexAttrib1NusvARB(GLuint index, const GLushort *v)
742 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0])));
745 static void GLAPIENTRY VertexAttrib1usvARB(GLuint index, const GLushort *v)
747 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, v[0]));
750 static void GLAPIENTRY VertexAttrib2NusvARB(GLuint index, const GLushort *v)
752 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
753 USHORT_TO_FLOAT(v[1])));
756 static void GLAPIENTRY VertexAttrib2usvARB(GLuint index, const GLushort *v)
758 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, v[0], v[1]));
761 static void GLAPIENTRY VertexAttrib3NusvARB(GLuint index, const GLushort *v)
763 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
764 USHORT_TO_FLOAT(v[1]),
765 USHORT_TO_FLOAT(v[2])));
768 static void GLAPIENTRY VertexAttrib3usvARB(GLuint index, const GLushort *v)
770 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, v[0], v[1], v[2]));
773 static void GLAPIENTRY VertexAttrib4NusvARB(GLuint index, const GLushort *v)
775 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, USHORT_TO_FLOAT(v[0]),
776 USHORT_TO_FLOAT(v[1]),
777 USHORT_TO_FLOAT(v[2]),
778 USHORT_TO_FLOAT(v[3])));
781 static void GLAPIENTRY VertexAttrib4usvARB(GLuint index, const GLushort *v)
783 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
786 /* GL_INT attributes */
788 static void GLAPIENTRY VertexAttrib1NivARB(GLuint index, const GLint *v)
790 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0])));
793 static void GLAPIENTRY VertexAttrib1ivARB(GLuint index, const GLint *v)
795 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, v[0]));
798 static void GLAPIENTRY VertexAttrib2NivARB(GLuint index, const GLint *v)
800 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
801 INT_TO_FLOAT(v[1])));
804 static void GLAPIENTRY VertexAttrib2ivARB(GLuint index, const GLint *v)
806 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, v[0], v[1]));
809 static void GLAPIENTRY VertexAttrib3NivARB(GLuint index, const GLint *v)
811 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
813 INT_TO_FLOAT(v[2])));
816 static void GLAPIENTRY VertexAttrib3ivARB(GLuint index, const GLint *v)
818 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, v[0], v[1], v[2]));
821 static void GLAPIENTRY VertexAttrib4NivARB(GLuint index, const GLint *v)
823 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, INT_TO_FLOAT(v[0]),
826 INT_TO_FLOAT(v[3])));
829 static void GLAPIENTRY VertexAttrib4ivARB(GLuint index, const GLint *v)
831 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
834 /* GL_UNSIGNED_INT attributes */
836 static void GLAPIENTRY VertexAttrib1NuivARB(GLuint index, const GLuint *v)
838 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0])));
841 static void GLAPIENTRY VertexAttrib1uivARB(GLuint index, const GLuint *v)
843 CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, v[0]));
846 static void GLAPIENTRY VertexAttrib2NuivARB(GLuint index, const GLuint *v)
848 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
849 UINT_TO_FLOAT(v[1])));
852 static void GLAPIENTRY VertexAttrib2uivARB(GLuint index, const GLuint *v)
854 CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, v[0], v[1]));
857 static void GLAPIENTRY VertexAttrib3NuivARB(GLuint index, const GLuint *v)
859 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
861 UINT_TO_FLOAT(v[2])));
864 static void GLAPIENTRY VertexAttrib3uivARB(GLuint index, const GLuint *v)
866 CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, v[0], v[1], v[2]));
869 static void GLAPIENTRY VertexAttrib4NuivARB(GLuint index, const GLuint *v)
871 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, UINT_TO_FLOAT(v[0]),
874 UINT_TO_FLOAT(v[3])));
877 static void GLAPIENTRY VertexAttrib4uivARB(GLuint index, const GLuint *v)
879 CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3]));
882 /* GL_FLOAT attributes */
884 static void GLAPIENTRY VertexAttrib1fvARB(GLuint index, const GLfloat *v)
886 CALL_VertexAttrib1fvARB(GET_DISPATCH(), (index, v));
889 static void GLAPIENTRY VertexAttrib2fvARB(GLuint index, const GLfloat *v)
891 CALL_VertexAttrib2fvARB(GET_DISPATCH(), (index, v));
894 static void GLAPIENTRY VertexAttrib3fvARB(GLuint index, const GLfloat *v)
896 CALL_VertexAttrib3fvARB(GET_DISPATCH(), (index, v));
899 static void GLAPIENTRY VertexAttrib4fvARB(GLuint index, const GLfloat *v)
901 CALL_VertexAttrib4fvARB(GET_DISPATCH(), (index, v));
904 /* GL_DOUBLE attributes */
906 static void GLAPIENTRY VertexAttrib1dvARB(GLuint index, const GLdouble *v)
908 CALL_VertexAttrib1dvARB(GET_DISPATCH(), (index, v));
911 static void GLAPIENTRY VertexAttrib2dvARB(GLuint index, const GLdouble *v)
913 CALL_VertexAttrib2dvARB(GET_DISPATCH(), (index, v));
916 static void GLAPIENTRY VertexAttrib3dvARB(GLuint index, const GLdouble *v)
918 CALL_VertexAttrib3dvARB(GET_DISPATCH(), (index, v));
921 static void GLAPIENTRY VertexAttrib4dvARB(GLuint index, const GLdouble *v)
923 CALL_VertexAttrib4dvARB(GET_DISPATCH(), (index, v));
928 * Array [size][type] of VertexAttrib functions
930 static attrib_func AttribFuncsARB[2][4][8] = {
935 (attrib_func) VertexAttrib1bvARB,
936 (attrib_func) VertexAttrib1ubvARB,
937 (attrib_func) VertexAttrib1svARB,
938 (attrib_func) VertexAttrib1usvARB,
939 (attrib_func) VertexAttrib1ivARB,
940 (attrib_func) VertexAttrib1uivARB,
941 (attrib_func) VertexAttrib1fvARB,
942 (attrib_func) VertexAttrib1dvARB
946 (attrib_func) VertexAttrib2bvARB,
947 (attrib_func) VertexAttrib2ubvARB,
948 (attrib_func) VertexAttrib2svARB,
949 (attrib_func) VertexAttrib2usvARB,
950 (attrib_func) VertexAttrib2ivARB,
951 (attrib_func) VertexAttrib2uivARB,
952 (attrib_func) VertexAttrib2fvARB,
953 (attrib_func) VertexAttrib2dvARB
957 (attrib_func) VertexAttrib3bvARB,
958 (attrib_func) VertexAttrib3ubvARB,
959 (attrib_func) VertexAttrib3svARB,
960 (attrib_func) VertexAttrib3usvARB,
961 (attrib_func) VertexAttrib3ivARB,
962 (attrib_func) VertexAttrib3uivARB,
963 (attrib_func) VertexAttrib3fvARB,
964 (attrib_func) VertexAttrib3dvARB
968 (attrib_func) VertexAttrib4bvARB,
969 (attrib_func) VertexAttrib4ubvARB,
970 (attrib_func) VertexAttrib4svARB,
971 (attrib_func) VertexAttrib4usvARB,
972 (attrib_func) VertexAttrib4ivARB,
973 (attrib_func) VertexAttrib4uivARB,
974 (attrib_func) VertexAttrib4fvARB,
975 (attrib_func) VertexAttrib4dvARB
979 /* normalized (except for float/double) */
982 (attrib_func) VertexAttrib1NbvARB,
983 (attrib_func) VertexAttrib1NubvARB,
984 (attrib_func) VertexAttrib1NsvARB,
985 (attrib_func) VertexAttrib1NusvARB,
986 (attrib_func) VertexAttrib1NivARB,
987 (attrib_func) VertexAttrib1NuivARB,
988 (attrib_func) VertexAttrib1fvARB,
989 (attrib_func) VertexAttrib1dvARB
993 (attrib_func) VertexAttrib2NbvARB,
994 (attrib_func) VertexAttrib2NubvARB,
995 (attrib_func) VertexAttrib2NsvARB,
996 (attrib_func) VertexAttrib2NusvARB,
997 (attrib_func) VertexAttrib2NivARB,
998 (attrib_func) VertexAttrib2NuivARB,
999 (attrib_func) VertexAttrib2fvARB,
1000 (attrib_func) VertexAttrib2dvARB
1004 (attrib_func) VertexAttrib3NbvARB,
1005 (attrib_func) VertexAttrib3NubvARB,
1006 (attrib_func) VertexAttrib3NsvARB,
1007 (attrib_func) VertexAttrib3NusvARB,
1008 (attrib_func) VertexAttrib3NivARB,
1009 (attrib_func) VertexAttrib3NuivARB,
1010 (attrib_func) VertexAttrib3fvARB,
1011 (attrib_func) VertexAttrib3dvARB
1015 (attrib_func) VertexAttrib4NbvARB,
1016 (attrib_func) VertexAttrib4NubvARB,
1017 (attrib_func) VertexAttrib4NsvARB,
1018 (attrib_func) VertexAttrib4NusvARB,
1019 (attrib_func) VertexAttrib4NivARB,
1020 (attrib_func) VertexAttrib4NuivARB,
1021 (attrib_func) VertexAttrib4fvARB,
1022 (attrib_func) VertexAttrib4dvARB
1027 /**********************************************************************/
1030 GLboolean _ae_create_context( GLcontext *ctx )
1032 if (ctx->aelt_context)
1035 /* These _gloffset_* values may not be compile-time constants */
1036 SecondaryColorFuncs[0] = _gloffset_SecondaryColor3bvEXT;
1037 SecondaryColorFuncs[1] = _gloffset_SecondaryColor3ubvEXT;
1038 SecondaryColorFuncs[2] = _gloffset_SecondaryColor3svEXT;
1039 SecondaryColorFuncs[3] = _gloffset_SecondaryColor3usvEXT;
1040 SecondaryColorFuncs[4] = _gloffset_SecondaryColor3ivEXT;
1041 SecondaryColorFuncs[5] = _gloffset_SecondaryColor3uivEXT;
1042 SecondaryColorFuncs[6] = _gloffset_SecondaryColor3fvEXT;
1043 SecondaryColorFuncs[7] = _gloffset_SecondaryColor3dvEXT;
1045 FogCoordFuncs[0] = -1;
1046 FogCoordFuncs[1] = -1;
1047 FogCoordFuncs[2] = -1;
1048 FogCoordFuncs[3] = -1;
1049 FogCoordFuncs[4] = -1;
1050 FogCoordFuncs[5] = -1;
1051 FogCoordFuncs[6] = _gloffset_FogCoordfvEXT;
1052 FogCoordFuncs[7] = _gloffset_FogCoorddvEXT;
1054 ctx->aelt_context = CALLOC( sizeof(AEcontext) );
1055 if (!ctx->aelt_context)
1058 AE_CONTEXT(ctx)->NewState = ~0;
1063 void _ae_destroy_context( GLcontext *ctx )
1065 if ( AE_CONTEXT( ctx ) ) {
1066 FREE( ctx->aelt_context );
1067 ctx->aelt_context = NULL;
1071 static void check_vbo( AEcontext *actx,
1072 struct gl_buffer_object *vbo )
1074 if (vbo->Name && !vbo->Pointer) {
1076 for (i = 0; i < actx->nr_vbos; i++)
1077 if (actx->vbo[i] == vbo)
1079 assert(actx->nr_vbos < VERT_ATTRIB_MAX);
1080 actx->vbo[actx->nr_vbos++] = vbo;
1086 * Make a list of per-vertex functions to call for each glArrayElement call.
1087 * These functions access the array data (i.e. glVertex, glColor, glNormal,
1089 * Note: this may be called during display list construction.
1091 static void _ae_update_state( GLcontext *ctx )
1093 AEcontext *actx = AE_CONTEXT(ctx);
1094 AEarray *aa = actx->arrays;
1095 AEattrib *at = actx->attribs;
1100 /* conventional vertex arrays */
1101 if (ctx->Array.ArrayObj->Index.Enabled) {
1102 aa->array = &ctx->Array.ArrayObj->Index;
1103 aa->offset = IndexFuncs[TYPE_IDX(aa->array->Type)];
1104 check_vbo(actx, aa->array->BufferObj);
1107 if (ctx->Array.ArrayObj->EdgeFlag.Enabled) {
1108 aa->array = &ctx->Array.ArrayObj->EdgeFlag;
1109 aa->offset = _gloffset_EdgeFlagv;
1110 check_vbo(actx, aa->array->BufferObj);
1113 if (ctx->Array.ArrayObj->Normal.Enabled) {
1114 aa->array = &ctx->Array.ArrayObj->Normal;
1115 aa->offset = NormalFuncs[TYPE_IDX(aa->array->Type)];
1116 check_vbo(actx, aa->array->BufferObj);
1119 if (ctx->Array.ArrayObj->Color.Enabled) {
1120 aa->array = &ctx->Array.ArrayObj->Color;
1121 aa->offset = ColorFuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
1122 check_vbo(actx, aa->array->BufferObj);
1125 if (ctx->Array.ArrayObj->SecondaryColor.Enabled) {
1126 aa->array = &ctx->Array.ArrayObj->SecondaryColor;
1127 aa->offset = SecondaryColorFuncs[TYPE_IDX(aa->array->Type)];
1128 check_vbo(actx, aa->array->BufferObj);
1131 if (ctx->Array.ArrayObj->FogCoord.Enabled) {
1132 aa->array = &ctx->Array.ArrayObj->FogCoord;
1133 aa->offset = FogCoordFuncs[TYPE_IDX(aa->array->Type)];
1134 check_vbo(actx, aa->array->BufferObj);
1137 for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
1138 struct gl_client_array *attribArray = &ctx->Array.ArrayObj->TexCoord[i];
1139 if (attribArray->Enabled) {
1140 /* NOTE: we use generic glVertexAttribNV functions here.
1141 * If we ever remove GL_NV_vertex_program this will have to change.
1143 at->array = attribArray;
1144 ASSERT(!at->array->Normalized);
1145 at->func = AttribFuncsNV[at->array->Normalized]
1147 [TYPE_IDX(at->array->Type)];
1148 at->index = VERT_ATTRIB_TEX0 + i;
1149 check_vbo(actx, at->array->BufferObj);
1154 /* generic vertex attribute arrays */
1155 for (i = 1; i < VERT_ATTRIB_MAX; i++) { /* skip zero! */
1156 struct gl_client_array *attribArray = &ctx->Array.ArrayObj->VertexAttrib[i];
1157 if (attribArray->Enabled) {
1158 at->array = attribArray;
1159 /* Note: we can't grab the _glapi_Dispatch->VertexAttrib1fvNV
1160 * function pointer here (for float arrays) since the pointer may
1161 * change from one execution of _ae_loopback_array_elt() to
1162 * the next. Doing so caused UT to break.
1164 if (ctx->VertexProgram._Enabled
1165 && ctx->VertexProgram.Current->IsNVProgram) {
1166 at->func = AttribFuncsNV[at->array->Normalized]
1168 [TYPE_IDX(at->array->Type)];
1171 at->func = AttribFuncsARB[at->array->Normalized]
1173 [TYPE_IDX(at->array->Type)];
1176 check_vbo(actx, at->array->BufferObj);
1181 /* finally, vertex position */
1182 if (ctx->Array.ArrayObj->VertexAttrib[0].Enabled) {
1183 /* Use glVertex(v) instead of glVertexAttrib(0, v) to be sure it's
1184 * issued as the last (provoking) attribute).
1186 aa->array = &ctx->Array.ArrayObj->VertexAttrib[0];
1187 assert(aa->array->Size >= 2); /* XXX fix someday? */
1188 aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
1189 check_vbo(actx, aa->array->BufferObj);
1192 else if (ctx->Array.ArrayObj->Vertex.Enabled) {
1193 aa->array = &ctx->Array.ArrayObj->Vertex;
1194 aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
1195 check_vbo(actx, aa->array->BufferObj);
1199 check_vbo(actx, ctx->Array.ElementArrayBufferObj);
1201 ASSERT(at - actx->attribs <= VERT_ATTRIB_MAX);
1202 ASSERT(aa - actx->arrays < 32);
1203 at->func = NULL; /* terminate the list */
1204 aa->offset = -1; /* terminate the list */
1209 void _ae_map_vbos( GLcontext *ctx )
1211 AEcontext *actx = AE_CONTEXT(ctx);
1214 if (actx->mapped_vbos)
1218 _ae_update_state(ctx);
1220 for (i = 0; i < actx->nr_vbos; i++)
1221 ctx->Driver.MapBuffer(ctx,
1222 GL_ARRAY_BUFFER_ARB,
1223 GL_DYNAMIC_DRAW_ARB,
1227 actx->mapped_vbos = GL_TRUE;
1230 void _ae_unmap_vbos( GLcontext *ctx )
1232 AEcontext *actx = AE_CONTEXT(ctx);
1235 if (!actx->mapped_vbos)
1238 assert (!actx->NewState);
1240 for (i = 0; i < actx->nr_vbos; i++)
1241 ctx->Driver.UnmapBuffer(ctx,
1242 GL_ARRAY_BUFFER_ARB,
1245 actx->mapped_vbos = GL_FALSE;
1250 * Called via glArrayElement() and glDrawArrays().
1251 * Issue the glNormal, glVertex, glColor, glVertexAttrib, etc functions
1252 * for all enabled vertex arrays (for elt-th element).
1253 * Note: this may be called during display list construction.
1255 void GLAPIENTRY _ae_loopback_array_elt( GLint elt )
1257 GET_CURRENT_CONTEXT(ctx);
1258 const AEcontext *actx = AE_CONTEXT(ctx);
1261 const struct _glapi_table * const disp = GET_DISPATCH();
1264 if (actx->NewState) {
1265 assert(!actx->mapped_vbos);
1266 _ae_update_state( ctx );
1269 do_map = actx->nr_vbos && !actx->mapped_vbos;
1276 /* generic attributes */
1277 for (at = actx->attribs; at->func; at++) {
1279 = ADD_POINTERS(at->array->BufferObj->Pointer, at->array->Ptr)
1280 + elt * at->array->StrideB;
1281 at->func( at->index, src );
1284 /* conventional arrays */
1285 for (aa = actx->arrays; aa->offset != -1 ; aa++) {
1287 = ADD_POINTERS(aa->array->BufferObj->Pointer, aa->array->Ptr)
1288 + elt * aa->array->StrideB;
1289 CALL_by_offset( disp, (array_func), aa->offset,
1290 ((const void *) src) );
1294 _ae_unmap_vbos(ctx);
1298 void _ae_invalidate_state( GLcontext *ctx, GLuint new_state )
1300 AEcontext *actx = AE_CONTEXT(ctx);
1303 /* Only interested in this subset of mesa state. Need to prune
1304 * this down as both tnl/ and the drivers can raise statechanges
1305 * for arcane reasons in the middle of seemingly atomic operations
1306 * like DrawElements, over which we'd like to keep a known set of
1307 * arrays and vbo's mapped.
1309 * Luckily, neither the drivers nor tnl muck with the state that
1312 new_state &= _NEW_ARRAY | _NEW_PROGRAM;
1314 assert(!actx->mapped_vbos);
1315 actx->NewState |= new_state;