Commit aef5c3c6 authored by Luca Barbieri's avatar Luca Barbieri

mesa, mesa/st: handle read color clamping properly

This follows the idea in this comment:
/* XXX
 * This test should probably go away.  Have the caller set/clear the
 * IMAGE_CLAMP_BIT as needed.
 */

We set IMAGE_CLAMP_BIT in the caller based on _ClampReadColor, where
the operation mandates it.

TODO: did I get the set of operations mandating it right?
parent 3a9cb5e5
......@@ -580,6 +580,7 @@ _mesa_GetColorTable( GLenum target, GLenum format,
struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
struct gl_color_table *table = NULL;
GLfloat rgba[MAX_COLOR_TABLE_SIZE][4];
GLbitfield transferOps = 0;
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
if (ctx->NewState) {
......@@ -698,8 +699,12 @@ _mesa_GetColorTable( GLenum target, GLenum format,
if (!data)
return;
/* TODO: is this correct? */
if(ctx->Color._ClampReadColor)
transferOps |= IMAGE_CLAMP_BIT;
_mesa_pack_rgba_span_float(ctx, table->Size, rgba,
format, type, data, &ctx->Pack, 0x0);
format, type, data, &ctx->Pack, transferOps);
_mesa_unmap_pbo_dest(ctx, &ctx->Pack);
}
......
......@@ -537,6 +537,7 @@ _mesa_GetConvolutionFilter(GLenum target, GLenum format, GLenum type,
{
struct gl_convolution_attrib *filter;
GLuint row;
GLbitfield transferOps = 0;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
......@@ -577,13 +578,17 @@ _mesa_GetConvolutionFilter(GLenum target, GLenum format, GLenum type,
if (!image)
return;
/* TODO: is this correct? */
if(ctx->Color._ClampReadColor)
transferOps |= IMAGE_CLAMP_BIT;
for (row = 0; row < filter->Height; row++) {
GLvoid *dst = _mesa_image_address2d(&ctx->Pack, image, filter->Width,
filter->Height, format, type,
row, 0);
GLfloat (*src)[4] = (GLfloat (*)[4]) (filter->Filter + row * filter->Width * 4);
_mesa_pack_rgba_span_float(ctx, filter->Width, src,
format, type, dst, &ctx->Pack, 0x0);
format, type, dst, &ctx->Pack, transferOps);
}
_mesa_unmap_pbo_dest(ctx, &ctx->Pack);
......@@ -727,6 +732,7 @@ _mesa_GetSeparableFilter(GLenum target, GLenum format, GLenum type,
{
const GLint colStart = MAX_CONVOLUTION_WIDTH * 4;
struct gl_convolution_attrib *filter;
GLbitfield transferOps = 0;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
......@@ -756,6 +762,10 @@ _mesa_GetSeparableFilter(GLenum target, GLenum format, GLenum type,
filter = &ctx->Separable2D;
/* TODO: is this correct? */
if(ctx->Color._ClampReadColor)
transferOps |= IMAGE_CLAMP_BIT;
/* Get row filter */
row = _mesa_map_validate_pbo_dest(ctx, 1, &ctx->Pack,
filter->Width, 1, 1,
......@@ -766,7 +776,7 @@ _mesa_GetSeparableFilter(GLenum target, GLenum format, GLenum type,
format, type, 0);
_mesa_pack_rgba_span_float(ctx, filter->Width,
(GLfloat (*)[4]) filter->Filter,
format, type, dst, &ctx->Pack, 0x0);
format, type, dst, &ctx->Pack, transferOps);
_mesa_unmap_pbo_dest(ctx, &ctx->Pack);
}
......@@ -780,7 +790,7 @@ _mesa_GetSeparableFilter(GLenum target, GLenum format, GLenum type,
format, type, 0);
GLfloat (*src)[4] = (GLfloat (*)[4]) (filter->Filter + colStart);
_mesa_pack_rgba_span_float(ctx, filter->Height, src,
format, type, dst, &ctx->Pack, 0x0);
format, type, dst, &ctx->Pack, transferOps);
_mesa_unmap_pbo_dest(ctx, &ctx->Pack);
}
......
......@@ -626,6 +626,7 @@ static void GLAPIENTRY _mesa_ResetMinmax(GLenum target);
static void GLAPIENTRY
_mesa_GetMinmax(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values)
{
GLbitfield transferOps = 0;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
......@@ -664,6 +665,13 @@ _mesa_GetMinmax(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvo
if (!values)
return;
if(ctx->NewState & (_NEW_BUFFERS | _NEW_COLOR))
_mesa_update_state(ctx);
/* TODO: is this correct? */
if(ctx->Color._ClampReadColor)
transferOps |= IMAGE_CLAMP_BIT;
{
GLfloat minmax[2][4];
minmax[0][RCOMP] = CLAMP(ctx->MinMax.Min[RCOMP], 0.0F, 1.0F);
......@@ -675,7 +683,7 @@ _mesa_GetMinmax(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvo
minmax[1][BCOMP] = CLAMP(ctx->MinMax.Max[BCOMP], 0.0F, 1.0F);
minmax[1][ACOMP] = CLAMP(ctx->MinMax.Max[ACOMP], 0.0F, 1.0F);
_mesa_pack_rgba_span_float(ctx, 2, minmax,
format, type, values, &ctx->Pack, 0x0);
format, type, values, &ctx->Pack, transferOps);
}
_mesa_unmap_pbo_dest(ctx, &ctx->Pack);
......
......@@ -2121,11 +2121,7 @@ _mesa_pack_rgba_span_float(GLcontext *ctx, GLuint n, GLfloat rgba[][4],
const GLint comps = _mesa_components_in_format(dstFormat);
GLuint i;
/* XXX
* This test should probably go away. Have the caller set/clear the
* IMAGE_CLAMP_BIT as needed.
*/
if (dstType != GL_FLOAT || ctx->Color.ClampReadColor == GL_TRUE) {
if (dstType != GL_FLOAT) {
/* need to clamp to [0, 1] */
transferOps |= IMAGE_CLAMP_BIT;
}
......
......@@ -328,7 +328,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
struct st_context *st = st_context(ctx);
struct pipe_context *pipe = st->pipe;
GLfloat temp[MAX_WIDTH][4];
const GLbitfield transferOps = ctx->_ImageTransferState;
GLbitfield transferOps = ctx->_ImageTransferState;
GLsizei i, j;
GLint yStep, dfStride;
GLfloat *df;
......@@ -383,7 +383,10 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
return;
}
if (format == GL_RGBA && type == GL_FLOAT) {
if(ctx->Color._ClampReadColor)
transferOps |= IMAGE_CLAMP_BIT;
if (format == GL_RGBA && type == GL_FLOAT && !transferOps) {
/* write tile(row) directly into user's buffer */
df = (GLfloat *) _mesa_image_address2d(&clippedPacking, dest, width,
height, format, type, 0, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment