2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Keith Whitwell <keith@tungstengraphics.com>
35 * After playback, copy everything but the position from the
36 * last vertex to the saved state
39 _playback_copy_to_current(struct gl_context
*ctx
,
40 const struct vbo_save_vertex_list
*node
)
42 struct vbo_context
*vbo
= vbo_context(ctx
);
43 GLfloat vertex
[VBO_ATTRIB_MAX
* 4];
47 if (node
->current_size
== 0)
50 if (node
->current_data
) {
51 data
= node
->current_data
;
57 offset
= (node
->buffer_offset
+
58 (node
->count
-1) * node
->vertex_size
* sizeof(GLfloat
));
60 offset
= node
->buffer_offset
;
62 ctx
->Driver
.GetBufferSubData( ctx
, offset
,
63 node
->vertex_size
* sizeof(GLfloat
),
64 data
, node
->vertex_store
->bufferobj
);
66 data
+= node
->attrsz
[0]; /* skip vertex position */
69 for (i
= VBO_ATTRIB_POS
+1 ; i
< VBO_ATTRIB_MAX
; i
++) {
70 if (node
->attrsz
[i
]) {
71 GLfloat
*current
= (GLfloat
*)vbo
->currval
[i
].Ptr
;
78 if (memcmp(current
, tmp
, 4 * sizeof(GLfloat
)) != 0) {
79 memcpy(current
, tmp
, 4 * sizeof(GLfloat
));
81 vbo
->currval
[i
].Size
= node
->attrsz
[i
];
82 assert(vbo
->currval
[i
].Type
== GL_FLOAT
);
83 vbo
->currval
[i
]._ElementSize
= vbo
->currval
[i
].Size
* sizeof(GLfloat
);
85 if (i
>= VBO_ATTRIB_FIRST_MATERIAL
&&
86 i
<= VBO_ATTRIB_LAST_MATERIAL
)
87 ctx
->NewState
|= _NEW_LIGHT
;
89 ctx
->NewState
|= _NEW_CURRENT_ATTRIB
;
92 data
+= node
->attrsz
[i
];
96 /* Colormaterial -- this kindof sucks.
98 if (ctx
->Light
.ColorMaterialEnabled
) {
99 _mesa_update_color_material(ctx
, ctx
->Current
.Attrib
[VBO_ATTRIB_COLOR
]);
102 /* CurrentExecPrimitive
104 if (node
->prim_count
) {
105 const struct _mesa_prim
*prim
= &node
->prim
[node
->prim_count
- 1];
107 ctx
->Driver
.CurrentExecPrimitive
= PRIM_OUTSIDE_BEGIN_END
;
109 ctx
->Driver
.CurrentExecPrimitive
= prim
->mode
;
116 * Treat the vertex storage as a VBO, define vertex arrays pointing
119 static void vbo_bind_vertex_list(struct gl_context
*ctx
,
120 const struct vbo_save_vertex_list
*node
)
122 struct vbo_context
*vbo
= vbo_context(ctx
);
123 struct vbo_save_context
*save
= &vbo
->save
;
124 struct gl_client_array
*arrays
= save
->arrays
;
125 GLuint buffer_offset
= node
->buffer_offset
;
127 GLubyte node_attrsz
[VBO_ATTRIB_MAX
]; /* copy of node->attrsz[] */
128 GLbitfield64 varying_inputs
= 0x0;
130 memcpy(node_attrsz
, node
->attrsz
, sizeof(node
->attrsz
));
132 /* Install the default (ie Current) attributes first, then overlay
135 for (attr
= 0; attr
< VBO_ATTRIB_MAX
; attr
++) {
136 save
->inputs
[attr
] = &vbo
->currval
[attr
];
139 for (attr
= 0; attr
< VBO_ATTRIB_MAX
; attr
++) {
141 if (node_attrsz
[attr
]) {
142 /* override the default array set above */
143 save
->inputs
[attr
] = &arrays
[attr
];
145 arrays
[attr
].Ptr
= (const GLubyte
*) NULL
+ buffer_offset
;
146 arrays
[attr
].Size
= node_attrsz
[attr
];
147 arrays
[attr
].StrideB
= node
->vertex_size
* sizeof(GLfloat
);
148 arrays
[attr
].Stride
= node
->vertex_size
* sizeof(GLfloat
);
149 arrays
[attr
].Type
= GL_FLOAT
;
150 arrays
[attr
].Enabled
= 1;
151 arrays
[attr
]._ElementSize
= arrays
[attr
].Size
* sizeof(GLfloat
);
152 _mesa_reference_buffer_object(ctx
,
153 &arrays
[attr
].BufferObj
,
154 node
->vertex_store
->bufferobj
);
155 arrays
[attr
]._MaxElement
= node
->count
; /* ??? */
157 assert(arrays
[attr
].BufferObj
->Name
);
159 buffer_offset
+= node_attrsz
[attr
] * sizeof(GLfloat
);
160 varying_inputs
|= VERT_BIT(attr
);
161 ctx
->NewState
|= _NEW_ARRAY
;
168 vbo_save_loopback_vertex_list(struct gl_context
*ctx
,
169 const struct vbo_save_vertex_list
*list
)
172 ctx
->Driver
.MapBufferRange(ctx
, 0,
173 list
->vertex_store
->bufferobj
->Size
,
174 GL_MAP_READ_BIT
, /* ? */
175 list
->vertex_store
->bufferobj
);
177 vbo_loopback_vertex_list(ctx
,
178 (const GLfloat
*)(buffer
+ list
->buffer_offset
),
185 ctx
->Driver
.UnmapBuffer(ctx
, list
->vertex_store
->bufferobj
);
190 * Execute the buffer and save copied verts.
191 * This is called from the display list code when executing
195 vbo_save_playback_vertex_list(struct gl_context
*ctx
, void *data
)
197 const struct vbo_save_vertex_list
*node
=
198 (const struct vbo_save_vertex_list
*) data
;
199 struct vbo_save_context
*save
= &vbo_context(ctx
)->save
;
200 struct vbo_exec_context
*exec
= &vbo_context(ctx
)->exec
;
202 FLUSH_CURRENT(ctx
, 0);
204 if (node
->prim_count
> 0) {
206 if (ctx
->Driver
.CurrentExecPrimitive
!= PRIM_OUTSIDE_BEGIN_END
&&
207 node
->prim
[0].begin
) {
209 /* Degenerate case: list is called inside begin/end pair and
210 * includes operations such as glBegin or glDrawArrays.
213 printf("displaylist recursive begin");
215 vbo_save_loopback_vertex_list( ctx
, node
);
218 else if (save
->replay_flags
) {
219 /* Various degnerate cases: translate into immediate mode
220 * calls rather than trying to execute in place.
222 vbo_save_loopback_vertex_list( ctx
, node
);
227 _mesa_update_state( ctx
);
229 vbo_bind_vertex_list( ctx
, node
);
231 vbo_draw_method(exec
, DRAW_DISPLAY_LIST
);
236 _mesa_update_state( ctx
);
238 if (node
->count
> 0) {
239 vbo_context(ctx
)->draw_prims(ctx
,
245 0, /* Node is a VBO, so this is ok */
252 _playback_copy_to_current( ctx
, node
);
256 #endif /* FEATURE_dlist */