| 806 | } |
| 807 | |
| 808 | _ensureGeometryBuffers(buffers, indices, indexType) { |
| 809 | if (!indices) return; |
| 810 | |
| 811 | const device = this.device; |
| 812 | |
| 813 | const buffer = device.createBuffer({ |
| 814 | size: Math.ceil((indices.length * indexType.BYTES_PER_ELEMENT) / 4) * 4, |
| 815 | usage: GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST, |
| 816 | mappedAtCreation: true, |
| 817 | }); |
| 818 | |
| 819 | // Write index data to buffer |
| 820 | const mapping = new indexType(buffer.getMappedRange()); |
| 821 | mapping.set(indices); |
| 822 | buffer.unmap(); |
| 823 | |
| 824 | buffers.indexBuffer = buffer; |
| 825 | buffers.indexBufferType = indexType === Uint32Array ? 'uint32' : 'uint16'; |
| 826 | } |
| 827 | |
| 828 | _freeBuffers(buffers) { |
| 829 | const destroyIfExists = (buf) => { |