gallium: Use unified pipe_context::draw_vbo.
authorChia-I Wu <olv@lunarg.com>
Thu, 15 Jul 2010 20:21:11 +0000 (04:21 +0800)
committerChia-I Wu <olv@lunarg.com>
Thu, 29 Jul 2010 05:45:31 +0000 (13:45 +0800)
Update u_draw_quad, st/vega, and st/mesa to use pipe_context::draw_vbo.

src/gallium/auxiliary/util/u_draw_quad.c
src/gallium/state_trackers/vega/polygon.c
src/mesa/state_tracker/st_draw.c

index b37b48b5aef4360e3b1b639b13cb25f4903ba63b..0b6dc5880f33fa39cae66f1cfb01348e9e55817b 100644 (file)
@@ -60,7 +60,7 @@ util_draw_vertex_buffer(struct pipe_context *pipe,
    /* note: vertex elements already set by caller */
 
    /* draw */
-   pipe->draw_arrays(pipe, prim_type, 0, num_verts);
+   util_draw_arrays(pipe, prim_type, 0, num_verts);
 }
 
 
index e9c8f03137396628efda862e8495f455964257ea..bc94170eb961a717f9f6bea69c238d791d4f9e05 100644 (file)
@@ -301,8 +301,7 @@ static void draw_polygon(struct vg_context *ctx,
    cso_set_vertex_elements(ctx->cso_context, 1, &velement);
 
    /* draw */
-   pipe->draw_arrays(pipe, PIPE_PRIM_TRIANGLE_FAN, 
-                     0, poly->num_verts);
+   util_draw_arrays(pipe, PIPE_PRIM_TRIANGLE_FAN, 0, (uint) poly->num_verts);
 }
 
 void polygon_fill(struct polygon *poly, struct vg_context *ctx)
index 5821da4889d3c9f9a8e21a3994a629aa94223a8c..5b0548927023633384bf81e886bc67026f972c97 100644 (file)
@@ -58,6 +58,7 @@
 #include "util/u_inlines.h"
 #include "util/u_format.h"
 #include "util/u_prim.h"
+#include "util/u_draw_quad.h"
 #include "draw/draw_context.h"
 #include "cso_cache/cso_context.h"
 
@@ -494,6 +495,49 @@ setup_non_interleaved_attribs(GLcontext *ctx,
 }
 
 
+static void
+setup_index_buffer(GLcontext *ctx,
+                   const struct _mesa_index_buffer *ib,
+                   struct pipe_index_buffer *ibuffer)
+{
+   struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st->pipe;
+
+   memset(ibuffer, 0, sizeof(*ibuffer));
+   if (ib) {
+      struct gl_buffer_object *bufobj = ib->obj;
+
+      switch (ib->type) {
+      case GL_UNSIGNED_INT:
+         ibuffer->index_size = 4;
+         break;
+      case GL_UNSIGNED_SHORT:
+         ibuffer->index_size = 2;
+         break;
+      case GL_UNSIGNED_BYTE:
+         ibuffer->index_size = 1;
+         break;
+      default:
+         assert(0);
+        return;
+      }
+
+      /* get/create the index buffer object */
+      if (bufobj && bufobj->Name) {
+         /* elements/indexes are in a real VBO */
+         struct st_buffer_object *stobj = st_buffer_object(bufobj);
+         pipe_resource_reference(&ibuffer->buffer, stobj->buffer);
+         ibuffer->offset = pointer_to_offset(ib->ptr);
+      }
+      else {
+         /* element/indicies are in user space memory */
+         ibuffer->buffer =
+            pipe_user_buffer_create(pipe->screen, (void *) ib->ptr,
+                                    ib->count * ibuffer->index_size,
+                                    PIPE_BIND_INDEX_BUFFER);
+      }
+   }
+}
 
 /**
  * Prior to drawing, check that any uniforms referenced by the
@@ -568,8 +612,11 @@ st_draw_vbo(GLcontext *ctx,
    GLuint attr;
    struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
    unsigned num_vbuffers, num_velements;
+   struct pipe_index_buffer ibuffer;
    GLboolean userSpace = GL_FALSE;
    GLboolean vertDataEdgeFlags;
+   struct pipe_draw_info info;
+   unsigned i;
 
    /* Mesa core state should have been validated already */
    assert(ctx->NewState == 0x0);
@@ -647,113 +694,35 @@ st_draw_vbo(GLcontext *ctx,
    if (num_vbuffers == 0 || num_velements == 0)
       return;
 
-   /* do actual drawing */
-   if (ib) {
-      /* indexed primitive */
-      struct gl_buffer_object *bufobj = ib->obj;
-      struct pipe_resource *indexBuf = NULL;
-      unsigned indexSize, indexOffset, i;
+   setup_index_buffer(ctx, ib, &ibuffer);
+   pipe->set_index_buffer(pipe, &ibuffer);
 
-      switch (ib->type) {
-      case GL_UNSIGNED_INT:
-         indexSize = 4;
-         break;
-      case GL_UNSIGNED_SHORT:
-         indexSize = 2;
-         break;
-      case GL_UNSIGNED_BYTE:
-         indexSize = 1;
-         break;
-      default:
-         assert(0);
-        return;
-      }
-
-      /* get/create the index buffer object */
-      if (bufobj && bufobj->Name) {
-         /* elements/indexes are in a real VBO */
-         struct st_buffer_object *stobj = st_buffer_object(bufobj);
-         pipe_resource_reference(&indexBuf, stobj->buffer);
-         indexOffset = pointer_to_offset(ib->ptr) / indexSize;
-      }
-      else {
-         /* element/indicies are in user space memory */
-         indexBuf = pipe_user_buffer_create(pipe->screen, (void *) ib->ptr,
-                                            ib->count * indexSize,
-                                           PIPE_BIND_INDEX_BUFFER);
-         indexOffset = 0;
+   util_draw_init_info(&info);
+   if (ib) {
+      info.indexed = TRUE;
+      if (min_index != ~0 && max_index != ~0) {
+         info.min_index = min_index;
+         info.max_index = max_index;
       }
+   }
 
-      /* draw */
-      if (pipe->draw_range_elements && min_index != ~0 && max_index != ~0) {
-         /* XXX: exercise temporary path to pass min/max directly
-          * through to driver & draw module.  These interfaces still
-          * need a bit of work...
-          */
-         for (i = 0; i < nr_prims; i++) {
-            unsigned vcount = prims[i].count;
-            unsigned prim = translate_prim(ctx, prims[i].mode);
-
-            if (u_trim_pipe_prim(prims[i].mode, &vcount)) {
-               pipe->draw_range_elements(pipe, indexBuf, indexSize,
-                                         prims[i].basevertex,
-                                         min_index, max_index, prim,
-                                         prims[i].start + indexOffset, vcount);
-            }
-         }
-      }
-      else {
-         for (i = 0; i < nr_prims; i++) {
-            unsigned vcount = prims[i].count;
-            unsigned prim = translate_prim(ctx, prims[i].mode);
-            
-            if (u_trim_pipe_prim(prims[i].mode, &vcount)) {
-               if (prims[i].num_instances == 1) {
-                  pipe->draw_elements(pipe, indexBuf,
-                                      indexSize,
-                                      prims[i].basevertex,
-                                      prim,
-                                      prims[i].start + indexOffset,
-                                      vcount);
-               }
-               else {
-                  pipe->draw_elements_instanced(pipe, indexBuf,
-                                                indexSize,
-                                                prims[i].basevertex,
-                                                prim,
-                                                prims[i].start + indexOffset,
-                                                vcount,
-                                                0, /* startInstance */
-                                                prims[i].num_instances);
-               }
-            }
-         }
+   /* do actual drawing */
+   for (i = 0; i < nr_prims; i++) {
+      info.mode = translate_prim( ctx, prims[i].mode );
+      info.start = prims[i].start;
+      info.count = prims[i].count;
+      info.instance_count = prims[i].num_instances;
+      info.index_bias = prims[i].basevertex;
+      if (!ib) {
+         info.min_index = info.start;
+         info.max_index = info.start + info.count - 1;
       }
 
-      pipe_resource_reference(&indexBuf, NULL);
+      if (u_trim_pipe_prim(info.mode, &info.count))
+         pipe->draw_vbo(pipe, &info);
    }
-   else {
-      /* non-indexed */
-      GLuint i;
-
-      for (i = 0; i < nr_prims; i++) {
-         unsigned vcount = prims[i].count;
-         unsigned prim = translate_prim(ctx, prims[i].mode);
 
-         if (u_trim_pipe_prim(prims[i].mode, &vcount)) {
-            if (prims[i].num_instances == 1) {
-               pipe->draw_arrays(pipe, prim, prims[i].start, vcount);
-            }
-            else {
-               pipe->draw_arrays_instanced(pipe, prim,
-                                           prims[i].start,
-                                           vcount,
-                                           0, /* startInstance */
-                                           prims[i].num_instances);
-            }
-         }
-      }
-   }
+   pipe_resource_reference(&ibuffer.buffer, NULL);
 
    /* unreference buffers (frees wrapped user-space buffer objects) */
    for (attr = 0; attr < num_vbuffers; attr++) {