Mesa (master): swrast: fix secondary color add for glBitmap

Brian Paul brianp at kemper.freedesktop.org
Mon Apr 6 23:19:13 UTC 2009


Module: Mesa
Branch: master
Commit: 76ac75af8e5481b498981c133836efa2101be2dc
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=76ac75af8e5481b498981c133836efa2101be2dc

Author: Brian Paul <brianp at vmware.com>
Date:   Mon Apr  6 17:17:52 2009 -0600

swrast: fix secondary color add for glBitmap

Also, clean up the logic involved in choosing per-vertex vs. per-fragment
primary+secondary color addition.

---

 src/mesa/swrast/s_context.c |   36 +++++++++++++++++++++++++++---------
 src/mesa/swrast/s_context.h |    1 +
 src/mesa/swrast/s_span.c    |    4 ++--
 3 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index 56bf203..a7eaf76 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -275,6 +275,24 @@ _swrast_update_fragment_program(GLcontext *ctx, GLbitfield newState)
 }
 
 
+/**
+ * See if we can do early diffuse+specular (primary+secondary) color
+ * add per vertex instead of per-fragment.
+ */
+static void
+_swrast_update_specular_vertex_add(GLcontext *ctx)
+{
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
+   GLboolean separateSpecular = ctx->Fog.ColorSumEnabled ||
+      (ctx->Light.Enabled &&
+       ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR);
+
+   swrast->SpecularVertexAdd = (separateSpecular
+                                && ctx->Texture._EnabledUnits == 0x0
+                                && !ctx->FragmentProgram._Current
+                                && !ctx->ATIFragmentShader._Enabled);
+}
+
 
 #define _SWRAST_NEW_DERIVED (_SWRAST_NEW_RASTERMASK |	\
 			     _NEW_TEXTURE |		\
@@ -336,9 +354,7 @@ _swrast_validate_triangle( GLcontext *ctx,
    swrast->choose_triangle( ctx );
    ASSERT(swrast->Triangle);
 
-   if (ctx->Texture._EnabledUnits == 0
-       && NEED_SECONDARY_COLOR(ctx)
-       && !ctx->FragmentProgram._Current) {
+   if (swrast->SpecularVertexAdd) {
       /* separate specular color, but no texture */
       swrast->SpecTriangle = swrast->Triangle;
       swrast->Triangle = _swrast_add_spec_terms_triangle;
@@ -360,9 +376,7 @@ _swrast_validate_line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 )
    swrast->choose_line( ctx );
    ASSERT(swrast->Line);
 
-   if (ctx->Texture._EnabledUnits == 0
-       && NEED_SECONDARY_COLOR(ctx)
-       && !ctx->FragmentProgram._Current) {
+   if (swrast->SpecularVertexAdd) {
       swrast->SpecLine = swrast->Line;
       swrast->Line = _swrast_add_spec_terms_line;
    }
@@ -382,9 +396,7 @@ _swrast_validate_point( GLcontext *ctx, const SWvertex *v0 )
    _swrast_validate_derived( ctx );
    swrast->choose_point( ctx );
 
-   if (ctx->Texture._EnabledUnits == 0
-       && NEED_SECONDARY_COLOR(ctx)
-       && !ctx->FragmentProgram._Current) {
+   if (swrast->SpecularVertexAdd) {
       swrast->SpecPoint = swrast->Point;
       swrast->Point = _swrast_add_spec_terms_point;
    }
@@ -666,6 +678,12 @@ _swrast_validate_derived( GLcontext *ctx )
                               _NEW_TEXTURE))
          _swrast_update_active_attribs(ctx);
 
+      if (swrast->NewState & (_NEW_FOG | 
+                              _NEW_PROGRAM |
+                              _NEW_LIGHT |
+                              _NEW_TEXTURE))
+         _swrast_update_specular_vertex_add(ctx);
+
       swrast->NewState = 0;
       swrast->StateChanges = 0;
       swrast->InvalidateState = _swrast_invalidate_state;
diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index b7a17cb..9059f9b 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -157,6 +157,7 @@ typedef struct
    GLbitfield NewState;
    GLuint StateChanges;
    GLenum Primitive;    /* current primitive being drawn (ala glBegin) */
+   GLboolean SpecularVertexAdd; /**< Add specular/secondary color per vertex */
 
    void (*InvalidateState)( GLcontext *ctx, GLbitfield new_state );
 
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index 08d725c..07b3966 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -1377,8 +1377,8 @@ _swrast_write_rgba_span( GLcontext *ctx, SWspan *span)
 
    ASSERT(span->arrayMask & SPAN_RGBA);
 
-   if (!shader) {
-      /* Add base and specular colors */
+   if (span->primitive == GL_BITMAP || !swrast->SpecularVertexAdd) {
+      /* Add primary and specular (diffuse + specular) colors */
       if (ctx->Fog.ColorSumEnabled ||
           (ctx->Light.Enabled &&
            ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)) {




More information about the mesa-commit mailing list