OpenGL ES 2.0: Commands Required Just Before glDrawElements with VBO

I set a vertex buffer object (VBO) with vertex and index data. I also created GLprogram to use custom shaders, so I call glUseProgram in my code.

My vertex data changes every frame, so I sent GL_STREAM_DRAW to my two glBufferData (one for vertex data, one for indexes).

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

My question is: what commands should I call every time I call glDrawElements ? Ideally, I would just call glDrawElements own for every frame for performance reasons.

I look through the book "OpenGL ES 2.0 Programming Guide", but nowhere does it tell me which commands I should use each time I draw, and which I need to call only once.

0
source share
1 answer

glDrawElements represents geometry. If you use VBOs, then it uses the entries in the currently GL_ELEMENT_ARRAY_BUFFER to index the entries in the corresponding parts of GL_ARRAY_BUFFER or the buffers GL_ARRAY_BUFFER with each attribute.

If you do not change any other bindings, you do not need to repeat the call other than glDrawElements . If you are currently calling glDrawElements , you copy and paste this line twice, all your geometry will be drawn twice as much as before.

+1
source

Source: https://habr.com/ru/post/896612/


All Articles