mirror of
https://github.com/processing/processing4.git
synced 2026-06-08 16:40:46 +02:00
fixes to lwjgl renderer
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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() { }
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user