import Kernel from '../Kernel' ; import Utils from '../Utils' ; import Camera from '../Camera' ; import MathUtils from '../math/Utils' ; import Program from '../Program' ; import Graphic from '../graphics/Graphic' ; import MarkerTextureMaterial from '../materials/MarkerTextureMaterial' ; import VertexBufferObject from '../VertexBufferObject' ; import Vertice from '../math/Vertice' ; const vs = `
attribute vec3 aPosition;
uniform mat4 uPMVMatrix;
uniform float uSize;

void main(void) {
  gl_Position = uPMVMatrix * vec4(aPosition, 1.0);
  gl_PointSize = uSize;
}
` ; const fs = `
precision mediump float;
uniform sampler2D uSampler;

void main()
{
	vec4 color = texture2D(uSampler, vec2(gl_PointCoord.x, gl_PointCoord.y));
  if(color.a == 0.0){
    discard;
  }
  gl_FragColor = color;
}
` ; export default class MultiPointsGraphic extends Graphic { private vbo : VertexBufferObject = null ; private vertices : Vertice [ ] = null ; constructor ( public material ) { super ( null , material ) ; this . vbo = new VertexBufferObject ( Kernel . gl . ARRAY_BUFFER ) ; this . vertices = [ ] ; } createProgram ( ) { return Program . getProgram ( vs , fs ) ; } isReady ( ) { return ! ! ( this . vertices . length > 0 && this . material && this . material . isReady ( ) ) ; } onDraw ( camera ) { const gl = Kernel . gl ; gl . disable ( Kernel . gl . DEPTH_TEST ) ; gl . depthMask ( false ) ; gl . enable ( Kernel . gl . BLEND ) ; gl . blendFunc ( Kernel . gl . SRC_ALPHA , Kernel . gl . ONE_MINUS_SRC_ALPHA ) ; var locPosition = this . program . getAttribLocation ( 'aPosition' ) ; this . program . enableVertexAttribArray ( 'aPosition' ) ; this . vbo . bind ( ) ; var vertices = [ ] ; this . vertices . map ( function ( vertice ) { vertices . push ( vertice . x , vertice . y , vertice . z ) ; } ) ; this . vbo . bufferData ( vertices , Kernel . gl . DYNAMIC_DRAW , true ) ; gl . vertexAttribPointer ( locPosition , 3 , Kernel . gl . FLOAT , false , 0 , 0 ) ; var pmvMatrix = camera . getProjViewMatrixForDraw ( ) ; var locPMVMatrix = this . program . getUniformLocation ( 'uPMVMatrix' ) ; gl . uniformMatrix4fv ( locPMVMatrix , false , pmvMatrix . getFloat32Array ( ) ) ; var locSize = this . program . getUniformLocation ( 'uSize' ) ; gl . uniform1f ( locSize , this . material . size ) ; var locSampler = this . program . getUniformLocation ( 'uSampler' ) ; gl . activeTexture ( gl . TEXTURE0 ) ; gl . bindTexture ( gl . TEXTURE_2D , this . material . texture ) ; gl . uniform1i ( locSampler , 0 ) ; gl . drawArrays ( gl . POINTS , 0 , vertices . length / 3 ) ; gl . enable ( gl . DEPTH_TEST ) ; gl . depthMask ( true ) ; gl . disable ( gl . BLEND ) ; } setLonlats ( lonlats ) { MultiPointsGraphic . prototype . clear . apply ( this ) ; this . vertices = [ ] ; lonlats . forEach ( ( lonlat ) => { var p = MathUtils . geographicToCartesianCoord ( lonlat [ 0 ] , lonlat [ 1 ] , Kernel . EARTH_RADIUS + 0.001 ) ; this . vertices . push ( p ) ; } ) ; } clear ( ) { this . vertices = [ ] ; } } ;