Skip to content

Commit

Permalink
WebGLTextures: Simplify updateMultisampleRenderTarget().
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Apr 15, 2024
1 parent 8c55e3e commit 16123ad
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions src/renderers/webgl/WebGLTextures.js
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

}

const invalidationArrayRead = [];
const invalidationArrayDraw = [];

function updateMultisampleRenderTarget( renderTarget ) {

if ( renderTarget.samples > 0 ) {
Expand All @@ -1841,7 +1844,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
const width = renderTarget.width;
const height = renderTarget.height;
let mask = _gl.COLOR_BUFFER_BIT;
const invalidationArray = [];
const depthStyle = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;
const renderTargetProperties = properties.get( renderTarget );
const isMultipleRenderTargets = ( textures.length > 1 );
Expand All @@ -1866,14 +1868,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

for ( let i = 0; i < textures.length; i ++ ) {

invalidationArray.push( _gl.COLOR_ATTACHMENT0 + i );

if ( renderTarget.depthBuffer ) {

invalidationArray.push( depthStyle );

}

const ignoreDepthValues = ( renderTargetProperties.__ignoreDepthValues !== undefined ) ? renderTargetProperties.__ignoreDepthValues : false;

if ( ignoreDepthValues === false ) {
Expand All @@ -1890,31 +1884,33 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,

_gl.framebufferRenderbuffer( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[ i ] );

const webglTexture = properties.get( textures[ i ] ).__webglTexture;
_gl.framebufferTexture2D( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, webglTexture, 0 );

}

if ( ignoreDepthValues === true && supportsInvalidateFramebuffer ) {
_gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, _gl.NEAREST );

_gl.invalidateFramebuffer( _gl.READ_FRAMEBUFFER, [ depthStyle ] );
_gl.invalidateFramebuffer( _gl.DRAW_FRAMEBUFFER, [ depthStyle ] );
if ( supportsInvalidateFramebuffer === true ) {

}
invalidationArrayRead.length = 0;
invalidationArrayDraw.length = 0;

if ( isMultipleRenderTargets ) {
invalidationArrayRead.push( _gl.COLOR_ATTACHMENT0 + i );

const webglTexture = properties.get( textures[ i ] ).__webglTexture;
_gl.framebufferTexture2D( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, webglTexture, 0 );
if ( renderTarget.depthBuffer && ignoreDepthValues === true ) {

}
invalidationArrayRead.push( depthStyle );
invalidationArrayDraw.push( depthStyle );

_gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, _gl.NEAREST );
_gl.invalidateFramebuffer( _gl.DRAW_FRAMEBUFFER, invalidationArrayDraw );

if ( supportsInvalidateFramebuffer ) {
}

_gl.invalidateFramebuffer( _gl.READ_FRAMEBUFFER, invalidationArray );
_gl.invalidateFramebuffer( _gl.READ_FRAMEBUFFER, invalidationArrayRead );

}


}

state.bindFramebuffer( _gl.READ_FRAMEBUFFER, null );
Expand Down

0 comments on commit 16123ad

Please sign in to comment.