|
@@ -1,172 +0,0 @@
|
|
|
-import { Nullable } from "../../types";
|
|
|
-import { InternalTexture, InternalTextureSource } from '../../Materials/Textures/internalTexture';
|
|
|
-import { Constants } from '../constants';
|
|
|
-import { Engine } from '../engine';
|
|
|
-
|
|
|
-declare module "../../Engines/engine" {
|
|
|
- export interface Engine {
|
|
|
- /**
|
|
|
- * 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;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-function _createRawTextureFunction(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 {
|
|
|
- const target = is3D ? this._gl.TEXTURE_3D : this._gl.TEXTURE_2D_ARRAY;
|
|
|
- const source = is3D ? InternalTextureSource.Raw3D : InternalTextureSource.Raw2DArray;
|
|
|
- const 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
|
|
|
- const 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 = _createRawTextureFunction(false);
|
|
|
-Engine.prototype.createRawTexture3D = _createRawTextureFunction(true);
|
|
|
-
|
|
|
-function _updateRawTextureFunction(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 {
|
|
|
- const 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 = _updateRawTextureFunction(false);
|
|
|
-Engine.prototype.updateRawTexture3D = _updateRawTextureFunction(true);
|