From 32240d2901d2c7ae55c442b7a07fd4e69b0a28fe Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 12 Jan 2015 14:38:25 -0500 Subject: [PATCH] fixes to lwjgl renderer --- core/src/processing/core/PApplet.java | 7 +++- core/src/processing/opengl/PGL.java | 7 +++- core/src/processing/opengl/PJOGL.java | 4 +- core/src/processing/opengl/PSurfaceNEWT.java | 6 +-- .../lwjgl/src/processing/lwjgl/PLWJGL.java | 13 ------- .../src/processing/lwjgl/PSurfaceLWJGL.java | 37 ++++++++++--------- 6 files changed, 36 insertions(+), 38 deletions(-) diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 893d318ae..043d5f8e4 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -2981,12 +2981,17 @@ public class PApplet implements PConstants { } + public boolean exitCalled() { + return exitCalled; + } + + /** * Some subclasses (I'm looking at you, processing.py) might wish to do something * other than actually terminate the JVM. This gives them a chance to do whatever * they have in mind when cleaning up. */ - protected void exitActual() { + public void exitActual() { try { System.exit(0); } catch (SecurityException e) { diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index d3c7dcf36..44400d3e1 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -612,11 +612,16 @@ public abstract class PGL { // protected abstract void swapBuffers(); - protected boolean threadIsCurrent() { + public boolean threadIsCurrent() { return Thread.currentThread() == glThread; } + public void setThread(Thread thread) { + glThread = thread; + } + + protected void beginGL() { } diff --git a/core/src/processing/opengl/PJOGL.java b/core/src/processing/opengl/PJOGL.java index 0359ceca5..84166d6fb 100644 --- a/core/src/processing/opengl/PJOGL.java +++ b/core/src/processing/opengl/PJOGL.java @@ -647,7 +647,7 @@ public class PJOGL extends PGL { this.drawable = pjogl.drawable; this.context = pjogl.context; this.glContext = pjogl.glContext; - this.glThread = pjogl.glThread; + setThread(pjogl.glThread); this.gl = pjogl.gl; this.gl2 = pjogl.gl2; @@ -659,7 +659,7 @@ public class PJOGL extends PGL { protected void getGL(GLAutoDrawable glDrawable) { context = glDrawable.getContext(); glContext = context.hashCode(); - glThread = Thread.currentThread(); + setThread(Thread.currentThread()); gl = context.getGL(); gl2 = gl.getGL2ES2(); diff --git a/core/src/processing/opengl/PSurfaceNEWT.java b/core/src/processing/opengl/PSurfaceNEWT.java index 5a5ead2d9..a38e2b57a 100644 --- a/core/src/processing/opengl/PSurfaceNEWT.java +++ b/core/src/processing/opengl/PSurfaceNEWT.java @@ -467,9 +467,9 @@ public class PSurfaceNEWT implements PSurface { public void dispose(GLAutoDrawable drawable) { pgl.getGL(drawable); sketch.dispose(); -// if (sketch.exitCalled) { -// sketch.exitActual(); -// } + if (sketch.exitCalled()) { + sketch.exitActual(); + } } public void init(GLAutoDrawable drawable) { pgl.init(drawable); diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PLWJGL.java b/java/libraries/lwjgl/src/processing/lwjgl/PLWJGL.java index 4e0cc69bc..69a011a85 100644 --- a/java/libraries/lwjgl/src/processing/lwjgl/PLWJGL.java +++ b/java/libraries/lwjgl/src/processing/lwjgl/PLWJGL.java @@ -23,12 +23,9 @@ package processing.lwjgl; -import java.awt.BorderLayout; import java.awt.Canvas; -import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; -import java.awt.Graphics2D; import java.awt.Shape; import java.awt.font.FontRenderContext; import java.awt.font.GlyphVector; @@ -40,12 +37,8 @@ import java.nio.IntBuffer; import java.nio.ShortBuffer; import org.lwjgl.BufferUtils; -import org.lwjgl.LWJGLException; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; import org.lwjgl.opengl.ARBES2Compatibility; import org.lwjgl.opengl.Display; -import org.lwjgl.opengl.DisplayMode; import org.lwjgl.opengl.EXTFramebufferObject; import org.lwjgl.opengl.EXTTextureFilterAnisotropic; import org.lwjgl.opengl.GL11; @@ -59,13 +52,7 @@ import org.lwjgl.opengl.GL31; import org.lwjgl.util.glu.GLU; import org.lwjgl.util.glu.GLUtessellator; import org.lwjgl.util.glu.GLUtessellatorCallbackAdapter; -import org.lwjgl.opengl.PixelFormat; -import processing.core.PApplet; -import processing.core.PConstants; -import processing.event.Event; -import processing.event.KeyEvent; -import processing.event.MouseEvent; import processing.opengl.PGL; import processing.opengl.PGraphicsOpenGL; diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PSurfaceLWJGL.java b/java/libraries/lwjgl/src/processing/lwjgl/PSurfaceLWJGL.java index 67236938e..c53e24a64 100644 --- a/java/libraries/lwjgl/src/processing/lwjgl/PSurfaceLWJGL.java +++ b/java/libraries/lwjgl/src/processing/lwjgl/PSurfaceLWJGL.java @@ -68,19 +68,6 @@ public class PSurfaceLWJGL implements PSurface { sketchWidth = sketch.sketchWidth(); sketchHeight = sketch.sketchHeight(); - try { - Display.setDisplayMode(new DisplayMode(sketchWidth, sketchHeight)); - Display.create(); - } catch (LWJGLException e) { - e.printStackTrace(); - System.exit(0); - } - - keyPoller = new KeyPoller(sketch); - keyPoller.start(); - - mousePoller = new MousePoller(sketch); - mousePoller.start(); frame = new DummyFrame(); return frame; @@ -252,6 +239,20 @@ public class PSurfaceLWJGL implements PSurface { */ @Override public void run() { // not good to make this synchronized, locks things up + try { + Display.setDisplayMode(new DisplayMode(sketchWidth, sketchHeight)); + Display.create(); + } catch (LWJGLException e) { + e.printStackTrace(); + System.exit(0); + } + + keyPoller = new KeyPoller(sketch); + keyPoller.start(); + + mousePoller = new MousePoller(sketch); + mousePoller.start(); + long beforeTime = System.nanoTime(); long overSleepTime = 0L; @@ -272,6 +273,7 @@ public class PSurfaceLWJGL implements PSurface { sketch.start(); while ((Thread.currentThread() == thread) && !sketch.finished) { + pgl.setThread(thread); checkPause(); // Don't resize the renderer from the EDT (i.e. from a ComponentEvent), @@ -327,10 +329,9 @@ public class PSurfaceLWJGL implements PSurface { // If the user called the exit() function, the window should close, // rather than the sketch just halting. - // TODO: these methods need to be public... -// if (sketch.exitCalled) { -// sketch.exitActual(); -// } + if (sketch.exitCalled()) { + sketch.exitActual(); + } } } @@ -495,7 +496,7 @@ public class PSurfaceLWJGL implements PSurface { } int x = Mouse.getX(); - int y = parent.height - Mouse.getY(); + int y = sketchHeight - Mouse.getY(); int button = 0; if (Mouse.isButtonDown(0)) { button = PConstants.LEFT;