UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

37 lines (36 loc) 1.03 kB
class WebglDrawCommands { indexSizeBytes; glCounts = null; glOffsetsBytes = null; glInstanceCounts = null; constructor(indexSizeBytes) { this.indexSizeBytes = indexSizeBytes; } allocate(maxCount) { if (this.glCounts && this.glCounts.length === maxCount) { return; } this.glCounts = new Int32Array(maxCount); this.glOffsetsBytes = new Int32Array(maxCount); this.glInstanceCounts = new Int32Array(maxCount); } add(i, indexOrVertexCount, instanceCount, firstIndexOrVertex) { this.glCounts[i] = indexOrVertexCount; this.glOffsetsBytes[i] = firstIndexOrVertex * this.indexSizeBytes; this.glInstanceCounts[i] = instanceCount; } update(count) { let totalPrimitives = 0; if (this.glCounts && this.glInstanceCounts && count > 0) { for (let d = 0; d < count; d++) { const indexOrVertexCount = this.glCounts[d]; const instanceCount = this.glInstanceCounts[d]; totalPrimitives += indexOrVertexCount * instanceCount; } } return totalPrimitives; } } export { WebglDrawCommands };