MCPcopy
hub / github.com/antvis/L7 / DeviceElements

Class DeviceElements

packages/renderer/src/device/DeviceElements.ts:9–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import { isTypedArray } from './utils/typedarray';
8
9export 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected