import { RenderTexture, Container, Renderer, Filter } from "pixi.js";

export default class RTTShader {
  readonly texture: RenderTexture;
  readonly container: Container;
  readonly renderer: Renderer;

  constructor(renderer: Renderer, filter: Filter, scale: number = 2) {
    this.renderer = renderer;
    this.texture = RenderTexture.create({
      width: this.renderer.width / scale,
      height: this.renderer.height / scale,
    });
    this.container = new Container();
    this.container.filterArea = this.texture.frame;
    this.container.filters = [filter];
  }

  rescale(scale: number) {
    this.texture.resize(
      this.renderer.width / scale,
      this.renderer.height / scale
    );
    this.container.filterArea = this.texture.frame;
  }

  render() {
    this.renderer.render(this.container, this.texture);
  }
}
