@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 1.64 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import{getMaxItemCount as t,getItemsRectangle as e}from"./TextureBackedBufferUtils.js";import{SizedPixelFormat as r,PixelType as o}from"../../../../webgl/enums.js";import i from"../../../../webgl/Texture.js";import{TextureDescriptor as s}from"../../../../webgl/TextureDescriptor.js";class a{constructor(a,n,u){this.layout=n;const l="number"!=typeof u,h=l?Math.floor(u.byteLength/n.byteStride):u;if(h>t(a,n))throw new Error(`Cannot allocate TextureBuffer for ${h}. Exceeding hardware texture limits`);const{itemCount:m,itemWidth:d,itemHeight:f}=e(h),{texelStride:p,byteStride:c}=this.layout,x=d*p,y=f;this.itemCount=m,this.byteLength=m*c;const w=new s(x,y);w.samplingMode=9728,w.wrapMode=33071,w.internalFormat=r.RGBA8UI,w.pixelFormat=36249,w.dataType=o.UNSIGNED_BYTE,w.isImmutable=!0,w.hasMipmap=!1,this.texture=new i(a,w),l&&this.setSubData(u)}get sizeBytes(){return this.byteLength}setSubData(t,e=0,r=0,o=Math.floor((t.byteLength-r)/this.layout.byteStride)){if(0===o)return;const{layout:i,texture:s}=this,{texelStride:a,texelByteStride:n}=i,{width:u}=s.descriptor;if(e+o>this.itemCount)throw new Error("Upload range is outside of texture");const l=e*a,h=o*a,m=Math.floor(l/u),d=l%u,f=(u-d)%u,p=h-f,c=Math.floor(p/u),x=p%u,y=0===d?m:m+1;if(0!==d){const e=new i.texelElementArrayConstructor(t,r);s.updateData(0,d,m,f,1,e)}if(c>0){const e=r+f*n,o=new i.texelElementArrayConstructor(t,e);s.updateData(0,0,y,u,c,o)}if(x>0){const e=r+(h-x)*n,o=y+c,a=new i.texelElementArrayConstructor(t,e);s.updateData(0,0,o,x,1,a)}}dispose(){this.texture.dispose()}}export{a as TextureBuffer};