Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to dynamically edit VBO's on the fly
    primarykey
    data
    text
    <p>I am looking for a way to dynamically edit the data that displays for a vertex buffer object. I have tried glBufferSubData, glMapBuffer, glBufferData, and some others, however had no luck. I have found that the time consuming method is glBindBuffer. I think I am using VBOs right, but I am not completely sure. Heres some sample code of my problem:</p> <pre><code> verticesId = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, verticesId); glBufferData(GL_ARRAY_BUFFER, verticesBuffer, GL_STREAM_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); normalsId = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, normalsId); glBufferData(GL_ARRAY_BUFFER, normalsBuffer, GL_STREAM_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); texturesId = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, texturesId); glBufferData(GL_ARRAY_BUFFER, texturesBuffer, GL_STREAM_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); </code></pre> <p>the verticesBuffer and other variables are the FloatBuffers that have the data in them. Next, I render them this way:</p> <pre><code> glEnableClientState(GL_VERTEX_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, verticesId); glVertexPointer(vertexSize, GL_FLOAT, 0, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, texturesId); glTexCoordPointer(2, GL_FLOAT, 0, 0); glDrawArrays(GL_QUADS, 0, amountOfVertices); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); </code></pre> <p>Here is how I edit the VBOs:</p> <pre><code> int position = 0; /////////////////////////////////////////////////////////////////// glBindBuffer(GL_ARRAY_BUFFER, verticesId); mapBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY, null); verticesBuffer = mapBuffer.order(ByteOrder.nativeOrder()).asFloatBuffer(); verticesBuffer.position(position); // ... edit some values in the 'vertices' float array ... verticesBuffer.put(vertices); verticesBuffer.rewind(); glUnmapBuffer(GL_ARRAY_BUFFER); glBindBuffer(GL_ARRAY_BUFFER, 0); </code></pre> <p>Is there any way to speed up the glBindBuffer method, or am I doing this wrong? And also, how should I edit the data for the most efficiency.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload