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: GLSL - named entry point

  1. #1
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,212

    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").

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    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.

    Plus, this will work with glCreateShaderProgramv, whereas your version needs two new functions.

    This is not something that needs to be a feature.

  3. #3
    Member Regular Contributor
    Join Date
    Mar 2007
    Location
    CA
    Posts
    408
    The trick with using a #define directive is good and I should try that.

    Another option that I have been using is GL shader wrangler: http://prideout.net/blog/?p=11 .

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,212
    Quote Originally Posted by Alfonse Reinheart View Post
    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.

    Plus, this will work with glCreateShaderProgramv, whereas your version needs two new functions.
    Except it doesn't work with current AMD drivers. Oh, it works OK if there's only one faked "main" function in the file, but as soon as you put 2 or more in, it breaks.

    Quote Originally Posted by Alfonse Reinheart View Post
    This is not something that needs to be a feature.
    It would be a well-specified part of the API that is required to be supported. Who cares if it needs an extra entry point?

  5. #5
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    Except it doesn't work with current AMD drivers. Oh, it works OK if there's only one faked "main" function in the file, but as soon as you put 2 or more in, it breaks.
    Then that's something that should be taken up with AMD. What kind of error do you get when that happens?

    We shouldn't create features based on driver bugs.

  6. #6
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    325
    Quote Originally Posted by Alfonse Reinheart View Post
    Code :
    #define TheActualEntrypoint main

    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.

    Using OpenGL 4.x, shader subroutines might be an alternative:

    Code :
     
    subroutine uniform myMain MyMain;       
     
    subroutine(myMain)
    void main1() {...}
     
    subroutine(myMain)
    void main2() {...}
     
    void main() {
        MyMain();
    }

Posting Permissions

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