Add support for GL_EXT_secondary_color, tested with seccolor test.
authorEric Anholt <anholt@FreeBSD.org>
Mon, 24 Oct 2005 21:30:06 +0000 (21:30 +0000)
committerEric Anholt <anholt@FreeBSD.org>
Mon, 24 Oct 2005 21:30:06 +0000 (21:30 +0000)
src/mesa/drivers/dri/sis/sis_context.c
src/mesa/drivers/dri/sis/sis_context.h
src/mesa/drivers/dri/sis/sis_reg.h
src/mesa/drivers/dri/sis/sis_state.c
src/mesa/drivers/dri/sis/sis_tris.c

index 8e2aa88ca39da3f44546c02b6d2a666ac93a7bd1..642560a0d9ecf0024a5c3048046b77b6510bc7bf 100644 (file)
@@ -60,6 +60,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #define need_GL_ARB_multisample
 #define need_GL_ARB_texture_compression
+#define need_GL_EXT_secondary_color
 #include "extension_helper.h"
 
 #ifndef SIS_DEBUG
@@ -78,6 +79,7 @@ struct dri_extension card_extensions[] =
     { "GL_ARB_texture_compression",        GL_ARB_texture_compression_functions },
     { "GL_ARB_texture_mirrored_repeat",    NULL },
     { "GL_EXT_texture_lod_bias",           NULL },
+    { "GL_EXT_secondary_color",            GL_EXT_secondary_color_functions },
     { "GL_EXT_stencil_wrap",               NULL },
     /*{ "GL_MESA_ycbcr_texture",             NULL },*/ /* not working yet */
     { "GL_NV_blend_square",                NULL },
index 54c1f0458f2f61734e2e7d05da379a09541afb01..fb5908407cee5d5c5aa1b6d92c77a62340930004 100644 (file)
@@ -265,6 +265,8 @@ struct sis_context
   void *vb_agp_handle;
   GLuint vb_agp_offset;
   GLboolean using_agp;
+  GLint coloroffset;           /* Offset in vertex format of current color */
+  GLint specoffset;            /* Offset in vertex format of specular color */
 
   GLuint NewGLState;
   GLuint Fallback;
index 1c245898a46d45c0305ab664b547b290f65a1673..fcfa92f23ca1d0d43f0e3b0fca1fdf6c68803ebf 100644 (file)
@@ -234,12 +234,12 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
  * wrong, new names SiS_PS_* based off of the 4.3.0 driver and research are
  * below.
  */
-#define SiS_PS_HAS_XYZ                         0x08000000
-#define SiS_PS_HAS_W                           0x04000000
-#define SiS_PS_HAS_SPECULAR                    0x02000000 /* XXX ? */
-#define SiS_PS_HAS_DIFFUSE                     0x01000000
-#define SiS_PS_HAS_UV0                         0x00400000
-#define SiS_PS_HAS_UV1                         0x00200000
+#define SiS_PS_HAS_XYZ                         MASK_PsVertex_HAS_RHW
+#define SiS_PS_HAS_W                           MASK_PsVertex_HAS_NORMALXYZ
+#define SiS_PS_HAS_DIFFUSE                     MASK_PsVertex_HAS_SPECULAR
+#define SiS_PS_HAS_SPECULAR                    MASK_PsVertex_HAS_DIFFUSE
+#define SiS_PS_HAS_UV0                         MASK_PsVertex_HAS_UVSet2
+#define SiS_PS_HAS_UV1                         MASK_PsVertex_HAS_UVSet3
 #define MASK_PsVertex_HAS_RHW                  0x08000000
 #define MASK_PsVertex_HAS_NORMALXYZ            0x04000000
 #define MASK_PsVertex_HAS_DIFFUSE              0x02000000
index 01688c2fda5302776a9df6bc444246f19166e53f..195a624b40c053286faa036540c5f8b9c26baffe 100644 (file)
@@ -400,6 +400,25 @@ static void sisDDColorMask( GLcontext *ctx,
  * Rendering attributes
  */
 
+static void sisUpdateSpecular(GLcontext *ctx)
+{
+   sisContextPtr smesa = SIS_CONTEXT(ctx);
+   __GLSiSHardware *current = &smesa->current;
+
+   if (NEED_SECONDARY_COLOR(ctx))
+      current->hwCapEnable |= MASK_SpecularEnable;
+   else
+      current->hwCapEnable &= ~MASK_SpecularEnable;
+}
+
+static void sisDDLightModelfv(GLcontext *ctx, GLenum pname,
+                             const GLfloat *param)
+{
+   if (pname == GL_LIGHT_MODEL_COLOR_CONTROL) {
+      sisUpdateSpecular(ctx);
+   }
+}
+
 static void sisDDShadeModel( GLcontext *ctx, GLenum mode )
 {
    sisContextPtr smesa = SIS_CONTEXT(ctx);
@@ -636,7 +655,11 @@ sisDDEnable( GLcontext * ctx, GLenum cap, GLboolean state )
                                   MASK_StencilWriteEnable);
       }
       break;
-    }
+   case GL_LIGHTING:
+   case GL_COLOR_SUM_EXT:
+      sisUpdateSpecular(ctx);
+      break;
+   }
 }
 
 
@@ -694,7 +717,6 @@ void sisDDInitState( sisContextPtr smesa )
    /* add Texture Perspective Enable */
    prev->hwCapEnable = MASK_FogPerspectiveEnable | MASK_TextureCacheEnable |
       MASK_TexturePerspectiveEnable | MASK_DitherEnable;
-   /*| MASK_SpecularEnable*/
 
    /*
    prev->hwCapEnable2 = 0x00aa0080;
@@ -829,6 +851,7 @@ void sisDDInitStateFuncs( GLcontext *ctx )
    ctx->Driver.RenderMode       = NULL;
    ctx->Driver.Scissor          = sisDDScissor;
    ctx->Driver.ShadeModel       = sisDDShadeModel;
+   ctx->Driver.LightModelfv     = sisDDLightModelfv;
    ctx->Driver.Viewport                 = sisDDViewport;
 
    /* Pixel path fallbacks. */
index de91268ee64dd6ccf8f21f7f650b75964c584942..da1e1ee692291f1218f8b065eb58e6254347d572 100644 (file)
@@ -379,7 +379,7 @@ do {                                                                \
 
 #define VERT_SET_SPEC( v0, c )                                 \
 do {                                                           \
-   if (havespec) {                                             \
+   if (specoffset != 0) {                                      \
       UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.red, (c)[0]);    \
       UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.green, (c)[1]);  \
       UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.blue, (c)[2]);   \
@@ -387,7 +387,7 @@ do {                                                                \
 } while (0)
 #define VERT_COPY_SPEC( v0, v1 )                       \
 do {                                                   \
-   if (havespec) {                                     \
+   if (specoffset != 0) {                              \
       v0->v.specular.red   = v1->v.specular.red;       \
       v0->v.specular.green = v1->v.specular.green;     \
       v0->v.specular.blue  = v1->v.specular.blue;      \
@@ -396,15 +396,15 @@ do {                                                      \
 
 #define VERT_SAVE_RGBA( idx )    color[idx] = v[idx]->ui[coloroffset]
 #define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
-#define VERT_SAVE_SPEC( idx )    if (havespec) spec[idx] = v[idx]->ui[5]
-#define VERT_RESTORE_SPEC( idx ) if (havespec) v[idx]->ui[5] = spec[idx]
+#define VERT_SAVE_SPEC( idx )    if (specoffset != 0) spec[idx] = v[idx]->ui[specoffset]
+#define VERT_RESTORE_SPEC( idx ) if (specoffset != 0) v[idx]->ui[specoffset] = spec[idx]
 
 #define LOCAL_VARS(n)                                          \
    sisContextPtr smesa = SIS_CONTEXT(ctx);                     \
    GLuint color[n], spec[n];                                   \
-   GLuint coloroffset = (smesa->vertex_size == 4 ? 3 : 4);     \
-   GLboolean havespec = (smesa->vertex_size == 4 ? 0 : 1);     \
-   (void) color; (void) spec; (void) coloroffset; (void) havespec;
+   GLuint coloroffset = smesa->coloroffset;                    \
+   GLuint specoffset = smesa->specoffset;                      \
+   (void) color; (void) spec; (void) coloroffset; (void) specoffset;
 
 /***********************************************************************
  *                Helpers for rendering unfilled primitives            *
@@ -833,14 +833,17 @@ static void sisRenderStart( GLcontext *ctx )
    if (index & _TNL_BITS_TEX_ANY) {
       EMIT_ATTR(_TNL_ATTRIB_POS, EMIT_4F_VIEWPORT);
       AGPParseSet |= SiS_PS_HAS_W;
+      smesa->coloroffset = 4;
    } else {
       EMIT_ATTR(_TNL_ATTRIB_POS, EMIT_3F_VIEWPORT);
+      smesa->coloroffset = 3;
    }
 
    EMIT_ATTR(_TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA);
 
    if (index & (_TNL_BIT_COLOR1|_TNL_BIT_FOG)) {
       AGPParseSet |= SiS_PS_HAS_SPECULAR;
+      smesa->specoffset = smesa->coloroffset + 1;
 
       if (index & _TNL_BIT_COLOR1) {
         EMIT_ATTR(_TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR);
@@ -848,10 +851,13 @@ static void sisRenderStart( GLcontext *ctx )
         EMIT_PAD(3);
       }
 
-      if (index & _TNL_BIT_FOG)
+      if (index & _TNL_BIT_FOG) {
         EMIT_ATTR(_TNL_ATTRIB_FOG, EMIT_1UB_1F);
-      else 
+      } else {
         EMIT_PAD(1);
+      }
+   } else {
+      smesa->specoffset = 0;
    }
 
    /* projective textures are not supported by the hardware */