// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("exports ../../core/arrayUtils ../../core/has ../../core/Logger ../../core/typedArrayUtil ./checkWebGLError ./enums".split(" "),function(h,p,q,l,m,k,c){class f{static createIndex(a,b,d){return new f(a,c.BufferType.ELEMENT_ARRAY_BUFFER,b,d)}static createVertex(a,b,d){return new f(a,c.BufferType.ARRAY_BUFFER,b,d)}static createUniform(a,b,d){return new f(a,c.BufferType.UNIFORM_BUFFER,b,d)}static createPixelPack(a,b=c.Usage.STREAM_READ,d){a=new f(a,c.BufferType.PIXEL_PACK_BUFFER,b);d&&a.setSize(d); return a}static createPixelUnpack(a,b=c.Usage.STREAM_DRAW,d){return new f(a,c.BufferType.PIXEL_UNPACK_BUFFER,b,d)}static createTransformFeedback(a,b=c.Usage.STATIC_DRAW,d){a=new f(a,c.BufferType.TRANSFORM_FEEDBACK_BUFFER,b);a.setSize(d);return a}constructor(a,b,d,e){this._context=a;this.bufferType=b;this.usage=d;this._glName=null;this._size=-1;this._indexType=void 0;a.instanceCounter.increment(c.ResourceType.BufferObject,this);this._glName=this._context.gl.createBuffer();k.checkWebGLError(this._context.gl); e&&this.setData(e)}get glName(){return this._glName}get size(){return this._size}get indexType(){return this._indexType}get usedMemory(){return this.bufferType===c.BufferType.ELEMENT_ARRAY_BUFFER?this._indexType===c.DataType.UNSIGNED_INT?4*this._size:2*this._size:this._size}get _isVAOAware(){return this.bufferType===c.BufferType.ELEMENT_ARRAY_BUFFER||this.bufferType===c.BufferType.ARRAY_BUFFER}dispose(){this._context?.gl?(this._glName&&(this._context.gl.deleteBuffer(this._glName),this._glName=null), this._context.instanceCounter.decrement(c.ResourceType.BufferObject,this),this._context=null):this._glName&&l.getLogger("esri.views.webgl.BufferObject").warn("Leaked WebGL buffer object")}setSize(a,b=null){if(this.bufferType===c.BufferType.ELEMENT_ARRAY_BUFFER&&null!=b)switch(this._indexType=b,b){case c.DataType.UNSIGNED_SHORT:a*=2;break;case c.DataType.UNSIGNED_INT:a*=4}this._setBufferData(a)}setData(a){if(a){var b=a.byteLength;this.bufferType===c.BufferType.ELEMENT_ARRAY_BUFFER&&(m.isUint16Array(a)&& (b/=2,this._indexType=c.DataType.UNSIGNED_SHORT),m.isUint32Array(a)&&(b/=4,this._indexType=c.DataType.UNSIGNED_INT));this._setBufferData(b,a)}}_setBufferData(a,b=null){this._size=a;const d=this._context.getBoundVAO();this._isVAOAware&&this._context.bindVAO(null);this._context.bindBuffer(this);const e=this._context.gl;null!=b?e.bufferData(this.bufferType,b,this.usage):e.bufferData(this.bufferType,a,this.usage);k.checkWebGLError(e);this._isVAOAware&&this._context.bindVAO(d)}setSubData(a,b,d,e){if(a){var g= this._context.getBoundVAO();this._isVAOAware&&this._context.bindVAO(null);this._context.bindBuffer(this);var {gl:n}=this._context;n.bufferSubData(this.bufferType,b*a.BYTES_PER_ELEMENT,a,d,e-d);k.checkWebGLError(n);this._isVAOAware&&this._context.bindVAO(g)}}getSubData(a,b=0,d,e){if(!(0>d||0>e)){var g=p.isArrayLike(a)?a.BYTES_PER_ELEMENT:1;g*((d??0)+(e??0))>a.byteLength||(b+g*(e??0)>this.usedMemory&&l.getLogger("esri.views.webgl.BufferObject").warn("Potential problem getting subdata: requested data exceeds buffer size!"), g=this._context.gl,this.bufferType===c.BufferType.TRANSFORM_FEEDBACK_BUFFER?(this._context.bindBuffer(this,c.BufferType.TRANSFORM_FEEDBACK_BUFFER),g.getBufferSubData(c.BufferType.TRANSFORM_FEEDBACK_BUFFER,b,a,d,e),this._context.unbindBuffer(c.BufferType.TRANSFORM_FEEDBACK_BUFFER)):(this._context.bindBuffer(this,c.BufferType.COPY_READ_BUFFER),g.getBufferSubData(c.BufferType.COPY_READ_BUFFER,b,a,d,e),this._context.unbindBuffer(c.BufferType.COPY_READ_BUFFER)))}}async getSubDataAsync(a,b=0,d,e){await this._context.clientWaitAsync(); this.getSubData(a,b,d,e)}}h.BufferObject=f;h.tracer=null;Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});