'use strict';

require('../core/settings.js');
require('../color.js');
var constants = require('../constants.js');
var extensions = require('../extensions.js');
require('../math/const.js');
require('../math/groupD8.js');
require('../math/Transform.js');
require('../runner.js');
require('../ticker/settings.js');
require('../ticker/const.js');
require('../ticker/Ticker.js');
require('../ticker/TickerPlugin.js');
require('../utils/settings.js');
require('../utils/is_mobile/index.js');
require('../utils/color/premultiply.js');
require('../utils/media/BoundingBox.js');
require('../core/autoDetectRenderer.js');
require('../core/background/BackgroundSystem.js');
require('../core/batch/BatchRenderer.js');
require('../core/shader/Program.js');
require('../core/batch/BatchSystem.js');
require('../core/context/ContextSystem.js');
require('../core/filters/Filter.js');
require('../core/filters/FilterSystem.js');
require('../core/textures/BaseTexture.js');
require('../core/framebuffer/FramebufferSystem.js');
require('../core/framebuffer/MultisampleSystem.js');
require('../core/geometry/BufferSystem.js');
require('../core/geometry/GeometrySystem.js');
require('../core/mask/MaskSystem.js');
require('../core/mask/ScissorSystem.js');
require('../core/mask/StencilSystem.js');
require('../core/plugin/PluginSystem.js');
require('../core/projection/ProjectionSystem.js');
require('../core/render/ObjectRendererSystem.js');
require('../core/Renderer.js');
require('../core/renderTexture/GenerateTextureSystem.js');
require('../core/renderTexture/RenderTexturePool.js');
require('../core/renderTexture/RenderTextureSystem.js');
require('../core/shader/ShaderSystem.js');
require('../core/startup/StartupSystem.js');
require('../core/state/StateSystem.js');
require('../core/textures/TextureGCSystem.js');
require('../core/textures/TextureSystem.js');
require('../core/transformFeedback/TransformFeedbackSystem.js');
require('../core/view/ViewSystem.js');
require('../core/textures/resources/index.js');

class PassSystem {
  // renderers scene graph!
  constructor(renderer) {
    this.stack = [];
    this.renderer = renderer;
  }
  begin(pass) {
    const { renderer } = this;
    if (pass.active) {
      throw new Error("PassSystem: using one pass two times!");
    }
    pass.textureCache.pushTexture(renderer);
    if (pass.clearColor || pass.clearDepth) {
      renderer.framebuffer.clear(pass.bgColor[0], pass.bgColor[1], pass.bgColor[2], pass.bgColor[3], Number(pass.clearColor) * constants.BUFFER_BITS.COLOR | Number(pass.clearDepth) * constants.BUFFER_BITS.DEPTH);
    }
    pass.active = true;
    this.stack.push(pass);
  }
  end(pass) {
    const lastPass = this.stack[this.stack.length - 1];
    if (pass && pass !== lastPass) {
      throw new Error("PassSystem: stack is wrong!");
    }
    lastPass.textureCache.popTexture(this.renderer);
    lastPass.active = false;
    this.stack.pop();
  }
  destroy() {
    this.renderer = null;
  }
}
PassSystem.extension = {
  type: extensions.ExtensionType.RendererSystem,
  name: "pass"
};
extensions.extensions.add(PassSystem);

exports.PassSystem = PassSystem;
//# sourceMappingURL=PassSystem.js.map
