dri/nouveau: Enable NV_fog_distance on NV10 and NV20 hardware
authorNicholas Miell <nmiell@gmail.com>
Tue, 20 Sep 2011 13:20:39 +0000 (15:20 +0200)
committerMarek Olšák <maraeo@gmail.com>
Tue, 1 Nov 2011 10:37:11 +0000 (11:37 +0100)
Add support for NV_fog_distance to the NV10 and NV20 drivers.

[ Francisco Jerez: Fix fog coord. signedness for
  GL_EYE_RADIAL_NV/GL_EYE_PLANE on nv20 ]

src/mesa/drivers/dri/nouveau/nv10_context.c
src/mesa/drivers/dri/nouveau/nv10_state_tnl.c
src/mesa/drivers/dri/nouveau/nv20_context.c
src/mesa/drivers/dri/nouveau/nv20_state_tnl.c

index da0ef2b3cf25b00a4dedf54f87fdf40a63ad6462..c4dc1c5767a7ee2639fa9e0c20bd48d9dcbcdcfe 100644 (file)
@@ -435,6 +435,7 @@ nv10_context_create(struct nouveau_screen *screen, const struct gl_config *visua
        ctx->Extensions.ARB_texture_env_crossbar = true;
        ctx->Extensions.ARB_texture_env_combine = true;
        ctx->Extensions.ARB_texture_env_dot3 = true;
+       ctx->Extensions.NV_fog_distance = true;
        ctx->Extensions.NV_texture_rectangle = true;
 
        /* GL constants. */
index 96d1b320d86e8265738ecf55e413f549f7573c4c..e21d8f12caf651cf8163b249523a1e5247498a25 100644 (file)
@@ -80,13 +80,22 @@ get_fog_mode(unsigned mode)
 }
 
 static unsigned
-get_fog_source(unsigned source)
+get_fog_source(unsigned source, unsigned distance_mode)
 {
        switch (source) {
        case GL_FOG_COORDINATE_EXT:
                return NV10_3D_FOG_COORD_FOG;
        case GL_FRAGMENT_DEPTH_EXT:
-               return NV10_3D_FOG_COORD_DIST_ORTHOGONAL_ABS;
+               switch (distance_mode) {
+               case GL_EYE_PLANE_ABSOLUTE_NV:
+                       return NV10_3D_FOG_COORD_DIST_ORTHOGONAL_ABS;
+               case GL_EYE_PLANE:
+                       return NV10_3D_FOG_COORD_DIST_ORTHOGONAL;
+               case GL_EYE_RADIAL_NV:
+                       return NV10_3D_FOG_COORD_DIST_RADIAL;
+               default:
+                       assert(0);
+               }
        default:
                assert(0);
        }
@@ -135,7 +144,7 @@ nv10_emit_fog(struct gl_context *ctx, int emit)
 
        BEGIN_RING(chan, celsius, NV10_3D_FOG_MODE, 4);
        OUT_RING(chan, get_fog_mode(f->Mode));
-       OUT_RING(chan, get_fog_source(source));
+       OUT_RING(chan, get_fog_source(source, f->FogDistanceMode));
        OUT_RINGb(chan, f->Enabled);
        OUT_RING(chan, pack_rgba_f(MESA_FORMAT_RGBA8888_REV, f->Color));
 
index 87a6db1196716ddfa7720a6668d70e956b2fedea..2a883e31088c960f3b49169f1e85c3614abd668d 100644 (file)
@@ -449,6 +449,7 @@ nv20_context_create(struct nouveau_screen *screen, const struct gl_config *visua
        ctx->Extensions.ARB_texture_env_crossbar = true;
        ctx->Extensions.ARB_texture_env_combine = true;
        ctx->Extensions.ARB_texture_env_dot3 = true;
+       ctx->Extensions.NV_fog_distance = true;
        ctx->Extensions.NV_texture_rectangle = true;
 
        /* GL constants. */
index 4f7ddd8e49f1b4e347d2f1ff6668eefb4ddad3f9..638c5f0e37fa2c2b73d1094b2cf3dda5bd647a40 100644 (file)
@@ -127,13 +127,22 @@ get_fog_mode_unsigned(unsigned mode)
 }
 
 static unsigned
-get_fog_source(unsigned source)
+get_fog_source(unsigned source, unsigned distance_mode)
 {
        switch (source) {
        case GL_FOG_COORDINATE_EXT:
                return NV20_3D_FOG_COORD_FOG;
        case GL_FRAGMENT_DEPTH_EXT:
-               return NV20_3D_FOG_COORD_DIST_ORTHOGONAL_ABS;
+               switch (distance_mode) {
+               case GL_EYE_PLANE_ABSOLUTE_NV:
+                       return NV20_3D_FOG_COORD_DIST_ORTHOGONAL_ABS;
+               case GL_EYE_PLANE:
+                       return NV20_3D_FOG_COORD_DIST_ORTHOGONAL;
+               case GL_EYE_RADIAL_NV:
+                       return NV20_3D_FOG_COORD_DIST_RADIAL;
+               default:
+                       assert(0);
+               }
        default:
                assert(0);
        }
@@ -153,10 +162,11 @@ nv20_emit_fog(struct gl_context *ctx, int emit)
        nv10_get_fog_coeff(ctx, k);
 
        BEGIN_RING(chan, kelvin, NV20_3D_FOG_MODE, 4);
-       OUT_RING(chan, (source == GL_FOG_COORDINATE_EXT ?
-                       get_fog_mode_signed(f->Mode) :
-                       get_fog_mode_unsigned(f->Mode)));
-       OUT_RING(chan, get_fog_source(source));
+       OUT_RING(chan, ((source == GL_FRAGMENT_DEPTH_EXT &&
+                        f->FogDistanceMode == GL_EYE_PLANE_ABSOLUTE_NV) ?
+                       get_fog_mode_unsigned(f->Mode) :
+                       get_fog_mode_signed(f->Mode)));
+       OUT_RING(chan, get_fog_source(source, f->FogDistanceMode));
        OUT_RINGb(chan, f->Enabled);
        OUT_RING(chan, pack_rgba_f(MESA_FORMAT_RGBA8888_REV, f->Color));