Hi, I cut some parts of the code that relevant to the issue.
I still did not manage to spot the problematic area.
Please note that the same code and shaders works for VA, but not for VBO.
struct sBoneData
{
vec4 vWeights,
vIndices;
};
Vertex Arrays
glVertexAttribPointer( iPositionAttribLoc, 3, GL_FLOAT, GL_FALSE, sizeof( vec3 ), &pGeo->vVertices[0].x );
glEnableVertexAttribArray( iPositionAttribLoc );
glVertexAttribPointer( iBoneWeightsAttribLoc, 4, GL_FLOAT, GL_FALSE, sizeof( sBoneData ), &pGeo->vBonesData[0].vWeights.x );
glEnableVertexAttribArray( iBoneWeightsAttribLoc );
glVertexAttribPointer( iBoneIndexesAttribLoc, 4, GL_FLOAT, GL_FALSE, sizeof( sBoneData ), &pGeo->vBonesData[0].vIndices.x );
glEnableVertexAttribArray( iBoneIndexesAttribLoc );
unsigned int *ptr = &pGeo->vFaces[ m_pObj->iFacesStartPos ].uIndex[ 0 ];
unsigned int sz = (unsigned int)( m_pObj->iFacesEndPos - m_pObj->iFacesStartPos ) * 3;
glDrawElements( GL_TRIANGLES, m_uNumElements, GL_UNSIGNED_INT, 0 );
VBO
Generate ...
{
glGenBuffers(3, m_Buffers);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[0]);
size_t size = sizeof(vec3) * pGeo->vVertices.size();
glBufferData(GL_ARRAY_BUFFER, size ,0 , GL_STATIC_DRAW);
size_t startOff = 0,
currSize = sizeof(vec3) *pGeo->vVertices.size();
m_VertexOffset = startOff;
glBufferSubData(GL_ARRAY_BUFFER, startOff, currSize, &pGeo->vVertices[0].x );
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[1]);
// Indices and weights
size_t size2 = sizeof(vec4) *pGeo->vBonesData.size() * 2;
glBufferData(GL_ARRAY_BUFFER, size2 ,0 , GL_STATIC_DRAW);
startOff = 0;
currSize = sizeof(vec4) *pGeo->vBonesData.size();
m_BonesWeightsOffset = startOff;
glBufferSubData(GL_ARRAY_BUFFER, startOff, currSize, &pGeo->vBonesData[0].vWeights.x );
startOff += currSize;
currSize = sizeof(vec4) *pGeo->vBonesData.size();
m_BonesIndicesOffset = startOff;
glBufferSubData(GL_ARRAY_BUFFER, startOff,currSize, &pGeo->vBonesData[0].vIndices.x );
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Buffers[2]);
unsigned int *ptr = &pGeo->vFaces[ m_pObj->iFacesStartPos ].uIndex[ 0 ];
unsigned int sz = (unsigned int)( m_pObj->iFacesEndPos - m_pObj->iFacesStartPos ) * 3;
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GL_UNSIGNED_INT) * sz,ptr, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
Bind ...
{
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[0]);
if ( handlers[0] != -1 && m_VertexOffset != -1)
{
//glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[0]);
glEnableVertexAttribArray( handlers[0] );
glVertexAttribPointer( handlers[0] ,3,GL_FLOAT, GL_FALSE, sizeof( vec3 ), reinterpret_cast<void*>( m_VertexOffset ));
}
{
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[1]);
if ( handlers[5] != -1 && m_BonesWeightsOffset != -1 )
{
glVertexAttribPointer( handlers[1], 4, GL_FLOAT, GL_FALSE, sizeof( sBoneData ), reinterpret_cast<void*>(m_BonesWeightsOffset) );
glEnableVertexAttribArray( handlers[1] );
}
if ( handlers[6] != -1 && m_BonesIndicesOffset != -1 )
{
glVertexAttribPointer( handlers[2], 4, GL_FLOAT, GL_FALSE, sizeof( sBoneData ), reinterpret_cast<void*>(m_BonesIndicesOffset) );
glEnableVertexAttribArray( handlers[2] );
}
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Buffers[2]);
}
Draw ...
{
glDrawElements( GL_TRIANGLES, m_uNumElements, GL_UNSIGNED_INT, 0 );
}
UnBind ...
for ( int i = 0 ; i < size ; ++i )
if ( handlers != -1 )
glDisableVertexAttribArray( handlers );
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}