From fefaaf4f62e78f21dd1986a395cfee949e53acf7 Mon Sep 17 00:00:00 2001 From: andres Date: Sun, 2 Jun 2013 13:55:09 -0400 Subject: [PATCH] working on a fix for issue #1648 --- core/src/processing/opengl/PGL.java | 18 +++++++++++++++++- .../src/processing/opengl/PGraphicsOpenGL.java | 9 +++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 49a37ace5..52385b50e 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -1137,8 +1137,11 @@ public class PGL { } + protected boolean prevCanDraw = false; protected void requestDraw() { - if (pg.initialized && pg.parent.canDraw()) { + boolean canDraw = pg.parent.canDraw(); + System.out.println(canDraw + " " + pg.parent.frameCount); + if (pg.initialized && (canDraw || prevCanDraw)) { try { drawLatch = new CountDownLatch(1); if (WINDOW_TOOLKIT == AWT) { @@ -1151,6 +1154,9 @@ public class PGL { } catch (InterruptedException e) { e.printStackTrace(); } + + if (canDraw) prevCanDraw = true; + else prevCanDraw = false; } catch (GLException e) { // Unwrap GLException so that only the causing exception is shown. Throwable tr = e.getCause(); @@ -1164,6 +1170,15 @@ public class PGL { } + protected void swapBuffers() { + if (WINDOW_TOOLKIT == AWT) { + canvasAWT.swapBuffers(); + } else if (WINDOW_TOOLKIT == NEWT) { + window.swapBuffers(); + } + } + + protected boolean threadIsCurrent() { return Thread.currentThread() == glThread; } @@ -2538,6 +2553,7 @@ public class PGL { @Override public void display(GLAutoDrawable glDrawable) { if (drawLatch == null || drawLatch.getCount() == 0) return; + System.out.println("display " + pg.parent.frameCount); drawable = glDrawable; context = glDrawable.getContext(); diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index bef0380fb..a570fada7 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -635,6 +635,14 @@ public class PGraphicsOpenGL extends PGraphics { public void dispose() { // PGraphics super.dispose(); + // Swap buffers the end to make sure that no + // garbage is shown on the screen, this particularly + // affects non-interactive sketches on windows that + // render only 1 frame, so no enough rendering + // iterations have been conducted so far to properly + // initialize all the buffers. + pgl.swapBuffers(); + deletePolyBuffers(); deleteLineBuffers(); deletePointBuffers(); @@ -5149,6 +5157,7 @@ public class PGraphicsOpenGL extends PGraphics { protected void restoreSurfaceFromPixels() { + System.out.println("restoreSurfaceFromPixels"); drawPixels(0, 0, width, height); }