X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=mupen64plus-pandora.git;a=blobdiff_plain;f=source%2Fgles2glide64%2Fsrc%2FGlideHQ%2Ftc-1.1%2B%2Fwrapper.c;h=cff314d32064dba93119c7739913dea78f7ffb19;hp=0a171ee4fabcc4a26aa64b35f659b2cdb4898011;hb=2d26287291331f2b1793a8e76ede08c75654fb7c;hpb=01d8ca6fb06a8261602900cab63c61e5a1b143c9 diff --git a/source/gles2glide64/src/GlideHQ/tc-1.1+/wrapper.c b/source/gles2glide64/src/GlideHQ/tc-1.1+/wrapper.c index 0a171ee..cff314d 100644 --- a/source/gles2glide64/src/GlideHQ/tc-1.1+/wrapper.c +++ b/source/gles2glide64/src/GlideHQ/tc-1.1+/wrapper.c @@ -21,87 +21,88 @@ #include +#include #include "types.h" #include "internal.h" -#include "dxtn.h" +#include +#include "../../Glide64/m64p.h" +typedef void (*dxtCompressTexFuncExt)(GLint srccomps, GLint width, GLint height, + const GLubyte *srcPixData, GLenum destformat, + GLubyte *dest, GLint dstRowStride); +static dxtCompressTexFuncExt _tx_compress_dxtn = NULL; -#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 -#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 -#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 -#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 +#ifdef TXCDXTN_EXTERNAL +#include "../../Glide64/osal_dynamiclib.h" -TAPI void TAPIENTRY -fetch_2d_texel_rgb_dxt1 (int texImage_RowStride, - const byte *texImage_Data, - int i, int j, - byte *texel) -{ - dxt1_rgb_decode_1(texImage_Data, texImage_RowStride, i, j, texel); -} +#if defined(_WIN32) || defined(WIN32) +#define DXTN_LIBNAME "dxtn.dll" +#elif defined(__DJGPP__) +#define DXTN_LIBNAME "dxtn.dxe" +#else +#define DXTN_LIBNAME "libtxc_dxtn.so" +#endif +static m64p_dynlib_handle dxtn_lib_handle; -TAPI void TAPIENTRY -fetch_2d_texel_rgba_dxt1 (int texImage_RowStride, - const byte *texImage_Data, - int i, int j, - byte *texel) +static void tx_compress_dxtn_init() { - dxt1_rgba_decode_1(texImage_Data, texImage_RowStride, i, j, texel); -} + m64p_error rval; + if (_tx_compress_dxtn) + return; -TAPI void TAPIENTRY -fetch_2d_texel_rgba_dxt3 (int texImage_RowStride, - const byte *texImage_Data, - int i, int j, - byte *texel) -{ - dxt3_rgba_decode_1(texImage_Data, texImage_RowStride, i, j, texel); + rval = osal_dynlib_open(&dxtn_lib_handle, DXTN_LIBNAME); + if (rval != M64ERR_SUCCESS) { + WriteLog(M64MSG_WARNING, "Failed to open %s", DXTN_LIBNAME); + return; + } + + _tx_compress_dxtn = osal_dynlib_getproc(dxtn_lib_handle, "tx_compress_dxtn"); + if (!_tx_compress_dxtn) { + WriteLog(M64MSG_WARNING, "Shared library '%s' invalid; no PluginGetVersion() function found.", DXTN_LIBNAME, "tx_compress_dxtn"); + osal_dynlib_close(dxtn_lib_handle); + return; + } } +#else -TAPI void TAPIENTRY -fetch_2d_texel_rgba_dxt5 (int texImage_RowStride, - const byte *texImage_Data, - int i, int j, - byte *texel) +#include "s2tc/txc_dxtn.h" + +static void tx_compress_dxtn_init() { - dxt5_rgba_decode_1(texImage_Data, texImage_RowStride, i, j, texel); + _tx_compress_dxtn = tx_compress_dxtn; } +#endif + TAPI void TAPIENTRY -tx_compress_dxtn (int srccomps, int width, int height, - const byte *source, int destformat, byte *dest, - int destRowStride) +tx_compress_dxtn_rgba(int srccomps, int width, int height, + const byte *source, int destformat, byte *dest, + int destRowStride) { int srcRowStride = width * srccomps; + void *newSource = NULL; - switch (destformat) { - case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - dxt1_rgb_encode(width, height, srccomps, - source, srcRowStride, - dest, destRowStride); - break; - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - dxt1_rgba_encode(width, height, srccomps, - source, srcRowStride, - dest, destRowStride); - break; - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - dxt3_rgba_encode(width, height, srccomps, - source, srcRowStride, - dest, destRowStride); - break; - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - dxt5_rgba_encode(width, height, srccomps, - source, srcRowStride, - dest, destRowStride); - break; - default: - assert(0); + tx_compress_dxtn_init(); + if (!_tx_compress_dxtn) { + WriteLog(M64MSG_ERROR, "Failed to initialize S3TC compressor"); + return; } + + assert(srccomps == 3 || srccomps == 4); + + if (srccomps == 3) + newSource = reorder_source_3_alloc(source, width, height, srcRowStride); + if (srccomps == 4) + newSource = reorder_source_4_alloc(source, width, height, srcRowStride); + + _tx_compress_dxtn(srccomps, width, height, newSource, destformat, dest, + destRowStride); + + free(newSource); }