GLSL Linking and Compiling

Started by
6 comments, last by Code-R 18 years, 6 months ago
I was wondering if GLSL linking/compiling works just as C/C++ and OBJ files. I was specifically wondering if I can compile MyShader, which has a main() and a prototype for vec3 foo(float); then compile foo() separately, then link both? will that save me compile time if I have a changing main() that's generated/compiled dynamically, that calls foo() or bar() depending on the situation? TIA
Advertisement
bump
Heh... Not quite how the system works. You use a library called GLEW to check for vertex and fragment shaders, and if they work, then you load the shader code and compile them runetime.
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
Clicky

void setShaders() {			char *vs,*fs;			v = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);		f = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);				vs = textFileRead("toon.vert");		fs = textFileRead("toon.frag");			const char * vv = vs;		const char * ff = fs;			glShaderSourceARB(v, 1, &vv,NULL);		glShaderSourceARB(f, 1, &ff,NULL);			free(vs);free(fs);			glCompileShaderARB(v);		glCompileShaderARB(f);			p = glCreateProgramObjectARB();				glAttachObjectARB(p,v);		glAttachObjectARB(p,f);			glLinkProgramARB(p);		glUseProgramObjectARB(p);	}        #include <GL/glew.h>	#include <GL/glut.h>		void main(int argc, char **argv) {			glutInit(&argc, argv);				...				glewInit();		if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)			printf("Ready for GLSL\n");		else {			printf("Not totally ready :( \n");			exit(1);		}			setShaders();			glutMainLoop();	}


The source code sample from above comes from the clicky link. The website names itself Lighthouse 3d.
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
Code-R, that's pretty much the idea, yeah. For example, you might want to share the code to transform a light vector into tangent space via a TBN matrix between a lot of shaders. So what you can do is write a seperate file with just that function, and then call that function from other shaders. Link them all together at runtime, and the function calls are resolved at link.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Quote:Original post by Promit
Code-R, that's pretty much the idea, yeah. For example, you might want to share the code to transform a light vector into tangent space via a TBN matrix between a lot of shaders. So what you can do is write a seperate file with just that function, and then call that function from other shaders. Link them all together at runtime, and the function calls are resolved at link.


Wait, am I right, or do I need to re-learn this stuff?
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
You were thinking about it from the wrong angle, you were talking about the C API end of things where as the OP was talking about shader objects themselves (which was answered by promit)
so I'll need to create a GL_FRAGMENT_SHADER object for each of my functions, compile them, then attach them and link?

This topic is closed to new replies.

Advertisement