PDA

View Full Version : Proper way of handling multiple shaders



XxOsurfer3xX
11-05-2013, 10:29 AM
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?

Dark Photon
11-05-2013, 05:11 PM
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.

XxOsurfer3xX
11-06-2013, 12:22 AM
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?

GClements
11-06-2013, 05:07 AM
I'm interested in what you said about caching precompiled shader binaries, could you elaborate more?
In OpenGL 4, you can use glGetProgramBinary (http://www.opengl.org/sdk/docs/man4/xhtml/glGetProgramBinary.xml) to retrieve the object code for a program, and glProgramBinary (http://www.opengl.org/sdk/docs/man4/xhtml/glProgramBinary.xml) to create a program from object code.

Kopelrativ
11-08-2013, 02:05 PM
I found GLSW (http://www.geeks3d.com/20100503/glsw-opengl-shader-wrangler-to-play-with-glsl-programs-with-ease/), a OpenGL shader wrangler. It helped me a lot of organize the shaders when they got a little more complex.

XxOsurfer3xX
11-11-2013, 02:10 AM
Thanks for all the answers! GLSW looks sweet, decissions, decissions...