Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for EXT_multisampled_render_to_texture extension and use it for WebXR #22550

Merged
merged 1 commit into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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