|
1 | 1 | import PicoGL, {App, Framebuffer, Texture} from 'picogl'; |
2 | 2 | import pointsVS from './shaders/GraphPoints.vs.glsl'; |
3 | 3 | import pointsFS from './shaders/GraphPoints.fs.glsl'; |
4 | | -import {GLDataTypes} from '../renderer/Renderable'; |
| 4 | +import {GLDataTypes, setDrawCallUniforms} from '../renderer/Renderable'; |
5 | 5 | import {DataMappings, concatenateData, packData} from './DataTools'; |
6 | 6 | import {vec2, vec3} from 'gl-matrix'; |
7 | 7 | import {DataTexture} from '../renderer/DataTexture'; |
8 | 8 |
|
| 9 | +export enum ClassModes { |
| 10 | + NONE, |
| 11 | + ADD, |
| 12 | +} |
| 13 | + |
| 14 | +export interface PointOptions { |
| 15 | + positionClassMode?: ClassModes |
| 16 | + radiusClassMode?: ClassModes |
| 17 | +} |
| 18 | + |
9 | 19 | export interface PointData { |
10 | 20 | id?: number | string; |
11 | 21 | class?: number | string; |
@@ -58,13 +68,31 @@ export class GraphPoints extends DataTexture { |
58 | 68 | private _pointView: DataView; |
59 | 69 | private _pointTexture: Texture; |
60 | 70 |
|
| 71 | + private _localUniforms = { |
| 72 | + uPositionClassMode: ClassModes.ADD, |
| 73 | + uRadiusClassMode: ClassModes.NONE, |
| 74 | + }; |
61 | 75 | private _dataArrayBuffer: Float32Array; |
62 | 76 |
|
63 | 77 | private _length: number = 0; |
64 | 78 | public get length(): number { |
65 | 79 | return this._length; |
66 | 80 | } |
67 | 81 |
|
| 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 | + |
68 | 96 | private map: Map<number | string, number>; |
69 | 97 | protected dirty: boolean = false; |
70 | 98 |
|
@@ -288,11 +316,13 @@ export class GraphPoints extends DataTexture { |
288 | 316 | .depthMask(false); |
289 | 317 |
|
290 | 318 | // 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(); |
| 319 | + const drawCall = context.createDrawCall(program, pointsVAO) |
| 320 | + .primitive(PicoGL.TRIANGLE_STRIP); |
| 321 | + setDrawCallUniforms(drawCall, Object.assign({}, this._localUniforms, { |
| 322 | + uPointTexture: this._pointTexture, |
| 323 | + uClassTexture: this._classTexture, |
| 324 | + })); |
| 325 | + drawCall.draw(); |
296 | 326 |
|
297 | 327 | // read points texture into stored buffer for point coordinates readback |
298 | 328 | this.readTextureAsync(this._frameBuffer.colorAttachments[0]).then(texArrayBuffer => { |
|
0 commit comments