import Kernel from '../Kernel' ; import Program from '../Program' ; import Graphic from './Graphic' ; import Line from '../geometries/Line' ; import ColorMaterial from '../materials/ColorMaterial' ; import Camera from '../Camera' ; const vs = `
attribute vec3 aPosition;
uniform vec3 uColor;
varying vec4 vColor;
uniform mat4 uPMVMatrix;

void main(void)
{
    gl_Position = uPMVMatrix * vec4(aPosition, 1.0);
    vColor = vec4(uColor,1.0);
}
` ; const fs = `
#ifdef GL_ES
precision highp float;
#endif

varying vec4 vColor;

void main(void) {
    gl_FragColor = vColor;
}
` ; export default class LineGraphic extends Graphic { constructor ( public geometry , public material , public lineWidth = 1 ) { super ( geometry , material ) ; } isReady ( ) { return this . geometry . isReady ( ) ; } createProgram ( ) { return Program . getProgram ( vs , fs ) ; } protected onDraw ( camera ) { const gl = Kernel . gl ; var pmvMatrix = camera . getProjViewMatrixForDraw ( ) ; var locPMVMatrix = this . program . getUniformLocation ( 'uPMVMatrix' ) ; gl . uniformMatrix4fv ( locPMVMatrix , false , pmvMatrix . getFloat32Array ( ) ) ; var locPosition = this . program . getAttribLocation ( 'aPosition' ) ; this . program . enableVertexAttribArray ( 'aPosition' ) ; this . geometry . vbo . bind ( ) ; gl . vertexAttribPointer ( locPosition , 3 , Kernel . gl . FLOAT , false , 0 , 0 ) ; var locColor = this . program . getUniformLocation ( 'uColor' ) ; gl . uniform3fv ( locColor , this . material . color ) ; gl . lineWidth ( this . lineWidth ) ; gl . drawArrays ( gl . LINE_STRIP , 0 , this . geometry . getVerticeCount ( ) ) ; } }