pioneerspacesim/pioneer — pull request #1507 by fluffyfreak (2012-09-13 15:12:34+00:00)
Title: Vertex cache optimisation and GeoSphere render call reduction

# Purpose
The purpose of this patch is two-fold, first to reduce the number of calls to OpenGL to render parts of an index buffer from 5 to 1 and secondly to make that call closer to being optimal.

## Future work
In future it should be possible to optimise LMR objects with the vcacheopt library

# Method
There are 16 possible configurations that a terrain patch can be rendered in from having all neighbours at lower resolution through to all neighbours at the same resolution.

Because of this we can precalculate all 16 configurations and create index buffers for them, we then choose which index buffer to use based on a patches edgeFriend pointers and render all of the applicable vertices with a single draw call.

Once each of the index buffers has been created it is then optimised, at lower resolutions this makes very little difference but at the higher resolutions the index ordering is substantially different.

# Issues
None, it works fine.

# No really, what's wrong with it?
Oh, ok, so the way I decide how to assign which combination of edges to which index buffer was a bit... "evolved", i.e: there was no intelligent design about it.
So whilst it's a perfectly workable system I'm 100% sure that there's a better way of doing it, it's just there on the tip of my mind I just can't see it clearly yet!
Other than that it really is pretty solid I think :)

# What else? C'mon...
Cripes ok, so the "vcacheopt" part isn't strictly necessary, you could just build the 16 index buffers and not bother to optimise them. The reason I don't just do that is that I started out trying to optimise the buffers using the vcacheopt system and only then did I realise the draw call reduction optimisation.

...that really is eveything though ;)