babylon.baseTexture.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var BaseTexture = (function () {
  4. function BaseTexture(scene) {
  5. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
  6. this.hasAlpha = false;
  7. this.level = 1;
  8. this.isCube = false;
  9. this._scene = scene;
  10. this._scene.textures.push(this);
  11. }
  12. BaseTexture.prototype.getScene = function () {
  13. return this._scene;
  14. };
  15. BaseTexture.prototype.getInternalTexture = function () {
  16. return this._texture;
  17. };
  18. BaseTexture.prototype.isReady = function () {
  19. if (this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
  20. return true;
  21. }
  22. if (this._texture) {
  23. return this._texture.isReady;
  24. }
  25. return false;
  26. };
  27. BaseTexture.prototype.getSize = function () {
  28. if (this._texture._width) {
  29. return { width: this._texture._width, height: this._texture._height };
  30. }
  31. if (this._texture._size) {
  32. return { width: this._texture._size, height: this._texture._size };
  33. }
  34. return { width: 0, height: 0 };
  35. };
  36. BaseTexture.prototype.getBaseSize = function () {
  37. if (!this.isReady())
  38. return { width: 0, height: 0 };
  39. if (this._texture._size) {
  40. return { width: this._texture._size, height: this._texture._size };
  41. }
  42. return { width: this._texture._baseWidth, height: this._texture._baseHeight };
  43. };
  44. BaseTexture.prototype._getFromCache = function (url, noMipmap) {
  45. var texturesCache = this._scene.getEngine().getLoadedTexturesCache();
  46. for (var index = 0; index < texturesCache.length; index++) {
  47. var texturesCacheEntry = texturesCache[index];
  48. if (texturesCacheEntry.url === url && texturesCacheEntry.noMipmap === noMipmap) {
  49. texturesCacheEntry.references++;
  50. return texturesCacheEntry;
  51. }
  52. }
  53. return null;
  54. };
  55. BaseTexture.prototype.delayLoad = function () {
  56. };
  57. BaseTexture.prototype.releaseInternalTexture = function () {
  58. if (!this._texture) {
  59. return;
  60. }
  61. var texturesCache = this._scene.getEngine().getLoadedTexturesCache();
  62. this._texture.references--;
  63. // Final reference ?
  64. if (this._texture.references == 0) {
  65. var index = texturesCache.indexOf(this._texture);
  66. texturesCache.splice(index, 1);
  67. this._scene.getEngine()._releaseTexture(this._texture);
  68. delete this._texture;
  69. }
  70. };
  71. BaseTexture.prototype.dispose = function () {
  72. // Remove from scene
  73. var index = this._scene.textures.indexOf(this);
  74. if (index >= 0) {
  75. this._scene.textures.splice(index, 1);
  76. }
  77. if (this._texture === undefined) {
  78. return;
  79. }
  80. this.releaseInternalTexture();
  81. // Callback
  82. if (this.onDispose) {
  83. this.onDispose();
  84. }
  85. };
  86. return BaseTexture;
  87. })();
  88. BABYLON.BaseTexture = BaseTexture;
  89. })(BABYLON || (BABYLON = {}));
  90. //# sourceMappingURL=babylon.baseTexture.js.map