Replies: 3 comments
-
Actually, would loading the shader files at runtime be preferable? I was thinking 0 runtime impact would be best, but there's a point at which having more comprehensible builds could outweigh that need. [EDIT] I've come up with a solution to pre-process the shaders and convert them to C files in one go, so there's no need for intermediate files and everything can be concatenated into a single C file! #!/bin/sh
OUT=shaders.c
HEADER=shaders.h
ppflags="-E -P -x c"
cpp=cc
echo "#include \"$HEADER\"" >"$OUT"
while [ "$1" != "" ] ; do
if [ "$1" == "-f" ] ; then
shift
ppflags="$ppflags $1"
elif [ "$1" == "-c" ] ; then
shift
cc="$1"
else
shaderpath=$1
shaderfile=`basename "$shaderpath"`
shadername=`echo "glsl_$shaderfile" | sed 's/[ -.]/_/g'`
( $cpp $ppflags $shaderpath && head -c 1 /dev/zero )\
| xxd -i /dev/stdin\
| sed s/_dev_stdin/$shadername/\
>>"$OUT"
fi
shift
done Made to plug into the Makefiles with something like |
Beta Was this translation helpful? Give feedback.
-
Ack! Might be more involved than I had hoped, since shaders are constructed dynamically. So there is a reason there's both C preprocessor and GLSL preprocessor. Need some way of escaping the GLSL directives [EDIT] Okay, I did find a solution, replace the |
Beta Was this translation helpful? Give feedback.
-
I've got it working now 😄 just need to fix up the Makefiles |
Beta Was this translation helpful? Give feedback.
-
Hello @andrei-drexler, I tried reaching out to you via Discord, but I see you haven't been on since, and this is probably a better venue for the discussion. Basically I wanted to play around with the shader code in my own branch for funzies, but found the existing shader code unpleasant to work with. I just don't like the way the code is split into string literals glued together with macros, mixing of GLSL pre-processor directives with C pre-processor directives, etc.
Basically my planned method would be to split up the shaders into their own
.vert
/.frag
/.compute
files with shared code in their own.glsl
files that could be included by the shaders at build time. (Still working on a viableinclude
mechanism, thinking of exploitinggcc -E
currently.) Then I'd take the pre-processed shaders and generate source files viaxxd -i
which could then be built and linked.I wanted to know if you'd accept such changes in a PR, and if so if there's any requirements you have WRT build and runtime. So far as I can tell I can implement this with 0 impact on the runtime, and no additional build dependencies*.
Most significant cons I can see is more complicated build, including having to distinguish between human-written C files and generated C files, but the pros are easier-to-maintain shaders.
*MingW seems to cover all scripting needs via bash and Tcl
Beta Was this translation helpful? Give feedback.
All reactions