diff options
Diffstat (limited to 'src/test')
10 files changed, 871 insertions, 41 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug1146GLContextDialogToolTipAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug1146GLContextDialogToolTipAWT.java new file mode 100644 index 000000000..42646c07e --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug1146GLContextDialogToolTipAWT.java @@ -0,0 +1,238 @@ +/** + * Copyright 2015 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.acore; + +import java.awt.AWTException; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Robot; +import java.awt.Window; +import java.lang.reflect.InvocationTargetException; +import java.util.Locale; + +import javax.swing.AbstractButton; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; + +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import com.jogamp.common.os.Platform; +import com.jogamp.opengl.GLCapabilities; +import com.jogamp.opengl.GLCapabilitiesImmutable; +import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.awt.GLCanvas; +import com.jogamp.opengl.test.junit.util.AWTRobotUtil; +import com.jogamp.opengl.test.junit.util.DumpGLInfo; +import com.jogamp.opengl.test.junit.util.GLClearColor; +import com.jogamp.opengl.test.junit.util.GLEventListenerCounter; +import com.jogamp.opengl.test.junit.util.UITestCase; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestBug1146GLContextDialogToolTipAWT extends UITestCase { + static final int NB_TEST = 5; + static final int ACTION_DELAY = 500; + static final int MOVE_DELAY = 2; + static final int MOVE_ITER = 100; + static final int TOOLTIP_WAIT = 3*1000; // 5s + + static AbstractButton findButton(final int depth, final Container c, final String buttonText) { + AbstractButton res = null; + final int cc = c.getComponentCount(); + for(int i=0; null==res && i<cc; i++) { + final Component e = c.getComponent(i); + // System.err.println("["+depth+"]["+i+"]: "+e.getClass().getSimpleName()+": "+e); + if( e instanceof AbstractButton ) { + final AbstractButton b = (AbstractButton) e; + final String bT = b.getText(); + if( buttonText.equals(bT) ) { + res = b; + } + } else if( e instanceof Container ) { + res = findButton(depth+1, (Container)e, buttonText); + } + } + return res; + } + + private void oneTest(final GLCapabilitiesImmutable caps) { + // base dialog + final JDialog dialog = new JDialog((Window) null); + dialog.setMinimumSize(new Dimension(500, 300)); + dialog.setPreferredSize(new Dimension(500, 300)); + + dialog.setModal(false); + + // build accessory + final GLEventListenerCounter glelc1 = new GLEventListenerCounter(); + final GLCanvas canvas1 = new GLCanvas(caps); + canvas1.addGLEventListener(new DumpGLInfo(Platform.getNewline()+Platform.getNewline()+"Pre-ToolTip", false, false, false)); + canvas1.addGLEventListener(new GLClearColor(1f, 0f, 0f, 1f)); + canvas1.addGLEventListener(glelc1); + final JPanel panel1 = new JPanel(new BorderLayout()); + panel1.add(canvas1, BorderLayout.CENTER); + panel1.setPreferredSize(new Dimension(300, 300)); + + final GLEventListenerCounter glelc2 = new GLEventListenerCounter(); + final GLCanvas canvas2 = new GLCanvas(caps); + canvas2.addGLEventListener(new DumpGLInfo(Platform.getNewline()+Platform.getNewline()+"Post-ToolTip", false, false, false)); + canvas2.addGLEventListener(new GLClearColor(0f, 0f, 1f, 1f)); + canvas2.addGLEventListener(glelc2); + final JPanel panel2 = new JPanel(new BorderLayout()); + panel2.add(canvas2, BorderLayout.CENTER); + panel2.setPreferredSize(new Dimension(300, 300)); + + // create file chooser with accessory + final JFileChooser fileChooser = new JFileChooser(); + final String approveButtonText = "Approved"; + fileChooser.setApproveButtonText(approveButtonText); + fileChooser.setApproveButtonToolTipText("Tool-Tip for Approved"); + fileChooser.setAccessory(panel1); + + final Locale l = fileChooser.getLocale(); + final String cancelButtonText = UIManager.getString("FileChooser.cancelButtonText",l); + + // launch robot action .. + new Thread() + { + public void run() + { + try { + Assert.assertEquals(true, AWTRobotUtil.waitForVisible(fileChooser, true)); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(canvas1, true)); + + final Point approveButtonPos; + final AbstractButton approveButton = findButton(0, fileChooser, approveButtonText); + if( null != approveButton ) { + approveButtonPos = approveButton.getLocationOnScreen(); + final Dimension approveButtonSize = approveButton.getSize(); + approveButtonPos.translate(approveButtonSize.width/2, approveButtonSize.height/2); + System.err.println("OK Button: "+approveButton.getClass().getSimpleName()+"; "+approveButton+", "+approveButtonPos); + } else { + System.err.println("OK Button: NULL"); + approveButtonPos = null; + } + final Point cancelButtonPos; + final AbstractButton cancelButton = findButton(0, fileChooser, cancelButtonText); + if( null != approveButton ) { + cancelButtonPos = cancelButton.getLocationOnScreen(); + final Dimension cancelButtonSize = cancelButton.getSize(); + cancelButtonPos.translate(cancelButtonSize.width/2, cancelButtonSize.height/2); + System.err.println("CANCEL Button: "+cancelButton.getClass().getSimpleName()+"; "+cancelButton+", "+cancelButtonPos); + } else { + cancelButtonPos = null; + System.err.println("CANCEL Button: NULL"); + } + final Robot robot = new Robot(); + // hover to 'approve' -> tool tip + if( null != approveButtonPos ) { + AWTRobotUtil.mouseMove(robot, approveButtonPos, MOVE_ITER, MOVE_DELAY); + Thread.sleep(TOOLTIP_WAIT); + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + fileChooser.setAccessory(panel2); + fileChooser.validate(); + } } ) ; + } catch (final InterruptedException e) { + e.printStackTrace(); + } catch (final InvocationTargetException e) { + e.printStackTrace(); + } + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(canvas2, true)); + } + if( null != cancelButtonPos ) { + AWTRobotUtil.mouseClick(robot, cancelButtonPos, MOVE_ITER, MOVE_DELAY, ACTION_DELAY); + } else { + // oops .. + fileChooser.cancelSelection(); + } + } catch (final AWTException e1) { + e1.printStackTrace(); + } catch (final InterruptedException e2) { + e2.printStackTrace(); + } + } + }.start(); + + // show file chooser dialog + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + dialog.setVisible(true); + fileChooser.showOpenDialog(dialog); + } } ) ; + } catch (final InterruptedException e) { + e.printStackTrace(); + } catch (final InvocationTargetException e) { + e.printStackTrace(); + } + + // dispose of resources + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + canvas1.destroy(); + canvas2.destroy(); + dialog.setVisible(false); + dialog.dispose(); + } } ) ; + } catch (final InterruptedException e) { + e.printStackTrace(); + } catch (final InvocationTargetException e) { + e.printStackTrace(); + } + + Assert.assertEquals(1, glelc1.initCount); + Assert.assertEquals(1, glelc2.initCount); + } + + + @Test(timeout=180000) // TO 3 min + public void test01() { + final GLCapabilities caps = new GLCapabilities(GLProfile.getDefault()); + for (int i = 0; i < NB_TEST; i++) { + System.out.println("Iteration " + i + " / " + NB_TEST); + oneTest(caps); + } + } + + public static void main(final String[] pArgs) + { + org.junit.runner.JUnitCore.main(TestBug1146GLContextDialogToolTipAWT.class.getName()); + } +}
\ No newline at end of file diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMapBufferRead01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMapBufferRead01NEWT.java index 1a9260219..21b653c69 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMapBufferRead01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMapBufferRead01NEWT.java @@ -31,13 +31,15 @@ import com.jogamp.common.nio.Buffers; import com.jogamp.opengl.test.junit.util.NEWTGLContext; import com.jogamp.opengl.test.junit.util.UITestCase; +import static org.junit.Assert.assertEquals; + import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.nio.FloatBuffer; import com.jogamp.opengl.GL; import com.jogamp.opengl.GL2ES3; -import com.jogamp.opengl.GL2GL3; import com.jogamp.opengl.GLBufferStorage; import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLProfile; @@ -50,6 +52,9 @@ import org.junit.runners.MethodSorters; /** * Verifies content of buffer storage's content * as well as general buffer- and buffer-storage tracking. + * <p> + * Implementation uses ByteBuffer and Buffers or NIO API. + * </p> * * @author Luz, et.al. */ @@ -63,9 +68,7 @@ public class TestMapBufferRead01NEWT extends UITestCase { System.err.println("Test requires GL2/GL3 profile."); return; } - final ByteBuffer verticiesBB = ByteBuffer.allocate(4*9); - verticiesBB.order(ByteOrder.nativeOrder()); - testWriteRead01(verticiesBB, false /* useRange */); + testWriteRead01(createVerticesBB(false), false /* useRange */); } @Test public void testWriteRead01bMap() throws InterruptedException { @@ -73,8 +76,7 @@ public class TestMapBufferRead01NEWT extends UITestCase { System.err.println("Test requires GL2/GL3 profile."); return; } - final ByteBuffer verticiesBB = Buffers.newDirectByteBuffer(4*9); - testWriteRead01(verticiesBB, false /* useRange */); + testWriteRead01(createVerticesBB(true), false /* useRange */); } @Test @@ -83,9 +85,7 @@ public class TestMapBufferRead01NEWT extends UITestCase { System.err.println("Test requires GL3 or GLES3 profile."); return; } - final ByteBuffer verticiesBB = ByteBuffer.allocate(4*9); - verticiesBB.order(ByteOrder.nativeOrder()); - testWriteRead01(verticiesBB, true/* useRange */); + testWriteRead01(createVerticesBB(false), true/* useRange */); } @Test public void testWriteRead02bMapRange() throws InterruptedException { @@ -93,11 +93,43 @@ public class TestMapBufferRead01NEWT extends UITestCase { System.err.println("Test requires GL3 or GLES3 profile."); return; } - final ByteBuffer verticiesBB = Buffers.newDirectByteBuffer(4*9); - testWriteRead01(verticiesBB, true /* useRange */); + testWriteRead01(createVerticesBB(true), true /* useRange */); + } + + static final float[] vertexData = new float[] { -0.3f, -0.2f, -0.1f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f }; + + static ByteBuffer createVerticesBB(final boolean useBuffersAPI) { + final ByteBuffer res; + if( useBuffersAPI ) { + res = Buffers.newDirectByteBuffer(Buffers.SIZEOF_FLOAT*vertexData.length); + final FloatBuffer resF = res.asFloatBuffer(); + resF.put(vertexData, 0, vertexData.length).rewind(); + } else { + res = ByteBuffer.allocate(Buffers.SIZEOF_FLOAT*vertexData.length); + res.order(ByteOrder.nativeOrder()); + for(int i=0; i<vertexData.length; i++) { + res.putFloat(vertexData[i]); + } + res.rewind(); + } + if(DEBUG) { + System.err.println("java "+res); + for(int i=0; i < res.capacity(); i+=4) { + System.err.println("java ["+i+"]: "+res.getFloat(i)); + } + } + return res; } private void testWriteRead01(final ByteBuffer verticiesBB, final boolean useRange) throws InterruptedException { + // Validate incoming ByteBuffer first + assertEquals(0, verticiesBB.position()); + assertEquals(Buffers.SIZEOF_FLOAT*vertexData.length, verticiesBB.limit()); + assertEquals(Buffers.SIZEOF_FLOAT*vertexData.length, verticiesBB.capacity()); + assertEquals(Buffers.SIZEOF_FLOAT*vertexData.length, verticiesBB.remaining()); + assertEquals(-0.3f, verticiesBB.getFloat(Buffers.SIZEOF_FLOAT*0), 0.05f); + assertEquals( 0.6f, verticiesBB.getFloat(Buffers.SIZEOF_FLOAT*8), 0.05f); + final GLProfile glp = GLProfile.getMaxProgrammable(true); final GLCapabilities caps = new GLCapabilities(glp); caps.setOnscreen(false); @@ -108,24 +140,6 @@ public class TestMapBufferRead01NEWT extends UITestCase { final int[] vertexBuffer = new int[1]; - verticiesBB.putFloat(-0.3f); - verticiesBB.putFloat(-0.2f); - verticiesBB.putFloat(-0.1f); - - verticiesBB.putFloat(0.1f); - verticiesBB.putFloat(0.2f); - verticiesBB.putFloat(0.3f); - - verticiesBB.putFloat(0.4f); - verticiesBB.putFloat(0.5f); - verticiesBB.putFloat(0.6f); - verticiesBB.rewind(); - if(DEBUG) { - for(int i=0; i < verticiesBB.capacity(); i+=4) { - System.err.println("java "+i+": "+verticiesBB.getFloat(i)); - } - } - gl.glGenBuffers(1, vertexBuffer, 0); gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vertexBuffer[0]); @@ -149,7 +163,7 @@ public class TestMapBufferRead01NEWT extends UITestCase { floatOffset = 0; byteOffset = 0; mapByteLength = verticiesBB.capacity(); - bb = gl.glMapBuffer(GL.GL_ARRAY_BUFFER, GL2GL3.GL_READ_ONLY); + bb = gl.glMapBuffer(GL.GL_ARRAY_BUFFER, GL2ES3.GL_READ_ONLY); } System.err.println("gpu-02 mapped GL_ARRAY_BUFFER, floatOffset "+floatOffset+", byteOffset "+byteOffset+", mapByteLength "+mapByteLength+" -> "+bb); System.err.println("gpu-03 GL_ARRAY_BUFFER -> bufferName "+bufferName+" -> "+bufferStorage); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMapBufferRead02NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMapBufferRead02NEWT.java new file mode 100644 index 000000000..49b158bd1 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMapBufferRead02NEWT.java @@ -0,0 +1,191 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package com.jogamp.opengl.test.junit.jogl.acore; + +import com.jogamp.common.nio.Buffers; +import com.jogamp.opengl.test.junit.util.NEWTGLContext; +import com.jogamp.opengl.test.junit.util.UITestCase; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; + +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GL2ES3; +import com.jogamp.opengl.GLBufferStorage; +import com.jogamp.opengl.GLCapabilities; +import com.jogamp.opengl.GLProfile; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +/** + * Verifies content of buffer storage's content + * as well as general buffer- and buffer-storage tracking. + * <p> + * Implementation uses FloatBuffer and Buffers or NIO API. + * </p> + * + * @author Luz, et.al. + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestMapBufferRead02NEWT extends UITestCase { + static final boolean DEBUG = false; + + @Test + public void testWriteRead01aMap() throws InterruptedException { + if(!GLProfile.isAvailable(GLProfile.GL2GL3)) { + System.err.println("Test requires GL2/GL3 profile."); + return; + } + testWriteRead01(createVerticesFB(false), false /* useRange */); + } + @Test + public void testWriteRead01bMap() throws InterruptedException { + if(!GLProfile.isAvailable(GLProfile.GL2GL3)) { + System.err.println("Test requires GL2/GL3 profile."); + return; + } + testWriteRead01(createVerticesFB(true), false /* useRange */); + } + + @Test + public void testWriteRead02aMapRange() throws InterruptedException { + if(!GLProfile.isAvailable(GLProfile.GL3) && !!GLProfile.isAvailable(GLProfile.GLES3)) { + System.err.println("Test requires GL3 or GLES3 profile."); + return; + } + testWriteRead01(createVerticesFB(false), true/* useRange */); + } + @Test + public void testWriteRead02bMapRange() throws InterruptedException { + if(!GLProfile.isAvailable(GLProfile.GL3) && !!GLProfile.isAvailable(GLProfile.GLES3)) { + System.err.println("Test requires GL3 or GLES3 profile."); + return; + } + testWriteRead01(createVerticesFB(true), true /* useRange */); + } + + static final float[] vertexData = new float[] { -0.3f, -0.2f, -0.1f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f }; + + static FloatBuffer createVerticesFB(final boolean useBuffersAPI) { + final FloatBuffer res; + if( useBuffersAPI ) { + res = Buffers.newDirectFloatBuffer(vertexData); + } else { + res = FloatBuffer.allocate(vertexData.length); + for(int i=0; i<vertexData.length; i++) { + res.put(vertexData[i]); + } + res.rewind(); + } + if(DEBUG) { + System.err.println("java "+res); + for(int i=0; i < res.remaining(); i+=4) { + System.err.println("java ["+i+"]: "+res.get(i)); + } + } + return res; + } + + private void testWriteRead01(final FloatBuffer verticiesFB, final boolean useRange) throws InterruptedException { + // Validate incoming ByteBuffer first + assertEquals(0, verticiesFB.position()); + assertEquals(vertexData.length, verticiesFB.limit()); + assertEquals(vertexData.length, verticiesFB.capacity()); + assertEquals(vertexData.length, verticiesFB.remaining()); + assertEquals(-0.3f, verticiesFB.get(0), 0.05f); + assertEquals( 0.6f, verticiesFB.get(8), 0.05f); + + final GLProfile glp = GLProfile.getMaxProgrammable(true); + final GLCapabilities caps = new GLCapabilities(glp); + caps.setOnscreen(false); + final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow( + caps, 800, 600, true); + try { + final GL gl = winctx.context.getGL(); + + final int[] vertexBuffer = new int[1]; + + gl.glGenBuffers(1, vertexBuffer, 0); + + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vertexBuffer[0]); + + gl.glBufferData(GL.GL_ARRAY_BUFFER, Buffers.SIZEOF_FLOAT*verticiesFB.remaining(), verticiesFB, GL2ES3.GL_STATIC_READ); + // gl.glBufferData(GL.GL_ARRAY_BUFFER, Buffers.SIZEOF_FLOAT*verticiesBB.remaining(), verticiesBB, GL.GL_STATIC_DRAW); + + final int bufferName = gl.getBoundBuffer(GL.GL_ARRAY_BUFFER); + final GLBufferStorage bufferStorage = gl.getBufferStorage(bufferName); + System.err.println("gpu-01 GL_ARRAY_BUFFER -> bufferName "+bufferName+" -> "+bufferStorage); + Assert.assertEquals("Buffer storage's bytes-buffer not null before map", null, bufferStorage.getMappedBuffer()); + + final int floatOffset, byteOffset, mapByteLength; + final ByteBuffer bb; + if( useRange ) { + floatOffset = 3; + byteOffset = Buffers.SIZEOF_FLOAT*floatOffset; + mapByteLength = Buffers.SIZEOF_FLOAT*verticiesFB.remaining()-byteOffset; + bb = gl.glMapBufferRange(GL.GL_ARRAY_BUFFER, byteOffset, mapByteLength, GL.GL_MAP_READ_BIT); + } else { + floatOffset = 0; + byteOffset = 0; + mapByteLength = Buffers.SIZEOF_FLOAT*verticiesFB.remaining(); + bb = gl.glMapBuffer(GL.GL_ARRAY_BUFFER, GL2ES3.GL_READ_ONLY); + } + System.err.println("gpu-02 mapped GL_ARRAY_BUFFER, floatOffset "+floatOffset+", byteOffset "+byteOffset+", mapByteLength "+mapByteLength+" -> "+bb); + System.err.println("gpu-03 GL_ARRAY_BUFFER -> bufferName "+bufferName+" -> "+bufferStorage); + Assert.assertNotNull(bb); + Assert.assertEquals("BufferStorage size less byteOffset not equals buffer storage size", bufferStorage.getSize()-byteOffset, bb.capacity()); + Assert.assertEquals("BufferStorage's bytes-buffer not equal with mapped bytes-buffer", bufferStorage.getMappedBuffer(), bb); + Assert.assertEquals("Buffer storage size not equals mapByteLength", mapByteLength, bb.remaining()); + + if(DEBUG) { + System.err.println("floatOffset "+floatOffset+", byteOffset "+byteOffset); + for(int i=0; i < bb.remaining(); i+=4) { + System.err.println("gpu "+i+": "+bb.getFloat(i)); + } + } + for(int i=0; i < bb.remaining(); i+=4) { + Assert.assertEquals(verticiesFB.get( (byteOffset+i) / Buffers.SIZEOF_FLOAT ), bb.getFloat(i), 0.0001f); + } + gl.glUnmapBuffer(GL.GL_ARRAY_BUFFER); + Assert.assertEquals("Buffer storage's bytes-buffer not null after unmap", null, bufferStorage.getMappedBuffer()); + } finally { + NEWTGLContext.destroyWindow(winctx); + } + } + public static void main(final String args[]) throws IOException { + final String tstname = TestMapBufferRead02NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedExternalContextAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedExternalContextAWT.java new file mode 100644 index 000000000..81489df17 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedExternalContextAWT.java @@ -0,0 +1,261 @@ +package com.jogamp.opengl.test.junit.jogl.acore; + +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import javax.swing.Timer; + +import org.junit.Test; + +import com.jogamp.common.os.Platform; +import com.jogamp.common.util.locks.LockFactory; +import com.jogamp.common.util.locks.RecursiveLock; +import com.jogamp.opengl.*; +import com.jogamp.opengl.test.junit.util.DumpGLInfo; + +/** + * Bug 1160. + * Test for context sharing with an external context. Creates an external GL context, then + * sets up an offscreen drawable which shares with it. The test contains two cases: one + * which creates and repaints the offscreen drawable on the EDT, and one which does so on + * a dedicated thread. On Windows+NVidia, the former fails. + */ +public class TestSharedExternalContextAWT { + + static final int LATCH_COUNT = 5; + + private void doTest(final boolean aUseEDT) throws Exception { + final CountDownLatch testLatch = new CountDownLatch(1); + final CountDownLatch masterLatch = new CountDownLatch(1); + final CountDownLatch slaveLatch = new CountDownLatch(LATCH_COUNT); + final MyGLEventListener listener = new MyGLEventListener(aUseEDT, slaveLatch); + + /** + * For the purpose of this test, this offscreen drawable will be used to create + * an external GL context. In the actual application, the external context + * represents a GL context which lives outside the JVM. + */ + final Runnable runnable = new Runnable() { + public void run() { + System.err.println("Master Thread Start: "+Thread.currentThread().getName()); + final GLProfile glProfile = GLProfile.getDefault(); + final GLCapabilities caps = new GLCapabilities(glProfile); + final GLAutoDrawable buffer = GLDrawableFactory.getDesktopFactory().createOffscreenAutoDrawable( + GLProfile.getDefaultDevice(), caps, null, 512, 512 + ); + // The listener will set up the context sharing in its init() method. + buffer.addGLEventListener(new DumpGLInfo(Platform.getNewline()+Platform.getNewline()+"Master GLContext", false, false, false)); + buffer.addGLEventListener(listener); + buffer.display(); + masterLatch.countDown(); + + // wait until test has finished + try { + testLatch.await(); + } catch (final InterruptedException e) { + e.printStackTrace(); + } + System.err.println("Master Thread End: "+Thread.currentThread().getName()); + } + }; + + // Kick off thread creating the actual external context + // which is suppose to lie outside of the JVM. + // The thread is kept alive, since this detail + // may be required for the OpenGL driver implementation. + final Thread thread = new Thread(runnable); + thread.setDaemon(true); + thread.start(); + masterLatch.await(3, TimeUnit.SECONDS); + + // Wait for slave to finish. + slaveLatch.await(3, TimeUnit.SECONDS); + + // signal master test has finished + testLatch.countDown(); + + // If exceptions occurred, fail. + final Exception e = listener.fException; + if (e != null) { + throw e; + } + } + + @Test + public void test01OnEDT() throws Exception { + doTest(true); + } + + @Test + public void test02OnExecutorThread() throws Exception { + doTest(false); + } + + /** + * Listener that creates an external drawable and an offscreen drawable, with context + * sharing between the two. + */ + private static class MyGLEventListener implements GLEventListener { + GLOffscreenAutoDrawable fOffscreenDrawable; + final boolean fUseEDT; + final CountDownLatch fLatch; + final RecursiveLock masterLock = LockFactory.createRecursiveLock(); + + private Exception fException = null; + + public MyGLEventListener(final boolean aUseEDT, final CountDownLatch aLatch) { + fUseEDT = aUseEDT; + fLatch = aLatch; + } + + @Override + public void init(final GLAutoDrawable drawable) { + // FIXME: We actually need to hook into GLContext make-current lock + masterLock.lock(); + try { + final GL2 gl = drawable.getGL().getGL2(); + gl.glClearColor(0.5f, 0.5f, 0.5f, 1.0f); + gl.glClear(GL.GL_COLOR_BUFFER_BIT); + + System.err.println(); System.err.println(); + System.err.println("Master (orig) Ct: "+drawable.getContext()); + // Create the external context on the caller thread. + final GLContext master = GLDrawableFactory.getDesktopFactory().createExternalGLContext(); + System.err.println(); System.err.println(); + System.err.println("External Context: "+master); + + // This runnable creates an offscreen drawable which shares with the external context. + final Runnable initializer = new Runnable() { + public void run() { + // FIXME: We actually need to hook into GLContext make-current lock + // masterLock.lock(); + try { + fOffscreenDrawable = GLDrawableFactory.getDesktopFactory().createOffscreenAutoDrawable( + GLProfile.getDefaultDevice(), + new GLCapabilities(GLProfile.getDefault()), + null, // new DefaultGLCapabilitiesChooser(), + 512, 512 + ); + fOffscreenDrawable.setSharedContext(master); + fOffscreenDrawable.addGLEventListener(new DumpGLInfo(Platform.getNewline()+Platform.getNewline()+"Slave GLContext", false, false, false)); + + try { + System.err.println(); System.err.println(); + System.err.println("Current: "+GLContext.getCurrent()); + fOffscreenDrawable.display(); + } catch (final GLException e) { + fException = e; + throw e; + } + } finally { + // masterLock.unlock(); + } + } + }; + + /** + * Depending on the test case, invoke the initialization on the EDT or on an + * executor thread. The test also displays the offscreen drawable a few times + * before finishing. + */ + if (fUseEDT) { + // Initialize using invokeLater(). + try { + // We cannot use EventQueue.invokeAndWait(..) since it will + // block this will block the current thread, holding the context! + // The whole issue w/ an external shared context is make-current + // synchronization. JOGL attempts to lock the surface/drawable + // of the master context to avoid concurrent usage. + // The semantic constraints of a shared context are not well defined, + // i.e. some driver may allow creating a shared context w/ a master context + // to be in use - others don't. + // Hence it is up to the user to sync the external master context in this case, + // see 'masterLock' of in this code! + // EventQueue.invokeAndWait(initializer); + EventQueue.invokeLater(initializer); + } catch (final Exception e) { + fException = e; + } + + // Display using a Swing timer, i.e. also on the EDT. + final Timer t = new Timer(200, new ActionListener() { + int i = 0; + + @Override + public void actionPerformed(final ActionEvent e) { + if (++i > LATCH_COUNT) { + return; + } + + System.err.println("Update on EDT"); + fOffscreenDrawable.display(); + fLatch.countDown(); + } + }); + t.start(); + } else { + // Initialize and display using a single-threaded executor. + final ScheduledExecutorService exe = Executors.newSingleThreadScheduledExecutor(); + exe.submit(initializer); + exe.scheduleAtFixedRate(new Runnable() { + int i = 0; + + @Override + public void run() { + if (++i > LATCH_COUNT) { + return; + } + + System.err.println("Update on Executor thread"); + fOffscreenDrawable.display(); + fLatch.countDown(); + } + }, 0, 200, TimeUnit.MILLISECONDS); + } + } finally { + masterLock.unlock(); + } + } + + @Override + public void dispose(final GLAutoDrawable drawable) { + // FIXME: We actually need to hook into GLContext make-current lock + masterLock.lock(); + try { + } finally { + masterLock.unlock(); + } + } + + @Override + public void display(final GLAutoDrawable drawable) { + // FIXME: We actually need to hook into GLContext make-current lock + masterLock.lock(); + try { + } finally { + masterLock.unlock(); + } + } + + @Override + public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { + // FIXME: We actually need to hook into GLContext make-current lock + masterLock.lock(); + try { + } finally { + masterLock.unlock(); + } + } + } + + public static void main(final String[] pArgs) + { + org.junit.runner.JUnitCore.main(TestSharedExternalContextAWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestVersionSemanticsNOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestVersionSemanticsNOUI.java index 7b8fa077a..bbbd92e5e 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestVersionSemanticsNOUI.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestVersionSemanticsNOUI.java @@ -56,12 +56,13 @@ public class TestVersionSemanticsNOUI extends SingletonJunitCase { static final VersionNumberString curVersionNumber = new VersionNumberString(curVersion.getImplementationVersion()); static final Set<String> excludesDefault; - static final Set<String> excludesStereoPackage; + static final Set<String> excludesStereoPackageAndAppletUtils; static { excludesDefault = new HashSet<String>(); excludesDefault.add("^\\Qjogamp/\\E.*$"); - excludesStereoPackage = new HashSet<String>(excludesDefault); - excludesStereoPackage.add("^\\Qcom/jogamp/opengl/util/stereo/\\E.*$"); + excludesStereoPackageAndAppletUtils = new HashSet<String>(excludesDefault); + excludesStereoPackageAndAppletUtils.add("^\\Qcom/jogamp/opengl/util/stereo/\\E.*$"); + excludesStereoPackageAndAppletUtils.add("^\\Qcom/jogamp/newt/util/applet/\\E.*$"); } @@ -138,7 +139,7 @@ public class TestVersionSemanticsNOUI extends SingletonJunitCase { VersionSemanticsUtil.testVersion(diffCriteria, expectedCompatibilityType, previousJar, preVersionNumber, curVersion.getClass(), currentCL, curVersionNumber, - excludesStereoPackage); + excludesStereoPackageAndAppletUtils); } public static void main(final String args[]) throws IOException { 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 9b414d7c5..f70df89dc 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 @@ -428,7 +428,8 @@ public class GearsES2 implements StereoGLEventListener, TileRendererBase.TileRen final Quaternion rollPitchYaw = new Quaternion(); // private final float eyeYaw = FloatUtil.PI; // 180 degrees in radians // rollPitchYaw.rotateByAngleY(eyeYaw); - final float[] shiftedEyePos = rollPitchYaw.rotateVector(vec3Tmp1, 0, viewerPose.position, 0); + // final float[] shiftedEyePos = rollPitchYaw.rotateVector(vec3Tmp1, 0, viewerPose.position, 0); + final float[] shiftedEyePos = VectorUtil.copyVec3(vec3Tmp1, 0, viewerPose.position, 0); VectorUtil.scaleVec3(shiftedEyePos, shiftedEyePos, vec3ScalePos); // amplify viewerPose position VectorUtil.addVec3(shiftedEyePos, shiftedEyePos, eyeParam.positionOffset); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/stereo/StereoDemo01.java b/src/test/com/jogamp/opengl/test/junit/jogl/stereo/StereoDemo01.java index c2e808770..0d1f1700d 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/stereo/StereoDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/stereo/StereoDemo01.java @@ -34,8 +34,10 @@ import java.util.Arrays; import com.jogamp.nativewindow.util.DimensionImmutable; import com.jogamp.nativewindow.util.PointImmutable; import com.jogamp.opengl.GL; +import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.GLRunnable; import jogamp.opengl.util.stereo.GenericStereoDevice; @@ -244,11 +246,6 @@ public class StereoDemo01 { } System.err.println("StereoDevice "+stereoDevice); - // Start the sensor which provides the Rift’s pose and motion. - if( !stereoDevice.startSensors(stereoDevice.getSupportedSensorBits(), 0) ) { - System.err.println("Could not start sensors on device "+deviceIndex); - } - // // // @@ -260,6 +257,11 @@ public class StereoDemo01 { final MonitorDevice monitor = StereoDeviceUtil.getMonitorDevice(stereoDevice, true); final Screen screen = monitor.getScreen(); + // Start the sensor which provides the Rift’s pose and motion. + if( !stereoDevice.startSensors(stereoDevice.getSupportedSensorBits(), 0) ) { + System.err.println("Could not start sensors on device "+deviceIndex); + } + final GLCapabilities caps = new GLCapabilities(GLProfile.getMaxProgrammable(true /* favorHardwareRasterizer */)); final GLWindow window = GLWindow.create(screen, caps); @@ -334,6 +336,24 @@ public class StereoDemo01 { return; } switch(e.getKeySymbol()) { + case KeyEvent.VK_O: { + window.invoke(false, new GLRunnable() { + @Override + public boolean run(final GLAutoDrawable drawable) { + stereoDevice.resetLocationSensorOrigin(); + return true; + } }); + break; + } + case KeyEvent.VK_P: { + window.invoke(false, new GLRunnable() { + @Override + public boolean run(final GLAutoDrawable drawable) { + System.err.println(stereoDeviceRenderer.getLastViewerPose()); + return true; + } }); + break; + } case KeyEvent.VK_R: { if( stereoDevice.getSensorsStarted() ) { stereoDevice.stopSensors(); diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java index d9e9fc0cb..477b761bd 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java +++ b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java @@ -36,6 +36,8 @@ import java.lang.reflect.InvocationTargetException; import java.util.concurrent.atomic.AtomicInteger; import java.awt.AWTException; import java.awt.EventQueue; +import java.awt.MouseInfo; +import java.awt.Point; import java.awt.Robot; import com.jogamp.nativewindow.NativeWindow; @@ -579,6 +581,25 @@ public class AWTRobotUtil { Assert.assertEquals("Wrong key count", typeCount, counter.getCount()-c0); } + public static void mouseMove(final Robot robot, final Point destination, final int iter, final int delay) { + final Point origin = MouseInfo.getPointerInfo().getLocation(); + for (int i = 1; i <= iter; i++) { + final float alpha = i / (float) iter; + robot.mouseMove((int) (origin.x * (1 - alpha) + destination.x * alpha), + (int) (origin.y * (1 - alpha) + destination.y * alpha)); + robot.delay(delay); + } + } + public static void mouseClick(final Robot robot, final Point pos, final int moveIter, final int moveDelay, final int actionDelay) { + robot.delay(actionDelay); + mouseMove(robot, pos, moveIter, moveDelay); + + robot.delay(actionDelay); + robot.mousePress(java.awt.event.InputEvent.BUTTON1_MASK); + robot.mouseRelease(java.awt.event.InputEvent.BUTTON1_MASK); + robot.delay(actionDelay); + } + static int mouseClick(final int i, final Robot robot, final int mouseButton, final Object obj, final InputEventCountAdapter counter) throws InterruptedException, AWTException, InvocationTargetException { diff --git a/src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java b/src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java index a2887112f..76f73989a 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java +++ b/src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java @@ -34,10 +34,32 @@ import com.jogamp.opengl.JoglVersion; public class DumpGLInfo implements GLEventListener { + final String header; + final boolean withGLAvailability; + final boolean withCapabilities; + final boolean withExtensions; + + public DumpGLInfo(final String header, final boolean withGLAvailability, final boolean withCapabilities, final boolean withExtensions) { + this.header = header; + this.withGLAvailability = withGLAvailability; + this.withCapabilities = withCapabilities; + this.withExtensions = withExtensions; + } + public DumpGLInfo() { + this.header = null; + this.withGLAvailability = true; + this.withCapabilities = true; + this.withExtensions = true; + } public void init(final GLAutoDrawable drawable) { final GL gl = drawable.getGL(); - System.err.println(JoglVersion.getGLInfo(gl, null, true)); + if( null != header ) { + System.err.println(header); + } + System.err.println(JoglVersion.getGLInfo(gl, null, withGLAvailability, withCapabilities, withExtensions)); + System.err.println("Drawable: "+drawable.getDelegatedDrawable().getClass().getSimpleName()); + System.err.println(drawable.getChosenGLCapabilities()); } public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { diff --git a/src/test/com/jogamp/opengl/test/junit/util/GLClearColor.java b/src/test/com/jogamp/opengl/test/junit/util/GLClearColor.java new file mode 100644 index 000000000..7a19ffe6f --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/GLClearColor.java @@ -0,0 +1,61 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.util; + + +import com.jogamp.opengl.*; +import com.jogamp.opengl.JoglVersion; + + +public class GLClearColor implements GLEventListener { + private final float red, green, blue, alpha; + + public GLClearColor(final float red, final float green, final float blue, final float alpha) { + this.red = red; + this.green = green; + this.blue = blue; + this.alpha = alpha; + } + public void init(final GLAutoDrawable drawable) { + final GL gl = drawable.getGL(); + gl.glClearColor(red, green, blue, alpha); + } + + public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { + } + + public void display(final GLAutoDrawable drawable) { + final GL gl = drawable.getGL(); + gl.glClearColor(red, green, blue, alpha); + gl.glClear(GL.GL_COLOR_BUFFER_BIT); + } + + public void dispose(final GLAutoDrawable drawable) { + } +} |