View Full Version : Linking multiple shader objects

09-25-2008, 12:52 AM
The OpenGL ES 2.0 spec is a bit vague about glAttachShader, only saying it is the same as desktop OpenGL 2. So, reading the desktop OpenGL spec, I find in section 2.15.2:

Multiple shader objects of the same type may be attached to a single program object, and a single shader object may be attached to more than one program object.

So lets say I have two fragment shader objects with the following code:

Shader 1:

uniform mediump float opacity;
mediump vec3 getColor();
void main(void) {
gl_FragColor.rgb = getColor();
gl_FragColor.a = opacity;

Shader 2:

mediump vec3 getColor() {
return vec3(1.0, 1.0, 1.0);

I want to compile each of the shaders as seperate objects and combine them, together with a vertex shader, into a single program object. As far as I understand the spec, this should be possible. Have I missed something? I ask because on the PowerVR SGX, the second shader fails to compile as it doesn't have a main() function:

ERROR: main() function is missing.
ERROR: 1 compilation errors. No code generated.

How are you supposed to attach "Multiple shader objects of the same type" if they all need a main() function?

09-30-2008, 02:59 AM
The OpenGL ES 2.0 specification is actually very explicit about this (Section 2.10.3 in the full spec, or 2.15.3 in the diff spec):

Multiple shader objects of the same type may not be attached to a single program object.
Though it may have been less clear in an older spec revision.

09-14-2010, 09:09 PM
Yeah you're going to have to merge your pixel shader text together before using glAttachShader