Skip to content

Commit 089e36d

Browse files
authored
XRManager: Fix foveation. (#30417)
1 parent 99b02bb commit 089e36d

File tree

4 files changed

+32
-24
lines changed

4 files changed

+32
-24
lines changed

src/renderers/common/Textures.js

+2-11
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,9 @@ class Textures extends DataMap {
127127

128128
const options = { sampleCount };
129129

130-
// when using the WebXR Layers API, the render target uses external textures which
131-
// require no manual updates
130+
// XR render targets require no texture updates
132131

133-
if ( renderTarget.isXRRenderTarget === true && renderTarget.hasExternalTextures === true ) {
134-
135-
if ( depthTexture && renderTarget.autoAllocateDepthBuffer === true ) {
136-
137-
this.updateTexture( depthTexture, options );
138-
139-
}
140-
141-
} else {
132+
if ( renderTarget.isXRRenderTarget !== true ) {
142133

143134
for ( let i = 0; i < textures.length; i ++ ) {
144135

src/renderers/common/XRRenderTarget.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class XRRenderTarget extends RenderTarget {
4646
* Allocating a depth buffer is the default behavior of XR render
4747
* targets. However, when using the WebXR Layers API, this flag
4848
* must be set to `false` when the `ignoreDepthValues` property of
49-
* the projection layers evaluates to `true`.
49+
* the projection layers evaluates to `false`.
5050
*
5151
* Reference: {@link https://www.w3.org/TR/webxrlayers-1/#dom-xrprojectionlayer-ignoredepthvalues}.
5252
*

src/renderers/webgl-fallback/WebGLBackend.js

+26-10
Original file line numberDiff line numberDiff line change
@@ -1963,14 +1963,24 @@ class WebGLBackend extends Backend {
19631963

19641964
}
19651965

1966-
if ( descriptor.depthTexture !== null ) {
1966+
if ( renderTarget.isXRRenderTarget && renderTarget.autoAllocateDepthBuffer === true ) {
19671967

1968-
const textureData = this.get( descriptor.depthTexture );
1969-
const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
1970-
textureData.renderTarget = descriptor.renderTarget;
1971-
textureData.cacheKey = cacheKey; // required for copyTextureToTexture()
1968+
const renderbuffer = gl.createRenderbuffer();
1969+
this.textureUtils.setupRenderBufferStorage( renderbuffer, descriptor, 0 );
1970+
renderTargetContextData.xrDepthRenderbuffer = renderbuffer;
1971+
1972+
} else {
19721973

1973-
gl.framebufferTexture2D( gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, textureData.textureGPU, 0 );
1974+
if ( descriptor.depthTexture !== null ) {
1975+
1976+
const textureData = this.get( descriptor.depthTexture );
1977+
const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
1978+
textureData.renderTarget = descriptor.renderTarget;
1979+
textureData.cacheKey = cacheKey; // required for copyTextureToTexture()
1980+
1981+
gl.framebufferTexture2D( gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, textureData.textureGPU, 0 );
1982+
1983+
}
19741984

19751985
}
19761986

@@ -1989,11 +1999,17 @@ class WebGLBackend extends Backend {
19891999

19902000
// rebind depth
19912001

1992-
if ( descriptor.depthTexture !== null ) {
2002+
const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
19932003

1994-
const textureData = this.get( descriptor.depthTexture );
1995-
const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
2004+
if ( renderTarget.autoAllocateDepthBuffer === true ) {
2005+
2006+
const renderbuffer = renderTargetContextData.xrDepthRenderbuffer;
2007+
gl.bindRenderbuffer( gl.RENDERBUFFER, renderbuffer );
2008+
gl.framebufferRenderbuffer( gl.FRAMEBUFFER, depthStyle, gl.RENDERBUFFER, renderbuffer );
19962009

2010+
} else {
2011+
2012+
const textureData = this.get( descriptor.depthTexture );
19972013
gl.framebufferTexture2D( gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, textureData.textureGPU, 0 );
19982014

19992015
}
@@ -2046,7 +2062,7 @@ class WebGLBackend extends Backend {
20462062
if ( depthRenderbuffer === undefined ) {
20472063

20482064
depthRenderbuffer = gl.createRenderbuffer();
2049-
this.textureUtils.setupRenderBufferStorage( depthRenderbuffer, descriptor );
2065+
this.textureUtils.setupRenderBufferStorage( depthRenderbuffer, descriptor, samples );
20502066

20512067
renderTargetContextData.depthRenderbuffer = depthRenderbuffer;
20522068

src/renderers/webgl-fallback/utils/WebGLTextureUtils.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -917,13 +917,14 @@ class WebGLTextureUtils {
917917
*
918918
* @param {WebGLRenderbuffer} renderbuffer - The render buffer.
919919
* @param {RenderContext} renderContext - The render context.
920+
* @param {Number} samples - The MSAA sample count.
920921
*/
921-
setupRenderBufferStorage( renderbuffer, renderContext ) {
922+
setupRenderBufferStorage( renderbuffer, renderContext, samples ) {
922923

923924
const { gl } = this;
924925
const renderTarget = renderContext.renderTarget;
925926

926-
const { samples, depthTexture, depthBuffer, stencilBuffer, width, height } = renderTarget;
927+
const { depthTexture, depthBuffer, stencilBuffer, width, height } = renderTarget;
927928

928929
gl.bindRenderbuffer( gl.RENDERBUFFER, renderbuffer );
929930

0 commit comments

Comments
 (0)