1 | "use strict";
|
2 | var color = require("@pixi/color"), extensions = require("@pixi/extensions"), math = require("@pixi/math");
|
3 | const tempRect = new math.Rectangle(), tempRect2 = new math.Rectangle();
|
4 | class RenderTextureSystem {
|
5 | |
6 |
|
7 |
|
8 | constructor(renderer) {
|
9 | this.renderer = renderer, this.defaultMaskStack = [], this.current = null, this.sourceFrame = new math.Rectangle(), this.destinationFrame = new math.Rectangle(), this.viewportFrame = new math.Rectangle();
|
10 | }
|
11 | contextChange() {
|
12 | const attributes = this.renderer?.gl.getContextAttributes();
|
13 | this._rendererPremultipliedAlpha = !!(attributes && attributes.alpha && attributes.premultipliedAlpha);
|
14 | }
|
15 | |
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | bind(renderTexture = null, sourceFrame, destinationFrame) {
|
22 | const renderer = this.renderer;
|
23 | this.current = renderTexture;
|
24 | let baseTexture, framebuffer, resolution;
|
25 | renderTexture ? (baseTexture = renderTexture.baseTexture, resolution = baseTexture.resolution, sourceFrame || (tempRect.width = renderTexture.frame.width, tempRect.height = renderTexture.frame.height, sourceFrame = tempRect), destinationFrame || (tempRect2.x = renderTexture.frame.x, tempRect2.y = renderTexture.frame.y, tempRect2.width = sourceFrame.width, tempRect2.height = sourceFrame.height, destinationFrame = tempRect2), framebuffer = baseTexture.framebuffer) : (resolution = renderer.resolution, sourceFrame || (tempRect.width = renderer._view.screen.width, tempRect.height = renderer._view.screen.height, sourceFrame = tempRect), destinationFrame || (destinationFrame = tempRect, destinationFrame.width = sourceFrame.width, destinationFrame.height = sourceFrame.height));
|
26 | const viewportFrame = this.viewportFrame;
|
27 | viewportFrame.x = destinationFrame.x * resolution, viewportFrame.y = destinationFrame.y * resolution, viewportFrame.width = destinationFrame.width * resolution, viewportFrame.height = destinationFrame.height * resolution, renderTexture || (viewportFrame.y = renderer.view.height - (viewportFrame.y + viewportFrame.height)), viewportFrame.ceil(), this.renderer.framebuffer.bind(framebuffer, viewportFrame), this.renderer.projection.update(destinationFrame, sourceFrame, resolution, !framebuffer), renderTexture ? this.renderer.mask.setMaskStack(baseTexture.maskStack) : this.renderer.mask.setMaskStack(this.defaultMaskStack), this.sourceFrame.copyFrom(sourceFrame), this.destinationFrame.copyFrom(destinationFrame);
|
28 | }
|
29 | |
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | clear(clearColor, mask) {
|
36 | const fallbackColor = this.current ? this.current.baseTexture.clear : this.renderer.background.backgroundColor, color$1 = color.Color.shared.setValue(clearColor || fallbackColor);
|
37 | (this.current && this.current.baseTexture.alphaMode > 0 || !this.current && this._rendererPremultipliedAlpha) && color$1.premultiply(color$1.alpha);
|
38 | const destinationFrame = this.destinationFrame, baseFrame = this.current ? this.current.baseTexture : this.renderer._view.screen, clearMask = destinationFrame.width !== baseFrame.width || destinationFrame.height !== baseFrame.height;
|
39 | if (clearMask) {
|
40 | let { x, y, width, height } = this.viewportFrame;
|
41 | x = Math.round(x), y = Math.round(y), width = Math.round(width), height = Math.round(height), this.renderer.gl.enable(this.renderer.gl.SCISSOR_TEST), this.renderer.gl.scissor(x, y, width, height);
|
42 | }
|
43 | this.renderer.framebuffer.clear(color$1.red, color$1.green, color$1.blue, color$1.alpha, mask), clearMask && this.renderer.scissor.pop();
|
44 | }
|
45 | resize() {
|
46 | this.bind(null);
|
47 | }
|
48 |
|
49 | reset() {
|
50 | this.bind(null);
|
51 | }
|
52 | destroy() {
|
53 | this.renderer = null;
|
54 | }
|
55 | }
|
56 | RenderTextureSystem.extension = {
|
57 | type: extensions.ExtensionType.RendererSystem,
|
58 | name: "renderTexture"
|
59 | };
|
60 | extensions.extensions.add(RenderTextureSystem);
|
61 | exports.RenderTextureSystem = RenderTextureSystem;
|
62 |
|