forked from codam-coding-college/MLX42
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile_shader.sh
executable file
·44 lines (40 loc) · 1.32 KB
/
compile_shader.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# -----------------------------------------------------------------------------
# Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard.
# See README in the root project for more information.
# -----------------------------------------------------------------------------
# If no arguments have been given, exit with error code 1
if [ "$#" -ne 1 ]; then
echo "ERROR: missing arguments, use as follows: $0 <ShaderFile>" 1>&2
exit 1
fi
# If file cannot be found, exit with error code 2
if [ ! -f "$1" ]; then
echo "ERROR: shader file not found: $1" 1>&2
exit 2
fi
SHADERTYPE="${1##*.}"
echo "// -----------------------------------------------------------------------------"
echo "// Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard. "
echo "// See README in the root project for more information. "
echo "// -----------------------------------------------------------------------------"
echo ""
echo "// If you wish to modify this file edit the .vert or .frag file!"
echo ""
echo "#include \"MLX42/MLX42_Int.h\""
echo ""
echo "const char* ${SHADERTYPE}_shader = \"$(sed -n '1{p;q;}' "$1")\\n\""
{
# Skip over first line
read
while IFS= read -r LINE; do
if [ ! "${LINE}" = "" ]; then
if [ "${LINE}" = "}" ]; then
echo " \"${LINE}\";"
else
echo " \"${LINE}\""
fi
fi
done
} < "$1"
exit 0