GLSL Linking and Compiling
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
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.
Clicky
The source code sample from above comes from the clicky link. The website names itself Lighthouse 3d.
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.
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.
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?
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)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement