Sign in to follow this  

Any way to make shaders all share the same functions?

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


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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this