Jump to content
  • Advertisement
Sign in to follow this  
aregee

OpenGL Handling multiple objects (models) with VAOs and VBOs

This topic is 2077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement


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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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! :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!