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 * This file implements the glArrayElement() function.
27 * It involves looking at the format/type of all the enabled vertex arrays
28 * and emitting a list of pointers to functions which set the per-vertex
29 * state for the element/index.
34 * Keith Whitwell <keith@tungstengraphics.com>
38 #include "api_arrayelt.h"
39 #include "bufferobj.h"
43 #include "mfeatures.h"
45 #include "main/dispatch.h"
47 typedef void (GLAPIENTRY
*array_func
)( const void * );
50 const struct gl_client_array
*array
;
54 typedef void (GLAPIENTRY
*attrib_func
)( GLuint indx
, const void *data
);
57 const struct gl_client_array
*array
;
64 AEattrib attribs
[VERT_ATTRIB_MAX
+ 1];
67 struct gl_buffer_object
*vbo
[VERT_ATTRIB_MAX
];
69 GLboolean mapped_vbos
;
73 #define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context)
77 * Convert GL_BYTE, GL_UNSIGNED_BYTE, .. GL_DOUBLE into an integer
78 * in the range [0, 7]. Luckily these type tokens are sequentially
79 * numbered in gl.h, except for GL_DOUBLE.
81 #define TYPE_IDX(t) ( (t) == GL_DOUBLE ? 7 : (t) & 7 )
89 static const int ColorFuncs
[2][NUM_TYPES
] = {
112 static const int VertexFuncs
[3][NUM_TYPES
] = {
145 static const int IndexFuncs
[NUM_TYPES
] = {
156 static const int NormalFuncs
[NUM_TYPES
] = {
167 /* Note: _gloffset_* for these may not be a compile-time constant. */
168 static int SecondaryColorFuncs
[NUM_TYPES
];
169 static int FogCoordFuncs
[NUM_TYPES
];
173 ** GL_NV_vertex_program
176 /* GL_BYTE attributes */
178 static void GLAPIENTRY
179 VertexAttrib1NbvNV(GLuint index
, const GLbyte
*v
)
181 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, BYTE_TO_FLOAT(v
[0])));
184 static void GLAPIENTRY
185 VertexAttrib1bvNV(GLuint index
, const GLbyte
*v
)
187 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0]));
190 static void GLAPIENTRY
191 VertexAttrib2NbvNV(GLuint index
, const GLbyte
*v
)
193 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, BYTE_TO_FLOAT(v
[0]), BYTE_TO_FLOAT(v
[1])));
196 static void GLAPIENTRY
197 VertexAttrib2bvNV(GLuint index
, const GLbyte
*v
)
199 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1]));
202 static void GLAPIENTRY
203 VertexAttrib3NbvNV(GLuint index
, const GLbyte
*v
)
205 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, BYTE_TO_FLOAT(v
[0]),
207 BYTE_TO_FLOAT(v
[2])));
210 static void GLAPIENTRY
211 VertexAttrib3bvNV(GLuint index
, const GLbyte
*v
)
213 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1], (GLfloat
)v
[2]));
216 static void GLAPIENTRY
217 VertexAttrib4NbvNV(GLuint index
, const GLbyte
*v
)
219 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, BYTE_TO_FLOAT(v
[0]),
222 BYTE_TO_FLOAT(v
[3])));
225 static void GLAPIENTRY
226 VertexAttrib4bvNV(GLuint index
, const GLbyte
*v
)
228 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1], (GLfloat
)v
[2], (GLfloat
)v
[3]));
231 /* GL_UNSIGNED_BYTE attributes */
233 static void GLAPIENTRY
234 VertexAttrib1NubvNV(GLuint index
, const GLubyte
*v
)
236 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, UBYTE_TO_FLOAT(v
[0])));
239 static void GLAPIENTRY
240 VertexAttrib1ubvNV(GLuint index
, const GLubyte
*v
)
242 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0]));
245 static void GLAPIENTRY
246 VertexAttrib2NubvNV(GLuint index
, const GLubyte
*v
)
248 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, UBYTE_TO_FLOAT(v
[0]),
249 UBYTE_TO_FLOAT(v
[1])));
252 static void GLAPIENTRY
253 VertexAttrib2ubvNV(GLuint index
, const GLubyte
*v
)
255 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1]));
258 static void GLAPIENTRY
259 VertexAttrib3NubvNV(GLuint index
, const GLubyte
*v
)
261 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, UBYTE_TO_FLOAT(v
[0]),
262 UBYTE_TO_FLOAT(v
[1]),
263 UBYTE_TO_FLOAT(v
[2])));
265 static void GLAPIENTRY
266 VertexAttrib3ubvNV(GLuint index
, const GLubyte
*v
)
268 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0],
269 (GLfloat
)v
[1], (GLfloat
)v
[2]));
272 static void GLAPIENTRY
273 VertexAttrib4NubvNV(GLuint index
, const GLubyte
*v
)
275 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, UBYTE_TO_FLOAT(v
[0]),
276 UBYTE_TO_FLOAT(v
[1]),
277 UBYTE_TO_FLOAT(v
[2]),
278 UBYTE_TO_FLOAT(v
[3])));
281 static void GLAPIENTRY
282 VertexAttrib4ubvNV(GLuint index
, const GLubyte
*v
)
284 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0],
285 (GLfloat
)v
[1], (GLfloat
)v
[2],
289 /* GL_SHORT attributes */
291 static void GLAPIENTRY
292 VertexAttrib1NsvNV(GLuint index
, const GLshort
*v
)
294 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, SHORT_TO_FLOAT(v
[0])));
297 static void GLAPIENTRY
298 VertexAttrib1svNV(GLuint index
, const GLshort
*v
)
300 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0]));
303 static void GLAPIENTRY
304 VertexAttrib2NsvNV(GLuint index
, const GLshort
*v
)
306 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, SHORT_TO_FLOAT(v
[0]),
307 SHORT_TO_FLOAT(v
[1])));
310 static void GLAPIENTRY
311 VertexAttrib2svNV(GLuint index
, const GLshort
*v
)
313 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1]));
316 static void GLAPIENTRY
317 VertexAttrib3NsvNV(GLuint index
, const GLshort
*v
)
319 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, SHORT_TO_FLOAT(v
[0]),
320 SHORT_TO_FLOAT(v
[1]),
321 SHORT_TO_FLOAT(v
[2])));
324 static void GLAPIENTRY
325 VertexAttrib3svNV(GLuint index
, const GLshort
*v
)
327 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1],
331 static void GLAPIENTRY
332 VertexAttrib4NsvNV(GLuint index
, const GLshort
*v
)
334 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, SHORT_TO_FLOAT(v
[0]),
335 SHORT_TO_FLOAT(v
[1]),
336 SHORT_TO_FLOAT(v
[2]),
337 SHORT_TO_FLOAT(v
[3])));
340 static void GLAPIENTRY
341 VertexAttrib4svNV(GLuint index
, const GLshort
*v
)
343 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1],
344 (GLfloat
)v
[2], (GLfloat
)v
[3]));
347 /* GL_UNSIGNED_SHORT attributes */
349 static void GLAPIENTRY
350 VertexAttrib1NusvNV(GLuint index
, const GLushort
*v
)
352 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, USHORT_TO_FLOAT(v
[0])));
355 static void GLAPIENTRY
356 VertexAttrib1usvNV(GLuint index
, const GLushort
*v
)
358 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0]));
361 static void GLAPIENTRY
362 VertexAttrib2NusvNV(GLuint index
, const GLushort
*v
)
364 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, USHORT_TO_FLOAT(v
[0]),
365 USHORT_TO_FLOAT(v
[1])));
368 static void GLAPIENTRY
369 VertexAttrib2usvNV(GLuint index
, const GLushort
*v
)
371 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0],
375 static void GLAPIENTRY
376 VertexAttrib3NusvNV(GLuint index
, const GLushort
*v
)
378 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, USHORT_TO_FLOAT(v
[0]),
379 USHORT_TO_FLOAT(v
[1]),
380 USHORT_TO_FLOAT(v
[2])));
383 static void GLAPIENTRY
384 VertexAttrib3usvNV(GLuint index
, const GLushort
*v
)
386 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1],
390 static void GLAPIENTRY
391 VertexAttrib4NusvNV(GLuint index
, const GLushort
*v
)
393 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, USHORT_TO_FLOAT(v
[0]),
394 USHORT_TO_FLOAT(v
[1]),
395 USHORT_TO_FLOAT(v
[2]),
396 USHORT_TO_FLOAT(v
[3])));
399 static void GLAPIENTRY
400 VertexAttrib4usvNV(GLuint index
, const GLushort
*v
)
402 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1],
403 (GLfloat
)v
[2], (GLfloat
)v
[3]));
406 /* GL_INT attributes */
408 static void GLAPIENTRY
409 VertexAttrib1NivNV(GLuint index
, const GLint
*v
)
411 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, INT_TO_FLOAT(v
[0])));
414 static void GLAPIENTRY
415 VertexAttrib1ivNV(GLuint index
, const GLint
*v
)
417 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0]));
420 static void GLAPIENTRY
421 VertexAttrib2NivNV(GLuint index
, const GLint
*v
)
423 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, INT_TO_FLOAT(v
[0]),
424 INT_TO_FLOAT(v
[1])));
427 static void GLAPIENTRY
428 VertexAttrib2ivNV(GLuint index
, const GLint
*v
)
430 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1]));
433 static void GLAPIENTRY
434 VertexAttrib3NivNV(GLuint index
, const GLint
*v
)
436 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, INT_TO_FLOAT(v
[0]),
438 INT_TO_FLOAT(v
[2])));
441 static void GLAPIENTRY
442 VertexAttrib3ivNV(GLuint index
, const GLint
*v
)
444 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1],
448 static void GLAPIENTRY
449 VertexAttrib4NivNV(GLuint index
, const GLint
*v
)
451 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, INT_TO_FLOAT(v
[0]),
454 INT_TO_FLOAT(v
[3])));
457 static void GLAPIENTRY
458 VertexAttrib4ivNV(GLuint index
, const GLint
*v
)
460 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1],
461 (GLfloat
)v
[2], (GLfloat
)v
[3]));
464 /* GL_UNSIGNED_INT attributes */
466 static void GLAPIENTRY
467 VertexAttrib1NuivNV(GLuint index
, const GLuint
*v
)
469 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, UINT_TO_FLOAT(v
[0])));
472 static void GLAPIENTRY
473 VertexAttrib1uivNV(GLuint index
, const GLuint
*v
)
475 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0]));
478 static void GLAPIENTRY
479 VertexAttrib2NuivNV(GLuint index
, const GLuint
*v
)
481 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, UINT_TO_FLOAT(v
[0]),
482 UINT_TO_FLOAT(v
[1])));
485 static void GLAPIENTRY
486 VertexAttrib2uivNV(GLuint index
, const GLuint
*v
)
488 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0],
492 static void GLAPIENTRY
493 VertexAttrib3NuivNV(GLuint index
, const GLuint
*v
)
495 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, UINT_TO_FLOAT(v
[0]),
497 UINT_TO_FLOAT(v
[2])));
500 static void GLAPIENTRY
501 VertexAttrib3uivNV(GLuint index
, const GLuint
*v
)
503 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1],
507 static void GLAPIENTRY
508 VertexAttrib4NuivNV(GLuint index
, const GLuint
*v
)
510 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, UINT_TO_FLOAT(v
[0]),
513 UINT_TO_FLOAT(v
[3])));
516 static void GLAPIENTRY
517 VertexAttrib4uivNV(GLuint index
, const GLuint
*v
)
519 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1],
520 (GLfloat
)v
[2], (GLfloat
)v
[3]));
523 /* GL_FLOAT attributes */
525 static void GLAPIENTRY
526 VertexAttrib1fvNV(GLuint index
, const GLfloat
*v
)
528 CALL_VertexAttrib1fvNV(GET_DISPATCH(), (index
, v
));
531 static void GLAPIENTRY
532 VertexAttrib2fvNV(GLuint index
, const GLfloat
*v
)
534 CALL_VertexAttrib2fvNV(GET_DISPATCH(), (index
, v
));
537 static void GLAPIENTRY
538 VertexAttrib3fvNV(GLuint index
, const GLfloat
*v
)
540 CALL_VertexAttrib3fvNV(GET_DISPATCH(), (index
, v
));
543 static void GLAPIENTRY
544 VertexAttrib4fvNV(GLuint index
, const GLfloat
*v
)
546 CALL_VertexAttrib4fvNV(GET_DISPATCH(), (index
, v
));
549 /* GL_DOUBLE attributes */
551 static void GLAPIENTRY
552 VertexAttrib1dvNV(GLuint index
, const GLdouble
*v
)
554 CALL_VertexAttrib1dvNV(GET_DISPATCH(), (index
, v
));
557 static void GLAPIENTRY
558 VertexAttrib2dvNV(GLuint index
, const GLdouble
*v
)
560 CALL_VertexAttrib2dvNV(GET_DISPATCH(), (index
, v
));
563 static void GLAPIENTRY
564 VertexAttrib3dvNV(GLuint index
, const GLdouble
*v
)
566 CALL_VertexAttrib3dvNV(GET_DISPATCH(), (index
, v
));
569 static void GLAPIENTRY
570 VertexAttrib4dvNV(GLuint index
, const GLdouble
*v
)
572 CALL_VertexAttrib4dvNV(GET_DISPATCH(), (index
, v
));
577 * Array [size][type] of VertexAttrib functions
579 static attrib_func AttribFuncsNV
[2][4][NUM_TYPES
] = {
584 (attrib_func
) VertexAttrib1bvNV
,
585 (attrib_func
) VertexAttrib1ubvNV
,
586 (attrib_func
) VertexAttrib1svNV
,
587 (attrib_func
) VertexAttrib1usvNV
,
588 (attrib_func
) VertexAttrib1ivNV
,
589 (attrib_func
) VertexAttrib1uivNV
,
590 (attrib_func
) VertexAttrib1fvNV
,
591 (attrib_func
) VertexAttrib1dvNV
595 (attrib_func
) VertexAttrib2bvNV
,
596 (attrib_func
) VertexAttrib2ubvNV
,
597 (attrib_func
) VertexAttrib2svNV
,
598 (attrib_func
) VertexAttrib2usvNV
,
599 (attrib_func
) VertexAttrib2ivNV
,
600 (attrib_func
) VertexAttrib2uivNV
,
601 (attrib_func
) VertexAttrib2fvNV
,
602 (attrib_func
) VertexAttrib2dvNV
606 (attrib_func
) VertexAttrib3bvNV
,
607 (attrib_func
) VertexAttrib3ubvNV
,
608 (attrib_func
) VertexAttrib3svNV
,
609 (attrib_func
) VertexAttrib3usvNV
,
610 (attrib_func
) VertexAttrib3ivNV
,
611 (attrib_func
) VertexAttrib3uivNV
,
612 (attrib_func
) VertexAttrib3fvNV
,
613 (attrib_func
) VertexAttrib3dvNV
617 (attrib_func
) VertexAttrib4bvNV
,
618 (attrib_func
) VertexAttrib4ubvNV
,
619 (attrib_func
) VertexAttrib4svNV
,
620 (attrib_func
) VertexAttrib4usvNV
,
621 (attrib_func
) VertexAttrib4ivNV
,
622 (attrib_func
) VertexAttrib4uivNV
,
623 (attrib_func
) VertexAttrib4fvNV
,
624 (attrib_func
) VertexAttrib4dvNV
628 /* normalized (except for float/double) */
631 (attrib_func
) VertexAttrib1NbvNV
,
632 (attrib_func
) VertexAttrib1NubvNV
,
633 (attrib_func
) VertexAttrib1NsvNV
,
634 (attrib_func
) VertexAttrib1NusvNV
,
635 (attrib_func
) VertexAttrib1NivNV
,
636 (attrib_func
) VertexAttrib1NuivNV
,
637 (attrib_func
) VertexAttrib1fvNV
,
638 (attrib_func
) VertexAttrib1dvNV
642 (attrib_func
) VertexAttrib2NbvNV
,
643 (attrib_func
) VertexAttrib2NubvNV
,
644 (attrib_func
) VertexAttrib2NsvNV
,
645 (attrib_func
) VertexAttrib2NusvNV
,
646 (attrib_func
) VertexAttrib2NivNV
,
647 (attrib_func
) VertexAttrib2NuivNV
,
648 (attrib_func
) VertexAttrib2fvNV
,
649 (attrib_func
) VertexAttrib2dvNV
653 (attrib_func
) VertexAttrib3NbvNV
,
654 (attrib_func
) VertexAttrib3NubvNV
,
655 (attrib_func
) VertexAttrib3NsvNV
,
656 (attrib_func
) VertexAttrib3NusvNV
,
657 (attrib_func
) VertexAttrib3NivNV
,
658 (attrib_func
) VertexAttrib3NuivNV
,
659 (attrib_func
) VertexAttrib3fvNV
,
660 (attrib_func
) VertexAttrib3dvNV
664 (attrib_func
) VertexAttrib4NbvNV
,
665 (attrib_func
) VertexAttrib4NubvNV
,
666 (attrib_func
) VertexAttrib4NsvNV
,
667 (attrib_func
) VertexAttrib4NusvNV
,
668 (attrib_func
) VertexAttrib4NivNV
,
669 (attrib_func
) VertexAttrib4NuivNV
,
670 (attrib_func
) VertexAttrib4fvNV
,
671 (attrib_func
) VertexAttrib4dvNV
676 /**********************************************************************/
679 GLboolean
_ae_create_context( struct gl_context
*ctx
)
681 if (ctx
->aelt_context
)
684 /* These _gloffset_* values may not be compile-time constants */
685 SecondaryColorFuncs
[0] = _gloffset_SecondaryColor3bvEXT
;
686 SecondaryColorFuncs
[1] = _gloffset_SecondaryColor3ubvEXT
;
687 SecondaryColorFuncs
[2] = _gloffset_SecondaryColor3svEXT
;
688 SecondaryColorFuncs
[3] = _gloffset_SecondaryColor3usvEXT
;
689 SecondaryColorFuncs
[4] = _gloffset_SecondaryColor3ivEXT
;
690 SecondaryColorFuncs
[5] = _gloffset_SecondaryColor3uivEXT
;
691 SecondaryColorFuncs
[6] = _gloffset_SecondaryColor3fvEXT
;
692 SecondaryColorFuncs
[7] = _gloffset_SecondaryColor3dvEXT
;
694 FogCoordFuncs
[0] = -1;
695 FogCoordFuncs
[1] = -1;
696 FogCoordFuncs
[2] = -1;
697 FogCoordFuncs
[3] = -1;
698 FogCoordFuncs
[4] = -1;
699 FogCoordFuncs
[5] = -1;
700 FogCoordFuncs
[6] = _gloffset_FogCoordfvEXT
;
701 FogCoordFuncs
[7] = _gloffset_FogCoorddvEXT
;
703 ctx
->aelt_context
= CALLOC( sizeof(AEcontext
) );
704 if (!ctx
->aelt_context
)
707 AE_CONTEXT(ctx
)->NewState
= ~0;
712 void _ae_destroy_context( struct gl_context
*ctx
)
714 if ( AE_CONTEXT( ctx
) ) {
715 FREE( ctx
->aelt_context
);
716 ctx
->aelt_context
= NULL
;
720 static void check_vbo( AEcontext
*actx
,
721 struct gl_buffer_object
*vbo
)
723 if (_mesa_is_bufferobj(vbo
) && !_mesa_bufferobj_mapped(vbo
)) {
725 for (i
= 0; i
< actx
->nr_vbos
; i
++)
726 if (actx
->vbo
[i
] == vbo
)
728 assert(actx
->nr_vbos
< VERT_ATTRIB_MAX
);
729 actx
->vbo
[actx
->nr_vbos
++] = vbo
;
735 * Make a list of per-vertex functions to call for each glArrayElement call.
736 * These functions access the array data (i.e. glVertex, glColor, glNormal,
738 * Note: this may be called during display list construction.
740 static void _ae_update_state( struct gl_context
*ctx
)
742 AEcontext
*actx
= AE_CONTEXT(ctx
);
743 AEarray
*aa
= actx
->arrays
;
744 AEattrib
*at
= actx
->attribs
;
745 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
749 /* conventional vertex arrays */
750 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
) {
751 aa
->array
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
];
752 aa
->offset
= IndexFuncs
[TYPE_IDX(aa
->array
->Type
)];
753 check_vbo(actx
, aa
->array
->BufferObj
);
756 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
) {
757 aa
->array
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
];
758 aa
->offset
= _gloffset_EdgeFlagv
;
759 check_vbo(actx
, aa
->array
->BufferObj
);
762 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
) {
763 aa
->array
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
];
764 aa
->offset
= NormalFuncs
[TYPE_IDX(aa
->array
->Type
)];
765 check_vbo(actx
, aa
->array
->BufferObj
);
768 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
) {
769 aa
->array
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
];
770 aa
->offset
= ColorFuncs
[aa
->array
->Size
-3][TYPE_IDX(aa
->array
->Type
)];
771 check_vbo(actx
, aa
->array
->BufferObj
);
774 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
) {
775 aa
->array
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
];
776 aa
->offset
= SecondaryColorFuncs
[TYPE_IDX(aa
->array
->Type
)];
777 check_vbo(actx
, aa
->array
->BufferObj
);
780 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
) {
781 aa
->array
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
];
782 aa
->offset
= FogCoordFuncs
[TYPE_IDX(aa
->array
->Type
)];
783 check_vbo(actx
, aa
->array
->BufferObj
);
787 struct gl_client_array
*attribArray
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_TEX
];
788 if (attribArray
->Enabled
) {
789 /* NOTE: we use generic glVertexAttribNV functions here.
790 * If we ever remove GL_NV_vertex_program this will have to change.
792 at
->array
= attribArray
;
793 ASSERT(!at
->array
->Normalized
);
794 at
->func
= AttribFuncsNV
[at
->array
->Normalized
]
796 [TYPE_IDX(at
->array
->Type
)];
797 at
->index
= VERT_ATTRIB_TEX
;
798 check_vbo(actx
, at
->array
->BufferObj
);
803 /* finally, vertex position */
804 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
) {
805 aa
->array
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
];
806 aa
->offset
= VertexFuncs
[aa
->array
->Size
-2][TYPE_IDX(aa
->array
->Type
)];
807 check_vbo(actx
, aa
->array
->BufferObj
);
811 check_vbo(actx
, arrayObj
->ElementArrayBufferObj
);
813 ASSERT(at
- actx
->attribs
<= VERT_ATTRIB_MAX
);
814 ASSERT(aa
- actx
->arrays
< 32);
815 at
->func
= NULL
; /* terminate the list */
816 aa
->offset
= -1; /* terminate the list */
821 void _ae_map_vbos( struct gl_context
*ctx
)
823 AEcontext
*actx
= AE_CONTEXT(ctx
);
826 if (actx
->mapped_vbos
)
830 _ae_update_state(ctx
);
832 for (i
= 0; i
< actx
->nr_vbos
; i
++)
833 ctx
->Driver
.MapBufferRange(ctx
, 0,
839 actx
->mapped_vbos
= GL_TRUE
;
842 void _ae_unmap_vbos( struct gl_context
*ctx
)
844 AEcontext
*actx
= AE_CONTEXT(ctx
);
847 if (!actx
->mapped_vbos
)
850 assert (!actx
->NewState
);
852 for (i
= 0; i
< actx
->nr_vbos
; i
++)
853 ctx
->Driver
.UnmapBuffer(ctx
, actx
->vbo
[i
]);
855 actx
->mapped_vbos
= GL_FALSE
;
860 * Called via glArrayElement() and glDrawArrays().
861 * Issue the glNormal, glVertex, glColor, glVertexAttrib, etc functions
862 * for all enabled vertex arrays (for elt-th element).
863 * Note: this may be called during display list construction.
865 void GLAPIENTRY
_ae_ArrayElement( GLint elt
)
867 GET_CURRENT_CONTEXT(ctx
);
868 const AEcontext
*actx
= AE_CONTEXT(ctx
);
871 const struct _glapi_table
* const disp
= GET_DISPATCH();
874 if (actx
->NewState
) {
875 assert(!actx
->mapped_vbos
);
876 _ae_update_state( ctx
);
879 /* Determine if we need to map/unmap VBOs */
880 do_map
= actx
->nr_vbos
&& !actx
->mapped_vbos
;
885 /* emit generic attribute elements */
886 for (at
= actx
->attribs
; at
->func
; at
++) {
888 = ADD_POINTERS(at
->array
->BufferObj
->Pointer
, at
->array
->Ptr
)
889 + elt
* at
->array
->StrideB
;
890 at
->func( at
->index
, src
);
893 /* emit conventional arrays elements */
894 for (aa
= actx
->arrays
; aa
->offset
!= -1 ; aa
++) {
896 = ADD_POINTERS(aa
->array
->BufferObj
->Pointer
, aa
->array
->Ptr
)
897 + elt
* aa
->array
->StrideB
;
898 CALL_by_offset( disp
, (array_func
), aa
->offset
,
899 ((const void *) src
) );
907 void _ae_invalidate_state( struct gl_context
*ctx
, GLuint new_state
)
909 AEcontext
*actx
= AE_CONTEXT(ctx
);
912 /* Only interested in this subset of mesa state. Need to prune
913 * this down as both tnl/ and the drivers can raise statechanges
914 * for arcane reasons in the middle of seemingly atomic operations
915 * like DrawElements, over which we'd like to keep a known set of
916 * arrays and vbo's mapped.
918 * Luckily, neither the drivers nor tnl muck with the state that
921 new_state
&= _NEW_ARRAY
;
923 assert(!actx
->mapped_vbos
);
924 actx
->NewState
|= new_state
;
929 void _mesa_install_arrayelt_vtxfmt(struct _glapi_table
*disp
,
930 const GLvertexformat
*vfmt
)
932 SET_ArrayElement(disp
, vfmt
->ArrayElement
);
936 #endif /* FEATURE_arrayelt */