mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
canDraw() in PApplet to better control GL draw requests
This commit is contained in:
@@ -659,6 +659,13 @@ public class PApplet extends Activity implements PConstants, Runnable {
|
||||
// return surfaceHolder;
|
||||
}
|
||||
|
||||
|
||||
/** Not official API, not guaranteed to work in the future. */
|
||||
public SurfaceView getSurfaceView() {
|
||||
return surfaceView;
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
@@ -927,17 +934,6 @@ public class PApplet extends Activity implements PConstants, Runnable {
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
/** Holy crap this was an ugly one. Need to fix. */
|
||||
public void andresNeedsBetterAPI() {
|
||||
if (looping) { // This "if" is needed to avoid flickering when looping is disabled.
|
||||
((GLSurfaceView) surfaceView).requestRender();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
/**
|
||||
* Called by the sketch surface view, thought it could conceivably be called
|
||||
* by Android as well.
|
||||
@@ -1933,7 +1929,7 @@ public class PApplet extends Activity implements PConstants, Runnable {
|
||||
// width and height that have been set by surfaceChanged().
|
||||
// boolean validSize = width != 0 && height != 0;
|
||||
// println("valid size = " + validSize + " (" + width + "x" + height + ")");
|
||||
if (g != null && surfaceReady && !paused && (looping || redraw)) {
|
||||
if (canDraw()) {
|
||||
// if (!g.canDraw()) {
|
||||
// // Don't draw if the renderer is not yet ready.
|
||||
// // (e.g. OpenGL has to wait for a peer to be on screen)
|
||||
@@ -2008,6 +2004,12 @@ public class PApplet extends Activity implements PConstants, Runnable {
|
||||
}
|
||||
|
||||
|
||||
/** Not official API, not guaranteed to work in the future. */
|
||||
public boolean canDraw() {
|
||||
return g != null && surfaceReady && !paused && (looping || redraw);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
@@ -333,6 +333,9 @@ public class PGL {
|
||||
/** The current opengl context */
|
||||
public static EGLContext context;
|
||||
|
||||
/** The current surface view */
|
||||
public static GLSurfaceView glview;
|
||||
|
||||
/** The PGraphics object using this interface */
|
||||
protected PGraphicsOpenGL pg;
|
||||
|
||||
@@ -452,6 +455,7 @@ public class PGL {
|
||||
|
||||
|
||||
protected void initSurface(int antialias) {
|
||||
glview = (GLSurfaceView)pg.parent.getSurfaceView();
|
||||
reqNumSamples = qualityToSamples(antialias);
|
||||
fboLayerCreated = false;
|
||||
fboLayerInUse = false;
|
||||
@@ -460,7 +464,7 @@ public class PGL {
|
||||
|
||||
|
||||
protected void deleteSurface() {
|
||||
if (glColorTex != null) {
|
||||
if (threadIsCurrent() && glColorTex != null) {
|
||||
deleteTextures(2, glColorTex);
|
||||
deleteFramebuffers(1, glColorFbo);
|
||||
deleteFramebuffers(1, glMultiFbo);
|
||||
@@ -469,6 +473,7 @@ public class PGL {
|
||||
deleteRenderbuffers(1, glDepth);
|
||||
deleteRenderbuffers(1, glStencil);
|
||||
}
|
||||
|
||||
fboLayerCreated = false;
|
||||
fboLayerInUse = false;
|
||||
firstFrame = true;
|
||||
@@ -821,9 +826,9 @@ public class PGL {
|
||||
|
||||
if (!fboLayerByDefault) {
|
||||
// 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 do
|
||||
// at some point the use of the FBO layer, but subsequently didn't
|
||||
// request it again, then the rendering won't use the FBO layer if not
|
||||
// needed, since it is slower than simple onscreen rendering.
|
||||
// needed, since it is slower than simple on-screen rendering.
|
||||
FORCE_SCREEN_FBO = false;
|
||||
}
|
||||
}
|
||||
@@ -861,7 +866,9 @@ public class PGL {
|
||||
|
||||
|
||||
protected void requestDraw() {
|
||||
pg.parent.andresNeedsBetterAPI();
|
||||
if (pg.initialized && pg.parent.canDraw()) {
|
||||
glview.requestRender();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user