Skip to content

Commit 7d437ba

Browse files
committed
added swapColorBuffers() to FrameBuffer, some cleanup
1 parent 4031ad0 commit 7d437ba

2 files changed

Lines changed: 31 additions & 19 deletions

File tree

core/src/processing/opengl/FrameBuffer.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,27 @@ public void setColorBuffers(Texture[] textures, int n) {
290290
}
291291

292292

293+
public void swapColorBuffers() {
294+
for (int i = 0; i < numColorBuffers - 1; i++) {
295+
int i1 = (i + 1);
296+
Texture tmp = colorBufferTex[i];
297+
colorBufferTex[i] = colorBufferTex[i1];
298+
colorBufferTex[i1] = tmp;
299+
}
300+
301+
pg.pushFramebuffer();
302+
pg.setFramebuffer(this);
303+
for (int i = 0; i < numColorBuffers; i++) {
304+
pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
305+
colorBufferTex[i].glTarget,
306+
colorBufferTex[i].glName, 0);
307+
}
308+
pgl.validateFramebuffer();
309+
310+
pg.popFramebuffer();
311+
}
312+
313+
293314
///////////////////////////////////////////////////////////
294315

295316
// Allocate/release framebuffer.

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,8 +1150,10 @@ protected void pushFramebuffer() {
11501150

11511151

11521152
protected void setFramebuffer(FrameBuffer fbo) {
1153-
currentFramebuffer = fbo;
1154-
currentFramebuffer.bind();
1153+
if (currentFramebuffer != fbo) {
1154+
currentFramebuffer = fbo;
1155+
currentFramebuffer.bind();
1156+
}
11551157
}
11561158

11571159

@@ -1160,9 +1162,12 @@ protected void popFramebuffer() {
11601162
throw new RuntimeException("popFramebuffer call is unbalanced.");
11611163
}
11621164
fbStackDepth--;
1163-
currentFramebuffer.finish();
1164-
currentFramebuffer = fbStack[fbStackDepth];
1165-
currentFramebuffer.bind();
1165+
FrameBuffer fbo = fbStack[fbStackDepth];
1166+
if (currentFramebuffer != fbo) {
1167+
currentFramebuffer.finish();
1168+
currentFramebuffer = fbo;
1169+
currentFramebuffer.bind();
1170+
}
11661171
}
11671172

11681173

@@ -5435,20 +5440,6 @@ public void loadTexture() {
54355440
if (offscreenMultisample) {
54365441
offscreenFramebufferMultisample.copy(offscreenFramebuffer);
54375442
}
5438-
5439-
// Make the offscreen color buffer opaque so it doesn't show
5440-
// the background when drawn on the main surface.
5441-
if (offscreenMultisample) {
5442-
pushFramebuffer();
5443-
setFramebuffer(offscreenFramebuffer);
5444-
}
5445-
pgl.colorMask(false, false, false, true);
5446-
pgl.clearColor(0, 0, 0, 1);
5447-
pgl.clear(PGL.COLOR_BUFFER_BIT);
5448-
pgl.colorMask(true, true, true, true);
5449-
if (offscreenMultisample) {
5450-
popFramebuffer();
5451-
}
54525443
}
54535444

54545445
if (needEndDraw) {

0 commit comments

Comments
 (0)