PDA

View Full Version : Doubt about initialize mesh



shotoreaper
02-06-2013, 12:18 PM
Hi!
If I change the value of the vertices from a mesh after call this code, Must I calling it again?:


glGenVertexArrays(1, &BufferIds[0]);

ExitOnGLError("ERROR: No se puede generar el VAO");
glBindVertexArray(BufferIds[0]);
ExitOnGLError("ERROR: No se puede bindear el VAO");

// Activamos dos vertex attribute locations
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
ExitOnGLError("ERROR: No se puede activar los vertex attributes");

// Creamos los VBO
glGenBuffers(2, &BufferIds[1]);
ExitOnGLError("ERROR: No se pueden generar los buffer objects");

// Bindeamos el VBO al VAO
glBindBuffer(GL_ARRAY_BUFFER, BufferIds[1]);
glBufferData(GL_ARRAY_BUFFER, vtn.size()*sizeof(VertexTextureNormal), &vtn[0], GL_STATIC_DRAW);
ExitOnGLError("ERROR: No se puede bindear el VBO al VAO");

glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(vtn[0]) ,0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(vtn[0]) , (GLvoid*) sizeof(vtn[0].position));
ExitOnGLError("ERROR: Could not set VAO attributes");

// Creamos el IBO
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferIds[2]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), &indices.front(), GL_STATIC_DRAW);
ExitOnGLError("ERROR: No se puede bindear el IBO al VAO");

glBindVertexArray(0);

BionicBytes
02-07-2013, 05:05 AM
If I change the value of the vertices from a mesh after call this code, Must I calling it again?:
I don't think you need to redine the VAO if you're just going to fill up the same buffer objects with new data.
If that's what you are doing, then you may want to reconsider the GL_STATIC_DRAW hint - as that's best used for cases when the data is never changed.

shotoreaper
02-08-2013, 12:50 AM
Im going to see if the program works if I use GL_DYNAMIC_DRAW and glBufferSubData to change the data.