Skip to content

Commit 2ab27ea

Browse files
aardgooseaardgoose
andauthored
WebGPURenderer: create invalidation array once for WebGL MSAA (#27505)
Co-authored-by: aardgoose <[email protected]>
1 parent ca62e47 commit 2ab27ea

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

examples/jsm/renderers/webgl/WebGLBackend.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,11 @@ class WebGLBackend extends Backend {
141141

142142
const renderTargetContextData = this.get( renderContext.renderTarget );
143143

144-
const { samples, stencilBuffer } = renderContext.renderTarget;
144+
const { samples } = renderContext.renderTarget;
145145
const fb = renderTargetContextData.framebuffer;
146146

147147
if ( samples > 0 ) {
148148

149-
const invalidationArray = [];
150-
const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
151-
152-
invalidationArray.push( gl.COLOR_ATTACHMENT0 );
153-
154-
if ( renderTargetContextData.depthBuffer ) {
155-
156-
invalidationArray.push( depthStyle );
157-
158-
}
159-
160149
// TODO For loop support MRT
161150
const msaaFrameBuffer = renderTargetContextData.msaaFrameBuffer;
162151

@@ -166,7 +155,7 @@ class WebGLBackend extends Backend {
166155

167156
gl.blitFramebuffer( 0, 0, renderContext.width, renderContext.height, 0, 0, renderContext.width, renderContext.height, gl.COLOR_BUFFER_BIT, gl.NEAREST );
168157

169-
gl.invalidateFramebuffer( gl.READ_FRAMEBUFFER, invalidationArray );
158+
gl.invalidateFramebuffer( gl.READ_FRAMEBUFFER, renderTargetContextData.invalidationArray );
170159

171160
}
172161

@@ -880,7 +869,7 @@ class WebGLBackend extends Backend {
880869

881870
const renderTarget = renderContext.renderTarget;
882871
const renderTargetContextData = this.get( renderTarget );
883-
const { samples } = renderTarget;
872+
const { samples, stencilBuffer } = renderTarget;
884873
const cubeFace = this.renderer._activeCubeFace;
885874
const isCube = renderTarget.isWebGLCubeRenderTarget === true;
886875

@@ -943,8 +932,9 @@ class WebGLBackend extends Backend {
943932
if ( renderContext.depthTexture !== null ) {
944933

945934
const textureData = this.get( renderContext.depthTexture );
935+
const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
946936

947-
gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, textureData.textureGPU, 0 );
937+
gl.framebufferTexture2D( gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, textureData.textureGPU, 0 );
948938

949939
}
950940

@@ -954,6 +944,8 @@ class WebGLBackend extends Backend {
954944

955945
if ( msaaFb === undefined ) {
956946

947+
const invalidationArray = [];
948+
957949
msaaFb = gl.createFramebuffer();
958950

959951
state.bindFramebuffer( gl.FRAMEBUFFER, msaaFb );
@@ -968,6 +960,8 @@ class WebGLBackend extends Backend {
968960
gl.renderbufferStorageMultisample( gl.RENDERBUFFER, samples, textureData.glInternalFormat, renderContext.width, renderContext.height );
969961
gl.framebufferRenderbuffer( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, msaaRenderbuffer );
970962

963+
invalidationArray.push( gl.COLOR_ATTACHMENT0 );
964+
971965
renderTargetContextData.msaaRenderbuffer = msaaRenderbuffer;
972966
renderTargetContextData.msaaFrameBuffer = msaaFb;
973967

@@ -978,8 +972,13 @@ class WebGLBackend extends Backend {
978972

979973
renderTargetContextData.depthRenderbuffer = depthRenderbuffer;
980974

975+
const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
976+
invalidationArray.push( depthStyle );
977+
981978
}
982979

980+
renderTargetContextData.invalidationArray = invalidationArray;
981+
983982
}
984983

985984
currentFrameBuffer = renderTargetContextData.msaaFrameBuffer;

0 commit comments

Comments
 (0)