diff options
author | Brian Paul <[email protected]> | 2012-02-13 10:06:54 -0700 |
---|---|---|
committer | Brian Paul <[email protected]> | 2012-02-15 14:08:50 -0700 |
commit | 0bda900743702a2c0f95024f004e6210e59fd5dd (patch) | |
tree | f991769a0215e501fe33a03e5769c28da437b778 /src | |
parent | dba7ad0ca92f1ff4012db4ffdf102d7bb8ee3c10 (diff) |
mesa: use z32f_x24s8 struct in format pack/unpack code
And remove needless & 0xff in _mesa_pack_uint_24_8_depth_stencil_row().
As suggested by José.
Reviewed-by: Jose Fonseca <[email protected]>
Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/main/format_pack.c | 31 | ||||
-rw-r--r-- | src/mesa/main/format_unpack.c | 20 |
2 files changed, 30 insertions, 21 deletions
diff --git a/src/mesa/main/format_pack.c b/src/mesa/main/format_pack.c index e20e361c842..ff08ac56112 100644 --- a/src/mesa/main/format_pack.c +++ b/src/mesa/main/format_pack.c @@ -42,6 +42,14 @@ #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h" +/** Helper struct for MESA_FORMAT_Z32_FLOAT_X24S8 */ +struct z32f_x24s8 +{ + float z; + uint32_t x24s8; +}; + + typedef void (*pack_ubyte_rgba_row_func)(GLuint n, const GLubyte src[][4], void *dst); @@ -2372,10 +2380,10 @@ _mesa_pack_float_z_row(gl_format format, GLuint n, break; case MESA_FORMAT_Z32_FLOAT_X24S8: { - GLfloat *d = ((GLfloat *) dst); + struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst; GLuint i; for (i = 0; i < n; i++) { - d[i * 2] = src[i]; + d[i].z = src[i]; } } break; @@ -2445,13 +2453,13 @@ _mesa_pack_uint_z_row(gl_format format, GLuint n, break; case MESA_FORMAT_Z32_FLOAT_X24S8: { - GLfloat *d = ((GLfloat *) dst); + struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst; const GLdouble scale = 1.0 / (GLdouble) 0xffffffff; GLuint i; for (i = 0; i < n; i++) { - d[i * 2] = src[i] * scale; - assert(d[i * 2] >= 0.0f); - assert(d[i * 2] <= 1.0f); + d[i].z = src[i] * scale; + assert(d[i].z >= 0.0f); + assert(d[i].z <= 1.0f); } } break; @@ -2495,10 +2503,10 @@ _mesa_pack_ubyte_stencil_row(gl_format format, GLuint n, break; case MESA_FORMAT_Z32_FLOAT_X24S8: { - GLuint *d = dst; + struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst; GLuint i; for (i = 0; i < n; i++) { - d[i * 2 + 1] = src[i]; + d[i].x24s8 = src[i]; } } break; @@ -2533,13 +2541,12 @@ _mesa_pack_uint_24_8_depth_stencil_row(gl_format format, GLuint n, case MESA_FORMAT_Z32_FLOAT_X24S8: { const GLdouble scale = 1.0 / (GLdouble) 0xffffff; - GLuint *destu = (GLuint *) dst; - GLfloat *destf = (GLfloat *) dst; + struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst; GLint i; for (i = 0; i < n; i++) { GLfloat z = (src[i] >> 8) * scale; - destf[i * 2 + 0] = z; - destu[i * 2 + 1] = src[i] & 0xff; + d[i].z = z; + d[i].x24s8 = src[i]; } } break; diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c index a484979e2a9..b00e01236b3 100644 --- a/src/mesa/main/format_unpack.c +++ b/src/mesa/main/format_unpack.c @@ -29,6 +29,13 @@ #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h" +/** Helper struct for MESA_FORMAT_Z32_FLOAT_X24S8 */ +struct z32f_x24s8 +{ + float z; + uint32_t x24s8; +}; + /* Expand 1, 2, 3, 4, 5, 6-bit values to fill 8 bits */ @@ -2825,10 +2832,10 @@ unpack_float_z_Z32F(GLuint n, const void *src, GLfloat *dst) static void unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst) { - const GLfloat *s = ((const GLfloat *) src); + const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src; GLuint i; for (i = 0; i < n; i++) { - dst[i] = s[i * 2]; + dst[i] = s[i].z; } } @@ -2929,11 +2936,6 @@ unpack_uint_z_Z32_FLOAT(const void *src, GLuint *dst, GLuint n) static void unpack_uint_z_Z32_FLOAT_X24S8(const void *src, GLuint *dst, GLuint n) { - struct z32f_x24s8 { - float z; - uint32_t x24s8; - }; - const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src; GLuint i; @@ -3015,10 +3017,10 @@ static void unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src, GLubyte *dst, GLuint n) { GLuint i; - const GLuint *src32 = src; + const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src; for (i = 0; i < n; i++) - dst[i] = src32[i * 2 + 1] & 0xff; + dst[i] = s[i].x24s8 & 0xff; } void |