@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 1.17 kB
JavaScript
import{isSome as t,isNone as e}from"../../../../../core/maybe.js";import{RemoveMode as o,MIN_PRIORITY as r}from"../../../../../core/MemCache.js";import{generateUID as s}from"../../../../../core/uid.js";import{VertexArrayObject as c}from"../../lib/VertexArrayObject.js";import{BufferObject as i}from"../../../../webgl/BufferObject.js";import{Usage as h}from"../../../../webgl/enums.js";const n=r+1;class a{constructor(t,e,o){this._rctx=t,this._locations=e,this._layout=o,this._cache=t.newCache(`VaoCache ${s()}`,p)}dispose(){this._cache.destroy()}newVao(e){const o=e.toString(),r=this._cache.pop(o);if(t(r)){const t=r.pop();return r.length>0&&this._cache.put(o,r,e*r.length,n),t}const s=new c(this._rctx,this._locations,{geometry:this._layout},{geometry:i.createVertex(this._rctx,h.STATIC_DRAW)});return s.vertexBuffers.geometry.setSize(e),s}deleteVao(o){if(e(o))return null;const r=o.size,s=r.toString(),c=this._cache.pop(s);return t(c)?(c.push(o),this._cache.put(s,c,r*c.length,-1)):this._cache.put(s,[o],r,-1),null}}function p(t,e){if(e===o.ALL)return void t.forEach((t=>t.dispose()));const r=t.pop(),s=t.length*r.size;return r.dispose(),s}export{a as VaoCache};