diff options
Diffstat (limited to 'src/test/com')
11 files changed, 141 insertions, 110 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java index 44ff2d20b..c899a310f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java @@ -108,7 +108,7 @@ public class TestSharedContextListAWT extends UITestCase { final Gears gears = new Gears(vsync ? 1 : 0); if(useShared) { - gears.setGears(sharedGears.getGear1(), sharedGears.getGear2(), sharedGears.getGear3()); + gears.setSharedGears(sharedGears); } glCanvas.addGLEventListener(gears); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java index 6f8d6c626..38b3f92ff 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java @@ -99,7 +99,7 @@ public class TestSharedContextListNEWT extends UITestCase { final Gears gears = new Gears(vsync ? 1 : 0); if(useShared) { - gears.setGears(sharedGears.getGear1(), sharedGears.getGear2(), sharedGears.getGear3()); + gears.setSharedGears(sharedGears); } glWindow.addGLEventListener(gears); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT2.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT2.java index 16467771d..7f5d50323 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT2.java @@ -100,7 +100,7 @@ public class TestSharedContextListNEWT2 extends UITestCase { final Gears gears = new Gears(vsync ? 1 : 0); if(useShared) { - gears.setGears(sharedGears.getGear1(), sharedGears.getGear2(), sharedGears.getGear3()); + gears.setSharedGears(sharedGears); } glWindow.addGLEventListener(gears); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java index f1c72cf57..855dc9cc6 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java @@ -127,7 +127,7 @@ public class TestSharedContextVBOES1NEWT extends UITestCase { final GearsES1 gears = new GearsES1(vsync ? 1 : 0); if(useShared) { - gears.setSharedGearsObjects(sharedGears.getGear1(), sharedGears.getGear2(), sharedGears.getGear3()); + gears.setSharedGears(sharedGears); } glWindow.addGLEventListener(gears); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT0.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT0.java index eeab0869a..54f60f576 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT0.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT0.java @@ -128,7 +128,7 @@ public class TestSharedContextVBOES2NEWT0 extends UITestCase { // 2nd // final GearsES2 g2 = new GearsES2(0); - g2.setSharedGearsObjects(g1.getGear1(), g1.getGear2(), g1.getGear3()); + g2.setSharedGears(g1); final GLWindow f2 = runTestGL(animator, f1.getX()+width+insets.getTotalWidth(), f1.getY()+0, g2, f1); final GLContext ctx2 = f2.getContext(); @@ -149,7 +149,7 @@ public class TestSharedContextVBOES2NEWT0 extends UITestCase { // 3rd // final GearsES2 g3 = new GearsES2(0); - g3.setSharedGearsObjects(g1.getGear1(), g1.getGear2(), g1.getGear3()); + g3.setSharedGears(g1); final GLWindow f3 = runTestGL(animator, f1.getX()+0, f1.getY()+height+insets.getTotalHeight(), g3, f1); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT1.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT1.java index e98957464..2c547ec06 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT1.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT1.java @@ -142,7 +142,7 @@ public class TestSharedContextVBOES2NEWT1 extends UITestCase { final GearsES2 gears = new GearsES2(vsync ? 1 : 0); if(useShared) { - gears.setSharedGearsObjects(sharedGears.getGear1(), sharedGears.getGear2(), sharedGears.getGear3()); + gears.setSharedGears(sharedGears); } glWindow.addGLEventListener(gears); @@ -171,7 +171,7 @@ public class TestSharedContextVBOES2NEWT1 extends UITestCase { return glWindow; } - // @Test + @Test public void test01CommonAnimatorSharedOnscreen() throws InterruptedException { initShared(true); final Animator animator = new Animator(); @@ -204,8 +204,46 @@ public class TestSharedContextVBOES2NEWT1 extends UITestCase { releaseShared(); } - // @Test - public void test02CommonAnimatorSharedOffscreen() throws InterruptedException { + @Test + public void test02EachWithAnimatorSharedOnscreen() throws InterruptedException { + initShared(true); + final Animator animator1 = new Animator(); + final Animator animator2 = new Animator(); + final Animator animator3 = new Animator(); + final GLWindow f1 = runTestGL(animator1, 0, 0, true, false); + final InsetsImmutable insets = f1.getInsets(); + final GLWindow f2 = runTestGL(animator2, f1.getX()+width+insets.getTotalWidth(), + f1.getY()+0, true, false); + final GLWindow f3 = runTestGL(animator3, f1.getX()+0, + f1.getY()+height+insets.getTotalHeight(), true, false); + + try { + Thread.sleep(duration); + } catch(final Exception e) { + e.printStackTrace(); + } + animator1.stop(); + animator2.stop(); + animator3.stop(); + + f1.destroy(); + f2.destroy(); + f3.destroy(); + Assert.assertTrue(AWTRobotUtil.waitForVisible(f1, false)); + Assert.assertTrue(AWTRobotUtil.waitForRealized(f1, false)); + Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f1, false)); + Assert.assertTrue(AWTRobotUtil.waitForVisible(f2, false)); + Assert.assertTrue(AWTRobotUtil.waitForRealized(f2, false)); + Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f2, false)); + Assert.assertTrue(AWTRobotUtil.waitForVisible(f3, false)); + Assert.assertTrue(AWTRobotUtil.waitForRealized(f3, false)); + Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f3, false)); + + releaseShared(); + } + + @Test + public void test11CommonAnimatorSharedOffscreen() throws InterruptedException { initShared(false); final Animator animator = new Animator(); final GLWindow f1 = runTestGL(animator, 0, 0, true, false); @@ -238,7 +276,7 @@ public class TestSharedContextVBOES2NEWT1 extends UITestCase { } @Test - public void test03EachWithAnimatorSharedOffscreen() throws InterruptedException { + public void test12EachWithAnimatorSharedOffscreen() throws InterruptedException { initShared(false); final Animator animator1 = new Animator(); final Animator animator2 = new Animator(); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT2.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT2.java index fb09e86ef..a66aaf9d8 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT2.java @@ -33,11 +33,9 @@ import java.util.List; import com.jogamp.newt.opengl.GLWindow; import javax.media.nativewindow.util.InsetsImmutable; -import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLContext; import javax.media.opengl.GLProfile; -import javax.media.opengl.GLRunnable; import com.jogamp.opengl.util.Animator; import com.jogamp.opengl.test.junit.util.AWTRobotUtil; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java index 3fdafdfd8..78242944f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java @@ -64,6 +64,7 @@ public class GearsES1 implements GLEventListener { private final float view_rotz = 0.0f; private GearsObject gear1=null, gear2=null, gear3=null; private FloatBuffer gear1Color=GearsObject.red, gear2Color=GearsObject.green, gear3Color=GearsObject.blue; + private GearsES1 sharedGears; private volatile boolean usesSharedGears = false; private boolean useMappedBuffers = false; private boolean validateBuffers = false; @@ -71,6 +72,7 @@ public class GearsES1 implements GLEventListener { private final int swapInterval; private final MouseListener gearsMouse = new GearsMouseAdapter(); private final KeyListener gearsKeys = new GearsKeyAdapter(); + private volatile boolean isInit = false; private int prevMouseX, prevMouseY; @@ -96,10 +98,8 @@ public class GearsES1 implements GLEventListener { this.gear3Color = gear3Color; } - public void setSharedGearsObjects(final GearsObject g1, final GearsObject g2, final GearsObject g3) { - gear1 = g1; - gear2 = g2; - gear3 = g3; + public void setSharedGears(final GearsES1 shared) { + sharedGears = shared; } /** @@ -123,6 +123,11 @@ public class GearsES1 implements GLEventListener { public void setValidateBuffers(final boolean v) { validateBuffers = v; } public void init(final GLAutoDrawable drawable) { + if(null != sharedGears && !sharedGears.isInit() ) { + System.err.println(Thread.currentThread()+" GearsES1.init.0: pending shared Gears .. re-init later XXXXX"); + drawable.setGLEventListenerInitState(this, false); + return; + } System.err.println(Thread.currentThread()+" GearsES1.init ..."); // Use debug pipeline @@ -167,28 +172,23 @@ public class GearsES1 implements GLEventListener { gl.glEnable(GL.GL_DEPTH_TEST); /* make the gears */ - if(null == gear1) { + if( null != sharedGears ) { + gear1 = new GearsObjectES1(sharedGears.getGear1()); + gear2 = new GearsObjectES1(sharedGears.getGear2()); + gear3 = new GearsObjectES1(sharedGears.getGear3()); + usesSharedGears = true; + System.err.println("gear1 reuse: "+gear1); + System.err.println("gear2 reuse: "+gear2); + System.err.println("gear3 reuse: "+gear3); + } else { gear1 = new GearsObjectES1(gl, useMappedBuffers, gear1Color, 1.0f, 4.0f, 1.0f, 20, 0.7f, validateBuffers); System.err.println("gear1 created: "+gear1); - } else { - usesSharedGears = true; - System.err.println("gear1 reused: "+gear1); - } - if(null == gear2) { gear2 = new GearsObjectES1(gl, useMappedBuffers, gear2Color, 0.5f, 2.0f, 2.0f, 10, 0.7f, validateBuffers); System.err.println("gear2 created: "+gear2); - } else { - usesSharedGears = true; - System.err.println("gear2 reused: "+gear2); - } - if(null == gear3) { gear3 = new GearsObjectES1(gl, useMappedBuffers, gear3Color, 1.3f, 2.0f, 0.5f, 10, 0.7f, validateBuffers); System.err.println("gear3 created: "+gear3); - } else { - usesSharedGears = true; - System.err.println("gear3 reused: "+gear3); } gl.glEnable(GLLightingFunc.GL_NORMALIZE); @@ -203,10 +203,14 @@ public class GearsES1 implements GLEventListener { new com.jogamp.newt.event.awt.AWTMouseAdapter(gearsMouse, drawable).addTo(comp); new com.jogamp.newt.event.awt.AWTKeyAdapter(gearsKeys, drawable).addTo(comp); } + isInit = true; System.err.println(Thread.currentThread()+" GearsES1.init FIN"); } + public final boolean isInit() { return isInit; } + public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { + if( !isInit ) { return; } System.err.println(Thread.currentThread()+" GearsES1.reshape "+x+"/"+y+" "+width+"x"+height+", swapInterval "+swapInterval); final GL2ES1 gl = drawable.getGL().getGL2ES1(); @@ -229,6 +233,8 @@ public class GearsES1 implements GLEventListener { } public void dispose(final GLAutoDrawable drawable) { + if( !isInit ) { return; } + isInit = false; System.err.println(Thread.currentThread()+" GearsES1.dispose ... "); final Object upstreamWidget = drawable.getUpstreamWidget(); if (upstreamWidget instanceof Window) { @@ -247,6 +253,8 @@ public class GearsES1 implements GLEventListener { } public void display(final GLAutoDrawable drawable) { + if( !isInit ) { return; } + // Turn the gears' teeth angle += 0.5f; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsObjectES1.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsObjectES1.java index bd487eae2..1355a44c8 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsObjectES1.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsObjectES1.java @@ -43,6 +43,10 @@ public class GearsObjectES1 extends GearsObject { super(gl, useMappedBuffers, gearColor, inner_radius, outer_radius, width, teeth, tooth_depth, validateBuffers); } + public GearsObjectES1(final GearsObject shared) { + super(shared); + } + @Override public GLArrayDataServer createInterleaved(final boolean useMappedBuffers, final int comps, final int dataType, final boolean normalized, final int initialSize, final int vboUsage) { if( useMappedBuffers ) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java index b3da5a53a..0f63566a2 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java @@ -142,12 +142,6 @@ public class GearsES2 implements StereoGLEventListener, TileRendererBase.TileRen this.gear3Color = gear3Color; } - public void setSharedGearsObjects(final GearsObjectES2 g1, final GearsObjectES2 g2, final GearsObjectES2 g3) { - gear1 = g1; - gear2 = g2; - gear3 = g3; - } - public void setSharedGears(final GearsES2 shared) { sharedGears = shared; } @@ -244,56 +238,30 @@ public class GearsES2 implements StereoGLEventListener, TileRendererBase.TileRen st.uniform(gl, colorU); if( null != sharedGears ) { - gear1 = new GearsObjectES2(sharedGears.getGear1(), st, pmvMatrix, pmvMatrixUniform, colorU); - gear2 = new GearsObjectES2(sharedGears.getGear2(), st, pmvMatrix, pmvMatrixUniform, colorU); - gear3 = new GearsObjectES2(sharedGears.getGear3(), st, pmvMatrix, pmvMatrixUniform, colorU); - usesSharedGears = true; - if(verbose) { - System.err.println("gear1 "+sid()+" created w/ share: "+sharedGears.getGear1()+" -> "+gear1); - System.err.println("gear2 "+sid()+" created w/ share: "+sharedGears.getGear2()+" -> "+gear2); - System.err.println("gear3 "+sid()+" created w/ share: "+sharedGears.getGear3()+" -> "+gear3); - } + gear1 = new GearsObjectES2(sharedGears.getGear1(), st, pmvMatrix, pmvMatrixUniform, colorU); + gear2 = new GearsObjectES2(sharedGears.getGear2(), st, pmvMatrix, pmvMatrixUniform, colorU); + gear3 = new GearsObjectES2(sharedGears.getGear3(), st, pmvMatrix, pmvMatrixUniform, colorU); + usesSharedGears = true; + if(verbose) { + System.err.println("gear1 "+sid()+" created w/ share: "+sharedGears.getGear1()+" -> "+gear1); + System.err.println("gear2 "+sid()+" created w/ share: "+sharedGears.getGear2()+" -> "+gear2); + System.err.println("gear3 "+sid()+" created w/ share: "+sharedGears.getGear3()+" -> "+gear3); + } } else { - if(null == gear1) { - gear1 = new GearsObjectES2(gl, useMappedBuffers, st, gear1Color, 1.0f, 4.0f, 1.0f, 20, 0.7f, pmvMatrix, pmvMatrixUniform, colorU, validateBuffers); - if(verbose) { - System.err.println("gear1 "+sid()+" created: "+gear1); - } - } else { - final GearsObjectES2 _gear1 = gear1; - gear1 = new GearsObjectES2(_gear1, st, pmvMatrix, pmvMatrixUniform, colorU); - usesSharedGears = true; - if(verbose) { - System.err.println("gear1 "+sid()+" created w/ share: "+_gear1+" -> "+gear1); - } + gear1 = new GearsObjectES2(gl, useMappedBuffers, st, gear1Color, 1.0f, 4.0f, 1.0f, 20, 0.7f, pmvMatrix, pmvMatrixUniform, colorU, validateBuffers); + if(verbose) { + System.err.println("gear1 "+sid()+" created: "+gear1); } - if(null == gear2) { - gear2 = new GearsObjectES2(gl, useMappedBuffers, st, gear2Color, 0.5f, 2.0f, 2.0f, 10, 0.7f, pmvMatrix, pmvMatrixUniform, colorU, validateBuffers); - if(verbose) { - System.err.println("gear2 "+sid()+" created: "+gear2); - } - } else { - final GearsObjectES2 _gear2 = gear2; - gear2 = new GearsObjectES2(_gear2, st, pmvMatrix, pmvMatrixUniform, colorU); - usesSharedGears = true; - if(verbose) { - System.err.println("gear2 "+sid()+" created w/ share: "+_gear2+" -> "+gear2); - } + gear2 = new GearsObjectES2(gl, useMappedBuffers, st, gear2Color, 0.5f, 2.0f, 2.0f, 10, 0.7f, pmvMatrix, pmvMatrixUniform, colorU, validateBuffers); + if(verbose) { + System.err.println("gear2 "+sid()+" created: "+gear2); } - if(null == gear3) { - gear3 = new GearsObjectES2(gl, useMappedBuffers, st, gear3Color, 1.3f, 2.0f, 0.5f, 10, 0.7f, pmvMatrix, pmvMatrixUniform, colorU, validateBuffers); - if(verbose) { - System.err.println("gear3 "+sid()+" created: "+gear2); - } - } else { - final GearsObjectES2 _gear3 = gear3; - gear3 = new GearsObjectES2(_gear3, st, pmvMatrix, pmvMatrixUniform, colorU); - usesSharedGears = true; - if(verbose) { - System.err.println("gear3 "+sid()+" created w/ share: "+_gear3+" -> "+gear3); - } + gear3 = new GearsObjectES2(gl, useMappedBuffers, st, gear3Color, 1.3f, 2.0f, 0.5f, 10, 0.7f, pmvMatrix, pmvMatrixUniform, colorU, validateBuffers); + if(verbose) { + System.err.println("gear3 "+sid()+" created: "+gear2); + } } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java index 9f97b4a21..6683f0fbf 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java @@ -78,10 +78,8 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList public void setVerbose(final boolean v) { verbose = v; } public void setFlipVerticalInGLOrientation(final boolean v) { flipVerticalInGLOrientation=v; } - public void setGears(final int g1, final int g2, final int g3) { - gear1 = g1; - gear2 = g2; - gear3 = g3; + public void setSharedGears(final Gears shared) { + sharedGears = shared; } /** @@ -103,17 +101,19 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList public void init(final GLAutoDrawable drawable) { final GL2 gl = drawable.getGL().getGL2(); - init(gl); - - final Object upstreamWidget = drawable.getUpstreamWidget(); - if (upstreamWidget instanceof Window) { - final Window window = (Window) upstreamWidget; - window.addMouseListener(gearsMouse); - window.addKeyListener(gearsKeys); - } else if (GLProfile.isAWTAvailable() && upstreamWidget instanceof java.awt.Component) { - final java.awt.Component comp = (java.awt.Component) upstreamWidget; - new AWTMouseAdapter(gearsMouse, drawable).addTo(comp); - new AWTKeyAdapter(gearsKeys, drawable).addTo(comp); + if( init(gl) ) { + final Object upstreamWidget = drawable.getUpstreamWidget(); + if (upstreamWidget instanceof Window) { + final Window window = (Window) upstreamWidget; + window.addMouseListener(gearsMouse); + window.addKeyListener(gearsKeys); + } else if (GLProfile.isAWTAvailable() && upstreamWidget instanceof java.awt.Component) { + final java.awt.Component comp = (java.awt.Component) upstreamWidget; + new AWTMouseAdapter(gearsMouse, drawable).addTo(comp); + new AWTKeyAdapter(gearsKeys, drawable).addTo(comp); + } + } else { + drawable.setGLEventListenerInitState(this, false); } } @@ -147,7 +147,11 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList } } - public void init(final GL2 gl) { + public boolean init(final GL2 gl) { + if(null != sharedGears && !sharedGears.isInit() ) { + System.err.println(Thread.currentThread()+" GearsES1.init.0: pending shared Gears .. re-init later XXXXX"); + return false; + } final float lightPos[] = { 5.0f, 5.0f, 10.0f, 0.0f }; final float red[] = { 0.8f, 0.1f, 0.0f, 0.7f }; final float green[] = { 0.0f, 0.8f, 0.2f, 0.7f }; @@ -171,44 +175,47 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList enableStates(gl, true); /* make the gears */ - if(0>=gear1) { + if( null != sharedGears ) { + gear1 = sharedGears.getGear1(); + gear2 = sharedGears.getGear2(); + gear3 = sharedGears.getGear3(); + System.err.println("gear1 list reused: "+gear1); + System.err.println("gear2 list reused: "+gear2); + System.err.println("gear3 list reused: "+gear3); + } else { gear1 = gl.glGenLists(1); gl.glNewList(gear1, GL2.GL_COMPILE); gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT_AND_DIFFUSE, red, 0); gear(gl, 1.0f, 4.0f, 1.0f, 20, 0.7f); gl.glEndList(); System.err.println("gear1 list created: "+gear1); - } else { - System.err.println("gear1 list reused: "+gear1); - } - if(0>=gear2) { gear2 = gl.glGenLists(1); gl.glNewList(gear2, GL2.GL_COMPILE); gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT_AND_DIFFUSE, green, 0); gear(gl, 0.5f, 2.0f, 2.0f, 10, 0.7f); gl.glEndList(); System.err.println("gear2 list created: "+gear2); - } else { - System.err.println("gear2 list reused: "+gear2); - } - if(0>=gear3) { gear3 = gl.glGenLists(1); gl.glNewList(gear3, GL2.GL_COMPILE); gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT_AND_DIFFUSE, blue, 0); gear(gl, 1.3f, 2.0f, 0.5f, 10, 0.7f); gl.glEndList(); System.err.println("gear3 list created: "+gear3); - } else { - System.err.println("gear3 list reused: "+gear3); } enableStates(gl, false); + + isInit = true; + return true; } + public final boolean isInit() { return isInit; } + @Override public void reshape(final GLAutoDrawable glad, final int x, final int y, final int width, final int height) { + if( !isInit ) { return; } final GL2 gl = glad.getGL().getGL2(); if(-1 != swapInterval) { gl.setSwapInterval(swapInterval); @@ -220,6 +227,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList public void reshapeTile(final TileRendererBase tr, final int tileX, final int tileY, final int tileWidth, final int tileHeight, final int imageWidth, final int imageHeight) { + if( !isInit ) { return; } final GL2 gl = tr.getAttachedDrawable().getGL().getGL2(); gl.setSwapInterval(0); reshape(gl, tileX, tileY, tileWidth, tileHeight, imageWidth, imageHeight); @@ -273,6 +281,8 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList @Override public void dispose(final GLAutoDrawable drawable) { + if( !isInit ) { return; } + isInit = false; System.err.println(Thread.currentThread()+" Gears.dispose: tileRendererInUse "+tileRendererInUse); try { final Object upstreamWidget = drawable.getUpstreamWidget(); @@ -282,11 +292,15 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList window.removeKeyListener(gearsKeys); } } catch (final Exception e) { System.err.println("Caught: "); e.printStackTrace(); } - setGears(0, 0, 0); + gear1 = 0; + gear2 = 0; + gear3 = 0; } @Override public void display(final GLAutoDrawable drawable) { + if( !isInit ) { return; } + // Get the GL corresponding to the drawable we are animating final GL2 gl = drawable.getGL().getGL2(); @@ -314,6 +328,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList } public void display(final GL2 gl) { + if( !isInit ) { return; } enableStates(gl, true); if( null == tileRendererInUse ) { |