UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) • 11.1 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as t}from"tslib";import{nextPowerOfTwo as e}from"../../../../core/mathUtils.js";import{disposeMaybe as i,destroyMaybe as r}from"../../../../core/maybe.js";import{property as s,subclass as h}from"../../../../core/accessorSupport/decorators.js";import{ortho as o}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{set as n}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{create as u}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UNIT_X as c,ZEROS as l}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{RenderNodeOutput as d,InternalRenderCategory as p}from"../../webgl.js";import{Frustum as _}from"../../state/Frustum.js";import{glLayout as f}from"../../support/buffer/glUtil.js";import{newLayout as m}from"../../support/buffer/InterleavedLayout.js";import g from"../../webgl/RenderCamera.js";import F from"../../webgl/RenderNode.js";import{ShaderOutputConfiguration as C}from"../core/shaderLibrary/ShaderOutputConfiguration.js";import{VertexArrayObject as w}from"./VertexArrayObject.js";import{C as R}from"../../../../chunks/CutFillDepth.glsl.js";import{CutFillDepthTechnique as P}from"../shaders/CutFillDepthTechnique.js";import{CutFillDepthTechniqueConfiguration as T}from"../shaders/CutFillDepthTechniqueConfiguration.js";import{C as b}from"../../../../chunks/CutFillReduction.glsl.js";import{CutFillReductionTechnique as x}from"../shaders/CutFillReductionTechnique.js";import{CutFillReductionTechniqueConfiguration as D}from"../shaders/CutFillReductionTechniqueConfiguration.js";import{C as B}from"../../../../chunks/CutFillTargetDepth.glsl.js";import{CutFillTargetDepthTechnique as y}from"../shaders/CutFillTargetDepthTechnique.js";import{ImmediateTask as j,TaskPriority as q}from"../../../support/Scheduler.js";import{Yield as S}from"../../../support/Yield.js";import{PrimitiveType as v,DataType as E}from"../../../webgl/enums.js";import{Sync as V}from"../../../webgl/Sync.js";import{VertexBuffer as O}from"../../../webgl/VertexBuffer.js";let A=class extends F{constructor(t){super(t),this.consumes={required:[d.TRANSPARENT]},this.produces=p.CUTFILL_DEPTH,this._cutFillTargetDepthConfiguration=new C,this._cutFillDepthConfiguration=new T,this._cutFillReductionConfiguration=new D,this._cutFillTargetDepthParameters=new B,this._cutFillDepthParameters=new R,this._cutFillReductionParameters=new b,this.needsRender=!1,this.readyToRun=!1,this.done=!0,this._frameTask=j,this._results=new k,this._localOrigin=u(),this._maxTextureSize=512,this._width=0,this._height=0,this._reducedWidth=0,this._reducedHeight=0,this._depthFormat=14,this._colorFormat=11,this._numChannels=2,this._targetVao=null,this._numReductions=3,this._reductionPasses=0,this._pixelBufferSize=0,this._pixelBufferOffset=0,this._perReductionPixelBufferSize=0}initialize(){this._frameTask=this.view.resourceController.scheduler.registerTask(q.VOLUME_MEASUREMENT,this),this.addHandles(this._frameTask),this._maxTextureSize=Math.min(this._maxTextureSize,this.fboCache.rctx.parameters.maxTextureSize),this._cutFillTargetDepthConfiguration.output=7,this._frustum=new _(this.view.renderCoordsHelper)}destroy(){this._targetVao=i(this._targetVao);const t=this.gl;this._sync=r(this._sync),this._pixelBuffer&&(t.deleteBuffer(this._pixelBuffer),this._pixelBuffer=null,this._pixelBufferSize=0)}precompile(){this.techniques.precompile(y,this._cutFillTargetDepthConfiguration),this._cutFillDepthConfiguration.preparePass=0,this.techniques.precompile(P,this._cutFillDepthConfiguration),this._cutFillDepthConfiguration.preparePass=1,this.techniques.precompile(P,this._cutFillDepthConfiguration),this._cutFillReductionConfiguration.reductionPass=0,this.techniques.precompile(x,this._cutFillReductionConfiguration),this._cutFillReductionConfiguration.reductionPass=1,this.techniques.precompile(x,this._cutFillReductionConfiguration),this._cutFillReductionConfiguration.reductionPass=2,this.techniques.precompile(x,this._cutFillReductionConfiguration),this.view.stage.renderer.precompileCutFill()}render(t){const e=t.find(({name:t})=>t===p.CUTFILL_DEPTH);if(!this._orthographicCamera||!this._targetVao||!this.needsRender||this._sync)return e;const i=this.techniques.get(y,this._cutFillTargetDepthConfiguration);this._cutFillDepthConfiguration.preparePass=0;const r=this.techniques.get(P,this._cutFillDepthConfiguration);this._cutFillDepthConfiguration.preparePass=1;const s=this.techniques.get(P,this._cutFillDepthConfiguration);this._cutFillReductionConfiguration.reductionPass=0;const h=this.techniques.get(x,this._cutFillReductionConfiguration);this._cutFillReductionConfiguration.reductionPass=1;const o=this.techniques.get(x,this._cutFillReductionConfiguration);this._cutFillReductionConfiguration.reductionPass=2;const n=this.techniques.get(x,this._cutFillReductionConfiguration);if(!(i.compiled&&r.compiled&&s.compiled&&h.compiled&&o.compiled&&n.compiled))return this.requestRender(1),e;this.needsRender=!1;const a=this.renderingContext,u=this.fboCache,d=this.gl,_=a.getViewport(),f=u.acquire(this._width,this._height,"cutfill reference depth",this._depthFormat);a.bindFramebuffer(f.fbo),a.setViewport(0,0,this._width,this._height),a.clear(1280),this.view.stage.renderer.renderCutFillReferenceDepth(this._orthographicCamera);const m=u.acquire(this._width,this._height,"cutfill target depth",this._depthFormat);a.bindFramebuffer(m.fbo),a.setViewport(0,0,this._width,this._height),a.setClearDepth(1),a.clear(256),this._cutFillTargetDepthParameters.origin=this._localOrigin,this._cutFillTargetDepthParameters.cutFillCamera=this._orthographicCamera,a.bindTechnique(i,this.bindParameters,this._cutFillTargetDepthParameters),a.bindVAO(this._targetVao),a.drawArrays(v.TRIANGLES,0,this._targetVao.vertexCount("geometry"));const g=u.acquire(this._width,this._height,"cutfill reduction even",this._colorFormat),F=u.acquire(this._width,this._height,"cutfill reduction odd",this._colorFormat);return this._cutFillDepthParameters.referenceDepthTexture=f.depthTexture,this._cutFillDepthParameters.targetDepthTexture=m.depthTexture,this._pixelBuffer||(this._pixelBuffer=d.createBuffer()),d.bindBuffer(d.PIXEL_PACK_BUFFER,this._pixelBuffer),d.bufferData(d.PIXEL_PACK_BUFFER,this._pixelBufferSize,d.STREAM_READ),this._prepareFBO(g,this.width,this.height),a.bindTechnique(r,this.bindParameters,this._cutFillDepthParameters),a.screen.draw(),this._runPyramidReduction(g,F,h),this._prepareFBO(g,this.width,this.height,c),a.bindTechnique(s,this.bindParameters,this._cutFillDepthParameters),a.screen.draw(),this._runPyramidReduction(g,F,o),this._prepareFBO(g,this.width,this.height,l),a.bindTechnique(s,this.bindParameters,this._cutFillDepthParameters),a.screen.draw(),this._runPyramidReduction(g,F,n),f.release(),m.release(),g.release(),F.release(),d.bindBuffer(d.PIXEL_PACK_BUFFER,null),a.setViewport(_.x,_.y,_.width,_.height),this._sync=new V(d),setTimeout(()=>this.readyToRun=!0,0),e}update(t,i){if(!this.done)return;this.done=!1;const r=this.renderingContext,{cameraDimensions:{width:s,height:h},localOriginRenderSpace:o}=t,n=this._maxTextureSize,a=h/s,u=s>h?n:n/a,c=s>h?n*a:n;this._width=e(u),this._height=e(c);const l=[this._width,this._height];this._orthographicCamera=this._createCamera(t,l),this._frustum?.update(this._orthographicCamera),this._updateTargetVao(r,i),this._localOrigin=o,this._reductionPasses=Math.ceil(Math.log2(Math.min(this._width,this._height))),this._reducedWidth=Math.ceil(this._width/2**this._reductionPasses),this._reducedHeight=Math.ceil(this._height/2**this._reductionPasses),this._perReductionPixelBufferSize=this._reducedWidth*this._reducedHeight*this._numChannels*4,this._pixelBufferSize=this._perReductionPixelBufferSize*this._numReductions,this._pixelBufferOffset=0,this.needsRender=!0,this.requestRender(1)}runTask(){if(!this._sync)return void(this.readyToRun=!1);try{if(!this._sync.poll())return S}catch(e){return this.readyToRun=!1,void(this._sync=r(this._sync))}this.readyToRun=!1,this._sync=r(this._sync);const t=this.gl;this._cpuBuffer=new Float32Array(this._pixelBufferSize/4),t.bindBuffer(t.PIXEL_PACK_BUFFER,this._pixelBuffer),t.getBufferSubData(t.PIXEL_PACK_BUFFER,0,this._cpuBuffer),t.bindBuffer(t.PIXEL_PACK_BUFFER,null),this._updateResults(this._cpuBuffer),this.done=!0}getResults(){return this._results}get frustum(){return this._frustum}get width(){return this._width}get height(){return this._height}get updating(){return this.readyToRun||!this.done||this._frameTask.updating}_runPyramidReduction(t,e,i){const r=this.renderingContext,s=this.gl;let h=this._width,o=this._height;for(let n=0;n<this._reductionPasses;n++)h=Math.ceil(h/2),o=Math.ceil(o/2),this._cutFillReductionParameters.depthTexture=t.getTexture(),this._prepareFBO(e,h,o),r.bindTechnique(i,this.bindParameters,this._cutFillReductionParameters),r.screen.draw(),[t,e]=[e,t];s.readPixels(0,0,h,o,33319,E.FLOAT,this._pixelBufferOffset),this._pixelBufferOffset+=this._perReductionPixelBufferSize}_updateResults(t){const e=new U(0,1,a()),i=new U(0,0,a());for(let r=0;r<this._reducedWidth;r++)for(let s=0;s<this._reducedHeight;s++){let h=(r+s*this._reducedWidth)*this._numChannels;const o=this._reducedWidth*this._reducedHeight*this._numChannels;e.totalDepth+=t[h],i.totalDepth+=t[h+1],h+=o;const n=t[h];n<e.labelDepth&&(e.labelDepth=n,L(e.labelCoords,t[h+1],this._width)),h+=o;const a=t[h];a>i.labelDepth&&(i.labelDepth=a,L(i.labelCoords,t[h+1],this._width))}this._results=new k(this._width,this._height,e,i)}_prepareFBO(t,e,i,r=l){const s=this.renderingContext;s.bindFramebuffer(t.fbo),s.setViewport(0,0,e,i),s.setClearColor(r[0],r[1],r[2],r[3]),s.clear(16384)}_createCamera(t,e){const{cameraPositionRenderSpace:i,localOriginRenderSpace:r,northVector:s,cameraDimensions:{width:h,height:n},cameraNearFar:{near:a,far:u}}=t,c=new g({eye:i,center:r,up:s,near:a,far:u});return c.viewport=[0,0,e[0],e[1]],o(c.projectionMatrix,-h/2,h/2,-n/2,n/2,a,u),c}_updateTargetVao(t,e){this._targetVao=i(this._targetVao);const r=e.reduce((t,e)=>t+e.indices.length,0),s=z.createBuffer(r),h=s.position;let o=0;for(const i of e){const{positions:t,indices:e}=i;for(let i=0;i<e.length;++i){const r=3*e[i];h.set(o,0,t[r]),h.set(o,1,t[r+1]),h.set(o,2,t[r+2]),o++}}const n=new O(t,f(z),s.buffer);this._targetVao=new w(t,n)}};t([s()],A.prototype,"consumes",void 0),t([s()],A.prototype,"produces",void 0),t([s()],A.prototype,"needsRender",void 0),t([s()],A.prototype,"readyToRun",void 0),t([s()],A.prototype,"done",void 0),t([s()],A.prototype,"updating",null),t([s()],A.prototype,"_frameTask",void 0),A=t([h("esri.views.3d.webgl-engine.lib.CutFillDepth")],A);const z=m().vec3f("position").freeze();function L(t,e,i){const r=e%i,s=Math.floor(e/i);n(t,r,s)}class M{constructor(t,e){this.positions=t,this.indices=e}}class U{constructor(t,e,i){this.totalDepth=t,this.labelDepth=e,this.labelCoords=i}}class k{constructor(t=0,e=0,i=new U(0,1,a()),r=new U(0,0,a())){this.width=t,this.height=e,this.cut=i,this.fill=r}}export{A as CutFillDepth,U as DepthResult,k as RenderResult,M as TargetGeometryRenderInfo};