I’ve been programming OpenGL for some time now but I’m quite new to OpenGL ES. One of issues I’m having is drawing primitives on the screen in an efficient maner.
I need to draw a number of equal line loops on the screen (with different translation) and noticed a huge performance drop with this code:
gl.glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, this.vertices);
for (int j = 0; j < height; j++)
{
for (int i = 0; i < width; i++)
{
gl.glPushMatrix();
gl.glTranslatef(i, j, 0);
gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, 4);
gl.glPopMatrix();
}
}
I figure that the glDrawArrays is the bad guy here.
So the question is how can I draw a bunch of line loops efficiently? The glDrawArrays must be called for each primitive when using GL_LINE_LOOP so do I need to change the type to GL_LINES? This would impose a huge memory waste since the vertex array (in code above, holding 4 vertices) will then hold width * height * 8 vertices.
I’m programming for Android OpenGL ES 1.1.
Yes and no. You are right in saying that DrawArrays is not a fast call, but it is the fastest way of rendering something if you don’t call it often.
Yes, so that you can draw everything with one draw call
Compared to just 4 vertices, I guess you could see it as a memoty waste. But GPU’s are built to render big batches at a time, it will hate you for drawing lot’s of little batches.
Also, you should have more than enough memory to hold the vertices, that shouldn’t be a problem.