OpenGL & multi-threading...

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

OpenGL & multi-threading...

AlexRNL
Hi there,

I am having some difficulties (concerning JOGL & OpenGL ^^) with solving a problem and I'm not sure which way is the best.

My problem is the following: I have to map a texture on a surface (a square). This texture is built from a BufferedImage that is updated permanently. To avoid obvious performance issues, i'm not building the texture each time i'm going in the draw loop.

So I was thinking of put the method which loads the texture in an other thread which can be called regularly. When I tried to set up a simple TimerTask (just as a test), I had a problem with GLContext. It seems that only one thread may have a GLContext at a time.

My idea was to pre-load the TextureData with a thread (this function doesn't seems to need a GLContext) and notify the OpenGL thread when the texture needs to be refreshed.

So I was wondering if my method for texturing an image (which is updating continuously) was fine or if this is totally nuts (I don't have a lot of experience with OpenGL and JOGL so...). If there is a more appropriate technique to realize that, I'd really like to know about it :)

Thanks in advance for your answer,
Alex.
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL & multi-threading...

Demoscene Passivist
Administrator
If u don't have a lot of experience with JOGL/OpenGL I would suggest using the helper class com.jogamp.opengl.util.awt.TextureRenderer for ur purpose. It encapsulates Java2D rendering (to a BufferedImage) and does the Texture conversion for u.

Regarding ur "partial" updates problem TextureRenderer also comes in handy as it has a markDirty() method wich (in conjunction with getTexture()) is "automatically" capable of doing partial texture updates.

By that u could also avoid ur multithreading problem completly as u could simply do multiple small partial updates inside ur GLEventListeners display() method. E.g. if u only need to update ur image every five frames, then simply update only 1/5th of ur TextureRenderer, thereby also reducing the performance impact of the texture upload to 1/5th.
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL & multi-threading...

AlexRNL
I managed to make it work using the TextureRenderer class !

The result is much better than what i had with my method :)

Thanks!