From ff27e058bc93338ef0dbe322ab4e588ea4bbec0d Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 11 Oct 2011 17:07:37 -0700 Subject: swrast: Directly map the stencil buffer in read_stencil_pixels. 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. v2: Move the unpack code to format_unpack.c. v3: Fix signed/unsigned comparison. Reviewed-by: Brian Paul --- src/mesa/main/format_unpack.c | 58 +++++++++++++++++++++++++++++++++++++++++++ src/mesa/main/format_unpack.h | 4 +++ 2 files changed, 62 insertions(+) (limited to 'src/mesa/main') diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c index fbda03135e9..3d044af0d4d 100644 --- a/src/mesa/main/format_unpack.c +++ b/src/mesa/main/format_unpack.c @@ -1480,4 +1480,62 @@ _mesa_unpack_uint_z_row(gl_format format, GLuint n, } } +static void +unpack_ubyte_s_S8(const void *src, GLubyte *dst, GLuint n) +{ + memcpy(dst, src, n); +} + +static void +unpack_ubyte_s_Z24_S8(const void *src, GLubyte *dst, GLuint n) +{ + GLuint i; + const GLuint *src32 = src; + + for (i = 0; i < n; i++) + dst[i] = src32[i] & 0xff; +} + +static void +unpack_ubyte_s_S8_Z24(const void *src, GLubyte *dst, GLuint n) +{ + GLuint i; + const GLuint *src32 = src; + + for (i = 0; i < n; i++) + dst[i] = src32[i] >> 24; +} + +static void +unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src, GLubyte *dst, GLuint n) +{ + GLuint i; + const GLuint *src32 = src; + + for (i = 0; i < n; i++) + dst[i] = src32[i * 2 + 1] & 0xff; +} +void +_mesa_unpack_ubyte_stencil_row(gl_format format, GLuint n, + const void *src, GLubyte *dst) +{ + switch (format) { + case MESA_FORMAT_S8: + unpack_ubyte_s_S8(src, dst, n); + break; + case MESA_FORMAT_Z24_S8: + unpack_ubyte_s_Z24_S8(src, dst, n); + break; + case MESA_FORMAT_S8_Z24: + unpack_ubyte_s_S8_Z24(src, dst, n); + break; + case MESA_FORMAT_Z32_FLOAT_X24S8: + unpack_ubyte_s_Z32_FLOAT_X24S8(src, dst, n); + break; + default: + _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row", + _mesa_get_format_name(format)); + return; + } +} diff --git a/src/mesa/main/format_unpack.h b/src/mesa/main/format_unpack.h index c37727d91a0..2e00047c201 100644 --- a/src/mesa/main/format_unpack.h +++ b/src/mesa/main/format_unpack.h @@ -45,5 +45,9 @@ void _mesa_unpack_uint_z_row(gl_format format, GLuint n, const void *src, GLuint *dst); +void +_mesa_unpack_ubyte_stencil_row(gl_format format, GLuint n, + const void *src, GLubyte *dst); + #endif /* FORMAT_UNPACK_H */ -- cgit v1.2.3