diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java
index 9f3762fe1..75d797a7b 100644
--- a/core/src/processing/core/PApplet.java
+++ b/core/src/processing/core/PApplet.java
@@ -1809,7 +1809,8 @@ public class PApplet extends Applet
}
// render a single frame
- handleDraw();
+ //handleDraw();
+ if (g != null) g.requestDraw();
if (frameCount == 1) {
// Call the request focus event once the image is sure to be on
@@ -2049,8 +2050,7 @@ public class PApplet extends Applet
//////////////////////////////////////////////////////////////
-
-
+
public void addListeners() {
addMouseListener(this);
addMouseMotionListener(this);
@@ -2073,7 +2073,6 @@ public class PApplet extends Applet
});
}
-
//////////////////////////////////////////////////////////////
diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java
index 7b6767d50..7a1b08995 100644
--- a/core/src/processing/core/PGraphics.java
+++ b/core/src/processing/core/PGraphics.java
@@ -631,7 +631,6 @@ public class PGraphics extends PImage implements PConstants {
reapplySettings();
}
-
/**
* Allocate memory for this renderer. Generally will need to be implemented
* for all renderers.
@@ -666,8 +665,9 @@ public class PGraphics extends PImage implements PConstants {
/**
* Try to draw, or put a draw request on the queue.
*/
-// public void requestDraw() { // ignore
-// }
+ public void requestDraw() { // ignore
+ parent.handleDraw();
+ }
/**
diff --git a/java/libraries/opengl/.classpath b/java/libraries/opengl/.classpath
index 32bff8c73..d5a1ed1b8 100644
--- a/java/libraries/opengl/.classpath
+++ b/java/libraries/opengl/.classpath
@@ -5,6 +5,5 @@
-
diff --git a/java/libraries/opengl/src/processing/opengl/PGL.java b/java/libraries/opengl/src/processing/opengl/PGL.java
index 43fbff4fe..d8902d791 100644
--- a/java/libraries/opengl/src/processing/opengl/PGL.java
+++ b/java/libraries/opengl/src/processing/opengl/PGL.java
@@ -36,15 +36,20 @@ import javax.media.nativewindow.awt.AWTGraphicsDevice;
import javax.media.nativewindow.awt.AWTGraphicsScreen;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
+import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLDrawable;
import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUtessellator;
import javax.media.opengl.glu.GLUtessellatorCallbackAdapter;
+import jogamp.nativewindow.Debug;
+
import processing.core.PApplet;
import processing.core.PConstants;
@@ -238,7 +243,9 @@ public class PGL {
public GLDrawable drawable;
/** The rendering context (holds rendering state info) */
- public GLContext context;
+ public GLContext context;
+
+ public GLCanvas canvas;
public PGraphicsOpenGL pg;
@@ -266,22 +273,22 @@ public class PGL {
* if possible.
*
*/
- static public void startup(boolean beforeUI) {
- try {
- GLProfile.initSingleton(beforeUI);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
+// static public void startup(boolean beforeUI) {
+// try {
+// GLProfile.initSingleton(beforeUI);
+// } catch (Exception e) {
+// e.printStackTrace();
+// }
+// }
static public void shutdown() {
- GLProfile.shutdown();
+ // GLProfile.shutdown();
}
- public void updatePrimary() {
- gl = context.getGL();
- gl2 = gl.getGL2();
- }
+// public void updatePrimary() {
+// gl = context.getGL();
+// gl2 = gl.getGL2();
+// }
public void updateOffscreen(PGL primary) {
gl = primary.gl;
@@ -290,23 +297,6 @@ public class PGL {
public void initPrimarySurface(int antialias) {
- if (pg.parent.online) {
- // RCP Application (Applet's, Webstart, Netbeans, ..) using JOGL may not
- // be able to initialize JOGL before the first UI action, so initSingleton()
- // is called with its argument set to false.
- GLProfile.initSingleton(false);
- } else {
- if (PApplet.platform == PConstants.LINUX) {
- // Special case for Linux, since the multithreading issues described for
- // example here:
- // http://forum.jogamp.org/QtJambi-JOGL-Ubuntu-Lucid-td909554.html
- // have not been solved yet (at least for stable release b32 of JOGL2).
- GLProfile.initSingleton(false);
- } else {
- GLProfile.initSingleton(true);
- }
- }
-
// For the time being we use the fixed function profile
// because GL3 is not supported in MacOSX Snow Leopard.
profile = GLProfile.getMaxFixedFunc();
@@ -323,22 +313,20 @@ public class PGL {
} else {
capabilities.setSampleBuffers(false);
}
-
- // Getting the native window:
- // http://www.java-gaming.org/index.php/topic,21559.0.html
- AWTGraphicsScreen screen = (AWTGraphicsScreen)AWTGraphicsScreen.createDefault();
- AWTGraphicsConfiguration config = (AWTGraphicsConfiguration)GraphicsConfigurationFactory
- .getFactory(AWTGraphicsDevice.class).chooseGraphicsConfiguration(capabilities, capabilities, null, screen);
- NativeWindow win = NativeWindowFactory.getNativeWindow(pg.parent, config);
- // With the native window we get the drawable and context:
- GLDrawableFactory factory = GLDrawableFactory.getFactory(profile);
- drawable = factory.createGLDrawable(win);
- context = drawable.createContext(null);
+ canvas = new GLCanvas(capabilities);
+ canvas.addGLEventListener(new JavaRenderer());
+
+ pg.parent.add(canvas);
+ canvas.setBounds(0, 0, pg.parent.width, pg.parent.height);
+ canvas.addMouseListener(pg.parent);
+ canvas.addMouseMotionListener(pg.parent);
+ canvas.addKeyListener(pg.parent);
+ canvas.addFocusListener(pg.parent);
initialized = true;
}
-
+
public void initOffscreenSurface(PGL primary) {
context = primary.context;
capabilities = primary.capabilities;
@@ -355,32 +343,33 @@ public class PGL {
/**
* Make the OpenGL rendering context current for this thread.
*/
- protected void detainContext() {
- try {
- while (context.makeCurrent() == GLContext.CONTEXT_NOT_CURRENT) {
- Thread.sleep(10);
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Release the context, otherwise the AWT lock on X11 will not be released
- */
- public void releaseContext() {
- context.release();
- }
-
- public void destroyContext() {
- context.destroy();
- context = null;
- }
+// protected void detainContext() {
+// try {
+// while (context.makeCurrent() == GLContext.CONTEXT_NOT_CURRENT) {
+// Thread.sleep(10);
+// }
+// } catch (InterruptedException e) {
+// e.printStackTrace();
+// }
+// }
+//
+// /**
+// * Release the context, otherwise the AWT lock on X11 will not be released
+// */
+// public void releaseContext() {
+// context.release();
+// }
+//
+// public void destroyContext() {
+// context.destroy();
+// context = null;
+// }
///////////////////////////////////////////////////////////////////////////////////
// Frame rendering
+ /*
public boolean initOnscreenDraw() {
if (drawable != null) {
// Call setRealized() after addNotify() has been called
@@ -394,6 +383,7 @@ public class PGL {
}
return false;
}
+ */
public void beginOnscreenDraw(boolean clear, int frame) {
}
@@ -414,7 +404,10 @@ public class PGL {
return pg.parent.isDisplayable();
}
- public void requestDraw() {
+ public void requestDraw() {
+ if (canvas != null) {
+ canvas.display();
+ }
}
///////////////////////////////////////////////////////////////////////////////////
@@ -953,5 +946,33 @@ public class PGL {
byte[] infoBytes = new byte[length];
infoLog.get(infoBytes);
return new String(infoBytes);
- }
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////
+
+ // Java specific stuff
+
+ class JavaRenderer implements GLEventListener {
+ @Override
+ public void display(GLAutoDrawable drawable) {
+ context = drawable.getContext();
+ gl = context.getGL();
+ gl2 = gl.getGL2();
+ pg.parent.handleDraw();
+ }
+
+ @Override
+ public void dispose(GLAutoDrawable drawable) {
+ }
+
+ @Override
+ public void init(GLAutoDrawable drawable) {
+ context = drawable.getContext();
+ }
+
+ @Override
+ public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
+ context = drawable.getContext();
+ }
+ }
}
diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java
index 9a0f662bb..3026dabe8 100644
--- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java
+++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java
@@ -472,6 +472,10 @@ public class PGraphicsOpenGL extends PGraphics {
}
+ public boolean handleListeners() {
+ return true;
+ }
+
/**
* Called by resize(), this handles creating the actual GLCanvas the
* first time around, or simply resizing it on subsequent calls.
@@ -511,6 +515,7 @@ public class PGraphicsOpenGL extends PGraphics {
// } else {
// reapplySettings();
// }
+ //initPrimary();
if (pgl.initialized) {
reapplySettings();
}
@@ -534,10 +539,10 @@ public class PGraphicsOpenGL extends PGraphics {
public void dispose() { // PGraphics
super.dispose();
- pgl.detainContext();
+ //pgl.detainContext();
deleteFinalizedGLResources();
- pgl.releaseContext();
- PGL.shutdown();
+ //pgl.releaseContext();
+ //PGL.shutdown();
}
@@ -1080,10 +1085,10 @@ public class PGraphicsOpenGL extends PGraphics {
public void restartContext() {
releaseResources();
- pgl.releaseContext();
- pgl.destroyContext();
+ //pgl.releaseContext();
+ //pgl.destroyContext();
restartSurface();
- pgl.detainContext();
+ //pgl.detainContext();
updatePGL();
}
@@ -1318,8 +1323,13 @@ public class PGraphicsOpenGL extends PGraphics {
}
- public void requestDraw() {
- pgl.requestDraw();
+ public void requestDraw() {
+ if (primarySurface) {
+ if (!pgl.initialized) {
+ initPrimary();
+ }
+ pgl.requestDraw();
+ }
}
@@ -1330,15 +1340,9 @@ public class PGraphicsOpenGL extends PGraphics {
}
if (primarySurface) {
- if (!pgl.initialized) {
- initPrimary();
- }
+ pgl.beginOnscreenDraw(clearColorBuffer, parent.frameCount);
- if (!pgl.initOnscreenDraw()) {
- return;
- }
- pgl.detainContext();
- } else {
+ } else {
if (!pgl.initialized) {
initOffscreen();
}
@@ -1349,9 +1353,11 @@ public class PGraphicsOpenGL extends PGraphics {
pgl.setDrawBuffer(0);
} else {
setFramebuffer(offscreenFramebuffer);
- }
- }
+ }
+ pgl.beginOffscreenDraw(clearColorBuffer, parent.frameCount);
+ }
+
updatePGL();
if (!glParamsRead) {
@@ -1368,11 +1374,6 @@ public class PGraphicsOpenGL extends PGraphics {
if (!primarySurface) {
pg.saveGLState();
-
- // Disabling all lights, so the offscreen renderer can set completely
- // new light configuration (otherwise some light configuration from the
- // primary renderer might stay).
- //pg.disableLights();
}
inGeo.reset();
@@ -1466,16 +1467,14 @@ public class PGraphicsOpenGL extends PGraphics {
pgl.glClearColor(0, 0, 0, 0);
pgl.glClear(PGL.GL_DEPTH_BUFFER_BIT | PGL.GL_STENCIL_BUFFER_BIT);
- if (primarySurface) {
- pgl.beginOnscreenDraw(clearColorBuffer, parent.frameCount);
- } else {
- pgl.beginOffscreenDraw(clearColorBuffer, parent.frameCount);
- }
-
drawing = true;
+ // This copy of the clear color buffer variable is needed to take into account
+ // the situation when clearColorBuffer = true with FBOs enabled at beginDraw()
+ // and clearColorBuffer = false at endDraw(). In such situation, an offscreen
+ // buffer might be bound, but should popped to the screen buffer for correct
+ // continuation of onscreen rendering.
clearColorBuffer0 = clearColorBuffer;
- clearColorBuffer = false;
report("bot beginDraw()");
}
@@ -1504,7 +1503,6 @@ public class PGraphicsOpenGL extends PGraphics {
if (primarySurface) {
pgl.glFlush();
pgl.endOnscreenDraw(clearColorBuffer0);
- pgl.releaseContext();
} else {
if (offscreenMultisample) {
offscreenFramebufferMultisample.copy(offscreenFramebuffer);
@@ -1528,20 +1526,18 @@ public class PGraphicsOpenGL extends PGraphics {
}
- public void endPGL() {
+ public void endGL() {
restoreGLState();
}
public void updatePGL() {
- if (primarySurface) {
- pgl.updatePrimary();
+ if (primarySurface) {
} else {
pgl.updateOffscreen(pg.pgl);
}
}
-
protected void saveGLState() {
}
@@ -1581,14 +1577,14 @@ public class PGraphicsOpenGL extends PGraphics {
// operation, such as grabbing the contents of the color
// buffer.
protected void beginGLOp() {
- pgl.detainContext();
+ //pgl.detainContext();
updatePGL();
}
// Pairs-up with beginGLOp().
protected void endGLOp() {
- pgl.releaseContext();
+ //pgl.releaseContext();
}
protected void updateGLProjection() {
@@ -1733,6 +1729,8 @@ public class PGraphicsOpenGL extends PGraphics {
specular(125);
emissive(0);
shininess(1);
+
+ clearColorBuffer = false;
}
// reapplySettings
@@ -4288,7 +4286,11 @@ public class PGraphicsOpenGL extends PGraphics {
pgl.glClearColor(backgroundR, backgroundG, backgroundB, 1);
pgl.glClear(PGL.GL_COLOR_BUFFER_BIT);
- clearColorBuffer = true;
+
+ if (0 < parent.frameCount) {
+ // Only one call to background during the drawing loop is needed to set the clear mode to true.
+ clearColorBuffer = true;
+ }
}
//////////////////////////////////////////////////////////////
@@ -5444,12 +5446,12 @@ public class PGraphicsOpenGL extends PGraphics {
// INITIALIZATION ROUTINES
static public void init() {
- PGL.startup(true);
+ //PGL.startup(true);
}
static public void init(boolean beforeUI) {
- PGL.startup(beforeUI);
+ //PGL.startup(beforeUI);
}
protected void restartSurface() {