Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 769
vallentin Avatar asked Aug 26 '13 09:08

vallentin


1 Answers

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

like image 194
Michael IV Avatar answered Sep 30 '22 13:09

Michael IV