@@ -1152,34 +1152,35 @@ class Framebuffer {
11521152 this . colorP5Texture . unbindTexture ( ) ;
11531153
11541154 this . prevFramebuffer = gl . getParameter ( gl . FRAMEBUFFER_BINDING ) ;
1155- gl . bindFramebuffer ( gl . FRAMEBUFFER , this . framebuffer ) ;
1156- if ( this . useDepth ) {
1157- gl . clearDepth ( 1 ) ;
1158- gl . clear ( gl . DEPTH_BUFFER_BIT ) ;
1159- }
11601155 if ( this . antialias ) {
1161- gl . bindFramebuffer ( gl . READ_FRAMEBUFFER , this . framebuffer ) ;
1162- gl . bindFramebuffer ( gl . DRAW_FRAMEBUFFER , this . aaFramebuffer ) ;
1163- const partsToCopy = [
1164- [ gl . COLOR_BUFFER_BIT , this . colorP5Texture . glMagFilter ]
1165- ] ;
1156+ // We need to make sure the antialiased framebuffer also has the updated
1157+ // pixels so that if more is drawn to it, it goes on top of the updated
1158+ // pixels instead of replacing them.
1159+ // We can't blit the framebuffer to the multisampled antialias
1160+ // framebuffer to leave both in the same state, so instead we have
1161+ // to use image() to put the framebuffer texture onto the antialiased
1162+ // framebuffer.
1163+ this . begin ( ) ;
1164+ this . target . push ( ) ;
1165+ this . target . imageMode ( this . target . CENTER ) ;
1166+ this . target . resetMatrix ( ) ;
1167+ this . target . noStroke ( ) ;
1168+ this . target . clear ( ) ;
1169+ this . target . image ( this , 0 , 0 ) ;
1170+ this . target . pop ( ) ;
11661171 if ( this . useDepth ) {
1167- partsToCopy . push (
1168- [ gl . DEPTH_BUFFER_BIT , this . depthP5Texture . glMagFilter ]
1169- ) ;
1172+ gl . clearDepth ( 1 ) ;
1173+ gl . clear ( gl . DEPTH_BUFFER_BIT ) ;
11701174 }
1171- for ( const [ flag , filter ] of partsToCopy ) {
1172- gl . blitFramebuffer (
1173- 0 , 0 ,
1174- this . width * this . density , this . height * this . density ,
1175- 0 , 0 ,
1176- this . width * this . density , this . height * this . density ,
1177- flag ,
1178- filter
1179- ) ;
1175+ this . end ( ) ;
1176+ } else {
1177+ gl . bindFramebuffer ( gl . FRAMEBUFFER , this . framebuffer ) ;
1178+ if ( this . useDepth ) {
1179+ gl . clearDepth ( 1 ) ;
1180+ gl . clear ( gl . DEPTH_BUFFER_BIT ) ;
11801181 }
1182+ gl . bindFramebuffer ( gl . FRAMEBUFFER , this . prevFramebuffer ) ;
11811183 }
1182- gl . bindFramebuffer ( gl . FRAMEBUFFER , this . prevFramebuffer ) ;
11831184 }
11841185}
11851186
0 commit comments