1 /**************************************************************************
3 Copyright 2002-2008 Tungsten Graphics Inc., Cedar Park, Texas.
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 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
35 /* Display list compiler attempts to store lists of vertices with the
36 * same vertex layout. Additionally it attempts to minimize the need
37 * for execute-time fixup of these vertex lists, allowing them to be
40 * There are still some circumstances where this can be thwarted, for
41 * example by building a list that consists of one very long primitive
42 * (eg Begin(Triangles), 1000 vertices, End), and calling that list
43 * from inside a different begin/end object (Begin(Lines), CallList,
46 * In that case the code will have to replay the list as individual
47 * commands through the Exec dispatch table, or fix up the copied
48 * vertices at execute-time.
50 * The other case where fixup is required is when a vertex attribute
51 * is introduced in the middle of a primitive. Eg:
53 * TexCoord1f() Vertex2f()
54 * TexCoord1f() Color3f() Vertex2f()
57 * If the current value of Color isn't known at compile-time, this
58 * primitive will require fixup.
61 * The list compiler currently doesn't attempt to compile lists
62 * containing EvalCoord or EvalPoint commands. On encountering one of
63 * these, compilation falls back to opcodes.
65 * This could be improved to fallback only when a mix of EvalCoord and
66 * Vertex commands are issued within a single primitive.
70 #include "main/glheader.h"
71 #include "main/bufferobj.h"
72 #include "main/context.h"
73 #include "main/dlist.h"
74 #include "main/enums.h"
75 #include "main/eval.h"
76 #include "main/macros.h"
77 #include "main/mfeatures.h"
78 #include "main/api_validate.h"
79 #include "main/api_arrayelt.h"
80 #include "main/vtxfmt.h"
81 #include "main/dispatch.h"
83 #include "vbo_context.h"
92 /* An interesting VBO number/name to help with debugging */
93 #define VBO_BUF_ID 12345
97 * NOTE: Old 'parity' issue is gone, but copying can still be
98 * wrong-footed on replay.
101 _save_copy_vertices(struct gl_context
*ctx
,
102 const struct vbo_save_vertex_list
*node
,
103 const GLfloat
* src_buffer
)
105 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
106 const struct _mesa_prim
*prim
= &node
->prim
[node
->prim_count
- 1];
107 GLuint nr
= prim
->count
;
108 GLuint sz
= save
->vertex_size
;
109 const GLfloat
*src
= src_buffer
+ prim
->start
* sz
;
110 GLfloat
*dst
= save
->copied
.buffer
;
116 switch (prim
->mode
) {
121 for (i
= 0; i
< ovf
; i
++)
122 memcpy(dst
+ i
* sz
, src
+ (nr
- ovf
+ i
) * sz
,
123 sz
* sizeof(GLfloat
));
127 for (i
= 0; i
< ovf
; i
++)
128 memcpy(dst
+ i
* sz
, src
+ (nr
- ovf
+ i
) * sz
,
129 sz
* sizeof(GLfloat
));
133 for (i
= 0; i
< ovf
; i
++)
134 memcpy(dst
+ i
* sz
, src
+ (nr
- ovf
+ i
) * sz
,
135 sz
* sizeof(GLfloat
));
141 memcpy(dst
, src
+ (nr
- 1) * sz
, sz
* sizeof(GLfloat
));
145 case GL_TRIANGLE_FAN
:
150 memcpy(dst
, src
+ 0, sz
* sizeof(GLfloat
));
154 memcpy(dst
, src
+ 0, sz
* sizeof(GLfloat
));
155 memcpy(dst
+ sz
, src
+ (nr
- 1) * sz
, sz
* sizeof(GLfloat
));
158 case GL_TRIANGLE_STRIP
:
171 for (i
= 0; i
< ovf
; i
++)
172 memcpy(dst
+ i
* sz
, src
+ (nr
- ovf
+ i
) * sz
,
173 sz
* sizeof(GLfloat
));
182 static struct vbo_save_vertex_store
*
183 alloc_vertex_store(struct gl_context
*ctx
)
185 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
186 struct vbo_save_vertex_store
*vertex_store
=
187 CALLOC_STRUCT(vbo_save_vertex_store
);
189 /* obj->Name needs to be non-zero, but won't ever be examined more
190 * closely than that. In particular these buffers won't be entered
191 * into the hash and can never be confused with ones visible to the
192 * user. Perhaps there could be a special number for internal
195 vertex_store
->bufferobj
= ctx
->Driver
.NewBufferObject(ctx
,
197 GL_ARRAY_BUFFER_ARB
);
198 if (vertex_store
->bufferobj
) {
199 save
->out_of_memory
=
200 !ctx
->Driver
.BufferData(ctx
,
202 VBO_SAVE_BUFFER_SIZE
* sizeof(GLfloat
),
203 NULL
, GL_STATIC_DRAW_ARB
,
204 vertex_store
->bufferobj
);
207 save
->out_of_memory
= GL_TRUE
;
210 if (save
->out_of_memory
) {
211 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "internal VBO allocation");
212 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt_noop
);
215 vertex_store
->buffer
= NULL
;
216 vertex_store
->used
= 0;
217 vertex_store
->refcount
= 1;
224 free_vertex_store(struct gl_context
*ctx
,
225 struct vbo_save_vertex_store
*vertex_store
)
227 assert(!vertex_store
->buffer
);
229 if (vertex_store
->bufferobj
) {
230 _mesa_reference_buffer_object(ctx
, &vertex_store
->bufferobj
, NULL
);
238 vbo_save_map_vertex_store(struct gl_context
*ctx
,
239 struct vbo_save_vertex_store
*vertex_store
)
241 assert(vertex_store
->bufferobj
);
242 assert(!vertex_store
->buffer
);
243 if (vertex_store
->bufferobj
->Size
> 0) {
244 vertex_store
->buffer
=
245 (GLfloat
*) ctx
->Driver
.MapBufferRange(ctx
, 0,
246 vertex_store
->bufferobj
->Size
,
247 GL_MAP_WRITE_BIT
, /* not used */
248 vertex_store
->bufferobj
);
249 assert(vertex_store
->buffer
);
250 return vertex_store
->buffer
+ vertex_store
->used
;
253 /* probably ran out of memory for buffers */
260 vbo_save_unmap_vertex_store(struct gl_context
*ctx
,
261 struct vbo_save_vertex_store
*vertex_store
)
263 if (vertex_store
->bufferobj
->Size
> 0) {
264 ctx
->Driver
.UnmapBuffer(ctx
, vertex_store
->bufferobj
);
266 vertex_store
->buffer
= NULL
;
270 static struct vbo_save_primitive_store
*
271 alloc_prim_store(struct gl_context
*ctx
)
273 struct vbo_save_primitive_store
*store
=
274 CALLOC_STRUCT(vbo_save_primitive_store
);
283 _save_reset_counters(struct gl_context
*ctx
)
285 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
287 save
->prim
= save
->prim_store
->buffer
+ save
->prim_store
->used
;
288 save
->buffer
= save
->vertex_store
->buffer
+ save
->vertex_store
->used
;
290 assert(save
->buffer
== save
->buffer_ptr
);
292 if (save
->vertex_size
)
293 save
->max_vert
= ((VBO_SAVE_BUFFER_SIZE
- save
->vertex_store
->used
) /
298 save
->vert_count
= 0;
299 save
->prim_count
= 0;
300 save
->prim_max
= VBO_SAVE_PRIM_SIZE
- save
->prim_store
->used
;
301 save
->dangling_attr_ref
= 0;
305 * For a list of prims, try merging prims that can just be extensions of the
309 vbo_merge_prims(struct gl_context
*ctx
,
310 struct _mesa_prim
*prim_list
,
314 struct _mesa_prim
*prev_prim
= prim_list
;
316 for (i
= 1; i
< *prim_count
; i
++) {
317 struct _mesa_prim
*this_prim
= prim_list
+ i
;
319 if (this_prim
->mode
== prev_prim
->mode
&&
320 this_prim
->mode
== GL_QUADS
&&
321 this_prim
->count
% 4 == 0 &&
322 prev_prim
->count
% 4 == 0 &&
323 this_prim
->start
== prev_prim
->start
+ prev_prim
->count
&&
324 this_prim
->basevertex
== prev_prim
->basevertex
&&
325 this_prim
->num_instances
== prev_prim
->num_instances
&&
326 this_prim
->base_instance
== prev_prim
->base_instance
) {
327 /* We've found a prim that just extend the previous one. Tack it
328 * onto the previous one, and let this primitive struct get dropped.
330 prev_prim
->count
+= this_prim
->count
;
331 prev_prim
->end
= this_prim
->end
;
335 /* If any previous primitives have been dropped, then we need to copy
336 * this later one into the next available slot.
339 if (prev_prim
!= this_prim
)
340 *prev_prim
= *this_prim
;
343 *prim_count
= prev_prim
- prim_list
+ 1;
347 * Insert the active immediate struct onto the display list currently
351 _save_compile_vertex_list(struct gl_context
*ctx
)
353 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
354 struct vbo_save_vertex_list
*node
;
356 /* Allocate space for this structure in the display list currently
359 node
= (struct vbo_save_vertex_list
*)
360 _mesa_dlist_alloc(ctx
, save
->opcode_vertex_list
, sizeof(*node
));
365 /* Duplicate our template, increment refcounts to the storage structs:
367 memcpy(node
->attrsz
, save
->attrsz
, sizeof(node
->attrsz
));
368 memcpy(node
->attrtype
, save
->attrtype
, sizeof(node
->attrtype
));
369 node
->vertex_size
= save
->vertex_size
;
370 node
->buffer_offset
=
371 (save
->buffer
- save
->vertex_store
->buffer
) * sizeof(GLfloat
);
372 node
->count
= save
->vert_count
;
373 node
->wrap_count
= save
->copied
.nr
;
374 node
->dangling_attr_ref
= save
->dangling_attr_ref
;
375 node
->prim
= save
->prim
;
376 node
->prim_count
= save
->prim_count
;
377 node
->vertex_store
= save
->vertex_store
;
378 node
->prim_store
= save
->prim_store
;
380 node
->vertex_store
->refcount
++;
381 node
->prim_store
->refcount
++;
383 if (node
->prim
[0].no_current_update
) {
384 node
->current_size
= 0;
385 node
->current_data
= NULL
;
388 node
->current_size
= node
->vertex_size
- node
->attrsz
[0];
389 node
->current_data
= NULL
;
391 if (node
->current_size
) {
392 /* If the malloc fails, we just pull the data out of the VBO
395 node
->current_data
= malloc(node
->current_size
* sizeof(GLfloat
));
396 if (node
->current_data
) {
397 const char *buffer
= (const char *) save
->vertex_store
->buffer
;
398 unsigned attr_offset
= node
->attrsz
[0] * sizeof(GLfloat
);
399 unsigned vertex_offset
= 0;
403 (node
->count
- 1) * node
->vertex_size
* sizeof(GLfloat
);
405 memcpy(node
->current_data
,
406 buffer
+ node
->buffer_offset
+ vertex_offset
+ attr_offset
,
407 node
->current_size
* sizeof(GLfloat
));
412 assert(node
->attrsz
[VBO_ATTRIB_POS
] != 0 || node
->count
== 0);
414 if (save
->dangling_attr_ref
)
415 ctx
->ListState
.CurrentList
->Flags
|= DLIST_DANGLING_REFS
;
417 save
->vertex_store
->used
+= save
->vertex_size
* node
->count
;
418 save
->prim_store
->used
+= node
->prim_count
;
420 /* Copy duplicated vertices
422 save
->copied
.nr
= _save_copy_vertices(ctx
, node
, save
->buffer
);
424 vbo_merge_prims(ctx
, node
->prim
, &node
->prim_count
);
426 /* Deal with GL_COMPILE_AND_EXECUTE:
428 if (ctx
->ExecuteFlag
) {
429 struct _glapi_table
*dispatch
= GET_DISPATCH();
431 _glapi_set_dispatch(ctx
->Exec
);
433 vbo_loopback_vertex_list(ctx
,
434 (const GLfloat
*) ((const char *) save
->
435 vertex_store
->buffer
+
436 node
->buffer_offset
),
437 node
->attrsz
, node
->prim
, node
->prim_count
,
438 node
->wrap_count
, node
->vertex_size
);
440 _glapi_set_dispatch(dispatch
);
443 /* Decide whether the storage structs are full, or can be used for
444 * the next vertex lists as well.
446 if (save
->vertex_store
->used
>
447 VBO_SAVE_BUFFER_SIZE
- 16 * (save
->vertex_size
+ 4)) {
451 vbo_save_unmap_vertex_store(ctx
, save
->vertex_store
);
453 /* Release old reference:
455 save
->vertex_store
->refcount
--;
456 assert(save
->vertex_store
->refcount
!= 0);
457 save
->vertex_store
= NULL
;
459 /* Allocate and map new store:
461 save
->vertex_store
= alloc_vertex_store(ctx
);
462 save
->buffer_ptr
= vbo_save_map_vertex_store(ctx
, save
->vertex_store
);
463 save
->out_of_memory
= save
->buffer_ptr
== NULL
;
466 if (save
->prim_store
->used
> VBO_SAVE_PRIM_SIZE
- 6) {
467 save
->prim_store
->refcount
--;
468 assert(save
->prim_store
->refcount
!= 0);
469 save
->prim_store
= alloc_prim_store(ctx
);
472 /* Reset our structures for the next run of vertices:
474 _save_reset_counters(ctx
);
479 * TODO -- If no new vertices have been stored, don't bother saving it.
482 _save_wrap_buffers(struct gl_context
*ctx
)
484 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
485 GLint i
= save
->prim_count
- 1;
488 GLboolean no_current_update
;
490 assert(i
< (GLint
) save
->prim_max
);
493 /* Close off in-progress primitive.
495 save
->prim
[i
].count
= (save
->vert_count
- save
->prim
[i
].start
);
496 mode
= save
->prim
[i
].mode
;
497 weak
= save
->prim
[i
].weak
;
498 no_current_update
= save
->prim
[i
].no_current_update
;
500 /* store the copied vertices, and allocate a new list.
502 _save_compile_vertex_list(ctx
);
504 /* Restart interrupted primitive
506 save
->prim
[0].mode
= mode
;
507 save
->prim
[0].weak
= weak
;
508 save
->prim
[0].no_current_update
= no_current_update
;
509 save
->prim
[0].begin
= 0;
510 save
->prim
[0].end
= 0;
511 save
->prim
[0].pad
= 0;
512 save
->prim
[0].start
= 0;
513 save
->prim
[0].count
= 0;
514 save
->prim
[0].num_instances
= 1;
515 save
->prim
[0].base_instance
= 0;
516 save
->prim_count
= 1;
521 * Called only when buffers are wrapped as the result of filling the
522 * vertex_store struct.
525 _save_wrap_filled_vertex(struct gl_context
*ctx
)
527 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
528 GLfloat
*data
= save
->copied
.buffer
;
531 /* Emit a glEnd to close off the last vertex list.
533 _save_wrap_buffers(ctx
);
535 /* Copy stored stored vertices to start of new list.
537 assert(save
->max_vert
- save
->vert_count
> save
->copied
.nr
);
539 for (i
= 0; i
< save
->copied
.nr
; i
++) {
540 memcpy(save
->buffer_ptr
, data
, save
->vertex_size
* sizeof(GLfloat
));
541 data
+= save
->vertex_size
;
542 save
->buffer_ptr
+= save
->vertex_size
;
549 _save_copy_to_current(struct gl_context
*ctx
)
551 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
554 for (i
= VBO_ATTRIB_POS
+ 1; i
< VBO_ATTRIB_MAX
; i
++) {
555 if (save
->attrsz
[i
]) {
556 save
->currentsz
[i
][0] = save
->attrsz
[i
];
557 COPY_CLEAN_4V_TYPE_AS_FLOAT(save
->current
[i
], save
->attrsz
[i
],
558 save
->attrptr
[i
], save
->attrtype
[i
]);
565 _save_copy_from_current(struct gl_context
*ctx
)
567 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
570 for (i
= VBO_ATTRIB_POS
+ 1; i
< VBO_ATTRIB_MAX
; i
++) {
571 switch (save
->attrsz
[i
]) {
573 save
->attrptr
[i
][3] = save
->current
[i
][3];
575 save
->attrptr
[i
][2] = save
->current
[i
][2];
577 save
->attrptr
[i
][1] = save
->current
[i
][1];
579 save
->attrptr
[i
][0] = save
->current
[i
][0];
587 /* Flush existing data, set new attrib size, replay copied vertices.
590 _save_upgrade_vertex(struct gl_context
*ctx
, GLuint attr
, GLuint newsz
)
592 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
597 /* Store the current run of vertices, and emit a GL_END. Emit a
598 * BEGIN in the new buffer.
600 if (save
->vert_count
)
601 _save_wrap_buffers(ctx
);
603 assert(save
->copied
.nr
== 0);
605 /* Do a COPY_TO_CURRENT to ensure back-copying works for the case
606 * when the attribute already exists in the vertex and is having
607 * its size increased.
609 _save_copy_to_current(ctx
);
613 oldsz
= save
->attrsz
[attr
];
614 save
->attrsz
[attr
] = newsz
;
616 save
->vertex_size
+= newsz
- oldsz
;
617 save
->max_vert
= ((VBO_SAVE_BUFFER_SIZE
- save
->vertex_store
->used
) /
619 save
->vert_count
= 0;
621 /* Recalculate all the attrptr[] values:
623 for (i
= 0, tmp
= save
->vertex
; i
< VBO_ATTRIB_MAX
; i
++) {
624 if (save
->attrsz
[i
]) {
625 save
->attrptr
[i
] = tmp
;
626 tmp
+= save
->attrsz
[i
];
629 save
->attrptr
[i
] = NULL
; /* will not be dereferenced. */
633 /* Copy from current to repopulate the vertex with correct values.
635 _save_copy_from_current(ctx
);
637 /* Replay stored vertices to translate them to new format here.
639 * If there are copied vertices and the new (upgraded) attribute
640 * has not been defined before, this list is somewhat degenerate,
641 * and will need fixup at runtime.
643 if (save
->copied
.nr
) {
644 GLfloat
*data
= save
->copied
.buffer
;
645 GLfloat
*dest
= save
->buffer
;
648 /* Need to note this and fix up at runtime (or loopback):
650 if (attr
!= VBO_ATTRIB_POS
&& save
->currentsz
[attr
][0] == 0) {
652 save
->dangling_attr_ref
= GL_TRUE
;
655 for (i
= 0; i
< save
->copied
.nr
; i
++) {
656 for (j
= 0; j
< VBO_ATTRIB_MAX
; j
++) {
657 if (save
->attrsz
[j
]) {
660 COPY_CLEAN_4V_TYPE_AS_FLOAT(dest
, oldsz
, data
,
666 COPY_SZ_4V(dest
, newsz
, save
->current
[attr
]);
671 GLint sz
= save
->attrsz
[j
];
672 COPY_SZ_4V(dest
, sz
, data
);
680 save
->buffer_ptr
= dest
;
681 save
->vert_count
+= save
->copied
.nr
;
687 save_fixup_vertex(struct gl_context
*ctx
, GLuint attr
, GLuint sz
)
689 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
691 if (sz
> save
->attrsz
[attr
]) {
692 /* New size is larger. Need to flush existing vertices and get
693 * an enlarged vertex format.
695 _save_upgrade_vertex(ctx
, attr
, sz
);
697 else if (sz
< save
->active_sz
[attr
]) {
699 const GLfloat
*id
= vbo_get_default_vals_as_float(save
->attrtype
[attr
]);
701 /* New size is equal or smaller - just need to fill in some
704 for (i
= sz
; i
<= save
->attrsz
[attr
]; i
++)
705 save
->attrptr
[attr
][i
- 1] = id
[i
- 1];
708 save
->active_sz
[attr
] = sz
;
713 _save_reset_vertex(struct gl_context
*ctx
)
715 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
718 for (i
= 0; i
< VBO_ATTRIB_MAX
; i
++) {
720 save
->active_sz
[i
] = 0;
723 save
->vertex_size
= 0;
728 #define ERROR(err) _mesa_compile_error(ctx, err, __FUNCTION__);
731 /* Only one size for each attribute may be active at once. Eg. if
732 * Color3f is installed/active, then Color4f may not be, even if the
733 * vertex actually contains 4 color coordinates. This is because the
734 * 3f version won't otherwise set color[3] to 1.0 -- this is the job
735 * of the chooser function when switching between Color4f and Color3f.
737 #define ATTR(A, N, T, V0, V1, V2, V3) \
739 struct vbo_save_context *save = &vbo_context(ctx)->save; \
741 if (save->active_sz[A] != N) \
742 save_fixup_vertex(ctx, A, N); \
745 GLfloat *dest = save->attrptr[A]; \
746 if (N>0) dest[0] = V0; \
747 if (N>1) dest[1] = V1; \
748 if (N>2) dest[2] = V2; \
749 if (N>3) dest[3] = V3; \
750 save->attrtype[A] = T; \
756 for (i = 0; i < save->vertex_size; i++) \
757 save->buffer_ptr[i] = save->vertex[i]; \
759 save->buffer_ptr += save->vertex_size; \
761 if (++save->vert_count >= save->max_vert) \
762 _save_wrap_filled_vertex(ctx); \
766 #define TAG(x) _save_##x
768 #include "vbo_attrib_tmp.h"
772 #define MAT( ATTR, N, face, params ) \
774 if (face != GL_BACK) \
775 MAT_ATTR( ATTR, N, params ); /* front */ \
776 if (face != GL_FRONT) \
777 MAT_ATTR( ATTR + 1, N, params ); /* back */ \
782 * Save a glMaterial call found between glBegin/End.
783 * glMaterial calls outside Begin/End are handled in dlist.c.
785 static void GLAPIENTRY
786 _save_Materialfv(GLenum face
, GLenum pname
, const GLfloat
*params
)
788 GET_CURRENT_CONTEXT(ctx
);
790 if (face
!= GL_FRONT
&& face
!= GL_BACK
&& face
!= GL_FRONT_AND_BACK
) {
791 _mesa_compile_error(ctx
, GL_INVALID_ENUM
, "glMaterial(face)");
797 MAT(VBO_ATTRIB_MAT_FRONT_EMISSION
, 4, face
, params
);
800 MAT(VBO_ATTRIB_MAT_FRONT_AMBIENT
, 4, face
, params
);
803 MAT(VBO_ATTRIB_MAT_FRONT_DIFFUSE
, 4, face
, params
);
806 MAT(VBO_ATTRIB_MAT_FRONT_SPECULAR
, 4, face
, params
);
809 if (*params
< 0 || *params
> ctx
->Const
.MaxShininess
) {
810 _mesa_compile_error(ctx
, GL_INVALID_VALUE
, "glMaterial(shininess)");
813 MAT(VBO_ATTRIB_MAT_FRONT_SHININESS
, 1, face
, params
);
816 case GL_COLOR_INDEXES
:
817 MAT(VBO_ATTRIB_MAT_FRONT_INDEXES
, 3, face
, params
);
819 case GL_AMBIENT_AND_DIFFUSE
:
820 MAT(VBO_ATTRIB_MAT_FRONT_AMBIENT
, 4, face
, params
);
821 MAT(VBO_ATTRIB_MAT_FRONT_DIFFUSE
, 4, face
, params
);
824 _mesa_compile_error(ctx
, GL_INVALID_ENUM
, "glMaterial(pname)");
830 /* Cope with EvalCoord/CallList called within a begin/end object:
831 * -- Flush current buffer
832 * -- Fallback to opcodes for the rest of the begin/end object.
835 dlist_fallback(struct gl_context
*ctx
)
837 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
839 if (save
->vert_count
|| save
->prim_count
) {
840 if (save
->prim_count
> 0) {
841 /* Close off in-progress primitive. */
842 GLint i
= save
->prim_count
- 1;
843 save
->prim
[i
].count
= save
->vert_count
- save
->prim
[i
].start
;
846 /* Need to replay this display list with loopback,
847 * unfortunately, otherwise this primitive won't be handled
850 save
->dangling_attr_ref
= 1;
852 _save_compile_vertex_list(ctx
);
855 _save_copy_to_current(ctx
);
856 _save_reset_vertex(ctx
);
857 _save_reset_counters(ctx
);
858 if (save
->out_of_memory
) {
859 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt_noop
);
862 _mesa_install_save_vtxfmt(ctx
, &ctx
->ListState
.ListVtxfmt
);
864 ctx
->Driver
.SaveNeedFlush
= 0;
868 static void GLAPIENTRY
869 _save_EvalCoord1f(GLfloat u
)
871 GET_CURRENT_CONTEXT(ctx
);
873 CALL_EvalCoord1f(ctx
->Save
, (u
));
876 static void GLAPIENTRY
877 _save_EvalCoord1fv(const GLfloat
* v
)
879 GET_CURRENT_CONTEXT(ctx
);
881 CALL_EvalCoord1fv(ctx
->Save
, (v
));
884 static void GLAPIENTRY
885 _save_EvalCoord2f(GLfloat u
, GLfloat v
)
887 GET_CURRENT_CONTEXT(ctx
);
889 CALL_EvalCoord2f(ctx
->Save
, (u
, v
));
892 static void GLAPIENTRY
893 _save_EvalCoord2fv(const GLfloat
* v
)
895 GET_CURRENT_CONTEXT(ctx
);
897 CALL_EvalCoord2fv(ctx
->Save
, (v
));
900 static void GLAPIENTRY
901 _save_EvalPoint1(GLint i
)
903 GET_CURRENT_CONTEXT(ctx
);
905 CALL_EvalPoint1(ctx
->Save
, (i
));
908 static void GLAPIENTRY
909 _save_EvalPoint2(GLint i
, GLint j
)
911 GET_CURRENT_CONTEXT(ctx
);
913 CALL_EvalPoint2(ctx
->Save
, (i
, j
));
916 static void GLAPIENTRY
917 _save_CallList(GLuint l
)
919 GET_CURRENT_CONTEXT(ctx
);
921 CALL_CallList(ctx
->Save
, (l
));
924 static void GLAPIENTRY
925 _save_CallLists(GLsizei n
, GLenum type
, const GLvoid
* v
)
927 GET_CURRENT_CONTEXT(ctx
);
929 CALL_CallLists(ctx
->Save
, (n
, type
, v
));
934 /* This begin is hooked into ... Updating of
935 * ctx->Driver.CurrentSavePrimitive is already taken care of.
938 vbo_save_NotifyBegin(struct gl_context
*ctx
, GLenum mode
)
940 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
942 GLuint i
= save
->prim_count
++;
944 assert(i
< save
->prim_max
);
945 save
->prim
[i
].mode
= mode
& VBO_SAVE_PRIM_MODE_MASK
;
946 save
->prim
[i
].begin
= 1;
947 save
->prim
[i
].end
= 0;
948 save
->prim
[i
].weak
= (mode
& VBO_SAVE_PRIM_WEAK
) ? 1 : 0;
949 save
->prim
[i
].no_current_update
=
950 (mode
& VBO_SAVE_PRIM_NO_CURRENT_UPDATE
) ? 1 : 0;
951 save
->prim
[i
].pad
= 0;
952 save
->prim
[i
].start
= save
->vert_count
;
953 save
->prim
[i
].count
= 0;
954 save
->prim
[i
].num_instances
= 1;
955 save
->prim
[i
].base_instance
= 0;
957 if (save
->out_of_memory
) {
958 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt_noop
);
961 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt
);
963 ctx
->Driver
.SaveNeedFlush
= 1;
968 static void GLAPIENTRY
971 GET_CURRENT_CONTEXT(ctx
);
972 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
973 GLint i
= save
->prim_count
- 1;
975 ctx
->Driver
.CurrentSavePrimitive
= PRIM_OUTSIDE_BEGIN_END
;
976 save
->prim
[i
].end
= 1;
977 save
->prim
[i
].count
= (save
->vert_count
- save
->prim
[i
].start
);
979 if (i
== (GLint
) save
->prim_max
- 1) {
980 _save_compile_vertex_list(ctx
);
981 assert(save
->copied
.nr
== 0);
984 /* Swap out this vertex format while outside begin/end. Any color,
985 * etc. received between here and the next begin will be compiled
988 if (save
->out_of_memory
) {
989 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt_noop
);
992 _mesa_install_save_vtxfmt(ctx
, &ctx
->ListState
.ListVtxfmt
);
997 /* These are all errors as this vtxfmt is only installed inside
1000 static void GLAPIENTRY
1001 _save_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1002 const GLvoid
* indices
)
1004 GET_CURRENT_CONTEXT(ctx
);
1009 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawElements");
1013 static void GLAPIENTRY
1014 _save_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
1015 GLsizei count
, GLenum type
, const GLvoid
* indices
)
1017 GET_CURRENT_CONTEXT(ctx
);
1024 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawRangeElements");
1028 static void GLAPIENTRY
1029 _save_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
1030 const GLvoid
* indices
, GLint basevertex
)
1032 GET_CURRENT_CONTEXT(ctx
);
1038 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawElements");
1042 static void GLAPIENTRY
1043 _save_DrawRangeElementsBaseVertex(GLenum mode
,
1048 const GLvoid
* indices
, GLint basevertex
)
1050 GET_CURRENT_CONTEXT(ctx
);
1058 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawRangeElements");
1062 static void GLAPIENTRY
1063 _save_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
1065 GET_CURRENT_CONTEXT(ctx
);
1069 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawArrays");
1073 static void GLAPIENTRY
1074 _save_MultiDrawElements(GLenum mode
, const GLsizei
*count
, GLenum type
,
1075 const GLvoid
**indices
, GLsizei primcount
)
1077 GET_CURRENT_CONTEXT(ctx
);
1083 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glMultiDrawElements");
1087 static void GLAPIENTRY
1088 _save_MultiDrawElementsBaseVertex(GLenum mode
, const GLsizei
*count
,
1089 GLenum type
, const GLvoid
* const *indices
,
1090 GLsizei primcount
, const GLint
*basevertex
)
1092 GET_CURRENT_CONTEXT(ctx
);
1099 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
,
1100 "glMultiDrawElementsBaseVertex");
1104 static void GLAPIENTRY
1105 _save_DrawTransformFeedback(GLenum mode
, GLuint name
)
1107 GET_CURRENT_CONTEXT(ctx
);
1110 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawTransformFeedback");
1114 static void GLAPIENTRY
1115 _save_DrawTransformFeedbackStream(GLenum mode
, GLuint name
, GLuint stream
)
1117 GET_CURRENT_CONTEXT(ctx
);
1121 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
,
1122 "glDrawTransformFeedbackStream");
1126 static void GLAPIENTRY
1127 _save_DrawTransformFeedbackInstanced(GLenum mode
, GLuint name
,
1130 GET_CURRENT_CONTEXT(ctx
);
1134 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
,
1135 "glDrawTransformFeedbackInstanced");
1139 static void GLAPIENTRY
1140 _save_DrawTransformFeedbackStreamInstanced(GLenum mode
, GLuint name
,
1141 GLuint stream
, GLsizei primcount
)
1143 GET_CURRENT_CONTEXT(ctx
);
1148 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
,
1149 "glDrawTransformFeedbackStreamInstanced");
1153 static void GLAPIENTRY
1154 _save_Rectf(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
1156 GET_CURRENT_CONTEXT(ctx
);
1161 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glRectf");
1165 static void GLAPIENTRY
1166 _save_EvalMesh1(GLenum mode
, GLint i1
, GLint i2
)
1168 GET_CURRENT_CONTEXT(ctx
);
1172 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glEvalMesh1");
1176 static void GLAPIENTRY
1177 _save_EvalMesh2(GLenum mode
, GLint i1
, GLint i2
, GLint j1
, GLint j2
)
1179 GET_CURRENT_CONTEXT(ctx
);
1185 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glEvalMesh2");
1189 static void GLAPIENTRY
1190 _save_Begin(GLenum mode
)
1192 GET_CURRENT_CONTEXT(ctx
);
1194 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "Recursive glBegin");
1198 static void GLAPIENTRY
1199 _save_PrimitiveRestartNV(void)
1202 GET_CURRENT_CONTEXT(ctx
);
1204 curPrim
= ctx
->Driver
.CurrentSavePrimitive
;
1207 _save_Begin(curPrim
);
1211 /* Unlike the functions above, these are to be hooked into the vtxfmt
1212 * maintained in ctx->ListState, active when the list is known or
1213 * suspected to be outside any begin/end primitive.
1214 * Note: OBE = Outside Begin/End
1216 static void GLAPIENTRY
1217 _save_OBE_Rectf(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
1219 GET_CURRENT_CONTEXT(ctx
);
1220 vbo_save_NotifyBegin(ctx
, GL_QUADS
| VBO_SAVE_PRIM_WEAK
);
1221 CALL_Vertex2f(GET_DISPATCH(), (x1
, y1
));
1222 CALL_Vertex2f(GET_DISPATCH(), (x2
, y1
));
1223 CALL_Vertex2f(GET_DISPATCH(), (x2
, y2
));
1224 CALL_Vertex2f(GET_DISPATCH(), (x1
, y2
));
1225 CALL_End(GET_DISPATCH(), ());
1229 static void GLAPIENTRY
1230 _save_OBE_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
1232 GET_CURRENT_CONTEXT(ctx
);
1233 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1236 if (!_mesa_validate_DrawArrays(ctx
, mode
, start
, count
))
1239 if (save
->out_of_memory
)
1244 vbo_save_NotifyBegin(ctx
, (mode
| VBO_SAVE_PRIM_WEAK
1245 | VBO_SAVE_PRIM_NO_CURRENT_UPDATE
));
1247 for (i
= 0; i
< count
; i
++)
1248 CALL_ArrayElement(GET_DISPATCH(), (start
+ i
));
1249 CALL_End(GET_DISPATCH(), ());
1251 _ae_unmap_vbos(ctx
);
1255 /* Could do better by copying the arrays and element list intact and
1256 * then emitting an indexed prim at runtime.
1258 static void GLAPIENTRY
1259 _save_OBE_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1260 const GLvoid
* indices
)
1262 GET_CURRENT_CONTEXT(ctx
);
1263 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1266 if (!_mesa_validate_DrawElements(ctx
, mode
, count
, type
, indices
, 0))
1269 if (save
->out_of_memory
)
1274 if (_mesa_is_bufferobj(ctx
->Array
.ArrayObj
->ElementArrayBufferObj
))
1276 ADD_POINTERS(ctx
->Array
.ArrayObj
->ElementArrayBufferObj
->Pointer
, indices
);
1278 vbo_save_NotifyBegin(ctx
, (mode
| VBO_SAVE_PRIM_WEAK
|
1279 VBO_SAVE_PRIM_NO_CURRENT_UPDATE
));
1282 case GL_UNSIGNED_BYTE
:
1283 for (i
= 0; i
< count
; i
++)
1284 CALL_ArrayElement(GET_DISPATCH(), (((GLubyte
*) indices
)[i
]));
1286 case GL_UNSIGNED_SHORT
:
1287 for (i
= 0; i
< count
; i
++)
1288 CALL_ArrayElement(GET_DISPATCH(), (((GLushort
*) indices
)[i
]));
1290 case GL_UNSIGNED_INT
:
1291 for (i
= 0; i
< count
; i
++)
1292 CALL_ArrayElement(GET_DISPATCH(), (((GLuint
*) indices
)[i
]));
1295 _mesa_error(ctx
, GL_INVALID_ENUM
, "glDrawElements(type)");
1299 CALL_End(GET_DISPATCH(), ());
1301 _ae_unmap_vbos(ctx
);
1305 static void GLAPIENTRY
1306 _save_OBE_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
1307 GLsizei count
, GLenum type
,
1308 const GLvoid
* indices
)
1310 GET_CURRENT_CONTEXT(ctx
);
1311 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1313 if (!_mesa_validate_DrawRangeElements(ctx
, mode
,
1314 start
, end
, count
, type
, indices
, 0))
1317 if (save
->out_of_memory
)
1320 _save_OBE_DrawElements(mode
, count
, type
, indices
);
1324 static void GLAPIENTRY
1325 _save_OBE_MultiDrawElements(GLenum mode
, const GLsizei
*count
, GLenum type
,
1326 const GLvoid
**indices
, GLsizei primcount
)
1330 for (i
= 0; i
< primcount
; i
++) {
1332 CALL_DrawElements(GET_DISPATCH(), (mode
, count
[i
], type
, indices
[i
]));
1338 static void GLAPIENTRY
1339 _save_OBE_MultiDrawElementsBaseVertex(GLenum mode
, const GLsizei
*count
,
1341 const GLvoid
* const *indices
,
1343 const GLint
*basevertex
)
1347 for (i
= 0; i
< primcount
; i
++) {
1349 CALL_DrawElementsBaseVertex(GET_DISPATCH(), (mode
, count
[i
], type
,
1358 _save_vtxfmt_init(struct gl_context
*ctx
)
1360 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1361 GLvertexformat
*vfmt
= &save
->vtxfmt
;
1363 _MESA_INIT_ARRAYELT_VTXFMT(vfmt
, _ae_
);
1365 vfmt
->Begin
= _save_Begin
;
1366 vfmt
->Color3f
= _save_Color3f
;
1367 vfmt
->Color3fv
= _save_Color3fv
;
1368 vfmt
->Color4f
= _save_Color4f
;
1369 vfmt
->Color4fv
= _save_Color4fv
;
1370 vfmt
->EdgeFlag
= _save_EdgeFlag
;
1371 vfmt
->End
= _save_End
;
1372 vfmt
->PrimitiveRestartNV
= _save_PrimitiveRestartNV
;
1373 vfmt
->FogCoordfEXT
= _save_FogCoordfEXT
;
1374 vfmt
->FogCoordfvEXT
= _save_FogCoordfvEXT
;
1375 vfmt
->Indexf
= _save_Indexf
;
1376 vfmt
->Indexfv
= _save_Indexfv
;
1377 vfmt
->Materialfv
= _save_Materialfv
;
1378 vfmt
->MultiTexCoord1fARB
= _save_MultiTexCoord1f
;
1379 vfmt
->MultiTexCoord1fvARB
= _save_MultiTexCoord1fv
;
1380 vfmt
->MultiTexCoord2fARB
= _save_MultiTexCoord2f
;
1381 vfmt
->MultiTexCoord2fvARB
= _save_MultiTexCoord2fv
;
1382 vfmt
->MultiTexCoord3fARB
= _save_MultiTexCoord3f
;
1383 vfmt
->MultiTexCoord3fvARB
= _save_MultiTexCoord3fv
;
1384 vfmt
->MultiTexCoord4fARB
= _save_MultiTexCoord4f
;
1385 vfmt
->MultiTexCoord4fvARB
= _save_MultiTexCoord4fv
;
1386 vfmt
->Normal3f
= _save_Normal3f
;
1387 vfmt
->Normal3fv
= _save_Normal3fv
;
1388 vfmt
->SecondaryColor3fEXT
= _save_SecondaryColor3fEXT
;
1389 vfmt
->SecondaryColor3fvEXT
= _save_SecondaryColor3fvEXT
;
1390 vfmt
->TexCoord1f
= _save_TexCoord1f
;
1391 vfmt
->TexCoord1fv
= _save_TexCoord1fv
;
1392 vfmt
->TexCoord2f
= _save_TexCoord2f
;
1393 vfmt
->TexCoord2fv
= _save_TexCoord2fv
;
1394 vfmt
->TexCoord3f
= _save_TexCoord3f
;
1395 vfmt
->TexCoord3fv
= _save_TexCoord3fv
;
1396 vfmt
->TexCoord4f
= _save_TexCoord4f
;
1397 vfmt
->TexCoord4fv
= _save_TexCoord4fv
;
1398 vfmt
->Vertex2f
= _save_Vertex2f
;
1399 vfmt
->Vertex2fv
= _save_Vertex2fv
;
1400 vfmt
->Vertex3f
= _save_Vertex3f
;
1401 vfmt
->Vertex3fv
= _save_Vertex3fv
;
1402 vfmt
->Vertex4f
= _save_Vertex4f
;
1403 vfmt
->Vertex4fv
= _save_Vertex4fv
;
1404 vfmt
->VertexAttrib1fARB
= _save_VertexAttrib1fARB
;
1405 vfmt
->VertexAttrib1fvARB
= _save_VertexAttrib1fvARB
;
1406 vfmt
->VertexAttrib2fARB
= _save_VertexAttrib2fARB
;
1407 vfmt
->VertexAttrib2fvARB
= _save_VertexAttrib2fvARB
;
1408 vfmt
->VertexAttrib3fARB
= _save_VertexAttrib3fARB
;
1409 vfmt
->VertexAttrib3fvARB
= _save_VertexAttrib3fvARB
;
1410 vfmt
->VertexAttrib4fARB
= _save_VertexAttrib4fARB
;
1411 vfmt
->VertexAttrib4fvARB
= _save_VertexAttrib4fvARB
;
1413 vfmt
->VertexAttrib1fNV
= _save_VertexAttrib1fNV
;
1414 vfmt
->VertexAttrib1fvNV
= _save_VertexAttrib1fvNV
;
1415 vfmt
->VertexAttrib2fNV
= _save_VertexAttrib2fNV
;
1416 vfmt
->VertexAttrib2fvNV
= _save_VertexAttrib2fvNV
;
1417 vfmt
->VertexAttrib3fNV
= _save_VertexAttrib3fNV
;
1418 vfmt
->VertexAttrib3fvNV
= _save_VertexAttrib3fvNV
;
1419 vfmt
->VertexAttrib4fNV
= _save_VertexAttrib4fNV
;
1420 vfmt
->VertexAttrib4fvNV
= _save_VertexAttrib4fvNV
;
1422 /* integer-valued */
1423 vfmt
->VertexAttribI1i
= _save_VertexAttribI1i
;
1424 vfmt
->VertexAttribI2i
= _save_VertexAttribI2i
;
1425 vfmt
->VertexAttribI3i
= _save_VertexAttribI3i
;
1426 vfmt
->VertexAttribI4i
= _save_VertexAttribI4i
;
1427 vfmt
->VertexAttribI2iv
= _save_VertexAttribI2iv
;
1428 vfmt
->VertexAttribI3iv
= _save_VertexAttribI3iv
;
1429 vfmt
->VertexAttribI4iv
= _save_VertexAttribI4iv
;
1431 /* unsigned integer-valued */
1432 vfmt
->VertexAttribI1ui
= _save_VertexAttribI1ui
;
1433 vfmt
->VertexAttribI2ui
= _save_VertexAttribI2ui
;
1434 vfmt
->VertexAttribI3ui
= _save_VertexAttribI3ui
;
1435 vfmt
->VertexAttribI4ui
= _save_VertexAttribI4ui
;
1436 vfmt
->VertexAttribI2uiv
= _save_VertexAttribI2uiv
;
1437 vfmt
->VertexAttribI3uiv
= _save_VertexAttribI3uiv
;
1438 vfmt
->VertexAttribI4uiv
= _save_VertexAttribI4uiv
;
1440 vfmt
->VertexP2ui
= _save_VertexP2ui
;
1441 vfmt
->VertexP3ui
= _save_VertexP3ui
;
1442 vfmt
->VertexP4ui
= _save_VertexP4ui
;
1443 vfmt
->VertexP2uiv
= _save_VertexP2uiv
;
1444 vfmt
->VertexP3uiv
= _save_VertexP3uiv
;
1445 vfmt
->VertexP4uiv
= _save_VertexP4uiv
;
1447 vfmt
->TexCoordP1ui
= _save_TexCoordP1ui
;
1448 vfmt
->TexCoordP2ui
= _save_TexCoordP2ui
;
1449 vfmt
->TexCoordP3ui
= _save_TexCoordP3ui
;
1450 vfmt
->TexCoordP4ui
= _save_TexCoordP4ui
;
1451 vfmt
->TexCoordP1uiv
= _save_TexCoordP1uiv
;
1452 vfmt
->TexCoordP2uiv
= _save_TexCoordP2uiv
;
1453 vfmt
->TexCoordP3uiv
= _save_TexCoordP3uiv
;
1454 vfmt
->TexCoordP4uiv
= _save_TexCoordP4uiv
;
1456 vfmt
->MultiTexCoordP1ui
= _save_MultiTexCoordP1ui
;
1457 vfmt
->MultiTexCoordP2ui
= _save_MultiTexCoordP2ui
;
1458 vfmt
->MultiTexCoordP3ui
= _save_MultiTexCoordP3ui
;
1459 vfmt
->MultiTexCoordP4ui
= _save_MultiTexCoordP4ui
;
1460 vfmt
->MultiTexCoordP1uiv
= _save_MultiTexCoordP1uiv
;
1461 vfmt
->MultiTexCoordP2uiv
= _save_MultiTexCoordP2uiv
;
1462 vfmt
->MultiTexCoordP3uiv
= _save_MultiTexCoordP3uiv
;
1463 vfmt
->MultiTexCoordP4uiv
= _save_MultiTexCoordP4uiv
;
1465 vfmt
->NormalP3ui
= _save_NormalP3ui
;
1466 vfmt
->NormalP3uiv
= _save_NormalP3uiv
;
1468 vfmt
->ColorP3ui
= _save_ColorP3ui
;
1469 vfmt
->ColorP4ui
= _save_ColorP4ui
;
1470 vfmt
->ColorP3uiv
= _save_ColorP3uiv
;
1471 vfmt
->ColorP4uiv
= _save_ColorP4uiv
;
1473 vfmt
->SecondaryColorP3ui
= _save_SecondaryColorP3ui
;
1474 vfmt
->SecondaryColorP3uiv
= _save_SecondaryColorP3uiv
;
1476 vfmt
->VertexAttribP1ui
= _save_VertexAttribP1ui
;
1477 vfmt
->VertexAttribP2ui
= _save_VertexAttribP2ui
;
1478 vfmt
->VertexAttribP3ui
= _save_VertexAttribP3ui
;
1479 vfmt
->VertexAttribP4ui
= _save_VertexAttribP4ui
;
1481 vfmt
->VertexAttribP1uiv
= _save_VertexAttribP1uiv
;
1482 vfmt
->VertexAttribP2uiv
= _save_VertexAttribP2uiv
;
1483 vfmt
->VertexAttribP3uiv
= _save_VertexAttribP3uiv
;
1484 vfmt
->VertexAttribP4uiv
= _save_VertexAttribP4uiv
;
1486 /* This will all require us to fallback to saving the list as opcodes:
1488 _MESA_INIT_DLIST_VTXFMT(vfmt
, _save_
); /* inside begin/end */
1490 _MESA_INIT_EVAL_VTXFMT(vfmt
, _save_
);
1492 /* These calls all generate GL_INVALID_OPERATION since this vtxfmt is
1493 * only used when we're inside a glBegin/End pair.
1495 vfmt
->Begin
= _save_Begin
;
1496 vfmt
->Rectf
= _save_Rectf
;
1497 vfmt
->DrawArrays
= _save_DrawArrays
;
1498 vfmt
->DrawElements
= _save_DrawElements
;
1499 vfmt
->DrawRangeElements
= _save_DrawRangeElements
;
1500 vfmt
->DrawElementsBaseVertex
= _save_DrawElementsBaseVertex
;
1501 vfmt
->DrawRangeElementsBaseVertex
= _save_DrawRangeElementsBaseVertex
;
1502 vfmt
->MultiDrawElementsEXT
= _save_MultiDrawElements
;
1503 vfmt
->MultiDrawElementsBaseVertex
= _save_MultiDrawElementsBaseVertex
;
1504 vfmt
->DrawTransformFeedback
= _save_DrawTransformFeedback
;
1505 vfmt
->DrawTransformFeedbackStream
= _save_DrawTransformFeedbackStream
;
1506 vfmt
->DrawTransformFeedbackInstanced
= _save_DrawTransformFeedbackInstanced
;
1507 vfmt
->DrawTransformFeedbackStreamInstanced
=
1508 _save_DrawTransformFeedbackStreamInstanced
;
1513 vbo_save_SaveFlushVertices(struct gl_context
*ctx
)
1515 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1517 /* Noop when we are actually active:
1519 if (ctx
->Driver
.CurrentSavePrimitive
== PRIM_INSIDE_UNKNOWN_PRIM
||
1520 ctx
->Driver
.CurrentSavePrimitive
<= GL_POLYGON
)
1523 if (save
->vert_count
|| save
->prim_count
)
1524 _save_compile_vertex_list(ctx
);
1526 _save_copy_to_current(ctx
);
1527 _save_reset_vertex(ctx
);
1528 _save_reset_counters(ctx
);
1529 ctx
->Driver
.SaveNeedFlush
= 0;
1534 vbo_save_NewList(struct gl_context
*ctx
, GLuint list
, GLenum mode
)
1536 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1541 if (!save
->prim_store
)
1542 save
->prim_store
= alloc_prim_store(ctx
);
1544 if (!save
->vertex_store
)
1545 save
->vertex_store
= alloc_vertex_store(ctx
);
1547 save
->buffer_ptr
= vbo_save_map_vertex_store(ctx
, save
->vertex_store
);
1549 _save_reset_vertex(ctx
);
1550 _save_reset_counters(ctx
);
1551 ctx
->Driver
.SaveNeedFlush
= 0;
1556 vbo_save_EndList(struct gl_context
*ctx
)
1558 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1560 /* EndList called inside a (saved) Begin/End pair?
1562 if (ctx
->Driver
.CurrentSavePrimitive
!= PRIM_OUTSIDE_BEGIN_END
) {
1564 if (save
->prim_count
> 0) {
1565 GLint i
= save
->prim_count
- 1;
1566 ctx
->Driver
.CurrentSavePrimitive
= PRIM_OUTSIDE_BEGIN_END
;
1567 save
->prim
[i
].end
= 0;
1568 save
->prim
[i
].count
= (save
->vert_count
- save
->prim
[i
].start
);
1571 /* Make sure this vertex list gets replayed by the "loopback"
1574 save
->dangling_attr_ref
= 1;
1575 vbo_save_SaveFlushVertices(ctx
);
1577 /* Swap out this vertex format while outside begin/end. Any color,
1578 * etc. received between here and the next begin will be compiled
1581 _mesa_install_save_vtxfmt(ctx
, &ctx
->ListState
.ListVtxfmt
);
1584 vbo_save_unmap_vertex_store(ctx
, save
->vertex_store
);
1586 assert(save
->vertex_size
== 0);
1591 vbo_save_BeginCallList(struct gl_context
*ctx
, struct gl_display_list
*dlist
)
1593 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1594 save
->replay_flags
|= dlist
->Flags
;
1599 vbo_save_EndCallList(struct gl_context
*ctx
)
1601 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1603 if (ctx
->ListState
.CallDepth
== 1) {
1604 /* This is correct: want to keep only the VBO_SAVE_FALLBACK
1605 * flag, if it is set:
1607 save
->replay_flags
&= VBO_SAVE_FALLBACK
;
1613 vbo_destroy_vertex_list(struct gl_context
*ctx
, void *data
)
1615 struct vbo_save_vertex_list
*node
= (struct vbo_save_vertex_list
*) data
;
1618 if (--node
->vertex_store
->refcount
== 0)
1619 free_vertex_store(ctx
, node
->vertex_store
);
1621 if (--node
->prim_store
->refcount
== 0)
1622 free(node
->prim_store
);
1624 free(node
->current_data
);
1625 node
->current_data
= NULL
;
1630 vbo_print_vertex_list(struct gl_context
*ctx
, void *data
)
1632 struct vbo_save_vertex_list
*node
= (struct vbo_save_vertex_list
*) data
;
1636 printf("VBO-VERTEX-LIST, %u vertices %d primitives, %d vertsize\n",
1637 node
->count
, node
->prim_count
, node
->vertex_size
);
1639 for (i
= 0; i
< node
->prim_count
; i
++) {
1640 struct _mesa_prim
*prim
= &node
->prim
[i
];
1641 printf(" prim %d: %s%s %d..%d %s %s\n",
1643 _mesa_lookup_prim_by_nr(prim
->mode
),
1644 prim
->weak
? " (weak)" : "",
1646 prim
->start
+ prim
->count
,
1647 (prim
->begin
) ? "BEGIN" : "(wrap)",
1648 (prim
->end
) ? "END" : "(wrap)");
1654 * Called during context creation/init.
1657 _save_current_init(struct gl_context
*ctx
)
1659 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1662 for (i
= VBO_ATTRIB_POS
; i
<= VBO_ATTRIB_GENERIC15
; i
++) {
1663 const GLuint j
= i
- VBO_ATTRIB_POS
;
1664 ASSERT(j
< VERT_ATTRIB_MAX
);
1665 save
->currentsz
[i
] = &ctx
->ListState
.ActiveAttribSize
[j
];
1666 save
->current
[i
] = ctx
->ListState
.CurrentAttrib
[j
];
1669 for (i
= VBO_ATTRIB_FIRST_MATERIAL
; i
<= VBO_ATTRIB_LAST_MATERIAL
; i
++) {
1670 const GLuint j
= i
- VBO_ATTRIB_FIRST_MATERIAL
;
1671 ASSERT(j
< MAT_ATTRIB_MAX
);
1672 save
->currentsz
[i
] = &ctx
->ListState
.ActiveMaterialSize
[j
];
1673 save
->current
[i
] = ctx
->ListState
.CurrentMaterial
[j
];
1679 * Initialize the display list compiler. Called during context creation.
1682 vbo_save_api_init(struct vbo_save_context
*save
)
1684 struct gl_context
*ctx
= save
->ctx
;
1687 save
->opcode_vertex_list
=
1688 _mesa_dlist_alloc_opcode(ctx
,
1689 sizeof(struct vbo_save_vertex_list
),
1690 vbo_save_playback_vertex_list
,
1691 vbo_destroy_vertex_list
,
1692 vbo_print_vertex_list
);
1694 ctx
->Driver
.NotifySaveBegin
= vbo_save_NotifyBegin
;
1696 _save_vtxfmt_init(ctx
);
1697 _save_current_init(ctx
);
1698 _mesa_noop_vtxfmt_init(&save
->vtxfmt_noop
);
1700 /* These will actually get set again when binding/drawing */
1701 for (i
= 0; i
< VBO_ATTRIB_MAX
; i
++)
1702 save
->inputs
[i
] = &save
->arrays
[i
];
1704 /* Hook our array functions into the outside-begin-end vtxfmt in
1707 ctx
->ListState
.ListVtxfmt
.Rectf
= _save_OBE_Rectf
;
1708 ctx
->ListState
.ListVtxfmt
.DrawArrays
= _save_OBE_DrawArrays
;
1709 ctx
->ListState
.ListVtxfmt
.DrawElements
= _save_OBE_DrawElements
;
1710 ctx
->ListState
.ListVtxfmt
.DrawRangeElements
= _save_OBE_DrawRangeElements
;
1711 ctx
->ListState
.ListVtxfmt
.MultiDrawElementsEXT
= _save_OBE_MultiDrawElements
;
1712 ctx
->ListState
.ListVtxfmt
.MultiDrawElementsBaseVertex
= _save_OBE_MultiDrawElementsBaseVertex
;