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

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) * BUFFER_BITS.COLOR | Number(pass.clearDepth) * 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: ExtensionType.RendererSystem,
  name: "pass"
};
extensions.add(PassSystem);

export { PassSystem };
//# sourceMappingURL=PassSystem.mjs.map
