#include "main/bufferobj.h"
#include "main/context.h"
#include "main/image.h"
+#include "main/pack.h"
+#include "main/pbo.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
+#include "util/u_format.h"
#include "util/u_inlines.h"
#include "util/u_tile.h"
* For color/depth we use get_tile(). For stencil, map the stencil buffer.
*/
void
-st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
+st_read_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
GLsizei width, GLsizei height,
GLenum format, GLenum type,
const struct gl_pixelstore_attrib *packing,
ubyte *stmap;
GLint j;
+ if (strb->Base.Wrapped) {
+ strb = st_renderbuffer(strb->Base.Wrapped);
+ }
+
if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
y = ctx->DrawBuffer->Height - y - height;
}
/* Create a read transfer from the renderbuffer's texture */
- pt = pipe_get_transfer(st_context(ctx)->pipe, strb->texture,
- 0, 0, 0,
- PIPE_TRANSFER_READ, x, y,
- width, height);
+ pt = pipe_get_transfer(pipe, strb->texture,
+ 0, 0,
+ PIPE_TRANSFER_READ,
+ x, y, width, height);
/* map the stencil buffer */
stmap = pipe_transfer_map(pipe, pt);
* commands.
*/
struct st_renderbuffer *
-st_get_color_read_renderbuffer(GLcontext *ctx)
+st_get_color_read_renderbuffer(struct gl_context *ctx)
{
struct gl_framebuffer *fb = ctx->ReadBuffer;
struct st_renderbuffer *strb =
* \return GL_TRUE for success, GL_FALSE for failure
*/
static GLboolean
-st_fast_readpixels(GLcontext *ctx, struct st_renderbuffer *strb,
+st_fast_readpixels(struct gl_context *ctx, struct st_renderbuffer *strb,
GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type,
const struct gl_pixelstore_attrib *pack,
y = strb->texture->height0 - y - height;
}
- trans = pipe_get_transfer(st_context(ctx)->pipe, strb->texture,
- 0, 0, 0,
- PIPE_TRANSFER_READ, x, y,
- width, height);
+ trans = pipe_get_transfer(pipe, strb->texture,
+ 0, 0,
+ PIPE_TRANSFER_READ,
+ x, y, width, height);
if (!trans) {
return GL_FALSE;
}
* Image transfer ops are done in software too.
*/
static void
-st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
+st_readpixels(struct gl_context *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type,
const struct gl_pixelstore_attrib *pack,
GLvoid *dest)
{
struct st_context *st = st_context(ctx);
struct pipe_context *pipe = st->pipe;
- GLfloat temp[MAX_WIDTH][4];
- const GLbitfield transferOps = ctx->_ImageTransferState;
+ GLfloat (*temp)[4];
+ GLbitfield transferOps = ctx->_ImageTransferState;
GLsizei i, j;
GLint yStep, dfStride;
GLfloat *df;
struct st_renderbuffer *strb;
struct gl_pixelstore_attrib clippedPacking = *pack;
struct pipe_transfer *trans;
+ enum pipe_format pformat;
assert(ctx->ReadBuffer->Width > 0);
- /* XXX convolution not done yet */
- assert((transferOps & IMAGE_CONVOLUTION_BIT) == 0);
-
st_validate_state(st);
/* Do all needed clipping here, so that we can forget about it later */
}
else if (format == GL_DEPTH_COMPONENT) {
strb = st_renderbuffer(ctx->ReadBuffer->_DepthBuffer);
+ if (strb->Base.Wrapped) {
+ strb = st_renderbuffer(strb->Base.Wrapped);
+ }
}
else {
/* Read color buffer */
return;
}
- if (format == GL_RGBA && type == GL_FLOAT) {
+ /* allocate temp pixel row buffer */
+ temp = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
+ if (!temp) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
+ return;
+ }
+
+ 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);
}
/* Create a read transfer from the renderbuffer's texture */
- trans = pipe_get_transfer(st_context(ctx)->pipe, strb->texture,
- 0, 0, 0,
- PIPE_TRANSFER_READ, x, y,
- width, height);
+ trans = pipe_get_transfer(pipe, strb->texture,
+ 0, 0,
+ PIPE_TRANSFER_READ,
+ x, y, width, height);
/* determine bottom-to-top vs. top-to-bottom order */
if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
yStep = 1;
}
+ /* possibly convert sRGB format to linear RGB format */
+ pformat = util_format_linear(trans->resource->format);
+
if (ST_DEBUG & DEBUG_FALLBACK)
debug_printf("%s: fallback processing\n", __FUNCTION__);
const GLint dstStride = _mesa_image_row_stride(&clippedPacking, width,
format, type);
- if (trans->resource->format == PIPE_FORMAT_Z24_UNORM_S8_USCALED ||
- trans->resource->format == PIPE_FORMAT_Z24X8_UNORM) {
+ if (pformat == PIPE_FORMAT_Z24_UNORM_S8_USCALED ||
+ pformat == PIPE_FORMAT_Z24X8_UNORM) {
if (format == GL_DEPTH_COMPONENT) {
for (i = 0; i < height; i++) {
GLuint ztemp[MAX_WIDTH];
}
}
}
- else if (trans->resource->format == PIPE_FORMAT_S8_USCALED_Z24_UNORM ||
- trans->resource->format == PIPE_FORMAT_X8Z24_UNORM) {
+ else if (pformat == PIPE_FORMAT_S8_USCALED_Z24_UNORM ||
+ pformat == PIPE_FORMAT_X8Z24_UNORM) {
if (format == GL_DEPTH_COMPONENT) {
for (i = 0; i < height; i++) {
GLuint ztemp[MAX_WIDTH];
}
}
}
- else if (trans->resource->format == PIPE_FORMAT_Z16_UNORM) {
+ else if (pformat == PIPE_FORMAT_Z16_UNORM) {
for (i = 0; i < height; i++) {
GLushort ztemp[MAX_WIDTH];
GLfloat zfloat[MAX_WIDTH];
dst += dstStride;
}
}
- else if (trans->resource->format == PIPE_FORMAT_Z32_UNORM) {
+ else if (pformat == PIPE_FORMAT_Z32_UNORM) {
for (i = 0; i < height; i++) {
GLuint ztemp[MAX_WIDTH];
GLfloat zfloat[MAX_WIDTH];
/* RGBA format */
/* Do a row at a time to flip image data vertically */
for (i = 0; i < height; i++) {
- pipe_get_tile_rgba(pipe, trans, 0, y, width, 1, df);
+ pipe_get_tile_rgba_format(pipe, trans, 0, y, width, 1,
+ pformat, df);
y += yStep;
df += dfStride;
if (!dfStride) {
}
}
+ free(temp);
+
pipe->transfer_destroy(pipe, trans);
_mesa_unmap_pbo_dest(ctx, &clippedPacking);