Since GLSL does not have an include-file option, I am trying to add this using the "#pragma include" parser. (I want this because I have some common methods that I would like to implement only once, but can use them in many different shaders, such as Ken Perlin smootherstep)
Parsing shader files to get included files works great. But when setting up a ShaderSource with multiple source files, I always run into problems; since my main shader usually starts with "#version 330", and the line # version should always be the first line in the shader, I can only add my main file as the first line in the array passed to glShadersource, and after that everything included files. But then my main file cannot use any functions implemented in these included files, since they will essentially be merged after my main file, so the compiler complains that it does not know the functions that my main file uses.
The only way I can get it to work is to read the main file, analyze the inclusion pragma, and then replace this pragmatic line with the contents of the file that will be included (recursively applying the same method to all included files, which may include others files), but this will mean that lineers in compilation errors will no longer correspond to the actual sizes of the tapes of the main file.
Has anyone set up some kind of "included" functionality for GLSL that works AND supports lines? And if so - how?
source
share