more work on GLW

This commit is contained in:
codeanticode
2014-01-21 16:43:11 -05:00
parent 66118b56ef
commit 9714f24648
6 changed files with 97 additions and 114 deletions
+13 -31
View File
@@ -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<PGraphics, GLWindow> windows = new HashMap<PGraphics, GLWindow>();
// static protected HashMap<GLWindow, PGraphics> canvases;
static public final String P2D = "processing.glw.PGraphics2D";
static public final String P3D = "processing.glw.PGraphics3D";
public GLW() {
static protected HashMap<PGraphics, GLWindow> windows =
new HashMap<PGraphics, GLWindow>();
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");
}
}
@@ -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();
// }
// }
// }
}
}
@@ -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();
// }
// }
// }
}
@@ -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.");
}
}
@@ -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,