From dcbe4d6d2f3eb2c099838875780991da34884646 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 13 Sep 2001 22:12:54 +0000 Subject: minor optimizations for flat shading (Klaus Niederkrueger) --- src/mesa/swrast/s_triangle.c | 117 +++++++++++++++++++++++++++++-------------- src/mesa/swrast/s_trispan.h | 22 ++++---- src/mesa/swrast/s_tritemp.h | 7 ++- 3 files changed, 95 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c index 1781c993d9..c1aa1facf1 100644 --- a/src/mesa/swrast/s_triangle.c +++ b/src/mesa/swrast/s_triangle.c @@ -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; diff --git a/src/mesa/swrast/s_trispan.h b/src/mesa/swrast/s_trispan.h index 2ac3c4d17a..48f397e4c5 100644 --- a/src/mesa/swrast/s_trispan.h +++ b/src/mesa/swrast/s_trispan.h @@ -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 @@ -44,14 +44,18 @@ */ -#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 { diff --git a/src/mesa/swrast/s_tritemp.h b/src/mesa/swrast/s_tritemp.h index 08a725cbd8..be69d7577d 100644 --- a/src/mesa/swrast/s_tritemp.h +++ b/src/mesa/swrast/s_tritemp.h @@ -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 @@ -400,6 +400,7 @@ } else { ASSERT (ctx->Light.ShadeModel == GL_FLAT); + span.activeMask |= SPAN_FLAT; drdx = drdy = 0.0F; dgdx = dgdy = 0.0F; dbdx = dbdy = 0.0F; @@ -506,7 +507,6 @@ dsbdx = dsbdy = span.specBlueStep = 0; } #endif - #ifdef INTERP_INDEX span.activeMask |= SPAN_INDEX; if (ctx->Light.ShadeModel == GL_SMOOTH) { @@ -518,6 +518,7 @@ didy = oneOverArea * (eMaj.dx * eBot_di - eMaj_di * eBot.dx); } else { + span.activeMask |= SPAN_FLAT; didx = didy = 0.0F; span.indexStep = 0; } @@ -542,7 +543,6 @@ } #endif - #ifdef INTERP_TEX span.activeMask |= SPAN_TEXTURE; { @@ -591,7 +591,6 @@ } # endif #endif - #ifdef INTERP_MULTITEX span.activeMask |= SPAN_TEXTURE; # ifdef INTERP_LAMBDA -- cgit v1.2.3