@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 30.7 kB
JavaScript
import{_ as e}from"../../../../chunks/tslib.es6.js";import r from"../../../../core/Accessor.js";import{update as t}from"../../../../core/arrayUtils.js";import s from"../../../../core/Handles.js";import has from"../../../../core/has.js";import{unwrapOr as i,removeMaybe as a,disposeMaybe as n,isSome as h,isNone as o,applySome as d,unwrap as l}from"../../../../core/maybe.js";import _ from"../../../../core/PooledArray.js";import{watch as c,syncAndInitial as p,initial as m,sync as u}from"../../../../core/reactiveUtils.js";import{property as f}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/accessorSupport/ensureType.js";import{subclass as g}from"../../../../core/accessorSupport/decorators/subclass.js";import{h as T,a as b,m as R}from"../../../../chunks/mat4.js";import{I as E,c as A}from"../../../../chunks/mat4f64.js";import{a as P}from"../../../../chunks/boundedPlane.js";import S from"../../support/debugFlags.js";import{TransparencyMode as y}from"../../terrain/TerrainRenderer.js";import{RenderPassManager as w}from"../core/renderPasses/RenderPassManager.js";import{ShaderOutput as O}from"../core/shaderLibrary/ShaderOutput.js";import{HUDTransparentRenderStyle as C}from"../core/shaderLibrary/hud/HUDUniforms.js";import{AnimationTimeStep as D}from"./AnimationTimeStep.js";import{Decorations as x,RenderRequestType as I,StencilBits as H}from"./basicInterfaces.js";import{BoundingInfo as v}from"./BoundingInfo.js";import{ZERO as M,union as L}from"./depthRange.js";import{depthRangeFromScene as N}from"./depthRangeUtils.js";import{createEmptyDepthTexture as U}from"./glUtil3D.js";import{Highlight as F}from"./Highlight.js";import{RenderOccludedFlag as j}from"./Material.js";import{OffscreenRendering as G}from"./OffscreenRendering.js";import{RenderContext as q}from"./RenderContext.js";import{splitRenderGeometryChangeSetByMaterial as V}from"./rendererUtils.js";import{RenderFeature as B,setupFeatureDefaults as W}from"./RenderFeature.js";import{RenderPluginManager as k}from"./RenderPluginManager.js";import{RenderSlot as Q}from"./RenderSlot.js";import{ShadowAccumulator as Y}from"./ShadowAccumulator.js";import{ShadowHighlight as X}from"./ShadowHighlight.js";import{ShadowMap as z,SnapshotSlot as J}from"./ShadowMap.js";import K from"./SliceHelper.js";import{SmaaRenderPass as Z}from"./SmaaRenderPass.js";import{SSAOHelper as $}from"./SSAOHelper.js";import{TransparencyPassType as ee}from"./TransparencyPassType.js";import{EdgeView as re}from"./edgeRendering/EdgeView.js";import{Transparency as te}from"./edgeRendering/interfaces.js";import{MergedRenderer as se}from"../materials/renderers/MergedRenderer.js";import{AlphaMode as ie}from"../shaders/CompositingTechniqueConfiguration.js";import{RendererPerformanceInfo as ae,PerformanceCategory as ne}from"../statistics/RendererPerformanceInfo.js";import{RenderState as he}from"../../../support/RenderState.js";import{ClearBufferBit as oe,PixelFormat as de,PixelType as le}from"../../../webgl/enums.js";let _e=class extends r{get _bindParameters(){return this._renderContext.bindParameters}isFeatureEnabled(e,r=this._state){return i(this._renderStateFeatures.get(r,e),!1)}setFeatureEnabled(e,r,t){this._renderStateFeatures.set(r,e,t),this.notifyChange("_renderStateFeatures"),this._requestRender()}get _antialiasing(){return this._antialiasingEnabled||this.isFeatureEnabled(B.Antialiasing)}get _highQualityTransparency(){return this._highQualityTransparencyEnabled||this.isFeatureEnabled(B.HighQualityTransparency)}get hasWaterReflection(){return this.hasWater&&(this._waterReflectionEnabled||this.isFeatureEnabled(B.WaterReflection))}get hasWater(){return this._hasWater||this._hasOverlayWater}constructor(e,r,t,i,a,n,h,o){super({}),this._stage=e,this._materialRepository=r,this._shaderTechniqueRepository=i,this._rctx=a,this._compositingHelper=n,this._magnifierHelper=h,this._requestRender=o,this._materialRenderers=new _,this._needsTransparentPass=!1,this._hasHUDElements=!1,this._hasHighlights=!1,this._hasWater=!1,this._hasOverlayWater=!1,this._renderOverlay=e=>{},this._isRendering=!1,this._fallbackDepthStencilTexture=null,this._sliceHelper=new K,this._state=he.IDLE,this._renderStateFeatures=W(),this._antialiasingEnabled=!0,this._highQualityTransparencyEnabled=!0,this._terrainRenderingEnabled=!0,this._terrainTransparency=y.Opaque,this._waterReflectionEnabled=!1,this._ssaoEnabled=!1,this._hasAnimations=!1,this._animationTimestep=new D,this._handles=new s,this._renderHiddenTransparentEdges=()=>{},this._oitUsed=!1,this._smaaPass=new Z(this._rctx,i),o(),this._offscreen=new G(this._rctx,this._compositingHelper),this.performanceInfo=new ae(this._rctx),this._shadowMap=new z(this._rctx,e.viewingMode),this._ssaoHelper=new $(e.view,i,this._rctx,o),this._highlight=new F(i,this._rctx),this._shadowHighlight=new X(this._rctx,e.viewingMode),this._shadowAccumulator=new Y(this._rctx,i,e,(e=>{const r=this.shadowsEnabled;this._shadowMap.enabled=!0,this._prepare(e.camera,e.contentCamera),this._renderPlugins.prepareRender(),this._shadowMap.enabled=r}),((e,r,t)=>{e.shadowMap.start(e.camera,r,t),this._renderShadowCascades(O.Shadow,e.shadowMap),e.camera.setGLViewport(this._rctx),this._prepare(e.camera,e.contentCamera)}),o),this._renderContext=new q(this._rctx,this._offscreen,this._shadowMap,this._ssaoHelper,this._sliceHelper),this._renderPlugins=new k({renderContext:this._renderContext,techniqueRepository:i,textureRepository:t,materialRepository:this._materialRepository,requestRender:o,controller:e}),this.renderPassManager=new w(this._rctx,this._shaderTechniqueRepository),this._renderPlugins.add(this.renderPassManager.slots(),this.renderPassManager),this._handles.add([c((()=>this._stage.view.state.camera),(()=>o()),p),c((()=>S.EDGES_SHOW_HIDDEN_TRANSPARENT_EDGES),(e=>{this._renderHiddenTransparentEdges=e?()=>this._renderEdges(te.TRANSPARENT):()=>{},o()}),m),c((()=>this._ssaoEnabled||this.isFeatureEnabled(B.SSAO)),(e=>this._ssaoHelper.enabled=e),p)])}normalizeCtorArgs(){return{}}destroy(){this._handles.destroy(),this._smaaPass.dispose(),this._gpuTimerHandle=a(this._gpuTimerHandle),this._materialRenderers.forAll((e=>e.dispose())),this._materialRenderers.clear(),this._offscreen.dispose(),this._fallbackDepthStencilTexture=n(this._fallbackDepthStencilTexture),this._shadowMap.dispose(),this._ssaoHelper.dispose(),this._highlight.dispose(),this._shadowHighlight.dispose(),this._shadowAccumulator.dispose(),v.prune()}disposeOffscreenBuffers(){this._offscreen.dispose(),this._shadowMap.disposeOffscreenBuffers(),this._smaaPass.disable(),this._ssaoHelper.disposeOffscreenBuffers()}get updating(){return this._antialiasing&&this._smaaPass.updating||h(this._edgeView)&&this._edgeView.updating||this._shadowAccumulator.running||!this.isCameraFinal}ensureEdgeView(){return o(this._edgeView)&&(this._edgeView=new re({rctx:this._rctx,renderSR:this._stage.view.renderSpatialReference,viewingMode:this._stage.viewingMode,techniqueRepository:this._shaderTechniqueRepository,setNeedsRender:()=>this._requestRender(),schedule:e=>this._stage.view.resourceController.immediate.schedule(e)}),this._handles.add(c((()=>d(this._edgeView,(e=>e.updating))),(()=>this._requestRender()),u)),this._requestRender()),this._edgeView}get edgeView(){return this._edgeView}get isCameraFinal(){return T(this._bindParameters.ssr.reprojectionMatrix,E)}set _reprojectionMatrix(e){t(this._bindParameters.ssr.reprojectionMatrix,e)&&this.notifyChange("isCameraFinal")}get shadowsEnabled(){return!!this._shadowMap?.enabled}setParameters(e){const{_shadowMap:r,_bindParameters:t}=this;if(void 0!==e.screenSpaceReflectionsEnabled&&t.ssr.enabled!==e.screenSpaceReflectionsEnabled&&(t.ssr.enabled=e.screenSpaceReflectionsEnabled,this._requestRender()),void 0!==e.shadowMap&&this._shadowMap.enabled!==e.shadowMap&&(this._shadowMap.enabled=e.shadowMap,this._requestRender()),void 0!==e.shadowMapMaxCascades&&r.maxCascades!==e.shadowMapMaxCascades&&(r.maxCascades=e.shadowMapMaxCascades,this._requestRender()),h(e.environment)){h(e.environment.weather)&&(this._bindParameters.weather=e.environment.weather,this._bindParameters.weatherVisible=!!e.weatherVisible),void 0!==e.environment.lighting.ambientOcclusionEnabled&&this._ssaoEnabled!==e.environment.lighting.ambientOcclusionEnabled&&(this._ssaoEnabled=e.environment.lighting.ambientOcclusionEnabled,this._requestRender()),void 0!==e.environment.lighting.waterReflectionEnabled&&this._waterReflectionEnabled!==e.environment.lighting.waterReflectionEnabled&&(this._waterReflectionEnabled=e.environment.lighting.waterReflectionEnabled,this._requestRender());const r="virtual"!==e.environment.lighting.type;t.enableFillLights!==r&&(t.enableFillLights=r,this._requestRender())}e.background&&this._offscreen.background!==e.background&&(this._offscreen.background=e.background,this._requestRender()),void 0!==e.antialiasingEnabled&&this._antialiasingEnabled!==e.antialiasingEnabled&&(this._antialiasingEnabled=e.antialiasingEnabled,this._requestRender()),void 0!==e.highQualityTransparency&&this._highQualityTransparencyEnabled!==e.highQualityTransparency&&(this._highQualityTransparencyEnabled=e.highQualityTransparency,this._requestRender()),void 0!==e.defaultHighlightOptions&&(this._highlight.setDefaultOptions(e.defaultHighlightOptions),this._shadowHighlight.setDefaultOptions(e.defaultHighlightOptions),this._requestRender()),void 0!==e.overlays&&this._bindParameters.overlays!==e.overlays&&(this._bindParameters.overlays=e.overlays,this._requestRender()),void 0!==e.hasOverlayWater&&this._hasOverlayWater!==e.hasOverlayWater&&(this._hasOverlayWater=e.hasOverlayWater,this._requestRender()),void 0!==e.renderOverlay&&this._renderOverlay!==e.renderOverlay&&(this._renderOverlay=e.renderOverlay,this._requestRender()),void 0!==e.slicePlane&&this._sliceHelper.plane!==e.slicePlane&&(this._sliceHelper.plane=l(e.slicePlane),this._requestRender()),void 0!==e.terrainRenderingEnabled&&this._terrainRenderingEnabled!==e.terrainRenderingEnabled&&(this._terrainRenderingEnabled=e.terrainRenderingEnabled,this._requestRender()),void 0!==e.terrainTransparency&&this._terrainTransparency!==e.terrainTransparency&&(this._terrainTransparency=e.terrainTransparency,this._requestRender()),void 0!==e.shadowCastOptions&&this._shadowAccumulator.setOptions(e.shadowCastOptions)}get hasSlicePlane(){return!!this._sliceHelper.plane}get renderPlugins(){return this._renderPlugins}get _hasOITSupport(){return this._rctx.driverTest.floatBufferBlend.result}get _oitEnabled(){return this._highQualityTransparency&&this._hasOITSupport}modify(e,r){this._isRendering&&console.warn("Renderer.modify called while rendering");const{adds:t,removes:s,updates:i}=e;if(0===t.length&&0===s.length&&0===i.length)return;const a=V(e);let n=!1;a.forEach(((t,s)=>{if(r.done)return;let i=this._materialRenderers.find((e=>e.material===s));o(i)&&t.adds.length>0&&(i=new se(this._rctx,this._materialRepository,s),this._materialRenderers.push(i)),i&&(i.modify(t),i.isEmpty&&(n=!0)),t.removes.forEach((r=>e.removes.removeUnordered(r))),t.adds.forEach((r=>e.adds.removeUnordered(r))),t.updates.forEach((r=>e.updates.removeUnordered(r))),r.madeProgress()})),n&&this._materialRenderers.filterInPlace((e=>!e.isEmpty||(e.dispose(),!1))),this._hasHighlights=this._materialRenderers.some((e=>e.hasHighlights)),this._bindParameters.hasOccludees=this._materialRenderers.some((e=>e.hasOccludees)),this._hasWater=this._materialRenderers.some((e=>e.hasWater)),this._hasHUDElements=this._materialRenderers.some((e=>e.requiresSlot(Q.LINE_CALLOUTS_HUD_DEPTH,O.Color)||e.requiresSlot(Q.HUD_MATERIAL,O.Color)||e.requiresSlot(Q.LABEL_MATERIAL,O.Color))),this._requestRender()}updateAnimation(e){const r=this._hasAnimations;return this._hasAnimations=!1,this._materialRenderers.forAll((r=>this._hasAnimations=r.updateAnimation(e)||this._hasAnimations)),this._hasAnimations=this._renderPlugins.updateAnimation(e)||this._hasAnimations,this._hasAnimations!==r&&(this._gpuTimerHandle=r?a(this._gpuTimerHandle):this.performanceInfo.enableGPUPerformanceInfo()),this._hasAnimations}get animationTimestep(){return this._animationTimestep.value}get animationTimeDilation(){return this._animationTimestep.timeDilation}resetAnimation(){this._animationTimestep.clear()}render(e,r,t,s,i){this._isRendering=!0,this.performanceInfo.startFrame();const{camera:a,contentCamera:n,mode:d}=t;this._state=d,this._renderOverlay(i),this.performanceInfo.advance(ne.OVERLAY),this._renderContext.time=i,this._bindParameters.transparencyPassType=ee.NONE;const l=this._offscreen;l.setupRenderTarget(this.hasWaterReflection);const _=P(this._sliceHelper.plane);s===x.OFF&&(this._sliceHelper.plane=null),this._rctx.bindFramebuffer(e),a.setGLViewport(this._rctx),this._prepare(a,n),this._renderPlugins.prepareRender(),this.performanceInfo.advance(ne.PREPARE);const c=this._computeDepthRange(a);this._renderShadowMap(e,a,this._bindParameters.lighting.mainLight.direction,c),this.performanceInfo.advance(ne.SHADOW_MAP),l.initializeFrame(a),this._ensureBindParameters(a,n),this._renderLinearDepth(),this.performanceInfo.advance(ne.LINEAR_DEPTH),this._accumulateShadows(c,a,n),this.performanceInfo.advance(ne.ACCUMULATED_SHADOWS),this._renderNormal(),this.performanceInfo.advance(ne.NORMALS),this._ensureBindParametersSSR(i),this._renderSSAO(i),this.performanceInfo.advance(ne.SSAO),this._renderContext.output=O.Color,l.bindFramebuffer(),this._renderOpaqueGeometry(),this.performanceInfo.advance(ne.OPAQUE);const p=this._terrainRenderingEnabled&&(this._terrainTransparency===y.Semitransparent||this._terrainTransparency===y.TransparentWithDraped),m=this._highQualityTransparency&&p;this._renderTerrainLinearDepth(m),this._setMultipassEnabled(m),this._setTerrainCulling(m),this._renderEdges(te.OPAQUE),this.performanceInfo.advance(ne.OPAQUE_EDGES),this._offscreen.bindTarget(this._offscreen.currentColorTarget,this._offscreen.mainDepth),this._renderSlot(Q.VOXEL),this.performanceInfo.advance(ne.VOXEL),this._renderHiddenTransparentEdges();const u=this._needsTransparentPass||this._renderPlugins.needsTransparentPass;u&&(this._oitEnabled?this._renderOrderIndependentTransparency((()=>this._renderTransparentGeometry()),!1):this._renderTransparentGeometry()),this.performanceInfo.advance(ne.TRANSPARENT),this._renderGeometryLinearDepth(m);const f=this._renderHUDVisibility(m);m||this._renderInternalSlot(Q.LINE_CALLOUTS),this.performanceInfo.advance(ne.HUD_VISIBILITY),this._renderObjectAndLayerIdColor(r),this.performanceInfo.advance(ne.OBJECT_AND_LAYER_ID_COLOR),this._renderEdges(te.TRANSPARENT,m),this.performanceInfo.advance(ne.TRANSPARENT_EDGES),this._renderTransparentTerrain(),p&&f&&(m?this._renderLineCallouts(C.Occluded):l.compositeTransparentTerrainOntoHUDVisibility(this._bindParameters),this._renderHUD(C.Occluded,l.framebuffer),this.performanceInfo.advance(ne.HUD_OCCLUDED)),this.performanceInfo.advance(ne.TRANSPARENT_TERRAIN),this._setTerrainCulling(!1),p&&(l.compositeTransparentTerrainOntoMain(this._bindParameters),m&&(this._renderEdges(te.OPAQUE),this.performanceInfo.advance(ne.OPAQUE_EDGES),u&&(this._oitEnabled?this._renderOrderIndependentTransparency((()=>this._renderTransparentGeometry()),!1):this._renderTransparentGeometry()),this.performanceInfo.advance(ne.TRANSPARENT),this._renderEdges(te.TRANSPARENT),this.performanceInfo.advance(ne.TRANSPARENT_EDGES))),m&&this._renderLineCallouts(C.NotOccluded),this._setMultipassEnabled(!1),this._shadowAccumulator.render(this._bindParameters),l.renderToTargets((()=>{this._renderInternalSlot(Q.TRANSPARENT_DEPTH_WRITE_DISABLED_MATERIAL),this._renderSlot(Q.POSTPROCESSING_ENVIRONMENT_TRANSPARENT),this._renderSlot(Q.LASERLINES)}),l.currentColorTarget,l.mainDepth),this.performanceInfo.advance(ne.ENVIRONMENT),this._renderPlugins.needsLaserlineWithContrastControl&&l.renderTmpAndCompositeToMain((()=>this._renderSlot(Q.LASERLINES_CONTRAST_CONTROL)),this._bindParameters,ie.PremultipliedAlpha),this.performanceInfo.advance(ne.LASER_LINE),this._renderOccluded(),this.performanceInfo.advance(ne.OCCLUDED);const g=s===x.ON&&this._magnifierHelper.enabled,T=g&&o(e)?this._offscreen.getFramebuffer(this._offscreen.tmpColor,this._offscreen.tmpDepth):e;this._rctx.bindFramebuffer(T);const b=this._offscreen.colorTexture;!this._renderAntiAliasing(b)&&h(b)&&this._compositingHelper.composite(this._bindParameters,b,ie.None),this.performanceInfo.advance(ne.ANTIALIASING),this._renderHUD(C.NotOccluded,T),this.performanceInfo.advance(ne.HUD),this._renderHighlights(T,this._bindParameters),this.performanceInfo.advance(ne.HIGHLIGHTS),g&&this._magnifierHelper.render(this._rctx,this._bindParameters),T!==e&&(this._rctx.bindFramebuffer(e),this._compositingHelper.composite(this._bindParameters,this._offscreen.tmpColorTexture,ie.None)),this._disposeOITBuffers(),this._renderContext.lastFrameCamera.copyFrom(this._bindParameters.camera),this._sliceHelper.plane=_,this._isRendering=!1,this.onPostRender&&this.onPostRender(),this.performanceInfo.finishFrame()}_renderObjectAndLayerIdColor(e){if(h(e)&&has("enable-feature:objectAndLayerId-rendering")){const r=this._renderContext.output;this._rctx.bindFramebuffer(e),this._offscreen.renderToFBO((()=>this._renderGeometryAndTransparentTerrainPass(O.ObjectAndLayerIdColor)),[0,0,0,0],!0,!0),this._rctx.bindFramebuffer(e),this._offscreen.renderToFBO((()=>{this._bindParameters.renderTransparentlyOccludedHUD=C.NotOccluded,this._renderInternalSlot(Q.HUD_MATERIAL)}),void 0,!0,!0),this._renderContext.output=r}}finish(e){this._hasAnimations||this._animationTimestep.clear();const r=this.performanceInfo.gpuSamplingEnabled,t=e===I.BACKGROUND;if(t||r){const e=t?this.performanceInfo.elapsedTime:0,s=r?this.performanceInfo.totalGPUTimeSampler.last:this._rctx.gl.getError(),i=Math.max(e,s);this._animationTimestep.frame(i,t)}}readDepthPixels(e,r,t){const s=this._offscreen.bindTarget(this._offscreen.linearDepth,this._offscreen.tmpDepth);if(!this._needsLinearDepth){this._ensureBindParameters(e,e),this._bindParameters.camera.setGLViewport(this._rctx),this._rctx.setClearColor(0,0,0,0);const r=oe.COLOR_BUFFER_BIT|oe.DEPTH_BUFFER_BIT|oe.STENCIL_BUFFER_BIT;this._rctx.clearSafe(r),this._renderGeometryAndTransparentTerrainPass(O.Depth)}s.readPixels(r[0],r[1],r[2],r[3],de.RGBA,le.UNSIGNED_BYTE,t)}readHUDVisibility(e,r,t,s,i){this._offscreen.bindTarget(this._offscreen.hudVisibility).readPixels(e,r,t,s,de.RGBA,le.UNSIGNED_BYTE,i)}readAccumulatedShadow(e){return this._shadowAccumulator.readAccumulatedShadow(e[0],e[1])}_setMultipassEnabled(e){this._bindParameters.multipassTerrain.enabled=this._bindParameters.multipassGeometry.enabled=e}_setTerrainCulling(e){this._bindParameters.multipassTerrain.cullAboveGround=e}_renderSlot(e){this._bindParameters.slot=e,this._renderPlugins.render()}_renderEdges(e,r=!1){const t=this._edgeView;h(t)&&t.shouldRender()&&this._offscreen.renderTmpAndCompositeToMain((()=>t.render(this._bindParameters,e)),this._bindParameters,ie.Alpha,r)}_renderShadowMap(e,r,t,s){const i=this._shadowMap;i.enabled&&this.isFeatureEnabled(B.ShadowMapUpdate)&&(i.start(r,t,s),this._shadowHighlight.updateParameters(r,t),this._needsShadowHighlight?(this._renderShadowCascades(O.ShadowHighlight,this._shadowMap,(e=>i.takeCascadeSnapshotTo(e,J.Highlight))),i.clear(),this._renderShadowCascades(O.ShadowExcludeHighlight,this._shadowMap,(e=>{i.takeCascadeSnapshotTo(e,J.Default),this._renderGeometryAndTransparentTerrainPass(O.ShadowHighlight)}))):this._renderShadowCascades(O.Shadow),i.finish(e),r.setGLViewport(this._rctx))}_renderShadowCascades(e,r=this._shadowMap,t=(e=>{})){for(const s of r.cascades)s.camera.setGLViewport(this._rctx),this._prepare(s.camera,s.camera),this._renderGeometryAndTransparentTerrainPass(e),t(s)}get _needsLinearDepth(){return this._ssaoHelper.active||this._renderPlugins.needsLinearDepth||this.hasWaterReflection||this._needsShadowHighlight||this._needsShadowCast}_renderLinearDepth(){this._needsLinearDepth?this._offscreen.renderToTargets((()=>this._renderGeometryAndTransparentTerrainPass(O.Depth)),this._offscreen.linearDepth,this._offscreen.tmpDepth,[0,0,0,0],!0,!0):this._offscreen.disposeTarget(this._offscreen.linearDepth),this._bindParameters.linearDepthTexture=this._offscreen.linearDepthTexture}_renderTerrainLinearDepth(e){if(e){const e=this._renderContext.output;this._renderContext.output=O.Depth,this._offscreen.renderToTargets((()=>this._renderTransparentTerrain()),this._offscreen.terrainLinearDepth,this._offscreen.tmpDepth,[-1e10,-1e10,-1e10,1],!0,!0),this._renderContext.output=e}else this._offscreen.disposeTarget(this._offscreen.terrainLinearDepth);this._bindParameters.multipassTerrain.linearDepthTexture=this._offscreen.terrainLinearDepthTexture}_renderGeometryLinearDepth(e){if(e){const e=this._renderContext.output;this._offscreen.renderToTargets((()=>this._renderGeometryPass(O.Depth)),this._offscreen.geometryLinearDepth,this._offscreen.tmpDepth,[1,1,1,1],!0,!0),this._renderContext.output=e}else this._offscreen.disposeTarget(this._offscreen.geometryLinearDepth);this._bindParameters.multipassGeometry.linearDepthTexture=this._offscreen.geometryLinearDepthTexture}get _needsNormal(){return this._ssaoHelper.active}_renderNormal(){this._needsNormal?this._offscreen.renderToTargets((()=>{this._renderGeometryAndTransparentTerrainPass(O.Normal)}),this._offscreen.normal,this._offscreen.tmpDepth,[0,0,0,0],!0,!0):this._offscreen.disposeTarget(this._offscreen.normal)}get _needsDepthRange(){return this._shadowMap.enabled||this._needsShadowCast}_computeDepthRange(e){if(!this._needsDepthRange)return M;const r=N(e,this._materialRenderers,this._stage.layers);return L(r,this.renderPlugins.queryDepthRange(e)),r.near=Math.max(e.near,r.near),r.far=Math.min(e.far,r.far),r}_renderGeometryAndTransparentTerrainPass(e){this._renderContext.output=e,this._renderGeometryPass(e),this._renderTransparentTerrain()}_renderGeometryPass(e){this._renderContext.output=e,this._renderOpaqueGeometry(),this._renderTransparentGeometry()}_renderSSAO(e){this._ssaoHelper.render(this._bindParameters,e,this._offscreen.linearDepthTexture,this._offscreen.normalTexture)}_renderOpaqueGeometry(){this._renderSlot(Q.INTEGRATED_MESH),this._renderSlot(Q.OPAQUE_TERRAIN),this._renderInternalSlot(Q.OPAQUE_MATERIAL),this._renderSlot(Q.OPAQUE_MATERIAL),this._renderSlot(Q.POSTPROCESSING_ENVIRONMENT_OPAQUE)}_renderTransparentGeometry(){this._renderInternalSlot(Q.TRANSPARENT_MATERIAL),this._renderSlot(Q.TRANSPARENT_MATERIAL)}_renderTransparentTerrain(){this._renderSlot(Q.TRANSPARENT_TERRAIN)}_renderHUDVisibility(e){let r=!1;return this._renderContext.offscreenRenderingHelper&&this._renderContext.offscreenRenderingHelper.renderHUDVisibility((()=>{this._bindParameters.hudVisibilityTexture=this._renderContext.offscreenRenderingHelper.hudVisibilityTexture,r=this._renderInternalSlot(Q.OCCLUSION_PIXELS)}),e),r}_renderLineCallouts(e){this._bindParameters.renderTransparentlyOccludedHUD=e,e===C.Occluded?this._offscreen.renderToTargets((()=>this._renderInternalSlot(Q.LINE_CALLOUTS)),this._offscreen.currentColorTarget,this._offscreen.tmpDepth,void 0,!0,!0):this._renderInternalSlot(Q.LINE_CALLOUTS)}_renderHUD(e,r){this._hasHUDElements&&(this._oitEnabled?(this._renderOrderIndependentTransparency((()=>this._renderHUDElements(e)),!0),this._rctx.bindFramebuffer(r),this._compositingHelper.composite(this._bindParameters,this._offscreen.hudColorTexture,ie.PremultipliedAlpha)):e===C.Occluded?this._offscreen.renderToTargets((()=>this._renderHUDElements(C.Occluded)),this._offscreen.currentColorTarget,this._offscreen.tmpDepth,void 0,!0,!0):this._renderHUDElements(e))}_renderHUDElements(e){this._bindParameters.renderTransparentlyOccludedHUD=e,this._renderInternalSlot(Q.LINE_CALLOUTS_HUD_DEPTH),this._renderInternalSlot(Q.HUD_MATERIAL),this._renderInternalSlot(Q.LABEL_MATERIAL)}get _needsHighlight(){return this._hasHighlights||this._renderPlugins.needsHighlight}get _needsShadowHighlight(){return this._shadowMap.enabled&&this._shadowHighlight.isVisible&&this._needsHighlight}_renderHighlights(e,r){if(!this._needsHighlight)return void this._offscreen.disposeTarget(this._offscreen.highlight);const t=this._highlight,s=this._offscreen.renderToTargets((()=>{this._renderGeometryAndTransparentTerrainPass(O.Highlight),this._rctx.clearSafe(oe.DEPTH_BUFFER_BIT),this._renderHUDElements(C.Both)}),this._offscreen.highlight,this._offscreen.tmpDepth,[0,0,0,0],!0,!0);this._bindParameters.highlightColorTexture=s.colorTexture,this._needsShadowHighlight&&this._shadowHighlight.render(r,e),t.render(this._bindParameters,s,e)}get _needsShadowCast(){return this._shadowAccumulator.isAccumulating}_accumulateShadows(e,r,t){this._needsShadowCast&&h(this._offscreen.linearDepthTexture)&&this._shadowAccumulator.renderAccumulation(this._offscreen.linearDepthTexture,e,r,t)}_renderOrderIndependentTransparency(e,r){const t=t=>{this._bindParameters.transparencyPassType=t,this._offscreen.renderOITPass((()=>e()),t,r)},s=this._renderContext.output;this._renderContext.output=O.Alpha,t(ee.Alpha),this._renderContext.output=O.Color,t(ee.Color),t(ee.FrontFace),this._offscreen.compositeTransparentOntoOpaque(this._bindParameters,r),this._bindParameters.transparencyPassType=ee.NONE,this._renderContext.output=s,this._oitUsed=!0}_disposeOITBuffers(){this._oitUsed||(this._offscreen.disposeTarget(this._offscreen.alphaFloatTarget),this._offscreen.disposeTarget(this._offscreen.colorFloatTarget),this._offscreen.disposeTarget(this._offscreen.frontFaceTarget)),this._oitUsed=!1}_renderOccluded(){let e=0;pe.clear(),this._materialRenderers.forAll((r=>{r.material&&r.material.isVisible()&&r.material.renderOccluded===j.OccludeAndTransparentStencil&&(e|=r.material.renderOccluded,pe.push(r))}));const r=this._offscreen,t=(t,s,i,a,n)=>{0!=(e&s)&&(r.renderToTargets(i,r.tmpColor,r.mainDepth,[0,0,0,0],a,n),r.compositeOccludedOntoMain(this._bindParameters,t))};0!==pe.length&&(this._renderInternalSlot(Q.OCCLUDER_MATERIAL,pe),t(.5,j.OccludeAndTransparentStencil,(()=>this._renderInternalSlot(Q.TRANSPARENT_OCCLUDER_MATERIAL,pe)),!1,!1)),pe.clear(),this._materialRenderers.forAll((r=>{r.material&&r.material.isVisible()&&(r.material.renderOccluded===j.OccludeAndTransparent||r.material.renderOccluded===j.Transparent||r.material.renderOccluded===j.Opaque)&&(e|=r.material.renderOccluded,pe.push(r))}));const s=this._renderPlugins.renderOccludedFlags;if(e|=s,!e)return;const i=e=>{this._renderContext.renderOccludedMask=e,s>j.Occlude&&this._renderSlot(Q.OCCLUDED_TERRAIN),this._renderInternalSlot(Q.OPAQUE_MATERIAL,pe),this._renderInternalSlot(Q.TRANSPARENT_MATERIAL,pe),this._renderInternalSlot(Q.TRANSPARENT_DEPTH_WRITE_DISABLED_MATERIAL,pe),this._renderContext.resetRenderOccludedMask()};this._renderContext.output=O.Color,t(.5,j.OccludeAndTransparent,(()=>i(j.OccludeAndTransparent)),!0,H.OutlineVisualElementMask),t(.5,j.Transparent,(()=>i(j.Transparent)),!0,H.OutlineVisualElementMask),t(1,j.Opaque,(()=>i(j.Opaque)),!0,H.OutlineVisualElementMask),pe.clear()}_renderAntiAliasing(e){if(this._antialiasing){if(this._smaaPass.enable((()=>this._requestRender()))&&h(e))return this._smaaPass.render(e),!0}else this._smaaPass.disable();return!1}_prepare(e,r){this._needsTransparentPass=this._materialRenderers.some((e=>e.requiresSlot(Q.TRANSPARENT_MATERIAL,O.Color))),this._bindParameters.camera=e,this._bindParameters.contentCamera=r}_ensureBindParameters(e,r){this._bindParameters.camera=e,this._bindParameters.contentCamera=r;const t=this._renderContext.offscreenRenderingHelper;this._bindParameters.hudVisibilityTexture=t.hudVisibilityTexture,this._bindParameters.mainColorTexture=t.mainColorTexture,this._bindParameters.highlightDepthTexture=t.depthTexture??this._getFallbackDepthTexture()}_ensureBindParametersSSR(e){if(this._bindParameters.ssr.enabled=this.hasWaterReflection,this._bindParameters.ssr.enabled){o(this._waterReflectionEnableTime)&&(this._waterReflectionEnableTime=e),this._renderContext.lastFrameCamera.equals(this._bindParameters.camera)?this._reprojectionMatrix=E:(b(ue,this._bindParameters.camera.viewMatrix),b(me,this._bindParameters.camera.projectionMatrix),R(fe,ue,me),R(fe,this._renderContext.lastFrameCamera.viewMatrix,fe),R(fe,this._renderContext.lastFrameCamera.projectionMatrix,fe),this._reprojectionMatrix=fe),this._bindParameters.ssr.lastFrameColorTexture=this._offscreen.lastFrameColorTexture;const r=this._stage.view.qualitySettings.fadeDuration;this._bindParameters.ssr.fadeFactor=r>0?Math.min(r,e-this._waterReflectionEnableTime)/r:1,this._bindParameters.ssr.fadeFactor<1&&this._requestRender()}else this._bindParameters.ssr.lastFrameColorTexture=null,this._waterReflectionEnableTime=null}_renderInternalSlot(e,r=this._materialRenderers){let t=!1;return this._bindParameters.slot=e,r.forAll((e=>{e.material.shouldRender(this._renderContext)&&e.render(this._renderContext.output,this._bindParameters)&&(t=!0)})),t}_getFallbackDepthTexture(){return this._fallbackDepthStencilTexture||(this._fallbackDepthStencilTexture=U(this._rctx)),this._fallbackDepthStencilTexture}get gpuMemoryUsage(){return{offscreen:this._offscreen?.gpuMemoryUsage??0,highlights:(this._highlight?.gpuMemoryUsage??0)+(this._shadowHighlight?.gpuMemoryUsage??0),shadows:this._shadowMap?.gpuMemoryUsage??0,ssao:this._ssaoHelper?.gpuMemoryUsage??0}}get test(){const e=this;return{offscreen:this._offscreen,shadowMap:this._shadowMap,ssao:this._ssaoHelper,highlight:this._highlight,lighting:this._bindParameters.lighting,materialRenderers:this._materialRenderers,shadowAccumulator:this._shadowAccumulator,weatherIsFading:this._bindParameters.cloudsFade.isFading,resetRenderStateFeatures:()=>{e._renderStateFeatures=W()},getFramebufferTexture:r=>{switch(r){case ce.Color:return e._offscreen.colorTexture;case ce.LinearDepth:return e._offscreen.linearDepthTexture;case ce.Normals:return e._offscreen.normalTexture;case ce.ShadowMap:return e._shadowMap.depthTexture;case ce.HudVisibility:return e._offscreen.hudVisibilityTexture;case ce.Highlight:return e._offscreen.highlightTexture}}}}};var ce;e([f()],_e.prototype,"_shadowAccumulator",void 0),e([f()],_e.prototype,"_state",void 0),e([f()],_e.prototype,"_renderStateFeatures",void 0),e([f()],_e.prototype,"_antialiasingEnabled",void 0),e([f({readOnly:!0})],_e.prototype,"_antialiasing",null),e([f()],_e.prototype,"_ssaoEnabled",void 0),e([f()],_e.prototype,"_smaaPass",void 0),e([f({autoDestroy:!0})],_e.prototype,"_edgeView",void 0),e([f()],_e.prototype,"updating",null),e([f()],_e.prototype,"isCameraFinal",null),_e=e([g("esri.views.3d.webgl-engine.lib.Renderer")],_e),function(e){e[e.Color=0]="Color",e[e.LinearDepth=1]="LinearDepth",e[e.Normals=2]="Normals",e[e.ShadowMap=3]="ShadowMap",e[e.HudVisibility=4]="HudVisibility",e[e.Highlight=5]="Highlight"}(ce||(ce={}));const pe=new _,me=A(),ue=A(),fe=A();export{ce as FramebufferId,_e as Renderer};