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"
95 /* An interesting VBO number/name to help with debugging */
96 #define VBO_BUF_ID 12345
100 * NOTE: Old 'parity' issue is gone, but copying can still be
101 * wrong-footed on replay.
104 _save_copy_vertices(struct gl_context
*ctx
,
105 const struct vbo_save_vertex_list
*node
,
106 const GLfloat
* src_buffer
)
108 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
109 const struct _mesa_prim
*prim
= &node
->prim
[node
->prim_count
- 1];
110 GLuint nr
= prim
->count
;
111 GLuint sz
= save
->vertex_size
;
112 const GLfloat
*src
= src_buffer
+ prim
->start
* sz
;
113 GLfloat
*dst
= save
->copied
.buffer
;
119 switch (prim
->mode
) {
124 for (i
= 0; i
< ovf
; i
++)
125 memcpy(dst
+ i
* sz
, src
+ (nr
- ovf
+ i
) * sz
,
126 sz
* sizeof(GLfloat
));
130 for (i
= 0; i
< ovf
; i
++)
131 memcpy(dst
+ i
* sz
, src
+ (nr
- ovf
+ i
) * sz
,
132 sz
* sizeof(GLfloat
));
136 for (i
= 0; i
< ovf
; i
++)
137 memcpy(dst
+ i
* sz
, src
+ (nr
- ovf
+ i
) * sz
,
138 sz
* sizeof(GLfloat
));
144 memcpy(dst
, src
+ (nr
- 1) * sz
, sz
* sizeof(GLfloat
));
148 case GL_TRIANGLE_FAN
:
153 memcpy(dst
, src
+ 0, sz
* sizeof(GLfloat
));
157 memcpy(dst
, src
+ 0, sz
* sizeof(GLfloat
));
158 memcpy(dst
+ sz
, src
+ (nr
- 1) * sz
, sz
* sizeof(GLfloat
));
161 case GL_TRIANGLE_STRIP
:
174 for (i
= 0; i
< ovf
; i
++)
175 memcpy(dst
+ i
* sz
, src
+ (nr
- ovf
+ i
) * sz
,
176 sz
* sizeof(GLfloat
));
185 static struct vbo_save_vertex_store
*
186 alloc_vertex_store(struct gl_context
*ctx
)
188 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
189 struct vbo_save_vertex_store
*vertex_store
=
190 CALLOC_STRUCT(vbo_save_vertex_store
);
192 /* obj->Name needs to be non-zero, but won't ever be examined more
193 * closely than that. In particular these buffers won't be entered
194 * into the hash and can never be confused with ones visible to the
195 * user. Perhaps there could be a special number for internal
198 vertex_store
->bufferobj
= ctx
->Driver
.NewBufferObject(ctx
,
200 GL_ARRAY_BUFFER_ARB
);
201 if (vertex_store
->bufferobj
) {
202 save
->out_of_memory
=
203 !ctx
->Driver
.BufferData(ctx
,
205 VBO_SAVE_BUFFER_SIZE
* sizeof(GLfloat
),
206 NULL
, GL_STATIC_DRAW_ARB
,
207 vertex_store
->bufferobj
);
210 save
->out_of_memory
= GL_TRUE
;
213 if (save
->out_of_memory
) {
214 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "internal VBO allocation");
215 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt_noop
);
218 vertex_store
->buffer
= NULL
;
219 vertex_store
->used
= 0;
220 vertex_store
->refcount
= 1;
227 free_vertex_store(struct gl_context
*ctx
,
228 struct vbo_save_vertex_store
*vertex_store
)
230 assert(!vertex_store
->buffer
);
232 if (vertex_store
->bufferobj
) {
233 _mesa_reference_buffer_object(ctx
, &vertex_store
->bufferobj
, NULL
);
241 vbo_save_map_vertex_store(struct gl_context
*ctx
,
242 struct vbo_save_vertex_store
*vertex_store
)
244 assert(vertex_store
->bufferobj
);
245 assert(!vertex_store
->buffer
);
246 if (vertex_store
->bufferobj
->Size
> 0) {
247 vertex_store
->buffer
=
248 (GLfloat
*) ctx
->Driver
.MapBufferRange(ctx
, 0,
249 vertex_store
->bufferobj
->Size
,
250 GL_MAP_WRITE_BIT
, /* not used */
251 vertex_store
->bufferobj
);
252 assert(vertex_store
->buffer
);
253 return vertex_store
->buffer
+ vertex_store
->used
;
256 /* probably ran out of memory for buffers */
263 vbo_save_unmap_vertex_store(struct gl_context
*ctx
,
264 struct vbo_save_vertex_store
*vertex_store
)
266 if (vertex_store
->bufferobj
->Size
> 0) {
267 ctx
->Driver
.UnmapBuffer(ctx
, vertex_store
->bufferobj
);
269 vertex_store
->buffer
= NULL
;
273 static struct vbo_save_primitive_store
*
274 alloc_prim_store(struct gl_context
*ctx
)
276 struct vbo_save_primitive_store
*store
=
277 CALLOC_STRUCT(vbo_save_primitive_store
);
286 _save_reset_counters(struct gl_context
*ctx
)
288 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
290 save
->prim
= save
->prim_store
->buffer
+ save
->prim_store
->used
;
291 save
->buffer
= save
->vertex_store
->buffer
+ save
->vertex_store
->used
;
293 assert(save
->buffer
== save
->buffer_ptr
);
295 if (save
->vertex_size
)
296 save
->max_vert
= ((VBO_SAVE_BUFFER_SIZE
- save
->vertex_store
->used
) /
301 save
->vert_count
= 0;
302 save
->prim_count
= 0;
303 save
->prim_max
= VBO_SAVE_PRIM_SIZE
- save
->prim_store
->used
;
304 save
->dangling_attr_ref
= 0;
309 * Insert the active immediate struct onto the display list currently
313 _save_compile_vertex_list(struct gl_context
*ctx
)
315 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
316 struct vbo_save_vertex_list
*node
;
318 /* Allocate space for this structure in the display list currently
321 node
= (struct vbo_save_vertex_list
*)
322 _mesa_dlist_alloc(ctx
, save
->opcode_vertex_list
, sizeof(*node
));
327 /* Duplicate our template, increment refcounts to the storage structs:
329 memcpy(node
->attrsz
, save
->attrsz
, sizeof(node
->attrsz
));
330 node
->vertex_size
= save
->vertex_size
;
331 node
->buffer_offset
=
332 (save
->buffer
- save
->vertex_store
->buffer
) * sizeof(GLfloat
);
333 node
->count
= save
->vert_count
;
334 node
->wrap_count
= save
->copied
.nr
;
335 node
->dangling_attr_ref
= save
->dangling_attr_ref
;
336 node
->prim
= save
->prim
;
337 node
->prim_count
= save
->prim_count
;
338 node
->vertex_store
= save
->vertex_store
;
339 node
->prim_store
= save
->prim_store
;
341 node
->vertex_store
->refcount
++;
342 node
->prim_store
->refcount
++;
344 if (node
->prim
[0].no_current_update
) {
345 node
->current_size
= 0;
346 node
->current_data
= NULL
;
349 node
->current_size
= node
->vertex_size
- node
->attrsz
[0];
350 node
->current_data
= NULL
;
352 if (node
->current_size
) {
353 /* If the malloc fails, we just pull the data out of the VBO
356 node
->current_data
= malloc(node
->current_size
* sizeof(GLfloat
));
357 if (node
->current_data
) {
358 const char *buffer
= (const char *) save
->vertex_store
->buffer
;
359 unsigned attr_offset
= node
->attrsz
[0] * sizeof(GLfloat
);
360 unsigned vertex_offset
= 0;
364 (node
->count
- 1) * node
->vertex_size
* sizeof(GLfloat
);
366 memcpy(node
->current_data
,
367 buffer
+ node
->buffer_offset
+ vertex_offset
+ attr_offset
,
368 node
->current_size
* sizeof(GLfloat
));
373 assert(node
->attrsz
[VBO_ATTRIB_POS
] != 0 || node
->count
== 0);
375 if (save
->dangling_attr_ref
)
376 ctx
->ListState
.CurrentList
->Flags
|= DLIST_DANGLING_REFS
;
378 save
->vertex_store
->used
+= save
->vertex_size
* node
->count
;
379 save
->prim_store
->used
+= node
->prim_count
;
381 /* Copy duplicated vertices
383 save
->copied
.nr
= _save_copy_vertices(ctx
, node
, save
->buffer
);
385 /* Deal with GL_COMPILE_AND_EXECUTE:
387 if (ctx
->ExecuteFlag
) {
388 struct _glapi_table
*dispatch
= GET_DISPATCH();
390 _glapi_set_dispatch(ctx
->Exec
);
392 vbo_loopback_vertex_list(ctx
,
393 (const GLfloat
*) ((const char *) save
->
394 vertex_store
->buffer
+
395 node
->buffer_offset
),
396 node
->attrsz
, node
->prim
, node
->prim_count
,
397 node
->wrap_count
, node
->vertex_size
);
399 _glapi_set_dispatch(dispatch
);
402 /* Decide whether the storage structs are full, or can be used for
403 * the next vertex lists as well.
405 if (save
->vertex_store
->used
>
406 VBO_SAVE_BUFFER_SIZE
- 16 * (save
->vertex_size
+ 4)) {
410 vbo_save_unmap_vertex_store(ctx
, save
->vertex_store
);
412 /* Release old reference:
414 save
->vertex_store
->refcount
--;
415 assert(save
->vertex_store
->refcount
!= 0);
416 save
->vertex_store
= NULL
;
418 /* Allocate and map new store:
420 save
->vertex_store
= alloc_vertex_store(ctx
);
421 save
->buffer_ptr
= vbo_save_map_vertex_store(ctx
, save
->vertex_store
);
422 save
->out_of_memory
= save
->buffer_ptr
== NULL
;
425 if (save
->prim_store
->used
> VBO_SAVE_PRIM_SIZE
- 6) {
426 save
->prim_store
->refcount
--;
427 assert(save
->prim_store
->refcount
!= 0);
428 save
->prim_store
= alloc_prim_store(ctx
);
431 /* Reset our structures for the next run of vertices:
433 _save_reset_counters(ctx
);
438 * TODO -- If no new vertices have been stored, don't bother saving it.
441 _save_wrap_buffers(struct gl_context
*ctx
)
443 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
444 GLint i
= save
->prim_count
- 1;
447 GLboolean no_current_update
;
449 assert(i
< (GLint
) save
->prim_max
);
452 /* Close off in-progress primitive.
454 save
->prim
[i
].count
= (save
->vert_count
- save
->prim
[i
].start
);
455 mode
= save
->prim
[i
].mode
;
456 weak
= save
->prim
[i
].weak
;
457 no_current_update
= save
->prim
[i
].no_current_update
;
459 /* store the copied vertices, and allocate a new list.
461 _save_compile_vertex_list(ctx
);
463 /* Restart interrupted primitive
465 save
->prim
[0].mode
= mode
;
466 save
->prim
[0].weak
= weak
;
467 save
->prim
[0].no_current_update
= no_current_update
;
468 save
->prim
[0].begin
= 0;
469 save
->prim
[0].end
= 0;
470 save
->prim
[0].pad
= 0;
471 save
->prim
[0].start
= 0;
472 save
->prim
[0].count
= 0;
473 save
->prim
[0].num_instances
= 1;
474 save
->prim
[0].base_instance
= 0;
475 save
->prim_count
= 1;
480 * Called only when buffers are wrapped as the result of filling the
481 * vertex_store struct.
484 _save_wrap_filled_vertex(struct gl_context
*ctx
)
486 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
487 GLfloat
*data
= save
->copied
.buffer
;
490 /* Emit a glEnd to close off the last vertex list.
492 _save_wrap_buffers(ctx
);
494 /* Copy stored stored vertices to start of new list.
496 assert(save
->max_vert
- save
->vert_count
> save
->copied
.nr
);
498 for (i
= 0; i
< save
->copied
.nr
; i
++) {
499 memcpy(save
->buffer_ptr
, data
, save
->vertex_size
* sizeof(GLfloat
));
500 data
+= save
->vertex_size
;
501 save
->buffer_ptr
+= save
->vertex_size
;
508 _save_copy_to_current(struct gl_context
*ctx
)
510 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
513 for (i
= VBO_ATTRIB_POS
+ 1; i
< VBO_ATTRIB_MAX
; i
++) {
514 if (save
->attrsz
[i
]) {
515 save
->currentsz
[i
][0] = save
->attrsz
[i
];
516 COPY_CLEAN_4V(save
->current
[i
], save
->attrsz
[i
], save
->attrptr
[i
]);
523 _save_copy_from_current(struct gl_context
*ctx
)
525 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
528 for (i
= VBO_ATTRIB_POS
+ 1; i
< VBO_ATTRIB_MAX
; i
++) {
529 switch (save
->attrsz
[i
]) {
531 save
->attrptr
[i
][3] = save
->current
[i
][3];
533 save
->attrptr
[i
][2] = save
->current
[i
][2];
535 save
->attrptr
[i
][1] = save
->current
[i
][1];
537 save
->attrptr
[i
][0] = save
->current
[i
][0];
545 /* Flush existing data, set new attrib size, replay copied vertices.
548 _save_upgrade_vertex(struct gl_context
*ctx
, GLuint attr
, GLuint newsz
)
550 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
555 /* Store the current run of vertices, and emit a GL_END. Emit a
556 * BEGIN in the new buffer.
558 if (save
->vert_count
)
559 _save_wrap_buffers(ctx
);
561 assert(save
->copied
.nr
== 0);
563 /* Do a COPY_TO_CURRENT to ensure back-copying works for the case
564 * when the attribute already exists in the vertex and is having
565 * its size increased.
567 _save_copy_to_current(ctx
);
571 oldsz
= save
->attrsz
[attr
];
572 save
->attrsz
[attr
] = newsz
;
574 save
->vertex_size
+= newsz
- oldsz
;
575 save
->max_vert
= ((VBO_SAVE_BUFFER_SIZE
- save
->vertex_store
->used
) /
577 save
->vert_count
= 0;
579 /* Recalculate all the attrptr[] values:
581 for (i
= 0, tmp
= save
->vertex
; i
< VBO_ATTRIB_MAX
; i
++) {
582 if (save
->attrsz
[i
]) {
583 save
->attrptr
[i
] = tmp
;
584 tmp
+= save
->attrsz
[i
];
587 save
->attrptr
[i
] = NULL
; /* will not be dereferenced. */
591 /* Copy from current to repopulate the vertex with correct values.
593 _save_copy_from_current(ctx
);
595 /* Replay stored vertices to translate them to new format here.
597 * If there are copied vertices and the new (upgraded) attribute
598 * has not been defined before, this list is somewhat degenerate,
599 * and will need fixup at runtime.
601 if (save
->copied
.nr
) {
602 GLfloat
*data
= save
->copied
.buffer
;
603 GLfloat
*dest
= save
->buffer
;
606 /* Need to note this and fix up at runtime (or loopback):
608 if (attr
!= VBO_ATTRIB_POS
&& save
->currentsz
[attr
][0] == 0) {
610 save
->dangling_attr_ref
= GL_TRUE
;
613 for (i
= 0; i
< save
->copied
.nr
; i
++) {
614 for (j
= 0; j
< VBO_ATTRIB_MAX
; j
++) {
615 if (save
->attrsz
[j
]) {
618 COPY_CLEAN_4V(dest
, oldsz
, data
);
623 COPY_SZ_4V(dest
, newsz
, save
->current
[attr
]);
628 GLint sz
= save
->attrsz
[j
];
629 COPY_SZ_4V(dest
, sz
, data
);
637 save
->buffer_ptr
= dest
;
638 save
->vert_count
+= save
->copied
.nr
;
644 save_fixup_vertex(struct gl_context
*ctx
, GLuint attr
, GLuint sz
)
646 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
648 if (sz
> save
->attrsz
[attr
]) {
649 /* New size is larger. Need to flush existing vertices and get
650 * an enlarged vertex format.
652 _save_upgrade_vertex(ctx
, attr
, sz
);
654 else if (sz
< save
->active_sz
[attr
]) {
655 static GLfloat id
[4] = { 0, 0, 0, 1 };
658 /* New size is equal or smaller - just need to fill in some
661 for (i
= sz
; i
<= save
->attrsz
[attr
]; i
++)
662 save
->attrptr
[attr
][i
- 1] = id
[i
- 1];
665 save
->active_sz
[attr
] = sz
;
670 _save_reset_vertex(struct gl_context
*ctx
)
672 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
675 for (i
= 0; i
< VBO_ATTRIB_MAX
; i
++) {
677 save
->active_sz
[i
] = 0;
680 save
->vertex_size
= 0;
685 #define ERROR(err) _mesa_compile_error(ctx, err, __FUNCTION__);
688 /* Only one size for each attribute may be active at once. Eg. if
689 * Color3f is installed/active, then Color4f may not be, even if the
690 * vertex actually contains 4 color coordinates. This is because the
691 * 3f version won't otherwise set color[3] to 1.0 -- this is the job
692 * of the chooser function when switching between Color4f and Color3f.
694 #define ATTR(A, N, V0, V1, V2, V3) \
696 struct vbo_save_context *save = &vbo_context(ctx)->save; \
698 if (save->active_sz[A] != N) \
699 save_fixup_vertex(ctx, A, N); \
702 GLfloat *dest = save->attrptr[A]; \
703 if (N>0) dest[0] = V0; \
704 if (N>1) dest[1] = V1; \
705 if (N>2) dest[2] = V2; \
706 if (N>3) dest[3] = V3; \
712 for (i = 0; i < save->vertex_size; i++) \
713 save->buffer_ptr[i] = save->vertex[i]; \
715 save->buffer_ptr += save->vertex_size; \
717 if (++save->vert_count >= save->max_vert) \
718 _save_wrap_filled_vertex(ctx); \
722 #define TAG(x) _save_##x
724 #include "vbo_attrib_tmp.h"
728 #define MAT( ATTR, N, face, params ) \
730 if (face != GL_BACK) \
731 MAT_ATTR( ATTR, N, params ); /* front */ \
732 if (face != GL_FRONT) \
733 MAT_ATTR( ATTR + 1, N, params ); /* back */ \
738 * Save a glMaterial call found between glBegin/End.
739 * glMaterial calls outside Begin/End are handled in dlist.c.
741 static void GLAPIENTRY
742 _save_Materialfv(GLenum face
, GLenum pname
, const GLfloat
*params
)
744 GET_CURRENT_CONTEXT(ctx
);
746 if (face
!= GL_FRONT
&& face
!= GL_BACK
&& face
!= GL_FRONT_AND_BACK
) {
747 _mesa_compile_error(ctx
, GL_INVALID_ENUM
, "glMaterial(face)");
753 MAT(VBO_ATTRIB_MAT_FRONT_EMISSION
, 4, face
, params
);
756 MAT(VBO_ATTRIB_MAT_FRONT_AMBIENT
, 4, face
, params
);
759 MAT(VBO_ATTRIB_MAT_FRONT_DIFFUSE
, 4, face
, params
);
762 MAT(VBO_ATTRIB_MAT_FRONT_SPECULAR
, 4, face
, params
);
765 if (*params
< 0 || *params
> ctx
->Const
.MaxShininess
) {
766 _mesa_compile_error(ctx
, GL_INVALID_VALUE
, "glMaterial(shininess)");
769 MAT(VBO_ATTRIB_MAT_FRONT_SHININESS
, 1, face
, params
);
772 case GL_COLOR_INDEXES
:
773 MAT(VBO_ATTRIB_MAT_FRONT_INDEXES
, 3, face
, params
);
775 case GL_AMBIENT_AND_DIFFUSE
:
776 MAT(VBO_ATTRIB_MAT_FRONT_AMBIENT
, 4, face
, params
);
777 MAT(VBO_ATTRIB_MAT_FRONT_DIFFUSE
, 4, face
, params
);
780 _mesa_compile_error(ctx
, GL_INVALID_ENUM
, "glMaterial(pname)");
786 /* Cope with EvalCoord/CallList called within a begin/end object:
787 * -- Flush current buffer
788 * -- Fallback to opcodes for the rest of the begin/end object.
791 dlist_fallback(struct gl_context
*ctx
)
793 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
795 if (save
->vert_count
|| save
->prim_count
) {
796 if (save
->prim_count
> 0) {
797 /* Close off in-progress primitive. */
798 GLint i
= save
->prim_count
- 1;
799 save
->prim
[i
].count
= save
->vert_count
- save
->prim
[i
].start
;
802 /* Need to replay this display list with loopback,
803 * unfortunately, otherwise this primitive won't be handled
806 save
->dangling_attr_ref
= 1;
808 _save_compile_vertex_list(ctx
);
811 _save_copy_to_current(ctx
);
812 _save_reset_vertex(ctx
);
813 _save_reset_counters(ctx
);
814 if (save
->out_of_memory
) {
815 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt_noop
);
818 _mesa_install_save_vtxfmt(ctx
, &ctx
->ListState
.ListVtxfmt
);
820 ctx
->Driver
.SaveNeedFlush
= 0;
824 static void GLAPIENTRY
825 _save_EvalCoord1f(GLfloat u
)
827 GET_CURRENT_CONTEXT(ctx
);
829 CALL_EvalCoord1f(ctx
->Save
, (u
));
832 static void GLAPIENTRY
833 _save_EvalCoord1fv(const GLfloat
* v
)
835 GET_CURRENT_CONTEXT(ctx
);
837 CALL_EvalCoord1fv(ctx
->Save
, (v
));
840 static void GLAPIENTRY
841 _save_EvalCoord2f(GLfloat u
, GLfloat v
)
843 GET_CURRENT_CONTEXT(ctx
);
845 CALL_EvalCoord2f(ctx
->Save
, (u
, v
));
848 static void GLAPIENTRY
849 _save_EvalCoord2fv(const GLfloat
* v
)
851 GET_CURRENT_CONTEXT(ctx
);
853 CALL_EvalCoord2fv(ctx
->Save
, (v
));
856 static void GLAPIENTRY
857 _save_EvalPoint1(GLint i
)
859 GET_CURRENT_CONTEXT(ctx
);
861 CALL_EvalPoint1(ctx
->Save
, (i
));
864 static void GLAPIENTRY
865 _save_EvalPoint2(GLint i
, GLint j
)
867 GET_CURRENT_CONTEXT(ctx
);
869 CALL_EvalPoint2(ctx
->Save
, (i
, j
));
872 static void GLAPIENTRY
873 _save_CallList(GLuint l
)
875 GET_CURRENT_CONTEXT(ctx
);
877 CALL_CallList(ctx
->Save
, (l
));
880 static void GLAPIENTRY
881 _save_CallLists(GLsizei n
, GLenum type
, const GLvoid
* v
)
883 GET_CURRENT_CONTEXT(ctx
);
885 CALL_CallLists(ctx
->Save
, (n
, type
, v
));
890 /* This begin is hooked into ... Updating of
891 * ctx->Driver.CurrentSavePrimitive is already taken care of.
894 vbo_save_NotifyBegin(struct gl_context
*ctx
, GLenum mode
)
896 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
898 GLuint i
= save
->prim_count
++;
900 assert(i
< save
->prim_max
);
901 save
->prim
[i
].mode
= mode
& VBO_SAVE_PRIM_MODE_MASK
;
902 save
->prim
[i
].begin
= 1;
903 save
->prim
[i
].end
= 0;
904 save
->prim
[i
].weak
= (mode
& VBO_SAVE_PRIM_WEAK
) ? 1 : 0;
905 save
->prim
[i
].no_current_update
=
906 (mode
& VBO_SAVE_PRIM_NO_CURRENT_UPDATE
) ? 1 : 0;
907 save
->prim
[i
].pad
= 0;
908 save
->prim
[i
].start
= save
->vert_count
;
909 save
->prim
[i
].count
= 0;
910 save
->prim
[i
].num_instances
= 1;
911 save
->prim
[i
].base_instance
= 0;
913 if (save
->out_of_memory
) {
914 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt_noop
);
917 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt
);
919 ctx
->Driver
.SaveNeedFlush
= 1;
924 static void GLAPIENTRY
927 GET_CURRENT_CONTEXT(ctx
);
928 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
929 GLint i
= save
->prim_count
- 1;
931 ctx
->Driver
.CurrentSavePrimitive
= PRIM_OUTSIDE_BEGIN_END
;
932 save
->prim
[i
].end
= 1;
933 save
->prim
[i
].count
= (save
->vert_count
- save
->prim
[i
].start
);
935 if (i
== (GLint
) save
->prim_max
- 1) {
936 _save_compile_vertex_list(ctx
);
937 assert(save
->copied
.nr
== 0);
940 /* Swap out this vertex format while outside begin/end. Any color,
941 * etc. received between here and the next begin will be compiled
944 if (save
->out_of_memory
) {
945 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt_noop
);
948 _mesa_install_save_vtxfmt(ctx
, &ctx
->ListState
.ListVtxfmt
);
953 /* These are all errors as this vtxfmt is only installed inside
956 static void GLAPIENTRY
957 _save_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
958 const GLvoid
* indices
)
960 GET_CURRENT_CONTEXT(ctx
);
965 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawElements");
969 static void GLAPIENTRY
970 _save_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
971 GLsizei count
, GLenum type
, const GLvoid
* indices
)
973 GET_CURRENT_CONTEXT(ctx
);
980 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawRangeElements");
984 static void GLAPIENTRY
985 _save_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
986 const GLvoid
* indices
, GLint basevertex
)
988 GET_CURRENT_CONTEXT(ctx
);
994 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawElements");
998 static void GLAPIENTRY
999 _save_DrawRangeElementsBaseVertex(GLenum mode
,
1004 const GLvoid
* indices
, GLint basevertex
)
1006 GET_CURRENT_CONTEXT(ctx
);
1014 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawRangeElements");
1018 static void GLAPIENTRY
1019 _save_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
1021 GET_CURRENT_CONTEXT(ctx
);
1025 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawArrays");
1029 static void GLAPIENTRY
1030 _save_MultiDrawElements(GLenum mode
, const GLsizei
*count
, GLenum type
,
1031 const GLvoid
**indices
, GLsizei primcount
)
1033 GET_CURRENT_CONTEXT(ctx
);
1039 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glMultiDrawElements");
1043 static void GLAPIENTRY
1044 _save_MultiDrawElementsBaseVertex(GLenum mode
, const GLsizei
*count
,
1045 GLenum type
, const GLvoid
* const *indices
,
1046 GLsizei primcount
, const GLint
*basevertex
)
1048 GET_CURRENT_CONTEXT(ctx
);
1055 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
,
1056 "glMultiDrawElementsBaseVertex");
1060 static void GLAPIENTRY
1061 _save_DrawTransformFeedback(GLenum mode
, GLuint name
)
1063 GET_CURRENT_CONTEXT(ctx
);
1066 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawTransformFeedback");
1070 static void GLAPIENTRY
1071 _save_DrawTransformFeedbackStream(GLenum mode
, GLuint name
, GLuint stream
)
1073 GET_CURRENT_CONTEXT(ctx
);
1077 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
,
1078 "glDrawTransformFeedbackStream");
1082 static void GLAPIENTRY
1083 _save_DrawTransformFeedbackInstanced(GLenum mode
, GLuint name
,
1086 GET_CURRENT_CONTEXT(ctx
);
1090 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
,
1091 "glDrawTransformFeedbackInstanced");
1095 static void GLAPIENTRY
1096 _save_DrawTransformFeedbackStreamInstanced(GLenum mode
, GLuint name
,
1097 GLuint stream
, GLsizei primcount
)
1099 GET_CURRENT_CONTEXT(ctx
);
1104 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
,
1105 "glDrawTransformFeedbackStreamInstanced");
1109 static void GLAPIENTRY
1110 _save_Rectf(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
1112 GET_CURRENT_CONTEXT(ctx
);
1117 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glRectf");
1121 static void GLAPIENTRY
1122 _save_EvalMesh1(GLenum mode
, GLint i1
, GLint i2
)
1124 GET_CURRENT_CONTEXT(ctx
);
1128 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glEvalMesh1");
1132 static void GLAPIENTRY
1133 _save_EvalMesh2(GLenum mode
, GLint i1
, GLint i2
, GLint j1
, GLint j2
)
1135 GET_CURRENT_CONTEXT(ctx
);
1141 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glEvalMesh2");
1145 static void GLAPIENTRY
1146 _save_Begin(GLenum mode
)
1148 GET_CURRENT_CONTEXT(ctx
);
1150 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "Recursive glBegin");
1154 static void GLAPIENTRY
1155 _save_PrimitiveRestartNV(void)
1158 GET_CURRENT_CONTEXT(ctx
);
1160 curPrim
= ctx
->Driver
.CurrentSavePrimitive
;
1163 _save_Begin(curPrim
);
1167 /* Unlike the functions above, these are to be hooked into the vtxfmt
1168 * maintained in ctx->ListState, active when the list is known or
1169 * suspected to be outside any begin/end primitive.
1170 * Note: OBE = Outside Begin/End
1172 static void GLAPIENTRY
1173 _save_OBE_Rectf(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
1175 GET_CURRENT_CONTEXT(ctx
);
1176 vbo_save_NotifyBegin(ctx
, GL_QUADS
| VBO_SAVE_PRIM_WEAK
);
1177 CALL_Vertex2f(GET_DISPATCH(), (x1
, y1
));
1178 CALL_Vertex2f(GET_DISPATCH(), (x2
, y1
));
1179 CALL_Vertex2f(GET_DISPATCH(), (x2
, y2
));
1180 CALL_Vertex2f(GET_DISPATCH(), (x1
, y2
));
1181 CALL_End(GET_DISPATCH(), ());
1185 static void GLAPIENTRY
1186 _save_OBE_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
1188 GET_CURRENT_CONTEXT(ctx
);
1189 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1192 if (!_mesa_validate_DrawArrays(ctx
, mode
, start
, count
))
1195 if (save
->out_of_memory
)
1200 vbo_save_NotifyBegin(ctx
, (mode
| VBO_SAVE_PRIM_WEAK
1201 | VBO_SAVE_PRIM_NO_CURRENT_UPDATE
));
1203 for (i
= 0; i
< count
; i
++)
1204 CALL_ArrayElement(GET_DISPATCH(), (start
+ i
));
1205 CALL_End(GET_DISPATCH(), ());
1207 _ae_unmap_vbos(ctx
);
1211 /* Could do better by copying the arrays and element list intact and
1212 * then emitting an indexed prim at runtime.
1214 static void GLAPIENTRY
1215 _save_OBE_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1216 const GLvoid
* indices
)
1218 GET_CURRENT_CONTEXT(ctx
);
1219 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1222 if (!_mesa_validate_DrawElements(ctx
, mode
, count
, type
, indices
, 0))
1225 if (save
->out_of_memory
)
1230 if (_mesa_is_bufferobj(ctx
->Array
.ArrayObj
->ElementArrayBufferObj
))
1232 ADD_POINTERS(ctx
->Array
.ArrayObj
->ElementArrayBufferObj
->Pointer
, indices
);
1234 vbo_save_NotifyBegin(ctx
, (mode
| VBO_SAVE_PRIM_WEAK
|
1235 VBO_SAVE_PRIM_NO_CURRENT_UPDATE
));
1238 case GL_UNSIGNED_BYTE
:
1239 for (i
= 0; i
< count
; i
++)
1240 CALL_ArrayElement(GET_DISPATCH(), (((GLubyte
*) indices
)[i
]));
1242 case GL_UNSIGNED_SHORT
:
1243 for (i
= 0; i
< count
; i
++)
1244 CALL_ArrayElement(GET_DISPATCH(), (((GLushort
*) indices
)[i
]));
1246 case GL_UNSIGNED_INT
:
1247 for (i
= 0; i
< count
; i
++)
1248 CALL_ArrayElement(GET_DISPATCH(), (((GLuint
*) indices
)[i
]));
1251 _mesa_error(ctx
, GL_INVALID_ENUM
, "glDrawElements(type)");
1255 CALL_End(GET_DISPATCH(), ());
1257 _ae_unmap_vbos(ctx
);
1261 static void GLAPIENTRY
1262 _save_OBE_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
1263 GLsizei count
, GLenum type
,
1264 const GLvoid
* indices
)
1266 GET_CURRENT_CONTEXT(ctx
);
1267 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1269 if (!_mesa_validate_DrawRangeElements(ctx
, mode
,
1270 start
, end
, count
, type
, indices
, 0))
1273 if (save
->out_of_memory
)
1276 _save_OBE_DrawElements(mode
, count
, type
, indices
);
1280 static void GLAPIENTRY
1281 _save_OBE_MultiDrawElements(GLenum mode
, const GLsizei
*count
, GLenum type
,
1282 const GLvoid
**indices
, GLsizei primcount
)
1286 for (i
= 0; i
< primcount
; i
++) {
1288 CALL_DrawElements(GET_DISPATCH(), (mode
, count
[i
], type
, indices
[i
]));
1294 static void GLAPIENTRY
1295 _save_OBE_MultiDrawElementsBaseVertex(GLenum mode
, const GLsizei
*count
,
1297 const GLvoid
* const *indices
,
1299 const GLint
*basevertex
)
1303 for (i
= 0; i
< primcount
; i
++) {
1305 CALL_DrawElementsBaseVertex(GET_DISPATCH(), (mode
, count
[i
], type
,
1314 _save_vtxfmt_init(struct gl_context
*ctx
)
1316 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1317 GLvertexformat
*vfmt
= &save
->vtxfmt
;
1319 _MESA_INIT_ARRAYELT_VTXFMT(vfmt
, _ae_
);
1321 vfmt
->Begin
= _save_Begin
;
1322 vfmt
->Color3f
= _save_Color3f
;
1323 vfmt
->Color3fv
= _save_Color3fv
;
1324 vfmt
->Color4f
= _save_Color4f
;
1325 vfmt
->Color4fv
= _save_Color4fv
;
1326 vfmt
->EdgeFlag
= _save_EdgeFlag
;
1327 vfmt
->End
= _save_End
;
1328 vfmt
->PrimitiveRestartNV
= _save_PrimitiveRestartNV
;
1329 vfmt
->FogCoordfEXT
= _save_FogCoordfEXT
;
1330 vfmt
->FogCoordfvEXT
= _save_FogCoordfvEXT
;
1331 vfmt
->Indexf
= _save_Indexf
;
1332 vfmt
->Indexfv
= _save_Indexfv
;
1333 vfmt
->Materialfv
= _save_Materialfv
;
1334 vfmt
->MultiTexCoord1fARB
= _save_MultiTexCoord1f
;
1335 vfmt
->MultiTexCoord1fvARB
= _save_MultiTexCoord1fv
;
1336 vfmt
->MultiTexCoord2fARB
= _save_MultiTexCoord2f
;
1337 vfmt
->MultiTexCoord2fvARB
= _save_MultiTexCoord2fv
;
1338 vfmt
->MultiTexCoord3fARB
= _save_MultiTexCoord3f
;
1339 vfmt
->MultiTexCoord3fvARB
= _save_MultiTexCoord3fv
;
1340 vfmt
->MultiTexCoord4fARB
= _save_MultiTexCoord4f
;
1341 vfmt
->MultiTexCoord4fvARB
= _save_MultiTexCoord4fv
;
1342 vfmt
->Normal3f
= _save_Normal3f
;
1343 vfmt
->Normal3fv
= _save_Normal3fv
;
1344 vfmt
->SecondaryColor3fEXT
= _save_SecondaryColor3fEXT
;
1345 vfmt
->SecondaryColor3fvEXT
= _save_SecondaryColor3fvEXT
;
1346 vfmt
->TexCoord1f
= _save_TexCoord1f
;
1347 vfmt
->TexCoord1fv
= _save_TexCoord1fv
;
1348 vfmt
->TexCoord2f
= _save_TexCoord2f
;
1349 vfmt
->TexCoord2fv
= _save_TexCoord2fv
;
1350 vfmt
->TexCoord3f
= _save_TexCoord3f
;
1351 vfmt
->TexCoord3fv
= _save_TexCoord3fv
;
1352 vfmt
->TexCoord4f
= _save_TexCoord4f
;
1353 vfmt
->TexCoord4fv
= _save_TexCoord4fv
;
1354 vfmt
->Vertex2f
= _save_Vertex2f
;
1355 vfmt
->Vertex2fv
= _save_Vertex2fv
;
1356 vfmt
->Vertex3f
= _save_Vertex3f
;
1357 vfmt
->Vertex3fv
= _save_Vertex3fv
;
1358 vfmt
->Vertex4f
= _save_Vertex4f
;
1359 vfmt
->Vertex4fv
= _save_Vertex4fv
;
1360 vfmt
->VertexAttrib1fARB
= _save_VertexAttrib1fARB
;
1361 vfmt
->VertexAttrib1fvARB
= _save_VertexAttrib1fvARB
;
1362 vfmt
->VertexAttrib2fARB
= _save_VertexAttrib2fARB
;
1363 vfmt
->VertexAttrib2fvARB
= _save_VertexAttrib2fvARB
;
1364 vfmt
->VertexAttrib3fARB
= _save_VertexAttrib3fARB
;
1365 vfmt
->VertexAttrib3fvARB
= _save_VertexAttrib3fvARB
;
1366 vfmt
->VertexAttrib4fARB
= _save_VertexAttrib4fARB
;
1367 vfmt
->VertexAttrib4fvARB
= _save_VertexAttrib4fvARB
;
1369 vfmt
->VertexAttrib1fNV
= _save_VertexAttrib1fNV
;
1370 vfmt
->VertexAttrib1fvNV
= _save_VertexAttrib1fvNV
;
1371 vfmt
->VertexAttrib2fNV
= _save_VertexAttrib2fNV
;
1372 vfmt
->VertexAttrib2fvNV
= _save_VertexAttrib2fvNV
;
1373 vfmt
->VertexAttrib3fNV
= _save_VertexAttrib3fNV
;
1374 vfmt
->VertexAttrib3fvNV
= _save_VertexAttrib3fvNV
;
1375 vfmt
->VertexAttrib4fNV
= _save_VertexAttrib4fNV
;
1376 vfmt
->VertexAttrib4fvNV
= _save_VertexAttrib4fvNV
;
1378 /* integer-valued */
1379 vfmt
->VertexAttribI1i
= _save_VertexAttribI1i
;
1380 vfmt
->VertexAttribI2i
= _save_VertexAttribI2i
;
1381 vfmt
->VertexAttribI3i
= _save_VertexAttribI3i
;
1382 vfmt
->VertexAttribI4i
= _save_VertexAttribI4i
;
1383 vfmt
->VertexAttribI2iv
= _save_VertexAttribI2iv
;
1384 vfmt
->VertexAttribI3iv
= _save_VertexAttribI3iv
;
1385 vfmt
->VertexAttribI4iv
= _save_VertexAttribI4iv
;
1387 /* unsigned integer-valued */
1388 vfmt
->VertexAttribI1ui
= _save_VertexAttribI1ui
;
1389 vfmt
->VertexAttribI2ui
= _save_VertexAttribI2ui
;
1390 vfmt
->VertexAttribI3ui
= _save_VertexAttribI3ui
;
1391 vfmt
->VertexAttribI4ui
= _save_VertexAttribI4ui
;
1392 vfmt
->VertexAttribI2uiv
= _save_VertexAttribI2uiv
;
1393 vfmt
->VertexAttribI3uiv
= _save_VertexAttribI3uiv
;
1394 vfmt
->VertexAttribI4uiv
= _save_VertexAttribI4uiv
;
1396 vfmt
->VertexP2ui
= _save_VertexP2ui
;
1397 vfmt
->VertexP3ui
= _save_VertexP3ui
;
1398 vfmt
->VertexP4ui
= _save_VertexP4ui
;
1399 vfmt
->VertexP2uiv
= _save_VertexP2uiv
;
1400 vfmt
->VertexP3uiv
= _save_VertexP3uiv
;
1401 vfmt
->VertexP4uiv
= _save_VertexP4uiv
;
1403 vfmt
->TexCoordP1ui
= _save_TexCoordP1ui
;
1404 vfmt
->TexCoordP2ui
= _save_TexCoordP2ui
;
1405 vfmt
->TexCoordP3ui
= _save_TexCoordP3ui
;
1406 vfmt
->TexCoordP4ui
= _save_TexCoordP4ui
;
1407 vfmt
->TexCoordP1uiv
= _save_TexCoordP1uiv
;
1408 vfmt
->TexCoordP2uiv
= _save_TexCoordP2uiv
;
1409 vfmt
->TexCoordP3uiv
= _save_TexCoordP3uiv
;
1410 vfmt
->TexCoordP4uiv
= _save_TexCoordP4uiv
;
1412 vfmt
->MultiTexCoordP1ui
= _save_MultiTexCoordP1ui
;
1413 vfmt
->MultiTexCoordP2ui
= _save_MultiTexCoordP2ui
;
1414 vfmt
->MultiTexCoordP3ui
= _save_MultiTexCoordP3ui
;
1415 vfmt
->MultiTexCoordP4ui
= _save_MultiTexCoordP4ui
;
1416 vfmt
->MultiTexCoordP1uiv
= _save_MultiTexCoordP1uiv
;
1417 vfmt
->MultiTexCoordP2uiv
= _save_MultiTexCoordP2uiv
;
1418 vfmt
->MultiTexCoordP3uiv
= _save_MultiTexCoordP3uiv
;
1419 vfmt
->MultiTexCoordP4uiv
= _save_MultiTexCoordP4uiv
;
1421 vfmt
->NormalP3ui
= _save_NormalP3ui
;
1422 vfmt
->NormalP3uiv
= _save_NormalP3uiv
;
1424 vfmt
->ColorP3ui
= _save_ColorP3ui
;
1425 vfmt
->ColorP4ui
= _save_ColorP4ui
;
1426 vfmt
->ColorP3uiv
= _save_ColorP3uiv
;
1427 vfmt
->ColorP4uiv
= _save_ColorP4uiv
;
1429 vfmt
->SecondaryColorP3ui
= _save_SecondaryColorP3ui
;
1430 vfmt
->SecondaryColorP3uiv
= _save_SecondaryColorP3uiv
;
1432 vfmt
->VertexAttribP1ui
= _save_VertexAttribP1ui
;
1433 vfmt
->VertexAttribP2ui
= _save_VertexAttribP2ui
;
1434 vfmt
->VertexAttribP3ui
= _save_VertexAttribP3ui
;
1435 vfmt
->VertexAttribP4ui
= _save_VertexAttribP4ui
;
1437 vfmt
->VertexAttribP1uiv
= _save_VertexAttribP1uiv
;
1438 vfmt
->VertexAttribP2uiv
= _save_VertexAttribP2uiv
;
1439 vfmt
->VertexAttribP3uiv
= _save_VertexAttribP3uiv
;
1440 vfmt
->VertexAttribP4uiv
= _save_VertexAttribP4uiv
;
1442 /* This will all require us to fallback to saving the list as opcodes:
1444 _MESA_INIT_DLIST_VTXFMT(vfmt
, _save_
); /* inside begin/end */
1446 _MESA_INIT_EVAL_VTXFMT(vfmt
, _save_
);
1448 /* These calls all generate GL_INVALID_OPERATION since this vtxfmt is
1449 * only used when we're inside a glBegin/End pair.
1451 vfmt
->Begin
= _save_Begin
;
1452 vfmt
->Rectf
= _save_Rectf
;
1453 vfmt
->DrawArrays
= _save_DrawArrays
;
1454 vfmt
->DrawElements
= _save_DrawElements
;
1455 vfmt
->DrawRangeElements
= _save_DrawRangeElements
;
1456 vfmt
->DrawElementsBaseVertex
= _save_DrawElementsBaseVertex
;
1457 vfmt
->DrawRangeElementsBaseVertex
= _save_DrawRangeElementsBaseVertex
;
1458 vfmt
->MultiDrawElementsEXT
= _save_MultiDrawElements
;
1459 vfmt
->MultiDrawElementsBaseVertex
= _save_MultiDrawElementsBaseVertex
;
1460 vfmt
->DrawTransformFeedback
= _save_DrawTransformFeedback
;
1461 vfmt
->DrawTransformFeedbackStream
= _save_DrawTransformFeedbackStream
;
1462 vfmt
->DrawTransformFeedbackInstanced
= _save_DrawTransformFeedbackInstanced
;
1463 vfmt
->DrawTransformFeedbackStreamInstanced
=
1464 _save_DrawTransformFeedbackStreamInstanced
;
1469 vbo_save_SaveFlushVertices(struct gl_context
*ctx
)
1471 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1473 /* Noop when we are actually active:
1475 if (ctx
->Driver
.CurrentSavePrimitive
== PRIM_INSIDE_UNKNOWN_PRIM
||
1476 ctx
->Driver
.CurrentSavePrimitive
<= GL_POLYGON
)
1479 if (save
->vert_count
|| save
->prim_count
)
1480 _save_compile_vertex_list(ctx
);
1482 _save_copy_to_current(ctx
);
1483 _save_reset_vertex(ctx
);
1484 _save_reset_counters(ctx
);
1485 ctx
->Driver
.SaveNeedFlush
= 0;
1490 vbo_save_NewList(struct gl_context
*ctx
, GLuint list
, GLenum mode
)
1492 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1497 if (!save
->prim_store
)
1498 save
->prim_store
= alloc_prim_store(ctx
);
1500 if (!save
->vertex_store
)
1501 save
->vertex_store
= alloc_vertex_store(ctx
);
1503 save
->buffer_ptr
= vbo_save_map_vertex_store(ctx
, save
->vertex_store
);
1505 _save_reset_vertex(ctx
);
1506 _save_reset_counters(ctx
);
1507 ctx
->Driver
.SaveNeedFlush
= 0;
1512 vbo_save_EndList(struct gl_context
*ctx
)
1514 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1516 /* EndList called inside a (saved) Begin/End pair?
1518 if (ctx
->Driver
.CurrentSavePrimitive
!= PRIM_OUTSIDE_BEGIN_END
) {
1520 if (save
->prim_count
> 0) {
1521 GLint i
= save
->prim_count
- 1;
1522 ctx
->Driver
.CurrentSavePrimitive
= PRIM_OUTSIDE_BEGIN_END
;
1523 save
->prim
[i
].end
= 0;
1524 save
->prim
[i
].count
= (save
->vert_count
- save
->prim
[i
].start
);
1527 /* Make sure this vertex list gets replayed by the "loopback"
1530 save
->dangling_attr_ref
= 1;
1531 vbo_save_SaveFlushVertices(ctx
);
1533 /* Swap out this vertex format while outside begin/end. Any color,
1534 * etc. received between here and the next begin will be compiled
1537 _mesa_install_save_vtxfmt(ctx
, &ctx
->ListState
.ListVtxfmt
);
1540 vbo_save_unmap_vertex_store(ctx
, save
->vertex_store
);
1542 assert(save
->vertex_size
== 0);
1547 vbo_save_BeginCallList(struct gl_context
*ctx
, struct gl_display_list
*dlist
)
1549 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1550 save
->replay_flags
|= dlist
->Flags
;
1555 vbo_save_EndCallList(struct gl_context
*ctx
)
1557 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1559 if (ctx
->ListState
.CallDepth
== 1) {
1560 /* This is correct: want to keep only the VBO_SAVE_FALLBACK
1561 * flag, if it is set:
1563 save
->replay_flags
&= VBO_SAVE_FALLBACK
;
1569 vbo_destroy_vertex_list(struct gl_context
*ctx
, void *data
)
1571 struct vbo_save_vertex_list
*node
= (struct vbo_save_vertex_list
*) data
;
1574 if (--node
->vertex_store
->refcount
== 0)
1575 free_vertex_store(ctx
, node
->vertex_store
);
1577 if (--node
->prim_store
->refcount
== 0)
1578 FREE(node
->prim_store
);
1580 if (node
->current_data
) {
1581 FREE(node
->current_data
);
1582 node
->current_data
= NULL
;
1588 vbo_print_vertex_list(struct gl_context
*ctx
, void *data
)
1590 struct vbo_save_vertex_list
*node
= (struct vbo_save_vertex_list
*) data
;
1594 printf("VBO-VERTEX-LIST, %u vertices %d primitives, %d vertsize\n",
1595 node
->count
, node
->prim_count
, node
->vertex_size
);
1597 for (i
= 0; i
< node
->prim_count
; i
++) {
1598 struct _mesa_prim
*prim
= &node
->prim
[i
];
1599 _mesa_debug(NULL
, " prim %d: %s%s %d..%d %s %s\n",
1601 _mesa_lookup_prim_by_nr(prim
->mode
),
1602 prim
->weak
? " (weak)" : "",
1604 prim
->start
+ prim
->count
,
1605 (prim
->begin
) ? "BEGIN" : "(wrap)",
1606 (prim
->end
) ? "END" : "(wrap)");
1612 * Called during context creation/init.
1615 _save_current_init(struct gl_context
*ctx
)
1617 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1620 for (i
= VBO_ATTRIB_POS
; i
<= VBO_ATTRIB_GENERIC15
; i
++) {
1621 const GLuint j
= i
- VBO_ATTRIB_POS
;
1622 ASSERT(j
< VERT_ATTRIB_MAX
);
1623 save
->currentsz
[i
] = &ctx
->ListState
.ActiveAttribSize
[j
];
1624 save
->current
[i
] = ctx
->ListState
.CurrentAttrib
[j
];
1627 for (i
= VBO_ATTRIB_FIRST_MATERIAL
; i
<= VBO_ATTRIB_LAST_MATERIAL
; i
++) {
1628 const GLuint j
= i
- VBO_ATTRIB_FIRST_MATERIAL
;
1629 ASSERT(j
< MAT_ATTRIB_MAX
);
1630 save
->currentsz
[i
] = &ctx
->ListState
.ActiveMaterialSize
[j
];
1631 save
->current
[i
] = ctx
->ListState
.CurrentMaterial
[j
];
1637 * Initialize the display list compiler. Called during context creation.
1640 vbo_save_api_init(struct vbo_save_context
*save
)
1642 struct gl_context
*ctx
= save
->ctx
;
1645 save
->opcode_vertex_list
=
1646 _mesa_dlist_alloc_opcode(ctx
,
1647 sizeof(struct vbo_save_vertex_list
),
1648 vbo_save_playback_vertex_list
,
1649 vbo_destroy_vertex_list
,
1650 vbo_print_vertex_list
);
1652 ctx
->Driver
.NotifySaveBegin
= vbo_save_NotifyBegin
;
1654 _save_vtxfmt_init(ctx
);
1655 _save_current_init(ctx
);
1656 _mesa_noop_vtxfmt_init(&save
->vtxfmt_noop
);
1658 /* These will actually get set again when binding/drawing */
1659 for (i
= 0; i
< VBO_ATTRIB_MAX
; i
++)
1660 save
->inputs
[i
] = &save
->arrays
[i
];
1662 /* Hook our array functions into the outside-begin-end vtxfmt in
1665 ctx
->ListState
.ListVtxfmt
.Rectf
= _save_OBE_Rectf
;
1666 ctx
->ListState
.ListVtxfmt
.DrawArrays
= _save_OBE_DrawArrays
;
1667 ctx
->ListState
.ListVtxfmt
.DrawElements
= _save_OBE_DrawElements
;
1668 ctx
->ListState
.ListVtxfmt
.DrawRangeElements
= _save_OBE_DrawRangeElements
;
1669 ctx
->ListState
.ListVtxfmt
.MultiDrawElementsEXT
= _save_OBE_MultiDrawElements
;
1670 ctx
->ListState
.ListVtxfmt
.MultiDrawElementsBaseVertex
= _save_OBE_MultiDrawElementsBaseVertex
;
1671 _mesa_install_save_vtxfmt(ctx
, &ctx
->ListState
.ListVtxfmt
);
1675 #endif /* FEATURE_dlist */