Login  Register

Re: transfer images from TextureData to a Texture off of the EDT in JOGL

Posted by gouessej on Aug 01, 2014; 8:44am
URL: https://forum.jogamp.org/transfer-images-from-TextureData-to-a-Texture-off-of-the-EDT-in-JOGL-tp4032678p4032680.html

Hi

Most of the answer is in the Java documentation:
This is separated from the notion of a Texture to support things like streaming in of textures in a background thread without requiring an OpenGL context to be current on that thread.
http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/util/texture/TextureData.html

What tag wrote is partially wrong. I confirm that making an OpenGL texture requires to call glTexImage and glTexImage2D. I confirm that obviously these are OpenGL commands. However, executing OpenGL commands requires a current OpenGL context, this isn't specific to JOGL, it would be necessary even though you were using C or C++. JOGL is able to define the thread which accesses to the OpenGL context of the drawable as you can see in the documentation:
http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/opengl/GLAutoDrawable.html#setExclusiveContextThread%28java.lang.Thread%29

You can write your own animator and return the thread you want:
http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/opengl/GLAnimatorControl.html#getThread%28%29

However, as stated in the documentation, it can cause some troubles with AWT which isn't a limitation of JOGL but rather a limitation of AWT and as far as I know, there is NO other Java binding for the OpenGL API providing a very decent support of AWT and Swing, the only other API that comes to my mind is famous to provide a crappy AWT support for more than 10 years for historical reasons (because of some Sun employees who tried to "hide" some private APIs in JAWT).

Moreover, it isn't a good solution but it has nothing to do with JOGL. Making an OpenGL context current on different threads can work reliably with a good driver on some platforms but it isn't guaranteed to work everywhere.

Finally, the second paragraph of tag's comment contains several wise advises with which I agree.

Edit.: Transferring huge images to the GPU is slow and necessary to create textures from them. Splitting them into smaller ones is an option as "tag" suggested.
Julien Gouesse | Personal blog | Website