From a5d90259a826a4e9805c34117bdb64ffd14ea7df Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 11 Oct 2024 19:38:20 -0700 Subject: [PATCH] WebGL 2: Add workaround for new Safari bug that breaks noclip Also remove workaround for EXT_clip_control now that Chrome has fixed its issues. --- src/gfx/platform/GfxPlatformWebGL2.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/gfx/platform/GfxPlatformWebGL2.ts b/src/gfx/platform/GfxPlatformWebGL2.ts index d36f7a27a..fe49a26ce 100644 --- a/src/gfx/platform/GfxPlatformWebGL2.ts +++ b/src/gfx/platform/GfxPlatformWebGL2.ts @@ -491,6 +491,7 @@ class GfxImplP_GL implements GfxSwapChain, GfxDevice { // GfxLimits private _uniformBufferMaxPageByteSize: number; + private _invalidateFramebufferBroken: boolean = false; public uniformBufferWordAlignment: number; public uniformBufferMaxPageWordSize: number; public supportedSampleCounts: number[]; @@ -503,9 +504,7 @@ class GfxImplP_GL implements GfxSwapChain, GfxDevice { this._WEBGL_compressed_texture_s3tc = gl.getExtension('WEBGL_compressed_texture_s3tc'); this._WEBGL_compressed_texture_s3tc_srgb = gl.getExtension('WEBGL_compressed_texture_s3tc_srgb'); - // https://github.com/magcius/noclip.website/issues/683 - // https://issues.chromium.org/issues/347197920 - // this._EXT_clip_control = gl.getExtension('EXT_clip_control'); + this._EXT_clip_control = gl.getExtension('EXT_clip_control'); this._EXT_texture_compression_rgtc = gl.getExtension('EXT_texture_compression_rgtc'); this._EXT_texture_filter_anisotropic = gl.getExtension('EXT_texture_filter_anisotropic'); this._EXT_texture_norm16 = gl.getExtension('EXT_texture_norm16'); @@ -605,12 +604,22 @@ class GfxImplP_GL implements GfxSwapChain, GfxDevice { } private _checkForBugQuirks(): void { + const gl = this.gl; + if (navigator.userAgent.includes('Firefox')) { // TODO(jstpierre): File Bugzilla bug, check Firefox version. // getQueryParameter on Firefox causes a full GL command buffer sync // (verified with private correspondence with Kelsey Gilbert). this.occlusionQueriesRecommended = false; } + + const WEBGL_debug_renderer_info = gl.getExtension('WEBGL_debug_renderer_info'); + if (WEBGL_debug_renderer_info !== null) { + const vendor = gl.getParameter(WEBGL_debug_renderer_info.UNMASKED_VENDOR_WEBGL); + // https://bugs.webkit.org/show_bug.cgi?id=280799 + if (vendor === "Apple Inc.") + this._invalidateFramebufferBroken = true; + } } //#region GfxSwapChain @@ -2392,7 +2401,7 @@ class GfxImplP_GL implements GfxSwapChain, GfxDevice { gl.blitFramebuffer(0, 0, colorResolveFrom.width, colorResolveFrom.height, 0, 0, colorResolveTo.width, colorResolveTo.height, gl.COLOR_BUFFER_BIT, gl.LINEAR); } - if (!colorStore) + if (!colorStore && !this._invalidateFramebufferBroken) gl.invalidateFramebuffer(gl.READ_FRAMEBUFFER, [gl.COLOR_ATTACHMENT0]); if (boundReadFB) @@ -2426,7 +2435,7 @@ class GfxImplP_GL implements GfxSwapChain, GfxDevice { gl.blitFramebuffer(0, 0, depthStencilResolveFrom.width, depthStencilResolveFrom.height, 0, 0, depthStencilResolveTo.width, depthStencilResolveTo.height, gl.DEPTH_BUFFER_BIT, gl.NEAREST); } - if (!depthStencilStore) + if (!depthStencilStore && !this._invalidateFramebufferBroken) gl.invalidateFramebuffer(gl.READ_FRAMEBUFFER, [gl.DEPTH_STENCIL_ATTACHMENT]); if (boundReadFB)