7.25 kBSource Map (JSON)View Raw
1{"version":3,"file":"RenderTexture.mjs","sources":["../../src/renderTexture/RenderTexture.ts"],"sourcesContent":["import { Texture } from '../textures/Texture';\nimport { BaseRenderTexture } from './BaseRenderTexture';\n\nimport type { MSAA_QUALITY } from '@pixi/constants';\nimport type { Rectangle } from '@pixi/math';\nimport type { Framebuffer } from '../framebuffer/Framebuffer';\nimport type { IBaseTextureOptions } from '../textures/BaseTexture';\n\n/**\n * A RenderTexture is a special texture that allows any PixiJS display object to be rendered to it.\n *\n * __Hint__: All DisplayObjects (i.e. Sprites) that render to a RenderTexture should be preloaded\n * otherwise black rectangles will be drawn instead.\n *\n * __Hint-2__: The actual memory allocation will happen on first render.\n * You shouldn't create renderTextures each frame just to delete them after, try to reuse them.\n *\n * A RenderTexture takes a snapshot of any Display Object given to its render method. For example:\n * @example\n * import { autoDetectRenderer, RenderTexture, Sprite } from 'pixi.js';\n *\n * const renderer = autoDetectRenderer();\n * const renderTexture = RenderTexture.create({ width: 800, height: 600 });\n * const sprite = Sprite.from('spinObj_01.png');\n *\n * sprite.position.x = 800 / 2;\n * sprite.position.y = 600 / 2;\n * sprite.anchor.x = 0.5;\n * sprite.anchor.y = 0.5;\n *\n * renderer.render(sprite, { renderTexture });\n *\n * // Note that you should not create a new renderer, but reuse the same one as the rest of the application.\n * // The Sprite in this case will be rendered using its local transform. To render this sprite at 0,0\n * // you can clear the transform\n *\n * sprite.setTransform();\n *\n * const renderTexture = new RenderTexture.create({ width: 100, height: 100 });\n *\n * renderer.render(sprite, { renderTexture }); // Renders to center of RenderTexture\n * @memberof PIXI\n */\nexport class RenderTexture extends Texture\n{\n public baseTexture: BaseRenderTexture;\n\n /**\n * Stores `sourceFrame` when this texture is inside current filter stack.\n *\n * You can read it inside filters.\n * @readonly\n */\n public filterFrame: Rectangle | null;\n\n /**\n * The key for pooled texture of FilterSystem.\n * @see PIXI.RenderTexturePool\n */\n public filterPoolKey: string | number | null;\n\n /**\n * @param baseRenderTexture - The base texture object that this texture uses.\n * @param frame - The rectangle frame of the texture to show.\n */\n constructor(baseRenderTexture: BaseRenderTexture, frame?: Rectangle)\n {\n super(baseRenderTexture, frame);\n\n this.valid = true;\n\n this.filterFrame = null;\n this.filterPoolKey = null;\n\n this.updateUvs();\n }\n\n /**\n * Shortcut to `this.baseTexture.framebuffer`, saves baseTexture cast.\n * @readonly\n */\n get framebuffer(): Framebuffer\n {\n return this.baseTexture.framebuffer;\n }\n\n /**\n * Shortcut to `this.framebuffer.multisample`.\n * @default PIXI.MSAA_QUALITY.NONE\n */\n get multisample(): MSAA_QUALITY\n {\n return this.framebuffer.multisample;\n }\n\n set multisample(value: MSAA_QUALITY)\n {\n this.framebuffer.multisample = value;\n }\n\n /**\n * Resizes the RenderTexture.\n * @param desiredWidth - The desired width to resize to.\n * @param desiredHeight - The desired height to resize to.\n * @param resizeBaseTexture - Should the baseTexture.width and height values be resized as well?\n */\n resize(desiredWidth: number, desiredHeight: number, resizeBaseTexture = true): void\n {\n const resolution = this.baseTexture.resolution;\n const width = Math.round(desiredWidth * resolution) / resolution;\n const height = Math.round(desiredHeight * resolution) / resolution;\n\n // TODO - could be not required..\n this.valid = (width > 0 && height > 0);\n\n this._frame.width = this.orig.width = width;\n this._frame.height = this.orig.height = height;\n\n if (resizeBaseTexture)\n {\n this.baseTexture.resize(width, height);\n }\n\n this.updateUvs();\n }\n\n /**\n * Changes the resolution of baseTexture, but does not change framebuffer size.\n * @param resolution - The new resolution to apply to RenderTexture\n */\n setResolution(resolution: number): void\n {\n const { baseTexture } = this;\n\n if (baseTexture.resolution === resolution)\n {\n return;\n }\n\n baseTexture.setResolution(resolution);\n this.resize(baseTexture.width, baseTexture.height, false);\n }\n\n /**\n * A short hand way of creating a render texture.\n * @param options - Options\n * @param {number} [options.width=100] - The width of the render texture\n * @param {number} [options.height=100] - The height of the render texture\n * @param {PIXI.SCALE_MODES} [options.scaleMode=PIXI.BaseTexture.defaultOptions.scaleMode] - See {@link PIXI.SCALE_MODES}\n * for possible values\n * @param {number} [options.resolution=PIXI.settings.RESOLUTION] - The resolution / device pixel ratio of the texture\n * being generated\n * @param {PIXI.MSAA_QUALITY} [options.multisample=PIXI.MSAA_QUALITY.NONE] - The number of samples of the frame buffer\n * @returns The new render texture\n */\n static create(options?: IBaseTextureOptions): RenderTexture\n {\n return new RenderTexture(new BaseRenderTexture(options));\n }\n}\n"],"names":[],"mappings":";;;AA2CO,MAAM,sBAAsB,OACnC,CAAA;AAAA,EAqBI,WAAA,CAAY,mBAAsC,KAClD,EAAA;AACI,IAAA,KAAA,CAAM,mBAAmB,KAAK,CAAA,CAAA;AAE9B,IAAA,IAAA,CAAK,KAAQ,GAAA,IAAA,CAAA;AAEb,IAAA,IAAA,CAAK,WAAc,GAAA,IAAA,CAAA;AACnB,IAAA,IAAA,CAAK,aAAgB,GAAA,IAAA,CAAA;AAErB,IAAA,IAAA,CAAK,SAAU,EAAA,CAAA;AAAA,GACnB;AAAA,EAMA,IAAI,WACJ,GAAA;AACI,IAAA,OAAO,KAAK,WAAY,CAAA,WAAA,CAAA;AAAA,GAC5B;AAAA,EAMA,IAAI,WACJ,GAAA;AACI,IAAA,OAAO,KAAK,WAAY,CAAA,WAAA,CAAA;AAAA,GAC5B;AAAA,EAEA,IAAI,YAAY,KAChB,EAAA;AACI,IAAA,IAAA,CAAK,YAAY,WAAc,GAAA,KAAA,CAAA;AAAA,GACnC;AAAA,EAQA,MAAO,CAAA,YAAA,EAAsB,aAAuB,EAAA,iBAAA,GAAoB,IACxE,EAAA;AACI,IAAM,MAAA,UAAA,GAAa,KAAK,WAAY,CAAA,UAAA,CAAA;AACpC,IAAA,MAAM,KAAQ,GAAA,IAAA,CAAK,KAAM,CAAA,YAAA,GAAe,UAAU,CAAI,GAAA,UAAA,CAAA;AACtD,IAAA,MAAM,MAAS,GAAA,IAAA,CAAK,KAAM,CAAA,aAAA,GAAgB,UAAU,CAAI,GAAA,UAAA,CAAA;AAGxD,IAAK,IAAA,CAAA,KAAA,G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