From 51663f0506ed2534e57b798cdfaf8a0d376eb7a2 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 3 Dec 2009 11:41:45 -0700 Subject: llvmpipe: quick & dirty implementation of lp_rast_store_zstencil() This allows us to do a glReadPixels(GL_DEPTH_COMPONENT) to see what's in the depth buffer to help debugging. --- src/gallium/drivers/llvmpipe/lp_rast.c | 53 ++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c index f88dd4ae68..c8359f45a2 100644 --- a/src/gallium/drivers/llvmpipe/lp_rast.c +++ b/src/gallium/drivers/llvmpipe/lp_rast.c @@ -95,6 +95,23 @@ boolean lp_rast_begin( struct lp_rasterizer *rast, return FALSE; } + if (zsbuf) { + rast->zsbuf_transfer = screen->get_tex_transfer(rast->screen, + zsbuf->texture, + zsbuf->face, + zsbuf->level, + zsbuf->zslice, + PIPE_TRANSFER_READ_WRITE, + 0, 0, width, height); + if (!rast->zsbuf_transfer) + return FALSE; + + rast->zsbuf_map = screen->transfer_map(rast->screen, + rast->zsbuf_transfer); + if (!rast->zsbuf_map) + return FALSE; + } + return TRUE; } @@ -117,7 +134,7 @@ void lp_rast_end( struct lp_rasterizer *rast ) screen->tex_transfer_destroy(rast->cbuf_transfer); if (rast->zsbuf_transfer) - screen->tex_transfer_destroy(rast->cbuf_transfer); + screen->tex_transfer_destroy(rast->zsbuf_transfer); rast->cbuf_transfer = NULL; rast->zsbuf_transfer = NULL; @@ -359,14 +376,44 @@ static void lp_rast_store_color( struct lp_rasterizer *rast ) } +static void +lp_tile_write_z32(const uint32_t *src, uint8_t *dst, unsigned dst_stride, + unsigned x0, unsigned y0, unsigned w, unsigned h) +{ + unsigned x, y; + uint8_t *dst_row = dst + y0*dst_stride; + for (y = 0; y < h; ++y) { + uint32_t *dst_pixel = (uint32_t *)(dst_row + x0*4); + for (x = 0; x < w; ++x) { + *dst_pixel++ = *src++; + } + dst_row += dst_stride; + } +} + /** * Write the rasterizer's z/stencil tile to the framebuffer. */ static void lp_rast_store_zstencil( struct lp_rasterizer *rast ) { - RAST_DEBUG("%s\n", __FUNCTION__); + const unsigned x = rast->x; + const unsigned y = rast->y; + unsigned w = TILE_SIZE; + unsigned h = TILE_SIZE; + + if (x + w > rast->width) + w -= x + w - rast->width; + + if (y + h > rast->height) + h -= y + h - rast->height; + + RAST_DEBUG("%s %d,%d %dx%d\n", __FUNCTION__, x, y, w, h); - /* FIXME: call u_tile func to store depth/stencil to surface */ + assert(rast->zsbuf_transfer->format == PIPE_FORMAT_Z32_UNORM); + lp_tile_write_z32(rast->tile.depth, + rast->zsbuf_map, + rast->zsbuf_transfer->stride, + x, y, w, h); } -- cgit v1.2.3