text: "use strict";
  var __extends = (this && this.__extends) || (function () {
      var extendStatics = function (d, b) {
          extendStatics = Object.setPrototypeOf ||
              ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
              function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
          return extendStatics(d, b);
      };
      return function (d, b) {
          extendStatics(d, b);
          function __() { this.constructor = d; }
          d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
      };
  })();
  var __importDefault = (this && this.__importDefault) || function (mod) {
      return (mod && mod.__esModule) ? mod : { "default": mod };
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  /**
   * Sigma.js WebGL Renderer Quadratic Bezier Edge Program
   * ======================================================
   *
   * TODO
   */
  var program_1 = __importDefault(require("./program"));
  var utils_1 = require("../utils");
  var edge_quadraticBezier_vert_glsl_1 = __importDefault(require("../shaders/edge.quadraticBezier.vert.glsl.js"));
  var edge_quadraticBezier_frag_glsl_1 = __importDefault(require("../shaders/edge.quadraticBezier.frag.glsl.js"));
  var POINTS = 3, ATTRIBUTES = 5;
  var EdgeQuadraticBezierProgram = /** @class */ (function (_super) {
      __extends(EdgeQuadraticBezierProgram, _super);
      function EdgeQuadraticBezierProgram(gl) {
          var _this = _super.call(this, gl, edge_quadraticBezier_vert_glsl_1.default, edge_quadraticBezier_frag_glsl_1.default) || this;
          // Locations
          _this.positionLocation = gl.getAttribLocation(_this.program, "a_position");
          // this.thicknessLocation = gl.getAttribLocation(this.program, 'a_thickness');
          _this.colorLocation = gl.getAttribLocation(_this.program, "a_color");
          _this.coordLocation = gl.getAttribLocation(_this.program, "a_coord");
          _this.resolutionLocation = gl.getUniformLocation(_this.program, "u_resolution");
          _this.ratioLocation = gl.getUniformLocation(_this.program, "u_ratio");
          _this.matrixLocation = gl.getUniformLocation(_this.program, "u_matrix");
          _this.scaleLocation = gl.getUniformLocation(_this.program, "u_scale");
          // Bindings
          gl.enableVertexAttribArray(_this.positionLocation);
          // gl.enableVertexAttribArray(this.thicknessLocation);
          gl.enableVertexAttribArray(_this.colorLocation);
          gl.enableVertexAttribArray(_this.coordLocation);
          gl.vertexAttribPointer(_this.positionLocation, 2, gl.FLOAT, false, ATTRIBUTES * Float32Array.BYTES_PER_ELEMENT, 0);
          // gl.vertexAttribPointer(this.thicknessLocation,
          //   1,
          //   gl.FLOAT,
          //   false,
          //   ATTRIBUTES * Float32Array.BYTES_PER_ELEMENT,
          //   8
          // );
          gl.vertexAttribPointer(_this.colorLocation, 4, gl.UNSIGNED_BYTE, true, ATTRIBUTES * Float32Array.BYTES_PER_ELEMENT, 8);
          gl.vertexAttribPointer(_this.coordLocation, 2, gl.FLOAT, false, ATTRIBUTES * Float32Array.BYTES_PER_ELEMENT, 12);
          return _this;
      }
      EdgeQuadraticBezierProgram.prototype.allocate = function (capacity) {
          this.array = new Float32Array(POINTS * ATTRIBUTES * capacity);
      };
      EdgeQuadraticBezierProgram.prototype.process = function (sourceData, targetData, data, offset) {
          var i = 0;
          if (sourceData.hidden || targetData.hidden || data.hidden) {
              for (var l = i + POINTS * ATTRIBUTES; i < l; i++)
                  this.array[i] = 0;
          }
          var x1 = sourceData.x, y1 = sourceData.y, x2 = targetData.x, y2 = targetData.y, color = utils_1.floatColor(data.color);
          i = POINTS * ATTRIBUTES * offset;
          var array = this.array;
          // Control point
          array[i++] = (x1 + x2) / 2 + (y2 - y1) / 4;
          array[i++] = (y1 + y2) / 2 + (x1 - x2) / 4;
          // array[i++] = thickness;
          array[i++] = color;
          array[i++] = 0.5;
          array[i++] = 0;
          // First point
          array[i++] = x1;
          array[i++] = y1;
          // array[i++] = thickness;
          array[i++] = color;
          array[i++] = 0;
          array[i++] = 0;
          // Second point
          array[i++] = x2;
          array[i++] = y2;
          // array[i++] = thickness;
          array[i++] = color;
          array[i++] = 1;
          array[i] = 1;
      };
      EdgeQuadraticBezierProgram.prototype.bufferData = function () {
          var gl = this.gl;
          // Vertices data
          gl.bufferData(gl.ARRAY_BUFFER, this.array, gl.DYNAMIC_DRAW);
      };
      EdgeQuadraticBezierProgram.prototype.render = function (params) {
          var gl = this.gl;
          var program = this.program;
          gl.useProgram(program);
          // Binding uniforms
          gl.uniform2f(this.resolutionLocation, params.width, params.height);
          gl.uniform1f(this.ratioLocation, params.ratio / Math.pow(params.ratio, params.edgesPowRatio));
          gl.uniformMatrix3fv(this.matrixLocation, false, params.matrix);
          gl.uniform1f(this.scaleLocation, params.ratio);
          // Drawing:
          gl.drawArrays(gl.TRIANGLES, 0, this.array.length / ATTRIBUTES);
      };
      return EdgeQuadraticBezierProgram;
  }(program_1.default));
  exports.default = EdgeQuadraticBezierProgram;
  