In my ongoing attempt to convert to OpenGL ES 2.0 from ES 1.x I'm currently converting some code to use Vertex Buffer Objects ('VBOs') rather than the existing unbuffered glDrawArrays calls.
I've set up the VBOs and got them working, but have hit a design dilemma and would be grateful the advice of someone more experienced with OpenGL ES 2.0.
I want to draw a bunch of polygonal sprites which move often. This is because they're dynamic Box2D bodies, if you're familiar with Box2D. These polygon bodies are each generated by use of GL_TRIANGLE_FAN, which is somewhat critical since GL_POLYGON is unavailable on ES 2.0 .
The polygons have other attributes such as color which may be changed at some stage during the application lifecycle, but it's the vertex positions which are guaranteed to change almost every frame.
The polygons are grouped in-game, so it's my intention to manage and draw an interleaved vertex/colour array per-group rather than per-body, in an attempt to minimise GPU communication.
There are a number of routes to success here, I've been reading OpenGL ES 2.0 programming guide to seek as much info and optimisation tips as I can relating to VBOs and here's what they say:
Interleaved data is favourable since "attribute data for each vertex can be read in sequential fashion".
The book recommends that "if a subset of vertex attribute data needs to be modified..one can.. store vertex attributes that are dynamic in nature in a separate buffer".
The recommendation is to "use GL_HALF_FLOAT_OES wherever possible" most notably for colors since unprojected vertex locations may exceed this space requirement.
glMapBufferOES should only be used if the whole buffer is being updated, and even in this case the operation "can still be expensive compared to glBufferData".
Here are my questions:
If using GL_TRIANGLE_FAN as the drawing mode, does this force me to store a VBO per-body rather than per-group? Or will a common vertex location to 'end' the fan and current body cause a new fan to be drawn for the next body in a group VBO?
Should I interleave all of my data despite vertex locations being updated at a high frequency, or should I separate all of it/just the locations into their own VBO?
Following the book advice above, presumably I should glBufferData my vertex locations in their entirety every time I update the render, rather than using glMapBufferOES or glBufferSubData to update the buffered locations?
Are there any unmentioned functions/design choices I should be utilising to enhance performance in a many-moving-polygons context?
Should I attempt to use GL_HALF_FLOAT_OES for color storage, i.e. in the space of 2 floats I instead store 4 half-float numbers? If the answer is 'yes', would I just use any GL type which is half the size of GLfloat for each colour, then bitwise OR them, then insert into the appropriate attribute array?
Once I've created X many VBOs, are the only calls I need to make for each render glBindBuffer, glBufferData, and glDrawElements/Arrays, or must I also call glEnableVertexAttribArray and glVertexAttribPointer each time I use glBufferData?
I'd be extremely grateful for further advice on this, thank you.