Results 1 to 3 of 3

Thread: Attaching shaders to multiple programs

  1. #1
    Member Contributor IneQuation.pl's Avatar
    Join Date
    Aug 2008
    Location
    Gliwice, Poland
    Posts
    69

    Attaching shaders to multiple programs

    Can one compiled shader be attached simultanously to a number of programs? Say, something like this:
    Code :
    glCompileShader(ID);
    glAttachShader(program1, ID);
    glLinkProgram(program1);
    glAttachShader(program2, ID);
    glLinkProgram(program2);
    And then just switching from one program to another on demand? I have a little library containing functions used in all the other shaders and having it compiled multiple times doesn't make much sense.

  2. #2
    Super Moderator Frequent Contributor imported_Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    937

    Re: Attaching shaders to multiple programs

    Yes you can. Actually you can even delete the shader after the program get compiled and link.

    There is no more good use for it after linking point
    [URL="http://www.g-truc.net"]G-Truc Creation[/URL] - [URL="http://glm.g-truc.net"]GLM[/URL] - [URL="http://samples.g-truc.net/"]OpenGL Samples Pack[/URL] - [URL="http://www.openglinsights.com"]OpenGL Insights[/URL]

  3. #3
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: Attaching shaders to multiple programs

    Yep, that's what specs say, but in real life things are different...

    glCompileShader does not really compile your shader. All shaders attached to a program are compiled and linked when you call glLinkProgram.

    Still, I do it exactly the way you described - if some program uses shader that I allready loaded, then I'll just attach it - no need to create new shader object.

    On GeForce, you can delete shader object after you linked your program object, but on Radeon, deleting shader object will damage all program objects that use it. So, no - you can't delete shader object after you linked your program.
    This information may not be up to date - perhaps AMD has fixed this issue allready, but then again - you may run into user that hasn't updated his drivers recently.

Similar Threads

  1. Shaders not attaching properly when linking.
    By SpacePotato in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-19-2018, 11:20 AM
  2. Generating pipelines, attaching shaders: working code anyone?
    By sam_thedancer in forum OpenGL: Basic Coding
    Replies: 12
    Last Post: 04-24-2013, 09:53 PM
  3. Replies: 4
    Last Post: 04-22-2013, 04:40 AM
  4. Shaders vs Programs
    By glfreak in forum OpenGL: Advanced Coding
    Replies: 11
    Last Post: 08-03-2004, 08:01 PM
  5. Texture shaders/programs
    By OrangyTang in forum OpenGL: General
    Replies: 2
    Last Post: 12-09-2002, 11:01 AM

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