Considering OpenGL 2.1 VBOs and 1.20 GLSL shaders:

  • When creating an entity like "Zombie", is it good to initialize just the VBO buffer with the data once and do N glDrawArrays() calls per each N zombies? Is there a more efficient way? (With a single call we cannot pass different uniforms to the shader to calculate an offset, see point 3)
  • When dealing with logical object (player, tree, cube etc), should I always use the same shader or should I customize (or be able to customize) the shaders per each object? Considering an entity class, should I create and define the shader at object initialization?
  • When having a movable object such as a human, is there any more powerful way to deal with its coordinates than to initialize its VBO object at 0,0 and define an uniform offset to pass to the shader to calculate its real position?

1 Answer 1

  1. For dynamic, animated objects reducing draw calls is not that easy as much data is required for each instance. You can pass multiple transformations at once as long as you have constant registers left and use GL_ARB_draw_instanced to let opengl draw the VBO multiple times with an automatically incrementing instanceId that you can use to access the transformations from your uniforms belonging to the current instance. The amount of instances you can draw using this technique is limited by your target hardware and the number of bones of the object. This is a decent method to render a big amount of non-animated dynamic objects too but for this GL_ARB_instanced_arrays is probably better as it allows basically passing an unlimited amount of instances using a second vertex stream with a different frequency (advances once for each instance). But this method will not work for animated data as it is not possible to pass all bones in one vertex. You could use textures thought.

  2. As many objects look differrently and require different shaders I would allow specifying a shader per object and sort the objects before rendering to remove obsolete shader changes.

  3. No. The object could move each frame. The camera could move each frame. All vertices need to be transformed and projected for rendering each frame. Applying a movement in world space is basically free as it is simply added into the transformation the gpu has to do anyway.

  4. I would recommend to extract this into a seperate question. I would probably store an array of all positions, all orientation etc. for all objects into seperate arrays and store one or multiple indices in the typed objects as most of this information is not exclusively required by zombies and some calculations are faster this way. But I'm not very experienced with that design yet.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .