Jump to content
  • Advertisement
Sign in to follow this  
MarkS

Simple glGenBuffers question. I should know this...

This topic is 2561 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

I've looked at various references to glGenBuffers and cannot find the answer. Is it necessary to call glGenBuffers with the number of VBOs I intend to use, or can I call it as needed? The official references are unclear on this and most assume that a certain number of VBOs will be set up first. I need to create VBOs dynamically, and I have no way of knowing the total number early.

This is for a tile engine. The tile map is composed of layers, with each layer having its own VBO. There is no way of knowing how many layers are needed and it is possible that the number can change, so calling glGenBuffers(any_large_amount,&VBO); will not work.

[edit]

Another question. In the tile layer class' copy constructor, is it safe and/or valid to simply copy the value stored in the VBO to the new object? It would seem so since the VBO is just an integer and not a pointer, but I want to make sure. There isn't a copy function for VBOs.

Share this post


Link to post
Share on other sites
Advertisement
Yes, it is completely valid to call glGenBuffers multiple times, as long as you call equal amounts of glDeleteBuffers at some point in the future.

Yes, you can copy the value as long as you have not deleted the buffer prior. When you create a vertex buffer object, you are only given a buffer identification number (ID) to work with that is valid until you delete the buffer.

Share this post


Link to post
Share on other sites

Yes, it is completely valid to call glGenBuffers multiple times, as long as you call equal amounts of glDeleteBuffers at some point in the future.

Yes, you can copy the value as long as you have not deleted the buffer prior. When you create a vertex buffer object, you are only given a buffer identification number (ID) to work with that is valid until you delete the buffer.


Thanks. That is what I was thinking, but there just isn't anything specific to this in any references I could find. I would hate for this to work under one implementation and not another. Right now I am developing on an nVidia platform, but their OpenGL implementation is notoriously flawed. Just because it works for me doesn't mean it would work on an AMD/ATi-based system. I hate guessing.

Share this post


Link to post
Share on other sites
Does the documentation say you can't call glGenBuffers multiple times? If it doesn't put a restriction, then there is none. There is no need for them to mention that you can call it multiple times.
In fact, you can call any GL function multiple times.

Also, be sure to use glGetError() for error checking.

Share this post


Link to post
Share on other sites

Does the documentation say you can't call glGenBuffers multiple times? If it doesn't put a restriction, then there is none. There is no need for them to mention that you can call it multiple times.


That is not how my mind works. The function seems to be written to allocate a batch of IDs. The documentation is written to support that and there is nothing stating that it can be called multiple times. With me being unfamiliar with what is going on behind the scenes and no documentation stating otherwise, I feel it is pretty safe to assume that the intent of the function is to be called once. As such, I could see it assigning the same ID multiple times if called multiple times. Unlikely, but entirely possible and undocumented. I'd rather be safe than sorry. Again, knowing how poor nVidia's OpenGL implementation is, I cannot assume that just because it works for me means it is correct for OpenGL. This makes testing really very difficult. I need an AMD/ATi system...


Also, be sure to use glGetError() for error checking.



Absolutely!

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!