shadow$provide.module$node_modules$pixi_DOT_js$lib$rendering$renderers$gl$GlStencilSystem = function(global, require, module, exports) {
  global = require("module$node_modules$pixi_DOT_js$lib$extensions$Extensions");
  var GpuStencilModesToPixi = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$gpu$state$GpuStencilModesToPixi"), _const = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$state$const");
  "use strict";
  class GlStencilSystem {
    constructor(renderer) {
      this._stencilCache = {enabled:!1, stencilReference:0, stencilMode:_const.STENCIL_MODES.NONE};
      this._renderTargetStencilState = Object.create(null);
      renderer.renderTarget.onRenderTargetChange.add(this);
    }
    contextChange(gl) {
      this._gl = gl;
      this._comparisonFuncMapping = {always:gl.ALWAYS, never:gl.NEVER, equal:gl.EQUAL, "not-equal":gl.NOTEQUAL, less:gl.LESS, "less-equal":gl.LEQUAL, greater:gl.GREATER, "greater-equal":gl.GEQUAL};
      this._stencilOpsMapping = {keep:gl.KEEP, zero:gl.ZERO, replace:gl.REPLACE, invert:gl.INVERT, "increment-clamp":gl.INCR, "decrement-clamp":gl.DECR, "increment-wrap":gl.INCR_WRAP, "decrement-wrap":gl.DECR_WRAP};
      this.resetState();
    }
    onRenderTargetChange(renderTarget) {
      if (this._activeRenderTarget !== renderTarget) {
        this._activeRenderTarget = renderTarget;
        var stencilState = this._renderTargetStencilState[renderTarget.uid];
        stencilState || (stencilState = this._renderTargetStencilState[renderTarget.uid] = {stencilMode:_const.STENCIL_MODES.DISABLED, stencilReference:0});
        this.setStencilMode(stencilState.stencilMode, stencilState.stencilReference);
      }
    }
    resetState() {
      this._stencilCache.enabled = !1;
      this._stencilCache.stencilMode = _const.STENCIL_MODES.NONE;
      this._stencilCache.stencilReference = 0;
    }
    setStencilMode(stencilMode, stencilReference) {
      const stencilState = this._renderTargetStencilState[this._activeRenderTarget.uid], gl = this._gl, mode = GpuStencilModesToPixi.GpuStencilModesToPixi[stencilMode], _stencilCache = this._stencilCache;
      stencilState.stencilMode = stencilMode;
      stencilState.stencilReference = stencilReference;
      if (stencilMode === _const.STENCIL_MODES.DISABLED) {
        this._stencilCache.enabled && (this._stencilCache.enabled = !1, gl.disable(gl.STENCIL_TEST));
      } else {
        if (this._stencilCache.enabled || (this._stencilCache.enabled = !0, gl.enable(gl.STENCIL_TEST)), stencilMode !== _stencilCache.stencilMode || _stencilCache.stencilReference !== stencilReference) {
          _stencilCache.stencilMode = stencilMode, _stencilCache.stencilReference = stencilReference, gl.stencilFunc(this._comparisonFuncMapping[mode.stencilBack.compare], stencilReference, 255), gl.stencilOp(gl.KEEP, gl.KEEP, this._stencilOpsMapping[mode.stencilBack.passOp]);
        }
      }
    }
  }
  GlStencilSystem.extension = {type:[global.ExtensionType.WebGLSystem], name:"stencil"};
  exports.GlStencilSystem = GlStencilSystem;
};

//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$rendering$renderers$gl$GlStencilSystem.js.map
