/*
 * This class copies our node.border program, but with another fragment shader to support dashed borders
 */
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 __());
    };
})();
import { floatColor } from 'sigma/utils';
import { AbstractNodeProgram } from 'sigma/rendering/webgl/programs/common/node';
import { vertexShaderSource } from './shaders/node.border.vert.glsl';
import { fragmentShaderSource } from './shaders/node.dashed.border.frag.glsl';
var POINTS = 1; // number of vertices for a node
var ATTRIBUTES = 6; // number of attributes for one vertex
var NodeDashedBorderProgram = /** @class */ (function (_super) {
    __extends(NodeDashedBorderProgram, _super);
    function NodeDashedBorderProgram(gl) {
        var _this = _super.call(this, gl, vertexShaderSource, 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;
    }
    NodeDashedBorderProgram.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);
    };
    NodeDashedBorderProgram.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++] = floatColor(data.color); // color
        array[i++] = data.highlighted ? 2 : 1; // size of border in pixels
        array[i] = data.inactive ? 1 : 0; // inactive flag
    };
    NodeDashedBorderProgram.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 NodeDashedBorderProgram;
}(AbstractNodeProgram));
export { NodeDashedBorderProgram };
