import { gl, ext } from './Renderer.js' export class Mesh { static #vaos = [] static #vbos = [] #vertexCount #count #id constructor(vertexCount) { this.#id = ext.createVertexArrayOES() ext.bindVertexArrayOES(this.#id) Mesh.#vaos.push(this.#id) this.#vertexCount = vertexCount this.#count = 0 } store(data, dim) { let id = gl.createBuffer() Mesh.#vbos.push(id) gl.bindBuffer(gl.ARRAY_BUFFER, id) gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(data), gl.STATIC_DRAW) gl.vertexAttribPointer(this.#count, dim, gl.FLOAT, false, Float32Array.BYTES_PER_ELEMENT * dim, 0) gl.enableVertexAttribArray(this.#count) this.#count++; return this } finish() { this.unbind() return this } bind() { ext.bindVertexArrayOES(this.#id) } unbind() { ext.bindVertexArrayOES(null) } draw() { gl.drawArrays(gl.TRIANGLES, 0, this.#vertexCount) } }