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>
39 typedef void (GLAPIENTRY
*array_func
)( const void * );
42 const struct gl_client_array
*array
;
46 typedef void (GLAPIENTRY
*attrib_func
)( GLuint indx
, const void *data
);
49 const struct gl_client_array
*array
;
56 AEattrib attribs
[VERT_ATTRIB_MAX
+ 1];
59 struct gl_buffer_object
*vbo
[VERT_ATTRIB_MAX
];
61 GLboolean mapped_vbos
;
65 #define AE_CONTEXT(ctx) ((AEcontext *)(ctx)->aelt_context)
69 * Convert GL_BYTE, GL_UNSIGNED_BYTE, .. GL_DOUBLE into an integer
70 * in the range [0, 7]. Luckily these type tokens are sequentially
71 * numbered in gl.h, except for GL_DOUBLE.
73 #define TYPE_IDX(t) ( (t) == GL_DOUBLE ? 7 : (t) & 7 )
81 static const int ColorFuncs
[2][NUM_TYPES
] = {
104 static const int VertexFuncs
[3][NUM_TYPES
] = {
137 static const int IndexFuncs
[NUM_TYPES
] = {
148 static const int NormalFuncs
[NUM_TYPES
] = {
159 /* Note: _gloffset_* for these may not be a compile-time constant. */
160 static int SecondaryColorFuncs
[NUM_TYPES
];
161 static int FogCoordFuncs
[NUM_TYPES
];
165 ** GL_NV_vertex_program
168 /* GL_BYTE attributes */
170 static void GLAPIENTRY
171 VertexAttrib1NbvNV(GLuint index
, const GLbyte
*v
)
173 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, BYTE_TO_FLOAT(v
[0])));
176 static void GLAPIENTRY
177 VertexAttrib1bvNV(GLuint index
, const GLbyte
*v
)
179 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0]));
182 static void GLAPIENTRY
183 VertexAttrib2NbvNV(GLuint index
, const GLbyte
*v
)
185 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, BYTE_TO_FLOAT(v
[0]), BYTE_TO_FLOAT(v
[1])));
188 static void GLAPIENTRY
189 VertexAttrib2bvNV(GLuint index
, const GLbyte
*v
)
191 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1]));
194 static void GLAPIENTRY
195 VertexAttrib3NbvNV(GLuint index
, const GLbyte
*v
)
197 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, BYTE_TO_FLOAT(v
[0]),
199 BYTE_TO_FLOAT(v
[2])));
202 static void GLAPIENTRY
203 VertexAttrib3bvNV(GLuint index
, const GLbyte
*v
)
205 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1], (GLfloat
)v
[2]));
208 static void GLAPIENTRY
209 VertexAttrib4NbvNV(GLuint index
, const GLbyte
*v
)
211 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, BYTE_TO_FLOAT(v
[0]),
214 BYTE_TO_FLOAT(v
[3])));
217 static void GLAPIENTRY
218 VertexAttrib4bvNV(GLuint index
, const GLbyte
*v
)
220 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1], (GLfloat
)v
[2], (GLfloat
)v
[3]));
223 /* GL_UNSIGNED_BYTE attributes */
225 static void GLAPIENTRY
226 VertexAttrib1NubvNV(GLuint index
, const GLubyte
*v
)
228 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, UBYTE_TO_FLOAT(v
[0])));
231 static void GLAPIENTRY
232 VertexAttrib1ubvNV(GLuint index
, const GLubyte
*v
)
234 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0]));
237 static void GLAPIENTRY
238 VertexAttrib2NubvNV(GLuint index
, const GLubyte
*v
)
240 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, UBYTE_TO_FLOAT(v
[0]),
241 UBYTE_TO_FLOAT(v
[1])));
244 static void GLAPIENTRY
245 VertexAttrib2ubvNV(GLuint index
, const GLubyte
*v
)
247 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1]));
250 static void GLAPIENTRY
251 VertexAttrib3NubvNV(GLuint index
, const GLubyte
*v
)
253 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, UBYTE_TO_FLOAT(v
[0]),
254 UBYTE_TO_FLOAT(v
[1]),
255 UBYTE_TO_FLOAT(v
[2])));
257 static void GLAPIENTRY
258 VertexAttrib3ubvNV(GLuint index
, const GLubyte
*v
)
260 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0],
261 (GLfloat
)v
[1], (GLfloat
)v
[2]));
264 static void GLAPIENTRY
265 VertexAttrib4NubvNV(GLuint index
, const GLubyte
*v
)
267 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, UBYTE_TO_FLOAT(v
[0]),
268 UBYTE_TO_FLOAT(v
[1]),
269 UBYTE_TO_FLOAT(v
[2]),
270 UBYTE_TO_FLOAT(v
[3])));
273 static void GLAPIENTRY
274 VertexAttrib4ubvNV(GLuint index
, const GLubyte
*v
)
276 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0],
277 (GLfloat
)v
[1], (GLfloat
)v
[2],
281 /* GL_SHORT attributes */
283 static void GLAPIENTRY
284 VertexAttrib1NsvNV(GLuint index
, const GLshort
*v
)
286 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, SHORT_TO_FLOAT(v
[0])));
289 static void GLAPIENTRY
290 VertexAttrib1svNV(GLuint index
, const GLshort
*v
)
292 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0]));
295 static void GLAPIENTRY
296 VertexAttrib2NsvNV(GLuint index
, const GLshort
*v
)
298 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, SHORT_TO_FLOAT(v
[0]),
299 SHORT_TO_FLOAT(v
[1])));
302 static void GLAPIENTRY
303 VertexAttrib2svNV(GLuint index
, const GLshort
*v
)
305 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1]));
308 static void GLAPIENTRY
309 VertexAttrib3NsvNV(GLuint index
, const GLshort
*v
)
311 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, SHORT_TO_FLOAT(v
[0]),
312 SHORT_TO_FLOAT(v
[1]),
313 SHORT_TO_FLOAT(v
[2])));
316 static void GLAPIENTRY
317 VertexAttrib3svNV(GLuint index
, const GLshort
*v
)
319 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1],
323 static void GLAPIENTRY
324 VertexAttrib4NsvNV(GLuint index
, const GLshort
*v
)
326 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, SHORT_TO_FLOAT(v
[0]),
327 SHORT_TO_FLOAT(v
[1]),
328 SHORT_TO_FLOAT(v
[2]),
329 SHORT_TO_FLOAT(v
[3])));
332 static void GLAPIENTRY
333 VertexAttrib4svNV(GLuint index
, const GLshort
*v
)
335 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1],
336 (GLfloat
)v
[2], (GLfloat
)v
[3]));
339 /* GL_UNSIGNED_SHORT attributes */
341 static void GLAPIENTRY
342 VertexAttrib1NusvNV(GLuint index
, const GLushort
*v
)
344 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, USHORT_TO_FLOAT(v
[0])));
347 static void GLAPIENTRY
348 VertexAttrib1usvNV(GLuint index
, const GLushort
*v
)
350 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0]));
353 static void GLAPIENTRY
354 VertexAttrib2NusvNV(GLuint index
, const GLushort
*v
)
356 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, USHORT_TO_FLOAT(v
[0]),
357 USHORT_TO_FLOAT(v
[1])));
360 static void GLAPIENTRY
361 VertexAttrib2usvNV(GLuint index
, const GLushort
*v
)
363 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0],
367 static void GLAPIENTRY
368 VertexAttrib3NusvNV(GLuint index
, const GLushort
*v
)
370 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, USHORT_TO_FLOAT(v
[0]),
371 USHORT_TO_FLOAT(v
[1]),
372 USHORT_TO_FLOAT(v
[2])));
375 static void GLAPIENTRY
376 VertexAttrib3usvNV(GLuint index
, const GLushort
*v
)
378 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1],
382 static void GLAPIENTRY
383 VertexAttrib4NusvNV(GLuint index
, const GLushort
*v
)
385 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, USHORT_TO_FLOAT(v
[0]),
386 USHORT_TO_FLOAT(v
[1]),
387 USHORT_TO_FLOAT(v
[2]),
388 USHORT_TO_FLOAT(v
[3])));
391 static void GLAPIENTRY
392 VertexAttrib4usvNV(GLuint index
, const GLushort
*v
)
394 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1],
395 (GLfloat
)v
[2], (GLfloat
)v
[3]));
398 /* GL_INT attributes */
400 static void GLAPIENTRY
401 VertexAttrib1NivNV(GLuint index
, const GLint
*v
)
403 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, INT_TO_FLOAT(v
[0])));
406 static void GLAPIENTRY
407 VertexAttrib1ivNV(GLuint index
, const GLint
*v
)
409 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0]));
412 static void GLAPIENTRY
413 VertexAttrib2NivNV(GLuint index
, const GLint
*v
)
415 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, INT_TO_FLOAT(v
[0]),
416 INT_TO_FLOAT(v
[1])));
419 static void GLAPIENTRY
420 VertexAttrib2ivNV(GLuint index
, const GLint
*v
)
422 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1]));
425 static void GLAPIENTRY
426 VertexAttrib3NivNV(GLuint index
, const GLint
*v
)
428 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, INT_TO_FLOAT(v
[0]),
430 INT_TO_FLOAT(v
[2])));
433 static void GLAPIENTRY
434 VertexAttrib3ivNV(GLuint index
, const GLint
*v
)
436 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1],
440 static void GLAPIENTRY
441 VertexAttrib4NivNV(GLuint index
, const GLint
*v
)
443 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, INT_TO_FLOAT(v
[0]),
446 INT_TO_FLOAT(v
[3])));
449 static void GLAPIENTRY
450 VertexAttrib4ivNV(GLuint index
, const GLint
*v
)
452 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1],
453 (GLfloat
)v
[2], (GLfloat
)v
[3]));
456 /* GL_UNSIGNED_INT attributes */
458 static void GLAPIENTRY
459 VertexAttrib1NuivNV(GLuint index
, const GLuint
*v
)
461 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, UINT_TO_FLOAT(v
[0])));
464 static void GLAPIENTRY
465 VertexAttrib1uivNV(GLuint index
, const GLuint
*v
)
467 CALL_VertexAttrib1fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0]));
470 static void GLAPIENTRY
471 VertexAttrib2NuivNV(GLuint index
, const GLuint
*v
)
473 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, UINT_TO_FLOAT(v
[0]),
474 UINT_TO_FLOAT(v
[1])));
477 static void GLAPIENTRY
478 VertexAttrib2uivNV(GLuint index
, const GLuint
*v
)
480 CALL_VertexAttrib2fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0],
484 static void GLAPIENTRY
485 VertexAttrib3NuivNV(GLuint index
, const GLuint
*v
)
487 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, UINT_TO_FLOAT(v
[0]),
489 UINT_TO_FLOAT(v
[2])));
492 static void GLAPIENTRY
493 VertexAttrib3uivNV(GLuint index
, const GLuint
*v
)
495 CALL_VertexAttrib3fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1],
499 static void GLAPIENTRY
500 VertexAttrib4NuivNV(GLuint index
, const GLuint
*v
)
502 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, UINT_TO_FLOAT(v
[0]),
505 UINT_TO_FLOAT(v
[3])));
508 static void GLAPIENTRY
509 VertexAttrib4uivNV(GLuint index
, const GLuint
*v
)
511 CALL_VertexAttrib4fNV(GET_DISPATCH(), (index
, (GLfloat
)v
[0], (GLfloat
)v
[1],
512 (GLfloat
)v
[2], (GLfloat
)v
[3]));
515 /* GL_FLOAT attributes */
517 static void GLAPIENTRY
518 VertexAttrib1fvNV(GLuint index
, const GLfloat
*v
)
520 CALL_VertexAttrib1fvNV(GET_DISPATCH(), (index
, v
));
523 static void GLAPIENTRY
524 VertexAttrib2fvNV(GLuint index
, const GLfloat
*v
)
526 CALL_VertexAttrib2fvNV(GET_DISPATCH(), (index
, v
));
529 static void GLAPIENTRY
530 VertexAttrib3fvNV(GLuint index
, const GLfloat
*v
)
532 CALL_VertexAttrib3fvNV(GET_DISPATCH(), (index
, v
));
535 static void GLAPIENTRY
536 VertexAttrib4fvNV(GLuint index
, const GLfloat
*v
)
538 CALL_VertexAttrib4fvNV(GET_DISPATCH(), (index
, v
));
541 /* GL_DOUBLE attributes */
543 static void GLAPIENTRY
544 VertexAttrib1dvNV(GLuint index
, const GLdouble
*v
)
546 CALL_VertexAttrib1dvNV(GET_DISPATCH(), (index
, v
));
549 static void GLAPIENTRY
550 VertexAttrib2dvNV(GLuint index
, const GLdouble
*v
)
552 CALL_VertexAttrib2dvNV(GET_DISPATCH(), (index
, v
));
555 static void GLAPIENTRY
556 VertexAttrib3dvNV(GLuint index
, const GLdouble
*v
)
558 CALL_VertexAttrib3dvNV(GET_DISPATCH(), (index
, v
));
561 static void GLAPIENTRY
562 VertexAttrib4dvNV(GLuint index
, const GLdouble
*v
)
564 CALL_VertexAttrib4dvNV(GET_DISPATCH(), (index
, v
));
569 * Array [size][type] of VertexAttrib functions
571 static attrib_func AttribFuncsNV
[2][4][NUM_TYPES
] = {
576 (attrib_func
) VertexAttrib1bvNV
,
577 (attrib_func
) VertexAttrib1ubvNV
,
578 (attrib_func
) VertexAttrib1svNV
,
579 (attrib_func
) VertexAttrib1usvNV
,
580 (attrib_func
) VertexAttrib1ivNV
,
581 (attrib_func
) VertexAttrib1uivNV
,
582 (attrib_func
) VertexAttrib1fvNV
,
583 (attrib_func
) VertexAttrib1dvNV
587 (attrib_func
) VertexAttrib2bvNV
,
588 (attrib_func
) VertexAttrib2ubvNV
,
589 (attrib_func
) VertexAttrib2svNV
,
590 (attrib_func
) VertexAttrib2usvNV
,
591 (attrib_func
) VertexAttrib2ivNV
,
592 (attrib_func
) VertexAttrib2uivNV
,
593 (attrib_func
) VertexAttrib2fvNV
,
594 (attrib_func
) VertexAttrib2dvNV
598 (attrib_func
) VertexAttrib3bvNV
,
599 (attrib_func
) VertexAttrib3ubvNV
,
600 (attrib_func
) VertexAttrib3svNV
,
601 (attrib_func
) VertexAttrib3usvNV
,
602 (attrib_func
) VertexAttrib3ivNV
,
603 (attrib_func
) VertexAttrib3uivNV
,
604 (attrib_func
) VertexAttrib3fvNV
,
605 (attrib_func
) VertexAttrib3dvNV
609 (attrib_func
) VertexAttrib4bvNV
,
610 (attrib_func
) VertexAttrib4ubvNV
,
611 (attrib_func
) VertexAttrib4svNV
,
612 (attrib_func
) VertexAttrib4usvNV
,
613 (attrib_func
) VertexAttrib4ivNV
,
614 (attrib_func
) VertexAttrib4uivNV
,
615 (attrib_func
) VertexAttrib4fvNV
,
616 (attrib_func
) VertexAttrib4dvNV
620 /* normalized (except for float/double) */
623 (attrib_func
) VertexAttrib1NbvNV
,
624 (attrib_func
) VertexAttrib1NubvNV
,
625 (attrib_func
) VertexAttrib1NsvNV
,
626 (attrib_func
) VertexAttrib1NusvNV
,
627 (attrib_func
) VertexAttrib1NivNV
,
628 (attrib_func
) VertexAttrib1NuivNV
,
629 (attrib_func
) VertexAttrib1fvNV
,
630 (attrib_func
) VertexAttrib1dvNV
634 (attrib_func
) VertexAttrib2NbvNV
,
635 (attrib_func
) VertexAttrib2NubvNV
,
636 (attrib_func
) VertexAttrib2NsvNV
,
637 (attrib_func
) VertexAttrib2NusvNV
,
638 (attrib_func
) VertexAttrib2NivNV
,
639 (attrib_func
) VertexAttrib2NuivNV
,
640 (attrib_func
) VertexAttrib2fvNV
,
641 (attrib_func
) VertexAttrib2dvNV
645 (attrib_func
) VertexAttrib3NbvNV
,
646 (attrib_func
) VertexAttrib3NubvNV
,
647 (attrib_func
) VertexAttrib3NsvNV
,
648 (attrib_func
) VertexAttrib3NusvNV
,
649 (attrib_func
) VertexAttrib3NivNV
,
650 (attrib_func
) VertexAttrib3NuivNV
,
651 (attrib_func
) VertexAttrib3fvNV
,
652 (attrib_func
) VertexAttrib3dvNV
656 (attrib_func
) VertexAttrib4NbvNV
,
657 (attrib_func
) VertexAttrib4NubvNV
,
658 (attrib_func
) VertexAttrib4NsvNV
,
659 (attrib_func
) VertexAttrib4NusvNV
,
660 (attrib_func
) VertexAttrib4NivNV
,
661 (attrib_func
) VertexAttrib4NuivNV
,
662 (attrib_func
) VertexAttrib4fvNV
,
663 (attrib_func
) VertexAttrib4dvNV
668 /**********************************************************************/
671 GLboolean
_ae_create_context( struct gl_context
*ctx
)
673 if (ctx
->aelt_context
)
676 /* These _gloffset_* values may not be compile-time constants */
677 SecondaryColorFuncs
[0] = _gloffset_SecondaryColor3bvEXT
;
678 SecondaryColorFuncs
[1] = _gloffset_SecondaryColor3ubvEXT
;
679 SecondaryColorFuncs
[2] = _gloffset_SecondaryColor3svEXT
;
680 SecondaryColorFuncs
[3] = _gloffset_SecondaryColor3usvEXT
;
681 SecondaryColorFuncs
[4] = _gloffset_SecondaryColor3ivEXT
;
682 SecondaryColorFuncs
[5] = _gloffset_SecondaryColor3uivEXT
;
683 SecondaryColorFuncs
[6] = _gloffset_SecondaryColor3fvEXT
;
684 SecondaryColorFuncs
[7] = _gloffset_SecondaryColor3dvEXT
;
686 FogCoordFuncs
[0] = -1;
687 FogCoordFuncs
[1] = -1;
688 FogCoordFuncs
[2] = -1;
689 FogCoordFuncs
[3] = -1;
690 FogCoordFuncs
[4] = -1;
691 FogCoordFuncs
[5] = -1;
692 FogCoordFuncs
[6] = _gloffset_FogCoordfvEXT
;
693 FogCoordFuncs
[7] = _gloffset_FogCoorddvEXT
;
695 ctx
->aelt_context
= CALLOC( sizeof(AEcontext
) );
696 if (!ctx
->aelt_context
)
699 AE_CONTEXT(ctx
)->NewState
= ~0;
704 void _ae_destroy_context( struct gl_context
*ctx
)
706 if ( AE_CONTEXT( ctx
) ) {
707 FREE( ctx
->aelt_context
);
708 ctx
->aelt_context
= NULL
;
712 static void check_vbo( AEcontext
*actx
,
713 struct gl_buffer_object
*vbo
)
715 if (_mesa_is_bufferobj(vbo
) && !_mesa_bufferobj_mapped(vbo
)) {
717 for (i
= 0; i
< actx
->nr_vbos
; i
++)
718 if (actx
->vbo
[i
] == vbo
)
720 assert(actx
->nr_vbos
< VERT_ATTRIB_MAX
);
721 actx
->vbo
[actx
->nr_vbos
++] = vbo
;
727 * Make a list of per-vertex functions to call for each glArrayElement call.
728 * These functions access the array data (i.e. glVertex, glColor, glNormal,
730 * Note: this may be called during display list construction.
732 static void _ae_update_state( struct gl_context
*ctx
)
734 AEcontext
*actx
= AE_CONTEXT(ctx
);
735 AEarray
*aa
= actx
->arrays
;
736 AEattrib
*at
= actx
->attribs
;
737 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
741 /* conventional vertex arrays */
742 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
) {
743 aa
->array
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
];
744 aa
->offset
= IndexFuncs
[TYPE_IDX(aa
->array
->Type
)];
745 check_vbo(actx
, aa
->array
->BufferObj
);
748 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
) {
749 aa
->array
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
];
750 aa
->offset
= _gloffset_EdgeFlagv
;
751 check_vbo(actx
, aa
->array
->BufferObj
);
754 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
) {
755 aa
->array
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
];
756 aa
->offset
= NormalFuncs
[TYPE_IDX(aa
->array
->Type
)];
757 check_vbo(actx
, aa
->array
->BufferObj
);
760 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
) {
761 aa
->array
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
];
762 aa
->offset
= ColorFuncs
[aa
->array
->Size
-3][TYPE_IDX(aa
->array
->Type
)];
763 check_vbo(actx
, aa
->array
->BufferObj
);
766 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
) {
767 aa
->array
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
];
768 aa
->offset
= SecondaryColorFuncs
[TYPE_IDX(aa
->array
->Type
)];
769 check_vbo(actx
, aa
->array
->BufferObj
);
772 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
) {
773 aa
->array
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
];
774 aa
->offset
= FogCoordFuncs
[TYPE_IDX(aa
->array
->Type
)];
775 check_vbo(actx
, aa
->array
->BufferObj
);
779 struct gl_client_array
*attribArray
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_TEX
];
780 if (attribArray
->Enabled
) {
781 /* NOTE: we use generic glVertexAttribNV functions here.
782 * If we ever remove GL_NV_vertex_program this will have to change.
784 at
->array
= attribArray
;
785 ASSERT(!at
->array
->Normalized
);
786 at
->func
= AttribFuncsNV
[at
->array
->Normalized
]
788 [TYPE_IDX(at
->array
->Type
)];
789 at
->index
= VERT_ATTRIB_TEX
;
790 check_vbo(actx
, at
->array
->BufferObj
);
795 /* finally, vertex position */
796 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
) {
797 aa
->array
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
];
798 aa
->offset
= VertexFuncs
[aa
->array
->Size
-2][TYPE_IDX(aa
->array
->Type
)];
799 check_vbo(actx
, aa
->array
->BufferObj
);
803 check_vbo(actx
, arrayObj
->ElementArrayBufferObj
);
805 ASSERT(at
- actx
->attribs
<= VERT_ATTRIB_MAX
);
806 ASSERT(aa
- actx
->arrays
< 32);
807 at
->func
= NULL
; /* terminate the list */
808 aa
->offset
= -1; /* terminate the list */
813 void _ae_map_vbos( struct gl_context
*ctx
)
815 AEcontext
*actx
= AE_CONTEXT(ctx
);
818 if (actx
->mapped_vbos
)
822 _ae_update_state(ctx
);
824 for (i
= 0; i
< actx
->nr_vbos
; i
++)
825 ctx
->Driver
.MapBufferRange(ctx
, 0,
831 actx
->mapped_vbos
= GL_TRUE
;
834 void _ae_unmap_vbos( struct gl_context
*ctx
)
836 AEcontext
*actx
= AE_CONTEXT(ctx
);
839 if (!actx
->mapped_vbos
)
842 assert (!actx
->NewState
);
844 for (i
= 0; i
< actx
->nr_vbos
; i
++)
845 ctx
->Driver
.UnmapBuffer(ctx
, actx
->vbo
[i
]);
847 actx
->mapped_vbos
= GL_FALSE
;
852 * Called via glArrayElement() and glDrawArrays().
853 * Issue the glNormal, glVertex, glColor, glVertexAttrib, etc functions
854 * for all enabled vertex arrays (for elt-th element).
855 * Note: this may be called during display list construction.
857 void GLAPIENTRY
_ae_ArrayElement( GLint elt
)
859 GET_CURRENT_CONTEXT(ctx
);
860 const AEcontext
*actx
= AE_CONTEXT(ctx
);
863 const struct _glapi_table
* const disp
= GET_DISPATCH();
866 if (actx
->NewState
) {
867 assert(!actx
->mapped_vbos
);
868 _ae_update_state( ctx
);
871 /* Determine if we need to map/unmap VBOs */
872 do_map
= actx
->nr_vbos
&& !actx
->mapped_vbos
;
877 /* emit generic attribute elements */
878 for (at
= actx
->attribs
; at
->func
; at
++) {
880 = ADD_POINTERS(at
->array
->BufferObj
->Pointer
, at
->array
->Ptr
)
881 + elt
* at
->array
->StrideB
;
882 at
->func( at
->index
, src
);
885 /* emit conventional arrays elements */
886 for (aa
= actx
->arrays
; aa
->offset
!= -1 ; aa
++) {
888 = ADD_POINTERS(aa
->array
->BufferObj
->Pointer
, aa
->array
->Ptr
)
889 + elt
* aa
->array
->StrideB
;
890 CALL_by_offset( disp
, (array_func
), aa
->offset
,
891 ((const void *) src
) );
899 void _ae_invalidate_state( struct gl_context
*ctx
, GLuint new_state
)
901 AEcontext
*actx
= AE_CONTEXT(ctx
);
904 /* Only interested in this subset of mesa state. Need to prune
905 * this down as both tnl/ and the drivers can raise statechanges
906 * for arcane reasons in the middle of seemingly atomic operations
907 * like DrawElements, over which we'd like to keep a known set of
908 * arrays and vbo's mapped.
910 * Luckily, neither the drivers nor tnl muck with the state that
913 new_state
&= _NEW_ARRAY
;
915 assert(!actx
->mapped_vbos
);
916 actx
->NewState
|= new_state
;
921 void _mesa_install_arrayelt_vtxfmt(struct _glapi_table
*disp
,
922 const GLvertexformat
*vfmt
)
924 SET_ArrayElement(disp
, vfmt
->ArrayElement
);
928 #endif /* FEATURE_arrayelt */