module import { AbstractProgram , IProgram , RenderParams } from "./program" ; import { NodeDisplayData } from "../../../../types" ; import Sigma from "../../../../sigma" ; export interface INodeProgram extends IProgram { process ( data , hidden , offset ) : void ; render ( params ) : void ; } constructor export abstract class AbstractNodeProgram extends AbstractProgram implements INodeProgram { positionLocation : GLint ; sizeLocation : GLint ; colorLocation : GLint ; matrixLocation : WebGLUniformLocation ; ratioLocation : WebGLUniformLocation ; scaleLocation : WebGLUniformLocation ; constructor ( gl , vertexShaderSource , fragmentShaderSource , points , attributes ) { super ( gl , vertexShaderSource , fragmentShaderSource , points , attributes ) ; this . positionLocation = gl . getAttribLocation ( this . program , "a_position" ) ; this . sizeLocation = gl . getAttribLocation ( this . program , "a_size" ) ; this . colorLocation = gl . getAttribLocation ( this . program , "a_color" ) ; const matrixLocation = gl . getUniformLocation ( this . program , "u_matrix" ) ; if ( matrixLocation === null ) throw new Error ( "AbstractNodeProgram: error while getting matrixLocation" ) ; this . matrixLocation = matrixLocation ; const ratioLocation = gl . getUniformLocation ( this . program , "u_ratio" ) ; if ( ratioLocation === null ) throw new Error ( "AbstractNodeProgram: error while getting ratioLocation" ) ; this . ratioLocation = ratioLocation ; const scaleLocation = gl . getUniformLocation ( this . program , "u_scale" ) ; if ( scaleLocation === null ) throw new Error ( "AbstractNodeProgram: error while getting scaleLocation" ) ; this . scaleLocation = scaleLocation ; } bind ( ) { const gl = this . gl ; gl . enableVertexAttribArray ( this . positionLocation ) ; gl . enableVertexAttribArray ( this . sizeLocation ) ; gl . enableVertexAttribArray ( this . colorLocation ) ; gl . vertexAttribPointer ( this . positionLocation , 2 , gl . FLOAT , false , this . attributes * Float32Array . BYTES_PER_ELEMENT , 0 ) ; gl . vertexAttribPointer ( this . sizeLocation , 1 , gl . FLOAT , false , this . attributes * Float32Array . BYTES_PER_ELEMENT , 8 ) ; gl . vertexAttribPointer ( this . colorLocation , 4 , gl . UNSIGNED_BYTE , true , this . attributes * Float32Array . BYTES_PER_ELEMENT , 12 ) ; } abstract process ( data , hidden , offset ) ; } export interface NodeProgramConstructor { new ( gl , renderer ) : INodeProgram ; } param { array } programClasses return { function } export function createNodeCompoundProgram ( programClasses ) { return class NodeCompoundProgram implements INodeProgram { programs : Array < INodeProgram > ; constructor ( gl , renderer ) { this . programs = programClasses . map ( ( ProgramClass ) => new ProgramClass ( gl , renderer ) ) ; } bufferData ( ) { this . programs . forEach ( ( program ) => program . bufferData ( ) ) ; } allocate ( capacity ) { this . programs . forEach ( ( program ) => program . allocate ( capacity ) ) ; } bind ( ) { } render ( params ) { this . programs . forEach ( ( program ) => program . render ( params ) ) ; } process ( data , hidden , offset ) { this . programs . forEach ( ( program ) => program . process ( data , hidden , offset ) ) ; } } ; }