softpipe: fix repeat() function for NPOT textures
authorBrian Paul <brianp@vmware.com>
Sat, 25 Sep 2010 19:06:31 +0000 (13:06 -0600)
committerBrian Paul <brianp@vmware.com>
Sat, 25 Sep 2010 19:37:05 +0000 (13:37 -0600)
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

index e654bb77c29f5d3a70003a1e80ea25b308c23c1e..96ccf1da988408c4dc15f9b91a99d09b9706ea02 100644 (file)
@@ -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;
 }