joessu
Posts: 2
Joined: Mon May 13, 2013 9:52 pm

glAttachShader with multiple shader methods not compiling?

Wed May 15, 2013 9:52 pm

I have a very simple setup of using multiple shaders to implement multi mode.

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); 
}
and here is the main frag that uses it.

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);
}
is this supported?
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

lb
Posts: 263
Joined: Sat Jan 28, 2012 8:07 pm

Re: glAttachShader with multiple shader methods not compilin

Fri May 17, 2013 2:15 pm

joessu wrote:I have a very simple setup of using multiple shaders to implement multi mode.

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?
No, this is not how glAttachShader works in GLES2. You can only attach one object per object type (documented here). This was likely done to simplify shader compilation.

Return to “OpenGLES”