diff options
-rwxr-xr-x | java-macosx-mainthread.sh | 3 | ||||
-rwxr-xr-x | java-macosx.sh | 3 | ||||
-rwxr-xr-x | src/demos/es1/RedSquare.java | 101 | ||||
-rwxr-xr-x | src/demos/es2/RedSquare.java | 104 |
4 files changed, 162 insertions, 49 deletions
diff --git a/java-macosx-mainthread.sh b/java-macosx-mainthread.sh index d8536fa..706b030 100755 --- a/java-macosx-mainthread.sh +++ b/java-macosx-mainthread.sh @@ -1,3 +1,6 @@ #! /bin/sh +# -Dgluegen.debug.ProcAddressHelper=true -Dgluegen.debug.NativeLibrary=true -Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all +# -Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all + java -XstartOnFirstThread -Djava.awt.headless=true com.sun.javafx.newt.util.MainThread $* 2>&1 | tee java-macosx.mainThread.log diff --git a/java-macosx.sh b/java-macosx.sh index ee793df..71f5549 100755 --- a/java-macosx.sh +++ b/java-macosx.sh @@ -1,3 +1,6 @@ #! /bin/sh +# -Dgluegen.debug.ProcAddressHelper=true -Dgluegen.debug.NativeLibrary=true -Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all +# -Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all + java -XstartOnFirstThread -Djava.awt.headless=true $* 2>&1 | tee java-macosx.log 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; 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 ; } } } 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 ; } } } |