aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2002-10-17 15:26:38 +0000
committerBrian Paul <[email protected]>2002-10-17 15:26:38 +0000
commit10d343f407bddf011be3d2b79a6541815759785a (patch)
tree9953198b654f697621d2f6d5a8eff9ea0da0419d /src/mesa
parent673077c613319218be6e9dcee55035d471f87977 (diff)
patches from Gerk Huisma for float-channel rendering
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/drivers/osmesa/osmesa.c14
-rw-r--r--src/mesa/swrast/s_blend.c71
-rw-r--r--src/mesa/swrast/s_tritemp.h6
3 files changed, 57 insertions, 34 deletions
diff --git a/src/mesa/drivers/osmesa/osmesa.c b/src/mesa/drivers/osmesa/osmesa.c
index ff966c3f037..cc2081129df 100644
--- a/src/mesa/drivers/osmesa/osmesa.c
+++ b/src/mesa/drivers/osmesa/osmesa.c
@@ -1,4 +1,4 @@
-/* $Id: osmesa.c,v 1.91 2002/10/14 17:08:27 brianp Exp $ */
+/* $Id: osmesa.c,v 1.92 2002/10/17 15:26:38 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -672,12 +672,12 @@ OSMesaGetProcAddress( const char *funcName )
*/
#if CHAN_TYPE == GL_FLOAT
-#define PACK_RGBA(DST, R, G, B, A) \
-do { \
- (DST)[0] = (R < 0.0f) ? 0.0f : ((R > 1.0f) ? 1.0f : R); \
- (DST)[1] = (G < 0.0f) ? 0.0f : ((G > 1.0f) ? 1.0f : G); \
- (DST)[2] = (B < 0.0f) ? 0.0f : ((B > 1.0f) ? 1.0f : B); \
- (DST)[3] = (A < 0.0f) ? 0.0f : ((A > 1.0f) ? 1.0f : A); \
+#define PACK_RGBA(DST, R, G, B, A) \
+do { \
+ (DST)[0] = MAX2( R, 0.0F ); \
+ (DST)[1] = MAX2( G, 0.0F ); \
+ (DST)[2] = MAX2( B, 0.0F ); \
+ (DST)[3] = CLAMP(A, 0.0F, CHAN_MAXF);\
} while (0)
#else
#define PACK_RGBA(DST, R, G, B, A) \
diff --git a/src/mesa/swrast/s_blend.c b/src/mesa/swrast/s_blend.c
index eb95bb36d33..5afc6a030c1 100644
--- a/src/mesa/swrast/s_blend.c
+++ b/src/mesa/swrast/s_blend.c
@@ -1,4 +1,4 @@
-/* $Id: s_blend.c,v 1.24 2002/08/07 00:45:07 brianp Exp $ */
+/* $Id: s_blend.c,v 1.25 2002/10/17 15:26:39 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -100,7 +100,7 @@ blend_transparency( GLcontext *ctx, GLuint n, const GLubyte mask[],
for (i=0;i<n;i++) {
if (mask[i]) {
- const GLint t = rgba[i][ACOMP]; /* t in [0, CHAN_MAX] */
+ const GLchan t = rgba[i][ACOMP]; /* t in [0, CHAN_MAX] */
if (t == 0) {
/* 0% alpha */
rgba[i][RCOMP] = dest[i][RCOMP];
@@ -153,7 +153,8 @@ blend_transparency( GLcontext *ctx, GLuint n, const GLubyte mask[],
const GLfloat r = (rgba[i][RCOMP] - dest[i][RCOMP]) * tt + dest[i][RCOMP];
const GLfloat g = (rgba[i][GCOMP] - dest[i][GCOMP]) * tt + dest[i][GCOMP];
const GLfloat b = (rgba[i][BCOMP] - dest[i][BCOMP]) * tt + dest[i][BCOMP];
- const GLfloat a = (rgba[i][ACOMP] - dest[i][ACOMP]) * tt + dest[i][ACOMP];
+ const GLfloat a = CLAMP( rgba[i][ACOMP], 0.0F, CHAN_MAXF ) * t +
+ CLAMP( dest[i][ACOMP], 0.0F, CHAN_MAXF ) * (1.0F - t);
#endif
#endif
ASSERT(r <= CHAN_MAX);
@@ -187,13 +188,11 @@ blend_add( GLcontext *ctx, GLuint n, const GLubyte mask[],
for (i=0;i<n;i++) {
if (mask[i]) {
#if CHAN_TYPE == GL_FLOAT
- GLfloat r = rgba[i][RCOMP] + dest[i][RCOMP];
- GLfloat g = rgba[i][GCOMP] + dest[i][GCOMP];
- GLfloat b = rgba[i][BCOMP] + dest[i][BCOMP];
- GLfloat a = rgba[i][ACOMP] + dest[i][ACOMP];
- rgba[i][RCOMP] = (GLchan) MIN2( r, CHAN_MAXF );
- rgba[i][GCOMP] = (GLchan) MIN2( g, CHAN_MAXF );
- rgba[i][BCOMP] = (GLchan) MIN2( b, CHAN_MAXF );
+ /* don't RGB clamp to max */
+ GLfloat a = CLAMP(rgba[i][ACOMP], 0.0F, CHAN_MAXF) + dest[i][ACOMP];
+ rgba[i][RCOMP] += dest[i][RCOMP];
+ rgba[i][GCOMP] += dest[i][GCOMP];
+ rgba[i][BCOMP] += dest[i][BCOMP];
rgba[i][ACOMP] = (GLchan) MIN2( a, CHAN_MAXF );
#else
GLint r = rgba[i][RCOMP] + dest[i][RCOMP];
@@ -227,7 +226,12 @@ blend_min( GLcontext *ctx, GLuint n, const GLubyte mask[],
rgba[i][RCOMP] = (GLchan) MIN2( rgba[i][RCOMP], dest[i][RCOMP] );
rgba[i][GCOMP] = (GLchan) MIN2( rgba[i][GCOMP], dest[i][GCOMP] );
rgba[i][BCOMP] = (GLchan) MIN2( rgba[i][BCOMP], dest[i][BCOMP] );
+#if CHAN_TYPE == GL_FLOAT
+ rgba[i][ACOMP] = (GLchan) MIN2(CLAMP(rgba[i][ACOMP], 0.0F, CHAN_MAXF),
+ dest[i][ACOMP]);
+#else
rgba[i][ACOMP] = (GLchan) MIN2( rgba[i][ACOMP], dest[i][ACOMP] );
+#endif
}
}
}
@@ -250,7 +254,12 @@ blend_max( GLcontext *ctx, GLuint n, const GLubyte mask[],
rgba[i][RCOMP] = (GLchan) MAX2( rgba[i][RCOMP], dest[i][RCOMP] );
rgba[i][GCOMP] = (GLchan) MAX2( rgba[i][GCOMP], dest[i][GCOMP] );
rgba[i][BCOMP] = (GLchan) MAX2( rgba[i][BCOMP], dest[i][BCOMP] );
+#if CHAN_TYPE == GL_FLOAT
+ rgba[i][ACOMP] = (GLchan) MAX2(CLAMP(rgba[i][ACOMP], 0.0F, CHAN_MAXF),
+ dest[i][ACOMP]);
+#else
rgba[i][ACOMP] = (GLchan) MAX2( rgba[i][ACOMP], dest[i][ACOMP] );
+#endif
}
}
}
@@ -310,10 +319,10 @@ static void _BLENDAPI
blend_general( GLcontext *ctx, GLuint n, const GLubyte mask[],
GLchan rgba[][4], CONST GLchan dest[][4] )
{
- GLfloat rscale = 1.0F / CHAN_MAXF;
- GLfloat gscale = 1.0F / CHAN_MAXF;
- GLfloat bscale = 1.0F / CHAN_MAXF;
- GLfloat ascale = 1.0F / CHAN_MAXF;
+ const GLfloat rscale = 1.0F / CHAN_MAXF;
+ const GLfloat gscale = 1.0F / CHAN_MAXF;
+ const GLfloat bscale = 1.0F / CHAN_MAXF;
+ const GLfloat ascale = 1.0F / CHAN_MAXF;
GLuint i;
for (i=0;i<n;i++) {
@@ -327,19 +336,33 @@ blend_general( GLcontext *ctx, GLuint n, const GLubyte mask[],
#endif
GLfloat sR, sG, sB, sA; /* Source scaling */
GLfloat dR, dG, dB, dA; /* Dest scaling */
- GLfloat r, g, b, a;
+ GLfloat r, g, b, a; /* result color */
- /* Source Color */
+ /* Incoming/source Color */
Rs = rgba[i][RCOMP];
Gs = rgba[i][GCOMP];
Bs = rgba[i][BCOMP];
As = rgba[i][ACOMP];
+#if CHAN_TYPE == GL_FLOAT
+ /* clamp */
+ Rs = MIN2(Rs, CHAN_MAXF);
+ Gs = MIN2(Gs, CHAN_MAXF);
+ Bs = MIN2(Bs, CHAN_MAXF);
+ As = MIN2(As, CHAN_MAXF);
+#endif
- /* Frame buffer color */
+ /* Frame buffer/dest color */
Rd = dest[i][RCOMP];
Gd = dest[i][GCOMP];
Bd = dest[i][BCOMP];
Ad = dest[i][ACOMP];
+#if CHAN_TYPE == GL_FLOAT
+ /* clamp */
+ Rd = MIN2(Rd, CHAN_MAXF);
+ Gd = MIN2(Gd, CHAN_MAXF);
+ Bd = MIN2(Bd, CHAN_MAXF);
+ Ad = MIN2(Ad, CHAN_MAXF);
+#endif
/* Source RGB factor */
switch (ctx->Color.BlendSrcRGB) {
@@ -363,7 +386,7 @@ blend_general( GLcontext *ctx, GLuint n, const GLubyte mask[],
sR = sG = sB = (GLfloat) As * ascale;
break;
case GL_ONE_MINUS_SRC_ALPHA:
- sR = sG = sB = (GLfloat) 1.0F - (GLfloat) As * ascale;
+ sR = sG = sB = 1.0F - (GLfloat) As * ascale;
break;
case GL_DST_ALPHA:
sR = sG = sB = (GLfloat) Ad * ascale;
@@ -429,7 +452,7 @@ blend_general( GLcontext *ctx, GLuint n, const GLubyte mask[],
sA = (GLfloat) As * ascale;
break;
case GL_ONE_MINUS_SRC_ALPHA:
- sA = (GLfloat) 1.0F - (GLfloat) As * ascale;
+ sA = 1.0F - (GLfloat) As * ascale;
break;
case GL_DST_ALPHA:
sA =(GLfloat) Ad * ascale;
@@ -486,7 +509,7 @@ blend_general( GLcontext *ctx, GLuint n, const GLubyte mask[],
dR = dG = dB = (GLfloat) As * ascale;
break;
case GL_ONE_MINUS_SRC_ALPHA:
- dR = dG = dB = (GLfloat) 1.0F - (GLfloat) As * ascale;
+ dR = dG = dB = 1.0F - (GLfloat) As * ascale;
break;
case GL_DST_ALPHA:
dR = dG = dB = (GLfloat) Ad * ascale;
@@ -544,7 +567,7 @@ blend_general( GLcontext *ctx, GLuint n, const GLubyte mask[],
dA = (GLfloat) As * ascale;
break;
case GL_ONE_MINUS_SRC_ALPHA:
- dA = (GLfloat) 1.0F - (GLfloat) As * ascale;
+ dA = 1.0F - (GLfloat) As * ascale;
break;
case GL_DST_ALPHA:
dA = (GLfloat) Ad * ascale;
@@ -624,9 +647,9 @@ blend_general( GLcontext *ctx, GLuint n, const GLubyte mask[],
}
/* final clamping */
- rgba[i][RCOMP] = CLAMP( r, 0.0F, CHAN_MAXF );
- rgba[i][GCOMP] = CLAMP( g, 0.0F, CHAN_MAXF );
- rgba[i][BCOMP] = CLAMP( b, 0.0F, CHAN_MAXF );
+ rgba[i][RCOMP] = MAX2( r, 0.0F );
+ rgba[i][GCOMP] = MAX2( g, 0.0F );
+ rgba[i][BCOMP] = MAX2( b, 0.0F );
rgba[i][ACOMP] = CLAMP( a, 0.0F, CHAN_MAXF );
#else
if (ctx->Color.BlendEquation==GL_FUNC_ADD_EXT) {
diff --git a/src/mesa/swrast/s_tritemp.h b/src/mesa/swrast/s_tritemp.h
index ef5e00eb5bf..dcd1f4a8d88 100644
--- a/src/mesa/swrast/s_tritemp.h
+++ b/src/mesa/swrast/s_tritemp.h
@@ -1,4 +1,4 @@
-/* $Id: s_tritemp.h,v 1.39 2002/10/02 23:24:04 brianp Exp $ */
+/* $Id: s_tritemp.h,v 1.40 2002/10/17 15:26:39 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -115,7 +115,7 @@
GLfloat oneOverArea;
const SWvertex *vMin, *vMid, *vMax; /* Y(vMin)<=Y(vMid)<=Y(vMax) */
float bf = SWRAST_CONTEXT(ctx)->_backface_sign;
- const GLint snapMask = ~((FIXED_ONE / 16) - 1); /* for x/y coord snapping */
+ const GLint snapMask = ~((FIXED_ONE / (1 << SUB_PIXEL_BITS)) - 1); /* for x/y coord snapping */
GLfixed vMin_fx, vMin_fy, vMid_fx, vMid_fy, vMax_fx, vMax_fy;
struct sw_span span;
@@ -206,7 +206,7 @@
if (area * bf < 0.0)
return;
- if (area == 0.0F || IS_INF_OR_NAN(area))
+ if (IS_INF_OR_NAN(area) || area == 0.0F)
return;
oneOverArea = 1.0F / area;