import { PRECISION } from '../../constants.mjs';
import '../../utils/settings.mjs';
import { isMobile } from '../../utils/is_mobile/index.mjs';
import '../../color.mjs';
import '../../utils/color/premultiply.mjs';
import '../../utils/media/BoundingBox.mjs';
import { ProgramCache } from '../../utils/media/caches.mjs';
import defaultFragment from './defaultProgram.frag.mjs';
import defaultVertex from './defaultProgram.vert.mjs';

let UID = 0;
class Program {
  /**
   * @param vertex - The source of the vertex shader.
   * @param fragment - The source of the fragment shader.
   * @param name - Name for shader
   * @param extra - Extra data for shader
   */
  constructor({ fragment, vertex, name }, extra = {}) {
    this.vertexProcessed = null;
    this.fragmentProcessed = null;
    this.options = {};
    this.extra = {};
    this.id = UID++;
    this.fragment = fragment;
    this.vertex = vertex;
    this.options.setProgramName = { name };
    this.key = `${this.vertex}:${this.fragment}`;
    this.vertex = vertex || Program.defaultVertexSrc;
    this.fragment = fragment || Program.defaultFragmentSrc;
    this.extra = extra;
    this.glPrograms = {};
    this.syncUniforms = null;
    this.vertexProcessed = "";
    this.fragmentProcessed = "";
  }
  getLocationListByAttributes(names) {
    const res = [];
    for (let i = 0; i < names.length; i++) {
      const attribData = this.attributeData[names[i]];
      if (attribData) {
        res.push(attribData.location);
      }
    }
    return res;
  }
  /**
   * The default vertex shader source.
   * @readonly
   */
  static get defaultVertexSrc() {
    return defaultVertex;
  }
  /**
   * The default fragment shader source.
   * @readonly
   */
  static get defaultFragmentSrc() {
    return defaultFragment;
  }
  /**
   * A short hand function to create a program based of a vertex and fragment shader.
   *
   * This method will also check to see if there is a cached program.
   * @param vertexSrc - The source of the vertex shader.
   * @param fragmentSrc - The source of the fragment shader.
   * @param name - Name for shader
   * @returns A shiny new PixiJS shader program!
   */
  static from(vertexSrc, fragmentSrc, name) {
    const key = `${vertexSrc}:${fragmentSrc}`;
    let program = ProgramCache[key];
    if (!program) {
      ProgramCache[key] = program = new Program({ vertex: vertexSrc, fragment: fragmentSrc, name });
    }
    return program;
  }
}
Program.defaultVertexPrecision = PRECISION.HIGH;
Program.defaultFragmentPrecision = isMobile.apple.device ? PRECISION.HIGH : PRECISION.MEDIUM;

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