I've started working on a 2D tile rendering system. So far it draws 8x8 tiles on the screen. At 640x480 resolution, there can be up to 4941 tiles on screen at a time, and the number quickly increases at higher resolutions. I'm looking for an efficient way to render them all.Attachment 2672

Additionally, each tile will be a solid color. On the application side, I have a vec4[MAX_COLORS] storing each color and I send an int colorIndex to each instance.

I'm using instanced rendering right now, but several things about my approach make me wonder if it's inefficient. I'm storing the colors in a uniform in the vertex shader, which I realize isn't the best way. I'm just getting the hang of openGL so I'm also not sure if instanced rendering would be the method here. Here's the relevant code:

Other approaches I've considered:
Drawing the tiles:
- Draw the static tiles as point sprites
- Just send the tile's color to each instance.
- Perhaps there's a way to connect all the static quads into one large quad, and just render that?

For storing all the colors, I'm thinking either a 1D texture array or an ssbo.

So my question is, for upwards of 20,000 tiles (at higher resolutions), is this method sufficient, or is there a better way to handle this?
Thanks

02-15-2018, 02:17 PM

Cornix

This number of triangles is so trivially low, that it will probably not really matter with todays hardware. Especially if your triangles dont overlap. What is way more important than the number of triangles is the number of fragments that are actually drawn. If you draw millions of tiny triangles it will be much faster than drawing a couple thousands of screen filling triangles.
For the situation you have described a simple VBO with the position and color data should be more than adequate. But I would guess that even with immediate mode you would still get a good enough frame rate in your situation.

02-15-2018, 03:37 PM

mhagain

I'll second the above; even immediate mode - just make sure you have a single glBegin/glEnd pair rather than thousands of them - may well be fine, and is often an optimal path for dynamic data (if that's what you have).