Question

I've setup a Vertex Buffer Object (VBO) with vertex and index data. I've also created a GLprogram to use custom shaders, so I call glUseProgram within my code.

My vertex data changes every frame, so I've supplied GL_STREAM_DRAW to my two glBufferData calls (one for vertex data, one for indices).

I use glBufferSubData to modify regions of my vertex data when they change. At each frame I want to draw from the first vertex to the Nth, with N being a changing value.

My question is: which commands must I call every time that I call glDrawElements? Ideally I'd like to simply call glDrawElements on its own in each frame, for performance reasons.

I'm poring over the book "OpenGL ES 2.0 Programming Guide" but nowhere does it tell me which commands I must use every time I draw, and which I need to call only once.

Was it helpful?

Solution

glDrawElements submits geometry. If you're using VBOs then it uses entries in the currently bound GL_ELEMENT_ARRAY_BUFFER to index entries in the relevant portions of the GL_ARRAY_BUFFER or buffers bound for each attribute.

If you don't change any other bindings then is no need to repeat any call other than glDrawElements. If, where you currently call glDrawElements you copy and paste that line to appear twice, all your geometry will be drawn twice as many times as before.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top