Behaviour of binding vertex attributes to shader variables

Hi all,

Recently I had a discussion concerning the behaviour of the GL when binding vertex attribute data to variables in a shader.
Let’s look at this situation:

// A simple interleaved vertex format x, y, z, s, t
float l_Vertices[] =
0., 0, 0., 0., 0.,
1., 0, 0., 1., 0.,
1., 1, 0., 1., 1.,
0., 1, 0., 0., 1.

(m_Pos was bound to location 0, m_TexCoord was bound to location 1)

// Set the data
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5sizeof(float), l_Vertices);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5
sizeof(float), &l_Vertices[3]);

Now what happens if in the shader the m_Pos attribute variable is declare as:
attribute vec4 m_Pos;
attribute vec2 m_TexCoord;

If the mismatch in component count of the shader variable and the pointer assignment guaranteed to be valid?
And would the m_Pos.w component guaranteed to be set to 1.0?

Any thoughts anyone?


Section 10.3.4 of the GL spec states

There’s your answer.

BTW, we just found a typo in the spec! :slight_smile:

Yes, a typo! Ok, so I feel a bit less awkward for not finding this passage my self. Something “good” came from it :wink:

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