diff options
author | Brian Paul <[email protected]> | 2012-12-08 15:19:44 -0700 |
---|---|---|
committer | Brian Paul <[email protected]> | 2012-12-14 06:33:07 -0700 |
commit | a774eaa57e290a4fe0bcf5827019ac7054d096e0 (patch) | |
tree | 8b2f3ae3751b559e9c57ea3e09b4f5e2213f8622 /src | |
parent | 2037a06da94bc0e14a0732c50c7d7044d9a29da0 (diff) |
mesa: add new texel fetch code for dxt formats
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/main/texcompress_s3tc.c | 106 | ||||
-rw-r--r-- | src/mesa/main/texcompress_s3tc.h | 5 |
2 files changed, 110 insertions, 1 deletions
diff --git a/src/mesa/main/texcompress_s3tc.c b/src/mesa/main/texcompress_s3tc.c index 476b998e078..9595c849b53 100644 --- a/src/mesa/main/texcompress_s3tc.c +++ b/src/mesa/main/texcompress_s3tc.c @@ -58,7 +58,7 @@ #define DXTN_LIBNAME "libtxc_dxtn.so" #endif -typedef void (*dxtFetchTexelFuncExt)( GLint srcRowstride, GLubyte *pixdata, GLint col, GLint row, GLvoid *texelOut ); +typedef void (*dxtFetchTexelFuncExt)( GLint srcRowstride, const GLubyte *pixdata, GLint col, GLint row, GLvoid *texelOut ); static dxtFetchTexelFuncExt fetch_ext_rgb_dxt1 = NULL; static dxtFetchTexelFuncExt fetch_ext_rgba_dxt1 = NULL; @@ -494,3 +494,107 @@ _mesa_fetch_texel_srgba_dxt5(const struct swrast_texture_image *texImage, texel[BCOMP] = _mesa_nonlinear_to_linear(rgba[BCOMP]); texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]); } + + +/** Report problem with dxt texture decompression, once */ +static void +problem(const char *func) +{ + static GLboolean warned = GL_FALSE; + if (!warned) { + _mesa_debug(NULL, "attempted to decode DXT texture without " + "library available: %s\n", func); + warned = GL_TRUE; + } +} + + +static void +fetch_rgb_dxt1(const GLubyte *map, const GLuint imageOffsets[], + GLint rowStride, GLint i, GLint j, GLint k, GLfloat *texel) +{ + if (fetch_ext_rgb_dxt1) { + GLuint sliceOffset = k ? imageOffsets[k] / 2 : 0; + GLubyte tex[4]; + fetch_ext_rgb_dxt1(rowStride, map + sliceOffset, i, j, tex); + texel[RCOMP] = UBYTE_TO_FLOAT(tex[RCOMP]); + texel[GCOMP] = UBYTE_TO_FLOAT(tex[GCOMP]); + texel[BCOMP] = UBYTE_TO_FLOAT(tex[BCOMP]); + texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]); + } + else { + problem("rgb_dxt1"); + } +} + +static void +fetch_rgba_dxt1(const GLubyte *map, const GLuint imageOffsets[], + GLint rowStride, GLint i, GLint j, GLint k, GLfloat *texel) +{ + if (fetch_ext_rgba_dxt1) { + GLuint sliceOffset = k ? imageOffsets[k] / 2 : 0; + GLubyte tex[4]; + fetch_ext_rgba_dxt1(rowStride, map + sliceOffset, i, j, tex); + texel[RCOMP] = UBYTE_TO_FLOAT(tex[RCOMP]); + texel[GCOMP] = UBYTE_TO_FLOAT(tex[GCOMP]); + texel[BCOMP] = UBYTE_TO_FLOAT(tex[BCOMP]); + texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]); + } + else { + problem("rgba_dxt1"); + } +} + +static void +fetch_rgba_dxt3(const GLubyte *map, const GLuint imageOffsets[], + GLint rowStride, GLint i, GLint j, GLint k, GLfloat *texel) +{ + if (fetch_ext_rgba_dxt3) { + GLuint sliceOffset = k ? imageOffsets[k] : 0; + GLubyte tex[4]; + fetch_ext_rgba_dxt3(rowStride, map + sliceOffset, i, j, tex); + texel[RCOMP] = UBYTE_TO_FLOAT(tex[RCOMP]); + texel[GCOMP] = UBYTE_TO_FLOAT(tex[GCOMP]); + texel[BCOMP] = UBYTE_TO_FLOAT(tex[BCOMP]); + texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]); + } + else { + problem("rgba_dxt3"); + } +} + +static void +fetch_rgba_dxt5(const GLubyte *map, const GLuint imageOffsets[], + GLint rowStride, GLint i, GLint j, GLint k, GLfloat *texel) +{ + if (fetch_ext_rgba_dxt5) { + GLuint sliceOffset = k ? imageOffsets[k] : 0; + GLubyte tex[4]; + fetch_ext_rgba_dxt5(rowStride, map + sliceOffset, i, j, tex); + texel[RCOMP] = UBYTE_TO_FLOAT(tex[RCOMP]); + texel[GCOMP] = UBYTE_TO_FLOAT(tex[GCOMP]); + texel[BCOMP] = UBYTE_TO_FLOAT(tex[BCOMP]); + texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]); + } + else { + problem("rgba_dxt5"); + } +} + + +compressed_fetch_func +_mesa_get_dxt_fetch_func(gl_format format) +{ + switch (format) { + case MESA_FORMAT_RGB_DXT1: + return fetch_rgb_dxt1; + case MESA_FORMAT_RGBA_DXT1: + return fetch_rgba_dxt1; + case MESA_FORMAT_RGBA_DXT3: + return fetch_rgba_dxt3; + case MESA_FORMAT_RGBA_DXT5: + return fetch_rgba_dxt5; + default: + return NULL; + } +} diff --git a/src/mesa/main/texcompress_s3tc.h b/src/mesa/main/texcompress_s3tc.h index 524ac0c134e..5758e8365c1 100644 --- a/src/mesa/main/texcompress_s3tc.h +++ b/src/mesa/main/texcompress_s3tc.h @@ -29,6 +29,7 @@ #include "glheader.h" #include "mfeatures.h" #include "texstore.h" +#include "texcompress.h" struct gl_context; struct swrast_texture_image; @@ -80,4 +81,8 @@ _mesa_fetch_texel_srgba_dxt5(const struct swrast_texture_image *texImage, extern void _mesa_init_texture_s3tc(struct gl_context *ctx); +extern compressed_fetch_func +_mesa_get_dxt_fetch_func(gl_format format); + + #endif /* TEXCOMPRESS_S3TC_H */ |