Skip to content

Commit 3b94911

Browse files
committed
[shaders] update compile_shaders
move compile_shaders to scripts
1 parent b157e9c commit 3b94911

File tree

4 files changed

+70
-19
lines changed

4 files changed

+70
-19
lines changed

modules/le_2d/shaders/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# To compile shaders in this directory, issue the following command:
2+
3+
4+
../../../scripts/compile_shaders.sh .

modules/le_imgui/shaders/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# To compile shaders in this directory, issue the following command:
2+
3+
4+
../../../scripts/compile_shaders.sh .

modules/le_imgui/shaders/compile_shaders.sh

Lines changed: 0 additions & 19 deletions
This file was deleted.

scripts/compile_shaders.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
3+
# This script will compile shaders from glsl source to spir-v,
4+
# and will autogenerate a .h file with embedded spir-v code for
5+
# each source shader file.
6+
7+
INVOCATION_DIR=$(realpath "$PWD")
8+
WORKING_DIR="$INVOCATION_DIR"
9+
10+
if [ "$1" ]; then
11+
# echo "Parameter given: '$1'"
12+
if [[ -d "${WORKING_DIR}/$1" ]]; then
13+
# echo "parameter names a directory"
14+
WORKING_DIR="${WORKING_DIR}/$1"
15+
elif [[ -f "${WORKING_DIR}/$1" ]]; then
16+
# echo "parameter does name a file"
17+
TARGET_FILE="${WORKING_DIR}/$1"
18+
WORKING_DIR=$(dirname "$TARGET_FILE")
19+
else
20+
echo "File or directory not found: '$1'"
21+
exit 1
22+
fi
23+
fi
24+
25+
WORKING_DIR=$(realpath "${WORKING_DIR}")
26+
27+
cd "$WORKING_DIR" || exit 1
28+
29+
# echo "working dir set to: '$WORKING_DIR'"
30+
# echo "target file set to $TARGET_FILE"
31+
32+
######################################################################
33+
# Generates .h files holding SPIR-V (encoded as uint32_t array)
34+
# from .vert/.frag/.comp glsl code.
35+
######################################################################
36+
if [[ -e "$TARGET_FILE" ]]; then
37+
# echo "target file exists"
38+
FILES="$TARGET_FILE"
39+
else
40+
FILES=$(find "$WORKING_DIR" \
41+
-name "*.vert" \
42+
-o -name "*.frag" \
43+
-o -name "*.comp" \
44+
)
45+
fi
46+
47+
for FILE in $FILES; do
48+
49+
# In case there is no match, $FILE may still contain something like "*.comp"
50+
# in which case we want to skip this iteration of the loop.
51+
if [ ! -e "$FILE" ]; then
52+
continue
53+
fi
54+
55+
FILENAME=$(basename "${FILE%.*}_${FILE#*.}")
56+
VARNAME=$(echo "SPIRV_SOURCE_${FILENAME}" | tr '[:lower:]' '[:upper:]')
57+
58+
echo "$FILE${FILENAME}.h"
59+
glslang --quiet -o "${FILENAME}.h" -V --vn "$VARNAME" "$FILE"
60+
done
61+
62+
cd "$INVOCATION_DIR" || exit 1

0 commit comments

Comments
 (0)