Skip to content

Commit

Permalink
Add support for the EXT_multisampled_render_to_texture extension and …
Browse files Browse the repository at this point in the history
…use it for WebXR (#22550)
  • Loading branch information
cabanier authored Sep 17, 2021
1 parent 89ca03d commit c789b20
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/renderers/webgl/WebGLExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function WebGLExtensions( gl ) {

getExtension( 'OES_texture_float_linear' );
getExtension( 'EXT_color_buffer_half_float' );
getExtension( 'EXT_multisampled_render_to_texture' );

},

Expand Down
34 changes: 27 additions & 7 deletions src/renderers/webxr/WebXRManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class WebXRManager extends EventDispatcher {
let xrFrame = null;
let depthStyle = null;
let clearStyle = null;
const msaartcSupported = renderer.extensions.has( 'EXT_multisampled_render_to_texture' );
let msaaExt = null;

const controllers = [];
const inputSourcesMap = new Map();
Expand Down Expand Up @@ -302,7 +304,11 @@ class WebXRManager extends EventDispatcher {

session.updateRenderState( { layers: [ glProjLayer ] } );

if ( isMultisample ) {
if ( isMultisample && msaartcSupported ) {

msaaExt = renderer.extensions.get( 'EXT_multisampled_render_to_texture' );

} else if ( isMultisample ) {

glMultisampledFramebuffer = gl.createFramebuffer();
glColorRenderbuffer = gl.createRenderbuffer();
Expand Down Expand Up @@ -623,13 +629,27 @@ class WebXRManager extends EventDispatcher {

state.bindXRFramebuffer( glFramebuffer );

if ( glSubImage.depthStencilTexture !== undefined ) {
if ( isMultisample && msaartcSupported ) {

gl.framebufferTexture2D( gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, glSubImage.depthStencilTexture, 0 );
if ( glSubImage.depthStencilTexture !== undefined ) {

}
msaaExt.framebufferTexture2DMultisampleEXT( gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, glSubImage.depthStencilTexture, 0, 4 );

}

msaaExt.framebufferTexture2DMultisampleEXT( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, glSubImage.colorTexture, 0, 4 );

} else {

gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, glSubImage.colorTexture, 0 );
if ( glSubImage.depthStencilTexture !== undefined ) {

gl.framebufferTexture2D( gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, glSubImage.depthStencilTexture, 0 );

}

gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, glSubImage.colorTexture, 0 );

}

viewport = glSubImage.viewport;

Expand All @@ -655,7 +675,7 @@ class WebXRManager extends EventDispatcher {

}

if ( isMultisample ) {
if ( isMultisample && ! msaartcSupported ) {

state.bindXRFramebuffer( glMultisampledFramebuffer );

Expand All @@ -680,7 +700,7 @@ class WebXRManager extends EventDispatcher {

if ( onAnimationFrameCallback ) onAnimationFrameCallback( time, frame );

if ( isMultisample ) {
if ( isMultisample && ! msaartcSupported ) {

const width = glProjLayer.textureWidth;
const height = glProjLayer.textureHeight;
Expand Down

0 comments on commit c789b20

Please sign in to comment.