1 | "use strict";
|
2 | var constants = require("@pixi/constants"), runner = require("@pixi/runner"), BaseTexture = require("../textures/BaseTexture.js");
|
3 | class Framebuffer {
|
4 | |
5 |
|
6 |
|
7 |
|
8 | constructor(width, height) {
|
9 | if (this.width = Math.round(width), this.height = Math.round(height), !this.width || !this.height)
|
10 | throw new Error("Framebuffer width or height is zero");
|
11 | this.stencil = !1, this.depth = !1, this.dirtyId = 0, this.dirtyFormat = 0, this.dirtySize = 0, this.depthTexture = null, this.colorTextures = [], this.glFramebuffers = {}, this.disposeRunner = new runner.Runner("disposeFramebuffer"), this.multisample = constants.MSAA_QUALITY.NONE;
|
12 | }
|
13 | |
14 |
|
15 |
|
16 |
|
17 | get colorTexture() {
|
18 | return this.colorTextures[0];
|
19 | }
|
20 | |
21 |
|
22 |
|
23 |
|
24 |
|
25 | addColorTexture(index = 0, texture) {
|
26 | return this.colorTextures[index] = texture || new BaseTexture.BaseTexture(null, {
|
27 | scaleMode: constants.SCALE_MODES.NEAREST,
|
28 | resolution: 1,
|
29 | mipmap: constants.MIPMAP_MODES.OFF,
|
30 | width: this.width,
|
31 | height: this.height
|
32 | }), this.dirtyId++, this.dirtyFormat++, this;
|
33 | }
|
34 | |
35 |
|
36 |
|
37 |
|
38 | addDepthTexture(texture) {
|
39 | return this.depthTexture = texture || new BaseTexture.BaseTexture(null, {
|
40 | scaleMode: constants.SCALE_MODES.NEAREST,
|
41 | resolution: 1,
|
42 | width: this.width,
|
43 | height: this.height,
|
44 | mipmap: constants.MIPMAP_MODES.OFF,
|
45 | format: constants.FORMATS.DEPTH_COMPONENT,
|
46 | type: constants.TYPES.UNSIGNED_SHORT
|
47 | }), this.dirtyId++, this.dirtyFormat++, this;
|
48 | }
|
49 |
|
50 | enableDepth() {
|
51 | return this.depth = !0, this.dirtyId++, this.dirtyFormat++, this;
|
52 | }
|
53 |
|
54 | enableStencil() {
|
55 | return this.stencil = !0, this.dirtyId++, this.dirtyFormat++, this;
|
56 | }
|
57 | |
58 |
|
59 |
|
60 |
|
61 |
|
62 | resize(width, height) {
|
63 | if (width = Math.round(width), height = Math.round(height), !width || !height)
|
64 | throw new Error("Framebuffer width and height must not be zero");
|
65 | if (!(width === this.width && height === this.height)) {
|
66 | this.width = width, this.height = height, this.dirtyId++, this.dirtySize++;
|
67 | for (let i = 0; i < this.colorTextures.length; i++) {
|
68 | const texture = this.colorTextures[i], resolution = texture.resolution;
|
69 | texture.setSize(width / resolution, height / resolution);
|
70 | }
|
71 | if (this.depthTexture) {
|
72 | const resolution = this.depthTexture.resolution;
|
73 | this.depthTexture.setSize(width / resolution, height / resolution);
|
74 | }
|
75 | }
|
76 | }
|
77 |
|
78 | dispose() {
|
79 | this.disposeRunner.emit(this, !1);
|
80 | }
|
81 |
|
82 | destroyDepthTexture() {
|
83 | this.depthTexture && (this.depthTexture.destroy(), this.depthTexture = null, ++this.dirtyId, ++this.dirtyFormat);
|
84 | }
|
85 | }
|
86 | exports.Framebuffer = Framebuffer;
|
87 |
|