shadow$provide.module$node_modules$pixi_DOT_js$lib$rendering$renderers$gl$state$GlStateSystem = function(global, require, module, exports) {
  global = require("module$node_modules$pixi_DOT_js$lib$extensions$Extensions");
  var State = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$state$State"), mapWebGLBlendModesToPixi = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$gl$state$mapWebGLBlendModesToPixi");
  "use strict";
  const node_modules$pixi_DOT_js$lib$rendering$renderers$gl$state$GlStateSystem$classdecl$var26 = class {
    constructor(renderer) {
      this._invertFrontFace = !1;
      this.gl = null;
      this.polygonOffset = this.stateId = 0;
      this.blendMode = "none";
      this._blendEq = !1;
      this.map = [];
      this.map[0] = this.setBlend;
      this.map[1] = this.setOffset;
      this.map[2] = this.setCullFace;
      this.map[3] = this.setDepthTest;
      this.map[4] = this.setFrontFace;
      this.map[5] = this.setDepthMask;
      this.checks = [];
      this.defaultState = State.State.for2d();
      renderer.renderTarget.onRenderTargetChange.add(this);
    }
    onRenderTargetChange(renderTarget) {
      this._invertFrontFace = !renderTarget.isRoot;
      this._cullFace ? this.setFrontFace(this._frontFace) : this._frontFaceDirty = !0;
    }
    contextChange(gl) {
      this.gl = gl;
      this.blendModesMap = mapWebGLBlendModesToPixi.mapWebGLBlendModesToPixi(gl);
      this.resetState();
    }
    set(state) {
      state || (state = this.defaultState);
      if (this.stateId !== state.data) {
        var diff = this.stateId ^ state.data;
        let i = 0;
        for (; diff;) {
          diff & 1 && this.map[i].call(this, !!(state.data & 1 << i)), diff >>= 1, i++;
        }
        this.stateId = state.data;
      }
      for (diff = 0; diff < this.checks.length; diff++) {
        this.checks[diff](this, state);
      }
    }
    forceState(state) {
      state || (state = this.defaultState);
      for (var i = 0; i < this.map.length; i++) {
        this.map[i].call(this, !!(state.data & 1 << i));
      }
      for (i = 0; i < this.checks.length; i++) {
        this.checks[i](this, state);
      }
      this.stateId = state.data;
    }
    setBlend(value) {
      this._updateCheck(node_modules$pixi_DOT_js$lib$rendering$renderers$gl$state$GlStateSystem$classdecl$var26._checkBlendMode, value);
      this.gl[value ? "enable" : "disable"](this.gl.BLEND);
    }
    setOffset(value) {
      this._updateCheck(node_modules$pixi_DOT_js$lib$rendering$renderers$gl$state$GlStateSystem$classdecl$var26._checkPolygonOffset, value);
      this.gl[value ? "enable" : "disable"](this.gl.POLYGON_OFFSET_FILL);
    }
    setDepthTest(value) {
      this.gl[value ? "enable" : "disable"](this.gl.DEPTH_TEST);
    }
    setDepthMask(value) {
      this.gl.depthMask(value);
    }
    setCullFace(value) {
      this._cullFace = value;
      this.gl[value ? "enable" : "disable"](this.gl.CULL_FACE);
      this._cullFace && this._frontFaceDirty && this.setFrontFace(this._frontFace);
    }
    setFrontFace(value) {
      this._frontFace = value;
      this._frontFaceDirty = !1;
      value = this._invertFrontFace ? !value : value;
      this._glFrontFace !== value && (this._glFrontFace = value, this.gl.frontFace(this.gl[value ? "CW" : "CCW"]));
    }
    setBlendMode(value) {
      this.blendModesMap[value] || (value = "normal");
      if (value !== this.blendMode) {
        this.blendMode = value;
        value = this.blendModesMap[value];
        var gl = this.gl;
        2 === value.length ? gl.blendFunc(value[0], value[1]) : gl.blendFuncSeparate(value[0], value[1], value[2], value[3]);
        6 === value.length ? (this._blendEq = !0, gl.blendEquationSeparate(value[4], value[5])) : this._blendEq && (this._blendEq = !1, gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD));
      }
    }
    setPolygonOffset(value, scale) {
      this.gl.polygonOffset(value, scale);
    }
    resetState() {
      this._invertFrontFace = this._frontFaceDirty = this._cullFace = this._frontFace = this._glFrontFace = !1;
      this.gl.frontFace(this.gl.CCW);
      this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, !1);
      this.forceState(this.defaultState);
      this._blendEq = !0;
      this.blendMode = "";
      this.setBlendMode("normal");
    }
    _updateCheck(func, value) {
      const index = this.checks.indexOf(func);
      value && -1 === index ? this.checks.push(func) : value || -1 === index || this.checks.splice(index, 1);
    }
    static _checkBlendMode(system, state) {
      system.setBlendMode(state.blendMode);
    }
    static _checkPolygonOffset(system, state) {
      system.setPolygonOffset(1, state.polygonOffset);
    }
    destroy() {
      this.gl = null;
      this.checks.length = 0;
    }
  };
  require = node_modules$pixi_DOT_js$lib$rendering$renderers$gl$state$GlStateSystem$classdecl$var26;
  require.extension = {type:[global.ExtensionType.WebGLSystem], name:"state"};
  exports.GlStateSystem = require;
};

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