问题
I have my VBO using single buffer at the moment, it has vertex, texcoord and color elements.
Now, is it possible to update efficiently only the texcoords without updating the vertex/color as well? It should be the same efficiency as having separate buffers updated.
回答1:
You can map a specific range of your VBO into user memory using glMapBufferRange. Of course, if your vertex, color and texcoord data are interleaved, it will be equivalent to a glMapBuffer.
EDIT:
If your VBO is:
[XYZ XYZ XYZ XYZ RGBA RGBA RGBA RGBA TxTy TxTy TxTy TxTy]
You can upload only the texture coordinates by mapping the last part of the buffer ([TxTy TxTy TxTy TxTy]
) and update it. You can also use glBufferSubData to do that. It would be faster to update that buffer than the full one.
But if you use interleaved data:
[XYZ RGBA TxTy XYZ RGBA TxTy XYZ RGBA TxTy XYZ RGBA TxTy]
Then you cannot update part of the buffer.
回答2:
You can map a VBO into memory space and then update the texcoords by striding across the data and modifying it.
One downside is that the entire VBO, once modified, will need to be resent to the video memory for rendering; if you are modifying this often, bus bandwidth can become an issue.
If you are trying to do some kind of algorithmic modification to your texcoords you could probably do this calculation in a shader. Another option would be to compose an array of the new values on the CPU side and send these values to the shader and do the replacment at render time; with this option though, you might as well just exclude the texcoords from the original VBO in the first place.
来源:https://stackoverflow.com/questions/6681871/modifying-only-a-specific-element-type-of-vbo-buffer-data