Sebastien Vandenberghe 5 anni fa
parent
commit
81e2bd3741

+ 2 - 2
package.json

@@ -95,7 +95,7 @@
         "style-loader": "^0.21.0",
         "through2": "~2.0.3",
         "ts-loader": "^5.2.1",
-        "tslib": "^1.9.3",
+        "tslib": "^1.10.0",
         "tslint": "^5.11.0",
         "typedoc": "^0.15.0",
         "typescript": "~3.6.3",
@@ -107,4 +107,4 @@
         "xhr2": "^0.1.4",
         "xmlbuilder": "8.2.2"
     }
-}
+}

+ 4 - 39
src/Engines/IPipelineContext.ts

@@ -60,60 +60,32 @@ export interface IPipelineContext {
     setIntArray4(uniformName: string, array: Int32Array): void;
 
     /**
-     * Sets an float array on a uniform variable.
-     * @param uniformName Name of the variable.
-     * @param array array to be set.
-     */
-    setFloatArray(uniformName: string, array: Float32Array): void;
-
-    /**
-     * Sets an float array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)
-     * @param uniformName Name of the variable.
-     * @param array array to be set.
-     */
-    setFloatArray2(uniformName: string, array: Float32Array): void;
-
-    /**
-     * Sets an float array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)
-     * @param uniformName Name of the variable.
-     * @param array array to be set.
-     */
-    setFloatArray3(uniformName: string, array: Float32Array): void;
-
-    /**
-     * Sets an float array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)
-     * @param uniformName Name of the variable.
-     * @param array array to be set.
-     */
-    setFloatArray4(uniformName: string, array: Float32Array): void;
-
-    /**
      * Sets an array on a uniform variable.
      * @param uniformName Name of the variable.
      * @param array array to be set.
      */
-    setArray(uniformName: string, array: number[]): void;
+    setArray(uniformName: string, array: number[] | Float32Array): void;
 
     /**
      * Sets an array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)
      * @param uniformName Name of the variable.
      * @param array array to be set.
      */
-    setArray2(uniformName: string, array: number[]): void;
+    setArray2(uniformName: string, array: number[] | Float32Array): void;
 
     /**
      * Sets an array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)
      * @param uniformName Name of the variable.
      * @param array array to be set.
      */
-    setArray3(uniformName: string, array: number[]): void;
+    setArray3(uniformName: string, array: number[] | Float32Array): void;
 
     /**
      * Sets an array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)
      * @param uniformName Name of the variable.
      * @param array array to be set.
      */
-    setArray4(uniformName: string, array: number[]): void;
+    setArray4(uniformName: string, array: number[] | Float32Array): void;
 
     /**
      * Sets matrices on a uniform variable.
@@ -151,13 +123,6 @@ export interface IPipelineContext {
     setFloat(uniformName: string, value: number): void;
 
     /**
-     * Sets a boolean on a uniform variable.
-     * @param uniformName Name of the variable.
-     * @param bool value to be set.
-     */
-    setBool(uniformName: string, bool: boolean): void;
-
-    /**
      * Sets a Vector2 on a uniform variable.
      * @param uniformName Name of the variable.
      * @param vector2 vector2 to be set.

+ 1 - 57
src/Engines/WebGL/webGLPipelineContext.ts

@@ -226,46 +226,6 @@ export class WebGLPipelineContext implements IPipelineContext {
     }
 
     /**
-     * Sets an float array on a uniform variable.
-     * @param uniformName Name of the variable.
-     * @param array array to be set.
-     */
-    public setFloatArray(uniformName: string, array: Float32Array): void {
-        this._valueCache[uniformName] = null;
-        this.engine.setFloatArray(this._uniforms[uniformName], array);
-    }
-
-    /**
-     * Sets an float array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)
-     * @param uniformName Name of the variable.
-     * @param array array to be set.
-     */
-    public setFloatArray2(uniformName: string, array: Float32Array): void {
-        this._valueCache[uniformName] = null;
-        this.engine.setFloatArray2(this._uniforms[uniformName], array);
-    }
-
-    /**
-     * Sets an float array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)
-     * @param uniformName Name of the variable.
-     * @param array array to be set.
-     */
-    public setFloatArray3(uniformName: string, array: Float32Array): void {
-        this._valueCache[uniformName] = null;
-        this.engine.setFloatArray3(this._uniforms[uniformName], array);
-    }
-
-    /**
-     * Sets an float array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)
-     * @param uniformName Name of the variable.
-     * @param array array to be set.
-     */
-    public setFloatArray4(uniformName: string, array: Float32Array): void {
-        this._valueCache[uniformName] = null;
-        this.engine.setFloatArray4(this._uniforms[uniformName], array);
-    }
-
-    /**
      * Sets an array on a uniform variable.
      * @param uniformName Name of the variable.
      * @param array array to be set.
@@ -369,22 +329,6 @@ export class WebGLPipelineContext implements IPipelineContext {
     }
 
     /**
-     * Sets a boolean on a uniform variable.
-     * @param uniformName Name of the variable.
-     * @param bool value to be set.
-     */
-    public setBool(uniformName: string, bool: boolean): void {
-        var cache = this._valueCache[uniformName];
-        if (cache !== undefined && cache === bool) {
-            return;
-        }
-
-        this._valueCache[uniformName] = bool;
-
-        this.engine.setBool(this._uniforms[uniformName], bool ? 1 : 0);
-    }
-
-    /**
      * Sets a Vector2 on a uniform variable.
      * @param uniformName Name of the variable.
      * @param vector2 vector2 to be set.
@@ -487,7 +431,7 @@ export class WebGLPipelineContext implements IPipelineContext {
      */
     public setDirectColor4(uniformName: string, color4: IColor4Like): void {
         if (this._cacheFloat4(uniformName, color4.r, color4.g, color4.b, color4.a)) {
-            this.engine.setDirectColor4(this._uniforms[uniformName], color4);
+            this.engine.setFloat4(this._uniforms[uniformName], color4.r, color4.g, color4.b, color4.a);
         }
     }
 }

+ 0 - 48
src/Engines/WebGPU/webgpuPipelineContext.ts

@@ -218,45 +218,6 @@ export class WebGPUPipelineContext implements IPipelineContext {
     }
 
     /**
-     * Sets an float array on a uniform variable.
-     * @param uniformName Name of the variable.
-     * @param array array to be set.
-     */
-    public setFloatArray(uniformName: string, array: Float32Array): void {
-        if (!this.uniformBuffer || !this.leftOverUniformsByName[uniformName]) {
-            return;
-        }
-        this.uniformBuffer.updateFloatArray(uniformName, array);
-    }
-
-    /**
-     * Sets an float array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)
-     * @param uniformName Name of the variable.
-     * @param array array to be set.
-     */
-    public setFloatArray2(uniformName: string, array: Float32Array): void {
-        throw "setFloatArray2 not Supported in LeftOver UBO.";
-    }
-
-    /**
-     * Sets an float array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)
-     * @param uniformName Name of the variable.
-     * @param array array to be set.
-     */
-    public setFloatArray3(uniformName: string, array: Float32Array): void {
-        throw "setFloatArray3 not Supported in LeftOver UBO.";
-    }
-
-    /**
-     * Sets an float array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)
-     * @param uniformName Name of the variable.
-     * @param array array to be set.
-     */
-    public setFloatArray4(uniformName: string, array: Float32Array): void {
-        throw "setFloatArray4 not Supported in LeftOver UBO.";
-    }
-
-    /**
      * Sets an array on a uniform variable.
      * @param uniformName Name of the variable.
      * @param array array to be set.
@@ -355,15 +316,6 @@ export class WebGPUPipelineContext implements IPipelineContext {
     }
 
     /**
-     * Sets a boolean on a uniform variable.
-     * @param uniformName Name of the variable.
-     * @param bool value to be set.
-     */
-    public setBool(uniformName: string, bool: boolean): void {
-        throw "setBool not Supported in LeftOver UBO.";
-    }
-
-    /**
      * Sets a Vector2 on a uniform variable.
      * @param uniformName Name of the variable.
      * @param vector2 vector2 to be set.

+ 9 - 10
src/Engines/nativeEngine.ts

@@ -12,14 +12,13 @@ import { DataBuffer } from '../Meshes/dataBuffer';
 import { Tools } from "../Misc/tools";
 import { Observer } from "../Misc/observable";
 import { EnvironmentTextureTools, EnvironmentTextureSpecularInfoV1 } from "../Misc/environmentTextureTools";
-import { Matrix, Viewport, Color3 } from "../Maths/math";
-import { IColor4Like } from '../Maths/math.like';
+// import { Matrix, Viewport, Color3 } from "../Maths/math";
 import { Scene } from "../scene";
 import { RenderTargetCreationOptions } from "../Materials/Textures/renderTargetCreationOptions";
 import { IPipelineContext } from './IPipelineContext';
 import { WebRequest } from '../Misc/webRequest';
 import { NativeShaderProcessor } from './Native/nativeShaderProcessor';
-import { IMatrixLike, IVector2Like, IVector3Like, IVector4Like, IColor3Like, IColor4Like } from '../Maths/math.like';
+import { IMatrixLike, IVector2Like, IVector3Like, IVector4Like, IColor3Like, IColor4Like, IViewportLike } from '../Maths/math.like';
 import { Logger } from "../Misc/logger";
 import { Constants } from './constants';
 import { ThinEngine } from './thinEngine';
@@ -266,7 +265,7 @@ class NativePipelineContext implements IPipelineContext {
 
         this._valueCache[uniformName] = value;
 
-        this.engine.setInt(this._uniforms[uniformName], value);
+        this.engine.setInt(this._uniforms[uniformName]!, value);
     }
 
     /**
@@ -465,7 +464,7 @@ class NativePipelineContext implements IPipelineContext {
 
         this._valueCache[uniformName] = bool;
 
-        this.engine.setBool(this._uniforms[uniformName]!, bool ? 1 : 0);
+        this.engine.setInt(this._uniforms[uniformName]!, bool ? 1 : 0);
     }
 
     /**
@@ -571,7 +570,7 @@ class NativePipelineContext implements IPipelineContext {
      */
     public setDirectColor4(uniformName: string, color4: IColor4Like): void {
         if (this._cacheFloat4(uniformName, color4.r, color4.g, color4.b, color4.a)) {
-            this.engine.setDirectColor4(this._uniforms[uniformName], color4);
+            this.engine.setColor4(this._uniforms[uniformName]!, color4, color4.a);
         }
     }
 }
@@ -958,7 +957,7 @@ export class NativeEngine extends Engine {
         this._currentEffect = null;
     }
 
-    public setMatrix(uniform: WebGLUniformLocation, matrix: Matrix): void {
+    public setMatrix(uniform: WebGLUniformLocation, matrix: IMatrixLike): void {
         if (!uniform) {
             return;
         }
@@ -982,7 +981,7 @@ export class NativeEngine extends Engine {
         return this._native.getRenderHeight();
     }
 
-    public setViewport(viewport: Viewport, requiredWidth?: number, requiredHeight?: number): void {
+    public setViewport(viewport: IViewportLike, requiredWidth?: number, requiredHeight?: number): void {
         this._cachedViewport = viewport;
         this._native.setViewPort(viewport.x, viewport.y, viewport.width, viewport.height);
     }
@@ -1248,7 +1247,7 @@ export class NativeEngine extends Engine {
         this._native.setFloat4(uniform, x, y, z, w);
     }
 
-    public setColor3(uniform: WebGLUniformLocation, color3: Color3): void {
+    public setColor3(uniform: WebGLUniformLocation, color3: IColor3Like): void {
         if (!uniform) {
             return;
         }
@@ -1256,7 +1255,7 @@ export class NativeEngine extends Engine {
         this._native.setFloat3(uniform, color3.r, color3.g, color3.b);
     }
 
-    public setColor4(uniform: WebGLUniformLocation, color3: Color3, alpha: number): void {
+    public setColor4(uniform: WebGLUniformLocation, color3: IColor3Like, alpha: number): void {
         if (!uniform) {
             return;
         }

+ 0 - 16
src/Engines/webgpuEngine.ts

@@ -4,7 +4,6 @@ import { Scene } from "../scene";
 import { Color4 } from "../Maths/math";
 import { Scalar } from "../Maths/math.scalar";
 import { Engine } from "../Engines/engine";
-import { EngineCapabilities } from "../Engines/engineCapabilities";
 import { InstancingAttributeInfo } from "../Engines/instancingAttributeInfo";
 import { RenderTargetCreationOptions } from "../Materials/Textures/renderTargetCreationOptions";
 import { InternalTexture, InternalTextureSource } from "../Materials/Textures/internalTexture";
@@ -2399,18 +2398,6 @@ export class WebGPUEngine extends Engine {
     public setIntArray4(uniform: WebGLUniformLocation, array: Int32Array): void {
     }
 
-    public setFloatArray(uniform: WebGLUniformLocation, array: Float32Array): void {
-    }
-
-    public setFloatArray2(uniform: WebGLUniformLocation, array: Float32Array): void {
-    }
-
-    public setFloatArray3(uniform: WebGLUniformLocation, array: Float32Array): void {
-    }
-
-    public setFloatArray4(uniform: WebGLUniformLocation, array: Float32Array): void {
-    }
-
     public setArray(uniform: WebGLUniformLocation, array: number[]): void {
     }
 
@@ -2441,9 +2428,6 @@ export class WebGPUEngine extends Engine {
     public setFloat3(uniform: WebGLUniformLocation, x: number, y: number, z: number): void {
     }
 
-    public setBool(uniform: WebGLUniformLocation, bool: number): void {
-    }
-
     public setFloat4(uniform: WebGLUniformLocation, x: number, y: number, z: number, w: number): void {
     }
 }

+ 5 - 5
src/Materials/effect.ts

@@ -816,7 +816,7 @@ export class Effect implements IDisposable {
      * @returns this effect.
      */
     public setFloatArray(uniformName: string, array: Float32Array): Effect {
-        this._pipelineContext!.setFloatArray(uniformName, array);
+        this._pipelineContext!.setArray(uniformName, array);
         return this;
     }
 
@@ -827,7 +827,7 @@ export class Effect implements IDisposable {
      * @returns this effect.
      */
     public setFloatArray2(uniformName: string, array: Float32Array): Effect {
-        this._pipelineContext!.setFloatArray2(uniformName, array);
+        this._pipelineContext!.setArray2(uniformName, array);
         return this;
     }
 
@@ -838,7 +838,7 @@ export class Effect implements IDisposable {
      * @returns this effect.
      */
     public setFloatArray3(uniformName: string, array: Float32Array): Effect {
-        this._pipelineContext!.setFloatArray3(uniformName, array);
+        this._pipelineContext!.setArray3(uniformName, array);
         return this;
     }
 
@@ -849,7 +849,7 @@ export class Effect implements IDisposable {
      * @returns this effect.
      */
     public setFloatArray4(uniformName: string, array: Float32Array): Effect {
-        this._pipelineContext!.setFloatArray4(uniformName, array);
+        this._pipelineContext!.setArray4(uniformName, array);
         return this;
     }
 
@@ -959,7 +959,7 @@ export class Effect implements IDisposable {
      * @returns this effect.
      */
     public setBool(uniformName: string, bool: boolean): Effect {
-        this._pipelineContext!.setBool(uniformName, bool);
+        this._pipelineContext!.setInt(uniformName, bool ? 1 : 0);
         return this;
     }