On Android with opengl-es, should I put all glVertexPointer data into one buffer?
I have a scene that contains a bunch of objects, for example lets say it's a simple grid of tiles. So there's a main "border" object, and then (rows x columns) cells.
For simplicity, assume each cell is a simple four-segment line consisting of a four-node GL_LINE_LOOP.
Currently, my frame rate is awefull, and it seems to sit in all the glVertexBuffer() calls that I'm making, as each cell has it's own set of vertices, so it's own call to glVertexPointer:
class MyModel ex开发者_StackOverflowtends Model {
...
public void onDrawFrame(GL10 gl) {
gl.glVertexPointer(0, GL10.GL_FLOAT, 0, mBuffer);
gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, 4);
}
}
Should I instead track all of my distinct primitive models in a world super-object, and keep a copy of all the vertices in memory? I could then perform a single glVertexPointer call at the start of each frame, and use offsets for the DrawArrays.
class MyModel extends Model {
public MyModel() {
// do something clever in parent Model class to track total verts
this.offsetId = somethingFromSuper();
}
public void onDrawFrame(GL10 gl) {
// super's vertices should all have been already sent to GL
gl.glDrawArrays(GL10.GL_LINE_LOOP, this.offsetId, 4);
}
}
I don't think that would make a big difference: you are still calling separate gl draw commands for each model. Instead, you probably want to have the drawing taken care of by the 'world' class that will combine all model vertices into one big array, and draw that with one call. Other than iterating through the models to get their vertex info and constructing the 'world' array, instead of calling a draw on each model, it is pretty much the same.
This approach is absolutely necessary if the render commands draw less than 30 vertices, according to this article from Qualcomm (bit old, but probably still relevant): http://www.cin.ufpe.br/~mact/graduacao/so/dia1/progpc21_dorbie_3dgraphics.pdf
You wouldn't be able to use GL_LINE_LOOP in this case, but would need to use GL_LINES instead. If you are drawing tris, you can use GL_TRIANGLES or GL_TRIANGLE_STRIP with degenerate triangles inserted to detach the models.
Cheers, Aert.
精彩评论