From: hgn Date: Thu, 28 Apr 2022 22:19:38 +0000 (+0100) Subject: switch to shell scripts X-Git-Url: https://skaterift.com/git/?p=convexer.git;a=commitdiff_plain;h=12102f7b89f21fe5148e9a4506f505fcaef98da2 switch to shell scripts --- diff --git a/.gitignore b/.gitignore index 9c351f9..0af4364 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,10 @@ * !*/ -*CMakeFiles/ *__pycache__/ !*.gitignore -!*CMakeLists.txt +!*.sh !*.c !*.h diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 24260da..0000000 --- a/CMakeLists.txt +++ /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 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: +# 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 index eb0455f..0000000 --- a/cxr/CMakeLists.txt +++ /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 index 0000000..3779646 --- /dev/null +++ b/makedist.sh @@ -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 index 8b3eb41..0000000 --- a/nbvtf/CMakeLists.txt +++ /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 index 2485679..0000000 --- a/nbvtf/nbvtf.c +++ /dev/null @@ -1,2 +0,0 @@ -#define NBVTF_AS_SO -#include "nbvtf.h" diff --git a/nbvtf/nbvtf.h b/nbvtf/nbvtf.h index 6be4714..aa82cbf 100644 --- a/nbvtf/nbvtf.h +++ b/nbvtf/nbvtf.h @@ -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 #include -#include #include + +#ifndef RGBCX_NO_ALGORITHM + #include +#else +int std_sort_int (const void * a, const void * b) +{ + return ( *(int*)a - *(int*)b ); +} +#endif + #include // 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++)