00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "main/imports.h"
00029 #include "main/image.h"
00030 #include "main/macros.h"
00031 #include "shader/prog_uniform.h"
00032
00033 #include "vbo/vbo.h"
00034
00035 #include "st_context.h"
00036 #include "st_atom.h"
00037 #include "st_cb_bufferobjects.h"
00038 #include "st_draw.h"
00039 #include "st_program.h"
00040
00041 #include "pipe/p_context.h"
00042 #include "pipe/p_defines.h"
00043 #include "pipe/p_inlines.h"
00044
00045 #include "draw/draw_private.h"
00046 #include "draw/draw_context.h"
00047
00048
00049 #if FEATURE_feedback || FEATURE_drawpix
00050
00055 static void
00056 set_feedback_vertex_format(GLcontext *ctx)
00057 {
00058 #if 0
00059 struct st_context *st = ctx->st;
00060 struct vertex_info vinfo;
00061 GLuint i;
00062
00063 memset(&vinfo, 0, sizeof(vinfo));
00064
00065 if (ctx->RenderMode == GL_SELECT) {
00066 assert(ctx->RenderMode == GL_SELECT);
00067 vinfo.num_attribs = 1;
00068 vinfo.format[0] = FORMAT_4F;
00069 vinfo.interp_mode[0] = INTERP_LINEAR;
00070 }
00071 else {
00072
00073
00074 vinfo.num_attribs = st->state.vs->cso->state.num_outputs;
00075 for (i = 0; i < vinfo.num_attribs; i++) {
00076 vinfo.format[i] = FORMAT_4F;
00077 vinfo.interp_mode[i] = INTERP_LINEAR;
00078 }
00079 }
00080
00081 draw_set_vertex_info(st->draw, &vinfo);
00082 #endif
00083 }
00084
00085
00093 void
00094 st_feedback_draw_vbo(GLcontext *ctx,
00095 const struct gl_client_array **arrays,
00096 const struct _mesa_prim *prims,
00097 GLuint nr_prims,
00098 const struct _mesa_index_buffer *ib,
00099 GLuint min_index,
00100 GLuint max_index)
00101 {
00102 struct st_context *st = ctx->st;
00103 struct pipe_context *pipe = st->pipe;
00104 struct draw_context *draw = st->draw;
00105 const struct st_vertex_program *vp;
00106 const struct pipe_shader_state *vs;
00107 struct pipe_buffer *index_buffer_handle = 0;
00108 struct pipe_vertex_buffer vbuffers[PIPE_MAX_SHADER_INPUTS];
00109 struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
00110 GLuint attr, i;
00111 ubyte *mapped_constants;
00112
00113 assert(draw);
00114
00115 st_validate_state(ctx->st);
00116
00117
00118 vp = ctx->st->vp;
00119 vs = &st->vp->state;
00120
00121 if (!st->vp->draw_shader) {
00122 st->vp->draw_shader = draw_create_vertex_shader(draw, vs);
00123 }
00124
00125
00126
00127
00128
00129
00130
00131 assert(draw);
00132 draw_set_viewport_state(draw, &st->state.viewport);
00133 draw_set_clip_state(draw, &st->state.clip);
00134 draw_set_rasterizer_state(draw, &st->state.rasterizer);
00135 draw_bind_vertex_shader(draw, st->vp->draw_shader);
00136 set_feedback_vertex_format(ctx);
00137
00138
00139
00140
00141 for (attr = 0; attr < vp->num_inputs; attr++) {
00142 const GLuint mesaAttr = vp->index_to_input[attr];
00143 struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj;
00144 void *map;
00145
00146 if (bufobj && bufobj->Name) {
00147
00148
00149
00150
00151 struct st_buffer_object *stobj = st_buffer_object(bufobj);
00152 assert(stobj->buffer);
00153
00154 vbuffers[attr].buffer = NULL;
00155 pipe_buffer_reference(pipe->screen, &vbuffers[attr].buffer, stobj->buffer);
00156 vbuffers[attr].buffer_offset = (unsigned) arrays[0]->Ptr;
00157 velements[attr].src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr;
00158 }
00159 else {
00160
00161 uint bytes = (arrays[mesaAttr]->Size
00162 * _mesa_sizeof_type(arrays[mesaAttr]->Type)
00163 * (max_index + 1));
00164
00165
00166 vbuffers[attr].buffer
00167 = pipe_user_buffer_create(pipe->screen, (void *) arrays[mesaAttr]->Ptr,
00168 bytes);
00169 vbuffers[attr].buffer_offset = 0;
00170 velements[attr].src_offset = 0;
00171 }
00172
00173
00174 vbuffers[attr].pitch = arrays[mesaAttr]->StrideB;
00175 vbuffers[attr].max_index = max_index;
00176 velements[attr].vertex_buffer_index = attr;
00177 velements[attr].nr_components = arrays[mesaAttr]->Size;
00178 velements[attr].src_format =
00179 st_pipe_vertex_format(arrays[mesaAttr]->Type,
00180 arrays[mesaAttr]->Size,
00181 arrays[mesaAttr]->Normalized);
00182 assert(velements[attr].src_format);
00183
00184
00185 #if 0
00186 draw_set_vertex_buffer(draw, attr, &vbuffer[attr]);
00187 #endif
00188
00189
00190 map = pipe_buffer_map(pipe->screen, vbuffers[attr].buffer,
00191 PIPE_BUFFER_USAGE_CPU_READ);
00192 draw_set_mapped_vertex_buffer(draw, attr, map);
00193 }
00194
00195 draw_set_vertex_buffers(draw, vp->num_inputs, vbuffers);
00196 draw_set_vertex_elements(draw, vp->num_inputs, velements);
00197
00198 if (ib) {
00199 unsigned indexSize;
00200 struct gl_buffer_object *bufobj = ib->obj;
00201 struct st_buffer_object *stobj = st_buffer_object(bufobj);
00202 void *map;
00203
00204 index_buffer_handle = stobj->buffer;
00205
00206 switch (ib->type) {
00207 case GL_UNSIGNED_INT:
00208 indexSize = 4;
00209 break;
00210 case GL_UNSIGNED_SHORT:
00211 indexSize = 2;
00212 break;
00213 default:
00214 assert(0);
00215 return;
00216 }
00217
00218 map = pipe_buffer_map(pipe->screen, index_buffer_handle,
00219 PIPE_BUFFER_USAGE_CPU_READ);
00220 draw_set_mapped_element_buffer(draw, indexSize, map);
00221 }
00222 else {
00223
00224 draw_set_mapped_element_buffer(draw, 0, NULL);
00225 }
00226
00227
00228
00229 mapped_constants = pipe_buffer_map(pipe->screen,
00230 st->state.constants[PIPE_SHADER_VERTEX].buffer,
00231 PIPE_BUFFER_USAGE_CPU_READ);
00232 draw_set_mapped_constant_buffer(st->draw, mapped_constants,
00233 st->state.constants[PIPE_SHADER_VERTEX].buffer->size);
00234
00235
00236
00237 for (i = 0; i < nr_prims; i++) {
00238 draw_arrays(draw, prims[i].mode, prims[i].start, prims[i].count);
00239 }
00240
00241
00242
00243 pipe_buffer_unmap(pipe->screen, st->state.constants[PIPE_SHADER_VERTEX].buffer);
00244
00245
00246
00247
00248 for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
00249 if (draw->pt.vertex_buffer[i].buffer) {
00250 pipe_buffer_unmap(pipe->screen, draw->pt.vertex_buffer[i].buffer);
00251 pipe_buffer_reference(pipe->screen, &draw->pt.vertex_buffer[i].buffer, NULL);
00252 draw_set_mapped_vertex_buffer(draw, i, NULL);
00253 }
00254 }
00255 if (ib) {
00256 pipe_buffer_unmap(pipe->screen, index_buffer_handle);
00257 draw_set_mapped_element_buffer(draw, 0, NULL);
00258 }
00259 }
00260
00261 #endif
00262