import { ClipSpace } from '@luma.gl/engine';
import { setGLParameters, withGLParameters, clear } from '@luma.gl/webgl';
import Pass from './pass';
export default class ScreenPass extends Pass {
  constructor(device, props) {
    super(device, props);
    this.model = void 0;
    const {
      module,
      fs,
      id
    } = props;
    this.model = new ClipSpace(device, {
      id,
      fs,
      modules: [module]
    });
  }

  render(params) {
    const [drawingBufferWidth, drawingBufferHeight] = this.device.canvasContext.getDrawingBufferSize();
    setGLParameters(this.device, {
      viewport: [0, 0, drawingBufferWidth, drawingBufferHeight]
    });
    withGLParameters(this.device, {
      framebuffer: params.outputBuffer,
      clearColor: [0, 0, 0, 0]
    }, () => this._renderPass(this.device, params));
  }

  delete() {
    this.model.destroy();
    this.model = null;
  }

  _renderPass(device, options) {
    const {
      inputBuffer
    } = options;
    clear(this.device, {
      color: true
    });
    this.model.setShaderModuleProps(options.moduleSettings);
    this.model.setBindings({
      texture: inputBuffer.colorAttachments[0]
    });
    this.model.setUniforms({
      texSize: [inputBuffer.width, inputBuffer.height]
    });
    this.model.setParameters({
      depthWriteEnabled: false,
      depthCompare: 'always'
    });
    this.model.draw(this.device.getDefaultRenderPass());
  }

}
//# sourceMappingURL=screen-pass.js.map