Skip to content

Commit

Permalink
Fix restoring framebuffer binding after texture swap
Browse files Browse the repository at this point in the history
  • Loading branch information
Oletus committed Jul 30, 2020
1 parent be6e703 commit 76a466d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ function WebGLRenderer( parameters ) {
let _currentActiveCubeFace = 0;
let _currentActiveMipmapLevel = 0;
let _currentRenderTarget = null;
let _currentFramebuffer = null;
let _currentMaterialId = - 1;

let _currentCamera = null;
Expand Down Expand Up @@ -1833,10 +1832,10 @@ function WebGLRenderer( parameters ) {

}

if ( _currentFramebuffer !== framebuffer ) {
if ( textures.currentFramebuffer !== framebuffer ) {

_gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
_currentFramebuffer = framebuffer;
textures.currentFramebuffer = framebuffer;

}

Expand Down Expand Up @@ -1874,7 +1873,7 @@ function WebGLRenderer( parameters ) {

let restore = false;

if ( framebuffer !== _currentFramebuffer ) {
if ( framebuffer !== textures.currentFramebuffer ) {

_gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );

Expand Down Expand Up @@ -1924,7 +1923,7 @@ function WebGLRenderer( parameters ) {

if ( restore ) {

_gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
_gl.bindFramebuffer( _gl.FRAMEBUFFER, textures.currentFramebuffer );

}

Expand Down
12 changes: 7 additions & 5 deletions src/renderers/webgl/WebGLTextures.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

}

_gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
_gl.bindFramebuffer( _gl.FRAMEBUFFER, this.currentFramebuffer );

} else {

_gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
_gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, textureProperties.__webglTexture, 0 );
_gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
_gl.bindFramebuffer( _gl.FRAMEBUFFER, this.currentFramebuffer );

}

Expand Down Expand Up @@ -879,7 +879,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
_gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
_gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
_gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
_gl.bindFramebuffer( _gl.FRAMEBUFFER, this.currentFramebuffer );

}

Expand Down Expand Up @@ -1045,7 +1045,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

}

_gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
_gl.bindFramebuffer( _gl.FRAMEBUFFER, this.currentFramebuffer );

}

Expand Down Expand Up @@ -1113,7 +1113,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

}

_gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
_gl.bindFramebuffer( _gl.FRAMEBUFFER, this.currentFramebuffer );


} else {
Expand Down Expand Up @@ -1334,6 +1334,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
this.safeSetTexture2D = safeSetTexture2D;
this.safeSetTextureCube = safeSetTextureCube;

this.currentFramebuffer = null;

}

export { WebGLTextures };

0 comments on commit 76a466d

Please sign in to comment.