Include directive functionality in GLSL

Started by
2 comments, last by Aks9 13 years ago
Hey GameDev,

I see we have a new forum. Just goes to show I haven't been here for a while. Ok, I got a question -- and I am a little surprised that this topic doesn't pop up more often, or at least that it hasn't been better covered when searching google.

I'm looking for something that will give me the same behavior as the "include" directive in C++, in GLSL. By scowering "teh interwebz" I have found out that there apparently is an existing definition for the functionality in OpenGL called "[font="monospace"]ARB_shading_language_include[/font]", but according to various posts, it seems as though it might - as of right now - still be unimplemented? The specification for this extension can be found here:

http://www.opengl.or...age_include.txt

where it also specifies that "[font="monospace"]This extension is written against the OpenGL 3.2 (Core Profile) and[/font][font="monospace"] OpenGL Shading Language 1.50 Specifications.[/font]". Does this mean that if I use the compatibility profile I am screwed? If so, can someone suggest an easy and painless alternative? I have some GLSL code I'd prefer to keep in "#version 120" since I like using some of the fixed functionality's pipeline to perform transformations. I'd also prefer if the solution does not require keeping all my GLSL code inside pre-defined strings as I love syntax highlighting.

So... I guess the straight forward question is: Does anyone have a simple solution which provides the same functionality as the include directive from C++ in the compatibility profile while still allowing me to see syntax highlighted GLSL code?

Regards,

Gazoo
Advertisement
It will probably be available in compatibility profile as well since both AMD and nVidia are committed to it. Sorry, I don't know of any tutorials on this extension.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
It's best (and really quite easy) to just do it yourself. Use the #pragma directive in GLSL with your own unique identifier (e.g. #pragma myinclude "stuff") and just pass it through a preprocessor of your own design before sending it to the GL. Scan for your custom pragma in the source string, then either replace it with the included source, or better yet simply leave the pragma as is and pass the included source as another string to glShaderSource. This is safe since according to the GL spec, any pragma directive which isn't recognized is simply ignored without error.

By scowering "teh interwebz" I have found out that there apparently is an existing definition for the functionality in OpenGL called "[font="monospace"]ARB_shading_language_include[/font]", but according to various posts, it seems as though it might - as of right now - still be unimplemented?




ARB_shading_language_include is implemented in NV drivers since 265.90 (maybe even earlier, but I don't have information about all drivers releases. I have a precision of about a month. ;) In 260.99 this extension is missing). I'm not sure if AMD implements it.


...where it also specifies that "[font="monospace"]This extension is written against the OpenGL 3.2 (Core Profile) and[/font][font="monospace"] OpenGL Shading Language 1.50 Specifications.[/font]". Does this mean that if I use the compatibility profile I am screwed?



That means ARB_shading_language_include is written as an extension of GL 3.2 Core spec. Paragraphs and sections from ARB_shading_language_include should be inserted into GL 3.2 core spec to have a complete overview. Compatibility profile enables full backward compatibility, so there is no problem in using ARB_shading_language_include. Just one more comment, ARB_shading_language_include is a part of GL 3.3 Core spec, although it is relatively recently implemented (9 months after the spec).

This topic is closed to new replies.

Advertisement