*
!*/
-*CMakeFiles/
*__pycache__/
!*.gitignore
-!*CMakeLists.txt
+!*.sh
!*.c
!*.h
+++ /dev/null
-cmake_minimum_required(VERSION 3.5)
-
-project( convexer )
-
-set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} )
-
-add_subdirectory( cxr )
-add_subdirectory( nbvtf )
--- /dev/null
+#!/bin/bash
+
+# Compilers, and cache wrapper
+# ----------------------------
+C="gcc"
+CXX="g++"
+compiler_cache="ccache"
+
+# Autodetect ccache unavailible
+if ! [ -x "$( command -v $compiler_cache )" ]; then
+ compiler_cache=""
+fi
+
+# Platform specific
+# -----------------
+target_os_windows(){
+ exe_ext=".exe"
+ lib_ext=".dll"
+ compiler_prefix="i686-w64-mingw32-"
+ asan=""
+}
+
+target_os_gnu_linux(){
+ exe_ext=""
+ lib_ext=".so"
+ compiler_prefix=""
+
+ asan="-fsanitize=address"
+}
+
+compile(){
+ cmd="$compiler_prefix$@"
+
+ echo $cmd
+ $compiler_cache $cmd
+
+ if [ $? -ne 0 ]; then
+ error "Compile failed"
+ exit 1
+ fi
+}
+
+# Commandline arguments
+# ---------------------
+if [[ $1 == "windows" ]]; then
+ target_os_windows
+else
+ target_os_gnu_linux
+fi
+
+# Actual compiler commands
+# format:
+# <compiler> optimisation level, output type
+# warning flags
+# defines
+# include directories
+# input files
+# output file
+# library links
+
+mkdir -p nbvtf/obj
+compile $C -O1 -ggdb -fPIC -shared \
+ -Wall -Wno-unused-variable -Wno-unused-function -std=c99 -pedantic \
+ -DCXR_SO -DCXR_DEBUG -DCXR_VALVE_MAP_FILE \
+ -xc cxr/cxr.h \
+ -o libcxr$lib_ext \
+ -lm
+
+compile $CXX -O3 -c \
+ nbvtf/librgbcx.cpp \
+ -o nbvtf/obj/librgbcx.o
+
+compile $C -O3 -c \
+ -DUSE_LIBRGBCX \
+ -I./nbvtf/ \
+ nbvtf/vtf_cmd.c \
+ -o nbvtf/obj/tovtf.o
+
+compile $CXX -O3 -fPIC -c \
+ -DUSE_LIBRGBCX -DNBVTF_AS_SO \
+ -xc nbvtf/nbvtf.h \
+ -o nbvtf/obj/libnbvtf.o
+
+compile $CXX -O3 -shared \
+ nbvtf/obj/librgbcx.o nbvtf/obj/libnbvtf.o \
+ -o libnbvtf$lib_ext
+
+compile $C -O3 \
+ -Wno-unused-variable -Wno-unused-function $asan -Werror=vla \
+ nbvtf/obj/tovtf.o nbvtf/obj/librgbcx.o \
+ -o tovtf$exe_ext \
+ -lm
+
+# This is for testing with asan on linux
+# compile gcc -ggdb -O1 -Wall \
+# -Wno-unused-variable -Wno-unused-function $asan -Werror=vla \
+# cxr/test.c \
+# -o test$exe_ext \
+# -lm
+++ /dev/null
-project( cxr )
-
-add_library( ${PROJECT_NAME} SHARED
- cxr.c
- cxr.h
- cxr_math.h
- cxr_mem.h
-)
-
-target_compile_definitions( ${PROJECT_NAME}
- PRIVATE CXR_SO CXR_DEBUG CXR_VALVE_MAP_FILE
-)
-
-target_compile_options( ${PROJECT_NAME}
- PRIVATE -Wall -Wno-unused-variable -Wno-unused-function
- -std=c99 -pedantic
-)
-
-target_link_libraries( ${PROJECT_NAME} m )
--- /dev/null
+mkdir win32_dist
+cp *.dll win32_dist/
+cp *.py win32_dist/
+zip -r convexer-win32.zip win32_dist/
+rm -r win32_dist
+++ /dev/null
-project( nbvtf )
-
-# RGBCX C++ -> C Wrapper object
-add_library( rgbcx OBJECT librgbcx.cpp )
-
-# NBVTF C object
-add_library( onbvtf OBJECT nbvtf.c )
-target_compile_definitions( onbvtf PRIVATE USE_LIBRGBCX )
-set_property( TARGET onbvtf PROPERTY POSITION_INDEPENDENT_CODE ON )
-
-# NBVTF Shared object
-add_library( ${PROJECT_NAME} SHARED )
-target_link_libraries( ${PROJECT_NAME} PRIVATE rgbcx onbvtf )
-
-target_compile_options( ${PROJECT_NAME}
- PRIVATE -Wall -Wno-unused-variable -Wno-unused-function
- -std=c99 -pedantic
-)
-
-# Extra tools
-add_library( otovtf OBJECT vtf_cmd.c nbvtf.h )
-target_compile_definitions( otovtf PRIVATE USE_LIBRGBCX )
-add_executable( tovtf )
-target_link_libraries( tovtf PRIVATE rgbcx otovtf )
-
-add_library( otodds OBJECT dds_cmd.c nbvtf.h )
-target_compile_definitions( otodds PRIVATE USE_LIBRGBCX )
-add_executable( todds )
-target_link_libraries( todds PRIVATE rgbcx otodds )
+++ /dev/null
-#define NBVTF_AS_SO
-#include "nbvtf.h"
#define STB_IMAGE_IMPLEMENTATION
#endif
+#define STBI_NO_THREAD_LOCALS
#include "stb/stb_image.h"
#ifdef USE_LIBRGBCX
+ // #define RGBCX_NO_ALGORITHM
#include "librgbcx.h"
-#else
+ #define HAS_DXT_COMPRESSOR
+#endif
+
+#if USE_STB_DXT
#define STB_DXT_IMPLEMENTATION
#include "stb/stb_dxt.h"
+ #define HAS_DXT_COMPRESSOR
+#endif
+
+#ifndef HAS_DXT_COMPRESSOR
+ #warning No DXT compressor specified! S3 Output will be invalid.
#endif
#ifdef NBVTF_SHOW_STDERR
{
rgbcx__encode_bc1( qual, dest, src, 0, 0 );
}
-#else
+#endif
+
+#if USE_STB_DXT
stb_compress_dxt_block( dest, src, alpha, STB_DXT_HIGHQUAL );
#endif
+
+#ifndef HAS_DXT_COMPRESSOR
+
+ for( int i=0; i<alpha? 16: 8; i++ )
+ dest[i] = i%1? 0xff: 0x00;
+#endif
}
void nbvtf_compress_dxt( uint8_t *src, int w, int h, int alpha, int qual,
#include <stdlib.h>
#include <stdint.h>
-#include <algorithm>
#include <assert.h>
+
+#ifndef RGBCX_NO_ALGORITHM
+ #include <algorithm>
+#else
+int std_sort_int (const void * a, const void * b)
+{
+ return ( *(int*)a - *(int*)b );
+}
+#endif
+
#include <limits.h>
// By default, the table used to accelerate cluster fit on 4 color blocks uses a 969x128 entry table.
dots[i] = (d << 4) + i;
}
- std::sort(dots, dots + 16);
+#ifdef RGBCX_NO_ALGORITHM
+ qsort( dots, 16, sizeof(int), std_sort_int );
+#else
+ std::sort(dots, dots + 16);
+#endif
uint32_t r_sum[17], g_sum[17], b_sum[17];
uint32_t r = 0, g = 0, b = 0;
assert(d >= 0);
dots[i] = (d << 4) + i;
}
+
+#ifdef RGBCX_NO_ALGORITHM
+ qsort( dots, 16, sizeof(int), std_sort_int );
+#else
+ std::sort(dots, dots + 16);
+#endif
- std::sort(dots, dots + 16);
-
uint32_t r_sum[17], g_sum[17], b_sum[17];
uint32_t r = 0, g = 0, b = 0;
for (uint32_t i = 0; i < 16; i++)