Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Proper way of handling multiple shaders

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2013
    Posts
    5

    Proper way of handling multiple shaders

    I have an application with multiple shaders, that right now I am loading from files (ie basic.vs basic.fs). I was wondering what is the best way to handle shaders. External files or embedded in the source code? I'm trying to use CMake to compile my app, and I don't want to include the shaders in the same folder as the executable. Do I have to tell CMake where the sahders are? Is there a way to load the shaders code from file on c++ compilation?

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,183
    Quote Originally Posted by XxOsurfer3xX View Post
    I have an application with multiple shaders, that right now I am loading from files (ie basic.vs basic.fs). I was wondering what is the best way to handle shaders. External files or embedded in the source code? I'm trying to use CMake to compile my app, and I don't want to include the shaders in the same folder as the executable. Do I have to tell CMake where the sahders are? Is there a way to load the shaders code from file on c++ compilation?
    Best depends on your needs. You can do any of what you describe. You can also cache off precompiled shader binaries so that further runs on the same GPU/driver are fast.

    CMake is an ancillary issue not directly related to your question.

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2013
    Posts
    5
    Quote Originally Posted by Dark Photon View Post
    Best depends on your needs. You can do any of what you describe. You can also cache off precompiled shader binaries so that further runs on the same GPU/driver are fast.

    CMake is an ancillary issue not directly related to your question.
    Thanks for the answer.

    I'm interested in what you said about caching precompiled shader binaries, could you elaborate more?

  4. #4
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    Quote Originally Posted by XxOsurfer3xX View Post
    I'm interested in what you said about caching precompiled shader binaries, could you elaborate more?
    In OpenGL 4, you can use glGetProgramBinary to retrieve the object code for a program, and glProgramBinary to create a program from object code.

  5. #5
    Junior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    214
    I found GLSW, a OpenGL shader wrangler. It helped me a lot of organize the shaders when they got a little more complex.

  6. #6
    Junior Member Newbie
    Join Date
    Sep 2013
    Posts
    5
    Thanks for all the answers! GLSW looks sweet, decissions, decissions...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •