@@ -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 ;
0 commit comments