loading texture from 2 different threads

Hi,

Here is my texture loading method:
private static Texture setTexture( String path ){
Texture texture=GLImageLoader.loadOpenGLTexture(path);
if ( texture!=null ){
texture.enable();
texture.bind();
}
return texture;
}

It seems that if I load a texture from a thread that has a GLCanvas then load it again from another thread that has also a GLCanvas, the texturing doesn’t work. Can you do something for me ? - my idea would be to assign a context id to each texture to avoid reloading only if name and context are the same -

[ I need this capability because I have a main window containing the game and sub windows for configurations that need some preview… ]

Cheers,
Bernard.

What do you mean when you say that a given thread has a GLCanvas? The OpenGL context is only current when one of your GLEventListener’s methods like init() or display() is active on the stack. I’m not sure what causes your setTexture() to get called, but if it’s a mouse event or something similar, you should probably set a flag somewhere and call GLCanvas.display(), then check that flag in your display() method and call setTexture().

You can alternatively fetch the GLContext out of the GLCanvas and call makeCurrent()/release() around or in your setTexture() method but I would recommend you look at the approach above first.

Here is how my app is coded:

class MainWindow extends JFrame{
//
GLCanvas mCanvas;
Animator mAnimator;

// Constructor
public MainWindow(){
// Initalize canvas

// Create Animator

// Start animator

}

// Some other stuff

}

class ConfigurationDialog extends JDialog{
//
GLCanvas mCanvas;
Animator mAnimator;

// Constructor
public ConfigurationDialog(){
// Initalize canvas

// Create Animator

// Start animator

}

// Some other stuff

}

Now, in the main function of the game I create a new MainWindow(). This main window has some buttons which are able to create new ConfigurationDialogs.

Here is the problem:
The display function called by the animator from MainWindow need some textures, so I use the JOGL texture loading utility.
But the display function from ConfigurationDialog also need those textures and if they were previously loaded in the MainWindow display function, it doesn’t work.

  • MainWindow and ConfigurationDialog does not know each other and I would prefer not using hacks -

Nothing better than your previous solutions ? ( I’m not sure to understand your 2nd solution )

So, you want to use Textures loaded/bound for one GL context in a different context, is this correct?

If you want to render OpenGL textures loaded in the MainWindow’s OpenGL context from the ConfigurationDialog’s OpenGL context you need to enable sharing of textures and display lists between the two GLCanvases. You can do this by fetching the GLCanvas from the first window created and passing that GLCanvas’s GLContext as an argument to the second GLCanvas’s constructor.