• Advertisement
Sign in to follow this  

Any way to make shaders all share the same functions?

This topic is 939 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