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 memcpy(node
->attrtype
, save
->attrtype
, sizeof(node
->attrtype
));
328 node
->vertex_size
= save
->vertex_size
;
329 node
->buffer_offset
=
330 (save
->buffer
- save
->vertex_store
->buffer
) * sizeof(GLfloat
);
331 node
->count
= save
->vert_count
;
332 node
->wrap_count
= save
->copied
.nr
;
333 node
->dangling_attr_ref
= save
->dangling_attr_ref
;
334 node
->prim
= save
->prim
;
335 node
->prim_count
= save
->prim_count
;
336 node
->vertex_store
= save
->vertex_store
;
337 node
->prim_store
= save
->prim_store
;
339 node
->vertex_store
->refcount
++;
340 node
->prim_store
->refcount
++;
342 if (node
->prim
[0].no_current_update
) {
343 node
->current_size
= 0;
344 node
->current_data
= NULL
;
347 node
->current_size
= node
->vertex_size
- node
->attrsz
[0];
348 node
->current_data
= NULL
;
350 if (node
->current_size
) {
351 /* If the malloc fails, we just pull the data out of the VBO
354 node
->current_data
= malloc(node
->current_size
* sizeof(GLfloat
));
355 if (node
->current_data
) {
356 const char *buffer
= (const char *) save
->vertex_store
->buffer
;
357 unsigned attr_offset
= node
->attrsz
[0] * sizeof(GLfloat
);
358 unsigned vertex_offset
= 0;
362 (node
->count
- 1) * node
->vertex_size
* sizeof(GLfloat
);
364 memcpy(node
->current_data
,
365 buffer
+ node
->buffer_offset
+ vertex_offset
+ attr_offset
,
366 node
->current_size
* sizeof(GLfloat
));
371 assert(node
->attrsz
[VBO_ATTRIB_POS
] != 0 || node
->count
== 0);
373 if (save
->dangling_attr_ref
)
374 ctx
->ListState
.CurrentList
->Flags
|= DLIST_DANGLING_REFS
;
376 save
->vertex_store
->used
+= save
->vertex_size
* node
->count
;
377 save
->prim_store
->used
+= node
->prim_count
;
379 /* Copy duplicated vertices
381 save
->copied
.nr
= _save_copy_vertices(ctx
, node
, save
->buffer
);
383 /* Deal with GL_COMPILE_AND_EXECUTE:
385 if (ctx
->ExecuteFlag
) {
386 struct _glapi_table
*dispatch
= GET_DISPATCH();
388 _glapi_set_dispatch(ctx
->Exec
);
390 vbo_loopback_vertex_list(ctx
,
391 (const GLfloat
*) ((const char *) save
->
392 vertex_store
->buffer
+
393 node
->buffer_offset
),
394 node
->attrsz
, node
->prim
, node
->prim_count
,
395 node
->wrap_count
, node
->vertex_size
);
397 _glapi_set_dispatch(dispatch
);
400 /* Decide whether the storage structs are full, or can be used for
401 * the next vertex lists as well.
403 if (save
->vertex_store
->used
>
404 VBO_SAVE_BUFFER_SIZE
- 16 * (save
->vertex_size
+ 4)) {
408 vbo_save_unmap_vertex_store(ctx
, save
->vertex_store
);
410 /* Release old reference:
412 save
->vertex_store
->refcount
--;
413 assert(save
->vertex_store
->refcount
!= 0);
414 save
->vertex_store
= NULL
;
416 /* Allocate and map new store:
418 save
->vertex_store
= alloc_vertex_store(ctx
);
419 save
->buffer_ptr
= vbo_save_map_vertex_store(ctx
, save
->vertex_store
);
420 save
->out_of_memory
= save
->buffer_ptr
== NULL
;
423 if (save
->prim_store
->used
> VBO_SAVE_PRIM_SIZE
- 6) {
424 save
->prim_store
->refcount
--;
425 assert(save
->prim_store
->refcount
!= 0);
426 save
->prim_store
= alloc_prim_store(ctx
);
429 /* Reset our structures for the next run of vertices:
431 _save_reset_counters(ctx
);
436 * TODO -- If no new vertices have been stored, don't bother saving it.
439 _save_wrap_buffers(struct gl_context
*ctx
)
441 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
442 GLint i
= save
->prim_count
- 1;
445 GLboolean no_current_update
;
447 assert(i
< (GLint
) save
->prim_max
);
450 /* Close off in-progress primitive.
452 save
->prim
[i
].count
= (save
->vert_count
- save
->prim
[i
].start
);
453 mode
= save
->prim
[i
].mode
;
454 weak
= save
->prim
[i
].weak
;
455 no_current_update
= save
->prim
[i
].no_current_update
;
457 /* store the copied vertices, and allocate a new list.
459 _save_compile_vertex_list(ctx
);
461 /* Restart interrupted primitive
463 save
->prim
[0].mode
= mode
;
464 save
->prim
[0].weak
= weak
;
465 save
->prim
[0].no_current_update
= no_current_update
;
466 save
->prim
[0].begin
= 0;
467 save
->prim
[0].end
= 0;
468 save
->prim
[0].pad
= 0;
469 save
->prim
[0].start
= 0;
470 save
->prim
[0].count
= 0;
471 save
->prim
[0].num_instances
= 1;
472 save
->prim
[0].base_instance
= 0;
473 save
->prim_count
= 1;
478 * Called only when buffers are wrapped as the result of filling the
479 * vertex_store struct.
482 _save_wrap_filled_vertex(struct gl_context
*ctx
)
484 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
485 GLfloat
*data
= save
->copied
.buffer
;
488 /* Emit a glEnd to close off the last vertex list.
490 _save_wrap_buffers(ctx
);
492 /* Copy stored stored vertices to start of new list.
494 assert(save
->max_vert
- save
->vert_count
> save
->copied
.nr
);
496 for (i
= 0; i
< save
->copied
.nr
; i
++) {
497 memcpy(save
->buffer_ptr
, data
, save
->vertex_size
* sizeof(GLfloat
));
498 data
+= save
->vertex_size
;
499 save
->buffer_ptr
+= save
->vertex_size
;
506 _save_copy_to_current(struct gl_context
*ctx
)
508 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
511 for (i
= VBO_ATTRIB_POS
+ 1; i
< VBO_ATTRIB_MAX
; i
++) {
512 if (save
->attrsz
[i
]) {
513 save
->currentsz
[i
][0] = save
->attrsz
[i
];
514 COPY_CLEAN_4V_TYPE_AS_FLOAT(save
->current
[i
], save
->attrsz
[i
],
515 save
->attrptr
[i
], save
->attrtype
[i
]);
522 _save_copy_from_current(struct gl_context
*ctx
)
524 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
527 for (i
= VBO_ATTRIB_POS
+ 1; i
< VBO_ATTRIB_MAX
; i
++) {
528 switch (save
->attrsz
[i
]) {
530 save
->attrptr
[i
][3] = save
->current
[i
][3];
532 save
->attrptr
[i
][2] = save
->current
[i
][2];
534 save
->attrptr
[i
][1] = save
->current
[i
][1];
536 save
->attrptr
[i
][0] = save
->current
[i
][0];
544 /* Flush existing data, set new attrib size, replay copied vertices.
547 _save_upgrade_vertex(struct gl_context
*ctx
, GLuint attr
, GLuint newsz
)
549 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
554 /* Store the current run of vertices, and emit a GL_END. Emit a
555 * BEGIN in the new buffer.
557 if (save
->vert_count
)
558 _save_wrap_buffers(ctx
);
560 assert(save
->copied
.nr
== 0);
562 /* Do a COPY_TO_CURRENT to ensure back-copying works for the case
563 * when the attribute already exists in the vertex and is having
564 * its size increased.
566 _save_copy_to_current(ctx
);
570 oldsz
= save
->attrsz
[attr
];
571 save
->attrsz
[attr
] = newsz
;
573 save
->vertex_size
+= newsz
- oldsz
;
574 save
->max_vert
= ((VBO_SAVE_BUFFER_SIZE
- save
->vertex_store
->used
) /
576 save
->vert_count
= 0;
578 /* Recalculate all the attrptr[] values:
580 for (i
= 0, tmp
= save
->vertex
; i
< VBO_ATTRIB_MAX
; i
++) {
581 if (save
->attrsz
[i
]) {
582 save
->attrptr
[i
] = tmp
;
583 tmp
+= save
->attrsz
[i
];
586 save
->attrptr
[i
] = NULL
; /* will not be dereferenced. */
590 /* Copy from current to repopulate the vertex with correct values.
592 _save_copy_from_current(ctx
);
594 /* Replay stored vertices to translate them to new format here.
596 * If there are copied vertices and the new (upgraded) attribute
597 * has not been defined before, this list is somewhat degenerate,
598 * and will need fixup at runtime.
600 if (save
->copied
.nr
) {
601 GLfloat
*data
= save
->copied
.buffer
;
602 GLfloat
*dest
= save
->buffer
;
605 /* Need to note this and fix up at runtime (or loopback):
607 if (attr
!= VBO_ATTRIB_POS
&& save
->currentsz
[attr
][0] == 0) {
609 save
->dangling_attr_ref
= GL_TRUE
;
612 for (i
= 0; i
< save
->copied
.nr
; i
++) {
613 for (j
= 0; j
< VBO_ATTRIB_MAX
; j
++) {
614 if (save
->attrsz
[j
]) {
617 COPY_CLEAN_4V_TYPE_AS_FLOAT(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
]) {
656 const GLfloat
*id
= vbo_get_default_vals_as_float(save
->attrtype
[attr
]);
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, T, 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; \
707 save->attrtype[A] = T; \
713 for (i = 0; i < save->vertex_size; i++) \
714 save->buffer_ptr[i] = save->vertex[i]; \
716 save->buffer_ptr += save->vertex_size; \
718 if (++save->vert_count >= save->max_vert) \
719 _save_wrap_filled_vertex(ctx); \
723 #define TAG(x) _save_##x
725 #include "vbo_attrib_tmp.h"
729 #define MAT( ATTR, N, face, params ) \
731 if (face != GL_BACK) \
732 MAT_ATTR( ATTR, N, params ); /* front */ \
733 if (face != GL_FRONT) \
734 MAT_ATTR( ATTR + 1, N, params ); /* back */ \
739 * Save a glMaterial call found between glBegin/End.
740 * glMaterial calls outside Begin/End are handled in dlist.c.
742 static void GLAPIENTRY
743 _save_Materialfv(GLenum face
, GLenum pname
, const GLfloat
*params
)
745 GET_CURRENT_CONTEXT(ctx
);
747 if (face
!= GL_FRONT
&& face
!= GL_BACK
&& face
!= GL_FRONT_AND_BACK
) {
748 _mesa_compile_error(ctx
, GL_INVALID_ENUM
, "glMaterial(face)");
754 MAT(VBO_ATTRIB_MAT_FRONT_EMISSION
, 4, face
, params
);
757 MAT(VBO_ATTRIB_MAT_FRONT_AMBIENT
, 4, face
, params
);
760 MAT(VBO_ATTRIB_MAT_FRONT_DIFFUSE
, 4, face
, params
);
763 MAT(VBO_ATTRIB_MAT_FRONT_SPECULAR
, 4, face
, params
);
766 if (*params
< 0 || *params
> ctx
->Const
.MaxShininess
) {
767 _mesa_compile_error(ctx
, GL_INVALID_VALUE
, "glMaterial(shininess)");
770 MAT(VBO_ATTRIB_MAT_FRONT_SHININESS
, 1, face
, params
);
773 case GL_COLOR_INDEXES
:
774 MAT(VBO_ATTRIB_MAT_FRONT_INDEXES
, 3, face
, params
);
776 case GL_AMBIENT_AND_DIFFUSE
:
777 MAT(VBO_ATTRIB_MAT_FRONT_AMBIENT
, 4, face
, params
);
778 MAT(VBO_ATTRIB_MAT_FRONT_DIFFUSE
, 4, face
, params
);
781 _mesa_compile_error(ctx
, GL_INVALID_ENUM
, "glMaterial(pname)");
787 /* Cope with EvalCoord/CallList called within a begin/end object:
788 * -- Flush current buffer
789 * -- Fallback to opcodes for the rest of the begin/end object.
792 dlist_fallback(struct gl_context
*ctx
)
794 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
796 if (save
->vert_count
|| save
->prim_count
) {
797 if (save
->prim_count
> 0) {
798 /* Close off in-progress primitive. */
799 GLint i
= save
->prim_count
- 1;
800 save
->prim
[i
].count
= save
->vert_count
- save
->prim
[i
].start
;
803 /* Need to replay this display list with loopback,
804 * unfortunately, otherwise this primitive won't be handled
807 save
->dangling_attr_ref
= 1;
809 _save_compile_vertex_list(ctx
);
812 _save_copy_to_current(ctx
);
813 _save_reset_vertex(ctx
);
814 _save_reset_counters(ctx
);
815 if (save
->out_of_memory
) {
816 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt_noop
);
819 _mesa_install_save_vtxfmt(ctx
, &ctx
->ListState
.ListVtxfmt
);
821 ctx
->Driver
.SaveNeedFlush
= 0;
825 static void GLAPIENTRY
826 _save_EvalCoord1f(GLfloat u
)
828 GET_CURRENT_CONTEXT(ctx
);
830 CALL_EvalCoord1f(ctx
->Save
, (u
));
833 static void GLAPIENTRY
834 _save_EvalCoord1fv(const GLfloat
* v
)
836 GET_CURRENT_CONTEXT(ctx
);
838 CALL_EvalCoord1fv(ctx
->Save
, (v
));
841 static void GLAPIENTRY
842 _save_EvalCoord2f(GLfloat u
, GLfloat v
)
844 GET_CURRENT_CONTEXT(ctx
);
846 CALL_EvalCoord2f(ctx
->Save
, (u
, v
));
849 static void GLAPIENTRY
850 _save_EvalCoord2fv(const GLfloat
* v
)
852 GET_CURRENT_CONTEXT(ctx
);
854 CALL_EvalCoord2fv(ctx
->Save
, (v
));
857 static void GLAPIENTRY
858 _save_EvalPoint1(GLint i
)
860 GET_CURRENT_CONTEXT(ctx
);
862 CALL_EvalPoint1(ctx
->Save
, (i
));
865 static void GLAPIENTRY
866 _save_EvalPoint2(GLint i
, GLint j
)
868 GET_CURRENT_CONTEXT(ctx
);
870 CALL_EvalPoint2(ctx
->Save
, (i
, j
));
873 static void GLAPIENTRY
874 _save_CallList(GLuint l
)
876 GET_CURRENT_CONTEXT(ctx
);
878 CALL_CallList(ctx
->Save
, (l
));
881 static void GLAPIENTRY
882 _save_CallLists(GLsizei n
, GLenum type
, const GLvoid
* v
)
884 GET_CURRENT_CONTEXT(ctx
);
886 CALL_CallLists(ctx
->Save
, (n
, type
, v
));
891 /* This begin is hooked into ... Updating of
892 * ctx->Driver.CurrentSavePrimitive is already taken care of.
895 vbo_save_NotifyBegin(struct gl_context
*ctx
, GLenum mode
)
897 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
899 GLuint i
= save
->prim_count
++;
901 assert(i
< save
->prim_max
);
902 save
->prim
[i
].mode
= mode
& VBO_SAVE_PRIM_MODE_MASK
;
903 save
->prim
[i
].begin
= 1;
904 save
->prim
[i
].end
= 0;
905 save
->prim
[i
].weak
= (mode
& VBO_SAVE_PRIM_WEAK
) ? 1 : 0;
906 save
->prim
[i
].no_current_update
=
907 (mode
& VBO_SAVE_PRIM_NO_CURRENT_UPDATE
) ? 1 : 0;
908 save
->prim
[i
].pad
= 0;
909 save
->prim
[i
].start
= save
->vert_count
;
910 save
->prim
[i
].count
= 0;
911 save
->prim
[i
].num_instances
= 1;
912 save
->prim
[i
].base_instance
= 0;
914 if (save
->out_of_memory
) {
915 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt_noop
);
918 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt
);
920 ctx
->Driver
.SaveNeedFlush
= 1;
925 static void GLAPIENTRY
928 GET_CURRENT_CONTEXT(ctx
);
929 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
930 GLint i
= save
->prim_count
- 1;
932 ctx
->Driver
.CurrentSavePrimitive
= PRIM_OUTSIDE_BEGIN_END
;
933 save
->prim
[i
].end
= 1;
934 save
->prim
[i
].count
= (save
->vert_count
- save
->prim
[i
].start
);
936 if (i
== (GLint
) save
->prim_max
- 1) {
937 _save_compile_vertex_list(ctx
);
938 assert(save
->copied
.nr
== 0);
941 /* Swap out this vertex format while outside begin/end. Any color,
942 * etc. received between here and the next begin will be compiled
945 if (save
->out_of_memory
) {
946 _mesa_install_save_vtxfmt(ctx
, &save
->vtxfmt_noop
);
949 _mesa_install_save_vtxfmt(ctx
, &ctx
->ListState
.ListVtxfmt
);
954 /* These are all errors as this vtxfmt is only installed inside
957 static void GLAPIENTRY
958 _save_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
959 const GLvoid
* indices
)
961 GET_CURRENT_CONTEXT(ctx
);
966 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawElements");
970 static void GLAPIENTRY
971 _save_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
972 GLsizei count
, GLenum type
, const GLvoid
* indices
)
974 GET_CURRENT_CONTEXT(ctx
);
981 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawRangeElements");
985 static void GLAPIENTRY
986 _save_DrawElementsBaseVertex(GLenum mode
, GLsizei count
, GLenum type
,
987 const GLvoid
* indices
, GLint basevertex
)
989 GET_CURRENT_CONTEXT(ctx
);
995 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawElements");
999 static void GLAPIENTRY
1000 _save_DrawRangeElementsBaseVertex(GLenum mode
,
1005 const GLvoid
* indices
, GLint basevertex
)
1007 GET_CURRENT_CONTEXT(ctx
);
1015 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawRangeElements");
1019 static void GLAPIENTRY
1020 _save_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
1022 GET_CURRENT_CONTEXT(ctx
);
1026 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawArrays");
1030 static void GLAPIENTRY
1031 _save_MultiDrawElements(GLenum mode
, const GLsizei
*count
, GLenum type
,
1032 const GLvoid
**indices
, GLsizei primcount
)
1034 GET_CURRENT_CONTEXT(ctx
);
1040 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glMultiDrawElements");
1044 static void GLAPIENTRY
1045 _save_MultiDrawElementsBaseVertex(GLenum mode
, const GLsizei
*count
,
1046 GLenum type
, const GLvoid
* const *indices
,
1047 GLsizei primcount
, const GLint
*basevertex
)
1049 GET_CURRENT_CONTEXT(ctx
);
1056 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
,
1057 "glMultiDrawElementsBaseVertex");
1061 static void GLAPIENTRY
1062 _save_DrawTransformFeedback(GLenum mode
, GLuint name
)
1064 GET_CURRENT_CONTEXT(ctx
);
1067 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glDrawTransformFeedback");
1071 static void GLAPIENTRY
1072 _save_DrawTransformFeedbackStream(GLenum mode
, GLuint name
, GLuint stream
)
1074 GET_CURRENT_CONTEXT(ctx
);
1078 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
,
1079 "glDrawTransformFeedbackStream");
1083 static void GLAPIENTRY
1084 _save_DrawTransformFeedbackInstanced(GLenum mode
, GLuint name
,
1087 GET_CURRENT_CONTEXT(ctx
);
1091 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
,
1092 "glDrawTransformFeedbackInstanced");
1096 static void GLAPIENTRY
1097 _save_DrawTransformFeedbackStreamInstanced(GLenum mode
, GLuint name
,
1098 GLuint stream
, GLsizei primcount
)
1100 GET_CURRENT_CONTEXT(ctx
);
1105 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
,
1106 "glDrawTransformFeedbackStreamInstanced");
1110 static void GLAPIENTRY
1111 _save_Rectf(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
1113 GET_CURRENT_CONTEXT(ctx
);
1118 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glRectf");
1122 static void GLAPIENTRY
1123 _save_EvalMesh1(GLenum mode
, GLint i1
, GLint i2
)
1125 GET_CURRENT_CONTEXT(ctx
);
1129 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glEvalMesh1");
1133 static void GLAPIENTRY
1134 _save_EvalMesh2(GLenum mode
, GLint i1
, GLint i2
, GLint j1
, GLint j2
)
1136 GET_CURRENT_CONTEXT(ctx
);
1142 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "glEvalMesh2");
1146 static void GLAPIENTRY
1147 _save_Begin(GLenum mode
)
1149 GET_CURRENT_CONTEXT(ctx
);
1151 _mesa_compile_error(ctx
, GL_INVALID_OPERATION
, "Recursive glBegin");
1155 static void GLAPIENTRY
1156 _save_PrimitiveRestartNV(void)
1159 GET_CURRENT_CONTEXT(ctx
);
1161 curPrim
= ctx
->Driver
.CurrentSavePrimitive
;
1164 _save_Begin(curPrim
);
1168 /* Unlike the functions above, these are to be hooked into the vtxfmt
1169 * maintained in ctx->ListState, active when the list is known or
1170 * suspected to be outside any begin/end primitive.
1171 * Note: OBE = Outside Begin/End
1173 static void GLAPIENTRY
1174 _save_OBE_Rectf(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
1176 GET_CURRENT_CONTEXT(ctx
);
1177 vbo_save_NotifyBegin(ctx
, GL_QUADS
| VBO_SAVE_PRIM_WEAK
);
1178 CALL_Vertex2f(GET_DISPATCH(), (x1
, y1
));
1179 CALL_Vertex2f(GET_DISPATCH(), (x2
, y1
));
1180 CALL_Vertex2f(GET_DISPATCH(), (x2
, y2
));
1181 CALL_Vertex2f(GET_DISPATCH(), (x1
, y2
));
1182 CALL_End(GET_DISPATCH(), ());
1186 static void GLAPIENTRY
1187 _save_OBE_DrawArrays(GLenum mode
, GLint start
, GLsizei count
)
1189 GET_CURRENT_CONTEXT(ctx
);
1190 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1193 if (!_mesa_validate_DrawArrays(ctx
, mode
, start
, count
))
1196 if (save
->out_of_memory
)
1201 vbo_save_NotifyBegin(ctx
, (mode
| VBO_SAVE_PRIM_WEAK
1202 | VBO_SAVE_PRIM_NO_CURRENT_UPDATE
));
1204 for (i
= 0; i
< count
; i
++)
1205 CALL_ArrayElement(GET_DISPATCH(), (start
+ i
));
1206 CALL_End(GET_DISPATCH(), ());
1208 _ae_unmap_vbos(ctx
);
1212 /* Could do better by copying the arrays and element list intact and
1213 * then emitting an indexed prim at runtime.
1215 static void GLAPIENTRY
1216 _save_OBE_DrawElements(GLenum mode
, GLsizei count
, GLenum type
,
1217 const GLvoid
* indices
)
1219 GET_CURRENT_CONTEXT(ctx
);
1220 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1223 if (!_mesa_validate_DrawElements(ctx
, mode
, count
, type
, indices
, 0))
1226 if (save
->out_of_memory
)
1231 if (_mesa_is_bufferobj(ctx
->Array
.ArrayObj
->ElementArrayBufferObj
))
1233 ADD_POINTERS(ctx
->Array
.ArrayObj
->ElementArrayBufferObj
->Pointer
, indices
);
1235 vbo_save_NotifyBegin(ctx
, (mode
| VBO_SAVE_PRIM_WEAK
|
1236 VBO_SAVE_PRIM_NO_CURRENT_UPDATE
));
1239 case GL_UNSIGNED_BYTE
:
1240 for (i
= 0; i
< count
; i
++)
1241 CALL_ArrayElement(GET_DISPATCH(), (((GLubyte
*) indices
)[i
]));
1243 case GL_UNSIGNED_SHORT
:
1244 for (i
= 0; i
< count
; i
++)
1245 CALL_ArrayElement(GET_DISPATCH(), (((GLushort
*) indices
)[i
]));
1247 case GL_UNSIGNED_INT
:
1248 for (i
= 0; i
< count
; i
++)
1249 CALL_ArrayElement(GET_DISPATCH(), (((GLuint
*) indices
)[i
]));
1252 _mesa_error(ctx
, GL_INVALID_ENUM
, "glDrawElements(type)");
1256 CALL_End(GET_DISPATCH(), ());
1258 _ae_unmap_vbos(ctx
);
1262 static void GLAPIENTRY
1263 _save_OBE_DrawRangeElements(GLenum mode
, GLuint start
, GLuint end
,
1264 GLsizei count
, GLenum type
,
1265 const GLvoid
* indices
)
1267 GET_CURRENT_CONTEXT(ctx
);
1268 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1270 if (!_mesa_validate_DrawRangeElements(ctx
, mode
,
1271 start
, end
, count
, type
, indices
, 0))
1274 if (save
->out_of_memory
)
1277 _save_OBE_DrawElements(mode
, count
, type
, indices
);
1281 static void GLAPIENTRY
1282 _save_OBE_MultiDrawElements(GLenum mode
, const GLsizei
*count
, GLenum type
,
1283 const GLvoid
**indices
, GLsizei primcount
)
1287 for (i
= 0; i
< primcount
; i
++) {
1289 CALL_DrawElements(GET_DISPATCH(), (mode
, count
[i
], type
, indices
[i
]));
1295 static void GLAPIENTRY
1296 _save_OBE_MultiDrawElementsBaseVertex(GLenum mode
, const GLsizei
*count
,
1298 const GLvoid
* const *indices
,
1300 const GLint
*basevertex
)
1304 for (i
= 0; i
< primcount
; i
++) {
1306 CALL_DrawElementsBaseVertex(GET_DISPATCH(), (mode
, count
[i
], type
,
1315 _save_vtxfmt_init(struct gl_context
*ctx
)
1317 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1318 GLvertexformat
*vfmt
= &save
->vtxfmt
;
1320 _MESA_INIT_ARRAYELT_VTXFMT(vfmt
, _ae_
);
1322 vfmt
->Begin
= _save_Begin
;
1323 vfmt
->Color3f
= _save_Color3f
;
1324 vfmt
->Color3fv
= _save_Color3fv
;
1325 vfmt
->Color4f
= _save_Color4f
;
1326 vfmt
->Color4fv
= _save_Color4fv
;
1327 vfmt
->EdgeFlag
= _save_EdgeFlag
;
1328 vfmt
->End
= _save_End
;
1329 vfmt
->PrimitiveRestartNV
= _save_PrimitiveRestartNV
;
1330 vfmt
->FogCoordfEXT
= _save_FogCoordfEXT
;
1331 vfmt
->FogCoordfvEXT
= _save_FogCoordfvEXT
;
1332 vfmt
->Indexf
= _save_Indexf
;
1333 vfmt
->Indexfv
= _save_Indexfv
;
1334 vfmt
->Materialfv
= _save_Materialfv
;
1335 vfmt
->MultiTexCoord1fARB
= _save_MultiTexCoord1f
;
1336 vfmt
->MultiTexCoord1fvARB
= _save_MultiTexCoord1fv
;
1337 vfmt
->MultiTexCoord2fARB
= _save_MultiTexCoord2f
;
1338 vfmt
->MultiTexCoord2fvARB
= _save_MultiTexCoord2fv
;
1339 vfmt
->MultiTexCoord3fARB
= _save_MultiTexCoord3f
;
1340 vfmt
->MultiTexCoord3fvARB
= _save_MultiTexCoord3fv
;
1341 vfmt
->MultiTexCoord4fARB
= _save_MultiTexCoord4f
;
1342 vfmt
->MultiTexCoord4fvARB
= _save_MultiTexCoord4fv
;
1343 vfmt
->Normal3f
= _save_Normal3f
;
1344 vfmt
->Normal3fv
= _save_Normal3fv
;
1345 vfmt
->SecondaryColor3fEXT
= _save_SecondaryColor3fEXT
;
1346 vfmt
->SecondaryColor3fvEXT
= _save_SecondaryColor3fvEXT
;
1347 vfmt
->TexCoord1f
= _save_TexCoord1f
;
1348 vfmt
->TexCoord1fv
= _save_TexCoord1fv
;
1349 vfmt
->TexCoord2f
= _save_TexCoord2f
;
1350 vfmt
->TexCoord2fv
= _save_TexCoord2fv
;
1351 vfmt
->TexCoord3f
= _save_TexCoord3f
;
1352 vfmt
->TexCoord3fv
= _save_TexCoord3fv
;
1353 vfmt
->TexCoord4f
= _save_TexCoord4f
;
1354 vfmt
->TexCoord4fv
= _save_TexCoord4fv
;
1355 vfmt
->Vertex2f
= _save_Vertex2f
;
1356 vfmt
->Vertex2fv
= _save_Vertex2fv
;
1357 vfmt
->Vertex3f
= _save_Vertex3f
;
1358 vfmt
->Vertex3fv
= _save_Vertex3fv
;
1359 vfmt
->Vertex4f
= _save_Vertex4f
;
1360 vfmt
->Vertex4fv
= _save_Vertex4fv
;
1361 vfmt
->VertexAttrib1fARB
= _save_VertexAttrib1fARB
;
1362 vfmt
->VertexAttrib1fvARB
= _save_VertexAttrib1fvARB
;
1363 vfmt
->VertexAttrib2fARB
= _save_VertexAttrib2fARB
;
1364 vfmt
->VertexAttrib2fvARB
= _save_VertexAttrib2fvARB
;
1365 vfmt
->VertexAttrib3fARB
= _save_VertexAttrib3fARB
;
1366 vfmt
->VertexAttrib3fvARB
= _save_VertexAttrib3fvARB
;
1367 vfmt
->VertexAttrib4fARB
= _save_VertexAttrib4fARB
;
1368 vfmt
->VertexAttrib4fvARB
= _save_VertexAttrib4fvARB
;
1370 vfmt
->VertexAttrib1fNV
= _save_VertexAttrib1fNV
;
1371 vfmt
->VertexAttrib1fvNV
= _save_VertexAttrib1fvNV
;
1372 vfmt
->VertexAttrib2fNV
= _save_VertexAttrib2fNV
;
1373 vfmt
->VertexAttrib2fvNV
= _save_VertexAttrib2fvNV
;
1374 vfmt
->VertexAttrib3fNV
= _save_VertexAttrib3fNV
;
1375 vfmt
->VertexAttrib3fvNV
= _save_VertexAttrib3fvNV
;
1376 vfmt
->VertexAttrib4fNV
= _save_VertexAttrib4fNV
;
1377 vfmt
->VertexAttrib4fvNV
= _save_VertexAttrib4fvNV
;
1379 /* integer-valued */
1380 vfmt
->VertexAttribI1i
= _save_VertexAttribI1i
;
1381 vfmt
->VertexAttribI2i
= _save_VertexAttribI2i
;
1382 vfmt
->VertexAttribI3i
= _save_VertexAttribI3i
;
1383 vfmt
->VertexAttribI4i
= _save_VertexAttribI4i
;
1384 vfmt
->VertexAttribI2iv
= _save_VertexAttribI2iv
;
1385 vfmt
->VertexAttribI3iv
= _save_VertexAttribI3iv
;
1386 vfmt
->VertexAttribI4iv
= _save_VertexAttribI4iv
;
1388 /* unsigned integer-valued */
1389 vfmt
->VertexAttribI1ui
= _save_VertexAttribI1ui
;
1390 vfmt
->VertexAttribI2ui
= _save_VertexAttribI2ui
;
1391 vfmt
->VertexAttribI3ui
= _save_VertexAttribI3ui
;
1392 vfmt
->VertexAttribI4ui
= _save_VertexAttribI4ui
;
1393 vfmt
->VertexAttribI2uiv
= _save_VertexAttribI2uiv
;
1394 vfmt
->VertexAttribI3uiv
= _save_VertexAttribI3uiv
;
1395 vfmt
->VertexAttribI4uiv
= _save_VertexAttribI4uiv
;
1397 vfmt
->VertexP2ui
= _save_VertexP2ui
;
1398 vfmt
->VertexP3ui
= _save_VertexP3ui
;
1399 vfmt
->VertexP4ui
= _save_VertexP4ui
;
1400 vfmt
->VertexP2uiv
= _save_VertexP2uiv
;
1401 vfmt
->VertexP3uiv
= _save_VertexP3uiv
;
1402 vfmt
->VertexP4uiv
= _save_VertexP4uiv
;
1404 vfmt
->TexCoordP1ui
= _save_TexCoordP1ui
;
1405 vfmt
->TexCoordP2ui
= _save_TexCoordP2ui
;
1406 vfmt
->TexCoordP3ui
= _save_TexCoordP3ui
;
1407 vfmt
->TexCoordP4ui
= _save_TexCoordP4ui
;
1408 vfmt
->TexCoordP1uiv
= _save_TexCoordP1uiv
;
1409 vfmt
->TexCoordP2uiv
= _save_TexCoordP2uiv
;
1410 vfmt
->TexCoordP3uiv
= _save_TexCoordP3uiv
;
1411 vfmt
->TexCoordP4uiv
= _save_TexCoordP4uiv
;
1413 vfmt
->MultiTexCoordP1ui
= _save_MultiTexCoordP1ui
;
1414 vfmt
->MultiTexCoordP2ui
= _save_MultiTexCoordP2ui
;
1415 vfmt
->MultiTexCoordP3ui
= _save_MultiTexCoordP3ui
;
1416 vfmt
->MultiTexCoordP4ui
= _save_MultiTexCoordP4ui
;
1417 vfmt
->MultiTexCoordP1uiv
= _save_MultiTexCoordP1uiv
;
1418 vfmt
->MultiTexCoordP2uiv
= _save_MultiTexCoordP2uiv
;
1419 vfmt
->MultiTexCoordP3uiv
= _save_MultiTexCoordP3uiv
;
1420 vfmt
->MultiTexCoordP4uiv
= _save_MultiTexCoordP4uiv
;
1422 vfmt
->NormalP3ui
= _save_NormalP3ui
;
1423 vfmt
->NormalP3uiv
= _save_NormalP3uiv
;
1425 vfmt
->ColorP3ui
= _save_ColorP3ui
;
1426 vfmt
->ColorP4ui
= _save_ColorP4ui
;
1427 vfmt
->ColorP3uiv
= _save_ColorP3uiv
;
1428 vfmt
->ColorP4uiv
= _save_ColorP4uiv
;
1430 vfmt
->SecondaryColorP3ui
= _save_SecondaryColorP3ui
;
1431 vfmt
->SecondaryColorP3uiv
= _save_SecondaryColorP3uiv
;
1433 vfmt
->VertexAttribP1ui
= _save_VertexAttribP1ui
;
1434 vfmt
->VertexAttribP2ui
= _save_VertexAttribP2ui
;
1435 vfmt
->VertexAttribP3ui
= _save_VertexAttribP3ui
;
1436 vfmt
->VertexAttribP4ui
= _save_VertexAttribP4ui
;
1438 vfmt
->VertexAttribP1uiv
= _save_VertexAttribP1uiv
;
1439 vfmt
->VertexAttribP2uiv
= _save_VertexAttribP2uiv
;
1440 vfmt
->VertexAttribP3uiv
= _save_VertexAttribP3uiv
;
1441 vfmt
->VertexAttribP4uiv
= _save_VertexAttribP4uiv
;
1443 /* This will all require us to fallback to saving the list as opcodes:
1445 _MESA_INIT_DLIST_VTXFMT(vfmt
, _save_
); /* inside begin/end */
1447 _MESA_INIT_EVAL_VTXFMT(vfmt
, _save_
);
1449 /* These calls all generate GL_INVALID_OPERATION since this vtxfmt is
1450 * only used when we're inside a glBegin/End pair.
1452 vfmt
->Begin
= _save_Begin
;
1453 vfmt
->Rectf
= _save_Rectf
;
1454 vfmt
->DrawArrays
= _save_DrawArrays
;
1455 vfmt
->DrawElements
= _save_DrawElements
;
1456 vfmt
->DrawRangeElements
= _save_DrawRangeElements
;
1457 vfmt
->DrawElementsBaseVertex
= _save_DrawElementsBaseVertex
;
1458 vfmt
->DrawRangeElementsBaseVertex
= _save_DrawRangeElementsBaseVertex
;
1459 vfmt
->MultiDrawElementsEXT
= _save_MultiDrawElements
;
1460 vfmt
->MultiDrawElementsBaseVertex
= _save_MultiDrawElementsBaseVertex
;
1461 vfmt
->DrawTransformFeedback
= _save_DrawTransformFeedback
;
1462 vfmt
->DrawTransformFeedbackStream
= _save_DrawTransformFeedbackStream
;
1463 vfmt
->DrawTransformFeedbackInstanced
= _save_DrawTransformFeedbackInstanced
;
1464 vfmt
->DrawTransformFeedbackStreamInstanced
=
1465 _save_DrawTransformFeedbackStreamInstanced
;
1470 vbo_save_SaveFlushVertices(struct gl_context
*ctx
)
1472 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1474 /* Noop when we are actually active:
1476 if (ctx
->Driver
.CurrentSavePrimitive
== PRIM_INSIDE_UNKNOWN_PRIM
||
1477 ctx
->Driver
.CurrentSavePrimitive
<= GL_POLYGON
)
1480 if (save
->vert_count
|| save
->prim_count
)
1481 _save_compile_vertex_list(ctx
);
1483 _save_copy_to_current(ctx
);
1484 _save_reset_vertex(ctx
);
1485 _save_reset_counters(ctx
);
1486 ctx
->Driver
.SaveNeedFlush
= 0;
1491 vbo_save_NewList(struct gl_context
*ctx
, GLuint list
, GLenum mode
)
1493 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1498 if (!save
->prim_store
)
1499 save
->prim_store
= alloc_prim_store(ctx
);
1501 if (!save
->vertex_store
)
1502 save
->vertex_store
= alloc_vertex_store(ctx
);
1504 save
->buffer_ptr
= vbo_save_map_vertex_store(ctx
, save
->vertex_store
);
1506 _save_reset_vertex(ctx
);
1507 _save_reset_counters(ctx
);
1508 ctx
->Driver
.SaveNeedFlush
= 0;
1513 vbo_save_EndList(struct gl_context
*ctx
)
1515 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1517 /* EndList called inside a (saved) Begin/End pair?
1519 if (ctx
->Driver
.CurrentSavePrimitive
!= PRIM_OUTSIDE_BEGIN_END
) {
1521 if (save
->prim_count
> 0) {
1522 GLint i
= save
->prim_count
- 1;
1523 ctx
->Driver
.CurrentSavePrimitive
= PRIM_OUTSIDE_BEGIN_END
;
1524 save
->prim
[i
].end
= 0;
1525 save
->prim
[i
].count
= (save
->vert_count
- save
->prim
[i
].start
);
1528 /* Make sure this vertex list gets replayed by the "loopback"
1531 save
->dangling_attr_ref
= 1;
1532 vbo_save_SaveFlushVertices(ctx
);
1534 /* Swap out this vertex format while outside begin/end. Any color,
1535 * etc. received between here and the next begin will be compiled
1538 _mesa_install_save_vtxfmt(ctx
, &ctx
->ListState
.ListVtxfmt
);
1541 vbo_save_unmap_vertex_store(ctx
, save
->vertex_store
);
1543 assert(save
->vertex_size
== 0);
1548 vbo_save_BeginCallList(struct gl_context
*ctx
, struct gl_display_list
*dlist
)
1550 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1551 save
->replay_flags
|= dlist
->Flags
;
1556 vbo_save_EndCallList(struct gl_context
*ctx
)
1558 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1560 if (ctx
->ListState
.CallDepth
== 1) {
1561 /* This is correct: want to keep only the VBO_SAVE_FALLBACK
1562 * flag, if it is set:
1564 save
->replay_flags
&= VBO_SAVE_FALLBACK
;
1570 vbo_destroy_vertex_list(struct gl_context
*ctx
, void *data
)
1572 struct vbo_save_vertex_list
*node
= (struct vbo_save_vertex_list
*) data
;
1575 if (--node
->vertex_store
->refcount
== 0)
1576 free_vertex_store(ctx
, node
->vertex_store
);
1578 if (--node
->prim_store
->refcount
== 0)
1579 free(node
->prim_store
);
1581 free(node
->current_data
);
1582 node
->current_data
= NULL
;
1587 vbo_print_vertex_list(struct gl_context
*ctx
, void *data
)
1589 struct vbo_save_vertex_list
*node
= (struct vbo_save_vertex_list
*) data
;
1593 printf("VBO-VERTEX-LIST, %u vertices %d primitives, %d vertsize\n",
1594 node
->count
, node
->prim_count
, node
->vertex_size
);
1596 for (i
= 0; i
< node
->prim_count
; i
++) {
1597 struct _mesa_prim
*prim
= &node
->prim
[i
];
1598 _mesa_debug(NULL
, " prim %d: %s%s %d..%d %s %s\n",
1600 _mesa_lookup_prim_by_nr(prim
->mode
),
1601 prim
->weak
? " (weak)" : "",
1603 prim
->start
+ prim
->count
,
1604 (prim
->begin
) ? "BEGIN" : "(wrap)",
1605 (prim
->end
) ? "END" : "(wrap)");
1611 * Called during context creation/init.
1614 _save_current_init(struct gl_context
*ctx
)
1616 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
1619 for (i
= VBO_ATTRIB_POS
; i
<= VBO_ATTRIB_GENERIC15
; i
++) {
1620 const GLuint j
= i
- VBO_ATTRIB_POS
;
1621 ASSERT(j
< VERT_ATTRIB_MAX
);
1622 save
->currentsz
[i
] = &ctx
->ListState
.ActiveAttribSize
[j
];
1623 save
->current
[i
] = ctx
->ListState
.CurrentAttrib
[j
];
1626 for (i
= VBO_ATTRIB_FIRST_MATERIAL
; i
<= VBO_ATTRIB_LAST_MATERIAL
; i
++) {
1627 const GLuint j
= i
- VBO_ATTRIB_FIRST_MATERIAL
;
1628 ASSERT(j
< MAT_ATTRIB_MAX
);
1629 save
->currentsz
[i
] = &ctx
->ListState
.ActiveMaterialSize
[j
];
1630 save
->current
[i
] = ctx
->ListState
.CurrentMaterial
[j
];
1636 * Initialize the display list compiler. Called during context creation.
1639 vbo_save_api_init(struct vbo_save_context
*save
)
1641 struct gl_context
*ctx
= save
->ctx
;
1644 save
->opcode_vertex_list
=
1645 _mesa_dlist_alloc_opcode(ctx
,
1646 sizeof(struct vbo_save_vertex_list
),
1647 vbo_save_playback_vertex_list
,
1648 vbo_destroy_vertex_list
,
1649 vbo_print_vertex_list
);
1651 ctx
->Driver
.NotifySaveBegin
= vbo_save_NotifyBegin
;
1653 _save_vtxfmt_init(ctx
);
1654 _save_current_init(ctx
);
1655 _mesa_noop_vtxfmt_init(&save
->vtxfmt_noop
);
1657 /* These will actually get set again when binding/drawing */
1658 for (i
= 0; i
< VBO_ATTRIB_MAX
; i
++)
1659 save
->inputs
[i
] = &save
->arrays
[i
];
1661 /* Hook our array functions into the outside-begin-end vtxfmt in
1664 ctx
->ListState
.ListVtxfmt
.Rectf
= _save_OBE_Rectf
;
1665 ctx
->ListState
.ListVtxfmt
.DrawArrays
= _save_OBE_DrawArrays
;
1666 ctx
->ListState
.ListVtxfmt
.DrawElements
= _save_OBE_DrawElements
;
1667 ctx
->ListState
.ListVtxfmt
.DrawRangeElements
= _save_OBE_DrawRangeElements
;
1668 ctx
->ListState
.ListVtxfmt
.MultiDrawElementsEXT
= _save_OBE_MultiDrawElements
;
1669 ctx
->ListState
.ListVtxfmt
.MultiDrawElementsBaseVertex
= _save_OBE_MultiDrawElementsBaseVertex
;