@Test public void testWindowParenting02CreateVisibleDestroy3Odd() throws InterruptedException { int x = 0; int y = 0; NEWTEventFiFo eventFifo = new NEWTEventFiFo(); GLWindow glWindow1 = GLWindow.create(glCaps); GLEventListener demo1 = new RedSquare(); setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); Frame frame = new Frame("AWT Parent Frame"); Assert.assertNotNull(frame); frame.setSize(width, height); // visible test frame.setVisible(true); frame.add(newtCanvasAWT); Animator animator1 = new Animator(glWindow1); animator1.start(); while (animator1.isAnimating() && animator1.getDuration() < durationPerTest) { Thread.sleep(100); } Assert.assertEquals(true, animator1.isAnimating()); // !!! frame.dispose(); glWindow1.destroy(true); }
@Test public void testWindowParenting04ReparentNewtWin2TopLayouted() throws InterruptedException { int x = 0; int y = 0; NEWTEventFiFo eventFifo = new NEWTEventFiFo(); GLWindow glWindow1 = GLWindow.create(glCaps); GLEventListener demo1 = new RedSquare(); setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); Frame frame = new Frame("AWT Parent Frame"); frame.setLayout(new BorderLayout()); frame.add(new Button("North"), BorderLayout.NORTH); frame.add(new Button("South"), BorderLayout.SOUTH); frame.add(new Button("East"), BorderLayout.EAST); frame.add(new Button("West"), BorderLayout.WEST); frame.setSize(width, height); frame.setLocation(640, 480); frame.setVisible(true); frame.add(newtCanvasAWT, BorderLayout.CENTER); Assert.assertEquals(newtCanvasAWT.getNativeWindow(), glWindow1.getParentNativeWindow()); Animator animator1 = new Animator(glWindow1); animator1.start(); int state = 0; while (animator1.isAnimating() && animator1.getDuration() < 3 * durationPerTest) { Thread.sleep(durationPerTest); switch (state) { case 0: glWindow1.reparentWindow(null, null); Assert.assertEquals(true, glWindow1.isNativeWindowValid()); Assert.assertNull(glWindow1.getParentNativeWindow()); break; case 1: glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow(), null); Assert.assertEquals(true, glWindow1.isNativeWindowValid()); Assert.assertEquals(newtCanvasAWT.getNativeWindow(), glWindow1.getParentNativeWindow()); break; } state++; } animator1.stop(); Assert.assertEquals(false, animator1.isAnimating()); frame.dispose(); glWindow1.destroy(true); }
@Test public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException { int x = 0; int y = 0; NEWTEventFiFo eventFifo = new NEWTEventFiFo(); GLWindow glWindow1 = GLWindow.create(glCaps); Assert.assertNotNull(glWindow1); Assert.assertEquals(false, glWindow1.isVisible()); Assert.assertEquals(false, glWindow1.isNativeWindowValid()); Assert.assertNull(glWindow1.getParentNativeWindow()); glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy"); GLEventListener demo1 = new RedSquare(); setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1); Assert.assertNotNull(newtCanvasAWT); Assert.assertEquals(false, glWindow1.isVisible()); Assert.assertEquals(false, glWindow1.isNativeWindowValid()); Assert.assertNull(glWindow1.getParentNativeWindow()); Frame frame1 = new Frame("AWT Parent Frame"); frame1.setLayout(new BorderLayout()); frame1.add(new Button("North"), BorderLayout.NORTH); frame1.add(new Button("South"), BorderLayout.SOUTH); frame1.add(new Button("East"), BorderLayout.EAST); frame1.add(new Button("West"), BorderLayout.WEST); Container container1 = new Container(); container1.setLayout(new BorderLayout()); container1.add(new Button("north"), BorderLayout.NORTH); container1.add(new Button("south"), BorderLayout.SOUTH); container1.add(new Button("east"), BorderLayout.EAST); container1.add(new Button("west"), BorderLayout.WEST); container1.add(newtCanvasAWT, BorderLayout.CENTER); frame1.add(container1, BorderLayout.CENTER); frame1.setSize(width, height); // visible test frame1.setVisible(true); Assert.assertEquals(newtCanvasAWT.getNativeWindow(), glWindow1.getParentNativeWindow()); Animator animator1 = new Animator(glWindow1); animator1.start(); while (animator1.isAnimating() && animator1.getDuration() < durationPerTest) { Thread.sleep(100); } animator1.stop(); Assert.assertEquals(false, animator1.isAnimating()); frame1.setVisible(false); Assert.assertEquals(false, glWindow1.isDestroyed()); frame1.setVisible(true); Assert.assertEquals(false, glWindow1.isDestroyed()); frame1.remove(newtCanvasAWT); // Assert.assertNull(glWindow1.getParentNativeWindow()); Assert.assertEquals(false, glWindow1.isDestroyed()); frame1.dispose(); Assert.assertEquals(false, glWindow1.isDestroyed()); glWindow1.destroy(true); // Assert.assertEquals(true, glWindow1.isDestroyed()); }
public void testWindowParenting1AWTTwoNewtChilds() throws InterruptedException, InvocationTargetException { Frame frame1 = new Frame("AWT Parent Frame"); GLWindow glWindow1 = GLWindow.create(glCaps); glWindow1.setUpdateFPSFrames(1, null); NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1); newtCanvasAWT1.setPreferredSize(size); GLEventListener demo1 = new GearsES2(1); setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); glWindow1.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1)); GLAnimatorControl animator1 = new Animator(glWindow1); animator1.start(); GLWindow glWindow2 = GLWindow.create(glCaps); glWindow2.setUpdateFPSFrames(1, null); NewtCanvasAWT newtCanvasAWT2 = new NewtCanvasAWT(glWindow2); newtCanvasAWT2.setPreferredSize(size); GLEventListener demo2 = new GearsES2(1); setDemoFields(demo2, glWindow2, false); glWindow2.addGLEventListener(demo2); glWindow2.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT2, glWindow2)); GLAnimatorControl animator2 = new Animator(glWindow2); animator2.start(); Container cont1 = new Container(); cont1.setLayout(new BorderLayout()); cont1.add(newtCanvasAWT1, BorderLayout.CENTER); System.err.println("******* Cont1 setVisible"); cont1.setVisible(true); Container cont2 = new Container(); cont2.setLayout(new BorderLayout()); cont2.add(newtCanvasAWT2, BorderLayout.CENTER); System.err.println("******* Cont2 setVisible"); cont2.setVisible(true); final Container f_cont2 = cont2; frame1.setLayout(new BorderLayout()); frame1.add(new Label("NORTH"), BorderLayout.NORTH); frame1.add(new Label("CENTER"), BorderLayout.CENTER); frame1.add(new Label("SOUTH"), BorderLayout.SOUTH); frame1.add(cont1, BorderLayout.EAST); frame1.setLocation(0, 0); frame1.setSize((int) size.getWidth() * 2, (int) size.getHeight() * 2); final Frame f_frame1 = frame1; javax.swing.SwingUtilities.invokeAndWait( new Runnable() { public void run() { f_frame1.pack(); System.err.println("******* Frame setVisible"); f_frame1.setVisible(true); } }); Assert.assertEquals(newtCanvasAWT1.getNativeWindow(), glWindow1.getParent()); Assert.assertEquals(newtCanvasAWT2.getNativeWindow(), glWindow2.getParent()); Assert.assertEquals(true, animator1.isAnimating()); Assert.assertEquals(false, animator1.isPaused()); Assert.assertNotNull(animator1.getThread()); Assert.assertEquals(true, animator2.isAnimating()); Assert.assertEquals(false, animator2.isPaused()); Assert.assertNotNull(animator2.getThread()); Thread.sleep(waitAdd2nd); javax.swing.SwingUtilities.invokeAndWait( new Runnable() { public void run() { f_frame1.add(f_cont2, BorderLayout.WEST); f_frame1.pack(); } }); Thread.sleep(durationPerTest); animator1.stop(); Assert.assertEquals(false, animator1.isAnimating()); Assert.assertEquals(false, animator1.isPaused()); Assert.assertEquals(null, animator1.getThread()); animator2.stop(); Assert.assertEquals(false, animator2.isAnimating()); Assert.assertEquals(false, animator2.isPaused()); Assert.assertEquals(null, animator2.getThread()); frame1.dispose(); glWindow1.destroy(); glWindow2.destroy(); }
protected void runOneSet( GLAutoDrawable drawable, String textBaseName, int numObjs, int numTextures, int loops) { GL2ES2 gl = drawable.getGL().getGL2ES2(); if (numTextures > MAX_TEXTURE_ENGINES) { throw new GLException("numTextures must be within 1.." + MAX_TEXTURE_ENGINES); } String textName = null; textDatas = new TextureData[numObjs]; textures = new Texture[numTextures]; try { for (int i = 0; i < numObjs; i++) { textName = "data/" + textBaseName + "." + (i + 1) + ".tga"; URL urlText = IOUtil.getResource(Perftst.class, textName); if (urlText == null) { throw new RuntimeException("couldn't fetch " + textName); } textDatas[i] = TextureIO.newTextureData(gl.getGLProfile(), urlText.openStream(), false, TextureIO.TGA); System.out.println(textBaseName + ": " + textDatas[i]); } for (int i = 0; i < numTextures; i++) { gl.glActiveTexture(i); textures[i] = new Texture(GL.GL_TEXTURE_2D); } } catch (IOException ioe) { System.err.println("couldn't fetch " + textName); throw new RuntimeException(ioe); } // // Vertices Data setup // st.useProgram(gl, true); GLArrayDataServer vertices = GLArrayDataServer.createGLSL("mgl_Vertex", 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); { FloatBuffer vb = (FloatBuffer) vertices.getBuffer(); vb.put(0f); vb.put(0f); vb.put(1f); vb.put(0f); vb.put(0f); vb.put(1f); vb.put(1f); vb.put(1f); } vertices.seal(gl, true); GLArrayDataServer texCoords = GLArrayDataServer.createGLSL( "mgl_MultiTexCoord0", 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); { FloatBuffer cb = (FloatBuffer) texCoords.getBuffer(); cb.put(0f); cb.put(0f); cb.put(1f); cb.put(0f); cb.put(0f); cb.put(1f); cb.put(1f); cb.put(1f); } texCoords.seal(gl, true); // // texture setup // long[] tU = new long[numObjs + 1]; tU[0] = System.currentTimeMillis(); for (int j = 0; j < numTextures; j++) { gl.glActiveTexture(j); textures[j].updateImage(gl, textDatas[0]); tU[j + 1] = System.currentTimeMillis(); } GLUniformData activeTexture = new GLUniformData("mgl_ActiveTexture", 0); st.uniform(gl, activeTexture); // // run loops // long dtC, dt, dt2, dt3, dtF, dtS, dtT; long[][] tC = new long[loops][numObjs]; long[][] t0 = new long[loops][numObjs]; long[][][] t1 = new long[loops][numObjs][numTextures]; long[][][] t2 = new long[loops][numObjs][numTextures]; long[][][] t3 = new long[loops][numObjs][numTextures]; long[][] tF = new long[loops][numObjs]; long[][] tS = new long[loops][numObjs]; for (int i = 0; i < loops; i++) { for (int j = 0; j < numObjs; j++) { tC[i][j] = System.currentTimeMillis(); gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); t0[i][j] = System.currentTimeMillis(); for (int k = 0; k < numTextures; k++) { gl.glActiveTexture(GL.GL_TEXTURE0 + k); textures[k].enable(gl); textures[k].bind(gl); activeTexture.setData(k); st.uniform(gl, activeTexture); t1[i][j][k] = System.currentTimeMillis(); textures[k].updateSubImage(gl, textDatas[j], 0, 0, 0); t2[i][j][k] = System.currentTimeMillis(); gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, vertices.getElementCount()); t3[i][j][k] = System.currentTimeMillis(); } gl.glFinish(); tF[i][j] = System.currentTimeMillis(); drawable.swapBuffers(); tS[i][j] = System.currentTimeMillis(); /*try { Thread.sleep(100); } catch (Exception e) {} */ } } int textBytes = 0; for (int j = 0; j < numObjs; j++) { textBytes += textDatas[j].getEstimatedMemorySize(); } textBytes *= numTextures; dt = 0; for (int i = 1; i < loops; i++) { for (int j = 0; j < numObjs; j++) { dt += tS[i][j] - tC[i][j]; } } System.out.println(""); System.out.println( "Texture " + textBaseName + ", loops " + loops + ", textures " + numTextures + ", objects " + numObjs + ", total bytes " + textBytes + ", total time: " + dt + "ms, fps(-1): " + (((loops - 1) * numObjs * 1000) / dt) + ",\n text kB/s: " + (((double) (loops * textBytes) / 1024.0) / ((double) dt / 1000.0))); for (int i = 0; i < loops; i++) { dtC = 0; dtF = 0; dtS = 0; dtT = 0; for (int j = 0; j < numObjs; j++) { dtC += t0[i][j] - tC[i][j]; dtF += tF[i][j] - t3[i][j][numTextures - 1]; dtS += tS[i][j] - tF[i][j]; dtT += tS[i][j] - tC[i][j]; } if (dtT <= 0) dtT = 1; System.out.println( "\tloop " + i + ": clear " + dtC + "ms, finish " + dtF + ", swap " + dtS + "ms, total: " + dtT + "ms, fps " + (numObjs * 1000) / dtT); /* for(int j=0; j<dummyUni.length; j++) { dt = t1[i][j] - t0[i]; dt2= t2[i][j] - t1[i][j]; dt3= t3[i][j] - t2[i][j]; dtT= dt+dt2+dt3; System.out.println("\t\tobj "+j+": setup "+dt +"ms, update "+dt2 +"ms, draw "+dt3+"ms, total: "+ dtT); } */ } System.out.println("*****************************************************************"); st.useProgram(gl, false); for (int i = 0; i < numTextures; i++) { textures[i].disable(gl); textures[i].destroy(gl); textures[i] = null; } for (int i = 0; i < numObjs; i++) { textDatas[i] = null; } textures = null; textDatas = null; System.gc(); try { Thread.sleep(100); } catch (Exception e) { } System.gc(); }
protected void runTestGL(final GLCapabilitiesImmutable caps) throws InterruptedException { final Display nDisplay = NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null, false); // local display final Screen nScreen = NewtFactory.createScreen(nDisplay, 0); // screen 0 final Window nWindow = NewtFactory.createWindow(nScreen, caps); final GLWindow glWindow = GLWindow.create(nWindow); Assert.assertNotNull(glWindow); glWindow.setTitle("Gears NewtAWTWrapper Test"); glWindow.addGLEventListener(new GearsES2(1)); final Animator animator = useAnimator ? new Animator(glWindow) : null; final QuitAdapter quitAdapter = new QuitAdapter(); glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter)); glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter)); if (useAnimator) { animator.start(); } int div = 3; glWindow.setSize(width / div, height / div); glWindow.setVisible(true); if (doResizeTest) { glWindow.display(); final int[] expSurfaceSize = glWindow.getNativeSurface().convertToPixelUnits(new int[] {width / div, height / div}); Assert.assertTrue( "Surface Size not reached: Expected " + expSurfaceSize[0] + "x" + expSurfaceSize[1] + ", Is " + glWindow.getSurfaceWidth() + "x" + glWindow.getSurfaceHeight(), AWTRobotUtil.waitForSize(glWindow, expSurfaceSize[0], expSurfaceSize[1])); Thread.sleep(600); div = 2; glWindow.setSize(width / div, height / div); glWindow.display(); expSurfaceSize[0] = width / div; expSurfaceSize[1] = height / div; glWindow.getNativeSurface().convertToPixelUnits(expSurfaceSize); Assert.assertTrue( "Surface Size not reached: Expected " + expSurfaceSize[0] + "x" + expSurfaceSize[1] + ", Is " + glWindow.getSurfaceWidth() + "x" + glWindow.getSurfaceHeight(), AWTRobotUtil.waitForSize(glWindow, expSurfaceSize[0], expSurfaceSize[1])); Thread.sleep(600); div = 1; glWindow.setSize(width / div, height / div); glWindow.display(); expSurfaceSize[0] = width / div; expSurfaceSize[1] = height / div; glWindow.getNativeSurface().convertToPixelUnits(expSurfaceSize); Assert.assertTrue( "Surface Size not reached: Expected " + expSurfaceSize[0] + "x" + expSurfaceSize[1] + ", Is " + glWindow.getSurfaceWidth() + "x" + glWindow.getSurfaceHeight(), AWTRobotUtil.waitForSize(glWindow, expSurfaceSize[0], expSurfaceSize[1])); Thread.sleep(600); } final long t0 = System.currentTimeMillis(); long t1 = t0; while (!quitAdapter.shouldQuit() && t1 - t0 < duration) { Thread.sleep(100); t1 = System.currentTimeMillis(); } if (useAnimator) { animator.stop(); } glWindow.destroy(); }