summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2000-10-28 20:41:13 +0000
committerBrian Paul <[email protected]>2000-10-28 20:41:13 +0000
commitc893a015d8a50a38cd3f727d99835e7e7e2ccea9 (patch)
tree49ceb3610b183301b64916d54fd74d13a5c3a31c /src
parentba643a2094a1e844b6ce60f468057057557859ce (diff)
New colormac.h file for color-related macros.
Lot's of clean-up in macros.h and mmath.h
Diffstat (limited to 'src')
-rw-r--r--src/mesa/main/clip.c3
-rw-r--r--src/mesa/main/colormac.h187
-rw-r--r--src/mesa/main/config.h12
-rw-r--r--src/mesa/main/convolve.c3
-rw-r--r--src/mesa/main/dlist.c3
-rw-r--r--src/mesa/main/drawpix.c8
-rw-r--r--src/mesa/main/eval.c9
-rw-r--r--src/mesa/main/feedback.c8
-rw-r--r--src/mesa/main/fog.c3
-rw-r--r--src/mesa/main/get.c24
-rw-r--r--src/mesa/main/image.c3
-rw-r--r--src/mesa/main/light.c22
-rw-r--r--src/mesa/main/macros.h100
-rw-r--r--src/mesa/main/pixel.c3
-rw-r--r--src/mesa/main/rastpos.c9
-rw-r--r--src/mesa/main/texstate.c3
16 files changed, 277 insertions, 123 deletions
diff --git a/src/mesa/main/clip.c b/src/mesa/main/clip.c
index 1e98358aa18..92788c638fc 100644
--- a/src/mesa/main/clip.c
+++ b/src/mesa/main/clip.c
@@ -1,4 +1,4 @@
-/* $Id: clip.c,v 1.10 2000/10/27 16:44:40 keithw Exp $ */
+/* $Id: clip.c,v 1.11 2000/10/28 20:41:13 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -30,6 +30,7 @@
#else
#include "glheader.h"
#include "clip.h"
+#include "colormac.h"
#include "context.h"
#include "macros.h"
#include "matrix.h"
diff --git a/src/mesa/main/colormac.h b/src/mesa/main/colormac.h
new file mode 100644
index 00000000000..5d125e27253
--- /dev/null
+++ b/src/mesa/main/colormac.h
@@ -0,0 +1,187 @@
+/* $Id: colormac.h,v 1.1 2000/10/28 20:41:13 brianp Exp $ */
+
+/*
+ * Mesa 3-D graphics library
+ * Version: 3.5
+ *
+ * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+
+/*
+ * Color-related macros
+ */
+
+#ifndef COLORMAC_H
+#define COLORMAC_H
+
+
+#include "glheader.h"
+#include "config.h"
+#include "macros.h"
+#include "mmath.h"
+
+
+
+/*
+ * 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 UBYTE_TO_CHAN(b) (b)
+#define SHORT_TO_CHAN(s) ((s) < 0 ? 0 : (GLchan) ((s) >> 7))
+#define USHORT_TO_CHAN(s) ((GLchan) ((s) >> 8))
+#define INT_TO_CHAN(i) ((i) < 0 ? 0 : (GLchan) ((i) >> 23))
+#define UINT_TO_CHAN(i) ((GLchan) ((i) >> 24))
+
+#define CHAN_TO_FLOAT(c) UBYTE_TO_FLOAT(c)
+
+#define FLOAT_COLOR_TO_CHAN(c, f) FLOAT_COLOR_TO_UBYTE_COLOR(c, f)
+
+#define COPY_CHAN4(DST, SRC) COPY_4UBV(DST, SRC)
+
+#define CHAN_PRODUCT(a, b) ( (GLubyte) (((GLint)(a) * ((GLint)(b) + 1)) >> 8) )
+
+#elif CHAN_BITS == 16
+
+#define BYTE_TO_CHAN(b) ((b) < 0 ? 0 : (GLchan) ((b) * 516))
+#define UBYTE_TO_CHAN(b) ((GLchan) (((b) << 8) | (b)))
+#define SHORT_TO_CHAN(s) ((s) < 0 ? 0 : (GLchan) (s))
+#define USHORT_TO_CHAN(s) (s)
+#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 FLOAT_COLOR_TO_CHAN(c, f) \
+ c = ((GLchan) FloatToInt(CLAMP(f, 0.0F, 1.0F) * CHAN_MAXF + 0.5F))
+
+#define COPY_CHAN4(DST, SRC) COPY_4V(DST, SRC)
+
+#define CHAN_PRODUCT(a, b) ( (GLchan) ((((GLint) (a)) * ((GLint) (b))) / 65535) )
+
+#elif CHAN_BITS == 32
+
+/* XXX floating-point color channels not fully thought-out */
+#define BYTE_TO_CHAN(b) ((GLfloat) ((b) * (1.0F / 127.0F)))
+#define UBYTE_TO_CHAN(b) ((GLfloat) ((b) * (1.0F / 255.0F)))
+#define SHORT_TO_CHAN(s) ((GLfloat) ((s) * (1.0F / 32767.0F)))
+#define USHORT_TO_CHAN(s) ((GLfloat) ((s) * (1.0F / 65535.0F)))
+#define INT_TO_CHAN(i) ((GLfloat) ((i) * (1.0F / 2147483647.0F)))
+#define UINT_TO_CHAN(i) ((GLfloat) ((i) * (1.0F / 4294967295.0F)))
+
+#define CHAN_TO_FLOAT(c) (c)
+
+#define FLOAT_COLOR_TO_CHAN(c, f) c = f
+
+#define COPY_CHAN4(DST, SRC) COPY_4V(DST, SRC)
+
+#define CHAN_PRODUCT(a, b) ((a) * (b))
+
+#else
+
+#error unexpected CHAN_BITS size
+
+#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) \
+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]); \
+} while(0)
+
+
+#if CHAN_BITS == 32
+
+#define FLOAT_TO_CHAN(f) (f)
+#define 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) )
+
+#endif
+
+
+#endif /* COLORMAC_H */
diff --git a/src/mesa/main/config.h b/src/mesa/main/config.h
index 35a0dded6ad..901d614b10b 100644
--- a/src/mesa/main/config.h
+++ b/src/mesa/main/config.h
@@ -1,4 +1,4 @@
-/* $Id: config.h,v 1.20 2000/10/28 18:34:48 brianp Exp $ */
+/* $Id: config.h,v 1.21 2000/10/28 20:41:13 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -162,12 +162,18 @@
* Bits per color channel (must be 8 at this time!)
*/
#define CHAN_BITS 8
-#define CHAN_MAX ((1 << CHAN_BITS) - 1)
-#define CHAN_MAXF ((GLfloat) CHAN_MAX)
#if CHAN_BITS == 8
typedef GLubyte GLchan;
+#define CHAN_MAX 255
+#define CHAN_MAXF 255.0F
#elif CHAN_BITS == 16
typedef GLushort GLchan;
+#define CHAN_MAX 65535
+#define CHAN_MAXF 65535.0F
+#elif CHAN_BITS == 32
+ typedef GLfloat GLchan;
+#define CHAN_MAX 1.0
+#define CHAN_MAXF 1.0F
#else
#error illegal number of color channel bits
#endif
diff --git a/src/mesa/main/convolve.c b/src/mesa/main/convolve.c
index 1c52bcc12af..b32b3e73731 100644
--- a/src/mesa/main/convolve.c
+++ b/src/mesa/main/convolve.c
@@ -1,4 +1,4 @@
-/* $Id: convolve.c,v 1.6 2000/10/28 18:34:48 brianp Exp $ */
+/* $Id: convolve.c,v 1.7 2000/10/28 20:41:13 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -37,6 +37,7 @@
#include "all.h"
#else
#include "glheader.h"
+#include "colormac.h"
#include "convolve.h"
#include "context.h"
#include "image.h"
diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c
index cb682c6ffc4..a0db2d3fc5b 100644
--- a/src/mesa/main/dlist.c
+++ b/src/mesa/main/dlist.c
@@ -1,4 +1,4 @@
-/* $Id: dlist.c,v 1.48 2000/10/27 18:31:21 brianp Exp $ */
+/* $Id: dlist.c,v 1.49 2000/10/28 20:41:13 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -36,6 +36,7 @@
#include "blend.h"
#include "buffers.h"
#include "clip.h"
+#include "colormac.h"
#include "colortab.h"
#include "context.h"
#include "convolve.h"
diff --git a/src/mesa/main/drawpix.c b/src/mesa/main/drawpix.c
index 177458c9eaf..6e1f6e0a090 100644
--- a/src/mesa/main/drawpix.c
+++ b/src/mesa/main/drawpix.c
@@ -1,4 +1,4 @@
-/* $Id: drawpix.c,v 1.39 2000/10/27 16:44:40 keithw Exp $ */
+/* $Id: drawpix.c,v 1.40 2000/10/28 20:41:13 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -29,6 +29,7 @@
#include "all.h"
#else
#include "glheader.h"
+#include "colormac.h"
#include "context.h"
#include "convolve.h"
#include "drawpix.h"
@@ -916,7 +917,10 @@ _mesa_DrawPixels( GLsizei width, GLsizei height,
if (ctx->Current.RasterPosValid) {
GLfloat color[4];
GLfloat texcoord[4], invq;
- UBYTE_RGBA_TO_FLOAT_RGBA(color, ctx->Current.ByteColor);
+ color[0] = CHAN_TO_FLOAT(ctx->Current.ByteColor[0]);
+ color[1] = CHAN_TO_FLOAT(ctx->Current.ByteColor[1]);
+ color[2] = CHAN_TO_FLOAT(ctx->Current.ByteColor[2]);
+ color[3] = CHAN_TO_FLOAT(ctx->Current.ByteColor[3]);
invq = 1.0F / ctx->Current.Texcoord[0][3];
texcoord[0] = ctx->Current.Texcoord[0][0] * invq;
texcoord[1] = ctx->Current.Texcoord[0][1] * invq;
diff --git a/src/mesa/main/eval.c b/src/mesa/main/eval.c
index da1ad431619..9a5bbc7c64d 100644
--- a/src/mesa/main/eval.c
+++ b/src/mesa/main/eval.c
@@ -1,8 +1,8 @@
-/* $Id: eval.c,v 1.11 2000/09/11 18:49:06 brianp Exp $ */
+/* $Id: eval.c,v 1.12 2000/10/28 20:41:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
- * Version: 3.3
+ * Version: 3.5
*
* Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
*
@@ -42,6 +42,7 @@
#include "all.h"
#else
#include "glheader.h"
+#include "colormac.h"
#include "context.h"
#include "eval.h"
#include "macros.h"
@@ -2110,7 +2111,7 @@ static GLvector4ub *eval1_color( GLvector4ub *dest,
GLfloat u = (coord[i][0] - u1) * du;
GLfloat fcolor[4];
horner_bezier_curve(map->Points, fcolor, u, 4, map->Order);
- FLOAT_RGBA_TO_UBYTE_RGBA(to[i], fcolor);
+ FLOAT_RGBA_TO_CHAN_RGBA(to[i], fcolor);
flags[i+1] |= VERT_RGBA; /* reset */
}
@@ -2270,7 +2271,7 @@ static GLvector4ub *eval2_color( GLvector4ub *dest,
GLfloat fcolor[4];
horner_bezier_surf(map->Points, fcolor, u, v, 4,
map->Uorder, map->Vorder);
- FLOAT_RGBA_TO_UBYTE_RGBA(to[i], fcolor);
+ FLOAT_RGBA_TO_CHAN_RGBA(to[i], fcolor);
flags[i+1] |= VERT_RGBA; /* reset */
}
diff --git a/src/mesa/main/feedback.c b/src/mesa/main/feedback.c
index f9de16b8931..1a6b34d7fee 100644
--- a/src/mesa/main/feedback.c
+++ b/src/mesa/main/feedback.c
@@ -1,4 +1,4 @@
-/* $Id: feedback.c,v 1.12 2000/10/28 18:34:48 brianp Exp $ */
+/* $Id: feedback.c,v 1.13 2000/10/28 20:41:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -29,6 +29,7 @@
#include "all.h"
#else
#include "glheader.h"
+#include "colormac.h"
#include "context.h"
#include "enums.h"
#include "feedback.h"
@@ -174,7 +175,10 @@ static void feedback_vertex( GLcontext *ctx, GLuint v, GLuint pv )
if (ctx->Light.ShadeModel == GL_SMOOTH)
pv = v;
- CHAN_RGBA_TO_FLOAT_RGBA( color, VB->ColorPtr->data[pv] );
+ color[0] = CHAN_TO_FLOAT(VB->ColorPtr->data[pv][0]);
+ color[1] = CHAN_TO_FLOAT(VB->ColorPtr->data[pv][1]);
+ color[2] = CHAN_TO_FLOAT(VB->ColorPtr->data[pv][2]);
+ color[3] = CHAN_TO_FLOAT(VB->ColorPtr->data[pv][3]);
if (VB->TexCoordPtr[texUnit]->size == 4 &&
VB->TexCoordPtr[texUnit]->data[v][3] != 0.0) {
diff --git a/src/mesa/main/fog.c b/src/mesa/main/fog.c
index a146a8f47a4..4c1502227c5 100644
--- a/src/mesa/main/fog.c
+++ b/src/mesa/main/fog.c
@@ -1,4 +1,4 @@
-/* $Id: fog.c,v 1.24 2000/10/28 18:34:48 brianp Exp $ */
+/* $Id: fog.c,v 1.25 2000/10/28 20:41:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -29,6 +29,7 @@
#include "all.h"
#else
#include "glheader.h"
+#include "colormac.h"
#include "context.h"
#include "fog.h"
#include "macros.h"
diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index 9876f4951b3..9123138caa5 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -1,4 +1,4 @@
-/* $Id: get.c,v 1.36 2000/10/28 18:34:48 brianp Exp $ */
+/* $Id: get.c,v 1.37 2000/10/28 20:41:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -29,6 +29,7 @@
#include "all.h"
#else
#include "glheader.h"
+#include "colormac.h"
#include "context.h"
#include "enable.h"
#include "enums.h"
@@ -1418,10 +1419,10 @@ _mesa_GetDoublev( GLenum pname, GLdouble *params )
*params = ENUM_TO_DOUBLE(ctx->Polygon.CullFaceMode);
break;
case GL_CURRENT_COLOR:
- params[0] = CHAN_COLOR_TO_FLOAT_COLOR(ctx->Current.ByteColor[0]);
- params[1] = CHAN_COLOR_TO_FLOAT_COLOR(ctx->Current.ByteColor[1]);
- params[2] = CHAN_COLOR_TO_FLOAT_COLOR(ctx->Current.ByteColor[2]);
- params[3] = CHAN_COLOR_TO_FLOAT_COLOR(ctx->Current.ByteColor[3]);
+ params[0] = CHAN_TO_FLOAT(ctx->Current.ByteColor[0]);
+ params[1] = CHAN_TO_FLOAT(ctx->Current.ByteColor[1]);
+ params[2] = CHAN_TO_FLOAT(ctx->Current.ByteColor[2]);
+ params[3] = CHAN_TO_FLOAT(ctx->Current.ByteColor[3]);
break;
case GL_CURRENT_INDEX:
*params = (GLdouble) ctx->Current.Index;
@@ -2610,7 +2611,10 @@ _mesa_GetFloatv( GLenum pname, GLfloat *params )
*params = ENUM_TO_FLOAT(ctx->Polygon.CullFaceMode);
break;
case GL_CURRENT_COLOR:
- CHAN_RGBA_TO_FLOAT_RGBA(params, ctx->Current.ByteColor);
+ params[0] = CHAN_TO_FLOAT(ctx->Current.ByteColor[0]);
+ params[1] = CHAN_TO_FLOAT(ctx->Current.ByteColor[1]);
+ params[2] = CHAN_TO_FLOAT(ctx->Current.ByteColor[2]);
+ params[3] = CHAN_TO_FLOAT(ctx->Current.ByteColor[3]);
break;
case GL_CURRENT_INDEX:
*params = (GLfloat) ctx->Current.Index;
@@ -3775,10 +3779,10 @@ _mesa_GetIntegerv( GLenum pname, GLint *params )
*params = (GLint) ctx->Polygon.CullFaceMode;
break;
case GL_CURRENT_COLOR:
- params[0] = FLOAT_TO_INT( CHAN_COLOR_TO_FLOAT_COLOR( ctx->Current.ByteColor[0] ) );
- params[1] = FLOAT_TO_INT( CHAN_COLOR_TO_FLOAT_COLOR( ctx->Current.ByteColor[1] ) );
- params[2] = FLOAT_TO_INT( CHAN_COLOR_TO_FLOAT_COLOR( ctx->Current.ByteColor[2] ) );
- params[3] = FLOAT_TO_INT( CHAN_COLOR_TO_FLOAT_COLOR( ctx->Current.ByteColor[3] ) );
+ params[0] = FLOAT_TO_INT( CHAN_TO_FLOAT( ctx->Current.ByteColor[0] ) );
+ params[1] = FLOAT_TO_INT( CHAN_TO_FLOAT( ctx->Current.ByteColor[1] ) );
+ params[2] = FLOAT_TO_INT( CHAN_TO_FLOAT( ctx->Current.ByteColor[2] ) );
+ params[3] = FLOAT_TO_INT( CHAN_TO_FLOAT( ctx->Current.ByteColor[3] ) );
break;
case GL_CURRENT_INDEX:
*params = (GLint) ctx->Current.Index;
diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c
index af60908280c..7c4fa887825 100644
--- a/src/mesa/main/image.c
+++ b/src/mesa/main/image.c
@@ -1,4 +1,4 @@
-/* $Id: image.c,v 1.43 2000/10/05 16:22:22 brianp Exp $ */
+/* $Id: image.c,v 1.44 2000/10/28 20:41:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -29,6 +29,7 @@
#include "all.h"
#else
#include "glheader.h"
+#include "colormac.h"
#include "context.h"
#include "image.h"
#include "imaging.h"
diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c
index 1ed1178e124..38e74e71152 100644
--- a/src/mesa/main/light.c
+++ b/src/mesa/main/light.c
@@ -1,4 +1,4 @@
-/* $Id: light.c,v 1.19 2000/10/28 18:34:48 brianp Exp $ */
+/* $Id: light.c,v 1.20 2000/10/28 20:41:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -29,6 +29,7 @@
#include "all.h"
#else
#include "glheader.h"
+#include "colormac.h"
#include "context.h"
#include "enums.h"
#include "light.h"
@@ -591,7 +592,7 @@ void gl_update_material( GLcontext *ctx,
ACC_SCALE_3V( light->MatDiffuse[0], light->Diffuse, tmp );
}
COPY_4FV( mat->Diffuse, src[0].Diffuse );
- FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Light.BaseAlpha[0], mat->Diffuse[3]);
+ FLOAT_COLOR_TO_CHAN(ctx->Light.BaseAlpha[0], mat->Diffuse[3]);
}
if (bitmask & BACK_DIFFUSE_BIT) {
struct gl_material *mat = &ctx->Light.Material[1];
@@ -601,7 +602,7 @@ void gl_update_material( GLcontext *ctx,
ACC_SCALE_3V( light->MatDiffuse[1], light->Diffuse, tmp );
}
COPY_4FV( mat->Diffuse, src[1].Diffuse );
- FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Light.BaseAlpha[1], mat->Diffuse[3]);
+ FLOAT_COLOR_TO_CHAN(ctx->Light.BaseAlpha[1], mat->Diffuse[3]);
}
/* update material specular values */
@@ -691,8 +692,11 @@ void gl_update_color_material( GLcontext *ctx,
GLuint bitmask = ctx->Light.ColorMaterialBitmask;
GLfloat color[4];
- UBYTE_RGBA_TO_FLOAT_RGBA( color, rgba );
-
+ color[0] = CHAN_TO_FLOAT(rgba[0]);
+ color[1] = CHAN_TO_FLOAT(rgba[1]);
+ color[2] = CHAN_TO_FLOAT(rgba[2]);
+ color[3] = CHAN_TO_FLOAT(rgba[3]);
+
if (MESA_VERBOSE&VERBOSE_IMMEDIATE)
fprintf(stderr, "gl_update_color_material, mask 0x%x\n", bitmask);
@@ -746,7 +750,7 @@ void gl_update_color_material( GLcontext *ctx,
ACC_SCALE_3V( light->MatDiffuse[0], light->Diffuse, tmp );
}
COPY_4FV( mat->Diffuse, color );
- FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Light.BaseAlpha[0], mat->Diffuse[3]);
+ FLOAT_COLOR_TO_CHAN(ctx->Light.BaseAlpha[0], mat->Diffuse[3]);
}
if (bitmask & BACK_DIFFUSE_BIT) {
@@ -757,7 +761,7 @@ void gl_update_color_material( GLcontext *ctx,
ACC_SCALE_3V( light->MatDiffuse[1], light->Diffuse, tmp );
}
COPY_4FV( mat->Diffuse, color );
- FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Light.BaseAlpha[1], mat->Diffuse[3]);
+ FLOAT_COLOR_TO_CHAN(ctx->Light.BaseAlpha[1], mat->Diffuse[3]);
}
/* update light->MatSpecular = light's specular * material's specular */
@@ -1280,8 +1284,8 @@ gl_update_lighting( GLcontext *ctx )
ctx->Light.Model.Ambient,
mat->Ambient);
- FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Light.BaseAlpha[side],
- ctx->Light.Material[side].Diffuse[3] );
+ FLOAT_COLOR_TO_CHAN(ctx->Light.BaseAlpha[side],
+ ctx->Light.Material[side].Diffuse[3] );
}
foreach (light, &ctx->Light.EnabledList) {
diff --git a/src/mesa/main/macros.h b/src/mesa/main/macros.h
index 443e2731c67..05c80d1a15c 100644
--- a/src/mesa/main/macros.h
+++ b/src/mesa/main/macros.h
@@ -1,10 +1,10 @@
-/* $Id: macros.h,v 1.10 2000/10/28 18:34:48 brianp Exp $ */
+/* $Id: macros.h,v 1.11 2000/10/28 20:41:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
- * Version: 3.3
+ * Version: 3.5
*
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -124,6 +124,19 @@ do { \
(DST)[3] = (SRC)[3]; \
} while (0)
+#define COPY_4UBV(DST, SRC) \
+do { \
+ if (sizeof(GLuint)==4*sizeof(GLubyte)) { \
+ *((GLuint*)(DST)) = *((GLuint*)(SRC)); \
+ } \
+ else { \
+ (DST)[0] = (SRC)[0]; \
+ (DST)[1] = (SRC)[1]; \
+ (DST)[2] = (SRC)[2]; \
+ (DST)[3] = (SRC)[3]; \
+ } \
+} while (0)
+
#define COPY_2FV( DST, SRC ) \
do { \
@@ -351,26 +364,6 @@ do { \
-/*
- * Copy a vector of 4 GLubytes from SRC to DST.
- */
-#define COPY_4UBV(DST, SRC) \
-do { \
- if (sizeof(GLuint)==4*sizeof(GLubyte)) { \
- *((GLuint*)(DST)) = *((GLuint*)(SRC)); \
- } \
- else { \
- (DST)[0] = (SRC)[0]; \
- (DST)[1] = (SRC)[1]; \
- (DST)[2] = (SRC)[2]; \
- (DST)[3] = (SRC)[3]; \
- } \
-} while (0)
-
-
-#define COPY_CHAN4(DST, SRC) COPY_4UBV(DST, SRC)
-
-
/* Assign scalers to short vectors: */
#define ASSIGN_2V( V, V0, V1 ) \
do { \
@@ -436,7 +429,7 @@ do { \
#define DOT4( a, b ) ( (a)[0]*(b)[0] + (a)[1]*(b)[1] + \
(a)[2]*(b)[2] + (a)[3]*(b)[3] )
-#define DOT4V(v,a,b,c,d) (v[0]*a + v[1]*b + v[2]*c + v[3]*d)
+#define DOT4V(v,a,b,c,d) (v[0]*(a) + v[1]*(b) + v[2]*(c) + v[3]*(d))
#define CROSS3(n, u, v) \
@@ -447,63 +440,4 @@ do { \
} while (0)
-/*
- * 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 GLubyte in [0,255] to GLfloat in [0.0,1.0] */
-#define UBYTE_TO_FLOAT(B) ((GLfloat) (B) * (1.0F / 255.0F))
-
-/* 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)) )
-
-
-/* XXX chan fix me */
-#define CHAN_TO_FLOAT(C) ( (GLfloat) ((C) * (1.0 / CHAN_MAXF)) )
-
#endif
diff --git a/src/mesa/main/pixel.c b/src/mesa/main/pixel.c
index 703d1294447..8a1d5982007 100644
--- a/src/mesa/main/pixel.c
+++ b/src/mesa/main/pixel.c
@@ -1,4 +1,4 @@
-/* $Id: pixel.c,v 1.14 2000/10/28 18:34:48 brianp Exp $ */
+/* $Id: pixel.c,v 1.15 2000/10/28 20:41:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -29,6 +29,7 @@
#include "all.h"
#else
#include "glheader.h"
+#include "colormac.h"
#include "context.h"
#include "macros.h"
#include "mem.h"
diff --git a/src/mesa/main/rastpos.c b/src/mesa/main/rastpos.c
index a262ed3002e..b4d36bbb0d1 100644
--- a/src/mesa/main/rastpos.c
+++ b/src/mesa/main/rastpos.c
@@ -1,4 +1,4 @@
-/* $Id: rastpos.c,v 1.9 2000/10/28 18:34:48 brianp Exp $ */
+/* $Id: rastpos.c,v 1.10 2000/10/28 20:41:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -30,6 +30,7 @@
#else
#include "glheader.h"
#include "clip.h"
+#include "colormac.h"
#include "context.h"
#include "feedback.h"
#include "light.h"
@@ -91,8 +92,10 @@ static void raster_pos4f( GLcontext *ctx,
else {
/* use current color or index */
if (ctx->Visual.RGBAflag) {
- CHAN_RGBA_TO_FLOAT_RGBA(ctx->Current.RasterColor,
- ctx->Current.ByteColor);
+ ctx->Current.RasterColor[0] = CHAN_TO_FLOAT(ctx->Current.ByteColor[0]);
+ ctx->Current.RasterColor[1] = CHAN_TO_FLOAT(ctx->Current.ByteColor[1]);
+ ctx->Current.RasterColor[2] = CHAN_TO_FLOAT(ctx->Current.ByteColor[2]);
+ ctx->Current.RasterColor[3] = CHAN_TO_FLOAT(ctx->Current.ByteColor[3]);
}
else {
ctx->Current.RasterIndex = ctx->Current.Index;
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index d4037267891..309b54fe80d 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -1,4 +1,4 @@
-/* $Id: texstate.c,v 1.17 2000/10/28 18:34:48 brianp Exp $ */
+/* $Id: texstate.c,v 1.18 2000/10/28 20:41:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -29,6 +29,7 @@
#include "all.h"
#else
#include "glheader.h"
+#include "colormac.h"
#include "context.h"
#include "enums.h"
#include "extensions.h"