Entry-Points

Hi.

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?

Jonas

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.

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

"void foo( void ) { /* ... */ } void bar( void ) { / * ... */ } void foobar( void ) { / * ... */ }
"

To select the main entry point use the preprocessor and the first string passed.

"#define foo main
" or "#define bar main
"

To load your shader strings, you call

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

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.