private void testImpl(final GLCapabilities caps, final GLEventListener glel) throws InterruptedException { final GLWindow glWindow = GLWindow.create(caps); Assert.assertNotNull(glWindow); glWindow.setSize(800, 600); glWindow.setVisible(true); glWindow.setTitle("JOGL Tessellation Shader Test"); Assert.assertTrue(glWindow.isNativeValid()); final QuitAdapter quitAdapter = new QuitAdapter(); glWindow.addKeyListener(quitAdapter); glWindow.addWindowListener(quitAdapter); glWindow.addGLEventListener(glel); final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener(); glWindow.addGLEventListener(snapshotGLEventListener); final Animator animator = new Animator(glWindow); animator.start(); animator.setUpdateFPSFrames(60, System.err); snapshotGLEventListener.setMakeSnapshot(); while (!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration() < duration) { Thread.sleep(100); } animator.stop(); glWindow.destroy(); }
protected void runTestGL(final GLCapabilities caps, final boolean forceFFPEmu) throws InterruptedException { final GLWindow glWindow = GLWindow.create(caps); Assert.assertNotNull(glWindow); glWindow.setTitle("Gears NEWT Test"); final GearsES1 demo = new GearsES1(swapInterval); demo.setForceFFPEmu(forceFFPEmu, forceFFPEmu, false, false); glWindow.addGLEventListener(demo); final SnapshotGLEventListener snap = new SnapshotGLEventListener(); glWindow.addGLEventListener(snap); final Animator animator = new Animator(glWindow); final QuitAdapter quitAdapter = new QuitAdapter(); // glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter)); // glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter)); glWindow.addKeyListener(quitAdapter); glWindow.addWindowListener(quitAdapter); final GLWindow f_glWindow = glWindow; glWindow.addKeyListener( new KeyAdapter() { public void keyReleased(final KeyEvent e) { if (!e.isPrintableKey() || e.isAutoRepeat()) { return; } if (e.getKeyChar() == 'f') { new Thread() { public void run() { f_glWindow.setFullscreen(!f_glWindow.isFullscreen()); } }.start(); } else if (e.getKeyChar() == 'd') { new Thread() { public void run() { f_glWindow.setUndecorated(!f_glWindow.isUndecorated()); } }.start(); } } }); glWindow.setSize(width, height); glWindow.setVisible(true); animator.setUpdateFPSFrames(1, null); animator.start(); snap.setMakeSnapshot(); while (!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration() < duration) { Thread.sleep(100); } animator.stop(); glWindow.destroy(); }
public void testImpl(boolean useFFP, final InputStream istream) throws InterruptedException, IOException { final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false); GLProfile glp; if (useFFP && GLProfile.isAvailable(GLProfile.GL2)) { glp = GLProfile.getMaxFixedFunc(true); } else if (!useFFP && GLProfile.isAvailable(GLProfile.GL2ES2)) { glp = GLProfile.getGL2ES2(); } else { System.err.println(getSimpleTestName(".") + ": GLProfile n/a, useFFP: " + useFFP); return; } final GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(1); final TextureData texData = TextureIO.newTextureData(glp, istream, false /* mipmap */, TextureIO.TGA); System.err.println("TextureData: " + texData); final GLWindow glad = GLWindow.create(caps); glad.setTitle("TestTGATextureGL2FromFileNEWT"); // Size OpenGL to Video Surface glad.setSize(texData.getWidth(), texData.getHeight()); // load texture from file inside current GL context to match the way // the bug submitter was doing it final GLEventListener gle = useFFP ? new TextureDraw01GL2Listener(texData) : new TextureDraw01ES2Listener(texData, 0); glad.addGLEventListener(gle); glad.addGLEventListener( new GLEventListener() { boolean shot = false; @Override public void init(GLAutoDrawable drawable) {} public void display(GLAutoDrawable drawable) { // 1 snapshot if (null != ((TextureDraw01Accessor) gle).getTexture() && !shot) { shot = true; snapshot(0, null, drawable.getGL(), screenshot, TextureIO.PNG, null); } } @Override public void dispose(GLAutoDrawable drawable) {} @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {} }); Animator animator = new Animator(glad); animator.setUpdateFPSFrames(60, showFPS ? System.err : null); QuitAdapter quitAdapter = new QuitAdapter(); glad.addKeyListener(quitAdapter); glad.addWindowListener(quitAdapter); glad.setVisible(true); animator.start(); while (!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration() < duration) { Thread.sleep(100); } animator.stop(); glad.destroy(); }
@Test public void compileShader() throws InterruptedException { GLProfile glp = GLProfile.get(GLProfile.GL2GL3); GLCapabilities caps = new GLCapabilities(glp); // commenting out this line makes it work caps.setStencilBits(8); // commenting in this line also makes it work // caps.setSampleBuffers(true); final Frame frame = new Frame("Bug 459 shader compilation test"); Assert.assertNotNull(frame); final GLCanvas glCanvas = new GLCanvas(caps); Assert.assertNotNull(glCanvas); frame.add(glCanvas); glCanvas.addGLEventListener( new GLEventListener() { /* @Override */ public void init(GLAutoDrawable drawable) { String code = "void main(void){gl_Position = vec4(0,0,0,1);}"; GL2GL3 gl = drawable.getGL().getGL2GL3(); int id = gl.glCreateShader(GL2GL3.GL_VERTEX_SHADER); try { gl.glShaderSource(id, 1, new String[] {code}, (int[]) null, 0); gl.glCompileShader(id); int[] compiled = new int[1]; gl.glGetShaderiv(id, GL2GL3.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == GL2GL3.GL_FALSE) { int[] logLength = new int[1]; gl.glGetShaderiv(id, GL2GL3.GL_INFO_LOG_LENGTH, logLength, 0); byte[] log = new byte[logLength[0]]; gl.glGetShaderInfoLog(id, logLength[0], (int[]) null, 0, log, 0); System.err.println("Error compiling the shader: " + new String(log)); gl.glDeleteShader(id); } else { System.out.println("Shader compiled: id=" + id); } } catch (GLException e) { glexception = e; } } /* @Override */ public void dispose(GLAutoDrawable drawable) {} /* @Override */ public void display(GLAutoDrawable drawable) {} /* @Override */ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {} }); Animator animator = new Animator(glCanvas); try { javax.swing.SwingUtilities.invokeAndWait( new Runnable() { public void run() { frame.setSize(512, 512); frame.setVisible(true); } }); } catch (Exception ex) { throw new RuntimeException(ex); } animator.setUpdateFPSFrames(1, null); animator.start(); while (animator.isAnimating() && animator.getTotalFPSDuration() < duration) { Thread.sleep(100); } Assert.assertTrue(glexception != null ? glexception.getMessage() : "", glexception == null); Assert.assertNotNull(frame); Assert.assertNotNull(glCanvas); Assert.assertNotNull(animator); animator.stop(); Assert.assertEquals(false, animator.isAnimating()); try { javax.swing.SwingUtilities.invokeAndWait( new Runnable() { public void run() { frame.setVisible(false); frame.remove(glCanvas); frame.dispose(); } }); } catch (Throwable throwable) { throwable.printStackTrace(); Assume.assumeNoException(throwable); } }
public void testImpl() throws InterruptedException { final JFrame frame = new JFrame(this.getSimpleTestName(".")); // // GLDrawableFactory factory = GLDrawableFactory.getFactory(GLProfile.get(GLProfile.GL2)); // GLContext sharedContext = factory.getOrCreateSharedContext(factory.getDefaultDevice()); // final GLCapabilities glCapabilities = new GLCapabilities(GLProfile.get(GLProfile.GL2)); glCapabilities.setSampleBuffers(true); glCapabilities.setNumSamples(4); final GearsES2 eventListener1 = new GearsES2(0); final GearsES2 eventListener2 = new GearsES2(1); final Component openGLComponent1; final Component openGLComponent2; final GLAutoDrawable openGLAutoDrawable1; final GLAutoDrawable openGLAutoDrawable2; final GLWindow glWindow1 = GLWindow.create(glCapabilities); final NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1); newtCanvasAWT1.setPreferredSize(new Dimension(640, 480)); glWindow1.addGLEventListener(eventListener1); // final GLWindow glWindow2 = GLWindow.create(glCapabilities); final NewtCanvasAWT newtCanvasAWT2 = new NewtCanvasAWT(glWindow2); newtCanvasAWT2.setPreferredSize(new Dimension(640, 480)); glWindow2.addGLEventListener(eventListener2); openGLComponent1 = newtCanvasAWT1; openGLComponent2 = newtCanvasAWT2; openGLAutoDrawable1 = glWindow1; openGLAutoDrawable2 = glWindow2; // group both OpenGL canvases / windows into a horizontal panel final JPanel openGLPanel = new JPanel(); openGLPanel.setLayout(new BoxLayout(openGLPanel, BoxLayout.LINE_AXIS)); openGLPanel.add(openGLComponent1); openGLPanel.add(Box.createHorizontalStrut(5)); openGLPanel.add(openGLComponent2); final JPanel mainPanel = (JPanel) frame.getContentPane(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.LINE_AXIS)); mainPanel.add(Box.createHorizontalGlue()); mainPanel.add(openGLPanel); mainPanel.add(Box.createHorizontalGlue()); final Animator animator = new Animator(Thread.currentThread().getThreadGroup()); animator.setUpdateFPSFrames(1, null); animator.add(openGLAutoDrawable1); animator.add(openGLAutoDrawable2); // make the window visible using the EDT SwingUtilities.invokeLater( new Runnable() { public void run() { frame.pack(); frame.setVisible(true); } }); Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true)); Assert.assertEquals(true, AWTRobotUtil.waitForRealized(openGLComponent1, true)); Assert.assertEquals(true, AWTRobotUtil.waitForRealized(openGLComponent2, true)); animator.start(); // sleep for test duration, then request the window to close, wait for the window to close,s and // stop the animation while (animator.isAnimating() && animator.getTotalFPSDuration() < durationPerTest) { Thread.sleep(100); } animator.stop(); // ask the EDT to dispose of the frame; // if using newt, explicitly dispose of the canvases because otherwise it seems our destroy // methods are not called SwingUtilities.invokeLater( new Runnable() { public void run() { newtCanvasAWT1.destroy(); // removeNotify does not destroy GLWindow newtCanvasAWT2.destroy(); // removeNotify does not destroy GLWindow frame.dispose(); } }); Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, false)); Assert.assertEquals(true, AWTRobotUtil.waitForRealized(openGLComponent1, false)); Assert.assertEquals(true, AWTRobotUtil.waitForRealized(openGLComponent2, false)); }