Jump to content
  • Advertisement
Sign in to follow this  
Code-R

GLSL Linking and Compiling

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

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
so I'll need to create a GL_FRAGMENT_SHADER object for each of my functions, compile them, then attach them and link?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!