Im at the point in the development of my game where I want to start rendering multiple objects on the screen and update them independently.

There are two concepts I can think of to manage this.

  1. Each layer of my scene i.e. world, entities, player, ui etc has it's own VBO. Every object in every layer gets updated on the CPU, recalculating vertex and UV data based on input or physics, and then re-buffered into the VBO of the layer that object belongs to before the next render cycle begins.

  2. Each dynamic object i.e. entities or npc's that can move independently of any other geometry, gets it's own VBO and I can then use uniforms to have the GPU do the number crunching for input or physics responses.

Option 1 requires the CPU to do a lot of crunching every frame and option 2 creates a lot of vertex buffers with a lot of draw calls.

Perhaps there is a paradigm I'm not aware of or perhaps I'm overthinking the downsides.

Either way the data I've researched so far has been very oriented around "this is an intro to OpenGL, let's get you a triangle on the screen."

Any suggestions on how I should proceed?

  • \$\begingroup\$ What changes do you expect to be making each frame that would demand changing the contents of a vertex and UV data, not just updating a transformation matrix? \$\endgroup\$
    – DMGregory
    Jan 17 at 1:43
  • \$\begingroup\$ Anything I can think of right now would boil down to changing a transform matrix or shifting UVs by a vector, the question is whether or not to do that on the CPU during the update cycle, which would mean less buffering, or to do it on the GPU which would mean individual buffers for individual objects. Either way the objects need to be updated/simulated individually \$\endgroup\$ Jan 17 at 2:04
  • \$\begingroup\$ Usually we'd have one buffer for any geometry that moves together (like say all the polygons in single object or character), and just update a matrix (or collection of bone matrices) for each instance referencing that shared buffer. It sounds like you have something more complicated going on though. What gameplay do you have in mind that involves changing vertices and UVs in this way? \$\endgroup\$
    – DMGregory
    Jan 17 at 2:07
  • \$\begingroup\$ Well it's a 2d topdown rpg, like GB era Zelda or Pokemon. Let's say I have a world vbo for my ground tiles, that's easy. And then my scene has 3 distinct enemy types, each enemy has a roaming routine so they wonder around the scene. I'm thinking I need to either recalculate the vertices for each enemy and then batch them into one buffer, or have a buffer for each enemy and change their positions by passing a transform to the shader. \$\endgroup\$ Jan 17 at 2:18
  • \$\begingroup\$ Why not have one buffer for each enemy type, and then render that buffer multiple times (or in a single instanced draw call) with a transform for each instance of that type? That's how it would normally be done. No need to duplicate all the vertex data if all that's different is the transformation matrix. \$\endgroup\$
    – DMGregory
    Jan 17 at 2:36


You must log in to answer this question.

Browse other questions tagged .