switch to shell scripts
authorhgn <hgodden00@gmail.com>
Thu, 28 Apr 2022 22:19:38 +0000 (23:19 +0100)
committerhgn <hgodden00@gmail.com>
Thu, 28 Apr 2022 22:19:38 +0000 (23:19 +0100)
.gitignore
CMakeLists.txt [deleted file]
build.sh [new file with mode: 0755]
cxr/CMakeLists.txt [deleted file]
makedist.sh [new file with mode: 0755]
nbvtf/CMakeLists.txt [deleted file]
nbvtf/nbvtf.c [deleted file]
nbvtf/nbvtf.h
nbvtf/rgbcx.h

index 9c351f9a37b92386db15145f92bdd81093674563..0af43647fdb1fff7692b57a5db6905fabc96268b 100644 (file)
@@ -1,11 +1,10 @@
 *
 
 !*/
-*CMakeFiles/
 *__pycache__/
 
 !*.gitignore
-!*CMakeLists.txt
+!*.sh
 
 !*.c
 !*.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
deleted file mode 100644 (file)
index 24260da..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-cmake_minimum_required(VERSION 3.5)
-
-project( convexer )
-
-set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} )
-
-add_subdirectory( cxr )
-add_subdirectory( nbvtf )
diff --git a/build.sh b/build.sh
new file mode 100755 (executable)
index 0000000..cee4b10
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,99 @@
+#!/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 
diff --git a/cxr/CMakeLists.txt b/cxr/CMakeLists.txt
deleted file mode 100644 (file)
index eb0455f..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-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 )
diff --git a/makedist.sh b/makedist.sh
new file mode 100755 (executable)
index 0000000..3779646
--- /dev/null
@@ -0,0 +1,5 @@
+mkdir win32_dist
+cp *.dll win32_dist/
+cp *.py win32_dist/
+zip -r convexer-win32.zip win32_dist/
+rm -r win32_dist
diff --git a/nbvtf/CMakeLists.txt b/nbvtf/CMakeLists.txt
deleted file mode 100644 (file)
index 8b3eb41..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-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 )
diff --git a/nbvtf/nbvtf.c b/nbvtf/nbvtf.c
deleted file mode 100644 (file)
index 2485679..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#define NBVTF_AS_SO
-#include "nbvtf.h"
index 6be4714ed99a26c0d340898bce37986c9abc4851..aa82cbf6a302823416a011f99a956e89e0f43383 100644 (file)
@@ -59,13 +59,23 @@ extern "C" {
  #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
@@ -541,9 +551,17 @@ void nbvtf_dxt_block( uint8_t *dest, uint8_t *src, int alpha, int qual )
        {
                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,
index dd199b781471d6ce432b798b9549048d0e332454..620441b3fc7c98b678a5c355e0223aad8091ef5e 100644 (file)
 
 #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. 
@@ -2818,7 +2827,11 @@ namespace rgbcx
                                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;
@@ -3716,9 +3729,13 @@ namespace rgbcx
                                        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++)