import { Texture } from '../../../../../rendering/renderers/shared/texture/Texture.mjs';
import { warn } from '../../../../../utils/logging/warn.mjs';
import { Cache } from '../../../../cache/Cache.mjs';

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

export { createTexture };
//# sourceMappingURL=createTexture.mjs.map
