ACLOCAL_AMFLAGS = -I m4
+
+if ENABLE_RUNTIME_LINKING
+AM_CPPFLAGS = -DENABLE_RUNTIME_LINKING
+endif
+
+if ENABLE_TOOLS
bin_PROGRAMS = s2tc_compress s2tc_decompress
s2tc_compress_SOURCES = s2tc_compress.cpp txc_dxtn.h s2tc_license.h
-s2tc_compress_LDADD = libtxc_dxtn.la
s2tc_decompress_SOURCES = s2tc_decompress.cpp txc_dxtn.h s2tc_license.h
+if ENABLE_RUNTIME_LINKING
+s2tc_compress_LDADD = -ldl
+s2tc_decompress_LDADD = -ldl
+else
+if ENABLE_LIB
+s2tc_compress_LDADD = libtxc_dxtn.la
s2tc_decompress_LDADD = libtxc_dxtn.la
+else
+s2tc_compress_LDADD = -ltxc_dxtn
+s2tc_decompress_LDADD = -ltxc_dxtn
+endif
+endif
+endif
+if ENABLE_LIB
lib_LTLIBRARIES = libtxc_dxtn.la
-
libtxc_dxtn_la_SOURCES = s2tc_algorithm.cpp s2tc_libtxc_dxtn.cpp s2tc_common.h s2tc_algorithm.h txc_dxtn.h s2tc_license.h
libtxc_dxtn_la_LDFLAGS = -versioninfo 0:0:0
libtxc_dxtn_la_LIBADD = -lm
libtxc_dxtn_la_CFLAGS = -fvisibility=hidden -Wold-style-definition -Wstrict-prototypes -Wsign-compare -Wdeclaration-after-statement
-
library_includedir = $(includedir)
library_include_HEADERS = txc_dxtn.h
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_HEADERS = txc_dxtn.pc
+endif
# versioninfo:
# - compatible interface change: c:r:a -> c+1:0:a+1
AC_PROG_LIBTOOL
+AC_ARG_ENABLE(runtime-linking, AS_HELP_STRING([--disable-runtime-linking], [Do not load the library at runtime (faster startup, more dependencies)]), [enable_runtime_linking=$enableval], [enable_runtime_linking=yes])
+AC_ARG_ENABLE(tools, AS_HELP_STRING([--disable-tools], [Do not build the s2tc_compress and s2_decompress tools]), [enable_tools=$enableval], [enable_tools=yes])
+AC_ARG_ENABLE(lib, AS_HELP_STRING([--disable-lib], [Do not build the included libtxc_dxtn library for S2TC]), [enable_lib=$enableval], [enable_lib=yes])
+
+AM_CONDITIONAL(ENABLE_RUNTIME_LINKING, [test x"$enable_runtime_linking" != xno])
+AM_CONDITIONAL(ENABLE_TOOLS, [test x"$enable_tools" != xno])
+AM_CONDITIONAL(ENABLE_LIB, [test x"$enable_lib" != xno])
+
AC_CONFIG_FILES([Makefile txc_dxtn.pc])
AC_OUTPUT
#include <algorithm>
#include "s2tc_common.h"
+#ifdef ENABLE_RUNTIME_LINKING
+#include <dlfcn.h>
+#include <GL/gl.h>
+extern "C"
+{
+ typedef void (tx_compress_dxtn_t)(GLint srccomps, GLint width, GLint height,
+ const GLubyte *srcPixData, GLenum destformat,
+ GLubyte *dest, GLint dstRowStride);
+};
+tx_compress_dxtn_t *tx_compress_dxtn = NULL;
+inline bool load_libraries()
+{
+ void *l = dlopen("libtxc_dxtn.so", RTLD_NOW);
+ if(!l)
+ {
+ fprintf(stderr, "Cannot load library: %s\n", dlerror());
+ return false;
+ }
+ tx_compress_dxtn = (tx_compress_dxtn_t *) dlsym(l, "tx_compress_dxtn");
+ if(!tx_compress_dxtn)
+ {
+ fprintf(stderr, "The selected libtxc_dxtn.so does not contain all required symbols.");
+ dlclose(l);
+ return false;
+ }
+ return true;
+}
+#else
extern "C"
{
#include "txc_dxtn.h"
};
+inline bool load_libraries()
+{
+ return true;
+}
+#endif
+
/* START stuff that originates from image.c in DarkPlaces */
/*
#include <string.h>
#include <algorithm>
+#ifdef ENABLE_RUNTIME_LINKING
+#include <dlfcn.h>
+#include <GL/gl.h>
+extern "C"
+{
+ typedef void (fetch_2d_texel_rgb_dxt1_t)(GLint srcRowStride, const GLubyte *pixdata,
+ GLint i, GLint j, GLvoid *texel);
+ typedef void (fetch_2d_texel_rgba_dxt1_t)(GLint srcRowStride, const GLubyte *pixdata,
+ GLint i, GLint j, GLvoid *texel);
+ typedef void (fetch_2d_texel_rgba_dxt3_t)(GLint srcRowStride, const GLubyte *pixdata,
+ GLint i, GLint j, GLvoid *texel);
+ typedef void (fetch_2d_texel_rgba_dxt5_t)(GLint srcRowStride, const GLubyte *pixdata,
+ GLint i, GLint j, GLvoid *texel);
+};
+fetch_2d_texel_rgb_dxt1_t *fetch_2d_texel_rgb_dxt1 = NULL;
+fetch_2d_texel_rgba_dxt1_t *fetch_2d_texel_rgba_dxt1 = NULL;
+fetch_2d_texel_rgba_dxt3_t *fetch_2d_texel_rgba_dxt3 = NULL;
+fetch_2d_texel_rgba_dxt5_t *fetch_2d_texel_rgba_dxt5 = NULL;
+inline bool load_libraries()
+{
+ void *l = dlopen("libtxc_dxtn.so", RTLD_NOW);
+ if(!l)
+ {
+ fprintf(stderr, "Cannot load library: %s\n", dlerror());
+ return false;
+ }
+ fetch_2d_texel_rgb_dxt1 = (fetch_2d_texel_rgb_dxt1_t *) dlsym(l, "fetch_2d_texel_rgb_dxt1");
+ fetch_2d_texel_rgba_dxt1 = (fetch_2d_texel_rgba_dxt1_t *) dlsym(l, "fetch_2d_texel_rgba_dxt1");
+ fetch_2d_texel_rgba_dxt3 = (fetch_2d_texel_rgba_dxt3_t *) dlsym(l, "fetch_2d_texel_rgba_dxt3");
+ fetch_2d_texel_rgba_dxt5 = (fetch_2d_texel_rgba_dxt5_t *) dlsym(l, "fetch_2d_texel_rgba_dxt5");
+ if(!fetch_2d_texel_rgb_dxt1 || !fetch_2d_texel_rgba_dxt1 || !fetch_2d_texel_rgba_dxt3 || !fetch_2d_texel_rgba_dxt5)
+ {
+ fprintf(stderr, "The selected libtxc_dxtn.so does not contain all required symbols.");
+ dlclose(l);
+ return false;
+ }
+ return true;
+}
+#else
extern "C"
{
#include "txc_dxtn.h"
};
+inline bool load_libraries()
+{
+ return true;
+}
+#endif
uint32_t LittleLong(uint32_t w)
{
void (*fetch)(GLint srcRowStride, const GLubyte *pixdata, GLint i, GLint j, GLvoid *texel) = NULL;
int blocksize;
+ if(!load_libraries())
+ return 1;
+
switch(fourcc)
{
case 0x31545844: