|
@@ -12167,6 +12167,9 @@ var BABYLON;
|
|
|
*/
|
|
|
Engine.prototype.resetTextureCache = function () {
|
|
|
for (var key in this._boundTexturesCache) {
|
|
|
+ if (!this._boundTexturesCache.hasOwnProperty(key)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
var boundTexture = this._boundTexturesCache[key];
|
|
|
if (boundTexture) {
|
|
|
this._removeDesignatedSlot(boundTexture);
|
|
@@ -14614,21 +14617,18 @@ var BABYLON;
|
|
|
Engine.prototype.updateTextureSamplingMode = function (samplingMode, texture) {
|
|
|
var filters = getSamplingParameters(samplingMode, texture.generateMipMaps, this._gl);
|
|
|
if (texture.isCube) {
|
|
|
- this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, texture, true);
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_MAG_FILTER, filters.mag);
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_MIN_FILTER, filters.min);
|
|
|
+ this._setTextureParameterInteger(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_MAG_FILTER, filters.mag, texture);
|
|
|
+ this._setTextureParameterInteger(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_MIN_FILTER, filters.min);
|
|
|
this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);
|
|
|
}
|
|
|
else if (texture.is3D) {
|
|
|
- this._bindTextureDirectly(this._gl.TEXTURE_3D, texture, true);
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_3D, this._gl.TEXTURE_MAG_FILTER, filters.mag);
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_3D, this._gl.TEXTURE_MIN_FILTER, filters.min);
|
|
|
+ this._setTextureParameterInteger(this._gl.TEXTURE_3D, this._gl.TEXTURE_MAG_FILTER, filters.mag, texture);
|
|
|
+ this._setTextureParameterInteger(this._gl.TEXTURE_3D, this._gl.TEXTURE_MIN_FILTER, filters.min);
|
|
|
this._bindTextureDirectly(this._gl.TEXTURE_3D, null);
|
|
|
}
|
|
|
else {
|
|
|
- this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, filters.mag);
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, filters.min);
|
|
|
+ this._setTextureParameterInteger(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, filters.mag, texture);
|
|
|
+ this._setTextureParameterInteger(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, filters.min);
|
|
|
this._bindTextureDirectly(this._gl.TEXTURE_2D, null);
|
|
|
}
|
|
|
texture.samplingMode = samplingMode;
|
|
@@ -16040,14 +16040,15 @@ var BABYLON;
|
|
|
}
|
|
|
};
|
|
|
/** @ignore */
|
|
|
- Engine.prototype._bindTextureDirectly = function (target, texture, forTextureDataUpdate) {
|
|
|
+ Engine.prototype._bindTextureDirectly = function (target, texture, forTextureDataUpdate, force) {
|
|
|
if (forTextureDataUpdate === void 0) { forTextureDataUpdate = false; }
|
|
|
+ if (force === void 0) { force = false; }
|
|
|
if (forTextureDataUpdate && texture && texture._designatedSlot > -1) {
|
|
|
this._activeChannel = texture._designatedSlot;
|
|
|
}
|
|
|
var currentTextureBound = this._boundTexturesCache[this._activeChannel];
|
|
|
var isTextureForRendering = texture && texture._initialSlot > -1;
|
|
|
- if (currentTextureBound !== texture) {
|
|
|
+ if (currentTextureBound !== texture || force) {
|
|
|
if (currentTextureBound) {
|
|
|
this._removeDesignatedSlot(currentTextureBound);
|
|
|
}
|
|
@@ -16156,6 +16157,17 @@ var BABYLON;
|
|
|
this._gl.uniform1i(uniform, destination);
|
|
|
uniform._currentState = destination;
|
|
|
};
|
|
|
+ Engine.prototype._getTextureWrapMode = function (mode) {
|
|
|
+ switch (mode) {
|
|
|
+ case BABYLON.Texture.WRAP_ADDRESSMODE:
|
|
|
+ return this._gl.REPEAT;
|
|
|
+ case BABYLON.Texture.CLAMP_ADDRESSMODE:
|
|
|
+ return this._gl.CLAMP_TO_EDGE;
|
|
|
+ case BABYLON.Texture.MIRROR_ADDRESSMODE:
|
|
|
+ return this._gl.MIRRORED_REPEAT;
|
|
|
+ }
|
|
|
+ return this._gl.REPEAT;
|
|
|
+ };
|
|
|
Engine.prototype._setTexture = function (channel, texture, isPartOfTextureArray, depthStencilTexture) {
|
|
|
if (isPartOfTextureArray === void 0) { isPartOfTextureArray = false; }
|
|
|
if (depthStencilTexture === void 0) { depthStencilTexture = false; }
|
|
@@ -16214,45 +16226,15 @@ var BABYLON;
|
|
|
}
|
|
|
if (internalTexture && internalTexture._cachedWrapU !== texture.wrapU) {
|
|
|
internalTexture._cachedWrapU = texture.wrapU;
|
|
|
- switch (texture.wrapU) {
|
|
|
- case BABYLON.Texture.WRAP_ADDRESSMODE:
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_3D, this._gl.TEXTURE_WRAP_S, this._gl.REPEAT);
|
|
|
- break;
|
|
|
- case BABYLON.Texture.CLAMP_ADDRESSMODE:
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_3D, this._gl.TEXTURE_WRAP_S, this._gl.CLAMP_TO_EDGE);
|
|
|
- break;
|
|
|
- case BABYLON.Texture.MIRROR_ADDRESSMODE:
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_3D, this._gl.TEXTURE_WRAP_S, this._gl.MIRRORED_REPEAT);
|
|
|
- break;
|
|
|
- }
|
|
|
+ this._setTextureParameterInteger(this._gl.TEXTURE_3D, this._gl.TEXTURE_WRAP_S, this._getTextureWrapMode(texture.wrapU), internalTexture);
|
|
|
}
|
|
|
if (internalTexture && internalTexture._cachedWrapV !== texture.wrapV) {
|
|
|
internalTexture._cachedWrapV = texture.wrapV;
|
|
|
- switch (texture.wrapV) {
|
|
|
- case BABYLON.Texture.WRAP_ADDRESSMODE:
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_3D, this._gl.TEXTURE_WRAP_T, this._gl.REPEAT);
|
|
|
- break;
|
|
|
- case BABYLON.Texture.CLAMP_ADDRESSMODE:
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_3D, this._gl.TEXTURE_WRAP_T, this._gl.CLAMP_TO_EDGE);
|
|
|
- break;
|
|
|
- case BABYLON.Texture.MIRROR_ADDRESSMODE:
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_3D, this._gl.TEXTURE_WRAP_T, this._gl.MIRRORED_REPEAT);
|
|
|
- break;
|
|
|
- }
|
|
|
+ this._setTextureParameterInteger(this._gl.TEXTURE_3D, this._gl.TEXTURE_WRAP_T, this._getTextureWrapMode(texture.wrapV), internalTexture);
|
|
|
}
|
|
|
if (internalTexture && internalTexture._cachedWrapR !== texture.wrapR) {
|
|
|
internalTexture._cachedWrapR = texture.wrapR;
|
|
|
- switch (texture.wrapR) {
|
|
|
- case BABYLON.Texture.WRAP_ADDRESSMODE:
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_3D, this._gl.TEXTURE_WRAP_R, this._gl.REPEAT);
|
|
|
- break;
|
|
|
- case BABYLON.Texture.CLAMP_ADDRESSMODE:
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_3D, this._gl.TEXTURE_WRAP_R, this._gl.CLAMP_TO_EDGE);
|
|
|
- break;
|
|
|
- case BABYLON.Texture.MIRROR_ADDRESSMODE:
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_3D, this._gl.TEXTURE_WRAP_R, this._gl.MIRRORED_REPEAT);
|
|
|
- break;
|
|
|
- }
|
|
|
+ this._setTextureParameterInteger(this._gl.TEXTURE_3D, this._gl.TEXTURE_WRAP_R, this._getTextureWrapMode(texture.wrapR), internalTexture);
|
|
|
}
|
|
|
this._setAnisotropicLevel(this._gl.TEXTURE_3D, texture);
|
|
|
}
|
|
@@ -16264,8 +16246,8 @@ var BABYLON;
|
|
|
internalTexture._cachedCoordinatesMode = texture.coordinatesMode;
|
|
|
// CUBIC_MODE and SKYBOX_MODE both require CLAMP_TO_EDGE. All other modes use REPEAT.
|
|
|
var textureWrapMode = (texture.coordinatesMode !== BABYLON.Texture.CUBIC_MODE && texture.coordinatesMode !== BABYLON.Texture.SKYBOX_MODE) ? this._gl.REPEAT : this._gl.CLAMP_TO_EDGE;
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_WRAP_S, textureWrapMode);
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_WRAP_T, textureWrapMode);
|
|
|
+ this._setTextureParameterInteger(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_WRAP_S, textureWrapMode, internalTexture);
|
|
|
+ this._setTextureParameterInteger(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_WRAP_T, textureWrapMode);
|
|
|
}
|
|
|
this._setAnisotropicLevel(this._gl.TEXTURE_CUBE_MAP, texture);
|
|
|
}
|
|
@@ -16275,31 +16257,11 @@ var BABYLON;
|
|
|
}
|
|
|
if (internalTexture && internalTexture._cachedWrapU !== texture.wrapU) {
|
|
|
internalTexture._cachedWrapU = texture.wrapU;
|
|
|
- switch (texture.wrapU) {
|
|
|
- case BABYLON.Texture.WRAP_ADDRESSMODE:
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.REPEAT);
|
|
|
- break;
|
|
|
- case BABYLON.Texture.CLAMP_ADDRESSMODE:
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.CLAMP_TO_EDGE);
|
|
|
- break;
|
|
|
- case BABYLON.Texture.MIRROR_ADDRESSMODE:
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.MIRRORED_REPEAT);
|
|
|
- break;
|
|
|
- }
|
|
|
+ this._setTextureParameterInteger(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._getTextureWrapMode(texture.wrapU), internalTexture);
|
|
|
}
|
|
|
if (internalTexture && internalTexture._cachedWrapV !== texture.wrapV) {
|
|
|
internalTexture._cachedWrapV = texture.wrapV;
|
|
|
- switch (texture.wrapV) {
|
|
|
- case BABYLON.Texture.WRAP_ADDRESSMODE:
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.REPEAT);
|
|
|
- break;
|
|
|
- case BABYLON.Texture.CLAMP_ADDRESSMODE:
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.CLAMP_TO_EDGE);
|
|
|
- break;
|
|
|
- case BABYLON.Texture.MIRROR_ADDRESSMODE:
|
|
|
- this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.MIRRORED_REPEAT);
|
|
|
- break;
|
|
|
- }
|
|
|
+ this._setTextureParameterInteger(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._getTextureWrapMode(texture.wrapV), internalTexture);
|
|
|
}
|
|
|
this._setAnisotropicLevel(this._gl.TEXTURE_2D, texture);
|
|
|
}
|
|
@@ -16327,7 +16289,7 @@ var BABYLON;
|
|
|
}
|
|
|
};
|
|
|
/** @ignore */
|
|
|
- Engine.prototype._setAnisotropicLevel = function (key, texture) {
|
|
|
+ Engine.prototype._setAnisotropicLevel = function (target, texture) {
|
|
|
var internalTexture = texture.getInternalTexture();
|
|
|
if (!internalTexture) {
|
|
|
return;
|
|
@@ -16340,10 +16302,20 @@ var BABYLON;
|
|
|
value = 1; // Forcing the anisotropic to 1 because else webgl will force filters to linear
|
|
|
}
|
|
|
if (anisotropicFilterExtension && internalTexture._cachedAnisotropicFilteringLevel !== value) {
|
|
|
- this._gl.texParameterf(key, anisotropicFilterExtension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(value, this._caps.maxAnisotropy));
|
|
|
+ this._setTextureParameterFloat(target, anisotropicFilterExtension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(value, this._caps.maxAnisotropy), internalTexture);
|
|
|
internalTexture._cachedAnisotropicFilteringLevel = value;
|
|
|
}
|
|
|
};
|
|
|
+ Engine.prototype._setTextureParameterFloat = function (target, parameter, value, texture) {
|
|
|
+ this._bindTextureDirectly(target, texture, true, true);
|
|
|
+ this._gl.texParameterf(target, parameter, value);
|
|
|
+ };
|
|
|
+ Engine.prototype._setTextureParameterInteger = function (target, parameter, value, texture) {
|
|
|
+ if (texture) {
|
|
|
+ this._bindTextureDirectly(target, texture, true, true);
|
|
|
+ }
|
|
|
+ this._gl.texParameteri(target, parameter, value);
|
|
|
+ };
|
|
|
/**
|
|
|
* Reads pixels from the current frame buffer. Please note that this function can be slow
|
|
|
* @param x defines the x coordinate of the rectangle where pixels must be read
|