12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import e from"../request.js";import has from"../core/has.js";import t from"../core/Logger.js";import{isSome as r,removeMaybe as s}from"../core/maybe.js";import{isAbortError as i}from"../core/promiseUtils.js";import{watch as a}from"../core/reactiveUtils.js";import{renderSRFromViewSR as n}from"../geometry/support/coordinateSystem.js";import{PointIndex as o,PlaneIndex as l}from"../geometry/support/frustum.js";import{WasmCullMode as h,VoxelRequestType as _,UpdateFlags as d,ContainerType as u}from"../libs/vxl/enums.js";import{loadVoxelWASM as c}from"../libs/vxl/VxlModule.js";import{ViewingMode as m}from"../views/ViewingMode.js";import{Frustum as g}from"../views/3d/state/Frustum.js";import{RenderCoordsHelper as x}from"../views/3d/support/RenderCoordsHelper.js";import{ShaderOutput as f}from"../views/3d/webgl-engine/core/shaderLibrary/ShaderOutput.js";import{RenderSlot as p}from"../views/3d/webgl-engine/lib/RenderSlot.js";import{ContextType as y}from"../views/webgl/context-util.js";import{CompareFunction as v,Face as b,StencilOperation as T}from"../views/webgl/enums.js";const w=t.getLogger("esri.layers.VoxelWasmPerSceneView");var R;!function(e){e[e.Lifetime=1]="Lifetime",e[e.RequestResponse=2]="RequestResponse",e[e.Rendering=3]="Rendering",e[e.Error=4]="Error"}(R||(R={}));class E{constructor(e){this._halfIntTexturesAvailable=!1,this._textureFloatLinearAvailable=!1,this._havePreparedWithAllLayers=!1,this._renderPluginContext=null,this._vxl=null,this._pluginIsActive=!1,this._moreToLoad=!1,this._viewportWidth=-1,this._viewportHeight=-1,this._newLayers=[],this._layers=new Map,this._shaderOutput=f.Color,this._renderSlot=p.VOXEL,this._rctx=null,this._renderTargetToRestore=null,this._lastFrameWasStationary=!1,this._wasmMemBlockSizes=[512,1024,2048,4096,8192,16384,32768,65536],this._wasmMemBlocks=new Map,this._dbgFlags=new Set,this._captureFrustum=!1,this._frustum=null,this._frustumRenderableId=-1,this._renderCoordsHelper=null,this._view=e,this._initialize()}get canRender(){return!!this._vxl&&"local"===this._view.viewingMode}_dbg(e,t){this._dbgFlags.has(e)&&(e===R.Error?w.error(t):w.warn(t))}_removeRenderPlugin(){this._pluginIsActive&&this._view._stage&&(this._dbg(R.Lifetime,"--removeRenderPlugin--"),this._view._stage.removeRenderPlugin(this)),this._pluginIsActive=!1}_initialize(){this._dbg(R.Lifetime,"--initialize--");for(const e of this._wasmMemBlockSizes)this._wasmMemBlocks.set(e,0);this._readyWatchHandle=a((()=>this._view.ready),(e=>{e&&"local"===this._view.viewingMode?(this._dbg(R.Lifetime,"view ready status changed to ready on a local view, calling addRenderPlugin"),this._view._stage.addRenderPlugin([this._renderSlot],this),this._pluginIsActive=!0):(this._dbg(R.Lifetime,"view ready status changed, not ready or not a local view!"),this._removeRenderPlugin())}),{initial:!0}),this._qualityWatchHandle=a((()=>this._view?.qualityProfile),(e=>{this._dbg(R.Rendering,"qualityProfile changed to "+e),this._vxl&&this._vxl.set_quality(this._toWasmQuality(e))}),{initial:!0}),this._timeExtentWatchHandle=a((()=>this._view?.timeExtent),(()=>{if(this._vxl){const e=this._getTimeArgs(this._view?.timeExtent);this._dbg(R.Rendering,"sceneView timeExtent changed to useTime="+e.useTime+" st="+e.startTime+" et="+e.endTime),this._vxl.set_scene_time_extent(e.startTime,e.endTime,e.useTime),this._renderPluginContext.requestRender()}}),{initial:!0}),this._stationaryWatchHandle=a((()=>this._view?.stationary),(e=>{this._vxl&&e&&!this._lastFrameWasStationary&&this._renderPluginContext.requestRender()}))}initializeRenderContext(e){this._dbg(R.Lifetime,"--initializeRenderContext--");const t=e.renderContext.rctx;t.type===y.WEBGL2?(this._renderPluginContext=e,this._rctx=e.renderContext.rctx,this._halfIntTexturesAvailable=!!this._rctx.capabilities.textureNorm16,this._textureFloatLinearAvailable=this._rctx.capabilities.textureFloatLinear,this._initializeWasm(t.gl)):this._dbg(R.Error,"WebGL 1 context only!")}uninitializeRenderContext(){this._renderPluginContext=null,this._rctx=null,this._dbg(R.Lifetime,"--uninitializeRenderContext--")}_restoreFramebuffer(){if(!this._renderTargetToRestore)return;const e=this._renderTargetToRestore.fbo;if(!!!this._rctx)return void this._dbg(R.Error,"no context in restoreFramebuffer!");this._rctx.bindFramebuffer(e,!0);const t=this._renderTargetToRestore.viewport;this._rctx.setViewport(t.x,t.y,t.width,t.height)}_bindPreviousDepthToSlot(e,t){const r=!!this._rctx,s=!!this._renderTargetToRestore;if(!r||!s)return 0;const i=this._renderTargetToRestore.fbo.depthStencilTexture;return i?(0===t?this._rctx.bindTexture(null,e,!0):this._rctx.bindTexture(i,e,!0),1):(this._dbg(R.Error,"no depth/stencil texture exists!"),0)}_modifyResourceCount(e,t,r){if(!this._rctx)return void this._dbg(R.Error,"modifyAllocation callback has no rendering context!");const s=e;1===r?this._rctx.instanceCounter.increment(s,t):this._rctx.instanceCounter.decrement(s,t)}_setBlendState(e,t,r,s){this._rctx?(this._rctx.setBlendingEnabled(1===e),this._rctx.setBlendFunction(t,r),this._rctx.setBlendEquation(s)):this._dbg(R.Error,"setBlendState callback has no rendering context!")}_setFrontFace(e){this._rctx?this._rctx.setFrontFace(e):this._dbg(R.Error,"setFrontFace callback has no rendering context!")}_setDepthStencilStateFunction(e,t,r){this._rctx?(this._rctx.setDepthFunction(r),this._rctx.setDepthTestEnabled(1===e),this._rctx.setDepthWriteEnabled(1===t),this._rctx.setStencilTestEnabled(!1),this._rctx.setStencilFunction(v.ALWAYS,0,255),this._rctx.setStencilOpSeparate(b.FRONT,T.KEEP,T.INCR,T.KEEP),this._rctx.setStencilOpSeparate(b.BACK,T.KEEP,T.DECR,T.KEEP)):this._dbg(R.Error,"setDepthStencilStateFunction callback has no rendering context!")}_setRasterizerState(e){if(this._rctx)switch(e){case h.None:this._rctx.setFaceCullingEnabled(!1);break;case h.Back:this._rctx.setCullFace(b.BACK),this._rctx.setFaceCullingEnabled(!0);break;case h.Front:this._rctx.setCullFace(b.FRONT),this._rctx.setFaceCullingEnabled(!0)}else this._dbg(R.Error,"setRasterizerState callback has no rendering context!")}_setViewport(e,t,r,s){this._rctx?this._rctx.setViewport(e,t,r,s):this._dbg(R.Error,"setViewport callback has no rendering context!")}_updateMemoryUsage(){this._layers.forEach(((e,t)=>{if(e.needMemoryUsageUpdate){const r=this._vxl.estimate_memory_usage(t);r>=0&&(e.needMemoryUsageUpdate=!1,e.layerView.setUsedMemory(r))}}))}_syncRequestsResponses(){this._layers.forEach(((t,r)=>{const s=[];t.responses.forEach(((e,i)=>{s.push(i),this._dbg(R.RequestResponse,"responding for requestID:"+i+" size:"+e.size),this._vxl.respond(r,i,e),e.requestType!==_.TreeIndex&&e.requestType!==_.Section||(t.needMemoryUsageUpdate=!0)}));const a=t.responses;for(const e of s)a.delete(e);const n=this._vxl.get_new_requests(r),o=t.abortController.signal;for(const l in n){t.outstandingRequestCount+=1,1===t.outstandingRequestCount&&t.layerView.updatingFlagChanged();const r=n[l],s={responseType:"array-buffer",signal:o};this._dbg(R.RequestResponse,"making requestID:"+l+" url:"+r.url),e(r.url,s).then((e=>{t.outstandingRequestCount-=1,0===t.outstandingRequestCount&&t.layerView.updatingFlagChanged(),this._dbg(R.RequestResponse,"have response for requestID:"+l);let s=0;if(e.data.byteLength>0){s=this._vxl._malloc(e.data.byteLength);const t=new Uint8Array(this._vxl.HEAPU8.buffer,s,e.data.byteLength),r=new Uint8Array(e.data);for(let s=0;s<e.data.byteLength;++s)t[s]=r[s]}a.set(+l,{responseType:r.responseType,ptr:s,size:e.data.byteLength,success:!0,requestType:r.requestType})})).catch((e=>{t.outstandingRequestCount-=1,0===t.outstandingRequestCount&&t.layerView.updatingFlagChanged(),i(e)||(this._dbg(R.Error,`requestID:${l} failed, error=${e.toString()}`),a.set(+l,{responseType:r.responseType,ptr:0,size:0,success:!1,requestType:r.requestType}))}))}}))}updateWasmCamera(e){this._vxl.set_projection_matrix.apply(this._vxl,e.projectionMatrix),this._vxl.set_view_matrix.apply(this._vxl,e.viewMatrix),this._vxl.set_near_far(e.near,e.far)}isUpdating(e){return!(this._vxl||!this._vxlPromise)||!!this._layers.has(e)&&this._layers.get(e).outstandingRequestCount>0}getLayerTimes(e){const t=[];return this._layers.forEach(((r,s)=>{if(r.layerView.wasmLayerId===e.wasmLayerId){const r=this._vxl.get_layer_epoch_times(s,e.layer.currentVariableId);for(let e=0;e<r.length;++e)t.push(r[e])}})),t}getCurrentLayerTimeIndex(e){let t=0;return this._layers.forEach(((r,s)=>{r.layerView.wasmLayerId===e.wasmLayerId&&(t=this._vxl.get_layer_current_time_id(s))})),t}setEnabled(e,t){this._layers.forEach(((r,s)=>{r.layerView.wasmLayerId===e.wasmLayerId&&(this._vxl.set_enabled(s,t),r.needMemoryUsageUpdate=!0,this._renderPluginContext.requestRender())}))}setStaticSections(e,t){const r={mask:d.StaticSections,staticSections:t};return this._doMaskedUIUpdate(e,r,!0)}setCurrentVariable(e,t){const r={mask:d.CurrentVariable,currentVariable:t};return this._doMaskedUIUpdate(e,r,!0)}setRenderMode(e,t){const r={mask:d.RenderMode,renderMode:t};return this._doMaskedUIUpdate(e,r,!0)}setVerticalExaggerationAndOffset(e,t,r,s){const i={mask:d.ExaggerationAndOffset,volStyleDesc:{volumeId:t,verticalExaggeration:r,verticalOffset:s}};return this._doMaskedUIUpdate(e,i,!0)}setVariableStyles(e,t){const r={mask:d.VariableStyles,variableStyles:t};return this._doMaskedUIUpdate(e,r,!0)}setVolumeStyles(e,t){const r={mask:d.VolumeStyles,volumeStyles:t};return this._doMaskedUIUpdate(e,r,!0)}setEnableDynamicSections(e,t){const r={mask:d.ContainerVisibility,containerIsVisible:t,container:u.DynamicSections};return this._doMaskedUIUpdate(e,r,!0)}setEnableIsosurfaces(e,t){const r={mask:d.ContainerVisibility,containerIsVisible:t,container:u.Isosurfaces};return this._doMaskedUIUpdate(e,r,!0)}setEnableSections(e,t){const r={mask:d.ContainerVisibility,containerIsVisible:t,container:u.StaticSections};return this._doMaskedUIUpdate(e,r,!0)}_doMaskedUIUpdate(e,t,r){if(!this._vxl)return!1;let s=!1;return this._layers.forEach(((r,i)=>{if(r.layerView.wasmLayerId===e.wasmLayerId){const e={str:JSON.stringify(t),byteCount:0,ptr:0,isReusable:!1};this._allocateBlock(e)&&(s=1===this._vxl.handle_masked_ui_update(i,e.ptr,e.byteCount),e.isReusable||this._vxl._free(e.ptr))}})),s&&r&&this._renderPluginContext.requestRender(),s}_addTriangleToWasmBuffer(e,t,r,s,i){return e[3*t+0]=r[0],e[3*t+1]=r[1],e[3*t+2]=r[2],e[3*(t+=1)+0]=s[0],e[3*t+1]=s[1],e[3*t+2]=s[2],e[3*(t+=1)+0]=i[0],e[3*t+1]=i[1],e[3*t+2]=i[2],t+=1}_addNormalToWasmBuffer(e,t,r){return e[3*t+0]=r[0],e[3*t+1]=r[1],e[3*t+2]=r[2],t+=1}_doCaptureFrustum(){if(!this._vxl)return;const e=36,t=e/3,r=this._vxl._malloc(3*e*Float32Array.BYTES_PER_ELEMENT),s=new Float32Array(this._vxl.HEAPF32.buffer,r,3*e),i=this._vxl._malloc(3*t*Float32Array.BYTES_PER_ELEMENT),a=new Float32Array(this._vxl.HEAPF32.buffer,i,e),n=this._frustum.points[o.NEAR_BOTTOM_LEFT],h=this._frustum.points[o.NEAR_BOTTOM_RIGHT],_=this._frustum.points[o.NEAR_TOP_RIGHT],d=this._frustum.points[o.NEAR_TOP_LEFT],u=this._frustum.points[o.FAR_BOTTOM_LEFT],c=this._frustum.points[o.FAR_BOTTOM_RIGHT],m=this._frustum.points[o.FAR_TOP_RIGHT],g=this._frustum.points[o.FAR_TOP_LEFT];let x=0,f=0;const p=this._frustum.planes[l.NEAR];x=this._addTriangleToWasmBuffer(s,x,_,h,n),f=this._addNormalToWasmBuffer(a,f,p),x=this._addTriangleToWasmBuffer(s,x,n,d,_),f=this._addNormalToWasmBuffer(a,f,p);const y=this._frustum.planes[l.FAR];x=this._addTriangleToWasmBuffer(s,x,u,c,m),f=this._addNormalToWasmBuffer(a,f,y),x=this._addTriangleToWasmBuffer(s,x,m,g,u),f=this._addNormalToWasmBuffer(a,f,y);const v=this._frustum.planes[l.TOP];x=this._addTriangleToWasmBuffer(s,x,m,_,d),f=this._addNormalToWasmBuffer(a,f,v),x=this._addTriangleToWasmBuffer(s,x,d,g,m),f=this._addNormalToWasmBuffer(a,f,v);const b=this._frustum.planes[l.BOTTOM];x=this._addTriangleToWasmBuffer(s,x,n,h,c),f=this._addNormalToWasmBuffer(a,f,b),x=this._addTriangleToWasmBuffer(s,x,c,u,n),f=this._addNormalToWasmBuffer(a,f,b);const T=this._frustum.planes[l.LEFT];x=this._addTriangleToWasmBuffer(s,x,d,n,u),f=this._addNormalToWasmBuffer(a,f,T),x=this._addTriangleToWasmBuffer(s,x,u,g,d),f=this._addNormalToWasmBuffer(a,f,T);const w=this._frustum.planes[l.RIGHT];x=this._addTriangleToWasmBuffer(s,x,_,m,c),f=this._addNormalToWasmBuffer(a,f,w),x=this._addTriangleToWasmBuffer(s,x,c,h,_),f=this._addNormalToWasmBuffer(a,f,w),-1!==this._frustumRenderableId&&this._vxl.remove_generic_mesh(this._frustumRenderableId),this._frustumRenderableId=this._vxl.add_generic_mesh(r,3*e,i,e,255,0,0,64),this._vxl._free(r),this._vxl._free(i),this._captureFrustum=!1,this._renderPluginContext.requestRender()}captureFrustum(){null===this._renderCoordsHelper&&(this._renderCoordsHelper=x.create(m.Local,n(!1,this._view.spatialReference))),null===this._frustum&&(this._frustum=new g(this._renderCoordsHelper)),this._captureFrustum=!0,null!==this._renderPluginContext&&this._renderPluginContext.requestRender()}toggleFullVolumeExtentDraw(e){this._vxl&&this._layers.forEach(((t,r)=>{t.layerView.wasmLayerId===e.wasmLayerId&&(this._vxl.toggle_full_volume_extent_draw(r),this._renderPluginContext.requestRender())}))}addVoxelLayer(e){if(!this._vxl){const t={layerView:e,resolveCallback:null,rejectCallback:null},r=new Promise(((e,r)=>{t.resolveCallback=e,t.rejectCallback=r}));return this._newLayers.push(t),r}const t=this._addVoxelLayer(e);return t<0?Promise.reject(-1):Promise.resolve(t)}removeVoxelLayer(e){if(!this._vxl){const t=this._newLayers.findIndex((t=>e.uid===t.layerView.uid));t>=0&&(this._newLayers[t].resolveCallback(-1),this._newLayers.splice(t,1));const r=this._newLayers.length;return 0===r&&(this._dbg(R.Lifetime," no voxel layers left after removing a layer, removing RenderPlugin and destroying"),this.destroy()),r}let t=-1;this._layers.forEach(((r,s)=>{r.layerView.wasmLayerId===e.wasmLayerId&&(t=s,r.abortController.abort(),this._vxl.remove_layer(t))})),t>=0&&this._layers.delete(t);const r=this._layers.size;return 0===r&&(this._dbg(R.Lifetime," no voxel layers left after removing a layer, removing RenderPlugin and destroying"),this.destroy()),r}_getBlockSize(e){for(const t of this._wasmMemBlockSizes)if(e<t)return t;return-1}_allocateBlock(e){e.byteCount=this._vxl.lengthBytesUTF8(e.str)+1;const t=this._getBlockSize(e.byteCount);return t<0?(e.isReusable=!1,e.ptr=this._vxl._malloc(e.byteCount)):(e.isReusable=!0,e.ptr=this._wasmMemBlocks.get(t),0===e.ptr&&(e.ptr=this._vxl._malloc(t),this._wasmMemBlocks.set(t,e.ptr))),0!==e.ptr&&(this._vxl.stringToUTF8(e.str,e.ptr,e.byteCount),!0)}_getTimeArgs(e){let t=-Number.MAX_VALUE,s=Number.MAX_VALUE,i=!1;return r(e)&&(e.isAllTime?i=!0:(r(e.start)&&(i=!0,t=e.start.getTime()/1e3),r(e.end)&&(i=!0,s=e.end.getTime()/1e3))),{startTime:t,endTime:s,useTime:i}}_addVoxelLayer(e){const t=e.layer;let r=-1;const s=t.getConfiguration();if(s.length<1)return-1;const i={str:s,byteCount:0,ptr:0,isReusable:!1};if(!this._allocateBlock(i))return-1;const a=this._getTimeArgs(this._view?.timeExtent),n=this._view.spatialReference.isWGS84&&t.spatialReference.isWGS84?111319.49079327357:1;if(r=this._vxl.add_layer(t.serviceRoot,i.ptr,i.byteCount,n,n,a.startTime,a.endTime,a.useTime,this._toWasmQuality(this._view.qualityProfile)),i.isReusable||this._vxl._free(i.ptr),r>=0){const t=new AbortController;if(this._layers.set(r,{layerView:e,responses:new Map,outstandingRequestCount:0,abortController:t,needMemoryUsageUpdate:!1}),!this._halfIntTexturesAvailable||has("mac")){const t=[];let r="";for(const s of e.layer.variables)"Int16"!==s.renderingFormat.type&&"UInt16"!==s.renderingFormat.type||(t.push(s.name),s.id===e.layer.currentVariableId&&(r=s.name));""!==r&&w.error("#addVoxelLayer_error()",e.layer,`The voxel layer '${e.layer.title}' cannot render the current variable '${r}' in this browser`),t.length>0&&w.warn("#addVoxelLayer_warning()",e.layer,`The voxel layer '${e.layer.title}' cannot render the variables '${t.toString()}' in this browser`)}if(!this._textureFloatLinearAvailable){const t=[];let r="";for(const s of e.layer.variables)"Float32"===s.renderingFormat.type&&(t.push(s.name),s.id===e.layer.currentVariableId&&(r=s.name));""!==r&&w.error("#addVoxelLayer_error()",e.layer,`The voxel layer '${e.layer.title}' cannot render the current variable '${r}' in this browser`),t.length>0&&w.warn("#addVoxelLayer_warning()",e.layer,`The voxel layer '${e.layer.title}' cannot render the variables '${t.toString()}' in this browser`)}return has("esri-mobile")&&w.warnOnce("Mobile support differs across devices. Voxel layer might not display as expected."),r}return-1}prepareRender(e){if(!this._vxl)return;const t=e.bindParameters.camera.viewForward,r=e.bindParameters.camera.eye;this._vxl.update_camera_pos_and_direction(r[0],r[1],r[2],t[0],t[1],t[2]);const s=this._vxl.cull();this._dbg(R.RequestResponse,"missingResourceCount="+s),this._moreToLoad=s>0,this._havePreparedWithAllLayers=0===this._newLayers.length,this._updateMemoryUsage()}render(e){if(!this._vxl||e.output!==this._shaderOutput||e.bindParameters.slot!==this._renderSlot)return;for(const r of this._newLayers){const e=this._addVoxelLayer(r.layerView);-1===e?r.rejectCallback(-1):r.resolveCallback(e)}if(this._newLayers=[],0===this._layers.size)return void this._dbg(R.Error,"No voxel layers but RenderPlugin instance is being asked to render!");this._renderTargetToRestore={fbo:this._rctx.getBoundFramebufferObject(),viewport:this._rctx.getViewport()},this._syncRequestsResponses(),this._lastFrameWasStationary=this._view.stationary,this._rctx.setPolygonOffsetFillEnabled(!1),this._rctx.setScissorTestEnabled(!1),this._rctx.setColorMask(!0,!0,!0,!0),this._vxl.begin_color_frame(!this._view.stationary||this._moreToLoad,e.bindParameters.lighting.mainLight.direction[0],e.bindParameters.lighting.mainLight.direction[1],e.bindParameters.lighting.mainLight.direction[2]);const t=this._renderTargetToRestore.viewport;t.width===this._viewportWidth&&t.height===this._viewportHeight||(this._viewportWidth=t.width,this._viewportHeight=t.height,this._vxl.set_viewport(t.width,t.height),this._layers.forEach((e=>{e.needMemoryUsageUpdate=!0}))),0===t.x&&0===t.y||this._dbg(R.Error,"Unsupported viewport parameters detected!"),this.updateWasmCamera(e.bindParameters.camera),this._captureFrustum&&(this._frustum.update(e.bindParameters.camera),this._doCaptureFrustum()),this._vxl.draw(),this._renderTargetToRestore.fbo=null,e.rctx.externalTextureUnitUpdate(this._vxl.get_texture_units_bound_in_frame(),this._vxl.get_active_texture_unit()),e.rctx.externalVertexArrayObjectUpdate(),e.rctx.externalVertexBufferUpdate(),this._rctx.externalProgramUpdate(),(this._moreToLoad||!this._havePreparedWithAllLayers&&this._layers.size>0)&&this._renderPluginContext.requestRender()}destroy(){this._dbg(R.Lifetime,"--destroy--"),this._removeRenderPlugin(),this._readyWatchHandle=s(this._readyWatchHandle),this._qualityWatchHandle=s(this._qualityWatchHandle),this._timeExtentWatchHandle=s(this._timeExtentWatchHandle),this._stationaryWatchHandle=s(this._stationaryWatchHandle),this._vxl&&(this._layers.forEach((e=>{e.abortController.abort()})),this._wasmMemBlocks.forEach((e=>{0!==e&&this._vxl._free(e)})),this._vxl.uninitialize_voxel_wasm(),this._vxl=null)}_initializeWasm(e){return this._vxl?Promise.resolve():(this._vxlPromise||(this._vxlPromise=c(e).then((e=>{if(this._vxl=e,this._vxlPromise=null,this._newLayers.length<=0)return this._dbg(R.Lifetime," no voxel layers left after WASM downloaded, removing RenderPlugin and destroying"),void this.destroy();const t=this._getTimeArgs(this._view?.timeExtent),r=this._vxl.addFunction(this._restoreFramebuffer.bind(this),"v"),s=this._vxl.addFunction(this._setBlendState.bind(this),"viiii"),i=this._vxl.addFunction(this._setFrontFace.bind(this),"vi"),a=this._vxl.addFunction(this._setRasterizerState.bind(this),"vi"),n=this._vxl.addFunction(this._setDepthStencilStateFunction.bind(this),"viii"),o=this._vxl.addFunction(this._setViewport.bind(this),"viiii"),l=this._vxl.addFunction(this._bindPreviousDepthToSlot.bind(this),"iii"),h=this._vxl.addFunction(this._modifyResourceCount.bind(this),"viii"),_=this._halfIntTexturesAvailable&&!has("mac"),d=this._textureFloatLinearAvailable;this._vxl.initialize_voxel_wasm(r,s,i,a,n,o,l,h,t.startTime,t.endTime,t.useTime,_,d),this._renderPluginContext&&this._renderPluginContext.requestRender()})).catch((()=>{for(const e of this._newLayers)e.rejectCallback(-2);this._dbg(R.Error," WASM failed to download, removing RenderPlugin and destroying"),this.destroy()}))),this._vxlPromise)}pickDepth(e,t,r){if(!this._vxl||!this._rctx||0===this._layers.size)return null;const s=r.viewport[3]-t;if(e<0||e>r.viewport[2]||t<0||t>r.viewport[3])return this._dbg(R.Error,`pickDepth: outOfRange, screenXY=[${e}, ${s}], vp=[${r.viewport.toString()}]`),null;this._renderTargetToRestore={fbo:this._rctx.getBoundFramebufferObject(),viewport:this._rctx.getViewport()};const i=r.viewForward,a=r.eye;this._vxl.update_camera_pos_and_direction(a[0],a[1],a[2],i[0],i[1],i[2]),this.updateWasmCamera(r),this._vxl.begin_frame();const n=this._vxl.pick_depth(e,s);if(this._renderTargetToRestore.fbo=null,this._rctx.externalTextureUnitUpdate(this._vxl.get_texture_units_bound_in_frame(),this._vxl.get_active_texture_unit()),this._rctx.externalVertexArrayObjectUpdate(),this._rctx.externalVertexBufferUpdate(),this._rctx.externalProgramUpdate(),n.success){return n.distanceToCamera}return null}_toWasmQuality(e){switch(e){case"low":return 0;case"medium":return 1;case"high":return 2}}}export{E as default};
|