vallentin
vallentin

Reputation: 26157

Render The Same Model Multiple Times

What I'm trying to do, is basically having 1 model which gets rendered multiple times, with different translations and rotations.

So I know how to use Array Buffers and Array Element Buffers (Vertex Buffer Objects), my question is. That now when I've loaded the model into a VBO what would be the best approach if I wanted to render it multiple times with different translations and rotations.

I have 2 theories for how this could be done. (Though I'm asking what would be the best approach).

  1. Load the model into one VBO and then keep calling glDrawArrays and apply the translation and rotation, for each model I want rendered.

  2. Load the model into one VBO multiple times. The same model then gets stored multiple times, which ends up using a lot of memory.

Extra: When doing the 1 way, Quadtrees and/or Frustum can be used which would minimize the amount of models required to be rendered.

Which one of these ways would then be the best to do, if I want high FPS and still save the most amount of memory possible, or is there another approach which is even better?

Just to clarify I'm not asking how to render using VBO's or how to render in general, I'm asking what is the best approach when you want to render the same model multiple times.

Test Model

This is just an image of the test model.

Demo Model

Edit

I'm currently using OpenGL version 4.2.0, and I'm using it on a Windows desktop computer.

Upvotes: 6

Views: 2070

Answers (1)

Michael IV
Michael IV

Reputation: 11436

To minimize draw calls and uniforms transfer you can use glDrawArrayInstanced().This way,you submit as many instances of the original object as you wish in a single draw call!Matrices for each instance you can pack into UBO(uniform buffer object) and access those in the vertex shader per instance with gl_InstanceID

Upvotes: 4

Related Questions