ALL: Huge upstream synch + PerRom DelaySI & CountPerOp parameters
[mupen64plus-pandora.git] / source / gles2glide64 / src / GlideHQ / tc-1.1+ / wrapper.c
1 /*
2  * Texture compression
3  * Version:  1.0
4  *
5  * Copyright (C) 2004  Daniel Borca   All Rights Reserved.
6  *
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)
10  * any later version.
11  *
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.
16  *
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.        
20  */
21
22
23 #include <assert.h>
24 #include <stdlib.h>
25
26 #include "types.h"
27 #include "internal.h"
28 #include <SDL_opengl.h>
29 #include "../../Glide64/m64p.h"
30
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;
35
36 #ifdef TXCDXTN_EXTERNAL
37
38 #include "../../Glide64/osal_dynamiclib.h"
39
40 #if defined(_WIN32) || defined(WIN32)
41 #define DXTN_LIBNAME "dxtn.dll"
42 #elif defined(__DJGPP__)
43 #define DXTN_LIBNAME "dxtn.dxe"
44 #else
45 #define DXTN_LIBNAME "libtxc_dxtn.so"
46 #endif
47
48 static m64p_dynlib_handle dxtn_lib_handle;
49
50 static void tx_compress_dxtn_init()
51 {
52     m64p_error rval;
53
54     if (_tx_compress_dxtn)
55         return;
56
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);
60         return;
61     }
62
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);
67         return;
68     }
69 }
70
71 #else
72
73 #include "s2tc/txc_dxtn.h"
74
75 static void tx_compress_dxtn_init()
76 {
77         _tx_compress_dxtn = tx_compress_dxtn;
78 }
79
80 #endif
81
82
83 TAPI void TAPIENTRY
84 tx_compress_dxtn_rgba(int srccomps, int width, int height,
85                       const byte *source, int destformat, byte *dest,
86                       int destRowStride)
87 {
88     int srcRowStride = width * srccomps;
89     void *newSource = NULL;
90
91     tx_compress_dxtn_init();
92     if (!_tx_compress_dxtn) {
93         WriteLog(M64MSG_ERROR, "Failed to initialize S3TC compressor");
94         return;
95     }
96
97     assert(srccomps == 3 || srccomps == 4);
98
99     if (srccomps == 3)
100         newSource = reorder_source_3_alloc(source, width, height, srcRowStride);
101     if (srccomps == 4)
102         newSource = reorder_source_4_alloc(source, width, height, srcRowStride);
103
104     _tx_compress_dxtn(srccomps, width, height, newSource, destformat, dest,
105                       destRowStride);
106
107     free(newSource);
108 }