Skip to content

Commit 2883319

Browse files
committed
some fixes of loop handing in GL renderers
1 parent 240f287 commit 2883319

File tree

5 files changed

+45
-26
lines changed

5 files changed

+45
-26
lines changed

core/src/processing/android/PFragment.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,6 @@ public void requestDraw() {
254254

255255

256256
public boolean canDraw() {
257-
if (sketch == null) return false;
258-
return sketch.isLooping();
257+
return sketch != null && sketch.isLooping();
259258
}
260-
261-
262-
//public void onBackPressed() {
263-
// sketch.exit();
264-
//}
265259
}

core/src/processing/core/PApplet.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,6 @@ public class PApplet extends Object implements ActivityAPI, PConstants {
315315

316316
protected boolean looping;
317317

318-
// This auxiliary variable is used to implement a little hack that fixes
319-
// https://github.com/processing/processing-android/issues/147
320-
// on older devices where the last frame cannot be maintained after ending
321-
// the rendering in GL. The trick consists in running one more frame after the
322-
// noLoop() call, which ensures that the FBO layer is properly initialized
323-
// and drawn with the contents of the previous frame.
324-
protected boolean requestedNoLoop = false;
325-
326318
/** flag set to true when a redraw is asked for by the user */
327319
protected boolean redraw;
328320

@@ -1908,7 +1900,7 @@ protected boolean handleSpecialDraw() {
19081900
g.endDraw();
19091901

19101902
handled = true;
1911-
} else if (requestedNoLoop) {
1903+
} else if (g.requestedNoLoop) {
19121904
// noLoop() was called sometime in the previous frame with a GL renderer, but only now
19131905
// we are sure that the frame is properly displayed.
19141906
looping = false;
@@ -1918,7 +1910,7 @@ protected boolean handleSpecialDraw() {
19181910
g.beginDraw();
19191911
g.endDraw();
19201912

1921-
requestedNoLoop = false;
1913+
g.requestedNoLoop = false;
19221914
handled = true;
19231915
}
19241916

@@ -1930,8 +1922,8 @@ protected boolean handleSpecialDraw() {
19301922
}
19311923
}
19321924

1933-
//////////////////////////////////////////////////////////////
19341925

1926+
//////////////////////////////////////////////////////////////
19351927

19361928

19371929
synchronized public void redraw() {
@@ -1961,8 +1953,8 @@ synchronized public void loop() {
19611953

19621954
synchronized public void noLoop() {
19631955
if (looping) {
1964-
if (g instanceof PGraphicsOpenGL) {
1965-
requestedNoLoop = true;
1956+
if (g.requestNoLoop()) {
1957+
g.requestedNoLoop = true;
19661958
} else {
19671959
looping = false;
19681960
}

core/src/processing/core/PGraphics.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,14 @@ public class PGraphics extends PImage implements PConstants {
649649
protected boolean restartedLoopingAfterResume = false;
650650
protected boolean restoredSurface = true;
651651

652+
// This auxiliary variable is used to implement a little hack that fixes
653+
// https://github.com/processing/processing-android/issues/147
654+
// on older devices where the last frame cannot be maintained after ending
655+
// the rendering in GL. The trick consists in running one more frame after the
656+
// noLoop() call, which ensures that the FBO layer is properly initialized
657+
// and drawn with the contents of the previous frame.
658+
protected boolean requestedNoLoop = false;
659+
652660
//////////////////////////////////////////////////////////////
653661

654662
// INTERNAL
@@ -996,7 +1004,7 @@ protected void restoreState() { // ignore
9961004
// This method probably does not need to be re-implemented in the subclasses. All we need to
9971005
// do is to check for the resume in no-loop state situation:
9981006
restoredSurface = false;
999-
if (!parent.isLooping()) {
1007+
if (!parent.looping) {
10001008
// The sketch needs to draw a few frames after resuming so it has the chance to restore the
10011009
// screen contents:
10021010
// https://github.com/processing/processing-android/issues/492
@@ -1023,6 +1031,19 @@ protected void restoreSurface() { // ignore
10231031
}
10241032
}
10251033

1034+
1035+
protected boolean requestNoLoop() { // ignore
1036+
// Some renderers (OpenGL) cannot be set to no-loop right away, it has to be requested so
1037+
// any pending frames are properly rendered. Override as needed.
1038+
return false;
1039+
}
1040+
1041+
1042+
protected boolean isLooping() { // ignore
1043+
return parent.isLooping() && (!requestNoLoop() || !requestedNoLoop);
1044+
}
1045+
1046+
10261047
//////////////////////////////////////////////////////////////
10271048

10281049
// HINTS

core/src/processing/opengl/PGL.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,9 @@ protected void beginRender() {
760760
float bb = ((argb) & 0xff) / 255.0f;
761761
clearColor(br, bg, bb, ba);
762762
clear(COLOR_BUFFER_BIT);
763-
} else if (!pclearColor || !sketch.isLooping()) {
764-
// Render previous back texture (now is the front) as background,
765-
// because no background() is being used ("incremental drawing")
763+
} else if (!pclearColor || !graphics.isLooping()) {
764+
// Render previous back texture (now is the front) as background, because no background()
765+
// is being used ("incremental drawing")
766766
int x = 0;
767767
int y = 0;
768768
if (presentMode) {
@@ -869,7 +869,7 @@ protected void endRender(int windowColor) {
869869
saveFirstFrame();
870870
}
871871

872-
if (!clearColor && 0 < sketch.frameCount || !sketch.isLooping()) {
872+
if (!clearColor && 0 < sketch.frameCount || !graphics.isLooping()) {
873873
enableFBOLayer();
874874
if (SINGLE_BUFFERED) {
875875
createFBOLayer();

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ protected void updatePixelSize() {
735735

736736

737737
// Factory method
738-
protected PGL createPGL(PGraphicsOpenGL pg) {
738+
protected PGL createPGL(PGraphicsOpenGL pg) { // ignore
739739
// return new PJOGL(pg);
740740
return new PGLES(pg);
741741
}
@@ -764,6 +764,12 @@ public void setFrameRate(float frameRate) {
764764
}
765765

766766

767+
@Override
768+
protected boolean isLooping() { // ignore
769+
return super.isLooping();
770+
}
771+
772+
767773
public boolean saveImpl(String filename) {
768774
return super.save(filename); // ASYNC save frame using PBOs not yet available on Android
769775

@@ -5798,6 +5804,12 @@ protected void restoreSurface() {
57985804
super.restoreSurface();
57995805
}
58005806

5807+
5808+
@Override
5809+
protected boolean requestNoLoop() {
5810+
return true;
5811+
}
5812+
58015813
//////////////////////////////////////////////////////////////
58025814

58035815
// GET/SET PIXELS

0 commit comments

Comments
 (0)