mesa: stop using MAX_WIDTH in glReadPixels code

Reviewed-by: José Fonseca <jfonseca@vmware.com>
This commit is contained in:
Brian Paul 2012-02-19 20:08:51 -07:00
parent 2e09fe4b9c
commit 531eaca41b

View file

@ -110,6 +110,7 @@ read_depth_pixels( struct gl_context *ctx,
GLint j; GLint j;
GLubyte *dst, *map; GLubyte *dst, *map;
int dstStride, stride; int dstStride, stride;
GLfloat *depthValues;
if (!rb) if (!rb)
return; return;
@ -119,8 +120,6 @@ read_depth_pixels( struct gl_context *ctx,
ASSERT(y >= 0); ASSERT(y >= 0);
ASSERT(x + width <= (GLint) rb->Width); ASSERT(x + width <= (GLint) rb->Width);
ASSERT(y + height <= (GLint) rb->Height); ASSERT(y + height <= (GLint) rb->Height);
/* width should never be > MAX_WIDTH since we did clipping earlier */
ASSERT(width <= MAX_WIDTH);
if (fast_read_depth_pixels(ctx, x, y, width, height, type, pixels, packing)) if (fast_read_depth_pixels(ctx, x, y, width, height, type, pixels, packing))
return; return;
@ -136,15 +135,23 @@ read_depth_pixels( struct gl_context *ctx,
return; return;
} }
depthValues = (GLfloat *) malloc(width * sizeof(GLfloat));
if (depthValues) {
/* General case (slower) */ /* General case (slower) */
for (j = 0; j < height; j++, y++) { for (j = 0; j < height; j++, y++) {
GLfloat depthValues[MAX_WIDTH];
_mesa_unpack_float_z_row(rb->Format, width, map, depthValues); _mesa_unpack_float_z_row(rb->Format, width, map, depthValues);
_mesa_pack_depth_span(ctx, width, dst, type, depthValues, packing); _mesa_pack_depth_span(ctx, width, dst, type, depthValues, packing);
dst += dstStride; dst += dstStride;
map += stride; map += stride;
} }
}
else {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
}
free(depthValues);
ctx->Driver.UnmapRenderbuffer(ctx, rb); ctx->Driver.UnmapRenderbuffer(ctx, rb);
} }
@ -163,15 +170,12 @@ read_stencil_pixels( struct gl_context *ctx,
struct gl_framebuffer *fb = ctx->ReadBuffer; struct gl_framebuffer *fb = ctx->ReadBuffer;
struct gl_renderbuffer *rb = fb->Attachment[BUFFER_STENCIL].Renderbuffer; struct gl_renderbuffer *rb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
GLint j; GLint j;
GLubyte *map; GLubyte *map, *stencil;
GLint stride; GLint stride;
if (!rb) if (!rb)
return; return;
/* width should never be > MAX_WIDTH since we did clipping earlier */
ASSERT(width <= MAX_WIDTH);
ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT, ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
&map, &stride); &map, &stride);
if (!map) { if (!map) {
@ -179,10 +183,12 @@ read_stencil_pixels( struct gl_context *ctx,
return; return;
} }
stencil = (GLubyte *) malloc(width * sizeof(GLubyte));
if (stencil) {
/* process image row by row */ /* process image row by row */
for (j = 0; j < height; j++) { for (j = 0; j < height; j++) {
GLvoid *dest; GLvoid *dest;
GLubyte stencil[MAX_WIDTH];
_mesa_unpack_ubyte_stencil_row(rb->Format, width, map, stencil); _mesa_unpack_ubyte_stencil_row(rb->Format, width, map, stencil);
dest = _mesa_image_address2d(packing, pixels, width, height, dest = _mesa_image_address2d(packing, pixels, width, height,
@ -192,6 +198,12 @@ read_stencil_pixels( struct gl_context *ctx,
map += stride; map += stride;
} }
}
else {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
}
free(stencil);
ctx->Driver.UnmapRenderbuffer(ctx, rb); ctx->Driver.UnmapRenderbuffer(ctx, rb);
} }
@ -378,7 +390,7 @@ fast_read_depth_stencil_pixels_separate(struct gl_context *ctx,
struct gl_framebuffer *fb = ctx->ReadBuffer; struct gl_framebuffer *fb = ctx->ReadBuffer;
struct gl_renderbuffer *depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer; struct gl_renderbuffer *depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
struct gl_renderbuffer *stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer; struct gl_renderbuffer *stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
GLubyte *depthMap, *stencilMap; GLubyte *depthMap, *stencilMap, *stencilVals;
int depthStride, stencilStride, i, j; int depthStride, stencilStride, i, j;
if (_mesa_get_format_datatype(depthRb->Format) != GL_UNSIGNED_NORMALIZED) if (_mesa_get_format_datatype(depthRb->Format) != GL_UNSIGNED_NORMALIZED)
@ -399,9 +411,10 @@ fast_read_depth_stencil_pixels_separate(struct gl_context *ctx,
return GL_TRUE; /* don't bother trying the slow path */ return GL_TRUE; /* don't bother trying the slow path */
} }
for (j = 0; j < height; j++) { stencilVals = (GLubyte *) malloc(width * sizeof(GLubyte));
GLubyte stencilVals[MAX_WIDTH];
if (stencilVals) {
for (j = 0; j < height; j++) {
_mesa_unpack_uint_z_row(depthRb->Format, width, depthMap, dst); _mesa_unpack_uint_z_row(depthRb->Format, width, depthMap, dst);
_mesa_unpack_ubyte_stencil_row(stencilRb->Format, width, _mesa_unpack_ubyte_stencil_row(stencilRb->Format, width,
stencilMap, stencilVals); stencilMap, stencilVals);
@ -414,6 +427,12 @@ fast_read_depth_stencil_pixels_separate(struct gl_context *ctx,
stencilMap += stencilStride; stencilMap += stencilStride;
dst += dstStride / 4; dst += dstStride / 4;
} }
}
else {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
}
free(stencilVals);
ctx->Driver.UnmapRenderbuffer(ctx, depthRb); ctx->Driver.UnmapRenderbuffer(ctx, depthRb);
ctx->Driver.UnmapRenderbuffer(ctx, stencilRb); ctx->Driver.UnmapRenderbuffer(ctx, stencilRb);
@ -434,6 +453,9 @@ slow_read_depth_stencil_pixels_separate(struct gl_context *ctx,
struct gl_renderbuffer *stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer; struct gl_renderbuffer *stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
GLubyte *depthMap, *stencilMap; GLubyte *depthMap, *stencilMap;
int depthStride, stencilStride, j; int depthStride, stencilStride, j;
GLubyte *stencilVals;
GLfloat *depthVals;
/* The depth and stencil buffers might be separate, or a single buffer. /* The depth and stencil buffers might be separate, or a single buffer.
* If one buffer, only map it once. * If one buffer, only map it once.
@ -460,10 +482,11 @@ slow_read_depth_stencil_pixels_separate(struct gl_context *ctx,
stencilStride = depthStride; stencilStride = depthStride;
} }
for (j = 0; j < height; j++) { stencilVals = (GLubyte *) malloc(width * sizeof(GLubyte));
GLubyte stencilVals[MAX_WIDTH]; depthVals = (GLfloat *) malloc(width * sizeof(GLfloat));
GLfloat depthVals[MAX_WIDTH];
if (stencilVals && depthVals) {
for (j = 0; j < height; j++) {
_mesa_unpack_float_z_row(depthRb->Format, width, depthMap, depthVals); _mesa_unpack_float_z_row(depthRb->Format, width, depthMap, depthVals);
_mesa_unpack_ubyte_stencil_row(stencilRb->Format, width, _mesa_unpack_ubyte_stencil_row(stencilRb->Format, width,
stencilMap, stencilVals); stencilMap, stencilVals);
@ -475,6 +498,13 @@ slow_read_depth_stencil_pixels_separate(struct gl_context *ctx,
stencilMap += stencilStride; stencilMap += stencilStride;
dst += dstStride; dst += dstStride;
} }
}
else {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
}
free(stencilVals);
free(depthVals);
ctx->Driver.UnmapRenderbuffer(ctx, depthRb); ctx->Driver.UnmapRenderbuffer(ctx, depthRb);
if (stencilRb != depthRb) { if (stencilRb != depthRb) {