Hi,
I have a Vertex shader which has two “in” vertex attributes:
in vec3 iv_Vertex;
in vec2 iv_UvCoord;
Normally I call glGetAttribLocation() on both and set glEnableVertexAttribArray() and glVertexAttribPointer() with the returned value.
I now want to draw some debug lines with the same shader so I dont need the uv-coordinates. I simply disabled the attribute via glDisableVertexAttribArray(), however glDrawArrays() crashes with an Access Violation at 0x0000000.
Some further investigation showed that my vertex shader always has two active Attributes, even right after the call to glDisableVertexAttribArray().
This is my investigation function:
DLL void init_vertexbuffer_vars_pos( void *buffer )
{
CShader *pShd = GetShaderManager()->GetActiveShader();
int attrib1 = pShd->GetAttribLoc( SHADER_VERTEX ); //This is always 1
glEnableVertexAttribArray( attrib1 );
glVertexAttribPointer( attrib1, 3, GL_FLOAT, GL_FALSE, 0, ((char*)buffer) + 0 );
int attrib2 = pShd->GetAttribLoc( SHADER_UVCOORD ); //This is always 0
if( attrib2 != -1 )
glDisableVertexAttribArray( attrib2 );
GLint active_attribs;
glGetProgramiv(pShd->m_iProgram, GL_ACTIVE_ATTRIBUTES, &active_attribs);
for( UINT i = 0; i < active_attribs; i++ )
{
GLchar var[32];
GLint size;
GLenum type;
glGetActiveAttrib( pShd->m_iProgram, i, 32, NULL, &size, &type, var );
ConsoleMessage( "Active Attribute: %s, program attrib nr. %i", var, i );
}
}
This function ALWAYS outputs the following:
] Active Attribute: iv_UvCoord, program attrib nr. 0
] Active Attribute: iv_Vertex, program attrib nr. 1
So my UvCoord-Attribute does not get disabled. How is that possible?