[Mesa-dev] [PATCH 09/24] swrast: Directly map the stencil buffer in read_stencil_pixels.
Brian Paul
brian.e.paul at gmail.com
Sat Oct 29 09:55:02 PDT 2011
On Fri, Oct 28, 2011 at 1:49 PM, Eric Anholt <eric at anholt.net> wrote:
> This avoids going through the wrapper that has to rewrite the data for
> packed depth/stencil. This isn't done in _swrast_read_stencil_span
> because we don't want to map/unmap for each span.
> ---
> src/mesa/swrast/s_readpix.c | 43 +++++++++++++++++++++++++++++++++++++++----
> 1 files changed, 39 insertions(+), 4 deletions(-)
>
> diff --git a/src/mesa/swrast/s_readpix.c b/src/mesa/swrast/s_readpix.c
> index 187c27e..4ecb5b8 100644
> --- a/src/mesa/swrast/s_readpix.c
> +++ b/src/mesa/swrast/s_readpix.c
> @@ -142,8 +142,10 @@ read_stencil_pixels( struct gl_context *ctx,
> const struct gl_pixelstore_attrib *packing )
> {
> struct gl_framebuffer *fb = ctx->ReadBuffer;
> - struct gl_renderbuffer *rb = fb->_StencilBuffer;
> - GLint j;
> + struct gl_renderbuffer *rb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
> + GLint j, i;
> + GLubyte *map;
> + GLint stride;
>
> if (!rb)
> return;
> @@ -151,18 +153,51 @@ read_stencil_pixels( struct gl_context *ctx,
> /* 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,
> + &map, &stride);
> +
> /* process image row by row */
> - for (j=0;j<height;j++,y++) {
> + for (j = 0; j < height; j++) {
> GLvoid *dest;
> GLstencil stencil[MAX_WIDTH];
>
> - _swrast_read_stencil_span(ctx, rb, width, x, y, stencil);
> + switch (rb->Format) {
> +
> + case MESA_FORMAT_S8_Z24: {
> + uint32_t *data = (uint32_t *)map;
> + for (i = 0; i < width; i++)
> + stencil[i] = data[i] >> 24;
> + break;
> + }
> +
> + case MESA_FORMAT_Z24_S8: {
> + uint32_t *data = (uint32_t *)map;
> + for (i = 0; i < width; i++)
> + stencil[i] = data[i] & 0xff;
> + break;
> + }
> +
> + case MESA_FORMAT_S8:
> + for (i = 0; i < width; i++)
> + stencil[i] = map[i];
> + break;
I'd probably put the code to unpack a row of stencil values into a new
_mesa_unpack_ubyte_stencil_row() function in format_unpack.c in case
it could be used elsewhere, like in the swrast stencil op code.
Otherwise this looks good.
-Brian
More information about the mesa-dev
mailing list