JOGL multithread / GLContext

How to use multithread in JOGL ?
I want to load texture and “display” in 2 threads.

How to use GLContext.makeCurrent() .release() .setSynchronized() ?

I’m using a GLCanvas and an Animator.

TY

The easiest and safest route is to load the texture data in another thread, and then send the data to the graphics card in your your GLEventListener.

Doing multithreading with OpenGL is risky business.

i found a trick to use multithread :

in my GLCanvas/GLEventListener :


	public void init(GLAutoDrawable drawable)
	{
		this.getContext().setSynchronized(true);
		this.thread.start(); // start a "texture loading" thread
	}

load a texture :


	public PViewerSubImage(BufferedImage subImage, Rectangle rect, PViewerTab tab) throws GLException, IOException
	{
		tab.getContext().makeCurrent();
		this.texture = AWTTextureIO.newTexture(subImage, true);
		tab.getContext().release();
		
		System.out.println(rect);
	}

setSynchronized() makes makeCurrent() synchronized
makeCurrent is implicitly called before display()