[Mesa-dev] [PATCH V3 02/30] mesa: fix packing of float texels to GL_SHORT/GL_BYTE
Kenneth Graunke
kenneth at whitecape.org
Sun Apr 6 22:07:31 PDT 2014
On 04/02/2014 01:04 AM, Chris Forbes wrote:
> Previously, we would unpack the texels to floats using *_TO_FLOAT_TEX,
> and then pack them into the desired format using FLOAT_TO_*. Unfortunately,
> this isn't quite the inverse operation, and so some texel values would
> end up off-by-one.
These functions sure could be named better...they don't have anything to
do with texturing. The TEX versions use a signed-normalized range ([-1,
1]) while the plain ones use an unsigned normalized range ([0, 1]).
Notably, all the cases below are signed data types, so this is clearly
correct. Thanks for the fix!
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
>
> This fixes the GL_RGB8_SNORM and GL_RGB16_SNORM subcases in piglit's
> arb_texture_view-format-consistency-get test on i965. The similar 1-, 2-
> and 4-component cases already worked because they took the memcpy path
> rather than repacking.
>
> Signed-off-by: Chris Forbes <chrisf at ijw.co.nz>
> ---
> src/mesa/main/pack.c | 116 +++++++++++++++++++++++++--------------------------
> 1 file changed, 58 insertions(+), 58 deletions(-)
>
> diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
> index d976e5a..1df6568 100644
> --- a/src/mesa/main/pack.c
> +++ b/src/mesa/main/pack.c
> @@ -1489,72 +1489,72 @@ _mesa_pack_rgba_span_float(struct gl_context *ctx, GLuint n, GLfloat rgba[][4],
> switch (dstFormat) {
> case GL_RED:
> for (i=0;i<n;i++)
> - dst[i] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
> + dst[i] = FLOAT_TO_BYTE_TEX(rgba[i][RCOMP]);
> break;
> case GL_GREEN:
> for (i=0;i<n;i++)
> - dst[i] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
> + dst[i] = FLOAT_TO_BYTE_TEX(rgba[i][GCOMP]);
> break;
> case GL_BLUE:
> for (i=0;i<n;i++)
> - dst[i] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
> + dst[i] = FLOAT_TO_BYTE_TEX(rgba[i][BCOMP]);
> break;
> case GL_ALPHA:
> for (i=0;i<n;i++)
> - dst[i] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
> + dst[i] = FLOAT_TO_BYTE_TEX(rgba[i][ACOMP]);
> break;
> case GL_LUMINANCE:
> for (i=0;i<n;i++)
> - dst[i] = FLOAT_TO_BYTE(luminance[i]);
> + dst[i] = FLOAT_TO_BYTE_TEX(luminance[i]);
> break;
> case GL_LUMINANCE_ALPHA:
> for (i=0;i<n;i++) {
> - dst[i*2+0] = FLOAT_TO_BYTE(luminance[i]);
> - dst[i*2+1] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
> + dst[i*2+0] = FLOAT_TO_BYTE_TEX(luminance[i]);
> + dst[i*2+1] = FLOAT_TO_BYTE_TEX(rgba[i][ACOMP]);
> }
> break;
> case GL_RG:
> for (i=0;i<n;i++) {
> - dst[i*2+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
> - dst[i*2+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
> + dst[i*2+0] = FLOAT_TO_BYTE_TEX(rgba[i][RCOMP]);
> + dst[i*2+1] = FLOAT_TO_BYTE_TEX(rgba[i][GCOMP]);
> }
> break;
> case GL_RGB:
> for (i=0;i<n;i++) {
> - dst[i*3+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
> - dst[i*3+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
> - dst[i*3+2] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
> + dst[i*3+0] = FLOAT_TO_BYTE_TEX(rgba[i][RCOMP]);
> + dst[i*3+1] = FLOAT_TO_BYTE_TEX(rgba[i][GCOMP]);
> + dst[i*3+2] = FLOAT_TO_BYTE_TEX(rgba[i][BCOMP]);
> }
> break;
> case GL_RGBA:
> for (i=0;i<n;i++) {
> - dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
> - dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
> - dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
> - dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
> + dst[i*4+0] = FLOAT_TO_BYTE_TEX(rgba[i][RCOMP]);
> + dst[i*4+1] = FLOAT_TO_BYTE_TEX(rgba[i][GCOMP]);
> + dst[i*4+2] = FLOAT_TO_BYTE_TEX(rgba[i][BCOMP]);
> + dst[i*4+3] = FLOAT_TO_BYTE_TEX(rgba[i][ACOMP]);
> }
> break;
> case GL_BGR:
> for (i=0;i<n;i++) {
> - dst[i*3+0] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
> - dst[i*3+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
> - dst[i*3+2] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
> + dst[i*3+0] = FLOAT_TO_BYTE_TEX(rgba[i][BCOMP]);
> + dst[i*3+1] = FLOAT_TO_BYTE_TEX(rgba[i][GCOMP]);
> + dst[i*3+2] = FLOAT_TO_BYTE_TEX(rgba[i][RCOMP]);
> }
> break;
> case GL_BGRA:
> for (i=0;i<n;i++) {
> - dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
> - dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
> - dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
> - dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
> + dst[i*4+0] = FLOAT_TO_BYTE_TEX(rgba[i][BCOMP]);
> + dst[i*4+1] = FLOAT_TO_BYTE_TEX(rgba[i][GCOMP]);
> + dst[i*4+2] = FLOAT_TO_BYTE_TEX(rgba[i][RCOMP]);
> + dst[i*4+3] = FLOAT_TO_BYTE_TEX(rgba[i][ACOMP]);
> }
> break;
> case GL_ABGR_EXT:
> for (i=0;i<n;i++) {
> - dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
> - dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
> - dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
> - dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
> + dst[i*4+0] = FLOAT_TO_BYTE_TEX(rgba[i][ACOMP]);
> + dst[i*4+1] = FLOAT_TO_BYTE_TEX(rgba[i][BCOMP]);
> + dst[i*4+2] = FLOAT_TO_BYTE_TEX(rgba[i][GCOMP]);
> + dst[i*4+3] = FLOAT_TO_BYTE_TEX(rgba[i][RCOMP]);
> }
> break;
> case GL_RED_INTEGER_EXT:
> @@ -1631,8 +1631,8 @@ _mesa_pack_rgba_span_float(struct gl_context *ctx, GLuint n, GLfloat rgba[][4],
> case GL_DUDV_ATI:
> case GL_DU8DV8_ATI:
> for (i=0;i<n;i++) {
> - dst[i*2+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
> - dst[i*2+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
> + dst[i*2+0] = FLOAT_TO_BYTE_TEX(rgba[i][RCOMP]);
> + dst[i*2+1] = FLOAT_TO_BYTE_TEX(rgba[i][GCOMP]);
> }
> break;
> default:
> @@ -1803,72 +1803,72 @@ _mesa_pack_rgba_span_float(struct gl_context *ctx, GLuint n, GLfloat rgba[][4],
> switch (dstFormat) {
> case GL_RED:
> for (i=0;i<n;i++)
> - dst[i] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
> + dst[i] = FLOAT_TO_SHORT_TEX(rgba[i][RCOMP]);
> break;
> case GL_GREEN:
> for (i=0;i<n;i++)
> - dst[i] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
> + dst[i] = FLOAT_TO_SHORT_TEX(rgba[i][GCOMP]);
> break;
> case GL_BLUE:
> for (i=0;i<n;i++)
> - dst[i] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
> + dst[i] = FLOAT_TO_SHORT_TEX(rgba[i][BCOMP]);
> break;
> case GL_ALPHA:
> for (i=0;i<n;i++)
> - dst[i] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
> + dst[i] = FLOAT_TO_SHORT_TEX(rgba[i][ACOMP]);
> break;
> case GL_LUMINANCE:
> for (i=0;i<n;i++)
> - dst[i] = FLOAT_TO_SHORT(luminance[i]);
> + dst[i] = FLOAT_TO_SHORT_TEX(luminance[i]);
> break;
> case GL_LUMINANCE_ALPHA:
> for (i=0;i<n;i++) {
> - dst[i*2+0] = FLOAT_TO_SHORT(luminance[i]);
> - dst[i*2+1] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
> + dst[i*2+0] = FLOAT_TO_SHORT_TEX(luminance[i]);
> + dst[i*2+1] = FLOAT_TO_SHORT_TEX(rgba[i][ACOMP]);
> }
> break;
> case GL_RG:
> for (i=0;i<n;i++) {
> - dst[i*2+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
> - dst[i*2+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
> + dst[i*2+0] = FLOAT_TO_SHORT_TEX(rgba[i][RCOMP]);
> + dst[i*2+1] = FLOAT_TO_SHORT_TEX(rgba[i][GCOMP]);
> }
> break;
> case GL_RGB:
> for (i=0;i<n;i++) {
> - dst[i*3+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
> - dst[i*3+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
> - dst[i*3+2] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
> + dst[i*3+0] = FLOAT_TO_SHORT_TEX(rgba[i][RCOMP]);
> + dst[i*3+1] = FLOAT_TO_SHORT_TEX(rgba[i][GCOMP]);
> + dst[i*3+2] = FLOAT_TO_SHORT_TEX(rgba[i][BCOMP]);
> }
> break;
> case GL_RGBA:
> for (i=0;i<n;i++) {
> - dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
> - dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
> - dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
> - dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
> + dst[i*4+0] = FLOAT_TO_SHORT_TEX(rgba[i][RCOMP]);
> + dst[i*4+1] = FLOAT_TO_SHORT_TEX(rgba[i][GCOMP]);
> + dst[i*4+2] = FLOAT_TO_SHORT_TEX(rgba[i][BCOMP]);
> + dst[i*4+3] = FLOAT_TO_SHORT_TEX(rgba[i][ACOMP]);
> }
> break;
> case GL_BGR:
> for (i=0;i<n;i++) {
> - dst[i*3+0] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
> - dst[i*3+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
> - dst[i*3+2] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
> + dst[i*3+0] = FLOAT_TO_SHORT_TEX(rgba[i][BCOMP]);
> + dst[i*3+1] = FLOAT_TO_SHORT_TEX(rgba[i][GCOMP]);
> + dst[i*3+2] = FLOAT_TO_SHORT_TEX(rgba[i][RCOMP]);
> }
> break;
> case GL_BGRA:
> for (i=0;i<n;i++) {
> - dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
> - dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
> - dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
> - dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
> + dst[i*4+0] = FLOAT_TO_SHORT_TEX(rgba[i][BCOMP]);
> + dst[i*4+1] = FLOAT_TO_SHORT_TEX(rgba[i][GCOMP]);
> + dst[i*4+2] = FLOAT_TO_SHORT_TEX(rgba[i][RCOMP]);
> + dst[i*4+3] = FLOAT_TO_SHORT_TEX(rgba[i][ACOMP]);
> }
> break;
> case GL_ABGR_EXT:
> for (i=0;i<n;i++) {
> - dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
> - dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
> - dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
> - dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
> + dst[i*4+0] = FLOAT_TO_SHORT_TEX(rgba[i][ACOMP]);
> + dst[i*4+1] = FLOAT_TO_SHORT_TEX(rgba[i][BCOMP]);
> + dst[i*4+2] = FLOAT_TO_SHORT_TEX(rgba[i][GCOMP]);
> + dst[i*4+3] = FLOAT_TO_SHORT_TEX(rgba[i][RCOMP]);
> }
> break;
> case GL_RED_INTEGER_EXT:
> @@ -1945,8 +1945,8 @@ _mesa_pack_rgba_span_float(struct gl_context *ctx, GLuint n, GLfloat rgba[][4],
> case GL_DUDV_ATI:
> case GL_DU8DV8_ATI:
> for (i=0;i<n;i++) {
> - dst[i*2+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
> - dst[i*2+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
> + dst[i*2+0] = FLOAT_TO_SHORT_TEX(rgba[i][RCOMP]);
> + dst[i*2+1] = FLOAT_TO_SHORT_TEX(rgba[i][GCOMP]);
> }
> break;
> default:
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140406/fab6205f/attachment-0001.sig>
More information about the mesa-dev
mailing list