I have a large vertex buffer object and I only want to update a small portion of it. Google tells me that this is a job for the glBufferSubData function but I'm not sure how to use it. I've been able to replace data in a array of vertices, but I'd rather leave them alone and work with the indices instead. However, trying to use glBufferSubData on my index VBO causes the entire array to go blank (my object disappears, anyway) and so I've just been recreating the entire array for each update (very slow). Here's my code for updating (written in Java with the lwjgl lib):
Code :public int updateChunk(int indexVboId, int totalVerts) { // Bind and buffer VBO ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, indexVboId); ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, intSize*totalVerts, ARBVertexBufferObject.GL_STREAM_DRAW_ARB); // Map VBO ByteBuffer indexBuffer = ARBVertexBufferObject.glMapBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, ARBVertexBufferObject.GL_WRITE_ONLY_ARB, intSize*totalVerts, null); // start replacing data at the beginning of the array (0) GL15.glBufferSubData(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, 0, indexBuffer); // replace first 4 indices with these indexBuffer.putInt(0).putInt(1).putInt(2).putInt(3).putInt(4); indexBuffer.flip(); //unmap and unbind ARBVertexBufferObject.glUnmapBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB); ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, 0); return 1; }
Does anything look wrong here? Why would this code work for an array of vertices but not indices?
Also, how would I remove indices from the VBO?



