Here's my first attempt at EXT_fog_coord for R200. For tcl_mode=0 it works fine. In fact, the code currently in CVS has all the support needed for tcl_mode=0. tcl_mode=1 is totally broken. I think I missed setting R200_VTX_DISCRETE_FOG somewhere for that path.

tcl_mode=2 and tcl_mode=3 (which are the same because there's no x86-specific codegen yet) *almost* work. It looks like the fog coordinate is being interpreted incorrectly, but I'm not sure why. I tried sending 1.0-f, but that wasn't right either. Anyone (esp. anyone with docs!) have any ideas?

I haven't done anything yet to support arrays of fog coordinates.

My intention is to get this done, then add support for point sizes != 1.0, then add support for cube map texture coordinates, then add support for 3D texture coordinates. I wanted to get my feet wet with what should have been the easiest of the four. :)

Index: src/mesa/drivers/dri/r200/r200_context.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r200/r200_context.c,v
retrieving revision 1.22
diff -u -d -r1.22 r200_context.c
--- a/src/mesa/drivers/dri/r200/r200_context.c  11 Mar 2004 20:35:40 -0000      1.22
+++ b/src/mesa/drivers/dri/r200/r200_context.c  28 Apr 2004 04:16:55 -0000
@@ -131,6 +131,7 @@
     "GL_EXT_blend_logic_op",
     "GL_EXT_blend_minmax",
     "GL_EXT_blend_subtract",
+    "GL_EXT_fog_coord",
     "GL_EXT_secondary_color",
     "GL_EXT_stencil_wrap",
     "GL_EXT_texture_edge_clamp",
Index: src/mesa/drivers/dri/r200/r200_context.h
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r200/r200_context.h,v
retrieving revision 1.14
diff -u -d -r1.14 r200_context.h
--- a/src/mesa/drivers/dri/r200/r200_context.h  26 Apr 2004 10:10:23 -0000      1.14
+++ b/src/mesa/drivers/dri/r200/r200_context.h  28 Apr 2004 04:16:55 -0000
@@ -711,6 +711,8 @@
    struct dynfn MultiTexCoord2fvARB;
    struct dynfn MultiTexCoord1fARB;
    struct dynfn MultiTexCoord1fvARB;
+   struct dynfn FogCoordfEXT;
+   struct dynfn FogCoordfvEXT;
 };
 
 struct dfn_generators {
@@ -740,6 +742,8 @@
    struct dynfn *(*MultiTexCoord2fvARB)( GLcontext *, const int * );
    struct dynfn *(*MultiTexCoord1fARB)( GLcontext *, const int * );
    struct dynfn *(*MultiTexCoord1fvARB)( GLcontext *, const int * );
+   struct dynfn *(*FogCoordfEXT)( GLcontext *, const int * );
+   struct dynfn *(*FogCoordfvEXT)( GLcontext *, const int * );
 };
 
 
@@ -770,6 +774,7 @@
 
    GLfloat *normalptr;
    GLfloat *floatcolorptr;
+   GLfloat *fogptr;
    r200_color_t *colorptr;
    GLfloat *floatspecptr;
    r200_color_t *specptr;
Index: src/mesa/drivers/dri/r200/r200_reg.h
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r200/r200_reg.h,v
retrieving revision 1.3
diff -u -d -r1.3 r200_reg.h
--- a/src/mesa/drivers/dri/r200/r200_reg.h      21 Oct 2003 06:05:47 -0000      1.3
+++ b/src/mesa/drivers/dri/r200/r200_reg.h      28 Apr 2004 04:16:55 -0000
@@ -58,6 +58,7 @@
 #define     R200_FOG_USE_DIFFUSE_ALPHA (2 << 25)
 #define     R200_FOG_USE_SPEC_ALPHA    (3 << 25)
 #define     R200_FOG_USE_VTX_FOG       (4 << 25)
+#define     R200_FOG_USE_MASK          (7 << 25)
 #define R200_RE_SOLID_COLOR               0x1c1c 
 #define R200_RB3D_BLENDCNTL               0x1c20
 #define     R200_COMB_FCN_MASK                    (7  << 12)
Index: src/mesa/drivers/dri/r200/r200_state.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r200/r200_state.c,v
retrieving revision 1.18
diff -u -d -r1.18 r200_state.c
--- a/src/mesa/drivers/dri/r200/r200_state.c    21 Mar 2004 17:05:03 -0000      1.18
+++ b/src/mesa/drivers/dri/r200/r200_state.c    28 Apr 2004 04:16:55 -0000
@@ -390,10 +390,38 @@
       rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] &= ~R200_FOG_COLOR_MASK;
       rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] |= i;
       break;
-   case GL_FOG_COORDINATE_SOURCE_EXT: 
-      /* What to do?
-       */
+   case GL_FOG_COORD_SOURCE: {
+      GLuint fmt_0 = rmesa->hw.vtx.cmd[VTX_VTXFMT_0];
+      GLuint out_0 = rmesa->hw.vtx.cmd[VTX_TCL_OUTPUT_VTXFMT_0];
+      GLuint fog   = rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR];
+
+      fog &= ~R200_FOG_USE_MASK;
+      if ( ctx->Fog.FogCoordinateSource == GL_FOG_COORD ) {
+        fog   |= R200_FOG_USE_VTX_FOG;
+        fmt_0 |= R200_VTX_DISCRETE_FOG;
+        out_0 |= R200_VTX_DISCRETE_FOG;
+      }
+      else {
+        fog   |=  R200_FOG_USE_SPEC_ALPHA;
+        fmt_0 &= ~R200_VTX_DISCRETE_FOG;
+        out_0 &= ~R200_VTX_DISCRETE_FOG;
+      }
+
+      if ( fog != rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] ) {
+        R200_STATECHANGE( rmesa, ctx );
+        rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] = fog;
+      }
+
+      if ( (fmt_0 != rmesa->hw.vtx.cmd[VTX_VTXFMT_0])
+          || (out_0 != rmesa->hw.vtx.cmd[VTX_TCL_OUTPUT_VTXFMT_0])) {
+        R200_STATECHANGE( rmesa, vtx );
+        rmesa->hw.vtx.cmd[VTX_VTXFMT_0] = fmt_0;
+        rmesa->hw.vtx.cmd[VTX_TCL_OUTPUT_VTXFMT_0] = out_0;
+      }
+
+      r200UpdateSpecular( ctx );
       break;
+   }
    default:
       return;
    }
Index: src/mesa/drivers/dri/r200/r200_swtcl.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r200/r200_swtcl.c,v
retrieving revision 1.10
diff -u -d -r1.10 r200_swtcl.c
--- a/src/mesa/drivers/dri/r200/r200_swtcl.c    23 Apr 2004 20:20:07 -0000      1.10
+++ b/src/mesa/drivers/dri/r200/r200_swtcl.c    28 Apr 2004 04:16:55 -0000
@@ -170,7 +170,12 @@
       }
    }
 
-
+   if ( (rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] & R200_FOG_USE_MASK)
+       != R200_FOG_USE_SPEC_ALPHA ) {
+      R200_STATECHANGE( rmesa, ctx );
+      rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] &= ~R200_FOG_USE_MASK;
+      rmesa->hw.ctx.cmd[CTX_PP_FOG_COLOR] |= R200_FOG_USE_SPEC_ALPHA;
+   }
 
    if ( (rmesa->hw.vtx.cmd[VTX_VTXFMT_0] != fmt_0)
        || (rmesa->hw.vtx.cmd[VTX_VTXFMT_1] != fmt_1) ) {
Index: src/mesa/drivers/dri/r200/r200_tcl.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r200/r200_tcl.c,v
retrieving revision 1.7
diff -u -d -r1.7 r200_tcl.c
--- a/src/mesa/drivers/dri/r200/r200_tcl.c      23 Apr 2004 20:20:07 -0000      1.7
+++ b/src/mesa/drivers/dri/r200/r200_tcl.c      28 Apr 2004 04:16:55 -0000
@@ -326,6 +326,10 @@
         }
       }
 
+      if ( ctx->Fog.FogCoordinateSource == GL_FOG_COORD ) {
+        inputs |= VERT_BIT_FOG;
+      }
+             
       if (ctx->Texture.Unit[0]._ReallyEnabled) {
         if (ctx->Texture.Unit[0].TexGenEnabled) {
            if (rmesa->TexGenNeedNormals[0]) {
Index: src/mesa/drivers/dri/r200/r200_vtxfmt.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r200/r200_vtxfmt.c,v
retrieving revision 1.7
diff -u -d -r1.7 r200_vtxfmt.c
--- a/src/mesa/drivers/dri/r200/r200_vtxfmt.c   27 Apr 2004 18:38:23 -0000      1.7
+++ b/src/mesa/drivers/dri/r200/r200_vtxfmt.c   28 Apr 2004 04:16:55 -0000
@@ -114,6 +114,10 @@
       ctx->Current.Attrib[VERT_ATTRIB_NORMAL][2] = rmesa->vb.normalptr[2];
    }
 
+   if (rmesa->vb.vtxfmt_0 & R200_VTX_DISCRETE_FOG) {
+      ctx->Current.Attrib[VERT_ATTRIB_FOG][0] = rmesa->vb.fogptr[0];
+   }
+
    switch( VTX_COLOR(rmesa->vb.vtxfmt_0, 0) ) {
    case R200_VTX_PK_RGBA:
       ctx->Current.Attrib[VERT_ATTRIB_COLOR0][0] = UBYTE_TO_FLOAT( 
rmesa->vb.colorptr->red );
@@ -138,7 +142,7 @@
    default:
       break;
    }
-      
+
    if (VTX_COLOR(rmesa->vb.vtxfmt_0, 1) == R200_VTX_PK_RGBA) {
       ctx->Current.Attrib[VERT_ATTRIB_COLOR1][0] = UBYTE_TO_FLOAT( 
rmesa->vb.specptr->red );
       ctx->Current.Attrib[VERT_ATTRIB_COLOR1][1] = UBYTE_TO_FLOAT( 
rmesa->vb.specptr->green );
@@ -430,6 +434,11 @@
         offset += 3;
       }
 
+      if (ind0 & R200_VTX_DISCRETE_FOG) {
+        _glapi_Dispatch->FogCoordfvEXT( &tmp[i][offset] ); 
+        offset++;
+      }
+
       if (VTX_COLOR(ind0, 0) == R200_VTX_PK_RGBA) {
         _glapi_Dispatch->Color4ubv( (GLubyte *)&tmp[i][offset] ); 
         offset++;
@@ -464,7 +473,11 @@
    /* Replay current vertex
     */
    if (ind0 & R200_VTX_N0) 
-       _glapi_Dispatch->Normal3fv( rmesa->vb.normalptr );
+      _glapi_Dispatch->Normal3fv( rmesa->vb.normalptr );
+
+   if (ind0 & R200_VTX_DISCRETE_FOG) {
+      _glapi_Dispatch->FogCoordfvEXT( rmesa->vb.fogptr ); 
+   }
 
    if (VTX_COLOR(ind0, 0) == R200_VTX_PK_RGBA) {
       _glapi_Dispatch->Color4ub( rmesa->vb.colorptr->red,
@@ -620,6 +633,10 @@
       }
    }
 
+   if ( ctx->Fog.FogCoordinateSource == GL_FOG_COORD ) {
+      ind0 |= R200_VTX_DISCRETE_FOG;
+   }
+
    if (ctx->Texture.Unit[0]._ReallyEnabled) {
       if (ctx->Texture.Unit[0].TexGenEnabled) {
         if (rmesa->TexGenNeedNormals[0]) {
@@ -664,6 +681,7 @@
    rmesa->vb.normalptr = ctx->Current.Attrib[VERT_ATTRIB_NORMAL];
    rmesa->vb.colorptr = NULL;
    rmesa->vb.floatcolorptr = ctx->Current.Attrib[VERT_ATTRIB_COLOR0];
+   rmesa->vb.fogptr = ctx->Current.Attrib[VERT_ATTRIB_FOG];
    rmesa->vb.specptr = NULL;
    rmesa->vb.floatspecptr = ctx->Current.Attrib[VERT_ATTRIB_COLOR1];
    rmesa->vb.texcoordptr[0] = ctx->Current.Attrib[VERT_ATTRIB_TEX0];
@@ -680,6 +698,12 @@
       rmesa->vb.normalptr[2] = ctx->Current.Attrib[VERT_ATTRIB_NORMAL][2];
    }
 
+   if (ind0 & R200_VTX_DISCRETE_FOG) {
+      rmesa->vb.fogptr = &rmesa->vb.vertex[rmesa->vb.vertex_size].color;
+      rmesa->vb.vertex_size += 1;
+      rmesa->vb.fogptr[0] = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
+   }
+
    if (VTX_COLOR(ind0, 0) == R200_VTX_PK_RGBA) {
       rmesa->vb.colorptr = &rmesa->vb.vertex[rmesa->vb.vertex_size].color;
       rmesa->vb.vertex_size += 1;
@@ -1006,8 +1030,6 @@
 
    /* Not active in supported states; just keep ctx->Current uptodate:
     */
-   vfmt->FogCoordfvEXT = _mesa_noop_FogCoordfvEXT;
-   vfmt->FogCoordfEXT = _mesa_noop_FogCoordfEXT;
    vfmt->EdgeFlag = _mesa_noop_EdgeFlag;
    vfmt->EdgeFlagv = _mesa_noop_EdgeFlagv;
    vfmt->Indexf = _mesa_noop_Indexf;
@@ -1079,6 +1101,8 @@
    make_empty_list( &rmesa->vb.dfn_cache.MultiTexCoord2fvARB );
    make_empty_list( &rmesa->vb.dfn_cache.MultiTexCoord1fARB );
    make_empty_list( &rmesa->vb.dfn_cache.MultiTexCoord1fvARB );
+   make_empty_list( &rmesa->vb.dfn_cache.FogCoordfEXT );
+   make_empty_list( &rmesa->vb.dfn_cache.FogCoordfvEXT );
 
    r200InitCodegen( &rmesa->vb.codegen, useCodegen );
 }
Index: src/mesa/drivers/dri/r200/r200_vtxfmt_c.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r200/r200_vtxfmt_c.c,v
retrieving revision 1.5
diff -u -d -r1.5 r200_vtxfmt_c.c
--- a/src/mesa/drivers/dri/r200/r200_vtxfmt_c.c 11 Dec 2003 16:25:37 -0000      1.5
+++ b/src/mesa/drivers/dri/r200/r200_vtxfmt_c.c 28 Apr 2004 04:16:55 -0000
@@ -503,6 +503,25 @@
 }
 
 
+/* FogCoord
+ */
+static void r200_FogCoordfEXT( GLfloat f )
+{
+   GET_CURRENT_CONTEXT(ctx);
+   r200ContextPtr rmesa = R200_CONTEXT(ctx);
+   GLfloat *dest = rmesa->vb.fogptr;
+   dest[0] = f;
+}
+
+static void r200_FogCoordfvEXT( const GLfloat *v )
+{
+   GET_CURRENT_CONTEXT(ctx);
+   r200ContextPtr rmesa = R200_CONTEXT(ctx);
+   GLfloat *dest = rmesa->vb.fogptr;
+   dest[0] = v[0];
+}
+
+
 /* TexCoord
  */
 static void r200_TexCoord1f( GLfloat s )
@@ -736,7 +755,8 @@
  */
 #define MASK_XYZW  (R200_VTX_W0|R200_VTX_Z0)
 #define MASK_NORM  (MASK_XYZW|R200_VTX_N0)
-#define MASK_COLOR (MASK_NORM |(R200_VTX_COLOR_MASK<<R200_VTX_COLOR_0_SHIFT))
+#define MASK_FOG   (MASK_NORM |R200_VTX_DISCRETE_FOG)
+#define MASK_COLOR (MASK_FOG |(R200_VTX_COLOR_MASK<<R200_VTX_COLOR_0_SHIFT))
 #define MASK_SPEC  (MASK_COLOR|(R200_VTX_COLOR_MASK<<R200_VTX_COLOR_1_SHIFT))
 
 /* VTXFMT_1
@@ -820,6 +840,10 @@
 CHOOSE(Vertex2fv, pfv, ~0, ~0, 
        (const GLfloat *v), (v))
 
+CHOOSE(FogCoordfEXT, p1f, MASK_FOG, ~0, 
+       (GLfloat f), (f))
+CHOOSE(FogCoordfvEXT, pfv, MASK_FOG, ~0, 
+       (const GLfloat *f), (f))
 
 
 
@@ -846,6 +870,8 @@
    vfmt->Vertex2fv = choose_Vertex2fv;
    vfmt->Vertex3f = choose_Vertex3f;
    vfmt->Vertex3fv = choose_Vertex3fv;
+   vfmt->FogCoordfEXT = choose_FogCoordfEXT;
+   vfmt->FogCoordfvEXT = choose_FogCoordfvEXT;
 
    /* TODO: restore ubyte colors to vtxfmt.
     */
@@ -894,6 +920,8 @@
    gen->TexCoord1fv = codegen_noop;
    gen->MultiTexCoord1fARB = codegen_noop;
    gen->MultiTexCoord1fvARB = codegen_noop;
+   gen->FogCoordfEXT = codegen_noop;
+   gen->FogCoordfvEXT = codegen_noop;
 
    if (useCodegen) {
 #if defined(USE_X86_ASM)

Reply via email to