return sizeof(GLint);
case GL_FLOAT:
return sizeof(GLfloat);
+ case GL_HALF_FLOAT_NV:
+ return sizeof(GLhalfNV);
default:
return -1;
}
return sizeof(GLuint);
case GL_INT:
return sizeof(GLint);
+ case GL_HALF_FLOAT_NV:
+ return sizeof(GLhalfNV);
case GL_FLOAT:
return sizeof(GLfloat);
case GL_UNSIGNED_BYTE_3_3_2:
return comps * sizeof(GLint);
case GL_FLOAT:
return comps * sizeof(GLfloat);
+ case GL_HALF_FLOAT_NV:
+ return comps * sizeof(GLhalfNV);
case GL_UNSIGNED_BYTE_3_3_2:
case GL_UNSIGNED_BYTE_2_3_3_REV:
if (format == GL_RGB || format == GL_BGR)
case GL_INT:
case GL_UNSIGNED_INT:
case GL_FLOAT:
+ case GL_HALF_FLOAT_NV:
return GL_TRUE;
default:
return GL_FALSE;
case GL_INT:
case GL_UNSIGNED_INT:
case GL_FLOAT:
+ case GL_HALF_FLOAT_NV:
return GL_TRUE;
default:
return GL_FALSE;
case GL_INT:
case GL_UNSIGNED_INT:
case GL_FLOAT:
+ case GL_HALF_FLOAT_NV:
case GL_UNSIGNED_BYTE_3_3_2:
case GL_UNSIGNED_BYTE_2_3_3_REV:
case GL_UNSIGNED_SHORT_5_6_5:
case GL_INT:
case GL_UNSIGNED_INT:
case GL_FLOAT:
+ case GL_HALF_FLOAT_NV:
case GL_UNSIGNED_SHORT_4_4_4_4:
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
case GL_UNSIGNED_SHORT_5_5_5_1:
}
}
break;
+ case GL_HALF_FLOAT_NV:
+ {
+ GLhalfNV *dst = (GLhalfNV *) dstAddr;
+ switch (dstFormat) {
+ case GL_RED:
+ for (i=0;i<n;i++)
+ dst[i] = _mesa_float_to_half(rgba[i][RCOMP]);
+ break;
+ case GL_GREEN:
+ for (i=0;i<n;i++)
+ dst[i] = _mesa_float_to_half(rgba[i][GCOMP]);
+ break;
+ case GL_BLUE:
+ for (i=0;i<n;i++)
+ dst[i] = _mesa_float_to_half(rgba[i][BCOMP]);
+ break;
+ case GL_ALPHA:
+ for (i=0;i<n;i++)
+ dst[i] = _mesa_float_to_half(rgba[i][ACOMP]);
+ break;
+ case GL_LUMINANCE:
+ for (i=0;i<n;i++)
+ dst[i] = _mesa_float_to_half(luminance[i]);
+ break;
+ case GL_LUMINANCE_ALPHA:
+ for (i=0;i<n;i++) {
+ dst[i*2+0] = _mesa_float_to_half(luminance[i]);
+ dst[i*2+1] = _mesa_float_to_half(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_RGB:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = _mesa_float_to_half(rgba[i][RCOMP]);
+ dst[i*3+1] = _mesa_float_to_half(rgba[i][GCOMP]);
+ dst[i*3+2] = _mesa_float_to_half(rgba[i][BCOMP]);
+ }
+ break;
+ case GL_RGBA:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = _mesa_float_to_half(rgba[i][RCOMP]);
+ dst[i*4+1] = _mesa_float_to_half(rgba[i][GCOMP]);
+ dst[i*4+2] = _mesa_float_to_half(rgba[i][BCOMP]);
+ dst[i*4+3] = _mesa_float_to_half(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_BGR:
+ for (i=0;i<n;i++) {
+ dst[i*3+0] = _mesa_float_to_half(rgba[i][BCOMP]);
+ dst[i*3+1] = _mesa_float_to_half(rgba[i][GCOMP]);
+ dst[i*3+2] = _mesa_float_to_half(rgba[i][RCOMP]);
+ }
+ break;
+ case GL_BGRA:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = _mesa_float_to_half(rgba[i][BCOMP]);
+ dst[i*4+1] = _mesa_float_to_half(rgba[i][GCOMP]);
+ dst[i*4+2] = _mesa_float_to_half(rgba[i][RCOMP]);
+ dst[i*4+3] = _mesa_float_to_half(rgba[i][ACOMP]);
+ }
+ break;
+ case GL_ABGR_EXT:
+ for (i=0;i<n;i++) {
+ dst[i*4+0] = _mesa_float_to_half(rgba[i][ACOMP]);
+ dst[i*4+1] = _mesa_float_to_half(rgba[i][BCOMP]);
+ dst[i*4+2] = _mesa_float_to_half(rgba[i][GCOMP]);
+ dst[i*4+3] = _mesa_float_to_half(rgba[i][RCOMP]);
+ }
+ break;
+ default:
+ _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap2( (GLushort *) dst, n * comps );
+ }
+ }
+ break;
case GL_UNSIGNED_BYTE_3_3_2:
if (dstFormat == GL_RGB) {
GLubyte *dst = (GLubyte *) dstAddr;
srcType == GL_SHORT ||
srcType == GL_UNSIGNED_INT ||
srcType == GL_INT ||
+ srcType == GL_HALF_FLOAT_NV ||
srcType == GL_FLOAT);
switch (srcType) {
}
}
break;
+ case GL_HALF_FLOAT_NV:
+ {
+ GLuint i;
+ const GLhalfNV *s = (const GLhalfNV *) src;
+ if (unpack->SwapBytes) {
+ for (i = 0; i < n; i++) {
+ GLhalfNV value = s[i];
+ SWAP2BYTE(value);
+ indexes[i] = (GLuint) _mesa_half_to_float(value);
+ }
+ }
+ else {
+ for (i = 0; i < n; i++)
+ indexes[i] = (GLuint) _mesa_half_to_float(s[i]);
+ }
+ }
+ break;
default:
_mesa_problem(NULL, "bad srcType in extract_uint_indexes");
return;
srcType == GL_SHORT ||
srcType == GL_UNSIGNED_INT ||
srcType == GL_INT ||
+ srcType == GL_HALF_FLOAT_NV ||
srcType == GL_FLOAT ||
srcType == GL_UNSIGNED_BYTE_3_3_2 ||
srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
PROCESS(blueIndex, BCOMP, 0.0F, GLfloat, (GLfloat));
PROCESS(alphaIndex, ACOMP, 1.0F, GLfloat, (GLfloat));
break;
+ case GL_HALF_FLOAT_NV:
+ PROCESS(redIndex, RCOMP, 0.0F, GLhalfNV, _mesa_half_to_float);
+ PROCESS(greenIndex, GCOMP, 0.0F, GLhalfNV, _mesa_half_to_float);
+ PROCESS(blueIndex, BCOMP, 0.0F, GLhalfNV, _mesa_half_to_float);
+ PROCESS(alphaIndex, ACOMP, 1.0F, GLhalfNV, _mesa_half_to_float);
+ break;
case GL_UNSIGNED_BYTE_3_3_2:
{
const GLubyte *ubsrc = (const GLubyte *) src;
srcType == GL_SHORT ||
srcType == GL_UNSIGNED_INT ||
srcType == GL_INT ||
+ srcType == GL_HALF_FLOAT_NV ||
srcType == GL_FLOAT ||
srcType == GL_UNSIGNED_BYTE_3_3_2 ||
srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
srcType == GL_SHORT ||
srcType == GL_UNSIGNED_INT ||
srcType == GL_INT ||
+ srcType == GL_HALF_FLOAT_NV ||
srcType == GL_FLOAT ||
srcType == GL_UNSIGNED_BYTE_3_3_2 ||
srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
srcType == GL_SHORT ||
srcType == GL_UNSIGNED_INT ||
srcType == GL_INT ||
+ srcType == GL_HALF_FLOAT_NV ||
srcType == GL_FLOAT);
ASSERT(dstType == GL_UNSIGNED_BYTE ||
}
}
break;
+ case GL_HALF_FLOAT_NV:
+ {
+ GLhalfNV *dst = (GLhalfNV *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = _mesa_float_to_half((GLfloat) source[i]);
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap2( (GLushort *) dst, n );
+ }
+ }
+ break;
default:
_mesa_problem(ctx, "bad type in _mesa_pack_index_span");
}
srcType == GL_SHORT ||
srcType == GL_UNSIGNED_INT ||
srcType == GL_INT ||
+ srcType == GL_HALF_FLOAT_NV ||
srcType == GL_FLOAT);
ASSERT(dstType == GL_UNSIGNED_BYTE ||
}
}
break;
+ case GL_HALF_FLOAT_NV:
+ {
+ GLhalfNV *dst = (GLhalfNV *) dest;
+ GLuint i;
+ for (i=0;i<n;i++) {
+ dst[i] = _mesa_half_to_float(source[i]);
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap2( (GLushort *) dst, n );
+ }
+ }
+ break;
case GL_BITMAP:
if (dstPacking->LsbFirst) {
GLubyte *dst = (GLubyte *) dest;
case GL_FLOAT:
MEMCPY(dest, source, n * sizeof(GLfloat));
break;
+ case GL_HALF_FLOAT_NV:
+ {
+ GLuint i;
+ const GLhalfNV *src = (const GLhalfNV *) source;
+ for (i = 0; i < n; i++) {
+ dest[i] = _mesa_half_to_float(src[i]);
+ }
+ }
+ break;
default:
_mesa_problem(NULL, "bad type in _mesa_unpack_depth_span()");
return;
}
}
break;
+ case GL_HALF_FLOAT_NV:
+ {
+ GLhalfNV *dst = (GLhalfNV *) dest;
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ dst[i] = _mesa_float_to_half(depthSpan[i]);
+ }
+ if (dstPacking->SwapBytes) {
+ _mesa_swap2( (GLushort *) dst, n );
+ }
+ }
+ break;
default:
_mesa_problem(ctx, "bad type in _mesa_pack_depth_span");
}
}
+/**
+ * Single precision square root.
+ */
float
_mesa_sqrtf( float x )
{
}
-/** Wrapper around either pow() or xf86pow() */
+/**
+ * Wrapper around either pow() or xf86pow().
+ */
double
_mesa_pow(double x, double y)
{
}
-/*
+/**
* Return number of bits set in given GLuint.
*/
unsigned int
return bits;
}
+
+/**
+ * Convert a 4-byte float to a 2-byte half float.
+ */
+GLhalfNV
+_mesa_float_to_half(float val)
+{
+ const int flt = *((int *) &val);
+ const int flt_m = flt & 0x7fffff;
+ const int flt_e = (flt >> 23) & 0xff;
+ const int flt_s = (flt >> 31) & 0x1;
+ int s, e, m;
+ GLhalfNV result;
+
+ /* sign bit */
+ s = flt_s;
+
+ /* handle special cases */
+ if ((flt_e == 0) && (flt_m == 0)) {
+ /* zero */
+ m = 0;
+ e = 0;
+ }
+ else if ((flt_e == 0) && (flt_m != 0)) {
+ /* denorm -- denorm float maps to 0 half */
+ m = 0;
+ e = 0;
+ }
+ else if ((flt_e == 0xff) && (flt_m == 0)) {
+ /* infinity */
+ m = 0;
+ e = 31;
+ }
+ else if ((flt_e == 0xff) && (flt_m != 0)) {
+ /* NaN */
+ m = 1;
+ e = 31;
+ }
+ else {
+ /* regular number */
+ const int new_exp = flt_e - 127;
+ if (new_exp < -24) {
+ /* this maps to 0 */
+ m = 0;
+ e = 0;
+ }
+ else if (new_exp < -14) {
+ /* this maps to a denorm */
+ unsigned int exp_val = (unsigned int) (-14 - new_exp); /* 2^-exp_val*/
+ e = 0;
+ switch (exp_val) {
+ case 0:
+ _mesa_warning(NULL,
+ "float_to_half: logical error in denorm creation!\n");
+ m = 0;
+ break;
+ case 1: m = 512 + (flt_m >> 14); break;
+ case 2: m = 256 + (flt_m >> 15); break;
+ case 3: m = 128 + (flt_m >> 16); break;
+ case 4: m = 64 + (flt_m >> 17); break;
+ case 5: m = 32 + (flt_m >> 18); break;
+ case 6: m = 16 + (flt_m >> 19); break;
+ case 7: m = 8 + (flt_m >> 20); break;
+ case 8: m = 4 + (flt_m >> 21); break;
+ case 9: m = 2 + (flt_m >> 22); break;
+ case 10: m = 1; break;
+ }
+ }
+ else if (new_exp > 15) {
+ /* map this value to infinity */
+ m = 0;
+ e = 31;
+ }
+ else {
+ /* regular */
+ e = new_exp + 15;
+ m = flt_m >> 13;
+ }
+ }
+
+ result = (s << 15) | (e << 10) | m;
+ return result;
+}
+
+
+/**
+ * Convert a 2-byte half float to a 4-byte float.
+ */
+float
+_mesa_half_to_float(GLhalfNV val)
+{
+ /* XXX could also use a 64K-entry lookup table */
+ const int m = val & 0x3ff;
+ const int e = (val >> 10) & 0x1f;
+ const int s = (val >> 15) & 0x1;
+ int flt_m, flt_e, flt_s, flt;
+ float result;
+
+ /* sign bit */
+ flt_s = s;
+
+ /* handle special cases */
+ if ((e == 0) && (m == 0)) {
+ /* zero */
+ flt_m = 0;
+ flt_e = 0;
+ }
+ else if ((e == 0) && (m != 0)) {
+ /* denorm -- denorm half will fit in non-denorm single */
+ const float half_denorm = 1.0f / 16384.0f; /* 2^-14 */
+ float mantissa = ((float) (m)) / 1024.0f;
+ float sign = s ? -1.0f : 1.0f;
+ return sign * mantissa * half_denorm;
+ }
+ else if ((e == 31) && (m == 0)) {
+ /* infinity */
+ flt_e = 0xff;
+ flt_m = 0;
+ }
+ else if ((e == 31) && (m != 0)) {
+ /* NaN */
+ flt_e = 0xff;
+ flt_m = 1;
+ }
+ else {
+ /* regular */
+ flt_e = e + 112;
+ flt_m = m << 13;
+ }
+
+ flt = (flt_s << 31) | (flt_e << 23) | flt_m;
+ result = *((float *) &flt);
+ return result;
+}
+
/*@}*/
/** \name Environment vars */
/*@{*/
-/** Wrapper around either () or xf86() */
+/**
+ * Wrapper for getenv().
+ */
char *
_mesa_getenv( const char *var )
{