@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 10.3 kB
JavaScript
import{_ as e}from"../../../../chunks/tslib.es6.js";import t from"../../../../core/Accessor.js";import r from"../../../../core/Evented.js";import has from"../../../../core/has.js";import i from"../../../../core/Logger.js";import{removeMaybe as s,destroyMaybe as o,isSome as n,isNone as a}from"../../../../core/maybe.js";import{watch as p,initial as d}from"../../../../core/reactiveUtils.js";import{addFrameTask as h}from"../../../../core/scheduling.js";import{Milliseconds as c}from"../../../../core/time.js";import{property as l}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import"../../../../core/arrayUtils.js";import{subclass as m}from"../../../../core/accessorSupport/decorators/subclass.js";import{ComponentObjectCollection as u}from"../collections/Component/ComponentObjectCollection.js";import{ShaderTechniqueRepository as _}from"../core/shaderTechnique/ShaderTechniqueRepository.js";import{RenderRequestType as f,Decorations as y}from"../lib/basicInterfaces.js";import g from"../lib/CompositingHelper.js";import{textureToDepth as R}from"../lib/depthRangeUtils.js";import{GLMaterialRepository as x}from"../lib/GLMaterialRepository.js";import{MagnifierHelper as b}from"../lib/MagnifierHelper.js";import{UpdateParameters as v}from"../lib/Material.js";import{ObjectAndLayerIdRenderHelper as j}from"../lib/ObjectAndLayerIdRenderHelper.js";import{Renderer as w}from"../lib/Renderer.js";import{RenderingContext as T}from"../lib/RenderingContext.js";import{TextureRepository as A}from"../lib/TextureRepository.js";import{StippleTextureRepository as C}from"../materials/StippleTextureRepository.js";import{WaterTextureRepository as U}from"../materials/internal/WaterTextureRepository.js";import{getContextCache as D}from"./contextCache.js";import{removeLoadedShaderModules as O}from"./requireUtils.js";import{ScreenshotManager as M,ScreenshotContext as q}from"./ScreenshotManager.js";import{contextCache as S}from"./testUtils.js";import{RenderState as L}from"../../../support/RenderState.js";import{createContextOrErrorHTML as H}from"../../../webgl/context-util.js";let B=class extends t{constructor(e){super({}),this.events=new r,this.waterTextureRepository=new U,this._magnifierHelper=new b,this.objectAndLayerIdRenderHelper=has("enable-feature:objectAndLayerId-rendering")?new j:null,this._needsUpdate=!0,this._needsRender=!0,this._idleSuspend=!0,this._needsWaterReflectionUpdate=!1,this._lastAnimationUpdate=0,this._container=e.container,this._viewingMode=e.viewingMode,this._initializeContext(e),p((()=>this.waterTextureRepository?.updating),(()=>this.requestRender()),d),this._magnifierHelper.events.on("request-render",(()=>this.requestRender())),this._stippleTextureRepository=new C(this._rctx),this._shaderTechniqueRepository=new _({rctx:this._rctx,viewingMode:e.viewingMode,stippleTextureRepository:this._stippleTextureRepository,waterTextureRepository:this.waterTextureRepository}),this._textureRepository=new A(e,this._shaderTechniqueRepository,this._rctx),this._textureRepository.events.on("changed",(e=>this.requestRender(e))),this._materialRepository=new x(this._textureRepository,this._shaderTechniqueRepository,(()=>this.requestRender()),(()=>this.requestRender())),this._compositingHelper=new g(this._rctx,this._shaderTechniqueRepository),this.renderer=new w(e,this._materialRepository,this._textureRepository,this._shaderTechniqueRepository,this._rctx,this._compositingHelper,this._magnifierHelper,(e=>this.requestRender(e)));const t={renderScene:(e,t,r,i,s)=>this.renderer.render(e,t,{camera:r,contentCamera:r,mode:L.IDLE},i,s),requestRenderScene:e=>this.requestRender(e),prepareOverlay:()=>e.options.screenshot.prepareOverlay(),renderOverlay:(t,r)=>e.options.screenshot.renderOverlay(t,r)};this._screenshotManager=new M(this._rctx,t,(e=>this.events.emit("force-camera-for-screenshot",e)),(()=>this.renderer.disposeOffscreenBuffers())),this._registerFrameTask(e)}normalizeCtorArgs(){return{}}destroy(){this._container.contains(this._canvas)&&this._container.removeChild(this._canvas),this._frameTask=s(this._frameTask),this._shaderTechniqueRepository=o(this._shaderTechniqueRepository)}get performanceInfo(){const e=this._rctx.gl;return{renderer:this.renderer.performanceInfo,textureMemory:void 0!==e.getUsedTextureMemory?e.getUsedTextureMemory():void 0,renderbufferMemory:void 0!==e.getUsedRenderbufferMemory?e.getUsedRenderbufferMemory():void 0,VBOMemory:void 0!==e.getUsedVBOMemory?e.getUsedVBOMemory():void 0}}requestRender(e=f.UPDATE){this._needsRender=!0,e===f.UPDATE&&(this._needsUpdate=!0)}get updating(){return this._needsUpdate||this._needsWaterReflectionUpdate||this.renderer.updating||this._textureRepository.updating||this.waterTextureRepository.updating||this._magnifierHelper.updating}get textureRepository(){return this._textureRepository}get compositingHelper(){return this._compositingHelper}set magnifier(e){this._magnifierHelper.magnifier=e}setIdleSuspend(e){this._idleSuspend!==e&&(this._idleSuspend=e,this.requestRender())}get renderingContext(){return this._rctx}get capabilities(){return this._rctx.capabilities}get canvas(){return this._canvas}takeScreenshot(e){return this._screenshotManager.takeScreenshot(e).then((e=>e[0]))}takeScreenshotWithOID(e){return e.objectAndLayerIdColor=!0,this._screenshotManager.takeScreenshot(e)}getAlpha(){return!!this._rctx.contextAttributes.alpha}getMinimalDepthForArea(e,t,r,i,s,o=s){const a=i.constrainWindowSize(t,r,s*i.pixelRatio,o*i.pixelRatio),p=this._ensureDepthBuffer(a);this.renderer.readDepthPixels(i,a,p);let d=Number.MAX_VALUE;for(let n=0;n<a[2]*a[3];n++){const e=R(4*n,p,i.nearFar);d>e&&e!==i.nearFar[0]&&e!==i.nearFar[1]&&(d=e)}if(n(e)){const s=e.pickDepth(t*i.pixelRatio,r*i.pixelRatio,i);n(s)&&d>s&&s!==i.nearFar[0]&&s!==i.nearFar[1]&&(d=s)}return d===Number.MAX_VALUE?void 0:d}_ensureDepthBuffer(e){const t=4*e[2]*e[3];return(a(this._tmpDepthBuffer)||this._tmpDepthBuffer.byteLength<t)&&(this._tmpDepthBuffer=new Uint8Array(t)),this._tmpDepthBuffer}async reloadShaders(){O(),await this._shaderTechniqueRepository.reloadAll(),this.requestRender()}_registerFrameTask(e){const t=e.view.state;let r=!1,i=f.BACKGROUND,s=!1;const o={preRender:({time:s})=>{r=this.updating,i=this._needsUpdate?f.UPDATE:f.BACKGROUND,e.commitSyncLayers();const o=c(s-this._lastAnimationUpdate);if(o>this.renderer.animationTimestep||n(t.forcedAnimationTime)||r||this._needsRender){const e=c(o/this.renderer.animationTimeDilation),r=new v(t.camera,e,t.forcedAnimationTime);this.renderer.updateAnimation(r)&&this.requestRender(f.BACKGROUND),this._lastAnimationUpdate=s}},render:({time:e})=>{if((this._needsRender||!this._idleSuspend||!this.renderer.isCameraFinal||this._needsWaterReflectionUpdate)&&t.camera.fullWidth>0&&t.camera.fullHeight>0){const r=this._needsUpdate&&this._idleSuspend&&this.renderer.isCameraFinal;this._needsRender=!1,this._needsUpdate=!1,this._needsWaterReflectionUpdate=!1,this.renderer.render(null,null,t,y.ON,e),s=!0,r&&this.renderer.hasWaterReflection&&(this.requestRender(f.BACKGROUND),this._needsWaterReflectionUpdate=!0)}},update:({time:e})=>{const r=new q(t.camera,this.renderer.hasSlicePlane||this._magnifierHelper.enabled);this._textureRepository.update(),this._screenshotManager.update(r,e)},finish:()=>{s&&(this.renderer.finish(t.mode===L.IDLE?i:f.UPDATE),s=!1)}};this._frameTask=h(o)}_initializeContext(e){const t=e.options;this._canvas=t.canvas,this._canvas||(this._canvas=document.createElement("canvas")),this._canvas.setAttribute("style","width: 100%; height:100%; display:block;");const r={alpha:t.alpha||!1,premultipliedAlpha:!0,antialias:!1,depth:!0,stencil:null==t.stencil||t.stencil,powerPreference:"high-performance",preserveDrawingBuffer:t.preserveDrawingBuffer??!1},s=H("3d",this._canvas,r);if(a(s)){const e=has("esri-force-webgl");i.getLogger(this.declaredClass).error(e)}else this._rctx=this._newRenderingContext(s,e),this._loadShaderOnlyExtensions(),!t.alpha&&this._rctx.contextAttributes.alpha&&i.getLogger(this.declaredClass).error("WebGL context has alpha channel even though no alpha channel was requested"),!this._rctx.contextAttributes.alpha&&has("safari")>=11&&(this._container.style.backgroundColor="black"),this._container.appendChild(this._canvas)}_newRenderingContext(e,t){const r={disabledExtensions:t.options.deactivatedWebGLExtensions||{},debugWebGLExtensions:t.options.debugWebGLExtensions||{},maxAnisotropy:8},i=(e,r)=>t.view.resourceController.memoryController.newCache(e,r);if(S.enabled){let t=E.get(e);return t?(t.configure(r),t.newCache=i,t.ref(),t):(t=new T(e,r,i),E.set(e,t),t.ref(),t)}return new T(e,r,i)}_loadShaderOnlyExtensions(){this._rctx.capabilities.enable("standardDerivatives"),this._rctx.capabilities.enable("shaderTextureLOD"),this._rctx.capabilities.enable("textureFloat")}getObjectAndLayerIdColor(e){return n(this.objectAndLayerIdRenderHelper)?this.objectAndLayerIdRenderHelper.getObjectAndLayerIdColor(e):null}get componentObjectCollection(){return a(this._componentObjectCollection)&&(this._componentObjectCollection=new u(this.renderer.renderPassManager,this._viewingMode)),this._componentObjectCollection}set componentObjectCollection(e){this._componentObjectCollection=e}};e([l({type:Boolean,readOnly:!0})],B.prototype,"updating",null),e([l({autoDestroy:!0})],B.prototype,"_rctx",void 0),e([l({autoDestroy:!0})],B.prototype,"_container",void 0),e([l({autoDestroy:!0})],B.prototype,"_canvas",void 0),e([l({autoDestroy:!0})],B.prototype,"_stippleTextureRepository",void 0),e([l({autoDestroy:!0})],B.prototype,"waterTextureRepository",void 0),e([l({autoDestroy:!0})],B.prototype,"_magnifierHelper",void 0),e([l({readOnly:!0})],B.prototype,"objectAndLayerIdRenderHelper",void 0),e([l({autoDestroy:!0})],B.prototype,"_textureRepository",void 0),e([l({autoDestroy:!0})],B.prototype,"_compositingHelper",void 0),e([l({autoDestroy:!0,readOnly:!0})],B.prototype,"renderer",void 0),e([l({autoDestroy:!0})],B.prototype,"_screenshotManager",void 0),e([l()],B.prototype,"componentObjectCollection",null),e([l({autoDestroy:!0})],B.prototype,"_componentObjectCollection",void 0),e([l()],B.prototype,"_needsUpdate",void 0),e([l()],B.prototype,"_needsWaterReflectionUpdate",void 0),B=e([m("esri.views.3d.webgl-engine.parts.RenderView")],B);const E=D();export{B as RenderView};