From 2883319a04e670ec9ced22c2a292cd3e04f94545 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sat, 29 Dec 2018 02:23:31 +0900 Subject: [PATCH] some fixes of loop handing in GL renderers --- core/src/processing/android/PFragment.java | 8 +------ core/src/processing/core/PApplet.java | 18 ++++----------- core/src/processing/core/PGraphics.java | 23 ++++++++++++++++++- core/src/processing/opengl/PGL.java | 8 +++---- .../processing/opengl/PGraphicsOpenGL.java | 14 ++++++++++- 5 files changed, 45 insertions(+), 26 deletions(-) diff --git a/core/src/processing/android/PFragment.java b/core/src/processing/android/PFragment.java index 33c1e5daf..1a2132ed3 100644 --- a/core/src/processing/android/PFragment.java +++ b/core/src/processing/android/PFragment.java @@ -254,12 +254,6 @@ public void requestDraw() { public boolean canDraw() { - if (sketch == null) return false; - return sketch.isLooping(); + return sketch != null && sketch.isLooping(); } - - -//public void onBackPressed() { -// sketch.exit(); -//} } diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index fe53bc527..0b1607db1 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -315,14 +315,6 @@ public class PApplet extends Object implements ActivityAPI, PConstants { protected boolean looping; - // This auxiliary variable is used to implement a little hack that fixes - // https://github.com/processing/processing-android/issues/147 - // on older devices where the last frame cannot be maintained after ending - // the rendering in GL. The trick consists in running one more frame after the - // noLoop() call, which ensures that the FBO layer is properly initialized - // and drawn with the contents of the previous frame. - protected boolean requestedNoLoop = false; - /** flag set to true when a redraw is asked for by the user */ protected boolean redraw; @@ -1908,7 +1900,7 @@ protected boolean handleSpecialDraw() { g.endDraw(); handled = true; - } else if (requestedNoLoop) { + } else if (g.requestedNoLoop) { // noLoop() was called sometime in the previous frame with a GL renderer, but only now // we are sure that the frame is properly displayed. looping = false; @@ -1918,7 +1910,7 @@ protected boolean handleSpecialDraw() { g.beginDraw(); g.endDraw(); - requestedNoLoop = false; + g.requestedNoLoop = false; handled = true; } @@ -1930,8 +1922,8 @@ protected boolean handleSpecialDraw() { } } - ////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////// synchronized public void redraw() { @@ -1961,8 +1953,8 @@ synchronized public void loop() { synchronized public void noLoop() { if (looping) { - if (g instanceof PGraphicsOpenGL) { - requestedNoLoop = true; + if (g.requestNoLoop()) { + g.requestedNoLoop = true; } else { looping = false; } diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index 1d53553a7..e8598a711 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -649,6 +649,14 @@ public class PGraphics extends PImage implements PConstants { protected boolean restartedLoopingAfterResume = false; protected boolean restoredSurface = true; + // This auxiliary variable is used to implement a little hack that fixes + // https://github.com/processing/processing-android/issues/147 + // on older devices where the last frame cannot be maintained after ending + // the rendering in GL. The trick consists in running one more frame after the + // noLoop() call, which ensures that the FBO layer is properly initialized + // and drawn with the contents of the previous frame. + protected boolean requestedNoLoop = false; + ////////////////////////////////////////////////////////////// // INTERNAL @@ -996,7 +1004,7 @@ protected void restoreState() { // ignore // This method probably does not need to be re-implemented in the subclasses. All we need to // do is to check for the resume in no-loop state situation: restoredSurface = false; - if (!parent.isLooping()) { + if (!parent.looping) { // The sketch needs to draw a few frames after resuming so it has the chance to restore the // screen contents: // https://github.com/processing/processing-android/issues/492 @@ -1023,6 +1031,19 @@ protected void restoreSurface() { // ignore } } + + protected boolean requestNoLoop() { // ignore + // Some renderers (OpenGL) cannot be set to no-loop right away, it has to be requested so + // any pending frames are properly rendered. Override as needed. + return false; + } + + + protected boolean isLooping() { // ignore + return parent.isLooping() && (!requestNoLoop() || !requestedNoLoop); + } + + ////////////////////////////////////////////////////////////// // HINTS diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index a048fd195..01b5f305e 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -760,9 +760,9 @@ protected void beginRender() { float bb = ((argb) & 0xff) / 255.0f; clearColor(br, bg, bb, ba); clear(COLOR_BUFFER_BIT); - } else if (!pclearColor || !sketch.isLooping()) { - // Render previous back texture (now is the front) as background, - // because no background() is being used ("incremental drawing") + } else if (!pclearColor || !graphics.isLooping()) { + // Render previous back texture (now is the front) as background, because no background() + // is being used ("incremental drawing") int x = 0; int y = 0; if (presentMode) { @@ -869,7 +869,7 @@ protected void endRender(int windowColor) { saveFirstFrame(); } - if (!clearColor && 0 < sketch.frameCount || !sketch.isLooping()) { + if (!clearColor && 0 < sketch.frameCount || !graphics.isLooping()) { enableFBOLayer(); if (SINGLE_BUFFERED) { createFBOLayer(); diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 1745530cb..bc902677d 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -735,7 +735,7 @@ protected void updatePixelSize() { // Factory method - protected PGL createPGL(PGraphicsOpenGL pg) { + protected PGL createPGL(PGraphicsOpenGL pg) { // ignore // return new PJOGL(pg); return new PGLES(pg); } @@ -764,6 +764,12 @@ public void setFrameRate(float frameRate) { } + @Override + protected boolean isLooping() { // ignore + return super.isLooping(); + } + + public boolean saveImpl(String filename) { return super.save(filename); // ASYNC save frame using PBOs not yet available on Android @@ -5798,6 +5804,12 @@ protected void restoreSurface() { super.restoreSurface(); } + + @Override + protected boolean requestNoLoop() { + return true; + } + ////////////////////////////////////////////////////////////// // GET/SET PIXELS