|
@@ -834,16 +834,23 @@ var BABYLON;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
- Engine.prototype.bindFramebuffer = function (texture) {
|
|
|
+ Engine.prototype.bindFramebuffer = function (texture, faceIndex) {
|
|
|
this._currentRenderTarget = texture;
|
|
|
var gl = this._gl;
|
|
|
gl.bindFramebuffer(gl.FRAMEBUFFER, texture._framebuffer);
|
|
|
+ if (texture.isCube) {
|
|
|
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, texture, 0);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
|
+ }
|
|
|
this._gl.viewport(0, 0, texture._width, texture._height);
|
|
|
this.wipeCaches();
|
|
|
};
|
|
|
- Engine.prototype.unBindFramebuffer = function (texture) {
|
|
|
+ Engine.prototype.unBindFramebuffer = function (texture, disableGenerateMipMaps) {
|
|
|
+ if (disableGenerateMipMaps === void 0) { disableGenerateMipMaps = false; }
|
|
|
this._currentRenderTarget = null;
|
|
|
- if (texture.generateMipMaps) {
|
|
|
+ if (texture.generateMipMaps && !disableGenerateMipMaps) {
|
|
|
var gl = this._gl;
|
|
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
|
gl.generateMipmap(gl.TEXTURE_2D);
|
|
@@ -851,6 +858,14 @@ var BABYLON;
|
|
|
}
|
|
|
this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, null);
|
|
|
};
|
|
|
+ Engine.prototype.generateMipMapsForCubemap = function (texture) {
|
|
|
+ if (texture.generateMipMaps) {
|
|
|
+ var gl = this._gl;
|
|
|
+ gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
|
|
|
+ gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
|
|
|
+ gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
|
|
|
+ }
|
|
|
+ };
|
|
|
Engine.prototype.flushFramebuffer = function () {
|
|
|
this._gl.flush();
|
|
|
};
|
|
@@ -1210,7 +1225,7 @@ var BABYLON;
|
|
|
var showSide = reverseSide ? this._gl.FRONT : this._gl.BACK;
|
|
|
var hideSide = reverseSide ? this._gl.BACK : this._gl.FRONT;
|
|
|
var cullFace = this.cullBackFaces ? showSide : hideSide;
|
|
|
- if (this._depthCullingState.cull !== culling || force || this._depthCullingState.cullFace != cullFace) {
|
|
|
+ if (this._depthCullingState.cull !== culling || force || this._depthCullingState.cullFace !== cullFace) {
|
|
|
if (culling) {
|
|
|
this._depthCullingState.cullFace = cullFace;
|
|
|
this._depthCullingState.cull = true;
|
|
@@ -1235,7 +1250,7 @@ var BABYLON;
|
|
|
this._gl.colorMask(enable, enable, enable, enable);
|
|
|
};
|
|
|
Engine.prototype.setAlphaMode = function (mode) {
|
|
|
- if (this._alphaMode == mode) {
|
|
|
+ if (this._alphaMode === mode) {
|
|
|
return;
|
|
|
}
|
|
|
switch (mode) {
|
|
@@ -1347,8 +1362,9 @@ var BABYLON;
|
|
|
onError();
|
|
|
}
|
|
|
};
|
|
|
+ var callback;
|
|
|
if (isTGA) {
|
|
|
- var callback = function (arrayBuffer) {
|
|
|
+ callback = function (arrayBuffer) {
|
|
|
var data = new Uint8Array(arrayBuffer);
|
|
|
var header = BABYLON.Internals.TGATools.GetTGAHeader(data);
|
|
|
prepareWebGLTexture(texture, _this._gl, scene, header.width, header.height, invertY, noMipmap, false, function () {
|
|
@@ -1556,7 +1572,7 @@ var BABYLON;
|
|
|
texture._isDisabled = true;
|
|
|
}
|
|
|
};
|
|
|
- Engine.prototype.createRenderTargetTexture = function (size, options, face) {
|
|
|
+ Engine.prototype.createRenderTargetTexture = function (size, options) {
|
|
|
// old version had a "generateMipMaps" arg instead of options.
|
|
|
// if options.generateMipMaps is undefined, consider that options itself if the generateMipmaps value
|
|
|
// in the same way, generateDepthBuffer is defaulted to true
|
|
@@ -1565,7 +1581,7 @@ var BABYLON;
|
|
|
var type = Engine.TEXTURETYPE_UNSIGNED_INT;
|
|
|
var samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE;
|
|
|
if (options !== undefined) {
|
|
|
- generateMipMaps = options.generateMipMaps === undefined ? options : options.generateMipmaps;
|
|
|
+ generateMipMaps = options.generateMipMaps === undefined ? options : options.generateMipMaps;
|
|
|
generateDepthBuffer = options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;
|
|
|
type = options.type === undefined ? type : options.type;
|
|
|
if (options.samplingMode !== undefined) {
|
|
@@ -1586,14 +1602,11 @@ var BABYLON;
|
|
|
type = Engine.TEXTURETYPE_UNSIGNED_INT;
|
|
|
BABYLON.Tools.Warn("Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type");
|
|
|
}
|
|
|
- if (face === undefined) {
|
|
|
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filters.mag);
|
|
|
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filters.min);
|
|
|
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
|
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
|
- }
|
|
|
- var target = face === undefined ? gl.TEXTURE_2D : (gl.TEXTURE_CUBE_MAP_POSITIVE_X + face);
|
|
|
- gl.texImage2D(target, 0, gl.RGBA, width, height, 0, gl.RGBA, getWebGLTextureType(gl, type), null);
|
|
|
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filters.mag);
|
|
|
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filters.min);
|
|
|
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
|
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
|
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, getWebGLTextureType(gl, type), null);
|
|
|
var depthBuffer;
|
|
|
// Create the depth buffer
|
|
|
if (generateDepthBuffer) {
|
|
@@ -1604,7 +1617,6 @@ var BABYLON;
|
|
|
// Create the framebuffer
|
|
|
var framebuffer = gl.createFramebuffer();
|
|
|
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
|
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
|
if (generateDepthBuffer) {
|
|
|
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuffer);
|
|
|
}
|
|
@@ -1629,22 +1641,45 @@ var BABYLON;
|
|
|
this._loadedTexturesCache.push(texture);
|
|
|
return texture;
|
|
|
};
|
|
|
- Engine.prototype.createRenderTargetCubeTexture = function (size) {
|
|
|
+ Engine.prototype.createRenderTargetCubeTexture = function (size, options) {
|
|
|
var gl = this._gl;
|
|
|
var texture = gl.createTexture();
|
|
|
+ var generateMipMaps = true;
|
|
|
+ var samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE;
|
|
|
+ if (options !== undefined) {
|
|
|
+ generateMipMaps = options.generateMipMaps === undefined ? options : options.generateMipMaps;
|
|
|
+ if (options.samplingMode !== undefined) {
|
|
|
+ samplingMode = options.samplingMode;
|
|
|
+ }
|
|
|
+ }
|
|
|
texture.isCube = true;
|
|
|
texture.references = 1;
|
|
|
- this._loadedTexturesCache.push(texture);
|
|
|
+ texture.generateMipMaps = generateMipMaps;
|
|
|
+ texture.references = 1;
|
|
|
+ texture.samplingMode = samplingMode;
|
|
|
+ var filters = getSamplingParameters(samplingMode, generateMipMaps, gl);
|
|
|
gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
|
|
|
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
|
|
|
for (var face = 0; face < 6; face++) {
|
|
|
- texture._cubeFaces[face] = this.createRenderTargetTexture(size, {}, face);
|
|
|
+ gl.texImage2D((gl.TEXTURE_CUBE_MAP_POSITIVE_X + face), 0, gl.RGBA, size, size, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
|
}
|
|
|
- gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
|
- gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
|
+ gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, filters.mag);
|
|
|
+ gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, filters.min);
|
|
|
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
|
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
|
+ // Create the depth buffer
|
|
|
+ var depthBuffer = gl.createRenderbuffer();
|
|
|
+ gl.bindRenderbuffer(gl.RENDERBUFFER, depthBuffer);
|
|
|
+ gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, size, size);
|
|
|
+ // Create the framebuffer
|
|
|
+ var framebuffer = gl.createFramebuffer();
|
|
|
+ gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
|
+ gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuffer);
|
|
|
+ // Unbind
|
|
|
gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
|
|
|
+ gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
|
|
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
|
+ texture._framebuffer = framebuffer;
|
|
|
+ texture._depthBuffer = depthBuffer;
|
|
|
this._activeTexturesCache = [];
|
|
|
texture._width = size;
|
|
|
texture._height = size;
|
|
@@ -1658,7 +1693,6 @@ var BABYLON;
|
|
|
texture.isCube = true;
|
|
|
texture.url = rootUrl;
|
|
|
texture.references = 1;
|
|
|
- this._loadedTexturesCache.push(texture);
|
|
|
var extension = rootUrl.substr(rootUrl.length - 4, 4).toLowerCase();
|
|
|
var isDDS = this.getCaps().s3tc && (extension === ".dds");
|
|
|
if (isDDS) {
|
|
@@ -1847,18 +1881,14 @@ var BABYLON;
|
|
|
if (!texture) {
|
|
|
return;
|
|
|
}
|
|
|
- var index;
|
|
|
- if (texture._cubeFaces) {
|
|
|
- for (index = 0; index < 6; index++) {
|
|
|
- this.releaseInternalTexture(texture._cubeFaces[index]);
|
|
|
- }
|
|
|
- }
|
|
|
- var texturesCache = this.getLoadedTexturesCache();
|
|
|
texture.references--;
|
|
|
// Final reference ?
|
|
|
if (texture.references === 0) {
|
|
|
- index = texturesCache.indexOf(texture);
|
|
|
- texturesCache.splice(index, 1);
|
|
|
+ var texturesCache = this.getLoadedTexturesCache();
|
|
|
+ var index = texturesCache.indexOf(texture);
|
|
|
+ if (index > -1) {
|
|
|
+ texturesCache.splice(index, 1);
|
|
|
+ }
|
|
|
this._releaseTexture(texture);
|
|
|
}
|
|
|
};
|