"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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        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 });
var utils_1 = require("../../../utils");
var node_1 = require("./common/node");
var node_circle_vert_glsl_1 = __importDefault(require("../shaders/node.circle.vert.glsl.js"));
var node_circle_frag_glsl_1 = __importDefault(require("../shaders/node.circle.frag.glsl.js"));
var UNSIGNED_BYTE = WebGLRenderingContext.UNSIGNED_BYTE, FLOAT = WebGLRenderingContext.FLOAT;
var UNIFORMS = ["u_sizeRatio", "u_correctionRatio", "u_matrix"];
var NodeCircleProgram = /** @class */ (function (_super) {
    __extends(NodeCircleProgram, _super);
    function NodeCircleProgram() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    NodeCircleProgram.prototype.getDefinition = function () {
        return {
            VERTICES: 3,
            VERTEX_SHADER_SOURCE: node_circle_vert_glsl_1.default,
            FRAGMENT_SHADER_SOURCE: node_circle_frag_glsl_1.default,
            METHOD: WebGLRenderingContext.TRIANGLES,
            UNIFORMS: UNIFORMS,
            ATTRIBUTES: [
                { name: "a_position", size: 2, type: FLOAT },
                { name: "a_size", size: 1, type: FLOAT },
                { name: "a_color", size: 4, type: UNSIGNED_BYTE, normalized: true },
                { name: "a_id", size: 4, type: UNSIGNED_BYTE, normalized: true },
            ],
            CONSTANT_ATTRIBUTES: [{ name: "a_angle", size: 1, type: FLOAT }],
            CONSTANT_DATA: [[NodeCircleProgram.ANGLE_1], [NodeCircleProgram.ANGLE_2], [NodeCircleProgram.ANGLE_3]],
        };
    };
    NodeCircleProgram.prototype.processVisibleItem = function (nodeIndex, startIndex, data) {
        var array = this.array;
        var color = (0, utils_1.floatColor)(data.color);
        array[startIndex++] = data.x;
        array[startIndex++] = data.y;
        array[startIndex++] = data.size;
        array[startIndex++] = color;
        array[startIndex++] = nodeIndex;
    };
    NodeCircleProgram.prototype.setUniforms = function (params, _a) {
        var gl = _a.gl, uniformLocations = _a.uniformLocations, isPicking = _a.isPicking;
        var u_sizeRatio = uniformLocations.u_sizeRatio, u_correctionRatio = uniformLocations.u_correctionRatio, u_matrix = uniformLocations.u_matrix;
        gl.uniform1f(u_correctionRatio, params.correctionRatio);
        gl.uniform1f(u_sizeRatio, isPicking ? params.downSizedSizeRatio : params.sizeRatio);
        gl.uniformMatrix3fv(u_matrix, false, params.matrix);
    };
    NodeCircleProgram.ANGLE_1 = 0;
    NodeCircleProgram.ANGLE_2 = (2 * Math.PI) / 3;
    NodeCircleProgram.ANGLE_3 = (4 * Math.PI) / 3;
    return NodeCircleProgram;
}(node_1.NodeProgram));
exports.default = NodeCircleProgram;
