|
@@ -2174,6 +2174,24 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private _viewportCached = new BABYLON.Vector4(0, 0, 0, 0);
|
|
|
|
+
|
|
|
|
+ /** @hidden */
|
|
|
|
+ public _viewport(x: number, y: number, width: number, height: number): void {
|
|
|
|
+ if (x !== this._viewportCached.x ||
|
|
|
|
+ y !== this._viewportCached.y ||
|
|
|
|
+ width !== this._viewportCached.z ||
|
|
|
|
+ height !== this._viewportCached.w)
|
|
|
|
+ {
|
|
|
|
+ this._viewportCached.x = x;
|
|
|
|
+ this._viewportCached.y = y;
|
|
|
|
+ this._viewportCached.z = width;
|
|
|
|
+ this._viewportCached.w = height;
|
|
|
|
+
|
|
|
|
+ this._gl.viewport(x, y, width, height);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Set the WebGL's viewport
|
|
* Set the WebGL's viewport
|
|
* @param viewport defines the viewport element to be used
|
|
* @param viewport defines the viewport element to be used
|
|
@@ -2188,7 +2206,7 @@
|
|
|
|
|
|
this._cachedViewport = viewport;
|
|
this._cachedViewport = viewport;
|
|
|
|
|
|
- this._gl.viewport(x * width, y * height, width * viewport.width, height * viewport.height);
|
|
|
|
|
|
+ this._viewport(x * width, y * height, width * viewport.width, height * viewport.height);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -2203,7 +2221,7 @@
|
|
let currentViewport = this._cachedViewport;
|
|
let currentViewport = this._cachedViewport;
|
|
this._cachedViewport = null;
|
|
this._cachedViewport = null;
|
|
|
|
|
|
- this._gl.viewport(x, y, width, height);
|
|
|
|
|
|
+ this._viewport(x, y, width, height);
|
|
|
|
|
|
return currentViewport;
|
|
return currentViewport;
|
|
}
|
|
}
|
|
@@ -2465,7 +2483,7 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- gl.viewport(0, 0, requiredWidth, requiredHeight);
|
|
|
|
|
|
+ this._viewport(0, 0, requiredWidth, requiredHeight);
|
|
}
|
|
}
|
|
|
|
|
|
this.wipeCaches();
|
|
this.wipeCaches();
|
|
@@ -4072,6 +4090,11 @@
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
this._currentEffect = null;
|
|
this._currentEffect = null;
|
|
|
|
+ this._unpackFlipYCached = null;
|
|
|
|
+ this._viewportCached.x = 0;
|
|
|
|
+ this._viewportCached.y = 0;
|
|
|
|
+ this._viewportCached.z = 0;
|
|
|
|
+ this._viewportCached.w = 0;
|
|
|
|
|
|
if (bruteForce) {
|
|
if (bruteForce) {
|
|
this.resetTextureCache();
|
|
this.resetTextureCache();
|
|
@@ -4384,7 +4407,7 @@
|
|
var internalFormat = this._getInternalFormat(format);
|
|
var internalFormat = this._getInternalFormat(format);
|
|
var textureType = this._getWebGLTextureType(type);
|
|
var textureType = this._getWebGLTextureType(type);
|
|
this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);
|
|
this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);
|
|
- this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
|
|
|
|
|
|
+ this._unpackFlipY(invertY === undefined ? true : (invertY ? true : false));
|
|
|
|
|
|
if (!this._doNotHandleContextLost) {
|
|
if (!this._doNotHandleContextLost) {
|
|
texture._bufferView = data;
|
|
texture._bufferView = data;
|
|
@@ -4463,6 +4486,15 @@
|
|
return texture;
|
|
return texture;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private _unpackFlipYCached: Nullable<boolean> = null;
|
|
|
|
+ /** @hidden */
|
|
|
|
+ public _unpackFlipY(value: boolean) {
|
|
|
|
+ if (this._unpackFlipYCached !== value) {
|
|
|
|
+ this._unpackFlipYCached = value;
|
|
|
|
+ this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, value ? 1 : 0);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Creates a dynamic texture
|
|
* Creates a dynamic texture
|
|
* @param width defines the width of the texture
|
|
* @param width defines the width of the texture
|
|
@@ -4534,7 +4566,7 @@
|
|
}
|
|
}
|
|
|
|
|
|
this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);
|
|
this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);
|
|
- this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY ? 1 : 0);
|
|
|
|
|
|
+ this._unpackFlipY(invertY);
|
|
if (premulAlpha) {
|
|
if (premulAlpha) {
|
|
this._gl.pixelStorei(this._gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);
|
|
this._gl.pixelStorei(this._gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);
|
|
}
|
|
}
|
|
@@ -4561,8 +4593,8 @@
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);
|
|
|
|
- this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY ? 0 : 1); // Video are upside down by default
|
|
|
|
|
|
+ var wasPreviouslyBound = this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);
|
|
|
|
+ this._unpackFlipY(!invertY); // Video are upside down by default
|
|
|
|
|
|
try {
|
|
try {
|
|
// Testing video texture support
|
|
// Testing video texture support
|
|
@@ -4602,7 +4634,9 @@
|
|
this._gl.generateMipmap(this._gl.TEXTURE_2D);
|
|
this._gl.generateMipmap(this._gl.TEXTURE_2D);
|
|
}
|
|
}
|
|
|
|
|
|
- this._bindTextureDirectly(this._gl.TEXTURE_2D, null);
|
|
|
|
|
|
+ if (!wasPreviouslyBound) {
|
|
|
|
+ this._bindTextureDirectly(this._gl.TEXTURE_2D, null);
|
|
|
|
+ }
|
|
// this.resetTextureCache();
|
|
// this.resetTextureCache();
|
|
texture.isReady = true;
|
|
texture.isReady = true;
|
|
|
|
|
|
@@ -5301,7 +5335,7 @@
|
|
var bindTarget = texture.isCube ? gl.TEXTURE_CUBE_MAP : gl.TEXTURE_2D;
|
|
var bindTarget = texture.isCube ? gl.TEXTURE_CUBE_MAP : gl.TEXTURE_2D;
|
|
|
|
|
|
this._bindTextureDirectly(bindTarget, texture, true);
|
|
this._bindTextureDirectly(bindTarget, texture, true);
|
|
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, texture.invertY ? 1 : 0);
|
|
|
|
|
|
+ this._unpackFlipY(texture.invertY);
|
|
|
|
|
|
var target = gl.TEXTURE_2D;
|
|
var target = gl.TEXTURE_2D;
|
|
if (texture.isCube) {
|
|
if (texture.isCube) {
|
|
@@ -5466,7 +5500,7 @@
|
|
if (loadData.isDDS) {
|
|
if (loadData.isDDS) {
|
|
var info: DDSInfo = loadData.info;
|
|
var info: DDSInfo = loadData.info;
|
|
var data: any = loadData.data;
|
|
var data: any = loadData.data;
|
|
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, info.isCompressed ? 1 : 0);
|
|
|
|
|
|
+ this._unpackFlipY(info.isCompressed);
|
|
|
|
|
|
DDSTools.UploadDDSLevels(this, this._gl, data, info, true, 6, mipmapIndex);
|
|
DDSTools.UploadDDSLevels(this, this._gl, data, info, true, 6, mipmapIndex);
|
|
}
|
|
}
|
|
@@ -5554,7 +5588,7 @@
|
|
var loadMipmap = ktx.numberOfMipmapLevels > 1 && !noMipmap;
|
|
var loadMipmap = ktx.numberOfMipmapLevels > 1 && !noMipmap;
|
|
|
|
|
|
this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
|
|
this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
|
|
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
|
|
|
|
|
|
+ this._unpackFlipY(true);
|
|
|
|
|
|
ktx.uploadLevels(this._gl, !noMipmap);
|
|
ktx.uploadLevels(this._gl, !noMipmap);
|
|
|
|
|
|
@@ -5601,7 +5635,7 @@
|
|
loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && !noMipmap;
|
|
loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && !noMipmap;
|
|
|
|
|
|
this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
|
|
this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
|
|
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, info.isCompressed ? 1 : 0);
|
|
|
|
|
|
+ this._unpackFlipY(info.isCompressed);
|
|
|
|
|
|
DDSTools.UploadDDSLevels(this, this._gl, data, info, loadMipmap, 6, -1, index);
|
|
DDSTools.UploadDDSLevels(this, this._gl, data, info, loadMipmap, 6, -1, index);
|
|
|
|
|
|
@@ -5636,7 +5670,7 @@
|
|
var loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && !noMipmap;
|
|
var loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && !noMipmap;
|
|
|
|
|
|
this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
|
|
this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
|
|
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, info.isCompressed ? 1 : 0);
|
|
|
|
|
|
+ this._unpackFlipY(info.isCompressed);
|
|
|
|
|
|
DDSTools.UploadDDSLevels(this, this._gl, data, info, loadMipmap, 6);
|
|
DDSTools.UploadDDSLevels(this, this._gl, data, info, loadMipmap, 6);
|
|
|
|
|
|
@@ -5683,7 +5717,7 @@
|
|
];
|
|
];
|
|
|
|
|
|
this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
|
|
this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
|
|
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
|
|
|
|
|
|
+ this._unpackFlipY(false);
|
|
|
|
|
|
let internalFormat = format ? this._getInternalFormat(format) : this._gl.RGBA;
|
|
let internalFormat = format ? this._getInternalFormat(format) : this._gl.RGBA;
|
|
for (var index = 0; index < faces.length; index++) {
|
|
for (var index = 0; index < faces.length; index++) {
|
|
@@ -5758,7 +5792,7 @@
|
|
}
|
|
}
|
|
|
|
|
|
this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
|
|
this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
|
|
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
|
|
|
|
|
|
+ this._unpackFlipY(invertY === undefined ? true : (invertY ? true : false));
|
|
|
|
|
|
if (texture.width % 4 !== 0) {
|
|
if (texture.width % 4 !== 0) {
|
|
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
|
|
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
|
|
@@ -5922,7 +5956,7 @@
|
|
}
|
|
}
|
|
|
|
|
|
this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
|
|
this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
|
|
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
|
|
|
|
|
|
+ this._unpackFlipY(false);
|
|
|
|
|
|
var mipData = mipmapGenerator(faceDataArrays);
|
|
var mipData = mipmapGenerator(faceDataArrays);
|
|
for (var level = 0; level < mipData.length; level++) {
|
|
for (var level = 0; level < mipData.length; level++) {
|
|
@@ -5975,7 +6009,7 @@
|
|
var internalSizedFomat = this._getRGBABufferInternalSizedFormat(textureType, format);
|
|
var internalSizedFomat = this._getRGBABufferInternalSizedFormat(textureType, format);
|
|
|
|
|
|
this._bindTextureDirectly(this._gl.TEXTURE_3D, texture, true);
|
|
this._bindTextureDirectly(this._gl.TEXTURE_3D, texture, true);
|
|
- this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
|
|
|
|
|
|
+ this._unpackFlipY(invertY === undefined ? true : (invertY ? true : false));
|
|
|
|
|
|
if (!this._doNotHandleContextLost) {
|
|
if (!this._doNotHandleContextLost) {
|
|
texture._bufferView = data;
|
|
texture._bufferView = data;
|
|
@@ -6100,7 +6134,7 @@
|
|
}
|
|
}
|
|
|
|
|
|
this._bindTextureDirectly(gl.TEXTURE_2D, texture, true);
|
|
this._bindTextureDirectly(gl.TEXTURE_2D, texture, true);
|
|
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
|
|
|
|
|
|
+ this._unpackFlipY(invertY === undefined ? true : (invertY ? true : false));
|
|
|
|
|
|
texture.baseWidth = width;
|
|
texture.baseWidth = width;
|
|
texture.baseHeight = height;
|
|
texture.baseHeight = height;
|
|
@@ -6326,7 +6360,8 @@
|
|
}
|
|
}
|
|
|
|
|
|
/** @hidden */
|
|
/** @hidden */
|
|
- protected _bindTextureDirectly(target: number, texture: Nullable<InternalTexture>, forTextureDataUpdate = false, force = false): void {
|
|
|
|
|
|
+ protected _bindTextureDirectly(target: number, texture: Nullable<InternalTexture>, forTextureDataUpdate = false, force = false): boolean {
|
|
|
|
+ var wasPreviouslyBound = false;
|
|
if (forTextureDataUpdate && texture && texture._designatedSlot > -1) {
|
|
if (forTextureDataUpdate && texture && texture._designatedSlot > -1) {
|
|
this._activeChannel = texture._designatedSlot;
|
|
this._activeChannel = texture._designatedSlot;
|
|
}
|
|
}
|
|
@@ -6358,12 +6393,15 @@
|
|
texture._designatedSlot = this._activeChannel;
|
|
texture._designatedSlot = this._activeChannel;
|
|
}
|
|
}
|
|
} else if (forTextureDataUpdate) {
|
|
} else if (forTextureDataUpdate) {
|
|
|
|
+ wasPreviouslyBound = true;
|
|
this._activateCurrentTexture();
|
|
this._activateCurrentTexture();
|
|
}
|
|
}
|
|
|
|
|
|
if (isTextureForRendering && !forTextureDataUpdate) {
|
|
if (isTextureForRendering && !forTextureDataUpdate) {
|
|
this._bindSamplerUniformToChannel(texture!._initialSlot, this._activeChannel);
|
|
this._bindSamplerUniformToChannel(texture!._initialSlot, this._activeChannel);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ return wasPreviouslyBound;
|
|
}
|
|
}
|
|
|
|
|
|
/** @hidden */
|
|
/** @hidden */
|