"use strict";
/*
 * This class copies sigma/examples/custom-rendering/programs/node.border, but with a some
 * difference: The fragment shader ("./node.border.frag.glsl") draws a transparent
 * disc with a colored border. Size of border depends on hasBorder and highlighted props
 */
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 __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeBorderProgram = void 0;
var utils_1 = require("sigma/utils");
var node_1 = require("sigma/rendering/webgl/programs/common/node");
var node_border_vert_glsl_1 = require("./shaders/node.border.vert.glsl");
var node_border_frag_glsl_1 = require("./shaders/node.border.frag.glsl");
var POINTS = 1; // number of vertices for a node
var ATTRIBUTES = 6; // number of attributes for one vertex
var NodeBorderProgram = /** @class */ (function (_super) {
    __extends(NodeBorderProgram, _super);
    function NodeBorderProgram(gl) {
        var _this = _super.call(this, gl, node_border_vert_glsl_1.vertexShaderSource, node_border_frag_glsl_1.fragmentShaderSource, POINTS, ATTRIBUTES) || this;
        // Attribute Location
        _this.borderSize = gl.getAttribLocation(_this.program, 'a_borderSize');
        _this.inactive = gl.getAttribLocation(_this.program, 'a_inactive');
        _this.bind();
        return _this;
    }
    NodeBorderProgram.prototype.bind = function () {
        _super.prototype.bind.call(this);
        var gl = this.gl;
        gl.enableVertexAttribArray(this.borderSize);
        gl.enableVertexAttribArray(this.inactive);
        gl.vertexAttribPointer(this.borderSize, 1, gl.FLOAT, false, this.attributes * Float32Array.BYTES_PER_ELEMENT, 16);
        gl.vertexAttribPointer(this.inactive, 1, gl.FLOAT, false, this.attributes * Float32Array.BYTES_PER_ELEMENT, 20);
    };
    NodeBorderProgram.prototype.process = function (data, hidden, offset) {
        var array = this.array;
        var i = offset * POINTS * ATTRIBUTES;
        if (hidden || !data.hasBorder) {
            // draw border only for nodes with hasBorder or not hidden
            array[i++] = 0;
            array[i++] = 0;
            array[i++] = 0;
            array[i++] = 0;
            array[i++] = 0;
            array[i++] = 0;
            return;
        }
        array[i++] = data.x; // position of center
        array[i++] = data.y;
        array[i++] = data.size; // size
        array[i++] = (0, utils_1.floatColor)(data.color); // color
        array[i++] = data.highlighted ? 4 : 2; // size of border in pixels
        array[i] = data.inactive ? 1 : 0; // inactive flag
    };
    NodeBorderProgram.prototype.render = function (params) {
        var gl = this.gl;
        var program = this.program;
        gl.useProgram(program);
        gl.uniform1f(this.ratioLocation, 1 / Math.sqrt(params.ratio));
        gl.uniform1f(this.scaleLocation, params.scalingRatio);
        gl.uniformMatrix3fv(this.matrixLocation, false, params.matrix);
        gl.drawArrays(gl.POINTS, 0, this.array.length / ATTRIBUTES);
    };
    return NodeBorderProgram;
}(node_1.AbstractNodeProgram));
exports.NodeBorderProgram = NodeBorderProgram;
