PDA

View Full Version : glGenVertexArrays returns 0 without glError in worker-thread?



yousry
05-16-2013, 01:32 AM
To change the scene-graph during runtime I'm using several working threads which disable the render-loop and update the gl-context (load/unload shaders / replace buffers etc.) e.g.

stop render-loop
get context
update
continue render-loop

If I try to generate a vao in a worker thread with:

glGenVertexArrays(1, &vaoId);

vaoId (the vertex array name) is 0 and glGenVertexArrays doesn't cast any error message.

I use a library for the gl-context processing but the code looks like this:

glXMakeCurrent(_glfw.x11.display, window->x11.handle, window->glx.context);

This behaviour isn't described in the SDK documatation about glGenVertexArrays.

I'm using a 3.2 core context (also tested with 4.3). My actual workaround would be to create a name-heap at startup and manage them by myself instead of using the gl-Is and gl-delete functions.

Alfonse Reinheart
05-16-2013, 01:52 AM
There's really no point in threading this like that. If you're using the same context, then shutting down the rendering thread is ultimately no different from simply letting the rendering thread do all of this stuff itself.

So just do it in the rendering thread, as a post-rendering operation. Either that, or make a new, shared context. But that won't help you, because VAOs are container objects and therefore are not shared.

yousry
05-16-2013, 02:07 AM
There's really no point in threading this like that. If you're using the same context, then shutting down the rendering thread is ultimately no different from simply letting the rendering thread do all of this stuff itself.

So just do it in the rendering thread, as a post-rendering operation. Either that, or make a new, shared context. But that won't help you, because VAOs are container objects and therefore are not shared.

Could you explan why vao creation doesn't work within a differen thread, if the context is current?

Update: The difference is a introduction of thread-lock this is bad if you use services for example.

yousry
05-16-2013, 04:54 AM
To answer my own question:

Enabling the current context in one thread doesn't disable it on another.
So I have to notify the renderloop (via semapohre) to give up the context (= NULL) before the new thread can claim it.

To reply Reinhearts suggestion:
I actually try to remove this synchronous and a-synchronous dispatching as much as possible. It is complicated and slow.