From 96ee00242f350b391dcc1cf4d72a442c969f565e Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Wed, 22 Dec 2021 13:59:13 +0100 Subject: add pw-frontend --- web/pw-frontend/src/lib/visualizer/webgl/buffer.ts | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 web/pw-frontend/src/lib/visualizer/webgl/buffer.ts (limited to 'web/pw-frontend/src/lib/visualizer/webgl/buffer.ts') diff --git a/web/pw-frontend/src/lib/visualizer/webgl/buffer.ts b/web/pw-frontend/src/lib/visualizer/webgl/buffer.ts new file mode 100644 index 0000000..2739fbe --- /dev/null +++ b/web/pw-frontend/src/lib/visualizer/webgl/buffer.ts @@ -0,0 +1,55 @@ + +export class Buffer { + buffer: WebGLBuffer; + data: any; + count: number; + type: number; + + constructor(gl: WebGLRenderingContext, data: number[], type: number) { + this.buffer = gl.createBuffer(); + this.type = type; + + if (data) + this.updateData(gl, data); + } + + _toArray(data: number[]): any { + return new Float32Array(data); + } + + updateData(gl: WebGLRenderingContext, data: number[]) { + this.data = data; + this.count = data.length; + gl.bindBuffer(this.type, this.buffer); + gl.bufferData(this.type, this._toArray(data), gl.STATIC_DRAW); + } + + bind(gl: WebGLRenderingContext) { + gl.bindBuffer(this.type, this.buffer); + } + + getCount(): number { + return this.count; + } +} + +export class VertexBuffer extends Buffer { + constructor(gl: WebGLRenderingContext, data: any) { + super(gl, data, gl.ARRAY_BUFFER); + } + + _toArray(data: number[]): any { + return new Float32Array(data); + } +} + + +export class IndexBuffer extends Buffer { + constructor(gl: WebGLRenderingContext, data: any) { + super(gl, data, gl.ELEMENT_ARRAY_BUFFER); + } + + _toArray(data: number[]): any { + return new Uint16Array(data); + } +} -- cgit v1.2.3