11import PicoGL , { App , Framebuffer , Texture } from 'picogl' ;
22import pointsVS from './shaders/GraphPoints.vs.glsl' ;
33import pointsFS from './shaders/GraphPoints.fs.glsl' ;
4- import { GLDataTypes } from '../renderer/Renderable' ;
4+ import { GLDataTypes , setDrawCallUniforms } from '../renderer/Renderable' ;
55import { DataMappings , concatenateData , packData } from './DataTools' ;
66import { vec2 , vec3 } from 'gl-matrix' ;
77import { DataTexture } from '../renderer/DataTexture' ;
88
9+ export enum ClassModes {
10+ NONE ,
11+ ADD ,
12+ }
13+
14+ export interface PointOptions {
15+ positionClassMode ?: ClassModes
16+ radiusClassMode ?: ClassModes
17+ }
18+
919export interface PointData {
1020 id ?: number | string ;
1121 class ?: number | string ;
@@ -58,13 +68,31 @@ export class GraphPoints extends DataTexture {
5868 private _pointView : DataView ;
5969 private _pointTexture : Texture ;
6070
71+ private _localUniforms = {
72+ uPositionClassMode : ClassModes . ADD ,
73+ uRadiusClassMode : ClassModes . NONE ,
74+ } ;
6175 private _dataArrayBuffer : Float32Array ;
6276
6377 private _length : number = 0 ;
6478 public get length ( ) : number {
6579 return this . _length ;
6680 }
6781
82+ public get positionClassMode ( ) : ClassModes {
83+ return this . _localUniforms . uPositionClassMode ;
84+ }
85+ public set positionClassMode ( value : ClassModes ) {
86+ this . _localUniforms . uPositionClassMode = value ;
87+ }
88+
89+ public get radiusClassMode ( ) : ClassModes {
90+ return this . _localUniforms . uRadiusClassMode ;
91+ }
92+ public set radiusClassMode ( value : ClassModes ) {
93+ this . _localUniforms . uRadiusClassMode = value ;
94+ }
95+
6896 private map : Map < number | string , number > ;
6997 protected dirty : boolean = false ;
7098
@@ -73,10 +101,12 @@ export class GraphPoints extends DataTexture {
73101 public bbDiagonal : number ;
74102
75103 constructor ( context : App , data : PointData [ ] ) ;
76- constructor ( context : App , data : unknown [ ] , mappings : Partial < PointDataMappings > ) ;
77- constructor ( context : App , data : unknown [ ] , mappings : Partial < PointDataMappings > = { } ) {
104+ constructor ( context : App , data : unknown [ ] , mappings : Partial < PointDataMappings > , options : PointOptions ) ;
105+ constructor ( context : App , data : unknown [ ] , mappings : Partial < PointDataMappings > = { } , options : PointOptions = { } ) {
78106 super ( context , data . length ) ;
79107
108+ this . _localUniforms = Object . assign ( { } , this . _localUniforms , options ) ;
109+
80110 this . map = new Map ( ) ;
81111 this . bb = {
82112 min : vec3 . fromValues ( Number . MAX_SAFE_INTEGER , Number . MAX_SAFE_INTEGER , Number . MAX_SAFE_INTEGER ) ,
@@ -288,11 +318,13 @@ export class GraphPoints extends DataTexture {
288318 . depthMask ( false ) ;
289319
290320 // create and initiate draw call
291- context . createDrawCall ( program , pointsVAO )
292- . primitive ( PicoGL . TRIANGLE_STRIP )
293- . texture ( 'uPointTexture' , this . _pointTexture )
294- . texture ( 'uClassTexture' , this . _classTexture )
295- . draw ( ) ;
321+ const drawCall = context . createDrawCall ( program , pointsVAO )
322+ . primitive ( PicoGL . TRIANGLE_STRIP ) ;
323+ setDrawCallUniforms ( drawCall , Object . assign ( { } , this . _localUniforms , {
324+ uPointTexture : this . _pointTexture ,
325+ uClassTexture : this . _classTexture ,
326+ } ) ) ;
327+ drawCall . draw ( ) ;
296328
297329 // read points texture into stored buffer for point coordinates readback
298330 this . readTextureAsync ( this . _frameBuffer . colorAttachments [ 0 ] ) . then ( texArrayBuffer => {
0 commit comments