Skip to content

Commit 5d464d8

Browse files
committed
initialize screen FBO
1 parent cc125c5 commit 5d464d8

File tree

3 files changed

+44
-59
lines changed

3 files changed

+44
-59
lines changed

core/src/processing/opengl/PGL.java

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public abstract class PGL {
137137

138138
// FBO layer
139139

140-
protected boolean fboLayerRequested = false;
140+
protected boolean requestedFBOLayer = false;
141141
protected boolean fboLayerCreated = false;
142142
protected boolean fboLayerInUse = false;
143143
protected boolean firstFrame = true;
@@ -528,7 +528,7 @@ protected int getDefaultReadBuffer() {
528528

529529

530530
public void requestFBOLayer() {
531-
fboLayerRequested = true;
531+
requestedFBOLayer = true;
532532
}
533533

534534

@@ -669,8 +669,8 @@ public boolean insideCloseButton(float x, float y) {
669669
// Frame rendering
670670

671671

672-
protected void beginDraw(boolean clear0) {
673-
if (needFBOLayer(clear0)) {
672+
protected void beginDraw(boolean pclear) {
673+
if (requestedFBOLayer) {
674674
if (!fboLayerCreated) createFBOLayer();
675675

676676
bindFramebufferImpl(FRAMEBUFFER, glColorFbo.get(0));
@@ -690,7 +690,7 @@ protected void beginDraw(boolean clear0) {
690690
float b = ((argb) & 0xff) / 255.0f;
691691
clearColor(r, g, b, a);
692692
clear(COLOR_BUFFER_BIT);
693-
} else if (!clear0) {
693+
} else if (!pclear) {
694694
// Render previous back texture (now is the front) as background,
695695
// because no background() is being used ("incremental drawing")
696696
int x = 0;
@@ -714,19 +714,9 @@ protected void beginDraw(boolean clear0) {
714714
if (firstFrame) {
715715
firstFrame = false;
716716
}
717-
718-
// if (!USE_FBOLAYER_BY_DEFAULT) {
719-
// The result of this assignment is the following: if the user requested
720-
// at some point the use of the FBO layer, but subsequently didn't
721-
// request it again, then the rendering won't render to the FBO layer if
722-
// not needed by the config, since it is slower than simple onscreen
723-
// rendering.
724-
// fboLayerRequested = false;
725-
// }
726717
}
727718

728719

729-
730720
protected void endDraw(boolean clear, int windowColor) {
731721
if (fboLayerInUse) {
732722
syncBackTexture();
@@ -753,14 +743,6 @@ protected void endDraw(boolean clear, int windowColor) {
753743
texParameteri(TEXTURE_2D, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
754744
texParameteri(TEXTURE_2D, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
755745
texImage2D(TEXTURE_2D, 0, RGBA, closeBtnWidth, closeBtnHeight, 0, RGBA, UNSIGNED_BYTE, null);
756-
// initTexture(TEXTURE_2D, RGBA, 100, 50, pg.backgroundColor);
757-
758-
// ByteBuffer bb = ByteBuffer.allocateDirect(labelPix.length*4);
759-
// bb.order(ByteOrder.nativeOrder());
760-
// IntBuffer ib = bb.asIntBuffer();
761-
// ib.put(labelPix);
762-
// ib.position(0);
763-
764746
IntBuffer buf = allocateIntBuffer(closeBtnPix);
765747
copyToTexture(TEXTURE_2D, RGBA, closeBtnTex.get(0), 0, 0, closeBtnWidth, closeBtnHeight, buf);
766748
bindTexture(TEXTURE_2D, 0);
@@ -769,19 +751,6 @@ protected void endDraw(boolean clear, int windowColor) {
769751
0, 0, closeBtnX + closeBtnWidth, closeBtnY + closeBtnHeight,
770752
0, closeBtnHeight, closeBtnWidth, 0,
771753
closeBtnX, closeBtnY, closeBtnX + closeBtnWidth, closeBtnY + closeBtnHeight);
772-
773-
/*
774-
// Don't use presentMode offset!
775-
drawTexture(TEXTURE_2D, labelTex.get(0),
776-
100, 50, pg.width, pg.height,
777-
0, 0, pg.width, pg.height,
778-
0, 0, pg.width, pg.height);
779-
780-
drawTexture2D(labelTex.get(0), 100, 50, int scrW, int scrH,
781-
0, 0, 100, 50,
782-
int scrX0, int scrY0, int scrX1, int scrY1);
783-
*/
784-
785754
} else {
786755
clearDepth(1);
787756
clearColor(0, 0, 0, 0);
@@ -808,13 +777,14 @@ protected void endDraw(boolean clear, int windowColor) {
808777
frontTex = backTex;
809778
backTex = temp;
810779
} else if (!clear && pg.parent.frameCount == 1) {
811-
//requestFBOLayer();
780+
requestFBOLayer();
812781
}
813782
}
814783

815784

816785
protected abstract void getGL(PGL pgl);
817786

787+
818788
protected abstract boolean canDraw();
819789

820790

@@ -843,16 +813,6 @@ protected void beginGL() { }
843813
protected void endGL() { }
844814

845815

846-
private boolean needFBOLayer(boolean clear0) {
847-
// TODO: need to revise this, on windows we might not want to use FBO layer
848-
// even with anti-aliasing enabled...
849-
// boolean res = !clear0 || fboLayerRequested || 1 < numSamples;
850-
// System.err.println(res + " " + clear0 + " " + fboLayerRequested + " " + numSamples);
851-
// return res;
852-
return fboLayerRequested;
853-
}
854-
855-
856816
private void createFBOLayer() {
857817
float scale = pg.getPixelScale();
858818

@@ -934,6 +894,26 @@ private void createFBOLayer() {
934894
clearColor(r, g, b, a);
935895
clear(DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT | COLOR_BUFFER_BIT);
936896

897+
if (0 < pg.parent.frameCount) {
898+
// Copy the contents of the front and back screen buffers to the textures
899+
// of the FBO, so they are properly initialized.
900+
bindFramebufferImpl(READ_FRAMEBUFFER, BACK);
901+
bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0));
902+
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0,
903+
TEXTURE_2D, glColorTex.get(backTex), 0);
904+
blitFramebuffer(0, 0, fboWidth, fboHeight,
905+
0, 0, fboWidth, fboHeight,
906+
COLOR_BUFFER_BIT, NEAREST);
907+
908+
bindFramebufferImpl(READ_FRAMEBUFFER, FRONT);
909+
bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0));
910+
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0,
911+
TEXTURE_2D, glColorTex.get(frontTex), 0);
912+
blitFramebuffer(0, 0, fboWidth, fboHeight,
913+
0, 0, fboWidth, fboHeight,
914+
COLOR_BUFFER_BIT, NEAREST);
915+
}
916+
937917
bindFramebufferImpl(FRAMEBUFFER, 0);
938918

939919
fboLayerCreated = true;

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,8 @@ public class PGraphicsOpenGL extends PGraphics {
443443
protected IntBuffer viewport;
444444

445445
/** Used to register calls to glClear. */
446-
protected boolean clearColorBuffer;
447-
protected boolean clearColorBuffer0;
446+
protected boolean clearColor;
447+
protected boolean pclearColor;
448448

449449
protected boolean openContour = false;
450450
protected boolean breakShape = false;
@@ -2397,7 +2397,7 @@ protected void defaultSettings() {
23972397

23982398
manipulatingCamera = false;
23992399

2400-
clearColorBuffer = false;
2400+
clearColor = false;
24012401

24022402
// easiest for beginners
24032403
textureMode(IMAGE);
@@ -5802,7 +5802,7 @@ protected void backgroundImpl(PImage image) {
58025802
backgroundImpl();
58035803
set(0, 0, image);
58045804
if (0 < parent.frameCount) {
5805-
clearColorBuffer = true;
5805+
clearColor = true;
58065806
}
58075807
// Setting the background as opaque. If this an offscreen surface, the
58085808
// alpha channel will be set to 1 in endOffscreenDraw(), even if
@@ -5824,7 +5824,7 @@ protected void backgroundImpl() {
58245824
pgl.clearColor(backgroundR, backgroundG, backgroundB, backgroundA);
58255825
pgl.clear(PGL.COLOR_BUFFER_BIT);
58265826
if (0 < parent.frameCount) {
5827-
clearColorBuffer = true;
5827+
clearColor = true;
58285828
}
58295829
}
58305830

@@ -6853,7 +6853,7 @@ protected void initPrimary() {
68536853
protected void beginOnscreenDraw() {
68546854
updatePixelSize();
68556855

6856-
pgl.beginDraw(clearColorBuffer);
6856+
pgl.beginDraw(clearColor);
68576857

68586858
if (drawFramebuffer == null) {
68596859
drawFramebuffer = new FrameBuffer(this, pixelWidth, pixelHeight, true);
@@ -6875,7 +6875,7 @@ protected void beginOnscreenDraw() {
68756875

68766876

68776877
protected void endOnscreenDraw() {
6878-
pgl.endDraw(clearColorBuffer, parent.sketchWindowColor());
6878+
pgl.endDraw(clearColor, parent.sketchWindowColor());
68796879
}
68806880

68816881

@@ -7122,8 +7122,8 @@ protected void setDrawDefaults() {
71227122

71237123
pixelsOp = OP_NONE;
71247124

7125-
clearColorBuffer0 = clearColorBuffer;
7126-
clearColorBuffer = false;
7125+
pclearColor = clearColor;
7126+
clearColor = false;
71277127

71287128
modified = false;
71297129
arePixelsUpToDate = false;

core/src/processing/opengl/PSurfaceJOGL.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ protected void initWindow() {
300300
}
301301
window.setSurfaceScale(reqSurfacePixelScale);
302302
window.setSize(sketchWidth, sketchHeight);
303+
// window.setResizable(false);
303304
setSize(sketchWidth, sketchHeight);
304305
sketchX = displayDevice.getViewportInWindowUnits().getX();
305306
sketchY = displayDevice.getViewportInWindowUnits().getY();
@@ -390,8 +391,13 @@ public void setVisible(boolean visible) {
390391

391392

392393
@Override
393-
public void setResizable(boolean resizable) {
394-
// TODO Auto-generated method stub
394+
public void setResizable(final boolean resizable) {
395+
// display.getEDTUtil().invoke(false, new Runnable() {
396+
// @Override
397+
// public void run() {
398+
// window.setResizable(resizable);
399+
// }
400+
// });
395401
}
396402

397403

@@ -1019,7 +1025,6 @@ public void setCursor(PImage image, int hotspotX, int hotspotY) {
10191025
// hotspotY);
10201026
//
10211027
// window.setPointerIcon(pi);
1022-
10231028
}
10241029

10251030

0 commit comments

Comments
 (0)