*/
void
st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
- GLsizei width, GLsizei height, GLenum type,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
const struct gl_pixelstore_attrib *packing,
GLvoid *pixels)
{
struct gl_framebuffer *fb = ctx->ReadBuffer;
struct pipe_screen *screen = ctx->st->pipe->screen;
struct st_renderbuffer *strb = st_renderbuffer(fb->_StencilBuffer);
- struct pipe_surface *ps;
+ struct pipe_transfer *pt;
ubyte *stmap;
GLint j;
- /* Create a CPU-READ surface/view into the renderbuffer's texture */
- ps = screen->get_tex_surface(screen, strb->texture, 0, 0, 0,
- PIPE_BUFFER_USAGE_CPU_READ);
+ 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 = screen->get_tex_transfer(screen, strb->texture, 0, 0, 0,
+ PIPE_TRANSFER_READ, x, y, width, height);
/* map the stencil buffer */
- stmap = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_READ);
+ stmap = screen->transfer_map(screen, pt);
/* width should never be > MAX_WIDTH since we did clipping earlier */
ASSERT(width <= MAX_WIDTH);
/* process image row by row */
- for (j = 0; j < height; j++, y++) {
+ for (j = 0; j < height; j++) {
GLvoid *dest;
- GLstencil values[MAX_WIDTH];
+ GLstencil sValues[MAX_WIDTH];
+ GLfloat zValues[MAX_WIDTH];
GLint srcY;
if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
- srcY = ctx->DrawBuffer->Height - y - 1;
+ srcY = height - j - 1;
}
else {
- srcY = y;
+ srcY = j;
}
- /* get stencil values */
- switch (ps->format) {
+ /* get stencil (and Z) values */
+ switch (pt->format) {
case PIPE_FORMAT_S8_UNORM:
{
- const ubyte *src = stmap + srcY * ps->stride + x;
- memcpy(values, src, width);
+ const ubyte *src = stmap + srcY * pt->stride;
+ memcpy(sValues, src, width);
}
break;
case PIPE_FORMAT_S8Z24_UNORM:
- {
- const uint *src = (uint *) (stmap + srcY * ps->stride + x*4);
+ if (format == GL_DEPTH_STENCIL) {
+ const uint *src = (uint *) (stmap + srcY * pt->stride);
+ const GLfloat scale = 1.0 / (0xffffff);
GLint k;
for (k = 0; k < width; k++) {
- values[k] = src[k] >> 24;
+ sValues[k] = src[k] >> 24;
+ zValues[k] = (src[k] & 0xffffff) * scale;
+ }
+ }
+ else {
+ const uint *src = (uint *) (stmap + srcY * pt->stride);
+ GLint k;
+ for (k = 0; k < width; k++) {
+ sValues[k] = src[k] >> 24;
}
}
break;
case PIPE_FORMAT_Z24S8_UNORM:
- {
- const uint *src = (uint *) (stmap + srcY * ps->stride + x*4);
+ if (format == GL_DEPTH_STENCIL) {
+ const uint *src = (uint *) (stmap + srcY * pt->stride);
+ const GLfloat scale = 1.0 / (0xffffff);
GLint k;
for (k = 0; k < width; k++) {
- values[k] = src[k] & 0xff;
+ sValues[k] = src[k] & 0xff;
+ zValues[k] = (src[k] >> 8) * scale;
+ }
+ }
+ else {
+ const uint *src = (uint *) (stmap + srcY * pt->stride);
+ GLint k;
+ for (k = 0; k < width; k++) {
+ sValues[k] = src[k] & 0xff;
}
}
break;
/* store */
dest = _mesa_image_address2d(packing, pixels, width, height,
- GL_STENCIL_INDEX, type, j, 0);
-
- _mesa_pack_stencil_span(ctx, width, type, dest, values, packing);
+ format, type, j, 0);
+ if (format == GL_DEPTH_STENCIL) {
+ _mesa_pack_depth_stencil_span(ctx, width, dest,
+ zValues, sValues, packing);
+ }
+ else {
+ _mesa_pack_stencil_span(ctx, width, type, dest, sValues, packing);
+ }
}
-
/* unmap the stencil buffer */
- screen->surface_unmap(screen, ps);
- pipe_surface_reference(&ps, NULL);
+ screen->transfer_unmap(screen, pt);
+ screen->tex_transfer_destroy(pt);
}
{
struct pipe_context *pipe = ctx->st->pipe;
struct pipe_screen *screen = pipe->screen;
- struct pipe_surface *surf;
+ struct pipe_transfer *trans;
const GLubyte *map;
GLubyte *dst;
GLint row, col, dy, dstStride;
- surf = screen->get_tex_surface(screen, strb->texture, 0, 0, 0,
- PIPE_BUFFER_USAGE_CPU_READ);
- if (!surf) {
+ if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+ y = strb->texture->height[0] - y - height;
+ }
+
+ trans = screen->get_tex_transfer(screen, strb->texture, 0, 0, 0,
+ PIPE_TRANSFER_READ, x, y, width, height);
+ if (!trans) {
return GL_FALSE;
}
- map = screen->surface_map(screen, surf, PIPE_BUFFER_USAGE_CPU_READ);
+ map = screen->transfer_map(screen, trans);
if (!map) {
- pipe_surface_reference(&surf, NULL);
+ screen->tex_transfer_destroy(trans);
return GL_FALSE;
}
if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
- y = surf->height - y - 1;
+ y = height - 1;
dy = -1;
}
else {
+ y = 0;
dy = 1;
}
switch (combo) {
case A8R8G8B8_UNORM_TO_RGBA_UBYTE:
for (row = 0; row < height; row++) {
- const GLubyte *src = map + y * surf->stride + x * 4;
+ const GLubyte *src = map + y * trans->stride;
for (col = 0; col < width; col++) {
GLuint pixel = ((GLuint *) src)[col];
dst[col*4+0] = (pixel >> 16) & 0xff;
break;
case A8R8G8B8_UNORM_TO_RGB_UBYTE:
for (row = 0; row < height; row++) {
- const GLubyte *src = map + y * surf->stride + x * 4;
+ const GLubyte *src = map + y * trans->stride;
for (col = 0; col < width; col++) {
GLuint pixel = ((GLuint *) src)[col];
dst[col*3+0] = (pixel >> 16) & 0xff;
break;
case A8R8G8B8_UNORM_TO_BGRA_UINT:
for (row = 0; row < height; row++) {
- const GLubyte *src = map + y * surf->stride + x * 4;
+ const GLubyte *src = map + y * trans->stride;
memcpy(dst, src, 4 * width);
dst += dstStride;
y += dy;
; /* nothing */
}
- screen->surface_unmap(screen, surf);
- pipe_surface_reference(&surf, NULL);
+ screen->transfer_unmap(screen, trans);
+ screen->tex_transfer_destroy(trans);
}
return GL_TRUE;
/**
- * Do glReadPixels by getting rows from the framebuffer surface with
+ * Do glReadPixels by getting rows from the framebuffer transfer with
* get_tile(). Convert to requested format/type with Mesa image routines.
* Image transfer ops are done in software too.
*/
GLfloat *df;
struct st_renderbuffer *strb;
struct gl_pixelstore_attrib clippedPacking = *pack;
- struct pipe_surface *surf;
+ struct pipe_transfer *trans;
assert(ctx->ReadBuffer->Width > 0);
/* Do all needed clipping here, so that we can forget about it later */
if (!_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) {
- /* The ReadPixels surface is totally outside the window bounds */
+ /* The ReadPixels transfer is totally outside the window bounds */
return;
}
if (!dest)
return;
- st_flush_bitmap_cache(ctx->st);
-
/* make sure rendering has completed */
- pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
+ st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
- if (format == GL_STENCIL_INDEX) {
- st_read_stencil_pixels(ctx, x, y, width, height, type, pack, dest);
+ if (format == GL_STENCIL_INDEX ||
+ format == GL_DEPTH_STENCIL) {
+ st_read_stencil_pixels(ctx, x, y, width, height,
+ format, type, pack, dest);
return;
}
else if (format == GL_DEPTH_COMPONENT) {
dfStride = 0;
}
+ if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
+ y = strb->Base.Height - y - height;
+ }
+
+ /* Create a read transfer from the renderbuffer's texture */
+ trans = screen->get_tex_transfer(screen, strb->texture, 0, 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) {
- y = strb->Base.Height - 1 - y;
+ y = height - 1;
yStep = -1;
}
else {
+ y = 0;
yStep = 1;
}
- /* Create a CPU-READ surface/view into the renderbuffer's texture */
- surf = screen->get_tex_surface(screen, strb->texture, 0, 0, 0,
- PIPE_BUFFER_USAGE_CPU_READ);
-
/*
- * Copy pixels from pipe_surface to user memory
+ * Copy pixels from pipe_transfer to user memory
*/
{
/* dest of first pixel in client memory */
const GLint dstStride = _mesa_image_row_stride(&clippedPacking, width,
format, type);
- if (surf->format == PIPE_FORMAT_S8Z24_UNORM ||
- surf->format == PIPE_FORMAT_X8Z24_UNORM) {
+ if (trans->format == PIPE_FORMAT_S8Z24_UNORM ||
+ trans->format == PIPE_FORMAT_X8Z24_UNORM) {
if (format == GL_DEPTH_COMPONENT) {
for (i = 0; i < height; i++) {
GLuint ztemp[MAX_WIDTH];
GLfloat zfloat[MAX_WIDTH];
const double scale = 1.0 / ((1 << 24) - 1);
- pipe_get_tile_raw(surf, x, y, width, 1, ztemp, 0);
+ pipe_get_tile_raw(trans, 0, y, width, 1, ztemp, 0);
y += yStep;
for (j = 0; j < width; j++) {
zfloat[j] = (float) (scale * (ztemp[j] & 0xffffff));
/* untested, but simple: */
assert(format == GL_DEPTH_STENCIL_EXT);
for (i = 0; i < height; i++) {
- pipe_get_tile_raw(surf, x, y, width, 1, dst, 0);
+ pipe_get_tile_raw(trans, 0, y, width, 1, dst, 0);
+ y += yStep;
+ dst += dstStride;
+ }
+ }
+ }
+ else if (trans->format == PIPE_FORMAT_Z24S8_UNORM ||
+ trans->format == PIPE_FORMAT_Z24X8_UNORM) {
+ if (format == GL_DEPTH_COMPONENT) {
+ for (i = 0; i < height; i++) {
+ GLuint ztemp[MAX_WIDTH];
+ GLfloat zfloat[MAX_WIDTH];
+ const double scale = 1.0 / ((1 << 24) - 1);
+ pipe_get_tile_raw(trans, 0, y, width, 1, ztemp, 0);
+ y += yStep;
+ for (j = 0; j < width; j++) {
+ zfloat[j] = (float) (scale * ((ztemp[j] >> 8) & 0xffffff));
+ }
+ _mesa_pack_depth_span(ctx, width, dst, type,
+ zfloat, &clippedPacking);
+ dst += dstStride;
+ }
+ }
+ else {
+ /* untested, but simple: */
+ assert(format == GL_DEPTH_STENCIL_EXT);
+ for (i = 0; i < height; i++) {
+ pipe_get_tile_raw(trans, 0, y, width, 1, dst, 0);
y += yStep;
dst += dstStride;
}
}
}
- else if (surf->format == PIPE_FORMAT_Z16_UNORM) {
+ else if (trans->format == PIPE_FORMAT_Z16_UNORM) {
for (i = 0; i < height; i++) {
GLushort ztemp[MAX_WIDTH];
GLfloat zfloat[MAX_WIDTH];
const double scale = 1.0 / 0xffff;
- pipe_get_tile_raw(surf, x, y, width, 1, ztemp, 0);
+ pipe_get_tile_raw(trans, 0, y, width, 1, ztemp, 0);
y += yStep;
for (j = 0; j < width; j++) {
zfloat[j] = (float) (scale * ztemp[j]);
dst += dstStride;
}
}
- else if (surf->format == PIPE_FORMAT_Z32_UNORM) {
+ else if (trans->format == PIPE_FORMAT_Z32_UNORM) {
for (i = 0; i < height; i++) {
GLuint ztemp[MAX_WIDTH];
GLfloat zfloat[MAX_WIDTH];
const double scale = 1.0 / 0xffffffff;
- pipe_get_tile_raw(surf, x, y, width, 1, ztemp, 0);
+ pipe_get_tile_raw(trans, 0, y, width, 1, ztemp, 0);
y += yStep;
for (j = 0; j < width; j++) {
zfloat[j] = (float) (scale * ztemp[j]);
/* RGBA format */
/* Do a row at a time to flip image data vertically */
for (i = 0; i < height; i++) {
- pipe_get_tile_rgba(surf, x, y, width, 1, df);
+ pipe_get_tile_rgba(trans, 0, y, width, 1, df);
y += yStep;
df += dfStride;
if (!dfStride) {
}
}
- pipe_surface_reference(&surf, NULL);
+ screen->tex_transfer_destroy(trans);
_mesa_unmap_readpix_pbo(ctx, &clippedPacking);
}