Mesa (master): softpipe: fix repeat() function for NPOT textures

Brian Paul brianp at kemper.freedesktop.org
Sat Sep 25 19:37:29 UTC 2010


Module: Mesa
Branch: master
Commit: e31f0f996537046228602a251706613ca4163209
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=e31f0f996537046228602a251706613ca4163209

Author: Brian Paul <brianp at vmware.com>
Date:   Sat Sep 25 13:06:31 2010 -0600

softpipe: fix repeat() function for NPOT textures

The trick of casting the coord to an unsigned value only works for POT
textures.  Add a bias instead.  This fixes a few piglit texwrap failures.

---

 src/gallium/drivers/softpipe/sp_tex_sample.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.c b/src/gallium/drivers/softpipe/sp_tex_sample.c
index e654bb7..96ccf1d 100644
--- a/src/gallium/drivers/softpipe/sp_tex_sample.c
+++ b/src/gallium/drivers/softpipe/sp_tex_sample.c
@@ -105,14 +105,14 @@ lerp_3d(float a, float b, float c,
 
 /**
  * Compute coord % size for repeat wrap modes.
- * Note that if coord is a signed integer, coord % size doesn't give
- * the right value for coord < 0 (in terms of texture repeat).  Just
- * casting to unsigned fixes that.
+ * Note that if coord is negative, coord % size doesn't give the right
+ * value.  To avoid that problem we add a large multiple of the size
+ * (rather than using a conditional).
  */
 static INLINE int
 repeat(int coord, unsigned size)
 {
-   return (int) ((unsigned) coord % size);
+   return (coord + size * 1024) % size;
 }
 
 




More information about the mesa-commit mailing list