basically i select the fragment shader chunks at runtime and call glAttachShader (which as far as i know concats them together).
Then in my "main" fragment shader i declare the methods from the other chunks, and use them in the body of main().
This works quite well on desktop, and should be supported by the OpenGL ES GLSL 1.00 spec i think?
here is an example...
diffuse_texture.frag
Code: Select all
uniform vec4 diffuseColor;
uniform sampler2D diffuseTexture;
varying vec2 oTexCoords;
vec4 apply_diffuse() {
vec4 dTexColor = texture2D(diffuseTexture, oTexCoords);
return vec4(0.0,0.0,0.0,1.0);
}
Code: Select all
vec4 apply_diffuse();
uniform mat4 viewProjectionMatrix;
uniform mat4 worldMatrix;
uniform vec3 ambientColor;
void main()
{
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
vec4 diffuse = apply_diffuse();
vec3 rez = (ambientColor) * diffuse.xyz;
gl_FragColor = vec4(clamp(rez, 0.0, 1.0) , diffuse.a);
}
I thought that maybe since compiling shaders on Pi is deferred to link time that my scope is different and therefore it thinks i'm redifining?
-J