5 * Copyright (C) 2004 Daniel Borca All Rights Reserved.
7 * this is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * this is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Make; see the file COPYING. If not, write to
19 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <SDL_opengl.h>
29 #include "../../Glide64/m64p.h"
31 typedef void (*dxtCompressTexFuncExt)(GLint srccomps, GLint width, GLint height,
32 const GLubyte *srcPixData, GLenum destformat,
33 GLubyte *dest, GLint dstRowStride);
34 static dxtCompressTexFuncExt _tx_compress_dxtn = NULL;
36 #ifdef TXCDXTN_EXTERNAL
38 #include "../../Glide64/osal_dynamiclib.h"
40 #if defined(_WIN32) || defined(WIN32)
41 #define DXTN_LIBNAME "dxtn.dll"
42 #elif defined(__DJGPP__)
43 #define DXTN_LIBNAME "dxtn.dxe"
45 #define DXTN_LIBNAME "libtxc_dxtn.so"
48 static m64p_dynlib_handle dxtn_lib_handle;
50 static void tx_compress_dxtn_init()
54 if (_tx_compress_dxtn)
57 rval = osal_dynlib_open(&dxtn_lib_handle, DXTN_LIBNAME);
58 if (rval != M64ERR_SUCCESS) {
59 WriteLog(M64MSG_WARNING, "Failed to open %s", DXTN_LIBNAME);
63 _tx_compress_dxtn = osal_dynlib_getproc(dxtn_lib_handle, "tx_compress_dxtn");
64 if (!_tx_compress_dxtn) {
65 WriteLog(M64MSG_WARNING, "Shared library '%s' invalid; no PluginGetVersion() function found.", DXTN_LIBNAME, "tx_compress_dxtn");
66 osal_dynlib_close(dxtn_lib_handle);
73 #include "s2tc/txc_dxtn.h"
75 static void tx_compress_dxtn_init()
77 _tx_compress_dxtn = tx_compress_dxtn;
84 tx_compress_dxtn_rgba(int srccomps, int width, int height,
85 const byte *source, int destformat, byte *dest,
88 int srcRowStride = width * srccomps;
89 void *newSource = NULL;
91 tx_compress_dxtn_init();
92 if (!_tx_compress_dxtn) {
93 WriteLog(M64MSG_ERROR, "Failed to initialize S3TC compressor");
97 assert(srccomps == 3 || srccomps == 4);
100 newSource = reorder_source_3_alloc(source, width, height, srcRowStride);
102 newSource = reorder_source_4_alloc(source, width, height, srcRowStride);
104 _tx_compress_dxtn(srccomps, width, height, newSource, destformat, dest,