'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var Texture = require('../../../../../rendering/renderers/shared/texture/Texture.js');
var warn = require('../../../../../utils/logging/warn.js');
var Cache = require('../../../../cache/Cache.js');

function createTexture(source, loader, url) {
  const texture = new Texture.Texture({
    source,
    label: url
  });
  const unload = () => {
    delete loader.promiseCache[url];
    if (Cache.Cache.has(url)) {
      Cache.Cache.remove(url);
    }
  };
  texture.once("destroy", () => {
    if (url in loader.promiseCache) {
      warn.warn("[Assets] A BaseTexture managed by Assets was destroyed instead of unloaded! Use Assets.unload() instead of destroying the BaseTexture.");
      unload();
    }
  });
  texture.source.once("destroy", () => {
    if (!source.destroyed) {
      warn.warn("[Assets] A Texture managed by Assets was destroyed instead of unloaded! Use Assets.unload() instead of destroying the Texture.");
      unload();
    }
  });
  return texture;
}

exports.createTexture = createTexture;
//# sourceMappingURL=createTexture.js.map
