babylon.baseTexture.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. module BABYLON {
  2. export class BaseTexture {
  3. public name: string;
  4. public delayLoadState = Engine.DELAYLOADSTATE_NONE;
  5. public hasAlpha = false;
  6. public getAlphaFromRGB = false;
  7. public level = 1;
  8. public isCube = false;
  9. public isRenderTarget = false;
  10. public animations = new Array<Animation>();
  11. public onDispose: () => void;
  12. public coordinatesIndex = 0;
  13. public coordinatesMode = Texture.EXPLICIT_MODE;
  14. public wrapU = Texture.WRAP_ADDRESSMODE;
  15. public wrapV = Texture.WRAP_ADDRESSMODE;
  16. public anisotropicFilteringLevel = 4;
  17. public _cachedAnisotropicFilteringLevel: number;
  18. private _scene: Scene;
  19. public _texture: WebGLTexture;
  20. constructor(scene: Scene) {
  21. this._scene = scene;
  22. this._scene.textures.push(this);
  23. }
  24. public getScene(): Scene {
  25. return this._scene;
  26. }
  27. public getTextureMatrix(): Matrix {
  28. return null;
  29. }
  30. public getReflectionTextureMatrix(): Matrix {
  31. return null;
  32. }
  33. public getInternalTexture(): WebGLTexture {
  34. return this._texture;
  35. }
  36. public isReady(): boolean {
  37. if (this.delayLoadState === Engine.DELAYLOADSTATE_NOTLOADED) {
  38. return true;
  39. }
  40. if (this._texture) {
  41. return this._texture.isReady;
  42. }
  43. return false;
  44. }
  45. public getSize(): ISize {
  46. if (this._texture._width) {
  47. return { width: this._texture._width, height: this._texture._height };
  48. }
  49. if (this._texture._size) {
  50. return { width: this._texture._size, height: this._texture._size };
  51. }
  52. return { width: 0, height: 0 };
  53. }
  54. public getBaseSize(): ISize {
  55. if (!this.isReady())
  56. return { width: 0, height: 0 };
  57. if (this._texture._size) {
  58. return { width: this._texture._size, height: this._texture._size };
  59. }
  60. return { width: this._texture._baseWidth, height: this._texture._baseHeight };
  61. }
  62. public scale(ratio: number): void {
  63. }
  64. public get canRescale(): boolean {
  65. return false;
  66. }
  67. public _removeFromCache(url: string, noMipmap: boolean): void {
  68. var texturesCache = this._scene.getEngine().getLoadedTexturesCache();
  69. for (var index = 0; index < texturesCache.length; index++) {
  70. var texturesCacheEntry = texturesCache[index];
  71. if (texturesCacheEntry.url === url && texturesCacheEntry.noMipmap === noMipmap) {
  72. texturesCache.splice(index, 1);
  73. return;
  74. }
  75. }
  76. }
  77. public _getFromCache(url: string, noMipmap: boolean, sampling?: number): WebGLTexture {
  78. var texturesCache = this._scene.getEngine().getLoadedTexturesCache();
  79. for (var index = 0; index < texturesCache.length; index++) {
  80. var texturesCacheEntry = texturesCache[index];
  81. if (texturesCacheEntry.url === url && texturesCacheEntry.noMipmap === noMipmap) {
  82. if (!sampling || sampling === texturesCacheEntry.samplingMode) {
  83. texturesCacheEntry.references++;
  84. return texturesCacheEntry;
  85. }
  86. }
  87. }
  88. return null;
  89. }
  90. public delayLoad(): void {
  91. }
  92. public clone(): BaseTexture {
  93. return null;
  94. }
  95. public releaseInternalTexture(): void {
  96. if (this._texture) {
  97. this._scene.getEngine().releaseInternalTexture(this._texture);
  98. delete this._texture;
  99. }
  100. }
  101. public dispose(): void {
  102. // Animations
  103. this.getScene().stopAnimation(this);
  104. // Remove from scene
  105. var index = this._scene.textures.indexOf(this);
  106. if (index >= 0) {
  107. this._scene.textures.splice(index, 1);
  108. }
  109. if (this._texture === undefined) {
  110. return;
  111. }
  112. // Callback
  113. if (this.onDispose) {
  114. this.onDispose();
  115. }
  116. }
  117. }
  118. }