#include "state.h"
#include "glformats.h"
#include "fbobject.h"
+#include "util/u_math.h"
/*
/* Truncate, to satisfy conformance tests (matches SGI's OpenGL). */
if (width > 0 && height > 0) {
const GLfloat epsilon = 0.0001F;
- GLint x = IFLOOR(ctx->Current.RasterPos[0] + epsilon - xorig);
- GLint y = IFLOOR(ctx->Current.RasterPos[1] + epsilon - yorig);
+ GLint x = util_ifloor(ctx->Current.RasterPos[0] + epsilon - xorig);
+ GLint y = util_ifloor(ctx->Current.RasterPos[1] + epsilon - yorig);
if (ctx->Unpack.BufferObj) {
/* unpack from PBO */
{
GLfloat t[4];
fetch_vector4(&inst->SrcReg[0], machine, t);
- machine->AddressReg[0][0] = IFLOOR(t[0]);
+ machine->AddressReg[0][0] = util_ifloor(t[0]);
if (DEBUG_PROG) {
printf("ARL %d\n", machine->AddressReg[0][0]);
}
const float xorig = g->xorig, yorig = g->yorig;
const float s0 = g->x, t0 = g->y;
const float s1 = s0 + g->w, t1 = t0 + g->h;
- const float x0 = IFLOOR(ctx->Current.RasterPos[0] - xorig + epsilon);
- const float y0 = IFLOOR(ctx->Current.RasterPos[1] - yorig + epsilon);
+ const float x0 = util_ifloor(ctx->Current.RasterPos[0] - xorig + epsilon);
+ const float y0 = util_ifloor(ctx->Current.RasterPos[1] - yorig + epsilon);
const float x1 = x0 + g->w, y1 = y0 + g->h;
const float clip_x0 = x0 * clip_x_scale - 1.0f;
const float clip_y0 = y0 * clip_y_scale - 1.0f;
for (dstCol = 0; dstCol < dstWidth; dstCol++) {
const GLfloat srcCol = (dstCol + 0.5F) / dstWidth * srcWidth - 0.5F;
- GLint srcCol0 = MAX2(0, IFLOOR(srcCol));
+ GLint srcCol0 = MAX2(0, util_ifloor(srcCol));
GLint srcCol1 = srcCol0 + 1;
GLfloat colWeight = srcCol - srcCol0; /* fractional part of srcCol */
GLfloat red, green, blue, alpha;
srcColor0[srcCol0][ACOMP], srcColor0[srcCol1][ACOMP],
srcColor1[srcCol0][ACOMP], srcColor1[srcCol1][ACOMP]);
- dstColor[dstCol][RCOMP] = IFLOOR(red);
- dstColor[dstCol][GCOMP] = IFLOOR(green);
- dstColor[dstCol][BCOMP] = IFLOOR(blue);
- dstColor[dstCol][ACOMP] = IFLOOR(alpha);
+ dstColor[dstCol][RCOMP] = util_ifloor(red);
+ dstColor[dstCol][GCOMP] = util_ifloor(green);
+ dstColor[dstCol][BCOMP] = util_ifloor(blue);
+ dstColor[dstCol][ACOMP] = util_ifloor(alpha);
}
}
for (dstCol = 0; dstCol < dstWidth; dstCol++) {
const GLfloat srcCol = (dstCol + 0.5F) / dstWidth * srcWidth - 0.5F;
- GLint srcCol0 = MAX2(0, IFLOOR(srcCol));
+ GLint srcCol0 = MAX2(0, util_ifloor(srcCol));
GLint srcCol1 = srcCol0 + 1;
GLfloat colWeight = srcCol - srcCol0; /* fractional part of srcCol */
GLfloat red, green, blue, alpha;
for (dstRow = 0; dstRow < dstHeight; dstRow++) {
const GLint dstY = dstYpos + dstRow;
GLfloat srcRow = (dstRow + 0.5F) / dstHeight * srcHeight - 0.5F;
- GLint srcRow0 = MAX2(0, IFLOOR(srcRow));
+ GLint srcRow0 = MAX2(0, util_ifloor(srcRow));
GLint srcRow1 = srcRow0 + 1;
GLfloat rowWeight = srcRow - srcRow0; /* fractional part of srcRow */
* 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) - IFLOOR(f))
+#define FRAC(f) ((f) - util_ifloor(f))
case GL_REPEAT:
u = s * size - 0.5F;
if (swImg->_IsPowerOfTwo) {
- *i0 = IFLOOR(u) & (size - 1);
+ *i0 = util_ifloor(u) & (size - 1);
*i1 = (*i0 + 1) & (size - 1);
}
else {
- *i0 = REMAINDER(IFLOOR(u), size);
+ *i0 = REMAINDER(util_ifloor(u), size);
*i1 = REMAINDER(*i0 + 1, size);
}
break;
else
u = s * size;
u -= 0.5F;
- *i0 = IFLOOR(u);
+ *i0 = util_ifloor(u);
*i1 = *i0 + 1;
if (*i0 < 0)
*i0 = 0;
else
u = s * size;
u -= 0.5F;
- *i0 = IFLOOR(u);
+ *i0 = util_ifloor(u);
*i1 = *i0 + 1;
}
break;
case GL_MIRRORED_REPEAT:
{
- const GLint flr = IFLOOR(s);
+ const GLint flr = util_ifloor(s);
if (flr & 1)
u = 1.0F - (s - (GLfloat) flr);
else
u = s - (GLfloat) flr;
u = (u * size) - 0.5F;
- *i0 = IFLOOR(u);
+ *i0 = util_ifloor(u);
*i1 = *i0 + 1;
if (*i0 < 0)
*i0 = 0;
else
u *= size;
u -= 0.5F;
- *i0 = IFLOOR(u);
+ *i0 = util_ifloor(u);
*i1 = *i0 + 1;
break;
case GL_MIRROR_CLAMP_TO_EDGE_EXT:
else
u *= size;
u -= 0.5F;
- *i0 = IFLOOR(u);
+ *i0 = util_ifloor(u);
*i1 = *i0 + 1;
if (*i0 < 0)
*i0 = 0;
else
u *= size;
u -= 0.5F;
- *i0 = IFLOOR(u);
+ *i0 = util_ifloor(u);
*i1 = *i0 + 1;
}
break;
else
u = s * size;
u -= 0.5F;
- *i0 = IFLOOR(u);
+ *i0 = util_ifloor(u);
*i1 = *i0 + 1;
break;
default:
case GL_REPEAT:
/* s limited to [0,1) */
/* i limited to [0,size-1] */
- i = IFLOOR(s * size);
+ i = util_ifloor(s * size);
if (swImg->_IsPowerOfTwo)
i &= (size - 1);
else
else if (s > max)
i = size - 1;
else
- i = IFLOOR(s * size);
+ i = util_ifloor(s * size);
}
return i;
case GL_CLAMP_TO_BORDER:
else if (s >= max)
i = size;
else
- i = IFLOOR(s * size);
+ i = util_ifloor(s * size);
}
return i;
case GL_MIRRORED_REPEAT:
{
const GLfloat min = 1.0F / (2.0F * size);
const GLfloat max = 1.0F - min;
- const GLint flr = IFLOOR(s);
+ const GLint flr = util_ifloor(s);
GLfloat u;
if (flr & 1)
u = 1.0F - (s - (GLfloat) flr);
else if (u > max)
i = size - 1;
else
- i = IFLOOR(u * size);
+ i = util_ifloor(u * size);
}
return i;
case GL_MIRROR_CLAMP_EXT:
else if (u >= 1.0F)
i = size - 1;
else
- i = IFLOOR(u * size);
+ i = util_ifloor(u * size);
}
return i;
case GL_MIRROR_CLAMP_TO_EDGE_EXT:
else if (u > max)
i = size - 1;
else
- i = IFLOOR(u * size);
+ i = util_ifloor(u * size);
}
return i;
case GL_MIRROR_CLAMP_TO_BORDER_EXT:
else if (u > max)
i = size;
else
- i = IFLOOR(u * size);
+ i = util_ifloor(u * size);
}
return i;
case GL_CLAMP:
else if (s >= 1.0F)
i = size - 1;
else
- i = IFLOOR(s * size);
+ i = util_ifloor(s * size);
return i;
default:
_mesa_problem(NULL, "Bad wrap mode");
GLint *i0, GLint *i1, GLfloat *weight)
{
GLfloat u = s * size - 0.5F;
- *i0 = IFLOOR(u) & (size - 1);
+ *i0 = util_ifloor(u) & (size - 1);
*i1 = (*i0 + 1) & (size - 1);
*weight = FRAC(u);
}
{
switch (wrapMode) {
case GL_CLAMP:
- return IFLOOR( CLAMP(coord, 0.0F, max - 1) );
+ return util_ifloor( CLAMP(coord, 0.0F, max - 1) );
case GL_CLAMP_TO_EDGE:
- return IFLOOR( CLAMP(coord, 0.5F, max - 0.5F) );
+ return util_ifloor( CLAMP(coord, 0.5F, max - 0.5F) );
case GL_CLAMP_TO_BORDER:
- return IFLOOR( CLAMP(coord, -0.5F, max + 0.5F) );
+ return util_ifloor( CLAMP(coord, -0.5F, max + 0.5F) );
default:
_mesa_problem(NULL, "bad wrapMode in clamp_rect_coord_nearest");
return 0;
case GL_CLAMP:
/* Not exactly what the spec says, but it matches NVIDIA output */
fcol = CLAMP(coord - 0.5F, 0.0F, max - 1);
- i0 = IFLOOR(fcol);
+ i0 = util_ifloor(fcol);
i1 = i0 + 1;
break;
case GL_CLAMP_TO_EDGE:
fcol = CLAMP(coord, 0.5F, max - 0.5F);
fcol -= 0.5F;
- i0 = IFLOOR(fcol);
+ i0 = util_ifloor(fcol);
i1 = i0 + 1;
if (i1 > max - 1)
i1 = max - 1;
case GL_CLAMP_TO_BORDER:
fcol = CLAMP(coord, -0.5F, max + 0.5F);
fcol -= 0.5F;
- i0 = IFLOOR(fcol);
+ i0 = util_ifloor(fcol);
i1 = i0 + 1;
break;
default:
static GLint
tex_array_slice(GLfloat coord, GLsizei size)
{
- GLint slice = IFLOOR(coord + 0.5f);
+ GLint slice = util_ifloor(coord + 0.5f);
slice = CLAMP(slice, 0, size - 1);
return slice;
}
(void) swImg;
for (k=0; k<n; k++) {
- GLint i = IFLOOR(texcoords[k][0] * width) & colMask;
- GLint j = IFLOOR(texcoords[k][1] * height) & rowMask;
+ GLint i = util_ifloor(texcoords[k][0] * width) & colMask;
+ GLint j = util_ifloor(texcoords[k][1] * height) & rowMask;
GLint pos = (j << shift) | i;
GLubyte *texel = (GLubyte *) swImg->ImageSlices[0] + 3 * pos;
rgba[k][RCOMP] = UBYTE_TO_FLOAT(texel[2]);
(void) swImg;
for (i = 0; i < n; i++) {
- const GLint col = IFLOOR(texcoords[i][0] * width) & colMask;
- const GLint row = IFLOOR(texcoords[i][1] * height) & rowMask;
+ const GLint col = util_ifloor(texcoords[i][0] * width) & colMask;
+ const GLint row = util_ifloor(texcoords[i][1] * height) & rowMask;
const GLint pos = (row << shift) | col;
const GLuint texel = *((GLuint *) swImg->ImageSlices[0] + pos);
rgba[i][RCOMP] = UBYTE_TO_FLOAT( (texel >> 24) );
(1.0 / tex_coord[2]) : 1.0; \
GLfloat s_tmp = (GLfloat) (tex_coord[0] * invQ); \
GLfloat t_tmp = (GLfloat) (tex_coord[1] * invQ); \
- GLint s = IFLOOR(s_tmp) & info->smask; \
- GLint t = IFLOOR(t_tmp) & info->tmask; \
+ GLint s = util_ifloor(s_tmp) & info->smask; \
+ GLint t = util_ifloor(t_tmp) & info->tmask; \
GLint pos = (t << info->twidth_log2) + s; \
const GLchan *tex00 = info->texture + COMP * pos; \
DO_TEX; \
return (int) (f + 0.5F);
}
-/** Return (as an integer) floor of float */
-static inline int IFLOOR(float f)
-{
-#if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__)
- /*
- * IEEE floor for computers that round to nearest or even.
- * 'f' must be between -4194304 and 4194303.
- * This floor operation is done by "(iround(f + .5) + iround(f - .5)) >> 1",
- * but uses some IEEE specific tricks for better speed.
- * Contributed by Josh Vanderhoof
- */
- int ai, bi;
- double af, bf;
- af = (3 << 22) + 0.5 + (double)f;
- bf = (3 << 22) + 0.5 - (double)f;
- /* GCC generates an extra fstp/fld without this. */
- __asm__ ("fstps %0" : "=m" (ai) : "t" (af) : "st");
- __asm__ ("fstps %0" : "=m" (bi) : "t" (bf) : "st");
- return (ai - bi) >> 1;
-#else
- int ai, bi;
- double af, bf;
- fi_type u;
- af = (3 << 22) + 0.5 + (double)f;
- bf = (3 << 22) + 0.5 - (double)f;
- u.f = (float) af; ai = u.i;
- u.f = (float) bf; bi = u.i;
- return (ai - bi) >> 1;
-#endif
-}
-
/**********************************************************************
* Functions