Generated file is now basisu_transcoder.cpp

Renamed the generated file to be the same as the non-amalgamated file, updating the script (and docs) accordinly. Added an example of generated amalgamated header and source.
This commit is contained in:
Carl Woffenden
2019-10-01 15:56:59 +02:00
parent a5c36a5291
commit c04d24dd12
7 changed files with 40 additions and 30 deletions

View File

@@ -1,2 +1,2 @@
# Don't commit the generated lib
basisutranslib.cpp
# Don't commit the generated files
basisu_transcoder.*

View File

@@ -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.

View File

@@ -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

View File

@@ -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"

View File

@@ -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"

View File

@@ -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)).

View File

@@ -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 <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include "../basisutranslib.cpp"
#include "../basisu_transcoder.cpp"
//********************************* Test Data ********************************/