1 line
2.9 KiB
Plaintext
1 line
2.9 KiB
Plaintext
{"version":3,"file":"getPo2TextureFromSource.mjs","sources":["../../../../src/scene/text/utils/getPo2TextureFromSource.ts"],"sourcesContent":["import { TexturePool } from '../../../rendering/renderers/shared/texture/TexturePool';\nimport { Bounds } from '../../container/bounds/Bounds';\n\nimport type { ICanvas } from '../../../environment/canvas/ICanvas';\nimport type { Texture } from '../../../rendering/renderers/shared/texture/Texture';\n\nconst tempBounds = new Bounds();\n\n/**\n * Takes an image and creates a texture from it, using a power of 2 texture from the texture pool.\n * Remember to return the texture when you don't need it any more!\n * @param image - The image to create a texture from\n * @param width - the frame width of the texture\n * @param height - the frame height of the texture\n * @param resolution - The resolution of the texture\n * @returns - The texture\n */\nexport function getPo2TextureFromSource(\n image: HTMLImageElement | HTMLCanvasElement | ICanvas,\n width: number,\n height: number,\n resolution: number\n): Texture\n{\n const bounds = tempBounds;\n\n bounds.minX = 0;\n bounds.minY = 0;\n\n bounds.maxX = (image.width / resolution) | 0;\n bounds.maxY = (image.height / resolution) | 0;\n\n const texture = TexturePool.getOptimalTexture(\n bounds.width,\n bounds.height,\n resolution,\n false\n );\n\n texture.source.uploadMethodId = 'image';\n texture.source.resource = image;\n texture.source.alphaMode = 'premultiply-alpha-on-upload';\n\n texture.frame.width = width / resolution;\n texture.frame.height = height / resolution;\n\n // We want to update the resource on the GPU,\n // but we do not want to resize the texture.\n // calling `texture.source.update` will fit the resource to the texture\n // causing a resize of the texture on the GPU.\n // which is not what we want!\n texture.source.emit('update', texture.source);\n\n texture.updateUvs();\n\n return texture;\n}\n"],"names":[],"mappings":";;;;AAMA,MAAM,UAAA,GAAa,IAAI,MAAO,EAAA,CAAA;AAWvB,SAAS,uBACZ,CAAA,KAAA,EACA,KACA,EAAA,MAAA,EACA,UAEJ,EAAA;AACI,EAAA,MAAM,MAAS,GAAA,UAAA,CAAA;AAEf,EAAA,MAAA,CAAO,IAAO,GAAA,CAAA,CAAA;AACd,EAAA,MAAA,CAAO,IAAO,GAAA,CAAA,CAAA;AAEd,EAAO,MAAA,CAAA,IAAA,GAAQ,KAAM,CAAA,KAAA,GAAQ,UAAc,GAAA,CAAA,CAAA;AAC3C,EAAO,MAAA,CAAA,IAAA,GAAQ,KAAM,CAAA,MAAA,GAAS,UAAc,GAAA,CAAA,CAAA;AAE5C,EAAA,MAAM,UAAU,WAAY,CAAA,iBAAA;AAAA,IACxB,MAAO,CAAA,KAAA;AAAA,IACP,MAAO,CAAA,MAAA;AAAA,IACP,UAAA;AAAA,IACA,KAAA;AAAA,GACJ,CAAA;AAEA,EAAA,OAAA,CAAQ,OAAO,cAAiB,GAAA,OAAA,CAAA;AAChC,EAAA,OAAA,CAAQ,OAAO,QAAW,GAAA,KAAA,CAAA;AAC1B,EAAA,OAAA,CAAQ,OAAO,SAAY,GAAA,6BAAA,CAAA;AAE3B,EAAQ,OAAA,CAAA,KAAA,CAAM,QAAQ,KAAQ,GAAA,UAAA,CAAA;AAC9B,EAAQ,OAAA,CAAA,KAAA,CAAM,SAAS,MAAS,GAAA,UAAA,CAAA;AAOhC,EAAA,OAAA,CAAQ,MAAO,CAAA,IAAA,CAAK,QAAU,EAAA,OAAA,CAAQ,MAAM,CAAA,CAAA;AAE5C,EAAA,OAAA,CAAQ,SAAU,EAAA,CAAA;AAElB,EAAO,OAAA,OAAA,CAAA;AACX;;;;"} |