Skip to content

Commit 99b02bb

Browse files
authored
WebGLBackend: Fix context parameter. (#30413)
* WebGLBackend: Fix context parameter. * WebGLBackend: Disable depth buffer of canvas.
1 parent 5077c09 commit 99b02bb

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/renderers/common/XRManager.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,6 @@ class XRManager extends EventDispatcher {
589589

590590
//
591591

592-
const attributes = gl.getContextAttributes();
593-
594592
if ( this._useLayers === true ) {
595593

596594
// default path using XRWebGLBinding/XRProjectionLayer
@@ -599,11 +597,11 @@ class XRManager extends EventDispatcher {
599597
let depthType = null;
600598
let glDepthFormat = null;
601599

602-
if ( attributes.depth ) {
600+
if ( renderer.depth ) {
603601

604-
glDepthFormat = attributes.stencil ? gl.DEPTH24_STENCIL8 : gl.DEPTH_COMPONENT24;
605-
depthFormat = attributes.stencil ? DepthStencilFormat : DepthFormat;
606-
depthType = attributes.stencil ? UnsignedInt248Type : UnsignedIntType;
602+
glDepthFormat = renderer.stencil ? gl.DEPTH24_STENCIL8 : gl.DEPTH_COMPONENT24;
603+
depthFormat = renderer.stencil ? DepthStencilFormat : DepthFormat;
604+
depthType = renderer.stencil ? UnsignedInt248Type : UnsignedIntType;
607605

608606
}
609607

@@ -632,8 +630,8 @@ class XRManager extends EventDispatcher {
632630
type: UnsignedByteType,
633631
colorSpace: renderer.outputColorSpace,
634632
depthTexture: new DepthTexture( glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, undefined, undefined, undefined, undefined, undefined, undefined, depthFormat ),
635-
stencilBuffer: attributes.stencil,
636-
samples: attributes.antialias ? 4 : 0
633+
stencilBuffer: renderer.stencil,
634+
samples: renderer.samples
637635
} );
638636

639637
this._xrRenderTarget.hasExternalTextures = true;
@@ -643,10 +641,10 @@ class XRManager extends EventDispatcher {
643641
// fallback to XRWebGLLayer
644642

645643
const layerInit = {
646-
antialias: attributes.antialias,
644+
antialias: renderer.samples > 0,
647645
alpha: true,
648-
depth: attributes.depth,
649-
stencil: attributes.stencil,
646+
depth: renderer.depth,
647+
stencil: renderer.stencil,
650648
framebufferScaleFactor: this.getFramebufferScaleFactor()
651649
};
652650

@@ -665,7 +663,7 @@ class XRManager extends EventDispatcher {
665663
format: RGBAFormat,
666664
type: UnsignedByteType,
667665
colorSpace: renderer.outputColorSpace,
668-
stencilBuffer: attributes.stencil
666+
stencilBuffer: renderer.stencil
669667
}
670668
);
671669

src/renderers/webgl-fallback/WebGLBackend.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,14 @@ class WebGLBackend extends Backend {
211211

212212
const parameters = this.parameters;
213213

214-
const glContext = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgl2' );
214+
const contextAttributes = {
215+
antialias: false, // MSAA is applied via a custom renderbuffer
216+
alpha: true, // always true for performance reasons
217+
depth: false, // depth and stencil are set to false since the engine always renders into a framebuffer target first
218+
stencil: false
219+
};
220+
221+
const glContext = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgl2', contextAttributes );
215222

216223
function onContextLost( event ) {
217224

0 commit comments

Comments
 (0)