Generate hex grid in a single mesh

Started by nickbrickmaster, October 22, 2013, 20:45:55

Previous topic - Next topic

nickbrickmaster

I'm trying to make a hexagonal grid for a RTS game, and the way I originally intended to draw the grid, it was causing terrible lag because each hex tile was a separate Render object, and those are called in a loop. The way I now think is the best is to make each tile part of a larger Render call, except I don't know how to generate the vertices and indices like this efficiently. If anyone could help that would be great.

Cornix

How many triangles are you rendering right now? Most of the time the issue is not the mesh but the way you render things.
With a somewhat new card you should easily be able to render hundred thousands of triangles per frame with steady 60 frames per second.
With my, now 4 years old, I get 1.5 million triangles with steady 60 frames per second.

nickbrickmaster

It's much less than that. A couple thousand, max.

Cornix

How do you draw? Immediate mode? (that is glBegin(...) {...} glEnd())
It is generally much faster to use either Display-Lists or VBO's for static portions of the game which terrain usually is. Even if it changes regularily VBO's can still be much faster then immediate mode.

You should also keep in mind to switch textures and shaders as little as possible. Try to sort your draw calls by texture and shader and batch them together. Each time you switch a texture or shader it costs you dearly in performance. In my tests is switching shaders is far worse then textures, but I dont know if this is true on all hardware.
You might want to use a texture atlas instead of having separate textures for each tile-type. (basically having all textures in one big image)

You might also want to try drawing the hexagons as quads with transparent corners.

nickbrickmaster

I'm drawing by generating vertices/indices in the constructor and then using glDrawElements to draw. I'm not sure what to call that.
I'm not texturing them yet, but when I am I will make sure to use a texture map.
I'll try messing with the drawing a bit to remove the switching of shaders.

Cornix

Maybe you would like to show your code.