Skip to content

Commit aac046b

Browse files
committed
more cleanup + fixes for multiview
1 parent 1740aa0 commit aac046b

File tree

8 files changed

+30
-27
lines changed

8 files changed

+30
-27
lines changed

src/core/RenderTarget.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class RenderTarget extends EventDispatcher {
3535
* @property {?Texture} [depthTexture=null] - Reference to a depth texture.
3636
* @property {number} [samples=0] - The MSAA samples count.
3737
* @property {number} [count=1] - Defines the number of color attachments . Must be at least `1`.
38+
* @property {boolean} [multiview=false] - Whether this target is used for multiview rendering.
3839
*/
3940

4041
/**
@@ -119,7 +120,8 @@ class RenderTarget extends EventDispatcher {
119120
resolveStencilBuffer: true,
120121
depthTexture: null,
121122
samples: 0,
122-
count: 1
123+
count: 1,
124+
multiview: false
123125
}, options );
124126

125127
const texture = new Texture( image, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace );
@@ -189,6 +191,14 @@ class RenderTarget extends EventDispatcher {
189191
*/
190192
this.samples = options.samples;
191193

194+
/**
195+
* Whether to this target is used in multiview rendering.
196+
*
197+
* @type {boolean}
198+
* @default false
199+
*/
200+
this.multiview = options.multiview;
201+
192202
}
193203

194204
/**

src/renderers/common/Renderer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,7 @@ class Renderer {
12021202
frameBufferTarget.viewport.multiplyScalar( this._pixelRatio );
12031203
frameBufferTarget.scissor.multiplyScalar( this._pixelRatio );
12041204
frameBufferTarget.scissorTest = this._scissorTest;
1205+
frameBufferTarget.multiview = outputRenderTarget !== null ? outputRenderTarget.multiview : false;
12051206

12061207
return frameBufferTarget;
12071208

src/renderers/common/Textures.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Textures extends DataMap {
7777

7878
if ( depthTexture === undefined && useDepthTexture ) {
7979

80-
if ( size.depth > 1 ) {
80+
if ( renderTarget.multiview === true && size.depth > 1 ) {
8181

8282
depthTexture = new DepthArrayTexture();
8383

@@ -147,7 +147,7 @@ class Textures extends DataMap {
147147

148148
const texture = textures[ i ];
149149

150-
texture.isTextureArray = this.renderer.xr.useMultiview() === true && size.depth > 1;
150+
texture.isTextureArray = renderTarget.multiview === true && size.depth > 1;
151151
if ( textureNeedsUpdate ) texture.needsUpdate = true;
152152

153153
this.updateTexture( texture, options );

src/renderers/common/XRManager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,11 +901,11 @@ class XRManager extends EventDispatcher {
901901
samples: attributes.antialias ? 4 : 0,
902902
resolveDepthBuffer: ( glProjLayer.ignoreDepthValues === false ),
903903
resolveStencilBuffer: ( glProjLayer.ignoreDepthValues === false ),
904-
depth: this._useMultiview ? 2 : 1
904+
depth: this._useMultiview ? 2 : 1,
905+
multiview: this._useMultiview
905906
} );
906907

907908
this._xrRenderTarget.hasExternalTextures = true;
908-
this._xrRenderTarget.useMultiview = this._useMultiview;
909909
this._xrRenderTarget.depth = this._useMultiview ? 2 : 1;
910910

911911
this._referenceSpace = await session.requestReferenceSpace( this.getReferenceSpaceType() );

src/renderers/common/XRRenderTarget.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ class XRRenderTarget extends RenderTarget {
5555
*/
5656
this.autoAllocateDepthBuffer = true;
5757

58-
/**
59-
* Whether this render target is used with multiview rendering or not.
60-
*
61-
* @type {boolean}
62-
* @default false
63-
*/
64-
this.useMultiview = false;
65-
6658
}
6759

6860
copy( source ) {

src/renderers/common/nodes/Nodes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class Nodes extends DataMap {
202202
nodeBuilder.environmentNode = this.getEnvironmentNode( renderObject.scene );
203203
nodeBuilder.fogNode = this.getFogNode( renderObject.scene );
204204
nodeBuilder.clippingContext = renderObject.clippingContext;
205-
if ( this.renderer.xr.useMultiview() ) {
205+
if ( this.renderer.getRenderTarget() ? this.renderer.getRenderTarget().multiview : false ) {
206206

207207
nodeBuilder.enableMultiview();
208208

src/renderers/webgl-fallback/WebGLBackend.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class WebGLBackend extends Backend {
361361

362362
// The multisample_render_to_texture extension doesn't work properly if there
363363
// are midframe flushes and an external depth texture.
364-
if ( ( this.extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true ) && renderTarget.autoAllocateDepthBuffer === true && renderTarget.useMultiview === false ) {
364+
if ( ( this.extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true ) && renderTarget.autoAllocateDepthBuffer === true && renderTarget.multiview === false ) {
365365

366366
console.warn( 'THREE.WebGLBackend: Render-to-texture extension was disabled because an external texture was provided' );
367367

@@ -2062,7 +2062,7 @@ class WebGLBackend extends Backend {
20622062

20632063
} else {
20642064

2065-
if ( this.renderer.xr.useMultiview() ) {
2065+
if ( renderTarget.multiview ) {
20662066

20672067
multiviewExt.framebufferTextureMultisampleMultiviewOVR( gl.FRAMEBUFFER, attachment, textureData.textureGPU, 0, samples, 0, 2 );
20682068

@@ -2099,7 +2099,7 @@ class WebGLBackend extends Backend {
20992099
textureData.renderTarget = descriptor.renderTarget;
21002100
textureData.cacheKey = cacheKey; // required for copyTextureToTexture()
21012101

2102-
if ( this.renderer.xr.useMultiview() ) {
2102+
if ( renderTarget.multiview ) {
21032103

21042104
multiviewExt.framebufferTextureMultisampleMultiviewOVR( gl.FRAMEBUFFER, depthStyle, textureData.textureGPU, 0, samples, 0, 2 );
21052105

@@ -2151,15 +2151,15 @@ class WebGLBackend extends Backend {
21512151

21522152
// rebind external XR textures
21532153

2154-
if ( ( isXRRenderTarget && hasExternalTextures ) || this.renderer.xr.useMultiview() ) {
2154+
if ( ( isXRRenderTarget && hasExternalTextures ) || renderTarget.multiview ) {
21552155

21562156
state.bindFramebuffer( gl.FRAMEBUFFER, fb );
21572157

21582158
// rebind color
21592159

21602160
const textureData = this.get( descriptor.textures[ 0 ] );
21612161

2162-
if ( this.renderer.xr.useMultiview() ) {
2162+
if ( renderTarget.multiview ) {
21632163

21642164
multiviewExt.framebufferTextureMultisampleMultiviewOVR( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, textureData.textureGPU, 0, samples, 0, 2 );
21652165

@@ -2187,7 +2187,7 @@ class WebGLBackend extends Backend {
21872187

21882188
const textureData = this.get( descriptor.depthTexture );
21892189

2190-
if ( this.renderer.xr.useMultiview() ) {
2190+
if ( renderTarget.multiview ) {
21912191

21922192
multiviewExt.framebufferTextureMultisampleMultiviewOVR( gl.FRAMEBUFFER, depthStyle, textureData.textureGPU, 0, samples, 0, 2 );
21932193

@@ -2207,7 +2207,7 @@ class WebGLBackend extends Backend {
22072207

22082208
}
22092209

2210-
if ( samples > 0 && useMultisampledRTT === false && ! this.renderer.xr.useMultiview() ) {
2210+
if ( samples > 0 && useMultisampledRTT === false && ! renderTarget.multiview ) {
22112211

22122212
if ( msaaFb === undefined ) {
22132213

@@ -2502,7 +2502,7 @@ class WebGLBackend extends Backend {
25022502
*/
25032503
_useMultisampledExtension( renderTarget ) {
25042504

2505-
if ( renderTarget.useMultiview === true ) {
2505+
if ( renderTarget.multiview === true ) {
25062506

25072507
return true;
25082508

src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,11 @@ ${ flowData.code }
557557

558558
}
559559

560-
if ( texture.compareFunction ) {
560+
if ( uniform.type === 'texture3D' && texture.isTextureArray === false ) {
561+
562+
snippet = `${typePrefix}sampler3D ${ uniform.name };`;
563+
564+
} else if ( texture.compareFunction ) {
561565

562566
if ( texture.isDepthArrayTexture === true ) {
563567

@@ -569,10 +573,6 @@ ${ flowData.code }
569573

570574
}
571575

572-
} else if ( uniform.type === 'texture3D' && texture.isTextureArray === false ) {
573-
574-
snippet = `${typePrefix}sampler3D ${ uniform.name };`;
575-
576576
} else if ( texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true || texture.isTextureArray === true ) {
577577

578578
snippet = `${typePrefix}sampler2DArray ${ uniform.name };`;

0 commit comments

Comments
 (0)