'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var Matrix = require('../../maths/Matrix.js');
var compileHighShaderToProgram = require('../../rendering/high-shader/compileHighShaderToProgram.js');
var localUniformBit = require('../../rendering/high-shader/shader-bits/localUniformBit.js');
var Shader = require('../../rendering/renderers/shared/shader/Shader.js');
var UniformGroup = require('../../rendering/renderers/shared/shader/UniformGroup.js');
var tilingBit = require('./tilingBit.js');

class TilingSpriteShader extends Shader.Shader {
  constructor(options) {
    const gpuProgram = compileHighShaderToProgram.compileHighShaderGpuProgram({
      name: "tiling-sprite-shader",
      bits: [
        localUniformBit.localUniformBit,
        tilingBit.tilingBit
      ]
    });
    const glProgram = compileHighShaderToProgram.compileHighShaderGlProgram({
      name: "tiling-sprite-shader",
      bits: [
        localUniformBit.localUniformBitGl,
        tilingBit.tilingBitGl
      ]
    });
    const tilingUniforms = new UniformGroup.UniformGroup({
      uMapCoord: { value: new Matrix.Matrix(), type: "mat3x3<f32>" },
      uClampFrame: { value: new Float32Array([0, 0, 1, 1]), type: "vec4<f32>" },
      uClampOffset: { value: new Float32Array([0, 0]), type: "vec2<f32>" },
      uTextureTransform: { value: new Matrix.Matrix(), type: "mat3x3<f32>" },
      uSizeAnchor: { value: new Float32Array([100, 200, 0.5, 0.5]), type: "vec4<f32>" }
    });
    super({
      glProgram,
      gpuProgram,
      resources: {
        tilingUniforms,
        uTexture: options.texture.source,
        uSampler: options.texture.source.style
      }
    });
  }
  get texture() {
    return this._texture;
  }
  set texture(value) {
    if (this._texture === value)
      return;
    this._texture = value;
    this.resources.uTexture = value.source;
    this.resources.uSampler = value.source.style;
  }
}

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