Posted by
LordSmoke on
Aug 10, 2016; 10:31pm
URL: https://forum.jogamp.org/Hello-and-Error-incorrectly-used-with-a-different-GLContext-tp4036820p4037047.html
It has been a while, and I have been working on this problem as time permits, so I think it is time to check in.
I have been reading OpenGL Programming Guide 8th Ed., but so far that seems mostly geared toward the actual plotting of things. That is working fine for me. My problem is with switching between JTabbedPane panels, and there seems to be precious little detail on the use of shared contexts.
I suspect my problem is a lack of theoretical understanding and not just a coding error, so any advice as to where to turn or sources of additional material, examples, etc on the use of shared contexts/autodrawables would be appreciated.
What I have done
(following
https://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/GLSharedContextSetter.html)
is:
1) Created a class to generate a GLAutoDrawable and functions to return that and other things as required by the example code.
2) I then pass this into my panel constructor and use it with my GLCanvas constructor:
public My_CanvasManager(My_SharedAutoDrawable sGLAD) {
if (sGLAD==null) {
GLCapabilities capabilities = new GLCapabilities(GLProfile.getMaxProgrammable(true));
GLCapabilities(GLProfile.getMaxProgrammable(true));
canvas = new GLCanvas(capabilities);
} else {
canvas = new GLCanvas(sGLAD.getGLCapabilities());
canvas.setSharedAutoDrawable(sGLAD.getSharedAutoDrawable());
}
3) I then set up a change listener for the JTabbedPane that then casts the value returned by getSelectedComponent(), queries if it has a GLCanvas, then calls a function to set the Shared AutoDrawable:
jTabbedPane_MainPane.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
System.out.println("Tab: " + jTabbedPane_MainPane.getSelectedIndex());
My_JPanel sljp = (My_JPanel)jTabbedPane_MainPane.getSelectedComponent();
if (sljp.getHasGLCanvas()) {
sljp.activateGL(sGLAD.getSharedAutoDrawable());
}
}
});
All of this works fine moving from one new panel to the next, but backing up to one that was earlier selected gives me:
Exception in thread "AWT-EventQueue-0" com.jogamp.opengl.GLException: Caught GLException: This GL object is being incorrectly used with a different GLContext than that which created it on thread AWT-EventQueue-0
Might someone care to point me in the right direction?