nouveau: Implement much of the fog handling.
authorCarlos Martín Nieto <carlos@cmartin.tk>
Sun, 14 Jan 2007 23:00:30 +0000 (00:00 +0100)
committerStephane Marchesin <marchesin@icps.u-strasbg.fr>
Sun, 14 Jan 2007 23:00:30 +0000 (00:00 +0100)
src/mesa/drivers/dri/nouveau/nouveau_reg.h
src/mesa/drivers/dri/nouveau/nv30_state.c

index f52d381f748332b12ef576a97be27983f8eafdf2..8758b538c85c7864db2e64803de5b0bfe1873ff6 100644 (file)
@@ -1035,6 +1035,7 @@ Object NV30_TCL_PRIMITIVE_3D used on: NV30 NV40 G70
 #      define          NV30_TCL_PRIMITIVE_3D_STENCIL_FRONT_OP_ZPASS            0x00000364
 #      define          NV30_TCL_PRIMITIVE_3D_SHADE_MODEL                       0x00000368
 #      define          NV30_TCL_PRIMITIVE_3D_FOG_ENABLE                        0x0000036c
+#      define          NV30_TCL_PRIMITIVE_3D_FOG_COLOR                         0x00000370
 #      define          NV40_TCL_PRIMITIVE_3D_COLOR_MASK_BUFFER123              0x00000370      /* Parameters: buffer3 b buffer3 g buffer3 r buffer3 a buffer2 b buffer2 g buffer2 r buffer2 a buffer1 b buffer1 g buffer1 r buffer1 a */
 #      define          NV30_TCL_PRIMITIVE_3D_NORMALIZE_ENABLE                  0x0000037c
 #      define          NV30_TCL_PRIMITIVE_3D_DEPTH_RANGE_NEAR                  0x00000394
index 9bf5f2adeab5bab20c7b65f6cf0039568dcafcd0..4d79bb6127ca5ed8de0f999002ce5937e54ff079 100644 (file)
@@ -348,17 +348,71 @@ static void nv30Enable(GLcontext *ctx, GLenum cap, GLboolean state)
 static void nv30Fogfv(GLcontext *ctx, GLenum pname, const GLfloat *params)
 {
     nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx);
+
+    if (NOUVEAU_CARD_USING_SHADERS)
+        return;
+
     switch(pname)
     {
-        case GL_FOG_MODE:
-            //BEGIN_RING_CACHE(NvSub3D, NV30_TCL_PRIMITIVE_3D_FOG_MODE, 1);
-            //OUT_RING_CACHE (params);
+    case GL_FOG_MODE:
+    {
+        int mode = 0;
+        /* The modes are different in GL and the card.  */
+        switch(ctx->Fog.Mode)
+        {
+        case GL_LINEAR:
+            mode = 0x804;
             break;
-            /* TODO: unsure about the rest.*/
-        default:
+        case GL_EXP:
+            mode = 0x802;
             break;
+        case GL_EXP2:
+            mode = 0x803;
+            break;
+        }
+       BEGIN_RING_CACHE(NvSub3D, NV30_TCL_PRIMITIVE_3D_FOG_MODE, 1);
+       OUT_RING_CACHE (mode);
+       break;
+    }
+    case GL_FOG_COLOR:
+    {
+       GLubyte c[4];
+       UNCLAMPED_FLOAT_TO_RGBA_CHAN(c,params);
+        BEGIN_RING_CACHE(NvSub3D, NV30_TCL_PRIMITIVE_3D_FOG_COLOR, 1);
+        /* nvidia ignores the alpha channel */
+       OUT_RING_CACHE(PACK_COLOR_8888_REV(c[0],c[1],c[2],c[3]));
+        break;
+    }
+    case GL_FOG_DENSITY:
+    case GL_FOG_START:
+    case GL_FOG_END:
+    {
+        GLfloat f=0., c=0.;
+        switch(ctx->Fog.Mode)
+        {
+        case GL_LINEAR:
+            f = -1.0/(ctx->Fog.End - ctx->Fog.Start);
+            c = ctx->Fog.Start/(ctx->Fog.End - ctx->Fog.Start) + 2.001953;
+            break;
+        case GL_EXP:
+            f = -0.090168*ctx->Fog.Density;
+            c = 1.5;
+        case GL_EXP2:
+            f = -0.212330*ctx->Fog.Density;
+            c = 1.5;
+        }
+        BEGIN_RING_CACHE(NvSub3D, NV30_TCL_PRIMITIVE_3D_FOG_EQUATION_LINEAR, 1);
+        OUT_RING_CACHE(f);
+        BEGIN_RING_CACHE(NvSub3D, NV30_TCL_PRIMITIVE_3D_FOG_EQUATION_CONSTANT, 1);
+        OUT_RING_CACHE(c);
+        BEGIN_RING_CACHE(NvSub3D, NV30_TCL_PRIMITIVE_3D_FOG_EQUATION_QUADRATIC, 1);
+        OUT_RING_CACHE(0); /* Is this always the same? */
+        break;
+    }
+//    case GL_FOG_COORD_SRC:
+    default:
+        break;
     }
-
 }
    
 static void nv30Hint(GLcontext *ctx, GLenum target, GLenum mode)