Hey, im working on engine for future game and i stumbled on a problem. I'm not sure how to efficiently manage (mostly store and send to GPU) data of my level geometry.
Game will be with Top-Down camera (3D), so visibile area will be reduced, also most of objects will be pretty low-poly since nobody needs extra sharp(/smooth) models if u barely can see some details on it. ;) Problem is that i'm not sure how to store it, (update if needed* - though geometry is static, just what is visible) and send to GPU.
I've come up with some ideas:
1. Most basic - load everything right in one VBO (as models are very low-poly it won't have too much data as you might think?).
I think that though vertex shadders will work on every vertex, fragment shaders will work only on visible fragments and "discard" others automatic, right?
+ simple to write
+ dont have to bind multiple VAOs/VBOs/textures every frame
+ don't have to send new data every frame to GPU (using CPU time) and compute it!
- lot of data is on VBO (though size won't change during game) and will go through Vertex Shader (i think not by F.S. - right?)
- it seem's not so optimized?
- everything must be in one texture atlas which limits possibilities
2. Load every distinct object at startup of level, and then every frame create new VBO with new mesh, that would be made from objects that are currently visible at scene (modified with transformation matrix so that it all works ok).
+ it sounds as its an optimization ;p (but after some thought i'm not so sure)
+ i manage what i send to draw, so i could do some work (like LOD, though not in that kind of game, becouse all models are usally at same distance from camera...) so it's not actually "pro" per se...
+ i bind one VAO/VBO after creating that whole scene's mesh and dont change it for frame.
+ only visible vertexes (objects, somevertex might be little out of course) are sent to GPU
- loooooot of work on CPU, which may result in: GPU waits for CPU data ..... CPU waits for rendering by GPU ... and again GPU waits...
- looks much more complicated to build efficiently (at least as much as can)
- everything visible must be in one texture atlas...
3. Split level on smaller areas like 2D-tiles, each tile contains every object's data that is (at least partial) in this tile. Just not too small tiles, so that per visible scene there would be 3x3 or 4x4 tiles max. (or even 2x2?).
+ sound pretty fast (only needed data, not many VAO/VBO binds per frame, VAO/VBO would be already set-up at loading-time so no computing time needed per frame, only draw call).
+ somehow more flexible with textures, becouse i need current texture only for small tile which can be only couple meshes.
- seems hard to code it efficient, some problems (look below)
- some meshe's that would be on more than one tile would have to be doubled or splitted (not easy job i guess to do it right and fast! doubled seems better somehow)
- lot of pre-processing so as long as #1 pre-processing or even longer.
4. Render each object separate. If it's visible multiple times, render it using some kind of mechanism to do it efficiently like instancing (or something else? suggestons? i dont know instancing yet, but i heard of it).
+ normally it may be common way to render scenes (when meshes have many triangles its ok, becouse switching vbo doesnt cost so much then)
+ easiest to implement
+ easy to manage scene
+ easy to create a scene (just add description of mesh - pos/rotate/scale and which object it is just to add it).
+ i could create VAOs/VBOs earlier so no computing time needed on CPU side every frame
+ only visible models would be rendered
- lot of switches between every objects (maybe not that much, but when meshes are low-poly, i guess switching would take long time compared to rendering)
- it doesn't seems too optimized.
As i said, mostly i'd like to balance between complexity and performance, since i'm not working on some top-level, AAA project, just smaller project that may be very playable, may not ;)
PS. Could someone write in some order or with "weights" how much OpenGL actions cost (about)? Like: single draw call, bind VBO, bind VAO, bind texture, etc... so i'd knew what to watch for