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;
306 * Insert the active immediate struct onto the display list currently
310 _save_compile_vertex_list(struct gl_context
*ctx
)
312 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
313 struct vbo_save_vertex_list
*node
;
315 /* Allocate space for this structure in the display list currently
318 node
= (struct vbo_save_vertex_list
*)
319 _mesa_dlist_alloc(ctx
, save
->opcode_vertex_list
, sizeof(*node
));
324 /* Duplicate our template, increment refcounts to the storage structs:
326 memcpy(node
->attrsz
, save
->attrsz
, sizeof(node
->attrsz
));
327 node
->vertex_size
= save
->vertex_size
;
328 node
->buffer_offset
=
329 (save
->buffer
- save
->vertex_store
->buffer
) * sizeof(GLfloat
);
330 node
->count
= save
->vert_count
;
331 node
->wrap_count
= save
->copied
.nr
;
332 node
->dangling_attr_ref
= save
->dangling_attr_ref
;
333 node
->prim
= save
->prim
;
334 node
->prim_count
= save
->prim_count
;
335 node
->vertex_store
= save
->vertex_store
;
336 node
->prim_store
= save
->prim_store
;
338 node
->vertex_store
->refcount
++;
339 node
->prim_store
->refcount
++;
341 if (node
->prim
[0].no_current_update
) {
342 node
->current_size
= 0;
343 node
->current_data
= NULL
;
346 node
->current_size
= node
->vertex_size
- node
->attrsz
[0];
347 node
->current_data
= NULL
;
349 if (node
->current_size
) {
350 /* If the malloc fails, we just pull the data out of the VBO
353 node
->current_data
= malloc(node
->current_size
* sizeof(GLfloat
));
354 if (node
->current_data
) {
355 const char *buffer
= (const char *) save
->vertex_store
->buffer
;
356 unsigned attr_offset
= node
->attrsz
[0] * sizeof(GLfloat
);
357 unsigned vertex_offset
= 0;
361 (node
->count
- 1) * node
->vertex_size
* sizeof(GLfloat
);
363 memcpy(node
->current_data
,
364 buffer
+ node
->buffer_offset
+ vertex_offset
+ attr_offset
,
365 node
->current_size
* sizeof(GLfloat
));
370 assert(node
->attrsz
[VBO_ATTRIB_POS
] != 0 || node
->count
== 0);
372 if (save
->dangling_attr_ref
)
373 ctx
->ListState
.CurrentList
->Flags
|= DLIST_DANGLING_REFS
;
375 save
->vertex_store
->used
+= save
->vertex_size
* node
->count
;
376 save
->prim_store
->used
+= node
->prim_count
;
378 /* Copy duplicated vertices
380 save
->copied
.nr
= _save_copy_vertices(ctx
, node
, save
->buffer
);
382 /* Deal with GL_COMPILE_AND_EXECUTE:
384 if (ctx
->ExecuteFlag
) {
385 struct _glapi_table
*dispatch
= GET_DISPATCH();
387 _glapi_set_dispatch(ctx
->Exec
);
389 vbo_loopback_vertex_list(ctx
,
390 (const GLfloat
*) ((const char *) save
->
391 vertex_store
->buffer
+
392 node
->buffer_offset
),
393 node
->attrsz
, node
->prim
, node
->prim_count
,
394 node
->wrap_count
, node
->vertex_size
);
396 _glapi_set_dispatch(dispatch
);
399 /* Decide whether the storage structs are full, or can be used for
400 * the next vertex lists as well.
402 if (save
->vertex_store
->used
>
403 VBO_SAVE_BUFFER_SIZE
- 16 * (save
->vertex_size
+ 4)) {
407 vbo_save_unmap_vertex_store(ctx
, save
->vertex_store
);
409 /* Release old reference:
411 save
->vertex_store
->refcount
--;
412 assert(save
->vertex_store
->refcount
!= 0);
413 save
->vertex_store
= NULL
;
415 /* Allocate and map new store:
417 save
->vertex_store
= alloc_vertex_store(ctx
);
418 save
->buffer_ptr
= vbo_save_map_vertex_store(ctx
, save
->vertex_store
);
419 save
->out_of_memory
= save
->buffer_ptr
== NULL
;
422 if (save
->prim_store
->used
> VBO_SAVE_PRIM_SIZE
- 6) {
423 save
->prim_store
->refcount
--;
424 assert(save
->prim_store
->refcount
!= 0);
425 save
->prim_store
= alloc_prim_store(ctx
);
428 /* Reset our structures for the next run of vertices:
430 _save_reset_counters(ctx
);
435 * TODO -- If no new vertices have been stored, don't bother saving it.
438 _save_wrap_buffers(struct gl_context
*ctx
)
440 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
441 GLint i
= save
->prim_count
- 1;
444 GLboolean no_current_update
;
446 assert(i
< (GLint
) save
->prim_max
);
449 /* Close off in-progress primitive.
451 save
->prim
[i
].count
= (save
->vert_count
- save
->prim
[i
].start
);
452 mode
= save
->prim
[i
].mode
;
453 weak
= save
->prim
[i
].weak
;
454 no_current_update
= save
->prim
[i
].no_current_update
;
456 /* store the copied vertices, and allocate a new list.
458 _save_compile_vertex_list(ctx
);
460 /* Restart interrupted primitive
462 save
->prim
[0].mode
= mode
;
463 save
->prim
[0].weak
= weak
;
464 save
->prim
[0].no_current_update
= no_current_update
;
465 save
->prim
[0].begin
= 0;
466 save
->prim
[0].end
= 0;
467 save
->prim
[0].pad
= 0;
468 save
->prim
[0].start
= 0;
469 save
->prim
[0].count
= 0;
470 save
->prim
[0].num_instances
= 1;
471 save
->prim
[0].base_instance
= 0;
472 save
->prim_count
= 1;
477 * Called only when buffers are wrapped as the result of filling the
478 * vertex_store struct.
481 _save_wrap_filled_vertex(struct gl_context
*ctx
)
483 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
484 GLfloat
*data
= save
->copied
.buffer
;
487 /* Emit a glEnd to close off the last vertex list.
489 _save_wrap_buffers(ctx
);
491 /* Copy stored stored vertices to start of new list.
493 assert(save
->max_vert
- save
->vert_count
> save
->copied
.nr
);
495 for (i
= 0; i
< save
->copied
.nr
; i
++) {
496 memcpy(save
->buffer_ptr
, data
, save
->vertex_size
* sizeof(GLfloat
));
497 data
+= save
->vertex_size
;
498 save
->buffer_ptr
+= save
->vertex_size
;
505 _save_copy_to_current(struct gl_context
*ctx
)
507 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
510 for (i
= VBO_ATTRIB_POS
+ 1; i
< VBO_ATTRIB_MAX
; i
++) {
511 if (save
->attrsz
[i
]) {
512 save
->currentsz
[i
][0] = save
->attrsz
[i
];
513 COPY_CLEAN_4V(save
->current
[i
], save
->attrsz
[i
], save
->attrptr
[i
]);
520 _save_copy_from_current(struct gl_context
*ctx
)
522 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
525 for (i
= VBO_ATTRIB_POS
+ 1; i
< VBO_ATTRIB_MAX
; i
++) {
526 switch (save
->attrsz
[i
]) {
528 save
->attrptr
[i
][3] = save
->current
[i
][3];
530 save
->attrptr
[i
][2] = save
->current
[i
][2];
532 save
->attrptr
[i
][1] = save
->current
[i
][1];
534 save
->attrptr
[i
][0] = save
->current
[i
][0];
542 /* Flush existing data, set new attrib size, replay copied vertices.
545 _save_upgrade_vertex(struct gl_context
*ctx
, GLuint attr
, GLuint newsz
)
547 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
552 /* Store the current run of vertices, and emit a GL_END. Emit a
553 * BEGIN in the new buffer.
555 if (save
->vert_count
)
556 _save_wrap_buffers(ctx
);
558 assert(save
->copied
.nr
== 0);
560 /* Do a COPY_TO_CURRENT to ensure back-copying works for the case
561 * when the attribute already exists in the vertex and is having
562 * its size increased.
564 _save_copy_to_current(ctx
);
568 oldsz
= save
->attrsz
[attr
];
569 save
->attrsz
[attr
] = newsz
;
571 save
->vertex_size
+= newsz
- oldsz
;
572 save
->max_vert
= ((VBO_SAVE_BUFFER_SIZE
- save
->vertex_store
->used
) /
574 save
->vert_count
= 0;
576 /* Recalculate all the attrptr[] values:
578 for (i
= 0, tmp
= save
->vertex
; i
< VBO_ATTRIB_MAX
; i
++) {
579 if (save
->attrsz
[i
]) {
580 save
->attrptr
[i
] = tmp
;
581 tmp
+= save
->attrsz
[i
];
584 save
->attrptr
[i
] = NULL
; /* will not be dereferenced. */
588 /* Copy from current to repopulate the vertex with correct values.
590 _save_copy_from_current(ctx
);
592 /* Replay stored vertices to translate them to new format here.
594 * If there are copied vertices and the new (upgraded) attribute
595 * has not been defined before, this list is somewhat degenerate,
596 * and will need fixup at runtime.
598 if (save
->copied
.nr
) {
599 GLfloat
*data
= save
->copied
.buffer
;
600 GLfloat
*dest
= save
->buffer
;
603 /* Need to note this and fix up at runtime (or loopback):
605 if (attr
!= VBO_ATTRIB_POS
&& save
->currentsz
[attr
][0] == 0) {
607 save
->dangling_attr_ref
= GL_TRUE
;
610 for (i
= 0; i
< save
->copied
.nr
; i
++) {
611 for (j
= 0; j
< VBO_ATTRIB_MAX
; j
++) {
612 if (save
->attrsz
[j
]) {
615 COPY_CLEAN_4V(dest
, oldsz
, data
);
620 COPY_SZ_4V(dest
, newsz
, save
->current
[attr
]);
625 GLint sz
= save
->attrsz
[j
];
626 COPY_SZ_4V(dest
, sz
, data
);
634 save
->buffer_ptr
= dest
;
635 save
->vert_count
+= save
->copied
.nr
;
641 save_fixup_vertex(struct gl_context
*ctx
, GLuint attr
, GLuint sz
)
643 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
645 if (sz
> save
->attrsz
[attr
]) {
646 /* New size is larger. Need to flush existing vertices and get
647 * an enlarged vertex format.
649 _save_upgrade_vertex(ctx
, attr
, sz
);
651 else if (sz
< save
->active_sz
[attr
]) {
652 static GLfloat id
[4] = { 0, 0, 0, 1 };
655 /* New size is equal or smaller - just need to fill in some
658 for (i
= sz
; i
<= save
->attrsz
[attr
]; i
++)
659 save
->attrptr
[attr
][i
- 1] = id
[i
- 1];
662 save
->active_sz
[attr
] = sz
;
667 _save_reset_vertex(struct gl_context
*ctx
)
669 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
672 for (i
= 0; i
< VBO_ATTRIB_MAX
; i
++) {
674 save
->active_sz
[i
] = 0;
677 save
->vertex_size
= 0;
682 #define ERROR(err) _mesa_compile_error(ctx, err, __FUNCTION__);
685 /* Only one size for each attribute may be active at once. Eg. if
686 * Color3f is installed/active, then Color4f may not be, even if the
687 * vertex actually contains 4 color coordinates. This is because the
688 * 3f version won't otherwise set color[3] to 1.0 -- this is the job
689 * of the chooser function when switching between Color4f and Color3f.
691 #define ATTR(A, N, V0, V1, V2, V3) \
693 struct vbo_save_context *save = &vbo_context(ctx)->save; \
695 if (save->active_sz[A] != N) \
696 save_fixup_vertex(ctx, A, N); \
699 GLfloat *dest = save->attrptr[A]; \
700 if (N>0) dest[0] = V0; \
701 if (N>1) dest[1] = V1; \
702 if (N>2) dest[2] = V2; \
703 if (N>3) dest[3] = V3; \
709 for (i = 0; i < save->vertex_size; i++) \
710 save->buffer_ptr[i] = save->vertex[i]; \
712 save->buffer_ptr += save->vertex_size; \
714 if (++save->vert_count >= save->max_vert) \
715 _save_wrap_filled_vertex(ctx); \
719 #define TAG(x) _save_##x
721 #include "vbo_attrib_tmp.h"
725 #define MAT( ATTR, N, face, params ) \
727 if (face != GL_BACK) \
728 MAT_ATTR( ATTR, N, params ); /* front */ \
729 if (face != GL_FRONT) \
730 MAT_ATTR( ATTR + 1, N, params ); /* back */ \
735 * Save a glMaterial call found between glBegin/End.
736 * glMaterial calls outside Begin/End are handled in dlist.c.
738 static void GLAPIENTRY
739 _save_Materialfv(GLenum face
, GLenum pname
, const GLfloat
*params
)
741 GET_CURRENT_CONTEXT(ctx
);
743 if (face
!= GL_FRONT
&& face
!= GL_BACK
&& face
!= GL_FRONT_AND_BACK
) {
744 _mesa_compile_error(ctx
, GL_INVALID_ENUM
, "glMaterial(face)");
750 MAT(VBO_ATTRIB_MAT_FRONT_EMISSION
, 4, face
, params
);
753 MAT(VBO_ATTRIB_MAT_FRONT_AMBIENT
, 4, face
, params
);
756 MAT(VBO_ATTRIB_MAT_FRONT_DIFFUSE
, 4, face
, params
);
759 MAT(VBO_ATTRIB_MAT_FRONT_SPECULAR
, 4, face
, params
);
762 if (*params
< 0 || *params
> ctx
->Const
.MaxShininess
) {
763 _mesa_compile_error(ctx
, GL_INVALID_VALUE
, "glMaterial(shininess)");
766 MAT(VBO_ATTRIB_MAT_FRONT_SHININESS
, 1, face
, params
);
769 case GL_COLOR_INDEXES
:
770 MAT(VBO_ATTRIB_MAT_FRONT_INDEXES
, 3, face
, params
);
772 case GL_AMBIENT_AND_DIFFUSE
:
773 MAT(VBO_ATTRIB_MAT_FRONT_AMBIENT
, 4, face
, params
);
774 MAT(VBO_ATTRIB_MAT_FRONT_DIFFUSE
, 4, face
, params
);
777 _mesa_compile_error(ctx
, GL_INVALID_ENUM
, "glMaterial(pname)");
783 /* Cope with EvalCoord/CallList called within a begin/end object:
784 * -- Flush current buffer
785 * -- Fallback to opcodes for the rest of the begin/end object.
788 dlist_fallback(struct gl_context
*ctx
)
790 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
792 if (save
->vert_count
|| save
->prim_count
) {
793 if (save
->prim_count
> 0) {
794 /* Close off in-progress primitive. */
795 GLint i
= save
->prim_count
- 1;
796 save
->prim
[i
].count
= save
->vert_count
- save
->prim
[i
].start
;
799 /* Need to replay this display list with loopback,
800 * unfortunately, otherwise this primitive won't be handled
803 save
->dangling_attr_ref
= 1;
805 _save_compile_vertex_list(ctx
);
808 _save_copy_to_current(ctx
);
809 _save_reset_vertex(ctx
);
810 _save_reset_counters(ctx
);
811 if (save
->out_of_memory
) {
812 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt_noop
);
815 _mesa_install_save_vtxfmt(ctx
, &ctx
->ListState
.ListVtxfmt
);
817 ctx
->Driver
.SaveNeedFlush
= 0;
821 static void GLAPIENTRY
822 _save_EvalCoord1f(GLfloat u
)
824 GET_CURRENT_CONTEXT(ctx
);
826 CALL_EvalCoord1f(ctx
->Save
, (u
));
829 static void GLAPIENTRY
830 _save_EvalCoord1fv(const GLfloat
* v
)
832 GET_CURRENT_CONTEXT(ctx
);
834 CALL_EvalCoord1fv(ctx
->Save
, (v
));
837 static void GLAPIENTRY
838 _save_EvalCoord2f(GLfloat u
, GLfloat v
)
840 GET_CURRENT_CONTEXT(ctx
);
842 CALL_EvalCoord2f(ctx
->Save
, (u
, v
));
845 static void GLAPIENTRY
846 _save_EvalCoord2fv(const GLfloat
* v
)
848 GET_CURRENT_CONTEXT(ctx
);
850 CALL_EvalCoord2fv(ctx
->Save
, (v
));
853 static void GLAPIENTRY
854 _save_EvalPoint1(GLint i
)
856 GET_CURRENT_CONTEXT(ctx
);
858 CALL_EvalPoint1(ctx
->Save
, (i
));
861 static void GLAPIENTRY
862 _save_EvalPoint2(GLint i
, GLint j
)
864 GET_CURRENT_CONTEXT(ctx
);
866 CALL_EvalPoint2(ctx
->Save
, (i
, j
));
869 static void GLAPIENTRY
870 _save_CallList(GLuint l
)
872 GET_CURRENT_CONTEXT(ctx
);
874 CALL_CallList(ctx
->Save
, (l
));
877 static void GLAPIENTRY
878 _save_CallLists(GLsizei n
, GLenum type
, const GLvoid
* v
)
880 GET_CURRENT_CONTEXT(ctx
);
882 CALL_CallLists(ctx
->Save
, (n
, type
, v
));
887 /* This begin is hooked into ... Updating of
888 * ctx->Driver.CurrentSavePrimitive is already taken care of.
891 vbo_save_NotifyBegin(struct gl_context
*ctx
, GLenum mode
)
893 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
895 GLuint i
= save
->prim_count
++;
897 assert(i
< save
->prim_max
);
898 save
->prim
[i
].mode
= mode
& VBO_SAVE_PRIM_MODE_MASK
;
899 save
->prim
[i
].begin
= 1;
900 save
->prim
[i
].end
= 0;
901 save
->prim
[i
].weak
= (mode
& VBO_SAVE_PRIM_WEAK
) ? 1 : 0;
902 save
->prim
[i
].no_current_update
=
903 (mode
& VBO_SAVE_PRIM_NO_CURRENT_UPDATE
) ? 1 : 0;
904 save
->prim
[i
].pad
= 0;
905 save
->prim
[i
].start
= save
->vert_count
;
906 save
->prim
[i
].count
= 0;
907 save
->prim
[i
].num_instances
= 1;
908 save
->prim
[i
].base_instance
= 0;
910 if (save
->out_of_memory
) {
911 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt_noop
);
914 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt
);
916 ctx
->Driver
.SaveNeedFlush
= 1;
921 static void GLAPIENTRY
924 GET_CURRENT_CONTEXT(ctx
);
925 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
926 GLint i
= save
->prim_count
- 1;
928 ctx
->Driver
.CurrentSavePrimitive
= PRIM_OUTSIDE_BEGIN_END
;
929 save
->prim
[i
].end
= 1;
930 save
->prim
[i
].count
= (save
->vert_count
- save
->prim
[i
].start
);
932 if (i
== (GLint
) save
->prim_max
- 1) {
933 _save_compile_vertex_list(ctx
);
934 assert(save
->copied
.nr
== 0);
937 /* Swap out this vertex format while outside begin/end. Any color,
938 * etc. received between here and the next begin will be compiled
941 if (save
->out_of_memory
) {
942 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt_noop
);
945 _mesa_install_save_vtxfmt(ctx
, &ctx
->ListState
.ListVtxfmt
);
950 /* These are all errors as this vtxfmt is only installed inside
953 static void GLAPIENTRY
954 _save_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
955 const GLvoid
* indices
)
957 GET_CURRENT_CONTEXT(ctx
);
962 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawElements");
966 static void GLAPIENTRY
967 _save_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
968 GLsizei count
, GLenum type
, const GLvoid
* indices
)
970 GET_CURRENT_CONTEXT(ctx
);
977 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawRangeElements");
981 static void GLAPIENTRY
982 _save_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
983 const GLvoid
* indices
, GLint basevertex
)
985 GET_CURRENT_CONTEXT(ctx
);
991 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawElements");
995 static void GLAPIENTRY
996 _save_DrawRangeElementsBaseVertex(GLenum mode
,
1001 const GLvoid
* indices
, GLint basevertex
)
1003 GET_CURRENT_CONTEXT(ctx
);
1011 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawRangeElements");
1015 static void GLAPIENTRY
1016 _save_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
1018 GET_CURRENT_CONTEXT(ctx
);
1022 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawArrays");
1026 static void GLAPIENTRY
1027 _save_MultiDrawElements(GLenum mode
, const GLsizei
*count
, GLenum type
,
1028 const GLvoid
**indices
, GLsizei primcount
)
1030 GET_CURRENT_CONTEXT(ctx
);
1036 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glMultiDrawElements");
1040 static void GLAPIENTRY
1041 _save_MultiDrawElementsBaseVertex(GLenum mode
, const GLsizei
*count
,
1042 GLenum type
, const GLvoid
* const *indices
,
1043 GLsizei primcount
, const GLint
*basevertex
)
1045 GET_CURRENT_CONTEXT(ctx
);
1052 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
,
1053 "glMultiDrawElementsBaseVertex");
1057 static void GLAPIENTRY
1058 _save_DrawTransformFeedback(GLenum mode
, GLuint name
)
1060 GET_CURRENT_CONTEXT(ctx
);
1063 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawTransformFeedback");
1067 static void GLAPIENTRY
1068 _save_DrawTransformFeedbackStream(GLenum mode
, GLuint name
, GLuint stream
)
1070 GET_CURRENT_CONTEXT(ctx
);
1074 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
,
1075 "glDrawTransformFeedbackStream");
1079 static void GLAPIENTRY
1080 _save_DrawTransformFeedbackInstanced(GLenum mode
, GLuint name
,
1083 GET_CURRENT_CONTEXT(ctx
);
1087 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
,
1088 "glDrawTransformFeedbackInstanced");
1092 static void GLAPIENTRY
1093 _save_DrawTransformFeedbackStreamInstanced(GLenum mode
, GLuint name
,
1094 GLuint stream
, GLsizei primcount
)
1096 GET_CURRENT_CONTEXT(ctx
);
1101 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
,
1102 "glDrawTransformFeedbackStreamInstanced");
1106 static void GLAPIENTRY
1107 _save_Rectf(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
1109 GET_CURRENT_CONTEXT(ctx
);
1114 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glRectf");
1118 static void GLAPIENTRY
1119 _save_EvalMesh1(GLenum mode
, GLint i1
, GLint i2
)
1121 GET_CURRENT_CONTEXT(ctx
);
1125 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glEvalMesh1");
1129 static void GLAPIENTRY
1130 _save_EvalMesh2(GLenum mode
, GLint i1
, GLint i2
, GLint j1
, GLint j2
)
1132 GET_CURRENT_CONTEXT(ctx
);
1138 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glEvalMesh2");
1142 static void GLAPIENTRY
1143 _save_Begin(GLenum mode
)
1145 GET_CURRENT_CONTEXT(ctx
);
1147 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "Recursive glBegin");
1151 static void GLAPIENTRY
1152 _save_PrimitiveRestartNV(void)
1155 GET_CURRENT_CONTEXT(ctx
);
1157 curPrim
= ctx
->Driver
.CurrentSavePrimitive
;
1160 _save_Begin(curPrim
);
1164 /* Unlike the functions above, these are to be hooked into the vtxfmt
1165 * maintained in ctx->ListState, active when the list is known or
1166 * suspected to be outside any begin/end primitive.
1167 * Note: OBE = Outside Begin/End
1169 static void GLAPIENTRY
1170 _save_OBE_Rectf(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
1172 GET_CURRENT_CONTEXT(ctx
);
1173 vbo_save_NotifyBegin(ctx
, GL_QUADS
| VBO_SAVE_PRIM_WEAK
);
1174 CALL_Vertex2f(GET_DISPATCH(), (x1
, y1
));
1175 CALL_Vertex2f(GET_DISPATCH(), (x2
, y1
));
1176 CALL_Vertex2f(GET_DISPATCH(), (x2
, y2
));
1177 CALL_Vertex2f(GET_DISPATCH(), (x1
, y2
));
1178 CALL_End(GET_DISPATCH(), ());
1182 static void GLAPIENTRY
1183 _save_OBE_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
1185 GET_CURRENT_CONTEXT(ctx
);
1186 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1189 if (!_mesa_validate_DrawArrays(ctx
, mode
, start
, count
))
1192 if (save
->out_of_memory
)
1197 vbo_save_NotifyBegin(ctx
, (mode
| VBO_SAVE_PRIM_WEAK
1198 | VBO_SAVE_PRIM_NO_CURRENT_UPDATE
));
1200 for (i
= 0; i
< count
; i
++)
1201 CALL_ArrayElement(GET_DISPATCH(), (start
+ i
));
1202 CALL_End(GET_DISPATCH(), ());
1204 _ae_unmap_vbos(ctx
);
1208 /* Could do better by copying the arrays and element list intact and
1209 * then emitting an indexed prim at runtime.
1211 static void GLAPIENTRY
1212 _save_OBE_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1213 const GLvoid
* indices
)
1215 GET_CURRENT_CONTEXT(ctx
);
1216 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1219 if (!_mesa_validate_DrawElements(ctx
, mode
, count
, type
, indices
, 0))
1222 if (save
->out_of_memory
)
1227 if (_mesa_is_bufferobj(ctx
->Array
.ArrayObj
->ElementArrayBufferObj
))
1229 ADD_POINTERS(ctx
->Array
.ArrayObj
->ElementArrayBufferObj
->Pointer
, indices
);
1231 vbo_save_NotifyBegin(ctx
, (mode
| VBO_SAVE_PRIM_WEAK
|
1232 VBO_SAVE_PRIM_NO_CURRENT_UPDATE
));
1235 case GL_UNSIGNED_BYTE
:
1236 for (i
= 0; i
< count
; i
++)
1237 CALL_ArrayElement(GET_DISPATCH(), (((GLubyte
*) indices
)[i
]));
1239 case GL_UNSIGNED_SHORT
:
1240 for (i
= 0; i
< count
; i
++)
1241 CALL_ArrayElement(GET_DISPATCH(), (((GLushort
*) indices
)[i
]));
1243 case GL_UNSIGNED_INT
:
1244 for (i
= 0; i
< count
; i
++)
1245 CALL_ArrayElement(GET_DISPATCH(), (((GLuint
*) indices
)[i
]));
1248 _mesa_error(ctx
, GL_INVALID_ENUM
, "glDrawElements(type)");
1252 CALL_End(GET_DISPATCH(), ());
1254 _ae_unmap_vbos(ctx
);
1258 static void GLAPIENTRY
1259 _save_OBE_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
1260 GLsizei count
, GLenum type
,
1261 const GLvoid
* indices
)
1263 GET_CURRENT_CONTEXT(ctx
);
1264 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1266 if (!_mesa_validate_DrawRangeElements(ctx
, mode
,
1267 start
, end
, count
, type
, indices
, 0))
1270 if (save
->out_of_memory
)
1273 _save_OBE_DrawElements(mode
, count
, type
, indices
);
1277 static void GLAPIENTRY
1278 _save_OBE_MultiDrawElements(GLenum mode
, const GLsizei
*count
, GLenum type
,
1279 const GLvoid
**indices
, GLsizei primcount
)
1283 for (i
= 0; i
< primcount
; i
++) {
1285 CALL_DrawElements(GET_DISPATCH(), (mode
, count
[i
], type
, indices
[i
]));
1291 static void GLAPIENTRY
1292 _save_OBE_MultiDrawElementsBaseVertex(GLenum mode
, const GLsizei
*count
,
1294 const GLvoid
* const *indices
,
1296 const GLint
*basevertex
)
1300 for (i
= 0; i
< primcount
; i
++) {
1302 CALL_DrawElementsBaseVertex(GET_DISPATCH(), (mode
, count
[i
], type
,
1311 _save_vtxfmt_init(struct gl_context
*ctx
)
1313 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1314 GLvertexformat
*vfmt
= &save
->vtxfmt
;
1316 _MESA_INIT_ARRAYELT_VTXFMT(vfmt
, _ae_
);
1318 vfmt
->Begin
= _save_Begin
;
1319 vfmt
->Color3f
= _save_Color3f
;
1320 vfmt
->Color3fv
= _save_Color3fv
;
1321 vfmt
->Color4f
= _save_Color4f
;
1322 vfmt
->Color4fv
= _save_Color4fv
;
1323 vfmt
->EdgeFlag
= _save_EdgeFlag
;
1324 vfmt
->End
= _save_End
;
1325 vfmt
->PrimitiveRestartNV
= _save_PrimitiveRestartNV
;
1326 vfmt
->FogCoordfEXT
= _save_FogCoordfEXT
;
1327 vfmt
->FogCoordfvEXT
= _save_FogCoordfvEXT
;
1328 vfmt
->Indexf
= _save_Indexf
;
1329 vfmt
->Indexfv
= _save_Indexfv
;
1330 vfmt
->Materialfv
= _save_Materialfv
;
1331 vfmt
->MultiTexCoord1fARB
= _save_MultiTexCoord1f
;
1332 vfmt
->MultiTexCoord1fvARB
= _save_MultiTexCoord1fv
;
1333 vfmt
->MultiTexCoord2fARB
= _save_MultiTexCoord2f
;
1334 vfmt
->MultiTexCoord2fvARB
= _save_MultiTexCoord2fv
;
1335 vfmt
->MultiTexCoord3fARB
= _save_MultiTexCoord3f
;
1336 vfmt
->MultiTexCoord3fvARB
= _save_MultiTexCoord3fv
;
1337 vfmt
->MultiTexCoord4fARB
= _save_MultiTexCoord4f
;
1338 vfmt
->MultiTexCoord4fvARB
= _save_MultiTexCoord4fv
;
1339 vfmt
->Normal3f
= _save_Normal3f
;
1340 vfmt
->Normal3fv
= _save_Normal3fv
;
1341 vfmt
->SecondaryColor3fEXT
= _save_SecondaryColor3fEXT
;
1342 vfmt
->SecondaryColor3fvEXT
= _save_SecondaryColor3fvEXT
;
1343 vfmt
->TexCoord1f
= _save_TexCoord1f
;
1344 vfmt
->TexCoord1fv
= _save_TexCoord1fv
;
1345 vfmt
->TexCoord2f
= _save_TexCoord2f
;
1346 vfmt
->TexCoord2fv
= _save_TexCoord2fv
;
1347 vfmt
->TexCoord3f
= _save_TexCoord3f
;
1348 vfmt
->TexCoord3fv
= _save_TexCoord3fv
;
1349 vfmt
->TexCoord4f
= _save_TexCoord4f
;
1350 vfmt
->TexCoord4fv
= _save_TexCoord4fv
;
1351 vfmt
->Vertex2f
= _save_Vertex2f
;
1352 vfmt
->Vertex2fv
= _save_Vertex2fv
;
1353 vfmt
->Vertex3f
= _save_Vertex3f
;
1354 vfmt
->Vertex3fv
= _save_Vertex3fv
;
1355 vfmt
->Vertex4f
= _save_Vertex4f
;
1356 vfmt
->Vertex4fv
= _save_Vertex4fv
;
1357 vfmt
->VertexAttrib1fARB
= _save_VertexAttrib1fARB
;
1358 vfmt
->VertexAttrib1fvARB
= _save_VertexAttrib1fvARB
;
1359 vfmt
->VertexAttrib2fARB
= _save_VertexAttrib2fARB
;
1360 vfmt
->VertexAttrib2fvARB
= _save_VertexAttrib2fvARB
;
1361 vfmt
->VertexAttrib3fARB
= _save_VertexAttrib3fARB
;
1362 vfmt
->VertexAttrib3fvARB
= _save_VertexAttrib3fvARB
;
1363 vfmt
->VertexAttrib4fARB
= _save_VertexAttrib4fARB
;
1364 vfmt
->VertexAttrib4fvARB
= _save_VertexAttrib4fvARB
;
1366 vfmt
->VertexAttrib1fNV
= _save_VertexAttrib1fNV
;
1367 vfmt
->VertexAttrib1fvNV
= _save_VertexAttrib1fvNV
;
1368 vfmt
->VertexAttrib2fNV
= _save_VertexAttrib2fNV
;
1369 vfmt
->VertexAttrib2fvNV
= _save_VertexAttrib2fvNV
;
1370 vfmt
->VertexAttrib3fNV
= _save_VertexAttrib3fNV
;
1371 vfmt
->VertexAttrib3fvNV
= _save_VertexAttrib3fvNV
;
1372 vfmt
->VertexAttrib4fNV
= _save_VertexAttrib4fNV
;
1373 vfmt
->VertexAttrib4fvNV
= _save_VertexAttrib4fvNV
;
1375 /* integer-valued */
1376 vfmt
->VertexAttribI1i
= _save_VertexAttribI1i
;
1377 vfmt
->VertexAttribI2i
= _save_VertexAttribI2i
;
1378 vfmt
->VertexAttribI3i
= _save_VertexAttribI3i
;
1379 vfmt
->VertexAttribI4i
= _save_VertexAttribI4i
;
1380 vfmt
->VertexAttribI2iv
= _save_VertexAttribI2iv
;
1381 vfmt
->VertexAttribI3iv
= _save_VertexAttribI3iv
;
1382 vfmt
->VertexAttribI4iv
= _save_VertexAttribI4iv
;
1384 /* unsigned integer-valued */
1385 vfmt
->VertexAttribI1ui
= _save_VertexAttribI1ui
;
1386 vfmt
->VertexAttribI2ui
= _save_VertexAttribI2ui
;
1387 vfmt
->VertexAttribI3ui
= _save_VertexAttribI3ui
;
1388 vfmt
->VertexAttribI4ui
= _save_VertexAttribI4ui
;
1389 vfmt
->VertexAttribI2uiv
= _save_VertexAttribI2uiv
;
1390 vfmt
->VertexAttribI3uiv
= _save_VertexAttribI3uiv
;
1391 vfmt
->VertexAttribI4uiv
= _save_VertexAttribI4uiv
;
1393 vfmt
->VertexP2ui
= _save_VertexP2ui
;
1394 vfmt
->VertexP3ui
= _save_VertexP3ui
;
1395 vfmt
->VertexP4ui
= _save_VertexP4ui
;
1396 vfmt
->VertexP2uiv
= _save_VertexP2uiv
;
1397 vfmt
->VertexP3uiv
= _save_VertexP3uiv
;
1398 vfmt
->VertexP4uiv
= _save_VertexP4uiv
;
1400 vfmt
->TexCoordP1ui
= _save_TexCoordP1ui
;
1401 vfmt
->TexCoordP2ui
= _save_TexCoordP2ui
;
1402 vfmt
->TexCoordP3ui
= _save_TexCoordP3ui
;
1403 vfmt
->TexCoordP4ui
= _save_TexCoordP4ui
;
1404 vfmt
->TexCoordP1uiv
= _save_TexCoordP1uiv
;
1405 vfmt
->TexCoordP2uiv
= _save_TexCoordP2uiv
;
1406 vfmt
->TexCoordP3uiv
= _save_TexCoordP3uiv
;
1407 vfmt
->TexCoordP4uiv
= _save_TexCoordP4uiv
;
1409 vfmt
->MultiTexCoordP1ui
= _save_MultiTexCoordP1ui
;
1410 vfmt
->MultiTexCoordP2ui
= _save_MultiTexCoordP2ui
;
1411 vfmt
->MultiTexCoordP3ui
= _save_MultiTexCoordP3ui
;
1412 vfmt
->MultiTexCoordP4ui
= _save_MultiTexCoordP4ui
;
1413 vfmt
->MultiTexCoordP1uiv
= _save_MultiTexCoordP1uiv
;
1414 vfmt
->MultiTexCoordP2uiv
= _save_MultiTexCoordP2uiv
;
1415 vfmt
->MultiTexCoordP3uiv
= _save_MultiTexCoordP3uiv
;
1416 vfmt
->MultiTexCoordP4uiv
= _save_MultiTexCoordP4uiv
;
1418 vfmt
->NormalP3ui
= _save_NormalP3ui
;
1419 vfmt
->NormalP3uiv
= _save_NormalP3uiv
;
1421 vfmt
->ColorP3ui
= _save_ColorP3ui
;
1422 vfmt
->ColorP4ui
= _save_ColorP4ui
;
1423 vfmt
->ColorP3uiv
= _save_ColorP3uiv
;
1424 vfmt
->ColorP4uiv
= _save_ColorP4uiv
;
1426 vfmt
->SecondaryColorP3ui
= _save_SecondaryColorP3ui
;
1427 vfmt
->SecondaryColorP3uiv
= _save_SecondaryColorP3uiv
;
1429 vfmt
->VertexAttribP1ui
= _save_VertexAttribP1ui
;
1430 vfmt
->VertexAttribP2ui
= _save_VertexAttribP2ui
;
1431 vfmt
->VertexAttribP3ui
= _save_VertexAttribP3ui
;
1432 vfmt
->VertexAttribP4ui
= _save_VertexAttribP4ui
;
1434 vfmt
->VertexAttribP1uiv
= _save_VertexAttribP1uiv
;
1435 vfmt
->VertexAttribP2uiv
= _save_VertexAttribP2uiv
;
1436 vfmt
->VertexAttribP3uiv
= _save_VertexAttribP3uiv
;
1437 vfmt
->VertexAttribP4uiv
= _save_VertexAttribP4uiv
;
1439 /* This will all require us to fallback to saving the list as opcodes:
1441 _MESA_INIT_DLIST_VTXFMT(vfmt
, _save_
); /* inside begin/end */
1443 _MESA_INIT_EVAL_VTXFMT(vfmt
, _save_
);
1445 /* These calls all generate GL_INVALID_OPERATION since this vtxfmt is
1446 * only used when we're inside a glBegin/End pair.
1448 vfmt
->Begin
= _save_Begin
;
1449 vfmt
->Rectf
= _save_Rectf
;
1450 vfmt
->DrawArrays
= _save_DrawArrays
;
1451 vfmt
->DrawElements
= _save_DrawElements
;
1452 vfmt
->DrawRangeElements
= _save_DrawRangeElements
;
1453 vfmt
->DrawElementsBaseVertex
= _save_DrawElementsBaseVertex
;
1454 vfmt
->DrawRangeElementsBaseVertex
= _save_DrawRangeElementsBaseVertex
;
1455 vfmt
->MultiDrawElementsEXT
= _save_MultiDrawElements
;
1456 vfmt
->MultiDrawElementsBaseVertex
= _save_MultiDrawElementsBaseVertex
;
1457 vfmt
->DrawTransformFeedback
= _save_DrawTransformFeedback
;
1458 vfmt
->DrawTransformFeedbackStream
= _save_DrawTransformFeedbackStream
;
1459 vfmt
->DrawTransformFeedbackInstanced
= _save_DrawTransformFeedbackInstanced
;
1460 vfmt
->DrawTransformFeedbackStreamInstanced
=
1461 _save_DrawTransformFeedbackStreamInstanced
;
1466 vbo_save_SaveFlushVertices(struct gl_context
*ctx
)
1468 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1470 /* Noop when we are actually active:
1472 if (ctx
->Driver
.CurrentSavePrimitive
== PRIM_INSIDE_UNKNOWN_PRIM
||
1473 ctx
->Driver
.CurrentSavePrimitive
<= GL_POLYGON
)
1476 if (save
->vert_count
|| save
->prim_count
)
1477 _save_compile_vertex_list(ctx
);
1479 _save_copy_to_current(ctx
);
1480 _save_reset_vertex(ctx
);
1481 _save_reset_counters(ctx
);
1482 ctx
->Driver
.SaveNeedFlush
= 0;
1487 vbo_save_NewList(struct gl_context
*ctx
, GLuint list
, GLenum mode
)
1489 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1494 if (!save
->prim_store
)
1495 save
->prim_store
= alloc_prim_store(ctx
);
1497 if (!save
->vertex_store
)
1498 save
->vertex_store
= alloc_vertex_store(ctx
);
1500 save
->buffer_ptr
= vbo_save_map_vertex_store(ctx
, save
->vertex_store
);
1502 _save_reset_vertex(ctx
);
1503 _save_reset_counters(ctx
);
1504 ctx
->Driver
.SaveNeedFlush
= 0;
1509 vbo_save_EndList(struct gl_context
*ctx
)
1511 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1513 /* EndList called inside a (saved) Begin/End pair?
1515 if (ctx
->Driver
.CurrentSavePrimitive
!= PRIM_OUTSIDE_BEGIN_END
) {
1517 if (save
->prim_count
> 0) {
1518 GLint i
= save
->prim_count
- 1;
1519 ctx
->Driver
.CurrentSavePrimitive
= PRIM_OUTSIDE_BEGIN_END
;
1520 save
->prim
[i
].end
= 0;
1521 save
->prim
[i
].count
= (save
->vert_count
- save
->prim
[i
].start
);
1524 /* Make sure this vertex list gets replayed by the "loopback"
1527 save
->dangling_attr_ref
= 1;
1528 vbo_save_SaveFlushVertices(ctx
);
1530 /* Swap out this vertex format while outside begin/end. Any color,
1531 * etc. received between here and the next begin will be compiled
1534 _mesa_install_save_vtxfmt(ctx
, &ctx
->ListState
.ListVtxfmt
);
1537 vbo_save_unmap_vertex_store(ctx
, save
->vertex_store
);
1539 assert(save
->vertex_size
== 0);
1544 vbo_save_BeginCallList(struct gl_context
*ctx
, struct gl_display_list
*dlist
)
1546 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1547 save
->replay_flags
|= dlist
->Flags
;
1552 vbo_save_EndCallList(struct gl_context
*ctx
)
1554 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1556 if (ctx
->ListState
.CallDepth
== 1) {
1557 /* This is correct: want to keep only the VBO_SAVE_FALLBACK
1558 * flag, if it is set:
1560 save
->replay_flags
&= VBO_SAVE_FALLBACK
;
1566 vbo_destroy_vertex_list(struct gl_context
*ctx
, void *data
)
1568 struct vbo_save_vertex_list
*node
= (struct vbo_save_vertex_list
*) data
;
1571 if (--node
->vertex_store
->refcount
== 0)
1572 free_vertex_store(ctx
, node
->vertex_store
);
1574 if (--node
->prim_store
->refcount
== 0)
1575 free(node
->prim_store
);
1577 free(node
->current_data
);
1578 node
->current_data
= NULL
;
1583 vbo_print_vertex_list(struct gl_context
*ctx
, void *data
)
1585 struct vbo_save_vertex_list
*node
= (struct vbo_save_vertex_list
*) data
;
1589 printf("VBO-VERTEX-LIST, %u vertices %d primitives, %d vertsize\n",
1590 node
->count
, node
->prim_count
, node
->vertex_size
);
1592 for (i
= 0; i
< node
->prim_count
; i
++) {
1593 struct _mesa_prim
*prim
= &node
->prim
[i
];
1594 _mesa_debug(NULL
, " prim %d: %s%s %d..%d %s %s\n",
1596 _mesa_lookup_prim_by_nr(prim
->mode
),
1597 prim
->weak
? " (weak)" : "",
1599 prim
->start
+ prim
->count
,
1600 (prim
->begin
) ? "BEGIN" : "(wrap)",
1601 (prim
->end
) ? "END" : "(wrap)");
1607 * Called during context creation/init.
1610 _save_current_init(struct gl_context
*ctx
)
1612 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1615 for (i
= VBO_ATTRIB_POS
; i
<= VBO_ATTRIB_GENERIC15
; i
++) {
1616 const GLuint j
= i
- VBO_ATTRIB_POS
;
1617 ASSERT(j
< VERT_ATTRIB_MAX
);
1618 save
->currentsz
[i
] = &ctx
->ListState
.ActiveAttribSize
[j
];
1619 save
->current
[i
] = ctx
->ListState
.CurrentAttrib
[j
];
1622 for (i
= VBO_ATTRIB_FIRST_MATERIAL
; i
<= VBO_ATTRIB_LAST_MATERIAL
; i
++) {
1623 const GLuint j
= i
- VBO_ATTRIB_FIRST_MATERIAL
;
1624 ASSERT(j
< MAT_ATTRIB_MAX
);
1625 save
->currentsz
[i
] = &ctx
->ListState
.ActiveMaterialSize
[j
];
1626 save
->current
[i
] = ctx
->ListState
.CurrentMaterial
[j
];
1632 * Initialize the display list compiler. Called during context creation.
1635 vbo_save_api_init(struct vbo_save_context
*save
)
1637 struct gl_context
*ctx
= save
->ctx
;
1640 save
->opcode_vertex_list
=
1641 _mesa_dlist_alloc_opcode(ctx
,
1642 sizeof(struct vbo_save_vertex_list
),
1643 vbo_save_playback_vertex_list
,
1644 vbo_destroy_vertex_list
,
1645 vbo_print_vertex_list
);
1647 ctx
->Driver
.NotifySaveBegin
= vbo_save_NotifyBegin
;
1649 _save_vtxfmt_init(ctx
);
1650 _save_current_init(ctx
);
1651 _mesa_noop_vtxfmt_init(&save
->vtxfmt_noop
);
1653 /* These will actually get set again when binding/drawing */
1654 for (i
= 0; i
< VBO_ATTRIB_MAX
; i
++)
1655 save
->inputs
[i
] = &save
->arrays
[i
];
1657 /* Hook our array functions into the outside-begin-end vtxfmt in
1660 ctx
->ListState
.ListVtxfmt
.Rectf
= _save_OBE_Rectf
;
1661 ctx
->ListState
.ListVtxfmt
.DrawArrays
= _save_OBE_DrawArrays
;
1662 ctx
->ListState
.ListVtxfmt
.DrawElements
= _save_OBE_DrawElements
;
1663 ctx
->ListState
.ListVtxfmt
.DrawRangeElements
= _save_OBE_DrawRangeElements
;
1664 ctx
->ListState
.ListVtxfmt
.MultiDrawElementsEXT
= _save_OBE_MultiDrawElements
;
1665 ctx
->ListState
.ListVtxfmt
.MultiDrawElementsBaseVertex
= _save_OBE_MultiDrawElementsBaseVertex
;
1666 _mesa_install_save_vtxfmt(ctx
, &ctx
->ListState
.ListVtxfmt
);