module import { loadVertexShader , loadFragmentShader , loadProgram } from "../../shaders/utils" ; export interface RenderParams { width : number ; height : number ; ratio : number ; matrix : Float32Array ; scalingRatio : number ; correctionRatio : number ; } export interface IProgram { bufferData ( ) : void ; allocate ( capacity ) : void ; bind ( ) : void ; render ( params ) : void ; } constructor export abstract class AbstractProgram implements IProgram { points : number ; attributes : number ; gl : WebGLRenderingContext ; array : Float32Array = new Float32Array ( ) ; buffer : WebGLBuffer ; vertexShaderSource : string ; vertexShader : WebGLShader ; fragmentShaderSource : string ; fragmentShader : WebGLShader ; program : WebGLProgram ; constructor ( gl , vertexShaderSource , fragmentShaderSource , points , attributes ) { this . points = points ; this . attributes = attributes ; this . gl = gl ; this . vertexShaderSource = vertexShaderSource ; this . fragmentShaderSource = fragmentShaderSource ; const buffer = gl . createBuffer ( ) ; if ( buffer === null ) throw new Error ( "AbstractProgram: error while creating the buffer" ) ; this . buffer = buffer ; gl . bindBuffer ( gl . ARRAY_BUFFER , this . buffer ) ; this . vertexShader = loadVertexShader ( gl , this . vertexShaderSource ) ; this . fragmentShader = loadFragmentShader ( gl , this . fragmentShaderSource ) ; this . program = loadProgram ( gl , [ this . vertexShader , this . fragmentShader ] ) ; } bufferData ( ) { const gl = this . gl ; gl . bufferData ( gl . ARRAY_BUFFER , this . array , gl . DYNAMIC_DRAW ) ; } allocate ( capacity ) { this . array = new Float32Array ( this . points * this . attributes * capacity ) ; } hasNothingToRender ( ) { return this . array . length === 0 ; } abstract bind ( ) ; abstract render ( params ) ; }