On 03/21/2014 04:01 PM, Anuj Phogat wrote:
Cc: <mesa-sta...@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.pho...@gmail.com>
---
src/mesa/main/format_unpack.c | 79 ++++++++++++++++++++++++++++++++++++++++++-
src/mesa/main/format_unpack.h | 5 +++
2 files changed, 83 insertions(+), 1 deletion(-)
diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c
index 7abbe46..1725f10 100644
--- a/src/mesa/main/format_unpack.c
+++ b/src/mesa/main/format_unpack.c
@@ -4264,6 +4264,79 @@ _mesa_unpack_uint_24_8_depth_stencil_row(mesa_format
format, GLuint n,
}
}
+static void
+unpack_float_32_uint_24_8_depth_stencil_S8_Z24(const GLuint *src,
+ GLuint *dst, GLuint n)
+{
+ GLuint i;
+
+ for (i = 0; i < n; i++) {
+ GLuint val = src[i];
+ GLuint z24 = val & 0xffffff;
+ GLfloat zf = z24 * (1.0F / 0xffffff);
In other function where we convert 24-bit Z to a float we need to use
double precision. See fc52534f012837a39c03a764eb611d460210514a
+ GLuint s = val & 0xff000000;
+ ((GLfloat *) dst)[i * 2 + 0] = zf;
+ dst[i * 2 + 1] = s;
+ }
+}
+
+static void
+unpack_float_32_uint_24_8_depth_stencil_Z32_S8X24(const GLuint *src,
+ GLuint *dst, GLuint n)
+{
+ GLuint i;
+
+ for (i = 0; i < n; i++) {
+ /* 8 bytes per pixel (float + uint32) */
+ GLfloat zf = ((GLfloat *) src)[i * 2 + 0];
+ GLuint s = src[i * 2 + 1] & 0xff;
+ ((GLfloat *) dst)[i * 2 + 0] = zf;
+ dst[i * 2 + 1] = s;
+ }
+}
+
+static void
+unpack_float_32_uint_24_8_depth_stencil_Z24_S8(const GLuint *src,
+ GLuint *dst, GLuint n)
+{
+ GLuint i;
+
+ for (i = 0; i < n; i++) {
+ GLuint val = src[i];
+ GLuint z24 = (val >> 8);
+ GLfloat zf = z24 * (1.0F / 0xffffff);
+ GLuint s = val & 0xff;
+ ((GLfloat *) dst)[i * 2 + 0] = zf;
+ dst[i * 2 + 1] = s << 24;
+ }
+}
+
+/**
+ * Unpack depth/stencil returning as GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
+ * \param format the source data format
+ */
+void
+_mesa_unpack_float_32_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
+ const void *src, GLuint *dst)
+{
+ switch (format) {
+ case MESA_FORMAT_S8_UINT_Z24_UNORM:
+ unpack_float_32_uint_24_8_depth_stencil_Z24_S8(src, dst, n);
Let's try to follow the new format naming conventions. So can we rename
the function to include the actual src format name? Something like:
unpack_float_32_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM().
or maybe unpack_float_32_uint_24_8_from_S8_UINT_Z24_UNORM().
I know the name gets a little crazy, but I think including the actual
format name in the function name is desirable. I'm about to post a
series which does this for most other functions in the
format_pack/unpack.c files.
+ break;
+ case MESA_FORMAT_Z24_UNORM_S8_UINT:
+ unpack_float_32_uint_24_8_depth_stencil_S8_Z24(src, dst, n);
+ break;
+ case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
+ unpack_float_32_uint_24_8_depth_stencil_Z32_S8X24(src, dst, n);
+ break;
+ default:
+ _mesa_problem(NULL,
+ "bad format %s in
_mesa_unpack_uint_24_8_depth_stencil_row",
+ _mesa_get_format_name(format));
+ return;
+ }
+}
+
/**
* Unpack depth/stencil
* \param format the source data format
@@ -4274,12 +4347,16 @@ _mesa_unpack_depth_stencil_row(mesa_format format,
GLuint n,
const void *src, GLenum type,
GLuint *dst)
{
- assert(type == GL_UNSIGNED_INT_24_8);
+ assert(type == GL_UNSIGNED_INT_24_8 ||
+ type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
switch (type) {
case GL_UNSIGNED_INT_24_8:
_mesa_unpack_uint_24_8_depth_stencil_row(format, n, src, dst);
break;
+ case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
+ _mesa_unpack_float_32_uint_24_8_depth_stencil_row(format, n, src, dst);
+ break;
default:
_mesa_problem(NULL,
"bad type 0x%x in _mesa_unpack_depth_stencil_row",
diff --git a/src/mesa/main/format_unpack.h b/src/mesa/main/format_unpack.h
index 5904a28..51f97df 100644
--- a/src/mesa/main/format_unpack.h
+++ b/src/mesa/main/format_unpack.h
@@ -64,6 +64,11 @@ _mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format,
GLuint n,
const void *src, GLuint *dst);
void
+_mesa_unpack_float_32_uint_24_8_depth_stencil_row(mesa_format format,
+ GLuint n,
+ const void *src,
+ GLuint *dst);
+void
_mesa_unpack_depth_stencil_row(mesa_format format, GLuint n,
const void *src, GLenum type,
GLuint *dst);
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev