Jump to content

  • Log In with Google      Sign In   
  • Create Account


Handling multiple objects (models) with VAOs and VBOs


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 aregee   Members   -  Reputation: 795

Like
0Likes
Like

Posted 14 February 2014 - 04:15 AM

Having scrapped everything I know about OpenGL, I think I finally have got the grasp on a few of the deal breaking difficulties of "modern" OpenGL.  I can now make a shader from scratch, compile, and connect inputs and outputs and make uniforms to scale, rotate or transform an object.  I have also struggled a bit understand VAOs and VBOs, and how they are connected, but I think I am starting to grasp the concept now.

 

My project is to make a very simple 3D editor.  That sort of makes the data dynamic, although the data in a different setting most likely will be static.  That makes me philosophise a bit about how to organise the objects (models) that you can make in the editor.  I want an as efficient way to handle objects as possible.

 

I have been thinking about three methods:

 

1. One oversized buffer object to handle incoming vertex (color, etc...) data.

2. One VAO, then one VBO for each object.

3. One VAO for each object.

 

I don't like option 1.  I don't like to guesstimate, or the complications that will arise when you fail on your estimate, then need to rebuild buffers or handle removal of objects, etc.  I like to allocate just the right amount of buffer that I need to hold my data, and I want a structure that makes it easy to organise a list of objects.  Besides, I am picturing a tree structure in my head.  That is what I desire.  (Or just a linked list to begin with.)

 

Option 2 is the one I actually prototyped.  That didn't work.  All I got to screen was the last object, no matter what I did.

 

Option 3 is the one that I have come to understand is the way to go.  I don't oppose to this option.  It is much better than 1, but it will incur state changes that I don't need.

 

I actually want to go for option 2.  Is that possible?  Can anyone tell me the exact steps needed for this to work, if it works at all?  If not, I will just implement option 3.  I have already tested that scenario, and it works.



Sponsor:

#2 Juliean   GDNet+   -  Reputation: 2246

Like
2Likes
Like

Posted 14 February 2014 - 05:00 AM


Option 3 is the one that I have come to understand is the way to go. I don't oppose to this option. It is much better than 1, but it will incur state changes that I don't need.

 

Can you elaborate on what unneeded state changes this will incur? You bind the VAO and then the VBOs for each object once when they are loaded, and from then on all you need to do is set the correct VAO and the object can be drawn. One VAO is not possible since when you bind another VBO to the same attribute location it will overwrite the previous one, so one VAO per Object is the way to go. Batching (as in your option 1) is a viable option though, its mostly used to increase performance.



#3 aregee   Members   -  Reputation: 795

Like
0Likes
Like

Posted 14 February 2014 - 05:13 AM

I think you answered my question.  Regarding state changes, I am thinking about the overhead by switching between VAOs.  Maybe most of that cost is incurred when you initially set it up, so it is negligible when you do the actual rendering?  Thank you for the answer.  That gives me a little bit more to go on understanding how everything is connected.



#4 Juliean   GDNet+   -  Reputation: 2246

Like
1Likes
Like

Posted 14 February 2014 - 05:23 AM


Regarding state changes, I am thinking about the overhead by switching between VAOs. Maybe most of that cost is incurred when you initially set it up, so it is negligible when you do the actual rendering?

 

Yes, most of the "overhead" happens on setup, and thats where arguably you don't have to worry about it for rendering speed. Actually, without VAOs you'd have to do all that setup once per frame, and thats why they are very handy. I don't know the implementation details, but I quess they are a lot faster then doing VBO-binds and vertex attrbiute definitions for each object, so don't worry.



#5 Hodgman   Moderators   -  Reputation: 27892

Like
2Likes
Like

Posted 14 February 2014 - 05:42 AM

Ironically, I've seen some other benchmarks that showed that reusing a single VAO (continually reinitializing it) was actually faster than pre-initializing many of them and then just switching between them... This of course depends on the driver, and GL drivers can be weird.

You can mix 2/3 with 1 to get a hybrid. Say you're loading 3 models at once that you know are required for the duration of the level -- they could potentially all put their different attribute streams into different offsets within the same VBO allocation.

#6 aregee   Members   -  Reputation: 795

Like
0Likes
Like

Posted 14 February 2014 - 06:44 AM

Ironically, I've seen some other benchmarks that showed that reusing a single VAO (continually reinitializing it) was actually faster than pre-initializing many of them and then just switching between them... This of course depends on the driver, and GL drivers can be weird.

 

That makes me even more curious about the inner workings of the implementation.  It strongly hints at fundamentally different approaches to implement GL drivers at different vendors to achieve the same result.  I wonder if anyone has done benchmarking of drivers on comparable hardware, if that is at all feasible.  Not that it has any practical value, as the overall performance is what really matters.



#7 aregee   Members   -  Reputation: 795

Like
0Likes
Like

Posted 14 February 2014 - 10:55 AM

Made it!  Rendering 10000 "VAOs" that really is just one random triangle each, with ok performance on my slow computer:

 

opengl0001.png

 

Now to load some real models instead of random data.  Thanks for help! :)






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS