I am trying to write efficient code to render a tile based map in android. I load for each tile the corresponding bitmap (just one time) and then create the according tiles. I have designed a class to do this:

public class VertexQuad {

private float[] mCoordArr;
private float[] mColArr;
private float[] mTexCoordArr;
private int mTextureName;
private static short mCounter = 0;
private short mIndex;

As you can see, each tile has it's x,y location, a color array, texture coordinates and a texture name. Now, I want to render all my created tiles.

To reduce the openGL api calls (I read somewhere that the state changes are costly and therefore I want to keep them to a minimum), I first want to hand ALL the coordinate-arrays, color-arrays and texture-coordinates over to OpenGL. After that I run two for loops. The first one iterates over the textures and binds the texture. The second for loop iterates over all Tiles and puts all tiles with the corresponding texture into an IndexBuffer. After the second for loop has finished, I call


whith the corresponding index buffer, to draw all tiles with the texture associated. For the next texture I do the same again.

Now I run into some problems: Allocating and filling the FloatBuffers at the start of each rendering cycle costs very much time. I just run a test, where i wanted to put 400 coordinates into a FloatBuffer which took me about 200ms.

My questions now are:

  • Is there a better way, handling the coordinate and color structures?
  • How is this correctly done, this is obviously not the optimal way? ;)

thanks in advance, regards Markus

  • \$\begingroup\$ OpenGL ES 1.x or OpenGL ES 2.x? \$\endgroup\$
    – Ellis
    Commented Feb 26, 2011 at 14:50
  • \$\begingroup\$ OpenGL ES1 1.x - sorry i forgot to mention that \$\endgroup\$
    – Maecky
    Commented Feb 26, 2011 at 15:01
  • \$\begingroup\$ 200ms for 400 sets of floating point coordinates seems like an incredibly long time. What do your data structures look like? What do the inner loops performing the copy look like? Are you using any of the glGet* API calls? \$\endgroup\$
    – moonshadow
    Commented Feb 28, 2011 at 21:27

2 Answers 2


In OpenGL ES 1.x, you can use several methods:

  • glDrawArrays
  • glDrawElements: TRIANGLES or TRIANGLES_STRIP (denormalized triangles)
  • VBO
  • glDrawTexfOES (you need to verify that you have this extension)

glDrawTexfOES is the faster method to draw efficiently quads but it is not available on old phones. VBO is efficient for static quads. If you use VBO with FloatBuffers, there is a bug on Android 2.2 and 2.1 devices which causes slowness. Use the libgdx.so, to transfert data into VBO for performance. If you use NDK, there is no performance issues.

Your question is not OpenGL ES related but OpenGL Java Wrapping issue.

Ps: in efficient opengl es 1.x engines, you have a tool to batch drawcalls. It is recommanded to limit your drawcalls to 50.

Ps 2: the FloatBuffers is very slow on android devices < 2.3. The libgdx has rewritten this part to speed its engines. You should look this issue.

  • \$\begingroup\$ thanks for your answer, i knew this already - the problem is, that filling the buffer in each cycle needs so much time ;( \$\endgroup\$
    – Maecky
    Commented Feb 26, 2011 at 15:02
  • \$\begingroup\$ You can use libgdx to resolve this issue. \$\endgroup\$
    – Ellis
    Commented Feb 26, 2011 at 15:12
  • \$\begingroup\$ TRIANGLES_STRIP (denormalized triangles) ??? What do you mean by that Ellis? I heard about Degenerated Triangles in regard to Trinagles_strip. Any thing like denormalized triangles too? \$\endgroup\$
    – Ayyappa
    Commented Jul 25, 2011 at 9:56

You don't refill buffers every frame unless it's totally necessary, because this has a great performance penalty (copying data from CPU to GPU is no trivial task).

Create a VBO for each texture type, and fill it once (on map load, or whenever you want) with the data of those tiles. Then, iterate your tile texture array, set the active texture and then draw the corresponding VBO.

Keep in mind that this solution is very inflexible (in case your map changes dinamically), but for static tile maps is the best solution.

  • \$\begingroup\$ Yeah, that's my problem - i want to scroll the map and therefore i run into the described problems. I haven't figured out yet, how to efficiently solve the problem. \$\endgroup\$
    – Maecky
    Commented Feb 26, 2011 at 21:18
  • \$\begingroup\$ Divide your map in square sections, and try to fit a quadtree in there. \$\endgroup\$
    – r2d2rigo
    Commented Feb 26, 2011 at 22:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .