*/
#include "glheader.h"
-#include "util/imports.h"
#include "draw_validate.h"
#include "bufferobj.h"
#include "context.h"
#include "glformats.h"
#include "fbobject.h"
#include "util/u_math.h"
+#include "util/rounding.h"
/*
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]));
+ lroundf(ctx->Current.RasterPos[0]),
+ lroundf(ctx->Current.RasterPos[1]));
if (width < 0 || height < 0) {
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 = lroundf(ctx->Current.RasterPos[0]);
+ GLint y = lroundf(ctx->Current.RasterPos[1]);
if (ctx->Unpack.BufferObj) {
/* unpack from PBO */
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]));
+ lroundf(ctx->Current.RasterPos[0]),
+ lroundf(ctx->Current.RasterPos[1]));
if (width < 0 || height < 0) {
_mesa_error(ctx, GL_INVALID_VALUE, "glCopyPixels(width or height < 0)");
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 = lroundf(ctx->Current.RasterPos[0]);
+ GLint desty = lroundf(ctx->Current.RasterPos[1]);
ctx->Driver.CopyPixels( ctx, srcx, srcy, width, height, destx, desty,
type );
}
else if (ctx->RenderMode == GL_FEEDBACK) {
FLUSH_CURRENT( ctx, 0 );
_mesa_feedback_token( ctx, (GLfloat) (GLint) GL_COPY_PIXEL_TOKEN );
- _mesa_feedback_vertex( ctx,
+ _mesa_feedback_vertex( ctx,
ctx->Current.RasterPos,
ctx->Current.RasterColor,
ctx->Current.RasterTexCoords[0] );
#include "glheader.h"
-#include "util/imports.h"
#include "context.h"
#include "eval.h"
#include "macros.h"
GLdouble v1, GLdouble v2, GLint vstride, GLint vorder,
const GLdouble *points )
{
- map2(target, (GLfloat) u1, (GLfloat) u2, ustride, uorder,
+ map2(target, (GLfloat) u1, (GLfloat) u2, ustride, uorder,
(GLfloat) v1, (GLfloat) v2, vstride, vorder, points, GL_DOUBLE);
}
if (bufSize < numBytes)
goto overflow;
for (i=0;i<n;i++) {
- v[i] = IROUND(data[i]);
+ v[i] = lroundf(data[i]);
}
}
break;
numBytes = 2 * sizeof *v;
if (bufSize < numBytes)
goto overflow;
- v[0] = IROUND(map1d->u1);
- v[1] = IROUND(map1d->u2);
+ v[0] = lroundf(map1d->u1);
+ v[1] = lroundf(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] = lroundf(map2d->u1);
+ v[1] = lroundf(map2d->u2);
+ v[2] = lroundf(map2d->v1);
+ v[3] = lroundf(map2d->v2);
}
break;
default:
_mesa_MapGrid2d( GLint un, GLdouble u1, GLdouble u2,
GLint vn, GLdouble v1, GLdouble v2 )
{
- _mesa_MapGrid2f( un, (GLfloat) u1, (GLfloat) u2,
+ _mesa_MapGrid2f( un, (GLfloat) u1, (GLfloat) u2,
vn, (GLfloat) v1, (GLfloat) v2 );
}
/**
- * Initialize a 2-D evaluator map
+ * Initialize a 2-D evaluator map
*/
static void
init_2d_map( struct gl_2d_map *map, int n, const float *initial )
break;
case TYPE_FLOAT_8:
- params[7] = IROUND(((GLfloat *) p)[7]);
- params[6] = IROUND(((GLfloat *) p)[6]);
- params[5] = IROUND(((GLfloat *) p)[5]);
- params[4] = IROUND(((GLfloat *) p)[4]);
+ params[7] = lroundf(((GLfloat *) p)[7]);
+ params[6] = lroundf(((GLfloat *) p)[6]);
+ params[5] = lroundf(((GLfloat *) p)[5]);
+ params[4] = lroundf(((GLfloat *) p)[4]);
case TYPE_FLOAT_4:
- params[3] = IROUND(((GLfloat *) p)[3]);
+ params[3] = lroundf(((GLfloat *) p)[3]);
case TYPE_FLOAT_3:
- params[2] = IROUND(((GLfloat *) p)[2]);
+ params[2] = lroundf(((GLfloat *) p)[2]);
case TYPE_FLOAT_2:
- params[1] = IROUND(((GLfloat *) p)[1]);
+ params[1] = lroundf(((GLfloat *) p)[1]);
case TYPE_FLOAT:
- params[0] = IROUND(((GLfloat *) p)[0]);
+ params[0] = lroundf(((GLfloat *) p)[0]);
break;
case TYPE_FLOATN_4:
break;
case TYPE_FLOAT_8:
- params[7] = IROUND64(((GLfloat *) p)[7]);
- params[6] = IROUND64(((GLfloat *) p)[6]);
- params[5] = IROUND64(((GLfloat *) p)[5]);
- params[4] = IROUND64(((GLfloat *) p)[4]);
+ params[7] = llround(((GLfloat *) p)[7]);
+ params[6] = llround(((GLfloat *) p)[6]);
+ params[5] = llround(((GLfloat *) p)[5]);
+ params[4] = llround(((GLfloat *) p)[4]);
case TYPE_FLOAT_4:
- params[3] = IROUND64(((GLfloat *) p)[3]);
+ params[3] = llround(((GLfloat *) p)[3]);
case TYPE_FLOAT_3:
- params[2] = IROUND64(((GLfloat *) p)[2]);
+ params[2] = llround(((GLfloat *) p)[2]);
case TYPE_FLOAT_2:
- params[1] = IROUND64(((GLfloat *) p)[1]);
+ params[1] = llround(((GLfloat *) p)[1]);
case TYPE_FLOAT:
- params[0] = IROUND64(((GLfloat *) p)[0]);
+ params[0] = llround(((GLfloat *) p)[0]);
break;
case TYPE_FLOATN_4:
switch (type) {
case TYPE_FLOAT_4:
case TYPE_FLOATN_4:
- params[3] = IROUND(v.value_float_4[3]);
+ params[3] = lroundf(v.value_float_4[3]);
case TYPE_FLOAT_3:
case TYPE_FLOATN_3:
- params[2] = IROUND(v.value_float_4[2]);
+ params[2] = lroundf(v.value_float_4[2]);
case TYPE_FLOAT_2:
case TYPE_FLOATN_2:
- params[1] = IROUND(v.value_float_4[1]);
+ params[1] = lroundf(v.value_float_4[1]);
case TYPE_FLOAT:
case TYPE_FLOATN:
- params[0] = IROUND(v.value_float_4[0]);
+ params[0] = lroundf(v.value_float_4[0]);
break;
case TYPE_DOUBLEN_2:
- params[1] = IROUND(v.value_double_2[1]);
+ params[1] = lroundf(v.value_double_2[1]);
case TYPE_DOUBLEN:
- params[0] = IROUND(v.value_double_2[0]);
+ params[0] = lroundf(v.value_double_2[0]);
break;
case TYPE_INT:
#include "c99_math.h"
#include "glheader.h"
-#include "util/imports.h"
#include "context.h"
#include "enums.h"
#include "light.h"
{
GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
- if (MESA_VERBOSE & VERBOSE_MATERIAL)
+ if (MESA_VERBOSE & VERBOSE_MATERIAL)
_mesa_debug(ctx, "_mesa_update_material, mask 0x%x\n", bitmask);
if (!bitmask)
while (mask) {
const int i = u_bit_scan(&mask);
struct gl_light *light = &ctx->Light.Light[i];
- SCALE_3V( light->_MatAmbient[0], light->Ambient,
+ SCALE_3V( light->_MatAmbient[0], light->Ambient,
mat[MAT_ATTRIB_FRONT_AMBIENT]);
}
}
while (mask) {
const int i = u_bit_scan(&mask);
struct gl_light *light = &ctx->Light.Light[i];
- SCALE_3V( light->_MatAmbient[1], light->Ambient,
+ SCALE_3V( light->_MatAmbient[1], light->Ambient,
mat[MAT_ATTRIB_BACK_AMBIENT]);
}
}
while (mask) {
const int i = u_bit_scan(&mask);
struct gl_light *light = &ctx->Light.Light[i];
- SCALE_3V( light->_MatDiffuse[0], light->Diffuse,
+ SCALE_3V( light->_MatDiffuse[0], light->Diffuse,
mat[MAT_ATTRIB_FRONT_DIFFUSE] );
}
}
while (mask) {
const int i = u_bit_scan(&mask);
struct gl_light *light = &ctx->Light.Light[i];
- SCALE_3V( light->_MatDiffuse[1], light->Diffuse,
+ SCALE_3V( light->_MatDiffuse[1], light->Diffuse,
mat[MAT_ATTRIB_BACK_DIFFUSE] );
}
}
while (mask) {
const int i = u_bit_scan(&mask);
struct gl_light *light = &ctx->Light.Light[i];
- SCALE_3V( light->_MatSpecular[0], light->Specular,
+ SCALE_3V( light->_MatSpecular[0], light->Specular,
mat[MAT_ATTRIB_FRONT_SPECULAR]);
}
}
params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][3] );
break;
case GL_SHININESS:
- *params = IROUND( mat[MAT_ATTRIB_SHININESS(f)][0] );
+ *params = lroundf( 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] = lroundf( mat[MAT_ATTRIB_INDEXES(f)][0] );
+ params[1] = lroundf( mat[MAT_ATTRIB_INDEXES(f)][1] );
+ params[2] = lroundf( mat[MAT_ATTRIB_INDEXES(f)][2] );
break;
default:
_mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" );
* Initialize the n-th light data structure.
*
* \param l pointer to the gl_light structure to be initialized.
- * \param n number of the light.
+ * \param n number of the light.
* \note The defaults for light 0 are different than the other lights.
*/
static void
/**
* Initialize the material data structure.
- *
+ *
* \param m pointer to the gl_material structure to be initialized.
*/
static void
ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_EMISSION], 0.0F, 0.0F, 0.0F, 1.0F );
ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_SHININESS], 0.0F, 0.0F, 0.0F, 0.0F );
ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_INDEXES], 0.0F, 1.0F, 1.0F, 0.0F );
-
+
ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_AMBIENT], 0.2F, 0.2F, 0.2F, 1.0F );
ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_DIFFUSE], 0.8F, 0.8F, 0.8F, 1.0F );
ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_SPECULAR], 0.0F, 0.0F, 0.0F, 1.0F );
* Pixel transfer functions (glPixelZoom, glPixelMap, glPixelTransfer)
*/
+#include "c99_math.h"
#include "glheader.h"
#include "bufferobj.h"
#include "context.h"
/* 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:
#include "context.h"
#include "pixelstore.h"
#include "mtypes.h"
+#include "util/rounding.h"
static ALWAYS_INLINE void
void GLAPIENTRY
_mesa_PixelStoref(GLenum pname, GLfloat param)
{
- _mesa_PixelStorei(pname, IROUND(param));
+ _mesa_PixelStorei(pname, lroundf(param));
}
void GLAPIENTRY
_mesa_PixelStoref_no_error(GLenum pname, GLfloat param)
{
- _mesa_PixelStorei_no_error(pname, IROUND(param));
+ _mesa_PixelStorei_no_error(pname, lroundf(param));
}
GLuint j;
struct gl_sampler_object *sampObj =
lookup_samplerobj_locked(ctx, samplers[i]);
-
+
if (sampObj) {
/* If the sampler is currently bound, unbind it. */
for (j = 0; j < ctx->Const.MaxCombinedTextureImageUnits; j++) {
return;
}
}
-
+
/* bind new sampler */
_mesa_bind_sampler(ctx, unit, sampObj);
}
* Check if a coordinate wrap mode is legal.
* \return GL_TRUE if legal, GL_FALSE otherwise
*/
-static GLboolean
+static GLboolean
validate_texture_wrap_mode(struct gl_context *ctx, GLenum wrap)
{
const struct gl_extensions * const e = &ctx->Extensions;
/* GL spec 'Data Conversions' section specifies that floating-point
* value in integer Get function is rounded to nearest integer
*/
- *params = IROUND(sampObj->MinLod);
+ *params = lroundf(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 = lroundf(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 = lroundf(sampObj->LodBias);
break;
case GL_TEXTURE_COMPARE_MODE:
*params = sampObj->CompareMode;
/* GL spec 'Data Conversions' section specifies that floating-point
* value in integer Get function is rounded to nearest integer
*/
- *params = IROUND(sampObj->MaxAnisotropy);
+ *params = lroundf(sampObj->MaxAnisotropy);
break;
case GL_TEXTURE_BORDER_COLOR:
params[0] = FLOAT_TO_INT(sampObj->BorderColor.f[0]);
}
if (*params == 0 && pname == GL_TEXTURE_INTENSITY_SIZE) {
/* Gallium may store intensity as LA */
- *params = _mesa_get_format_bits(texFormat,
+ *params = _mesa_get_format_bits(texFormat,
GL_TEXTURE_ALPHA_SIZE);
}
}
/* 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 = lroundf(obj->Sampler.MinLod);
break;
case GL_TEXTURE_MAX_LOD:
if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(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 = lroundf(obj->Sampler.MaxLod);
break;
case GL_TEXTURE_BASE_LEVEL:
if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(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 = lroundf(obj->Sampler.MaxAnisotropy);
break;
case GL_GENERATE_MIPMAP_SGIS:
if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
/* 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 = lroundf(obj->Sampler.LodBias);
break;
case GL_TEXTURE_CROP_RECT_OES:
if (ctx->API != API_OPENGLES || !ctx->Extensions.OES_draw_texture)
for (dstRow = 0; dstRow < dstHeight; dstRow++) {
GLfloat srcRowF = (dstRow + 0.5F) / dstHeight * srcHeight - 0.5F;
- GLint srcRow = IROUND(srcRowF);
+ GLint srcRow = lroundf(srcRowF);
GLubyte *dstRowStart = dstMap + dstRowStride * dstRow;
assert(srcRow >= 0);
alpha = lerp_2d(colWeight, rowWeight,
srcColor0[srcCol0][ACOMP], srcColor0[srcCol1][ACOMP],
srcColor1[srcCol0][ACOMP], srcColor1[srcCol1][ACOMP]);
-
+
dstColor[dstCol][RCOMP] = util_ifloor(red);
dstColor[dstCol][GCOMP] = util_ifloor(green);
dstColor[dstCol][BCOMP] = util_ifloor(blue);
alpha = lerp_2d(colWeight, rowWeight,
srcColor0[srcCol0][ACOMP], srcColor0[srcCol1][ACOMP],
srcColor1[srcCol0][ACOMP], srcColor1[srcCol1][ACOMP]);
-
+
dstColor[dstCol][RCOMP] = red;
dstColor[dstCol][GCOMP] = green;
dstColor[dstCol][BCOMP] = blue;
#include "swrast.h"
#include "s_fragprog.h"
#include "s_span.h"
+#include "util/rounding.h"
typedef void (*texture_sample_func)(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) (lroundf((X) * FIXED_SCALE))
#define FixedToDouble(X) ((X) * (1.0 / FIXED_DBL_SCALE))
#define IntToFixed(I) ((I) << FIXED_SHIFT)
#define FixedToInt(X) ((X) >> FIXED_SHIFT)
#endif
-/**
- * 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 int64_t IROUND64(float f)
-{
- return (int64_t) ((f >= 0.0F) ? (f + 0.5F) : (f - 0.5F));
-}
-
-
/**********************************************************************
* Functions
*/
#endif
}
+
/**
* \brief Rounds \c x to the nearest integer, with ties to the even integer,
* and returns the value as a long int.