UNPKG

7.19 kBSource Map (JSON)View Raw
1{"version":3,"file":"BaseRenderTexture.mjs","sources":["../../src/renderTexture/BaseRenderTexture.ts"],"sourcesContent":["import { Color } from '@pixi/color';\nimport { MIPMAP_MODES, MSAA_QUALITY } from '@pixi/constants';\nimport { Framebuffer } from '../framebuffer/Framebuffer';\nimport { BaseTexture } from '../textures/BaseTexture';\n\nimport type { ColorSource } from '@pixi/color';\nimport type { MaskData } from '../mask/MaskData';\nimport type { IBaseTextureOptions } from '../textures/BaseTexture';\n\nexport interface BaseRenderTexture extends GlobalMixins.BaseRenderTexture, BaseTexture {}\n\n/**\n * A BaseRenderTexture 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 BaseRenderTexture should be preloaded\n * otherwise black rectangles will be drawn instead.\n *\n * A BaseRenderTexture takes a snapshot of any Display Object given to its render method. The position\n * and rotation of the given Display Objects is ignored. For example:\n * @example\n * import { autoDetectRenderer, BaseRenderTexture, RenderTexture, Sprite } from 'pixi.js';\n *\n * const renderer = autoDetectRenderer();\n * const baseRenderTexture = new BaseRenderTexture({ width: 800, height: 600 });\n * const renderTexture = new RenderTexture(baseRenderTexture);\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 * // The Sprite in this case will be rendered using its local transform.\n * // To render this sprite at 0,0 you can clear the transform\n * sprite.setTransform();\n *\n * const baseRenderTexture = new BaseRenderTexture({ width: 100, height: 100 });\n * const renderTexture = new RenderTexture(baseRenderTexture);\n *\n * renderer.render(sprite, { renderTexture }); // Renders to center of RenderTexture\n * @memberof PIXI\n */\nexport class BaseRenderTexture extends BaseTexture\n{\n public _clear: Color;\n\n /**\n * The framebuffer of this base texture.\n * @readonly\n */\n public framebuffer: Framebuffer;\n\n /** The data structure for the stencil masks. */\n maskStack: Array<MaskData>;\n\n /** The data structure for the filters. */\n filterStack: Array<any>;\n\n /**\n * @param options\n * @param {number} [options.width=100] - The width of the base render texture.\n * @param {number} [options.height=100] - The height of the base 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\n * of the texture being generated.\n * @param {PIXI.MSAA_QUALITY} [options.multisample=PIXI.MSAA_QUALITY.NONE] - The number of samples of the frame buffer.\n */\n constructor(options: IBaseTextureOptions = {})\n {\n if (typeof options === 'number')\n {\n /* eslint-disable prefer-rest-params */\n // Backward compatibility of signature\n const width = arguments[0];\n const height = arguments[1];\n const scaleMode = arguments[2];\n const resolution = arguments[3];\n\n options = { width, height, scaleMode, resolution };\n /* eslint-enable prefer-rest-params */\n }\n\n options.width = options.width ?? 100;\n options.height = options.height ?? 100;\n options.multisample ??= MSAA_QUALITY.NONE;\n\n super(null, options);\n\n // Set defaults\n this.mipmap = MIPMAP_MODES.OFF;\n this.valid = true;\n\n this._clear = new Color([0, 0, 0, 0]);\n this.framebuffer = new Framebuffer(this.realWidth, this.realHeight)\n .addColorTexture(0, this);\n this.framebuffer.multisample = options.multisample;\n\n // TODO - could this be added the systems?\n this.maskStack = [];\n this.filterStack = [{}];\n }\n\n /** Color when clearning the texture. */\n set clearColor(value: ColorSource)\n {\n this._clear.setValue(value);\n }\n get clearColor(): ColorSource\n {\n return this._clear.value;\n }\n\n /**\n * Color object when clearning the texture.\n * @readonly\n * @since 7.2.0\n */\n get clear(): Color\n {\n return this._clear;\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 BaseRenderTexture.\n * @param desiredWidth - The desired width to resize to.\n * @param desiredHeight - The desired height to resize to.\n */\n resize(desiredWidth: number, desiredHeight: number): void\n {\n this.framebuffer.resize(desiredWidth * this.resolution, desiredHeight * this.resolution);\n this.setRealSize(this.framebuffer.width, this.framebuffer.height);\n }\n\n /**\n * Frees the texture and framebuffer from WebGL memory without destroying this texture object.\n * This means you can still use the texture later which will upload it to GPU\n * memory again.\n * @fires PIXI.BaseTexture#dispose\n */\n dispose(): void\n {\n this.framebuffer.dispose();\n\n super.dispose();\n }\n\n /** Destroys this texture. */\n destroy(): void\n {\n super.destroy();\n\n this.framebuffer.destroyDepthTexture();\n this.framebuffer = null;\n }\n}\n"],"names":[],"mappings":";;;;AA4CO,MAAM,0BAA0B,YACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBI,YAAY,UAA+B,IAC3C;AACQ,QAAA,OAAO,WAAY,UACvB;AAGI,YAAM,QAAQ,UAAU,CAAC,GACnB,SAAS,UAAU,CAAC,GACpB,YAAY,UAAU,CAAC,GACvB,aAAa,UAAU,CAAC;AAE9B,gBAAU,EAAE,OAAO,QAAQ,WAAW,WAAW;AAAA,IAErD;AAEA,YAAQ,QAAQ,QAAQ,SAAS,KACjC,QAAQ,SAAS,QAAQ,UAAU,KACnC,QAAQ,gBAAR,QAAQ,cAAgB,aAAa,OAErC,MAAM,MAAM,OAAO,GAGnB,KAAK,SAAS,aAAa,KAC3B,KAAK,QAAQ,IAEb,KAAK,SAAS,IAAI,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,GACpC,KAAK,cAAc,IAAI,YAAY,KAAK,WAAW,KAAK,UAAU,EAC7D,gBAAgB,GAAG,IAAI,GAC5B,KAAK,YAAY,cAAc,QAAQ,aAGvC,KAAK,YAAY,CAAC,GAClB,KAAK,cAAc,CAAC,CAAA,CAAE;AAAA,EAC1B;AAAA;AAAA,EAGA,IAAI,WAAW,OACf;AACS,SAAA,OAA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