Fix problem w/ two-sided lighting and fragment programs (depth-peel regression)
authorBrian <brian.paul@tungstengraphics.com>
Wed, 23 May 2007 21:33:46 +0000 (15:33 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Wed, 23 May 2007 21:34:50 +0000 (15:34 -0600)
src/mesa/swrast_setup/ss_context.c
src/mesa/swrast_setup/ss_context.h
src/mesa/swrast_setup/ss_tritmp.h

index 9f83fde1f5660772b459fbcf42c7df8b4a0e66f1..cd4ac57d37d199986b5d75ea2a8ed21b5f9a9c5b 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.3
+ * Version:  7.1
  *
  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
@@ -123,12 +123,13 @@ setup_vertex_format(GLcontext *ctx)
       EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, attrib[FRAG_ATTRIB_WPOS] );
 
       if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR0 )) {
-         if (ctx->FragmentProgram._Current
-             || ctx->ATIFragmentShader._Enabled
-             || CHAN_TYPE == GL_FLOAT)
-            EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4F, attrib[FRAG_ATTRIB_COL0]);
-         else
+         swsetup->intColors = !ctx->FragmentProgram._Current
+                           && !ctx->ATIFragmentShader._Enabled
+                           && CHAN_TYPE == GL_UNSIGNED_BYTE;
+         if (swsetup->intColors)
             EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4CHAN_4F_RGBA, color );
+         else
+            EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4F, attrib[FRAG_ATTRIB_COL0]);
       }
 
       if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) {
index e5d890447a7082c33d25d2b8a6ef146cad638e2b..11f9ded3ffb0d730aa2d62136571070fccc5e190 100644 (file)
@@ -1,9 +1,8 @@
-
 /*
  * Mesa 3-D graphics library
- * Version:  6.5
+ * Version:  7.1
  *
- * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -39,6 +38,7 @@ typedef struct {
    GLenum render_prim;
    DECLARE_RENDERINPUTS(last_index_bitset);
    SWvertex *verts;
+   GLboolean intColors;
 } SScontext;
 
 #define SWSETUP_CONTEXT(ctx) ((SScontext *)ctx->swsetup_context)
index 9fcde31644ddf7a0dfa1e3b16510f4565f3afb08..c14468e9514be5f213b461c53d895f43988630b2 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.1
+ * Version:  7.1
  *
- * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  */
 
 
+/**
+ * This is where we handle assigning vertex colors based on front/back
+ * facing, compute polygon offset and handle glPolygonMode().
+ */
 static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
 {
    struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
+   SScontext *swsetup = SWSETUP_CONTEXT(ctx);
    SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts;
    SWvertex *v[3];
    GLfloat z[3];
@@ -36,6 +41,7 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
    GLenum mode = GL_FILL;
    GLuint facing = 0;
    GLchan saved_color[3][4];
+   GLfloat saved_col0[3][4];
    GLfloat saved_spec[3][4];
    GLfloat saved_index[3];
 
@@ -66,19 +72,41 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
                   if (VB->ColorPtr[1]) {
                      GLfloat (*vbcolor)[4] = VB->ColorPtr[1]->data;
 
-                     COPY_CHAN4(saved_color[0], v[0]->color);
-                     COPY_CHAN4(saved_color[1], v[1]->color);
-                     COPY_CHAN4(saved_color[2], v[2]->color);
+                     if (swsetup->intColors) {
+                        COPY_CHAN4(saved_color[0], v[0]->color);
+                        COPY_CHAN4(saved_color[1], v[1]->color);
+                        COPY_CHAN4(saved_color[2], v[2]->color);
+                     }
+                     else {
+                        COPY_4V(saved_col0[0], v[0]->attrib[FRAG_ATTRIB_COL0]);
+                        COPY_4V(saved_col0[1], v[1]->attrib[FRAG_ATTRIB_COL0]);
+                        COPY_4V(saved_col0[2], v[2]->attrib[FRAG_ATTRIB_COL0]);
+                     }
 
                      if (VB->ColorPtr[1]->stride) {
-                        SS_COLOR(v[0]->color, vbcolor[e0]);
-                        SS_COLOR(v[1]->color, vbcolor[e1]);
-                        SS_COLOR(v[2]->color, vbcolor[e2]);
+                        if (swsetup->intColors) {
+                           SS_COLOR(v[0]->color, vbcolor[e0]);
+                           SS_COLOR(v[1]->color, vbcolor[e1]);
+                           SS_COLOR(v[2]->color, vbcolor[e2]);
+                        }
+                        else {
+                           COPY_4V(v[0]->attrib[FRAG_ATTRIB_COL0], vbcolor[e0]);
+                           COPY_4V(v[1]->attrib[FRAG_ATTRIB_COL0], vbcolor[e1]);
+                           COPY_4V(v[2]->attrib[FRAG_ATTRIB_COL0], vbcolor[e2]);
+                        }
                      }
                      else {
-                        SS_COLOR(v[0]->color, vbcolor[0]);
-                        SS_COLOR(v[1]->color, vbcolor[0]);
-                        SS_COLOR(v[2]->color, vbcolor[0]);
+                        /* flat shade */
+                        if (swsetup->intColors) {
+                           SS_COLOR(v[0]->color, vbcolor[0]);
+                           SS_COLOR(v[1]->color, vbcolor[0]);
+                           SS_COLOR(v[2]->color, vbcolor[0]);
+                        }
+                        else {
+                           COPY_4V(v[0]->attrib[FRAG_ATTRIB_COL0], vbcolor[0]);
+                           COPY_4V(v[1]->attrib[FRAG_ATTRIB_COL0], vbcolor[0]);
+                           COPY_4V(v[2]->attrib[FRAG_ATTRIB_COL0], vbcolor[0]);
+                        }
                      }
                   }
 
@@ -160,6 +188,9 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
       _swrast_Triangle( ctx, v[0], v[1], v[2] );
    }
 
+   /*
+    * Restore original vertex colors, etc.
+    */
    if (IND & SS_OFFSET_BIT) {
       v[0]->attrib[FRAG_ATTRIB_WPOS][2] = z[0];
       v[1]->attrib[FRAG_ATTRIB_WPOS][2] = z[1];
@@ -170,9 +201,16 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
       if (facing == 1) {
         if (IND & SS_RGBA_BIT) {
             if (VB->ColorPtr[1]) {
-               COPY_CHAN4(v[0]->color, saved_color[0]);
-               COPY_CHAN4(v[1]->color, saved_color[1]);
-               COPY_CHAN4(v[2]->color, saved_color[2]);
+               if (swsetup->intColors) {
+                  COPY_CHAN4(v[0]->color, saved_color[0]);
+                  COPY_CHAN4(v[1]->color, saved_color[1]);
+                  COPY_CHAN4(v[2]->color, saved_color[2]);
+               }
+               else {
+                  COPY_4V(v[0]->attrib[FRAG_ATTRIB_COL0], saved_col0[0]);
+                  COPY_4V(v[1]->attrib[FRAG_ATTRIB_COL0], saved_col0[1]);
+                  COPY_4V(v[2]->attrib[FRAG_ATTRIB_COL0], saved_col0[2]);
+               }
             }
 
            if (VB->SecondaryColorPtr[1]) {