Results 1 to 3 of 3

Thread: Linking multiple shader objects

  1. #1
    Junior Member
    Join Date
    May 2008

    Linking multiple shader objects

    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:
    Code :
    uniform mediump float opacity;
    mediump vec3 getColor();
    void main(void) {
       gl_FragColor.rgb = getColor();
       gl_FragColor.a = opacity;

    Shader 2:
    Code :
    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?

  2. #2
    Senior Member
    Join Date
    May 2006

    Re: Linking multiple shader objects

    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.
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum |

  3. #3
    Junior Member
    Join Date
    Sep 2010

    Re: Linking multiple shader objects

    Yeah you're going to have to merge your pixel shader text together before using glAttachShader

Similar Threads

  1. Replies: 1
    Last Post: 09-14-2010, 09:02 PM
  2. Multiple objects
    By whreckz in forum OpenGL ES
    Replies: 0
    Last Post: 05-27-2008, 11:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean