diff options
Diffstat (limited to 'src')
3 files changed, 38 insertions, 29 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java index d1155bd30..11ca64258 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java @@ -40,6 +40,7 @@ import java.util.HashSet; import java.util.Set; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import javax.media.opengl.GL; import javax.media.opengl.GL2; @@ -122,8 +123,8 @@ public class TestSharedContextNewtAWTBug523 extends UITestCase { // Buffer objects can be shared across shared OpenGL context. // If we run with sharedContext, then the tests will use these shared buffer objects, // otherwise each event listener allocates its own buffer objects. - private static volatile int[] sharedVertexBufferObjects = {0}; - private static volatile int[] sharedIndexBufferObjects = {0}; + private static AtomicInteger sharedVertexBufferObjects = new AtomicInteger(0); + private static AtomicInteger sharedIndexBufferObjects = new AtomicInteger(0); @BeforeClass public static void initClass() { @@ -240,19 +241,22 @@ public class TestSharedContextNewtAWTBug523 extends UITestCase { // if (useShared) { System.err.println("Using shared VBOs on slave 0x"+Integer.toHexString(hashCode())); - vertexBufferObjects = sharedVertexBufferObjects; - indexBufferObjects = sharedIndexBufferObjects; + privateVertexBufferObjects[0] = sharedVertexBufferObjects.get(); + privateIndexBufferObjects[0] = sharedIndexBufferObjects.get(); } else { System.err.println("Using local VBOs on slave 0x"+Integer.toHexString(hashCode())); - vertexBufferObjects = privateVertexBufferObjects; - indexBufferObjects = privateIndexBufferObjects; } + vertexBufferObjects = privateVertexBufferObjects; + indexBufferObjects = privateIndexBufferObjects; // if buffer sharing is enabled, then the first of the two event listeners to be // initialized will allocate the buffers, and the other will re-use the allocated one if (vertexBufferObjects[0] == 0) { System.err.println("Creating vertex VBO on slave 0x"+Integer.toHexString(hashCode())); vertexBufferObjects[0] = createVertexBuffer(gl2); + if (useShared) { + sharedVertexBufferObjects.set(vertexBufferObjects[0]); + } } // A check in the case that buffer sharing is enabled but context sharing is not enabled -- in that @@ -276,6 +280,9 @@ public class TestSharedContextNewtAWTBug523 extends UITestCase { if (indexBufferObjects[0] == 0) { System.err.println("Creating index VBO on slave 0x"+Integer.toHexString(hashCode())); indexBufferObjects[0] = createVertexIndexBuffer(gl2); + if (useShared) { + sharedIndexBufferObjects.set(indexBufferObjects[0]); + } } // again, a check in the case that buffer sharing is enabled but context sharing is not enabled @@ -311,12 +318,13 @@ public class TestSharedContextNewtAWTBug523 extends UITestCase { int [] vertexBufferObjects; int [] indexBufferObjects; if (useShared) { - vertexBufferObjects = sharedVertexBufferObjects; - indexBufferObjects = sharedIndexBufferObjects; - } else { - vertexBufferObjects = privateVertexBufferObjects; - indexBufferObjects = privateIndexBufferObjects; + privateVertexBufferObjects[0] = sharedVertexBufferObjects.get(); + privateIndexBufferObjects[0] = sharedIndexBufferObjects.get(); + sharedVertexBufferObjects.set(0); + sharedIndexBufferObjects.set(0); } + vertexBufferObjects = privateVertexBufferObjects; + indexBufferObjects = privateIndexBufferObjects; gl2.glDeleteBuffers(1, vertexBufferObjects, 0); logAnyErrorCodes(this, gl2, "dispose.2"); @@ -414,12 +422,11 @@ public class TestSharedContextNewtAWTBug523 extends UITestCase { int [] indexBufferObjects; synchronized (this) { if (useShared) { - vertexBufferObjects = sharedVertexBufferObjects; - indexBufferObjects = sharedIndexBufferObjects; - } else { - vertexBufferObjects = privateVertexBufferObjects; - indexBufferObjects = privateIndexBufferObjects; + privateVertexBufferObjects[0] = sharedVertexBufferObjects.get(); + privateIndexBufferObjects[0] = sharedIndexBufferObjects.get(); } + vertexBufferObjects = privateVertexBufferObjects; + indexBufferObjects = privateIndexBufferObjects; } // synchronized (this) // A check in the case that buffer sharing is enabled but context sharing is not enabled -- in that diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit02AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit02AWT.java index 0cbcd5e2f..c60c395eb 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit02AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit02AWT.java @@ -32,6 +32,7 @@ import java.awt.Component; import java.awt.Dimension; import java.awt.Graphics; import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.atomic.AtomicInteger; import javax.media.opengl.GLAnimatorControl; import javax.media.opengl.GLAutoDrawable; @@ -95,7 +96,7 @@ public class TestPerf001GLJPanelInit02AWT extends UITestCase { UITestCase.waitForKey("Pre-Init"); } System.err.println("INIT START"); - initCount = 0; + initCount.set(0); try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -121,7 +122,7 @@ public class TestPerf001GLJPanelInit02AWT extends UITestCase { glad.addGLEventListener(new GLEventListener() { @Override public void init(final GLAutoDrawable drawable) { - initCount++; + initCount.incrementAndGet(); } @Override public void dispose(final GLAutoDrawable drawable) {} @@ -152,7 +153,7 @@ public class TestPerf001GLJPanelInit02AWT extends UITestCase { super.paintComponent(g); if( !initialized && added && reshapeWidth > 0 && reshapeHeight > 0 && isDisplayable() ) { initialized = true; - initCount++; + initCount.incrementAndGet(); } } }; @@ -178,7 +179,7 @@ public class TestPerf001GLJPanelInit02AWT extends UITestCase { } final long t0 = System.currentTimeMillis(); long t1 = t0; - while( frameCount > initCount && INIT_TIMEOUT > t1 - t0 ) { + while( frameCount > initCount.get() && INIT_TIMEOUT > t1 - t0 ) { try { Thread.sleep(100); System.err.println("Sleep initialized: "+initCount+"/"+frameCount); @@ -188,9 +189,9 @@ public class TestPerf001GLJPanelInit02AWT extends UITestCase { t1 = System.currentTimeMillis(); } t[3] = Platform.currentTimeMillis(); - final double panelCountF = initCount; + final double panelCountF = initCount.get(); System.err.printf("P: %d %s%s:%n\tctor\t%6d/t %6.2f/1%n\tvisible\t%6d/t %6.2f/1%n\tsum-i\t%6d/t %6.2f/1%n", - initCount, + initCount.get(), useGLJPanel?"GLJPanel":(useGLCanvas?"GLCanvas":"No_GL"), initMT?" (mt)":" (01)", t[1]-t[0], (t[1]-t[0])/panelCountF, t[3]-t[1], (t[3]-t[1])/panelCountF, @@ -380,7 +381,7 @@ public class TestPerf001GLJPanelInit02AWT extends UITestCase { static boolean wait = false; static int width = 800, height = 600, frameCount = 25; - volatile int initCount = 0; + AtomicInteger initCount = new AtomicInteger(0); public static void main(final String[] args) { boolean manual=false; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLWindowInit03NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLWindowInit03NEWT.java index d3dddc56f..60e31aa6a 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLWindowInit03NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLWindowInit03NEWT.java @@ -28,6 +28,7 @@ package com.jogamp.opengl.test.junit.jogl.perf; import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.atomic.AtomicInteger; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; @@ -72,7 +73,7 @@ public class TestPerf001GLWindowInit03NEWT extends UITestCase { UITestCase.waitForKey("Pre-Init"); } System.err.println("INIT START"); - initCount = 0; + initCount.set(0); t[0] = Platform.currentTimeMillis(); int x = 32, y = 32; @@ -93,7 +94,7 @@ public class TestPerf001GLWindowInit03NEWT extends UITestCase { frame[i].addGLEventListener(new GLEventListener() { @Override public void init(final GLAutoDrawable drawable) { - initCount++; + initCount.incrementAndGet(); } @Override public void dispose(final GLAutoDrawable drawable) {} @@ -111,7 +112,7 @@ public class TestPerf001GLWindowInit03NEWT extends UITestCase { final long t0 = System.currentTimeMillis(); long t1 = t0; - while( frameCount > initCount && INIT_TIMEOUT > t1 - t0 ) { + while( frameCount > initCount.get() && INIT_TIMEOUT > t1 - t0 ) { try { Thread.sleep(100); System.err.println("Sleep initialized: "+initCount+"/"+frameCount); @@ -121,9 +122,9 @@ public class TestPerf001GLWindowInit03NEWT extends UITestCase { t1 = System.currentTimeMillis(); } t[3] = Platform.currentTimeMillis(); - final double panelCountF = initCount; + final double panelCountF = initCount.get(); System.err.printf("P: %d GLWindow:%n\tctor\t%6d/t %6.2f/1%n\tvisible\t%6d/t %6.2f/1%n\tsum-i\t%6d/t %6.2f/1%n", - initCount, + initCount.get(), t[1]-t[0], (t[1]-t[0])/panelCountF, t[3]-t[1], (t[3]-t[1])/panelCountF, t[3]-t[0], (t[3]-t[0])/panelCountF); @@ -169,7 +170,7 @@ public class TestPerf001GLWindowInit03NEWT extends UITestCase { static boolean wait = false, mainRun = false; static int width = 800, height = 600, frameCount = 25; - volatile int initCount = 0; + AtomicInteger initCount = new AtomicInteger(0); public static void main(final String[] args) { mainRun = true; |