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/es1/RedSquare.java | 101 +++++++++++++++++++++++++++++++++---------- 1 file changed, 78 insertions(+), 23 deletions(-) (limited to 'src/demos/es1/RedSquare.java') diff --git a/src/demos/es1/RedSquare.java b/src/demos/es1/RedSquare.java index 5c8e7fa..b8592d8 100755 --- a/src/demos/es1/RedSquare.java +++ b/src/demos/es1/RedSquare.java @@ -82,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() 0"); int width = 800; @@ -103,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); window.enablePerfLog(true); // Size OpenGL to Video Surface @@ -112,19 +115,43 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo window.setVisible(true); window.enablePerfLog(true); - do { - window.display(); - } while (!quit && window.getDuration() < 20000) ; + if(!oneThread) { + do { + display(); + } while (!quit && window.getDuration() < 20000) ; + + 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(); } } + // FIXME: we must add storage of the pointers in the GL state to // the GLImpl classes. The need for this can be seen by making // these variables method local instead of instance members. The @@ -217,42 +244,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