point.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import REGL = require('regl');
  7. import { ValueCell } from 'mol-util/value-cell'
  8. import { Renderable } from '../renderable'
  9. import { createBaseDefines, createBaseUniforms, createBaseAttributes, destroyUniforms, destroyAttributes } from './util'
  10. import { PointShaders, addDefines } from '../shaders'
  11. import { ColorData } from 'mol-geo/color';
  12. type Point = 'point'
  13. namespace Point {
  14. export type Data = {
  15. objectId: number
  16. position: ValueCell<Float32Array>
  17. size?: ValueCell<Float32Array>
  18. id: ValueCell<Float32Array>
  19. color: ColorData
  20. transform: ValueCell<Float32Array>
  21. instanceCount: number
  22. elementCount: number
  23. positionCount: number
  24. }
  25. export function create(regl: REGL.Regl, props: Data): Renderable {
  26. const defines = createBaseDefines(regl, props)
  27. const uniforms = createBaseUniforms(regl, props)
  28. const attributes = createBaseAttributes(regl, props)
  29. const command = regl({
  30. ...addDefines(defines, PointShaders),
  31. uniforms,
  32. attributes,
  33. count: props.positionCount,
  34. instances: props.instanceCount,
  35. primitive: 'points'
  36. })
  37. return {
  38. draw: () => command(),
  39. get stats() {
  40. return command.stats
  41. },
  42. name: 'point',
  43. dispose: () => {
  44. destroyAttributes(attributes)
  45. destroyUniforms(uniforms)
  46. }
  47. }
  48. }
  49. }
  50. export default Point