To simplify managing multiple types of data with different shaders and textures, I thought about creating a generic Scene
object (is there a name for this?) which would allow me to pre-configure how I want to render something, and how the data changes. Let me give an example:
Everything below is in the context of a 2D top-down game
- Some parts are completely static, e.g. the background, and their geometry never changes.
- Then there'd be a "NPC" layer, which can change on almost every single frame, uses different shaders.
- Last but not least, there's a UI layer, which sits on top of everything else.
Some of these parts would probably be split into multiple subparts, such as parts rendered as GL_TRIANGLE_FAN
, and other parts rendered as GL_LINE_STRIP
, etc. To avoid duplicating lots of setup/generate geometry/render phases, it would seem logical to wrap this in something that can be configured, such as:
Scene s;
Batch b1 = s.create_batch(somehow_specify_shaders_etc);
generate_background_geometry(b1);
Batch b2 = s.create_batch(somehow_specify_other_shaders_and_VAO);
// game loop
while (true) {
// this would generate/update the NPC geometry on the fly
b2.process_input(gather_user_input());
for (Batch b: s) b.render();
}
Now what if I wanted to specify different texture bindings for each batch? Or different shaders?
Is there a general pattern for managing geometry data like this?