diff --git a/java/libraries/glw/examples/MultipleWindows/MultipleWindows.pde b/java/libraries/glw/examples/MultipleWindows/MultipleWindows.pde new file mode 100644 index 000000000..e69de29bb diff --git a/java/libraries/glw/src/processing/glw/GLW.java b/java/libraries/glw/src/processing/glw/GLW.java index 290204dde..5968461e7 100644 --- a/java/libraries/glw/src/processing/glw/GLW.java +++ b/java/libraries/glw/src/processing/glw/GLW.java @@ -1,47 +1,29 @@ package processing.glw; -import java.util.HashMap; +import processing.core.PGraphics; import com.jogamp.newt.opengl.GLWindow; -import processing.core.PGraphics; -import processing.opengl.PGraphicsOpenGL; +import java.util.HashMap; public class GLW { - static public final String DUMMY = "processing.glw.PGraphicsGLW"; - static public final String OPENGL = "processing.glw.PGraphicsGLW"; - static public final String P2D = "processing.glw.PGraphics2D"; - static public final String P3D = "processing.glw.PGraphics3D"; + static public final String RENDERER = "processing.glw.PGraphicsGLW"; + static public final String OPENGL = "processing.glw.PGraphicsGLW"; - static protected HashMap windows = new HashMap(); -// static protected HashMap canvases; + static public final String P2D = "processing.glw.PGraphics2D"; + static public final String P3D = "processing.glw.PGraphics3D"; - public GLW() { - + static protected HashMap windows = + new HashMap(); + + public GLW() { } static public void createWindow(PGraphics pg) { - if (pg instanceof PGraphicsGLW || pg instanceof PGraphics2D || pg instanceof PGraphics3D) { - //PGraphicsOpenGL pgopengl = (PGraphicsOpenGL)pg; - //PNEWT pgl = (PNEWT)pgopengl.pgl; - //GLWindow win = pgl.createWindow(pg.width, pg.height, /*PNEWT.getWindow().getContext(), */pgopengl); - - -// windows.put(pg, win); + if (pg instanceof PGraphics2D || pg instanceof PGraphics3D) { windows.put(pg, null); - //canvases.put(win, pg); - //win.setTitle("NEWT window " + windows.size()); - -// if (pg instanceof PGraphicsGLW) { -// PGraphicsGLW pgw = (PGraphicsGLW)pg; -// pgw.windowed = true; -// } else if (pg instanceof PGraphics2D) { -// PGraphics2D pgw = (PGraphics2D)pg; -// pgw.windowed = true; -// } else if (pg instanceof PGraphics3D) { -// PGraphics3D pgw = (PGraphics3D)pg; -// pgw.windowed = true; -// } + } else { + throw new RuntimeException("Only GLW.P2D or GLW.P3D surfaces can be attached to a window"); } } diff --git a/java/libraries/glw/src/processing/glw/PGraphics2D.java b/java/libraries/glw/src/processing/glw/PGraphics2D.java index a7b9d3055..90b52899c 100644 --- a/java/libraries/glw/src/processing/glw/PGraphics2D.java +++ b/java/libraries/glw/src/processing/glw/PGraphics2D.java @@ -4,19 +4,7 @@ import processing.opengl.PGL; import processing.opengl.PGraphicsOpenGL; public class PGraphics2D extends processing.opengl.PGraphics2D { -// protected boolean windowed = false; protected PGL createPGL(PGraphicsOpenGL pg) { return new PNEWT(pg); - } - -// public void requestDraw() { -// System.out.println("requesting draw"); -// if (primarySurface || windowed) { -// if (initialized) { -// ((PNEWT)pgl).update(sized); -// } else { -// initPrimary(); -// } -// } -// } + } } diff --git a/java/libraries/glw/src/processing/glw/PGraphics3D.java b/java/libraries/glw/src/processing/glw/PGraphics3D.java index 3d3063e79..c4e011a98 100644 --- a/java/libraries/glw/src/processing/glw/PGraphics3D.java +++ b/java/libraries/glw/src/processing/glw/PGraphics3D.java @@ -4,19 +4,7 @@ import processing.opengl.PGL; import processing.opengl.PGraphicsOpenGL; public class PGraphics3D extends processing.opengl.PGraphics3D { -// protected boolean windowed = false; - protected PGL createPGL(PGraphicsOpenGL pg) { return new PNEWT(pg); } - -// public void requestDraw() { -// if (primarySurface || windowed) { -// if (initialized) { -// ((PNEWT)pgl).update(sized); -// } else { -// initPrimary(); -// } -// } -// } } diff --git a/java/libraries/glw/src/processing/glw/PGraphicsGLW.java b/java/libraries/glw/src/processing/glw/PGraphicsGLW.java index 0c96c6564..34c334fce 100644 --- a/java/libraries/glw/src/processing/glw/PGraphicsGLW.java +++ b/java/libraries/glw/src/processing/glw/PGraphicsGLW.java @@ -26,23 +26,60 @@ import processing.opengl.PGL; import processing.opengl.PGraphicsOpenGL; /** - * GLW renderer. + * GLW renderer. It's only role is to drive the main animation loop by calling + * requestDraw() and so allowing the offscreen canvases to be drawn inside the + * draw() method of the sketch. Currently, it cannot be used to draw into. * */ public class PGraphicsGLW extends PGraphicsOpenGL { -// protected boolean windowed = false; - protected PGL createPGL(PGraphicsOpenGL pg) { return new PNEWT(pg); - } + } -// public void requestDraw() { -// if (primarySurface || windowed) { -// if (initialized) { -// ((PNEWT)pgl).update(sized); -// } else { -// initPrimary(); -// } -// } -// } + public void beginDraw() { + if (primarySurface) { + setCurrentPG(this); + } else { + throw new RuntimeException("GLW renderer cannot be used as an offscreen surface"); + } + + report("top beginDraw()"); + + if (!checkGLThread()) { + return; + } + + if (drawing) { + return; + } + + if (!glParamsRead) { + getGLParameters(); + } + + drawing = true; + + report("bot beginDraw()"); + } + + public void endDraw() { + report("top endDraw()"); + + if (!drawing) { + return; + } + + if (primarySurface) { + setCurrentPG(null); + } else { + throw new RuntimeException("GLW renderer cannot be used as an offscreen surface."); + } + drawing = false; + + report("bot endDraw()"); + } + + protected void vertexImpl(float x, float y, float z, float u, float v) { + throw new RuntimeException("The main GLW renderer cannot be used to draw to."); + } } diff --git a/java/libraries/glw/src/processing/glw/PNEWT.java b/java/libraries/glw/src/processing/glw/PNEWT.java index 020a0eab9..08d3de581 100644 --- a/java/libraries/glw/src/processing/glw/PNEWT.java +++ b/java/libraries/glw/src/processing/glw/PNEWT.java @@ -24,26 +24,19 @@ package processing.glw; -import javax.media.opengl.GL; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLContext; import javax.media.opengl.GLDrawableFactory; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLException; -import javax.media.opengl.GLFBODrawable; import javax.media.opengl.GLProfile; -import javax.media.opengl.awt.GLCanvas; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.newt.event.WindowAdapter; import com.jogamp.newt.event.WindowEvent; -import com.jogamp.opengl.FBObject; import processing.core.PApplet; import processing.core.PGraphics; -import processing.event.KeyEvent; -import processing.event.MouseEvent; import processing.opengl.PGL; import processing.opengl.PGraphicsOpenGL; import processing.opengl.PJOGL; @@ -60,7 +53,7 @@ public class PNEWT extends PJOGL { } protected static GLCapabilities sharedCaps; - protected static GLAutoDrawable sharedDrawable; + protected static GLAutoDrawable sharedDrawable; public PNEWT(PGraphicsOpenGL pg) { @@ -69,6 +62,10 @@ public class PNEWT extends PJOGL { protected void initSurface(int antialias) { + if (!(pg instanceof PGraphicsGLW)) { + throw new RuntimeException("GLW.RENDERER is the only option in size() when using the GLW library."); + } + if (profile == null) { if (PROFILE == 2) { try { @@ -118,28 +115,6 @@ public class PNEWT extends PJOGL { sharedDrawable.display(); // triggers GLContext object creation and native realization. DummyListener listener = new DummyListener(); sharedDrawable.addGLEventListener(listener); - - - /* - window = GLWindow.create(caps); - window.setSize(pg.width, pg.height); - window.setVisible(true); - window.setTitle(pg.parent.frame.getTitle()); - //window.setUndecorated(true); - pg.parent.frame.setVisible(false); - - canvas = canvasNEWT; - canvasAWT = null; - - window.addWindowListener(new WindowAdapter() { - @Override - public void windowDestroyNotify(final WindowEvent e) { - System.exit(0); - } - }); - - registerListeners(); - */ pg.parent.frame.setVisible(false); } @@ -149,13 +124,29 @@ public class PNEWT extends PJOGL { return false; } + + protected void beginDraw(boolean clear0) { + } + + + protected void endDraw(boolean clear0) { + } + + protected void requestDraw() { - // Creating windows + createWindows(); + + // Calling display() so the main draw() method is triggered, where the + // offscreen GLW canvases can be updated. + sharedDrawable.display(); + + displayWindows(); + } + + private void createWindows() { for (PGraphics pg: GLW.windows.keySet()) { GLWindow win = GLW.windows.get(pg); if (win == null) { - System.out.println("creating window"); - //win = GLWindow.create(sharedCaps); win = GLWindow.create(sharedCaps); win.setSharedAutoDrawable(sharedDrawable); win.setSize(pg.width, pg.height); @@ -163,7 +154,6 @@ public class PNEWT extends PJOGL { win.setVisible(true); GLW.windows.put(pg, win); - NEWTListener listener = new NEWTListener(pg); win.addGLEventListener(listener); @@ -173,21 +163,18 @@ public class PNEWT extends PJOGL { win.addKeyListener(keyListener); NEWTWindowListener winListener = new NEWTWindowListener(); win.addWindowListener(winListener); - win.addWindowListener(new WindowAdapter() { @Override public void windowDestroyNotify(final WindowEvent e) { - System.out.println("window destroyed"); -// System.exit(0); } }); } } - - sharedDrawable.display(); - - // Display windows + } + + + private void displayWindows() { int totalCount = 0; int realizedCount = 0; for (GLWindow win: GLW.windows.values()) { @@ -199,11 +186,12 @@ public class PNEWT extends PJOGL { } if (0 < totalCount && realizedCount == 0) { - System.out.println("SHOULD QUIT NOW"); + // All windows where closed, exit the application sharedDrawable.destroy(); System.exit(0); - } - } + } + } + protected class DummyListener implements GLEventListener { public DummyListener() { @@ -254,7 +242,7 @@ public class PNEWT extends PJOGL { @Override public void display(GLAutoDrawable glDrawable) { pgl.getGL(glDrawable); - Texture tex = pg.texture; + Texture tex = pg.getTexture(false); if (tex != null) { pgl.disable(PGL.BLEND); pgl.drawTexture(tex.glTarget, tex.glName,