Mesa (i965g-restart): mesa/st: avoid quadstrips if its easy to do so

Keith Whitwell keithw at kemper.freedesktop.org
Tue Dec 1 08:52:45 PST 2009


Module: Mesa
Branch: i965g-restart
Commit: 759c094bf8fd0f104b738490d7f0b85f40fc2779
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=759c094bf8fd0f104b738490d7f0b85f40fc2779

Author: Keith Whitwell <keithw at vmware.com>
Date:   Tue Dec  1 16:31:21 2009 +0000

mesa/st: avoid quadstrips if its easy to do so

Tristrips are easier for many drivers to handle.

---

 src/mesa/state_tracker/st_draw.c |   29 ++++++++++++++++++++++++++---
 1 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index ec9c859..47330d8 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -528,6 +528,20 @@ check_uniforms(GLcontext *ctx)
 }
 
 
+static unsigned translate_prim( GLcontext *ctx,
+                                unsigned prim )
+{
+   /* Avoid quadstrips if it's easy to do so:
+    */
+   if (prim == GL_QUAD_STRIP &&
+       ctx->Light.ShadeModel != GL_FLAT &&
+       ctx->Polygon.FrontMode == GL_FILL &&
+       ctx->Polygon.BackMode == GL_FILL)
+      prim = GL_TRIANGLE_STRIP;
+
+   return prim;
+}
+
 /**
  * This function gets plugged into the VBO module and is called when
  * we have something to render.
@@ -624,6 +638,7 @@ st_draw_vbo(GLcontext *ctx,
       struct gl_buffer_object *bufobj = ib->obj;
       struct pipe_buffer *indexBuf = NULL;
       unsigned indexSize, indexOffset, i;
+      unsigned prim;
 
       switch (ib->type) {
       case GL_UNSIGNED_INT:
@@ -666,10 +681,12 @@ st_draw_vbo(GLcontext *ctx,
                          prims[i].start + indexOffset, prims[i].count,
                          arrays[VERT_ATTRIB_EDGEFLAG]);
 
+         prim = translate_prim( ctx, prims[i].mode );
+
          pipe->draw_range_elements(pipe, indexBuf, indexSize,
                                    min_index,
                                    max_index,
-                                   prims[i].mode,
+                                   prim,
                                    prims[i].start + indexOffset, prims[i].count);
       }
       else {
@@ -677,9 +694,11 @@ st_draw_vbo(GLcontext *ctx,
             setup_edgeflags(ctx, prims[i].mode,
                             prims[i].start + indexOffset, prims[i].count,
                             arrays[VERT_ATTRIB_EDGEFLAG]);
+
+            prim = translate_prim( ctx, prims[i].mode );
             
             pipe->draw_elements(pipe, indexBuf, indexSize,
-                                prims[i].mode,
+                                prim,
                                 prims[i].start + indexOffset, prims[i].count);
          }
       }
@@ -689,12 +708,16 @@ st_draw_vbo(GLcontext *ctx,
    else {
       /* non-indexed */
       GLuint i;
+      GLuint prim;
+
       for (i = 0; i < nr_prims; i++) {
          setup_edgeflags(ctx, prims[i].mode,
                          prims[i].start, prims[i].count,
                          arrays[VERT_ATTRIB_EDGEFLAG]);
 
-         pipe->draw_arrays(pipe, prims[i].mode, prims[i].start, prims[i].count);
+         prim = translate_prim( ctx, prims[i].mode );
+
+         pipe->draw_arrays(pipe, prim, prims[i].start, prims[i].count);
       }
    }
 



More information about the mesa-commit mailing list