r300: Make LOD bias a persistent environment variable.
authorCorbin Simpson <MostAwesomeDude@gmail.com>
Mon, 16 Jun 2008 18:37:32 +0000 (11:37 -0700)
committerCorbin Simpson <MostAwesomeDude@gmail.com>
Mon, 16 Jun 2008 18:40:34 +0000 (11:40 -0700)
Per airlied's suggestion.

src/mesa/drivers/dri/r300/r300_state.c
src/mesa/drivers/dri/r300/r300_tex.c

index a86e4bc344471b787b75ea923075767136ce7df0..55d3d55e9006547d4578605d66f679020d0efe4b 100644 (file)
@@ -1381,6 +1381,18 @@ static void r500SetupFragmentShaderTextures(GLcontext *ctx, int *tmu_mappings)
        }
 }
 
+static GLuint r300CalculateTexLodBias(GLfloat bias)
+{
+       GLuint b;
+       b = (unsigned int)fabsf(ceilf(bias*31));
+       if (signbit(bias)) {
+               b ^= 0x3ff; /* 10 bits */
+       }
+       b <<= 3;
+       b &= R300_LOD_BIAS_MASK;
+       return b;
+}
+
 static void r300SetupTextures(GLcontext * ctx)
 {
        int i, mtu;
@@ -1444,7 +1456,8 @@ static void r300SetupTextures(GLcontext * ctx)
                        r300->hw.tex.filter.cmd[R300_TEX_VALUE_0 +
                                                hw_tmu] =
                            gen_fixed_filter(t->filter) | (hw_tmu << 28);
-                       r300->hw.tex.filter_1.cmd[R300_TEX_VALUE_0 + hw_tmu] = t->filter_1;
+                       r300->hw.tex.filter_1.cmd[R300_TEX_VALUE_0 + hw_tmu] = t->filter_1
+                               | r300CalculateTexLodBias(r300->LODBias);
                        r300->hw.tex.size.cmd[R300_TEX_VALUE_0 + hw_tmu] =
                            t->size;
                        r300->hw.tex.format.cmd[R300_TEX_VALUE_0 +
index a3d6f90ef6aea1482aa86e3e67270026e069f087..5f54bcad9a39a167069ed403d1f4872edc7bedaa 100644 (file)
@@ -284,7 +284,6 @@ static r300TexObjPtr r300AllocTexObj(struct gl_texture_object *texObj)
                r300SetTexWrap(t, texObj->WrapS, texObj->WrapT, texObj->WrapR);
                r300SetTexFilter(t, texObj->MinFilter, texObj->MagFilter, texObj->MaxAnisotropy);
                r300SetTexBorderColor(t, texObj->_BorderChan);
-               r300SetTexLodBias(t, texObj->LodBias);
        }
 
        return t;
@@ -1036,18 +1035,6 @@ static void r300TexEnv(GLcontext * ctx, GLenum target,
                        "no_neg_lod_bias") ? 0.0 : -16.0;
                bias = CLAMP(bias, min, 16.0);
 
-               /* This next part feels quite hackish;
-                * is there a cleaner way? */
-               GLenum target = r300TexUnitTarget(&ctx->Texture.Unit[ctx->Texture.CurrentUnit]);
-               if (target) {
-                       struct gl_texture_object *texObj =
-                               _mesa_select_tex_object(ctx, &ctx->Texture.Unit[ctx->Texture.CurrentUnit], target);
-                       r300TexObjPtr t = (r300TexObjPtr) texObj->DriverData;
-                       texObj->LodBias = bias;
-
-                       r300SetTexLodBias(t, texObj->LodBias);
-               }
-
                rmesa->LODBias = bias;
 
                break;