LWJGL Forum

Programming => OpenGL => Topic started by: Blacksmid on June 02, 2011, 18:06:00

Title: Rendering in a thread not possible?
Post by: Blacksmid on June 02, 2011, 18:06:00
Hey,
I've been programming in java for a while now. Now i'm trying to make a 3d game with lwjgl. However, i want a thread to calculate and prepare the display lists for the terrain(infinity terrain). But i got a nullpointerexception. I read that you can't use opengl in 2 diffrent threads, but isn't there ANY way around this?

thanks
Title: Re: Rendering in a thread not possible?
Post by: CodeBunny on June 02, 2011, 21:10:56
I believe you have to share contexts, using a PBuffer or a SharedDrawable. This is what I've been told and seen in the examples, but unfortunately my machine doesn't support context sharing (which is a possible problem with your plan), so I haven't tested it myself.
Title: Re: Rendering in a thread not possible?
Post by: Blacksmid on June 03, 2011, 08:18:07
Hmm but does that mean only one thread can render at the time? Cause that pretty much ruins my plan. I need both threads to be able to access opengl commands at the same time, i want to make display lists for the terain, while the other one is still drawing everything.
Title: Re: Rendering in a thread not possible?
Post by: spasi on June 03, 2011, 10:03:58
No, you can have the main thread doing rendering, while the SharedDrawable or Pbuffer context is creating/updating resources. See org.lwjgl.test.opengl.multithread.BackgroundLoadTest in LWJGL's test package for an example.
Title: Re: Rendering in a thread not possible?
Post by: Blacksmid on June 03, 2011, 14:43:10
Thanks, i got it working. but what's the diffrence between the Pbuffer thing and a Shareddrawable?
Title: Re: Rendering in a thread not possible?
Post by: spasi on June 03, 2011, 17:00:27
SharedDrawable is more lightweight, it's just a GL context sharing objects with the Display context. Pbuffer on the other hand is a context with a framebuffer, so it requires dimensions and a PixelFormat to be specified when creating it. You could specify a 1x1 size, to minimize the extra cost, but it's just simpler to use SharedDrawable. Besides, p-buffers are kinda obsolete these days with Framebuffer Objects, you're better off avoiding them altogether.