1 | "use strict";
|
2 | var constants = require("@pixi/constants"), utils = require("@pixi/utils"), BaseRenderTexture = require("./BaseRenderTexture.js"), RenderTexture = require("./RenderTexture.js");
|
3 | class RenderTexturePool {
|
4 | |
5 |
|
6 |
|
7 |
|
8 | constructor(textureOptions) {
|
9 | this.texturePool = {}, this.textureOptions = textureOptions || {}, this.enableFullScreen = !1, this._pixelsWidth = 0, this._pixelsHeight = 0;
|
10 | }
|
11 | |
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | createTexture(realWidth, realHeight, multisample = constants.MSAA_QUALITY.NONE) {
|
18 | const baseRenderTexture = new BaseRenderTexture.BaseRenderTexture(Object.assign({
|
19 | width: realWidth,
|
20 | height: realHeight,
|
21 | resolution: 1,
|
22 | multisample
|
23 | }, this.textureOptions));
|
24 | return new RenderTexture.RenderTexture(baseRenderTexture);
|
25 | }
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | getOptimalTexture(minWidth, minHeight, resolution = 1, multisample = constants.MSAA_QUALITY.NONE) {
|
35 | let key;
|
36 | minWidth = Math.max(Math.ceil(minWidth * resolution - 1e-6), 1), minHeight = Math.max(Math.ceil(minHeight * resolution - 1e-6), 1), !this.enableFullScreen || minWidth !== this._pixelsWidth || minHeight !== this._pixelsHeight ? (minWidth = utils.nextPow2(minWidth), minHeight = utils.nextPow2(minHeight), key = ((minWidth & 65535) << 16 | minHeight & 65535) >>> 0, multisample > 1 && (key += multisample * 4294967296)) : key = multisample > 1 ? -multisample : -1, this.texturePool[key] || (this.texturePool[key] = []);
|
37 | let renderTexture = this.texturePool[key].pop();
|
38 | return renderTexture || (renderTexture = this.createTexture(minWidth, minHeight, multisample)), renderTexture.filterPoolKey = key, renderTexture.setResolution(resolution), renderTexture;
|
39 | }
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | getFilterTexture(input, resolution, multisample) {
|
50 | const filterTexture = this.getOptimalTexture(
|
51 | input.width,
|
52 | input.height,
|
53 | resolution || input.resolution,
|
54 | multisample || constants.MSAA_QUALITY.NONE
|
55 | );
|
56 | return filterTexture.filterFrame = input.filterFrame, filterTexture;
|
57 | }
|
58 | |
59 |
|
60 |
|
61 |
|
62 | returnTexture(renderTexture) {
|
63 | const key = renderTexture.filterPoolKey;
|
64 | renderTexture.filterFrame = null, this.texturePool[key].push(renderTexture);
|
65 | }
|
66 | |
67 |
|
68 |
|
69 |
|
70 | returnFilterTexture(renderTexture) {
|
71 | this.returnTexture(renderTexture);
|
72 | }
|
73 | |
74 |
|
75 |
|
76 |
|
77 | clear(destroyTextures) {
|
78 | if (destroyTextures = destroyTextures !== !1, destroyTextures)
|
79 | for (const i in this.texturePool) {
|
80 | const textures = this.texturePool[i];
|
81 | if (textures)
|
82 | for (let j = 0; j < textures.length; j++)
|
83 | textures[j].destroy(!0);
|
84 | }
|
85 | this.texturePool = {};
|
86 | }
|
87 | |
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | setScreenSize(size) {
|
95 | if (!(size.width === this._pixelsWidth && size.height === this._pixelsHeight)) {
|
96 | this.enableFullScreen = size.width > 0 && size.height > 0;
|
97 | for (const i in this.texturePool) {
|
98 | if (!(Number(i) < 0))
|
99 | continue;
|
100 | const textures = this.texturePool[i];
|
101 | if (textures)
|
102 | for (let j = 0; j < textures.length; j++)
|
103 | textures[j].destroy(!0);
|
104 | this.texturePool[i] = [];
|
105 | }
|
106 | this._pixelsWidth = size.width, this._pixelsHeight = size.height;
|
107 | }
|
108 | }
|
109 | }
|
110 | RenderTexturePool.SCREEN_KEY = -1;
|
111 | exports.RenderTexturePool = RenderTexturePool;
|
112 |
|