0
\$\begingroup\$

I have the OpenGL VAO object (~40K) to draw the 3D scene

glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 4, GL_UNSIGNED_BYTE, nullptr);
glBindVertexArray(0);

To add some data I can use glMapBuffer:

GLuint buffer;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, (2 * steps) * sizeof(float),
     NULL, GL_STATIC_DRAW);
float *data = (float *) glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
myFuncAddingData(data,{2.4f, 40.0f, 19.0f});
glUnmapBuffer(GL_ARRAY_BUFFER);

Can I to remove (hide/mask) some verteces (3 from 40K) directly from the located in the grafical memory VAO without full complete replacement all of the 40K?

\$\endgroup\$
0
\$\begingroup\$

If you would use vertex indices, you could just skip those indices, but you would have to almost completely replace the indices list, which I guess would defeat the purpose of this question.

If you only want to have the visual effect of removing a polygon you can flip the order of vertices and use face culling. Or change the color of the polygon to clear(few ways to do this, but generally hard to do with UV mapping).

Because the data is linearly mapped to memory you can't really just remove data without rewriting your code in a more complicated manner. If you really desire to do this you can.

What I suggest you do is to use GLMultiDrawArrays or GLMultiDrawElements which would allow you to have all the objects in your scene in a single VAO, but you get to specify which you want to draw. The downside is that they all have to use the same state for drawing (rarely an actual problem). The upside is that you use code with minimal driver overhead. Now if you want to add and remove data from this VAO you have to apply your own memory management code so you wouldn't override data that is still in use. I wouldn't worry about deleting the data because your VAO is still linearly mapped and the memory is inaccessible for the GPU anyways and vertex data is rarely a significant part of used memory.

Now if you want to go hardcore on the optimizations you can use GLMultiDrawArraysIndirect or GLMultidrawElementsIndirect, but this requires OpenGL 4.3 or greater. The added benefit would be even less communication with the GPU, but you have to store some data in GPU memory and also manage that.

\$\endgroup\$
  • \$\begingroup\$ @Andeas, If I'm wrong, correct me. glMultiDrawArrays — render multiple sets of primitives from array data, according not using GPU memory and VAO. Can you give here example fo illustrate you answer? \$\endgroup\$ – bigov Oct 30 '16 at 12:45
  • \$\begingroup\$ The difference with regular glDrawArrays is the word multiple. They use memory the same way, but glMultiDrawArrays allows to specify multiple objects to be drawn with a single command. Same goes for glMultiDrawElements. The vertex data is stored exactly the same, that is in the VAO. If you like to learn more I suggest you explore the opengl.org/wiki page or find a book. \$\endgroup\$ – Andreas Oct 30 '16 at 14:42
  • \$\begingroup\$ Thanks you for the advice. And why would a website "stackexchange.com"? \$\endgroup\$ – bigov Nov 1 '16 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.