ALL: Huge upstream synch + PerRom DelaySI & CountPerOp parameters
[mupen64plus-pandora.git] / source / gles2glide64 / src / GlideHQ / tc-1.1+ / wrapper.c
CommitLineData
98e75f2d 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>
2d262872 24#include <stdlib.h>
98e75f2d 25
26#include "types.h"
27#include "internal.h"
2d262872 28#include <SDL_opengl.h>
29#include "../../Glide64/m64p.h"
98e75f2d 30
2d262872 31typedef void (*dxtCompressTexFuncExt)(GLint srccomps, GLint width, GLint height,
32 const GLubyte *srcPixData, GLenum destformat,
33 GLubyte *dest, GLint dstRowStride);
34static dxtCompressTexFuncExt _tx_compress_dxtn = NULL;
98e75f2d 35
2d262872 36#ifdef TXCDXTN_EXTERNAL
98e75f2d 37
2d262872 38#include "../../Glide64/osal_dynamiclib.h"
98e75f2d 39
2d262872 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
98e75f2d 47
2d262872 48static m64p_dynlib_handle dxtn_lib_handle;
98e75f2d 49
2d262872 50static void tx_compress_dxtn_init()
98e75f2d 51{
2d262872 52 m64p_error rval;
98e75f2d 53
2d262872 54 if (_tx_compress_dxtn)
55 return;
98e75f2d 56
2d262872 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 }
98e75f2d 69}
70
2d262872 71#else
98e75f2d 72
2d262872 73#include "s2tc/txc_dxtn.h"
74
75static void tx_compress_dxtn_init()
98e75f2d 76{
2d262872 77 _tx_compress_dxtn = tx_compress_dxtn;
98e75f2d 78}
79
2d262872 80#endif
81
98e75f2d 82
83TAPI void TAPIENTRY
2d262872 84tx_compress_dxtn_rgba(int srccomps, int width, int height,
85 const byte *source, int destformat, byte *dest,
86 int destRowStride)
98e75f2d 87{
88 int srcRowStride = width * srccomps;
2d262872 89 void *newSource = NULL;
98e75f2d 90
2d262872 91 tx_compress_dxtn_init();
92 if (!_tx_compress_dxtn) {
93 WriteLog(M64MSG_ERROR, "Failed to initialize S3TC compressor");
94 return;
98e75f2d 95 }
2d262872 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);
98e75f2d 108}