Clean-up of color conversion macros.
New mmath.h macros (IROUND, IFLOOR, ICEIL, FRAC) used in various places.
#include "tnl/t_pipeline.h"
+
+float gl_ubyte_to_float_255_color_tab[256];
+
/* These lookup table are used to extract RGB values in [0,255] from
* 16-bit pixel values.
*/
int fxDDInitFxMesaContext( fxMesaContext fxMesa )
{
+ int i;
static int firsttime = 1;
+ for (i = 0 ; i < 256 ; i++) {
+ gl_ubyte_to_float_255_color_tab[i] = (float) i;
+ }
+
if (firsttime) {
fxDDSetupInit();
fxDDTrifuncInit();
#define T1COORD GR_VERTEX_TOW_TMU1_OFFSET
+extern float gl_ubyte_to_float_255_color_tab[256];
+#define UBYTE_COLOR_TO_FLOAT_255_COLOR(c) gl_ubyte_to_float_255_color_tab[c]
+#define UBYTE_COLOR_TO_FLOAT_255_COLOR2(f,c) \
+ (*(int *)&(f)) = ((int *)gl_ubyte_to_float_255_color_tab)[c]
+
+
+#define LINTERP(T, A, B) ((A) + (T) * ((B) - (A)))
+
+
+
/* Should have size == 16 * sizeof(float).
*/
typedef union {
-/* $Id: osmesa.c,v 1.35 2000/12/26 05:09:30 keithw Exp $ */
+/* $Id: osmesa.c,v 1.36 2001/01/02 22:02:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "macros.h"
#include "mem.h"
#include "matrix.h"
+#include "mmath.h"
#include "mtypes.h"
#include "extensions.h"
#include "swrast/swrast.h"
-/* $Id: xm_line.c,v 1.13 2000/12/13 16:24:40 brianp Exp $ */
+/* $Id: xm_line.c,v 1.14 2001/01/02 22:02:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "glxheader.h"
#include "depth.h"
#include "macros.h"
+#include "mmath.h"
#include "mtypes.h"
#include "xmesaP.h"
-/* $Id: xm_tri.c,v 1.14 2000/12/13 16:24:39 brianp Exp $ */
+/* $Id: xm_tri.c,v 1.15 2001/01/02 22:02:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "glxheader.h"
#include "depth.h"
#include "macros.h"
+#include "mmath.h"
#include "mtypes.h"
#include "xmesaP.h"
-/* $Id: api_loopback.c,v 1.4 2000/12/26 05:09:27 keithw Exp $ */
+/* $Id: api_loopback.c,v 1.5 2001/01/02 22:02:51 brianp Exp $ */
/*
* Mesa 3-D graphics library
GLfloat r = red;
GLfloat g = green;
GLfloat b = blue;
- FLOAT_COLOR_TO_UBYTE_COLOR(col[0], r);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[1], g);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[2], b);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[0], r);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[1], g);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[2], b);
col[3] = 255;
COLORUBV( col );
}
GLfloat g = green;
GLfloat b = blue;
GLfloat a = alpha;
- FLOAT_COLOR_TO_UBYTE_COLOR(col[0], r);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[1], g);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[2], b);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[3], a);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[0], r);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[1], g);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[2], b);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[3], a);
COLORUBV( col );
}
GLfloat r = red;
GLfloat g = green;
GLfloat b = blue;
- FLOAT_COLOR_TO_UBYTE_COLOR(col[0], r);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[1], g);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[2], b);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[0], r);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[1], g);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[2], b);
SECONDARYCOLORUB( col[0], col[1], col[2] );
}
static void
loopback_SecondaryColor3bvEXT( const GLbyte *v )
{
- SECONDARYCOLORUB(BYTE_TO_UBYTE(v[0]),
- BYTE_TO_UBYTE(v[1]),
- BYTE_TO_UBYTE(v[2]));
+ const GLfloat r = BYTE_TO_FLOAT(v[0]);
+ const GLfloat g = BYTE_TO_FLOAT(v[1]);
+ const GLfloat b = BYTE_TO_FLOAT(v[2]);
+ SECONDARYCOLORF(r, g, b);
}
static void
GLfloat r = v[0];
GLfloat g = v[1];
GLfloat b = v[2];
- FLOAT_COLOR_TO_UBYTE_COLOR(col[0], r);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[1], g);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[2], b);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[0], r);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[1], g);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[2], b);
SECONDARYCOLORUB( col[0], col[1], col[2] );
}
{
GET_CURRENT_CONTEXT(ctx);
GLubyte *color = ctx->Current.Color;
- FLOAT_COLOR_TO_UBYTE_COLOR(color[0], a);
- FLOAT_COLOR_TO_UBYTE_COLOR(color[1], b);
- FLOAT_COLOR_TO_UBYTE_COLOR(color[2], c);
- FLOAT_COLOR_TO_UBYTE_COLOR(color[3], d);
+ UNCLAMPED_FLOAT_TO_UBYTE(color[0], a);
+ UNCLAMPED_FLOAT_TO_UBYTE(color[1], b);
+ UNCLAMPED_FLOAT_TO_UBYTE(color[2], c);
+ UNCLAMPED_FLOAT_TO_UBYTE(color[3], d);
}
void _mesa_noop_Color4fv( const GLfloat *v )
{
GET_CURRENT_CONTEXT(ctx);
GLubyte *color = ctx->Current.Color;
- FLOAT_RGBA_TO_CHAN_RGBA( color, v );
+ UNCLAMPED_FLOAT_TO_CHAN(color[0], v[0]);
+ UNCLAMPED_FLOAT_TO_CHAN(color[1], v[1]);
+ UNCLAMPED_FLOAT_TO_CHAN(color[2], v[2]);
}
void _mesa_noop_Color3ub( GLubyte a, GLubyte b, GLubyte c )
{
GET_CURRENT_CONTEXT(ctx);
GLubyte *color = ctx->Current.Color;
- FLOAT_COLOR_TO_UBYTE_COLOR(color[0], a);
- FLOAT_COLOR_TO_UBYTE_COLOR(color[1], b);
- FLOAT_COLOR_TO_UBYTE_COLOR(color[2], c);
+ UNCLAMPED_FLOAT_TO_UBYTE(color[0], a);
+ UNCLAMPED_FLOAT_TO_UBYTE(color[1], b);
+ UNCLAMPED_FLOAT_TO_UBYTE(color[2], c);
color[3] = 255;
}
{
GET_CURRENT_CONTEXT(ctx);
GLubyte *color = ctx->Current.Color;
- FLOAT_RGB_TO_CHAN_RGB( color, v );
+ UNCLAMPED_FLOAT_TO_CHAN(color[0], v[0]);
+ UNCLAMPED_FLOAT_TO_CHAN(color[1], v[1]);
+ UNCLAMPED_FLOAT_TO_CHAN(color[2], v[2]);
color[3] = 255;
}
{
GET_CURRENT_CONTEXT(ctx);
GLubyte *color = ctx->Current.SecondaryColor;
- FLOAT_COLOR_TO_UBYTE_COLOR(color[0], a);
- FLOAT_COLOR_TO_UBYTE_COLOR(color[1], b);
- FLOAT_COLOR_TO_UBYTE_COLOR(color[2], c);
+ UNCLAMPED_FLOAT_TO_UBYTE(color[0], a);
+ UNCLAMPED_FLOAT_TO_UBYTE(color[1], b);
+ UNCLAMPED_FLOAT_TO_UBYTE(color[2], c);
color[3] = 255;
}
{
GET_CURRENT_CONTEXT(ctx);
GLubyte *color = ctx->Current.SecondaryColor;
- FLOAT_RGB_TO_CHAN_RGB( color, v );
+ UNCLAMPED_FLOAT_TO_CHAN(color[0], v[0]);
+ UNCLAMPED_FLOAT_TO_CHAN(color[1], v[1]);
+ UNCLAMPED_FLOAT_TO_CHAN(color[2], v[2]);
color[3] = 255;
}
-/* $Id: colormac.h,v 1.4 2000/11/24 10:25:05 keithw Exp $ */
+/* $Id: colormac.h,v 1.5 2001/01/02 22:02:51 brianp Exp $ */
/*
* Mesa 3-D graphics library
*/
-/*
- * Integer / float conversion for colors, normals, etc.
- */
-
-#define BYTE_TO_UBYTE(b) (b < 0 ? 0 : (GLubyte) b)
-#define SHORT_TO_UBYTE(s) (s < 0 ? 0 : (GLubyte) (s >> 7))
-#define USHORT_TO_UBYTE(s) (GLubyte) (s >> 8)
-#define INT_TO_UBYTE(i) (i < 0 ? 0 : (GLubyte) (i >> 23))
-#define UINT_TO_UBYTE(i) (GLubyte) (i >> 24)
-
-/* Convert GLfloat in [0.0,1.0] to GLubyte in [0,255] */
-#define FLOAT_TO_UBYTE(X) ((GLubyte) (GLint) (((X)) * 255.0F))
-
-
-/* Convert GLbyte in [-128,127] to GLfloat in [-1.0,1.0] */
-#define BYTE_TO_FLOAT(B) ((2.0F * (B) + 1.0F) * (1.0F/255.0F))
-
-/* Convert GLfloat in [-1.0,1.0] to GLbyte in [-128,127] */
-#define FLOAT_TO_BYTE(X) ( (((GLint) (255.0F * (X))) - 1) / 2 )
-
-
-/* Convert GLushort in [0,65536] to GLfloat in [0.0,1.0] */
-#define USHORT_TO_FLOAT(S) ((GLfloat) (S) * (1.0F / 65535.0F))
-
-/* Convert GLfloat in [0.0,1.0] to GLushort in [0,65536] */
-#define FLOAT_TO_USHORT(X) ((GLushort) (GLint) ((X) * 65535.0F))
-
-
-/* Convert GLshort in [-32768,32767] to GLfloat in [-1.0,1.0] */
-#define SHORT_TO_FLOAT(S) ((2.0F * (S) + 1.0F) * (1.0F/65535.0F))
-
-/* Convert GLfloat in [0.0,1.0] to GLshort in [-32768,32767] */
-#define FLOAT_TO_SHORT(X) ( (((GLint) (65535.0F * (X))) - 1) / 2 )
-
-
-/* Convert GLuint in [0,4294967295] to GLfloat in [0.0,1.0] */
-#define UINT_TO_FLOAT(U) ((GLfloat) (U) * (1.0F / 4294967295.0F))
-
-/* Convert GLfloat in [0.0,1.0] to GLuint in [0,4294967295] */
-#define FLOAT_TO_UINT(X) ((GLuint) ((X) * 4294967295.0))
-
-
-/* Convert GLint in [-2147483648,2147483647] to GLfloat in [-1.0,1.0] */
-#define INT_TO_FLOAT(I) ((2.0F * (I) + 1.0F) * (1.0F/4294967294.0F))
-
-/* Convert GLfloat in [-1.0,1.0] to GLint in [-2147483648,2147483647] */
-/* causes overflow:
-#define FLOAT_TO_INT(X) ( (((GLint) (4294967294.0F * (X))) - 1) / 2 )
-*/
-/* a close approximation: */
-#define FLOAT_TO_INT(X) ( (GLint) (2147483647.0 * (X)) )
-
-
-
#if CHAN_BITS == 8
#define BYTE_TO_CHAN(b) ((b) < 0 ? 0 : (GLchan) (b))
#define UINT_TO_CHAN(i) ((GLchan) ((i) >> 24))
#define CHAN_TO_FLOAT(c) UBYTE_TO_FLOAT(c)
+#define FLOAT_TO_CHAN(f) ( (GLchan) IROUND((f) * CHAN_MAXF) )
-#define FLOAT_COLOR_TO_CHAN(c, f) FLOAT_COLOR_TO_UBYTE_COLOR(c, f)
+#define CLAMPED_FLOAT_TO_CHAN(c, f) CLAMPED_FLOAT_TO_UBYTE(c, f)
+#define UNCLAMPED_FLOAT_TO_CHAN(c, f) UNCLAMPED_FLOAT_TO_UBYTE(c, f)
#define COPY_CHAN4(DST, SRC) COPY_4UBV(DST, SRC)
-#define CHAN_PRODUCT(a, b) ( (GLubyte) (((GLint)(a) * ((GLint)(b) + 1)) >> 8) )
+#define CHAN_PRODUCT(a, b) ((GLubyte) (((GLint)(a) * ((GLint)(b) + 1)) >> 8))
+
#elif CHAN_BITS == 16
#define INT_TO_CHAN(i) ((i) < 0 ? 0 : (GLchan) ((i) >> 15))
#define UINT_TO_CHAN(i) ((GLchan) ((i) >> 16))
-#define CHAN_TO_FLOAT(c) ((GLfloat) ((c) * (1.0 / CHAN_MAXF)))
+#define CHAN_TO_FLOAT(c) ((GLfloat) ((c) * (1.0 / CHAN_MAXF) + 0.5F))
+#define FLOAT_TO_CHAN(f) ((GLchan) IROUND((f) * CHAN_MAXF))
-#define FLOAT_COLOR_TO_CHAN(c, f) \
- c = ((GLchan) FloatToInt(CLAMP(f, 0.0F, 1.0F) * CHAN_MAXF + 0.5F))
+#define CLAMPED_FLOAT_TO_CHAN(c, f) \
+ c = ((GLchan) IROUND((f) * CHAN_MAXF))
+#define UNCLAMPED_FLOAT_TO_CHAN(c, f) \
+ c = ( (GLchan) IROUND( CLAMP(f, 0.0, 1.0) * CHAN_MAXF) )
#define COPY_CHAN4(DST, SRC) COPY_4V(DST, SRC)
-#define CHAN_PRODUCT(a, b) ( (GLchan) ((((GLint) (a)) * ((GLint) (b))) / 65535) )
+#define CHAN_PRODUCT(a, b) ((GLchan) ((((GLint) (a)) * ((GLint) (b))) / 65535))
+
#elif CHAN_BITS == 32
#define UINT_TO_CHAN(i) ((GLfloat) ((i) * (1.0F / 4294967295.0F)))
#define CHAN_TO_FLOAT(c) (c)
+#define FLOAT_TO_CHAN(f) (f)
-#define FLOAT_COLOR_TO_CHAN(c, f) c = f
+#define CLAMPED_FLOAT_COLOR_TO_CHAN(c, f) c = (f)
+#define UNCLAMPED_FLOAT_TO_CHAN(c, f) c = (f)
#define COPY_CHAN4(DST, SRC) COPY_4V(DST, SRC)
#endif
-#define FLOAT_RGB_TO_CHAN_RGB(dst, f) \
-do { \
- FLOAT_COLOR_TO_CHAN(dst[0], f[0]); \
- FLOAT_COLOR_TO_CHAN(dst[1], f[1]); \
- FLOAT_COLOR_TO_CHAN(dst[2], f[2]); \
-} while(0)
-#define FLOAT_RGBA_TO_CHAN_RGBA(c, f) \
+/*
+ * Convert 3 channels at once.
+ */
+#define FLOAT_RGB_TO_CHAN_RGB(dst, f) \
do { \
- FLOAT_COLOR_TO_CHAN(c[0], f[0]); \
- FLOAT_COLOR_TO_CHAN(c[1], f[1]); \
- FLOAT_COLOR_TO_CHAN(c[2], f[2]); \
- FLOAT_COLOR_TO_CHAN(c[3], f[3]); \
+ UNCLAMPED_FLOAT_TO_CHAN(dst[0], f[0]); \
+ UNCLAMPED_FLOAT_TO_CHAN(dst[1], f[1]); \
+ UNCLAMPED_FLOAT_TO_CHAN(dst[2], f[2]); \
} while(0)
-#if CHAN_BITS == 32
-
-#define FLOAT_TO_CHAN(f) (f)
-#define DOUBLE_TO_CHAN(f) ((GLfloat) (f))
-#define UNCLAMPED_FLOAT_TO_CHAN(f) (f)
-#define UNCLAMPED_DOUBLE_TO_CHAN(f) ((GLfloat) (f))
-
-#else
-
-#define FLOAT_TO_CHAN(f) ( (GLchan) FloatToInt((f) * CHAN_MAXF + 0.5F) )
-#define DOUBLE_TO_CHAN(f) ( (GLchan) FloatToInt((f) * CHAN_MAXF + 0.5F) )
-
-#define UNCLAMPED_FLOAT_TO_CHAN(f) \
- ( (GLchan) FloatToInt( CLAMP(f, 0.0, 1.0) * CHAN_MAXF + 0.5F) )
-
-#define UNCLAMPED_DOUBLE_TO_CHAN(f) \
- ( (GLchan) FloatToInt( CLAMP(f, 0.0, 1.0) * CHAN_MAXF + 0.5F) )
-
-#endif
-
-
#endif /* COLORMAC_H */
-/* $Id: get.c,v 1.48 2000/12/26 05:09:28 keithw Exp $ */
+/* $Id: get.c,v 1.49 2001/01/02 22:02:51 brianp Exp $ */
/*
* Mesa 3-D graphics library
break;
case GL_CURRENT_SECONDARY_COLOR_EXT:
FLUSH_CURRENT(ctx, 0);
- params[0] = UBYTE_COLOR_TO_FLOAT_COLOR(ctx->Current.SecondaryColor[0]);
- params[1] = UBYTE_COLOR_TO_FLOAT_COLOR(ctx->Current.SecondaryColor[1]);
- params[2] = UBYTE_COLOR_TO_FLOAT_COLOR(ctx->Current.SecondaryColor[2]);
+ params[0] = CHAN_TO_FLOAT(ctx->Current.SecondaryColor[0]);
+ params[1] = CHAN_TO_FLOAT(ctx->Current.SecondaryColor[1]);
+ params[2] = CHAN_TO_FLOAT(ctx->Current.SecondaryColor[2]);
break;
case GL_SECONDARY_COLOR_ARRAY_EXT:
*params = (GLdouble) ctx->Array.SecondaryColor.Enabled;
break;
case GL_CURRENT_SECONDARY_COLOR_EXT:
FLUSH_CURRENT(ctx, 0);
- params[0] = UBYTE_COLOR_TO_FLOAT_COLOR(ctx->Current.SecondaryColor[0]);
- params[1] = UBYTE_COLOR_TO_FLOAT_COLOR(ctx->Current.SecondaryColor[1]);
- params[2] = UBYTE_COLOR_TO_FLOAT_COLOR(ctx->Current.SecondaryColor[2]);
+ params[0] = CHAN_TO_FLOAT(ctx->Current.SecondaryColor[0]);
+ params[1] = CHAN_TO_FLOAT(ctx->Current.SecondaryColor[1]);
+ params[2] = CHAN_TO_FLOAT(ctx->Current.SecondaryColor[2]);
break;
case GL_SECONDARY_COLOR_ARRAY_EXT:
*params = (GLfloat) ctx->Array.SecondaryColor.Enabled;
break;
case GL_CURRENT_SECONDARY_COLOR_EXT:
FLUSH_CURRENT(ctx, 0);
- params[0] = FLOAT_TO_INT( UBYTE_COLOR_TO_FLOAT_COLOR( ctx->Current.SecondaryColor[0] ) );
- params[1] = FLOAT_TO_INT( UBYTE_COLOR_TO_FLOAT_COLOR( ctx->Current.SecondaryColor[1] ) );
- params[2] = FLOAT_TO_INT( UBYTE_COLOR_TO_FLOAT_COLOR( ctx->Current.SecondaryColor[2] ) );
+ params[0] = FLOAT_TO_INT( CHAN_TO_FLOAT(ctx->Current.SecondaryColor[0]) );
+ params[1] = FLOAT_TO_INT( CHAN_TO_FLOAT(ctx->Current.SecondaryColor[1]) );
+ params[2] = FLOAT_TO_INT( CHAN_TO_FLOAT(ctx->Current.SecondaryColor[2]) );
break;
case GL_SECONDARY_COLOR_ARRAY_EXT:
*params = (GLint) ctx->Array.SecondaryColor.Enabled;
-/* $Id: image.c,v 1.50 2000/11/28 00:07:51 brianp Exp $ */
+/* $Id: image.c,v 1.51 2001/01/02 22:02:51 brianp Exp $ */
/*
* Mesa 3-D graphics library
GLuint i;
for (i = 0; i < n; i ++) {
GLuint p = uisrc[i];
- rgba[i][rComp] = UBYTE_COLOR_TO_FLOAT_COLOR((p ) & 0xff);
- rgba[i][gComp] = UBYTE_COLOR_TO_FLOAT_COLOR((p >> 8) & 0xff);
- rgba[i][bComp] = UBYTE_COLOR_TO_FLOAT_COLOR((p >> 16) & 0xff);
- rgba[i][aComp] = UBYTE_COLOR_TO_FLOAT_COLOR((p >> 24) );
+ rgba[i][rComp] = UBYTE_TO_FLOAT((p ) & 0xff);
+ rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff);
+ rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff);
+ rgba[i][aComp] = UBYTE_TO_FLOAT((p >> 24) );
}
}
else {
GLuint i;
for (i = 0; i < n; i ++) {
GLuint p = uisrc[i];
- rgba[i][rComp] = UBYTE_COLOR_TO_FLOAT_COLOR((p >> 24) );
- rgba[i][gComp] = UBYTE_COLOR_TO_FLOAT_COLOR((p >> 16) & 0xff);
- rgba[i][bComp] = UBYTE_COLOR_TO_FLOAT_COLOR((p >> 8) & 0xff);
- rgba[i][aComp] = UBYTE_COLOR_TO_FLOAT_COLOR((p ) & 0xff);
+ rgba[i][rComp] = UBYTE_TO_FLOAT((p >> 24) );
+ rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff);
+ rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff);
+ rgba[i][aComp] = UBYTE_TO_FLOAT((p ) & 0xff);
}
}
break;
GLuint i;
for (i = 0; i < n; i ++) {
GLuint p = uisrc[i];
- rgba[i][rComp] = UBYTE_COLOR_TO_FLOAT_COLOR((p >> 24) );
- rgba[i][gComp] = UBYTE_COLOR_TO_FLOAT_COLOR((p >> 16) & 0xff);
- rgba[i][bComp] = UBYTE_COLOR_TO_FLOAT_COLOR((p >> 8) & 0xff);
- rgba[i][aComp] = UBYTE_COLOR_TO_FLOAT_COLOR((p ) & 0xff);
+ rgba[i][rComp] = UBYTE_TO_FLOAT((p >> 24) );
+ rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff);
+ rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff);
+ rgba[i][aComp] = UBYTE_TO_FLOAT((p ) & 0xff);
}
}
else {
GLuint i;
for (i = 0; i < n; i ++) {
GLuint p = uisrc[i];
- rgba[i][rComp] = UBYTE_COLOR_TO_FLOAT_COLOR((p ) & 0xff);
- rgba[i][gComp] = UBYTE_COLOR_TO_FLOAT_COLOR((p >> 8) & 0xff);
- rgba[i][bComp] = UBYTE_COLOR_TO_FLOAT_COLOR((p >> 16) & 0xff);
- rgba[i][aComp] = UBYTE_COLOR_TO_FLOAT_COLOR((p >> 24) );
+ rgba[i][rComp] = UBYTE_TO_FLOAT((p ) & 0xff);
+ rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff);
+ rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff);
+ rgba[i][aComp] = UBYTE_TO_FLOAT((p >> 24) );
}
}
break;
-/* $Id: light.c,v 1.31 2000/12/26 05:09:28 keithw Exp $ */
+/* $Id: light.c,v 1.32 2001/01/02 22:02:51 brianp Exp $ */
/*
* Mesa 3-D graphics library
foreach (light, list) {
SCALE_3V( light->_MatDiffuse[0], light->Diffuse, mat->Diffuse );
}
- FLOAT_COLOR_TO_CHAN(ctx->Light._BaseAlpha[0], mat->Diffuse[3]);
+ UNCLAMPED_FLOAT_TO_CHAN(ctx->Light._BaseAlpha[0], mat->Diffuse[3]);
}
if (bitmask & BACK_DIFFUSE_BIT) {
struct gl_material *mat = &ctx->Light.Material[1];
foreach (light, list) {
SCALE_3V( light->_MatDiffuse[1], light->Diffuse, mat->Diffuse );
}
- FLOAT_COLOR_TO_CHAN(ctx->Light._BaseAlpha[1], mat->Diffuse[3]);
+ UNCLAMPED_FLOAT_TO_CHAN(ctx->Light._BaseAlpha[1], mat->Diffuse[3]);
}
/* update material specular values */
foreach (light, list) {
SCALE_3V( light->_MatDiffuse[0], light->Diffuse, mat->Diffuse );
}
- FLOAT_COLOR_TO_CHAN(ctx->Light._BaseAlpha[0], mat->Diffuse[3]);
+ UNCLAMPED_FLOAT_TO_CHAN(ctx->Light._BaseAlpha[0], mat->Diffuse[3]);
}
if (bitmask & BACK_DIFFUSE_BIT) {
foreach (light, list) {
SCALE_3V( light->_MatDiffuse[1], light->Diffuse, mat->Diffuse );
}
- FLOAT_COLOR_TO_CHAN(ctx->Light._BaseAlpha[1], mat->Diffuse[3]);
+ UNCLAMPED_FLOAT_TO_CHAN(ctx->Light._BaseAlpha[1], mat->Diffuse[3]);
}
/* update light->_MatSpecular = light's specular * material's specular */
ctx->Light.Model.Ambient,
mat->Ambient);
- FLOAT_COLOR_TO_CHAN(ctx->Light._BaseAlpha[side],
- ctx->Light.Material[side].Diffuse[3] );
+ UNCLAMPED_FLOAT_TO_CHAN(ctx->Light._BaseAlpha[side],
+ ctx->Light.Material[side].Diffuse[3] );
}
foreach (light, &ctx->Light.EnabledList) {
-/* $Id: mtypes.h,v 1.8 2000/12/27 22:52:45 keithw Exp $ */
+/* $Id: mtypes.h,v 1.9 2001/01/02 22:02:51 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "glheader.h"
#include "config.h" /* Hardwired parameters */
-#include "fixed.h" /* GLfixed */
#include "glapitable.h"
#include "glthread.h"
#endif
-/* Maximum number of temporary vertices required for clipping. (Used
- * in array_cache and tnl modules).
- */
-#define MAX_CLIPPED_VERTICES ((2 * (6 + MAX_CLIP_PLANES))+1)
-
/*
* Depth buffer data type:
*/
typedef GLuint GLdepth; /* Must be 32-bits! */
+/*
+ * Fixed point data type:
+ */
+typedef int GLfixed;
+
+
+
/*
* Some forward type declarations
*/
+/* Maximum number of temporary vertices required for clipping. (Used
+ * in array_cache and tnl modules).
+ */
+#define MAX_CLIPPED_VERTICES ((2 * (6 + MAX_CLIP_PLANES))+1)
+
+
/* Data structure for color tables */
struct gl_color_table {
GLvoid *Table;
#define _MESA_NEW_NEED_NORMALS (_NEW_LIGHT| \
_NEW_TEXTURE)
-
#define _IMAGE_NEW_TRANSFER_STATE (_NEW_PIXEL|_NEW_COLOR_MATRIX)
-/* $Id: m_trans_tmp.h,v 1.1 2000/11/16 21:05:41 keithw Exp $ */
+/* $Id: m_trans_tmp.h,v 1.2 2001/01/02 22:02:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
- * Version: 3.1
+ * Version: 3.5
*
* Copyright (C) 1999 Brian Paul All Rights Reserved.
*
-/* $Id: m_translate.c,v 1.2 2000/12/26 05:09:31 keithw Exp $ */
+/* $Id: m_translate.c,v 1.3 2001/01/02 22:02:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
/* GL_BYTE
*/
+#define BYTE_TO_UBYTE(b) (b < 0 ? 0 : (GLubyte) b)
+
#define SRC GLbyte
#define SRC_IDX TYPE_IDX(GL_BYTE)
#define TRX_3F(f,n) BYTE_TO_FLOAT( PTR_ELT(f,n) )
#define SRC_IDX TYPE_IDX(GL_DOUBLE)
#define TRX_3F(f,n) PTR_ELT(f,n)
#define TRX_4F(f,n) PTR_ELT(f,n)
-#define TRX_UB(ub,f,n) FLOAT_COLOR_TO_CHAN(ub, PTR_ELT(f,n))
+#define TRX_UB(ub,f,n) UNCLAMPED_FLOAT_TO_CHAN(ub, PTR_ELT(f,n))
#define TRX_UI(f,n) (GLuint) (GLint) PTR_ELT(f,n)
#define TRX_1F(f,n) PTR_ELT(f,n)
-/* $Id: s_aatriangle.c,v 1.4 2000/11/19 23:10:26 brianp Exp $ */
+/* $Id: s_aatriangle.c,v 1.5 2001/01/02 22:02:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
*/
+#include "mmath.h"
#include "s_aatriangle.h"
#include "s_context.h"
#include "s_span.h"
-/* $Id: s_texture.c,v 1.4 2000/12/14 20:25:59 brianp Exp $ */
+/* $Id: s_texture.c,v 1.5 2001/01/02 22:02:52 brianp Exp $ */
/*
* Mesa 3-D graphics library
{ \
if (wrapMode == GL_REPEAT) { \
U = S * SIZE - 0.5F; \
- I0 = ((GLint) myFloor(U)) & (SIZE - 1); \
+ I0 = IFLOOR(U) & (SIZE - 1); \
I1 = (I0 + 1) & (SIZE - 1); \
} \
else { \
else if (U >= SIZE) \
U = SIZE; \
U -= 0.5F; \
- I0 = (GLint) myFloor(U); \
+ I0 = IFLOOR(U); \
I1 = I0 + 1; \
if (wrapMode == GL_CLAMP_TO_EDGE) { \
if (I0 < 0) \
/**********************************************************************/
-/*
- * Return floor of x, being careful of negative values.
- */
-static GLfloat myFloor(GLfloat x)
-{
- if (x < 0.0F)
- return (GLfloat) ((GLint) x - 1);
- else
- return (GLfloat) (GLint) x;
-}
-
-
-/*
- * Return the fractional part of x.
- */
-#define myFrac(x) ( (x) - myFloor(x) )
-
-
-
-
/*
* Given 1-D texture image and an (i) texel column coordinate, return the
* texel color.
}
{
- const GLfloat a = myFrac(u);
+ const GLfloat a = FRAC(u);
/* compute sample weights in fixed point in [0,WEIGHT_SCALE] */
const GLint w0 = (GLint) ((1.0F-a) * WEIGHT_SCALE + 0.5F);
const GLint w1 = (GLint) ( a * WEIGHT_SCALE + 0.5F);
}
else {
GLchan t0[4], t1[4];
- const GLfloat f = myFrac(lambda);
+ const GLfloat f = FRAC(lambda);
sample_1d_nearest( tObj, tObj->Image[level ], s, t0 );
sample_1d_nearest( tObj, tObj->Image[level+1], s, t1 );
rgba[RCOMP] = (GLchan) (GLint) ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]);
}
else {
GLchan t0[4], t1[4];
- const GLfloat f = myFrac(lambda);
+ const GLfloat f = FRAC(lambda);
sample_1d_linear( tObj, tObj->Image[level ], s, t0 );
sample_1d_linear( tObj, tObj->Image[level+1], s, t1 );
rgba[RCOMP] = (GLchan) (GLint) ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]);
}
{
- const GLfloat a = myFrac(u);
- const GLfloat b = myFrac(v);
+ const GLfloat a = FRAC(u);
+ const GLfloat b = FRAC(v);
/* compute sample weights in fixed point in [0,WEIGHT_SCALE] */
const GLint w00 = (GLint) ((1.0F-a)*(1.0F-b) * WEIGHT_SCALE + 0.5F);
const GLint w10 = (GLint) ( a *(1.0F-b) * WEIGHT_SCALE + 0.5F);
}
else {
GLchan t0[4], t1[4]; /* texels */
- const GLfloat f = myFrac(lambda);
+ const GLfloat f = FRAC(lambda);
sample_2d_nearest( tObj, tObj->Image[level ], s, t, t0 );
sample_2d_nearest( tObj, tObj->Image[level+1], s, t, t1 );
rgba[RCOMP] = (GLchan) (GLint) ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]);
}
else {
GLchan t0[4], t1[4]; /* texels */
- const GLfloat f = myFrac(lambda);
+ const GLfloat f = FRAC(lambda);
sample_2d_linear( tObj, tObj->Image[level ], s, t, t0 );
sample_2d_linear( tObj, tObj->Image[level+1], s, t, t1 );
rgba[RCOMP] = (GLchan) (GLint) ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]);
}
{
- const GLfloat a = myFrac(u);
- const GLfloat b = myFrac(v);
- const GLfloat c = myFrac(w);
+ const GLfloat a = FRAC(u);
+ const GLfloat b = FRAC(v);
+ const GLfloat c = FRAC(w);
/* compute sample weights in fixed point in [0,WEIGHT_SCALE] */
GLint w000 = (GLint) ((1.0F-a)*(1.0F-b)*(1.0F-c) * WEIGHT_SCALE + 0.5F);
GLint w100 = (GLint) ( a *(1.0F-b)*(1.0F-c) * WEIGHT_SCALE + 0.5F);
}
else {
GLchan t0[4], t1[4]; /* texels */
- const GLfloat f = myFrac(lambda);
+ const GLfloat f = FRAC(lambda);
sample_3d_nearest( tObj, tObj->Image[level ], s, t, r, t0 );
sample_3d_nearest( tObj, tObj->Image[level+1], s, t, r, t1 );
rgba[RCOMP] = (GLchan) (GLint) ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]);
}
else {
GLchan t0[4], t1[4]; /* texels */
- const GLfloat f = myFrac(lambda);
+ const GLfloat f = FRAC(lambda);
sample_3d_linear( tObj, tObj->Image[level ], s, t, r, t0 );
sample_3d_linear( tObj, tObj->Image[level+1], s, t, r, t1 );
rgba[RCOMP] = (GLchan) (GLint) ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]);
}
else {
GLchan t0[4], t1[4]; /* texels */
- const GLfloat f = myFrac(lambda);
+ const GLfloat f = FRAC(lambda);
sample_2d_nearest( tObj, images[level ], newS, newT, t0 );
sample_2d_nearest( tObj, images[level+1], newS, newT, t1 );
rgba[RCOMP] = (GLchan) (GLint) ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]);
}
else {
GLchan t0[4], t1[4];
- const GLfloat f = myFrac(lambda);
+ const GLfloat f = FRAC(lambda);
sample_2d_linear( tObj, images[level ], newS, newT, t0 );
sample_2d_linear( tObj, images[level+1], newS, newT, t1 );
rgba[RCOMP] = (GLchan) (GLint) ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]);
#if CHAN_BITS == 8
GLubyte col[4];
GET_IMMEDIATE;
- FLOAT_COLOR_TO_UBYTE_COLOR(col[0], red);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[1], green);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[2], blue);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[0], red);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[1], green);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[2], blue);
col[3] = CHAN_MAX;
COLORV( IM, col );
#else
#if CHAN_BITS == 8
GLubyte col[4];
GET_IMMEDIATE;
- FLOAT_COLOR_TO_UBYTE_COLOR(col[0], red);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[1], green);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[2], blue);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[3], alpha);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[0], red);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[1], green);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[2], blue);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[3], alpha);
COLORV( IM, col );
#else
GET_IMMEDIATE;
#if CHAN_BITS == 8
GLubyte col[4];
GET_IMMEDIATE;
- FLOAT_COLOR_TO_UBYTE_COLOR(col[0], v[0]);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[1], v[1]);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[2], v[2]);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[0], v[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[1], v[1]);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[2], v[2]);
col[3] = CHAN_MAX;
COLORV( IM, col );
#else
#if CHAN_BITS == 8
GLubyte col[4];
GET_IMMEDIATE;
- FLOAT_COLOR_TO_UBYTE_COLOR(col[0], v[0]);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[1], v[1]);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[2], v[2]);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[3], v[3]);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[0], v[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[1], v[1]);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[2], v[2]);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[3], v[3]);
COLORV( IM, col );
#else
GET_IMMEDIATE;
#if CHAN_BITS == 8
GLubyte col[3];
GET_IMMEDIATE;
- FLOAT_COLOR_TO_UBYTE_COLOR(col[0], red);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[1], green);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[2], blue);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[0], red);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[1], green);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[2], blue);
SECONDARY_COLORV( IM, col );
#else
GET_IMMEDIATE;
#if CHAN_BITS == 8
GLubyte col[3];
GET_IMMEDIATE;
- FLOAT_COLOR_TO_UBYTE_COLOR(col[0], v[0]);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[1], v[1]);
- FLOAT_COLOR_TO_UBYTE_COLOR(col[2], v[2]);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[0], v[0]);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[1], v[1]);
+ UNCLAMPED_FLOAT_TO_UBYTE(col[2], v[2]);
SECONDARY_COLORV( IM, col );
#else
GET_IMMEDIATE;
-/* $Id: t_imm_elt.c,v 1.1 2000/12/26 05:09:32 keithw Exp $ */
+/* $Id: t_imm_elt.c,v 1.2 2001/01/02 22:02:53 brianp Exp $ */
/*
* Mesa 3-D graphics library
#define SRC_IDX TYPE_IDX(GL_DOUBLE)
#define TRX_3F(f,n) PTR_ELT(f,n)
#define TRX_4F(f,n) PTR_ELT(f,n)
-#define TRX_UB(ub,f,n) FLOAT_COLOR_TO_CHAN(ub, PTR_ELT(f,n))
+#define TRX_UB(ub,f,n) UNCLAMPED_FLOAT_TO_CHAN(ub, PTR_ELT(f,n))
#define TRX_UI(f,n) (GLuint) (GLint) PTR_ELT(f,n)
#define TRX_1F(f,n) PTR_ELT(f,n)