shadow$provide.module$node_modules$pixi_DOT_js$lib$rendering$renderers$gl$renderTarget$GlRenderTargetAdaptor = function(global, require, module, exports) {
  var Rectangle = require("module$node_modules$pixi_DOT_js$lib$maths$shapes$Rectangle"), warn = require("module$node_modules$pixi_DOT_js$lib$utils$logging$warn"), CanvasSource = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$texture$sources$CanvasSource"), _const = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$gl$const"), GlRenderTarget = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$gl$GlRenderTarget");
  "use strict";
  class GlRenderTargetAdaptor {
    constructor() {
      this._clearColorCache = [0, 0, 0, 0];
      this._viewPortCache = new Rectangle.Rectangle();
    }
    init(renderer, renderTargetSystem) {
      this._renderer = renderer;
      this._renderTargetSystem = renderTargetSystem;
      renderer.runners.contextChange.add(this);
    }
    contextChange() {
      this._clearColorCache = [0, 0, 0, 0];
      this._viewPortCache = new Rectangle.Rectangle();
      const gl = this._renderer.gl;
      this._drawBuffersCache = [];
      for (let i = 1; 16 >= i; i++) {
        this._drawBuffersCache[i] = Array.from({length:i}, (_, j) => gl.COLOR_ATTACHMENT0 + j);
      }
    }
    copyToTexture(sourceRenderSurfaceTexture, destinationTexture, originSrc, size, originDest) {
      const renderer = this._renderer, glRenderTarget = this._renderTargetSystem.getGpuRenderTarget(sourceRenderSurfaceTexture), gl = renderer.gl;
      this.finishRenderPass(sourceRenderSurfaceTexture);
      gl.bindFramebuffer(gl.FRAMEBUFFER, glRenderTarget.resolveTargetFramebuffer);
      renderer.texture.bind(destinationTexture, 0);
      gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, originDest.x, originDest.y, originSrc.x, originSrc.y, size.width, size.height);
      return destinationTexture;
    }
    startRenderPass(renderTarget, clear = !0, clearColor, viewport, mipLevel = 0, layer = 0) {
      var source = renderTarget.colorTexture;
      const gpuRenderTarget = this._renderTargetSystem.getGpuRenderTarget(renderTarget);
      if (0 !== layer && 2 > this._renderer.context.webGLVersion) {
        throw Error("[RenderTargetSystem] Rendering to array layers requires WebGL2.");
      }
      if (0 < mipLevel) {
        if (gpuRenderTarget.msaa) {
          throw Error("[RenderTargetSystem] Rendering to mip levels is not supported with MSAA render targets.");
        }
        if (2 > this._renderer.context.webGLVersion) {
          throw Error("[RenderTargetSystem] Rendering to mip levels requires WebGL2.");
        }
      }
      let viewPortY = viewport.y;
      renderTarget.isRoot && (viewPortY = source.pixelHeight - viewport.height - viewport.y);
      renderTarget.colorTextures.forEach(texture => {
        this._renderer.texture.unbind(texture);
      });
      const gl = this._renderer.gl;
      gl.bindFramebuffer(gl.FRAMEBUFFER, gpuRenderTarget.framebuffer);
      renderTarget.isRoot || gpuRenderTarget._attachedMipLevel === mipLevel && gpuRenderTarget._attachedLayer === layer || (renderTarget.colorTextures.forEach((colorTexture, i) => {
        colorTexture = this._renderer.texture.getGlSource(colorTexture);
        if (colorTexture.target === gl.TEXTURE_2D) {
          if (0 !== layer) {
            throw Error("[RenderTargetSystem] layer must be 0 when rendering to 2D textures in WebGL.");
          }
          gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.TEXTURE_2D, colorTexture.texture, mipLevel);
        } else if (colorTexture.target === gl.TEXTURE_2D_ARRAY) {
          if (2 > this._renderer.context.webGLVersion) {
            throw Error("[RenderTargetSystem] Rendering to 2D array textures requires WebGL2.");
          }
          gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, colorTexture.texture, mipLevel, layer);
        } else if (colorTexture.target === gl.TEXTURE_CUBE_MAP) {
          if (0 > layer || 5 < layer) {
            throw Error("[RenderTargetSystem] Cube map layer must be between 0 and 5.");
          }
          gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.TEXTURE_CUBE_MAP_POSITIVE_X + layer, colorTexture.texture, mipLevel);
        } else {
          throw Error("[RenderTargetSystem] Unsupported texture target for render-to-layer in WebGL.");
        }
      }), gpuRenderTarget._attachedMipLevel = mipLevel, gpuRenderTarget._attachedLayer = layer);
      1 < renderTarget.colorTextures.length && this._setDrawBuffers(renderTarget, gl);
      source = this._viewPortCache;
      if (source.x !== viewport.x || source.y !== viewPortY || source.width !== viewport.width || source.height !== viewport.height) {
        source.x = viewport.x, source.y = viewPortY, source.width = viewport.width, source.height = viewport.height, gl.viewport(viewport.x, viewPortY, viewport.width, viewport.height);
      }
      gpuRenderTarget.depthStencilRenderBuffer || !renderTarget.stencil && !renderTarget.depth || this._initStencil(gpuRenderTarget);
      this.clear(renderTarget, clear, clearColor);
    }
    finishRenderPass(renderTarget) {
      renderTarget = this._renderTargetSystem.getGpuRenderTarget(renderTarget);
      if (renderTarget.msaa) {
        var gl = this._renderer.gl;
        gl.bindFramebuffer(gl.FRAMEBUFFER, renderTarget.resolveTargetFramebuffer);
        gl.bindFramebuffer(gl.READ_FRAMEBUFFER, renderTarget.framebuffer);
        gl.blitFramebuffer(0, 0, renderTarget.width, renderTarget.height, 0, 0, renderTarget.width, renderTarget.height, gl.COLOR_BUFFER_BIT, gl.NEAREST);
        gl.bindFramebuffer(gl.FRAMEBUFFER, renderTarget.framebuffer);
      }
    }
    initGpuRenderTarget(renderTarget) {
      const gl = this._renderer.gl, glRenderTarget = new GlRenderTarget.GlRenderTarget();
      glRenderTarget._attachedMipLevel = 0;
      glRenderTarget._attachedLayer = 0;
      if (renderTarget.colorTexture instanceof CanvasSource.CanvasSource) {
        return this._renderer.context.ensureCanvasSize(renderTarget.colorTexture.resource), glRenderTarget.framebuffer = null, glRenderTarget;
      }
      this._initColor(renderTarget, glRenderTarget);
      gl.bindFramebuffer(gl.FRAMEBUFFER, null);
      return glRenderTarget;
    }
    destroyGpuRenderTarget(gpuRenderTarget) {
      const gl = this._renderer.gl;
      gpuRenderTarget.framebuffer && (gl.deleteFramebuffer(gpuRenderTarget.framebuffer), gpuRenderTarget.framebuffer = null);
      gpuRenderTarget.resolveTargetFramebuffer && (gl.deleteFramebuffer(gpuRenderTarget.resolveTargetFramebuffer), gpuRenderTarget.resolveTargetFramebuffer = null);
      gpuRenderTarget.depthStencilRenderBuffer && (gl.deleteRenderbuffer(gpuRenderTarget.depthStencilRenderBuffer), gpuRenderTarget.depthStencilRenderBuffer = null);
      gpuRenderTarget.msaaRenderBuffer.forEach(renderBuffer => {
        gl.deleteRenderbuffer(renderBuffer);
      });
      gpuRenderTarget.msaaRenderBuffer = null;
    }
    clear(_renderTarget, clear, clearColor, _viewport, _mipLevel, layer = 0) {
      if (clear) {
        if (0 !== layer) {
          throw Error("[RenderTargetSystem] Clearing array layers is not supported in WebGL renderer.");
        }
        _viewport = this._renderTargetSystem;
        "boolean" === typeof clear && (clear = clear ? _const.CLEAR.ALL : _const.CLEAR.NONE);
        _renderTarget = this._renderer.gl;
        clear & _const.CLEAR.COLOR && (clearColor ?? (clearColor = _viewport.defaultClearColor), _viewport = this._clearColorCache, _viewport[0] !== clearColor[0] || _viewport[1] !== clearColor[1] || _viewport[2] !== clearColor[2] || _viewport[3] !== clearColor[3]) && (_viewport[0] = clearColor[0], _viewport[1] = clearColor[1], _viewport[2] = clearColor[2], _viewport[3] = clearColor[3], _renderTarget.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]));
        _renderTarget.clear(clear);
      }
    }
    resizeGpuRenderTarget(renderTarget) {
      if (!renderTarget.isRoot) {
        var glRenderTarget = this._renderTargetSystem.getGpuRenderTarget(renderTarget);
        this._resizeColor(renderTarget, glRenderTarget);
        (renderTarget.stencil || renderTarget.depth) && this._resizeStencil(glRenderTarget);
      }
    }
    _initColor(renderTarget, glRenderTarget) {
      const renderer = this._renderer, gl = renderer.gl;
      var resolveTargetFramebuffer = gl.createFramebuffer();
      glRenderTarget.resolveTargetFramebuffer = resolveTargetFramebuffer;
      gl.bindFramebuffer(gl.FRAMEBUFFER, resolveTargetFramebuffer);
      glRenderTarget.width = renderTarget.colorTexture.source.pixelWidth;
      glRenderTarget.height = renderTarget.colorTexture.source.pixelHeight;
      renderTarget.colorTextures.forEach((colorTexture, i) => {
        colorTexture = colorTexture.source;
        colorTexture.antialias && (renderer.context.supports.msaa ? glRenderTarget.msaa = !0 : warn.warn("[RenderTexture] Antialiasing on textures is not supported in WebGL1"));
        renderer.texture.bindSource(colorTexture, 0);
        colorTexture = renderer.texture.getGlSource(colorTexture);
        const glTexture = colorTexture.texture;
        if (colorTexture.target === gl.TEXTURE_2D) {
          gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.TEXTURE_2D, glTexture, 0);
        } else if (colorTexture.target === gl.TEXTURE_2D_ARRAY) {
          if (2 > renderer.context.webGLVersion) {
            throw Error("[RenderTargetSystem] TEXTURE_2D_ARRAY requires WebGL2.");
          }
          gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, glTexture, 0, 0);
        } else if (colorTexture.target === gl.TEXTURE_CUBE_MAP) {
          gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.TEXTURE_CUBE_MAP_POSITIVE_X, glTexture, 0);
        } else {
          throw Error("[RenderTargetSystem] Unsupported texture target for framebuffer attachment.");
        }
      });
      glRenderTarget.msaa ? (resolveTargetFramebuffer = gl.createFramebuffer(), glRenderTarget.framebuffer = resolveTargetFramebuffer, gl.bindFramebuffer(gl.FRAMEBUFFER, resolveTargetFramebuffer), renderTarget.colorTextures.forEach((_, i) => {
        _ = gl.createRenderbuffer();
        glRenderTarget.msaaRenderBuffer[i] = _;
      })) : glRenderTarget.framebuffer = resolveTargetFramebuffer;
      this._resizeColor(renderTarget, glRenderTarget);
    }
    _resizeColor(renderTarget, glRenderTarget) {
      const source = renderTarget.colorTexture.source;
      glRenderTarget.width = source.pixelWidth;
      glRenderTarget.height = source.pixelHeight;
      glRenderTarget._attachedMipLevel = 0;
      glRenderTarget._attachedLayer = 0;
      renderTarget.colorTextures.forEach((colorTexture, i) => {
        0 !== i && colorTexture.source.resize(source.width, source.height, source._resolution);
      });
      if (glRenderTarget.msaa) {
        const renderer = this._renderer, gl = renderer.gl;
        gl.bindFramebuffer(gl.FRAMEBUFFER, glRenderTarget.framebuffer);
        renderTarget.colorTextures.forEach((colorTexture, i) => {
          colorTexture = colorTexture.source;
          renderer.texture.bindSource(colorTexture, 0);
          const glInternalFormat = renderer.texture.getGlSource(colorTexture).internalFormat, msaaRenderBuffer = glRenderTarget.msaaRenderBuffer[i];
          gl.bindRenderbuffer(gl.RENDERBUFFER, msaaRenderBuffer);
          gl.renderbufferStorageMultisample(gl.RENDERBUFFER, 4, glInternalFormat, colorTexture.pixelWidth, colorTexture.pixelHeight);
          gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.RENDERBUFFER, msaaRenderBuffer);
        });
      }
    }
    _initStencil(glRenderTarget) {
      if (null !== glRenderTarget.framebuffer) {
        var gl = this._renderer.gl, depthStencilRenderBuffer = gl.createRenderbuffer();
        glRenderTarget.depthStencilRenderBuffer = depthStencilRenderBuffer;
        gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencilRenderBuffer);
        gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, depthStencilRenderBuffer);
        this._resizeStencil(glRenderTarget);
      }
    }
    _resizeStencil(glRenderTarget) {
      const gl = this._renderer.gl;
      gl.bindRenderbuffer(gl.RENDERBUFFER, glRenderTarget.depthStencilRenderBuffer);
      glRenderTarget.msaa ? gl.renderbufferStorageMultisample(gl.RENDERBUFFER, 4, gl.DEPTH24_STENCIL8, glRenderTarget.width, glRenderTarget.height) : gl.renderbufferStorage(gl.RENDERBUFFER, 2 === this._renderer.context.webGLVersion ? gl.DEPTH24_STENCIL8 : gl.DEPTH_STENCIL, glRenderTarget.width, glRenderTarget.height);
    }
    prerender(renderTarget) {
      renderTarget = renderTarget.colorTexture.resource;
      this._renderer.context.multiView && CanvasSource.CanvasSource.test(renderTarget) && this._renderer.context.ensureCanvasSize(renderTarget);
    }
    postrender(renderTarget) {
      if (this._renderer.context.multiView && CanvasSource.CanvasSource.test(renderTarget.colorTexture.resource)) {
        const contextCanvas = this._renderer.context.canvas;
        renderTarget = renderTarget.colorTexture;
        renderTarget.context2D.drawImage(contextCanvas, 0, renderTarget.pixelHeight - contextCanvas.height);
      }
    }
    _setDrawBuffers(renderTarget, gl) {
      renderTarget = this._drawBuffersCache[renderTarget.colorTextures.length];
      1 === this._renderer.context.webGLVersion ? (gl = this._renderer.context.extensions.drawBuffers) ? gl.drawBuffersWEBGL(renderTarget) : warn.warn("[RenderTexture] This WebGL1 context does not support rendering to multiple targets") : gl.drawBuffers(renderTarget);
    }
  }
  exports.GlRenderTargetAdaptor = GlRenderTargetAdaptor;
};

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