"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _engine = require("@luma.gl/engine");

var _webgl = require("@luma.gl/webgl");

var _pass = _interopRequireDefault(require("./pass"));

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var ScreenPass = function (_Pass) {
  (0, _inherits2.default)(ScreenPass, _Pass);

  var _super = _createSuper(ScreenPass);

  function ScreenPass(device, props) {
    var _this;

    (0, _classCallCheck2.default)(this, ScreenPass);
    _this = _super.call(this, device, props);
    _this.model = void 0;
    var module = props.module,
        fs = props.fs,
        id = props.id;
    _this.model = new _engine.ClipSpace(device, {
      id: id,
      fs: fs,
      modules: [module]
    });
    return _this;
  }

  var _proto = ScreenPass.prototype;

  _proto.render = function render(params) {
    var _this2 = this;

    var _this$device$canvasCo = this.device.canvasContext.getDrawingBufferSize(),
        _this$device$canvasCo2 = (0, _slicedToArray2.default)(_this$device$canvasCo, 2),
        drawingBufferWidth = _this$device$canvasCo2[0],
        drawingBufferHeight = _this$device$canvasCo2[1];

    (0, _webgl.setGLParameters)(this.device, {
      viewport: [0, 0, drawingBufferWidth, drawingBufferHeight]
    });
    (0, _webgl.withGLParameters)(this.device, {
      framebuffer: params.outputBuffer,
      clearColor: [0, 0, 0, 0]
    }, function () {
      return _this2._renderPass(_this2.device, params);
    });
  };

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

  _proto._renderPass = function _renderPass(device, options) {
    var inputBuffer = options.inputBuffer;
    (0, _webgl.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());
  };

  return ScreenPass;
}(_pass.default);

exports.default = ScreenPass;
//# sourceMappingURL=screen-pass.js.map