PDA

View Full Version : Dynamically generating buffers during runtime



Chris3D
09-18-2012, 09:04 AM
Hi folks,

is there a workaround for using glGenBuffersARB/glGenBuffers and such calls while rendering? I know they only work in the initialization before the first render call. Is there a command to halt the rendering, so I can call these functions? Or a similar trick?

Background: I'm trying to create textures at runtime, because my app is receiving those textures from an external source, the number of textures is not known and may change during runtime while other stuff is being drawn.

Your help is greatly appreciated,
Chris

Alfonse Reinheart
09-18-2012, 09:08 AM
is there a workaround for using glGenBuffersARB/glGenBuffers and such calls while rendering? I know they only work in the initialization before the first render call.

Says who? There's no limitation on when you can generate objects. Though generally you should avoid doing so for performance reasons in the middle of your render loop, there is no reason why you can't.

If you're having problems with this, that's likely due to either an incredibly buggy driver or user error.

Chris3D
09-18-2012, 09:11 AM
I never had success calling glGenTextures(1, &m_textureID); in the rendering loop or from another thread, it would not set the value m_textureID.. I doubt its the driver, so it must be me.. any suggestions?

thokra
09-18-2012, 09:20 AM
Though generally you should avoid doing so for performance reasons in the middle of your render loop[..]

Chris3D: To work around this, you could simply implement some observer-like approach. For instance, pass a callback to the external source (if you can) which will only be invoked if there are actual changes to the amount of textures etc. Threading issues are, of course, to be dealt with as well. Another solution would be to poll the external source to see if there are actual changes to be considered in the rendering loop before doing texture related work.

As usual: Any GL errors when calling glGenTextures()? Care to share some code?