summaryrefslogtreecommitdiff
path: root/src/gallium/drivers
diff options
context:
space:
mode:
authorJakob Bornecrantz <jakob@tungstengraphics.com>2008-05-28 12:42:42 +0200
committerJakob Bornecrantz <jakob@tungstengraphics.com>2008-05-28 12:42:42 +0200
commit938d9d596324e411fde5312f2bb65b444c502c37 (patch)
treef32087f7c61f0827980278a5dae2b32edf534b72 /src/gallium/drivers
parent5d90f97f48f8ba231d52bb1a4758dd37f81ec8d6 (diff)
parent7b85ea19de09d4e7e077ca147528e90e52683690 (diff)
Merge branch 'gallium-vertex-linear' into gallium-0.1
Conflicts: src/gallium/auxiliary/draw/draw_pt_varray.c
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r--src/gallium/drivers/softpipe/sp_context.c13
-rw-r--r--src/gallium/drivers/softpipe/sp_prim_setup.c15
-rw-r--r--src/gallium/drivers/softpipe/sp_prim_vbuf.c270
3 files changed, 170 insertions, 128 deletions
diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c
index 2af0db3714..531bd76963 100644
--- a/src/gallium/drivers/softpipe/sp_context.c
+++ b/src/gallium/drivers/softpipe/sp_context.c
@@ -88,7 +88,8 @@ static void softpipe_destroy( struct pipe_context *pipe )
struct pipe_winsys *ws = pipe->winsys;
uint i;
- draw_destroy( softpipe->draw );
+ if (softpipe->draw)
+ draw_destroy( softpipe->draw );
softpipe->quad.polygon_stipple->destroy( softpipe->quad.polygon_stipple );
softpipe->quad.earlyz->destroy( softpipe->quad.earlyz );
@@ -216,8 +217,12 @@ softpipe_create( struct pipe_screen *screen,
* Create drawing context and plug our rendering stage into it.
*/
softpipe->draw = draw_create();
- assert(softpipe->draw);
+ if (!softpipe->draw)
+ goto fail;
+
softpipe->setup = sp_draw_render_stage(softpipe);
+ if (!softpipe->setup)
+ goto fail;
if (GETENV( "SP_NO_RAST" ) != NULL)
softpipe->no_rast = TRUE;
@@ -241,4 +246,8 @@ softpipe_create( struct pipe_screen *screen,
sp_init_surface_functions(softpipe);
return &softpipe->pipe;
+
+ fail:
+ softpipe_destroy(&softpipe->pipe);
+ return NULL;
}
diff --git a/src/gallium/drivers/softpipe/sp_prim_setup.c b/src/gallium/drivers/softpipe/sp_prim_setup.c
index 1cf9ffa632..941ab62e00 100644
--- a/src/gallium/drivers/softpipe/sp_prim_setup.c
+++ b/src/gallium/drivers/softpipe/sp_prim_setup.c
@@ -64,16 +64,17 @@ static INLINE struct setup_stage *setup_stage( struct draw_stage *stage )
}
+typedef const float (*cptrf4)[4];
static void
do_tri(struct draw_stage *stage, struct prim_header *prim)
{
struct setup_stage *setup = setup_stage( stage );
-
+
setup_tri( setup->setup,
- prim->v[0]->data,
- prim->v[1]->data,
- prim->v[2]->data );
+ (cptrf4)prim->v[0]->data,
+ (cptrf4)prim->v[1]->data,
+ (cptrf4)prim->v[2]->data );
}
static void
@@ -82,8 +83,8 @@ do_line(struct draw_stage *stage, struct prim_header *prim)
struct setup_stage *setup = setup_stage( stage );
setup_line( setup->setup,
- prim->v[0]->data,
- prim->v[1]->data );
+ (cptrf4)prim->v[0]->data,
+ (cptrf4)prim->v[1]->data );
}
static void
@@ -92,7 +93,7 @@ do_point(struct draw_stage *stage, struct prim_header *prim)
struct setup_stage *setup = setup_stage( stage );
setup_point( setup->setup,
- prim->v[0]->data );
+ (cptrf4)prim->v[0]->data );
}
diff --git a/src/gallium/drivers/softpipe/sp_prim_vbuf.c b/src/gallium/drivers/softpipe/sp_prim_vbuf.c
index e063fe82ef..e9fae951e0 100644
--- a/src/gallium/drivers/softpipe/sp_prim_vbuf.c
+++ b/src/gallium/drivers/softpipe/sp_prim_vbuf.c
@@ -116,30 +116,28 @@ sp_vbuf_set_primitive(struct vbuf_render *vbr, unsigned prim)
- if (prim == PIPE_PRIM_TRIANGLES ||
- prim == PIPE_PRIM_LINES ||
- prim == PIPE_PRIM_POINTS) {
- cvbr->prim = prim;
- return TRUE;
- }
- else {
- return FALSE;
- }
+ cvbr->prim = prim;
+ return TRUE;
}
+static INLINE cptrf4 get_vert( const void *vertex_buffer,
+ int index,
+ int stride )
+{
+ return (cptrf4)((char *)vertex_buffer + index * stride);
+}
static void
-sp_vbuf_draw(struct vbuf_render *vbr, const ushort *indices, uint nr_indices)
+sp_vbuf_draw(struct vbuf_render *vbr, const ushort *indices, uint nr)
{
struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr);
struct softpipe_context *softpipe = cvbr->softpipe;
- unsigned vertex_size = softpipe->vertex_info_vbuf.size * sizeof(float);
- unsigned i, j;
- void *vertex_buffer = cvbr->vertex_buffer;
- cptrf4 v[3];
+ unsigned stride = softpipe->vertex_info_vbuf.size * sizeof(float);
+ unsigned i;
+ const void *vertex_buffer = cvbr->vertex_buffer;
/* XXX: break this dependency - make setup_context live under
* softpipe, rename the old "setup" draw stage to something else.
@@ -149,40 +147,98 @@ sp_vbuf_draw(struct vbuf_render *vbr, const ushort *indices, uint nr_indices)
switch (cvbr->prim) {
- case PIPE_PRIM_TRIANGLES:
- for (i = 0; i < nr_indices; i += 3) {
- for (j = 0; j < 3; j++)
- v[j] = (cptrf4)((char *)vertex_buffer +
- indices[i+j] * vertex_size);
-
- setup_tri( setup_ctx,
- v[0],
- v[1],
- v[2]);
+ case PIPE_PRIM_POINTS:
+ for (i = 0; i < nr; i++) {
+ setup_point( setup_ctx,
+ get_vert(vertex_buffer, indices[i-0], stride) );
}
break;
case PIPE_PRIM_LINES:
- for (i = 0; i < nr_indices; i += 2) {
- for (j = 0; j < 2; j++)
- v[j] = (cptrf4)((char *)vertex_buffer +
- indices[i+j] * vertex_size);
+ for (i = 1; i < nr; i += 2) {
+ setup_line( setup_ctx,
+ get_vert(vertex_buffer, indices[i-1], stride),
+ get_vert(vertex_buffer, indices[i-0], stride) );
+ }
+ break;
+ case PIPE_PRIM_LINE_STRIP:
+ for (i = 1; i < nr; i ++) {
setup_line( setup_ctx,
- v[0],
- v[1] );
+ get_vert(vertex_buffer, indices[i-1], stride),
+ get_vert(vertex_buffer, indices[i-0], stride) );
}
break;
- case PIPE_PRIM_POINTS:
- for (i = 0; i < nr_indices; i++) {
- v[0] = (cptrf4)((char *)vertex_buffer +
- indices[i] * vertex_size);
+ case PIPE_PRIM_LINE_LOOP:
+ for (i = 1; i < nr; i ++) {
+ setup_line( setup_ctx,
+ get_vert(vertex_buffer, indices[i-1], stride),
+ get_vert(vertex_buffer, indices[i-0], stride) );
+ }
+ if (nr) {
+ setup_line( setup_ctx,
+ get_vert(vertex_buffer, indices[nr-1], stride),
+ get_vert(vertex_buffer, indices[0], stride) );
+ }
+ break;
- setup_point( setup_ctx,
- v[0] );
+
+ case PIPE_PRIM_TRIANGLES:
+ for (i = 2; i < nr; i += 3) {
+ setup_tri( setup_ctx,
+ get_vert(vertex_buffer, indices[i-2], stride),
+ get_vert(vertex_buffer, indices[i-1], stride),
+ get_vert(vertex_buffer, indices[i-0], stride));
+ }
+ break;
+
+ case PIPE_PRIM_TRIANGLE_STRIP:
+ for (i = 2; i < nr; i += 1) {
+ setup_tri( setup_ctx,
+ get_vert(vertex_buffer, indices[i+(i&1)-2], stride),
+ get_vert(vertex_buffer, indices[i-(i&1)-1], stride),
+ get_vert(vertex_buffer, indices[i-0], stride));
+ }
+ break;
+
+ case PIPE_PRIM_TRIANGLE_FAN:
+ case PIPE_PRIM_POLYGON:
+ for (i = 2; i < nr; i += 1) {
+ setup_tri( setup_ctx,
+ get_vert(vertex_buffer, indices[0], stride),
+ get_vert(vertex_buffer, indices[i-1], stride),
+ get_vert(vertex_buffer, indices[i-0], stride));
}
break;
+ case PIPE_PRIM_QUADS:
+ for (i = 3; i < nr; i += 4) {
+ setup_tri( setup_ctx,
+ get_vert(vertex_buffer, indices[i-3], stride),
+ get_vert(vertex_buffer, indices[i-2], stride),
+ get_vert(vertex_buffer, indices[i-0], stride));
+
+ setup_tri( setup_ctx,
+ get_vert(vertex_buffer, indices[i-2], stride),
+ get_vert(vertex_buffer, indices[i-1], stride),
+ get_vert(vertex_buffer, indices[i-0], stride));
+ }
+ break;
+ case PIPE_PRIM_QUAD_STRIP:
+ for (i = 3; i < nr; i += 2) {
+ setup_tri( setup_ctx,
+ get_vert(vertex_buffer, indices[i-3], stride),
+ get_vert(vertex_buffer, indices[i-2], stride),
+ get_vert(vertex_buffer, indices[i-0], stride));
+
+ setup_tri( setup_ctx,
+ get_vert(vertex_buffer, indices[i-1], stride),
+ get_vert(vertex_buffer, indices[i-3], stride),
+ get_vert(vertex_buffer, indices[i-0], stride));
+ }
+ break;
+ default:
+ assert(0);
}
/* XXX: why are we calling this??? If we had to call something, it
@@ -202,131 +258,107 @@ sp_vbuf_draw_arrays(struct vbuf_render *vbr, uint start, uint nr)
struct softpipe_vbuf_render *cvbr = softpipe_vbuf_render(vbr);
struct softpipe_context *softpipe = cvbr->softpipe;
struct draw_stage *setup = softpipe->setup;
- const void *vertex_buffer = cvbr->vertex_buffer;
- const unsigned vertex_size = softpipe->vertex_info_vbuf.size * sizeof(float);
+ const void *vertex_buffer = NULL;
+ const unsigned stride = softpipe->vertex_info_vbuf.size * sizeof(float);
unsigned i;
struct setup_context *setup_ctx = sp_draw_setup_context(setup);
- cptrf4 v[3];
-#define VERTEX(I) \
- (cptrf4) ((char *) vertex_buffer + (I) * vertex_size)
+ vertex_buffer = (void *)get_vert(cvbr->vertex_buffer, start, stride);
switch (cvbr->prim) {
case PIPE_PRIM_POINTS:
for (i = 0; i < nr; i++) {
- v[0] = VERTEX(i);
- setup_point( setup_ctx, v[0] );
+ setup_point( setup_ctx,
+ get_vert(vertex_buffer, i-0, stride) );
}
break;
+
case PIPE_PRIM_LINES:
- assert(nr % 2 == 0);
- for (i = 0; i < nr; i += 2) {
- v[0] = VERTEX(i);
- v[1] = VERTEX(i + 1);
- setup_line( setup_ctx, v[0], v[1] );
+ for (i = 1; i < nr; i += 2) {
+ setup_line( setup_ctx,
+ get_vert(vertex_buffer, i-1, stride),
+ get_vert(vertex_buffer, i-0, stride) );
}
break;
+
case PIPE_PRIM_LINE_STRIP:
- for (i = 1; i < nr; i++) {
- v[0] = VERTEX(i - 1);
- v[1] = VERTEX(i);
- setup_line( setup_ctx, v[0], v[1] );
+ for (i = 1; i < nr; i ++) {
+ setup_line( setup_ctx,
+ get_vert(vertex_buffer, i-1, stride),
+ get_vert(vertex_buffer, i-0, stride) );
}
break;
+
+ case PIPE_PRIM_LINE_LOOP:
+ for (i = 1; i < nr; i ++) {
+ setup_line( setup_ctx,
+ get_vert(vertex_buffer, i-1, stride),
+ get_vert(vertex_buffer, i-0, stride) );
+ }
+ if (nr) {
+ setup_line( setup_ctx,
+ get_vert(vertex_buffer, nr-1, stride),
+ get_vert(vertex_buffer, 0, stride) );
+ }
+ break;
+
+
case PIPE_PRIM_TRIANGLES:
- assert(nr % 3 == 0);
- for (i = 0; i < nr; i += 3) {
- v[0] = VERTEX(i + 0);
- v[1] = VERTEX(i + 1);
- v[2] = VERTEX(i + 2);
+ for (i = 2; i < nr; i += 3) {
setup_tri( setup_ctx,
- v[0],
- v[1],
- v[2] );
+ get_vert(vertex_buffer, i-2, stride),
+ get_vert(vertex_buffer, i-1, stride),
+ get_vert(vertex_buffer, i-0, stride));
}
break;
+
case PIPE_PRIM_TRIANGLE_STRIP:
- assert(nr >= 3);
- for (i = 2; i < nr; i++) {
- v[0] = VERTEX(i - 2);
- v[1] = VERTEX(i - 1);
- v[2] = VERTEX(i);
+ for (i = 2; i < nr; i += 1) {
setup_tri( setup_ctx,
- v[0],
- v[1],
- v[2] );
+ get_vert(vertex_buffer, i+(i&1)-2, stride),
+ get_vert(vertex_buffer, i-(i&1)-1, stride),
+ get_vert(vertex_buffer, i-0, stride));
}
break;
+
case PIPE_PRIM_TRIANGLE_FAN:
- assert(nr >= 3);
- for (i = 2; i < nr; i++) {
- v[0] = VERTEX(0);
- v[1] = VERTEX(i - 1);
- v[2] = VERTEX(i);
+ case PIPE_PRIM_POLYGON:
+ for (i = 2; i < nr; i += 1) {
setup_tri( setup_ctx,
- v[0],
- v[1],
- v[2] );
+ get_vert(vertex_buffer, 0, stride),
+ get_vert(vertex_buffer, i-1, stride),
+ get_vert(vertex_buffer, i-0, stride));
}
break;
case PIPE_PRIM_QUADS:
- assert(nr % 4 == 0);
- for (i = 0; i < nr; i += 4) {
- v[0] = VERTEX(i + 0);
- v[1] = VERTEX(i + 1);
- v[2] = VERTEX(i + 2);
+ for (i = 3; i < nr; i += 4) {
setup_tri( setup_ctx,
- v[0],
- v[1],
- v[2] );
+ get_vert(vertex_buffer, i-3, stride),
+ get_vert(vertex_buffer, i-2, stride),
+ get_vert(vertex_buffer, i-0, stride));
- v[0] = VERTEX(i + 0);
- v[1] = VERTEX(i + 2);
- v[2] = VERTEX(i + 3);
setup_tri( setup_ctx,
- v[0],
- v[1],
- v[2] );
+ get_vert(vertex_buffer, i-2, stride),
+ get_vert(vertex_buffer, i-1, stride),
+ get_vert(vertex_buffer, i-0, stride));
}
break;
case PIPE_PRIM_QUAD_STRIP:
- assert(nr >= 4);
- for (i = 2; i < nr; i += 2) {
- v[0] = VERTEX(i - 2);
- v[1] = VERTEX(i);
- v[2] = VERTEX(i + 1);
+ for (i = 3; i < nr; i += 2) {
setup_tri( setup_ctx,
- v[0],
- v[1],
- v[2] );
+ get_vert(vertex_buffer, i-3, stride),
+ get_vert(vertex_buffer, i-2, stride),
+ get_vert(vertex_buffer, i-0, stride));
- v[0] = VERTEX(i - 2);
- v[1] = VERTEX(i + 1);
- v[2] = VERTEX(i - 1);
setup_tri( setup_ctx,
- v[0],
- v[1],
- v[2] );
- }
- break;
- case PIPE_PRIM_POLYGON:
- /* draw as tri fan */
- for (i = 2; i < nr; i++) {
- v[0] = VERTEX(0);
- v[1] = VERTEX(i - 1);
- v[2] = VERTEX(i);
- setup_tri( setup_ctx,
- v[0],
- v[1],
- v[2] );
+ get_vert(vertex_buffer, i-1, stride),
+ get_vert(vertex_buffer, i-3, stride),
+ get_vert(vertex_buffer, i-0, stride));
}
break;
default:
- /* XXX finish remaining prim types */
assert(0);
}
-
-#undef VERTEX
}