On Fri, Feb 15, 2013 at 10:36 AM, Lord Anton Hvornum <[email protected]>wrote:
> As for *GL applications not being able to render things in different > threads, i'm aware of the fact that this is normally how it's done because > it will cause major graphical errors if updated in the wrong time etc, but > technically it's possible so there for, it should be doable :) > It is certainly possible to render things on different threads, but only one thread at a time may render into a single context. See http://www.opengl.org/wiki/OpenGL_and_multithreading -- To make your original example work, you need to call pyglet.gl.Context.set_current()<http://www.pyglet.org/doc/api/pyglet.gl.Context-class.html#set_current> to make the context active *each time you switch threads*, which means that you need to wrap each OpenGL drawing operation (and by extension, pretty much all of pyglet's functionality) with a mutex, to prevent both threads from attempting to access them at the same time. At this point you will indeed be rendering in two threads, but only one of them at a time, so you don't buy any performance this way (you could just as well perform non-OpenGL work on the secondary thread, and post the results back to the main thread for rendering). And between the overhead of context switches, mutexes and set_current(), you'll may well be sacrificing performance. -- You can also, as Peter says, create a second context that shares resources with your main context. This will allow you to load textures, display lists, buffers and shaders in one context, and then use them from the other. But you can't actually render from both contexts - only the primary one is connected to the display surface. This method used to often be used to load large textures into the GPU asynchronously, but it has pretty much been superseded by using a PBO to make the initial transfer to the GPU<http://www.songho.ca/opengl/gl_pbo.html#unpack> . -- Tristam MacDonald Software Development Engineer, Amazon.com http://swiftcoder.wordpress.com/ -- You received this message because you are subscribed to the Google Groups "pyglet-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/pyglet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
