mesa: new BYTE/SHORT_TO_FLOATZ() macros

Rather than redefining the BYTE/SHORT_TO_FLOAT macros, just define new
ones with different names.  These macros preserve zero when converting.

Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
Brian Paul
2011-11-12 11:50:32 -07:00
parent b098e1af1c
commit 546f76d58f
3 changed files with 17 additions and 42 deletions
-16
View File
@@ -39,22 +39,6 @@
#include "mtypes.h"
/**
* NOTE:
* Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
* we later convert the float to a packed integer value (such as for
* GL_RGB5_A1) because we'll wind up with a non-zero value.
*
* We redefine the macros here so zero is handled correctly.
*/
#undef BYTE_TO_FLOAT
#define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
#undef SHORT_TO_FLOAT
#define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
/**
* \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
+7
View File
@@ -54,6 +54,10 @@ extern GLfloat _mesa_ubyte_to_float_color_tab[256];
#define FLOAT_TO_BYTE(X) ( (((GLint) (255.0F * (X))) - 1) / 2 )
/** Convert GLbyte to GLfloat while preserving zero */
#define BYTE_TO_FLOATZ(B) ((B) == 0 ? 0.0F : BYTE_TO_FLOAT(B))
/** Convert GLbyte in [-128,127] to GLfloat in [-1.0,1.0], texture/fb data */
#define BYTE_TO_FLOAT_TEX(B) ((B) == -128 ? -1.0F : (B) * (1.0F/127.0F))
@@ -73,6 +77,9 @@ extern GLfloat _mesa_ubyte_to_float_color_tab[256];
/** Convert GLfloat in [-1.0,1.0] to GLshort in [-32768,32767] */
#define FLOAT_TO_SHORT(X) ( (((GLint) (65535.0F * (X))) - 1) / 2 )
/** Convert GLshort to GLfloat while preserving zero */
#define SHORT_TO_FLOATZ(S) ((S) == 0 ? 0.0F : SHORT_TO_FLOAT(S))
/** Convert GLshort in [-32768,32767] to GLfloat in [-1.0,1.0], texture/fb data */
#define SHORT_TO_FLOAT_TEX(S) ((S) == -32768 ? -1.0F : (S) * (1.0F/32767.0F))
+10 -26
View File
@@ -43,22 +43,6 @@
#include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
/**
* NOTE:
* Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
* we later convert the float to a packed integer value (such as for
* GL_RGB5_A1) because we'll wind up with a non-zero value.
*
* We redefine the macros here so zero is handled correctly.
*/
#undef BYTE_TO_FLOAT
#define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
#undef SHORT_TO_FLOAT
#define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
/**
* Flip the 8 bits in each byte of the given array.
*
@@ -2504,10 +2488,10 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4],
PROCESS(aSrc, ACOMP, 1.0F, 255, GLubyte, UBYTE_TO_FLOAT);
break;
case GL_BYTE:
PROCESS(rSrc, RCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT);
PROCESS(gSrc, GCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT);
PROCESS(bSrc, BCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOAT);
PROCESS(aSrc, ACOMP, 1.0F, 127, GLbyte, BYTE_TO_FLOAT);
PROCESS(rSrc, RCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOATZ);
PROCESS(gSrc, GCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOATZ);
PROCESS(bSrc, BCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOATZ);
PROCESS(aSrc, ACOMP, 1.0F, 127, GLbyte, BYTE_TO_FLOATZ);
break;
case GL_UNSIGNED_SHORT:
PROCESS(rSrc, RCOMP, 0.0F, 0, GLushort, USHORT_TO_FLOAT);
@@ -2516,10 +2500,10 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4],
PROCESS(aSrc, ACOMP, 1.0F, 0xffff, GLushort, USHORT_TO_FLOAT);
break;
case GL_SHORT:
PROCESS(rSrc, RCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT);
PROCESS(gSrc, GCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT);
PROCESS(bSrc, BCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOAT);
PROCESS(aSrc, ACOMP, 1.0F, 32767, GLshort, SHORT_TO_FLOAT);
PROCESS(rSrc, RCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOATZ);
PROCESS(gSrc, GCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOATZ);
PROCESS(bSrc, BCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOATZ);
PROCESS(aSrc, ACOMP, 1.0F, 32767, GLshort, SHORT_TO_FLOATZ);
break;
case GL_UNSIGNED_INT:
PROCESS(rSrc, RCOMP, 0.0F, 0, GLuint, UINT_TO_FLOAT);
@@ -4822,14 +4806,14 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
*/
switch (srcType) {
case GL_BYTE:
DEPTH_VALUES(GLbyte, BYTE_TO_FLOAT);
DEPTH_VALUES(GLbyte, BYTE_TO_FLOATZ);
needClamp = GL_TRUE;
break;
case GL_UNSIGNED_BYTE:
DEPTH_VALUES(GLubyte, UBYTE_TO_FLOAT);
break;
case GL_SHORT:
DEPTH_VALUES(GLshort, SHORT_TO_FLOAT);
DEPTH_VALUES(GLshort, SHORT_TO_FLOATZ);
needClamp = GL_TRUE;
break;
case GL_UNSIGNED_SHORT: