Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Entry-Points

  1. #1
    Intern Newbie
    Join Date
    Nov 2002



    Is it somehow possible to have multiple entry points in a single shader?

    CG has the feature, and it is very convenient, to keep several shaders related to the same effect in one file. I have not been able to find any documentation on how to do it?


  2. #2
    Senior Member OpenGL Guru
    Join Date
    Mar 2001

    Re: Entry-Points

    What you want can be done in a different way in glslang. A cleaner way.

    A compiled shader is like a .o file. It doesn't need to have a main() in it. It can just have some common functions. At link-time, (program building), you can link together multiple compiled shaders, one of which has a main() function. So, effectively, you can have a few shader files that you use as libraries that you link into the final program building section.

  3. #3
    Intern Contributor
    Join Date
    Sep 2001
    Marlboro MA

    Re: Entry-Points

    First, Korval is exactly right. All "main()" vertex or fragment shaders can be compiled as separate shader objects. You attach whichever main shader object you wish to a program object, and then link. The disadvantage is that requires the application to split up the "single text file" into multiple parts.

    Another approach is to pass your "single text file" as the *second* string to glShaderSourceARB. (Remember, it takes an array of pointers to strings.) Let's say your "single text file" contains the string

    Code :
    "void foo( void ) { /* ... */ } void bar( void ) { / * ... */ } void foobar( void ) { / * ... */ }\n"
    To select the main entry point use the preprocessor and the first string passed.
    Code :
    "#define foo main\n" or "#define bar main\n"
    To load your shader strings, you call
    Code :
    glShaderSourceARB( shader, [B]2[/B], &strings, NULL );
    If you choose this approach, the disadvantage is you'll be compiling the "same" source multiple times.

    -mr. bill

    [This message has been edited by mrbill (edited 03-10-2004).]

Posting Permissions

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