Skip to content

Commit

Permalink
some fixes of loop handing in GL renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
codeanticode committed Dec 28, 2018
1 parent 240f287 commit 2883319
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 26 deletions.
8 changes: 1 addition & 7 deletions core/src/processing/android/PFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
//}
}
18 changes: 5 additions & 13 deletions core/src/processing/core/PApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -1918,7 +1910,7 @@ protected boolean handleSpecialDraw() {
g.beginDraw();
g.endDraw();

requestedNoLoop = false;
g.requestedNoLoop = false;
handled = true;
}

Expand All @@ -1930,8 +1922,8 @@ protected boolean handleSpecialDraw() {
}
}

//////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////


synchronized public void redraw() {
Expand Down Expand Up @@ -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;
}
Expand Down
23 changes: 22 additions & 1 deletion core/src/processing/core/PGraphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions core/src/processing/opengl/PGL.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 13 additions & 1 deletion core/src/processing/opengl/PGraphicsOpenGL.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -5798,6 +5804,12 @@ protected void restoreSurface() {
super.restoreSurface();
}


@Override
protected boolean requestNoLoop() {
return true;
}

//////////////////////////////////////////////////////////////

// GET/SET PIXELS
Expand Down

0 comments on commit 2883319

Please sign in to comment.