Merge branch 'mesa_7_6_branch'
[mesa.git] / src / gallium / drivers / softpipe / sp_draw_arrays.c
index 424bd568460bce9ca8551ef48aab001e512ee815..d4045816d03ed7a428d8ea6849d057ad84c3b956 100644 (file)
@@ -33,8 +33,9 @@
 
 #include "pipe/p_defines.h"
 #include "pipe/p_context.h"
-#include "pipe/p_winsys.h"
+#include "pipe/internal/p_winsys_screen.h"
 #include "pipe/p_inlines.h"
+#include "util/u_prim.h"
 
 #include "sp_context.h"
 #include "sp_state.h"
@@ -47,18 +48,25 @@ static void
 softpipe_map_constant_buffers(struct softpipe_context *sp)
 {
    struct pipe_winsys *ws = sp->pipe.winsys;
-   uint i;
+   uint i, size;
+
    for (i = 0; i < PIPE_SHADER_TYPES; i++) {
-      if (sp->constants[i].size)
+      if (sp->constants[i].buffer && sp->constants[i].buffer->size)
          sp->mapped_constants[i] = ws->buffer_map(ws, sp->constants[i].buffer,
                                                   PIPE_BUFFER_USAGE_CPU_READ);
    }
 
+   if (sp->constants[PIPE_SHADER_VERTEX].buffer)
+      size = sp->constants[PIPE_SHADER_VERTEX].buffer->size;
+   else
+      size = 0;
+
    draw_set_mapped_constant_buffer(sp->draw,
                                    sp->mapped_constants[PIPE_SHADER_VERTEX],
-                                   sp->constants[PIPE_SHADER_VERTEX].size);
+                                   size);
 }
 
+
 static void
 softpipe_unmap_constant_buffers(struct softpipe_context *sp)
 {
@@ -73,27 +81,13 @@ softpipe_unmap_constant_buffers(struct softpipe_context *sp)
    draw_set_mapped_constant_buffer(sp->draw, NULL, 0);
 
    for (i = 0; i < 2; i++) {
-      if (sp->constants[i].size)
+      if (sp->constants[i].buffer && sp->constants[i].buffer->size)
          ws->buffer_unmap(ws, sp->constants[i].buffer);
       sp->mapped_constants[i] = NULL;
    }
 }
 
 
-static unsigned reduced_prim[PIPE_PRIM_POLYGON + 1] = {
-   PIPE_PRIM_POINTS,
-   PIPE_PRIM_LINES,
-   PIPE_PRIM_LINES,
-   PIPE_PRIM_LINES,
-   PIPE_PRIM_TRIANGLES,
-   PIPE_PRIM_TRIANGLES,
-   PIPE_PRIM_TRIANGLES,
-   PIPE_PRIM_TRIANGLES,
-   PIPE_PRIM_TRIANGLES,
-   PIPE_PRIM_TRIANGLES
-};
-
-
 boolean
 softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
                      unsigned start, unsigned count)
@@ -102,15 +96,11 @@ softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
 }
 
 
-
 /**
  * Draw vertex arrays, with optional indexing.
  * Basically, map the vertex buffers (and drawing surfaces), then hand off
  * the drawing to the 'draw' module.
- *
- * XXX should the element buffer be specified/bound with a separate function?
  */
-
 boolean
 softpipe_draw_range_elements(struct pipe_context *pipe,
                              struct pipe_buffer *indexBuffer,
@@ -123,12 +113,12 @@ softpipe_draw_range_elements(struct pipe_context *pipe,
    struct draw_context *draw = sp->draw;
    unsigned i;
 
-   sp->reduced_api_prim = reduced_prim[mode];
+   sp->reduced_api_prim = u_reduced_prim(mode);
 
    if (sp->dirty)
       softpipe_update_derived( sp );
 
-   softpipe_map_surfaces(sp);
+   softpipe_map_transfers(sp);
    softpipe_map_constant_buffers(sp);
 
    /*
@@ -141,6 +131,7 @@ softpipe_draw_range_elements(struct pipe_context *pipe,
                                     PIPE_BUFFER_USAGE_CPU_READ);
       draw_set_mapped_vertex_buffer(draw, i, buf);
    }
+
    /* Map index buffer, if present */
    if (indexBuffer) {
       void *mapped_indexes
@@ -153,10 +144,10 @@ softpipe_draw_range_elements(struct pipe_context *pipe,
    }
    else {
       /* no index/element buffer */
-      draw_set_mapped_element_buffer_range(draw, 0, start, start + count - 1, NULL);
+      draw_set_mapped_element_buffer_range(draw, 0, start,
+                                           start + count - 1, NULL);
    }
 
-
    /* draw! */
    draw_arrays(draw, mode, start, count);
 
@@ -176,9 +167,12 @@ softpipe_draw_range_elements(struct pipe_context *pipe,
    /* Note: leave drawing surfaces mapped */
    softpipe_unmap_constant_buffers(sp);
 
+   sp->dirty_render_cache = TRUE;
+   
    return TRUE;
 }
 
+
 boolean
 softpipe_draw_elements(struct pipe_context *pipe,
                        struct pipe_buffer *indexBuffer,
@@ -192,11 +186,9 @@ softpipe_draw_elements(struct pipe_context *pipe,
 }
 
 
-
 void
 softpipe_set_edgeflags(struct pipe_context *pipe, const unsigned *edgeflags)
 {
    struct softpipe_context *sp = softpipe_context(pipe);
    draw_set_edgeflags(sp->draw, edgeflags);
 }
-