webgl/public/js/buffer.js
Tyler Murphy a28e995202 initial
2023-01-18 09:30:41 -05:00

44 lines
No EOL
903 B
JavaScript

const Buffer = {}
let vaos = []
let vbos = []
class Mesh {
static #vaos = []
static #vbos = []
#count = 0
constructor(vertexCount) {
this.id = gl.createVertexArray()
gl.bindVertexArray(this.id)
Mesh.#vaos.push(this.id)
this.vertexCount = vertexCount
}
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() {
gl.bindVertexArray(this.id)
}
unbind() {
gl.bindVertexArray(null)
}
}