summaryrefslogtreecommitdiff
path: root/src/mesa/main/image.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main/image.c')
-rw-r--r--src/mesa/main/image.c133
1 files changed, 84 insertions, 49 deletions
diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c
index caaf281657..ba46cdc1b1 100644
--- a/src/mesa/main/image.c
+++ b/src/mesa/main/image.c
@@ -1,6 +1,6 @@
/*
* Mesa 3-D graphics library
- * Version: 7.0
+ * Version: 7.1
*
* Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
*
@@ -3648,11 +3648,13 @@ _mesa_unpack_stencil_span( const GLcontext *ctx, GLuint n,
* Try simple cases first
*/
if (transferOps == 0 &&
+ !ctx->Pixel.MapStencilFlag &&
srcType == GL_UNSIGNED_BYTE &&
dstType == GL_UNSIGNED_BYTE) {
_mesa_memcpy(dest, source, n * sizeof(GLubyte));
}
else if (transferOps == 0 &&
+ !ctx->Pixel.MapStencilFlag &&
srcType == GL_UNSIGNED_INT &&
dstType == GL_UNSIGNED_INT &&
!srcPacking->SwapBytes) {
@@ -3668,19 +3670,17 @@ _mesa_unpack_stencil_span( const GLcontext *ctx, GLuint n,
extract_uint_indexes(n, indexes, GL_STENCIL_INDEX, srcType, source,
srcPacking);
- if (transferOps) {
- if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
- /* shift and offset indexes */
- shift_and_offset_ci(ctx, n, indexes);
- }
+ if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
+ /* shift and offset indexes */
+ shift_and_offset_ci(ctx, n, indexes);
+ }
- if (ctx->Pixel.MapStencilFlag) {
- /* Apply stencil lookup table */
- GLuint mask = ctx->PixelMaps.StoS.Size - 1;
- GLuint i;
- for (i=0;i<n;i++) {
- indexes[i] = ctx->PixelMaps.StoS.Map[ indexes[i] & mask ];
- }
+ if (ctx->Pixel.MapStencilFlag) {
+ /* Apply stencil lookup table */
+ const GLuint mask = ctx->PixelMaps.StoS.Size - 1;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ indexes[i] = ctx->PixelMaps.StoS.Map[ indexes[i] & mask ];
}
}
@@ -3878,17 +3878,28 @@ _mesa_pack_stencil_span( const GLcontext *ctx, GLuint n,
SWAP4BYTE(value); \
} \
} \
- depthValues[i] = CLAMP(GLTYPE2FLOAT(value), 0.0F, 1.0F); \
+ depthValues[i] = GLTYPE2FLOAT(value); \
} \
} while (0)
+
+/**
+ * Unpack a row of depth/z values from memory, returning GLushort, GLuint
+ * or GLfloat values.
+ * The glPixelTransfer (scale/bias) params will be applied.
+ *
+ * \param dstType one of GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, GL_FLOAT
+ * \param depthMax max value for returned GLushort or GLuint values
+ * (ignored for GLfloat).
+ */
void
_mesa_unpack_depth_span( const GLcontext *ctx, GLuint n,
- GLenum dstType, GLvoid *dest, GLfloat depthScale,
+ GLenum dstType, GLvoid *dest, GLuint depthMax,
GLenum srcType, const GLvoid *source,
const struct gl_pixelstore_attrib *srcPacking )
{
GLfloat depthTemp[MAX_WIDTH], *depthValues;
+ GLboolean needClamp = GL_FALSE;
/* Look for special cases first.
* Not only are these faster, they're less prone to numeric conversion
@@ -3906,7 +3917,9 @@ _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n,
}
return;
}
- if (srcType == GL_UNSIGNED_SHORT && dstType == GL_UNSIGNED_INT) {
+ if (srcType == GL_UNSIGNED_SHORT
+ && dstType == GL_UNSIGNED_INT
+ && depthMax == 0xffffffff) {
const GLushort *src = (const GLushort *) source;
GLuint *dst = (GLuint *) dest;
GLuint i;
@@ -3918,7 +3931,7 @@ _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n,
/* XXX may want to add additional cases here someday */
}
- /* general case path */
+ /* general case path follows */
if (dstType == GL_FLOAT) {
depthValues = (GLfloat *) dest;
@@ -3927,32 +3940,34 @@ _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n,
depthValues = depthTemp;
}
- /* XXX we need to obey srcPacking->SwapBytes here!!! */
- (void) srcPacking;
-
- /* convert incoming values to GLfloat */
+ /* Convert incoming values to GLfloat. Some conversions will require
+ * clamping, below.
+ */
switch (srcType) {
case GL_BYTE:
- DEPTH_VALUES(GLbyte, BYTE_TO_FLOAT);
- break;
+ DEPTH_VALUES(GLbyte, BYTE_TO_FLOAT);
+ needClamp = GL_TRUE;
+ break;
case GL_UNSIGNED_BYTE:
- DEPTH_VALUES(GLubyte, UBYTE_TO_FLOAT);
- break;
+ DEPTH_VALUES(GLubyte, UBYTE_TO_FLOAT);
+ break;
case GL_SHORT:
- DEPTH_VALUES(GLshort, SHORT_TO_FLOAT);
- break;
+ DEPTH_VALUES(GLshort, SHORT_TO_FLOAT);
+ needClamp = GL_TRUE;
+ break;
case GL_UNSIGNED_SHORT:
- DEPTH_VALUES(GLushort, USHORT_TO_FLOAT);
- break;
+ DEPTH_VALUES(GLushort, USHORT_TO_FLOAT);
+ break;
case GL_INT:
- DEPTH_VALUES(GLint, INT_TO_FLOAT);
- break;
+ DEPTH_VALUES(GLint, INT_TO_FLOAT);
+ needClamp = GL_TRUE;
+ break;
case GL_UNSIGNED_INT:
- DEPTH_VALUES(GLuint, UINT_TO_FLOAT);
- break;
+ DEPTH_VALUES(GLuint, UINT_TO_FLOAT);
+ break;
case GL_UNSIGNED_INT_24_8_EXT: /* GL_EXT_packed_depth_stencil */
if (dstType == GL_UNSIGNED_INT &&
- depthScale == (GLfloat) 0xffffff &&
+ depthMax == 0xffffff &&
ctx->Pixel.DepthScale == 1.0 &&
ctx->Pixel.DepthBias == 0.0) {
const GLuint *src = (const GLuint *) source;
@@ -3981,19 +3996,21 @@ _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n,
}
break;
case GL_FLOAT:
- DEPTH_VALUES(GLfloat, 1*);
- break;
+ DEPTH_VALUES(GLfloat, 1*);
+ needClamp = GL_TRUE;
+ break;
case GL_HALF_FLOAT_ARB:
{
GLuint i;
const GLhalfARB *src = (const GLhalfARB *) source;
for (i = 0; i < n; i++) {
- GLhalfARB value = src[i];
- if (srcPacking->SwapBytes) {
- SWAP2BYTE(value);
- }
+ GLhalfARB value = src[i];
+ if (srcPacking->SwapBytes) {
+ SWAP2BYTE(value);
+ }
depthValues[i] = _mesa_half_to_float(value);
}
+ needClamp = GL_TRUE;
}
break;
default:
@@ -4001,25 +4018,43 @@ _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n,
return;
}
+ /* apply depth scale and bias */
+ {
+ const GLfloat scale = ctx->Pixel.DepthScale;
+ const GLfloat bias = ctx->Pixel.DepthBias;
+ if (scale != 1.0 || bias != 0.0) {
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ depthValues[i] = depthValues[i] * scale + bias;
+ }
+ needClamp = GL_TRUE;
+ }
+ }
- /* apply depth scale and bias and clamp to [0,1] */
- if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0) {
- _mesa_scale_and_bias_depth(ctx, n, depthValues);
+ /* clamp to [0, 1] */
+ if (needClamp) {
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ depthValues[i] = CLAMP(depthValues[i], 0.0, 1.0);
+ }
}
+ /*
+ * Convert values to dstType
+ */
if (dstType == GL_UNSIGNED_INT) {
GLuint *zValues = (GLuint *) dest;
GLuint i;
- if (depthScale <= (GLfloat) 0xffffff) {
+ if (depthMax <= 0xffffff) {
/* no overflow worries */
for (i = 0; i < n; i++) {
- zValues[i] = (GLuint) (depthValues[i] * depthScale);
+ zValues[i] = (GLuint) (depthValues[i] * (GLfloat) depthMax);
}
}
else {
/* need to use double precision to prevent overflow problems */
for (i = 0; i < n; i++) {
- GLdouble z = depthValues[i] * depthScale;
+ GLdouble z = depthValues[i] * (GLfloat) depthMax;
if (z >= (GLdouble) 0xffffffff)
zValues[i] = 0xffffffff;
else
@@ -4030,14 +4065,14 @@ _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n,
else if (dstType == GL_UNSIGNED_SHORT) {
GLushort *zValues = (GLushort *) dest;
GLuint i;
- ASSERT(depthScale <= 65535.0);
+ ASSERT(depthMax <= 0xffff);
for (i = 0; i < n; i++) {
- zValues[i] = (GLushort) (depthValues[i] * depthScale);
+ zValues[i] = (GLushort) (depthValues[i] * (GLfloat) depthMax);
}
}
else {
ASSERT(dstType == GL_FLOAT);
- ASSERT(depthScale == 1.0F);
+ /*ASSERT(depthMax == 1.0F);*/
}
}