import { ensurePrecision } from './program/ensurePrecision.mjs';
import { getMaxFragmentPrecision } from './program/getMaxFragmentPrecision.mjs';
import { setProgramName } from './program/setProgramName.mjs';
import { setProgramVersion } from './program/setProgramVersion.mjs';

const processes = {
  ensurePrecision,
  setProgramName,
  setProgramVersion
};
const _GlProgram = class {
  constructor(options) {
    options = { ..._GlProgram.defaultOptions, ...options };
    const preprocessorOptions = {
      ensurePrecision: {
        requestedFragmentPrecision: options.preferredFragmentPrecision,
        requestedVertexPrecision: options.preferredVertexPrecision,
        maxSupportedVertexPrecision: "highp",
        maxSupportedFragmentPrecision: getMaxFragmentPrecision()
      },
      setProgramName: {
        name: options.name
      },
      setProgramVersion: {
        version: "300 es"
      }
    };
    let fragment = options.fragment;
    let vertex = options.vertex;
    Object.keys(processes).forEach((processKey) => {
      const processOptions = preprocessorOptions[processKey] ?? {};
      fragment = processes[processKey](fragment, processOptions, true);
      vertex = processes[processKey](vertex, processOptions, false);
    });
    this.fragment = fragment;
    this.vertex = vertex;
    this.key = `${this.vertex}:${this.fragment}`;
  }
  destroy() {
    this.fragment = null;
    this.vertex = null;
    this.attributeData = null;
    this.uniformData = null;
    this.uniformBlockData = null;
    this.transformFeedbackVaryings = null;
  }
  static from(options) {
    const key = `${options.vertex}:${options.fragment}`;
    if (!_GlProgram.programCached[key]) {
      _GlProgram.programCached[key] = new _GlProgram(options);
    }
    return _GlProgram.programCached[key];
  }
};
let GlProgram = _GlProgram;
GlProgram.defaultOptions = {
  preferredVertexPrecision: "highp",
  preferredFragmentPrecision: "mediump"
};
GlProgram.programCached = /* @__PURE__ */ Object.create(null);

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