| 1 |
- import{a as _}from"./chunk-XKBSMKNP.js";import{a as o}from"./chunk-ZRLECQ27.js";import{a as d}from"./chunk-4D2ERGZX.js";import{a as h}from"./chunk-EDZQSM3T.js";import{a as i}from"./chunk-PJGSCWXZ.js";import{a as u}from"./chunk-NUC3LT2W.js";var l={STREAM_DRAW:o.STREAM_DRAW,STATIC_DRAW:o.STATIC_DRAW,DYNAMIC_DRAW:o.DYNAMIC_DRAW,validate:function(e){return e===l.STREAM_DRAW||e===l.STATIC_DRAW||e===l.DYNAMIC_DRAW}},c=l;function A(){return!0}function p(e,t){t=d(t,"This object was destroyed, i.e., destroy() was called.");function r(){throw new i(t)}for(var n in e)typeof e[n]=="function"&&(e[n]=r);e.isDestroyed=A}var B=p;function y(e){if(e=d(e,d.EMPTY_OBJECT),h.defined("options.context",e.context),!u(e.typedArray)&&!u(e.sizeInBytes))throw new i("Either options.sizeInBytes or options.typedArray is required.");if(u(e.typedArray)&&u(e.sizeInBytes))throw new i("Cannot pass in both options.sizeInBytes and options.typedArray.");if(u(e.typedArray)&&(h.typeOf.object("options.typedArray",e.typedArray),h.typeOf.number("options.typedArray.byteLength",e.typedArray.byteLength)),!c.validate(e.usage))throw new i("usage is invalid.");var t=e.context._gl,r=e.bufferTarget,n=e.typedArray,a=e.sizeInBytes,s=e.usage,f=u(n);f&&(a=n.byteLength),h.typeOf.number.greaterThan("sizeInBytes",a,0);var b=t.createBuffer();t.bindBuffer(r,b),t.bufferData(r,f?n:a,s),t.bindBuffer(r,null),this._gl=t,this._webgl2=e.context._webgl2,this._bufferTarget=r,this._sizeInBytes=a,this._usage=s,this._buffer=b,this.vertexArrayDestroyable=!0,this.context=e.context,e.context.memorySize+=a}y.createVertexBuffer=function(e){return h.defined("options.context",e.context),new y({context:e.context,bufferTarget:o.ARRAY_BUFFER,typedArray:e.typedArray,sizeInBytes:e.sizeInBytes,usage:e.usage})};y.createIndexBuffer=function(e){if(h.defined("options.context",e.context),!_.validate(e.indexDatatype))throw new i("Invalid indexDatatype.");if(e.indexDatatype===_.UNSIGNED_INT&&!e.context.elementIndexUint)throw new i("IndexDatatype.UNSIGNED_INT requires OES_element_index_uint, which is not supported on this system. Check context.elementIndexUint.");var t=e.context,r=e.indexDatatype,n=_.getSizeInBytes(r),a=new y({context:t,bufferTarget:o.ELEMENT_ARRAY_BUFFER,typedArray:e.typedArray,sizeInBytes:e.sizeInBytes,usage:e.usage}),s=a.sizeInBytes/n;return Object.defineProperties(a,{indexDatatype:{get:function(){return r}},bytesPerIndex:{get:function(){return n}},numberOfIndices:{get:function(){return s}}}),a};Object.defineProperties(y.prototype,{sizeInBytes:{get:function(){return this._sizeInBytes}},usage:{get:function(){return this._usage}}});y.prototype._getBuffer=function(){return this._buffer};y.prototype.copyFromArrayView=function(e,t){t=d(t,0),h.defined("arrayView",e),h.typeOf.number.lessThanOrEquals("offsetInBytes + arrayView.byteLength",t+e.byteLength,this._sizeInBytes);var r=this._gl,n=this._bufferTarget;r.bindBuffer(n,this._buffer),r.bufferSubData(n,t,e),r.bindBuffer(n,null)};y.prototype.copyFromBuffer=function(e,t,r,n){if(!this._webgl2)throw new i("A WebGL 2 context is required.");if(!u(e))throw new i("readBuffer must be defined.");if(!u(n)||n<=0)throw new i("sizeInBytes must be defined and be greater than zero.");if(!u(t)||t<0||t+n>e._sizeInBytes)throw new i("readOffset must be greater than or equal to zero and readOffset + sizeInBytes must be less than of equal to readBuffer.sizeInBytes.");if(!u(r)||r<0||r+n>this._sizeInBytes)throw new i("writeOffset must be greater than or equal to zero and writeOffset + sizeInBytes must be less than of equal to this.sizeInBytes.");if(this._buffer===e._buffer&&(r>=t&&r<t+n||t>r&&t<r+n))throw new i("When readBuffer is equal to this, the ranges [readOffset + sizeInBytes) and [writeOffset, writeOffset + sizeInBytes) must not overlap.");if(this._bufferTarget===o.ELEMENT_ARRAY_BUFFER&&e._bufferTarget!==o.ELEMENT_ARRAY_BUFFER||this._bufferTarget!==o.ELEMENT_ARRAY_BUFFER&&e._bufferTarget===o.ELEMENT_ARRAY_BUFFER)throw new i("Can not copy an index buffer into another buffer type.");var a=o.COPY_READ_BUFFER,s=o.COPY_WRITE_BUFFER,f=this._gl;f.bindBuffer(s,this._buffer),f.bindBuffer(a,e._buffer),f.copyBufferSubData(a,s,t,r,n),f.bindBuffer(s,null),f.bindBuffer(a,null)};y.prototype.getBufferData=function(e,t,r,n){if(t=d(t,0),r=d(r,0),!this._webgl2)throw new i("A WebGL 2 context is required.");if(!u(e))throw new i("arrayView is required.");var a,s,f=e.byteLength;if(u(n)?(a=n,u(f)?s=1:(f=e.length,s=e.BYTES_PER_ELEMENT)):u(f)?(a=f-r,s=1):(f=e.length,a=f-r,s=e.BYTES_PER_ELEMENT),r<0||r>f)throw new i("destinationOffset must be greater than zero and less than the arrayView length.");if(r+a>f)throw new i("destinationOffset + length must be less than or equal to the arrayViewLength.");if(t<0||t>this._sizeInBytes)throw new i("sourceOffset must be greater than zero and less than the buffers size.");if(t+a*s>this._sizeInBytes)throw new i("sourceOffset + length must be less than the buffers size.");var b=this._gl,g=o.COPY_READ_BUFFER;b.bindBuffer(g,this._buffer),b.getBufferSubData(g,t,e,r,n),b.bindBuffer(g,null)};y.prototype.isDestroyed=function(){return!1};y.prototype.destroy=function(){return this._gl.deleteBuffer(this._buffer),this.context.memorySize-=this.sizeInBytes,B(this)};var C=y;export{B as a,c as b,C as c};
|