UNPKG

6.68 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,QACnC;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBI,YAAY,mBAAsC,OAClD;AACI,UAAM,mBAAmB,KAAK,GAEzB,KAAA,QAAQ,IAEb,KAAK,cAAc,MACnB,KAAK,gBAAgB,MAErB,KAAK,UAAU;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,cACJ;AACI,WAAO,KAAK,YAAY;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,cACJ;AACI,WAAO,KAAK,YAAY;AAAA,EAC5B;AAAA,EAEA,IAAI,YAAY,OAChB;AACI,SAAK,YAAY,cAAc;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,cAAsB,eAAuB,oBAAoB,IACxE;AACI,UAAM,aAAa,KAAK,YAAY,YAC9B,QAAQ,KAAK,MAAM,eAAe,UAAU,IAAI,YAChD,SAAS,KAAK,MAAM,gBAAgB,UAAU,IAAI;AAGnD,SAAA,QAAS,QAAQ,KAAK,SAAS,GAEpC,KAAK,OAAO,QAAQ,KAAK,KAAK,QAAQ,OACtC,KAAK,OAAO,SAAS,KAAK,KAAK,SAAS,QAEpC,qBAEA,KAAK,YAAY,OAAO,OAAO,MAAM,GAGzC,KAAK,UAAU;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,cAAc,YACd;AACU,UAAA,EAAE,YAAgB,IAAA;AAEpB,gBAAY,eAAe,eAK/B,YAAY,cAAc,UAAU,GACpC,KAAK,OAAO,YAAY,OAAO,YAAY,QAAQ,EAAK;AAAA,EAC5D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,OAAO,OAAO,SACd;AACI,WAAO,IAAI,cAAc,IAAI,kBAAkB,OAAO,CAAC;AAAA,EAC3D;AACJ;"}
\No newline at end of file