diff --git a/contrib/single_file_transcoder/.gitignore b/contrib/single_file_transcoder/.gitignore index b16a751..59d6462 100644 --- a/contrib/single_file_transcoder/.gitignore +++ b/contrib/single_file_transcoder/.gitignore @@ -1,2 +1,2 @@ -# Don't commit the generated lib -basisutranslib.cpp +# Don't commit the generated files +basisu_transcoder.* diff --git a/contrib/single_file_transcoder/README.md b/contrib/single_file_transcoder/README.md index 9923dd6..c8af8da 100644 --- a/contrib/single_file_transcoder/README.md +++ b/contrib/single_file_transcoder/README.md @@ -2,18 +2,27 @@ The script `combine.sh` creates an _amalgamated_ C++ source file that can be used with or without `basisu_transcoder.h`. This _isn't_ a header-only file but it does offer a similar level of simplicity when integrating into a project. -Create `basisutranslib.cpp` from the transcoder source using: +Create `basisu_transcoder.cpp` from the transcoder sources using: ``` cd basis_universal/contrib/single_file_transcoder -./combine.sh -r ../../transcoder -o basisutranslib.cpp basisutranslib-in.cpp + +./combine.sh -r ../../transcoder -o basisu_transcoder.cpp basisu_transcoder-in.cpp ``` Then add the resulting file to your project (see the [example files](examples)). -If certain features will _never__ be enabled, e.g. `BASISD_SUPPORT_BC7_MODE6_OPAQUE_ONLY`, then `combine.sh` can be told to exclude files completely: +If certain features will _never__ be enabled, e.g. `BASISD_SUPPORT_BC7_MODE6_OPAQUE_ONLY`, then `combine.sh` can be told to exclude files with the `-x` option: ``` -./combine.sh -r ../../transcoder -x basisu_transcoder_tables_bc7_m6.inc -o basisutranslib.cpp basisutranslib-in.cpp +./combine.sh -r ../../transcoder -x basisu_transcoder_tables_bc7_m6.inc -o basisu_transcoder.cpp basisu_transcoder-in.cpp +``` +Excluding the BC7 mode 6 support reduces the generated source by 1.2MB, which is the choice taken in `basisu_transcoder-in.cpp` and used in the examples, with `create_transcoder.sh` running the above script, creating the final `basisu_transcoder.cpp`. + +The combiner script can also generate separate amalgamated header and source files, using the `-k` option to keep the specified inline directive: +``` +./combine.sh -r ../../transcoder -o basisu_transcoder.h ../../transcoder/basisu_transcoder.h + +./combine.sh -r ../../transcoder -x basisu_transcoder_tables_bc7_m6.inc -k basisu_transcoder.h -o basisu_transcoder.cpp basisu_transcoder-in.cpp + ``` -Excluding the BC7 mode 6 support reduces the generated source by 1.2MB, which is the choice taken in both `basisutranslib-in.cpp` and `create_translib.sh`, will run the above script, creating the final `basisutranslib.cpp`. Note: the amalgamation script will run on pretty much anything but is _extremely_ slow on Windows with the `bash` included with Git. diff --git a/contrib/single_file_transcoder/basisutranslib-in.cpp b/contrib/single_file_transcoder/basisu_transcoder-in.cpp similarity index 97% rename from contrib/single_file_transcoder/basisutranslib-in.cpp rename to contrib/single_file_transcoder/basisu_transcoder-in.cpp index 43fe0fd..67140e2 100644 --- a/contrib/single_file_transcoder/basisutranslib-in.cpp +++ b/contrib/single_file_transcoder/basisu_transcoder-in.cpp @@ -1,7 +1,7 @@ /** * Basis Universal single file library. Generated using: * \code - * ./combine.sh -r ../../transcoder -x basisu_transcoder_tables_bc7_m6.inc -o basisutranslib.cpp basisutranslib-in.cpp + * ./combine.sh -r ../../transcoder -x basisu_transcoder_tables_bc7_m6.inc -o basisu_transcoder.cpp basisu_transcoder-in.cpp * \endcode * * \note The script above excludes the BC7 mode 6 tables, a choice reflected in diff --git a/contrib/single_file_transcoder/combine.sh b/contrib/single_file_transcoder/combine.sh index 86ceac9..0a59391 100755 --- a/contrib/single_file_transcoder/combine.sh +++ b/contrib/single_file_transcoder/combine.sh @@ -10,7 +10,7 @@ # Script released under a CC0 license. # Common file roots -ROOTS="./" +ROOTS="." # -x option excluded includes XINCS="" @@ -65,16 +65,16 @@ write_line() { add_file() { # Match the path local file= - if [ -f "$1" ]; then - file="$1" - else - for root in $ROOTS; do - if test -f "$root/$1"; then - file="$root/$1" - fi - done - fi + for root in $ROOTS; do + if [ -f "$root/$1" ]; then + file="$root/$1" + fi + done if [ -n "$file" ]; then + if [ -n "$DESTN" ]; then + # Log but only if not writing to stdout + echo "Processing: $file" + fi # Read the file local line= while IFS= read -r line; do @@ -117,13 +117,13 @@ add_file() { while getopts ":r:x:k:o:" opts; do case $opts in r) - ROOTS="$OPTARG $ROOTS" + ROOTS="$ROOTS $OPTARG" ;; x) - XINCS="$OPTARG $XINCS" + XINCS="$XINCS $OPTARG" ;; k) - KINCS="$OPTARG $KINCS" + KINCS="$KINCS $OPTARG" ;; o) DESTN="$OPTARG" diff --git a/contrib/single_file_transcoder/create_translib.sh b/contrib/single_file_transcoder/create_transcoder.sh similarity index 65% rename from contrib/single_file_transcoder/create_translib.sh rename to contrib/single_file_transcoder/create_transcoder.sh index f20daf3..51e7383 100755 --- a/contrib/single_file_transcoder/create_translib.sh +++ b/contrib/single_file_transcoder/create_transcoder.sh @@ -2,7 +2,7 @@ echo "Amalgamating files... this can take a while" echo "Note: basisu_transcoder_tables_bc7_m6.inc is excluded" -./combine.sh -r "../../transcoder" -x basisu_transcoder_tables_bc7_m6.inc -o basisutranslib.cpp basisutranslib-in.cpp +./combine.sh -r ../../transcoder -x basisu_transcoder_tables_bc7_m6.inc -o -o basisu_transcoder.cpp basisu_transcoder-in.cpp # Did combining work? if [ $? -ne 0 ]; then echo "Combine script: FAILED" diff --git a/contrib/single_file_transcoder/examples/README.md b/contrib/single_file_transcoder/examples/README.md index c27901f..b862eee 100644 --- a/contrib/single_file_transcoder/examples/README.md +++ b/contrib/single_file_transcoder/examples/README.md @@ -1,6 +1,6 @@ # Single File Basis Universal Examples -The examples `#include` the generated `basisutranslib.cpp` directly but work equally as well when including `basisu_transcoder.h` and compiling the amalgamated source separately. +The examples `#include` the generated `basisu_transcoder.cpp` directly but work equally as well when including `basisu_transcoder.h` and compiling the amalgamated source separately. `emscripten.cpp` is a bare-bones [Emscripten](https://github.com/emscripten-core/emscripten) compiled WebGL demo picking the best transcoder format for the sample texture (see the [original PNG image](testcard.png)). diff --git a/contrib/single_file_transcoder/examples/emscripten.cpp b/contrib/single_file_transcoder/examples/emscripten.cpp index eaf519c..5d7dddf 100644 --- a/contrib/single_file_transcoder/examples/emscripten.cpp +++ b/contrib/single_file_transcoder/examples/emscripten.cpp @@ -1,7 +1,7 @@ /** * \file emscripten.cpp - * Emscripten example of using the single-file \c basisutranslib. Draws a - * rotating textured quad with data from the in-line compressed textures. + * Emscripten example of using the single-file \c basisu_transcoder.cpp. Draws + * a rotating textured quad with data from the in-line compressed textures. * \n * Compile using: * \code @@ -9,13 +9,14 @@ * export EM_FLAGS="-s ENVIRONMENT=web -s WASM=1 --shell-file shell.html --closure 1" * emcc $CC_FLAGS $EM_FLAGS -o out.html emscripten.cpp * \endcode - * Alternatively include \c basisu_transcoder.h and build \c basisutranslib - * separately (the resulting binary is exactly the same size): + * Alternatively include \c basisu_transcoder.h and compile \c + * basisu_transcoder.cpp separately (the resulting binary is exactly the same + * size): * \code - * emcc $CC_FLAGS $EM_FLAGS -o out.html ../basisutranslib.cpp emscripten.cpp + * emcc $CC_FLAGS $EM_FLAGS -o out.html ../basisu_transcoder.cpp emscripten.cpp * \encode * To determine the WebAssembly size without the transcoder comment the \c - * basisutranslib.cpp include (which stubs the texture creation). + * basisu_transcoder.cpp include (which stubs the texture creation). * \n * Example code released under a CC0 license. */ @@ -29,7 +30,7 @@ #include #include -#include "../basisutranslib.cpp" +#include "../basisu_transcoder.cpp" //********************************* Test Data ********************************/