2 /**************************************************************************
4 Copyright 2002 Tungsten Graphics Inc., Cedar Park, Texas.
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the "Software"),
10 to deal in the Software without restriction, including without limitation
11 on the rights to use, copy, modify, merge, publish, distribute, sub
12 license, and/or sell copies of the Software, and to permit persons to whom
13 the Software is furnished to do so, subject to the following conditions:
15 The above copyright notice and this permission notice (including the next
16 paragraph) shall be included in all copies or substantial portions of the
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
23 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
31 * Keith Whitwell <keith@tungstengraphics.com>
36 /* Display list compiler attempts to store lists of vertices with the
37 * same vertex layout. Additionally it attempts to minimize the need
38 * for execute-time fixup of these vertex lists, allowing them to be
41 * There are still some circumstances where this can be thwarted, for
42 * example by building a list that consists of one very long primitive
43 * (eg Begin(Triangles), 1000 vertices, End), and calling that list
44 * from inside a different begin/end object (Begin(Lines), CallList,
47 * In that case the code will have to replay the list as individual
48 * commands through the Exec dispatch table, or fix up the copied
49 * vertices at execute-time.
51 * The other case where fixup is required is when a vertex attribute
52 * is introduced in the middle of a primitive. Eg:
54 * TexCoord1f() Vertex2f()
55 * TexCoord1f() Color3f() Vertex2f()
58 * If the current value of Color isn't known at compile-time, this
59 * primitive will require fixup.
62 * The list compiler currently doesn't attempt to compile lists
63 * containing EvalCoord or EvalPoint commands. On encountering one of
64 * these, compilation falls back to opcodes.
66 * This could be improved to fallback only when a mix of EvalCoord and
67 * Vertex commands are issued within a single primitive.
76 #include "api_validate.h"
77 #include "api_arrayelt.h"
79 #include "t_save_api.h"
82 * NOTE: Old 'parity' issue is gone, but copying can still be
83 * wrong-footed on replay.
85 static GLuint
_save_copy_vertices( GLcontext
*ctx
,
86 const struct tnl_vertex_list
*node
)
88 TNLcontext
*tnl
= TNL_CONTEXT( ctx
);
89 const struct tnl_prim
*prim
= &node
->prim
[node
->prim_count
-1];
90 GLuint nr
= prim
->count
;
91 GLuint sz
= tnl
->save
.vertex_size
;
92 const GLfloat
*src
= node
->buffer
+ prim
->start
* sz
;
93 GLfloat
*dst
= tnl
->save
.copied
.buffer
;
96 if (prim
->mode
& PRIM_END
)
99 switch( prim
->mode
& PRIM_MODE_MASK
)
105 for (i
= 0 ; i
< ovf
; i
++)
106 _mesa_memcpy( dst
+i
*sz
, src
+(nr
-ovf
+i
)*sz
, sz
*sizeof(GLfloat
) );
110 for (i
= 0 ; i
< ovf
; i
++)
111 _mesa_memcpy( dst
+i
*sz
, src
+(nr
-ovf
+i
)*sz
, sz
*sizeof(GLfloat
) );
115 for (i
= 0 ; i
< ovf
; i
++)
116 _mesa_memcpy( dst
+i
*sz
, src
+(nr
-ovf
+i
)*sz
, sz
*sizeof(GLfloat
) );
122 _mesa_memcpy( dst
, src
+(nr
-1)*sz
, sz
*sizeof(GLfloat
) );
126 case GL_TRIANGLE_FAN
:
131 _mesa_memcpy( dst
, src
+0, sz
*sizeof(GLfloat
) );
134 _mesa_memcpy( dst
, src
+0, sz
*sizeof(GLfloat
) );
135 _mesa_memcpy( dst
+sz
, src
+(nr
-1)*sz
, sz
*sizeof(GLfloat
) );
138 case GL_TRIANGLE_STRIP
:
141 case 0: ovf
= 0; break;
142 case 1: ovf
= 1; break;
143 default: ovf
= 2 + (nr
&1); break;
145 for (i
= 0 ; i
< ovf
; i
++)
146 _mesa_memcpy( dst
+i
*sz
, src
+(nr
-ovf
+i
)*sz
, sz
*sizeof(GLfloat
) );
156 build_normal_lengths( struct tnl_vertex_list
*node
)
160 GLfloat
*n
= node
->buffer
;
161 GLuint stride
= node
->vertex_size
;
162 GLuint count
= node
->count
;
164 len
= node
->normal_lengths
= (GLfloat
*) MALLOC( count
* sizeof(GLfloat
) );
168 /* Find the normal of the first vertex:
170 for (i
= 0 ; i
< _TNL_ATTRIB_NORMAL
; i
++)
171 n
+= node
->attrsz
[i
];
173 for (i
= 0 ; i
< count
; i
++, n
+= stride
) {
174 len
[i
] = LEN_3FV( n
);
175 if (len
[i
] > 0.0F
) len
[i
] = 1.0F
/ len
[i
];
179 static struct tnl_vertex_store
*alloc_vertex_store( GLcontext
*ctx
)
181 struct tnl_vertex_store
*store
= MALLOC_STRUCT(tnl_vertex_store
);
188 static struct tnl_primitive_store
*alloc_prim_store( GLcontext
*ctx
)
190 struct tnl_primitive_store
*store
= MALLOC_STRUCT(tnl_primitive_store
);
197 static void _save_reset_counters( GLcontext
*ctx
)
199 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
201 tnl
->save
.prim
= tnl
->save
.prim_store
->buffer
+ tnl
->save
.prim_store
->used
;
202 tnl
->save
.buffer
= (tnl
->save
.vertex_store
->buffer
+
203 tnl
->save
.vertex_store
->used
);
205 if (tnl
->save
.vertex_size
)
206 tnl
->save
.initial_counter
= ((SAVE_BUFFER_SIZE
-
207 tnl
->save
.vertex_store
->used
) /
208 tnl
->save
.vertex_size
);
210 tnl
->save
.initial_counter
= 0;
212 if (tnl
->save
.initial_counter
> ctx
->Const
.MaxArrayLockSize
)
213 tnl
->save
.initial_counter
= ctx
->Const
.MaxArrayLockSize
;
215 tnl
->save
.counter
= tnl
->save
.initial_counter
;
216 tnl
->save
.prim_count
= 0;
217 tnl
->save
.prim_max
= SAVE_PRIM_SIZE
- tnl
->save
.prim_store
->used
;
218 tnl
->save
.copied
.nr
= 0;
219 tnl
->save
.dangling_attr_ref
= 0;
223 /* Insert the active immediate struct onto the display list currently
226 static void _save_compile_vertex_list( GLcontext
*ctx
)
228 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
229 struct tnl_vertex_list
*node
;
231 /* Allocate space for this structure in the display list currently
234 node
= (struct tnl_vertex_list
*)
235 _mesa_alloc_instruction(ctx
, tnl
->save
.opcode_vertex_list
, sizeof(*node
));
240 /* Duplicate our template, increment refcounts to the storage structs:
242 _mesa_memcpy(node
->attrsz
, tnl
->save
.attrsz
, sizeof(node
->attrsz
));
243 node
->vertex_size
= tnl
->save
.vertex_size
;
244 node
->buffer
= tnl
->save
.buffer
;
245 node
->wrap_count
= tnl
->save
.copied
.nr
;
246 node
->count
= tnl
->save
.initial_counter
- tnl
->save
.counter
;
247 node
->prim
= tnl
->save
.prim
;
248 node
->prim_count
= tnl
->save
.prim_count
;
249 node
->vertex_store
= tnl
->save
.vertex_store
;
250 node
->prim_store
= tnl
->save
.prim_store
;
251 node
->dangling_attr_ref
= tnl
->save
.dangling_attr_ref
;
252 node
->normal_lengths
= 0;
254 node
->vertex_store
->refcount
++;
255 node
->prim_store
->refcount
++;
257 assert(node
->attrsz
[_TNL_ATTRIB_POS
] != 0 ||
260 /* Maybe calculate normal lengths:
262 if (tnl
->CalcDListNormalLengths
&&
263 node
->attrsz
[_TNL_ATTRIB_NORMAL
] == 3 &&
264 !node
->dangling_attr_ref
)
265 build_normal_lengths( node
);
267 tnl
->save
.vertex_store
->used
+= tnl
->save
.vertex_size
* node
->count
;
268 tnl
->save
.prim_store
->used
+= node
->prim_count
;
270 /* Decide whether the storage structs are full, or can be used for
271 * the next vertex lists as well.
273 if (tnl
->save
.vertex_store
->used
>
274 SAVE_BUFFER_SIZE
- 16 * (tnl
->save
.vertex_size
+ 4)) {
276 tnl
->save
.vertex_store
->refcount
--;
277 assert(tnl
->save
.vertex_store
->refcount
!= 0);
278 tnl
->save
.vertex_store
= alloc_vertex_store( ctx
);
279 tnl
->save
.vbptr
= tnl
->save
.vertex_store
->buffer
;
282 if (tnl
->save
.prim_store
->used
> SAVE_PRIM_SIZE
- 6) {
283 tnl
->save
.prim_store
->refcount
--;
284 assert(tnl
->save
.prim_store
->refcount
!= 0);
285 tnl
->save
.prim_store
= alloc_prim_store( ctx
);
288 /* Reset our structures for the next run of vertices:
290 _save_reset_counters( ctx
);
292 /* Copy duplicated vertices
294 tnl
->save
.copied
.nr
= _save_copy_vertices( ctx
, node
);
297 /* Deal with GL_COMPILE_AND_EXECUTE:
299 if (ctx
->ExecuteFlag
) {
300 _tnl_playback_vertex_list( ctx
, (void *) node
);
305 /* TODO -- If no new vertices have been stored, don't bother saving
308 static void _save_wrap_buffers( GLcontext
*ctx
)
310 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
311 GLint i
= tnl
->save
.prim_count
- 1;
314 assert(i
< (GLint
) tnl
->save
.prim_max
);
317 /* Close off in-progress primitive.
319 tnl
->save
.prim
[i
].count
= ((tnl
->save
.initial_counter
- tnl
->save
.counter
) -
320 tnl
->save
.prim
[i
].start
);
321 mode
= tnl
->save
.prim
[i
].mode
& ~(PRIM_BEGIN
|PRIM_END
);
323 /* store the copied vertices, and allocate a new list.
325 _save_compile_vertex_list( ctx
);
327 /* Restart interrupted primitive
329 tnl
->save
.prim
[0].mode
= mode
;
330 tnl
->save
.prim
[0].start
= 0;
331 tnl
->save
.prim
[0].count
= 0;
332 tnl
->save
.prim_count
= 1;
337 /* Called only when buffers are wrapped as the result of filling the
338 * vertex_store struct.
340 static void _save_wrap_filled_vertex( GLcontext
*ctx
)
342 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
343 GLfloat
*data
= tnl
->save
.copied
.buffer
;
346 /* Emit a glEnd to close off the last vertex list.
348 _save_wrap_buffers( ctx
);
350 /* Copy stored stored vertices to start of new list.
352 assert(tnl
->save
.counter
> tnl
->save
.copied
.nr
);
354 for (i
= 0 ; i
< tnl
->save
.copied
.nr
; i
++) {
355 _mesa_memcpy( tnl
->save
.vbptr
, data
, tnl
->save
.vertex_size
* sizeof(GLfloat
));
356 data
+= tnl
->save
.vertex_size
;
357 tnl
->save
.vbptr
+= tnl
->save
.vertex_size
;
363 static void _save_copy_to_current( GLcontext
*ctx
)
365 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
368 for (i
= _TNL_ATTRIB_POS
+1 ; i
<= _TNL_ATTRIB_INDEX
; i
++) {
369 if (tnl
->save
.attrsz
[i
]) {
370 tnl
->save
.currentsz
[i
][0] = tnl
->save
.attrsz
[i
];
371 ASSIGN_4V(tnl
->save
.current
[i
], 0, 0, 0, 1);
372 COPY_SZ_4V(tnl
->save
.current
[i
],
374 tnl
->save
.attrptr
[i
]);
378 /* Edgeflag requires special treatment:
380 if (tnl
->save
.attrsz
[_TNL_ATTRIB_EDGEFLAG
]) {
381 ctx
->ListState
.ActiveEdgeFlag
= 1;
382 ctx
->ListState
.CurrentEdgeFlag
=
383 (tnl
->save
.attrptr
[_TNL_ATTRIB_EDGEFLAG
][0] == 1.0);
388 static void _save_copy_from_current( GLcontext
*ctx
)
390 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
393 for (i
= _TNL_ATTRIB_POS
+1 ; i
<= _TNL_ATTRIB_INDEX
; i
++)
394 switch (tnl
->save
.attrsz
[i
]) {
395 case 4: tnl
->save
.attrptr
[i
][3] = tnl
->save
.current
[i
][3];
396 case 3: tnl
->save
.attrptr
[i
][2] = tnl
->save
.current
[i
][2];
397 case 2: tnl
->save
.attrptr
[i
][1] = tnl
->save
.current
[i
][1];
398 case 1: tnl
->save
.attrptr
[i
][0] = tnl
->save
.current
[i
][0];
402 /* Edgeflag requires special treatment:
404 if (tnl
->save
.attrsz
[_TNL_ATTRIB_EDGEFLAG
])
405 tnl
->save
.attrptr
[_TNL_ATTRIB_EDGEFLAG
][0] =
406 (GLfloat
)ctx
->ListState
.CurrentEdgeFlag
;
412 /* Flush existing data, set new attrib size, replay copied vertices.
414 static void _save_upgrade_vertex( GLcontext
*ctx
,
418 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
423 /* Store the current run of vertices, and emit a GL_END. Emit a
424 * BEGIN in the new buffer.
426 if (tnl
->save
.initial_counter
!= tnl
->save
.counter
)
427 _save_wrap_buffers( ctx
);
429 assert( tnl
->save
.copied
.nr
== 0 );
431 /* Do a COPY_TO_CURRENT to ensure back-copying works for the case
432 * when the attribute already exists in the vertex and is having
433 * its size increased.
435 _save_copy_to_current( ctx
);
439 oldsz
= tnl
->save
.attrsz
[attr
];
440 tnl
->save
.attrsz
[attr
] = newsz
;
442 tnl
->save
.vertex_size
+= newsz
- oldsz
;
443 tnl
->save
.counter
= ((SAVE_BUFFER_SIZE
- tnl
->save
.vertex_store
->used
) /
444 tnl
->save
.vertex_size
);
445 if (tnl
->save
.counter
> ctx
->Const
.MaxArrayLockSize
)
446 tnl
->save
.counter
= ctx
->Const
.MaxArrayLockSize
;
447 tnl
->save
.initial_counter
= tnl
->save
.counter
;
449 /* Recalculate all the attrptr[] values:
451 for (i
= 0, tmp
= tnl
->save
.vertex
; i
< _TNL_ATTRIB_MAX
; i
++) {
452 if (tnl
->save
.attrsz
[i
]) {
453 tnl
->save
.attrptr
[i
] = tmp
;
454 tmp
+= tnl
->save
.attrsz
[i
];
457 tnl
->save
.attrptr
[i
] = 0; /* will not be dereferenced. */
460 /* Copy from current to repopulate the vertex with correct values.
462 _save_copy_from_current( ctx
);
464 /* Replay stored vertices to translate them to new format here.
466 * If there are copied vertices and the new (upgraded) attribute
467 * has not been defined before, this list is somewhat degenerate,
468 * and will need fixup at runtime.
470 if (tnl
->save
.copied
.nr
)
472 GLfloat
*data
= tnl
->save
.copied
.buffer
;
473 GLfloat
*dest
= tnl
->save
.buffer
;
476 /* Need to note this and fix up at runtime (or loopback):
478 if (tnl
->save
.currentsz
[attr
][0] == 0) {
480 tnl
->save
.dangling_attr_ref
= GL_TRUE
;
481 _mesa_debug(0, "_save_upgrade_vertex: dangling reference attr %d\n",
485 /* The current strategy is to punt these degenerate cases
486 * through _tnl_loopback_vertex_list(), a lower-performance
487 * option. To minimize the impact of this, artificially
488 * reduce the size of this vertex_list.
490 if (t
->save
.counter
> 10) {
491 t
->save
.initial_counter
= 10;
492 t
->save
.counter
= 10;
497 for (i
= 0 ; i
< tnl
->save
.copied
.nr
; i
++) {
498 for (j
= 0 ; j
< _TNL_ATTRIB_MAX
; j
++) {
499 if (tnl
->save
.attrsz
[j
]) {
502 ASSIGN_4V( dest
, 0, 0, 0, 1 );
503 COPY_SZ_4V( dest
, oldsz
, data
);
508 COPY_SZ_4V( dest
, newsz
, tnl
->save
.current
[attr
] );
513 GLint sz
= tnl
->save
.attrsz
[j
];
514 COPY_SZ_4V( dest
, sz
, data
);
522 tnl
->save
.vbptr
= dest
;
523 tnl
->save
.counter
-= tnl
->save
.copied
.nr
;
530 /* Helper function for 'CHOOSE' macro. Do what's necessary when an
531 * entrypoint is called for the first time.
533 static void do_choose( GLuint attr
, GLuint sz
,
534 void (*attr_func
)( const GLfloat
*),
535 void (*choose1
)( const GLfloat
*),
536 void (*choose2
)( const GLfloat
*),
537 void (*choose3
)( const GLfloat
*),
538 void (*choose4
)( const GLfloat
*),
541 GET_CURRENT_CONTEXT( ctx
);
542 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
543 static GLfloat id
[4] = { 0, 0, 0, 1 };
546 if (tnl
->save
.attrsz
[attr
] < sz
) {
547 /* New size is larger. Need to flush existing vertices and get
548 * an enlarged vertex format.
550 _save_upgrade_vertex( ctx
, attr
, sz
);
553 /* New size is equal or smaller - just need to fill in some
556 for (i
= sz
; i
<= tnl
->save
.attrsz
[attr
] ; i
++)
557 tnl
->save
.attrptr
[attr
][i
-1] = id
[i
-1];
560 /* Reset any active pointers for this attribute
562 tnl
->save
.tabfv
[attr
][0] = choose1
;
563 tnl
->save
.tabfv
[attr
][1] = choose2
;
564 tnl
->save
.tabfv
[attr
][2] = choose3
;
565 tnl
->save
.tabfv
[attr
][3] = choose4
;
567 /* Update the secondary dispatch table with the new function
569 tnl
->save
.tabfv
[attr
][sz
-1] = attr_func
;
576 /* Only one size for each attribute may be active at once. Eg. if
577 * Color3f is installed/active, then Color4f may not be, even if the
578 * vertex actually contains 4 color coordinates. This is because the
579 * 3f version won't otherwise set color[3] to 1.0 -- this is the job
580 * of the chooser function when switching between Color4f and Color3f.
582 #define ATTRFV( ATTR, N ) \
583 static void save_choose_##ATTR##_##N( const GLfloat *v ); \
585 static void save_attrib_##ATTR##_##N( const GLfloat *v ) \
587 GET_CURRENT_CONTEXT( ctx ); \
588 TNLcontext *tnl = TNL_CONTEXT(ctx); \
593 if (N>0) tnl->save.vbptr[0] = v[0]; \
594 if (N>1) tnl->save.vbptr[1] = v[1]; \
595 if (N>2) tnl->save.vbptr[2] = v[2]; \
596 if (N>3) tnl->save.vbptr[3] = v[3]; \
598 for (i = N; i < tnl->save.vertex_size; i++) \
599 tnl->save.vbptr[i] = tnl->save.vertex[i]; \
601 tnl->save.vbptr += tnl->save.vertex_size; \
603 if (--tnl->save.counter == 0) \
604 _save_wrap_filled_vertex( ctx ); \
607 GLfloat *dest = tnl->save.attrptr[ATTR]; \
608 if (N>0) dest[0] = v[0]; \
609 if (N>1) dest[1] = v[1]; \
610 if (N>2) dest[2] = v[2]; \
611 if (N>3) dest[3] = v[3]; \
615 #define CHOOSE( ATTR, N ) \
616 static void save_choose_##ATTR##_##N( const GLfloat *v ) \
619 save_attrib_##ATTR##_##N, \
620 save_choose_##ATTR##_1, \
621 save_choose_##ATTR##_2, \
622 save_choose_##ATTR##_3, \
623 save_choose_##ATTR##_4, \
628 static void save_init_##ATTR( TNLcontext *tnl ) \
630 tnl->save.tabfv[ATTR][0] = save_choose_##ATTR##_1; \
631 tnl->save.tabfv[ATTR][1] = save_choose_##ATTR##_2; \
632 tnl->save.tabfv[ATTR][2] = save_choose_##ATTR##_3; \
633 tnl->save.tabfv[ATTR][3] = save_choose_##ATTR##_4; \
636 #define ATTRS( ATTRIB ) \
637 ATTRFV( ATTRIB, 1 ) \
638 ATTRFV( ATTRIB, 2 ) \
639 ATTRFV( ATTRIB, 3 ) \
640 ATTRFV( ATTRIB, 4 ) \
641 CHOOSE( ATTRIB, 1 ) \
642 CHOOSE( ATTRIB, 2 ) \
643 CHOOSE( ATTRIB, 3 ) \
644 CHOOSE( ATTRIB, 4 ) \
648 /* Generate a lot of functions. These are the actual worker
649 * functions, which are equivalent to those generated via codegen
670 static void _save_reset_vertex( GLcontext
*ctx
)
672 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
692 for (i
= 0 ; i
< _TNL_ATTRIB_MAX
; i
++)
693 tnl
->save
.attrsz
[i
] = 0;
695 tnl
->save
.vertex_size
= 0;
696 tnl
->save
.have_materials
= 0;
698 _save_reset_counters( ctx
);
703 /* Cope with aliasing of classic Vertex, Normal, etc. and the fan-out
704 * of glMultTexCoord and glProgramParamterNV by routing all these
705 * through a second level dispatch table.
707 #define DISPATCH_ATTRFV( ATTR, COUNT, P ) \
709 GET_CURRENT_CONTEXT( ctx ); \
710 TNLcontext *tnl = TNL_CONTEXT(ctx); \
711 tnl->save.tabfv[ATTR][COUNT-1]( P ); \
714 #define DISPATCH_ATTR1FV( ATTR, V ) DISPATCH_ATTRFV( ATTR, 1, V )
715 #define DISPATCH_ATTR2FV( ATTR, V ) DISPATCH_ATTRFV( ATTR, 2, V )
716 #define DISPATCH_ATTR3FV( ATTR, V ) DISPATCH_ATTRFV( ATTR, 3, V )
717 #define DISPATCH_ATTR4FV( ATTR, V ) DISPATCH_ATTRFV( ATTR, 4, V )
719 #define DISPATCH_ATTR1F( ATTR, S ) DISPATCH_ATTRFV( ATTR, 1, &(S) )
721 #if defined(USE_X86_ASM) && 0 /* will break register calling convention */
724 #define DISPATCH_ATTR2F( ATTR, S,T ) DISPATCH_ATTRFV( ATTR, 2, &(S) )
725 #define DISPATCH_ATTR3F( ATTR, S,T,R ) DISPATCH_ATTRFV( ATTR, 3, &(S) )
726 #define DISPATCH_ATTR4F( ATTR, S,T,R,Q ) DISPATCH_ATTRFV( ATTR, 4, &(S) )
730 #define DISPATCH_ATTR2F( ATTR, S,T ) \
733 v[0] = S; v[1] = T; \
734 DISPATCH_ATTR2FV( ATTR, v ); \
736 #define DISPATCH_ATTR3F( ATTR, S,T,R ) \
739 v[0] = S; v[1] = T; v[2] = R; \
740 DISPATCH_ATTR3FV( ATTR, v ); \
742 #define DISPATCH_ATTR4F( ATTR, S,T,R,Q ) \
745 v[0] = S; v[1] = T; v[2] = R; v[3] = Q; \
746 DISPATCH_ATTR4FV( ATTR, v ); \
751 static void enum_error( void )
753 GET_CURRENT_CONTEXT( ctx
);
754 _mesa_compile_error( ctx
, GL_INVALID_ENUM
, "glVertexAttrib" );
757 static void GLAPIENTRY
_save_Vertex2f( GLfloat x
, GLfloat y
)
759 DISPATCH_ATTR2F( _TNL_ATTRIB_POS
, x
, y
);
762 static void GLAPIENTRY
_save_Vertex2fv( const GLfloat
*v
)
764 DISPATCH_ATTR2FV( _TNL_ATTRIB_POS
, v
);
767 static void GLAPIENTRY
_save_Vertex3f( GLfloat x
, GLfloat y
, GLfloat z
)
769 DISPATCH_ATTR3F( _TNL_ATTRIB_POS
, x
, y
, z
);
772 static void GLAPIENTRY
_save_Vertex3fv( const GLfloat
*v
)
774 DISPATCH_ATTR3FV( _TNL_ATTRIB_POS
, v
);
777 static void GLAPIENTRY
_save_Vertex4f( GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
779 DISPATCH_ATTR4F( _TNL_ATTRIB_POS
, x
, y
, z
, w
);
782 static void GLAPIENTRY
_save_Vertex4fv( const GLfloat
*v
)
784 DISPATCH_ATTR4FV( _TNL_ATTRIB_POS
, v
);
787 static void GLAPIENTRY
_save_TexCoord1f( GLfloat x
)
789 DISPATCH_ATTR1F( _TNL_ATTRIB_TEX0
, x
);
792 static void GLAPIENTRY
_save_TexCoord1fv( const GLfloat
*v
)
794 DISPATCH_ATTR1FV( _TNL_ATTRIB_TEX0
, v
);
797 static void GLAPIENTRY
_save_TexCoord2f( GLfloat x
, GLfloat y
)
799 DISPATCH_ATTR2F( _TNL_ATTRIB_TEX0
, x
, y
);
802 static void GLAPIENTRY
_save_TexCoord2fv( const GLfloat
*v
)
804 DISPATCH_ATTR2FV( _TNL_ATTRIB_TEX0
, v
);
807 static void GLAPIENTRY
_save_TexCoord3f( GLfloat x
, GLfloat y
, GLfloat z
)
809 DISPATCH_ATTR3F( _TNL_ATTRIB_TEX0
, x
, y
, z
);
812 static void GLAPIENTRY
_save_TexCoord3fv( const GLfloat
*v
)
814 DISPATCH_ATTR3FV( _TNL_ATTRIB_TEX0
, v
);
817 static void GLAPIENTRY
_save_TexCoord4f( GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
819 DISPATCH_ATTR4F( _TNL_ATTRIB_TEX0
, x
, y
, z
, w
);
822 static void GLAPIENTRY
_save_TexCoord4fv( const GLfloat
*v
)
824 DISPATCH_ATTR4FV( _TNL_ATTRIB_TEX0
, v
);
827 static void GLAPIENTRY
_save_Normal3f( GLfloat x
, GLfloat y
, GLfloat z
)
829 DISPATCH_ATTR3F( _TNL_ATTRIB_NORMAL
, x
, y
, z
);
832 static void GLAPIENTRY
_save_Normal3fv( const GLfloat
*v
)
834 DISPATCH_ATTR3FV( _TNL_ATTRIB_NORMAL
, v
);
837 static void GLAPIENTRY
_save_FogCoordfEXT( GLfloat x
)
839 DISPATCH_ATTR1F( _TNL_ATTRIB_FOG
, x
);
842 static void GLAPIENTRY
_save_FogCoordfvEXT( const GLfloat
*v
)
844 DISPATCH_ATTR1FV( _TNL_ATTRIB_FOG
, v
);
847 static void GLAPIENTRY
_save_Color3f( GLfloat x
, GLfloat y
, GLfloat z
)
849 DISPATCH_ATTR3F( _TNL_ATTRIB_COLOR0
, x
, y
, z
);
852 static void GLAPIENTRY
_save_Color3fv( const GLfloat
*v
)
854 DISPATCH_ATTR3FV( _TNL_ATTRIB_COLOR0
, v
);
857 static void GLAPIENTRY
_save_Color4f( GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
859 DISPATCH_ATTR4F( _TNL_ATTRIB_COLOR0
, x
, y
, z
, w
);
862 static void GLAPIENTRY
_save_Color4fv( const GLfloat
*v
)
864 DISPATCH_ATTR4FV( _TNL_ATTRIB_COLOR0
, v
);
867 static void GLAPIENTRY
_save_SecondaryColor3fEXT( GLfloat x
, GLfloat y
, GLfloat z
)
869 DISPATCH_ATTR3F( _TNL_ATTRIB_COLOR1
, x
, y
, z
);
872 static void GLAPIENTRY
_save_SecondaryColor3fvEXT( const GLfloat
*v
)
874 DISPATCH_ATTR3FV( _TNL_ATTRIB_COLOR1
, v
);
877 static void GLAPIENTRY
_save_MultiTexCoord1f( GLenum target
, GLfloat x
)
879 GLuint attr
= (target
& 0x7) + _TNL_ATTRIB_TEX0
;
880 DISPATCH_ATTR1F( attr
, x
);
883 static void GLAPIENTRY
_save_MultiTexCoord1fv( GLenum target
, const GLfloat
*v
)
885 GLuint attr
= (target
& 0x7) + _TNL_ATTRIB_TEX0
;
886 DISPATCH_ATTR1FV( attr
, v
);
889 static void GLAPIENTRY
_save_MultiTexCoord2f( GLenum target
, GLfloat x
, GLfloat y
)
891 GLuint attr
= (target
& 0x7) + _TNL_ATTRIB_TEX0
;
892 DISPATCH_ATTR2F( attr
, x
, y
);
895 static void GLAPIENTRY
_save_MultiTexCoord2fv( GLenum target
, const GLfloat
*v
)
897 GLuint attr
= (target
& 0x7) + _TNL_ATTRIB_TEX0
;
898 DISPATCH_ATTR2FV( attr
, v
);
901 static void GLAPIENTRY
_save_MultiTexCoord3f( GLenum target
, GLfloat x
, GLfloat y
,
904 GLuint attr
= (target
& 0x7) + _TNL_ATTRIB_TEX0
;
905 DISPATCH_ATTR3F( attr
, x
, y
, z
);
908 static void GLAPIENTRY
_save_MultiTexCoord3fv( GLenum target
, const GLfloat
*v
)
910 GLuint attr
= (target
& 0x7) + _TNL_ATTRIB_TEX0
;
911 DISPATCH_ATTR3FV( attr
, v
);
914 static void GLAPIENTRY
_save_MultiTexCoord4f( GLenum target
, GLfloat x
, GLfloat y
,
915 GLfloat z
, GLfloat w
)
917 GLuint attr
= (target
& 0x7) + _TNL_ATTRIB_TEX0
;
918 DISPATCH_ATTR4F( attr
, x
, y
, z
, w
);
921 static void GLAPIENTRY
_save_MultiTexCoord4fv( GLenum target
, const GLfloat
*v
)
923 GLuint attr
= (target
& 0x7) + _TNL_ATTRIB_TEX0
;
924 DISPATCH_ATTR4FV( attr
, v
);
927 static void GLAPIENTRY
_save_VertexAttrib1fNV( GLuint index
, GLfloat x
)
929 if (index
< VERT_ATTRIB_MAX
)
930 DISPATCH_ATTR1F( index
, x
);
935 static void GLAPIENTRY
_save_VertexAttrib1fvNV( GLuint index
, const GLfloat
*v
)
937 if (index
< VERT_ATTRIB_MAX
)
938 DISPATCH_ATTR1FV( index
, v
);
943 static void GLAPIENTRY
_save_VertexAttrib2fNV( GLuint index
, GLfloat x
, GLfloat y
)
945 if (index
< VERT_ATTRIB_MAX
)
946 DISPATCH_ATTR2F( index
, x
, y
);
951 static void GLAPIENTRY
_save_VertexAttrib2fvNV( GLuint index
, const GLfloat
*v
)
953 if (index
< VERT_ATTRIB_MAX
)
954 DISPATCH_ATTR2FV( index
, v
);
959 static void GLAPIENTRY
_save_VertexAttrib3fNV( GLuint index
, GLfloat x
, GLfloat y
,
962 if (index
< VERT_ATTRIB_MAX
)
963 DISPATCH_ATTR3F( index
, x
, y
, z
);
968 static void GLAPIENTRY
_save_VertexAttrib3fvNV( GLuint index
, const GLfloat
*v
)
970 if (index
< VERT_ATTRIB_MAX
)
971 DISPATCH_ATTR3FV( index
, v
);
976 static void GLAPIENTRY
_save_VertexAttrib4fNV( GLuint index
, GLfloat x
, GLfloat y
,
977 GLfloat z
, GLfloat w
)
979 if (index
< VERT_ATTRIB_MAX
)
980 DISPATCH_ATTR4F( index
, x
, y
, z
, w
);
985 static void GLAPIENTRY
_save_VertexAttrib4fvNV( GLuint index
, const GLfloat
*v
)
987 if (index
< VERT_ATTRIB_MAX
)
988 DISPATCH_ATTR4FV( index
, v
);
994 static void GLAPIENTRY
995 _save_VertexAttrib1fARB( GLuint index
, GLfloat x
)
997 if (index
< VERT_ATTRIB_MAX
)
998 DISPATCH_ATTR1F( index
, x
);
1003 static void GLAPIENTRY
1004 _save_VertexAttrib1fvARB( GLuint index
, const GLfloat
*v
)
1006 if (index
< VERT_ATTRIB_MAX
)
1007 DISPATCH_ATTR1FV( index
, v
);
1012 static void GLAPIENTRY
1013 _save_VertexAttrib2fARB( GLuint index
, GLfloat x
, GLfloat y
)
1015 if (index
< VERT_ATTRIB_MAX
)
1016 DISPATCH_ATTR2F( index
, x
, y
);
1021 static void GLAPIENTRY
1022 _save_VertexAttrib2fvARB( GLuint index
, const GLfloat
*v
)
1024 if (index
< VERT_ATTRIB_MAX
)
1025 DISPATCH_ATTR2FV( index
, v
);
1030 static void GLAPIENTRY
1031 _save_VertexAttrib3fARB( GLuint index
, GLfloat x
, GLfloat y
, GLfloat z
)
1033 if (index
< VERT_ATTRIB_MAX
)
1034 DISPATCH_ATTR3F( index
, x
, y
, z
);
1039 static void GLAPIENTRY
1040 _save_VertexAttrib3fvARB( GLuint index
, const GLfloat
*v
)
1042 if (index
< VERT_ATTRIB_MAX
)
1043 DISPATCH_ATTR3FV( index
, v
);
1048 static void GLAPIENTRY
1049 _save_VertexAttrib4fARB( GLuint index
, GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
1051 if (index
< VERT_ATTRIB_MAX
)
1052 DISPATCH_ATTR4F( index
, x
, y
, z
, w
);
1057 static void GLAPIENTRY
1058 _save_VertexAttrib4fvARB( GLuint index
, const GLfloat
*v
)
1060 if (index
< VERT_ATTRIB_MAX
)
1061 DISPATCH_ATTR4FV( index
, v
);
1069 * These are treated as per-vertex attributes, at indices above where
1070 * the NV_vertex_program leaves off. There are a lot of good things
1071 * about treating materials this way.
1073 * However: I don't want to double the number of generated functions
1074 * just to cope with this, so I unroll the 'C' varients of CHOOSE and
1075 * ATTRF into this function, and dispense with codegen and
1076 * second-level dispatch.
1078 * There is no aliasing of material attributes with other entrypoints.
1080 #define MAT_ATTR( A, N, params ) \
1082 if (tnl->save.attrsz[A] < N) { \
1083 _save_upgrade_vertex( ctx, A, N ); \
1084 tnl->save.have_materials = GL_TRUE; \
1088 GLfloat *dest = tnl->save.attrptr[A]; \
1089 if (N>0) dest[0] = params[0]; \
1090 if (N>1) dest[1] = params[1]; \
1091 if (N>2) dest[2] = params[2]; \
1092 if (N>3) dest[3] = params[3]; \
1097 #define MAT( ATTR, N, face, params ) \
1099 if (face != GL_BACK) \
1100 MAT_ATTR( ATTR, N, params ); /* front */ \
1101 if (face != GL_FRONT) \
1102 MAT_ATTR( ATTR + 1, N, params ); /* back */ \
1106 /* NOTE: Have to remove/deal-with colormaterial crossovers, probably
1107 * later on - in the meantime just store everything.
1109 static void GLAPIENTRY
_save_Materialfv( GLenum face
, GLenum pname
,
1110 const GLfloat
*params
)
1112 GET_CURRENT_CONTEXT( ctx
);
1113 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1117 MAT( _TNL_ATTRIB_MAT_FRONT_EMISSION
, 4, face
, params
);
1120 MAT( _TNL_ATTRIB_MAT_FRONT_AMBIENT
, 4, face
, params
);
1123 MAT( _TNL_ATTRIB_MAT_FRONT_DIFFUSE
, 4, face
, params
);
1126 MAT( _TNL_ATTRIB_MAT_FRONT_SPECULAR
, 4, face
, params
);
1129 MAT( _TNL_ATTRIB_MAT_FRONT_SHININESS
, 1, face
, params
);
1131 case GL_COLOR_INDEXES
:
1132 MAT( _TNL_ATTRIB_MAT_FRONT_INDEXES
, 3, face
, params
);
1134 case GL_AMBIENT_AND_DIFFUSE
:
1135 MAT( _TNL_ATTRIB_MAT_FRONT_AMBIENT
, 4, face
, params
);
1136 MAT( _TNL_ATTRIB_MAT_FRONT_DIFFUSE
, 4, face
, params
);
1139 _mesa_compile_error( ctx
, GL_INVALID_ENUM
, "glMaterialfv" );
1145 #define IDX_ATTR( A, IDX ) \
1147 GET_CURRENT_CONTEXT( ctx ); \
1148 TNLcontext *tnl = TNL_CONTEXT(ctx); \
1150 if (tnl->save.attrsz[A] < 1) { \
1151 _save_upgrade_vertex( ctx, A, 1 ); \
1155 GLfloat *dest = tnl->save.attrptr[A]; \
1161 static void GLAPIENTRY
_save_EdgeFlag( GLboolean b
)
1163 IDX_ATTR( _TNL_ATTRIB_EDGEFLAG
, (GLfloat
)b
);
1166 static void GLAPIENTRY
_save_EdgeFlagv( const GLboolean
*v
)
1168 IDX_ATTR( _TNL_ATTRIB_EDGEFLAG
, (GLfloat
)(v
[0]) );
1171 static void GLAPIENTRY
_save_Indexf( GLfloat f
)
1173 IDX_ATTR( _TNL_ATTRIB_INDEX
, f
);
1176 static void GLAPIENTRY
_save_Indexfv( const GLfloat
*f
)
1178 IDX_ATTR( _TNL_ATTRIB_INDEX
, f
[0] );
1184 /* Cope with EvalCoord/CallList called within a begin/end object:
1185 * -- Flush current buffer
1186 * -- Fallback to opcodes for the rest of the begin/end object.
1188 #define FALLBACK(ctx) \
1190 TNLcontext *tnl = TNL_CONTEXT(ctx); \
1192 /*fprintf(stderr, "fallback %s inside begin/end\n", __FUNCTION__);*/ \
1194 if (tnl->save.initial_counter != tnl->save.counter || \
1195 tnl->save.prim_count) \
1196 _save_compile_vertex_list( ctx ); \
1198 _save_copy_to_current( ctx ); \
1199 _save_reset_vertex( ctx ); \
1200 _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt ); \
1201 ctx->Driver.SaveNeedFlush = 0; \
1204 static void GLAPIENTRY
_save_EvalCoord1f( GLfloat u
)
1206 GET_CURRENT_CONTEXT(ctx
);
1208 ctx
->Save
->EvalCoord1f( u
);
1211 static void GLAPIENTRY
_save_EvalCoord1fv( const GLfloat
*v
)
1213 GET_CURRENT_CONTEXT(ctx
);
1215 ctx
->Save
->EvalCoord1fv( v
);
1218 static void GLAPIENTRY
_save_EvalCoord2f( GLfloat u
, GLfloat v
)
1220 GET_CURRENT_CONTEXT(ctx
);
1222 ctx
->Save
->EvalCoord2f( u
, v
);
1225 static void GLAPIENTRY
_save_EvalCoord2fv( const GLfloat
*v
)
1227 GET_CURRENT_CONTEXT(ctx
);
1229 ctx
->Save
->EvalCoord2fv( v
);
1232 static void GLAPIENTRY
_save_EvalPoint1( GLint i
)
1234 GET_CURRENT_CONTEXT(ctx
);
1236 ctx
->Save
->EvalPoint1( i
);
1239 static void GLAPIENTRY
_save_EvalPoint2( GLint i
, GLint j
)
1241 GET_CURRENT_CONTEXT(ctx
);
1243 ctx
->Save
->EvalPoint2( i
, j
);
1246 static void GLAPIENTRY
_save_CallList( GLuint l
)
1248 GET_CURRENT_CONTEXT(ctx
);
1250 ctx
->Save
->CallList( l
);
1253 static void GLAPIENTRY
_save_CallLists( GLsizei n
, GLenum type
, const GLvoid
*v
)
1255 GET_CURRENT_CONTEXT(ctx
);
1257 ctx
->Save
->CallLists( n
, type
, v
);
1263 /* This begin is hooked into ... Updating of
1264 * ctx->Driver.CurrentSavePrimitive is already taken care of.
1266 static GLboolean
_save_NotifyBegin( GLcontext
*ctx
, GLenum mode
)
1268 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1271 GLuint i
= tnl
->save
.prim_count
++;
1273 assert(i
< tnl
->save
.prim_max
);
1274 tnl
->save
.prim
[i
].mode
= mode
| PRIM_BEGIN
;
1275 tnl
->save
.prim
[i
].start
= tnl
->save
.initial_counter
- tnl
->save
.counter
;
1276 tnl
->save
.prim
[i
].count
= 0;
1278 _mesa_install_save_vtxfmt( ctx
, &tnl
->save_vtxfmt
);
1279 ctx
->Driver
.SaveNeedFlush
= 1;
1288 static void GLAPIENTRY
_save_End( void )
1290 GET_CURRENT_CONTEXT( ctx
);
1291 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1292 GLint i
= tnl
->save
.prim_count
- 1;
1294 ctx
->Driver
.CurrentSavePrimitive
= PRIM_OUTSIDE_BEGIN_END
;
1295 tnl
->save
.prim
[i
].mode
|= PRIM_END
;
1296 tnl
->save
.prim
[i
].count
= ((tnl
->save
.initial_counter
- tnl
->save
.counter
) -
1297 tnl
->save
.prim
[i
].start
);
1299 if (i
== (GLint
) tnl
->save
.prim_max
- 1) {
1300 _save_compile_vertex_list( ctx
);
1301 assert(tnl
->save
.copied
.nr
== 0);
1304 /* Swap out this vertex format while outside begin/end. Any color,
1305 * etc. received between here and the next begin will be compiled
1308 _mesa_install_save_vtxfmt( ctx
, &ctx
->ListState
.ListVtxfmt
);
1312 /* These are all errors as this vtxfmt is only installed inside
1315 static void GLAPIENTRY
_save_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1316 const GLvoid
*indices
)
1318 GET_CURRENT_CONTEXT(ctx
);
1319 (void) mode
; (void) count
; (void) type
; (void) indices
;
1320 _mesa_compile_error( ctx
, GL_INVALID_OPERATION
, "glDrawElements" );
1324 static void GLAPIENTRY
_save_DrawRangeElements(GLenum mode
,
1325 GLuint start
, GLuint end
,
1326 GLsizei count
, GLenum type
,
1327 const GLvoid
*indices
)
1329 GET_CURRENT_CONTEXT(ctx
);
1330 (void) mode
; (void) start
; (void) end
; (void) count
; (void) type
; (void) indices
;
1331 _mesa_compile_error( ctx
, GL_INVALID_OPERATION
, "glDrawRangeElements" );
1334 static void GLAPIENTRY
_save_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
1336 GET_CURRENT_CONTEXT(ctx
);
1337 (void) mode
; (void) start
; (void) count
;
1338 _mesa_compile_error( ctx
, GL_INVALID_OPERATION
, "glDrawArrays" );
1341 static void GLAPIENTRY
_save_Rectf( GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
1343 GET_CURRENT_CONTEXT(ctx
);
1344 (void) x1
; (void) y1
; (void) x2
; (void) y2
;
1345 _mesa_compile_error( ctx
, GL_INVALID_OPERATION
, "glRectf" );
1348 static void GLAPIENTRY
_save_EvalMesh1( GLenum mode
, GLint i1
, GLint i2
)
1350 GET_CURRENT_CONTEXT(ctx
);
1351 (void) mode
; (void) i1
; (void) i2
;
1352 _mesa_compile_error( ctx
, GL_INVALID_OPERATION
, "glEvalMesh1" );
1355 static void GLAPIENTRY
_save_EvalMesh2( GLenum mode
, GLint i1
, GLint i2
,
1356 GLint j1
, GLint j2
)
1358 GET_CURRENT_CONTEXT(ctx
);
1359 (void) mode
; (void) i1
; (void) i2
; (void) j1
; (void) j2
;
1360 _mesa_compile_error( ctx
, GL_INVALID_OPERATION
, "glEvalMesh2" );
1363 static void GLAPIENTRY
_save_Begin( GLenum mode
)
1365 GET_CURRENT_CONTEXT( ctx
);
1367 _mesa_compile_error( ctx
, GL_INVALID_OPERATION
, "Recursive glBegin" );
1371 /* Unlike the functions above, these are to be hooked into the vtxfmt
1372 * maintained in ctx->ListState, active when the list is known or
1373 * suspected to be outside any begin/end primitive.
1375 static void GLAPIENTRY
_save_OBE_Rectf( GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
1377 GET_CURRENT_CONTEXT(ctx
);
1378 _save_NotifyBegin( ctx
, GL_QUADS
| PRIM_WEAK
);
1379 GL_CALL(Vertex2f
)( x1
, y1
);
1380 GL_CALL(Vertex2f
)( x2
, y1
);
1381 GL_CALL(Vertex2f
)( x2
, y2
);
1382 GL_CALL(Vertex2f
)( x1
, y2
);
1387 static void GLAPIENTRY
_save_OBE_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
1389 GET_CURRENT_CONTEXT(ctx
);
1392 if (!_mesa_validate_DrawArrays( ctx
, mode
, start
, count
))
1395 _save_NotifyBegin( ctx
, mode
| PRIM_WEAK
);
1396 for (i
= 0; i
< count
; i
++)
1397 GL_CALL(ArrayElement
)(start
+ i
);
1402 static void GLAPIENTRY
_save_OBE_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1403 const GLvoid
*indices
)
1405 GET_CURRENT_CONTEXT(ctx
);
1408 if (!_mesa_validate_DrawElements( ctx
, mode
, count
, type
, indices
))
1411 _save_NotifyBegin( ctx
, mode
| PRIM_WEAK
);
1414 case GL_UNSIGNED_BYTE
:
1415 for (i
= 0 ; i
< count
; i
++)
1416 GL_CALL(ArrayElement
)( ((GLubyte
*)indices
)[i
] );
1418 case GL_UNSIGNED_SHORT
:
1419 for (i
= 0 ; i
< count
; i
++)
1420 GL_CALL(ArrayElement
)( ((GLushort
*)indices
)[i
] );
1422 case GL_UNSIGNED_INT
:
1423 for (i
= 0 ; i
< count
; i
++)
1424 GL_CALL(ArrayElement
)( ((GLuint
*)indices
)[i
] );
1427 _mesa_error( ctx
, GL_INVALID_ENUM
, "glDrawElements(type)" );
1434 static void GLAPIENTRY
_save_OBE_DrawRangeElements(GLenum mode
,
1435 GLuint start
, GLuint end
,
1436 GLsizei count
, GLenum type
,
1437 const GLvoid
*indices
)
1439 GET_CURRENT_CONTEXT(ctx
);
1440 if (_mesa_validate_DrawRangeElements( ctx
, mode
,
1442 count
, type
, indices
))
1443 _save_OBE_DrawElements( mode
, count
, type
, indices
);
1450 static void _save_vtxfmt_init( GLcontext
*ctx
)
1452 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1453 GLvertexformat
*vfmt
= &tnl
->save_vtxfmt
;
1455 vfmt
->ArrayElement
= _ae_loopback_array_elt
; /* generic helper */
1456 vfmt
->Begin
= _save_Begin
;
1457 vfmt
->Color3f
= _save_Color3f
;
1458 vfmt
->Color3fv
= _save_Color3fv
;
1459 vfmt
->Color4f
= _save_Color4f
;
1460 vfmt
->Color4fv
= _save_Color4fv
;
1461 vfmt
->EdgeFlag
= _save_EdgeFlag
;
1462 vfmt
->EdgeFlagv
= _save_EdgeFlagv
;
1463 vfmt
->End
= _save_End
;
1464 vfmt
->FogCoordfEXT
= _save_FogCoordfEXT
;
1465 vfmt
->FogCoordfvEXT
= _save_FogCoordfvEXT
;
1466 vfmt
->Indexf
= _save_Indexf
;
1467 vfmt
->Indexfv
= _save_Indexfv
;
1468 vfmt
->Materialfv
= _save_Materialfv
;
1469 vfmt
->MultiTexCoord1fARB
= _save_MultiTexCoord1f
;
1470 vfmt
->MultiTexCoord1fvARB
= _save_MultiTexCoord1fv
;
1471 vfmt
->MultiTexCoord2fARB
= _save_MultiTexCoord2f
;
1472 vfmt
->MultiTexCoord2fvARB
= _save_MultiTexCoord2fv
;
1473 vfmt
->MultiTexCoord3fARB
= _save_MultiTexCoord3f
;
1474 vfmt
->MultiTexCoord3fvARB
= _save_MultiTexCoord3fv
;
1475 vfmt
->MultiTexCoord4fARB
= _save_MultiTexCoord4f
;
1476 vfmt
->MultiTexCoord4fvARB
= _save_MultiTexCoord4fv
;
1477 vfmt
->Normal3f
= _save_Normal3f
;
1478 vfmt
->Normal3fv
= _save_Normal3fv
;
1479 vfmt
->SecondaryColor3fEXT
= _save_SecondaryColor3fEXT
;
1480 vfmt
->SecondaryColor3fvEXT
= _save_SecondaryColor3fvEXT
;
1481 vfmt
->TexCoord1f
= _save_TexCoord1f
;
1482 vfmt
->TexCoord1fv
= _save_TexCoord1fv
;
1483 vfmt
->TexCoord2f
= _save_TexCoord2f
;
1484 vfmt
->TexCoord2fv
= _save_TexCoord2fv
;
1485 vfmt
->TexCoord3f
= _save_TexCoord3f
;
1486 vfmt
->TexCoord3fv
= _save_TexCoord3fv
;
1487 vfmt
->TexCoord4f
= _save_TexCoord4f
;
1488 vfmt
->TexCoord4fv
= _save_TexCoord4fv
;
1489 vfmt
->Vertex2f
= _save_Vertex2f
;
1490 vfmt
->Vertex2fv
= _save_Vertex2fv
;
1491 vfmt
->Vertex3f
= _save_Vertex3f
;
1492 vfmt
->Vertex3fv
= _save_Vertex3fv
;
1493 vfmt
->Vertex4f
= _save_Vertex4f
;
1494 vfmt
->Vertex4fv
= _save_Vertex4fv
;
1495 vfmt
->VertexAttrib1fNV
= _save_VertexAttrib1fNV
;
1496 vfmt
->VertexAttrib1fvNV
= _save_VertexAttrib1fvNV
;
1497 vfmt
->VertexAttrib2fNV
= _save_VertexAttrib2fNV
;
1498 vfmt
->VertexAttrib2fvNV
= _save_VertexAttrib2fvNV
;
1499 vfmt
->VertexAttrib3fNV
= _save_VertexAttrib3fNV
;
1500 vfmt
->VertexAttrib3fvNV
= _save_VertexAttrib3fvNV
;
1501 vfmt
->VertexAttrib4fNV
= _save_VertexAttrib4fNV
;
1502 vfmt
->VertexAttrib4fvNV
= _save_VertexAttrib4fvNV
;
1503 vfmt
->VertexAttrib1fARB
= _save_VertexAttrib1fARB
;
1504 vfmt
->VertexAttrib1fvARB
= _save_VertexAttrib1fvARB
;
1505 vfmt
->VertexAttrib2fARB
= _save_VertexAttrib2fARB
;
1506 vfmt
->VertexAttrib2fvARB
= _save_VertexAttrib2fvARB
;
1507 vfmt
->VertexAttrib3fARB
= _save_VertexAttrib3fARB
;
1508 vfmt
->VertexAttrib3fvARB
= _save_VertexAttrib3fvARB
;
1509 vfmt
->VertexAttrib4fARB
= _save_VertexAttrib4fARB
;
1510 vfmt
->VertexAttrib4fvARB
= _save_VertexAttrib4fvARB
;
1512 /* This will all require us to fallback to saving the list as opcodes:
1514 vfmt
->CallList
= _save_CallList
; /* inside begin/end */
1515 vfmt
->CallLists
= _save_CallLists
; /* inside begin/end */
1516 vfmt
->EvalCoord1f
= _save_EvalCoord1f
;
1517 vfmt
->EvalCoord1fv
= _save_EvalCoord1fv
;
1518 vfmt
->EvalCoord2f
= _save_EvalCoord2f
;
1519 vfmt
->EvalCoord2fv
= _save_EvalCoord2fv
;
1520 vfmt
->EvalPoint1
= _save_EvalPoint1
;
1521 vfmt
->EvalPoint2
= _save_EvalPoint2
;
1523 /* These are all errors as we at least know we are in some sort of
1526 vfmt
->EvalMesh1
= _save_EvalMesh1
;
1527 vfmt
->EvalMesh2
= _save_EvalMesh2
;
1528 vfmt
->Begin
= _save_Begin
;
1529 vfmt
->Rectf
= _save_Rectf
;
1530 vfmt
->DrawArrays
= _save_DrawArrays
;
1531 vfmt
->DrawElements
= _save_DrawElements
;
1532 vfmt
->DrawRangeElements
= _save_DrawRangeElements
;
1537 void _tnl_SaveFlushVertices( GLcontext
*ctx
)
1539 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1541 /* Noop when we are actually active:
1543 if (ctx
->Driver
.CurrentSavePrimitive
== PRIM_INSIDE_UNKNOWN_PRIM
||
1544 ctx
->Driver
.CurrentSavePrimitive
<= GL_POLYGON
)
1547 if (tnl
->save
.initial_counter
!= tnl
->save
.counter
||
1548 tnl
->save
.prim_count
)
1549 _save_compile_vertex_list( ctx
);
1551 _save_copy_to_current( ctx
);
1552 _save_reset_vertex( ctx
);
1553 ctx
->Driver
.SaveNeedFlush
= 0;
1556 void _tnl_NewList( GLcontext
*ctx
, GLuint list
, GLenum mode
)
1558 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1560 (void) list
; (void) mode
;
1562 if (!tnl
->save
.prim_store
)
1563 tnl
->save
.prim_store
= alloc_prim_store( ctx
);
1565 if (!tnl
->save
.vertex_store
) {
1566 tnl
->save
.vertex_store
= alloc_vertex_store( ctx
);
1567 tnl
->save
.vbptr
= tnl
->save
.vertex_store
->buffer
;
1570 _save_reset_vertex( ctx
);
1571 ctx
->Driver
.SaveNeedFlush
= 0;
1574 void _tnl_EndList( GLcontext
*ctx
)
1577 assert(TNL_CONTEXT(ctx
)->save
.vertex_size
== 0);
1580 void _tnl_BeginCallList( GLcontext
*ctx
, GLuint list
)
1582 (void) ctx
; (void) list
;
1585 void _tnl_EndCallList( GLcontext
*ctx
)
1591 static void _tnl_destroy_vertex_list( GLcontext
*ctx
, void *data
)
1593 struct tnl_vertex_list
*node
= (struct tnl_vertex_list
*)data
;
1596 if ( --node
->vertex_store
->refcount
== 0 )
1597 FREE( node
->vertex_store
);
1599 if ( --node
->prim_store
->refcount
== 0 )
1600 FREE( node
->prim_store
);
1602 if ( node
->normal_lengths
)
1603 FREE( node
->normal_lengths
);
1607 static void _tnl_print_vertex_list( GLcontext
*ctx
, void *data
)
1609 struct tnl_vertex_list
*node
= (struct tnl_vertex_list
*)data
;
1613 _mesa_debug(0, "TNL-VERTEX-LIST, %u vertices %d primitives, %d vertsize\n",
1618 for (i
= 0 ; i
< node
->prim_count
; i
++) {
1619 struct tnl_prim
*prim
= &node
->prim
[i
];
1620 _mesa_debug(0, " prim %d: %s %d..%d %s %s\n",
1622 _mesa_lookup_enum_by_nr(prim
->mode
& PRIM_MODE_MASK
),
1624 prim
->start
+ prim
->count
,
1625 (prim
->mode
& PRIM_BEGIN
) ? "BEGIN" : "(wrap)",
1626 (prim
->mode
& PRIM_END
) ? "END" : "(wrap)");
1631 static void _save_current_init( GLcontext
*ctx
)
1633 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1636 for (i
= 0; i
< _TNL_ATTRIB_MAT_FRONT_AMBIENT
; i
++) {
1637 ASSERT(i
< VERT_ATTRIB_MAX
);
1638 tnl
->save
.currentsz
[i
] = &ctx
->ListState
.ActiveAttribSize
[i
];
1639 tnl
->save
.current
[i
] = ctx
->ListState
.CurrentAttrib
[i
];
1642 for (i
= _TNL_ATTRIB_MAT_FRONT_AMBIENT
; i
< _TNL_ATTRIB_INDEX
; i
++) {
1643 const GLuint j
= i
- _TNL_ATTRIB_MAT_FRONT_AMBIENT
;
1644 ASSERT(j
< MAT_ATTRIB_MAX
);
1645 tnl
->save
.currentsz
[i
] = &ctx
->ListState
.ActiveMaterialSize
[j
];
1646 tnl
->save
.current
[i
] = ctx
->ListState
.CurrentMaterial
[j
];
1649 tnl
->save
.currentsz
[_TNL_ATTRIB_INDEX
] = &ctx
->ListState
.ActiveIndex
;
1650 tnl
->save
.current
[_TNL_ATTRIB_INDEX
] = &ctx
->ListState
.CurrentIndex
;
1652 /* Current edgeflag is handled individually */
1656 * Initialize the display list compiler
1658 void _tnl_save_init( GLcontext
*ctx
)
1660 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1661 struct tnl_vertex_arrays
*tmp
= &tnl
->save_inputs
;
1665 for (i
= 0; i
< _TNL_ATTRIB_MAX
; i
++)
1666 _mesa_vector4f_init( &tmp
->Attribs
[i
], 0, 0);
1668 tnl
->save
.opcode_vertex_list
=
1669 _mesa_alloc_opcode( ctx
,
1670 sizeof(struct tnl_vertex_list
),
1671 _tnl_playback_vertex_list
,
1672 _tnl_destroy_vertex_list
,
1673 _tnl_print_vertex_list
);
1675 ctx
->Driver
.NotifySaveBegin
= _save_NotifyBegin
;
1677 _save_vtxfmt_init( ctx
);
1678 _save_current_init( ctx
);
1680 /* Hook our array functions into the outside-begin-end vtxfmt in
1683 ctx
->ListState
.ListVtxfmt
.Rectf
= _save_OBE_Rectf
;
1684 ctx
->ListState
.ListVtxfmt
.DrawArrays
= _save_OBE_DrawArrays
;
1685 ctx
->ListState
.ListVtxfmt
.DrawElements
= _save_OBE_DrawElements
;
1686 ctx
->ListState
.ListVtxfmt
.DrawRangeElements
= _save_OBE_DrawRangeElements
;
1687 _mesa_install_save_vtxfmt( ctx
, &ctx
->ListState
.ListVtxfmt
);
1692 * Deallocate the immediate-mode buffer for the given context, if
1693 * its reference count goes to zero.
1695 void _tnl_save_destroy( GLcontext
*ctx
)