Confusion with VAO/glDrawArrays and Frustum Culling

Hey there.

Just to give you all my context: I know that there is A LOT of good engines and libraries out there, like libGDX, JMonkeyEngine, etc. But I’m developing a small personal “engine”, for learning OpenGL.

Now, to the point: Currently, I have a world with ~1050 blocks, and I use a >ImmediateArrayBatcher< class (which extends >Batcher> class with some useful but not important methods) for drawing them, also using a >VertexObject> class behind the scenes.

ImmediateArrayBatcher: http://pastebin.com/sTth55yN
VertexObject: http://pastebin.com/zmu8hpGW

Then, EVERY frame, I’m re-populating the VertexObject buffers and re-calling glDrawArrays() and the other methods on ImmediateArrayBatcher._flush().

I have read a bit about immediate mode, VAOs and VBOs, but I still can’t pull this out to code.

I tested the performance with this ImmediateArrayBatcher and a ImmediateBatcher, which uses the deprecated immediate mode (glBegin, glEnd…), and the FPS was the same (~1050 blocks, ~140 FPS on my machine), even with Frustum Culling.

Then, I came into another problem: I could use display lists, but… what about the Frustum Culling? When in a frame some blocks would not be render, they will not be anymore rendered since they were not rendered on the display list when it was created. Or, even more, I think that only populating the VertexObject buffers one time, and then only calling glDrawArrays() after would cause the same thing.

Also, my blocks are not necessarily 1x1x1: then, I cannot create something like “chunks” for separating display lists for each one.

So, my questions are:

1 - Should I use glDrawArrays() or glDrawElements()? And, if I use the second one, how should I populate my VertexObject class?
2 - As I said before, since I’m using Frustum Culling, I cannot use display lists, and I don’t know how to properly populate the VertexObject buffers and calling glDrawArrays() after. Then, would VAO and/or VBO help me there?

Thanks.

Try to use a Octtree for this: http://en.wikipedia.org/wiki/Octree

You frustum cull against the octree, only drawing the nodes of the tree with actual content that are inside the frustum.

Edit:
A grid could also work, but since you said your ‘objcts’ can be bigger than ‘1’ that probably means that they can overlap the cells of the grid, which might be a problem.