Skip to content

Commit 4accc17

Browse files
committed
handle framebuffer set to 0
1 parent 341065b commit 4accc17

File tree

5 files changed

+41
-22
lines changed

5 files changed

+41
-22
lines changed

core/src/processing/opengl/FrameBuffer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,16 @@ public void copyStencil(FrameBuffer dest) {
198198
}
199199

200200
public void copy(FrameBuffer dest, int mask) {
201-
pgl.bindFramebuffer(PGL.READ_FRAMEBUFFER, this.glFbo);
202-
pgl.bindFramebuffer(PGL.DRAW_FRAMEBUFFER, dest.glFbo);
201+
pgl.bindFramebufferImpl(PGL.READ_FRAMEBUFFER, this.glFbo);
202+
pgl.bindFramebufferImpl(PGL.DRAW_FRAMEBUFFER, dest.glFbo);
203203
pgl.blitFramebuffer(0, 0, this.width, this.height,
204204
0, 0, dest.width, dest.height, mask, PGL.NEAREST);
205-
pgl.bindFramebuffer(PGL.READ_FRAMEBUFFER, pg.getCurrentFB().glFbo);
206-
pgl.bindFramebuffer(PGL.DRAW_FRAMEBUFFER, pg.getCurrentFB().glFbo);
205+
pgl.bindFramebufferImpl(PGL.READ_FRAMEBUFFER, pg.getCurrentFB().glFbo);
206+
pgl.bindFramebufferImpl(PGL.DRAW_FRAMEBUFFER, pg.getCurrentFB().glFbo);
207207
}
208208

209209
public void bind() {
210-
pgl.bindFramebuffer(PGL.FRAMEBUFFER, glFbo);
210+
pgl.bindFramebufferImpl(PGL.FRAMEBUFFER, glFbo);
211211
}
212212

213213
public void disableDepthTest() {

core/src/processing/opengl/PGL.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ protected void unbindFrontTexture() {
511511
protected void syncBackTexture() {
512512
if (usingFrontTex) needSepFrontTex = true;
513513
if (1 < numSamples) {
514-
bindFramebuffer(READ_FRAMEBUFFER, glMultiFbo.get(0));
515-
bindFramebuffer(DRAW_FRAMEBUFFER, glColorFbo.get(0));
514+
bindFramebufferImpl(READ_FRAMEBUFFER, glMultiFbo.get(0));
515+
bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0));
516516
blitFramebuffer(0, 0, fboWidth, fboHeight,
517517
0, 0, fboWidth, fboHeight,
518518
COLOR_BUFFER_BIT, NEAREST);
@@ -529,12 +529,12 @@ protected void beginDraw(boolean clear0) {
529529
if (needFBOLayer(clear0)) {
530530
if (!fboLayerCreated) createFBOLayer();
531531

532-
bindFramebuffer(FRAMEBUFFER, glColorFbo.get(0));
532+
bindFramebufferImpl(FRAMEBUFFER, glColorFbo.get(0));
533533
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0,
534534
TEXTURE_2D, glColorTex.get(backTex), 0);
535535

536536
if (1 < numSamples) {
537-
bindFramebuffer(FRAMEBUFFER, glMultiFbo.get(0));
537+
bindFramebufferImpl(FRAMEBUFFER, glMultiFbo.get(0));
538538
}
539539

540540
if (firstFrame) {
@@ -580,7 +580,7 @@ protected void endDraw(boolean clear0) {
580580
syncBackTexture();
581581

582582
// Draw the contents of the back texture to the screen framebuffer.
583-
bindFramebuffer(FRAMEBUFFER, 0);
583+
bindFramebufferImpl(FRAMEBUFFER, 0);
584584

585585
clearDepth(1);
586586
clearColor(0, 0, 0, 0);
@@ -670,14 +670,14 @@ private void createFBOLayer() {
670670
frontTex = 1;
671671

672672
genFramebuffers(1, glColorFbo);
673-
bindFramebuffer(FRAMEBUFFER, glColorFbo.get(0));
673+
bindFramebufferImpl(FRAMEBUFFER, glColorFbo.get(0));
674674
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0, TEXTURE_2D,
675675
glColorTex.get(backTex), 0);
676676

677677
if (multisample) {
678678
// Creating multisampled FBO
679679
genFramebuffers(1, glMultiFbo);
680-
bindFramebuffer(FRAMEBUFFER, glMultiFbo.get(0));
680+
bindFramebufferImpl(FRAMEBUFFER, glMultiFbo.get(0));
681681

682682
// color render buffer...
683683
genRenderbuffers(1, glColorBuf);
@@ -766,7 +766,7 @@ private void createFBOLayer() {
766766
clearColor(r, g, b, a);
767767
clear(DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT | COLOR_BUFFER_BIT);
768768

769-
bindFramebuffer(FRAMEBUFFER, 0);
769+
bindFramebufferImpl(FRAMEBUFFER, 0);
770770

771771
fboLayerCreated = true;
772772
}
@@ -2559,11 +2559,11 @@ protected interface FontOutline {
25592559
// to glReadPixels() should be done in readPixelsImpl().
25602560

25612561
public void readPixels(int x, int y, int width, int height, int format, int type, Buffer buffer){
2562-
boolean needEndBegin = format != STENCIL_INDEX &&
2563-
format != DEPTH_COMPONENT && format != DEPTH_STENCIL;
2564-
if (needEndBegin) pg.beginReadPixels();
2562+
boolean pgCall = format != STENCIL_INDEX &&
2563+
format != DEPTH_COMPONENT && format != DEPTH_STENCIL;
2564+
if (pgCall) pg.beginReadPixels();
25652565
readPixelsImpl(x, y, width, height, format, type, buffer);
2566-
if (needEndBegin) pg.endReadPixels();
2566+
if (pgCall) pg.endReadPixels();
25672567
}
25682568

25692569
protected abstract void readPixelsImpl(int x, int y, int width, int height, int format, int type, Buffer buffer);
@@ -2745,7 +2745,13 @@ public void bindTexture(int target, int texture) {
27452745

27462746
// Framebuffers Objects
27472747

2748-
public abstract void bindFramebuffer(int target, int framebuffer);
2748+
public void bindFramebuffer(int target, int framebuffer) {
2749+
pg.beginBindFramebuffer(target, framebuffer);
2750+
bindFramebufferImpl(target, framebuffer);
2751+
pg.endBindFramebuffer(target, framebuffer);
2752+
}
2753+
protected abstract void bindFramebufferImpl(int target, int framebuffer);
2754+
27492755
public abstract void deleteFramebuffers(int n, IntBuffer framebuffers);
27502756
public abstract void genFramebuffers(int n, IntBuffer framebuffers);
27512757
public abstract void bindRenderbuffer(int target, int renderbuffer);

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,11 +1812,24 @@ protected void restoreGL() {
18121812
}
18131813
}
18141814

1815-
public void beginReadPixels() {
1815+
protected void beginBindFramebuffer(int target, int framebuffer) {
1816+
// Actually, nothing to do here.
1817+
}
1818+
1819+
protected void endBindFramebuffer(int target, int framebuffer) {
1820+
if (framebuffer == 0 && currentFramebuffer != null &&
1821+
currentFramebuffer.glFbo != 0) {
1822+
// The user is setting the framebuffer to 0 (screen buffer), but the
1823+
// renderer is rendering to an offscreen buffer.
1824+
currentFramebuffer.bind();
1825+
}
1826+
}
1827+
1828+
protected void beginReadPixels() {
18161829
beginPixelsOp(OP_READ);
18171830
}
18181831

1819-
public void endReadPixels() {
1832+
protected void endReadPixels() {
18201833
endPixelsOp();
18211834
}
18221835

core/src/processing/opengl/PJOGL.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2414,7 +2414,7 @@ public void clearStencil(int s) {
24142414
// Framebuffers Objects
24152415

24162416
@Override
2417-
public void bindFramebuffer(int target, int framebuffer) {
2417+
protected void bindFramebufferImpl(int target, int framebuffer) {
24182418
gl.glBindFramebuffer(target, framebuffer);
24192419
}
24202420

java/libraries/lwjgl/src/processing/lwjgl/PLWJGL.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,7 @@ public void clearStencil(int s) {
19251925

19261926
// Framebuffers Objects
19271927

1928-
public void bindFramebuffer(int target, int framebuffer) {
1928+
protected void bindFramebufferImpl(int target, int framebuffer) {
19291929
GL30.glBindFramebuffer(target, framebuffer);
19301930
}
19311931

0 commit comments

Comments
 (0)