OSDN Git Service

Use new draw_arrays() code.
authorBrian <brian.paul@tungstengraphics.com>
Mon, 20 Aug 2007 23:25:38 +0000 (17:25 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Mon, 20 Aug 2007 23:25:38 +0000 (17:25 -0600)
The i915 driver now uses the software-based vertex shader interpreter
and draws everything through pipe->draw_arrays().

src/mesa/pipe/i915simple/i915_context.c
src/mesa/pipe/i915simple/i915_context.h
src/mesa/pipe/i915simple/i915_state.c

index b34899a..fdb1a74 100644 (file)
@@ -148,18 +148,69 @@ static void i915_destroy( struct pipe_context *pipe )
 }
 
 
-static void i915_draw_arrays( struct pipe_context *pipe,
-                              unsigned mode, unsigned start, unsigned count)
+
+static void i915_draw_elements( struct pipe_context *pipe,
+                                struct pipe_buffer_handle *indexBuffer,
+                                unsigned indexSize,
+                                unsigned prim, unsigned start, unsigned count)
 {
    struct i915_context *i915 = i915_context( pipe );
+   struct draw_context *draw = i915->draw;
+   unsigned i;
 
    if (i915->dirty)
       i915_update_derived( i915 );
 
-   draw_arrays(i915->draw, mode, start, count);
+
+  /*
+    * Map vertex buffers
+    */
+   for (i = 0; i < PIPE_ATTRIB_MAX; i++) {
+      if (i915->vertex_buffer[i].buffer) {
+         void *buf
+            = pipe->winsys->buffer_map(pipe->winsys,
+                                       i915->vertex_buffer[i].buffer,
+                                       PIPE_BUFFER_FLAG_READ);
+         draw_set_mapped_vertex_buffer(draw, i, buf);
+      }
+   }
+   /* Map index buffer, if present */
+   if (indexBuffer) {
+      void *mapped_indexes
+         = pipe->winsys->buffer_map(pipe->winsys, indexBuffer,
+                                    PIPE_BUFFER_FLAG_READ);
+      draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
+   }
+   else {
+      /* no index/element buffer */
+      draw_set_mapped_element_buffer(draw, 0, NULL);
+   }
+
+   /* draw! */
+   draw_arrays(i915->draw, prim, start, count);
+
+   /*
+    * unmap vertex/index buffers
+    */
+   for (i = 0; i < PIPE_ATTRIB_MAX; i++) {
+      if (i915->vertex_buffer[i].buffer) {
+         pipe->winsys->buffer_unmap(pipe->winsys, i915->vertex_buffer[i].buffer);
+         draw_set_mapped_vertex_buffer(draw, i, NULL);
+      }
+   }
+   if (indexBuffer) {
+      pipe->winsys->buffer_unmap(pipe->winsys, indexBuffer);
+      draw_set_mapped_element_buffer(draw, 0, NULL);
+   }
 }
 
 
+static void i915_draw_arrays( struct pipe_context *pipe,
+                              unsigned prim, unsigned start, unsigned count)
+{
+   i915_draw_elements(pipe, NULL, 0, prim, start, count);
+}
+
 
 
 struct pipe_context *i915_create( struct pipe_winsys *pipe_winsys,
@@ -205,6 +256,7 @@ struct pipe_context *i915_create( struct pipe_winsys *pipe_winsys,
    i915->pipe.get_occlusion_counter = NULL;
 
    i915->pipe.draw_arrays = i915_draw_arrays;
+   i915->pipe.draw_elements = i915_draw_elements;
 
    /*
     * Create drawing context and plug our rendering stage into it.
index 1e48485..a3927bf 100644 (file)
@@ -113,6 +113,8 @@ struct i915_context
    struct pipe_stencil_state stencil;
    struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS];
    struct pipe_viewport_state viewport;
+   struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX];
+
    unsigned dirty;
 
    unsigned *batch_start;
index 06fa716..1de6fea 100644 (file)
@@ -121,6 +121,16 @@ static void i915_set_fs_state( struct pipe_context *pipe,
 }
 
 
+static void i915_set_vs_state( struct pipe_context *pipe,
+                               const struct pipe_shader_state *vs )
+{
+   struct i915_context *i915 = i915_context(pipe);
+
+   /* just pass-through to draw module */
+   draw_set_vertex_shader(i915->draw, vs);
+}
+
+
 static void i915_set_sampler_state(struct pipe_context *pipe,
                            unsigned unit,
                            const struct pipe_sampler_state *sampler)
@@ -216,6 +226,28 @@ static void i915_set_setup_state( struct pipe_context *pipe,
 }
 
 
+static void i915_set_vertex_buffer( struct pipe_context *pipe,
+                                    unsigned index,
+                                    const struct pipe_vertex_buffer *buffer )
+{
+   struct i915_context *i915 = i915_context(pipe);
+   i915->vertex_buffer[index] = *buffer;
+   /* pass-through to draw module */
+   draw_set_vertex_buffer(i915->draw, index, buffer);
+}
+   
+
+static void i915_set_vertex_element( struct pipe_context *pipe,
+                                     unsigned index,
+                                     const struct pipe_vertex_element *element)
+{
+   struct i915_context *i915 = i915_context(pipe);
+   /* pass-through to draw module */
+   draw_set_vertex_element(i915->draw, index, element);
+}
+
+
+
 void
 i915_init_state_functions( struct i915_context *i915 )
 {
@@ -227,6 +259,7 @@ i915_init_state_functions( struct i915_context *i915 )
    i915->pipe.set_depth_state = i915_set_depth_test_state;
    i915->pipe.set_framebuffer_state = i915_set_framebuffer_state;
    i915->pipe.set_fs_state = i915_set_fs_state;
+   i915->pipe.set_vs_state = i915_set_vs_state;
    i915->pipe.set_polygon_stipple = i915_set_polygon_stipple;
    i915->pipe.set_sampler_state = i915_set_sampler_state;
    i915->pipe.set_scissor_state = i915_set_scissor_state;
@@ -234,4 +267,6 @@ i915_init_state_functions( struct i915_context *i915 )
    i915->pipe.set_stencil_state = i915_set_stencil_state;
    i915->pipe.set_texture_state = i915_set_texture_state;
    i915->pipe.set_viewport_state = i915_set_viewport_state;
+   i915->pipe.set_vertex_buffer = i915_set_vertex_buffer;
+   i915->pipe.set_vertex_element = i915_set_vertex_element;
 }