PDA

View Full Version : Confused about the number of draw calls



chickens
11-28-2014, 04:26 AM
Hello everyone. I am starting to learn about OpenGL (and English, sorry about my bad English :) ). Can you please tell me if my understanding about OpenGL is correct?

1) Send vertex data which has information about position, colour, uv data etc etc.

2) Make a shader program using a fragment and vertex shaders (lets forget that others exist for now :D ).

3) Bind the shader program and the data and do a draw. something like glDrawArrays() )

And for every image we have on screen we do the steps 1 2 and 3.

So in case we have a game where we have something made out of different images, for example the game I'm playing now is Braid, in Braid you have the cliffs, which are drawn using several different images. Let's imagine a game has like 1000 separate images that we need to show our user. So are we going to do steps 1 2 and 3, 1000 times ?

jonasstrandstedt
11-28-2014, 06:54 AM
In principle yes, you have to do it a thousand times if you want to display it a thousand times. There are stuff you could do to optimize, for example you could use glMultiDrawArrays to render multiple objects in one draw call. Depending on exactly what you want to do there would be different answers, but in short, if you want to draw 1000 images, then you have to do the operations you described a thousand times.

Edit:
But you don't have to initialize the buffer objects and rebuild the shader programs all the time, only the draw calls.

Cornix
11-28-2014, 09:07 AM
You can use the same shaders for various rendering operations.
If you want to show 1000 images but they all use the same kind of information you only need a single shader.

You can also draw all 1000 of them at once with a single draw call if you store the information for all of them in one large VBO.


There are numerous ways to do the same thing. I would recommend going with the most simple design first and changing it up as you notice performance problems.

chickens
11-28-2014, 12:29 PM
Thanks very much for the answers. I really appreciate it.