Skip to content

Commit

Permalink
WebGLBackend: Fix context parameter. (#30413)
Browse files Browse the repository at this point in the history
* WebGLBackend: Fix context parameter.

* WebGLBackend: Disable depth buffer of canvas.
  • Loading branch information
Mugen87 authored Jan 28, 2025
1 parent 5077c09 commit 99b02bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
22 changes: 10 additions & 12 deletions src/renderers/common/XRManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,6 @@ class XRManager extends EventDispatcher {

//

const attributes = gl.getContextAttributes();

if ( this._useLayers === true ) {

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

if ( attributes.depth ) {
if ( renderer.depth ) {

glDepthFormat = attributes.stencil ? gl.DEPTH24_STENCIL8 : gl.DEPTH_COMPONENT24;
depthFormat = attributes.stencil ? DepthStencilFormat : DepthFormat;
depthType = attributes.stencil ? UnsignedInt248Type : UnsignedIntType;
glDepthFormat = renderer.stencil ? gl.DEPTH24_STENCIL8 : gl.DEPTH_COMPONENT24;
depthFormat = renderer.stencil ? DepthStencilFormat : DepthFormat;
depthType = renderer.stencil ? UnsignedInt248Type : UnsignedIntType;

}

Expand Down Expand Up @@ -632,8 +630,8 @@ class XRManager extends EventDispatcher {
type: UnsignedByteType,
colorSpace: renderer.outputColorSpace,
depthTexture: new DepthTexture( glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, undefined, undefined, undefined, undefined, undefined, undefined, depthFormat ),
stencilBuffer: attributes.stencil,
samples: attributes.antialias ? 4 : 0
stencilBuffer: renderer.stencil,
samples: renderer.samples
} );

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

const layerInit = {
antialias: attributes.antialias,
antialias: renderer.samples > 0,
alpha: true,
depth: attributes.depth,
stencil: attributes.stencil,
depth: renderer.depth,
stencil: renderer.stencil,
framebufferScaleFactor: this.getFramebufferScaleFactor()
};

Expand All @@ -665,7 +663,7 @@ class XRManager extends EventDispatcher {
format: RGBAFormat,
type: UnsignedByteType,
colorSpace: renderer.outputColorSpace,
stencilBuffer: attributes.stencil
stencilBuffer: renderer.stencil
}
);

Expand Down
9 changes: 8 additions & 1 deletion src/renderers/webgl-fallback/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,14 @@ class WebGLBackend extends Backend {

const parameters = this.parameters;

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

const glContext = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgl2', contextAttributes );

function onContextLost( event ) {

Expand Down

0 comments on commit 99b02bb

Please sign in to comment.