Move away from using the ctx->_TriangleCaps bitfield.
authorBrian Paul <brian.paul@tungstengraphics.com>
Thu, 18 Sep 2003 23:21:08 +0000 (23:21 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Thu, 18 Sep 2003 23:21:08 +0000 (23:21 +0000)
New macros in context.h for testing state: NEED_SECONDARY_COLOR
and NEED_TWO_SIDED_LIGHTING.

src/mesa/main/context.h
src/mesa/swrast/s_aatriangle.c
src/mesa/swrast/s_context.c
src/mesa/swrast/s_lines.c
src/mesa/swrast_setup/ss_triangle.c
src/mesa/swrast_setup/ss_vb.c
src/mesa/tnl/t_vb_render.c

index be65be8..78b2179 100644 (file)
@@ -361,4 +361,30 @@ do {                                                                       \
 /*@}*/
 
 
+
+/**
+ * Macros to help evaluate current state conditions
+ */
+
+/*@{*/
+
+/**
+ * Is the secondary color needed?
+ */
+#define NEED_SECONDARY_COLOR(CTX)                                      \
+   (((CTX)->Light.Enabled &&                                           \
+     (CTX)->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)    \
+    || (CTX)->Fog.ColorSumEnabled)
+
+
+/**
+ * Is two-sided lighting in effect?
+ */
+#define NEED_TWO_SIDED_LIGHTING(CTX) \
+   (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
+
+
+/*@}*/
+
+
 #endif
index 21b8c04..7f2f3e3 100644 (file)
@@ -464,7 +464,7 @@ _swrast_set_aa_triangle_function(GLcontext *ctx)
    ASSERT(ctx->Polygon.SmoothFlag);
 
    if (ctx->Texture._EnabledCoordUnits != 0) {
-      if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) {
+      if (NEED_SECONDARY_COLOR(ctx)) {
          if (ctx->Texture._EnabledCoordUnits > 1) {
             SWRAST_CONTEXT(ctx)->Triangle = spec_multitex_aa_tri;
          }
index 9e429ae..99da79a 100644 (file)
@@ -226,8 +226,8 @@ _swrast_validate_triangle( GLcontext *ctx,
    _swrast_validate_derived( ctx );
    swrast->choose_triangle( ctx );
 
-   if ((ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) &&
-       ctx->Texture._EnabledUnits == 0) {
+   if (ctx->Texture._EnabledUnits == 0 && NEED_SECONDARY_COLOR(ctx)) {
+      /* separate specular color, but no texture */
       swrast->SpecTriangle = swrast->Triangle;
       swrast->Triangle = _swrast_add_spec_terms_triangle;
    }
@@ -243,8 +243,7 @@ _swrast_validate_line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 )
    _swrast_validate_derived( ctx );
    swrast->choose_line( ctx );
 
-   if ((ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) &&
-       ctx->Texture._EnabledUnits == 0) {
+   if (ctx->Texture._EnabledUnits == 0 && NEED_SECONDARY_COLOR(ctx)) {
       swrast->SpecLine = swrast->Line;
       swrast->Line = _swrast_add_spec_terms_line;
    }
@@ -261,8 +260,7 @@ _swrast_validate_point( GLcontext *ctx, const SWvertex *v0 )
    _swrast_validate_derived( ctx );
    swrast->choose_point( ctx );
 
-   if ((ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) &&
-       ctx->Texture._EnabledUnits == 0) {
+   if (ctx->Texture._EnabledUnits == 0 && NEED_SECONDARY_COLOR(ctx)) {
       swrast->SpecPoint = swrast->Point;
       swrast->Point = _swrast_add_spec_terms_point;
    }
index 97143a2..f003395 100644 (file)
@@ -24,6 +24,7 @@
 
 
 #include "glheader.h"
+#include "context.h"
 #include "colormac.h"
 #include "macros.h"
 #include "s_aaline.h"
@@ -304,7 +305,7 @@ _swrast_choose_line( GLcontext *ctx )
       else if (ctx->Texture._EnabledCoordUnits) {
          /* textured lines */
          if (ctx->Texture._EnabledCoordUnits > 0x1
-             || (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)) {
+             || NEED_SECONDARY_COLOR(ctx)) {
             /* multi-texture and/or separate specular color */
             USE(multitextured_line);
          }
index b041c32..d106d4c 100644 (file)
@@ -69,7 +69,7 @@ static void _swsetup_render_line_tri( GLcontext *ctx,
          return;
    }
 
-   if (ctx->_TriangleCaps & DD_FLATSHADE) {
+   if (ctx->Light.ShadeModel == GL_FLAT) {
       COPY_CHAN4(c[0], v0->color);
       COPY_CHAN4(c[1], v1->color);
       COPY_CHAN4(s[0], v0->specular);
@@ -95,7 +95,7 @@ static void _swsetup_render_line_tri( GLcontext *ctx,
       if (ef[e2]) _swrast_Line( ctx, v2, v0 );
    }
 
-   if (ctx->_TriangleCaps & DD_FLATSHADE) {
+   if (ctx->Light.ShadeModel == GL_FLAT) {
       COPY_CHAN4(v0->color, c[0]);
       COPY_CHAN4(v1->color, c[1]);
       COPY_CHAN4(v0->specular, s[0]);
@@ -128,7 +128,8 @@ static void _swsetup_render_point_tri( GLcontext *ctx,
          return;
    }
 
-   if (ctx->_TriangleCaps & DD_FLATSHADE) {
+   if (ctx->Light.ShadeModel == GL_FLAT) {
+      /* save colors/indexes for v0, v1 vertices */
       COPY_CHAN4(c[0], v0->color);
       COPY_CHAN4(c[1], v1->color);
       COPY_CHAN4(s[0], v0->specular);
@@ -136,6 +137,7 @@ static void _swsetup_render_point_tri( GLcontext *ctx,
       i[0] = v0->index;
       i[1] = v1->index;
 
+      /* copy v2 color/indexes to v0, v1 indexes */
       COPY_CHAN4(v0->color, v2->color);
       COPY_CHAN4(v1->color, v2->color);
       COPY_CHAN4(v0->specular, v2->specular);
@@ -148,7 +150,8 @@ static void _swsetup_render_point_tri( GLcontext *ctx,
    if (ef[e1]) _swrast_Point( ctx, v1 );
    if (ef[e2]) _swrast_Point( ctx, v2 );
 
-   if (ctx->_TriangleCaps & DD_FLATSHADE) {
+   if (ctx->Light.ShadeModel == GL_FLAT) {
+      /* restore v0, v1 colores/indexes */
       COPY_CHAN4(v0->color, c[0]);
       COPY_CHAN4(v1->color, c[1]);
       COPY_CHAN4(v0->specular, s[0]);
@@ -294,7 +297,8 @@ void _swsetup_choose_trifuncs( GLcontext *ctx )
    /* We piggyback the two-sided stencil front/back determination on the
     * unfilled triangle path.
     */
-   if ((ctx->_TriangleCaps & DD_TRI_UNFILLED) ||
+   if (ctx->Polygon.FrontMode != GL_FILL ||
+       ctx->Polygon.BackMode != GL_FILL ||
        (ctx->Stencil.Enabled && ctx->Stencil.TestTwoSide))
       ind |= SS_UNFILLED_BIT;
 
index fa49934..29bad8e 100644 (file)
@@ -392,7 +392,7 @@ _swsetup_choose_rastersetup_func(GLcontext *ctx)
          else if (ctx->Texture._EnabledCoordUnits == 1)
             funcindex |= TEX0;  /* only unit 0 is enabled */
 
-         if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)
+         if (NEED_SECONDARY_COLOR(ctx))
             funcindex |= SPEC;
       }
       else {
@@ -418,7 +418,9 @@ _swsetup_choose_rastersetup_func(GLcontext *ctx)
    swsetup->SetupIndex = funcindex;
    tnl->Driver.Render.BuildVertices = setup_tab[funcindex];
 
-   if (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED)) {
+   if (NEED_TWO_SIDED_LIGHTING(ctx) ||
+       ctx->Polygon.FrontMode != GL_FILL ||
+       ctx->Polygon.BackMode != GL_FILL) {
       tnl->Driver.Render.Interp = interp_extras;
       tnl->Driver.Render.CopyPV = copy_pv_extras;
    }
index 28dd141..dd06874 100644 (file)
@@ -72,7 +72,7 @@
 /*              Clip and render whole begin/end objects               */
 /**********************************************************************/
 
-#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED)
+#define NEED_EDGEFLAG_SETUP (ctx->Polygon.FrontMode != GL_FILL || ctx->Polygon.BackMode != GL_FILL)
 #define EDGEFLAG_GET(idx) VB->EdgeFlag[idx]
 #define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val
 
@@ -184,7 +184,7 @@ static void clip_elt_triangles( GLcontext *ctx,
 /*                  Render whole begin/end objects                    */
 /**********************************************************************/
 
-#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED)
+#define NEED_EDGEFLAG_SETUP (ctx->Polygon.FrontMode != GL_FILL || ctx->Polygon.BackMode != GL_FILL)
 #define EDGEFLAG_GET(idx) VB->EdgeFlag[idx]
 #define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val
 
@@ -348,7 +348,7 @@ static void check_render( GLcontext *ctx, struct gl_pipeline_stage *stage )
    if (ctx->Visual.rgbMode) {
       inputs |= VERT_BIT_COLOR0;
 
-      if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)
+      if (NEED_SECONDARY_COLOR(ctx))
         inputs |= VERT_BIT_COLOR1;
 
       if (ctx->Texture._EnabledCoordUnits) {
@@ -370,7 +370,7 @@ static void check_render( GLcontext *ctx, struct gl_pipeline_stage *stage )
    if (ctx->Fog.Enabled)
       inputs |= VERT_BIT_FOG;
 
-   if (ctx->_TriangleCaps & DD_TRI_UNFILLED)
+   if (ctx->Polygon.FrontMode != GL_FILL || ctx->Polygon.BackMode != GL_FILL)
       inputs |= VERT_BIT_EDGEFLAG;
 
    if (ctx->RenderMode==GL_FEEDBACK)