Jump to content
  • Advertisement
Sign in to follow this  
Solid_Spy

Any way to make shaders all share the same functions?

This topic is 1120 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am having a bit of a problem here.

 

My shaders are starting to get rather difficult to work with, because they are becomming too long.

 

I understand that glsl is a very low level language, and isn't compiled the same as C++ or Java, but is there a way I can get multiple shaders to share the same functions in a separate file, so that way I do not have to copy/paste the same functions over to each and every shader? It would also shorten the shaders, and make it easier to navigate.

 

I can use folding in notepad++, but it can still be very daunting.

Any Ideas on how to do this? Or is there just no way?

Edited by Solid_Spy

Share this post


Link to post
Share on other sites
Advertisement

glShaderSource:

void glShaderSource (GLuint shader,
  	GLsizei count,
  	const GLchar **string,
  	const GLint *length);

The existence of count and the fact that string is GLchar** gives you one way to make this happen.  For example:

GLchar *sharedSource = "....";
GLchar *source0 = "....";
GLchar *source1 = "....";

GLchar *sh0[2] = {sharedSource, source0};
GLchar *sh1[2] = {sharedSource, source1};

glShaderSource (shaderObject0, 2, sh0, NULL);
glShaderSource (shaderObject1, 2, sh1, NULL);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!