diff options
author | Matt Turner <mattst88@gmail.com> | 2015-07-31 13:05:23 -0700 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2015-08-06 15:32:15 -0700 |
commit | 9514eae033e49561b17b1472e04846f8aa2b1045 (patch) | |
tree | cda05e73cf5588b4456399d94ca21bbf245d0406 | |
parent | b003435a135ad99f6790a4743fc6d44d75f9cc23 (diff) |
mesa: Replace uses of IROUND{,64} with libm functions.
lroundf is the most common replacement. I replaced uses of IROUND()
where there was a comment saying "rounded to nearest integer" with
_mesa_lroundevenf.
IROUND64 is replaced with llroundf.
-rw-r--r-- | src/mesa/main/drawpix.c | 21 | ||||
-rw-r--r-- | src/mesa/main/eval.c | 15 | ||||
-rw-r--r-- | src/mesa/main/get.c | 29 | ||||
-rw-r--r-- | src/mesa/main/imports.h | 18 | ||||
-rw-r--r-- | src/mesa/main/light.c | 9 | ||||
-rw-r--r-- | src/mesa/main/pixel.c | 2 | ||||
-rw-r--r-- | src/mesa/main/pixelstore.c | 3 | ||||
-rw-r--r-- | src/mesa/main/samplerobj.c | 8 | ||||
-rw-r--r-- | src/mesa/main/texparam.c | 8 | ||||
-rw-r--r-- | src/mesa/main/uniform_query.cpp | 2 | ||||
-rw-r--r-- | src/mesa/swrast/s_blit.c | 3 | ||||
-rw-r--r-- | src/mesa/swrast/s_context.h | 3 |
12 files changed, 55 insertions, 66 deletions
diff --git a/src/mesa/main/drawpix.c b/src/mesa/main/drawpix.c index 720a082ce6d7..d84bcd914452 100644 --- a/src/mesa/main/drawpix.c +++ b/src/mesa/main/drawpix.c @@ -36,6 +36,7 @@ #include "dispatch.h" #include "glformats.h" #include "fbobject.h" +#include "util/rounding.h" /* @@ -51,14 +52,14 @@ _mesa_DrawPixels( GLsizei width, GLsizei height, FLUSH_VERTICES(ctx, 0); if (MESA_VERBOSE & VERBOSE_API) - _mesa_debug(ctx, "glDrawPixels(%d, %d, %s, %s, %p) // to %s at %d, %d\n", + _mesa_debug(ctx, "glDrawPixels(%d, %d, %s, %s, %p) // to %s at %ld, %ld\n", width, height, _mesa_enum_to_string(format), _mesa_enum_to_string(type), pixels, _mesa_enum_to_string(ctx->DrawBuffer->ColorDrawBuffer[0]), - IROUND(ctx->Current.RasterPos[0]), - IROUND(ctx->Current.RasterPos[1])); + _mesa_lroundevenf(ctx->Current.RasterPos[0]), + _mesa_lroundevenf(ctx->Current.RasterPos[1])); if (width < 0 || height < 0) { @@ -140,8 +141,8 @@ _mesa_DrawPixels( GLsizei width, GLsizei height, if (ctx->RenderMode == GL_RENDER) { if (width > 0 && height > 0) { /* Round, to satisfy conformance tests (matches SGI's OpenGL) */ - GLint x = IROUND(ctx->Current.RasterPos[0]); - GLint y = IROUND(ctx->Current.RasterPos[1]); + GLint x = _mesa_lroundevenf(ctx->Current.RasterPos[0]); + GLint y = _mesa_lroundevenf(ctx->Current.RasterPos[1]); if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) { /* unpack from PBO */ @@ -196,13 +197,13 @@ _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height, if (MESA_VERBOSE & VERBOSE_API) _mesa_debug(ctx, - "glCopyPixels(%d, %d, %d, %d, %s) // from %s to %s at %d, %d\n", + "glCopyPixels(%d, %d, %d, %d, %s) // from %s to %s at %ld, %ld\n", srcx, srcy, width, height, _mesa_enum_to_string(type), _mesa_enum_to_string(ctx->ReadBuffer->ColorReadBuffer), _mesa_enum_to_string(ctx->DrawBuffer->ColorDrawBuffer[0]), - IROUND(ctx->Current.RasterPos[0]), - IROUND(ctx->Current.RasterPos[1])); + _mesa_lroundevenf(ctx->Current.RasterPos[0]), + _mesa_lroundevenf(ctx->Current.RasterPos[1])); if (width < 0 || height < 0) { _mesa_error(ctx, GL_INVALID_VALUE, "glCopyPixels(width or height < 0)"); @@ -264,8 +265,8 @@ _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height, if (ctx->RenderMode == GL_RENDER) { /* Round to satisfy conformance tests (matches SGI's OpenGL) */ if (width > 0 && height > 0) { - GLint destx = IROUND(ctx->Current.RasterPos[0]); - GLint desty = IROUND(ctx->Current.RasterPos[1]); + GLint destx = _mesa_lroundevenf(ctx->Current.RasterPos[0]); + GLint desty = _mesa_lroundevenf(ctx->Current.RasterPos[1]); ctx->Driver.CopyPixels( ctx, srcx, srcy, width, height, destx, desty, type ); } diff --git a/src/mesa/main/eval.c b/src/mesa/main/eval.c index 86c8f75a1d25..8d12b8d35876 100644 --- a/src/mesa/main/eval.c +++ b/src/mesa/main/eval.c @@ -44,6 +44,7 @@ #include "macros.h" #include "mtypes.h" #include "main/dispatch.h" +#include "util/rounding.h" /* @@ -704,7 +705,7 @@ _mesa_GetnMapivARB( GLenum target, GLenum query, GLsizei bufSize, GLint *v ) if (bufSize < numBytes) goto overflow; for (i=0;i<n;i++) { - v[i] = IROUND(data[i]); + v[i] = _mesa_lroundevenf(data[i]); } } break; @@ -728,17 +729,17 @@ _mesa_GetnMapivARB( GLenum target, GLenum query, GLsizei bufSize, GLint *v ) numBytes = 2 * sizeof *v; if (bufSize < numBytes) goto overflow; - v[0] = IROUND(map1d->u1); - v[1] = IROUND(map1d->u2); + v[0] = _mesa_lroundevenf(map1d->u1); + v[1] = _mesa_lroundevenf(map1d->u2); } else { numBytes = 4 * sizeof *v; if (bufSize < numBytes) goto overflow; - v[0] = IROUND(map2d->u1); - v[1] = IROUND(map2d->u2); - v[2] = IROUND(map2d->v1); - v[3] = IROUND(map2d->v2); + v[0] = _mesa_lroundevenf(map2d->u1); + v[1] = _mesa_lroundevenf(map2d->u2); + v[2] = _mesa_lroundevenf(map2d->v1); + v[3] = _mesa_lroundevenf(map2d->v2); } break; default: diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c index 307a5ffbd1c6..4be242b1cc4b 100644 --- a/src/mesa/main/get.c +++ b/src/mesa/main/get.c @@ -38,6 +38,7 @@ #include "framebuffer.h" #include "samplerobj.h" #include "stencil.h" +#include "util/rounding.h" /* This is a table driven implemetation of the glGet*v() functions. * The basic idea is that most getters just look up an int somewhere @@ -1527,13 +1528,13 @@ _mesa_GetIntegerv(GLenum pname, GLint *params) break; case TYPE_FLOAT_4: - params[3] = IROUND(((GLfloat *) p)[3]); + params[3] = _mesa_lroundevenf(((GLfloat *) p)[3]); case TYPE_FLOAT_3: - params[2] = IROUND(((GLfloat *) p)[2]); + params[2] = _mesa_lroundevenf(((GLfloat *) p)[2]); case TYPE_FLOAT_2: - params[1] = IROUND(((GLfloat *) p)[1]); + params[1] = _mesa_lroundevenf(((GLfloat *) p)[1]); case TYPE_FLOAT: - params[0] = IROUND(((GLfloat *) p)[0]); + params[0] = _mesa_lroundevenf(((GLfloat *) p)[0]); break; case TYPE_FLOATN_4: @@ -1621,13 +1622,13 @@ _mesa_GetInteger64v(GLenum pname, GLint64 *params) break; case TYPE_FLOAT_4: - params[3] = IROUND64(((GLfloat *) p)[3]); + params[3] = _mesa_llroundevenf(((GLfloat *) p)[3]); case TYPE_FLOAT_3: - params[2] = IROUND64(((GLfloat *) p)[2]); + params[2] = _mesa_llroundevenf(((GLfloat *) p)[2]); case TYPE_FLOAT_2: - params[1] = IROUND64(((GLfloat *) p)[1]); + params[1] = _mesa_llroundevenf(((GLfloat *) p)[1]); case TYPE_FLOAT: - params[0] = IROUND64(((GLfloat *) p)[0]); + params[0] = _mesa_llroundevenf(((GLfloat *) p)[0]); break; case TYPE_FLOATN_4: @@ -2110,22 +2111,22 @@ _mesa_GetIntegeri_v( GLenum pname, GLuint index, GLint *params ) switch (type) { case TYPE_FLOAT_4: case TYPE_FLOATN_4: - params[3] = IROUND(v.value_float_4[3]); + params[3] = _mesa_lroundevenf(v.value_float_4[3]); case TYPE_FLOAT_3: case TYPE_FLOATN_3: - params[2] = IROUND(v.value_float_4[2]); + params[2] = _mesa_lroundevenf(v.value_float_4[2]); case TYPE_FLOAT_2: case TYPE_FLOATN_2: - params[1] = IROUND(v.value_float_4[1]); + params[1] = _mesa_lroundevenf(v.value_float_4[1]); case TYPE_FLOAT: case TYPE_FLOATN: - params[0] = IROUND(v.value_float_4[0]); + params[0] = _mesa_lroundevenf(v.value_float_4[0]); break; case TYPE_DOUBLEN_2: - params[1] = IROUND(v.value_double_2[1]); + params[1] = _mesa_lroundeven(v.value_double_2[1]); case TYPE_DOUBLEN: - params[0] = IROUND(v.value_double_2[0]); + params[0] = _mesa_lroundeven(v.value_double_2[0]); break; case TYPE_INT: diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h index d61279ac4e5a..1d4b9c11f4e6 100644 --- a/src/mesa/main/imports.h +++ b/src/mesa/main/imports.h @@ -144,24 +144,6 @@ static inline GLfloat LOG2(GLfloat x) /** - * Convert float to int by rounding to nearest integer, away from zero. - */ -static inline int IROUND(float f) -{ - return (int) ((f >= 0.0F) ? (f + 0.5F) : (f - 0.5F)); -} - - -/** - * Convert float to int64 by rounding to nearest integer. - */ -static inline GLint64 IROUND64(float f) -{ - return (GLint64) ((f >= 0.0F) ? (f + 0.5F) : (f - 0.5F)); -} - - -/** * Convert positive float to int by rounding to nearest integer. */ static inline int IROUND_POS(float f) diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c index 14b4b04162b0..b539bf287a38 100644 --- a/src/mesa/main/light.c +++ b/src/mesa/main/light.c @@ -34,6 +34,7 @@ #include "util/simple_list.h" #include "mtypes.h" #include "math/m_matrix.h" +#include "util/rounding.h" void GLAPIENTRY @@ -850,12 +851,12 @@ _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params ) params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][3] ); break; case GL_SHININESS: - *params = IROUND( mat[MAT_ATTRIB_SHININESS(f)][0] ); + *params = _mesa_lroundevenf( mat[MAT_ATTRIB_SHININESS(f)][0] ); break; case GL_COLOR_INDEXES: - params[0] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][0] ); - params[1] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][1] ); - params[2] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][2] ); + params[0] = _mesa_lroundevenf( mat[MAT_ATTRIB_INDEXES(f)][0] ); + params[1] = _mesa_lroundevenf( mat[MAT_ATTRIB_INDEXES(f)][1] ); + params[2] = _mesa_lroundevenf( mat[MAT_ATTRIB_INDEXES(f)][2] ); break; default: _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" ); diff --git a/src/mesa/main/pixel.c b/src/mesa/main/pixel.c index 608a5454702e..47c7f50dbb03 100644 --- a/src/mesa/main/pixel.c +++ b/src/mesa/main/pixel.c @@ -114,7 +114,7 @@ store_pixelmap(struct gl_context *ctx, GLenum map, GLsizei mapsize, /* special case */ ctx->PixelMaps.StoS.Size = mapsize; for (i = 0; i < mapsize; i++) { - ctx->PixelMaps.StoS.Map[i] = (GLfloat)IROUND(values[i]); + ctx->PixelMaps.StoS.Map[i] = roundf(values[i]); } break; case GL_PIXEL_MAP_I_TO_I: diff --git a/src/mesa/main/pixelstore.c b/src/mesa/main/pixelstore.c index fc815337b8df..c3c43c53e12a 100644 --- a/src/mesa/main/pixelstore.c +++ b/src/mesa/main/pixelstore.c @@ -33,6 +33,7 @@ #include "context.h" #include "pixelstore.h" #include "mtypes.h" +#include "util/rounding.h" void GLAPIENTRY @@ -223,7 +224,7 @@ invalid_value_error: void GLAPIENTRY _mesa_PixelStoref( GLenum pname, GLfloat param ) { - _mesa_PixelStorei( pname, IROUND(param) ); + _mesa_PixelStorei( pname, _mesa_lroundevenf(param) ); } diff --git a/src/mesa/main/samplerobj.c b/src/mesa/main/samplerobj.c index 32180fb1ba29..9b16e78c9611 100644 --- a/src/mesa/main/samplerobj.c +++ b/src/mesa/main/samplerobj.c @@ -1327,19 +1327,19 @@ _mesa_GetSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params) /* GL spec 'Data Conversions' section specifies that floating-point * value in integer Get function is rounded to nearest integer */ - *params = IROUND(sampObj->MinLod); + *params = _mesa_lroundevenf(sampObj->MinLod); break; case GL_TEXTURE_MAX_LOD: /* GL spec 'Data Conversions' section specifies that floating-point * value in integer Get function is rounded to nearest integer */ - *params = IROUND(sampObj->MaxLod); + *params = _mesa_lroundevenf(sampObj->MaxLod); break; case GL_TEXTURE_LOD_BIAS: /* GL spec 'Data Conversions' section specifies that floating-point * value in integer Get function is rounded to nearest integer */ - *params = IROUND(sampObj->LodBias); + *params = _mesa_lroundevenf(sampObj->LodBias); break; case GL_TEXTURE_COMPARE_MODE: if (!ctx->Extensions.ARB_shadow) @@ -1355,7 +1355,7 @@ _mesa_GetSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params) /* GL spec 'Data Conversions' section specifies that floating-point * value in integer Get function is rounded to nearest integer */ - *params = IROUND(sampObj->MaxAnisotropy); + *params = _mesa_lroundevenf(sampObj->MaxAnisotropy); break; case GL_TEXTURE_BORDER_COLOR: params[0] = FLOAT_TO_INT(sampObj->BorderColor.f[0]); diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c index c0611c3e489e..cc7d8180fcff 100644 --- a/src/mesa/main/texparam.c +++ b/src/mesa/main/texparam.c @@ -1961,7 +1961,7 @@ get_tex_parameteriv(struct gl_context *ctx, /* GL spec 'Data Conversions' section specifies that floating-point * value in integer Get function is rounded to nearest integer */ - *params = IROUND(obj->Sampler.MinLod); + *params = _mesa_lroundevenf(obj->Sampler.MinLod); break; case GL_TEXTURE_MAX_LOD: if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx)) @@ -1969,7 +1969,7 @@ get_tex_parameteriv(struct gl_context *ctx, /* GL spec 'Data Conversions' section specifies that floating-point * value in integer Get function is rounded to nearest integer */ - *params = IROUND(obj->Sampler.MaxLod); + *params = _mesa_lroundevenf(obj->Sampler.MaxLod); break; case GL_TEXTURE_BASE_LEVEL: if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx)) @@ -1986,7 +1986,7 @@ get_tex_parameteriv(struct gl_context *ctx, /* GL spec 'Data Conversions' section specifies that floating-point * value in integer Get function is rounded to nearest integer */ - *params = IROUND(obj->Sampler.MaxAnisotropy); + *params = _mesa_lroundevenf(obj->Sampler.MaxAnisotropy); break; case GL_GENERATE_MIPMAP_SGIS: if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES) @@ -2024,7 +2024,7 @@ get_tex_parameteriv(struct gl_context *ctx, /* GL spec 'Data Conversions' section specifies that floating-point * value in integer Get function is rounded to nearest integer */ - *params = IROUND(obj->Sampler.LodBias); + *params = _mesa_lroundevenf(obj->Sampler.LodBias); break; case GL_TEXTURE_CROP_RECT_OES: if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture) diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp index 036530e91b65..60d9d8113300 100644 --- a/src/mesa/main/uniform_query.cpp +++ b/src/mesa/main/uniform_query.cpp @@ -407,7 +407,7 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location, * a floating-point value is rounded to the * nearest integer..." */ - dst[i].i = IROUND(src[i].f); + dst[i].i = _mesa_lroundevenf(src[i].f); break; case GLSL_TYPE_BOOL: dst[i].i = src[i].i ? 1 : 0; diff --git a/src/mesa/swrast/s_blit.c b/src/mesa/swrast/s_blit.c index 3e838a41d44b..c18a3a9d6d58 100644 --- a/src/mesa/swrast/s_blit.c +++ b/src/mesa/swrast/s_blit.c @@ -31,6 +31,7 @@ #include "main/format_pack.h" #include "main/condrender.h" #include "s_context.h" +#include "util/rounding.h" #define ABS(X) ((X) < 0 ? -(X) : (X)) @@ -296,7 +297,7 @@ blit_nearest(struct gl_context *ctx, for (dstRow = 0; dstRow < dstHeight; dstRow++) { GLfloat srcRowF = (dstRow + 0.5F) / dstHeight * srcHeight - 0.5F; - GLint srcRow = IROUND(srcRowF); + GLint srcRow = _mesa_lroundevenf(srcRowF); GLubyte *dstRowStart = dstMap + dstRowStride * dstRow; assert(srcRow >= 0); diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h index 7cf0e30dc308..2e662a0a48b6 100644 --- a/src/mesa/swrast/s_context.h +++ b/src/mesa/swrast/s_context.h @@ -50,6 +50,7 @@ #include "swrast.h" #include "s_fragprog.h" #include "s_span.h" +#include "util/rounding.h" typedef void (*texture_sample_func)(struct gl_context *ctx, @@ -434,7 +435,7 @@ _swrast_unmap_renderbuffers(struct gl_context *ctx); #define FIXED_EPSILON 1 #define FIXED_SCALE ((float) FIXED_ONE) #define FIXED_DBL_SCALE ((double) FIXED_ONE) -#define FloatToFixed(X) (IROUND((X) * FIXED_SCALE)) +#define FloatToFixed(X) (_mesa_lroundevenf((X) * FIXED_SCALE)) #define FixedToDouble(X) ((X) * (1.0 / FIXED_DBL_SCALE)) #define IntToFixed(I) ((I) << FIXED_SHIFT) #define FixedToInt(X) ((X) >> FIXED_SHIFT) |