Minor r200 vertex program cleanups. Remove disabled leftovers from r300 vertex progra...
[mesa.git] / src / mesa / drivers / dri / i965 / brw_save_draw.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.1
4 *
5 * Copyright (C) 1999-2004 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 "glheader.h"
30 #include "context.h"
31 #include "imports.h"
32 #include "mtypes.h"
33 #include "macros.h"
34 #include "light.h"
35 #include "state.h"
36
37 #include "brw_save.h"
38 #include "brw_draw.h"
39 #include "brw_fallback.h"
40
41
42 static void _playback_copy_to_current( GLcontext *ctx,
43 const struct brw_save_vertex_list *node )
44 {
45 struct brw_save_context *save = IMM_CONTEXT(ctx)->save;
46 GLfloat vertex[BRW_ATTRIB_MAX * 4], *data = vertex;
47 GLuint i, offset;
48
49 if (node->count)
50 offset = node->buffer_offset + (node->count-1) * node->vertex_size;
51 else
52 offset = node->buffer_offset;
53
54 ctx->Driver.GetBufferSubData( ctx, 0, offset, node->vertex_size,
55 data, node->vertex_store->bufferobj );
56
57 for (i = BRW_ATTRIB_POS+1 ; i <= BRW_ATTRIB_INDEX ; i++) {
58 if (node->attrsz[i]) {
59 COPY_CLEAN_4V(save->current[i], node->attrsz[i], data);
60 data += node->attrsz[i];
61
62 if (i >= BRW_ATTRIB_MAT_FRONT_AMBIENT &&
63 i <= BRW_ATTRIB_MAT_BACK_INDEXES)
64 ctx->NewState |= _NEW_LIGHT;
65 }
66 }
67
68 /* Edgeflag requires special treatment:
69 */
70 if (node->attrsz[BRW_ATTRIB_EDGEFLAG]) {
71 ctx->Current.EdgeFlag = (data[0] == 1.0);
72 }
73
74
75 #if 1
76 /* Colormaterial -- this kindof sucks.
77 */
78 if (ctx->Light.ColorMaterialEnabled) {
79 _mesa_update_color_material(ctx, ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
80 }
81 #endif
82
83 /* CurrentExecPrimitive
84 */
85 if (node->prim_count) {
86 const struct brw_draw_prim *prim = &node->prim[node->prim_count - 1];
87 if (prim->end)
88 ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END;
89 else
90 ctx->Driver.CurrentExecPrimitive = prim->mode;
91 }
92 }
93
94
95
96 /* Treat the vertex storage as a VBO, define vertex arrays pointing
97 * into it:
98 */
99 static void brw_bind_vertex_list( struct brw_save_context *save,
100 const struct brw_save_vertex_list *node )
101 {
102 struct gl_client_array *arrays = save->arrays;
103 GLuint data = node->buffer_offset;
104 GLuint attr;
105
106 memset(arrays, 0, BRW_ATTRIB_MAX * sizeof(arrays[0]));
107
108 for (attr = 0; attr <= BRW_ATTRIB_INDEX; attr++) {
109 if (node->attrsz[attr]) {
110 arrays[attr].Ptr = (const GLubyte *)data;
111 arrays[attr].Size = node->attrsz[attr];
112 arrays[attr].StrideB = node->vertex_size * sizeof(GLfloat);
113 arrays[attr].Stride = node->vertex_size * sizeof(GLfloat);
114 arrays[attr].Type = GL_FLOAT;
115 arrays[attr].Enabled = 1;
116 arrays[attr].BufferObj = node->vertex_store->bufferobj;
117 arrays[attr]._MaxElement = node->count; /* ??? */
118
119 assert(arrays[attr].BufferObj->Name);
120
121 data += node->attrsz[attr] * sizeof(GLfloat);
122 }
123 }
124 }
125
126 static void brw_save_loopback_vertex_list( GLcontext *ctx,
127 const struct brw_save_vertex_list *list )
128 {
129 const char *buffer = ctx->Driver.MapBuffer(ctx,
130 GL_ARRAY_BUFFER_ARB,
131 GL_DYNAMIC_READ_ARB, /* ? */
132 list->vertex_store->bufferobj);
133
134 brw_loopback_vertex_list( ctx,
135 (const GLfloat *)(buffer + list->buffer_offset),
136 list->attrsz,
137 list->prim,
138 list->prim_count,
139 list->wrap_count,
140 list->vertex_size);
141
142 ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER_ARB,
143 list->vertex_store->bufferobj);
144 }
145
146
147 /**
148 * Execute the buffer and save copied verts.
149 */
150 void brw_save_playback_vertex_list( GLcontext *ctx, void *data )
151 {
152 const struct brw_save_vertex_list *node = (const struct brw_save_vertex_list *) data;
153 struct brw_save_context *save = IMM_CONTEXT(ctx)->save;
154
155 FLUSH_CURRENT(ctx, 0);
156
157 if (node->prim_count > 0 && node->count > 0) {
158
159 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END &&
160 node->prim[0].begin) {
161
162 /* Degenerate case: list is called inside begin/end pair and
163 * includes operations such as glBegin or glDrawArrays.
164 */
165 if (0)
166 _mesa_printf("displaylist recursive begin");
167
168 brw_save_loopback_vertex_list( ctx, node );
169 return;
170 }
171 else if (save->replay_flags) {
172 /* Various degnerate cases: translate into immediate mode
173 * calls rather than trying to execute in place.
174 */
175 brw_save_loopback_vertex_list( ctx, node );
176 return;
177 }
178
179 if (ctx->NewState)
180 _mesa_update_state( ctx );
181
182 if ((ctx->VertexProgram.Enabled && !ctx->VertexProgram._Enabled) ||
183 (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled)) {
184 _mesa_error(ctx, GL_INVALID_OPERATION,
185 "glBegin (invalid vertex/fragment program)");
186 return;
187 }
188
189 brw_bind_vertex_list( save, node );
190
191 if (!brw_draw_prims( save->ctx,
192 save->inputs,
193 node->prim,
194 node->prim_count,
195 NULL,
196 0, /* Node is a VBO, so this is ok */
197 node->count,
198 0 )) {
199 brw_fallback(ctx);
200 brw_save_loopback_vertex_list( ctx, node );
201 brw_unfallback(ctx);
202 return;
203 }
204 }
205
206 /* Copy to current?
207 */
208 _playback_copy_to_current( ctx, node );
209 }