mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
cleaning up PGL
This commit is contained in:
@@ -351,23 +351,20 @@ public abstract class PGL {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the native canvas the OpenGL context associated to this PGL object
|
||||
* is rendering to (if any).
|
||||
*/
|
||||
public abstract Object getCanvas();
|
||||
|
||||
|
||||
protected abstract void setFps(float fps);
|
||||
|
||||
|
||||
protected abstract void initSurface(int antialias);
|
||||
|
||||
|
||||
protected abstract void reinitSurface();
|
||||
|
||||
|
||||
protected abstract void registerListeners();
|
||||
// public abstract Object getCanvas();
|
||||
//
|
||||
//
|
||||
// protected abstract void setFps(float fps);
|
||||
//
|
||||
//
|
||||
// protected abstract void initSurface(int antialias);
|
||||
//
|
||||
//
|
||||
// protected abstract void reinitSurface();
|
||||
//
|
||||
//
|
||||
// protected abstract void registerListeners();
|
||||
|
||||
|
||||
protected void deleteSurface() {
|
||||
@@ -569,7 +566,7 @@ public abstract class PGL {
|
||||
// The result of this assignment is the following: if the user requested
|
||||
// at some point the use of the FBO layer, but subsequently didn't
|
||||
// request it again, then the rendering won't render to the FBO layer if
|
||||
// not needed by the condif, since it is slower than simple onscreen
|
||||
// not needed by the config, since it is slower than simple onscreen
|
||||
// rendering.
|
||||
fboLayerRequested = false;
|
||||
}
|
||||
@@ -602,18 +599,18 @@ public abstract class PGL {
|
||||
|
||||
|
||||
protected abstract void getGL(PGL pgl);
|
||||
|
||||
|
||||
protected abstract boolean canDraw();
|
||||
|
||||
|
||||
protected abstract void requestFocus();
|
||||
|
||||
|
||||
protected abstract void requestDraw();
|
||||
|
||||
|
||||
protected abstract void swapBuffers();
|
||||
//
|
||||
//
|
||||
// protected abstract boolean canDraw();
|
||||
//
|
||||
//
|
||||
// protected abstract void requestFocus();
|
||||
//
|
||||
//
|
||||
// protected abstract void requestDraw();
|
||||
//
|
||||
//
|
||||
// protected abstract void swapBuffers();
|
||||
|
||||
|
||||
protected boolean threadIsCurrent() {
|
||||
@@ -630,10 +627,10 @@ public abstract class PGL {
|
||||
private boolean needFBOLayer(boolean clear0) {
|
||||
// TODO: need to revise this, on windows we might not want to use FBO layer
|
||||
// even with anti-aliasing enabled...
|
||||
boolean res = !clear0 || fboLayerRequested || 1 < numSamples;
|
||||
// boolean res = !clear0 || fboLayerRequested || 1 < numSamples;
|
||||
// System.err.println(res + " " + clear0 + " " + fboLayerRequested + " " + numSamples);
|
||||
// return res;
|
||||
return false;
|
||||
return fboLayerRequested;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -632,7 +632,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
// render only 1 frame, so no enough rendering
|
||||
// iterations have been conducted so far to properly
|
||||
// initialize all the buffers.
|
||||
pgl.swapBuffers();
|
||||
// pgl.swapBuffers();
|
||||
}
|
||||
|
||||
finalizePolyBuffers();
|
||||
@@ -1649,10 +1649,10 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
* OpenGL cannot draw until a proper native peer is available, so this
|
||||
* returns the value of PApplet.isDisplayable() (inherited from Component).
|
||||
*/
|
||||
@Override
|
||||
public boolean canDraw() {
|
||||
return pgl.canDraw();
|
||||
}
|
||||
// @Override
|
||||
// public boolean canDraw() {
|
||||
// return pgl.canDraw();
|
||||
// }
|
||||
|
||||
|
||||
// @Override
|
||||
@@ -1671,10 +1671,14 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
@Override
|
||||
public void beginDraw() {
|
||||
if (primarySurface) {
|
||||
if (initialized) {
|
||||
if (sized) pgl.reinitSurface();
|
||||
if (parent.canDraw()) pgl.requestDraw();
|
||||
} else {
|
||||
// if (initialized) {
|
||||
// if (sized) pgl.reinitSurface();
|
||||
// if (parent.canDraw()) pgl.requestDraw();
|
||||
// } else {
|
||||
initPrimary();
|
||||
// }
|
||||
|
||||
if (!initialized) {
|
||||
initPrimary();
|
||||
}
|
||||
|
||||
@@ -6351,7 +6355,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
|
||||
|
||||
protected void initPrimary() {
|
||||
pgl.initSurface(quality);
|
||||
// pgl.initSurface(quality);
|
||||
if (texture != null) {
|
||||
removeCache(this);
|
||||
texture = ptexture = null;
|
||||
|
||||
@@ -221,6 +221,7 @@ public class PJOGL extends PGL {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@Override
|
||||
public Canvas getCanvas() {
|
||||
return canvas;
|
||||
@@ -242,11 +243,12 @@ public class PJOGL extends PGL {
|
||||
setFps = true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
@Override
|
||||
protected void initSurface(int antialias) {
|
||||
/*
|
||||
|
||||
if (profile == null) {
|
||||
if (PROFILE == 2) {
|
||||
try {
|
||||
@@ -377,15 +379,16 @@ public class PJOGL extends PGL {
|
||||
|
||||
pg.parent.defaultSize = false;
|
||||
registerListeners();
|
||||
*/
|
||||
|
||||
|
||||
fboLayerCreated = false;
|
||||
fboLayerInUse = false;
|
||||
firstFrame = true;
|
||||
setFps = false;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
@Override
|
||||
protected void reinitSurface() {
|
||||
sinkFBO = backFBO = frontFBO = null;
|
||||
@@ -394,10 +397,10 @@ public class PJOGL extends PGL {
|
||||
firstFrame = true;
|
||||
pg.parent.defaultSize = false;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@Override
|
||||
protected void registerListeners() {
|
||||
// @Override
|
||||
// protected void registerListeners() {
|
||||
// if (WINDOW_TOOLKIT == AWT) {
|
||||
// pg.parent.addListeners(canvasAWT);
|
||||
//
|
||||
@@ -422,11 +425,11 @@ public class PJOGL extends PGL {
|
||||
// if (canvas != null) {
|
||||
// canvas.setFocusTraversalKeysEnabled(false);
|
||||
// }
|
||||
}
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
protected void deleteSurface() {
|
||||
// @Override
|
||||
// protected void deleteSurface() {
|
||||
// super.deleteSurface();
|
||||
//
|
||||
// if (canvasAWT != null) {
|
||||
@@ -435,9 +438,9 @@ public class PJOGL extends PGL {
|
||||
// } else if (canvasNEWT != null) {
|
||||
// windowNEWT.removeGLEventListener(listener);
|
||||
// }
|
||||
}
|
||||
|
||||
// }
|
||||
|
||||
/*
|
||||
@Override
|
||||
protected int getReadFramebuffer() {
|
||||
if (fboLayerInUse) {
|
||||
@@ -637,7 +640,7 @@ public class PJOGL extends PGL {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@Override
|
||||
protected void getGL(PGL pgl) {
|
||||
@@ -675,6 +678,8 @@ public class PJOGL extends PGL {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
@Override
|
||||
protected boolean canDraw() {
|
||||
return true;
|
||||
@@ -689,7 +694,7 @@ public class PJOGL extends PGL {
|
||||
|
||||
@Override
|
||||
protected void requestDraw() {
|
||||
/*
|
||||
|
||||
drawException = null;
|
||||
boolean canDraw = pg.parent.canDraw();
|
||||
if (pg.initialized && (canDraw || prevCanDraw)) {
|
||||
@@ -718,18 +723,18 @@ public class PJOGL extends PGL {
|
||||
throw new RuntimeException(drawException);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void swapBuffers() {
|
||||
// if (WINDOW_TOOLKIT == AWT) {
|
||||
// canvasAWT.swapBuffers();
|
||||
// } else if (WINDOW_TOOLKIT == NEWT) {
|
||||
// windowNEWT.swapBuffers();
|
||||
// }
|
||||
if (WINDOW_TOOLKIT == AWT) {
|
||||
canvasAWT.swapBuffers();
|
||||
} else if (WINDOW_TOOLKIT == NEWT) {
|
||||
windowNEWT.swapBuffers();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@Override
|
||||
@@ -861,6 +866,20 @@ public class PJOGL extends PGL {
|
||||
}
|
||||
}
|
||||
|
||||
protected void init(GLAutoDrawable glDrawable) {
|
||||
capabilities = glDrawable.getChosenGLCapabilities();
|
||||
if (!hasFBOs()) {
|
||||
throw new RuntimeException(MISSING_FBO_ERROR);
|
||||
}
|
||||
if (!hasShaders()) {
|
||||
throw new RuntimeException(MISSING_GLSL_ERROR);
|
||||
}
|
||||
if (USE_JOGL_FBOLAYER && capabilities.isFBO()) {
|
||||
int maxs = maxSamples();
|
||||
numSamples = PApplet.min(capabilities.getNumSamples(), maxs);
|
||||
}
|
||||
}
|
||||
|
||||
protected class PGLListener implements GLEventListener {
|
||||
public PGLListener() {}
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ public class PSurfaceNEWT implements PSurface {
|
||||
caps.setStencilBits(PGL.REQUESTED_STENCIL_BITS);
|
||||
|
||||
caps.setPBuffer(false);
|
||||
caps.setFBO(true);
|
||||
caps.setFBO(false);
|
||||
|
||||
caps.setSampleBuffers(true);
|
||||
caps.setNumSamples(2);
|
||||
@@ -286,15 +286,21 @@ public class PSurfaceNEWT implements PSurface {
|
||||
}
|
||||
|
||||
public void startThread() {
|
||||
animator.start();
|
||||
if (animator != null) {
|
||||
animator.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void pauseThread() {
|
||||
animator.pause();
|
||||
if (animator != null) {
|
||||
animator.pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void resumeThread() {
|
||||
animator.resume();
|
||||
if (animator != null) {
|
||||
animator.resume();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean stopThread() {
|
||||
@@ -351,7 +357,7 @@ public class PSurfaceNEWT implements PSurface {
|
||||
}
|
||||
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
|
||||
pgl.getGL(drawable);
|
||||
if (animator.isStarted()) {
|
||||
if (animator != null && animator.isStarted()) {
|
||||
setSize(w, h);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user