'use strict';

var constants = require('../../constants.js');
require('../../utils/settings.js');
var index = require('../../utils/is_mobile/index.js');
require('../../color.js');
require('../../utils/color/premultiply.js');
require('../../utils/media/BoundingBox.js');
var caches = require('../../utils/media/caches.js');
var defaultProgram$1 = require('./defaultProgram.frag.js');
var defaultProgram = require('./defaultProgram.vert.js');

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 defaultProgram.default;
  }
  /**
   * The default fragment shader source.
   * @readonly
   */
  static get defaultFragmentSrc() {
    return defaultProgram$1.default;
  }
  /**
   * 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 = caches.ProgramCache[key];
    if (!program) {
      caches.ProgramCache[key] = program = new Program({ vertex: vertexSrc, fragment: fragmentSrc, name });
    }
    return program;
  }
}
Program.defaultVertexPrecision = constants.PRECISION.HIGH;
Program.defaultFragmentPrecision = index.isMobile.apple.device ? constants.PRECISION.HIGH : constants.PRECISION.MEDIUM;

exports.Program = Program;
//# sourceMappingURL=Program.js.map
