put back pixel restore

This commit is contained in:
codeanticode
2012-11-25 01:06:22 +00:00
parent b7ab26c830
commit ffa643d2f4
2 changed files with 73 additions and 21 deletions
+28 -14
View File
@@ -369,6 +369,7 @@ public class PGL {
/** Whether OpenGL has been initialized or not */
protected boolean initialized;
protected boolean firstFrame;
/** Windowing toolkit */
protected static int toolkit = NEWT;
@@ -414,16 +415,16 @@ public class PGL {
// Objects for onscreen FBO-based rendering
/** Back (== draw, current frame) buffer */
protected FBObject backFBO;
protected static FBObject backFBO;
/** Sink buffer, used in the multisampled case */
protected FBObject sinkFBO;
protected static FBObject sinkFBO;
/** Front (== read, previous frame) buffer */
protected FBObject frontFBO;
protected static FBObject frontFBO;
protected FBObject.TextureAttachment backTex;
protected FBObject.TextureAttachment frontTex;
protected static FBObject.TextureAttachment backTex;
protected static FBObject.TextureAttachment frontTex;
///////////////////////////////////////////////////////////
@@ -540,6 +541,7 @@ public class PGL {
window.removeGLEventListener(listener);
pg.parent.remove(canvasNEWT);
}
sinkFBO = backFBO = frontFBO = null;
setFramerate = false;
}
@@ -607,6 +609,7 @@ public class PGL {
animator.start();
}
firstFrame = true;
initialized = true;
}
@@ -757,7 +760,7 @@ public class PGL {
protected void endDraw(boolean clear0) {
if (!clear0 && isFBOBacked() && capabilities.getNumSamples() == 0) {
if (!clear0 && isFBOBacked() && !isMultisampled()) {
// Draw the back texture into the front texture, which will be used as
// front texture in the next frame. Otherwise flickering will occur if
// the sketch uses "incremental drawing" (background() not called).
@@ -2366,11 +2369,28 @@ public class PGL {
protected class PGLListener implements GLEventListener {
@Override
// http://www.opengl.org/wiki/Default_Framebuffer
public void display(GLAutoDrawable glDrawable) {
drawable = glDrawable;
context = glDrawable.getContext();
gl = context.getGL();
gl2 = gl.getGL2ES2();
try {
gl2x = gl.getGL2();
} catch (javax.media.opengl.GLException e) {
gl2x = null;
}
if (firstFrame) {
// Cleaning all buffers for the first time.
gl.glClearDepthf(1);
gl.glClearStencil(0);
gl.glClearColor(0, 0, 0, 0);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT |
GL.GL_STENCIL_BUFFER_BIT);
firstFrame = false;
}
if (capabilities.isFBO()) {
// The onscreen drawing surface is backed by an FBO layer.
GLFBODrawable fboDrawable = null;
@@ -2420,13 +2440,7 @@ public class PGL {
}
}
gl = context.getGL();
gl2 = gl.getGL2ES2();
try {
gl2x = gl.getGL2();
} catch (javax.media.opengl.GLException e) {
gl2x = null;
}
pg.parent.handleDraw();
}
@@ -418,6 +418,9 @@ public class PGraphicsOpenGL extends PGraphics {
/** True if we are inside a beginDraw()/endDraw() block. */
protected boolean drawing = false;
/** Used to indicate an OpenGL surface recreation */
protected boolean restoreSurface = false;
/** Used to detect continuous use of the smooth/noSmooth functions */
protected boolean smoothDisabled = false;
protected int smoothCallCount = 0;
@@ -1566,15 +1569,21 @@ public class PGraphicsOpenGL extends PGraphics {
if (readFramebuffer == null) {
readFramebuffer = new FrameBuffer(parent, width, height, true);
}
if (pgl.isFBOBacked() && texture == null) {
texture = pgl.wrapBackTexture();
ptexture = pgl.wrapFrontTexture();
}
drawFramebuffer.setFBO(pgl.getDrawFramebuffer());
readFramebuffer.setFBO(pgl.getReadFramebuffer());
texture.glName = pgl.getBackTextureName();
ptexture.glName = pgl.getFrontTextureName();
if (pgl.isFBOBacked()) {
if (texture == null) {
texture = pgl.wrapBackTexture();
} else {
texture.glName = pgl.getBackTextureName();
}
if (ptexture == null) {
ptexture = pgl.wrapFrontTexture();
} else {
ptexture.glName = pgl.getFrontTextureName();
}
}
pgl.update();
} else {
@@ -1726,7 +1735,10 @@ public class PGraphicsOpenGL extends PGraphics {
defaultSettings();
}
if (restoreSurface) {
restoreSurfaceFromPixels();
restoreSurface = false;
}
if (hints[DISABLE_DEPTH_MASK]) {
pgl.depthMask(false);
@@ -1742,6 +1754,9 @@ public class PGraphicsOpenGL extends PGraphics {
clearColorBuffer0 = clearColorBuffer;
clearColorBuffer = false;
report("bot beginDraw()");
}
@@ -1758,6 +1773,18 @@ public class PGraphicsOpenGL extends PGraphics {
return;
}
if (!pgPrimary.pgl.initialized || parent.frameCount == 0) {
// Smooth was disabled/enabled at some point during drawing. We save
// the current contents of the back buffer (because the buffers haven't
// been swapped yet) to the pixels array. The frameCount == 0 condition
// is to handle the situation when no smooth is called in setup in the
// PDE, but the OpenGL appears to be recreated due to the size() nastiness.
saveSurfaceToPixels();
restoreSurface = true;
}
if (primarySurface) {
pgl.endDraw(clearColorBuffer0);
pgl.flush();
@@ -5142,6 +5169,17 @@ public class PGraphicsOpenGL extends PGraphics {
}
protected void saveSurfaceToPixels() {
allocatePixels();
readPixels();
}
protected void restoreSurfaceFromPixels() {
drawPixels(0, 0, width, height);
}
protected void readPixels() {
beginPixelsOp(OP_READ);
pixelBuffer.rewind();