aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/main/texformat_tmp.h
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2004-01-24 17:02:19 +0000
committerBrian Paul <[email protected]>2004-01-24 17:02:19 +0000
commitfe03108ce0349cf6016fc88b0496735a8db3e804 (patch)
tree00e572fcd557457cfe534fb137c5328fd2c2914c /src/mesa/main/texformat_tmp.h
parentc6bf130e98b3c5b691ecaf4d99d401f2aab48e03 (diff)
Some initial RGB and RGBA floating point texture formats.
Diffstat (limited to 'src/mesa/main/texformat_tmp.h')
-rw-r--r--src/mesa/main/texformat_tmp.h132
1 files changed, 89 insertions, 43 deletions
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