sp_prim_vbuf.c File Reference

Include dependency graph for sp_prim_vbuf.c:

Go to the source code of this file.

Data Structures

struct  softpipe_vbuf_render
 Subclass of vbuf_render. More...

Defines

#define SP_MAX_VBUF_INDEXES   1024
 Post-transform vertex buffering.
#define SP_MAX_VBUF_SIZE   4096

Typedefs

typedef const float(* cptrf4 )[4]

Functions

static struct
softpipe_vbuf_render
softpipe_vbuf_render (struct vbuf_render *vbr)
 cast wrapper
static struct vertex_infosp_vbuf_get_vertex_info (struct vbuf_render *vbr)
static void * sp_vbuf_allocate_vertices (struct vbuf_render *vbr, ushort vertex_size, ushort nr_vertices)
static void sp_vbuf_release_vertices (struct vbuf_render *vbr, void *vertices, unsigned vertex_size, unsigned vertices_used)
static boolean sp_vbuf_set_primitive (struct vbuf_render *vbr, unsigned prim)
static cptrf4 get_vert (const void *vertex_buffer, int index, int stride)
static void sp_vbuf_draw (struct vbuf_render *vbr, const ushort *indices, uint nr)
static void sp_vbuf_draw_arrays (struct vbuf_render *vbr, uint start, uint nr)
 This function is hit when the draw module is working in pass-through mode.
static void sp_vbuf_destroy (struct vbuf_render *vbr)
void sp_init_vbuf (struct softpipe_context *sp)
 Initialize the post-transform vertex buffer information for the given context.


Define Documentation

#define SP_MAX_VBUF_INDEXES   1024

Post-transform vertex buffering.

This is an optional part of the softpipe rendering pipeline. Probably not desired in general, but useful for testing/debuggin. Enabled/Disabled with SP_VBUF env var.

Authors Brian Paul

Definition at line 49 of file sp_prim_vbuf.c.

#define SP_MAX_VBUF_SIZE   4096

Definition at line 50 of file sp_prim_vbuf.c.


Typedef Documentation

typedef const float(* cptrf4)[4]

Definition at line 52 of file sp_prim_vbuf.c.


Function Documentation

static cptrf4 get_vert ( const void *  vertex_buffer,
int  index,
int  stride 
) [static]

Definition at line 126 of file sp_prim_vbuf.c.

00129 {
00130    return (cptrf4)((char *)vertex_buffer + index * stride);
00131 }

static struct softpipe_vbuf_render* softpipe_vbuf_render ( struct vbuf_render vbr  )  [static, read]

cast wrapper

Definition at line 69 of file sp_prim_vbuf.c.

00070 {
00071    return (struct softpipe_vbuf_render *) vbr;
00072 }

void sp_init_vbuf ( struct softpipe_context sp  ) 

Initialize the post-transform vertex buffer information for the given context.

Definition at line 381 of file sp_prim_vbuf.c.

References vbuf_render::allocate_vertices, assert, softpipe_vbuf_render::base, CALLOC_STRUCT, vbuf_render::destroy, vbuf_render::draw, softpipe_context::draw, vbuf_render::draw_arrays, draw_set_rasterize_stage(), draw_set_render(), draw_vbuf_stage(), vbuf_render::get_vertex_info, vbuf_render::max_indices, vbuf_render::max_vertex_buffer_bytes, vbuf_render::release_vertices, vbuf_render::set_primitive, softpipe_vbuf_render::softpipe, SP_MAX_VBUF_INDEXES, SP_MAX_VBUF_SIZE, sp_vbuf_allocate_vertices(), sp_vbuf_destroy(), sp_vbuf_draw(), sp_vbuf_draw_arrays(), sp_vbuf_get_vertex_info(), sp_vbuf_release_vertices(), sp_vbuf_set_primitive(), softpipe_context::vbuf, and softpipe_context::vbuf_render.

static void* sp_vbuf_allocate_vertices ( struct vbuf_render vbr,
ushort  vertex_size,
ushort  nr_vertices 
) [static]

Definition at line 84 of file sp_prim_vbuf.c.

References align_malloc(), assert, softpipe_vbuf_render(), softpipe_vbuf_render::vertex_buffer, and softpipe_vbuf_render::vertex_size.

00086 {
00087    struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr);
00088    assert(!cvbr->vertex_buffer);
00089    cvbr->vertex_buffer = align_malloc(vertex_size * nr_vertices, 16);
00090    cvbr->vertex_size = vertex_size;
00091    return cvbr->vertex_buffer;
00092 }

static void sp_vbuf_destroy ( struct vbuf_render vbr  )  [static]

Definition at line 368 of file sp_prim_vbuf.c.

References FREE, softpipe_vbuf_render::softpipe, softpipe_vbuf_render(), and softpipe_context::vbuf_render.

00369 {
00370    struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr);
00371    cvbr->softpipe->vbuf_render = NULL;
00372    FREE(cvbr);
00373 }

static void sp_vbuf_draw ( struct vbuf_render vbr,
const ushort indices,
uint  nr 
) [static]

Definition at line 135 of file sp_prim_vbuf.c.

References assert, get_vert(), PIPE_PRIM_LINE_LOOP, PIPE_PRIM_LINE_STRIP, PIPE_PRIM_LINES, PIPE_PRIM_POINTS, PIPE_PRIM_POLYGON, PIPE_PRIM_QUAD_STRIP, PIPE_PRIM_QUADS, PIPE_PRIM_TRIANGLE_FAN, PIPE_PRIM_TRIANGLE_STRIP, PIPE_PRIM_TRIANGLES, softpipe_vbuf_render::prim, softpipe_context::setup, setup, setup_line(), setup_point(), setup_tri(), vertex_info::size, softpipe_vbuf_render::softpipe, softpipe_vbuf_render(), sp_draw_flush(), sp_draw_setup_context(), stride(), softpipe_vbuf_render::vertex_buffer, softpipe_context::vertex_buffer, and softpipe_context::vertex_info_vbuf.

00136 {
00137    struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr);
00138    struct softpipe_context *softpipe = cvbr->softpipe;
00139    unsigned stride = softpipe->vertex_info_vbuf.size * sizeof(float);
00140    unsigned i;
00141    const void *vertex_buffer = cvbr->vertex_buffer;
00142 
00143    /* XXX: break this dependency - make setup_context live under
00144     * softpipe, rename the old "setup" draw stage to something else.
00145     */
00146    struct draw_stage *setup = softpipe->setup;
00147    struct setup_context *setup_ctx = sp_draw_setup_context(softpipe->setup);
00148 
00149 
00150    switch (cvbr->prim) {
00151    case PIPE_PRIM_POINTS:
00152       for (i = 0; i < nr; i++) {
00153          setup_point( setup_ctx,
00154                       get_vert(vertex_buffer, indices[i-0], stride) );
00155       }
00156       break;
00157 
00158    case PIPE_PRIM_LINES:
00159       for (i = 1; i < nr; i += 2) {
00160          setup_line( setup_ctx,
00161                      get_vert(vertex_buffer, indices[i-1], stride),
00162                      get_vert(vertex_buffer, indices[i-0], stride) );
00163       }
00164       break;
00165 
00166    case PIPE_PRIM_LINE_STRIP:
00167       for (i = 1; i < nr; i ++) {
00168          setup_line( setup_ctx,
00169                      get_vert(vertex_buffer, indices[i-1], stride),
00170                      get_vert(vertex_buffer, indices[i-0], stride) );
00171       }
00172       break;
00173 
00174    case PIPE_PRIM_LINE_LOOP:
00175       for (i = 1; i < nr; i ++) {
00176          setup_line( setup_ctx,
00177                      get_vert(vertex_buffer, indices[i-1], stride),
00178                      get_vert(vertex_buffer, indices[i-0], stride) );
00179       }
00180       if (nr) {
00181          setup_line( setup_ctx,
00182                      get_vert(vertex_buffer, indices[nr-1], stride),
00183                      get_vert(vertex_buffer, indices[0], stride) );
00184       }
00185       break;
00186 
00187 
00188    case PIPE_PRIM_TRIANGLES:
00189       for (i = 2; i < nr; i += 3) {
00190          setup_tri( setup_ctx,
00191                     get_vert(vertex_buffer, indices[i-2], stride),
00192                     get_vert(vertex_buffer, indices[i-1], stride),
00193                     get_vert(vertex_buffer, indices[i-0], stride));
00194       }
00195       break;
00196 
00197    case PIPE_PRIM_TRIANGLE_STRIP:
00198       for (i = 2; i < nr; i += 1) {
00199          setup_tri( setup_ctx,
00200                     get_vert(vertex_buffer, indices[i+(i&1)-2], stride),
00201                     get_vert(vertex_buffer, indices[i-(i&1)-1], stride),
00202                     get_vert(vertex_buffer, indices[i-0], stride));
00203       }
00204       break;
00205 
00206    case PIPE_PRIM_TRIANGLE_FAN:
00207    case PIPE_PRIM_POLYGON:
00208       for (i = 2; i < nr; i += 1) {
00209          setup_tri( setup_ctx,
00210                     get_vert(vertex_buffer, indices[0], stride),
00211                     get_vert(vertex_buffer, indices[i-1], stride),
00212                     get_vert(vertex_buffer, indices[i-0], stride));
00213       }
00214       break;
00215    case PIPE_PRIM_QUADS:
00216       for (i = 3; i < nr; i += 4) {
00217          setup_tri( setup_ctx,
00218                     get_vert(vertex_buffer, indices[i-3], stride),
00219                     get_vert(vertex_buffer, indices[i-2], stride),
00220                     get_vert(vertex_buffer, indices[i-0], stride));
00221 
00222          setup_tri( setup_ctx,
00223                     get_vert(vertex_buffer, indices[i-2], stride),
00224                     get_vert(vertex_buffer, indices[i-1], stride),
00225                     get_vert(vertex_buffer, indices[i-0], stride));
00226       }
00227       break;
00228    case PIPE_PRIM_QUAD_STRIP:
00229       for (i = 3; i < nr; i += 2) {
00230          setup_tri( setup_ctx,
00231                     get_vert(vertex_buffer, indices[i-3], stride),
00232                     get_vert(vertex_buffer, indices[i-2], stride),
00233                     get_vert(vertex_buffer, indices[i-0], stride));
00234 
00235          setup_tri( setup_ctx,
00236                     get_vert(vertex_buffer, indices[i-1], stride),
00237                     get_vert(vertex_buffer, indices[i-3], stride),
00238                     get_vert(vertex_buffer, indices[i-0], stride));
00239       }
00240       break;
00241    default:
00242       assert(0);
00243    }
00244 
00245    /* XXX: why are we calling this???  If we had to call something, it
00246     * would be a function in sp_setup.c:
00247     */
00248    sp_draw_flush( setup );
00249 }

static void sp_vbuf_draw_arrays ( struct vbuf_render vbr,
uint  start,
uint  nr 
) [static]

This function is hit when the draw module is working in pass-through mode.

It's up to us to convert the vertex array into point/line/tri prims.

Definition at line 257 of file sp_prim_vbuf.c.

References assert, get_vert(), PIPE_PRIM_LINE_LOOP, PIPE_PRIM_LINE_STRIP, PIPE_PRIM_LINES, PIPE_PRIM_POINTS, PIPE_PRIM_POLYGON, PIPE_PRIM_QUAD_STRIP, PIPE_PRIM_QUADS, PIPE_PRIM_TRIANGLE_FAN, PIPE_PRIM_TRIANGLE_STRIP, PIPE_PRIM_TRIANGLES, softpipe_vbuf_render::prim, softpipe_context::setup, setup, setup_line(), setup_point(), setup_tri(), vertex_info::size, softpipe_vbuf_render::softpipe, softpipe_vbuf_render(), sp_draw_setup_context(), stride(), softpipe_vbuf_render::vertex_buffer, and softpipe_context::vertex_info_vbuf.

00258 {
00259    struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr);
00260    struct softpipe_context *softpipe = cvbr->softpipe;
00261    struct draw_stage *setup = softpipe->setup;
00262    const void *vertex_buffer = NULL;
00263    const unsigned stride = softpipe->vertex_info_vbuf.size * sizeof(float);
00264    unsigned i;
00265    struct setup_context *setup_ctx = sp_draw_setup_context(setup);
00266 
00267    vertex_buffer = (void *)get_vert(cvbr->vertex_buffer, start, stride);
00268 
00269    switch (cvbr->prim) {
00270    case PIPE_PRIM_POINTS:
00271       for (i = 0; i < nr; i++) {
00272          setup_point( setup_ctx,
00273                       get_vert(vertex_buffer, i-0, stride) );
00274       }
00275       break;
00276 
00277    case PIPE_PRIM_LINES:
00278       for (i = 1; i < nr; i += 2) {
00279          setup_line( setup_ctx,
00280                      get_vert(vertex_buffer, i-1, stride),
00281                      get_vert(vertex_buffer, i-0, stride) );
00282       }
00283       break;
00284 
00285    case PIPE_PRIM_LINE_STRIP:
00286       for (i = 1; i < nr; i ++) {
00287          setup_line( setup_ctx,
00288                      get_vert(vertex_buffer, i-1, stride),
00289                      get_vert(vertex_buffer, i-0, stride) );
00290       }
00291       break;
00292 
00293    case PIPE_PRIM_LINE_LOOP:
00294       for (i = 1; i < nr; i ++) {
00295          setup_line( setup_ctx,
00296                      get_vert(vertex_buffer, i-1, stride),
00297                      get_vert(vertex_buffer, i-0, stride) );
00298       }
00299       if (nr) {
00300          setup_line( setup_ctx,
00301                      get_vert(vertex_buffer, nr-1, stride),
00302                      get_vert(vertex_buffer, 0, stride) );
00303       }
00304       break;
00305 
00306 
00307    case PIPE_PRIM_TRIANGLES:
00308       for (i = 2; i < nr; i += 3) {
00309          setup_tri( setup_ctx,
00310                     get_vert(vertex_buffer, i-2, stride),
00311                     get_vert(vertex_buffer, i-1, stride),
00312                     get_vert(vertex_buffer, i-0, stride));
00313       }
00314       break;
00315 
00316    case PIPE_PRIM_TRIANGLE_STRIP:
00317       for (i = 2; i < nr; i += 1) {
00318          setup_tri( setup_ctx,
00319                     get_vert(vertex_buffer, i+(i&1)-2, stride),
00320                     get_vert(vertex_buffer, i-(i&1)-1, stride),
00321                     get_vert(vertex_buffer, i-0, stride));
00322       }
00323       break;
00324 
00325    case PIPE_PRIM_TRIANGLE_FAN:
00326    case PIPE_PRIM_POLYGON:
00327       for (i = 2; i < nr; i += 1) {
00328          setup_tri( setup_ctx,
00329                     get_vert(vertex_buffer, 0, stride),
00330                     get_vert(vertex_buffer, i-1, stride),
00331                     get_vert(vertex_buffer, i-0, stride));
00332       }
00333       break;
00334    case PIPE_PRIM_QUADS:
00335       for (i = 3; i < nr; i += 4) {
00336          setup_tri( setup_ctx,
00337                     get_vert(vertex_buffer, i-3, stride),
00338                     get_vert(vertex_buffer, i-2, stride),
00339                     get_vert(vertex_buffer, i-0, stride));
00340 
00341          setup_tri( setup_ctx,
00342                     get_vert(vertex_buffer, i-2, stride),
00343                     get_vert(vertex_buffer, i-1, stride),
00344                     get_vert(vertex_buffer, i-0, stride));
00345       }
00346       break;
00347    case PIPE_PRIM_QUAD_STRIP:
00348       for (i = 3; i < nr; i += 2) {
00349          setup_tri( setup_ctx,
00350                     get_vert(vertex_buffer, i-3, stride),
00351                     get_vert(vertex_buffer, i-2, stride),
00352                     get_vert(vertex_buffer, i-0, stride));
00353 
00354          setup_tri( setup_ctx,
00355                     get_vert(vertex_buffer, i-1, stride),
00356                     get_vert(vertex_buffer, i-3, stride),
00357                     get_vert(vertex_buffer, i-0, stride));
00358       }
00359       break;
00360    default:
00361       assert(0);
00362    }
00363 }

static struct vertex_info* sp_vbuf_get_vertex_info ( struct vbuf_render vbr  )  [static, read]

Definition at line 76 of file sp_prim_vbuf.c.

References softpipe_vbuf_render::softpipe, softpipe_get_vbuf_vertex_info(), and softpipe_vbuf_render().

00077 {
00078    struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr);
00079    return softpipe_get_vbuf_vertex_info(cvbr->softpipe);
00080 }

static void sp_vbuf_release_vertices ( struct vbuf_render vbr,
void *  vertices,
unsigned  vertex_size,
unsigned  vertices_used 
) [static]

Definition at line 96 of file sp_prim_vbuf.c.

References align_free(), assert, softpipe_vbuf_render(), and softpipe_vbuf_render::vertex_buffer.

00098 {
00099    struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr);
00100    align_free(vertices);
00101    assert(vertices == cvbr->vertex_buffer);
00102    cvbr->vertex_buffer = NULL;
00103 }

static boolean sp_vbuf_set_primitive ( struct vbuf_render vbr,
unsigned  prim 
) [static]

Definition at line 107 of file sp_prim_vbuf.c.

References softpipe_vbuf_render::prim, softpipe_context::setup, setup_prepare(), softpipe_vbuf_render::softpipe, softpipe_vbuf_render(), sp_draw_setup_context(), and TRUE.

00108 {
00109    struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr);
00110 
00111    /* XXX: break this dependency - make setup_context live under
00112     * softpipe, rename the old "setup" draw stage to something else.
00113     */
00114    struct setup_context *setup_ctx = sp_draw_setup_context(cvbr->softpipe->setup);
00115    
00116    setup_prepare( setup_ctx );
00117 
00118 
00119 
00120    cvbr->prim = prim;
00121    return TRUE;
00122 
00123 }


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