I am using opengl in order to visualize geometric deformations on 3d meshes. I am using a vao to draw the mesh. This is the code I use to setup the buffers and the vao
void setupDrawingBuffers() {
glGenVertexArrays(1, &VAO); glGenBuffers(1, &VBO); glGenBuffers(1, &EBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(MyVertex), &vertices[0], GL_DYNAMIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), &indices[0], GL_DYNAMIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(MyVertex), (GLvoid*)0); glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(MyVertex), (GLvoid*)offsetof(MyVertex, Normal)); glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(MyVertex), (GLvoid*)offsetof(MyVertex, Color)); glEnableVertexAttribArray(2);
glBindVertexArray(0); } |
After I do a transformation of the mesh data (deforming some vertices lets say) I want to update the buffers so the changes I did can be rendered. How do I correctly do that?
What I tried:1)After the deformation I called setupDrawingBuffers() but nothing was rendered on screen.
2)Instead of calling setupDrawingBuffers() after the deformation I called it in my rendering loop. That worked but it is obviously wrong since my setupDrawingBuffers function generates new buffers each time it is called which results in a memory leak on every rendering cycle.
First of all, this isn't Java/LWJGL. And second, are you sure you understand what that code is doing?
Have a look at glBufferSubData (https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBufferSubData.xhtml).
It allows to update (a subrange of) the buffer data.