Disabled attributes don't work with compatibility profile

Started by Eric, February 28, 2014, 08:19:18

Previous topic - Next topic

Eric

Hello,

I've noticed that my shaders stop working when they contain attributes that I haven't enabled with glEnableVertexAttribArray. The attributes in question don't seem to get initialized to any useful default value and doing it manually with glVertexAttrib* doesn't work either. I don't get any errors with GL11.glGetError(), but the shaders won't paint anything.

This only happens when using compatibility profile. Everything works as expected when using the core profile. The attribute is initialized with a default value (vec4(0, 0, 0, 1) in my case) and I can change it using glVertexAttrib*.

Vertex shader:

#version 150 core
uniform mat4 uMVPMatrix;
attribute vec4 aPosition;
attribute vec4 aColor;
varying vec4 vColor;
void main() {
  vColor = aColor;
  gl_Position = uMVPMatrix * aPosition;
}


Fragment shader:

#version 150 core
precision mediump float;
varying vec4 vColor;
void main() {
  gl_FragColor = vColor;
 }


In this case I'm trying to paint without enabling aColor. But I only got it to work when using the core profile. I don't undestand why it won't work in compatibility profile. Could anybody point me into the right direction?

quew8

The behaviour you are describing from the compatibility profile is what I would expect to happen. I think it's the core profile that's wrong if I'm understanding you correctly.

This is from the glEnableVertexAttribArray() docs:

QuoteBy default, all client-side capabilities are disabled, including all generic vertex attribute arrays

That means that if you haven't explicitly enabled a vertex attrib array then it shouldn't work.

Eric

Thank you for your answer!

Somehow the way the core profile works makes more sense to me, since GL20.glVertexAttrib4f() for example only works with disabled attributes.

Also, some generic OpenGL tutorials speak of a default value for disabled attributes:

QuoteIf the attribute has been disabled by calling glDisableVertexAttribArray, the vertex shader input will take the default value { 0.0, 0.0, 0.0, 1.0 }. Commands from the immediate mode API, such as glVertexAttrib4f, can change the default value used when the attribute array is disabled.

But I have no idea what the standards say.

quew8

Well I don't have time to look through the specs right now but this is again from the glDisableVertexAttribArray() docs:

QuoteIf enabled, the values in the generic vertex attribute array will be accessed and used for rendering when calls are made to vertex array commands such as glDrawArrays, glDrawElements, glDrawRangeElements, glMultiDrawElements, or glMultiDrawArrays.

Implying it isn't accessed if it isn't enabled. That seems to me (and from memory this is my experience as well although I've never tried deliberately disabling and then trying to use a vertex attrib) to suggest that the shader won't look up the value of a disabled attribute so the immediate mode shouldn't work either and the value should be undefined.

Maybe someone else can chip in with their experience.