/*
- * Note, the FRAC macro has to work perfectly. Otherwise you'll sometimes
- * see 1-pixel bands of improperly weighted linear-filtered textures.
+ * Return fractional part of 'f'. Used for computing interpolation weights.
+ * Need to be careful with negative values.
+ * Note, if this function isn't perfect you'll sometimes see 1-pixel bands
+ * of improperly weighted linear-filtered textures.
* The tests/texwrap.c demo is a good test.
- * Also note, FRAC(x) doesn't truly return the fractional part of x for x < 0.
- * Instead, if x < 0 then FRAC(x) = 1 - true_frac(x).
*/
-#define FRAC(f) ((f) - util_ifloor(f))
+static INLINE float
+frac(float f)
+{
+ return f - util_ifloor(f);
+}
+
/**
/**
- * If A is a signed integer, A % B doesn't give the right value for A < 0
- * (in terms of texture repeat). Just casting to unsigned fixes that.
+ * 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.
*/
-#define REMAINDER(A, B) ((unsigned) (A) % (unsigned) (B))
+static INLINE int
+repeat(int coord, unsigned size)
+{
+ return (int) ((unsigned) coord % size);
+}
/**
/* i limited to [0,size-1] */
for (ch = 0; ch < 4; ch++) {
int i = util_ifloor(s[ch] * size);
- icoord[ch] = REMAINDER(i, size);
+ icoord[ch] = repeat(i, size);
}
}
uint ch;
for (ch = 0; ch < 4; ch++) {
float u = s[ch] * size - 0.5F;
- icoord0[ch] = REMAINDER(util_ifloor(u), size);
- icoord1[ch] = REMAINDER(icoord0[ch] + 1, size);
- w[ch] = FRAC(u);
+ icoord0[ch] = repeat(util_ifloor(u), size);
+ icoord1[ch] = repeat(icoord0[ch] + 1, size);
+ w[ch] = frac(u);
}
}
u = u * size - 0.5f;
icoord0[ch] = util_ifloor(u);
icoord1[ch] = icoord0[ch] + 1;
- w[ch] = FRAC(u);
+ w[ch] = frac(u);
}
}
icoord0[ch] = 0;
if (icoord1[ch] >= (int) size)
icoord1[ch] = size - 1;
- w[ch] = FRAC(u);
+ w[ch] = frac(u);
}
}
u = u * size - 0.5f;
icoord0[ch] = util_ifloor(u);
icoord1[ch] = icoord0[ch] + 1;
- w[ch] = FRAC(u);
+ w[ch] = frac(u);
}
}
icoord0[ch] = 0;
if (icoord1[ch] >= (int) size)
icoord1[ch] = size - 1;
- w[ch] = FRAC(u);
+ w[ch] = frac(u);
}
}
u -= 0.5F;
icoord0[ch] = util_ifloor(u);
icoord1[ch] = icoord0[ch] + 1;
- w[ch] = FRAC(u);
+ w[ch] = frac(u);
}
}
icoord0[ch] = 0;
if (icoord1[ch] >= (int) size)
icoord1[ch] = size - 1;
- w[ch] = FRAC(u);
+ w[ch] = frac(u);
}
}
u -= 0.5F;
icoord0[ch] = util_ifloor(u);
icoord1[ch] = icoord0[ch] + 1;
- w[ch] = FRAC(u);
+ w[ch] = frac(u);
}
}
float u = CLAMP(s[ch] - 0.5F, 0.0f, (float) size - 1.0f);
icoord0[ch] = util_ifloor(u);
icoord1[ch] = icoord0[ch] + 1;
- w[ch] = FRAC(u);
+ w[ch] = frac(u);
}
}
icoord1[ch] = icoord0[ch] + 1;
if (icoord1[ch] > (int) size - 1)
icoord1[ch] = size - 1;
- w[ch] = FRAC(u);
+ w[ch] = frac(u);
}
}