summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mesa/main/texformat.c108
-rw-r--r--src/mesa/main/texformat.h29
-rw-r--r--src/mesa/main/texformat_tmp.h132
3 files changed, 216 insertions, 53 deletions
diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
index 7d366b51d79..7222b77eb59 100644
--- a/src/mesa/main/texformat.c
+++ b/src/mesa/main/texformat.c
@@ -222,6 +222,7 @@ const struct gl_texture_format _mesa_texformat_color_index = {
fetch_texel_3d_f_color_index, /* FetchTexel3Df */
};
+/* XXX someday implement 16, 24 and 32-bit integer depth images */
const struct gl_texture_format _mesa_texformat_depth_component = {
MESA_FORMAT_DEPTH_COMPONENT, /* MesaFormat */
GL_DEPTH_COMPONENT, /* BaseFormat */
@@ -242,6 +243,87 @@ const struct gl_texture_format _mesa_texformat_depth_component = {
fetch_texel_3d_f_depth_component, /* FetchTexel3Df */
};
+const struct gl_texture_format _mesa_texformat_rgba_float32 = {
+ MESA_FORMAT_RGBA_FLOAT32, /* MesaFormat */
+ GL_RGBA, /* BaseFormat */
+ 8 * sizeof(GLfloat), /* RedBits */
+ 8 * sizeof(GLfloat), /* GreenBits */
+ 8 * sizeof(GLfloat), /* BlueBits */
+ 8 * sizeof(GLfloat), /* AlphaBits */
+ 0, /* LuminanceBits */
+ 0, /* IntensityBits */
+ 0, /* IndexBits */
+ 0, /* DepthBits */
+ 4 * sizeof(GLfloat), /* TexelBytes */
+ fetch_null_texel, /* FetchTexel1D */
+ fetch_null_texel, /* FetchTexel1D */
+ fetch_null_texel, /* FetchTexel1D */
+ fetch_texel_1d_f_rgba_f32, /* FetchTexel1Df */
+ fetch_texel_2d_f_rgba_f32, /* FetchTexel2Df */
+ fetch_texel_3d_f_rgba_f32, /* FetchTexel3Df */
+};
+
+const struct gl_texture_format _mesa_texformat_rgba_float16 = {
+ MESA_FORMAT_RGBA_FLOAT16, /* MesaFormat */
+ GL_RGBA, /* BaseFormat */
+ 8 * sizeof(GLhalfNV), /* RedBits */
+ 8 * sizeof(GLhalfNV), /* GreenBits */
+ 8 * sizeof(GLhalfNV), /* BlueBits */
+ 8 * sizeof(GLhalfNV), /* AlphaBits */
+ 0, /* LuminanceBits */
+ 0, /* IntensityBits */
+ 0, /* IndexBits */
+ 0, /* DepthBits */
+ 4 * sizeof(GLhalfNV), /* TexelBytes */
+ fetch_null_texel, /* FetchTexel1D */
+ fetch_null_texel, /* FetchTexel1D */
+ fetch_null_texel, /* FetchTexel1D */
+ fetch_texel_1d_f_rgba_f16, /* FetchTexel1Df */
+ fetch_texel_2d_f_rgba_f16, /* FetchTexel2Df */
+ fetch_texel_3d_f_rgba_f16, /* FetchTexel3Df */
+};
+
+const struct gl_texture_format _mesa_texformat_rgb_float32 = {
+ MESA_FORMAT_RGB_FLOAT32, /* MesaFormat */
+ GL_RGB, /* BaseFormat */
+ 8 * sizeof(GLfloat), /* RedBits */
+ 8 * sizeof(GLfloat), /* GreenBits */
+ 8 * sizeof(GLfloat), /* BlueBits */
+ 0, /* AlphaBits */
+ 0, /* LuminanceBits */
+ 0, /* IntensityBits */
+ 0, /* IndexBits */
+ 0, /* DepthBits */
+ 4 * sizeof(GLfloat), /* TexelBytes */
+ fetch_null_texel, /* FetchTexel1D */
+ fetch_null_texel, /* FetchTexel1D */
+ fetch_null_texel, /* FetchTexel1D */
+ fetch_texel_1d_f_rgb_f32, /* FetchTexel1Df */
+ fetch_texel_2d_f_rgb_f32, /* FetchTexel2Df */
+ fetch_texel_3d_f_rgb_f32, /* FetchTexel3Df */
+};
+
+const struct gl_texture_format _mesa_texformat_rgb_float16 = {
+ MESA_FORMAT_RGB_FLOAT16, /* MesaFormat */
+ GL_RGB, /* BaseFormat */
+ 8 * sizeof(GLhalfNV), /* RedBits */
+ 8 * sizeof(GLhalfNV), /* GreenBits */
+ 8 * sizeof(GLhalfNV), /* BlueBits */
+ 0, /* AlphaBits */
+ 0, /* LuminanceBits */
+ 0, /* IntensityBits */
+ 0, /* IndexBits */
+ 0, /* DepthBits */
+ 4 * sizeof(GLhalfNV), /* TexelBytes */
+ fetch_null_texel, /* FetchTexel1D */
+ fetch_null_texel, /* FetchTexel1D */
+ fetch_null_texel, /* FetchTexel1D */
+ fetch_texel_1d_f_rgb_f16, /* FetchTexel1Df */
+ fetch_texel_2d_f_rgb_f16, /* FetchTexel2Df */
+ fetch_texel_3d_f_rgb_f16, /* FetchTexel3Df */
+};
+
+
/*@}*/
@@ -855,15 +937,16 @@ _mesa_is_hardware_tex_format( const struct gl_texture_format *format )
/**
- * Choose an appropriate texture format.
+ * Choose an appropriate texture format given the format, type and
+ * internalFormat parameters passed to glTexImage().
*
- * \param ctx GL context.
- * \param internalFormat internal texture format.
- * \param format pixel format.
- * \param type data type.
+ * \param ctx the GL context.
+ * \param internalFormat user's prefered internal texture format.
+ * \param format incoming image pixel format.
+ * \param type incoming image data type.
*
- * \return a pointer to a gl_texture_format in which to store the texture on
- * success, or NULL on failure.
+ * \return a pointer to a gl_texture_format object which describes the
+ * choosen texture format, or NULL on failure.
*
* This is called via dd_function_table::ChooseTextureFormat. Hardware drivers
* typically override this function with a specialized version.
@@ -1046,6 +1129,17 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
else
return NULL;
+ /* XXX prototype/example code */
+ /* GL_ATI_texture_float or GL_NV_float_buffer */
+ case GL_RGBA_FLOAT32_ATI:
+ return &_mesa_texformat_rgba_float32;
+ case GL_RGBA_FLOAT16_ATI:
+ return &_mesa_texformat_rgba_float16;
+ case GL_RGB_FLOAT32_ATI:
+ return &_mesa_texformat_rgb_float32;
+ case GL_RGB_FLOAT16_ATI:
+ return &_mesa_texformat_rgb_float16;
+
default:
_mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
return NULL;
diff --git a/src/mesa/main/texformat.h b/src/mesa/main/texformat.h
index c43da46d7b1..67bd4b5133c 100644
--- a/src/mesa/main/texformat.h
+++ b/src/mesa/main/texformat.h
@@ -75,12 +75,17 @@ enum _format {
MESA_FORMAT_YCBCR_REV, /* UorV UorV YYYY YYYY */
/*@}*/
+ /**
+ * \name Compressed texture formats.
+ */
+ /*@{*/
MESA_FORMAT_RGB_FXT1,
MESA_FORMAT_RGBA_FXT1,
MESA_FORMAT_RGB_DXT1,
MESA_FORMAT_RGBA_DXT1,
MESA_FORMAT_RGBA_DXT3,
MESA_FORMAT_RGBA_DXT5,
+ /*@}*/
#if 0
/**
@@ -108,8 +113,8 @@ enum _format {
* converted to one of these formats. Components are arrays of GLchan
* values, so there will be no big/little endian issues.
*
- * \note Because these are based on the GLchan data type, one cannot assume 8
- * bits per channel with these formats. If you require GLubyte channels,
+ * \note Because these are based on the GLchan data type, one cannot assume
+ * 8 bits per channel with these formats. If you require GLubyte channels,
* use one of the hardware formats above.
*/
/*@{*/
@@ -120,7 +125,17 @@ enum _format {
MESA_FORMAT_LUMINANCE_ALPHA,
MESA_FORMAT_INTENSITY,
MESA_FORMAT_COLOR_INDEX,
- MESA_FORMAT_DEPTH_COMPONENT
+ /*@}*/
+
+ /**
+ * \name Floating point texture formats.
+ */
+ /*@{*/
+ MESA_FORMAT_DEPTH_COMPONENT,
+ MESA_FORMAT_RGBA_FLOAT32,
+ MESA_FORMAT_RGBA_FLOAT16,
+ MESA_FORMAT_RGB_FLOAT32,
+ MESA_FORMAT_RGB_FLOAT16
/*@}*/
};
@@ -145,7 +160,15 @@ extern const struct gl_texture_format _mesa_texformat_luminance;
extern const struct gl_texture_format _mesa_texformat_luminance_alpha;
extern const struct gl_texture_format _mesa_texformat_intensity;
extern const struct gl_texture_format _mesa_texformat_color_index;
+/*@}*/
+
+/** Floating point texture formats */
+/*@{*/
extern const struct gl_texture_format _mesa_texformat_depth_component;
+extern const struct gl_texture_format _mesa_texformat_rgba_float32;
+extern const struct gl_texture_format _mesa_texformat_rgba_float16;
+extern const struct gl_texture_format _mesa_texformat_rgb_float32;
+extern const struct gl_texture_format _mesa_texformat_rgb_float16;
/*@}*/
/** \name The hardware-friendly formats */
diff --git a/src/mesa/main/texformat_tmp.h b/src/mesa/main/texformat_tmp.h
index 061f11daca3..cf1b3d87a44 100644
--- a/src/mesa/main/texformat_tmp.h
+++ b/src/mesa/main/texformat_tmp.h
@@ -48,8 +48,10 @@
((GLubyte *)(t)->Data + (i) * (sz))
#define USHORT_SRC( t, i, j, k ) \
((GLushort *)(t)->Data + (i))
-#define FLOAT_SRC( t, i, j, k ) \
- ((GLfloat *)(t)->Data + (i))
+#define FLOAT_SRC( t, i, j, k, sz ) \
+ ((GLfloat *)(t)->Data + (i) * (sz))
+#define HALF_SRC( t, i, j, k, sz ) \
+ ((GLhalfNV *)(t)->Data + (i) * (sz))
#define FETCH(x) fetch_texel_1d_##x
@@ -61,8 +63,10 @@
((GLubyte *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
#define USHORT_SRC( t, i, j, k ) \
((GLushort *)(t)->Data + ((t)->RowStride * (j) + (i)))
-#define FLOAT_SRC( t, i, j, k ) \
- ((GLfloat *)(t)->Data + ((t)->RowStride * (j) + (i)))
+#define FLOAT_SRC( t, i, j, k, sz ) \
+ ((GLfloat *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
+#define HALF_SRC( t, i, j, k, sz ) \
+ ((GLhalfNV *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
#define FETCH(x) fetch_texel_2d_##x
@@ -77,9 +81,12 @@
#define USHORT_SRC( t, i, j, k ) \
((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \
(t)->RowStride + (i)))
-#define FLOAT_SRC( t, i, j, k ) \
+#define FLOAT_SRC( t, i, j, k, sz ) \
((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \
- (t)->RowStride + (i)))
+ (t)->RowStride + (i)) * (sz))
+#define HALF_SRC( t, i, j, k, sz ) \
+ ((GLhalfNV *)(t)->Data + (((t)->Height * (k) + (j)) * \
+ (t)->RowStride + (i)) * (sz))
#define FETCH(x) fetch_texel_3d_##x
@@ -225,8 +232,7 @@ static void FETCH(color_index)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLchan *texel )
{
const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
- GLchan *index = (GLchan *) texel;
- index[0] = src[0];
+ texel[0] = src[0];
}
/* Fetch CI texel from 1D, 2D or 3D CI texture, returning 1 GLfloat */
@@ -238,31 +244,75 @@ static void FETCH(f_color_index)( const struct gl_texture_image *texImage,
}
-#if 000
/* Fetch depth texel from 1D, 2D or 3D DEPTH texture, returning 1 GLfloat */
-static void FETCH(depth_component)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLchan *texel )
+/* Note: no GLchan version of this function */
+static void FETCH(f_depth_component)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
{
-#if 0
- const GLfloat *src = FLOAT_SRC( texImage, i, j, k );
- GLfloat *depth = (GLfloat *) texel;
- depth[0] = src[0];
-#else
- _mesa_problem(NULL, "fetching depth component as non-float!");
-#endif
+ const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 1 );
+ texel[0] = src[0];
}
-#endif
-/* Fetch depth texel from 1D, 2D or 3D DEPTH texture, returning 1 GLfloat */
-static void FETCH(f_depth_component)( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
+/* Fetch color texel from 1D, 2D or 3D RGBA_FLOAT32 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_rgba_f32)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
{
- const GLfloat *src = FLOAT_SRC( texImage, i, j, k );
- texel[0] = src[0];
+ const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 4 );
+ texel[RCOMP] = src[0];
+ texel[GCOMP] = src[1];
+ texel[BCOMP] = src[2];
+ texel[ACOMP] = src[3];
+}
+
+/* Fetch color texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_rgba_f16)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLhalfNV *src = HALF_SRC( texImage, i, j, k, 4 );
+ texel[RCOMP] = _mesa_half_to_float(src[0]);
+ texel[GCOMP] = _mesa_half_to_float(src[1]);
+ texel[BCOMP] = _mesa_half_to_float(src[2]);
+ texel[ACOMP] = _mesa_half_to_float(src[3]);
+}
+
+
+/* Fetch color texel from 1D, 2D or 3D RGB_FLOAT32 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_rgb_f32)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 3 );
+ texel[RCOMP] = src[0];
+ texel[GCOMP] = src[1];
+ texel[BCOMP] = src[2];
+ texel[ACOMP] = CHAN_MAXF;
+}
+
+/* Fetch color texel from 1D, 2D or 3D RGB_FLOAT16 texture,
+ * returning 4 GLfloats.
+ */
+static void FETCH(f_rgb_f16)( const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLhalfNV *src = HALF_SRC( texImage, i, j, k, 3 );
+ texel[RCOMP] = _mesa_half_to_float(src[0]);
+ texel[GCOMP] = _mesa_half_to_float(src[1]);
+ texel[BCOMP] = _mesa_half_to_float(src[2]);
+ texel[ACOMP] = CHAN_MAXF;
}
+
+/*
+ * Begin Hardware formats
+ */
+
/* Fetch color texel from 1D, 2D or 3D rgba8888 texture, return 4 GLchans */
static void FETCH(rgba8888)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLchan *texel )
@@ -350,10 +400,9 @@ static void FETCH(f_rgb565)( const struct gl_texture_image *texImage,
{
const GLushort *src = USHORT_SRC( texImage, i, j, k );
const GLushort s = *src;
- /* xxx fixup */
- texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) * 255 / 0xf8 );
- texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) * 255 / 0xfc );
- texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) * 255 / 0xf8 );
+ texel[RCOMP] = ((s >> 8) & 0xf8) * (1.0F / 248.0F);
+ texel[GCOMP] = ((s >> 3) & 0xfc) * (1.0F / 252.0F);
+ texel[BCOMP] = ((s << 3) & 0xf8) * (1.0F / 248.0F);
texel[ACOMP] = CHAN_MAXF;
}
@@ -376,11 +425,10 @@ static void FETCH(f_argb4444)( const struct gl_texture_image *texImage,
{
const GLushort *src = USHORT_SRC( texImage, i, j, k );
const GLushort s = *src;
- /* xxx fixup */
- texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf );
- texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf );
- texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf );
- texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 12) & 0xf) * 255 / 0xf );
+ texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
+ texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
+ texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
+ texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
}
@@ -402,11 +450,10 @@ static void FETCH(f_argb1555)( const struct gl_texture_image *texImage,
{
const GLushort *src = USHORT_SRC( texImage, i, j, k );
const GLushort s = *src;
- /* xxx better */
- texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0x1f) * 255 / 0x1f );
- texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0x1f) * 255 / 0x1f );
- texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0x1f) * 255 / 0x1f );
- texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
+ texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
+ texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
+ texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
+ texel[ACOMP] = ((s >> 15) & 0x01);
}
@@ -451,10 +498,9 @@ static void FETCH(f_rgb332)( const struct gl_texture_image *texImage,
{
const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
const GLubyte s = *src;
- /* xxx improve */
- texel[RCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xe0) * 255 / 0xe0 );
- texel[GCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xe0) * 255 / 0xe0 );
- texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 5) & 0xc0) * 255 / 0xc0 );
+ texel[RCOMP] = ((s ) & 0xe0) * (1.0F / 224.0F);
+ texel[GCOMP] = ((s << 3) & 0xe0) * (1.0F / 224.0F);
+ texel[BCOMP] = ((s << 5) & 0xc0) * (1.0F / 192.0F);
texel[ACOMP] = CHAN_MAXF;
}
@@ -647,7 +693,6 @@ static void FETCH(ycbcr_rev)( const struct gl_texture_image *texImage,
/* Fetch color texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats */
/* We convert YCbCr to RGB here */
-/* XXX this may break if GLchan != GLubyte */
static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLfloat *texel )
{
@@ -885,5 +930,6 @@ static void FETCH(bgr233)( const struct gl_texture_image *texImage,
#undef UBYTE_SRC
#undef USHORT_SRC
#undef FLOAT_SRC
+#undef HALF_SRC
#undef FETCH
#undef DIM