@@ -264,6 +264,7 @@ class WebGLBackend extends Backend {
264264 this . extensions . get ( 'WEBGL_multisampled_render_to_texture' ) ;
265265 this . extensions . get ( 'WEBGL_render_shared_exponent' ) ;
266266 this . extensions . get ( 'WEBGL_multi_draw' ) ;
267+ this . extensions . get ( 'OVR_multiview2' ) ;
267268
268269 this . disjoint = this . extensions . get ( 'EXT_disjoint_timer_query_webgl2' ) ;
269270 this . parallel = this . extensions . get ( 'KHR_parallel_shader_compile' ) ;
@@ -360,7 +361,7 @@ class WebGLBackend extends Backend {
360361
361362 // The multisample_render_to_texture extension doesn't work properly if there
362363 // are midframe flushes and an external depth texture.
363- if ( ( this . extensions . has ( 'WEBGL_multisampled_render_to_texture' ) === true ) && renderTarget . autoAllocateDepthBuffer ) {
364+ if ( ( this . extensions . has ( 'WEBGL_multisampled_render_to_texture' ) === true ) && renderTarget . autoAllocateDepthBuffer && ! renderTarget . usesMultiview ) {
364365
365366 console . warn ( 'THREE.WebGLBackend: Render-to-texture extension was disabled because an external texture was provided' ) ;
366367
@@ -547,7 +548,7 @@ class WebGLBackend extends Backend {
547548
548549 const { samples } = renderContext . renderTarget ;
549550
550- if ( samples > 0 && this . _useMultisampledRTT ( renderContext . renderTarget ) === false ) {
551+ if ( samples > 0 && this . _usesMultisampledExtension ( renderContext . renderTarget ) === false ) {
551552
552553 const fb = renderTargetContextData . framebuffers [ renderContext . getCacheKey ( ) ] ;
553554
@@ -1142,7 +1143,7 @@ class WebGLBackend extends Backend {
11421143
11431144 } ;
11441145
1145- if ( renderObject . camera . isArrayCamera && renderObject . camera . cameras . length > 0 ) {
1146+ if ( renderObject . camera . isArrayCamera && renderObject . camera . cameras . length > 0 && ! renderObject . camera . isMultiViewCamera ) {
11461147
11471148 const cameraData = this . get ( renderObject . camera ) ;
11481149 const cameras = renderObject . camera . cameras ;
@@ -1998,7 +1999,8 @@ class WebGLBackend extends Backend {
19981999 let msaaFb = renderTargetContextData . msaaFrameBuffer ;
19992000 let depthRenderbuffer = renderTargetContextData . depthRenderbuffer ;
20002001 const multisampledRTTExt = this . extensions . get ( 'WEBGL_multisampled_render_to_texture' ) ;
2001- const useMultisampledRTT = this . _useMultisampledRTT ( renderTarget ) ;
2002+ const multiviewExt = this . extensions . get ( 'OVR_multiview2' ) ;
2003+ const useMultisampledRTT = this . _usesMultisampledExtension ( renderTarget ) ;
20022004
20032005 const cacheKey = getCacheKey ( descriptor ) ;
20042006
@@ -2061,7 +2063,11 @@ class WebGLBackend extends Backend {
20612063
20622064 } else {
20632065
2064- if ( hasExternalTextures && useMultisampledRTT ) {
2066+ if ( hasExternalTextures && this . renderer . xr . usesMultiview ( ) ) {
2067+
2068+ multiviewExt . framebufferTextureMultisampleMultiviewOVR ( gl . FRAMEBUFFER , attachment , textureData . textureGPU , 0 , samples , 0 , 2 ) ;
2069+
2070+ } else if ( hasExternalTextures && useMultisampledRTT ) {
20652071
20662072 multisampledRTTExt . framebufferTexture2DMultisampleEXT ( gl . FRAMEBUFFER , attachment , gl . TEXTURE_2D , textureData . textureGPU , 0 , samples ) ;
20672073
@@ -2094,7 +2100,11 @@ class WebGLBackend extends Backend {
20942100 textureData . renderTarget = descriptor . renderTarget ;
20952101 textureData . cacheKey = cacheKey ; // required for copyTextureToTexture()
20962102
2097- if ( hasExternalTextures && useMultisampledRTT ) {
2103+ if ( hasExternalTextures && this . renderer . xr . usesMultiview ( ) ) {
2104+
2105+ multiviewExt . framebufferTextureMultisampleMultiviewOVR ( gl . FRAMEBUFFER , depthStyle , textureData . textureGPU , 0 , samples , 0 , 2 ) ;
2106+
2107+ } else if ( hasExternalTextures && useMultisampledRTT ) {
20982108
20992109 multisampledRTTExt . framebufferTexture2DMultisampleEXT ( gl . FRAMEBUFFER , depthStyle , gl . TEXTURE_2D , textureData . textureGPU , 0 , samples ) ;
21002110
@@ -2151,7 +2161,11 @@ class WebGLBackend extends Backend {
21512161
21522162 const textureData = this . get ( descriptor . textures [ 0 ] ) ;
21532163
2154- if ( useMultisampledRTT ) {
2164+ if ( this . renderer . xr . usesMultiview ( ) ) {
2165+
2166+ multiviewExt . framebufferTextureMultisampleMultiviewOVR ( gl . FRAMEBUFFER , gl . COLOR_ATTACHMENT0 , textureData . textureGPU , 0 , samples , 0 , 2 ) ;
2167+
2168+ } else if ( useMultisampledRTT ) {
21552169
21562170 multisampledRTTExt . framebufferTexture2DMultisampleEXT ( gl . FRAMEBUFFER , gl . COLOR_ATTACHMENT0 , gl . TEXTURE_2D , textureData . textureGPU , 0 , samples ) ;
21572171
@@ -2175,7 +2189,11 @@ class WebGLBackend extends Backend {
21752189
21762190 const textureData = this . get ( descriptor . depthTexture ) ;
21772191
2178- if ( useMultisampledRTT ) {
2192+ if ( this . renderer . xr . usesMultiview ( ) ) {
2193+
2194+ multiviewExt . framebufferTextureMultisampleMultiviewOVR ( gl . FRAMEBUFFER , depthStyle , textureData . textureGPU , 0 , samples , 0 , 2 ) ;
2195+
2196+ } else if ( useMultisampledRTT ) {
21792197
21802198 multisampledRTTExt . framebufferTexture2DMultisampleEXT ( gl . FRAMEBUFFER , depthStyle , gl . TEXTURE_2D , textureData . textureGPU , 0 , samples ) ;
21812199
@@ -2191,7 +2209,7 @@ class WebGLBackend extends Backend {
21912209
21922210 }
21932211
2194- if ( samples > 0 && useMultisampledRTT === false ) {
2212+ if ( samples > 0 && useMultisampledRTT === false && ! this . renderer . xr . usesMultiview ) {
21952213
21962214 if ( msaaFb === undefined ) {
21972215
@@ -2484,7 +2502,13 @@ class WebGLBackend extends Backend {
24842502 * @param {RenderTarget } renderTarget - The render target that should be multisampled.
24852503 * @return {boolean } Whether to use the `WEBGL_multisampled_render_to_texture` extension for MSAA or not.
24862504 */
2487- _useMultisampledRTT ( renderTarget ) {
2505+ _usesMultisampledExtension ( renderTarget ) {
2506+
2507+ if ( renderTarget . usesMultiview ) {
2508+
2509+ return true ;
2510+
2511+ }
24882512
24892513 return renderTarget . samples > 0 && this . extensions . has ( 'WEBGL_multisampled_render_to_texture' ) === true && renderTarget . autoAllocateDepthBuffer !== false ;
24902514
0 commit comments