View Full Version : vaoID is not working?

10-11-2016, 08:54 AM
This sounds weird but it really seems like for some reason the vaoID i use does not work.
Ive just implemented a new entity system ( as already discribed here (http://gamedev.stackexchange.com/questions/131280/component-based-entity-system-using-polymorphism-opengl-does-not-render))
Instead of passing the Mesh-class object containing the vaoID, indexNumber and vertexNumber to my loadMesh() and render() functions i store all mesh objects inside of a
std::multimap<unsigned int, Component*> and using the entity IDs i can access every entities components through this multimap.
here is how i load my vertices and indices into my vao

glCreateVertexArrays(1, &vaoID);
glGenBuffers(1, &vboID);
glGenBuffers(1, &iboID);

//associate vertexArray with vboID and indexArray with iboID
glNamedBufferStorage(vboID, sizeof(Vertex)*vertexNum, &vertexArray[0], GL_STATIC_DRAW);
glNamedBufferStorage(iboID, sizeof(unsigned int)*indexNum, &indexArray[0], GL_STATIC_DRAW);
glVertexArrayElementBuffer(vaoID, iboID);
//vaoID vertex attrib array binding location 0 -> vboID
glVertexArrayVertexBuffer(vaoID, 0, vboID, 0, sizeof(Vertex));

//vao binding location 0 -> attribute 0
glVertexArrayAttribBinding(vaoID, 0, 0);
glVertexArrayAttribFormat(vaoID, 0, 4, GL_FLOAT, GL_FALSE, offsetof(Vertex, position));

glVertexArrayAttribBinding(vaoID, 1, 0);
glVertexArrayAttribFormat(vaoID, 1, 4, GL_FLOAT, GL_FALSE, offsetof(Vertex, color));

//here i initialize the current component with the relevant data

when i render, i do it like this

void Graphic::render()
for (unsigned int c = 0; c < Component::entityComponents.size(); ++c) {
std::multimap<unsigned int, Component*>::iterator cItr = Component::entityComponents.find(c);
std::multimap<unsigned int, Component*>::iterator lastC = Component::entityComponents.upper_bound(c);

if(cItr != Component::entityComponents.end()){

for (; cItr != lastC; ++cItr) {
if (cItr->second->getComType() == ComType::Space) {
glm::vec3 position = cItr->second->getPos();
glm::mat4 translate = glm::translate(Camera::camMatrix(), position);
glm::mat4 rotate = glm::rotate(translate, 2.0f, glm::vec3(1.0f, 1.0f, 1.0f));
glm::mat4 fullMatrix = glm::scale(rotate, glm::vec3(1.0f, 1.0f, 1.0f));
currentShader.addUniform("transformationMatrix", fullMatrix);

//printf("%f %f %f \n\n", Camera::position.x, Camera::position.y, Camera::position.z);
if (cItr->second->getComType() == ComType::Mesh) {
GLuint vaoID = cItr->second->getVAO();
unsigned int indexNum = cItr->second->getIndexNum();
glEnableVertexArrayAttrib(vaoID, 0);
glEnableVertexArrayAttrib(vaoID, 1);
glDrawElements(GL_TRIANGLES, indexNum, GL_UNSIGNED_INT, nullptr);

i checked using breakpoints, the vao stays the same. and i did not change any of the loading or rendering process. i just changed how i access the ids in my entity objects.
Is there anything else openGL needs for rendering exept an integer ID and an integer of index Count?


10-11-2016, 10:58 AM
Okay its fixed now, but i dont know why. I played around and started copying the rendering in the loading function and then i called the loading function every frame (together with my other rendering function). i got 2 cubes, which had me wondering because i expected one (from the loadMesh function). when i erased the rendering part from the loadMesh function the one cube from the render() function stayed there! i dont know what happened, but it just works now. it might be because i called

glEnableVertexArrayAttrib(vaoID, 0);
glEnableVertexArrayAttrib(vaoID, 1);
when i copied the rendering part but i am not calling it anymore now and it still works! really weird.

EDIT: it looks like i HAVE to use glCreateBuffers instead of glGenBuffers. that was literally it.

10-11-2016, 12:10 PM
EDIT: it looks like i HAVE to use glCreateBuffers instead of glGenBuffers. that was literally it.

Yes actually - if you use any DSA function then you really should be using them everywhere. In particular there is a difference between glGen* (which just gives you a free name but doesn't create the object) and glCreate* (which does create the object).