PDA

View Full Version : Rolling back GLSL 3.30 shaders to 1.50



JoshKlint
03-26-2011, 11:31 AM
I'm testing my 3.3 renderer with OpenGL 3.2 and GLSL 1.50, for better compatibility. Here's part of a fragment shader I use:
layout(location = 0) out vec4 out_diffuse;
layout(location = 1) out vec4 out_normal;
layout(location = 2) out vec4 out_properties;
layout(location = 3) out vec4 out_emission;

Now in GLSL, the layout stuff isn't supported, right? What do I use to define these values from my main program for GLSL 1.50?

Ilian Dinev
03-26-2011, 11:35 AM
for vertex attribs: glBindAttribLocation
for frag outputs: glBindFragDataLocation

JoshKlint
03-26-2011, 12:22 PM
Whew, that is way easier than using GetAttributeLocation, or whatever it's called. The problem with letting OpenGL automatically assign the attribute locations like uniforms is that your vertex buffer class becomes dependent on feedback from your shader class, and it gets messy.

JoshKlint
03-26-2011, 02:20 PM
I actually like using glBindAttribLocation better than specifying the layout in the shader, because you only have to store the attribute definitions in one place in your program.

kaerimasu
03-28-2011, 10:26 AM
Whew, that is way easier than using GetAttributeLocation, or whatever it's called. The problem with letting OpenGL automatically assign the attribute locations like uniforms is that your vertex buffer class becomes dependent on feedback from your shader class, and it gets messy.

I hear you, but then drawing the same VAO with multiple shaders gets messy.

- Chris

malexander
03-28-2011, 11:32 AM
One of the issues I found with 1.50 is that it's not possible to query what the fragment shader outputs are, unlike input attributes (which are queried with glGetProgram(GL_ACTIVE_ATTRIBUTES)/glGetActiveAttrib). You just have to know what outputs the shader has, though admittedly in most cases this isn't an issue. Explicit Attribute Location comes in handy in the other cases, but it still doesn't seem possible to query the number of fragment shader outputs.

Edit: I should point out that I worked around the issue by doing a glGetFragDataLocation() for all output names that were supported in a given context and checking it against -1.