Skip to content

Commit

Permalink
testing a couple of library methods to access the contents of the
Browse files Browse the repository at this point in the history
offscreen FrameBuffers
  • Loading branch information
codeanticode committed Jan 23, 2014
1 parent 2e15859 commit 4563296
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
21 changes: 16 additions & 5 deletions core/src/processing/opengl/FrameBuffer.java
Expand Up @@ -185,14 +185,25 @@ public void clear() {
pg.popFramebuffer();
}

public void copy(FrameBuffer dest, FrameBuffer current) {
public void copyColor(FrameBuffer dest) {
copy(dest, PGL.COLOR_BUFFER_BIT);
}

public void copyDepth(FrameBuffer dest) {
copy(dest, PGL.DEPTH_BUFFER_BIT);
}

public void copyStencil(FrameBuffer dest) {
copy(dest, PGL.STENCIL_BUFFER_BIT);
}

public void copy(FrameBuffer dest, int mask) {
pgl.bindFramebuffer(PGL.READ_FRAMEBUFFER, this.glFbo);
pgl.bindFramebuffer(PGL.DRAW_FRAMEBUFFER, dest.glFbo);
pgl.blitFramebuffer(0, 0, this.width, this.height,
0, 0, dest.width, dest.height,
PGL.COLOR_BUFFER_BIT, PGL.NEAREST);
pgl.bindFramebuffer(PGL.READ_FRAMEBUFFER, current.glFbo);
pgl.bindFramebuffer(PGL.DRAW_FRAMEBUFFER, current.glFbo);
0, 0, dest.width, dest.height, mask, PGL.NEAREST);
pgl.bindFramebuffer(PGL.READ_FRAMEBUFFER, pg.getCurrentFB().glFbo);
pgl.bindFramebuffer(PGL.DRAW_FRAMEBUFFER, pg.getCurrentFB().glFbo);
}

public void bind() {
Expand Down
24 changes: 21 additions & 3 deletions core/src/processing/opengl/PGraphicsOpenGL.java
Expand Up @@ -1842,7 +1842,7 @@ protected void beginPixelsOp(int op) {
if (op == OP_READ) {
if (offscreenMultisample) {
// Making sure the offscreen FBO is up-to-date
multisampleFramebuffer.copy(offscreenFramebuffer, getCurrentFB());
multisampleFramebuffer.copyColor(offscreenFramebuffer);
}
// We always read the screen pixels from the color FBO.
pixfb = offscreenFramebuffer;
Expand Down Expand Up @@ -5621,7 +5621,7 @@ public void loadTexture() {
} else if (offscreenMultisample) {
// We need to copy the contents of the multisampled buffer to the color
// buffer, so the later is up-to-date with the last drawing.
multisampleFramebuffer.copy(offscreenFramebuffer, getCurrentFB());
multisampleFramebuffer.copyColor(offscreenFramebuffer);
}

if (needEndDraw) {
Expand Down Expand Up @@ -6088,6 +6088,24 @@ public Texture getTexture(PImage img) {
}


/**
* Not an approved function, test its use in libraries to grab the FB objects
* for offscreen PGraphics.
*/
public FrameBuffer getFrameBuffer() {
return getFrameBuffer(false);
}


public FrameBuffer getFrameBuffer(boolean multi) {
if (multi) {
return multisampleFramebuffer;
} else {
return offscreenFramebuffer;
}
}


protected Object initCache(PImage img) {
if (!checkGLThread()) {
return null;
Expand Down Expand Up @@ -6373,7 +6391,7 @@ protected void endOffscreenDraw() {
// pgl.colorMask(true, true, true, true);

if (offscreenMultisample) {
multisampleFramebuffer.copy(offscreenFramebuffer, getCurrentFB());
multisampleFramebuffer.copyColor(offscreenFramebuffer);
}

popFramebuffer();
Expand Down

0 comments on commit 4563296

Please sign in to comment.