PDA

View Full Version : Using Display Lists to boost FPS in Minecraft-like grid-based world



NewEonOrchestra
04-25-2012, 12:03 PM
NOTE: SOLVED. Sort of.

Hello everyone! First post here. I am developing in Java using LWJGL.

I'm trying to develop a first-person shooter kind of game that uses a grid-based world, such as in Minecraft. Each "block" is 1x1 wide and can vary in height freely. Each block has a top surface and four sides, so five polygons, each polygon containing a 64x64-pixel PNG texture.

My code is set up like this:

A "Tile" is class that is set of five polygons. The drawing step is done at this level.

A "TileGrid" is a 16x16 array of Tiles. (1280 polygons.)

A "TileWorld" is a 2x2 array of TileGrids. (5120 polygons.)

However, if I increase the size of TileWorld to a 4x4 grid (20,480 polygons) the frame rate drops to about 27-28 fps. It normally runs at a steady 60, and I'm hoping to keep it up in that range. I was hoping to permit the game to be able to load up and draw more than that to provide Minecraft's open world feel.

I think using Display Lists will help, but I'm not sure how to go about using them. Every tutorial I've seen so far has been simple, showing off some vertex/polygon code in a list, then calling the draw on the list a bit later.

Should I call a Display list for each individual tile? Would it better to call the TileWorld.draw within a single list?

My computer can handle Minecraft with 64x64 textures easily enough with far more polygons on screen at a given moment, so I don't think it's a hardware matter.

BionicBytes
04-25-2012, 12:43 PM
The answer depends upon the level of granularity you need. Display list represent geometry and or state which does not alter. So you could easily encapsulate certain types of blocks each with its own displaylist.
Just as important however, is how you are culling unseen portions of the world from the camera?

NewEonOrchestra
04-25-2012, 12:55 PM
I was able to increase my fps by having all my tiles being drawn in a list before the main execution loop of my program and then calling the draw list inside it. Now I can load in a 4x4 grid of 16x16 tiles and keep my 60 fps; any higher, though, and I get the performance hit. Much better than before, but I'm hoping for somewhere in the range of being able to draw at least a 7x7 grid with an average fps of 60.

So far I've experimented with backface culling. Some of my polygons have their vertices declared backwards so that the wrong face is culled. However, calling backspace culling on my terrain polygons doesn't alter the frames per second in any noticeable way. The code I've called for calling method is just this:

glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

ZbuffeR
04-26-2012, 03:07 AM
Depending on what is your bottleneck, you can have some gain in roughly drawing front-to-back, to take advantage of early-z optimization. But as you say that backface culling did not help at all, it may provide no gain either.

Does the rendering speed change, when you reduce the rendering window to say 160x100 pixels ?