zahirtezcan's picture

Multiple-threaded issue

I am trying to build up a multi-threaded opengl environment with command dispatchers and stuff, but here i want to demonstrate a simple case which has the same issue as i have. This demo will show up a bluish screen having a white triangle on upper left side. I initiate a thread for objects (buffers/arrays/programs...) for which the context sharing is enabled, then I render on the main thread.

The problem is on main thread BindVertexArray causes an error with code InvalidOperation. I have tested BindBuffer, BindTextureetc. on my other application, and they are no problem. Even UseProgramis not an issue.

I am using an ATI 4650, forward compatible context with version 3.2 (output window shows both contexts are initiated successfully)

I have attached the simple project with two configurations Debug and Debug-Threaded. Debug version uses main thread for initialization and it shows the window successfully, but threaded version fails on my computer. Is there anything that I am doing wrong or is this a driver issue?

AttachmentSize
SimpleMultithreaded.zip12.11 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Vertex Array Objects are not sharable between contexts.

Quote:

This extension differs from GL_APPLE_vertex_array_object in that client
memory cannot be accessed through a non-zero vertex array object. It also
differs in that vertex array objects are explicitly not sharable between
contexts.

http://www.opengl.org/registry/specs/ARB/vertex_array_object.txt

zahirtezcan's picture

Thanks for the reply. I missed that my bad

zahirtezcan's picture

can you try the code on an nvidia card? at work (quadro card, no problem during multiple sharing context initialization) i tried this and has given InvalidValue at GL.UseProgram line in main thread. which was not an issue for my ati card

Hortus Longus's picture

Here at work on my NVidia Geforce 8500 GT I have no errors; I see a window titled "Simple", which has a lightblue background and is empty, but it eats 95% corepower of both processors.

the Fiddler's picture

It reduce CPU usage, add calls to System.Threading.Thread.Sleep() to all threads as necessary. In the main thread, you can enable vsync, instead (VSync = VSyncMode.On).

Note that you might have to use GL.Flush() or GL.Finish() to sync the background thread with the foreground thread. The InvalidProgram could be the result of a race condition (the program hasn't been created yet).

zahirtezcan's picture

:Hortus Longus
there should be white triangle on the screen, which means your version did give same or similar error but you are either using OpenTK release dll or you do not stop on exceptions.

:theFiddler
Actually i have got synchronization with a .net WaitHandle, though it might still be a sync issue such that for given OpenGL command it might not take effect on server immediately, ill try to sync with OpenGL server too.

zahirtezcan's picture

I have tried Flush/Finish and even FenceSync/WaitSync (I might have have fail on this) but those were no help.