Browse Source

Engine "features" are not static anymore

Popov72 4 years ago
parent
commit
f5c53645d2

+ 33 - 47
src/Engines/thinEngine.ts

@@ -172,31 +172,6 @@ export class ThinEngine {
     }
 
     /**
-     * Returns the features of the engine
-     */
-    public static Features: EngineFeatures = {
-        forceBitmapOverHTMLImageElement: false,
-        supportRenderAndCopyToLodForFloatTextures: false,
-        framebuffersHaveYTopToBottom: false,
-        supportDepthStencilTexture: false,
-        supportShadowSamplers: false,
-        uniformBufferHardCheckMatrix: false,
-        allowTexturePrefiltering: false,
-        trackUbosInFrame: false,
-        supportCSM: false,
-        basisNeedsPOT: false,
-        support3DTextures: false,
-        supportMultipleRenderTargets: false,
-        needTypeSuffixInShaderConstants: false,
-        supportMSAA: false,
-        supportSSAO2: false,
-        supportExtendedTextureFormats: false,
-        supportPrePassRenderer: false,
-        supportSwitchCaseInShader: false,
-        _collectUbosUpdatedInFrame: false,
-    };
-
-    /**
      * Returns a string describing the current engine
      */
     public get description(): string {
@@ -216,6 +191,13 @@ export class ThinEngine {
         return "WebGL";
     }
 
+    /**
+     * Returns the version of the engine
+     */
+    public get version(): number {
+        return this._webGLVersion;
+    }
+
     // Updatable statics so stick with vars here
 
     /**
@@ -330,6 +312,7 @@ export class ThinEngine {
     protected _hardwareScalingLevel: number;
     /** @hidden */
     public _caps: EngineCapabilities;
+    public _features: EngineFeatures;
     protected _isStencilEnable: boolean;
 
     private _glVersion: string;
@@ -761,21 +744,7 @@ export class ThinEngine {
 
         this._isStencilEnable = options.stencil ? true : false;
         this._initGLContext();
-
-        ThinEngine.Features.supportRenderAndCopyToLodForFloatTextures = this._webGLVersion !== 1;
-        ThinEngine.Features.supportDepthStencilTexture = this._webGLVersion !== 1;
-        ThinEngine.Features.supportShadowSamplers = this._webGLVersion !== 1;
-        ThinEngine.Features.allowTexturePrefiltering = this._webGLVersion !== 1;
-        ThinEngine.Features.supportCSM = this._webGLVersion !== 1;
-        ThinEngine.Features.basisNeedsPOT = this._webGLVersion === 1;
-        ThinEngine.Features.support3DTextures = this._webGLVersion !== 1;
-        ThinEngine.Features.supportMultipleRenderTargets = this._webGLVersion !== 1 || this.getCaps().drawBuffersExtension;
-        ThinEngine.Features.needTypeSuffixInShaderConstants = this._webGLVersion !== 1;
-        ThinEngine.Features.supportMSAA = this._webGLVersion !== 1;
-        ThinEngine.Features.supportSSAO2 = this._webGLVersion !== 1;
-        ThinEngine.Features.supportExtendedTextureFormats = this._webGLVersion !== 1;
-        ThinEngine.Features.supportPrePassRenderer = this._webGLVersion !== 1;
-        ThinEngine.Features.supportSwitchCaseInShader = this._webGLVersion !== 1;
+        this._initFeatures();
 
         // Prepare buffer pointers
         for (var i = 0; i < this._caps.maxVertexAttribs; i++) {
@@ -1088,6 +1057,30 @@ export class ThinEngine {
         }
     }
 
+    protected _initFeatures(): void {
+        this._features = {
+            forceBitmapOverHTMLImageElement: false,
+            supportRenderAndCopyToLodForFloatTextures: this._webGLVersion !== 1,
+            framebuffersHaveYTopToBottom: false,
+            supportDepthStencilTexture: this._webGLVersion !== 1,
+            supportShadowSamplers: this._webGLVersion !== 1,
+            uniformBufferHardCheckMatrix: false,
+            allowTexturePrefiltering: this._webGLVersion !== 1,
+            trackUbosInFrame: false,
+            supportCSM: this._webGLVersion !== 1,
+            basisNeedsPOT: this._webGLVersion === 1,
+            support3DTextures: this._webGLVersion !== 1,
+            supportMultipleRenderTargets: this._webGLVersion !== 1 || this.getCaps().drawBuffersExtension,
+            needTypeSuffixInShaderConstants: this._webGLVersion !== 1,
+            supportMSAA: this._webGLVersion !== 1,
+            supportSSAO2: this._webGLVersion !== 1,
+            supportExtendedTextureFormats: this._webGLVersion !== 1,
+            supportPrePassRenderer: this._webGLVersion !== 1,
+            supportSwitchCaseInShader: this._webGLVersion !== 1,
+            _collectUbosUpdatedInFrame: false,
+        };
+    }
+
     /**
      * Gets version of the current webGL context
      * Keep it for back compat - use version instead
@@ -1097,13 +1090,6 @@ export class ThinEngine {
     }
 
     /**
-     * Returns the version of the engine
-     */
-    public get version(): number {
-        return this._webGLVersion;
-    }
-
-    /**
      * Gets a string identifying the name of the class
      * @returns "Engine" string
      */

+ 24 - 22
src/Engines/webgpuEngine.ts

@@ -22,7 +22,7 @@ import { ShaderProcessingContext } from "./Processors/shaderProcessingOptions";
 import { WebGPUShaderProcessingContext } from "./WebGPU/webgpuShaderProcessingContext";
 import { Tools } from "../Misc/tools";
 import { WebGPUTextureHelper } from './WebGPU/webgpuTextureHelper';
-import { ISceneLike, ThinEngine } from './thinEngine';
+import { ISceneLike } from './thinEngine';
 import { Scene } from '../scene';
 import { WebGPUBufferManager } from './WebGPU/webgpuBufferManager';
 import { DepthTextureCreationOptions } from './depthTextureCreationOptions';
@@ -260,26 +260,6 @@ export class WebGPUEngine extends Engine {
     public constructor(canvas: HTMLCanvasElement, options: WebGPUEngineOptions = {}) {
         super(null);
 
-        ThinEngine.Features.forceBitmapOverHTMLImageElement = true;
-        ThinEngine.Features.supportRenderAndCopyToLodForFloatTextures = true;
-        ThinEngine.Features.framebuffersHaveYTopToBottom = true;
-        ThinEngine.Features.supportDepthStencilTexture = true;
-        ThinEngine.Features.supportShadowSamplers = true;
-        ThinEngine.Features.uniformBufferHardCheckMatrix = true;
-        ThinEngine.Features.allowTexturePrefiltering = true;
-        ThinEngine.Features.trackUbosInFrame = true;
-        ThinEngine.Features.supportCSM = true;
-        ThinEngine.Features.basisNeedsPOT = false;
-        ThinEngine.Features.support3DTextures = false; // TODO WEBGPU change to true when Chrome supports 3D textures
-        ThinEngine.Features.supportMultipleRenderTargets = true;
-        ThinEngine.Features.needTypeSuffixInShaderConstants = true;
-        ThinEngine.Features.supportMSAA = true;
-        ThinEngine.Features.supportSSAO2 = true;
-        ThinEngine.Features.supportExtendedTextureFormats = true;
-        ThinEngine.Features.supportPrePassRenderer = true;
-        ThinEngine.Features.supportSwitchCaseInShader = true;
-        ThinEngine.Features._collectUbosUpdatedInFrame = true;
-
         options.deviceDescriptor = options.deviceDescriptor || { };
         options.swapChainFormat = options.swapChainFormat || WebGPUConstants.TextureFormat.BGRA8Unorm;
         options.antialiasing = false; //options.antialiasing === undefined ? true : options.antialiasing;
@@ -475,6 +455,28 @@ export class WebGPUEngine extends Engine {
         };
 
         this._caps.parallelShaderCompile = null as any;
+
+        this._features = {
+            forceBitmapOverHTMLImageElement: true,
+            supportRenderAndCopyToLodForFloatTextures: true,
+            framebuffersHaveYTopToBottom: true,
+            supportDepthStencilTexture: true,
+            supportShadowSamplers: true,
+            uniformBufferHardCheckMatrix: true,
+            allowTexturePrefiltering: true,
+            trackUbosInFrame: true,
+            supportCSM: true,
+            basisNeedsPOT: false,
+            support3DTextures: false, // TODO WEBGPU change to true when Chrome supports 3D textures
+            supportMultipleRenderTargets: true,
+            needTypeSuffixInShaderConstants: true,
+            supportMSAA: true,
+            supportSSAO2: true,
+            supportExtendedTextureFormats: true,
+            supportPrePassRenderer: true,
+            supportSwitchCaseInShader: true,
+            _collectUbosUpdatedInFrame: true,
+        };
     }
 
     private _initializeContextAndSwapChain(): void {
@@ -2089,7 +2091,7 @@ export class WebGPUEngine extends Engine {
         this._textureHelper.destroyDeferredTextures();
         this._bufferManager.destroyDeferredBuffers();
 
-        if (ThinEngine.Features._collectUbosUpdatedInFrame) {
+        if (this._features._collectUbosUpdatedInFrame) {
             if (dbgVerboseLogsForFirstFrames) {
                 if (!(this as any)._count || (this as any)._count < dbgVerboseLogsNumFrames) {
                     const list: Array<string> = [];

+ 6 - 2
src/Lights/Shadows/cascadedShadowGenerator.ts

@@ -23,7 +23,7 @@ import { DepthRenderer } from '../../Rendering/depthRenderer';
 import { DepthReducer } from '../../Misc/depthReducer';
 
 import { Logger } from "../../Misc/logger";
-import { ThinEngine } from '../../Engines/thinEngine';
+import { EngineStore } from '../../Engines/engineStore';
 
 interface ICascade {
     prevBreakDistance: number;
@@ -693,7 +693,11 @@ export class CascadedShadowGenerator extends ShadowGenerator {
     *  Support test.
     */
     public static get IsSupported(): boolean {
-        return ThinEngine.Features.supportCSM;
+        var engine = EngineStore.LastCreatedEngine;
+        if (!engine) {
+            return false;
+        }
+        return engine._features.supportCSM;
     }
 
     /** @hidden */

+ 2 - 3
src/Lights/Shadows/shadowGenerator.ts

@@ -28,7 +28,6 @@ import { Observable } from '../../Misc/observable';
 import { _DevTools } from '../../Misc/devTools';
 import { EffectFallbacks } from '../../Materials/effectFallbacks';
 import { RenderingManager } from '../../Rendering/renderingManager';
-import { ThinEngine } from '../../Engines/thinEngine';
 
 const tmpMatrix = new Matrix(),
       tmpMatrix2 = new Matrix();
@@ -416,7 +415,7 @@ export class ShadowGenerator implements IShadowGenerator {
 
         // Weblg1 fallback for PCF.
         if (value === ShadowGenerator.FILTER_PCF || value === ShadowGenerator.FILTER_PCSS) {
-            if (!ThinEngine.Features.supportShadowSamplers) {
+            if (!this._scene.getEngine()._features.supportShadowSamplers) {
                 this.usePoissonSampling = true;
                 return;
             }
@@ -864,7 +863,7 @@ export class ShadowGenerator implements IShadowGenerator {
     }
 
     protected _createTargetRenderTexture(): void {
-        if (ThinEngine.Features.supportDepthStencilTexture) {
+        if (this._scene.getEngine()._features.supportDepthStencilTexture) {
             this._shadowMap = new RenderTargetTexture(this._light.name + "_shadowMap", this._mapSize, this._scene, false, true, this._textureType, this._light.needCube(), undefined, false, false);
             this._shadowMap.createDepthStencilTexture(Constants.LESS, true);
         }

+ 3 - 4
src/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.ts

@@ -30,7 +30,6 @@ import { SubSurfaceBlock } from './subSurfaceBlock';
 import { RefractionBlock } from './refractionBlock';
 import { PerturbNormalBlock } from '../Fragment/perturbNormalBlock';
 import { Constants } from '../../../../Engines/constants';
-import { ThinEngine } from '../../../../Engines/thinEngine';
 
 const mapOutputToVariable: { [name: string] : [string, string] } = {
     "ambient":      ["finalAmbient", ""],
@@ -618,7 +617,9 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
         defines.setValue("REALTIME_FILTERING", this.realTimeFiltering, true);
         defines.setValue("NUM_SAMPLES", "" + this.realTimeFilteringQuality, true);
 
-        if (ThinEngine.Features.needTypeSuffixInShaderConstants) {
+        const scene = mesh.getScene();
+
+        if (scene.getEngine()._features.needTypeSuffixInShaderConstants) {
             defines.setValue("NUM_SAMPLES", this.realTimeFilteringQuality + "u", true);
         }
 
@@ -642,8 +643,6 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
             return;
         }
 
-        const scene = mesh.getScene();
-
         if (!this.light) {
             // Lights
             MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, nodeMaterial.maxSimultaneousLights);

+ 1 - 2
src/Materials/PBR/pbrBaseMaterial.ts

@@ -41,7 +41,6 @@ import "../../Shaders/pbr.vertex";
 
 import { EffectFallbacks } from '../effectFallbacks';
 import { IMaterialDetailMapDefines, DetailMapConfiguration } from '../material.detailMapConfiguration';
-import { ThinEngine } from '../../Engines/thinEngine';
 
 declare type PrePassRenderer = import("../../Rendering/prePassRenderer").PrePassRenderer;
 
@@ -1389,7 +1388,7 @@ export abstract class PBRBaseMaterial extends PushMaterial {
 
                     if (this.realTimeFiltering && this.realTimeFilteringQuality > 0) {
                         defines.NUM_SAMPLES = "" + this.realTimeFilteringQuality;
-                        if (ThinEngine.Features.needTypeSuffixInShaderConstants) {
+                        if (engine._features.needTypeSuffixInShaderConstants) {
                             defines.NUM_SAMPLES = defines.NUM_SAMPLES + "u";
                         }
 

+ 1 - 1
src/Materials/Textures/Filtering/hdrFiltering.ts

@@ -197,7 +197,7 @@ export class HDRFiltering {
       * @return Promise called when prefiltering is done
       */
     public prefilter(texture: BaseTexture, onFinished: Nullable<() => void> = null) {
-        if (!ThinEngine.Features.allowTexturePrefiltering) {
+        if (!this._engine._features.allowTexturePrefiltering) {
             Logger.Warn("HDR prefiltering is not available in WebGL 1., you can use real time filtering instead.");
             return;
         }

+ 2 - 2
src/Materials/Textures/colorGradingTexture.ts

@@ -94,7 +94,7 @@ export class ColorGradingTexture extends BaseTexture {
     private load3dlTexture() {
         var engine = this._getEngine()!;
         var texture: InternalTexture;
-        if (!ThinEngine.Features.support3DTextures) {
+        if (!engine._features.support3DTextures) {
             texture = engine.createRawTexture(null, 1, 1, Constants.TEXTUREFORMAT_RGBA, false, false, Constants.TEXTURE_BILINEAR_SAMPLINGMODE, null, Constants.TEXTURETYPE_UNSIGNED_INT);
         }
         else {
@@ -105,7 +105,7 @@ export class ColorGradingTexture extends BaseTexture {
         this._texture.isReady = false;
 
         this.isCube = false;
-        this.is3D = ThinEngine.Features.support3DTextures;
+        this.is3D = engine._features.support3DTextures;
         this.wrapU = Constants.TEXTURE_CLAMP_ADDRESSMODE;
         this.wrapV = Constants.TEXTURE_CLAMP_ADDRESSMODE;
         this.wrapR = Constants.TEXTURE_CLAMP_ADDRESSMODE;

+ 1 - 1
src/Materials/Textures/hdrCubeTexture.ts

@@ -237,7 +237,7 @@ export class HDRCubeTexture extends BaseTexture {
             return results;
         };
 
-        if (ThinEngine.Features.allowTexturePrefiltering && this._prefilterOnLoad) {
+        if (engine._features.allowTexturePrefiltering && this._prefilterOnLoad) {
             const previousOnLoad = this._onLoad;
             const hdrFiltering = new HDRFiltering(engine);
             this._onLoad = () => {

+ 1 - 2
src/Materials/Textures/multiRenderTarget.ts

@@ -6,7 +6,6 @@ import { RenderTargetTexture } from "../../Materials/Textures/renderTargetTextur
 import { Constants } from "../../Engines/constants";
 
 import "../../Engines/Extensions/engine.multiRender";
-import { ThinEngine } from '../../Engines/thinEngine';
 
 /**
  * Creation options of the multi render target texture.
@@ -67,7 +66,7 @@ export class MultiRenderTarget extends RenderTargetTexture {
      * Get if draw buffers are currently supported by the used hardware and browser.
      */
     public get isSupported(): boolean {
-        return ThinEngine.Features.supportMultipleRenderTargets;
+        return this._engine?._features.supportMultipleRenderTargets ?? false;
     }
 
     /**

+ 8 - 9
src/Materials/uniformBuffer.ts

@@ -7,7 +7,6 @@ import { BaseTexture } from "../Materials/Textures/baseTexture";
 import { DataBuffer } from '../Meshes/dataBuffer';
 import { Color3 } from '../Maths/math.color';
 import { IMatrixLike } from '../Maths/math.like';
-import { ThinEngine } from '../Engines/thinEngine';
 
 import "../Engines/Extensions/engine.uniformBuffer";
 
@@ -212,7 +211,7 @@ export class UniformBuffer {
         this._uniformLocationPointer = 0;
         this._needSync = false;
 
-        if (ThinEngine.Features.trackUbosInFrame) {
+        if (this._engine._features.trackUbosInFrame) {
             this._buffers = [];
             this._bufferIndex = -1;
             this._createBufferOnWrite = false;
@@ -522,7 +521,7 @@ export class UniformBuffer {
             this._buffer = this._engine.createUniformBuffer(this._bufferData);
         }
 
-        if (ThinEngine.Features.trackUbosInFrame) {
+        if (this._engine._features.trackUbosInFrame) {
             this._buffers.push(this._buffer);
             this._bufferIndex = this._buffers.length - 1;
             this._createBufferOnWrite = false;
@@ -555,13 +554,13 @@ export class UniformBuffer {
         }
 
         if (!this._dynamic && !this._needSync) {
-            this._createBufferOnWrite = ThinEngine.Features.trackUbosInFrame;
+            this._createBufferOnWrite = this._engine._features.trackUbosInFrame;
             return;
         }
 
         this._engine.updateUniformBuffer(this._buffer, this._bufferData);
 
-        if (ThinEngine.Features._collectUbosUpdatedInFrame) {
+        if (this._engine._features._collectUbosUpdatedInFrame) {
             if (!UniformBuffer._updatedUbosInFrame[this._name]) {
                 UniformBuffer._updatedUbosInFrame[this._name] = 0;
             }
@@ -569,7 +568,7 @@ export class UniformBuffer {
         }
 
         this._needSync = false;
-        this._createBufferOnWrite = ThinEngine.Features.trackUbosInFrame;
+        this._createBufferOnWrite = this._engine._features.trackUbosInFrame;
     }
 
     private _createNewBuffer() {
@@ -587,7 +586,7 @@ export class UniformBuffer {
     }
 
     private _checkNewFrame(): void {
-        if (ThinEngine.Features.trackUbosInFrame && this._currentFrameId !== this._engine.frameId) {
+        if (this._engine._features.trackUbosInFrame && this._currentFrameId !== this._engine.frameId) {
             this._currentFrameId = this._engine.frameId;
             this._createBufferOnWrite = false;
             if (this._buffers && this._buffers.length > 0) {
@@ -632,7 +631,7 @@ export class UniformBuffer {
             var changed = false;
 
             for (var i = 0; i < size; i++) {
-                if ((size === 16 && !ThinEngine.Features.uniformBufferHardCheckMatrix) || this._bufferData[location + i] !== data[i]) {
+                if ((size === 16 && !this._engine._features.uniformBufferHardCheckMatrix) || this._bufferData[location + i] !== data[i]) {
                     changed = true;
                     if (this._createBufferOnWrite) {
                         this._createNewBuffer();
@@ -969,7 +968,7 @@ export class UniformBuffer {
             uniformBuffers.pop();
         }
 
-        if (ThinEngine.Features.trackUbosInFrame && this._buffers) {
+        if (this._engine._features.trackUbosInFrame && this._buffers) {
             for (let i = 0; i < this._buffers.length; ++i) {
                 const buffer = this._buffers[i];
                 this._engine._releaseBuffer(buffer!);

+ 2 - 3
src/Misc/basis.ts

@@ -5,7 +5,6 @@ import { InternalTexture, InternalTextureSource } from '../Materials/Textures/in
 import { Scalar } from '../Maths/math.scalar';
 import { Constants } from '../Engines/constants';
 import { Engine } from '../Engines/engine';
-import { ThinEngine } from '../Engines/thinEngine';
 
 /**
  * Info about the .basis files
@@ -196,7 +195,7 @@ export class BasisTools {
                 texture.type = Constants.TEXTURETYPE_UNSIGNED_SHORT_5_6_5;
                 texture.format = Constants.TEXTUREFORMAT_RGB;
 
-                if (ThinEngine.Features.basisNeedsPOT && (Scalar.Log2(rootImage.width) % 1 !== 0 || Scalar.Log2(rootImage.height) % 1 !== 0)) {
+                if (engine._features.basisNeedsPOT && (Scalar.Log2(rootImage.width) % 1 !== 0 || Scalar.Log2(rootImage.height) % 1 !== 0)) {
                     // Create non power of two texture
                     let source = new InternalTexture(engine, InternalTextureSource.Temp);
 
@@ -233,7 +232,7 @@ export class BasisTools {
                     engine._uploadCompressedDataToTextureDirectly(texture, BasisTools.GetInternalFormatFromBasisFormat(transcodeResult.format!), level.width, level.height, level.transcodedPixels, i, index);
                 });
 
-                if (ThinEngine.Features.basisNeedsPOT && (Scalar.Log2(texture.width) % 1 !== 0 || Scalar.Log2(texture.height) % 1 !== 0)) {
+                if (engine._features.basisNeedsPOT && (Scalar.Log2(texture.width) % 1 !== 0 || Scalar.Log2(texture.height) % 1 !== 0)) {
                     Tools.Warn("Loaded .basis texture width and height are not a power of two. Texture wrapping will be set to Texture.CLAMP_ADDRESSMODE as other modes are not supported with non power of two dimensions in webGL 1.");
                     texture._cachedWrapU = Texture.CLAMP_ADDRESSMODE;
                     texture._cachedWrapV = Texture.CLAMP_ADDRESSMODE;

+ 2 - 3
src/Misc/environmentTextureTools.ts

@@ -17,7 +17,6 @@ import "../Materials/Textures/baseTexture.polynomial";
 import "../Shaders/rgbdEncode.fragment";
 import "../Shaders/rgbdDecode.fragment";
 import { Engine } from '../Engines/engine';
-import { ThinEngine } from '../Engines/thinEngine';
 import { RGBDTextureTools } from './rgbdTextureTools';
 
 /**
@@ -425,7 +424,7 @@ export class EnvironmentTextureTools {
             lodTextures = {};
         }
         // in webgl 1 there are no ways to either render or copy lod level information for float textures.
-        else if (!ThinEngine.Features.supportRenderAndCopyToLodForFloatTextures) {
+        else if (!engine._features.supportRenderAndCopyToLodForFloatTextures) {
             expandTexture = false;
         }
         // If half float available we can uncompress the texture
@@ -514,7 +513,7 @@ export class EnvironmentTextureTools {
                 let url = URL.createObjectURL(blob);
                 let promise: Promise<void>;
 
-                if (typeof Image === "undefined" || ThinEngine.Features.forceBitmapOverHTMLImageElement) {
+                if (typeof Image === "undefined" || engine._features.forceBitmapOverHTMLImageElement) {
                     promise = createImageBitmap(blob, { premultiplyAlpha: "none" }).then((img) => {
                         return this._OnImageReadyAsync(img, engine, expandTexture, rgbdPostProcess, url, face, i, generateNonLODTextures, lodTextures, cubeRtt, texture);
                     });

+ 5 - 2
src/Misc/fileTools.ts

@@ -8,8 +8,9 @@ import { FilesInputStore } from './filesInputStore';
 import { RetryStrategy } from './retryStrategy';
 import { BaseError } from './baseError';
 import { StringTools } from './stringTools';
-import { ThinEngine } from '../Engines/thinEngine';
 import { ShaderProcessor } from '../Engines/Processors/shaderProcessor';
+import { ThinEngine } from '../Engines/thinEngine';
+import { EngineStore } from '../Engines/engineStore';
 
 /** @ignore */
 export class LoadFileError extends BaseError {
@@ -155,7 +156,9 @@ export class FileTools {
             url = FileTools.PreprocessUrl(input);
         }
 
-        if (typeof Image === "undefined" || ThinEngine.Features.forceBitmapOverHTMLImageElement) {
+        const engine = EngineStore.LastCreatedEngine;
+
+        if (typeof Image === "undefined" || (engine?._features.forceBitmapOverHTMLImageElement ?? false)) {
             FileTools.LoadFile(url, (data) => {
                 createImageBitmap(new Blob([data], { type: mimeType }), { premultiplyAlpha: "none" }).then((imgBmp) => {
                     onLoad(imgBmp);

+ 1 - 2
src/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.ts

@@ -20,7 +20,6 @@ import "../../../PostProcesses/RenderPipeline/postProcessRenderPipelineManagerSc
 
 import "../../../Shaders/ssao2.fragment";
 import "../../../Shaders/ssaoCombine.fragment";
-import { ThinEngine } from '../../../Engines/thinEngine';
 
 /**
  * Render pipeline to produce ssao effect
@@ -163,7 +162,7 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
         if (!engine) {
             return false;
         }
-        return ThinEngine.Features.supportSSAO2;
+        return engine._features.supportSSAO2;
     }
 
     private _scene: Scene;

+ 1 - 2
src/PostProcesses/RenderPipeline/postProcessRenderPipeline.ts

@@ -5,7 +5,6 @@ import { Camera } from "../../Cameras/camera";
 import { Engine } from "../../Engines/engine";
 import { PostProcessRenderEffect } from "./postProcessRenderEffect";
 import { IInspectable } from '../../Misc/iInspectable';
-import { ThinEngine } from '../../Engines/thinEngine';
 
 declare type PrePassRenderer = import("../../Rendering/prePassRenderer").PrePassRenderer;
 
@@ -216,7 +215,7 @@ export class PostProcessRenderPipeline {
     }
 
     protected _enableMSAAOnFirstPostProcess(sampleCount: number): boolean {
-        if (!ThinEngine.Features.supportMSAA) {
+        if (!this.engine._features.supportMSAA) {
             return false;
         }
 

+ 1 - 2
src/PostProcesses/screenSpaceCurvaturePostProcess.ts

@@ -11,7 +11,6 @@ import "../Shaders/screenSpaceCurvature.fragment";
 import { EngineStore } from '../Engines/engineStore';
 import { _TypeStore } from '../Misc/typeStore';
 import { serialize, SerializationHelper } from '../Misc/decorators';
-import { ThinEngine } from '../Engines/thinEngine';
 
 declare type Engine = import("../Engines/engine").Engine;
 declare type Scene = import("../scene").Scene;
@@ -83,7 +82,7 @@ export class ScreenSpaceCurvaturePostProcess extends PostProcess {
             return false;
         }
 
-        return ThinEngine.Features.supportMultipleRenderTargets;
+        return engine._features.supportMultipleRenderTargets;
     }
 
     /** @hidden */

+ 1 - 2
src/Rendering/depthRenderer.ts

@@ -15,7 +15,6 @@ import { Constants } from "../Engines/constants";
 import "../Shaders/depth.fragment";
 import "../Shaders/depth.vertex";
 import { _DevTools } from '../Misc/devTools';
-import { ThinEngine } from '../Engines/thinEngine';
 
 /**
  * This represents a depth renderer in Babylon.
@@ -73,7 +72,7 @@ export class DepthRenderer {
         var engine = scene.getEngine();
 
         // Render target
-        var format = (this.isPacked || !ThinEngine.Features.supportExtendedTextureFormats) ? Constants.TEXTUREFORMAT_RGBA : Constants.TEXTUREFORMAT_R;
+        var format = (this.isPacked || !engine._features.supportExtendedTextureFormats) ? Constants.TEXTUREFORMAT_RGBA : Constants.TEXTUREFORMAT_R;
         this._depthMap = new RenderTargetTexture("depthMap", { width: engine.getRenderWidth(), height: engine.getRenderHeight() }, this._scene, false, true, type,
             false, undefined, undefined, undefined, undefined,
             format);

+ 1 - 2
src/Rendering/prePassRenderer.ts

@@ -11,7 +11,6 @@ import { PrePassEffectConfiguration } from "./prePassEffectConfiguration";
 import { Nullable } from "../types";
 import { AbstractMesh } from '../Meshes/abstractMesh';
 import { Material } from '../Materials/material';
-import { ThinEngine } from '../Engines/thinEngine';
 
 /**
  * Renders a pre pass of the scene
@@ -165,7 +164,7 @@ export class PrePassRenderer {
      * Indicates if rendering a prepass is supported
      */
     public get isSupported() {
-        return ThinEngine.Features.supportPrePassRenderer;
+        return this._engine._features.supportPrePassRenderer;
     }
 
     /**

+ 1 - 2
src/Sprites/spriteMap.ts

@@ -13,7 +13,6 @@ import { Effect } from "../Materials/effect";
 import "../Meshes/Builders/planeBuilder";
 import "../Shaders/spriteMap.fragment";
 import "../Shaders/spriteMap.vertex";
-import { ThinEngine } from '../Engines/thinEngine';
 
 /**
  * Defines the basic options interface of a SpriteMap
@@ -227,7 +226,7 @@ export class SpriteMap implements ISpriteMap {
         let shaderString: string = Effect.ShadersStore["spriteMapPixelShader"];
 
         let layerSampleString: string;
-        if (!ThinEngine.Features.supportSwitchCaseInShader) {
+        if (!scene.getEngine()._features.supportSwitchCaseInShader) {
             layerSampleString = "";
             for (let i = 0; i < options.layerCount; i++) {
                 layerSampleString += `if (${i} == i) { frameID = texture2D(tileMaps[${i}], (tileID + 0.5) / stageSize, 0.).x; }`;