123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- import { Nullable } from "../../types";
- import { InternalTexture } from "../../Materials/Textures/internalTexture";
- import { Constants } from "../../Engines/constants";
- import { ISize, Size } from '../../Maths/math.size';
- import { ThinEngine } from '../../Engines/thinEngine';
- /**
- * Base class of all the textures in babylon.
- * It groups all the common properties required to work with Thin Engine.
- */
- export class ThinTexture {
- protected _wrapU = Constants.TEXTURE_WRAP_ADDRESSMODE;
- /**
- * | Value | Type | Description |
- * | ----- | ------------------ | ----------- |
- * | 0 | CLAMP_ADDRESSMODE | |
- * | 1 | WRAP_ADDRESSMODE | |
- * | 2 | MIRROR_ADDRESSMODE | |
- */
- public get wrapU() {
- return this._wrapU;
- }
- public set wrapU(value: number) {
- this._wrapU = value;
- }
- protected _wrapV = Constants.TEXTURE_WRAP_ADDRESSMODE;
- /**
- * | Value | Type | Description |
- * | ----- | ------------------ | ----------- |
- * | 0 | CLAMP_ADDRESSMODE | |
- * | 1 | WRAP_ADDRESSMODE | |
- * | 2 | MIRROR_ADDRESSMODE | |
- */
- public get wrapV() {
- return this._wrapV;
- }
- public set wrapV(value: number) {
- this._wrapV = value;
- }
- /**
- * | Value | Type | Description |
- * | ----- | ------------------ | ----------- |
- * | 0 | CLAMP_ADDRESSMODE | |
- * | 1 | WRAP_ADDRESSMODE | |
- * | 2 | MIRROR_ADDRESSMODE | |
- */
- public wrapR = Constants.TEXTURE_WRAP_ADDRESSMODE;
- /**
- * With compliant hardware and browser (supporting anisotropic filtering)
- * this defines the level of anisotropic filtering in the texture.
- * The higher the better but the slower. This defaults to 4 as it seems to be the best tradeoff.
- */
- public anisotropicFilteringLevel = 4;
- /**
- * Define the current state of the loading sequence when in delayed load mode.
- */
- public delayLoadState = Constants.DELAYLOADSTATE_NONE;
- /**
- * How a texture is mapped.
- * Unused in thin texture mode.
- */
- public get coordinatesMode(): number {
- return 0;
- }
- /**
- * Define if the texture is a cube texture or if false a 2d texture.
- */
- public get isCube(): boolean {
- if (!this._texture) {
- return false;
- }
- return this._texture.isCube;
- }
- public set isCube(value: boolean) {
- if (!this._texture) {
- return;
- }
- this._texture.isCube = value;
- }
- /**
- * Define if the texture is a 3d texture (webgl 2) or if false a 2d texture.
- */
- public get is3D(): boolean {
- if (!this._texture) {
- return false;
- }
- return this._texture.is3D;
- }
- public set is3D(value: boolean) {
- if (!this._texture) {
- return;
- }
- this._texture.is3D = value;
- }
- /**
- * Define if the texture is a 2d array texture (webgl 2) or if false a 2d texture.
- */
- public get is2DArray(): boolean {
- if (!this._texture) {
- return false;
- }
- return this._texture.is2DArray;
- }
- public set is2DArray(value: boolean) {
- if (!this._texture) {
- return;
- }
- this._texture.is2DArray = value;
- }
- /**
- * Get the class name of the texture.
- * @returns "ThinTexture"
- */
- public getClassName(): string {
- return "ThinTexture";
- }
- /** @hidden */
- public _texture: Nullable<InternalTexture> = null;
- protected _engine: Nullable<ThinEngine> = null;
- private _cachedSize: ISize = Size.Zero();
- private _cachedBaseSize: ISize = Size.Zero();
- /**
- * Instantiates a new ThinTexture.
- * Base class of all the textures in babylon.
- * This can be used as an internal texture wrapper in ThinEngine to benefit from the cache
- * @param internalTexture Define the internalTexture to wrap
- */
- constructor(internalTexture: Nullable<InternalTexture>) {
- this._texture = internalTexture;
- if (this._texture) {
- this._engine = this._texture.getEngine();
- }
- }
- /**
- * Get if the texture is ready to be used (downloaded, converted, mip mapped...).
- * @returns true if fully ready
- */
- public isReady(): boolean {
- if (this.delayLoadState === Constants.DELAYLOADSTATE_NOTLOADED) {
- this.delayLoad();
- return false;
- }
- if (this._texture) {
- return this._texture.isReady;
- }
- return false;
- }
- /**
- * Triggers the load sequence in delayed load mode.
- */
- public delayLoad(): void {
- }
- /**
- * Get the underlying lower level texture from Babylon.
- * @returns the insternal texture
- */
- public getInternalTexture(): Nullable<InternalTexture> {
- return this._texture;
- }
- /**
- * Get the size of the texture.
- * @returns the texture size.
- */
- public getSize(): ISize {
- if (this._texture) {
- if (this._texture.width) {
- this._cachedSize.width = this._texture.width;
- this._cachedSize.height = this._texture.height;
- return this._cachedSize;
- }
- if (this._texture._size) {
- this._cachedSize.width = this._texture._size;
- this._cachedSize.height = this._texture._size;
- return this._cachedSize;
- }
- }
- return this._cachedSize;
- }
- /**
- * Get the base size of the texture.
- * It can be different from the size if the texture has been resized for POT for instance
- * @returns the base size
- */
- public getBaseSize(): ISize {
- if (!this.isReady() || !this._texture) {
- this._cachedBaseSize.width = 0;
- this._cachedBaseSize.height = 0;
- return this._cachedBaseSize;
- }
- if (this._texture._size) {
- this._cachedBaseSize.width = this._texture._size;
- this._cachedBaseSize.height = this._texture._size;
- return this._cachedBaseSize;
- }
- this._cachedBaseSize.width = this._texture.baseWidth;
- this._cachedBaseSize.height = this._texture.baseHeight;
- return this._cachedBaseSize;
- }
- /**
- * Update the sampling mode of the texture.
- * Default is Trilinear mode.
- *
- * | Value | Type | Description |
- * | ----- | ------------------ | ----------- |
- * | 1 | NEAREST_SAMPLINGMODE or NEAREST_NEAREST_MIPLINEAR | Nearest is: mag = nearest, min = nearest, mip = linear |
- * | 2 | BILINEAR_SAMPLINGMODE or LINEAR_LINEAR_MIPNEAREST | Bilinear is: mag = linear, min = linear, mip = nearest |
- * | 3 | TRILINEAR_SAMPLINGMODE or LINEAR_LINEAR_MIPLINEAR | Trilinear is: mag = linear, min = linear, mip = linear |
- * | 4 | NEAREST_NEAREST_MIPNEAREST | |
- * | 5 | NEAREST_LINEAR_MIPNEAREST | |
- * | 6 | NEAREST_LINEAR_MIPLINEAR | |
- * | 7 | NEAREST_LINEAR | |
- * | 8 | NEAREST_NEAREST | |
- * | 9 | LINEAR_NEAREST_MIPNEAREST | |
- * | 10 | LINEAR_NEAREST_MIPLINEAR | |
- * | 11 | LINEAR_LINEAR | |
- * | 12 | LINEAR_NEAREST | |
- *
- * > _mag_: magnification filter (close to the viewer)
- * > _min_: minification filter (far from the viewer)
- * > _mip_: filter used between mip map levels
- *@param samplingMode Define the new sampling mode of the texture
- */
- public updateSamplingMode(samplingMode: number): void {
- if (this._texture && this._engine) {
- this._engine.updateTextureSamplingMode(samplingMode, this._texture);
- }
- }
- /**
- * Release and destroy the underlying lower level texture aka internalTexture.
- */
- public releaseInternalTexture(): void {
- if (this._texture) {
- this._texture.dispose();
- this._texture = null;
- }
- }
- /**
- * Dispose the texture and release its associated resources.
- */
- public dispose(): void {
- if (this._texture) {
- this.releaseInternalTexture();
- this._engine = null;
- }
- }
- }
|