1 | {"version":3,"file":"Framebuffer.js","sources":["../../src/framebuffer/Framebuffer.ts"],"sourcesContent":["import { FORMATS, MIPMAP_MODES, MSAA_QUALITY, SCALE_MODES, TYPES } from '@pixi/constants';\nimport { Runner } from '@pixi/runner';\nimport { BaseTexture } from '../textures/BaseTexture';\nimport { DepthResource } from '../textures/resources/DepthResource';\n\nimport type { GLFramebuffer } from './GLFramebuffer';\n\n/**\n * A framebuffer can be used to render contents off of the screen. {@link PIXI.BaseRenderTexture} uses\n * one internally to render into itself. You can attach a depth or stencil buffer to a framebuffer.\n *\n * On WebGL 2 machines, shaders can output to multiple textures simultaneously with GLSL 300 ES.\n * @memberof PIXI\n */\nexport class Framebuffer\n{\n /** Width of framebuffer in pixels. */\n public width: number;\n\n /** Height of framebuffer in pixels. */\n public height: number;\n\n /**\n * Desired number of samples for antialiasing. 0 means AA should not be used.\n *\n * Experimental WebGL2 feature, allows to use antialiasing in individual renderTextures.\n * Antialiasing is the same as for main buffer with renderer `antialias: true` options.\n * Seriously affects GPU memory consumption and GPU performance.\n * @example\n * import { MSAA_QUALITY } from 'pixi.js';\n *\n * renderTexture.framebuffer.multisample = MSAA_QUALITY.HIGH;\n * // ...\n * renderer.render(myContainer, { renderTexture });\n * renderer.framebuffer.blit(); // Copies data from MSAA framebuffer to texture\n * @default PIXI.MSAA_QUALITY.NONE\n */\n public multisample: MSAA_QUALITY;\n\n stencil: boolean;\n depth: boolean;\n dirtyId: number;\n dirtyFormat: number;\n dirtySize: number;\n depthTexture: BaseTexture;\n colorTextures: Array<BaseTexture>;\n glFramebuffers: {[key: string]: GLFramebuffer};\n disposeRunner: Runner;\n\n /**\n * @param width - Width of the frame buffer\n * @param height - Height of the frame buffer\n */\n constructor(width: number, height: number)\n {\n this.width = Math.round(width || 100);\n this.height = Math.round(height || 100);\n\n this.stencil = false;\n this.depth = false;\n\n this.dirtyId = 0;\n this.dirtyFormat = 0;\n this.dirtySize = 0;\n\n this.depthTexture = null;\n this.colorTextures = [];\n\n this.glFramebuffers = {};\n\n this.disposeRunner = new Runner('disposeFramebuffer');\n this.multisample = MSAA_QUALITY.NONE;\n }\n\n /**\n * Reference to the colorTexture.\n * @readonly\n */\n get colorTexture(): BaseTexture\n {\n return this.colorTextures[0];\n }\n\n /**\n * Add texture to the colorTexture array.\n * @param index - Index of the array to add the texture to\n * @param texture - Texture to add to the array\n */\n addColorTexture(index = 0, texture?: BaseTexture): this\n {\n // TODO add some validation to the texture - same width / height etc?\n this.colorTextures[index] = texture || new BaseTexture(null, {\n scaleMode: SCALE_MODES.NEAREST,\n resolution: 1,\n mipmap: MIPMAP_MODES.OFF,\n width: this.width,\n height: this.height,\n });\n\n this.dirtyId++;\n this.dirtyFormat++;\n\n return this;\n }\n\n /**\n * Add a depth texture to the frame buffer.\n * @param texture - Texture to add.\n */\n addDepthTexture(texture?: BaseTexture): this\n {\n /* eslint-disable max-len */\n this.depthTexture = texture || new BaseTexture(new DepthResource(null, { width: this.width, height: this.height }), {\n scaleMode: SCALE_MODES.NEAREST,\n resolution: 1,\n width: this.width,\n height: this.height,\n mipmap: MIPMAP_MODES.OFF,\n format: FORMATS.DEPTH_COMPONENT,\n type: TYPES.UNSIGNED_SHORT,\n });\n\n this.dirtyId++;\n this.dirtyFormat++;\n\n return this;\n }\n\n /** Enable depth on the frame buffer. */\n enableDepth(): this\n {\n this.depth = true;\n\n this.dirtyId++;\n this.dirtyFormat++;\n\n return this;\n }\n\n /** Enable stencil on the frame buffer. */\n enableStencil(): this\n {\n this.stencil = true;\n\n this.dirtyId++;\n this.dirtyFormat++;\n\n return this;\n }\n\n /**\n * Resize the frame buffer\n * @param width - Width of the frame buffer to resize to\n * @param height - Height of the frame buffer to resize to\n */\n resize(width: number, height: number): void\n {\n width = Math.round(width);\n height = Math.round(height);\n\n if (width === this.width && height === this.height) return;\n\n this.width = width;\n this.height = height;\n\n this.dirtyId++;\n this.dirtySize++;\n\n for (let i = 0; i < this.colorTextures.length; i++)\n {\n const texture = this.colorTextures[i];\n const resolution = texture.resolution;\n\n // take into account the fact the texture may have a different resolution..\n texture.setSize(width / resolution, height / resolution);\n }\n\n if (this.depthTexture)\n {\n const resolution = this.depthTexture.resolution;\n\n this.depthTexture.setSize(width / resolution, height / resolution);\n }\n }\n\n /** Disposes WebGL resources that are connected to this geometry. */\n dispose(): void\n {\n this.disposeRunner.emit(this, false);\n }\n\n /** Destroys and removes the depth texture added to this framebuffer. */\n destroyDepthTexture(): void\n {\n if (this.depthTexture)\n {\n this.depthTexture.destroy();\n this.depthTexture = null;\n\n ++this.dirtyId;\n ++this.dirtyFormat;\n }\n }\n}\n"],"names":["Runner","MSAA_QUALITY","BaseTexture","SCALE_MODES","MIPMAP_MODES","DepthResource","FORMATS","TYPES"],"mappings":";;;;;;;;;AAcO,MAAM,WACb,CAAA;AAAA,EAsCI,WAAA,CAAY,OAAe,MAC3B,EAAA;AACI,IAAA,IAAA,CAAK,KAAQ,GAAA,IAAA,CAAK,KAAM,CAAA,KAAA,IAAS,GAAG,CAAA,CAAA;AACpC,IAAA,IAAA,CAAK,MAAS,GAAA,IAAA,CAAK,KAAM,CAAA,MAAA,IAAU,GAAG,CAAA,CAAA;AAEtC,IAAA,IAAA,CAAK,OAAU,GAAA,KAAA,CAAA;AACf,IAAA,IAAA,CAAK,KAAQ,GAAA,KAAA,CAAA;AAEb,IAAA,IAAA,CAAK,OAAU,GAAA,CAAA,CAAA;AACf,IAAA,IAAA,CAAK,WAAc,GAAA,CAAA,CAAA;AACnB,IAAA,IAAA,CAAK,SAAY,GAAA,CAAA,CAAA;AAEjB,IAAA,IAAA,CAAK,YAAe,GAAA,IAAA,CAAA;AACpB,IAAA,IAAA,CAAK,gBAAgB,EAAC,CAAA;AAEtB,IAAA,IAAA,CAAK,iBAAiB,EAAC,CAAA;AAEvB,IAAK,IAAA,CAAA,aAAA,GAAgB,IAAIA,aAAA,CAAO,oBAAoB,CAAA,CAAA;AACpD,IAAA,IAAA,CAAK,cAAcC,sBAAa,CAAA,IAAA,CA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