mesa/es: Remove omit list.
[mesa.git] / src / mesa / vbo / vbo_save_draw.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.2
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25 /* Author:
26 * Keith Whitwell <keith@tungstengraphics.com>
27 */
28
29 #include "main/glheader.h"
30 #include "main/bufferobj.h"
31 #include "main/context.h"
32 #include "main/imports.h"
33 #include "main/mtypes.h"
34 #include "main/macros.h"
35 #include "main/light.h"
36 #include "main/state.h"
37
38 #include "vbo_context.h"
39
40
41 #if FEATURE_dlist
42
43
44 /*
45 * After playback, copy everything but the position from the
46 * last vertex to the saved state
47 */
48 static void _playback_copy_to_current( GLcontext *ctx,
49 const struct vbo_save_vertex_list *node )
50 {
51 struct vbo_context *vbo = vbo_context(ctx);
52 GLfloat vertex[VBO_ATTRIB_MAX * 4];
53 GLfloat *data;
54 GLuint i, offset;
55
56 if (node->current_size == 0)
57 return;
58
59 if (node->current_data) {
60 data = node->current_data;
61 }
62 else {
63 data = vertex;
64
65 if (node->count)
66 offset = (node->buffer_offset +
67 (node->count-1) * node->vertex_size * sizeof(GLfloat));
68 else
69 offset = node->buffer_offset;
70
71 ctx->Driver.GetBufferSubData( ctx, 0, offset,
72 node->vertex_size * sizeof(GLfloat),
73 data, node->vertex_store->bufferobj );
74
75 data += node->attrsz[0]; /* skip vertex position */
76 }
77
78 for (i = VBO_ATTRIB_POS+1 ; i < VBO_ATTRIB_MAX ; i++) {
79 if (node->attrsz[i]) {
80 GLfloat *current = (GLfloat *)vbo->currval[i].Ptr;
81 GLfloat tmp[4];
82
83 COPY_CLEAN_4V(tmp,
84 node->attrsz[i],
85 data);
86
87 if (memcmp(current, tmp, 4 * sizeof(GLfloat)) != 0)
88 {
89 memcpy(current, tmp, 4 * sizeof(GLfloat));
90
91 vbo->currval[i].Size = node->attrsz[i];
92
93 if (i >= VBO_ATTRIB_FIRST_MATERIAL &&
94 i <= VBO_ATTRIB_LAST_MATERIAL)
95 ctx->NewState |= _NEW_LIGHT;
96
97 ctx->NewState |= _NEW_CURRENT_ATTRIB;
98 }
99
100 data += node->attrsz[i];
101 }
102 }
103
104 /* Colormaterial -- this kindof sucks.
105 */
106 if (ctx->Light.ColorMaterialEnabled) {
107 _mesa_update_color_material(ctx, ctx->Current.Attrib[VBO_ATTRIB_COLOR0]);
108 }
109
110 /* CurrentExecPrimitive
111 */
112 if (node->prim_count) {
113 const struct _mesa_prim *prim = &node->prim[node->prim_count - 1];
114 if (prim->end)
115 ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END;
116 else
117 ctx->Driver.CurrentExecPrimitive = prim->mode;
118 }
119 }
120
121
122
123 /* Treat the vertex storage as a VBO, define vertex arrays pointing
124 * into it:
125 */
126 static void vbo_bind_vertex_list( GLcontext *ctx,
127 const struct vbo_save_vertex_list *node )
128 {
129 struct vbo_context *vbo = vbo_context(ctx);
130 struct vbo_save_context *save = &vbo->save;
131 struct gl_client_array *arrays = save->arrays;
132 GLuint buffer_offset = node->buffer_offset;
133 const GLuint *map;
134 GLuint attr;
135 GLubyte node_attrsz[VBO_ATTRIB_MAX]; /* copy of node->attrsz[] */
136 GLbitfield varying_inputs = 0x0;
137
138 memcpy(node_attrsz, node->attrsz, sizeof(node->attrsz));
139
140 /* Install the default (ie Current) attributes first, then overlay
141 * all active ones.
142 */
143 switch (get_program_mode(ctx)) {
144 case VP_NONE:
145 for (attr = 0; attr < 16; attr++) {
146 save->inputs[attr] = &vbo->legacy_currval[attr];
147 }
148 for (attr = 0; attr < MAT_ATTRIB_MAX; attr++) {
149 save->inputs[attr + 16] = &vbo->mat_currval[attr];
150 }
151 map = vbo->map_vp_none;
152 break;
153 case VP_NV:
154 case VP_ARB:
155 /* The aliasing of attributes for NV vertex programs has already
156 * occurred. NV vertex programs cannot access material values,
157 * nor attributes greater than VERT_ATTRIB_TEX7.
158 */
159 for (attr = 0; attr < 16; attr++) {
160 save->inputs[attr] = &vbo->legacy_currval[attr];
161 save->inputs[attr + 16] = &vbo->generic_currval[attr];
162 }
163 map = vbo->map_vp_arb;
164
165 /* check if VERT_ATTRIB_POS is not read but VERT_BIT_GENERIC0 is read.
166 * In that case we effectively need to route the data from
167 * glVertexAttrib(0, val) calls to feed into the GENERIC0 input.
168 */
169 if ((ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_POS) == 0 &&
170 (ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_GENERIC0)) {
171 save->inputs[16] = save->inputs[0];
172 node_attrsz[16] = node_attrsz[0];
173 node_attrsz[0] = 0;
174 }
175 break;
176 default:
177 assert(0);
178 }
179
180 for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
181 GLuint src = map[attr];
182
183 if (node_attrsz[src]) {
184 /* override the default array set above */
185 save->inputs[attr] = &arrays[attr];
186
187 arrays[attr].Ptr = (const GLubyte *) NULL + buffer_offset;
188 arrays[attr].Size = node->attrsz[src];
189 arrays[attr].StrideB = node->vertex_size * sizeof(GLfloat);
190 arrays[attr].Stride = node->vertex_size * sizeof(GLfloat);
191 arrays[attr].Type = GL_FLOAT;
192 arrays[attr].Format = GL_RGBA;
193 arrays[attr].Enabled = 1;
194 _mesa_reference_buffer_object(ctx,
195 &arrays[attr].BufferObj,
196 node->vertex_store->bufferobj);
197 arrays[attr]._MaxElement = node->count; /* ??? */
198
199 assert(arrays[attr].BufferObj->Name);
200
201 buffer_offset += node->attrsz[src] * sizeof(GLfloat);
202 varying_inputs |= 1<<attr;
203 }
204 }
205
206 _mesa_set_varying_vp_inputs( ctx, varying_inputs );
207 }
208
209 static void vbo_save_loopback_vertex_list( GLcontext *ctx,
210 const struct vbo_save_vertex_list *list )
211 {
212 const char *buffer = ctx->Driver.MapBuffer(ctx,
213 GL_ARRAY_BUFFER_ARB,
214 GL_READ_ONLY, /* ? */
215 list->vertex_store->bufferobj);
216
217 vbo_loopback_vertex_list( ctx,
218 (const GLfloat *)(buffer + list->buffer_offset),
219 list->attrsz,
220 list->prim,
221 list->prim_count,
222 list->wrap_count,
223 list->vertex_size);
224
225 ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER_ARB,
226 list->vertex_store->bufferobj);
227 }
228
229
230 /**
231 * Execute the buffer and save copied verts.
232 */
233 void vbo_save_playback_vertex_list( GLcontext *ctx, void *data )
234 {
235 const struct vbo_save_vertex_list *node = (const struct vbo_save_vertex_list *) data;
236 struct vbo_save_context *save = &vbo_context(ctx)->save;
237
238 FLUSH_CURRENT(ctx, 0);
239
240 if (node->prim_count > 0 && node->count > 0) {
241
242 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END &&
243 node->prim[0].begin) {
244
245 /* Degenerate case: list is called inside begin/end pair and
246 * includes operations such as glBegin or glDrawArrays.
247 */
248 if (0)
249 printf("displaylist recursive begin");
250
251 vbo_save_loopback_vertex_list( ctx, node );
252 return;
253 }
254 else if (save->replay_flags) {
255 /* Various degnerate cases: translate into immediate mode
256 * calls rather than trying to execute in place.
257 */
258 vbo_save_loopback_vertex_list( ctx, node );
259 return;
260 }
261
262 if (ctx->NewState)
263 _mesa_update_state( ctx );
264
265 /* XXX also need to check if shader enabled, but invalid */
266 if ((ctx->VertexProgram.Enabled && !ctx->VertexProgram._Enabled) ||
267 (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled)) {
268 _mesa_error(ctx, GL_INVALID_OPERATION,
269 "glBegin (invalid vertex/fragment program)");
270 return;
271 }
272
273 vbo_bind_vertex_list( ctx, node );
274
275 /* Again...
276 */
277 if (ctx->NewState)
278 _mesa_update_state( ctx );
279
280 vbo_context(ctx)->draw_prims( ctx,
281 save->inputs,
282 node->prim,
283 node->prim_count,
284 NULL,
285 GL_TRUE,
286 0, /* Node is a VBO, so this is ok */
287 node->count - 1);
288 }
289
290 /* Copy to current?
291 */
292 _playback_copy_to_current( ctx, node );
293 }
294
295
296 #endif /* FEATURE_dlist */