import '../core/settings.mjs';
import { Color } from '../color.mjs';
import '../constants.mjs';
import '../extensions.mjs';
import '../math/const.mjs';
import '../math/groupD8.mjs';
import { Matrix } from '../math/Matrix.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 { Program } from '../core/shader/Program.mjs';
import { Shader } from '../core/shader/Shader.mjs';
import '../core/batch/BatchSystem.mjs';
import '../core/context/ContextSystem.mjs';
import '../core/filters/Filter.mjs';
import '../core/filters/FilterSystem.mjs';
import { TextureMatrix } from '../core/textures/TextureMatrix.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';
import fragment from './shader/mesh.frag.mjs';
import vertex from './shader/mesh.vert.mjs';

class MeshMaterial extends Shader {
  /**
   * @param uSampler - Texture that material uses to render.
   * @param options - Additional options
   * @param {number} [options.alpha=1] - Default alpha.
   * @param {PIXI.ColorSource} [options.tint=0xFFFFFF] - Default tint.
   * @param {string} [options.pluginName='batch'] - Renderer plugin for batching.
   * @param {PIXI.Program} [options.program=0xFFFFFF] - Custom program.
   * @param {object} [options.uniforms] - Custom uniforms.
   */
  constructor(uSampler, options) {
    const uniforms = {
      uSampler,
      alpha: 1,
      uTextureMatrix: Matrix.IDENTITY,
      uColor: new Float32Array([1, 1, 1, 1])
    };
    options = Object.assign({
      tint: 16777215,
      alpha: 1,
      pluginName: "batch"
    }, options);
    if (options.uniforms) {
      Object.assign(uniforms, options.uniforms);
    }
    super(options.program || Program.from(vertex, fragment), uniforms);
    this._colorDirty = false;
    this.uvMatrix = new TextureMatrix(uSampler);
    this.batchable = options.program === void 0;
    this.pluginName = options.pluginName;
    this._tintColor = new Color(options.tint);
    this._tintRGB = this._tintColor.toLittleEndianNumber();
    this._colorDirty = true;
    this.alpha = options.alpha;
  }
  /** Reference to the texture being rendered. */
  get texture() {
    return this.uniforms.uSampler;
  }
  set texture(value) {
    if (this.uniforms.uSampler !== value) {
      if (!this.uniforms.uSampler.baseTexture.alphaMode !== !value.baseTexture.alphaMode) {
        this._colorDirty = true;
      }
      this.uniforms.uSampler = value;
      this.uvMatrix.texture = value;
    }
  }
  /**
   * This gets automatically set by the object using this.
   * @default 1
   */
  set alpha(value) {
    if (value === this._alpha)
      return;
    this._alpha = value;
    this._colorDirty = true;
  }
  get alpha() {
    return this._alpha;
  }
  /**
   * Multiply tint for the material.
   * @default 0xFFFFFF
   */
  set tint(value) {
    if (value === this.tint)
      return;
    this._tintColor.setValue(value);
    this._tintRGB = this._tintColor.toLittleEndianNumber();
    this._colorDirty = true;
  }
  get tint() {
    return this._tintColor.value;
  }
  /**
   * Get the internal number from tint color
   * @ignore
   */
  get tintValue() {
    return this._tintColor.toNumber();
  }
  /** Gets called automatically by the Mesh. Intended to be overridden for custom {@link PIXI.MeshMaterial} objects. */
  update() {
    if (this._colorDirty) {
      this._colorDirty = false;
      const baseTexture = this.texture.baseTexture;
      const applyToChannels = baseTexture.alphaMode;
      Color.shared.setValue(this._tintColor).premultiply(this._alpha, applyToChannels).toArray(this.uniforms.uColor);
    }
    if (this.uvMatrix.update()) {
      this.uniforms.uTextureMatrix = this.uvMatrix.mapCoord;
    }
  }
}

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