{"version":3,"file":"createTexture.mjs","sources":["../../../../../../src/assets/loader/parsers/textures/utils/createTexture.ts"],"sourcesContent":["import { Texture } from '../../../../../rendering/renderers/shared/texture/Texture';\nimport { warn } from '../../../../../utils/logging/warn';\nimport { Cache } from '../../../../cache/Cache';\n\nimport type { TextureSource } from '../../../../../rendering/renderers/shared/texture/sources/TextureSource';\nimport type { Loader } from '../../../Loader';\n\n/**\n * Creates a texture from a source and adds it to the cache.\n * @param source - source of the texture\n * @param loader - loader\n * @param url - url of the texture\n * @ignore\n */\nexport function createTexture(source: TextureSource, loader: Loader, url: string)\n{\n    source.label = url;\n    source._sourceOrigin = url;\n\n    const texture = new Texture({\n        source,\n        label: url,\n    });\n\n    const unload = () =>\n    {\n        delete loader.promiseCache[url];\n\n        if (Cache.has(url))\n        {\n            Cache.remove(url);\n        }\n    };\n\n    // remove the promise from the loader and the url from the cache when the texture is destroyed\n    texture.source.once('destroy', () =>\n    {\n        if (loader.promiseCache[url])\n        {\n            // #if _DEBUG\n            warn('[Assets] A TextureSource managed by Assets was destroyed instead of unloaded! '\n           + 'Use Assets.unload() instead of destroying the TextureSource.');\n            // #endif\n\n            unload();\n        }\n    });\n\n    texture.once('destroy', () =>\n    {\n        if (!source.destroyed)\n        {\n            // #if _DEBUG\n            warn('[Assets] A Texture managed by Assets was destroyed instead of unloaded! '\n             + 'Use Assets.unload() instead of destroying the Texture.');\n            // #endif\n\n            unload();\n        }\n    });\n\n    return texture;\n}\n"],"names":[],"mappings":";;;;;AAcO,SAAS,aAAA,CAAc,MAAA,EAAuB,MAAA,EAAgB,GAAA,EACrE;AACI,EAAA,MAAA,CAAO,KAAA,GAAQ,GAAA;AACf,EAAA,MAAA,CAAO,aAAA,GAAgB,GAAA;AAEvB,EAAA,MAAM,OAAA,GAAU,IAAI,OAAA,CAAQ;AAAA,IACxB,MAAA;AAAA,IACA,KAAA,EAAO;AAAA,GACV,CAAA;AAED,EAAA,MAAM,SAAS,MACf;AACI,IAAA,OAAO,MAAA,CAAO,aAAa,GAAG,CAAA;AAE9B,IAAA,IAAI,KAAA,CAAM,GAAA,CAAI,GAAG,CAAA,EACjB;AACI,MAAA,KAAA,CAAM,OAAO,GAAG,CAAA;AAAA,IACpB;AAAA,EACJ,CAAA;AAGA,EAAA,OAAA,CAAQ,MAAA,CAAO,IAAA,CAAK,SAAA,EAAW,MAC/B;AACI,IAAA,IAAI,MAAA,CAAO,YAAA,CAAa,GAAG,CAAA,EAC3B;AAEI,MAAA,IAAA,CAAK,4IAC0D,CAAA;AAG/D,MAAA,MAAA,EAAO;AAAA,IACX;AAAA,EACJ,CAAC,CAAA;AAED,EAAA,OAAA,CAAQ,IAAA,CAAK,WAAW,MACxB;AACI,IAAA,IAAI,CAAC,OAAO,SAAA,EACZ;AAEI,MAAA,IAAA,CAAK,gIACsD,CAAA;AAG3D,MAAA,MAAA,EAAO;AAAA,IACX;AAAA,EACJ,CAAC,CAAA;AAED,EAAA,OAAO,OAAA;AACX;;;;"}