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 */
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 */
+};
+
+
/*@}*/
/**
- * 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.
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;
((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
((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
#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
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 */
}
-#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 )
{
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;
}
{
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);
}
{
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);
}
{
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;
}
/* 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 )
{
#undef UBYTE_SRC
#undef USHORT_SRC
#undef FLOAT_SRC
+#undef HALF_SRC
#undef FETCH
#undef DIM