I am working on a glsl shader program as part of a plugin that runs inside a "closed source" application. The application (maya) is written using opengl 2.1, but our graphics cards support opengl/glsl 4.1 and I want to use tessellation and geometry shaders in my program. The application sets up the opengl viewport and the traditional model/view matrix stack and I do not have control over that part of the code.
My pass-through vertex shader uses GLSL 1.2 and works fine:
// GLSL VERTEX SHADER
#version 120
void main ()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
My pass-through geomery shader uses glsl 4.1 and also works fine inside the application:
// GLSL GEOMETRY SHADER
#version 410
layout (lines_adjacency) in;
layout (line_strip, max_vertices = 2) out;
void main ()
{
gl_Position = gl_in[1].gl_Position;
EmitVertex();
gl_Position = gl_in[2].gl_Position;
EmitVertex();
EndPrimitive();
}
But this is just a pass-through test. In my real geometry shader I need to do some calculations in world-space but the geometry shader points are in view-space. My question is: can I access the gl_ModelViewProjectionMatrix inside a 4.1 geometry shader? I understand that the traditional matrix stack has been deprecated in glsl 4.1 in favor of uniform variables, but I cannot change the application. I cannot use glsl 1.2 in my geometry shader because I need the lines_adjacency input type. Do I need to copy the matrix into a uniform variable in my plugin's C++ source? Or is there a "back door" to get at it directly from glsl 4.1? Or something else I'm not thinking of?
You can use compatibility mode (if your GL implementation supports it) by saying:
#version 410 compatibility
in the shader. This will reenable all the deprecated global uniform state (among other things)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With