| 7 | import { isTypedArray } from './utils/typedarray'; |
| 8 | |
| 9 | export default class DeviceElements implements IElements { |
| 10 | private indexBuffer: Buffer; |
| 11 | private type; |
| 12 | private count: number; |
| 13 | |
| 14 | constructor(device: Device, options: IElementsInitializationOptions) { |
| 15 | const { data, type, count = 0 } = options; |
| 16 | |
| 17 | let typed: TypedArray; |
| 18 | if (isTypedArray(data)) { |
| 19 | typed = data; |
| 20 | } else { |
| 21 | typed = new typedArrayCtorMap[this.type || gl.UNSIGNED_INT](data as number[]); |
| 22 | } |
| 23 | |
| 24 | this.type = type; |
| 25 | this.count = count; |
| 26 | |
| 27 | this.indexBuffer = device.createBuffer({ |
| 28 | viewOrSize: typed, |
| 29 | usage: BufferUsage.INDEX, |
| 30 | }); |
| 31 | } |
| 32 | |
| 33 | public get() { |
| 34 | return this.indexBuffer; |
| 35 | } |
| 36 | |
| 37 | public subData({ |
| 38 | data, |
| 39 | }: { |
| 40 | data: number[] | number[][] | Uint8Array | Uint16Array | Uint32Array; |
| 41 | }) { |
| 42 | let typed: TypedArray; |
| 43 | if (isTypedArray(data)) { |
| 44 | typed = data; |
| 45 | } else { |
| 46 | typed = new typedArrayCtorMap[this.type || gl.UNSIGNED_INT](data as number[]); |
| 47 | } |
| 48 | this.indexBuffer.setSubData(0, new Uint8Array(typed.buffer)); |
| 49 | } |
| 50 | |
| 51 | public destroy() { |
| 52 | this.indexBuffer.destroy(); |
| 53 | } |
| 54 | } |
nothing calls this directly
no outgoing calls
no test coverage detected