util.ts 1.2 KB

123456789101112131415161718192021222324252627282930
  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 { Attributes, AttributesData, AttributesBuffers } from '../renderable'
  8. import Attribute from '../attribute'
  9. export function createTransformAttributes (regl: REGL.Regl, transform: Float32Array) {
  10. const size = 4
  11. const divisor = 1
  12. const bpe = transform.BYTES_PER_ELEMENT
  13. const stride = 16 * bpe
  14. return {
  15. transformColumn0: Attribute.create(regl, transform, { size, divisor, offset: 0, stride }),
  16. transformColumn1: Attribute.create(regl, transform, { size, divisor, offset: 4 * bpe, stride }),
  17. transformColumn2: Attribute.create(regl, transform, { size, divisor, offset: 8 * bpe, stride }),
  18. transformColumn3: Attribute.create(regl, transform, { size, divisor, offset: 12 * bpe, stride })
  19. }
  20. }
  21. export function getBuffers<T extends AttributesData>(attributes: Attributes<T>): AttributesBuffers<T> {
  22. const buffers: AttributesBuffers<any> = {}
  23. for (const k of Object.keys(attributes)) {
  24. buffers[k] = attributes[k].buffer
  25. }
  26. return buffers as AttributesBuffers<T>
  27. }