minor optimizations for flat shading (Klaus Niederkrueger)
authorBrian Paul <brian.paul@tungstengraphics.com>
Thu, 13 Sep 2001 22:12:54 +0000 (22:12 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Thu, 13 Sep 2001 22:12:54 +0000 (22:12 +0000)
src/mesa/swrast/s_triangle.c
src/mesa/swrast/s_trispan.h
src/mesa/swrast/s_tritemp.h

index 1781c993d976dc7484696c9430739ccc198b22ea..c1aa1facf14e040559a4a7e356ede42b8cbfbc27 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: s_triangle.c,v 1.36 2001/07/26 15:57:49 brianp Exp $ */
+/* $Id: s_triangle.c,v 1.37 2001/09/13 22:12:54 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -1011,57 +1011,98 @@ rasterize_span(GLcontext *ctx, const struct triangle_span *span)
    CHECKARRAY(mLambda, return);
 
    if (span->activeMask & SPAN_RGBA) {
+      if (span->activeMask & SPAN_FLAT) {
+         GLuint i;
+         GLchan color[4];
+         color[RCOMP] = FixedToChan(span->red);
+         color[GCOMP] = FixedToChan(span->green);
+         color[BCOMP] = FixedToChan(span->blue);
+         color[ACOMP] = FixedToChan(span->alpha);
+         for (i = 0; i < span->count; i++) {
+            COPY_CHAN4(rgba[i], color);
+         }
+      }
+      else {
+         /* smooth interpolation */
 #if CHAN_TYPE == GL_FLOAT
-      GLfloat r = span->red;
-      GLfloat g = span->green;
-      GLfloat b = span->blue;
-      GLfloat a = span->alpha;
+         GLfloat r = span->red;
+         GLfloat g = span->green;
+         GLfloat b = span->blue;
+         GLfloat a = span->alpha;
 #else
-      GLfixed r = span->red;
-      GLfixed g = span->green;
-      GLfixed b = span->blue;
-      GLfixed a = span->alpha;
+         GLfixed r = span->red;
+         GLfixed g = span->green;
+         GLfixed b = span->blue;
+         GLfixed a = span->alpha;
 #endif
-      GLuint i;
-      for (i = 0; i < span->count; i++) {
-         rgba[i][RCOMP] = FixedToChan(r);
-         rgba[i][GCOMP] = FixedToChan(g);
-         rgba[i][BCOMP] = FixedToChan(b);
-         rgba[i][ACOMP] = FixedToChan(a);
-         r += span->redStep;
-         g += span->greenStep;
-         b += span->blueStep;
-         a += span->alphaStep;
+         GLuint i;
+         for (i = 0; i < span->count; i++) {
+            rgba[i][RCOMP] = FixedToChan(r);
+            rgba[i][GCOMP] = FixedToChan(g);
+            rgba[i][BCOMP] = FixedToChan(b);
+            rgba[i][ACOMP] = FixedToChan(a);
+            r += span->redStep;
+            g += span->greenStep;
+            b += span->blueStep;
+            a += span->alphaStep;
+         }
       }
    }
+
    if (span->activeMask & SPAN_SPEC) {
+      if (span->activeMask & SPAN_FLAT) {
+         const GLchan r = FixedToChan(span->specRed);
+         const GLchan g = FixedToChan(span->specGreen);
+         const GLchan b = FixedToChan(span->specBlue);
+         GLuint i;
+         for (i = 0; i < span->count; i++) {
+            spec[i][RCOMP] = r;
+            spec[i][GCOMP] = g;
+            spec[i][BCOMP] = b;
+         }
+      }
+      else {
+         /* smooth interpolation */
 #if CHAN_TYPE == GL_FLOAT
-      GLfloat r = span->specRed;
-      GLfloat g = span->specGreen;
-      GLfloat b = span->specBlue;
+         GLfloat r = span->specRed;
+         GLfloat g = span->specGreen;
+         GLfloat b = span->specBlue;
 #else
-      GLfixed r = span->specRed;
-      GLfixed g = span->specGreen;
-      GLfixed b = span->specBlue;
+         GLfixed r = span->specRed;
+         GLfixed g = span->specGreen;
+         GLfixed b = span->specBlue;
 #endif
-      GLuint i;
-      for (i = 0; i < span->count; i++) {
-         spec[i][RCOMP] = FixedToChan(r);
-         spec[i][GCOMP] = FixedToChan(g);
-         spec[i][BCOMP] = FixedToChan(b);
-         r += span->specRedStep;
-         g += span->specGreenStep;
-         b += span->specBlueStep;
+         GLuint i;
+         for (i = 0; i < span->count; i++) {
+            spec[i][RCOMP] = FixedToChan(r);
+            spec[i][GCOMP] = FixedToChan(g);
+            spec[i][BCOMP] = FixedToChan(b);
+            r += span->specRedStep;
+            g += span->specGreenStep;
+            b += span->specBlueStep;
+         }
       }
    }
+
    if (span->activeMask & SPAN_INDEX) {
-      GLuint i;
-      GLfixed ind = span->index;
-      for (i = 0; i < span->count; i++) {
-         index[i] = FixedToInt(ind);
-         ind += span->indexStep;
+      if (span->activeMask & SPAN_FLAT) {
+         GLuint i;
+         const GLint indx = FixedToInt(span->index);
+         for (i = 0; i < span->count; i++) {
+            index[i] = indx;
+         }
+      }
+      else {
+         /* smooth interpolation */
+         GLuint i;
+         GLfixed ind = span->index;
+         for (i = 0; i < span->count; i++) {
+            index[i] = FixedToInt(ind);
+            ind += span->indexStep;
+         }
       }
    }
+
    if (span->activeMask & SPAN_Z) {
       if (ctx->Visual.depthBits <= 16) {
          GLuint i;
index 2ac3c4d17a8258e6a2debfdaefa0e0a735684a2e..48f397e4c513c0e276760ceb917a138c1340f380 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: s_trispan.h,v 1.2 2001/07/14 17:53:04 brianp Exp $ */
+/* $Id: s_trispan.h,v 1.3 2001/09/13 22:12:54 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
  */
 
 
-#define SPAN_RGBA         0x01
-#define SPAN_SPEC         0x02
-#define SPAN_INDEX        0x04
-#define SPAN_Z            0x08
-#define SPAN_FOG          0x10
-#define SPAN_TEXTURE      0x20
-#define SPAN_INT_TEXTURE  0x40
-#define SPAN_LAMBDA       0x80
+/* When the triangle_span struct is initialized, these flags indicates
+ * which values are needed for rendering the triangle.
+ */
+#define SPAN_RGBA         0x001
+#define SPAN_SPEC         0x002
+#define SPAN_INDEX        0x004
+#define SPAN_Z            0x008
+#define SPAN_FOG          0x010
+#define SPAN_TEXTURE      0x020
+#define SPAN_INT_TEXTURE  0x040
+#define SPAN_LAMBDA       0x080
+#define SPAN_FLAT         0x100  /* flat shading? */
 
 
 struct triangle_span {
index 08a725cbd8ac045f8aa0bba338d258e6f9f6beb1..be69d7577d5d405919d52484bc27d03baee0bc4c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: s_tritemp.h,v 1.25 2001/09/13 21:54:29 brianp Exp $ */
+/* $Id: s_tritemp.h,v 1.26 2001/09/13 22:12:54 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
       }
       else {
          ASSERT (ctx->Light.ShadeModel == GL_FLAT);
+         span.activeMask |= SPAN_FLAT;
          drdx = drdy = 0.0F;
          dgdx = dgdy = 0.0F;
          dbdx = dbdy = 0.0F;
          dsbdx = dsbdy = span.specBlueStep = 0;
       }
 #endif
-
 #ifdef INTERP_INDEX
       span.activeMask |= SPAN_INDEX;
       if (ctx->Light.ShadeModel == GL_SMOOTH) {
          didy = oneOverArea * (eMaj.dx * eBot_di - eMaj_di * eBot.dx);
       }
       else {
+         span.activeMask |= SPAN_FLAT;
          didx = didy = 0.0F;
          span.indexStep = 0;
       }
       }
 
 #endif
-
 #ifdef INTERP_TEX
       span.activeMask |= SPAN_TEXTURE;
       {
       }
 #  endif
 #endif
-
 #ifdef INTERP_MULTITEX
       span.activeMask |= SPAN_TEXTURE;
 #  ifdef INTERP_LAMBDA