draw_pt_emit.c File Reference

Include dependency graph for draw_pt_emit.c:

Go to the source code of this file.

Data Structures

struct  pt_emit

Functions

void draw_pt_emit_prepare (struct pt_emit *emit, unsigned prim, unsigned *max_vertices)
void draw_pt_emit (struct pt_emit *emit, const float(*vertex_data)[4], unsigned vertex_count, unsigned stride, const ushort *elts, unsigned count)
void draw_pt_emit_linear (struct pt_emit *emit, const float(*vertex_data)[4], unsigned vertex_count, unsigned stride, unsigned start, unsigned count)
struct pt_emitdraw_pt_emit_create (struct draw_context *draw)
void draw_pt_emit_destroy (struct pt_emit *emit)


Function Documentation

void draw_pt_emit ( struct pt_emit emit,
const float *  vertex_data[4],
unsigned  vertex_count,
unsigned  stride,
const ushort elts,
unsigned  count 
)

Definition at line 152 of file draw_pt_emit.c.

References vbuf_render::allocate_vertices, assert, vbuf_render::draw, pt_emit::draw, draw, draw_do_flush(), DRAW_FLUSH_BACKEND, translate::key, translate_key::output_stride, pipe_rasterizer_state::point_size, pt_emit::prim, draw_context::rasterizer, vbuf_render::release_vertices, draw_context::render, translate::set_buffer, vbuf_render::set_primitive, and pt_emit::translate.

00158 {
00159    struct draw_context *draw = emit->draw;
00160    struct translate *translate = emit->translate;
00161    struct vbuf_render *render = draw->render;
00162    void *hw_verts;
00163 
00164    /* XXX: need to flush to get prim_vbuf.c to release its allocation?? 
00165     */
00166    draw_do_flush( draw, DRAW_FLUSH_BACKEND );
00167 
00168    /* XXX: and work out some way to coordinate the render primitive
00169     * between vbuf.c and here...
00170     */
00171    if (!draw->render->set_primitive(draw->render, emit->prim)) {
00172       assert(0);
00173       return;
00174    }
00175 
00176    hw_verts = render->allocate_vertices(render,
00177                                         (ushort)translate->key.output_stride,
00178                                         (ushort)vertex_count);
00179    if (!hw_verts) {
00180       assert(0);
00181       return;
00182    }
00183 
00184    translate->set_buffer(translate, 
00185                          0, 
00186                          vertex_data,
00187                          stride );
00188 
00189    translate->set_buffer(translate, 
00190                          1, 
00191                          &draw->rasterizer->point_size,
00192                          0);
00193 
00194    translate->run( translate,
00195                    0, 
00196                    vertex_count,
00197                    hw_verts );
00198 
00199    render->draw(render,
00200                 elts,
00201                 count);
00202 
00203    render->release_vertices(render,
00204                             hw_verts,
00205                             translate->key.output_stride,
00206                             vertex_count);
00207 }

struct pt_emit* draw_pt_emit_create ( struct draw_context draw  )  [read]

Definition at line 276 of file draw_pt_emit.c.

References pt_emit::cache, CALLOC_STRUCT, pt_emit::draw, FREE, and translate_cache_create().

00277 {
00278    struct pt_emit *emit = CALLOC_STRUCT(pt_emit);
00279    if (!emit)
00280       return NULL;
00281 
00282    emit->draw = draw;
00283    emit->cache = translate_cache_create();
00284    if (!emit->cache) {
00285       FREE(emit);
00286       return NULL;
00287    }
00288 
00289    return emit;
00290 }

void draw_pt_emit_destroy ( struct pt_emit emit  ) 

Definition at line 292 of file draw_pt_emit.c.

References pt_emit::cache, FREE, and translate_cache_destroy().

00293 {
00294    if (emit->cache)
00295       translate_cache_destroy(emit->cache);
00296 
00297    FREE(emit);
00298 }

void draw_pt_emit_linear ( struct pt_emit emit,
const float *  vertex_data[4],
unsigned  vertex_count,
unsigned  stride,
unsigned  start,
unsigned  count 
)

Definition at line 210 of file draw_pt_emit.c.

References vbuf_render::allocate_vertices, assert, debug_printf(), pt_emit::draw, draw, vbuf_render::draw_arrays, draw_do_flush(), draw_dump_emitted_vertex(), DRAW_FLUSH_BACKEND, translate::key, translate_key::output_stride, pipe_rasterizer_state::point_size, pt_emit::prim, draw_context::rasterizer, vbuf_render::release_vertices, draw_context::render, translate::set_buffer, vbuf_render::set_primitive, pt_emit::translate, and pt_emit::vinfo.

00216 {
00217    struct draw_context *draw = emit->draw;
00218    struct translate *translate = emit->translate;
00219    struct vbuf_render *render = draw->render;
00220    void *hw_verts;
00221 
00222 #if 0
00223    debug_printf("Linear emit\n");
00224 #endif
00225    /* XXX: need to flush to get prim_vbuf.c to release its allocation?? 
00226     */
00227    draw_do_flush( draw, DRAW_FLUSH_BACKEND );
00228 
00229    /* XXX: and work out some way to coordinate the render primitive
00230     * between vbuf.c and here...
00231     */
00232    if (!draw->render->set_primitive(draw->render, emit->prim)) {
00233       assert(0);
00234       return;
00235    }
00236 
00237    hw_verts = render->allocate_vertices(render,
00238                                         (ushort)translate->key.output_stride,
00239                                         (ushort)count);
00240    if (!hw_verts) {
00241       assert(0);
00242       return;
00243    }
00244 
00245    translate->set_buffer(translate, 0,
00246                          vertex_data, stride);
00247 
00248    translate->set_buffer(translate, 1,
00249                          &draw->rasterizer->point_size,
00250                          0);
00251 
00252    translate->run(translate,
00253                   0,
00254                   vertex_count,
00255                   hw_verts);
00256 
00257    if (0) {
00258       unsigned i;
00259       for (i = 0; i < vertex_count; i++) {
00260          debug_printf("\n\n%s vertex %d:\n", __FUNCTION__, i);
00261          draw_dump_emitted_vertex( emit->vinfo, 
00262                                    (const uint8_t *)hw_verts + 
00263                                    translate->key.output_stride * i );
00264       }
00265    }
00266 
00267 
00268    render->draw_arrays(render, start, count);
00269 
00270    render->release_vertices(render,
00271                             hw_verts,
00272                             translate->key.output_stride,
00273                             vertex_count);
00274 }

void draw_pt_emit_prepare ( struct pt_emit emit,
unsigned  prim,
unsigned *  max_vertices 
)

Definition at line 48 of file draw_pt_emit.c.

References assert, vertex_info::attrib, pt_emit::cache, pt_emit::draw, draw, draw_do_flush(), DRAW_FLUSH_BACKEND, translate_key::element, vertex_info::emit, EMIT_1F, EMIT_1F_PSIZE, EMIT_2F, EMIT_3F, EMIT_4F, EMIT_4UB, vbuf_render::get_vertex_info, translate_element::input_buffer, translate_element::input_format, translate_element::input_offset, translate::key, vbuf_render::max_vertex_buffer_bytes, translate_key::nr_elements, vertex_info::num_attribs, translate_element::output_format, translate_element::output_offset, translate_key::output_stride, PIPE_FORMAT_B8G8R8A8_UNORM, PIPE_FORMAT_NONE, PIPE_FORMAT_R32_FLOAT, PIPE_FORMAT_R32G32_FLOAT, PIPE_FORMAT_R32G32B32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, pt_emit::prim, draw_context::render, vbuf_render::set_primitive, vertex_info::size, vertex_info::src_index, pt_emit::translate, translate_cache_find(), translate_key_compare(), translate_key_sanitize(), and pt_emit::vinfo.

00051 {
00052    struct draw_context *draw = emit->draw;
00053    const struct vertex_info *vinfo;
00054    unsigned dst_offset;
00055    struct translate_key hw_key;
00056    unsigned i;
00057    boolean ok;
00058    
00059    /* XXX: need to flush to get prim_vbuf.c to release its allocation?? 
00060     */
00061    draw_do_flush( draw, DRAW_FLUSH_BACKEND );
00062 
00063 
00064    /* XXX: may need to defensively reset this later on as clipping can
00065     * clobber this state in the render backend.
00066     */
00067    emit->prim = prim;
00068 
00069    ok = draw->render->set_primitive(draw->render, emit->prim);
00070    if (!ok) {
00071       assert(0);
00072       return;
00073    }
00074 
00075    /* Must do this after set_primitive() above:
00076     */
00077    emit->vinfo = vinfo = draw->render->get_vertex_info(draw->render);
00078 
00079 
00080    /* Translate from pipeline vertices to hw vertices.
00081     */
00082    dst_offset = 0;
00083    for (i = 0; i < vinfo->num_attribs; i++) {
00084       unsigned emit_sz = 0;
00085       unsigned src_buffer = 0;
00086       unsigned output_format;
00087       unsigned src_offset = (vinfo->attrib[i].src_index * 4 * sizeof(float) );
00088 
00089 
00090          
00091       switch (vinfo->attrib[i].emit) {
00092       case EMIT_4F:
00093          output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
00094          emit_sz = 4 * sizeof(float);
00095          break;
00096       case EMIT_3F:
00097          output_format = PIPE_FORMAT_R32G32B32_FLOAT;
00098          emit_sz = 3 * sizeof(float);
00099          break;
00100       case EMIT_2F:
00101          output_format = PIPE_FORMAT_R32G32_FLOAT;
00102          emit_sz = 2 * sizeof(float);
00103          break;
00104       case EMIT_1F:
00105          output_format = PIPE_FORMAT_R32_FLOAT;
00106          emit_sz = 1 * sizeof(float);
00107          break;
00108       case EMIT_1F_PSIZE:
00109          output_format = PIPE_FORMAT_R32_FLOAT;
00110          emit_sz = 1 * sizeof(float);
00111          src_buffer = 1;
00112          src_offset = 0;
00113          break;
00114       case EMIT_4UB:
00115          output_format = PIPE_FORMAT_B8G8R8A8_UNORM;
00116          emit_sz = 4 * sizeof(ubyte);
00117          break;
00118       default:
00119          assert(0);
00120          output_format = PIPE_FORMAT_NONE;
00121          emit_sz = 0;
00122          break;
00123       }
00124       
00125       hw_key.element[i].input_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
00126       hw_key.element[i].input_buffer = src_buffer;
00127       hw_key.element[i].input_offset = src_offset;
00128       hw_key.element[i].output_format = output_format;
00129       hw_key.element[i].output_offset = dst_offset;
00130 
00131       dst_offset += emit_sz;
00132    }
00133 
00134    hw_key.nr_elements = vinfo->num_attribs;
00135    hw_key.output_stride = vinfo->size * 4;
00136 
00137    if (!emit->translate ||
00138        translate_key_compare(&emit->translate->key, &hw_key) != 0)
00139    {
00140       translate_key_sanitize(&hw_key);
00141       emit->translate = translate_cache_find(emit->cache, &hw_key);
00142    }
00143 
00144    *max_vertices = (draw->render->max_vertex_buffer_bytes / 
00145                     (vinfo->size * 4));
00146 
00147    /* even number */
00148    *max_vertices = *max_vertices & ~1;
00149 }


Generated on Tue Sep 29 06:25:21 2009 for Gallium3D by  doxygen 1.5.4