diff options
author | Sven Gothel <[email protected]> | 2009-06-17 13:32:55 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2009-06-17 13:32:55 +0000 |
commit | 42a3da77136f0f39679f022b9c7e243464025539 (patch) | |
tree | e84523a9f76aa43cfb8722308fd9d332fbcf90f9 /src/demos/es2 | |
parent | ac2cdb722753f4eb5294cac532d54b284ad21725 (diff) |
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
Diffstat (limited to 'src/demos/es2')
-rwxr-xr-x | src/demos/es2/RedSquare.java | 104 |
1 files changed, 78 insertions, 26 deletions
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; i<args.length; i++) { - if(args[i].equals("-awt")) { + if(args[i].equals("-pumponce")) { + pumpOnce=true; + } else if(args[i].equals("-1thread")) { + oneThread=true; + } else if(args[i].equals("-awt")) { type |= USE_AWT; - } - if(args[i].startsWith("-GL")) { + } else if(args[i].startsWith("-GL")) { threads.add(new RedSquare(args[i].substring(1), type)); } } if(threads.size()==0) { threads.add(new RedSquare(null, type)); } - Thread firstT = (Thread) threads.remove(0); - for(Iterator i = threads.iterator(); i.hasNext(); ) { - ((Thread)i.next()).start(); - } + if(!oneThread) { + Thread firstT = (Thread) threads.remove(0); - // always run the first on main .. - firstT.run(); + for(Iterator i = threads.iterator(); i.hasNext(); ) { + ((Thread)i.next()).start(); + } + + // always run the first on main .. + firstT.run(); - boolean done = false; + boolean done = false; - while(!done) { - int aliveCount = 0; + while(!done) { + int aliveCount = 0; + for(Iterator i = threads.iterator(); i.hasNext(); ) { + if ( ((Thread)i.next()).isAlive() ) { + try { + Thread.sleep(100); + } catch (InterruptedException ie) {} + aliveCount++; + } + } + done = 0==aliveCount ; + } + } else { + // init all .. for(Iterator i = threads.iterator(); i.hasNext(); ) { - if ( ((Thread)i.next()).isAlive() ) { - try { - Thread.sleep(100); - } catch (InterruptedException ie) {} - aliveCount++; + ((Thread)i.next()).run(); + } + while (threads.size()>0) { + 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 ; } } } |