Rolling back GLSL 3.30 shaders to 1.50

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?

for vertex attribs: glBindAttribLocation
for frag outputs: glBindFragDataLocation

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 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.

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

  • Chris

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.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.