summaryrefslogtreecommitdiffstats
path: root/src/mesa/pipe
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-08-20 12:52:00 -0600
committerBrian <[email protected]>2007-08-20 12:52:00 -0600
commit1dd55a77c87bd4e057d689163efd070a2dfe3454 (patch)
tree5d4794d78c37a762133339c398d4ffb5f10eb4aa /src/mesa/pipe
parent730df7662f57a46dee892733afc9a55f37d2ab03 (diff)
implement draw_elements()
Diffstat (limited to 'src/mesa/pipe')
-rw-r--r--src/mesa/pipe/p_context.h5
-rw-r--r--src/mesa/pipe/softpipe/sp_context.c1
-rw-r--r--src/mesa/pipe/softpipe/sp_draw_arrays.c48
-rw-r--r--src/mesa/pipe/softpipe/sp_state.h5
4 files changed, 51 insertions, 8 deletions
diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h
index 320b4877c3e..a3664a3b80c 100644
--- a/src/mesa/pipe/p_context.h
+++ b/src/mesa/pipe/p_context.h
@@ -82,6 +82,11 @@ struct pipe_context {
void (*draw_arrays)( struct pipe_context *pipe,
unsigned mode, unsigned start, unsigned count);
+ void (*draw_elements)( struct pipe_context *pipe,
+ struct pipe_buffer_handle *indexBuffer,
+ unsigned indexSize,
+ unsigned mode, unsigned start, unsigned count);
+
/** Clear a surface to given value (no scissor; clear whole surface) */
void (*clear)(struct pipe_context *pipe, struct pipe_surface *ps,
unsigned clearValue);
diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c
index ea2f0ec04f9..e7694bbe867 100644
--- a/src/mesa/pipe/softpipe/sp_context.c
+++ b/src/mesa/pipe/softpipe/sp_context.c
@@ -288,6 +288,7 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys,
softpipe->pipe.draw_vb = softpipe_draw_vb;
softpipe->pipe.draw_vertices = softpipe_draw_vertices;
softpipe->pipe.draw_arrays = softpipe_draw_arrays;
+ softpipe->pipe.draw_elements = softpipe_draw_elements;
softpipe->pipe.clear = softpipe_clear;
softpipe->pipe.flush = softpipe_flush;
diff --git a/src/mesa/pipe/softpipe/sp_draw_arrays.c b/src/mesa/pipe/softpipe/sp_draw_arrays.c
index ce5d4e0cbc7..6213286f476 100644
--- a/src/mesa/pipe/softpipe/sp_draw_arrays.c
+++ b/src/mesa/pipe/softpipe/sp_draw_arrays.c
@@ -316,9 +316,32 @@ void
softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
unsigned start, unsigned count)
{
+ softpipe_draw_elements(pipe, NULL, 0, mode, start, count);
+}
+
+
+
+/**
+ * XXX should the element buffer be specified/bound with a separate function?
+ */
+void
+softpipe_draw_elements(struct pipe_context *pipe,
+ struct pipe_buffer_handle *indexBuffer,
+ unsigned indexSize,
+ unsigned mode, unsigned start, unsigned count)
+{
+
struct softpipe_context *sp = softpipe_context(pipe);
struct draw_context *draw = sp->draw;
unsigned length, first, incr, i;
+ void *mapped_indexes = NULL;
+
+ /* first, check that the primitive is not malformed */
+ draw_prim_info( mode, &first, &incr );
+ length = draw_trim( count, first, incr );
+ if (!length)
+ return;
+
if (sp->dirty)
softpipe_update_derived( sp );
@@ -336,6 +359,16 @@ softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
PIPE_BUFFER_FLAG_READ);
}
}
+ /* Map index buffer, if present */
+ if (indexBuffer) {
+ mapped_indexes = pipe->winsys->buffer_map(pipe->winsys,
+ indexBuffer,
+ PIPE_BUFFER_FLAG_READ);
+ draw_set_element_buffer(draw, indexSize, mapped_indexes);
+ }
+ else {
+ draw_set_element_buffer(draw, 0, NULL); /* no index/element buffer */
+ }
/* tell drawing pipeline we're beginning drawing */
draw->pipeline.first->begin( draw->pipeline.first );
@@ -345,14 +378,10 @@ softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
draw_invalidate_vcache( draw );
- draw_set_element_buffer(draw, 0, NULL); /* no index/element buffer */
+ draw_set_prim( draw, mode );
- draw_prim_info( mode, &first, &incr );
- length = draw_trim( count, first, incr );
- if (length) {
- draw_set_prim( draw, mode );
- draw_prim(draw, start, count);
- }
+ /* drawing done here: */
+ draw_prim(draw, start, count);
/* draw any left-over buffered prims */
draw_flush(draw);
@@ -361,13 +390,16 @@ softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
draw->pipeline.first->end( draw->pipeline.first );
/*
- * unmap vertex buffers
+ * unmap vertex/index buffers
*/
for (i = 0; i < PIPE_ATTRIB_MAX; i++) {
if (sp->vertex_buffer[i].buffer) {
pipe->winsys->buffer_unmap(pipe->winsys, sp->vertex_buffer[i].buffer);
}
}
+ if (indexBuffer) {
+ pipe->winsys->buffer_unmap(pipe->winsys, indexBuffer);
+ }
softpipe_unmap_surfaces(sp);
}
diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h
index f25a20a5e3f..49fef0ddce2 100644
--- a/src/mesa/pipe/softpipe/sp_state.h
+++ b/src/mesa/pipe/softpipe/sp_state.h
@@ -98,6 +98,11 @@ void softpipe_update_derived( struct softpipe_context *softpipe );
void softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
unsigned start, unsigned count);
+void softpipe_draw_elements(struct pipe_context *pipe,
+ struct pipe_buffer_handle *indexBuffer,
+ unsigned indexSize,
+ unsigned mode, unsigned start, unsigned count);
+
void
softpipe_map_surfaces(struct softpipe_context *sp);