UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 670 B
import{BUFFER_GPUDYNAMIC as e,BUFFER_STREAM as f,BUFFER_DYNAMIC as t,BUFFER_STATIC as r}from"../constants.js";class s{constructor(){this.bufferId=null}destroy(e){this.bufferId&&(e.gl.deleteBuffer(this.bufferId),this.bufferId=null)}get initialized(){return!!this.bufferId}loseContext(){this.bufferId=null}unlock(s,u,i,b){const a=s.gl;if(this.bufferId)a.bindBuffer(i,this.bufferId),a.bufferSubData(i,0,b);else{let d;switch(u){case r:d=a.STATIC_DRAW;break;case t:d=a.DYNAMIC_DRAW;break;case f:d=a.STREAM_DRAW;break;case e:d=s.isWebGL2?a.DYNAMIC_COPY:a.STATIC_DRAW}this.bufferId=a.createBuffer(),a.bindBuffer(i,this.bufferId),a.bufferData(i,b,d)}}}export{s as WebglBuffer};