From 42a3da77136f0f39679f022b9c7e243464025539 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 17 Jun 2009 13:32:55 +0000 Subject: RedSquare: single thread / one-pump test git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/trunk@354 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4 --- src/demos/es2/RedSquare.java | 104 ++++++++++++++++++++++++++++++++----------- 1 file changed, 78 insertions(+), 26 deletions(-) (limited to 'src/demos/es2/RedSquare.java') diff --git a/src/demos/es2/RedSquare.java b/src/demos/es2/RedSquare.java index b0f86d1..3389204 100755 --- a/src/demos/es2/RedSquare.java +++ b/src/demos/es2/RedSquare.java @@ -18,8 +18,6 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo private GLProfile glp; private GLU glu; private boolean quit = false; - private long startTime; - private long curTime; private String glprofile; private int type; @@ -84,6 +82,8 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo public void mouseWheelMoved(MouseEvent e) { } + public boolean shouldQuit() { return quit; } + public void run() { System.err.println(glp+" RedSquare.run()"); int width = 800; @@ -105,7 +105,8 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo window.addKeyListener(this); window.addGLEventListener(this); // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_CURRENT); // default - // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_NONE); // no current .. + window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_NONE); // no current .. + window.setRunPumpMessages(pumpOnce?false:true); // Size OpenGL to Video Surface window.setSize(width, height); @@ -113,21 +114,44 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo window.setVisible(true); window.enablePerfLog(true); - startTime = System.currentTimeMillis(); + if(!oneThread) { + do { + display(); + } while (!quit && window.getDuration() < 20000) ; - while (!quit && ((curTime = System.currentTimeMillis()) - startTime) < 20000) { - window.display(); + shutdown(); } + } catch (Throwable t) { + t.printStackTrace(); + } + } + + public void display() { + try { + if(pumpOnce && !oneThread) { + GLWindow.runCurrentThreadPumpMessage(); + } + window.display(); + } catch (Throwable t) { + t.printStackTrace(); + } + } + + public void shutdown() { + try { // Shut things down cooperatively window.destroy(); - window.getFactory().shutdown(); + if(oneThread) { + window.getFactory().shutdown(); + } System.out.println(glp+" RedSquare shut down cleanly."); } catch (Throwable t) { t.printStackTrace(); } } + ShaderState st; PMVMatrix pmvMatrix; @@ -251,7 +275,7 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo pmvMatrix.glMatrixMode(pmvMatrix.GL_MODELVIEW); pmvMatrix.glLoadIdentity(); pmvMatrix.glTranslatef(0, 0, -10); - float ang = ((float) (curTime - startTime) * 360.0f) / 4000.0f; + float ang = ((float) window.getDuration() * 360.0f) / 4000.0f; pmvMatrix.glRotatef(ang, 0, 0, 1); pmvMatrix.glRotatef(ang, 0, 1, 0); @@ -273,42 +297,70 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo public static int USE_NEWT = 0; public static int USE_AWT = 1 << 0; + public static boolean oneThread = false; + public static boolean pumpOnce = true; + public static void main(String[] args) { int type = USE_NEWT ; List threads = new ArrayList(); for(int i=0; i0) { + if(pumpOnce) { + GLWindow.runCurrentThreadPumpMessage(); + } + for(Iterator i = threads.iterator(); i.hasNext(); ) { + RedSquare app = (RedSquare) i.next(); + if(app.shouldQuit()) { + app.shutdown(); + i.remove(); + } else { + app.display(); + } } } - done = 0==aliveCount ; } } } -- cgit v1.2.3