UNPKG

3.01 kBJavaScriptView Raw
1import { Color } from "@pixi/color";
2import { MSAA_QUALITY, MIPMAP_MODES } from "@pixi/constants";
3import { Framebuffer } from "../framebuffer/Framebuffer.mjs";
4import { BaseTexture } from "../textures/BaseTexture.mjs";
5class BaseRenderTexture extends BaseTexture {
6 /**
7 * @param options
8 * @param {number} [options.width=100] - The width of the base render texture.
9 * @param {number} [options.height=100] - The height of the base render texture.
10 * @param {PIXI.SCALE_MODES} [options.scaleMode=PIXI.BaseTexture.defaultOptions.scaleMode] - See {@link PIXI.SCALE_MODES}
11 * for possible values.
12 * @param {number} [options.resolution=PIXI.settings.RESOLUTION] - The resolution / device pixel ratio
13 * of the texture being generated.
14 * @param {PIXI.MSAA_QUALITY} [options.multisample=PIXI.MSAA_QUALITY.NONE] - The number of samples of the frame buffer.
15 */
16 constructor(options = {}) {
17 if (typeof options == "number") {
18 const width = arguments[0], height = arguments[1], scaleMode = arguments[2], resolution = arguments[3];
19 options = { width, height, scaleMode, resolution };
20 }
21 options.width = options.width ?? 100, options.height = options.height ?? 100, options.multisample ?? (options.multisample = MSAA_QUALITY.NONE), super(null, options), this.mipmap = MIPMAP_MODES.OFF, this.valid = !0, this._clear = new Color([0, 0, 0, 0]), this.framebuffer = new Framebuffer(this.realWidth, this.realHeight).addColorTexture(0, this), this.framebuffer.multisample = options.multisample, this.maskStack = [], this.filterStack = [{}];
22 }
23 /** Color when clearning the texture. */
24 set clearColor(value) {
25 this._clear.setValue(value);
26 }
27 get clearColor() {
28 return this._clear.value;
29 }
30 /**
31 * Color object when clearning the texture.
32 * @readonly
33 * @since 7.2.0
34 */
35 get clear() {
36 return this._clear;
37 }
38 /**
39 * Shortcut to `this.framebuffer.multisample`.
40 * @default PIXI.MSAA_QUALITY.NONE
41 */
42 get multisample() {
43 return this.framebuffer.multisample;
44 }
45 set multisample(value) {
46 this.framebuffer.multisample = value;
47 }
48 /**
49 * Resizes the BaseRenderTexture.
50 * @param desiredWidth - The desired width to resize to.
51 * @param desiredHeight - The desired height to resize to.
52 */
53 resize(desiredWidth, desiredHeight) {
54 this.framebuffer.resize(desiredWidth * this.resolution, desiredHeight * this.resolution), this.setRealSize(this.framebuffer.width, this.framebuffer.height);
55 }
56 /**
57 * Frees the texture and framebuffer from WebGL memory without destroying this texture object.
58 * This means you can still use the texture later which will upload it to GPU
59 * memory again.
60 * @fires PIXI.BaseTexture#dispose
61 */
62 dispose() {
63 this.framebuffer.dispose(), super.dispose();
64 }
65 /** Destroys this texture. */
66 destroy() {
67 super.destroy(), this.framebuffer.destroyDepthTexture(), this.framebuffer = null;
68 }
69}
70export {
71 BaseRenderTexture
72};
73//# sourceMappingURL=BaseRenderTexture.mjs.map