/*
* Mesa 3-D graphics library
- * Version: 6.5.1
*
* Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
* Copyright (c) 2008 VMware, Inc.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
*/
#include "colormac.h"
#include "context.h"
#include "formats.h"
-#include "mfeatures.h"
#include "mtypes.h"
+#include "context.h"
#include "texcompress.h"
#include "texcompress_fxt1.h"
#include "texcompress_rgtc.h"
#include "texcompress_s3tc.h"
#include "texcompress_etc.h"
-#include "swrast/s_context.h"
/**
n += 3;
}
}
- if (ctx->Extensions.S3_s3tc) {
- if (formats) {
- formats[n++] = GL_RGB_S3TC;
- formats[n++] = GL_RGB4_S3TC;
- formats[n++] = GL_RGBA_S3TC;
- formats[n++] = GL_RGBA4_S3TC;
- }
- else {
- n += 4;
- }
- }
- if (ctx->Extensions.OES_compressed_ETC1_RGB8_texture) {
+ /* The GL_OES_compressed_ETC1_RGB8_texture spec says:
+ *
+ * "New State
+ *
+ * The queries for NUM_COMPRESSED_TEXTURE_FORMATS and
+ * COMPRESSED_TEXTURE_FORMATS include ETC1_RGB8_OES."
+ */
+ if (_mesa_is_gles(ctx)
+ && ctx->Extensions.OES_compressed_ETC1_RGB8_texture) {
if (formats) {
formats[n++] = GL_ETC1_RGB8_OES;
}
/**
- * Decompress a compressed texture image, returning a GL_RGBA/GL_FLOAT image.
- * \param srcRowStride stride in bytes between rows of blocks in the
- * compressed source image.
+ * Return a texel-fetch function for the given format, or NULL if
+ * invalid format.
*/
-void
-_mesa_decompress_image(gl_format format, GLuint width, GLuint height,
- const GLubyte *src, GLint srcRowStride,
- GLfloat *dest)
+compressed_fetch_func
+_mesa_get_compressed_fetch_func(gl_format format)
{
- void (*fetch)(const struct swrast_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel);
- struct swrast_texture_image texImage; /* dummy teximage */
- GLuint i, j;
- GLuint bytes, bw, bh;
-
- bytes = _mesa_get_format_bytes(format);
- _mesa_get_format_block_size(format, &bw, &bh);
-
- /* setup dummy texture image info */
- memset(&texImage, 0, sizeof(texImage));
- texImage.Map = (void *) src;
-
- /* XXX This line is a bit of a hack to adapt to the row stride
- * convention used by the texture decompression functions.
- */
- texImage.RowStride = srcRowStride * bh / bytes;
-
switch (format) {
- /* DXT formats */
case MESA_FORMAT_RGB_DXT1:
- fetch = _mesa_fetch_texel_rgb_dxt1;
- break;
case MESA_FORMAT_RGBA_DXT1:
- fetch = _mesa_fetch_texel_rgba_dxt1;
- break;
case MESA_FORMAT_RGBA_DXT3:
- fetch = _mesa_fetch_texel_rgba_dxt3;
- break;
case MESA_FORMAT_RGBA_DXT5:
- fetch = _mesa_fetch_texel_rgba_dxt5;
- break;
-
- /* FXT1 formats */
+ case MESA_FORMAT_SRGB_DXT1:
+ case MESA_FORMAT_SRGBA_DXT1:
+ case MESA_FORMAT_SRGBA_DXT3:
+ case MESA_FORMAT_SRGBA_DXT5:
+ return _mesa_get_dxt_fetch_func(format);
case MESA_FORMAT_RGB_FXT1:
- fetch = _mesa_fetch_texel_2d_f_rgb_fxt1;
- break;
case MESA_FORMAT_RGBA_FXT1:
- fetch = _mesa_fetch_texel_2d_f_rgba_fxt1;
- break;
-
- /* Red/RG formats */
+ return _mesa_get_fxt_fetch_func(format);
case MESA_FORMAT_RED_RGTC1:
- fetch = _mesa_fetch_texel_red_rgtc1;
- break;
- case MESA_FORMAT_SIGNED_RED_RGTC1:
- fetch = _mesa_fetch_texel_signed_red_rgtc1;
- break;
- case MESA_FORMAT_RG_RGTC2:
- fetch = _mesa_fetch_texel_rg_rgtc2;
- break;
- case MESA_FORMAT_SIGNED_RG_RGTC2:
- fetch = _mesa_fetch_texel_signed_rg_rgtc2;
- break;
-
- /* L/LA formats */
case MESA_FORMAT_L_LATC1:
- fetch = _mesa_fetch_texel_l_latc1;
- break;
+ case MESA_FORMAT_SIGNED_RED_RGTC1:
case MESA_FORMAT_SIGNED_L_LATC1:
- fetch = _mesa_fetch_texel_signed_l_latc1;
- break;
+ case MESA_FORMAT_RG_RGTC2:
case MESA_FORMAT_LA_LATC2:
- fetch = _mesa_fetch_texel_la_latc2;
- break;
+ case MESA_FORMAT_SIGNED_RG_RGTC2:
case MESA_FORMAT_SIGNED_LA_LATC2:
- fetch = _mesa_fetch_texel_signed_la_latc2;
- break;
-
- /* ETC1 formats */
+ return _mesa_get_compressed_rgtc_func(format);
case MESA_FORMAT_ETC1_RGB8:
- fetch = _mesa_fetch_texel_2d_f_etc1_rgb8;
- break;
+ return _mesa_get_etc_fetch_func(format);
+ default:
+ return NULL;
+ }
+}
- /* ETC2 formats */
- case MESA_FORMAT_ETC2_RGB8:
- fetch = _mesa_fetch_texel_2d_f_etc2_rgb8;
- break;
- case MESA_FORMAT_ETC2_SRGB8:
- fetch = _mesa_fetch_texel_2d_f_etc2_srgb8;
- break;
- case MESA_FORMAT_ETC2_RGBA8_EAC:
- fetch = _mesa_fetch_texel_2d_f_etc2_rgba8_eac;
- break;
- case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC:
- fetch = _mesa_fetch_texel_2d_f_etc2_srgb8_alpha8_eac;
- break;
- case MESA_FORMAT_ETC2_R11_EAC:
- fetch = _mesa_fetch_texel_2d_f_etc2_r11_eac;
- break;
- case MESA_FORMAT_ETC2_RG11_EAC:
- fetch = _mesa_fetch_texel_2d_f_etc2_rg11_eac;
- break;
- case MESA_FORMAT_ETC2_SIGNED_R11_EAC:
- fetch = _mesa_fetch_texel_2d_f_etc2_signed_r11_eac;
- break;
- case MESA_FORMAT_ETC2_SIGNED_RG11_EAC:
- fetch = _mesa_fetch_texel_2d_f_etc2_signed_rg11_eac;
- break;
- case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:
- fetch = _mesa_fetch_texel_2d_f_etc2_rgb8_punchthrough_alpha1;
- break;
- case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
- fetch = _mesa_fetch_texel_2d_f_etc2_srgb8_punchthrough_alpha1;
- break;
- default:
+/**
+ * Decompress a compressed texture image, returning a GL_RGBA/GL_FLOAT image.
+ * \param srcRowStride stride in bytes between rows of blocks in the
+ * compressed source image.
+ */
+void
+_mesa_decompress_image(gl_format format, GLuint width, GLuint height,
+ const GLubyte *src, GLint srcRowStride,
+ GLfloat *dest)
+{
+ compressed_fetch_func fetch;
+ GLuint i, j;
+ GLuint bytes, bw, bh;
+ GLint stride;
+
+ bytes = _mesa_get_format_bytes(format);
+ _mesa_get_format_block_size(format, &bw, &bh);
+
+ fetch = _mesa_get_compressed_fetch_func(format);
+ if (!fetch) {
_mesa_problem(NULL, "Unexpected format in _mesa_decompress_image()");
return;
}
+
+ stride = srcRowStride * bh / bytes;
for (j = 0; j < height; j++) {
for (i = 0; i < width; i++) {
- fetch(&texImage, i, j, 0, dest);
+ fetch(src, stride, i, j, dest);
dest += 4;
}
}