import { isTypedArray , TypedArray } from "../utils" ; import RenderingContext from "./RenderingContext" ; /**
 * Buffer is a wrapper around WebGLBuffer with type and size information.
 */ export default class Buffer { private length : number ; private type : number ; private rctx : RenderingContext ; private glBuffer : WebGLBuffer ; param rctx param isElemArray param data constructor ( rctx , isElemArray = false , data ? ) { const gl = rctx . getGl ( ) ; this . type = isElemArray ? gl . ELEMENT_ARRAY_BUFFER : gl . ARRAY_BUFFER ; this . rctx = rctx ; this . glBuffer = gl . createBuffer ( ) ; this . length = 0 ; if ( data ) { this . setData ( data ) ; } } param array public setData ( array ) { if ( ! isTypedArray ( array ) ) { array = new Float32Array ( array ) ; } const gl = this . rctx . getGl ( ) ; this . length = array . length ; gl . bindBuffer ( this . type , this . glBuffer ) ; gl . bufferData ( this . type , array , gl . STATIC_DRAW ) ; } /**
     * Returns the WebGLBuffer for this Buffer
     */ public getGlBuffer ( ) { return this . glBuffer ; } /**
     * Returns the length of the data
     */ public getLength ( ) { return this . length ; } /**
     * Destroys the buffer
     */ public destroy ( ) { this . rctx . getGl ( ) . deleteBuffer ( this . glBuffer ) ; } }