summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mesa/main/colortab.c3
-rw-r--r--src/mesa/main/context.c6
-rw-r--r--src/mesa/main/convolve.c12
-rw-r--r--src/mesa/main/image.c32
-rw-r--r--src/mesa/main/image.h10
-rw-r--r--src/mesa/main/mtypes.h6
-rw-r--r--src/mesa/main/texstore.c5
-rw-r--r--src/mesa/swrast/s_copypix.c95
-rw-r--r--src/mesa/swrast/s_drawpix.c5
9 files changed, 92 insertions, 82 deletions
diff --git a/src/mesa/main/colortab.c b/src/mesa/main/colortab.c
index af7aa00512..862f210bb9 100644
--- a/src/mesa/main/colortab.c
+++ b/src/mesa/main/colortab.c
@@ -204,8 +204,7 @@ store_colortable_entries(GLcontext *ctx, struct gl_color_table *table,
tempTab, /* dest address */
format, type, data, /* src data */
&ctx->Unpack,
- 0, /* transfer ops */
- GL_FALSE); /* clamping */
+ IMAGE_CLAMP_BIT); /* transfer ops */
tableF = (GLfloat *) table->Table;
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 7de8115ad1..951763642b 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1133,6 +1133,12 @@ init_attrib_groups( GLcontext *ctx )
ctx->ErrorValue = (GLenum) GL_NO_ERROR;
ctx->CatchSignals = GL_TRUE;
ctx->_Facing = 0;
+#if CHAN_TYPE == GL_FLOAT
+ ctx->ClampFragmentColors = GL_FALSE; /* XXX temporary */
+#else
+ ctx->ClampFragmentColors = GL_TRUE;
+#endif
+ ctx->ClampVertexColors = GL_TRUE;
return GL_TRUE;
}
diff --git a/src/mesa/main/convolve.c b/src/mesa/main/convolve.c
index edb02482b3..c1965c5feb 100644
--- a/src/mesa/main/convolve.c
+++ b/src/mesa/main/convolve.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 5.1
+ * Version: 6.1
*
- * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2004 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"),
@@ -146,7 +146,7 @@ _mesa_ConvolutionFilter1D(GLenum target, GLenum internalFormat, GLsizei width, G
_mesa_unpack_color_span_float(ctx, width, GL_RGBA,
ctx->Convolution1D.Filter,
format, type, image, &ctx->Unpack,
- 0, GL_FALSE);
+ 0); /* transferOps */
/* apply scale and bias */
{
@@ -229,7 +229,7 @@ _mesa_ConvolutionFilter2D(GLenum target, GLenum internalFormat, GLsizei width, G
GLfloat *dst = ctx->Convolution2D.Filter + i * width * 4;
_mesa_unpack_color_span_float(ctx, width, GL_RGBA, dst,
format, type, src, &ctx->Unpack,
- 0, GL_FALSE);
+ 0); /* transferOps */
}
/* apply scale and bias */
@@ -810,7 +810,7 @@ _mesa_SeparableFilter2D(GLenum target, GLenum internalFormat, GLsizei width, GLs
_mesa_unpack_color_span_float(ctx, width, GL_RGBA,
ctx->Separable2D.Filter,
format, type, row, &ctx->Unpack,
- 0, GL_FALSE);
+ 0); /* transferOps */
/* apply scale and bias */
{
@@ -837,7 +837,7 @@ _mesa_SeparableFilter2D(GLenum target, GLenum internalFormat, GLsizei width, GLs
_mesa_unpack_color_span_float(ctx, width, GL_RGBA,
&ctx->Separable2D.Filter[colStart],
format, type, column, &ctx->Unpack,
- 0, GL_FALSE);
+ 0); /* transferOps */
/* apply scale and bias */
{
diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c
index ba5b4ff17a..5c117f6ce6 100644
--- a/src/mesa/main/image.c
+++ b/src/mesa/main/image.c
@@ -972,8 +972,7 @@ _mesa_apply_rgba_transfer_ops(GLcontext *ctx, GLuint transferOps,
if (transferOps & IMAGE_MIN_MAX_BIT) {
_mesa_update_minmax(ctx, n, (CONST GLfloat (*)[4]) rgba);
}
-
-#if CHAN_TYPE != GL_FLOAT
+ /* clamping to [0,1] */
if (transferOps & IMAGE_CLAMP_BIT) {
GLuint i;
for (i = 0; i < n; i++) {
@@ -983,7 +982,6 @@ _mesa_apply_rgba_transfer_ops(GLcontext *ctx, GLuint transferOps,
rgba[i][ACOMP] = CLAMP(rgba[i][ACOMP], 0.0F, 1.0F);
}
}
-#endif
}
@@ -1026,17 +1024,18 @@ _mesa_pack_rgba_span_float( GLcontext *ctx,
rgba = (const GLfloat (*)[4]) rgbaIn;
}
- /* XXX clamp rgba to [0,1]? */
-
if (dstFormat == GL_LUMINANCE || dstFormat == GL_LUMINANCE_ALPHA) {
/* compute luminance values */
- for (i = 0; i < n; i++) {
- GLfloat sum = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
-#if CHAN_TYPE == GL_FLOAT
- luminance[i] = sum;
-#else
- luminance[i] = CLAMP(sum, 0.0F, 1.0F);
-#endif
+ if (ctx->ClampFragmentColors) {
+ for (i = 0; i < n; i++) {
+ GLfloat sum = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
+ luminance[i] = CLAMP(sum, 0.0F, 1.0F);
+ }
+ }
+ else {
+ for (i = 0; i < n; i++) {
+ luminance[i] = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
+ }
}
}
@@ -2942,6 +2941,7 @@ _mesa_unpack_color_span_chan( GLcontext *ctx,
srcPacking->SwapBytes);
}
+ /* Need to clamp if returning GLubytes or GLushorts */
#if CHAN_TYPE != GL_FLOAT
transferOps |= IMAGE_CLAMP_BIT;
#endif
@@ -3069,7 +3069,7 @@ _mesa_unpack_color_span_float( GLcontext *ctx,
GLenum srcFormat, GLenum srcType,
const GLvoid *source,
const struct gl_pixelstore_attrib *srcPacking,
- GLuint transferOps, GLboolean clamp )
+ GLuint transferOps )
{
ASSERT(dstFormat == GL_ALPHA ||
dstFormat == GL_LUMINANCE ||
@@ -3169,12 +3169,6 @@ _mesa_unpack_color_span_float( GLcontext *ctx,
srcPacking->SwapBytes);
}
-#if CHAN_TYPE != GL_FLOAT
- if (clamp) {
- transferOps |= IMAGE_CLAMP_BIT;
- }
-#endif
-
if (transferOps) {
_mesa_apply_rgba_transfer_ops(ctx, transferOps, n, rgba);
}
diff --git a/src/mesa/main/image.h b/src/mesa/main/image.h
index cd79d5f223..b3757a30fd 100644
--- a/src/mesa/main/image.h
+++ b/src/mesa/main/image.h
@@ -110,10 +110,10 @@ _mesa_pack_rgba_span_float( GLcontext *ctx,
extern void
_mesa_pack_rgba_span_chan( GLcontext *ctx,
- GLuint n, CONST GLchan rgba[][4],
- GLenum dstFormat, GLenum dstType, GLvoid *dstAddr,
- const struct gl_pixelstore_attrib *dstPacking,
- GLuint transferOps );
+ GLuint n, CONST GLchan rgba[][4],
+ GLenum dstFormat, GLenum dstType, GLvoid *dstAddr,
+ const struct gl_pixelstore_attrib *dstPacking,
+ GLuint transferOps );
extern void
@@ -131,7 +131,7 @@ _mesa_unpack_color_span_float( GLcontext *ctx,
GLenum srcFormat, GLenum srcType,
const GLvoid *source,
const struct gl_pixelstore_attrib *srcPacking,
- GLuint transferOps, GLboolean clamp );
+ GLuint transferOps );
extern void
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index d1cfa4597b..1c03a05606 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2319,6 +2319,12 @@ struct __GLcontextRec {
GLfloat MRD; /**< minimum resolvable difference in Z values */
/*@}*/
+ /** \name Color clamping (tentative part of GL_ARB_color_clamp_control) */
+ /*@{*/
+ GLboolean ClampFragmentColors;
+ GLboolean ClampVertexColors;
+ /*@}*/
+
/** Should 3Dfx Glide driver catch signals? */
GLboolean CatchSignals;
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index 61bbc10bf6..315cd6ca2d 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -360,9 +360,8 @@ transfer_teximage(GLcontext *ctx, GLuint dimensions,
srcAddr, srcWidth, srcHeight,
srcFormat, srcType, img, row, 0);
_mesa_unpack_color_span_float(ctx, srcWidth, GL_RGBA, dstf,
- srcFormat, srcType, src, srcPacking,
- transferOps & IMAGE_PRE_CONVOLUTION_BITS,
- GL_TRUE);
+ srcFormat, srcType, src, srcPacking,
+ (transferOps & IMAGE_PRE_CONVOLUTION_BITS) | IMAGE_CLAMP_BIT);
dstf += srcWidth * 4;
}
diff --git a/src/mesa/swrast/s_copypix.c b/src/mesa/swrast/s_copypix.c
index 9176755e35..f715e5a626 100644
--- a/src/mesa/swrast/s_copypix.c
+++ b/src/mesa/swrast/s_copypix.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 5.1
+ * Version: 6.1
*
- * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2004 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"),
@@ -25,8 +25,10 @@
#include "glheader.h"
#include "context.h"
+#include "colormac.h"
#include "convolve.h"
#include "histogram.h"
+#include "image.h"
#include "macros.h"
#include "imports.h"
#include "pixel.h"
@@ -86,6 +88,40 @@ regions_overlap(GLint srcx, GLint srcy,
}
+/**
+ * Convert GLfloat[n][4] colors to GLchan[n][4].
+ * XXX maybe move into image.c
+ */
+static void
+float_span_to_chan(GLuint n, CONST GLfloat in[][4], GLchan out[][4])
+{
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ UNCLAMPED_FLOAT_TO_CHAN(out[i][RCOMP], in[i][RCOMP]);
+ UNCLAMPED_FLOAT_TO_CHAN(out[i][GCOMP], in[i][GCOMP]);
+ UNCLAMPED_FLOAT_TO_CHAN(out[i][BCOMP], in[i][BCOMP]);
+ UNCLAMPED_FLOAT_TO_CHAN(out[i][ACOMP], in[i][ACOMP]);
+ }
+}
+
+
+/**
+ * Convert GLchan[n][4] colors to GLfloat[n][4].
+ * XXX maybe move into image.c
+ */
+static void
+chan_span_to_float(GLuint n, CONST GLchan in[][4], GLfloat out[][4])
+{
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ out[i][RCOMP] = CHAN_TO_FLOAT(in[i][RCOMP]);
+ out[i][GCOMP] = CHAN_TO_FLOAT(in[i][GCOMP]);
+ out[i][BCOMP] = CHAN_TO_FLOAT(in[i][BCOMP]);
+ out[i][ACOMP] = CHAN_TO_FLOAT(in[i][ACOMP]);
+ }
+}
+
+
/*
* RGBA copypixels with convolution.
@@ -150,15 +186,11 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
dest = tmpImage;
for (row = 0; row < height; row++) {
GLchan rgba[MAX_WIDTH][4];
- GLint i;
- _swrast_read_rgba_span(ctx, ctx->ReadBuffer, width, srcx, srcy + row, rgba);
- /* convert GLchan to GLfloat */
- for (i = 0; i < width; i++) {
- *dest++ = (GLfloat) rgba[i][RCOMP] * (1.0F / CHAN_MAXF);
- *dest++ = (GLfloat) rgba[i][GCOMP] * (1.0F / CHAN_MAXF);
- *dest++ = (GLfloat) rgba[i][BCOMP] * (1.0F / CHAN_MAXF);
- *dest++ = (GLfloat) rgba[i][ACOMP] * (1.0F / CHAN_MAXF);
- }
+ /* Read GLchan and convert to GLfloat */
+ _swrast_read_rgba_span(ctx, ctx->ReadBuffer, width, srcx,
+ srcy + row, rgba);
+ chan_span_to_float(width, (CONST GLchan (*)[4]) rgba,
+ (GLfloat (*)[4]) dest);
}
if (changeBuffer) {
@@ -195,19 +227,10 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
/* write the new image */
for (row = 0; row < height; row++) {
const GLfloat *src = convImage + row * width * 4;
- GLint i, dy;
+ GLint dy;
- /* clamp to [0,1] and convert float back to chan */
- for (i = 0; i < width; i++) {
- GLint r = (GLint) (src[i * 4 + RCOMP] * CHAN_MAXF);
- GLint g = (GLint) (src[i * 4 + GCOMP] * CHAN_MAXF);
- GLint b = (GLint) (src[i * 4 + BCOMP] * CHAN_MAXF);
- GLint a = (GLint) (src[i * 4 + ACOMP] * CHAN_MAXF);
- span.array->rgba[i][RCOMP] = (GLchan) CLAMP(r, 0, CHAN_MAX);
- span.array->rgba[i][GCOMP] = (GLchan) CLAMP(g, 0, CHAN_MAX);
- span.array->rgba[i][BCOMP] = (GLchan) CLAMP(b, 0, CHAN_MAX);
- span.array->rgba[i][ACOMP] = (GLchan) CLAMP(a, 0, CHAN_MAX);
- }
+ /* convert floats back to chan */
+ float_span_to_chan(width, (const GLfloat (*)[4]) src, span.array->rgba);
if (ctx->Pixel.PixelTextureEnabled && ctx->Texture._EnabledUnits) {
span.end = width;
@@ -355,32 +378,16 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
}
if (transferOps) {
- const GLfloat scale = (1.0F / CHAN_MAXF);
- GLint k;
DEFMARRAY(GLfloat, rgbaFloat, MAX_WIDTH, 4); /* mac 32k limitation */
CHECKARRAY(rgbaFloat, return);
- /* convert chan to float */
- for (k = 0; k < width; k++) {
- rgbaFloat[k][RCOMP] = (GLfloat) span.array->rgba[k][RCOMP] * scale;
- rgbaFloat[k][GCOMP] = (GLfloat) span.array->rgba[k][GCOMP] * scale;
- rgbaFloat[k][BCOMP] = (GLfloat) span.array->rgba[k][BCOMP] * scale;
- rgbaFloat[k][ACOMP] = (GLfloat) span.array->rgba[k][ACOMP] * scale;
- }
-
+ /* convert to float, transfer, convert back to chan */
+ chan_span_to_float(width, (CONST GLchan (*)[4]) span.array->rgba,
+ rgbaFloat);
_mesa_apply_rgba_transfer_ops(ctx, transferOps, width, rgbaFloat);
+ float_span_to_chan(width, (CONST GLfloat (*)[4]) rgbaFloat,
+ span.array->rgba);
- /* clamp to [0,1] and convert float back to chan */
- for (k = 0; k < width; k++) {
- GLint r = (GLint) (rgbaFloat[k][RCOMP] * CHAN_MAXF);
- GLint g = (GLint) (rgbaFloat[k][GCOMP] * CHAN_MAXF);
- GLint b = (GLint) (rgbaFloat[k][BCOMP] * CHAN_MAXF);
- GLint a = (GLint) (rgbaFloat[k][ACOMP] * CHAN_MAXF);
- span.array->rgba[k][RCOMP] = (GLchan) CLAMP(r, 0, CHAN_MAX);
- span.array->rgba[k][GCOMP] = (GLchan) CLAMP(g, 0, CHAN_MAX);
- span.array->rgba[k][BCOMP] = (GLchan) CLAMP(b, 0, CHAN_MAX);
- span.array->rgba[k][ACOMP] = (GLchan) CLAMP(a, 0, CHAN_MAX);
- }
UNDEFARRAY(rgbaFloat); /* mac 32k limitation */
}
diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c
index cc2564f6c5..5b6f924405 100644
--- a/src/mesa/swrast/s_drawpix.c
+++ b/src/mesa/swrast/s_drawpix.c
@@ -803,9 +803,8 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y,
const GLvoid *source = _mesa_image_address(unpack,
pixels, width, height, format, type, 0, row, 0);
_mesa_unpack_color_span_float(ctx, width, GL_RGBA, (GLfloat *) dest,
- format, type, source, unpack,
- transferOps & IMAGE_PRE_CONVOLUTION_BITS,
- GL_FALSE);
+ format, type, source, unpack,
+ transferOps & IMAGE_PRE_CONVOLUTION_BITS);
dest += width * 4;
}