I have a custom solution based on http://blackpixel.com/blog/494/xcode-using-includes-in-opengl-shaders/ [404 now]. Basically it said that you can use m4 tool to preprocess the files.
In the GLSL source files just include the desired fragment you want to reuse:
include(Utils.glsl)
include(Colors.glsl)
...
void main (void) {
...
}
In Xcode, add all glsl
files to “Copy Bundle Resources”.
Add a “Run Script” phase with this shell script:
#!/bin/sh
cd ${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}
find . -name "*.fsh" | while read file; do
echo Preprocess $file
m4 "$file" > "$file.tmp"
mv "$file.tmp" "$file"
done
exit 0
The script assumes your shaders have .fsh
extension. It’s trivial to modify it to match your shader extensions.
Be warned: your shaders will be easily accessible to almost anyone. You may use it for development and convert them to strings before releasing them (not a real protection unless you encrypt it...).
Also, if there is no much sharing between shaders, you'll end up with a lot of unused code. I guess the shader compiler will take care of it but I'm not 100% sure if there is some performance penalty.