|
|
@@ -563,15 +563,40 @@ class WebGLBackend extends Backend {
|
|
|
}
|
|
|
|
|
|
const msaaFrameBuffer = renderTargetContextData.msaaFrameBuffer;
|
|
|
+ const msaaRenderbuffers = renderTargetContextData.msaaRenderbuffers;
|
|
|
|
|
|
const textures = renderContext.textures;
|
|
|
+ const isMRT = textures.length > 1;
|
|
|
|
|
|
state.bindFramebuffer( gl.READ_FRAMEBUFFER, msaaFrameBuffer );
|
|
|
state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb );
|
|
|
|
|
|
+ if ( isMRT ) {
|
|
|
+
|
|
|
+ // blitFramebuffer() can only copy/resolve the first color attachment of a framebuffer. When using MRT,
|
|
|
+ // the engine temporarily removes all attachments and then configures each attachment for the resolve.
|
|
|
+
|
|
|
+ for ( let i = 0; i < textures.length; i ++ ) {
|
|
|
+
|
|
|
+ gl.framebufferRenderbuffer( gl.READ_FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.RENDERBUFFER, null );
|
|
|
+ gl.framebufferTexture2D( gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.TEXTURE_2D, null, 0 );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
for ( let i = 0; i < textures.length; i ++ ) {
|
|
|
|
|
|
- // TODO Add support for MRT
|
|
|
+ if ( isMRT ) {
|
|
|
+
|
|
|
+ // configure attachment for resolve
|
|
|
+
|
|
|
+ const { textureGPU } = this.get( textures[ i ] );
|
|
|
+
|
|
|
+ gl.framebufferRenderbuffer( gl.READ_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, msaaRenderbuffers[ i ] );
|
|
|
+ gl.framebufferTexture2D( gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, textureGPU, 0 );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
if ( renderContext.scissor ) {
|
|
|
|
|
|
@@ -601,6 +626,21 @@ class WebGLBackend extends Backend {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ if ( isMRT ) {
|
|
|
+
|
|
|
+ // restore attachments
|
|
|
+
|
|
|
+ for ( let i = 0; i < textures.length; i ++ ) {
|
|
|
+
|
|
|
+ const { textureGPU } = this.get( textures[ i ] );
|
|
|
+
|
|
|
+ gl.framebufferRenderbuffer( gl.READ_FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.RENDERBUFFER, msaaRenderbuffers[ i ] );
|
|
|
+ gl.framebufferTexture2D( gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.TEXTURE_2D, textureGPU, 0 );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
} else if ( renderTarget.resolveDepthBuffer === false && renderTargetContextData.framebuffers ) {
|
|
|
|
|
|
const fb = renderTargetContextData.framebuffers[ renderContext.getCacheKey() ];
|
|
|
@@ -2095,8 +2135,6 @@ class WebGLBackend extends Backend {
|
|
|
|
|
|
}
|
|
|
|
|
|
- state.drawBuffers( descriptor, fb );
|
|
|
-
|
|
|
}
|
|
|
|
|
|
const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
|
|
|
@@ -2271,6 +2309,8 @@ class WebGLBackend extends Backend {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ gl.bindRenderbuffer( gl.RENDERBUFFER, null );
|
|
|
+
|
|
|
renderTargetContextData.msaaFrameBuffer = msaaFb;
|
|
|
renderTargetContextData.msaaRenderbuffers = msaaRenderbuffers;
|
|
|
|
|
|
@@ -2298,6 +2338,8 @@ class WebGLBackend extends Backend {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ state.drawBuffers( descriptor, fb );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
state.bindFramebuffer( gl.FRAMEBUFFER, currentFrameBuffer );
|