123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591 |
- import { Nullable } from "../../types";
- import { InternalTexture, InternalTextureSource } from '../../Materials/Textures/internalTexture';
- import { Logger } from '../../Misc/logger';
- import { Tools } from '../../Misc/tools';
- import { Scene } from '../../scene';
- import { Constants } from '../constants';
- import { Engine } from '../engine';
- import { IWebRequest } from '../../Misc/interfaces/iWebRequest';
- declare module "../../Engines/engine" {
- export interface Engine {
- /**
- * Creates a raw texture
- * @param data defines the data to store in the texture
- * @param width defines the width of the texture
- * @param height defines the height of the texture
- * @param format defines the format of the data
- * @param generateMipMaps defines if the engine should generate the mip levels
- * @param invertY defines if data must be stored with Y axis inverted
- * @param samplingMode defines the required sampling mode (Texture.NEAREST_SAMPLINGMODE by default)
- * @param compression defines the compression used (null by default)
- * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)
- * @returns the raw texture inside an InternalTexture
- */
- createRawTexture(data: Nullable<ArrayBufferView>, width: number, height: number, format: number, generateMipMaps: boolean, invertY: boolean, samplingMode: number, compression: Nullable<string>, type: number): InternalTexture;
- /**
- * Update a raw texture
- * @param texture defines the texture to update
- * @param data defines the data to store in the texture
- * @param format defines the format of the data
- * @param invertY defines if data must be stored with Y axis inverted
- */
- updateRawTexture(texture: Nullable<InternalTexture>, data: Nullable<ArrayBufferView>, format: number, invertY: boolean): void;
- /**
- * Update a raw texture
- * @param texture defines the texture to update
- * @param data defines the data to store in the texture
- * @param format defines the format of the data
- * @param invertY defines if data must be stored with Y axis inverted
- * @param compression defines the compression used (null by default)
- * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)
- */
- updateRawTexture(texture: Nullable<InternalTexture>, data: Nullable<ArrayBufferView>, format: number, invertY: boolean, compression: Nullable<string>, type: number): void;
- /**
- * Creates a new raw cube texture
- * @param data defines the array of data to use to create each face
- * @param size defines the size of the textures
- * @param format defines the format of the data
- * @param type defines the type of the data (like Engine.TEXTURETYPE_UNSIGNED_INT)
- * @param generateMipMaps defines if the engine should generate the mip levels
- * @param invertY defines if data must be stored with Y axis inverted
- * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)
- * @param compression defines the compression used (null by default)
- * @returns the cube texture as an InternalTexture
- */
- createRawCubeTexture(data: Nullable<ArrayBufferView[]>, size: number, format: number, type: number, generateMipMaps: boolean, invertY: boolean, samplingMode: number, compression: Nullable<string>): InternalTexture;
- /**
- * Update a raw cube texture
- * @param texture defines the texture to udpdate
- * @param data defines the data to store
- * @param format defines the data format
- * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)
- * @param invertY defines if data must be stored with Y axis inverted
- */
- updateRawCubeTexture(texture: InternalTexture, data: ArrayBufferView[], format: number, type: number, invertY: boolean): void;
- /**
- * Update a raw cube texture
- * @param texture defines the texture to udpdate
- * @param data defines the data to store
- * @param format defines the data format
- * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)
- * @param invertY defines if data must be stored with Y axis inverted
- * @param compression defines the compression used (null by default)
- */
- updateRawCubeTexture(texture: InternalTexture, data: ArrayBufferView[], format: number, type: number, invertY: boolean, compression: Nullable<string>): void;
- /**
- * Update a raw cube texture
- * @param texture defines the texture to udpdate
- * @param data defines the data to store
- * @param format defines the data format
- * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)
- * @param invertY defines if data must be stored with Y axis inverted
- * @param compression defines the compression used (null by default)
- * @param level defines which level of the texture to update
- */
- updateRawCubeTexture(texture: InternalTexture, data: ArrayBufferView[], format: number, type: number, invertY: boolean, compression: Nullable<string>, level: number): void;
- /**
- * Creates a new raw cube texture from a specified url
- * @param url defines the url where the data is located
- * @param scene defines the current scene
- * @param size defines the size of the textures
- * @param format defines the format of the data
- * @param type defines the type fo the data (like Engine.TEXTURETYPE_UNSIGNED_INT)
- * @param noMipmap defines if the engine should avoid generating the mip levels
- * @param callback defines a callback used to extract texture data from loaded data
- * @param mipmapGenerator defines to provide an optional tool to generate mip levels
- * @param onLoad defines a callback called when texture is loaded
- * @param onError defines a callback called if there is an error
- * @returns the cube texture as an InternalTexture
- */
- createRawCubeTextureFromUrl(url: string, scene: Scene, size: number, format: number, type: number, noMipmap: boolean,
- callback: (ArrayBuffer: ArrayBuffer) => Nullable<ArrayBufferView[]>,
- mipmapGenerator: Nullable<((faces: ArrayBufferView[]) => ArrayBufferView[][])>,
- onLoad: Nullable<() => void>,
- onError: Nullable<(message?: string, exception?: any) => void>): InternalTexture;
- /**
- * Creates a new raw cube texture from a specified url
- * @param url defines the url where the data is located
- * @param scene defines the current scene
- * @param size defines the size of the textures
- * @param format defines the format of the data
- * @param type defines the type fo the data (like Engine.TEXTURETYPE_UNSIGNED_INT)
- * @param noMipmap defines if the engine should avoid generating the mip levels
- * @param callback defines a callback used to extract texture data from loaded data
- * @param mipmapGenerator defines to provide an optional tool to generate mip levels
- * @param onLoad defines a callback called when texture is loaded
- * @param onError defines a callback called if there is an error
- * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)
- * @param invertY defines if data must be stored with Y axis inverted
- * @returns the cube texture as an InternalTexture
- */
- createRawCubeTextureFromUrl(url: string, scene: Scene, size: number, format: number, type: number, noMipmap: boolean,
- callback: (ArrayBuffer: ArrayBuffer) => Nullable<ArrayBufferView[]>,
- mipmapGenerator: Nullable<((faces: ArrayBufferView[]) => ArrayBufferView[][])>,
- onLoad: Nullable<() => void>,
- onError: Nullable<(message?: string, exception?: any) => void>,
- samplingMode: number,
- invertY: boolean): InternalTexture;
- /**
- * Creates a new raw 3D texture
- * @param data defines the data used to create the texture
- * @param width defines the width of the texture
- * @param height defines the height of the texture
- * @param depth defines the depth of the texture
- * @param format defines the format of the texture
- * @param generateMipMaps defines if the engine must generate mip levels
- * @param invertY defines if data must be stored with Y axis inverted
- * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)
- * @param compression defines the compressed used (can be null)
- * @param textureType defines the compressed used (can be null)
- * @returns a new raw 3D texture (stored in an InternalTexture)
- */
- createRawTexture3D(data: Nullable<ArrayBufferView>, width: number, height: number, depth: number, format: number, generateMipMaps: boolean, invertY: boolean, samplingMode: number, compression: Nullable<string>, textureType: number): InternalTexture;
- /**
- * Update a raw 3D texture
- * @param texture defines the texture to update
- * @param data defines the data to store
- * @param format defines the data format
- * @param invertY defines if data must be stored with Y axis inverted
- */
- updateRawTexture3D(texture: InternalTexture, data: Nullable<ArrayBufferView>, format: number, invertY: boolean): void;
- /**
- * Update a raw 3D texture
- * @param texture defines the texture to update
- * @param data defines the data to store
- * @param format defines the data format
- * @param invertY defines if data must be stored with Y axis inverted
- * @param compression defines the used compression (can be null)
- * @param textureType defines the texture Type (Engine.TEXTURETYPE_UNSIGNED_INT, Engine.TEXTURETYPE_FLOAT...)
- */
- updateRawTexture3D(texture: InternalTexture, data: Nullable<ArrayBufferView>, format: number, invertY: boolean, compression: Nullable<string>, textureType: number): void;
- /**
- * Creates a new raw 2D array texture
- * @param data defines the data used to create the texture
- * @param width defines the width of the texture
- * @param height defines the height of the texture
- * @param depth defines the number of layers of the texture
- * @param format defines the format of the texture
- * @param generateMipMaps defines if the engine must generate mip levels
- * @param invertY defines if data must be stored with Y axis inverted
- * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)
- * @param compression defines the compressed used (can be null)
- * @param textureType defines the compressed used (can be null)
- * @returns a new raw 2D array texture (stored in an InternalTexture)
- */
- createRawTexture2DArray(data: Nullable<ArrayBufferView>, width: number, height: number, depth: number, format: number, generateMipMaps: boolean, invertY: boolean, samplingMode: number, compression: Nullable<string>, textureType: number): InternalTexture;
- /**
- * Update a raw 2D array texture
- * @param texture defines the texture to update
- * @param data defines the data to store
- * @param format defines the data format
- * @param invertY defines if data must be stored with Y axis inverted
- */
- updateRawTexture2DArray(texture: InternalTexture, data: Nullable<ArrayBufferView>, format: number, invertY: boolean): void;
- /**
- * Update a raw 2D array texture
- * @param texture defines the texture to update
- * @param data defines the data to store
- * @param format defines the data format
- * @param invertY defines if data must be stored with Y axis inverted
- * @param compression defines the used compression (can be null)
- * @param textureType defines the texture Type (Engine.TEXTURETYPE_UNSIGNED_INT, Engine.TEXTURETYPE_FLOAT...)
- */
- updateRawTexture2DArray(texture: InternalTexture, data: Nullable<ArrayBufferView>, format: number, invertY: boolean, compression: Nullable<string>, textureType: number): void;
- }
- }
- Engine.prototype.updateRawTexture = function(texture: Nullable<InternalTexture>, data: Nullable<ArrayBufferView>, format: number, invertY: boolean, compression: Nullable<string> = null, type: number = Constants.TEXTURETYPE_UNSIGNED_INT): void {
- if (!texture) {
- return;
- }
- // Babylon's internalSizedFomat but gl's texImage2D internalFormat
- var internalSizedFomat = this._getRGBABufferInternalSizedFormat(type, format);
- // Babylon's internalFormat but gl's texImage2D format
- var internalFormat = this._getInternalFormat(format);
- var textureType = this._getWebGLTextureType(type);
- this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);
- this._unpackFlipY(invertY === undefined ? true : (invertY ? true : false));
- if (!this._doNotHandleContextLost) {
- texture._bufferView = data;
- texture.format = format;
- texture.type = type;
- texture.invertY = invertY;
- texture._compression = compression;
- }
- if (texture.width % 4 !== 0) {
- this._gl.pixelStorei(this._gl.UNPACK_ALIGNMENT, 1);
- }
- if (compression && data) {
- this._gl.compressedTexImage2D(this._gl.TEXTURE_2D, 0, (<any>this.getCaps().s3tc)[compression], texture.width, texture.height, 0, <DataView>data);
- } else {
- this._gl.texImage2D(this._gl.TEXTURE_2D, 0, internalSizedFomat, texture.width, texture.height, 0, internalFormat, textureType, data);
- }
- if (texture.generateMipMaps) {
- this._gl.generateMipmap(this._gl.TEXTURE_2D);
- }
- this._bindTextureDirectly(this._gl.TEXTURE_2D, null);
- // this.resetTextureCache();
- texture.isReady = true;
- };
- Engine.prototype.createRawTexture = function(data: Nullable<ArrayBufferView>, width: number, height: number, format: number, generateMipMaps: boolean, invertY: boolean, samplingMode: number, compression: Nullable<string> = null, type: number = Constants.TEXTURETYPE_UNSIGNED_INT): InternalTexture {
- var texture = new InternalTexture(this, InternalTextureSource.Raw);
- texture.baseWidth = width;
- texture.baseHeight = height;
- texture.width = width;
- texture.height = height;
- texture.format = format;
- texture.generateMipMaps = generateMipMaps;
- texture.samplingMode = samplingMode;
- texture.invertY = invertY;
- texture._compression = compression;
- texture.type = type;
- if (!this._doNotHandleContextLost) {
- texture._bufferView = data;
- }
- this.updateRawTexture(texture, data, format, invertY, compression, type);
- this._bindTextureDirectly(this._gl.TEXTURE_2D, texture, true);
- // Filters
- var filters = this._getSamplingParameters(samplingMode, generateMipMaps);
- 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);
- if (generateMipMaps) {
- this._gl.generateMipmap(this._gl.TEXTURE_2D);
- }
- this._bindTextureDirectly(this._gl.TEXTURE_2D, null);
- this._internalTexturesCache.push(texture);
- return texture;
- };
- Engine.prototype.createRawCubeTexture = function(data: Nullable<ArrayBufferView[]>, size: number, format: number, type: number,
- generateMipMaps: boolean, invertY: boolean, samplingMode: number,
- compression: Nullable<string> = null): InternalTexture {
- var gl = this._gl;
- var texture = new InternalTexture(this, InternalTextureSource.CubeRaw);
- texture.isCube = true;
- texture.format = format;
- texture.type = type;
- if (!this._doNotHandleContextLost) {
- texture._bufferViewArray = data;
- }
- var textureType = this._getWebGLTextureType(type);
- var internalFormat = this._getInternalFormat(format);
- if (internalFormat === gl.RGB) {
- internalFormat = gl.RGBA;
- }
- // Mipmap generation needs a sized internal format that is both color-renderable and texture-filterable
- if (textureType === gl.FLOAT && !this._caps.textureFloatLinearFiltering) {
- generateMipMaps = false;
- samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;
- Logger.Warn("Float texture filtering is not supported. Mipmap generation and sampling mode are forced to false and TEXTURE_NEAREST_SAMPLINGMODE, respectively.");
- }
- else if (textureType === this._gl.HALF_FLOAT_OES && !this._caps.textureHalfFloatLinearFiltering) {
- generateMipMaps = false;
- samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;
- Logger.Warn("Half float texture filtering is not supported. Mipmap generation and sampling mode are forced to false and TEXTURE_NEAREST_SAMPLINGMODE, respectively.");
- }
- else if (textureType === gl.FLOAT && !this._caps.textureFloatRender) {
- generateMipMaps = false;
- Logger.Warn("Render to float textures is not supported. Mipmap generation forced to false.");
- }
- else if (textureType === gl.HALF_FLOAT && !this._caps.colorBufferFloat) {
- generateMipMaps = false;
- Logger.Warn("Render to half float textures is not supported. Mipmap generation forced to false.");
- }
- var width = size;
- var height = width;
- texture.width = width;
- texture.height = height;
- // Double check on POT to generate Mips.
- var isPot = !this.needPOTTextures || (Tools.IsExponentOfTwo(texture.width) && Tools.IsExponentOfTwo(texture.height));
- if (!isPot) {
- generateMipMaps = false;
- }
- // Upload data if needed. The texture won't be ready until then.
- if (data) {
- this.updateRawCubeTexture(texture, data, format, type, invertY, compression);
- }
- this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, texture, true);
- // Filters
- if (data && generateMipMaps) {
- this._gl.generateMipmap(this._gl.TEXTURE_CUBE_MAP);
- }
- var filters = this._getSamplingParameters(samplingMode, generateMipMaps);
- 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);
- this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);
- texture.generateMipMaps = generateMipMaps;
- return texture;
- };
- Engine.prototype.updateRawCubeTexture = function(texture: InternalTexture, data: ArrayBufferView[], format: number, type: number, invertY: boolean, compression: Nullable<string> = null, level: number = 0): void {
- texture._bufferViewArray = data;
- texture.format = format;
- texture.type = type;
- texture.invertY = invertY;
- texture._compression = compression;
- var gl = this._gl;
- var textureType = this._getWebGLTextureType(type);
- var internalFormat = this._getInternalFormat(format);
- var internalSizedFomat = this._getRGBABufferInternalSizedFormat(type);
- var needConversion = false;
- if (internalFormat === gl.RGB) {
- internalFormat = gl.RGBA;
- needConversion = true;
- }
- this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
- this._unpackFlipY(invertY === undefined ? true : (invertY ? true : false));
- if (texture.width % 4 !== 0) {
- gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
- }
- // Data are known to be in +X +Y +Z -X -Y -Z
- for (let faceIndex = 0; faceIndex < 6; faceIndex++) {
- let faceData = data[faceIndex];
- if (compression) {
- gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, (<any>(this.getCaps().s3tc))[compression], texture.width, texture.height, 0, <DataView>faceData);
- } else {
- if (needConversion) {
- faceData = this._convertRGBtoRGBATextureData(faceData, texture.width, texture.height, type);
- }
- gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, level, internalSizedFomat, texture.width, texture.height, 0, internalFormat, textureType, faceData);
- }
- }
- var isPot = !this.needPOTTextures || (Tools.IsExponentOfTwo(texture.width) && Tools.IsExponentOfTwo(texture.height));
- if (isPot && texture.generateMipMaps && level === 0) {
- this._gl.generateMipmap(this._gl.TEXTURE_CUBE_MAP);
- }
- this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP, null);
- // this.resetTextureCache();
- texture.isReady = true;
- };
- Engine.prototype.createRawCubeTextureFromUrl = function(url: string, scene: Scene, size: number, format: number, type: number, noMipmap: boolean,
- callback: (ArrayBuffer: ArrayBuffer) => Nullable<ArrayBufferView[]>,
- mipmapGenerator: Nullable<((faces: ArrayBufferView[]) => ArrayBufferView[][])>,
- onLoad: Nullable<() => void> = null,
- onError: Nullable<(message?: string, exception?: any) => void> = null,
- samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,
- invertY: boolean = false): InternalTexture {
- var gl = this._gl;
- var texture = this.createRawCubeTexture(null, size, format, type, !noMipmap, invertY, samplingMode, null);
- scene._addPendingData(texture);
- texture.url = url;
- this._internalTexturesCache.push(texture);
- var onerror = (request?: IWebRequest, exception?: any) => {
- scene._removePendingData(texture);
- if (onError && request) {
- onError(request.status + " " + request.statusText, exception);
- }
- };
- var internalCallback = (data: any) => {
- var width = texture.width;
- var faceDataArrays = callback(data);
- if (!faceDataArrays) {
- return;
- }
- if (mipmapGenerator) {
- var textureType = this._getWebGLTextureType(type);
- var internalFormat = this._getInternalFormat(format);
- var internalSizedFomat = this._getRGBABufferInternalSizedFormat(type);
- var needConversion = false;
- if (internalFormat === gl.RGB) {
- internalFormat = gl.RGBA;
- needConversion = true;
- }
- this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
- this._unpackFlipY(false);
- var mipData = mipmapGenerator(faceDataArrays);
- for (var level = 0; level < mipData.length; level++) {
- var mipSize = width >> level;
- for (var faceIndex = 0; faceIndex < 6; faceIndex++) {
- let mipFaceData = mipData[level][faceIndex];
- if (needConversion) {
- mipFaceData = this._convertRGBtoRGBATextureData(mipFaceData, mipSize, mipSize, type);
- }
- gl.texImage2D(faceIndex, level, internalSizedFomat, mipSize, mipSize, 0, internalFormat, textureType, mipFaceData);
- }
- }
- this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);
- }
- else {
- this.updateRawCubeTexture(texture, faceDataArrays, format, type, invertY);
- }
- texture.isReady = true;
- // this.resetTextureCache();
- scene._removePendingData(texture);
- if (onLoad) {
- onLoad();
- }
- };
- this._loadFile(url, (data) => {
- internalCallback(data);
- }, undefined, scene.offlineProvider, true, onerror);
- return texture;
- };
- /**
- * Create a function for createRawTexture3D/createRawTexture2DArray
- * @param is3D true for TEXTURE_3D and false for TEXTURE_2D_ARRAY
- * @hidden
- */
- function _makeCreateRawTextureFunction(is3D: boolean) {
- return function(this: Engine, data: Nullable<ArrayBufferView>, width: number, height: number, depth: number, format: number, generateMipMaps: boolean, invertY: boolean, samplingMode: number, compression: Nullable<string> = null, textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT): InternalTexture {
- var target = is3D ? this._gl.TEXTURE_3D : this._gl.TEXTURE_2D_ARRAY;
- var source = is3D ? InternalTextureSource.Raw3D : InternalTextureSource.Raw2DArray;
- var texture = new InternalTexture(this, source);
- texture.baseWidth = width;
- texture.baseHeight = height;
- texture.baseDepth = depth;
- texture.width = width;
- texture.height = height;
- texture.depth = depth;
- texture.format = format;
- texture.type = textureType;
- texture.generateMipMaps = generateMipMaps;
- texture.samplingMode = samplingMode;
- if (is3D) {
- texture.is3D = true;
- } else {
- texture.is2DArray = true;
- }
- if (!this._doNotHandleContextLost) {
- texture._bufferView = data;
- }
- if (is3D) {
- this.updateRawTexture3D(texture, data, format, invertY, compression, textureType);
- } else {
- this.updateRawTexture2DArray(texture, data, format, invertY, compression, textureType);
- }
- this._bindTextureDirectly(target, texture, true);
- // Filters
- var filters = this._getSamplingParameters(samplingMode, generateMipMaps);
- this._gl.texParameteri(target, this._gl.TEXTURE_MAG_FILTER, filters.mag);
- this._gl.texParameteri(target, this._gl.TEXTURE_MIN_FILTER, filters.min);
- if (generateMipMaps) {
- this._gl.generateMipmap(target);
- }
- this._bindTextureDirectly(target, null);
- this._internalTexturesCache.push(texture);
- return texture;
- };
- }
- Engine.prototype.createRawTexture2DArray = _makeCreateRawTextureFunction(false);
- Engine.prototype.createRawTexture3D = _makeCreateRawTextureFunction(true);
- /**
- * Create a function for updateRawTexture3D/updateRawTexture2DArray
- * @param is3D true for TEXTURE_3D and false for TEXTURE_2D_ARRAY
- * @hidden
- */
- function _makeUpdateRawTextureFunction(is3D: boolean) {
- return function(this: Engine, texture: InternalTexture, data: Nullable<ArrayBufferView>, format: number, invertY: boolean, compression: Nullable<string> = null, textureType: number = Constants.TEXTURETYPE_UNSIGNED_INT): void {
- var target = is3D ? this._gl.TEXTURE_3D : this._gl.TEXTURE_2D_ARRAY;
- var internalType = this._getWebGLTextureType(textureType);
- var internalFormat = this._getInternalFormat(format);
- var internalSizedFomat = this._getRGBABufferInternalSizedFormat(textureType, format);
- this._bindTextureDirectly(target, texture, true);
- this._unpackFlipY(invertY === undefined ? true : (invertY ? true : false));
- if (!this._doNotHandleContextLost) {
- texture._bufferView = data;
- texture.format = format;
- texture.invertY = invertY;
- texture._compression = compression;
- }
- if (texture.width % 4 !== 0) {
- this._gl.pixelStorei(this._gl.UNPACK_ALIGNMENT, 1);
- }
- if (compression && data) {
- this._gl.compressedTexImage3D(target, 0, (<any>this.getCaps().s3tc)[compression], texture.width, texture.height, texture.depth, 0, data);
- } else {
- this._gl.texImage3D(target, 0, internalSizedFomat, texture.width, texture.height, texture.depth, 0, internalFormat, internalType, data);
- }
- if (texture.generateMipMaps) {
- this._gl.generateMipmap(target);
- }
- this._bindTextureDirectly(target, null);
- // this.resetTextureCache();
- texture.isReady = true;
- };
- }
- Engine.prototype.updateRawTexture2DArray = _makeUpdateRawTextureFunction(false);
- Engine.prototype.updateRawTexture3D = _makeUpdateRawTextureFunction(true);
|