GLSL - named entry point

Currently the entry point for all GLSL shaders must be called "main". This can make shader management in your code something of a pain in the ass, as you can't just drop a bunch of related shaders into a single source file and have glCompileShader pick up the correct one without doing some fancy footwork to get around it.

So a simple proposal: glCompileShaderNamedEntryPoint (GLuint shader, const GLchar *entrypoint) to allow user-supplied named entry points. This is proposed for glCompileShader rather than glShaderSource as convenience can be had by specifying a single glShaderSource call followed by a bunch of glCompileShaderNamedEntryPoint calls, thereby allowing shader source to be read from and specified from a single file for multiple shaders. The orginal glCompileShader is functionally identical to glCompileShaderNamedEntryPoint (shader, "main").

This can make shader management in your code something of a pain in the ass, as you can't just drop a bunch of related shaders into a single source file and have glCompileShader pick up the correct one without doing some fancy footwork to get around it.

Code :

#define TheActualEntrypoint main

It's that simple. Just stick that string in front of the shader when you compile it. Odds are good that in any system based on putting a bunch of stuff in a single shader file that you're going to have specialized #defines anyway. So it's not like one more will be noticed.

It's that simple. Just stick that string in front of the shader when you compile it. Odds are good that in any system based on putting a bunch of stuff in a single shader file that you're going to have specialized #defines anyway. So it's not like one more will be noticed.

It's that simple. Just stick that string in front of the shader when you compile it.

You can add a #define, however, not as the first line of your shader (unless you are talking version 1.10). Section 3.3 of the GLSL specs state that "The #version directive must occur in a shader before anything else, except for comments and white space." - so, no #defines are allowed before that.