Jump to content

  • Log In with Google      Sign In   
  • Create Account


jsmtux

Member Since 06 Jul 2013
Offline Last Active Apr 13 2014 01:18 PM
-----

Posts I've Made

In Topic: invalid operation error on glBindVertexArray

23 July 2013 - 10:11 AM

Hi all, thanks for your time.

The code I use to initialize the vaos is:

glGenVertexArrays(1, &iVAO);
glBindVertexArray(iVAO);

glGenBuffers(5, m_Buffers);

//here I load the buffers' information and the images

glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[POS_VB]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Positions[0]) * Positions.size(), &Positions[0],
               GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[TEXCOORD_VB]);
glBufferData(GL_ARRAY_BUFFER, sizeof(TexCoords[0]) * TexCoords.size(), &TexCoords[0],
                GL_STATIC_DRAW);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[NORMAL_VB]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Normals[0]) * Normals.size(), &Normals[0],
                GL_STATIC_DRAW);
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, 0);
    
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[BONE_VB]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Bones[0]) * Bones.size(), &Bones[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(BONE_ID_LOCATION);
glVertexAttribIPointer(BONE_ID_LOCATION, 4, GL_INT, sizeof(VertexBoneData), (const GLvoid*)0);
glEnableVertexAttribArray(BONE_WEIGHT_LOCATION);
glVertexAttribPointer(BONE_WEIGHT_LOCATION, 4, GL_FLOAT, GL_FALSE, sizeof(VertexBoneData), (const GLvoid*)16);
    
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Buffers[INDEX_BUFFER]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices[0]) * Indices.size()*3, &Indices[0],
                GL_STATIC_DRAW);
    
glBindVertexArray(0);

And the code to draw them is:

glBindVertexArray(iVAO);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[POS_VB]);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[TEXCOORD_VB]);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[NORMAL_VB]);
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[BONE_VB]);
glEnableVertexAttribArray(BONE_ID_LOCATION);
glVertexAttribIPointer(BONE_ID_LOCATION, 4, GL_INT, sizeof(VertexBoneData), (const GLvoid*)0);
glEnableVertexAttribArray(BONE_WEIGHT_LOCATION);
glVertexAttribPointer(BONE_WEIGHT_LOCATION, 4, GL_FLOAT, GL_FALSE, sizeof(VertexBoneData), (const GLvoid*)16);
    
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Buffers[INDEX_BUFFER]);

for (unsigned int i = 0 ; i < meshes.size() ; i++) {
    const unsigned int MaterialIndex = meshes[i].MaterialIndex;

   if (MaterialIndex < maps.size() && maps[MaterialIndex]) {
       dynamic_cast<Image*>(maps[MaterialIndex])->Bind();
   }
       
    glDrawElementsBaseVertex(GL_TRIANGLES,
                              meshes[i].NumIndices,
                              GL_UNSIGNED_INT,
                              (void*)(sizeof(unsigned int) * meshes[i].BaseIndex),
                              meshes[i].BaseVertex);
}

// Make sure the VAO is not changed from the outside
glBindVertexArray(0);

And this way it works, but if the VAO weren't invalid It should work like this

glBindVertexArray(iVAO);
    
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Buffers[INDEX_BUFFER]);

for (unsigned int i = 0 ; i < meshes.size() ; i++) {
    const unsigned int MaterialIndex = meshes[i].MaterialIndex;

   if (MaterialIndex < maps.size() && maps[MaterialIndex]) {
       dynamic_cast<Image*>(maps[MaterialIndex])->Bind();
   }
       
    glDrawElementsBaseVertex(GL_TRIANGLES,
                              meshes[i].NumIndices,
                              GL_UNSIGNED_INT,
                              (void*)(sizeof(unsigned int) * meshes[i].BaseIndex),
                              meshes[i].BaseVertex);
}

// Make sure the VAO is not changed from the outside
glBindVertexArray(0);

In Topic: invalid operation error on glBindVertexArray

22 July 2013 - 11:57 AM

Thank you very much for your answer.

I found out that the vertex array gets invalidated when I call the SFML display function.

But I still have no clue about how to fix it or what kind of calls could lead to this behaviour


In Topic: Problem returning lua object references

08 July 2013 - 09:57 AM

Going on with the problem, if I change my function to this:

lua_rawgeti(L, LUA_REGISTRYINDEX, tmp.luaRef);
luaL_checktype(L, -1, LUA_TTABLE); 
   
return 1; 

Checktype says that a lua table is on top of the stack, but if I print this return value from lua it says it is a nil value


PARTNERS