|
@@ -20,6 +20,95 @@ module BABYLON {
|
|
|
private static _tempBuffer = new Float32Array(UniformBuffer._MAX_UNIFORM_SIZE);
|
|
|
|
|
|
/**
|
|
|
+ * Wrapper for updateUniform.
|
|
|
+ * @method updateMatrix3x3
|
|
|
+ * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
+ * @param {Float32Array} matrix
|
|
|
+ */
|
|
|
+ public updateMatrix3x3: (name: string, matrix: Float32Array) => void;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Wrapper for updateUniform.
|
|
|
+ * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
+ * @param {Float32Array} matrix
|
|
|
+ */
|
|
|
+ public updateMatrix2x2: (name: string, matrix: Float32Array) => void;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Wrapper for updateUniform.
|
|
|
+ * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
+ * @param {number} x
|
|
|
+ */
|
|
|
+ public updateFloat: (name: string, x: number) => void;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Wrapper for updateUniform.
|
|
|
+ * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
+ * @param {number} x
|
|
|
+ * @param {number} y
|
|
|
+ */
|
|
|
+ public updateFloat2: (name: string, x: number, y: number) => void;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Wrapper for updateUniform.
|
|
|
+ * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
+ * @param {number} x
|
|
|
+ * @param {number} y
|
|
|
+ * @param {number} z
|
|
|
+ * @param {string} [suffix] Suffix to add to the uniform name.
|
|
|
+ */
|
|
|
+ public updateFloat3: (name: string, x: number, y: number, z: number, suffix?: string) => void;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Wrapper for updateUniform.
|
|
|
+ * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
+ * @param {number} x
|
|
|
+ * @param {number} y
|
|
|
+ * @param {number} z
|
|
|
+ * @param {number} w
|
|
|
+ * @param {string} [suffix] Suffix to add to the uniform name.
|
|
|
+ */
|
|
|
+ public updateFloat4: (name: string, x: number, y: number, z: number, w: number, suffix?: string) => void;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Wrapper for updateUniform.
|
|
|
+ * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
+ * @param {Matrix} A 4x4 matrix.
|
|
|
+ */
|
|
|
+ public updateMatrix: (name: string, mat: Matrix) => void;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Wrapper for updateUniform.
|
|
|
+ * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
+ * @param {Vector3} vector
|
|
|
+ */
|
|
|
+ public updateVector3: (name: string, vector: Vector3) => void;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Wrapper for updateUniform.
|
|
|
+ * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
+ * @param {Vector4} vector
|
|
|
+ */
|
|
|
+ public updateVector4: (name: string, vector: Vector4) => void;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Wrapper for updateUniform.
|
|
|
+ * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
+ * @param {Color3} color
|
|
|
+ * @param {string} [suffix] Suffix to add to the uniform name.
|
|
|
+ */
|
|
|
+ public updateColor3: (name: string, color: Color3, suffix?: string) => void;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Wrapper for updateUniform.
|
|
|
+ * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
+ * @param {Color3} color
|
|
|
+ * @param {number} alpha
|
|
|
+ * @param {string} [suffix] Suffix to add to the uniform name.
|
|
|
+ */
|
|
|
+ public updateColor4: (name: string, color: Color3, alpha: number, suffix?: string) => void;
|
|
|
+
|
|
|
+ /**
|
|
|
* Uniform buffer objects.
|
|
|
*
|
|
|
* Handles blocks of uniform on the GPU.
|
|
@@ -41,6 +130,32 @@ module BABYLON {
|
|
|
this._uniformLocationPointer = 0;
|
|
|
this._needSync = false;
|
|
|
|
|
|
+ if (this._noUBO) {
|
|
|
+ this.updateMatrix3x3 = this._updateMatrix3x3ForEffect;
|
|
|
+ this.updateMatrix2x2 = this._updateMatrix2x2ForEffect;
|
|
|
+ this.updateFloat = this._updateFloatForEffect;
|
|
|
+ this.updateFloat2 = this._updateFloat2ForEffect;
|
|
|
+ this.updateFloat3 = this._updateFloat3ForEffect;
|
|
|
+ this.updateFloat4 = this._updateFloat4ForEffect;
|
|
|
+ this.updateMatrix = this._updateMatrixForEffect;
|
|
|
+ this.updateVector3 = this._updateVector3ForEffect;
|
|
|
+ this.updateVector4 = this._updateVector4ForEffect;
|
|
|
+ this.updateColor3 = this._updateColor3ForEffect;
|
|
|
+ this.updateColor4 = this._updateColor4ForEffect;
|
|
|
+ } else {
|
|
|
+ this.updateMatrix3x3 = this._updateMatrix3x3ForUniform;
|
|
|
+ this.updateMatrix2x2 = this._updateMatrix2x2ForUniform;
|
|
|
+ this.updateFloat = this._updateFloatForUniform;
|
|
|
+ this.updateFloat2 = this._updateFloat2ForUniform;
|
|
|
+ this.updateFloat3 = this._updateFloat3ForUniform;
|
|
|
+ this.updateFloat4 = this._updateFloat4ForUniform;
|
|
|
+ this.updateMatrix = this._updateMatrixForUniform;
|
|
|
+ this.updateVector3 = this._updateVector3ForUniform;
|
|
|
+ this.updateVector4 = this._updateVector4ForUniform;
|
|
|
+ this.updateColor3 = this._updateColor3ForUniform;
|
|
|
+ this.updateColor4 = this._updateColor4ForUniform;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// Properties
|
|
@@ -324,19 +439,9 @@ module BABYLON {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Wrapper for updateUniform.
|
|
|
- * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
- * @param {Float32Array} matrix
|
|
|
- */
|
|
|
- public updateMatrix3x3(name: string, matrix: Float32Array): Effect {
|
|
|
- if (this._noUBO) {
|
|
|
- if (this._currentEffect) {
|
|
|
- this._currentEffect.setMatrix3x3(name, matrix);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
+ // Update methods
|
|
|
|
|
|
+ private _updateMatrix3x3ForUniform(name: string, matrix: Float32Array): void {
|
|
|
// To match std140, matrix must be realigned
|
|
|
for (var i = 0; i < 3; i++) {
|
|
|
UniformBuffer._tempBuffer[i * 4] = matrix[i * 3];
|
|
@@ -348,19 +453,15 @@ module BABYLON {
|
|
|
this.updateUniform(name, UniformBuffer._tempBuffer, 12);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Wrapper for updateUniform.
|
|
|
- * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
- * @param {Float32Array} matrix
|
|
|
- */
|
|
|
- public updateMatrix2x2(name: string, matrix: Float32Array): Effect {
|
|
|
- if (this._noUBO) {
|
|
|
- if (this._currentEffect) {
|
|
|
- this._currentEffect.setMatrix2x2(name, matrix);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
+ private _updateMatrix3x3ForEffect(name: string, matrix: Float32Array): void {
|
|
|
+ this._currentEffect.setMatrix3x3(name, matrix);
|
|
|
+ }
|
|
|
+
|
|
|
+ private _updateMatrix2x2ForEffect(name: string, matrix: Float32Array): void {
|
|
|
+ this._currentEffect.setMatrix2x2(name, matrix);
|
|
|
+ }
|
|
|
|
|
|
+ private _updateMatrix2x2ForUniform(name: string, matrix: Float32Array): void {
|
|
|
// To match std140, matrix must be realigned
|
|
|
for (var i = 0; i < 2; i++) {
|
|
|
UniformBuffer._tempBuffer[i * 4] = matrix[i * 2];
|
|
@@ -372,81 +473,42 @@ module BABYLON {
|
|
|
this.updateUniform(name, UniformBuffer._tempBuffer, 8);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Wrapper for updateUniform.
|
|
|
- * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
- * @param {number} x
|
|
|
- */
|
|
|
- public updateFloat(name: string, x: number) {
|
|
|
- if (this._noUBO) {
|
|
|
- if (this._currentEffect) {
|
|
|
- this._currentEffect.setFloat(name, x);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
+ private _updateFloatForEffect(name: string, x: number) {
|
|
|
+ this._currentEffect.setFloat(name, x);
|
|
|
+ }
|
|
|
|
|
|
+ private _updateFloatForUniform(name: string, x: number) {
|
|
|
UniformBuffer._tempBuffer[0] = x;
|
|
|
this.updateUniform(name, UniformBuffer._tempBuffer, 1);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Wrapper for updateUniform.
|
|
|
- * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
- * @param {number} x
|
|
|
- * @param {number} y
|
|
|
- */
|
|
|
- public updateFloat2(name: string, x: number, y: number) {
|
|
|
- if (this._noUBO) {
|
|
|
- if (this._currentEffect) {
|
|
|
- this._currentEffect.setFloat2(name, x, y);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
+ private _updateFloat2ForEffect(name: string, x: number, y: number) {
|
|
|
+ this._currentEffect.setFloat2(name, x, y);
|
|
|
+ }
|
|
|
|
|
|
+ private _updateFloat2ForUniform(name: string, x: number, y: number) {
|
|
|
UniformBuffer._tempBuffer[0] = x;
|
|
|
UniformBuffer._tempBuffer[1] = y;
|
|
|
this.updateUniform(name, UniformBuffer._tempBuffer, 2);
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * Wrapper for updateUniform.
|
|
|
- * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
- * @param {number} x
|
|
|
- * @param {number} y
|
|
|
- * @param {number} z
|
|
|
- * @param {string|number} [suffix] Suffix to add to the uniform name.
|
|
|
- */
|
|
|
- public updateFloat3(name: string, x: number, y: number, z: number, suffix?: string | number) {
|
|
|
- if (this._noUBO) {
|
|
|
- if (this._currentEffect) {
|
|
|
- this._currentEffect.setFloat3(name + suffix, x, y, z);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
+ private _updateFloat3ForEffect(name: string, x: number, y: number, z: number, suffix = "") {
|
|
|
+ this._currentEffect.setFloat3(name + suffix, x, y, z);
|
|
|
+ }
|
|
|
|
|
|
+ private _updateFloat3ForUniform(name: string, x: number, y: number, z: number, suffix = "") {
|
|
|
UniformBuffer._tempBuffer[0] = x;
|
|
|
UniformBuffer._tempBuffer[1] = y;
|
|
|
UniformBuffer._tempBuffer[2] = z;
|
|
|
this.updateUniform(name, UniformBuffer._tempBuffer, 3);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Wrapper for updateUniform.
|
|
|
- * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
- * @param {number} x
|
|
|
- * @param {number} y
|
|
|
- * @param {number} z
|
|
|
- * @param {number} w
|
|
|
- * @param {string|number} [suffix] Suffix to add to the uniform name.
|
|
|
- */
|
|
|
- public updateFloat4(name: string, x: number, y: number, z: number, w: number, suffix?: string | number) {
|
|
|
- if (this._noUBO) {
|
|
|
- if (this._currentEffect) {
|
|
|
- this._currentEffect.setFloat4(name + suffix, x, y, z, w);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
+ private _updateFloat4ForEffect(name: string, x: number, y: number, z: number, w: number, suffix = "") {
|
|
|
+ this._currentEffect.setFloat4(name + suffix, x, y, z, w);
|
|
|
+ }
|
|
|
|
|
|
+ private _updateFloat4ForUniform(name: string, x: number, y: number, z: number, w: number, suffix = "") {
|
|
|
UniformBuffer._tempBuffer[0] = x;
|
|
|
UniformBuffer._tempBuffer[1] = y;
|
|
|
UniformBuffer._tempBuffer[2] = z;
|
|
@@ -454,85 +516,46 @@ module BABYLON {
|
|
|
this.updateUniform(name, UniformBuffer._tempBuffer, 4);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Wrapper for updateUniform.
|
|
|
- * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
- * @param {Matrix} A 4x4 matrix.
|
|
|
- */
|
|
|
- public updateMatrix(name: string, mat: Matrix) {
|
|
|
- if (this._noUBO) {
|
|
|
- if (this._currentEffect) {
|
|
|
- this._currentEffect.setMatrix(name, mat);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
+ private _updateMatrixForEffect(name: string, mat: Matrix) {
|
|
|
+ this._currentEffect.setMatrix(name, mat);
|
|
|
+ }
|
|
|
|
|
|
+ private _updateMatrixForUniform(name: string, mat: Matrix) {
|
|
|
this.updateUniform(name, mat.toArray(), 16);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Wrapper for updateUniform.
|
|
|
- * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
- * @param {Vector3} vector
|
|
|
- */
|
|
|
- public updateVector3(name: string, vector: Vector3) {
|
|
|
- if (this._noUBO) {
|
|
|
- if (this._currentEffect) {
|
|
|
- this._currentEffect.setVector3(name, vector);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
+ private _updateVector3ForEffect(name: string, vector: Vector3) {
|
|
|
+ this._currentEffect.setVector3(name, vector);
|
|
|
+ }
|
|
|
+
|
|
|
+ private _updateVector3ForUniform(name: string, vector: Vector3) {
|
|
|
vector.toArray(UniformBuffer._tempBuffer);
|
|
|
this.updateUniform(name, UniformBuffer._tempBuffer, 3);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Wrapper for updateUniform.
|
|
|
- * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
- * @param {Vector4} vector
|
|
|
- */
|
|
|
- public updateVector4(name: string, vector: Vector4) {
|
|
|
- if (this._noUBO) {
|
|
|
- if (this._currentEffect) {
|
|
|
- this._currentEffect.setVector4(name, vector);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
+ private _updateVector4ForEffect(name: string, vector: Vector4) {
|
|
|
+ this._currentEffect.setVector4(name, vector);
|
|
|
+ }
|
|
|
+
|
|
|
+ private _updateVector4ForUniform(name: string, vector: Vector4) {
|
|
|
vector.toArray(UniformBuffer._tempBuffer);
|
|
|
this.updateUniform(name, UniformBuffer._tempBuffer, 4);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Wrapper for updateUniform.
|
|
|
- * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
- * @param {Color3} color
|
|
|
- * @param {string|number} [suffix] Suffix to add to the uniform name.
|
|
|
- */
|
|
|
- public updateColor3(name: string, color: Color3, suffix?: string | number) {
|
|
|
- if (this._noUBO) {
|
|
|
- if (this._currentEffect) {
|
|
|
- this._currentEffect.setColor3(name + suffix, color);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
+ private _updateColor3ForEffect(name: string, color: Color3, suffix = "") {
|
|
|
+ this._currentEffect.setColor3(name + suffix, color);
|
|
|
+ }
|
|
|
+
|
|
|
+ private _updateColor3ForUniform(name: string, color: Color3, suffix = "") {
|
|
|
color.toArray(UniformBuffer._tempBuffer);
|
|
|
this.updateUniform(name, UniformBuffer._tempBuffer, 3);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Wrapper for updateUniform.
|
|
|
- * @param {string} name Name of the uniform, as used in the uniform block in the shader.
|
|
|
- * @param {Color3} color
|
|
|
- * @param {number} alpha
|
|
|
- * @param {string|number} [suffix] Suffix to add to the uniform name.
|
|
|
- */
|
|
|
- public updateColor4(name: string, color: Color3, alpha: number, suffix?: string | number) {
|
|
|
- if (this._noUBO) {
|
|
|
- if (this._currentEffect) {
|
|
|
- this._currentEffect.setColor4(name + suffix, color, alpha);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
+ private _updateColor4ForEffect(name: string, color: Color3, alpha: number, suffix = "") {
|
|
|
+ this._currentEffect.setColor4(name + suffix, color, alpha);
|
|
|
+ }
|
|
|
+
|
|
|
+ private _updateColor4ForUniform(name: string, color: Color3, alpha: number, suffix = "") {
|
|
|
color.toArray(UniformBuffer._tempBuffer);
|
|
|
UniformBuffer._tempBuffer[3] = alpha;
|
|
|
this.updateUniform(name, UniformBuffer._tempBuffer, 4);
|