The problem ist that if BaseLevel + MinLod is bigger than MaxLevel, min_lod 
becomes bigger than max_lod, so the code below swaps min_lod and max_lod and 
we send a max_lod to the driver that is bigger than MaxLevel.

This could also be fixed by adding a condition like
if (sampler->min_lod > texobj->MaxLevel)
  sampler->min_lod = texobj->MaxLevel;

But clamping is a little bit cleaner imho.

Fabian
From 3e21ca559b9c49f86a768db849f6fa0497055706 Mon Sep 17 00:00:00 2001
From: Fabian Bieler <der.f...@gmx.net>
Date: Tue, 29 Mar 2011 11:56:31 +0200
Subject: [PATCH 3/4] st/mesa: Clamp min_lod and max_lod to BaseLevel and MaxLevel

This works correctly if BaseLevel + MinLod > MaxLevel.

Note: This also changes the behaviour if MaxLevel < BaseLevel.
---
 src/mesa/state_tracker/st_atom_sampler.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c
index 5f1849d..2025720 100644
--- a/src/mesa/state_tracker/st_atom_sampler.c
+++ b/src/mesa/state_tracker/st_atom_sampler.c
@@ -166,12 +166,11 @@ update_samplers(struct st_context *st)
          sampler->lod_bias = st->ctx->Texture.Unit[texUnit].LodBias +
             texobj->LodBias;
 
-         sampler->min_lod = texobj->BaseLevel + texobj->MinLod;
-         if (sampler->min_lod < texobj->BaseLevel)
-            sampler->min_lod = texobj->BaseLevel;
+         sampler->min_lod = CLAMP(texobj->BaseLevel + texobj->MinLod,
+               texobj->BaseLevel, texobj->MaxLevel);
+         sampler->max_lod = CLAMP(texobj->BaseLevel + texobj->MaxLod,
+               texobj->BaseLevel, texobj->MaxLevel);
 
-         sampler->max_lod = MIN2((GLfloat) texobj->MaxLevel,
-                                 (texobj->MaxLod + texobj->BaseLevel));
          if (sampler->max_lod < sampler->min_lod) {
             /* The GL spec doesn't seem to specify what to do in this case.
              * Swap the values.
-- 
1.7.4.1

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to