|
@@ -1118,7 +1118,10 @@ module BABYLON {
|
|
|
this._webGLVersion = 2.0;
|
|
|
}
|
|
|
|
|
|
- options.stencil = this._gl.getContextAttributes().stencil;
|
|
|
+ const attributes = this._gl.getContextAttributes();
|
|
|
+ if (attributes) {
|
|
|
+ options.stencil = attributes.stencil;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Viewport
|
|
@@ -1858,7 +1861,7 @@ module BABYLON {
|
|
|
// Register new frame
|
|
|
var requester = null;
|
|
|
if (this._vrDisplay && this._vrDisplay.isPresenting) {
|
|
|
- requester = this._vrDisplay;
|
|
|
+ requester = this._vrDisplay;
|
|
|
}
|
|
|
this._frameHandler = Tools.QueueNewFrame(this._bindedRenderFunction, requester);
|
|
|
} else {
|
|
@@ -1964,8 +1967,7 @@ module BABYLON {
|
|
|
if (x !== this._viewportCached.x ||
|
|
|
y !== this._viewportCached.y ||
|
|
|
width !== this._viewportCached.z ||
|
|
|
- height !== this._viewportCached.w)
|
|
|
- {
|
|
|
+ height !== this._viewportCached.w) {
|
|
|
this._viewportCached.x = x;
|
|
|
this._viewportCached.y = y;
|
|
|
this._viewportCached.z = width;
|
|
@@ -2120,7 +2122,7 @@ module BABYLON {
|
|
|
vrSupported: this._vrSupported
|
|
|
};
|
|
|
this.onVRDisplayChangedObservable.notifyObservers(eventArgs);
|
|
|
- this._webVRInitPromise = new Promise((res) => {res(eventArgs); });
|
|
|
+ this._webVRInitPromise = new Promise((res) => { res(eventArgs); });
|
|
|
};
|
|
|
|
|
|
if (!this._onVrDisplayConnect) {
|
|
@@ -3220,6 +3222,10 @@ module BABYLON {
|
|
|
var gl = this._gl;
|
|
|
var shader = gl.createShader(type === "vertex" ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER);
|
|
|
|
|
|
+ if (!shader) {
|
|
|
+ throw new Error("Something went wrong while compile the shader.");
|
|
|
+ }
|
|
|
+
|
|
|
gl.shaderSource(shader, source);
|
|
|
gl.compileShader(shader);
|
|
|
|
|
@@ -3230,10 +3236,6 @@ module BABYLON {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!shader) {
|
|
|
- throw new Error("Something went wrong while compile the shader.");
|
|
|
- }
|
|
|
-
|
|
|
return shader;
|
|
|
}
|
|
|
|
|
@@ -3395,7 +3397,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setIntArray(uniform: Nullable<WebGLUniformLocation>, array: Int32Array): void {
|
|
|
if (!uniform) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform1iv(uniform, array);
|
|
@@ -3408,7 +3410,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setIntArray2(uniform: Nullable<WebGLUniformLocation>, array: Int32Array): void {
|
|
|
if (!uniform || array.length % 2 !== 0) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform2iv(uniform, array);
|
|
@@ -3421,7 +3423,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setIntArray3(uniform: Nullable<WebGLUniformLocation>, array: Int32Array): void {
|
|
|
if (!uniform || array.length % 3 !== 0) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform3iv(uniform, array);
|
|
@@ -3434,7 +3436,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setIntArray4(uniform: Nullable<WebGLUniformLocation>, array: Int32Array): void {
|
|
|
if (!uniform || array.length % 4 !== 0) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform4iv(uniform, array);
|
|
@@ -3447,7 +3449,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setFloatArray(uniform: Nullable<WebGLUniformLocation>, array: Float32Array): void {
|
|
|
if (!uniform) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform1fv(uniform, array);
|
|
@@ -3460,7 +3462,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setFloatArray2(uniform: Nullable<WebGLUniformLocation>, array: Float32Array): void {
|
|
|
if (!uniform || array.length % 2 !== 0) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform2fv(uniform, array);
|
|
@@ -3473,7 +3475,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setFloatArray3(uniform: Nullable<WebGLUniformLocation>, array: Float32Array): void {
|
|
|
if (!uniform || array.length % 3 !== 0) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform3fv(uniform, array);
|
|
@@ -3486,7 +3488,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setFloatArray4(uniform: Nullable<WebGLUniformLocation>, array: Float32Array): void {
|
|
|
if (!uniform || array.length % 4 !== 0) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform4fv(uniform, array);
|
|
@@ -3499,7 +3501,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setArray(uniform: Nullable<WebGLUniformLocation>, array: number[]): void {
|
|
|
if (!uniform) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform1fv(uniform, <any>array);
|
|
@@ -3512,7 +3514,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setArray2(uniform: Nullable<WebGLUniformLocation>, array: number[]): void {
|
|
|
if (!uniform || array.length % 2 !== 0) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform2fv(uniform, <any>array);
|
|
@@ -3525,7 +3527,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setArray3(uniform: Nullable<WebGLUniformLocation>, array: number[]): void {
|
|
|
if (!uniform || array.length % 3 !== 0) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform3fv(uniform, <any>array);
|
|
@@ -3538,7 +3540,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setArray4(uniform: Nullable<WebGLUniformLocation>, array: number[]): void {
|
|
|
if (!uniform || array.length % 4 !== 0) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform4fv(uniform, <any>array);
|
|
@@ -3551,7 +3553,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setMatrices(uniform: Nullable<WebGLUniformLocation>, matrices: Float32Array): void {
|
|
|
if (!uniform) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniformMatrix4fv(uniform, false, matrices);
|
|
@@ -3564,7 +3566,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setMatrix(uniform: Nullable<WebGLUniformLocation>, matrix: Matrix): void {
|
|
|
if (!uniform) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniformMatrix4fv(uniform, false, matrix.toArray());
|
|
@@ -3577,7 +3579,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setMatrix3x3(uniform: Nullable<WebGLUniformLocation>, matrix: Float32Array): void {
|
|
|
if (!uniform) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniformMatrix3fv(uniform, false, matrix);
|
|
@@ -3590,7 +3592,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setMatrix2x2(uniform: Nullable<WebGLUniformLocation>, matrix: Float32Array): void {
|
|
|
if (!uniform) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniformMatrix2fv(uniform, false, matrix);
|
|
@@ -3603,7 +3605,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setInt(uniform: Nullable<WebGLUniformLocation>, value: number): void {
|
|
|
if (!uniform) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform1i(uniform, value);
|
|
@@ -3616,7 +3618,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setFloat(uniform: Nullable<WebGLUniformLocation>, value: number): void {
|
|
|
if (!uniform) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform1f(uniform, value);
|
|
@@ -3630,7 +3632,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setFloat2(uniform: Nullable<WebGLUniformLocation>, x: number, y: number): void {
|
|
|
if (!uniform) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform2f(uniform, x, y);
|
|
@@ -3645,7 +3647,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setFloat3(uniform: Nullable<WebGLUniformLocation>, x: number, y: number, z: number): void {
|
|
|
if (!uniform) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform3f(uniform, x, y, z);
|
|
@@ -3658,7 +3660,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setBool(uniform: Nullable<WebGLUniformLocation>, bool: number): void {
|
|
|
if (!uniform) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform1i(uniform, bool);
|
|
@@ -3674,7 +3676,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setFloat4(uniform: Nullable<WebGLUniformLocation>, x: number, y: number, z: number, w: number): void {
|
|
|
if (!uniform) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform4f(uniform, x, y, z, w);
|
|
@@ -3687,7 +3689,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setColor3(uniform: Nullable<WebGLUniformLocation>, color3: Color3): void {
|
|
|
if (!uniform) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform3f(uniform, color3.r, color3.g, color3.b);
|
|
@@ -3701,7 +3703,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setColor4(uniform: Nullable<WebGLUniformLocation>, color3: Color3, alpha: number): void {
|
|
|
if (!uniform) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform4f(uniform, color3.r, color3.g, color3.b, alpha);
|
|
@@ -3714,7 +3716,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public setDirectColor4(uniform: Nullable<WebGLUniformLocation>, color4: Color4): void {
|
|
|
if (!uniform) {
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this._gl.uniform4f(uniform, color4.r, color4.g, color4.b, color4.a);
|
|
@@ -4218,9 +4220,9 @@ module BABYLON {
|
|
|
var callback = (data: string | ArrayBuffer) => {
|
|
|
loader!.loadData(data as ArrayBuffer, texture, (width: number, height: number, loadMipmap: boolean, isCompressed: boolean, done: () => void) => {
|
|
|
this._prepareWebGLTexture(texture, scene, width, height, invertY, !loadMipmap, isCompressed, () => {
|
|
|
- done();
|
|
|
- return false;
|
|
|
- },
|
|
|
+ done();
|
|
|
+ return false;
|
|
|
+ },
|
|
|
samplingMode);
|
|
|
});
|
|
|
};
|
|
@@ -4359,7 +4361,8 @@ module BABYLON {
|
|
|
* @param compression defines the compression used (null by default)
|
|
|
* @param type defines the type fo the data (BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT by default)
|
|
|
*/
|
|
|
- public updateRawTexture(texture: Nullable<InternalTexture>, data: Nullable<ArrayBufferView>, format: number, invertY: boolean, compression: Nullable<string> = null, type = Engine.TEXTURETYPE_UNSIGNED_INT): void { if (!texture) {
|
|
|
+ public updateRawTexture(texture: Nullable<InternalTexture>, data: Nullable<ArrayBufferView>, format: number, invertY: boolean, compression: Nullable<string> = null, type = Engine.TEXTURETYPE_UNSIGNED_INT): void {
|
|
|
+ if (!texture) {
|
|
|
return;
|
|
|
}
|
|
|
// babylon's internalSizedFomat but gl's texImage2D internalFormat
|
|
@@ -4669,7 +4672,7 @@ module BABYLON {
|
|
|
texture._comparisonFunction = comparisonFunction;
|
|
|
}
|
|
|
|
|
|
- private _setupDepthStencilTexture(internalTexture: InternalTexture, size: number | { width: number, height: number }, generateStencil: boolean, bilinearFiltering: boolean, comparisonFunction: number) : void {
|
|
|
+ private _setupDepthStencilTexture(internalTexture: InternalTexture, size: number | { width: number, height: number }, generateStencil: boolean, bilinearFiltering: boolean, comparisonFunction: number): void {
|
|
|
var width = (<{ width: number, height: number }>size).width || <number>size;
|
|
|
var height = (<{ width: number, height: number }>size).height || <number>size;
|
|
|
internalTexture.baseWidth = width;
|
|
@@ -4710,7 +4713,7 @@ module BABYLON {
|
|
|
* @param options The options defining the texture.
|
|
|
* @returns The texture
|
|
|
*/
|
|
|
- public createDepthStencilTexture(size: number | { width: number, height: number }, options: DepthTextureCreationOptions) : InternalTexture {
|
|
|
+ public createDepthStencilTexture(size: number | { width: number, height: number }, options: DepthTextureCreationOptions): InternalTexture {
|
|
|
if (options.isCube) {
|
|
|
let width = (<{ width: number, height: number }>size).width || <number>size;
|
|
|
return this._createDepthStencilCubeTexture(width, options);
|
|
@@ -4727,7 +4730,7 @@ module BABYLON {
|
|
|
* @param options The options defining the texture.
|
|
|
* @returns The texture
|
|
|
*/
|
|
|
- private _createDepthStencilTexture(size: number | { width: number, height: number }, options: DepthTextureCreationOptions) : InternalTexture {
|
|
|
+ private _createDepthStencilTexture(size: number | { width: number, height: number }, options: DepthTextureCreationOptions): InternalTexture {
|
|
|
var internalTexture = new InternalTexture(this, InternalTexture.DATASOURCE_DEPTHTEXTURE);
|
|
|
|
|
|
if (!this._caps.depthTextureExtension) {
|
|
@@ -4776,7 +4779,7 @@ module BABYLON {
|
|
|
* @param options The options defining the cube texture.
|
|
|
* @returns The cube texture
|
|
|
*/
|
|
|
- private _createDepthStencilCubeTexture(size: number, options: DepthTextureCreationOptions) : InternalTexture {
|
|
|
+ private _createDepthStencilCubeTexture(size: number, options: DepthTextureCreationOptions): InternalTexture {
|
|
|
var internalTexture = new InternalTexture(this, InternalTexture.DATASOURCE_UNKNOWN);
|
|
|
internalTexture.isCube = true;
|
|
|
|
|
@@ -5368,23 +5371,23 @@ module BABYLON {
|
|
|
*/
|
|
|
public createRenderTargetCubeTexture(size: number, options?: Partial<RenderTargetCreationOptions>): InternalTexture {
|
|
|
let fullOptions = {
|
|
|
- generateMipMaps: true,
|
|
|
- generateDepthBuffer: true,
|
|
|
- generateStencilBuffer: false,
|
|
|
- type: Engine.TEXTURETYPE_UNSIGNED_INT,
|
|
|
- samplingMode: Engine.TEXTURE_TRILINEAR_SAMPLINGMODE,
|
|
|
- format: Engine.TEXTUREFORMAT_RGBA,
|
|
|
- ...options
|
|
|
+ generateMipMaps: true,
|
|
|
+ generateDepthBuffer: true,
|
|
|
+ generateStencilBuffer: false,
|
|
|
+ type: Engine.TEXTURETYPE_UNSIGNED_INT,
|
|
|
+ samplingMode: Engine.TEXTURE_TRILINEAR_SAMPLINGMODE,
|
|
|
+ format: Engine.TEXTUREFORMAT_RGBA,
|
|
|
+ ...options
|
|
|
};
|
|
|
fullOptions.generateStencilBuffer = fullOptions.generateDepthBuffer && fullOptions.generateStencilBuffer;
|
|
|
|
|
|
if (fullOptions.type === Engine.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {
|
|
|
- // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE
|
|
|
- fullOptions.samplingMode = Engine.TEXTURE_NEAREST_SAMPLINGMODE;
|
|
|
+ // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE
|
|
|
+ fullOptions.samplingMode = Engine.TEXTURE_NEAREST_SAMPLINGMODE;
|
|
|
}
|
|
|
else if (fullOptions.type === Engine.TEXTURETYPE_HALF_FLOAT && !this._caps.textureHalfFloatLinearFiltering) {
|
|
|
- // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE
|
|
|
- fullOptions.samplingMode = Engine.TEXTURE_NEAREST_SAMPLINGMODE;
|
|
|
+ // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE
|
|
|
+ fullOptions.samplingMode = Engine.TEXTURE_NEAREST_SAMPLINGMODE;
|
|
|
}
|
|
|
var gl = this._gl;
|
|
|
|
|
@@ -5394,8 +5397,8 @@ module BABYLON {
|
|
|
var filters = this._getSamplingParameters(fullOptions.samplingMode, fullOptions.generateMipMaps);
|
|
|
|
|
|
if (fullOptions.type === Engine.TEXTURETYPE_FLOAT && !this._caps.textureFloat) {
|
|
|
- fullOptions.type = Engine.TEXTURETYPE_UNSIGNED_INT;
|
|
|
- Tools.Warn("Float textures are not supported. Cube render target forced to TEXTURETYPE_UNESIGNED_BYTE type");
|
|
|
+ fullOptions.type = Engine.TEXTURETYPE_UNSIGNED_INT;
|
|
|
+ Tools.Warn("Float textures are not supported. Cube render target forced to TEXTURETYPE_UNESIGNED_BYTE type");
|
|
|
}
|
|
|
|
|
|
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, filters.mag);
|
|
@@ -5415,7 +5418,7 @@ module BABYLON {
|
|
|
|
|
|
// MipMaps
|
|
|
if (fullOptions.generateMipMaps) {
|
|
|
- gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
|
|
|
+ gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
|
|
|
}
|
|
|
|
|
|
// Unbind
|
|
@@ -5769,8 +5772,8 @@ module BABYLON {
|
|
|
* @returns the cube texture as an InternalTexture
|
|
|
*/
|
|
|
public createRawCubeTexture(data: Nullable<ArrayBufferView[]>, size: number, format: number, type: number,
|
|
|
- generateMipMaps: boolean, invertY: boolean, samplingMode: number,
|
|
|
- compression: Nullable<string> = null): InternalTexture {
|
|
|
+ generateMipMaps: boolean, invertY: boolean, samplingMode: number,
|
|
|
+ compression: Nullable<string> = null): InternalTexture {
|
|
|
var gl = this._gl;
|
|
|
var texture = new InternalTexture(this, InternalTexture.DATASOURCE_CUBERAW);
|
|
|
texture.isCube = true;
|
|
@@ -6889,7 +6892,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public get loadingScreen(): ILoadingScreen {
|
|
|
if (!this._loadingScreen && DefaultLoadingScreen && this._renderingCanvas) {
|
|
|
- this._loadingScreen = new DefaultLoadingScreen(this._renderingCanvas);
|
|
|
+ this._loadingScreen = new DefaultLoadingScreen(this._renderingCanvas);
|
|
|
}
|
|
|
return this._loadingScreen;
|
|
|
}
|
|
@@ -7264,7 +7267,7 @@ module BABYLON {
|
|
|
return this._gl.RGBA8UI;
|
|
|
default:
|
|
|
return this._gl.RGBA8;
|
|
|
- }
|
|
|
+ }
|
|
|
case Engine.TEXTURETYPE_SHORT:
|
|
|
switch (format) {
|
|
|
case Engine.TEXTUREFORMAT_RED_INTEGER:
|