UNPKG

1.46 kBJavaScriptView Raw
1import { Texture } from '../textures/Texture.mjs';
2import { BaseRenderTexture } from './BaseRenderTexture.mjs';
3
4class RenderTexture extends Texture {
5 constructor(baseRenderTexture, frame) {
6 super(baseRenderTexture, frame);
7 this.valid = true;
8 this.filterFrame = null;
9 this.filterPoolKey = null;
10 this.updateUvs();
11 }
12 get framebuffer() {
13 return this.baseTexture.framebuffer;
14 }
15 get multisample() {
16 return this.framebuffer.multisample;
17 }
18 set multisample(value) {
19 this.framebuffer.multisample = value;
20 }
21 resize(desiredWidth, desiredHeight, resizeBaseTexture = true) {
22 const resolution = this.baseTexture.resolution;
23 const width = Math.round(desiredWidth * resolution) / resolution;
24 const height = Math.round(desiredHeight * resolution) / resolution;
25 this.valid = width > 0 && height > 0;
26 this._frame.width = this.orig.width = width;
27 this._frame.height = this.orig.height = height;
28 if (resizeBaseTexture) {
29 this.baseTexture.resize(width, height);
30 }
31 this.updateUvs();
32 }
33 setResolution(resolution) {
34 const { baseTexture } = this;
35 if (baseTexture.resolution === resolution) {
36 return;
37 }
38 baseTexture.setResolution(resolution);
39 this.resize(baseTexture.width, baseTexture.height, false);
40 }
41 static create(options) {
42 return new RenderTexture(new BaseRenderTexture(options));
43 }
44}
45
46export { RenderTexture };
47//# sourceMappingURL=RenderTexture.mjs.map