libGDX rendering performance

Hi there,

I am currently developing a game where I need to render a lot of dynamic small tiles.
One tile is 6x6px targeting a resolution of 1024x768 resulting in a tile-count of 170x128=21760 tiles.

On the desktop I get a decent framerate of 400fps whereas on my test device (acer a500 tegra2) I only get about 20fps :/.

Keeping in mind that the gamelogic, ki, etc. is excluded in this test, I would be happy with a framerate of about 50fps on the tablet.

I am only! rendering tiles that are visible and there are no unnecessary texture binds involved.

Here is the code that is called for each tile:


	@Override
	public void renderTile(short tileId, int screenX, int screenY) {
		batch.setColor(tileProvider.getTile(tileId).color);
		batch.draw(tileTexture, screenX - tileMap.getTileSize(), screenHeight - screenY - tileMap.getTileSize());
	}

Is there any chance to improve this?

Thanks in advance :slight_smile:

Of course all (all tiles) batch.draw() calls are called between batch.begin() / batch.end().

Check out this thread: http://badlogicgames.com/forum/viewtopic.php?f=11&t=9420
Rendering many tiles requires some optimization

Btw: 6x6 tiles ? why so small D=
never seen anything under 16x16

Hm thank you for the link but I guess caching is no solution to my problem.

The tiles (and that’s why I choosed 6x6 for them) are part of a dynamic sandgame style map.
That means each tile could interact with each other tile at any given moment.

Maybe you would benefit from building your own batcher.

But it sounds more like you need a highly optimized particle system. Or something like this, with some tweaking to work on OpenGL ES:

21,760 tiles is a lot. To break it down; that’s 43,520 triangles, or 130,560 vertices. If each vertex has position, (packed) color, and texcoords, then you are sending 5 floats per vertices, or 652,800 floats to the GPU per frame. Maybe there are some ways you could reduce this. For example; perhaps you could make some of the data static on the GPU.

Also ensure that your problem isn’t coming from setColor or some other part of your code. Do some basic profiling to see what’s up.