Browse Source

Remove all webGLVersion occurrences outside the webgl engine

Popov72 4 năm trước cách đây
mục cha
commit
735da80db4

+ 1 - 1
inspector/src/components/actionTabs/tabs/propertyGrids/materials/textures/propertiesBar.tsx

@@ -84,7 +84,7 @@ export class PropertiesBar extends React.PureComponent<IPropertiesBarProps,IProp
         const {mipLevel, setMipLevel, pixelData, resizeTexture, texture, face, setFace, saveTexture, resetTexture, uploadTexture} = this.props;
         const maxLevels = Math.floor(Math.log2(Math.max(texture.getSize().width, texture.getSize().height)));
         const engine = texture.getScene()!.getEngine();
-        const mipsEnabled = (!texture.noMipmap && (engine.webGLVersion == 2 || engine._gl.getExtension('EXT_shader_texture_lod')));
+        const mipsEnabled = (!texture.noMipmap && engine.getCaps().textureLOD);
         return <div id='properties'>
                 <div className='tab' id='logo-tab'>
                     <img className='icon' src={this._babylonLogo}/>

+ 1 - 1
inspector/src/components/actionTabs/tabs/statisticsTabComponent.tsx

@@ -102,7 +102,7 @@ export class StatisticsTabComponent extends PaneComponent {
                 <LineContainerComponent globalState={this.props.globalState} title="SYSTEM INFO">
                     <TextLineComponent label="Resolution" value={engine.getRenderWidth() + "x" + engine.getRenderHeight()} />
                     <TextLineComponent label="Hardware scaling level" value={engine.getHardwareScalingLevel().toString()} />
-                    <TextLineComponent label="WebGL version" value={engine.webGLVersion.toString()} />
+                    <TextLineComponent label="Engine" value={engine.description} />
                     <BooleanLineComponent label="Std derivatives" value={caps.standardDerivatives} />
                     <BooleanLineComponent label="Compressed textures" value={caps.s3tc !== undefined} />
                     <BooleanLineComponent label="Hardware instances" value={caps.instancedArrays} />

+ 2 - 1
inspector/src/components/sceneExplorer/sceneExplorerComponent.tsx

@@ -26,6 +26,7 @@ import { StandardMaterial } from 'babylonjs/Materials/standardMaterial';
 import { PBRMaterial } from 'babylonjs/Materials/PBR/pbrMaterial';
 import { SpriteManager } from 'babylonjs/Sprites/spriteManager';
 import { TargetCamera } from 'babylonjs/Cameras/targetCamera';
+import { ThinEngine } from 'babylonjs/Engines/thinEngine';
 
 require("./sceneExplorer.scss");
 
@@ -291,7 +292,7 @@ export class SceneExplorerComponent extends React.Component<ISceneExplorerCompon
                 });
             }
 
-            if (scene.getEngine().webGLVersion > 1 && !pipelines.some(p => p.getClassName() === "SSAORenderingPipeline")) {
+            if (ThinEngine.Features.supportMultipleRenderTargets && !pipelines.some(p => p.getClassName() === "SSAORenderingPipeline")) {
                 pipelineContextMenus.push({
                     label: "Add new SSAO2 Rendering Pipeline",
                     action: () => {

+ 22 - 0
src/Engines/engineFeatures.ts

@@ -1,3 +1,4 @@
+/** @hidden */
 export interface EngineFeatures {
     /** Force using Bitmap when Bitmap or HTMLImageElement can be used */
     forceBitmapOverHTMLImageElement: boolean;
@@ -32,6 +33,27 @@ export interface EngineFeatures {
     /** Indicates that the engine supports 3D textures */
     support3DTextures: boolean;
 
+    /** Indicates that the engine supports rendering to multiple render targets */
+    supportMultipleRenderTargets: boolean;
+
+    /** Indicates that constants need a type suffix in shaders (used by realtime filtering...) */
+    needTypeSuffixInShaderConstants: boolean;
+
+    /** Indicates that MSAA is supported */
+    supportMSAA: boolean;
+
+    /** Indicates that SSAO2 is supported */
+    supportSSAO2: boolean;
+
+    /** Indicates that some additional texture formats are supported (like TEXTUREFORMAT_R for eg) */
+    supportExtendedTextureFormats: boolean;
+
+    /** Indicates that the pre-pass renderer can be used */
+    supportPrePassRenderer: boolean;
+
+    /** Indicates that the switch/case construct is supported in shaders */
+    supportSwitchCaseInShader: boolean;
+
     /** @hidden */
     _collectUbosUpdatedInFrame: boolean;
 }

+ 38 - 9
src/Engines/thinEngine.ts

@@ -186,6 +186,13 @@ export class ThinEngine {
         supportCSM: false,
         basisNeedsPOT: false,
         support3DTextures: false,
+        supportMultipleRenderTargets: false,
+        needTypeSuffixInShaderConstants: false,
+        supportMSAA: false,
+        supportSSAO2: false,
+        supportExtendedTextureFormats: false,
+        supportPrePassRenderer: false,
+        supportSwitchCaseInShader: false,
         _collectUbosUpdatedInFrame: false,
     };
 
@@ -193,7 +200,7 @@ export class ThinEngine {
      * Returns a string describing the current engine
      */
     public get description(): string {
-        let description = "WebGL" + this.webGLVersion;
+        let description = this.name + this.webGLVersion;
 
         if (this._caps.parallelShaderCompile) {
             description += " - Parallel shader compilation";
@@ -202,6 +209,13 @@ export class ThinEngine {
         return description;
     }
 
+    /**
+     * Returns the name of the engine
+     */
+    public get name(): string {
+        return "WebGL";
+    }
+
     // Updatable statics so stick with vars here
 
     /**
@@ -731,14 +745,6 @@ export class ThinEngine {
             }
         }
 
-        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;
-
         // Ensures a consistent color space unpacking of textures cross browser.
         this._gl.pixelStorei(this._gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, this._gl.NONE);
 
@@ -756,6 +762,21 @@ 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;
+
         // Prepare buffer pointers
         for (var i = 0; i < this._caps.maxVertexAttribs; i++) {
             this._currentBufferPointers[i] = new BufferPointer();
@@ -1069,12 +1090,20 @@ export class ThinEngine {
 
     /**
      * Gets version of the current webGL context
+     * Keep it for back compat - use version instead
      */
     public get webGLVersion(): number {
         return this._webGLVersion;
     }
 
     /**
+     * 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
      */

+ 30 - 0
src/Engines/webgpuEngine.ts

@@ -230,6 +230,29 @@ export class WebGPUEngine extends Engine {
     }
 
     /**
+     * Returns the name of the engine
+     */
+    public get name(): string {
+        return "WebGPU";
+    }
+
+    /**
+     * Returns a string describing the current engine
+     */
+    public get description(): string {
+        let description = this.name + this.version;
+
+        return description;
+    }
+
+    /**
+     * Returns the version of the engine
+     */
+    public get version(): number {
+        return 1;
+    }
+
+    /**
      * Create a new instance of the gpu engine.
      * @param canvas Defines the canvas to use to display the result
      * @param options Defines the options passed to the engine to create the GPU context dependencies
@@ -248,6 +271,13 @@ export class WebGPUEngine extends Engine {
         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 || { };

+ 2 - 1
src/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.ts

@@ -30,6 +30,7 @@ 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", ""],
@@ -617,7 +618,7 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
         defines.setValue("REALTIME_FILTERING", this.realTimeFiltering, true);
         defines.setValue("NUM_SAMPLES", "" + this.realTimeFilteringQuality, true);
 
-        if (this._scene.getEngine().webGLVersion > 1) {
+        if (ThinEngine.Features.needTypeSuffixInShaderConstants) {
             defines.setValue("NUM_SAMPLES", this.realTimeFilteringQuality + "u", true);
         }
 

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

@@ -41,6 +41,7 @@ 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;
 
@@ -1388,7 +1389,7 @@ export abstract class PBRBaseMaterial extends PushMaterial {
 
                     if (this.realTimeFiltering && this.realTimeFilteringQuality > 0) {
                         defines.NUM_SAMPLES = "" + this.realTimeFilteringQuality;
-                        if (engine.webGLVersion > 1) {
+                        if (ThinEngine.Features.needTypeSuffixInShaderConstants) {
                             defines.NUM_SAMPLES = defines.NUM_SAMPLES + "u";
                         }
 

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

@@ -6,6 +6,7 @@ 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.
@@ -66,7 +67,7 @@ export class MultiRenderTarget extends RenderTargetTexture {
      * Get if draw buffers are currently supported by the used hardware and browser.
      */
     public get isSupported(): boolean {
-        return this._getEngine()!.webGLVersion > 1 || this._getEngine()!.getCaps().drawBuffersExtension;
+        return ThinEngine.Features.supportMultipleRenderTargets;
     }
 
     /**

+ 1 - 1
src/Materials/effect.ts

@@ -311,7 +311,7 @@ export class Effect implements IDisposable {
             supportsUniformBuffers: this._engine.supportsUniformBuffers,
             shadersRepository: Effect.ShadersRepository,
             includesShadersStore: Effect.IncludesShadersStore,
-            version: (this._engine.webGLVersion * 100).toString(),
+            version: (this._engine.version * 100).toString(),
             platformName: this._engine.shaderPlatformName,
             processingContext: this._processingContext
         };

+ 1 - 1
src/Particles/gpuParticleSystem.ts

@@ -83,7 +83,7 @@ export class GPUParticleSystem extends BaseParticleSystem implements IDisposable
         if (!EngineStore.LastCreatedEngine) {
             return false;
         }
-        return EngineStore.LastCreatedEngine.webGLVersion > 1;
+        return EngineStore.LastCreatedEngine.name === "WebGL" && EngineStore.LastCreatedEngine.version > 1;
     }
 
     /**

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

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

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

@@ -5,6 +5,7 @@ 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;
 
@@ -215,7 +216,7 @@ export class PostProcessRenderPipeline {
     }
 
     protected _enableMSAAOnFirstPostProcess(sampleCount: number): boolean {
-        if (this.engine.webGLVersion === 1) {
+        if (!ThinEngine.Features.supportMSAA) {
             return false;
         }
 

+ 2 - 1
src/PostProcesses/screenSpaceCurvaturePostProcess.ts

@@ -11,6 +11,7 @@ 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;
@@ -82,7 +83,7 @@ export class ScreenSpaceCurvaturePostProcess extends PostProcess {
             return false;
         }
 
-        return engine.webGLVersion > 1 || engine.getCaps().drawBuffersExtension;
+        return ThinEngine.Features.supportMultipleRenderTargets;
     }
 
     /** @hidden */

+ 2 - 1
src/Rendering/depthRenderer.ts

@@ -15,6 +15,7 @@ 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.
@@ -72,7 +73,7 @@ export class DepthRenderer {
         var engine = scene.getEngine();
 
         // Render target
-        var format = (this.isPacked || engine.webGLVersion === 1) ? Constants.TEXTUREFORMAT_RGBA : Constants.TEXTUREFORMAT_R;
+        var format = (this.isPacked || !ThinEngine.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);

+ 2 - 1
src/Rendering/prePassRenderer.ts

@@ -11,6 +11,7 @@ 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
@@ -164,7 +165,7 @@ export class PrePassRenderer {
      * Indicates if rendering a prepass is supported
      */
     public get isSupported() {
-        return this._engine.webGLVersion > 1;
+        return ThinEngine.Features.supportPrePassRenderer;
     }
 
     /**

+ 2 - 1
src/Sprites/spriteMap.ts

@@ -13,6 +13,7 @@ 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
@@ -226,7 +227,7 @@ export class SpriteMap implements ISpriteMap {
         let shaderString: string = Effect.ShadersStore["spriteMapPixelShader"];
 
         let layerSampleString: string;
-        if (this._scene.getEngine().webGLVersion === 1) {
+        if (!ThinEngine.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; }`;