summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/dri/r300
diff options
context:
space:
mode:
authorNicolai Haehnle <nhaehnle@gmail.com>2008-06-30 00:44:26 +0200
committerNicolai Haehnle <nhaehnle@gmail.com>2008-06-30 00:49:00 +0200
commit4002b75e6267ecd0f9e3093e221e34ed5c8485d4 (patch)
treedb290fbec2d9c71d72444e857a5bd0138a48a494 /src/mesa/drivers/dri/r300
parenta74d22ba715da5e52efb15aebd15a74851f87d43 (diff)
r300: Cleanup LodBias support
. There is both a per-texture unit and a per-texture object (at least for OpenGL 1.4); this should now be supported properly. . The LOD bias calculation in r300_state has been simplified and corrected (need to multiply by 32 instead of 31, and ensure clamping) . do not clamp LOD bias in TexEnv, as that behaviour conflicts with what the spec says . set Const.MaxTextureLodBias properly . remove the no_neg_lod_bias property; if somebody can explain what it's good for, we can add it back in, but according to Google, nobody seems to use it . removed some dead code and unused variables
Diffstat (limited to 'src/mesa/drivers/dri/r300')
-rw-r--r--src/mesa/drivers/dri/r300/r300_context.c1
-rw-r--r--src/mesa/drivers/dri/r300/r300_context.h5
-rw-r--r--src/mesa/drivers/dri/r300/r300_state.c28
-rw-r--r--src/mesa/drivers/dri/r300/r300_tex.c91
4 files changed, 18 insertions, 107 deletions
diff --git a/src/mesa/drivers/dri/r300/r300_context.c b/src/mesa/drivers/dri/r300/r300_context.c
index 063d4e575e..44c368030f 100644
--- a/src/mesa/drivers/dri/r300/r300_context.c
+++ b/src/mesa/drivers/dri/r300/r300_context.c
@@ -279,6 +279,7 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
MIN2(ctx->Const.MaxTextureImageUnits,
ctx->Const.MaxTextureCoordUnits);
ctx->Const.MaxTextureMaxAnisotropy = 16.0;
+ ctx->Const.MaxTextureLodBias = 16.0;
if (screen->chip_family >= CHIP_FAMILY_RV515) {
ctx->Const.MaxTextureLevels = 13;
diff --git a/src/mesa/drivers/dri/r300/r300_context.h b/src/mesa/drivers/dri/r300/r300_context.h
index 285b2ad6fd..a24ab0cad7 100644
--- a/src/mesa/drivers/dri/r300/r300_context.h
+++ b/src/mesa/drivers/dri/r300/r300_context.h
@@ -806,10 +806,10 @@ struct r500_fragment_program {
GLcontext *ctx;
GLboolean translated;
GLboolean error;
-
+
struct r500_fragment_program_external_state state;
struct r500_fragment_program_code code;
-
+
GLboolean writes_depth;
GLuint optimization;
@@ -925,7 +925,6 @@ struct r300_context {
driTextureObject swapped;
int texture_depth;
float initialMaxAnisotropy;
- float LODBias;
/* Clientdata textures;
*/
diff --git a/src/mesa/drivers/dri/r300/r300_state.c b/src/mesa/drivers/dri/r300/r300_state.c
index 00351014af..9e4cc777a9 100644
--- a/src/mesa/drivers/dri/r300/r300_state.c
+++ b/src/mesa/drivers/dri/r300/r300_state.c
@@ -1381,16 +1381,14 @@ static void r500SetupFragmentShaderTextures(GLcontext *ctx, int *tmu_mappings)
}
}
-static GLuint r300CalculateTexLodBias(GLfloat bias)
+static GLuint translate_lod_bias(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;
+ GLint b = (int)(bias*32);
+ if (b >= (1 << 9))
+ b = (1 << 9)-1;
+ else if (b < -(1 << 9))
+ b = -(1 << 9);
+ return ((GLuint)b) << R300_LOD_BIAS_SHIFT;
}
static void r300SetupTextures(GLcontext * ctx)
@@ -1456,10 +1454,14 @@ static void r300SetupTextures(GLcontext * ctx)
r300->hw.tex.filter.cmd[R300_TEX_VALUE_0 +
hw_tmu] =
gen_fixed_filter(t->filter) | (hw_tmu << 28);
- /* Make LOD bias a bit more per-tex and less per-everything. */
- t->filter_1 &= ~R300_LOD_BIAS_MASK;
- t->filter_1 |= r300CalculateTexLodBias(ctx->Texture.Unit[i].LodBias);
- r300->hw.tex.filter_1.cmd[R300_TEX_VALUE_0 + hw_tmu] = t->filter_1;
+ /* Note: There is a LOD bias per texture unit and a LOD bias
+ * per texture object. We add them here to get the correct behaviour.
+ * (The per-texture object LOD bias was introduced in OpenGL 1.4
+ * and is not present in the EXT_texture_object extension).
+ */
+ r300->hw.tex.filter_1.cmd[R300_TEX_VALUE_0 + hw_tmu] =
+ t->filter_1 |
+ translate_lod_bias(ctx->Texture.Unit[i].LodBias + t->base.tObj->LodBias);
r300->hw.tex.size.cmd[R300_TEX_VALUE_0 + hw_tmu] =
t->size;
r300->hw.tex.format.cmd[R300_TEX_VALUE_0 +
diff --git a/src/mesa/drivers/dri/r300/r300_tex.c b/src/mesa/drivers/dri/r300/r300_tex.c
index 4ed71777d3..c8f02c4ef5 100644
--- a/src/mesa/drivers/dri/r300/r300_tex.c
+++ b/src/mesa/drivers/dri/r300/r300_tex.c
@@ -175,20 +175,6 @@ static void r300SetTexBorderColor(r300TexObjPtr t, GLubyte c[4])
t->pp_border_color = PACK_COLOR_8888(c[3], c[0], c[1], c[2]);
}
-static void r300SetTexLodBias(r300TexObjPtr t, 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;
-
- t->filter_1 &= ~R300_LOD_BIAS_MASK;
- t->filter_1 |= b;
-}
-
/**
* Allocate space for and load the mesa images into the texture memory block.
* This will happen before drawing with a new texture, or drawing with a
@@ -912,78 +898,6 @@ r300TexSubImage3D(GLcontext * ctx, GLenum target, GLint level,
t->dirty_images[0] |= (1 << level);
}
-/* This feels like a prime target for code reuse, so I'm putting it here
- * instead of inlining it in TexEnv. */
-static GLenum r300TexUnitTarget(struct gl_texture_unit *unit) {
- if (unit->_ReallyEnabled & (TEXTURE_RECT_BIT)) {
- return GL_TEXTURE_RECTANGLE_NV;
- } else if (unit->_ReallyEnabled & (TEXTURE_1D_BIT)) {
- return GL_TEXTURE_1D;
- } else if (unit->_ReallyEnabled & (TEXTURE_2D_BIT)) {
- return GL_TEXTURE_2D;
- } else if (unit->_ReallyEnabled & (TEXTURE_3D_BIT)) {
- return GL_TEXTURE_3D;
- } else if (unit->_ReallyEnabled & (TEXTURE_CUBE_BIT)) {
- return GL_TEXTURE_CUBE_MAP;
- }
- if (unit->Enabled & (TEXTURE_RECT_BIT)) {
- return GL_TEXTURE_RECTANGLE_NV;
- } else if (unit->Enabled & (TEXTURE_1D_BIT)) {
- return GL_TEXTURE_1D;
- } else if (unit->Enabled & (TEXTURE_2D_BIT)) {
- return GL_TEXTURE_2D;
- } else if (unit->Enabled & (TEXTURE_3D_BIT)) {
- return GL_TEXTURE_3D;
- } else if (unit->Enabled & (TEXTURE_CUBE_BIT)) {
- return GL_TEXTURE_CUBE_MAP;
- }
- return 0;
-}
-
-static void r300TexEnv(GLcontext * ctx, GLenum target,
- GLenum pname, const GLfloat * param)
-{
- r300ContextPtr rmesa = R300_CONTEXT(ctx);
- if (RADEON_DEBUG & DEBUG_STATE) {
- fprintf(stderr, "%s( %s )\n",
- __FUNCTION__, _mesa_lookup_enum_by_nr(pname));
- }
-
- /* This is incorrect: Need to maintain this data for each of
- * GL_TEXTURE_{123}D, GL_TEXTURE_RECTANGLE_NV, etc, and switch
- * between them according to _ReallyEnabled.
- */
- switch (pname) {
- case GL_TEXTURE_LOD_BIAS_EXT: {
- GLfloat bias, min;
-
- /* The R300's LOD bias is a signed 2's complement value with a
- * range of -16.0 <= bias < 16.0.
- *
- * NOTE: Add a small bias to the bias for conform mipsel.c test.
- */
- bias = *param + .01;
- min = driQueryOptionb(&rmesa->radeon.optionCache,
- "no_neg_lod_bias") ? 0.0 : -16.0;
- bias = CLAMP(bias, min, 16.0);
-
- /* There's probably a magic Mesa method for finding the REAL
- * texture unit. I don't know it, though. */
- if (!(ctx->Texture._EnabledUnits & (1 << ctx->Texture.CurrentUnit))) {
- break;
- }
-
- /* Save our newly clamped LOD bias. */
- ctx->Texture.Unit[ctx->Texture.CurrentUnit].LodBias = bias;
-
- break;
- }
-
- default:
- return;
- }
-}
-
/**
* Changes variables and flags for a state update, which will happen at the
* next UpdateTextureState
@@ -1106,10 +1020,6 @@ static struct gl_texture_object *r300NewTextureObject(GLcontext * ctx,
return NULL;
obj->MaxAnisotropy = rmesa->initialMaxAnisotropy;
- /* Attempt to fill LOD bias, if previously set.
- * Should start at 0.0, which won't affect the HW. */
- obj->LodBias = rmesa->LODBias;
-
r300AllocTexObj(obj);
return obj;
}
@@ -1131,7 +1041,6 @@ void r300InitTextureFuncs(struct dd_function_table *functions)
functions->DeleteTexture = r300DeleteTexture;
functions->IsTextureResident = driIsTextureResident;
- functions->TexEnv = r300TexEnv;
functions->TexParameter = r300TexParameter;
functions->CompressedTexImage2D = r300CompressedTexImage2D;