@arcgis/core 6.0.0-next.35 → 6.0.0-next.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/{0202eb8c2b2865f99981.js → 00311d1b18d5952a014b.js} +1 -1
- package/assets/esri/core/workers/chunks/0b21d0e2e5a91c34a108.js +1 -0
- package/assets/esri/core/workers/chunks/{f717005e14a7e9141df7.js → 2050c844b5a29b1df28a.js} +1 -1
- package/assets/esri/core/workers/chunks/2c3612379111457c3221.js +1 -0
- package/assets/esri/core/workers/chunks/2f9072563194026e320e.js +1 -0
- package/assets/esri/core/workers/chunks/{d9a240a3c6bf85124474.js → 342a97974a78007b25e0.js} +1 -1
- package/assets/esri/core/workers/chunks/34467f7d84baffd772a3.js +1 -0
- package/assets/esri/core/workers/chunks/{4d18b48d4a282a0f341c.js → 427d929dc7f89b0a1ea9.js} +1 -1
- package/assets/esri/core/workers/chunks/432728c557be5dfa26b5.js +1 -0
- package/assets/esri/core/workers/chunks/46969f379623810b2eca.js +1 -0
- package/assets/esri/core/workers/chunks/592b5db1459c02cf6a0c.js +1 -0
- package/assets/esri/core/workers/chunks/6a21dc13a465757ba007.js +1 -0
- package/assets/esri/core/workers/chunks/{379db67f78161ebd5468.js → 7023651ed6398dcf8efb.js} +1 -1
- package/assets/esri/core/workers/chunks/{90360c0bd053d3e3fd77.js → 7027a0e7bfabb3bb7fc2.js} +1 -1
- package/assets/esri/core/workers/chunks/78818c2a898444f7e890.js +1 -0
- package/assets/esri/core/workers/chunks/{40c2674dae73f0942751.js → 7d497df6e13162156342.js} +1 -1
- package/assets/esri/core/workers/chunks/8a3dfe997712dc2ddead.js +1 -0
- package/assets/esri/core/workers/chunks/{81bcc495e6eaf2cf7474.js → 8f82a0a6747f673a2a7e.js} +1 -1
- package/assets/esri/core/workers/chunks/9826baa3c15ea2062669.js +1 -0
- package/assets/esri/core/workers/chunks/{d3369ffed19f4c264dcd.js → 9ab0735e86cf8932bf9d.js} +1 -1
- package/assets/esri/core/workers/chunks/ab0ea4042f4e13874aed.js +1 -0
- package/assets/esri/core/workers/chunks/ab98ade3257360015d6c.js +1 -0
- package/assets/esri/core/workers/chunks/{796c6195b6bf59dcc9bd.js → b25a05c58b0fd0f6ac60.js} +1 -1
- package/assets/esri/core/workers/chunks/b90271ce38522bcf813b.js +1 -0
- package/assets/esri/core/workers/chunks/ba91df9835cdea7698a9.js +1 -0
- package/assets/esri/core/workers/chunks/bfe13ac9fa1aafb190a1.js +1 -0
- package/assets/esri/core/workers/chunks/ce0274847ccce6a1ac53.js +1 -0
- package/assets/esri/core/workers/chunks/cf2e5f827cea7d7319ce.js +1 -0
- package/assets/esri/core/workers/chunks/dae2036faa28dade2119.js +1 -0
- package/assets/esri/core/workers/chunks/{e8fb2ba7b7a4f0916325.js → eed4b90494a54f8b337b.js} +1 -1
- package/assets/esri/core/workers/chunks/fc77eb7683e708774168.js +1 -0
- package/chunks/Clouds.glsl.js +7 -11
- package/chunks/RibbonLine.glsl.js +158 -84
- package/config.js +1 -1
- package/core/libs/gl-matrix-2/math/vec3.js +1 -1
- package/kernel.js +1 -1
- package/layers/BaseElevationLayer.js +1 -1
- package/layers/ElevationLayer.js +1 -1
- package/layers/IntegratedMesh3DTilesLayer.js +1 -1
- package/layers/IntegratedMeshLayer.d.ts +2 -0
- package/layers/IntegratedMeshLayer.js +1 -1
- package/layers/knowledgeGraph/KnowledgeGraphLayerDataManager.js +1 -1
- package/layers/support/ElevationQuery.js +1 -1
- package/layers/video/VideoController.js +3 -3
- package/layers/video/types.d.ts +12 -0
- package/package.json +3 -3
- package/support/timeUtils.js +1 -1
- package/views/2d/engine/Bitmap.js +1 -1
- package/views/2d/engine/flow/styles/Imagery.js +1 -1
- package/views/2d/engine/vectorTiles/SpriteMosaic.js +1 -1
- package/views/2d/engine/vectorTiles/VTLPainter3D.js +1 -1
- package/views/2d/engine/webgl/AttributeStoreView.js +1 -1
- package/views/2d/engine/webgl/GlyphMosaic.js +1 -1
- package/views/2d/engine/webgl/Overlay.js +1 -1
- package/views/2d/engine/webgl/OverlayMultipoint.js +1 -1
- package/views/2d/engine/webgl/SpriteMosaic.js +1 -1
- package/views/2d/engine/webgl/VideoScreenRenderer.js +1 -1
- package/views/2d/engine/webgl/animations/store/AnimationStore.js +1 -1
- package/views/2d/engine/webgl/collisions/LabelStore.js +1 -1
- package/views/2d/engine/webgl/effects/highlight/HighlightGradient.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/TextureStatisticsTechnique.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/blend/BlendTechnique.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/colorize/ColorizeTechnique.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/dotDensity/DotDensityResources.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/drop-shadow/DropShadowTechnique.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/heatmap/HeatmapResources.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/magnifier/MagnifierTechnique.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/opacity/OpacityTechnique.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/raster/RasterColorizerTechnique.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/raster/RasterHighlightTechnique.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/raster/processor/textureUtils.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/tile/TileDebugInfoTexture.js +1 -1
- package/views/2d/engine/webgl/textureUtils.js +1 -1
- package/views/2d/layers/LayerView2D.js +1 -1
- package/views/2d/webglDeps.js +1 -1
- package/views/3d/GroundView3D.js +1 -1
- package/views/3d/analysis/LineOfSight/LineOfSightController.js +1 -1
- package/views/3d/analysis/LineOfSight/placementUtils.js +1 -1
- package/views/3d/analysis/Viewshed/placementUtils.js +1 -1
- package/views/3d/input/SceneInputManager.js +1 -1
- package/views/3d/interactive/Manipulator3D.js +1 -1
- package/views/3d/interactive/editingTools/draw/DrawGraphicTool3D.js +1 -1
- package/views/3d/interactive/editingTools/originGeometryVisualElementUtils.js +1 -1
- package/views/3d/layers/GaussianSplatLayerView3D.js +1 -1
- package/views/3d/layers/I3SMeshView3D.js +1 -1
- package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
- package/views/3d/layers/graphics/ElevationAligners.js +1 -1
- package/views/3d/layers/graphics/Graphics3DLineSymbolLayer.js +1 -1
- package/views/3d/layers/i3s/I3SViewportQueries.js +1 -1
- package/views/3d/layers/i3s/LayerElevationProvider.js +1 -1
- package/views/3d/layers/support/Tiles3DBVH.js +1 -1
- package/views/3d/layers/support/Tiles3DMeshIntersectionHandler.js +1 -1
- package/views/3d/support/engineContent/line.js +1 -1
- package/views/3d/support/engineContent/marker.js +1 -1
- package/views/3d/support/flow/StreamlineResources3D.js +1 -1
- package/views/3d/support/flow/StreamlineResources3DOverlay.js +1 -1
- package/views/3d/support/flow/StreamlineResources3DShape.js +1 -1
- package/views/3d/support/flow/geometryUtils.js +1 -1
- package/views/3d/support/gaussianSplatting/GaussianSplatFadeHelper.js +1 -1
- package/views/3d/support/gaussianSplatting/GaussianSplatIntersectionHandler.js +1 -1
- package/views/3d/support/gaussianSplatting/GaussianSplatOrderTexture.js +1 -1
- package/views/3d/support/gaussianSplatting/GaussianSplatTextureAtlas.js +1 -1
- package/views/3d/support/gaussianSplatting/GaussianTile.js +1 -1
- package/views/3d/support/gaussianSplatting/GaussianTileBuilder.js +2 -0
- package/views/3d/support/gaussianSplatting/formatConstants.js +2 -0
- package/views/3d/support/pointsOfInterest/CameraOnSurface.js +1 -1
- package/views/3d/support/pointsOfInterest/StableSurfaceCenter.js +1 -1
- package/views/3d/support/pointsOfInterest/SurfaceGeometryUpdates.js +1 -1
- package/views/3d/terrain/OverlayRenderer.js +1 -1
- package/views/3d/terrain/TerrainRenderer.js +1 -1
- package/views/3d/terrain/TerrainSurface.js +1 -1
- package/views/3d/terrain/TileCompositor.js +1 -1
- package/views/3d/terrain/TileRenderer.js +1 -1
- package/views/3d/webgl/RenderNode.d.ts +1 -1
- package/views/3d/webgl-engine/collections/Component/ComponentObject.js +1 -1
- package/views/3d/webgl-engine/core/FBOCache.js +1 -1
- package/views/3d/webgl-engine/core/renderPasses/RenderPassManager.js +1 -1
- package/views/3d/webgl-engine/core/shaderLibrary/hud/HUD.glsl.js +1 -1
- package/views/3d/webgl-engine/core/shaderLibrary/util/GaussianSplatUnpacking.glsl.js +15 -11
- package/views/3d/webgl-engine/effects/atmosphere/LocalAtmosphere.js +1 -1
- package/views/3d/webgl-engine/effects/atmosphere/MarsAtmosphere.js +1 -1
- package/views/3d/webgl-engine/effects/clouds/CloudsRenderer.js +1 -1
- package/views/3d/webgl-engine/effects/highlight/Highlight.js +1 -1
- package/views/3d/webgl-engine/effects/magnifier/Magnifier.js +1 -1
- package/views/3d/webgl-engine/effects/smaa/SMAA.js +1 -1
- package/views/3d/webgl-engine/effects/ssao/SSAO.js +1 -1
- package/views/3d/webgl-engine/effects/stars/Stars.js +1 -1
- package/views/3d/webgl-engine/lib/AttributeView.js +1 -1
- package/views/3d/webgl-engine/lib/BasisUtil.js +1 -1
- package/views/3d/webgl-engine/lib/BindParameters.js +1 -1
- package/views/3d/webgl-engine/lib/DDSUtil.js +1 -1
- package/views/3d/webgl-engine/lib/DrapedHeatmapRenderer.js +1 -1
- package/views/3d/webgl-engine/lib/GPUPointOcclusionQuery.js +1 -1
- package/views/3d/webgl-engine/lib/GaussianSplatRenderUtils.js +1 -1
- package/views/3d/webgl-engine/lib/ManagedTexture.js +1 -1
- package/views/3d/webgl-engine/lib/Renderer.js +1 -1
- package/views/3d/webgl-engine/lib/TextTextureAtlas.js +1 -1
- package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBuffer.js +1 -1
- package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBufferView.js +1 -1
- package/views/3d/webgl-engine/lib/VerticesView.js +2 -0
- package/views/3d/webgl-engine/lib/attributeViewUtils.js +1 -1
- package/views/3d/webgl-engine/lib/edgeRendering/strokes.js +1 -1
- package/views/3d/webgl-engine/lib/glUtil3D.js +1 -1
- package/views/3d/webgl-engine/lib/lodRendering/LodRenderer.js +1 -1
- package/views/3d/webgl-engine/materials/LineMarkerMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/internal/WaterTextureRepository.js +1 -1
- package/views/3d/webgl-engine/materials/internal/lineMarkerBufferUtils.js +2 -0
- package/views/3d/webgl-engine/materials/internal/ribbonLineBufferUtils.js +2 -0
- package/views/3d/webgl-engine/materials/renderers/VaoRenderer.js +1 -1
- package/views/3d/webgl-engine/materials/stippleTextureRepository.js +1 -1
- package/views/draw/DrawTool.js +1 -1
- package/views/draw/support/ManagedTooltipField.js +1 -1
- package/views/support/TextureCompressionHelper.js +1 -1
- package/views/support/imageReprojection.js +1 -1
- package/views/webgl/FramebufferObject.js +1 -1
- package/views/webgl/RenderingContext.js +1 -1
- package/views/webgl/Texture.js +1 -1
- package/views/webgl/rasterUtils.js +1 -1
- package/views/webgl/testSVGPremultipliedAlpha.js +1 -1
- package/views/webgl/textureUtils.js +1 -1
- package/widgets/OrientedImageryViewer/navigation/NavigationManager.js +1 -1
- package/widgets/OrientedImageryViewer/navigation/queries.js +1 -1
- package/widgets/OrientedImageryViewer/navigation/utils.js +1 -1
- package/widgets/OrientedImageryViewer.js +2 -2
- package/widgets/ScaleRangeSlider/types.d.ts +3 -3
- package/assets/esri/core/workers/chunks/039d9bc5b5015012f811.js +0 -1
- package/assets/esri/core/workers/chunks/08140725277de5d2e41a.js +0 -1
- package/assets/esri/core/workers/chunks/16cda273927ab0a39544.js +0 -1
- package/assets/esri/core/workers/chunks/29c610ce1c81ebb84a6b.js +0 -1
- package/assets/esri/core/workers/chunks/3223f9fbc76ba9ef8d13.js +0 -1
- package/assets/esri/core/workers/chunks/3fdcc383bbd9cf0d274c.js +0 -1
- package/assets/esri/core/workers/chunks/46c290108a90518ef695.js +0 -1
- package/assets/esri/core/workers/chunks/48b8b57f559a53c6c513.js +0 -1
- package/assets/esri/core/workers/chunks/4a979fce1c971b614a18.js +0 -1
- package/assets/esri/core/workers/chunks/5bd1414220e42cb8ebcf.js +0 -1
- package/assets/esri/core/workers/chunks/5d781c2c6204cffffd0d.js +0 -1
- package/assets/esri/core/workers/chunks/723df53cfa0189837d01.js +0 -1
- package/assets/esri/core/workers/chunks/7400b8c454b47ee4fb3c.js +0 -1
- package/assets/esri/core/workers/chunks/7af4edc6e87d27b9d467.js +0 -1
- package/assets/esri/core/workers/chunks/990e96139b5a1dccb061.js +0 -1
- package/assets/esri/core/workers/chunks/a607541959169741a943.js +0 -1
- package/assets/esri/core/workers/chunks/aa779896fd9e5c341349.js +0 -1
- package/assets/esri/core/workers/chunks/c131e0dd180a4c10e12e.js +0 -1
- package/assets/esri/core/workers/chunks/f3b4159c0722df8ffe13.js +0 -1
- package/assets/esri/core/workers/chunks/f75eec2cbc541eec9712.js +0 -1
- package/views/3d/webgl-engine/lib/GaussianSplatPrepassDepthRenderer.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import{getAssetUrl as t}from"../../../../../assets.js";import n from"../../../../../core/Accessor.js";import{createTask as r}from"../../../../../core/asyncUtils.js";import i from"../../../../../core/Logger.js";import{abortMaybe as a,disposeMaybe as o}from"../../../../../core/maybe.js";import{throwIfAborted as s}from"../../../../../core/promiseUtils.js";import{property as c,subclass as l}from"../../../../../core/accessorSupport/decorators.js";import{requestImage as u}from"../../../../../request/image.js";import{NoParameters as d}from"../../../../webgl/NoParameters.js";import f
|
|
2
|
+
import{__decorate as e}from"tslib";import{getAssetUrl as t}from"../../../../../assets.js";import n from"../../../../../core/Accessor.js";import{createTask as r}from"../../../../../core/asyncUtils.js";import i from"../../../../../core/Logger.js";import{abortMaybe as a,disposeMaybe as o}from"../../../../../core/maybe.js";import{throwIfAborted as s}from"../../../../../core/promiseUtils.js";import{property as c,subclass as l}from"../../../../../core/accessorSupport/decorators.js";import{requestImage as u}from"../../../../../request/image.js";import{NoParameters as d}from"../../../../webgl/NoParameters.js";import{Texture as f}from"../../../../webgl/Texture.js";import{TextureDescriptor as p}from"../../../../webgl/TextureDescriptor.js";let m=class extends n{constructor(){super(...arguments),this._passParameters=new h,this._resourcesTask=null}get passParameters(){return this._passParameters}destroy(){this._resourcesTask=a(this._resourcesTask),this._passParameters.waveNormal=o(this._passParameters.waveNormal),this._passParameters.wavePerturbation=o(this._passParameters.wavePerturbation)}get updating(){return!!this._resourcesTask&&!this._resourcesTask.finished}ensureResources(e){return this._resourcesTask||=r(async n=>{await Promise.allSettled([this._loadImageResource(e,t(`esri/images/materials/water/normals.jpg`),e=>this._passParameters.waveNormal=e,n),this._loadImageResource(e,t(`esri/images/materials/water/perturbation.jpg`),e=>this._passParameters.wavePerturbation=e,n)])}),this._resourcesTask.finished?2:1}async _loadImageResource(e,t,n,r){try{let i=await u(t,{signal:r});s(r);let a=new p(i.width,i.height);a.pixelFormat=6407,a.samplingMode=9987,a.hasMipmap=!0,a.maxAnisotropy=8,n(new f(e,a,i))}catch(e){i.getLogger(this).error(`Failed to load water material normal texture.`,e)}}};e([c()],m.prototype,`_resourcesTask`,void 0),e([c({type:Boolean,readOnly:!0})],m.prototype,`updating`,null),m=e([l(`esri.views.3d.webgl-engine.materials.internal.WaterTextureRepository`)],m);class h extends d{}export{h as WaterTexturePassParameters,m as WaterTextureRepository};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
+
import{fromTranslation as e}from"../../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as t}from"../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{negate as n,equals as r,transformMat4 as i}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as a,UNIT_X as o}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{ONES as s}from"../../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{BufferViewVec4f16 as c,BufferViewVec3f as l,BufferViewVec2f16 as u,BufferViewVec4u8 as d,BufferViewFloat as f,BufferViewFloat16 as p,BufferViewVec3f16 as m}from"../../../../../geometry/support/buffer/BufferView.js";import{BufferGeometry as h}from"../../lib/BufferGeometry.js";import{Buffers as g}from"../../lib/Buffers.js";import{createVerticesView as _}from"../../lib/VerticesView.js";import{writeDeltaF16Vector as v}from"./bufferWriterUtils.js";import{getLayout as y}from"../../shaders/LineMarkerTechnique.js";function b(t,r,i){let{attributeData:a}=r,o=y(t.parameters).createBuffer(t.parameters.placement===`begin-end`?12:6);return n(k,i.vec3),e(A,k),x({position:_({data:a.position,size:3,stride:3},3),color:a.color??void 0,size:a.size??void 0,normal:a.normal??void 0,colorFeature:C(a.colorFeature),sizeFeature:C(a.sizeFeature),opacityFeature:C(a.opacityFeature)},t.parameters,{buffer:o,offset:0},A),new h(t,new g(o),i,r.mapPositions)}function x(e,t,n,r){S(e.position,t,{position:n.buffer.getField(`position`,l),previousDelta:n.buffer.getField(`previousDelta`,c),offset:n.offset},r);let{buffer:i,offset:a}=n,o=i.getField(`uv0`,u),s=i.getField(`color`,d),h=i.getField(`colorFeatureAttribute`,f),g=i.getField(`size`,p),_=i.getField(`sizeFeatureAttribute`,f),v=i.getField(`opacityFeatureAttribute`,f),y=i.getField(`normal`,m),b=t.placement===`begin-end`?12:6;for(let n=0;n<b;n++){let r=a+n,i=t.placement===`begin`||t.placement===`begin-end`&&n<6?0:e.position.count-1;if(o.setValues(r,w[n%6][0],w[n%6][1]),s!=null){let t=e.color??T,n=Math.min(i*4,t.length-4);s.setValues(r,t[n]*255,t[n+1]*255,t[n+2]*255,t[n+3]*255)}if(h?.set(r,e.colorFeature??0),v?.set(r,e.opacityFeature??0),g?.set(r,e.size??1),_?.set(r,e.sizeFeature??0),t.worldSpace){let t=e.normal??E;y.setValues(r,t[0],t[1],t[2])}}}function S(e,t,n,a=null){let{position:o,previousDelta:s}=n,c=n.offset,l=(t,n)=>{e.getVec(t,D);let l=t+n;do e.getVec(l,O),l+=n;while(r(D,O)&&l>=0&&l<e.count);a!=null&&(i(D,D,a),i(O,O,a));for(let e=0;e<6;e++,c++)o.setVec(c,D),v(O,D,s.typedBuffer,c*s.typedBufferStride)};(t.placement===`begin`||t.placement===`begin-end`)&&l(0,1),(t.placement===`end`||t.placement===`begin-end`)&&l(e.count-1,-1)}function C(e){return typeof e==`number`?e:e?.[0]}const w=[[-1,-1],[1,-1],[1,1],[-1,-1],[1,1],[-1,1]],T=s,E=o,D=a(),O=a(),k=a(),A=t();export{b as createLineMarkerBufferGeometry,x as writeLineMarkerBuffer,S as writeLineMarkerPositions};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
+
import{transformMat4 as e,distance as t,copy as n}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as r}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{BufferViewVec3f as i,BufferViewFloat as a,BufferViewVec4Unorm8 as o,BufferViewVec4u8 as s,BufferViewVec4f16 as c,BufferViewUint32 as l}from"../../../../../geometry/support/buffer/BufferView.js";import{olidEnabled as u}from"../../effects/geometry/olidUtils.js";import{encodeRibbonLineVertexInfo as d}from"../../lib/RibbonLineVertexInfo.js";import{assert as f}from"../../lib/Util.js";import{createVerticesView as p}from"../../lib/VerticesView.js";import{n as m}from"../../../../../chunks/RibbonLine.glsl.js";function h(e,t){return(e===`round`?m:0)+ +!!t}function g(e,t,n){let r=t?e:e-2,i=h(n.join,n.stipplePattern!=null),a=(t?2:4)+r*(i*2+4)+2;return n.wireframe?2+(a-2)*4:a}function _(e,t,n,r,i){let{buffer:a,offset:o}=r,s=a.getField(`ribbonLineVertexInfo`,l).typedBuffer,c=h(n.join,n.stipplePattern!=null),u=o+1,f=(e,t,n)=>{s[u++]=d(i+n+1,t,e)};t||(f(1,7,0),f(1,5,0));let p=t?e:e-1;for(let e=+!t;e<p;e++){f(0,2,e),f(0,0,e);for(let t=0;t<c;t++){let n=(t+1)/(c+1);f(n,2,e),f(n,0,e)}f(1,6,e),f(1,4,e)}f(0,t?2:3,p),f(0,+!t,p),s[o]=s[o+1],s[u]=s[u-1],u++,n.wireframe&&v(s,o,u)}function v(e,t,n){let r=n;for(let i=t;i<=n-4;i+=2)e[r++]=e[i],e[r++]=e[i+2],e[r++]=e[i+1],e[r++]=e[i+2],e[r++]=e[i+1],e[r++]=e[i+3]}function y(r,l,d,p){let m=r.position,{buffer:h,offset:g}=d,_=h.getField(`position`,i);f(_!=null,`Expected valid position field in texture buffer`);let v=h.getField(`u0`,a),y=r.distancesToStart,x=h.getField(`color`,o),S=h.getField(`size`,a),C=h.getField(`colorFeatureAttribute`,a),O=h.getField(`sizeFeatureAttribute`,a),k=h.getField(`opacityFeatureAttribute`,a),A=u()?h.getField(`olidColor`,o):null,j=A==null?null:new s(A.buffer,A.start,A.stride),M=h.getField(`timeStamps`,c),N=0;for(let i=0;i<m.count;i++){m.getVec(i,E),p!=null&&e(E,E,p),v!=null&&i>0&&(y==null?N+=t(D,E):N=y[i]??N);let a=g+i+1;if(_.setVec(a,E),v!=null&&(v.set(a,N),n(D,E)),S?.set(a,w(r.size,i,1)),x!=null){let e=r.color??T,t=Math.min(i*4,e.length-4);x.setValues(a,e[t],e[t+1],e[t+2],e[t+3])}if(C?.set(a,w(r.colorFeature,i)),k?.set(a,w(r.opacityFeature,i)),O?.set(a,w(r.sizeFeature,i)),M!=null&&r.timeStamps!=null&&M.setValues(a,r.timeStamps[i*4],r.timeStamps[i*4+1],r.timeStamps[i*4+2],r.timeStamps[i*4+3]),j!=null&&r.olidColor!=null){let e=Math.min(i*4,r.olidColor.length-4);j.setValues(a,r.olidColor[e],r.olidColor[e+1],r.olidColor[e+2],r.olidColor[e+3])}}b(h,m.count,l,g),l&&v!=null&&(m.getVec(0,E),p!=null&&e(E,E,p),v.set(g+m.count+1,y?.[m.count]??N+t(D,E)))}function b(e,t,n,r=0){let i=r+1,a=r+t;n?(e.copyItem(a,r),e.copyItem(i,a+1),e.copyItem(i+1,a+2)):(e.copyItem(i,r),e.copyItem(a,a+1))}function x(e,t){let n=e.count-(t&&e.count>4?3:2);return e.slice(1,n)}function S(e,t){if(e.type===1)return x(e.buffers.storage.getField(`position`,i),t);let n=e.attributes.get(`position`);return p(n,3)}function C(e,r){let o=e.buffers.storage,s=o.getField(`u0`,a);if(s==null)return;let c=x(o.getField(`position`,i),r),l=0;for(let e=0;e<c.count;e++)c.getVec(e,E),e>0&&(l+=t(D,E)),s.set(e+1,l),n(D,E);r&&c.count>2?(c.getVec(0,E),s.set(0,l),s.set(c.count+1,l+t(D,E)),s.set(c.count+2,s.get(2))):(s.set(0,0),s.set(c.count+1,l))}function w(e,t,n=0){return typeof e==`number`?e:e?.[e.length===1?0:t]??n}const T=[1,1,1,1],E=r(),D=r();export{b as fillRibbonLinePadding,h as getNumJoinSubdivisions,x as getRibbonLineBufferPositions,S as getRibbonLinePositions,g as ribbonLineVertexCount,C as updateRibbonLineDistances,y as writeRibbonLineTextureBuffer,_ as writeRibbonLineVertices};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import t from"../../../../../core/Accessor.js";import"../../../../../core/has.js";import{disposeMaybe as n}from"../../../../../core/maybe.js";import{property as r,subclass as i}from"../../../../../core/accessorSupport/decorators.js";import{GLMaterialLoader as a}from"../../lib/GLMaterialLoader.js";import{assert as o}from"../../lib/Util.js";import{DrawParameters as s}from"../DrawParameters.js";import{getStrideForDataType as c}from"./IndexLayout.js";import{defaultHighlightName as l}from"../../../../support/HighlightDefaults.js";let u=class extends t{constructor(e){super(e),this._glMaterialLoader=null,this._drawParameters=new s,this._highlightNames=new Set,this._produces=new Map}initialize(){this.
|
|
2
|
+
import{__decorate as e}from"tslib";import t from"../../../../../core/Accessor.js";import"../../../../../core/has.js";import{disposeMaybe as n}from"../../../../../core/maybe.js";import{property as r,subclass as i}from"../../../../../core/accessorSupport/decorators.js";import{GLMaterialLoader as a}from"../../lib/GLMaterialLoader.js";import{assert as o}from"../../lib/Util.js";import{DrawParameters as s}from"../DrawParameters.js";import{getStrideForDataType as c}from"./IndexLayout.js";import{defaultHighlightName as l}from"../../../../support/HighlightDefaults.js";let u=class extends t{constructor(e){super(e),this._glMaterialLoader=null,this._drawParameters=new s,this._highlightNames=new Set,this._produces=new Map}initialize(){this.material.produces.forEach((e,t)=>{this._produces.set(t,t=>this.dataByBaseInstance.size===0||(t===10||t===6)&&!this._hasHighlights?!1:e(t))})}destroy(){this.uninitializeRenderContext()}get _hasHighlights(){return this._highlightNames.size>0}hasHighlight(e){return this._highlightNames.has(e)}get produces(){return this._produces}initializeRenderContext(e){this._glMaterialLoader=new a(this.material,e.materials)}uninitializeRenderContext(){this._glMaterialLoader=n(this._glMaterialLoader)}acquireTechniques(e){if(!this.material.shouldRender(e))return null;let{output:t,bind:n}=e;if(!this.material.produces.get(n.slot)?.(t))return null;let{highlight:r,slot:i}=n,a=t===6,o=t===10,s=o||a,c=r?.name;if(s&&(this._highlightNames.size===0||o&&c&&!this._highlightNames.has(c)))return null;let u=e=>o&&!!c&&!e.has(c),d=t===7,f=!(s||d);for(let r of this.dataByBaseInstance.values())for(let o of r.dataByOrigin.values())for(let r of o.buffers){if(u(r.highlightNames))continue;let o=a?r.drawCommandsHighlights.get(l):s?c?r.drawCommandsHighlights.get(c):r.drawCommandsHighlights.size>0:((d&&r.needsMultipleCommands?r.drawCommandsShadowHighlightRest:r.drawCommandsDefault)||null)?.length??!1,p=f&&r.drawCommandsOccludees||null;if(o||p?.length){let r=this._glMaterialLoader.load(e.rctx,i,t)?.beginSlot(n);if(r)return r}}return null}render(e,t){let{output:n,bind:r}=e,{highlight:i}=r,a=n===10,s=i?.name??``;if(a&&!i)return;let c=n===6,u=a||c,g=n===7,_=!(u||g),{rctx:v}=e,x=v.bindTechnique(t,r,this.material.parameters),S=this.material.useIndexing;for(let e of this.dataByBaseInstance.values()){let{baseInstanceData:n}=e,i=n!=null;o(!(i&&S),`Instanced indexed rendering is not supported`);let C=i?h:S?m:p,w=i?f:d;for(let i of e.dataByOrigin.values()){this._drawParameters.origin=i.origin;for(let e of i.buffers){if(a&&(!e.hasHighlights||!e.drawCommandsHighlights.has(s))||c&&(!e.hasHighlights||!e.drawCommandsHighlights.has(l)))continue;this._drawParameters.textureBuffer=e.textureBuffer?.texture;let i=w(e),o=y(i,e.needsMultipleCommands,s,c,u,g),d=b(i,_);(o?.length||d?.length)&&(x.bindDraw(r,this.material.parameters,this._drawParameters),C(v,e,n,t,o,d,r,this.material.parameters)),this._drawParameters.textureBuffer=null}}}}updateHighlights(){let{_highlightNames:e}=this;e.clear();for(let t of this.dataByBaseInstance.values())for(let n of t.dataByOrigin.values())for(let t of n.buffers)for(let n of t.highlightNames)e.add(n)}get test(){}};e([r({constructOnly:!0})],u.prototype,`material`,void 0),e([r({constructOnly:!0})],u.prototype,`dataByBaseInstance`,void 0),u=e([i(`esri.views.3d.webgl-engine.materials.renderers.VaoRenderer`)],u);const d=e=>e,f=e=>e.instancedCommandVAOs,p=(e,{vao:t},n,r,i,a,o,s)=>{r.ensureAttributeLocations(t),e.bindVAO(t),g(e,r,i,o,s,!1),g(e,r,a,o,s,!0)},m=(e,{vao:t},n,r,i,a,s,c)=>{r.ensureAttributeLocations(t),e.bindVAO(t);let l=t.indexBuffer?.indexType;o(l!=null,`Missing index array`),_(e,r,i,s,c,!1,l),_(e,r,a,s,c,!0,l)},h=(e,t,{baseCommand:n},r,i,a,o,s)=>{v(e,r,n,i,o,s,!1),v(e,r,n,a,o,s,!0)};function g(e,t,n,r,i,a){if(n?.length){e.setPipelineState(t.getPipeline(r,i,a));for(let r of n)e.drawArrays(t.primitiveType,r.first,r.count)}}function _(e,t,n,r,i,a,o){if(!n?.length)return;let s=c(o);e.setPipelineState(t.getPipeline(r,i,a));for(let r of n)e.drawElements(t.primitiveType,r.count,o,r.first*s)}function v(e,t,{first:n,count:r},i,a,o,s){if(i?.length){e.setPipelineState(t.getPipeline(a,o,s));for(let{vao:a,instanceCount:o}of i)t.ensureAttributeLocations(a),e.bindVAO(a),e.drawArraysInstanced(t.primitiveType,n,r,o)}}function y(e,t,n,r,i,a){let o=i&&!r?e.drawCommandsHighlights.get(n)??null:null;return r?e.drawCommandsHighlights.get(l):i?o:a&&t?e.drawCommandsShadowHighlightRest:e.drawCommandsDefault}function b(e,t){return t&&e.drawCommandsOccludees||null}export{u as VaoRenderer};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{isImagePattern as e}from"./lineStippleUtils.js";import{ProceduralTextureRepository as t}from"./ProceduralTextureRepository.js";import{PixelType as n,SizedPixelFormat as r}from"../../../webgl/enums.js";import i
|
|
2
|
+
import{isImagePattern as e}from"./lineStippleUtils.js";import{ProceduralTextureRepository as t}from"./ProceduralTextureRepository.js";import{PixelType as n,SizedPixelFormat as r}from"../../../webgl/enums.js";import{Texture as i}from"../../../webgl/Texture.js";import{TextureDescriptor as a}from"../../../webgl/TextureDescriptor.js";function o(o,c){return new t(t=>{if(e(t))return u(o,t.image);let{data:c,textureSize:l}=s(t),d=new a(l,1);return d.dataType=n.FLOAT,d.pixelFormat=6403,d.internalFormat=r.R16F,d.wrapMode=10497,new i(o,d,c)},t=>e(t)?`image-${t.uuid}`:`${t.pattern.join(`,`)}-r${t.pixelRatio}`,c)}function s(e){let t=c(e),n=1/e.pixelRatio,r=l(e),i=[],a=0,o=0,s=0,u=1;for(let e of t)e>0&&(o!==u&&(i.push(s),a||=u),o=u,s+=e),u=-u;i.length>1&&a===o&&(i[0]=i.pop());let d=Math.round(t[0]/2),f=new Float32Array(r);if(i.length===1)f.fill(a*65504);else if(i.length>1){let e=0,t=a,o=i[0]===0?0:i[0]-r,s=i[1];for(let a=0;a<r;a++){let c=a+d+.5;if(c>=s){e=(e+1)%i.length,t=-t,o=s;let n=i[(e+1)%i.length];s+=(n-i[e]+r)%r}f[a]=t*Math.min(c-o,s-c)*n}}return{data:f,textureSize:r}}function c(e){return e.pattern.map(t=>Math.round(t*e.pixelRatio))}function l(e){if(e==null)return 1;let t=c(e);return Math.floor(t.reduce((e,t)=>e+t,0))}function u(e,t){let{data:o,width:s,height:c}=t,l=new a(s,c);return l.dataType=n.UNSIGNED_BYTE,l.pixelFormat=6408,l.internalFormat=r.RGBA8,l.wrapMode={s:10497,t:33071},l.hasMipmap=!0,l.samplingMode=9987,new i(e,l,o)}export{l as computeTextureSize,o as createStippleTextureRepository,u as imageToTexture,s as patternToTextureData};
|
package/views/draw/DrawTool.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{__addDisposableResource as e,__disposeResources as t,__decorate as n}from"tslib";import{createTask as r}from"../../core/asyncUtils.js";import{makeHandle as i,disposable as a}from"../../core/handleUtils.js";import o from"../../core/Logger.js";import{getOrCreateMapValue as s}from"../../core/MapUtils.js";import{destroyMaybe as c,abortMaybe as l}from"../../core/maybe.js";import{ignoreAbortErrors as u}from"../../core/promiseUtils.js";import{when as d,initial as f,watch as p,syncAndInitial as ee,on as m,sync as h}from"../../core/reactiveUtils.js";import{screenPointEqual as g,createScreenPoint as _}from"../../core/screenUtils.js";import{diff as v}from"../../core/accessorSupport/diffUtils.js";import{property as y}from"../../core/accessorSupport/decorators/property.js";import{subclass as b}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as x}from"../../core/support/UpdatingHandles.js";import te from"../../geometry/Polygon.js";import{simplifyIsSimple as S,simplifyExecute as C}from"../../geometry/operators/simplifyOperator.js";import{isPolygon as w}from"../../geometry/support/typeUtils.js";import{isCurvedGeometry as T}from"../../geometry/support/curves/curveUtils.js";import{densifyCurvedGeometry as E}from"../../geometry/support/curves/densifyCurvedGeometry.js";import{getEffectiveElevationInfo as D}from"../../support/elevationInfoUtils.js";import{getMaxDeviationInPixels as O,getMinSegmentsPerCurve as k}from"../2d/layers/graphics/densificationConstants.js";import{createSnappingVisualizer as A}from"./support/createSnappingVisualizer.js";import{multipointFromGeometry as j,markHandled as M,getPointerType as N,getPointerId as P}from"./support/drawToolUtils.js";import{PluginContext as F}from"./support/PluginContext.js";import{viewEventToCommand as I}from"./support/input/drawToolInput.js";import{EditSessionManager as L}from"./support/managers/EditSessionManager.js";import{GlobalStateManager as R}from"./support/managers/GlobalStateManager.js";import{InteractiveHandleManager as z}from"./support/managers/InteractiveHandleManager.js";import{MeasurementManager as B}from"./support/managers/MeasurementManager.js";import{PluginLifecycleManager as V}from"./support/managers/PluginLifecycleManager.js";import{SurfaceManager as H}from"./support/managers/SurfaceManager.js";import{TooltipManager as U}from"./support/managers/TooltipManager.js";import{ViewEventPriorities as W}from"../input/InputManager.js";import{createCoordinateHelper as G}from"../interactive/coordinateHelper.js";import{InteractiveToolBase as K}from"../interactive/InteractiveToolBase.js";import{KeyBindings as q,mediaKeys as J,sketchKeys as Y,advancedSketchKeys as X,tooltipKeys as Z}from"../interactive/keybindings.js";import{isInputModeAvailable as ne}from"../interactive/tooltip/tooltipCommonUtils.js";const Q=Symbol();let $=class extends K{constructor(e){super(e),this._shapeVisualId=Symbol(),this._vertexVisualId=Symbol(),this._pluginContexts=new Map,this._queuedFeedbackEvents=[],this._flushingQueuedFeedbackEvents=!1,this._commandsSuspended=!1,this._snappingVisualizer=null,this._segmentLabels=null,this._segmentLabelsImportTask=null,this._updatingHandles=new x,this._keybindings=this._makeKeyBindings(),this._pendingBeginRequest=null,this.type=`draw-2.0`,this.automaticManipulatorSelection=!0,this.snappingManager=null,this.toolOptions=null,this.elevationInfo=null,this.hasZ=!1,this.defaultZ=0,this.lastScreenPosition=null,this.measurementManager=new B,this.globalStateManager=new R({getPluginStack:()=>this.pluginStack}),this.editSessionManager=new L({getContext:()=>this._editSessionManagerContext}),this.lifecycleManager=new V({getContext:this._getContextForPlugin.bind(this),editSessionManager:this.editSessionManager,afterAttach:this._afterAttach.bind(this),afterDetach:this._afterDetach.bind(this),beforeResume:this._beforeResume.bind(this)}),this.surfaceManager=null,this.interactiveHandleManager=null,this.renderer=null,this.readPluginSetting=null,this.enableVertexVisuals=!0}initialize(){let{view:e}=this;this.interactiveHandleManager=new z({view:e,renderer:this.renderer}),this._override(`manipulators`,this.interactiveHandleManager.manipulators),this.tooltipManager=new U({getDependencies:()=>this._tooltipDependencies,getLastScreenPosition:()=>this.lastScreenPosition}),this.addHandles(d(()=>this.renderer,t=>{t.addOrUpdateVisual(this._shapeVisualId,{role:`outputGeometry`}),t.addOrUpdateVisual(this._vertexVisualId,{role:`vertex`}),this._updatingHandles.addPromise(A(e,t).then(e=>this._snappingVisualizer=e))},f)),this.addHandles([p(()=>[this.view,this.coordinateHelper.spatialReference,this.defaultZ,this.hasZ,this.elevationInfo],([e,t,n,r,i])=>{this.surfaceManager?.destroy(),this.surfaceManager=new H({spatialReference:t,excludedGraphicsLayer:null,defaultZ:n,hasZ:r,view:e,elevationInfo:i,getContext:()=>({drawAtFixedElevation:this.globalStateManager.drawAtFixedElevation,elevationConstraint:this.tooltipManager?.elevationConstraint,constraintsEnabled:this.tooltipManager?.constraintsEnabled??!1})})},ee),d(()=>this.toolOptions?.tooltips.effectiveEnabled,()=>this.measurementManager.preloadMeasurementUtils(),{once:!0,initial:!0}),p(()=>[this.editGeometryOperations,this.toolOptions?.labels.enabled,this.globalStateManager.segmentLabelsDisabled],()=>{this._updatingHandles.addPromise(this._setupSegmentLabels())},f),m(()=>this.editSessionManager,`cancelPlugin`,({plugin:e})=>{this._suspendPlugin(e)},h),m(()=>this.editSessionManager,`restartPlugin`,({restartInfo:e})=>{this._resumePlugin(e)},h),p(()=>this.lifecycleManager.updating,e=>{e||this._emitQueuedFeedbackEvents()},h),m(()=>this.editGeometryOperations,[`vertex-add`,`vertex-update`,`vertex-remove`],e=>{let t=e.vertices.map(e=>({componentIndex:0,vertexIndex:e.index,coordinates:this.coordinateHelper.vectorToArray(e.pos)})),n=t.map(e=>e.coordinates);switch(e.type){case`vertex-add`:this._emitWhenReady(e.type,{...e,added:n,vertices:t});break;case`vertex-update`:this._emitWhenReady(e.type,{...e,updated:n,vertices:t});break;case`vertex-remove`:this._emitWhenReady(e.type,{...e,removed:n,vertices:t})}})])}destroy(){this.active&&this.onDeactivate(),this.editSessionManager.destroy(),this.lifecycleManager.destroy(),this.measurementManager.destroy(),this.globalStateManager.destroy();for(let e of this._pluginContexts.values())e.destroy();this._pluginContexts.clear(),this.surfaceManager=c(this.surfaceManager),this.interactiveHandleManager=c(this.interactiveHandleManager),this._segmentLabelsImportTask=l(this._segmentLabelsImportTask),this._segmentLabels=c(this._segmentLabels),this.tooltipManager=c(this.tooltipManager)}get _zOfLastUserInput(){let e=(this.mostDownstreamPlugin&&this.editSessionManager.getSession(this.mostDownstreamPlugin))?.firstPointAddedBySession?.point;return e?.hasZ?e.z:null}get _tooltipDependencies(){let{defaultZ:e,editGeometryOperations:t,toolOptions:n,directionOptions:r,elevationInfo:i,view:a}=this;return!t||!n||!a?null:{defaultZ:e,directionOptions:r,elevationInfo:i,editGeometryOperations:t,toolOptions:n,view:a,getActiveHandle:()=>this.interactiveHandleManager?.focusedHandle,getAllHandles:()=>this.interactiveHandleManager?.allhandles,getHelpMessageKey:()=>this.helpMessageKey,notifyTooltipsChanged:()=>{let{interactiveHandleManager:e,movementCommandContext:t}=this;e&&t&&e.reapplyPositions(t)}}}get _editSessionManagerContext(){let{coordinateHelper:e,view:t}=this;return t?{coordinateHelper:e,viewingMode:t.type===`3d`&&t.viewingMode===`global`?1:2}:null}get _densificationParameters(){let{view:e,coordinateHelper:t}=this,n=t.spatialReference,r=e?.spatialReference,i=e.resolution;if(!n||!r||!i||!Number.isFinite(i))return null;let a=r.metersPerUnit/n.metersPerUnit;return{maxDeviation:2**Math.round(Math.log2(i))*O()*a,minSegmentsPerCurve:k()}}get test(){return{densificationParameters:this._densificationParameters,segmentLabels:this._segmentLabels}}get updating(){return this._updatingHandles.updating||this.snappingManager?.updating||this.lifecycleManager.updating||!!this._segmentLabels?.updating}get coordinateHelper(){return G(this.hasZ,!1,this.view.spatialReference)}get editGeometry(){return this.editGeometryOperations?.data}get editGeometryOperations(){return this.editSessionManager.editGeometryOperations}get unprocessedGeometry(){return this.editSessionManager.outputGeometry}get simplifiedGeometryPreview(){let e=this.editSessionManager.outputGeometry;if(e&&w(e))try{let t=this._densificationParameters,n=T(e)&&t?new te({...E(e,t)}):e;if(!S(n))return C(n)}catch{return e}return e}get _suppressCoincidentPointOverlaysIn3D(){return this.view.type===`3d`&&this.unprocessedGeometry?.type===`point`&&!!this.interactiveHandleManager?.allhandles?.find(e=>e.role===`primary`)?.outputMapPosition}get _shapeVisualGeometry(){return this._suppressCoincidentPointOverlaysIn3D?null:this.simplifiedGeometryPreview}get _vertexVisualGeometry(){return this._suppressCoincidentPointOverlaysIn3D?null:this.unprocessedGeometry}get canUndo(){return this.editSessionManager.canUndo}get canRedo(){return this.editSessionManager.canRedo}get pluginStack(){return this.lifecycleManager.pluginStack}get mostDownstreamPlugin(){return this.pluginStack.at(-1)}get mostUpstreamPlugin(){return this.pluginStack.at(0)}get positionOfLastUserInput(){let e=this.lastScreenPosition;return e?this.surfaceManager?.screenToMap(e,{firstPointZ:this._zOfLastUserInput})??this.view.toMap(e):this.view.center}get movementCommandContext(){let{editGeometryOperations:e,tooltipManager:t,surfaceManager:n,snappingManager:r,interactiveHandleManager:i,_snappingVisualizer:a,defaultZ:o,hasZ:s,globalStateManager:{drawAtFixedElevation:c},view:l}=this;return{tooltipManager:t,editGeometryOperations:e,surfaceManager:n,interactiveHandleManager:i,snappingManager:r,snappingVisualizer:a,pointerType:`mouse`,hasZ:s,defaultZ:o,view:l,drawAtFixedElevation:c}}get tooltip(){return this.tooltipManager?.tooltip}get activeTooltipInfo(){return this.tooltipManager?.tooltipInfo}get helpMessageKey(){return this.pluginStack.items.findLast(e=>e.helpMessageKey)?.helpMessageKey??`noTool`}begin(e){this.active?(this.lifecycleManager.begin(e),this._pendingBeginRequest=null):this._pendingBeginRequest=e}complete(e){let t=this.lifecycleManager;if(e&&t.complete(e),t.pluginStack.length===0){let e=this.unprocessedGeometry,t=!e||e.type===`mesh`||S(e);this.emit(`complete`,{geometry:e,isSimple:t,aborted:!1,type:`complete`,vertices:[]}),this.view?.activeTool===this&&(this.view.activeTool=null)}}cancelFirstUserLeafPlugin(){let e=this.pluginStack.toArray().findLast(e=>e.configuration?.hidden!==!0);e&&this.lifecycleManager.cancel(e)}getVertexSnappingCandidates(){return this.interactiveHandleManager?.capturingHandle?.role===`secondary`?[]:this.snappingManager?.getVertexCandidates()??[]}replaceLeaf(e){let t=this.lifecycleManager;t.updating?o.getLogger(this).info(`Ignoring command; arrived while updating:`,`replaceLeaf`):t.replaceLeaf(e)}finishPart(){let e=this.mostUpstreamPlugin?.configuration;if(this.editGeometryOperations&&e&&e.kind?.includes(`multipart`)){let e=this.pluginStack.at(1);e&&this.complete(e)}}undo(){this._handleCommand({action:`undo`})}redo(){this._handleCommand({action:`redo`})}executeCommand(e){return this._handleCommand(e)}suspendCommands(){return this._commandsSuspended=!0,i(()=>{this._commandsSuspended=!1;let e=this.view?.inputManager.latestPointerInfo;if(e){let{x:t,y:n}=e.location;this._handleCommand({action:`manipulator-move-to`,x:t,y:n})}})}addPromise(e){return this._updatingHandles.addPromise(e)}readPluginSettingValue(e,t){return this.readPluginSetting?.(e,t)}getGeometryIfCompleted(){let e=this.lifecycleManager.gatherCompletablePlugins();return this.editSessionManager?.generatePreviewGeometryForPlugins(e)}onActivate(){super.onActivate();let{view:e}=this;this.lastScreenPosition=e?.inputManager.latestPointerInfo?.location,this.renderer?.activate(),this._pendingBeginRequest&&=(this.begin(this._pendingBeginRequest),null),this.enableVertexVisuals&&this.addHandles(p(()=>this._vertexVisualGeometry,e=>{this.renderer?.addOrUpdateVisual(this._vertexVisualId,{geometry:e?j(e):null})},f)),this.addHandles([p(()=>this._shapeVisualGeometry,e=>{this.renderer?.addOrUpdateVisual(this._shapeVisualId,{geometry:e})},f),d(()=>this.interactiveHandleManager?.capturingHandle?.screenPosition,e=>this.lastScreenPosition=e,{initial:!0,equals:g}),p(()=>this.interactiveHandleManager?.capturingHandle?.outputMapPosition,(e,t)=>{let n=this.interactiveHandleManager?.capturingHandle?.editSession?.endVertex;e&&t&&n&&this._emitWhenReady(`cursor-update`,{updated:n.pos,type:`vertex-update`,operation:`apply`,vertices:[{componentIndex:n.part.index,vertexIndex:n.index,coordinates:n.pos}]})},h),this._keybindings.register(e,W.TOOL),p(()=>e.viewpoint,(e,t)=>{e&&t&&v(e,t)&&this._handleCommand({action:`viewpoint-moved`})})],Q)}onDeactivate(){super.onDeactivate(),this.removeHandles(Q),this.renderer?.deactivate(),this.snappingManager?.doneSnapping(),this.lifecycleManager.cancelAll(),this._pendingBeginRequest=null}onInputEvent(e){e.type===`pointer-down`?this.interactiveHandleManager?.notePointerDown(e.pointerId,e.pointerType):(e.type===`pointer-up`||e.type===`pointer-leave`)&&this.interactiveHandleManager?.notePointerUp(e.pointerId,e.pointerType);let t=I(e);t&&this._handleCommand(t)}forceAddVertex(){this._commitNext()}_emitWhenReady(e,t){if(this.destroyed)return;let n=()=>{this.emit(e,t)};this.lifecycleManager.updating||this._flushingQueuedFeedbackEvents?this._queuedFeedbackEvents.push(n):n()}_emitQueuedFeedbackEvents(){if(!(this.destroyed||this._flushingQueuedFeedbackEvents||this.lifecycleManager.updating||this._queuedFeedbackEvents.length===0)){this._flushingQueuedFeedbackEvents=!0;try{for(;!this.destroyed&&!this.lifecycleManager.updating&&this._queuedFeedbackEvents.length>0;)this._queuedFeedbackEvents.shift()?.()}finally{this._flushingQueuedFeedbackEvents=!1}}}async _handleCommand(e){if(!this._commandsSuspended){if(this.lifecycleManager.updating)o.getLogger(this).info(`Ignoring command; arrived while updating:`,e.action);else switch(e.action){case`view-drag`:return await this._handleViewDragCommand(e);case`vertex-add`:return this._guardCommand(e,()=>{M(e),this._commitNext()});case`vertex-add-and-finish-part`:return this._handleVertexAddAndFinishPartCommand(e);case`cancel`:return this._guardCommand(e,()=>this.cancel());case`complete`:return this._guardCommand(e,()=>{this.mostUpstreamPlugin&&(M(e),this.complete(this.mostUpstreamPlugin))});case`finish-part`:return this._guardCommand(e,()=>this.finishPart());case`undo`:return this._guardCommand(e,()=>this.editSessionManager.undo());case`redo`:return this._guardCommand(e,()=>this.editSessionManager.redo());case`next-manipulator`:return this._guardCommand(e,()=>this.interactiveHandleManager?.cycleManipulator(`forward`));case`previous-manipulator`:return this._guardCommand(e,()=>this.interactiveHandleManager?.cycleManipulator(`backward`));case`toggle-manipulator-follow`:this.interactiveHandleManager?.toggleFollow()&&M(e);break;case`viewpoint-moved`:return await this._handleViewpointMovedCommand(e);case`manipulator-move-to`:return await this._handleManipulatorMoveToCommand(e);case`manipulator-drag-to`:return await this._handleManipulatorDragToCommand(e);case`vertex-add-at-point`:return await this._handleVertexAddAtPointCommand(e);case`show-tooltip`:return this._guardCommand(e,async()=>{let t=this.tooltipManager?.tooltip;t&&ne(t.info)&&(await t.enterInputMode(),M(e))});case`constraint-center`:this.globalStateManager.setCentered(e.enabled);break;case`constraint-aspect`:this.globalStateManager.setPreserveAspectRatio(e.enabled)}}}async _handleViewDragCommand(e){if(!this.editable)return;let t=e.originalEvent,n=this.interactiveHandleManager?.capturingHandle;(t&&`pointerType`in t&&t.pointerType===`touch`&&(n?.captureMode===`capture-always`||n?.captureMode===`capture-when-engaged`)||this.interactiveHandleManager?.capturingHandle?.captureMode===`capture-when-engaged`||this._before(e))&&M(e)}_handleVertexAddAndFinishPartCommand(e){this._before(e)||(M(e),this._commitNext(),this.finishPart())}async _handleViewpointMovedCommand(e){if(!this.editable)return;let t=N(e.originalEvent),n=P(e.originalEvent);await this._updatingHandles.addPromise(this.interactiveHandleManager?.capturingHandle?.moveTo(null,{...this.movementCommandContext,pointerType:t,pointerId:n})),this.interactiveHandleManager?.updateAllScreenPositions(this.movementCommandContext.surfaceManager)}async _handleManipulatorMoveToCommand(e){if(!this.editable)return;let t=N(e.originalEvent),n=P(e.originalEvent);if(!this.interactiveHandleManager?.shouldCaptureInput(n,t))return;let r=this._updateLastScreenPosition(e);this.interactiveHandleManager?.capturingHandle&&M(e),await this._updatingHandles.addPromise(this.interactiveHandleManager?.capturingHandle?.moveTo(r,{...this.movementCommandContext,pointerType:t,pointerId:n}))}async _handleManipulatorDragToCommand(e){if(!this.editable)return;let t=N(e.originalEvent),n=P(e.originalEvent);if(!this.interactiveHandleManager?.shouldCaptureInput(n,t))return;let r=this._updateLastScreenPosition(e),i=this.interactiveHandleManager?.findHandleByManipulator(r,t);t===`touch`&&i&&e.state===`start`&&this.interactiveHandleManager?.releaseHandle();let a=this.interactiveHandleManager?.findHandleDragging(),o=this.interactiveHandleManager?.capturingHandle,s=a??o??i;s&&!i&&M(e),s?.captureMode===`capture-when-engaged`||s?.captureMode===`capture-always`&&t===`touch`?e.state===`end`?await this._updatingHandles.addPromise(s.noteDragEnd(r,{...this.movementCommandContext,pointerType:t,pointerId:n}).then(()=>{s&&N(e.originalEvent)===`touch`&&s.captureMode!==`grabbable-object`&&s.defaultCaptureMode!==`capture-when-engaged`&&s.role===`primary`&&(this.interactiveHandleManager?.handleCount===1?this._handleCommand({action:`vertex-add`}):this.interactiveHandleManager?.releaseHandle())})):e.state===`start`?await this._updatingHandles.addPromise(s.noteDragStart(r,{...this.movementCommandContext,pointerType:t,pointerId:n}).then(()=>{s&&N(e.originalEvent)===`touch`&&s.captureMode!==`grabbable-object`&&s.defaultCaptureMode!==`capture-when-engaged`&&!s.editSession?.lastPointAddedBySession&&this._handleCommand({action:`vertex-add`})})):await this._updatingHandles.addPromise(s?.moveTo(r,{...this.movementCommandContext,pointerType:t,pointerId:n})):s?.captureMode===`grabbable-object`&&(this.interactiveHandleManager?.releaseHandle(o),await this._updatingHandles.addPromise(s.moveTo(r,{...this.movementCommandContext,pointerType:t,pointerId:n})))}async _handleVertexAddAtPointCommand(e){let t=this._updateLastScreenPosition(e),n=N(e.originalEvent),r=P(e.originalEvent);if(!this.interactiveHandleManager?.shouldCaptureInput(r,n))return;let i=this.interactiveHandleManager?.capturingHandle??this.interactiveHandleManager?.findHandleByManipulator(t,n);this.editable&&i&&(this._before(e)||(M(e),await this._updatingHandles.addPromise(i.moveTo(t,{...this.movementCommandContext,skipSnapping:!0,pointerType:n,pointerId:r}).finally(()=>this._commitNext()))))}_makeKeyBindings(){let e=new q,t=(t,n)=>{e.addToggle(t,e=>this._handleCommand({action:n,originalEvent:e,enabled:e.type===`key-down`}))},n=(t,n)=>{e.add(t,e=>this._handleCommand({action:n,originalEvent:e}))};return t(J.preserveAspectRatio,`constraint-aspect`),t(Y.center,`constraint-center`),n(X.toggleFollowManipulator,`toggle-manipulator-follow`),n(Y.undo,`undo`),n(Y.redo,`redo`),n(Y.complete,`complete`),n(Y.vertexAdd,`vertex-add`),n({key:Z.enterInputMode,continuePropagation:!0,repeats:!0},`show-tooltip`),e}_afterAttach(){}_afterDetach(e){this.interactiveHandleManager?.unregisterCustomConstraint(e),this.interactiveHandleManager?.unregisterHandle(e),this.tooltipManager?.unregisterPluginFields(e),this.globalStateManager.clearPluginOverrides(e);let t=this._pluginContexts.get(e);t&&(t.destroy(),this._pluginContexts.delete(e))}_beforeResume(e,t){this.interactiveHandleManager?.replaceEditSessions(e,t)}_commitNext(){let n={stack:[],error:void 0,hasError:!1};try{let t=this.mostDownstreamPlugin;if(!t)return;this.tooltipManager?.storeConstraintSnapshot();let r=this.tooltipManager?.getFieldsToUnlockOnVertexPlacement()??[],i=!1,o=this.editGeometryOperations;e(n,o?a(o.on(`vertex-add`,()=>i=!0)):null,!1),t.completeStep?t.completeStep():this.complete(t),i&&this.tooltipManager?.unlockOnVertexPlacement(r)}catch(e){n.error=e,n.hasError=!0}finally{t(n)}}_suspendPlugin(e){this.lifecycleManager.suspend(e),this.measurementManager.suspendPlugin(e)}_resumePlugin(e){this.lifecycleManager.resume(e)}_updateLastScreenPosition(e){let t=_(e.x,e.y);return this.lastScreenPosition=t,t}_getContextForPlugin(e,t){let n=s(this._pluginContexts,e,()=>new F({drawTool:this,plugin:e,session:t}));return n.session=t,n}_before(e){if(!this.hasEventListener(`before-${e.action}`))return!1;let t=new CustomEvent(`before-${e.action}`,{detail:e,cancelable:!0});return this.emit(`before-${e.action}`,t),t.defaultPrevented}_guardCommand(e,t,n){return this._before(e)?n?.():t()}async _setupSegmentLabels(){let e=this.editGeometryOperations,t=this.toolOptions?.labels,n=!!t?.enabled,r=this.globalStateManager.segmentLabelsDisabled;if(!e||!t||!n){this._segmentLabels=c(this._segmentLabels);return}if(r){this._segmentLabels&&(this._segmentLabels.visible=!1);return}if(this._segmentLabels?.context?.editGeometryOperations===e&&this._segmentLabels.context.labelOptions===t){this._segmentLabels.visible=!0;return}let i=await this._createSegmentLabels(e,t);i&&(this._segmentLabels=c(this._segmentLabels),this._segmentLabels=i)}async _createSegmentLabels(e,t){this._segmentLabelsImportTask?.abort();let n=this._segmentLabelsImportTask=r(async n=>{if(this.view.type===`3d`){let r=import(`../3d/interactive/SegmentLabels3D.js`),{SegmentLabels3D:i}=await this._updatingHandles.addPromise(r);return this._isSegmentLabelsSetupStale(n,e,t)?null:new i({context:{view:this.view,editGeometryOperations:e,elevationInfo:D(this.hasZ,this.elevationInfo),labelOptions:t},visible:!0})}let r=import(`../2d/interactive/SegmentLabels2D.js`),{SegmentLabels2D:i}=await this._updatingHandles.addPromise(r);return this._isSegmentLabelsSetupStale(n,e,t)?null:new i({context:{view:this.view,editGeometryOperations:e,elevationInfo:D(this.hasZ,this.elevationInfo),labelOptions:t},visible:!0})});return u(n.promise)}_isSegmentLabelsSetupStale(e,t,n){return e.aborted||this.editGeometryOperations!==t||this.toolOptions?.labels!==n||!n.enabled||this.globalStateManager.segmentLabelsDisabled}};n([y()],$.prototype,`_commandsSuspended`,void 0),n([y()],$.prototype,`_zOfLastUserInput`,null),n([y()],$.prototype,`_snappingVisualizer`,void 0),n([y()],$.prototype,`_segmentLabels`,void 0),n([y()],$.prototype,`_segmentLabelsImportTask`,void 0),n([y()],$.prototype,`_tooltipDependencies`,null),n([y()],$.prototype,`_editSessionManagerContext`,null),n([y()],$.prototype,`_densificationParameters`,null),n([y({constructOnly:!0,nonNullable:!0})],$.prototype,`view`,void 0),n([y()],$.prototype,`automaticManipulatorSelection`,void 0),n([y()],$.prototype,`updating`,null),n([y()],$.prototype,`coordinateHelper`,null),n([y()],$.prototype,`editGeometry`,null),n([y()],$.prototype,`editGeometryOperations`,null),n([y()],$.prototype,`unprocessedGeometry`,null),n([y()],$.prototype,`simplifiedGeometryPreview`,null),n([y()],$.prototype,`_suppressCoincidentPointOverlaysIn3D`,null),n([y()],$.prototype,`_shapeVisualGeometry`,null),n([y()],$.prototype,`_vertexVisualGeometry`,null),n([y()],$.prototype,`snappingManager`,void 0),n([y()],$.prototype,`toolOptions`,void 0),n([y()],$.prototype,`elevationInfo`,void 0),n([y()],$.prototype,`hasZ`,void 0),n([y()],$.prototype,`defaultZ`,void 0),n([y()],$.prototype,`directionOptions`,void 0),n([y()],$.prototype,`canUndo`,null),n([y()],$.prototype,`canRedo`,null),n([y()],$.prototype,`pluginStack`,null),n([y()],$.prototype,`mostDownstreamPlugin`,null),n([y()],$.prototype,`mostUpstreamPlugin`,null),n([y()],$.prototype,`lastScreenPosition`,void 0),n([y()],$.prototype,`positionOfLastUserInput`,null),n([y()],$.prototype,`tooltipManager`,void 0),n([y()],$.prototype,`measurementManager`,void 0),n([y()],$.prototype,`globalStateManager`,void 0),n([y()],$.prototype,`editSessionManager`,void 0),n([y()],$.prototype,`lifecycleManager`,void 0),n([y()],$.prototype,`surfaceManager`,void 0),n([y()],$.prototype,`interactiveHandleManager`,void 0),n([y()],$.prototype,`renderer`,void 0),n([y()],$.prototype,`readPluginSetting`,void 0),n([y()],$.prototype,`movementCommandContext`,null),n([y()],$.prototype,`tooltip`,null),n([y()],$.prototype,`activeTooltipInfo`,null),n([y()],$.prototype,`helpMessageKey`,null),n([y({constructOnly:!0})],$.prototype,`enableVertexVisuals`,void 0),$=n([b(`esri.views.draw.DrawTool`)],$);export{$ as DrawTool};
|
|
2
|
+
import{__addDisposableResource as e,__disposeResources as t,__decorate as n}from"tslib";import{createTask as r}from"../../core/asyncUtils.js";import{makeHandle as i,disposable as a}from"../../core/handleUtils.js";import o from"../../core/Logger.js";import{getOrCreateMapValue as s}from"../../core/MapUtils.js";import{destroyMaybe as c,abortMaybe as l}from"../../core/maybe.js";import{ignoreAbortErrors as u}from"../../core/promiseUtils.js";import{when as d,initial as f,watch as p,syncAndInitial as ee,on as m,sync as h}from"../../core/reactiveUtils.js";import{screenPointEqual as g,createScreenPoint as _}from"../../core/screenUtils.js";import{diff as v}from"../../core/accessorSupport/diffUtils.js";import{property as y}from"../../core/accessorSupport/decorators/property.js";import{subclass as b}from"../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as x}from"../../core/support/UpdatingHandles.js";import te from"../../geometry/Polygon.js";import{simplifyIsSimple as S,simplifyExecute as C}from"../../geometry/operators/simplifyOperator.js";import{isPolygon as w}from"../../geometry/support/typeUtils.js";import{isCurvedGeometry as T}from"../../geometry/support/curves/curveUtils.js";import{densifyCurvedGeometry as E}from"../../geometry/support/curves/densifyCurvedGeometry.js";import{getEffectiveElevationInfo as D}from"../../support/elevationInfoUtils.js";import{getMaxDeviationInPixels as O,getMinSegmentsPerCurve as k}from"../2d/layers/graphics/densificationConstants.js";import{createSnappingVisualizer as A}from"./support/createSnappingVisualizer.js";import{multipointFromGeometry as j,markHandled as M,getPointerType as N,getPointerId as P}from"./support/drawToolUtils.js";import{PluginContext as F}from"./support/PluginContext.js";import{viewEventToCommand as I}from"./support/input/drawToolInput.js";import{EditSessionManager as L}from"./support/managers/EditSessionManager.js";import{GlobalStateManager as R}from"./support/managers/GlobalStateManager.js";import{InteractiveHandleManager as z}from"./support/managers/InteractiveHandleManager.js";import{MeasurementManager as B}from"./support/managers/MeasurementManager.js";import{PluginLifecycleManager as V}from"./support/managers/PluginLifecycleManager.js";import{SurfaceManager as H}from"./support/managers/SurfaceManager.js";import{TooltipManager as U}from"./support/managers/TooltipManager.js";import{ViewEventPriorities as W}from"../input/InputManager.js";import{createCoordinateHelper as G}from"../interactive/coordinateHelper.js";import{InteractiveToolBase as K}from"../interactive/InteractiveToolBase.js";import{KeyBindings as q,mediaKeys as J,sketchKeys as Y,advancedSketchKeys as X,tooltipKeys as Z}from"../interactive/keybindings.js";import{isInputModeAvailable as ne}from"../interactive/tooltip/tooltipCommonUtils.js";const Q=Symbol();let $=class extends K{constructor(e){super(e),this._shapeVisualId=Symbol(),this._vertexVisualId=Symbol(),this._pluginContexts=new Map,this._queuedFeedbackEvents=[],this._flushingQueuedFeedbackEvents=!1,this._commandsSuspended=!1,this._snappingVisualizer=null,this._segmentLabels=null,this._segmentLabelsImportTask=null,this._updatingHandles=new x,this._keybindings=this._makeKeyBindings(),this._pendingBeginRequest=null,this.type=`draw-2.0`,this.automaticManipulatorSelection=!0,this.snappingManager=null,this.toolOptions=null,this.disableTouchDrag=!1,this.elevationInfo=null,this.hasZ=!1,this.defaultZ=0,this.lastScreenPosition=null,this.measurementManager=new B,this.globalStateManager=new R({getPluginStack:()=>this.pluginStack}),this.editSessionManager=new L({getContext:()=>this._editSessionManagerContext}),this.lifecycleManager=new V({getContext:this._getContextForPlugin.bind(this),editSessionManager:this.editSessionManager,afterAttach:this._afterAttach.bind(this),afterDetach:this._afterDetach.bind(this),beforeResume:this._beforeResume.bind(this)}),this.surfaceManager=null,this.interactiveHandleManager=null,this.renderer=null,this.readPluginSetting=null,this.enableVertexVisuals=!0}initialize(){let{view:e}=this;this.interactiveHandleManager=new z({view:e,renderer:this.renderer}),this._override(`manipulators`,this.interactiveHandleManager.manipulators),this.tooltipManager=new U({getDependencies:()=>this._tooltipDependencies,getLastScreenPosition:()=>this.lastScreenPosition}),this.addHandles(d(()=>this.renderer,t=>{t.addOrUpdateVisual(this._shapeVisualId,{role:`outputGeometry`}),t.addOrUpdateVisual(this._vertexVisualId,{role:`vertex`}),this._updatingHandles.addPromise(A(e,t).then(e=>this._snappingVisualizer=e))},f)),this.addHandles([p(()=>[this.view,this.coordinateHelper.spatialReference,this.defaultZ,this.hasZ,this.elevationInfo],([e,t,n,r,i])=>{this.surfaceManager?.destroy(),this.surfaceManager=new H({spatialReference:t,excludedGraphicsLayer:null,defaultZ:n,hasZ:r,view:e,elevationInfo:i,getContext:()=>({drawAtFixedElevation:this.globalStateManager.drawAtFixedElevation,elevationConstraint:this.tooltipManager?.elevationConstraint,constraintsEnabled:this.tooltipManager?.constraintsEnabled??!1})})},ee),d(()=>this.toolOptions?.tooltips.effectiveEnabled,()=>this.measurementManager.preloadMeasurementUtils(),{once:!0,initial:!0}),p(()=>[this.editGeometryOperations,this.toolOptions?.labels.enabled,this.globalStateManager.segmentLabelsDisabled],()=>{this._updatingHandles.addPromise(this._setupSegmentLabels())},f),m(()=>this.editSessionManager,`cancelPlugin`,({plugin:e})=>{this._suspendPlugin(e)},h),m(()=>this.editSessionManager,`restartPlugin`,({restartInfo:e})=>{this._resumePlugin(e)},h),p(()=>this.lifecycleManager.updating,e=>{e||this._emitQueuedFeedbackEvents()},h),m(()=>this.editGeometryOperations,[`vertex-add`,`vertex-update`,`vertex-remove`],e=>{let t=e.vertices.map(e=>({componentIndex:0,vertexIndex:e.index,coordinates:this.coordinateHelper.vectorToArray(e.pos)})),n=t.map(e=>e.coordinates);switch(e.type){case`vertex-add`:this._emitWhenReady(e.type,{...e,added:n,vertices:t});break;case`vertex-update`:this._emitWhenReady(e.type,{...e,updated:n,vertices:t});break;case`vertex-remove`:this._emitWhenReady(e.type,{...e,removed:n,vertices:t})}})])}destroy(){this.active&&this.onDeactivate(),this.editSessionManager.destroy(),this.lifecycleManager.destroy(),this.measurementManager.destroy(),this.globalStateManager.destroy();for(let e of this._pluginContexts.values())e.destroy();this._pluginContexts.clear(),this.surfaceManager=c(this.surfaceManager),this.interactiveHandleManager=c(this.interactiveHandleManager),this._segmentLabelsImportTask=l(this._segmentLabelsImportTask),this._segmentLabels=c(this._segmentLabels),this.tooltipManager=c(this.tooltipManager)}get _zOfLastUserInput(){let e=(this.mostDownstreamPlugin&&this.editSessionManager.getSession(this.mostDownstreamPlugin))?.firstPointAddedBySession?.point;return e?.hasZ?e.z:null}get _tooltipDependencies(){let{defaultZ:e,editGeometryOperations:t,toolOptions:n,directionOptions:r,elevationInfo:i,view:a}=this;return!t||!n||!a?null:{defaultZ:e,directionOptions:r,elevationInfo:i,editGeometryOperations:t,toolOptions:n,view:a,getActiveHandle:()=>this.interactiveHandleManager?.focusedHandle,getAllHandles:()=>this.interactiveHandleManager?.allhandles,getHelpMessageKey:()=>this.helpMessageKey,notifyTooltipsChanged:()=>{let{interactiveHandleManager:e,movementCommandContext:t}=this;e&&t&&e.reapplyPositions(t)}}}get _editSessionManagerContext(){let{coordinateHelper:e,view:t}=this;return t?{coordinateHelper:e,viewingMode:t.type===`3d`&&t.viewingMode===`global`?1:2}:null}get _densificationParameters(){let{view:e,coordinateHelper:t}=this,n=t.spatialReference,r=e?.spatialReference,i=e.resolution;if(!n||!r||!i||!Number.isFinite(i))return null;let a=r.metersPerUnit/n.metersPerUnit;return{maxDeviation:2**Math.round(Math.log2(i))*O()*a,minSegmentsPerCurve:k()}}get test(){return{densificationParameters:this._densificationParameters,segmentLabels:this._segmentLabels}}get updating(){return this._updatingHandles.updating||this.snappingManager?.updating||this.lifecycleManager.updating||!!this._segmentLabels?.updating}get coordinateHelper(){return G(this.hasZ,!1,this.view.spatialReference)}get editGeometry(){return this.editGeometryOperations?.data}get editGeometryOperations(){return this.editSessionManager.editGeometryOperations}get unprocessedGeometry(){return this.editSessionManager.outputGeometry}get simplifiedGeometryPreview(){let e=this.editSessionManager.outputGeometry;if(e&&w(e))try{let t=this._densificationParameters,n=T(e)&&t?new te({...E(e,t)}):e;if(!S(n))return C(n)}catch{return e}return e}get _suppressCoincidentPointOverlaysIn3D(){return this.view.type===`3d`&&this.unprocessedGeometry?.type===`point`&&!!this.interactiveHandleManager?.allhandles?.find(e=>e.role===`primary`)?.outputMapPosition}get _shapeVisualGeometry(){return this._suppressCoincidentPointOverlaysIn3D?null:this.simplifiedGeometryPreview}get _vertexVisualGeometry(){return this._suppressCoincidentPointOverlaysIn3D?null:this.unprocessedGeometry}get canUndo(){return this.editSessionManager.canUndo}get canRedo(){return this.editSessionManager.canRedo}get pluginStack(){return this.lifecycleManager.pluginStack}get mostDownstreamPlugin(){return this.pluginStack.at(-1)}get mostUpstreamPlugin(){return this.pluginStack.at(0)}get positionOfLastUserInput(){let e=this.lastScreenPosition;return e?this.surfaceManager?.screenToMap(e,{firstPointZ:this._zOfLastUserInput})??this.view.toMap(e):this.view.center}get movementCommandContext(){let{editGeometryOperations:e,tooltipManager:t,surfaceManager:n,snappingManager:r,interactiveHandleManager:i,_snappingVisualizer:a,defaultZ:o,hasZ:s,globalStateManager:{drawAtFixedElevation:c},view:l}=this;return{tooltipManager:t,editGeometryOperations:e,surfaceManager:n,interactiveHandleManager:i,snappingManager:r,snappingVisualizer:a,pointerType:`mouse`,hasZ:s,defaultZ:o,view:l,drawAtFixedElevation:c}}get tooltip(){return this.tooltipManager?.tooltip}get activeTooltipInfo(){return this.tooltipManager?.tooltipInfo}get helpMessageKey(){return this.pluginStack.items.findLast(e=>e.helpMessageKey)?.helpMessageKey??`noTool`}begin(e){this.active?(this.lifecycleManager.begin(e),this._pendingBeginRequest=null):this._pendingBeginRequest=e}complete(e){let t=this.lifecycleManager;if(e&&t.complete(e),t.pluginStack.length===0){let e=this.unprocessedGeometry,t=!e||e.type===`mesh`||S(e);this.emit(`complete`,{geometry:e,isSimple:t,aborted:!1,type:`complete`,vertices:[]}),this.view?.activeTool===this&&(this.view.activeTool=null)}}cancelFirstUserLeafPlugin(){let e=this.pluginStack.toArray().findLast(e=>e.configuration?.hidden!==!0);e&&this.lifecycleManager.cancel(e)}getVertexSnappingCandidates(){return this.interactiveHandleManager?.capturingHandle?.role===`secondary`?[]:this.snappingManager?.getVertexCandidates()??[]}replaceLeaf(e){let t=this.lifecycleManager;t.updating?o.getLogger(this).info(`Ignoring command; arrived while updating:`,`replaceLeaf`):t.replaceLeaf(e)}finishPart(){let e=this.mostUpstreamPlugin?.configuration;if(this.editGeometryOperations&&e&&e.kind?.includes(`multipart`)){let e=this.pluginStack.at(1);e&&this.complete(e)}}undo(){this._handleCommand({action:`undo`})}redo(){this._handleCommand({action:`redo`})}executeCommand(e){return this._handleCommand(e)}suspendCommands(){return this._commandsSuspended=!0,i(()=>{this._commandsSuspended=!1;let e=this.view?.inputManager.latestPointerInfo;if(e){let{x:t,y:n}=e.location;this._handleCommand({action:`manipulator-move-to`,x:t,y:n})}})}addPromise(e){return this._updatingHandles.addPromise(e)}readPluginSettingValue(e,t){return this.readPluginSetting?.(e,t)}getGeometryIfCompleted(){let e=this.lifecycleManager.gatherCompletablePlugins();return this.editSessionManager?.generatePreviewGeometryForPlugins(e)}onActivate(){super.onActivate();let{view:e}=this;this.lastScreenPosition=e?.inputManager.latestPointerInfo?.location,this.renderer?.activate(),this._pendingBeginRequest&&=(this.begin(this._pendingBeginRequest),null),this.enableVertexVisuals&&this.addHandles(p(()=>this._vertexVisualGeometry,e=>{this.renderer?.addOrUpdateVisual(this._vertexVisualId,{geometry:e?j(e):null})},f)),this.addHandles([p(()=>this._shapeVisualGeometry,e=>{this.renderer?.addOrUpdateVisual(this._shapeVisualId,{geometry:e})},f),d(()=>this.interactiveHandleManager?.capturingHandle?.screenPosition,e=>this.lastScreenPosition=e,{initial:!0,equals:g}),p(()=>this.interactiveHandleManager?.capturingHandle?.outputMapPosition,(e,t)=>{let n=this.interactiveHandleManager?.capturingHandle?.editSession?.endVertex;e&&t&&n&&this._emitWhenReady(`cursor-update`,{updated:n.pos,type:`vertex-update`,operation:`apply`,vertices:[{componentIndex:n.part.index,vertexIndex:n.index,coordinates:n.pos}]})},h),this._keybindings.register(e,W.TOOL),p(()=>e.viewpoint,(e,t)=>{e&&t&&v(e,t)&&this._handleCommand({action:`viewpoint-moved`})})],Q)}onDeactivate(){super.onDeactivate(),this.removeHandles(Q),this.renderer?.deactivate(),this.snappingManager?.doneSnapping(),this.lifecycleManager.cancelAll(),this._pendingBeginRequest=null}onInputEvent(e){if(this.disableTouchDrag&&(e.type===`drag`||e.type===`pointer-drag`)&&e.pointerType===`touch`)return;e.type===`pointer-down`?this.interactiveHandleManager?.notePointerDown(e.pointerId,e.pointerType):(e.type===`pointer-up`||e.type===`pointer-leave`)&&this.interactiveHandleManager?.notePointerUp(e.pointerId,e.pointerType);let t=I(e);t&&this._handleCommand(t)}forceAddVertex(){this._commitNext()}_emitWhenReady(e,t){if(this.destroyed)return;let n=()=>{this.emit(e,t)};this.lifecycleManager.updating||this._flushingQueuedFeedbackEvents?this._queuedFeedbackEvents.push(n):n()}_emitQueuedFeedbackEvents(){if(!(this.destroyed||this._flushingQueuedFeedbackEvents||this.lifecycleManager.updating||this._queuedFeedbackEvents.length===0)){this._flushingQueuedFeedbackEvents=!0;try{for(;!this.destroyed&&!this.lifecycleManager.updating&&this._queuedFeedbackEvents.length>0;)this._queuedFeedbackEvents.shift()?.()}finally{this._flushingQueuedFeedbackEvents=!1}}}async _handleCommand(e){if(!this._commandsSuspended){if(this.lifecycleManager.updating)o.getLogger(this).info(`Ignoring command; arrived while updating:`,e.action);else switch(e.action){case`view-drag`:return await this._handleViewDragCommand(e);case`vertex-add`:return this._guardCommand(e,()=>{M(e),this._commitNext()});case`vertex-add-and-finish-part`:return this._handleVertexAddAndFinishPartCommand(e);case`cancel`:return this._guardCommand(e,()=>this.cancel());case`complete`:return this._guardCommand(e,()=>{this.mostUpstreamPlugin&&(M(e),this.complete(this.mostUpstreamPlugin))});case`finish-part`:return this._guardCommand(e,()=>this.finishPart());case`undo`:return this._guardCommand(e,()=>this.editSessionManager.undo());case`redo`:return this._guardCommand(e,()=>this.editSessionManager.redo());case`next-manipulator`:return this._guardCommand(e,()=>this.interactiveHandleManager?.cycleManipulator(`forward`));case`previous-manipulator`:return this._guardCommand(e,()=>this.interactiveHandleManager?.cycleManipulator(`backward`));case`toggle-manipulator-follow`:this.interactiveHandleManager?.toggleFollow()&&M(e);break;case`viewpoint-moved`:return await this._handleViewpointMovedCommand(e);case`manipulator-move-to`:return await this._handleManipulatorMoveToCommand(e);case`manipulator-drag-to`:return await this._handleManipulatorDragToCommand(e);case`vertex-add-at-point`:return await this._handleVertexAddAtPointCommand(e);case`show-tooltip`:return this._guardCommand(e,async()=>{let t=this.tooltipManager?.tooltip;t&&ne(t.info)&&(await t.enterInputMode(),M(e))});case`constraint-center`:this.globalStateManager.setCentered(e.enabled);break;case`constraint-aspect`:this.globalStateManager.setPreserveAspectRatio(e.enabled)}}}async _handleViewDragCommand(e){if(!this.editable)return;let t=e.originalEvent,n=this.interactiveHandleManager?.capturingHandle;(t&&`pointerType`in t&&t.pointerType===`touch`&&(n?.captureMode===`capture-always`||n?.captureMode===`capture-when-engaged`)||this.interactiveHandleManager?.capturingHandle?.captureMode===`capture-when-engaged`||this._before(e))&&M(e)}_handleVertexAddAndFinishPartCommand(e){this._before(e)||(M(e),this._commitNext(),this.finishPart())}async _handleViewpointMovedCommand(e){if(!this.editable)return;let t=N(e.originalEvent),n=P(e.originalEvent);await this._updatingHandles.addPromise(this.interactiveHandleManager?.capturingHandle?.moveTo(null,{...this.movementCommandContext,pointerType:t,pointerId:n})),this.interactiveHandleManager?.updateAllScreenPositions(this.movementCommandContext.surfaceManager)}async _handleManipulatorMoveToCommand(e){if(!this.editable)return;let t=N(e.originalEvent),n=P(e.originalEvent);if(!this.interactiveHandleManager?.shouldCaptureInput(n,t))return;let r=this._updateLastScreenPosition(e);this.interactiveHandleManager?.capturingHandle&&M(e),await this._updatingHandles.addPromise(this.interactiveHandleManager?.capturingHandle?.moveTo(r,{...this.movementCommandContext,pointerType:t,pointerId:n}))}async _handleManipulatorDragToCommand(e){if(!this.editable)return;let t=N(e.originalEvent),n=P(e.originalEvent);if(!this.interactiveHandleManager?.shouldCaptureInput(n,t))return;let r=this._updateLastScreenPosition(e),i=this.interactiveHandleManager?.findHandleByManipulator(r,t);t===`touch`&&i&&e.state===`start`&&this.interactiveHandleManager?.releaseHandle();let a=this.interactiveHandleManager?.findHandleDragging(),o=this.interactiveHandleManager?.capturingHandle,s=a??o??i;s&&!i&&M(e),s?.captureMode===`capture-when-engaged`||s?.captureMode===`capture-always`&&t===`touch`?e.state===`end`?await this._updatingHandles.addPromise(s.noteDragEnd(r,{...this.movementCommandContext,pointerType:t,pointerId:n}).then(()=>{s&&N(e.originalEvent)===`touch`&&s.captureMode!==`grabbable-object`&&s.defaultCaptureMode!==`capture-when-engaged`&&s.role===`primary`&&(this.interactiveHandleManager?.handleCount===1?this._handleCommand({action:`vertex-add`}):this.interactiveHandleManager?.releaseHandle())})):e.state===`start`?await this._updatingHandles.addPromise(s.noteDragStart(r,{...this.movementCommandContext,pointerType:t,pointerId:n}).then(()=>{s&&N(e.originalEvent)===`touch`&&s.captureMode!==`grabbable-object`&&s.defaultCaptureMode!==`capture-when-engaged`&&!s.editSession?.lastPointAddedBySession&&this._handleCommand({action:`vertex-add`})})):await this._updatingHandles.addPromise(s?.moveTo(r,{...this.movementCommandContext,pointerType:t,pointerId:n})):s?.captureMode===`grabbable-object`&&(this.interactiveHandleManager?.releaseHandle(o),await this._updatingHandles.addPromise(s.moveTo(r,{...this.movementCommandContext,pointerType:t,pointerId:n})))}async _handleVertexAddAtPointCommand(e){let t=this._updateLastScreenPosition(e),n=N(e.originalEvent),r=P(e.originalEvent);if(!this.interactiveHandleManager?.shouldCaptureInput(r,n))return;let i=this.interactiveHandleManager?.capturingHandle??this.interactiveHandleManager?.findHandleByManipulator(t,n);this.editable&&i&&(this._before(e)||(M(e),await this._updatingHandles.addPromise(i.moveTo(t,{...this.movementCommandContext,skipSnapping:!0,pointerType:n,pointerId:r}).finally(()=>this._commitNext()))))}_makeKeyBindings(){let e=new q,t=(t,n)=>{e.addToggle(t,e=>this._handleCommand({action:n,originalEvent:e,enabled:e.type===`key-down`}))},n=(t,n)=>{e.add(t,e=>this._handleCommand({action:n,originalEvent:e}))};return t(J.preserveAspectRatio,`constraint-aspect`),t(Y.center,`constraint-center`),n(X.toggleFollowManipulator,`toggle-manipulator-follow`),n(Y.undo,`undo`),n(Y.redo,`redo`),n(Y.complete,`complete`),n(Y.vertexAdd,`vertex-add`),n({key:Z.enterInputMode,continuePropagation:!0,repeats:!0},`show-tooltip`),e}_afterAttach(){}_afterDetach(e){this.interactiveHandleManager?.unregisterCustomConstraint(e),this.interactiveHandleManager?.unregisterHandle(e),this.tooltipManager?.unregisterPluginFields(e),this.globalStateManager.clearPluginOverrides(e);let t=this._pluginContexts.get(e);t&&(t.destroy(),this._pluginContexts.delete(e))}_beforeResume(e,t){this.interactiveHandleManager?.replaceEditSessions(e,t)}_commitNext(){let n={stack:[],error:void 0,hasError:!1};try{let t=this.mostDownstreamPlugin;if(!t)return;this.tooltipManager?.storeConstraintSnapshot();let r=this.tooltipManager?.getFieldsToUnlockOnVertexPlacement()??[],i=!1,o=this.editGeometryOperations;e(n,o?a(o.on(`vertex-add`,()=>i=!0)):null,!1),t.completeStep?t.completeStep():this.complete(t),i&&this.tooltipManager?.unlockOnVertexPlacement(r)}catch(e){n.error=e,n.hasError=!0}finally{t(n)}}_suspendPlugin(e){this.lifecycleManager.suspend(e),this.measurementManager.suspendPlugin(e)}_resumePlugin(e){this.lifecycleManager.resume(e)}_updateLastScreenPosition(e){let t=_(e.x,e.y);return this.lastScreenPosition=t,t}_getContextForPlugin(e,t){let n=s(this._pluginContexts,e,()=>new F({drawTool:this,plugin:e,session:t}));return n.session=t,n}_before(e){if(!this.hasEventListener(`before-${e.action}`))return!1;let t=new CustomEvent(`before-${e.action}`,{detail:e,cancelable:!0});return this.emit(`before-${e.action}`,t),t.defaultPrevented}_guardCommand(e,t,n){return this._before(e)?n?.():t()}async _setupSegmentLabels(){let e=this.editGeometryOperations,t=this.toolOptions?.labels,n=!!t?.enabled,r=this.globalStateManager.segmentLabelsDisabled;if(!e||!t||!n){this._segmentLabels=c(this._segmentLabels);return}if(r){this._segmentLabels&&(this._segmentLabels.visible=!1);return}if(this._segmentLabels?.context?.editGeometryOperations===e&&this._segmentLabels.context.labelOptions===t){this._segmentLabels.visible=!0;return}let i=await this._createSegmentLabels(e,t);i&&(this._segmentLabels=c(this._segmentLabels),this._segmentLabels=i)}async _createSegmentLabels(e,t){this._segmentLabelsImportTask?.abort();let n=this._segmentLabelsImportTask=r(async n=>{if(this.view.type===`3d`){let r=import(`../3d/interactive/SegmentLabels3D.js`),{SegmentLabels3D:i}=await this._updatingHandles.addPromise(r);return this._isSegmentLabelsSetupStale(n,e,t)?null:new i({context:{view:this.view,editGeometryOperations:e,elevationInfo:D(this.hasZ,this.elevationInfo),labelOptions:t},visible:!0})}let r=import(`../2d/interactive/SegmentLabels2D.js`),{SegmentLabels2D:i}=await this._updatingHandles.addPromise(r);return this._isSegmentLabelsSetupStale(n,e,t)?null:new i({context:{view:this.view,editGeometryOperations:e,elevationInfo:D(this.hasZ,this.elevationInfo),labelOptions:t},visible:!0})});return u(n.promise)}_isSegmentLabelsSetupStale(e,t,n){return e.aborted||this.editGeometryOperations!==t||this.toolOptions?.labels!==n||!n.enabled||this.globalStateManager.segmentLabelsDisabled}};n([y()],$.prototype,`_commandsSuspended`,void 0),n([y()],$.prototype,`_zOfLastUserInput`,null),n([y()],$.prototype,`_snappingVisualizer`,void 0),n([y()],$.prototype,`_segmentLabels`,void 0),n([y()],$.prototype,`_segmentLabelsImportTask`,void 0),n([y()],$.prototype,`_tooltipDependencies`,null),n([y()],$.prototype,`_editSessionManagerContext`,null),n([y()],$.prototype,`_densificationParameters`,null),n([y({constructOnly:!0,nonNullable:!0})],$.prototype,`view`,void 0),n([y()],$.prototype,`automaticManipulatorSelection`,void 0),n([y()],$.prototype,`updating`,null),n([y()],$.prototype,`coordinateHelper`,null),n([y()],$.prototype,`editGeometry`,null),n([y()],$.prototype,`editGeometryOperations`,null),n([y()],$.prototype,`unprocessedGeometry`,null),n([y()],$.prototype,`simplifiedGeometryPreview`,null),n([y()],$.prototype,`_suppressCoincidentPointOverlaysIn3D`,null),n([y()],$.prototype,`_shapeVisualGeometry`,null),n([y()],$.prototype,`_vertexVisualGeometry`,null),n([y()],$.prototype,`snappingManager`,void 0),n([y()],$.prototype,`toolOptions`,void 0),n([y()],$.prototype,`disableTouchDrag`,void 0),n([y()],$.prototype,`elevationInfo`,void 0),n([y()],$.prototype,`hasZ`,void 0),n([y()],$.prototype,`defaultZ`,void 0),n([y()],$.prototype,`directionOptions`,void 0),n([y()],$.prototype,`canUndo`,null),n([y()],$.prototype,`canRedo`,null),n([y()],$.prototype,`pluginStack`,null),n([y()],$.prototype,`mostDownstreamPlugin`,null),n([y()],$.prototype,`mostUpstreamPlugin`,null),n([y()],$.prototype,`lastScreenPosition`,void 0),n([y()],$.prototype,`positionOfLastUserInput`,null),n([y()],$.prototype,`tooltipManager`,void 0),n([y()],$.prototype,`measurementManager`,void 0),n([y()],$.prototype,`globalStateManager`,void 0),n([y()],$.prototype,`editSessionManager`,void 0),n([y()],$.prototype,`lifecycleManager`,void 0),n([y()],$.prototype,`surfaceManager`,void 0),n([y()],$.prototype,`interactiveHandleManager`,void 0),n([y()],$.prototype,`renderer`,void 0),n([y()],$.prototype,`readPluginSetting`,void 0),n([y()],$.prototype,`movementCommandContext`,null),n([y()],$.prototype,`tooltip`,null),n([y()],$.prototype,`activeTooltipInfo`,null),n([y()],$.prototype,`helpMessageKey`,null),n([y({constructOnly:!0})],$.prototype,`enableVertexVisuals`,void 0),$=n([b(`esri.views.draw.DrawTool`)],$);export{$ as DrawTool};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{ignoreAbortErrors as n,debounce as r,isAbortError as i}from"../../../core/promiseUtils.js";import{pausable as a}from"../../../core/reactiveUtils.js";import{property as o,subclass as s}from"../../../core/accessorSupport/decorators.js";import{UpdatingHandles as c}from"../../../core/support/UpdatingHandles.js";let l=class extends t{constructor(e){super(e),this._debouncedMeasure=null,this._pausableWatch=null,this._inputWatch=null,this._lastSeenValue=void 0,this._getContext=null,this._updatingHandles=new c,this.field=null,this.appliesToHandlesWithRole=null,this.appliesToHandlesWithName=null,this.displayGroup=null}get name(){return this.field.name}get displayOrder(){return this.field.displayOrder}set displayOrder(e){this.field.displayOrder=e}get readOnly(){return this.field.readOnly}set
|
|
2
|
+
import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{ignoreAbortErrors as n,debounce as r,isAbortError as i}from"../../../core/promiseUtils.js";import{pausable as a}from"../../../core/reactiveUtils.js";import{property as o,subclass as s}from"../../../core/accessorSupport/decorators.js";import{UpdatingHandles as c}from"../../../core/support/UpdatingHandles.js";let l=class extends t{constructor(e){super(e),this._debouncedMeasure=null,this._pausableWatch=null,this._inputWatch=null,this._lastSeenValue=void 0,this._getContext=null,this._updatingHandles=new c,this.field=null,this.appliesToHandlesWithRole=null,this.appliesToHandlesWithName=null,this.displayGroup=null}get name(){return this.field.name}get displayOrder(){return this.field.displayOrder}set displayOrder(e){this.field.displayOrder=e}get readOnly(){return this.field.readOnly}set readOnly(e){this.field.readOnly=e}get lockable(){return this.field.lockable}set lockable(e){this.field.lockable=e}get unlockOnVertexPlacement(){return this.field.unlockOnVertexPlacement}set unlockOnVertexPlacement(e){this.field.unlockOnVertexPlacement=e}get parse(){return this.field.parse}set parse(e){this.field.parse=e}get format(){return this.field.format}set format(e){this.field.format=e}get formatForInputMode(){return this.field.formatForInputMode}set formatForInputMode(e){this.field.formatForInputMode=e}get suffix(){return this.field.suffix}set suffix(e){this.field.suffix=e}get enabled(){return this._get(`enabled`)}set enabled(e){this._set(`enabled`,e),e?(this._pausableWatch?.resume(),this._debouncedMeasure&&this._updatingHandles.addPromise(n(this._debouncedMeasure(this._inputWatch?.(),this._getContext?.(),this._lastSeenValue)))):this._pausableWatch?.pause()}get updating(){return this._updatingHandles.updating}setActual(e){this.field.setActual(e)}getCommitted(){return this.field.committed}getActual(){return this.field.actual}getInput(){return this.field.inputValue}registerMeasurement(e,t,o){this._inputWatch=e,this._getContext=o;let s=(e,n,r)=>t(e,n,r).then(e=>(this.setActual(e),e)).catch(e=>{if(!i(e))return this.setActual(null),null});this._debouncedMeasure=r(s);let c=this._pausableWatch=a(e,(e,t)=>{this._lastSeenValue=e,o()&&this._debouncedMeasure&&this._updatingHandles.addPromise(n(this._debouncedMeasure(e,o(),t)))});if(!this.enabled)c.pause();else{let t=e();this._updatingHandles.addPromise(n(this._debouncedMeasure(t,o(),void 0)))}this.addHandles(c)}show(){this.field.visible=!0}hide(){this.field.visible=!1}};e([o({constructOnly:!0})],l.prototype,`field`,void 0),e([o()],l.prototype,`name`,null),e([o()],l.prototype,`displayOrder`,null),e([o()],l.prototype,`readOnly`,null),e([o()],l.prototype,`lockable`,null),e([o()],l.prototype,`unlockOnVertexPlacement`,null),e([o()],l.prototype,`parse`,null),e([o()],l.prototype,`format`,null),e([o()],l.prototype,`formatForInputMode`,null),e([o()],l.prototype,`suffix`,null),e([o()],l.prototype,`appliesToHandlesWithRole`,void 0),e([o()],l.prototype,`appliesToHandlesWithName`,void 0),e([o()],l.prototype,`enabled`,null),e([o()],l.prototype,`displayGroup`,void 0),e([o()],l.prototype,`updating`,null),l=e([s(`esri.views.draw.support.ManagedTooltipField`)],l);export{l as ManagedTooltipField};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import e from"../../core/Logger.js";import{makeScheduleFunction as t}from"../3d/layers/support/makeScheduleFunction.js";import{TextureCompressionWorkerHandle as n}from"./TextureCompressionWorkerHandle.js";import r
|
|
2
|
+
import e from"../../core/Logger.js";import{makeScheduleFunction as t}from"../3d/layers/support/makeScheduleFunction.js";import{TextureCompressionWorkerHandle as n}from"./TextureCompressionWorkerHandle.js";import{Texture as r}from"../webgl/Texture.js";const i=new Set,a=()=>e.getLogger(`esri/views/support/TextureCompressionHelper`);function o(e,o){return r.compressionWorkerHandle??=new n(t(o)),i.has(e)?a().warn(`Repeated texture compression worker initialization by the same view.`):i.add(e),r.compressionWorkerHandle}function s(e){let t=r.compressionWorkerHandle;t&&(i.delete(e)||a().warn(`Unknown view attempted to destroy the texture compression worker.`),i.size||(t.destroyWorkerAndSelf(),r.compressionWorkerHandle=null))}export{s as destroyTextureCompressionWorker,o as initializeTextureCompressionWorker};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import e from"../../request.js";import t from"../../geometry/Point.js";import{projectExecute as n}from"../../geometry/operators/projectOperator.js";import{projectResolution as r,getProjectionOffsetGrid as i,load as a}from"../../layers/raster/functions/rasterProjectionHelper.js";import{isImageSource as o,rasterize as s}from"../2d/engine/Bitmap.js";import{RenderingDevice as c}from"../2d/engine/webgl/RenderingDevice.js";import{SimpleMesh as l}from"../2d/engine/webgl/meshing/SimpleMesh.js";import{ReprojectShader as u}from"../2d/engine/webgl/shaderGraph/techniques/shaders/raster/processor/ReprojectShader.js";import{PixelType as d}from"../webgl/enums.js";import{DisposableFramebufferObject as f}from"../webgl/FramebufferObject.js";import{createTransformTexture as p}from"../webgl/rasterUtils.js";import{RenderingContext as m}from"../webgl/RenderingContext.js";import{RenderingContextOptions as h}from"../webgl/RenderingContextOptions.js";import g
|
|
2
|
+
import e from"../../request.js";import t from"../../geometry/Point.js";import{projectExecute as n}from"../../geometry/operators/projectOperator.js";import{projectResolution as r,getProjectionOffsetGrid as i,load as a}from"../../layers/raster/functions/rasterProjectionHelper.js";import{isImageSource as o,rasterize as s}from"../2d/engine/Bitmap.js";import{RenderingDevice as c}from"../2d/engine/webgl/RenderingDevice.js";import{SimpleMesh as l}from"../2d/engine/webgl/meshing/SimpleMesh.js";import{ReprojectShader as u}from"../2d/engine/webgl/shaderGraph/techniques/shaders/raster/processor/ReprojectShader.js";import{PixelType as d}from"../webgl/enums.js";import{DisposableFramebufferObject as f}from"../webgl/FramebufferObject.js";import{createTransformTexture as p}from"../webgl/rasterUtils.js";import{RenderingContext as m}from"../webgl/RenderingContext.js";import{RenderingContextOptions as h}from"../webgl/RenderingContextOptions.js";import{Texture as g}from"../webgl/Texture.js";import{TextureDescriptor as _}from"../webgl/TextureDescriptor.js";const v={color:{blendMode:`none`,write:[!0,!0,!0,!0]},depth:!1,stencil:!1};class y{static{this._instanceRefCount=0}constructor(e){if(this._ownsRctx=!1,e)this._ownsRctx=!1,this._rctx=e;else{if(y._instance)return y._instanceRefCount++,y._instance;y._instanceRefCount=1,y._instance=this,this._ownsRctx=!0;let e=document.createElement(`canvas`).getContext(`webgl2`);e.getExtension(`OES_texture_float`),this._rctx=new m(e,new h)}this._renderingDevice=new c,this._renderingDevice.setPipelineState(v),this._shader=new u,this._quad=l.fromVertexStream(this._rctx,[0,0,1,0,0,1,1,1])}reprojectTexture(e,a,o=!1){let s=n(e.extent,a),c=new t({x:(e.extent.xmax-e.extent.xmin)/e.texture.descriptor.width,y:(e.extent.ymax-e.extent.ymin)/e.texture.descriptor.height,spatialReference:e.extent.spatialReference}),{x:l,y:u}=r(c,a,e.extent),m=(l+u)/2,h=Math.round((s.xmax-s.xmin)/m),g=Math.round((s.ymax-s.ymin)/m);m=(s.width/h+s.height/g)/2;let v=new t({x:m,y:m,spatialReference:s.spatialReference}),y=i({projectedExtent:s,srcBufferExtent:e.extent,pixelSize:v,hasWrapAround:!0,spacing:[16,16]}),b=p(this._rctx,y),x=new _(h,g);x.wrapMode=33071;let S=new f(this._rctx,x);if(this._rctx.bindFramebuffer(S),this._rctx.setViewport(0,0,h,g),this._drawReprojectedTexture(e.texture,b,{targetImageSize:[h,g],transformSpacing:y.spacing,transformGridSize:y.size}),this._rctx.useProgram(null),this._rctx.bindFramebuffer(null),b.dispose(),o){let{width:e,height:t}=S,n=new ImageData(e??0,t??0);S.readPixels(0,0,e??0,t??0,6408,d.UNSIGNED_BYTE,n.data);let r=S.detachColorTexture();return S.dispose(),{texture:r,extent:s,imageData:n}}let C=S.detachColorTexture();return S.dispose(),{texture:C,extent:s}}reprojectBitmapData(e,t){let n=o(e.bitmapData)?s(e.bitmapData):e.bitmapData,r=new _(e.bitmapData.width,e.bitmapData.height);r.wrapMode=33071;let i=new g(this._rctx,r,n),a=this.reprojectTexture({texture:i,extent:e.extent},t,!0);a.texture.dispose();let c=document.createElement(`canvas`),l=a.imageData;return c.width=l.width,c.height=l.height,c.getContext(`2d`).putImageData(l,0,0),{bitmapData:c,extent:a.extent}}async loadAndReprojectBitmapData(t,n,r){let[i]=await Promise.all([e(t,{responseType:`image`}).then(e=>e.data),a()]),o=document.createElement(`canvas`);o.width=i.width,o.height=i.height;let s=o.getContext(`2d`);s.drawImage(i,0,0);let c=s.getImageData(0,0,o.width,o.height);if(n.spatialReference.equals(r))return{bitmapData:c,extent:n};let l=this.reprojectBitmapData({bitmapData:c,extent:n},r);return{bitmapData:l.bitmapData,extent:l.extent}}_drawReprojectedTexture(e,t,n){let{width:r=0,height:i=0}=e.descriptor,a={coordScale:[1,1],srcImageSize:[r,i],opacity:1},o={texture:{texture:e,unit:0},projectionTextures:{transformTexture:{texture:t,unit:1}},pixelMaskTexture:null,highlightTexture:null},s={shader:this._shader,uniforms:{config:a,projectionConfig:n},textures:o,defines:{applyProjection:!0,lookupProjection:n.transformSpacing[0]===1,bilinear:!1,bicubic:!1,nearestOnEdge:!1,applyPixelMask:!1,applyPixelHighlights:!1},optionalAttributes:{},useComputeBuffer:!1};this._renderingDevice.setPipelineStateNeedsUpdate(!0),this._renderingDevice.submitDrawMesh(this._rctx,s,this._quad)}destroy(){this._ownsRctx?(y._instanceRefCount--,y._instanceRefCount===0&&(this._destroyWebGLResource(),this._rctx.dispose(),y._instance=null)):this._destroyWebGLResource()}_destroyWebGLResource(){this._quad.destroy(),this._renderingDevice.dispose()}}export{y as ImageReprojector};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import e from"../../core/Logger.js";import{disposeMaybe as t}from"../../core/maybe.js";import{BufferObject as n}from"./BufferObject.js";import{webglDebugEnabled as r}from"./checkWebGLError.js";import{ResourceType as i,ColorAttachment0 as a,PixelType as o,StencilAttachment as s,SizedDepthStencilFormat as c,DepthStencilAttachment as l,SizedDepthFormat as u,DepthAttachment as d}from"./enums.js";import{Renderbuffer as f}from"./Renderbuffer.js";import p from"./Texture.js";const m=()=>e.getLogger(`esri.views.webgl.FramebufferObject`);class h{constructor(e,t,n){if(this._context=e,this._level=0,this._glName=null,this._colorAttachments=new Map,this._depthStencilBuffer=null,this._depthStencilTexture=null,e.instanceCounter.increment(i.FramebufferObject,this),t!=null){let n=C(e,t);n!=null&&(this._colorAttachments.set(a,n),_(n)?this._validateTextureDescriptor(n.descriptor):this._validateRenderbufferDescriptor(n.descriptor)),this._validateColorAttachmentPoint(a)}if(n!=null){if(y(n))this._depthStencilTexture=_(n)?n:new p(e,n),this._validateTextureDescriptor(this._depthStencilTexture.descriptor);else{let t=v(n)?n:new f(e,n);this._depthStencilBuffer=t,this._validateRenderbufferDescriptor(t.descriptor)}}}get glName(){return this._glName}get colorTexture(){let e=this._colorAttachments.get(a);return _(e)?e:null}get depthStencil(){return this._depthStencilTexture||this._depthStencilBuffer}get depthStencilTexture(){return this._depthStencilTexture}get width(){return(this._colorAttachments.get(a)??this._depthStencilTexture??this._depthStencilBuffer)?.descriptor?.width??0}get height(){return(this._colorAttachments.get(a)??this._depthStencilTexture??this._depthStencilBuffer)?.descriptor?.height??0}get usedMemory(){return this._colorAttachments.values().reduce((e,t)=>e+t.usedMemory,this.depthStencil?.usedMemory??0)}get level(){return this._level}set level(e){this._level!==e&&(this._level=e,this._glName&&this._context.temporaryBindFramebuffer(this,()=>this._initializeAttachments()))}static{this._MAX_COLOR_ATTACHMENTS=-1}getColorTexture(e){let t=this._colorAttachments.get(e);return!t||!_(t)?null:t}get colorAttachments(){return Array.from(this._colorAttachments.keys())}attachColorTexture(e,t=a){if(!e)return;this._validateColorAttachmentPoint(t);let{descriptor:n}=e;this._validateTextureDescriptor(n),this.detachColorTexture(t)?.dispose(),this._colorAttachments.set(t,e),this._glName&&(this._context.bindFramebuffer(this),this._framebufferTexture2D(e.glName,t))}detachColorTexture(e=a){let t=this._colorAttachments.get(e);if(!t)return;let n=_(t);return this._glName&&this._context.temporaryBindFramebuffer(this,()=>{if(n)this._framebufferTexture2D(null,e);else{let t=this._context.gl;t.framebufferRenderbuffer(t.FRAMEBUFFER,e,t.RENDERBUFFER,null)}}),this._colorAttachments.delete(e),n?t:void 0}detachColorTextures(...e){if(e.length!==0){if(this._glName){let t=this._context.gl;this._context.temporaryBindFramebuffer(this,()=>{e.forEach(e=>{_(this._colorAttachments.get(e))?this._framebufferTexture2D(null,e):t.framebufferRenderbuffer(t.FRAMEBUFFER,e,t.RENDERBUFFER,null)})})}e.forEach(e=>this._colorAttachments.delete(e))}}setColorTextureTarget(e,t=a,n=0){let r=this._colorAttachments.get(t);r&&(e===35866?this._framebufferTextureLayer(r.glName,t,36160,n):this._framebufferTexture2D(r.glName,t,e,36160))}attachDepthStencil(e){if(e)switch(e.type){case 1:return this._attachDepthStencilTexture(e);case 2:return this._attachDepthStencilBuffer(e)}}_attachDepthStencilTexture(e){if(e==null)return;let{descriptor:t}=e,{pixelFormat:n,dataType:r}=t;n!==34041&&n!==6402?console.error(`Depth/Stencil texture must have a pixel type of DEPTH_STENCIL!`):n===34041&&r!==o.UNSIGNED_INT_24_8?console.error(`Depth/Stencil texture must have data type of UNSIGNED_INT_24_8!`):n===6402&&r!==o.UNSIGNED_INT&&r!==o.UNSIGNED_SHORT?console.error(`Depth texture must have data type of UNSIGNED_INT or UNSIGNED_SHORT!`):(this._validateTextureDescriptor(t),this._disposeDepthStencilAttachments(),this._glName&&(this._context.bindFramebuffer(this),this._framebufferTexture2D(e.glName,E(n))),this._depthStencilTexture?.dispose(),this._depthStencilTexture=e)}detachDepthStencilTexture(){let e=this._depthStencilTexture;return e&&this._glName&&this._context.temporaryBindFramebuffer(this,()=>{this._framebufferTexture2D(null,E(e.descriptor.pixelFormat))}),this._depthStencilTexture=null,e}_attachDepthStencilBuffer(e){if(e==null)return;let t=e.descriptor;if(this._validateRenderbufferDescriptor(t),this._disposeDepthStencilAttachments(),this._glName){this._context.bindFramebuffer(this);let{gl:n}=this._context,r=this._getGLAttachmentPoint(t);n.framebufferRenderbuffer(36160,r,n.RENDERBUFFER,e.glName)}this._depthStencilBuffer=e}detachDepthStencilBuffer(){let e=this._depthStencilBuffer;if(e&&this._glName){let{_context:t}=this,n=t.boundFramebuffer;t.bindFramebuffer(this);let{gl:r}=t,i=this._getGLAttachmentPoint(e.descriptor);r.framebufferRenderbuffer(36160,i,r.RENDERBUFFER,null),t.bindFramebuffer(n)}return this._depthStencilBuffer=null,e}invalidateAttachments(e){let{_context:t}=this;t.temporaryBindFramebuffer(this,()=>t.gl.invalidateFramebuffer(36160,e),!0)}copyToTexture(e,t,n,r,i,a,o){(e<0||t<0||i<0||a<0)&&console.error(`Offsets cannot be negative!`),(n<=0||r<=0)&&console.error(`Copy width and height must be greater than zero!`);let s=o.descriptor;o.descriptor.target!==3553&&console.error(`Texture target must be TEXTURE_2D!`),(s?.width==null||s?.height==null||e+n>this.width||t+r>this.height||i+n>s.width||a+r>s.height)&&console.error(`Bad dimensions, the current input values will attempt to read or copy out of bounds!`);let c=this._context,l=c.bindTexture(o,p.TEXTURE_UNIT_FOR_UPDATES);c.setActiveTexture(p.TEXTURE_UNIT_FOR_UPDATES),c.bindFramebuffer(this),c.gl.copyTexSubImage2D(3553,0,i,a,e,t,n,r),c.bindTexture(l,p.TEXTURE_UNIT_FOR_UPDATES)}readPixels(e,t,n,r,i,a,o){(n<=0||r<=0)&&console.error(`Copy width and height must be greater than zero!`),o||console.error(`Target memory is not initialized!`),this._context.bindFramebuffer(this),this._context.gl.readPixels(e,t,n,r,i,a,o)}async readPixelsAsync(e,t,r,i,a,o,s,c){let{gl:l}=this._context,u=n.createPixelPack(this._context,35041,s.byteLength);try{this._context.bindBuffer(u);let n=this._context.boundFramebuffer;try{this._context.bindFramebuffer(this),l.readPixels(e,t,r,i,a,o,0)}finally{this._context.unbindBuffer(35051),this._context.bindFramebuffer(n)}await u.getSubDataAsync(s,void 0,void 0,void 0,c)}finally{u.dispose()}}resize(e,t){if(this.width===e&&this.height===t)return;let n={width:e,height:t};if(w(n,this._context.parameters.maxTextureSize),this._colorAttachments.forEach(e=>e.resize(n.width,n.height)),this._depthStencilTexture?.resize(n.width,n.height),this._glName&&(w(n,this._context.parameters.maxRenderbufferSize),this._depthStencilBuffer?.resize(n.width,n.height),r())){let{gl:e}=this._context;e.checkFramebufferStatus(36160)!==e.FRAMEBUFFER_COMPLETE&&console.error(`Framebuffer is incomplete!`)}}initializeAndBind(e=36160){let{gl:t}=this._context;this._glName?t.bindFramebuffer(e,this._glName):(this._glName&&t.deleteFramebuffer(this._glName),this._glName=t.createFramebuffer(),t.bindFramebuffer(e,this._glName),this._initializeAttachments(e))}_initializeAttachments(e=36160){let{gl:t}=this._context;if(this._colorAttachments.forEach((t,n)=>{if(_(t)){let r=T(t);r===35866?this._framebufferTextureLayer(t.glName,n,e):this._framebufferTexture2D(t.glName,n,r,e)}else if(v(t)){let r=this._context.gl;r.framebufferRenderbuffer(e,n,r.RENDERBUFFER,t.glName)}}),this._depthStencilBuffer){let n=this._getGLAttachmentPoint(this._depthStencilBuffer.descriptor);t.framebufferRenderbuffer(e,n,t.RENDERBUFFER,this._depthStencilBuffer.glName)}else if(this._depthStencilTexture){let t=E(this._depthStencilTexture.descriptor.pixelFormat);this._framebufferTexture2D(this._depthStencilTexture.glName,t,T(this._depthStencilTexture),e)}r()&&t.checkFramebufferStatus(e)!==t.FRAMEBUFFER_COMPLETE&&console.error(`Framebuffer is incomplete!`)}_framebufferTexture2D(e,t=a,n=3553,r=36160){this._context.gl.framebufferTexture2D(r,t,n,e,this._level)}_framebufferTextureLayer(e,t=a,n=36160,r=0){this._context.gl.framebufferTextureLayer(n,t,e,this._level,r)}_disposeDepthStencilAttachments(){let e=this._context.gl;if(this._depthStencilBuffer){if(this._glName){this._context.bindFramebuffer(this);let t=this._getGLAttachmentPoint(this._depthStencilBuffer.descriptor);e.framebufferRenderbuffer(36160,t,e.RENDERBUFFER,null)}this._depthStencilBuffer=t(this._depthStencilBuffer)}this._depthStencilTexture&&=(this._glName&&(this._context.bindFramebuffer(this),this._framebufferTexture2D(null,E(this._depthStencilTexture.descriptor.pixelFormat))),t(this._depthStencilTexture))}_validateTextureDescriptor(e){e.target!==3553&&e.target!==34067&&e.target!==35866&&console.error(`Texture type must be TEXTURE_2D, TEXTURE_2D_ARRAY or TEXTURE_CUBE_MAP!`),w(e,this._context.parameters.maxTextureSize),this._validateBufferDimensions(e)}_validateRenderbufferDescriptor(e){w(e,this._context.parameters.maxRenderbufferSize),this._validateBufferDimensions(e)}_validateBufferDimensions(e){e.width<=0&&(e.width=this.width),e.height<=0&&(e.height=this.height),this.width>0&&this.height>0&&(this.width!==e.width||this.height!==e.height)&&console.error(`Attachment size must match framebuffer size!`)}_getGLAttachmentPoint(e){switch(e.internalFormat){case u.DEPTH_COMPONENT16:case u.DEPTH_COMPONENT24:case u.DEPTH_COMPONENT32F:return d;case c.DEPTH24_STENCIL8:case c.DEPTH32F_STENCIL8:return l;case 36168:return s;default:return a}}_validateColorAttachmentPoint(t){if(h._MAX_COLOR_ATTACHMENTS===-1){let{gl:e}=this._context;h._MAX_COLOR_ATTACHMENTS=e.getParameter(e.MAX_COLOR_ATTACHMENTS)}let n=t-a;n+1>h._MAX_COLOR_ATTACHMENTS&&e.getLogger(`esri.views.webgl.FrameBufferObject`).error(`esri.FrameBufferObject`,`illegal attachment point for color attachment: ${n+1}. Implementation supports up to ${h._MAX_COLOR_ATTACHMENTS} color attachments`)}}class g extends h{constructor(e,t,n){super(e,t,n)}dispose(){let{_colorAttachments:e,_glName:t,_context:n}=this;if(n.instanceCounter.decrement(i.FramebufferObject,this),e.size===0&&!this._depthStencilBuffer&&!this._depthStencilTexture&&!t)return;let r=n.boundFramebuffer,a=Array.from(e.values());this.detachColorTextures(...e.keys()),a.forEach(e=>e.dispose()),this.detachDepthStencilBuffer()?.dispose(),this.detachDepthStencilTexture()?.dispose(),n.gl.deleteFramebuffer(this._glName),this._glName=null,n.bindFramebuffer(r===this?null:r)}}function _(e){return S(e)===1}function v(e){return S(e)===2}function y(e){return _(e)||b(e)}function b(e){return S(e)===0}function x(e){return S(e)===3||e!=null&&`samples`in e}function S(e){return e!=null&&`type`in e?e.type:null}function C(e,t){return _(t)||v(t)?t:b(t)?new p(e,t):x(t)?new f(e,t):null}function w(e,t){let n=Math.max(e.width,e.height);if(n>t){m().warnOnce(`Resizing FBO attachment size ${e.width}x${e.height} to device limit ${t}`);let r=t/n;return e.width=Math.round(e.width*r),e.height=Math.round(e.height*r),!1}return!0}function T(e){return e.descriptor.target===34067?34069:e.descriptor.target===35866?35866:3553}function E(e){return e===6402?d:l}export{g as DisposableFramebufferObject,h as FramebufferObject,w as ensureAttachmentMaxSize};
|
|
2
|
+
import e from"../../core/Logger.js";import{disposeMaybe as t}from"../../core/maybe.js";import{BufferObject as n}from"./BufferObject.js";import{webglDebugEnabled as r}from"./checkWebGLError.js";import{ResourceType as i,ColorAttachment0 as a,PixelType as o,StencilAttachment as s,SizedDepthStencilFormat as c,DepthStencilAttachment as l,SizedDepthFormat as u,DepthAttachment as d}from"./enums.js";import{Renderbuffer as f}from"./Renderbuffer.js";import{Texture as p}from"./Texture.js";const m=()=>e.getLogger(`esri.views.webgl.FramebufferObject`);class h{constructor(e,t,n){if(this._context=e,this._level=0,this._glName=null,this._colorAttachments=new Map,this._depthStencilBuffer=null,this._depthStencilTexture=null,e.instanceCounter.increment(i.FramebufferObject,this),t!=null){let n=C(e,t);n!=null&&(this._colorAttachments.set(a,n),_(n)?this._validateTextureDescriptor(n.descriptor):this._validateRenderbufferDescriptor(n.descriptor)),this._validateColorAttachmentPoint(a)}if(n!=null){if(y(n))this._depthStencilTexture=_(n)?n:new p(e,n),this._validateTextureDescriptor(this._depthStencilTexture.descriptor);else{let t=v(n)?n:new f(e,n);this._depthStencilBuffer=t,this._validateRenderbufferDescriptor(t.descriptor)}}}get glName(){return this._glName}get colorTexture(){let e=this._colorAttachments.get(a);return _(e)?e:null}get depthStencil(){return this._depthStencilTexture||this._depthStencilBuffer}get depthStencilTexture(){return this._depthStencilTexture}get width(){return(this._colorAttachments.get(a)??this._depthStencilTexture??this._depthStencilBuffer)?.descriptor?.width??0}get height(){return(this._colorAttachments.get(a)??this._depthStencilTexture??this._depthStencilBuffer)?.descriptor?.height??0}get usedMemory(){return this._colorAttachments.values().reduce((e,t)=>e+t.usedMemory,this.depthStencil?.usedMemory??0)}get level(){return this._level}set level(e){this._level!==e&&(this._level=e,this._glName&&this._context.temporaryBindFramebuffer(this,()=>this._initializeAttachments()))}static{this._MAX_COLOR_ATTACHMENTS=-1}getColorTexture(e){let t=this._colorAttachments.get(e);return!t||!_(t)?null:t}get colorAttachments(){return Array.from(this._colorAttachments.keys())}attachColorTexture(e,t=a){if(!e)return;this._validateColorAttachmentPoint(t);let{descriptor:n}=e;this._validateTextureDescriptor(n),this.detachColorTexture(t)?.dispose(),this._colorAttachments.set(t,e),this._glName&&(this._context.bindFramebuffer(this),this._framebufferTexture2D(e.glName,t))}detachColorTexture(e=a){let t=this._colorAttachments.get(e);if(!t)return;let n=_(t);return this._glName&&this._context.temporaryBindFramebuffer(this,()=>{if(n)this._framebufferTexture2D(null,e);else{let t=this._context.gl;t.framebufferRenderbuffer(t.FRAMEBUFFER,e,t.RENDERBUFFER,null)}}),this._colorAttachments.delete(e),n?t:void 0}detachColorTextures(...e){if(e.length!==0){if(this._glName){let t=this._context.gl;this._context.temporaryBindFramebuffer(this,()=>{e.forEach(e=>{_(this._colorAttachments.get(e))?this._framebufferTexture2D(null,e):t.framebufferRenderbuffer(t.FRAMEBUFFER,e,t.RENDERBUFFER,null)})})}e.forEach(e=>this._colorAttachments.delete(e))}}setColorTextureTarget(e,t=a,n=0){let r=this._colorAttachments.get(t);r&&(e===35866?this._framebufferTextureLayer(r.glName,t,36160,n):this._framebufferTexture2D(r.glName,t,e,36160))}attachDepthStencil(e){if(e)switch(e.type){case 1:return this._attachDepthStencilTexture(e);case 2:return this._attachDepthStencilBuffer(e)}}_attachDepthStencilTexture(e){if(e==null)return;let{descriptor:t}=e,{pixelFormat:n,dataType:r}=t;n!==34041&&n!==6402?console.error(`Depth/Stencil texture must have a pixel type of DEPTH_STENCIL!`):n===34041&&r!==o.UNSIGNED_INT_24_8?console.error(`Depth/Stencil texture must have data type of UNSIGNED_INT_24_8!`):n===6402&&r!==o.UNSIGNED_INT&&r!==o.UNSIGNED_SHORT?console.error(`Depth texture must have data type of UNSIGNED_INT or UNSIGNED_SHORT!`):(this._validateTextureDescriptor(t),this._disposeDepthStencilAttachments(),this._glName&&(this._context.bindFramebuffer(this),this._framebufferTexture2D(e.glName,E(n))),this._depthStencilTexture?.dispose(),this._depthStencilTexture=e)}detachDepthStencilTexture(){let e=this._depthStencilTexture;return e&&this._glName&&this._context.temporaryBindFramebuffer(this,()=>{this._framebufferTexture2D(null,E(e.descriptor.pixelFormat))}),this._depthStencilTexture=null,e}_attachDepthStencilBuffer(e){if(e==null)return;let t=e.descriptor;if(this._validateRenderbufferDescriptor(t),this._disposeDepthStencilAttachments(),this._glName){this._context.bindFramebuffer(this);let{gl:n}=this._context,r=this._getGLAttachmentPoint(t);n.framebufferRenderbuffer(36160,r,n.RENDERBUFFER,e.glName)}this._depthStencilBuffer=e}detachDepthStencilBuffer(){let e=this._depthStencilBuffer;if(e&&this._glName){let{_context:t}=this,n=t.boundFramebuffer;t.bindFramebuffer(this);let{gl:r}=t,i=this._getGLAttachmentPoint(e.descriptor);r.framebufferRenderbuffer(36160,i,r.RENDERBUFFER,null),t.bindFramebuffer(n)}return this._depthStencilBuffer=null,e}invalidateAttachments(e){let{_context:t}=this;t.temporaryBindFramebuffer(this,()=>t.gl.invalidateFramebuffer(36160,e),!0)}copyToTexture(e,t,n,r,i,a,o){(e<0||t<0||i<0||a<0)&&console.error(`Offsets cannot be negative!`),(n<=0||r<=0)&&console.error(`Copy width and height must be greater than zero!`);let s=o.descriptor;o.descriptor.target!==3553&&console.error(`Texture target must be TEXTURE_2D!`),(s?.width==null||s?.height==null||e+n>this.width||t+r>this.height||i+n>s.width||a+r>s.height)&&console.error(`Bad dimensions, the current input values will attempt to read or copy out of bounds!`);let c=this._context,l=c.bindTexture(o,p.TEXTURE_UNIT_FOR_UPDATES);c.setActiveTexture(p.TEXTURE_UNIT_FOR_UPDATES),c.bindFramebuffer(this),c.gl.copyTexSubImage2D(3553,0,i,a,e,t,n,r),c.bindTexture(l,p.TEXTURE_UNIT_FOR_UPDATES)}readPixels(e,t,n,r,i,a,o){(n<=0||r<=0)&&console.error(`Copy width and height must be greater than zero!`),o||console.error(`Target memory is not initialized!`),this._context.bindFramebuffer(this),this._context.gl.readPixels(e,t,n,r,i,a,o)}async readPixelsAsync(e,t,r,i,a,o,s,c){let{gl:l}=this._context,u=n.createPixelPack(this._context,35041,s.byteLength);try{this._context.bindBuffer(u);let n=this._context.boundFramebuffer;try{this._context.bindFramebuffer(this),l.readPixels(e,t,r,i,a,o,0)}finally{this._context.unbindBuffer(35051),this._context.bindFramebuffer(n)}await u.getSubDataAsync(s,void 0,void 0,void 0,c)}finally{u.dispose()}}resize(e,t){if(this.width===e&&this.height===t)return;let n={width:e,height:t};if(w(n,this._context.parameters.maxTextureSize),this._colorAttachments.forEach(e=>e.resize(n.width,n.height)),this._depthStencilTexture?.resize(n.width,n.height),this._glName&&(w(n,this._context.parameters.maxRenderbufferSize),this._depthStencilBuffer?.resize(n.width,n.height),r())){let{gl:e}=this._context;e.checkFramebufferStatus(36160)!==e.FRAMEBUFFER_COMPLETE&&console.error(`Framebuffer is incomplete!`)}}initializeAndBind(e=36160){let{gl:t}=this._context;this._glName?t.bindFramebuffer(e,this._glName):(this._glName&&t.deleteFramebuffer(this._glName),this._glName=t.createFramebuffer(),t.bindFramebuffer(e,this._glName),this._initializeAttachments(e))}_initializeAttachments(e=36160){let{gl:t}=this._context;if(this._colorAttachments.forEach((t,n)=>{if(_(t)){let r=T(t);r===35866?this._framebufferTextureLayer(t.glName,n,e):this._framebufferTexture2D(t.glName,n,r,e)}else if(v(t)){let r=this._context.gl;r.framebufferRenderbuffer(e,n,r.RENDERBUFFER,t.glName)}}),this._depthStencilBuffer){let n=this._getGLAttachmentPoint(this._depthStencilBuffer.descriptor);t.framebufferRenderbuffer(e,n,t.RENDERBUFFER,this._depthStencilBuffer.glName)}else if(this._depthStencilTexture){let t=E(this._depthStencilTexture.descriptor.pixelFormat);this._framebufferTexture2D(this._depthStencilTexture.glName,t,T(this._depthStencilTexture),e)}r()&&t.checkFramebufferStatus(e)!==t.FRAMEBUFFER_COMPLETE&&console.error(`Framebuffer is incomplete!`)}_framebufferTexture2D(e,t=a,n=3553,r=36160){this._context.gl.framebufferTexture2D(r,t,n,e,this._level)}_framebufferTextureLayer(e,t=a,n=36160,r=0){this._context.gl.framebufferTextureLayer(n,t,e,this._level,r)}_disposeDepthStencilAttachments(){let e=this._context.gl;if(this._depthStencilBuffer){if(this._glName){this._context.bindFramebuffer(this);let t=this._getGLAttachmentPoint(this._depthStencilBuffer.descriptor);e.framebufferRenderbuffer(36160,t,e.RENDERBUFFER,null)}this._depthStencilBuffer=t(this._depthStencilBuffer)}this._depthStencilTexture&&=(this._glName&&(this._context.bindFramebuffer(this),this._framebufferTexture2D(null,E(this._depthStencilTexture.descriptor.pixelFormat))),t(this._depthStencilTexture))}_validateTextureDescriptor(e){e.target!==3553&&e.target!==34067&&e.target!==35866&&console.error(`Texture type must be TEXTURE_2D, TEXTURE_2D_ARRAY or TEXTURE_CUBE_MAP!`),w(e,this._context.parameters.maxTextureSize),this._validateBufferDimensions(e)}_validateRenderbufferDescriptor(e){w(e,this._context.parameters.maxRenderbufferSize),this._validateBufferDimensions(e)}_validateBufferDimensions(e){e.width<=0&&(e.width=this.width),e.height<=0&&(e.height=this.height),this.width>0&&this.height>0&&(this.width!==e.width||this.height!==e.height)&&console.error(`Attachment size must match framebuffer size!`)}_getGLAttachmentPoint(e){switch(e.internalFormat){case u.DEPTH_COMPONENT16:case u.DEPTH_COMPONENT24:case u.DEPTH_COMPONENT32F:return d;case c.DEPTH24_STENCIL8:case c.DEPTH32F_STENCIL8:return l;case 36168:return s;default:return a}}_validateColorAttachmentPoint(t){if(h._MAX_COLOR_ATTACHMENTS===-1){let{gl:e}=this._context;h._MAX_COLOR_ATTACHMENTS=e.getParameter(e.MAX_COLOR_ATTACHMENTS)}let n=t-a;n+1>h._MAX_COLOR_ATTACHMENTS&&e.getLogger(`esri.views.webgl.FrameBufferObject`).error(`esri.FrameBufferObject`,`illegal attachment point for color attachment: ${n+1}. Implementation supports up to ${h._MAX_COLOR_ATTACHMENTS} color attachments`)}}class g extends h{constructor(e,t,n){super(e,t,n)}dispose(){let{_colorAttachments:e,_glName:t,_context:n}=this;if(n.instanceCounter.decrement(i.FramebufferObject,this),e.size===0&&!this._depthStencilBuffer&&!this._depthStencilTexture&&!t)return;let r=n.boundFramebuffer,a=Array.from(e.values());this.detachColorTextures(...e.keys()),a.forEach(e=>e.dispose()),this.detachDepthStencilBuffer()?.dispose(),this.detachDepthStencilTexture()?.dispose(),n.gl.deleteFramebuffer(this._glName),this._glName=null,n.bindFramebuffer(r===this?null:r)}}function _(e){return S(e)===1}function v(e){return S(e)===2}function y(e){return _(e)||b(e)}function b(e){return S(e)===0}function x(e){return S(e)===3||e!=null&&`samples`in e}function S(e){return e!=null&&`type`in e?e.type:null}function C(e,t){return _(t)||v(t)?t:b(t)?new p(e,t):x(t)?new f(e,t):null}function w(e,t){let n=Math.max(e.width,e.height);if(n>t){m().warnOnce(`Resizing FBO attachment size ${e.width}x${e.height} to device limit ${t}`);let r=t/n;return e.width=Math.round(e.width*r),e.height=Math.round(e.height*r),!1}return!0}function T(e){return e.descriptor.target===34067?34069:e.descriptor.target===35866?35866:3553}function E(e){return e===6402?d:l}export{g as DisposableFramebufferObject,h as FramebufferObject,w as ensureAttachmentMaxSize};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import has from"../../core/has.js";import e from"../../core/Logger.js";import{disposeMaybe as t}from"../../core/maybe.js";import{after as n}from"../../core/promiseUtils.js";import{Milliseconds as r}from"../../core/time.js";import{webglDebugEnabled as i,checkWebGLError as a,getErrorMessage as o,webglValidateShadersEnabled as s}from"./checkWebGLError.js";import{ContextState as c}from"./ContextState.js";import{baseTextureUnit as l,DrawBufferBack as u,DrawBufferNone as d,ResourceType as f,ColorAttachment0 as p,PrimitiveType as m}from"./enums.js";import{InstanceCounter as h}from"./InstanceCounter.js";import{Parameters as g}from"./Parameters.js";import{ProgramCache as _}from"./ProgramCache.js";import{StateTracker as v}from"./renderState.js";import y from"./Texture.js";import{WebGLDriverTest as b}from"./WebGLDriverTest.js";import{Capabilities as x}from"./capabilities/Capabilities.js";const S=()=>e.getLogger(`esri.views.webgl.RenderingContext`);let C=class{constructor(e,t){this.gl=e,this.instanceCounter=new h,this._programCache=new _(this),this._transformFeedbackRequestInfo=null,this._state=new c,this._numOfDrawCalls=0,this._numOfTriangles=0,this._options=t,this.configure(t)}configure(e){this._options=e,this._capabilities=new x(this.gl,e),this._parameters=new g(this.gl,this._capabilities,e),y.TEXTURE_UNIT_FOR_UPDATES=this._parameters.maxTextureImageUnits-1;let n=this.gl.getParameter(this.gl.VIEWPORT);this._state=new c,this._state.viewport={x:n[0],y:n[1],width:n[2],height:n[3]},this._stateTracker=new v({setBlending:e=>{if(e){this.setBlendingEnabled(!0),this.setBlendEquationSeparate(e.opRgb,e.opAlpha),this.setBlendFunctionSeparate(e.srcRgb,e.dstRgb,e.srcAlpha,e.dstAlpha);let t=e.color;this.setBlendColor(t.r,t.g,t.b,t.a)}else this.setBlendingEnabled(!1)},setCulling:e=>{e?(this.setFaceCullingEnabled(!0),this.setCullFace(e.face),this.setFrontFace(e.mode)):this.setFaceCullingEnabled(!1)},setPolygonOffset:e=>{e?(this.setPolygonOffsetFillEnabled(!0),this.setPolygonOffset(e.factor,e.units)):this.setPolygonOffsetFillEnabled(!1)},setDepthTest:e=>{e?(this.setDepthTestEnabled(!0),this.setDepthFunction(e.func)):this.setDepthTestEnabled(!1)},setStencilTest:e=>{if(e){this.setStencilTestEnabled(!0);let{ref:t,readMask:n,stencilFront:r,stencilBack:i}=e;r.compare===i.compare?this.setStencilFunction(r.compare,t,n):(this.setStencilFunctionSeparate(1028,r.compare,t,n),this.setStencilFunctionSeparate(1029,i.compare,t,n)),r.fail===i.fail&&r.zFail===i.zFail&&r.zPass===i.zPass?this.setStencilOp(r.fail,r.zFail,r.zPass):(this.setStencilOpSeparate(1028,r.fail,r.zFail,r.zPass),this.setStencilOpSeparate(1029,i.fail,i.zFail,i.zPass))}else this.setStencilTestEnabled(!1)},setDepthWrite:e=>{e?(this.setDepthWriteEnabled(!0),this.setDepthRange(e.zNear,e.zFar)):this.setDepthWriteEnabled(!1)},setColorWrite:e=>{e?this.setColorMask(e.r,e.g,e.b,e.a):this.setColorMask(!1,!1,!1,!1)},setStencilWrite:e=>{e?this.setStencilWriteMask(e.mask):this.setStencilWriteMask(0)}}),this.enforceState(),t(this._driverTest),this._driverTest=new b(this)}updateOptions(e){this._options={...this._options,...e},this._parameters=new g(this.gl,this._capabilities,this._options)}dispose(){this._driverTest=t(this._driverTest),this._programCache=t(this._programCache),this.bindVAO(null),this.unbindBuffer(34962),this.unbindBuffer(34963),this.unbindBuffer(35345),this.bindUniformBufferBindingPoints([]),this.unbindBuffer(35051),this.unbindBuffer(35052),this.unbindBuffer(36662),this.unbindBuffer(36663),this._state.textureUnitMap.length=0,this._state.textureUnitSamplerMap.length=0,this._state=null,this._capabilities=null,this._stateTracker=null;let e=i()&&this.instanceCounter.resourceInformation;e&&console.log(e)}get driverTest(){return this._driverTest}get contextAttributes(){return this.gl.getContextAttributes()}get parameters(){return this._parameters}get programCache(){return this._programCache}setPipelineState(e){this._stateTracker.setPipeline(e)}getPipelineState(){return this._stateTracker.getPipelineState()}setBlendingEnabled(e){this._state.blend!==e&&(e===!0?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this._state.blend=e,this._stateTracker.invalidateBlending())}externalProgramUpdate(){this._state.program?.stop(),this._state.program=null}externalTextureUnitUpdate(e,t){for(let t=0;t<e.length;++t){let n=e[t];this._state.textureUnitMap[n]=null,this._state.textureUnitSamplerMap[n]=null}t>=0&&(this._state.activeTexture=t)}externalVertexArrayObjectUpdate(){this.gl.bindVertexArray(null),this._state.vertexArrayObject=null,this._state.vertexBuffer=null,this._state.indexBuffer=null}externalVertexBufferUpdate(){this._state.vertexBuffer=null}externalIndexBufferUpdate(){this._state.indexBuffer=null}setBlendColor(e,t,n,r){(e!==this._state.blendColor.r||t!==this._state.blendColor.g||n!==this._state.blendColor.b||r!==this._state.blendColor.a)&&(this.gl.blendColor(e,t,n,r),this._state.blendColor.r=e,this._state.blendColor.g=t,this._state.blendColor.b=n,this._state.blendColor.a=r,this._stateTracker.invalidateBlending())}setBlendFunction(e,t){(e!==this._state.blendFunction.srcRGB||t!==this._state.blendFunction.dstRGB)&&(this.gl.blendFunc(e,t),this._state.blendFunction.srcRGB=e,this._state.blendFunction.srcAlpha=e,this._state.blendFunction.dstRGB=t,this._state.blendFunction.dstAlpha=t,this._stateTracker.invalidateBlending())}setBlendFunctionSeparate(e,t,n,r){(this._state.blendFunction.srcRGB!==e||this._state.blendFunction.srcAlpha!==n||this._state.blendFunction.dstRGB!==t||this._state.blendFunction.dstAlpha!==r)&&(this.gl.blendFuncSeparate(e,t,n,r),this._state.blendFunction.srcRGB=e,this._state.blendFunction.srcAlpha=n,this._state.blendFunction.dstRGB=t,this._state.blendFunction.dstAlpha=r,this._stateTracker.invalidateBlending())}setBlendEquation(e){this._state.blendEquation.mode!==e&&(this.gl.blendEquation(e),this._state.blendEquation.mode=e,this._state.blendEquation.modeAlpha=e,this._stateTracker.invalidateBlending())}setBlendEquationSeparate(e,t){(this._state.blendEquation.mode!==e||this._state.blendEquation.modeAlpha!==t)&&(this.gl.blendEquationSeparate(e,t),this._state.blendEquation.mode=e,this._state.blendEquation.modeAlpha=t,this._stateTracker.invalidateBlending())}setColorMask(e,t,n,r){(this._state.colorMask.r!==e||this._state.colorMask.g!==t||this._state.colorMask.b!==n||this._state.colorMask.a!==r)&&(this.gl.colorMask(e,t,n,r),this._state.colorMask.r=e,this._state.colorMask.g=t,this._state.colorMask.b=n,this._state.colorMask.a=r,this._stateTracker.invalidateColorWrite())}setClearColor(e,t,n,r){(this._state.clearColor.r!==e||this._state.clearColor.g!==t||this._state.clearColor.b!==n||this._state.clearColor.a!==r)&&(this.gl.clearColor(e,t,n,r),this._state.clearColor.r=e,this._state.clearColor.g=t,this._state.clearColor.b=n,this._state.clearColor.a=r)}setFaceCullingEnabled(e){this._state.faceCulling!==e&&(e===!0?this.gl.enable(this.gl.CULL_FACE):this.gl.disable(this.gl.CULL_FACE),this._state.faceCulling=e,this._stateTracker.invalidateCulling())}setPolygonOffsetFillEnabled(e){this._state.polygonOffsetFill!==e&&(e===!0?this.gl.enable(this.gl.POLYGON_OFFSET_FILL):this.gl.disable(this.gl.POLYGON_OFFSET_FILL),this._state.polygonOffsetFill=e,this._stateTracker.invalidatePolygonOffset())}setPolygonOffset(e,t){(this._state.polygonOffset[0]!==e||this._state.polygonOffset[1]!==t)&&(this._state.polygonOffset[0]=e,this._state.polygonOffset[1]=t,this.gl.polygonOffset(e,t),this._stateTracker.invalidatePolygonOffset())}setCullFace(e){this._state.cullFace!==e&&(this.gl.cullFace(e),this._state.cullFace=e,this._stateTracker.invalidateCulling())}setFrontFace(e){this._state.frontFace!==e&&(this.gl.frontFace(e),this._state.frontFace=e,this._stateTracker.invalidateCulling())}setScissorTestEnabled(e){this._state.scissorTest!==e&&(e===!0?this.gl.enable(this.gl.SCISSOR_TEST):this.gl.disable(this.gl.SCISSOR_TEST),this._state.scissorTest=e)}setScissorRect(e,t,n,r){(this._state.scissorRect.x!==e||this._state.scissorRect.y!==t||this._state.scissorRect.width!==n||this._state.scissorRect.height!==r)&&(this.gl.scissor(e,t,n,r),this._state.scissorRect.x=e,this._state.scissorRect.y=t,this._state.scissorRect.width=n,this._state.scissorRect.height=r)}setDepthTestEnabled(e){this._state.depthTest!==e&&(e===!0?this.gl.enable(this.gl.DEPTH_TEST):this.gl.disable(this.gl.DEPTH_TEST),this._state.depthTest=e,this._stateTracker.invalidateDepthTest())}setClearDepth(e){this._state.clearDepth!==e&&(this.gl.clearDepth(e),this._state.clearDepth=e)}setDepthFunction(e){this._state.depthFunction!==e&&(this.gl.depthFunc(e),this._state.depthFunction=e,this._stateTracker.invalidateDepthTest())}setDepthWriteEnabled(e){this._state.depthWrite!==e&&(this.gl.depthMask(e),this._state.depthWrite=e,this._stateTracker.invalidateDepthWrite())}setDepthRange(e,t){(this._state.depthRange.zNear!==e||this._state.depthRange.zFar!==t)&&(this.gl.depthRange(e,t),this._state.depthRange.zNear=e,this._state.depthRange.zFar=t,this._stateTracker.invalidateDepthWrite())}setStencilTestEnabled(e){this._state.stencilTest!==e&&(e===!0?this.gl.enable(this.gl.STENCIL_TEST):this.gl.disable(this.gl.STENCIL_TEST),this._state.stencilTest=e,this._stateTracker.invalidateStencilTest())}setClearStencil(e){e!==this._state.clearStencil&&(this.gl.clearStencil(e),this._state.clearStencil=e)}setStencilFunction(e,t,n){(this._state.stencilFunction.face!==1032||this._state.stencilFunction.func!==e||this._state.stencilFunction.ref!==t||this._state.stencilFunction.mask!==n)&&(this.gl.stencilFunc(e,t,n),this._state.stencilFunction.face=1032,this._state.stencilFunction.func=e,this._state.stencilFunction.ref=t,this._state.stencilFunction.mask=n,this._stateTracker.invalidateStencilTest())}setStencilFunctionSeparate(e,t,n,r){(this._state.stencilFunction.face!==e||this._state.stencilFunction.func!==t||this._state.stencilFunction.ref!==n||this._state.stencilFunction.mask!==r)&&(this.gl.stencilFuncSeparate(e,t,n,r),this._state.stencilFunction.face=e,this._state.stencilFunction.func=t,this._state.stencilFunction.ref=n,this._state.stencilFunction.mask=r,this._stateTracker.invalidateStencilTest())}setStencilWriteMask(e){this._state.stencilWriteMask!==e&&(this.gl.stencilMask(e),this._state.stencilWriteMask=e,this._stateTracker.invalidateStencilWrite())}setStencilOp(e,t,n){(this._state.stencilOperation.face!==1032||this._state.stencilOperation.fail!==e||this._state.stencilOperation.zFail!==t||this._state.stencilOperation.zPass!==n)&&(this.gl.stencilOp(e,t,n),this._state.stencilOperation.face=1032,this._state.stencilOperation.fail=e,this._state.stencilOperation.zFail=t,this._state.stencilOperation.zPass=n,this._stateTracker.invalidateStencilTest())}setStencilOpSeparate(e,t,n,r){(this._state.stencilOperation.face!==e||this._state.stencilOperation.fail!==t||this._state.stencilOperation.zFail!==n||this._state.stencilOperation.zPass!==r)&&(this.gl.stencilOpSeparate(e,t,n,r),this._state.stencilOperation.face=e,this._state.stencilOperation.fail=t,this._state.stencilOperation.zFail=n,this._state.stencilOperation.zPass=r,this._stateTracker.invalidateStencilTest())}setActiveTexture(e,t=!1){let n=this._state.activeTexture;return e>=0&&(t||e!==this._state.activeTexture)&&(this.gl.activeTexture(l+e),this._state.activeTexture=e),n}setDrawBuffers(e){let t=this.drawBuffers;if(t.length===e.length&&t.every((t,n)=>t===e[n]))return t;if(e.length>this.parameters.maxDrawBuffers)return S().error(`Setting more active draw buffers (${e.length}) than GL.MAX_DRAW_BUFFERS allows ( ${this.parameters.maxDrawBuffers}).`),t;let n=this._state.drawFramebuffer,r=n===null;if(r){if(e.length>1)return S().error(`The default framebuffer can only have 1 active draw buffer but was requested with ${e.length}.`),t;if(e[0]!==u&&e[0]!==d)return S().error(`The default framebuffer can only use the constants GL.BACK or GL.NONE as draw buffers but got ${e[0]}`),t}else if(e.includes(u))return S().error(`A framebuffer object can only use the constants GL.COLOR_ATTACHMENTx or GL.NONE as draw buffers.`),t;return this.gl.drawBuffers(e),a(this.gl),r?this._state.drawBuffers.defaultFramebuffer=e:this._state.drawBuffers.fbos.set(n,e),t}get drawBuffers(){let e=this._state.drawFramebuffer;return e===null?this._state.drawBuffers.defaultFramebuffer:this._state.drawBuffers.fbos.get(e)??[]}clear(e,t=255){e&&(e&16384&&this.setColorMask(!0,!0,!0,!0),e&256&&this.setDepthWriteEnabled(!0),e&1024&&this.setStencilWriteMask(t),this.gl.clear(e))}clearFramebuffer(e,t=!1,n=!1){let r=0;if(e){let t=Math.max(1e-13,e[3]);this.setClearColor(e[0],e[1],e[2],t),r|=16384}t&&(r|=256),n===!1?n=0:(n===!0&&(n=255),r|=1024),r&&this.clear(r,n)}clearBuffer(e,t,n=6144,r){this.gl.clearBufferfv(n,e,t,r)}clearBufferInteger(e,t,n=6144,r){this.gl.clearBufferiv(n,e,t,r)}clearBufferUnsignedInteger(e,t,n=6144,r){this.gl.clearBufferuiv(n,e,t,r)}drawArrays(e,t,n){if(this._transformFeedbackRequestInfo){if(e!==this._transformFeedbackRequestInfo.primitiveType)throw Error(`DrawArrays called during transform feedback, but primitiveType does not match that of the current transform feedback request`);if(this._state.program?.hasTransformFeedbackVaryings==null)throw Error(`DrawArrays called during transform feedback, but the shader program was not linked with a transform feedback varying`)}if(i()&&(this._numOfDrawCalls++,this._numOfTriangles+=T(e,n),has(`enable-feature:webgl-debug:textureReadWrite`))){let e=this._state.textureUnitMap;for(let t=0;t<e.length;t++){let n=e[t];if(n!=null&&n===this._state.drawFramebuffer?.colorTexture)throw Error(`Detected readWrite. Texture already bound at index ${t}`)}}this.gl.drawArrays(e,t,n),a(this.gl)}drawArraysInstanced(e,t,n,r){this.gl.drawArraysInstanced(e,t,n,r),a(this.gl)}drawElements(e,t,n,r){if(this._transformFeedbackRequestInfo)throw Error(`Cannot called drawElements during a transform feedback request`);if(i()&&(this._numOfDrawCalls++,this._numOfTriangles+=T(e,t)),this.gl.drawElements(e,t,n,r),i()){let i=o(this.gl);if(i){let a=this.getBoundVAO(),o=a?.indexBuffer,s={indexBuffer:o,vertexBuffers:a?.buffers},c={mode:e,count:t,type:n,offset:r},l=o?.size??0,u=r+t,d=l<u?`. Buffer is too small. Attempted to draw index ${u} of ${l}`:``;S().error(`drawElements: ${i}${d}`,{args:c,vao:s})}}}drawElementsInstanced(e,t,n,r,i){this.gl.drawElementsInstanced(e,t,n,r,i),a(this.gl)}logInfo(){i()&&console.log(`DrawCalls: ${this._numOfDrawCalls}, Triangles: ${this._numOfTriangles}`)}resetInfo(){i()&&(this._numOfDrawCalls=0,this._numOfTriangles=0)}get capabilities(){return this._capabilities}setViewport(e,t,n,r){n=Math.max(Math.round(n),1),r=Math.max(Math.round(r),1);let i=this._state.viewport;(i.x!==e||i.y!==t||i.width!==n||i.height!==r)&&(i.x=e,i.y=t,i.width=n,i.height=r,this.gl.viewport(e,t,n,r))}setViewport4fv(e){this.setViewport(e[0],e[1],e[2],e[3])}restoreViewport({x:e,y:t,width:n,height:r}){this.setViewport(e,t,n,r)}getViewport(){let e=this._state.viewport;return{x:e.x,y:e.y,width:e.width,height:e.height}}useProgram(e){if(this._state.program!==e){if(e&&e.glName==null&&s())throw Error(`Attempting to use disposed or invalid Program`);this._state.program?.stop(),this._state.program=e,this.gl.useProgram(e?.glName??null)}}bindTexture(e,t,n=!1,r=null){(t>=this.parameters.maxTextureImageUnits||t<0)&&S().error(`Input texture unit (${t}) is out of range of available units (0...${this.parameters.maxTextureImageUnits})
|
|
2
|
+
import has from"../../core/has.js";import e from"../../core/Logger.js";import{disposeMaybe as t}from"../../core/maybe.js";import{after as n}from"../../core/promiseUtils.js";import{Milliseconds as r}from"../../core/time.js";import{webglDebugEnabled as i,checkWebGLError as a,getErrorMessage as o,webglValidateShadersEnabled as s}from"./checkWebGLError.js";import{ContextState as c}from"./ContextState.js";import{baseTextureUnit as l,DrawBufferBack as u,DrawBufferNone as d,ResourceType as f,ColorAttachment0 as p,PrimitiveType as m}from"./enums.js";import{InstanceCounter as h}from"./InstanceCounter.js";import{Parameters as g}from"./Parameters.js";import{ProgramCache as _}from"./ProgramCache.js";import{StateTracker as v}from"./renderState.js";import{Texture as y}from"./Texture.js";import{WebGLDriverTest as b}from"./WebGLDriverTest.js";import{Capabilities as x}from"./capabilities/Capabilities.js";const S=()=>e.getLogger(`esri.views.webgl.RenderingContext`);let C=class{constructor(e,t){this.gl=e,this.instanceCounter=new h,this._programCache=new _(this),this._transformFeedbackRequestInfo=null,this._state=new c,this._numOfDrawCalls=0,this._numOfTriangles=0,this._options=t,this.configure(t)}configure(e){this._options=e,this._capabilities=new x(this.gl,e),this._parameters=new g(this.gl,this._capabilities,e),y.TEXTURE_UNIT_FOR_UPDATES=this._parameters.maxTextureImageUnits-1;let n=this.gl.getParameter(this.gl.VIEWPORT);this._state=new c,this._state.viewport={x:n[0],y:n[1],width:n[2],height:n[3]},this._stateTracker=new v({setBlending:e=>{if(e){this.setBlendingEnabled(!0),this.setBlendEquationSeparate(e.opRgb,e.opAlpha),this.setBlendFunctionSeparate(e.srcRgb,e.dstRgb,e.srcAlpha,e.dstAlpha);let t=e.color;this.setBlendColor(t.r,t.g,t.b,t.a)}else this.setBlendingEnabled(!1)},setCulling:e=>{e?(this.setFaceCullingEnabled(!0),this.setCullFace(e.face),this.setFrontFace(e.mode)):this.setFaceCullingEnabled(!1)},setPolygonOffset:e=>{e?(this.setPolygonOffsetFillEnabled(!0),this.setPolygonOffset(e.factor,e.units)):this.setPolygonOffsetFillEnabled(!1)},setDepthTest:e=>{e?(this.setDepthTestEnabled(!0),this.setDepthFunction(e.func)):this.setDepthTestEnabled(!1)},setStencilTest:e=>{if(e){this.setStencilTestEnabled(!0);let{ref:t,readMask:n,stencilFront:r,stencilBack:i}=e;r.compare===i.compare?this.setStencilFunction(r.compare,t,n):(this.setStencilFunctionSeparate(1028,r.compare,t,n),this.setStencilFunctionSeparate(1029,i.compare,t,n)),r.fail===i.fail&&r.zFail===i.zFail&&r.zPass===i.zPass?this.setStencilOp(r.fail,r.zFail,r.zPass):(this.setStencilOpSeparate(1028,r.fail,r.zFail,r.zPass),this.setStencilOpSeparate(1029,i.fail,i.zFail,i.zPass))}else this.setStencilTestEnabled(!1)},setDepthWrite:e=>{e?(this.setDepthWriteEnabled(!0),this.setDepthRange(e.zNear,e.zFar)):this.setDepthWriteEnabled(!1)},setColorWrite:e=>{e?this.setColorMask(e.r,e.g,e.b,e.a):this.setColorMask(!1,!1,!1,!1)},setStencilWrite:e=>{e?this.setStencilWriteMask(e.mask):this.setStencilWriteMask(0)}}),this.enforceState(),t(this._driverTest),this._driverTest=new b(this)}updateOptions(e){this._options={...this._options,...e},this._parameters=new g(this.gl,this._capabilities,this._options)}dispose(){this._driverTest=t(this._driverTest),this._programCache=t(this._programCache),this.bindVAO(null),this.unbindBuffer(34962),this.unbindBuffer(34963),this.unbindBuffer(35345),this.bindUniformBufferBindingPoints([]),this.unbindBuffer(35051),this.unbindBuffer(35052),this.unbindBuffer(36662),this.unbindBuffer(36663),this._state.textureUnitMap.length=0,this._state.textureUnitSamplerMap.length=0,this._state=null,this._capabilities=null,this._stateTracker=null;let e=i()&&this.instanceCounter.resourceInformation;e&&console.log(e)}get driverTest(){return this._driverTest}get contextAttributes(){return this.gl.getContextAttributes()}get parameters(){return this._parameters}get programCache(){return this._programCache}setPipelineState(e){this._stateTracker.setPipeline(e)}getPipelineState(){return this._stateTracker.getPipelineState()}setBlendingEnabled(e){this._state.blend!==e&&(e===!0?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this._state.blend=e,this._stateTracker.invalidateBlending())}externalProgramUpdate(){this._state.program?.stop(),this._state.program=null}externalTextureUnitUpdate(e,t){for(let t=0;t<e.length;++t){let n=e[t];this._state.textureUnitMap[n]=null,this._state.textureUnitSamplerMap[n]=null}t>=0&&(this._state.activeTexture=t)}externalVertexArrayObjectUpdate(){this.gl.bindVertexArray(null),this._state.vertexArrayObject=null,this._state.vertexBuffer=null,this._state.indexBuffer=null}externalVertexBufferUpdate(){this._state.vertexBuffer=null}externalIndexBufferUpdate(){this._state.indexBuffer=null}setBlendColor(e,t,n,r){(e!==this._state.blendColor.r||t!==this._state.blendColor.g||n!==this._state.blendColor.b||r!==this._state.blendColor.a)&&(this.gl.blendColor(e,t,n,r),this._state.blendColor.r=e,this._state.blendColor.g=t,this._state.blendColor.b=n,this._state.blendColor.a=r,this._stateTracker.invalidateBlending())}setBlendFunction(e,t){(e!==this._state.blendFunction.srcRGB||t!==this._state.blendFunction.dstRGB)&&(this.gl.blendFunc(e,t),this._state.blendFunction.srcRGB=e,this._state.blendFunction.srcAlpha=e,this._state.blendFunction.dstRGB=t,this._state.blendFunction.dstAlpha=t,this._stateTracker.invalidateBlending())}setBlendFunctionSeparate(e,t,n,r){(this._state.blendFunction.srcRGB!==e||this._state.blendFunction.srcAlpha!==n||this._state.blendFunction.dstRGB!==t||this._state.blendFunction.dstAlpha!==r)&&(this.gl.blendFuncSeparate(e,t,n,r),this._state.blendFunction.srcRGB=e,this._state.blendFunction.srcAlpha=n,this._state.blendFunction.dstRGB=t,this._state.blendFunction.dstAlpha=r,this._stateTracker.invalidateBlending())}setBlendEquation(e){this._state.blendEquation.mode!==e&&(this.gl.blendEquation(e),this._state.blendEquation.mode=e,this._state.blendEquation.modeAlpha=e,this._stateTracker.invalidateBlending())}setBlendEquationSeparate(e,t){(this._state.blendEquation.mode!==e||this._state.blendEquation.modeAlpha!==t)&&(this.gl.blendEquationSeparate(e,t),this._state.blendEquation.mode=e,this._state.blendEquation.modeAlpha=t,this._stateTracker.invalidateBlending())}setColorMask(e,t,n,r){(this._state.colorMask.r!==e||this._state.colorMask.g!==t||this._state.colorMask.b!==n||this._state.colorMask.a!==r)&&(this.gl.colorMask(e,t,n,r),this._state.colorMask.r=e,this._state.colorMask.g=t,this._state.colorMask.b=n,this._state.colorMask.a=r,this._stateTracker.invalidateColorWrite())}setClearColor(e,t,n,r){(this._state.clearColor.r!==e||this._state.clearColor.g!==t||this._state.clearColor.b!==n||this._state.clearColor.a!==r)&&(this.gl.clearColor(e,t,n,r),this._state.clearColor.r=e,this._state.clearColor.g=t,this._state.clearColor.b=n,this._state.clearColor.a=r)}setFaceCullingEnabled(e){this._state.faceCulling!==e&&(e===!0?this.gl.enable(this.gl.CULL_FACE):this.gl.disable(this.gl.CULL_FACE),this._state.faceCulling=e,this._stateTracker.invalidateCulling())}setPolygonOffsetFillEnabled(e){this._state.polygonOffsetFill!==e&&(e===!0?this.gl.enable(this.gl.POLYGON_OFFSET_FILL):this.gl.disable(this.gl.POLYGON_OFFSET_FILL),this._state.polygonOffsetFill=e,this._stateTracker.invalidatePolygonOffset())}setPolygonOffset(e,t){(this._state.polygonOffset[0]!==e||this._state.polygonOffset[1]!==t)&&(this._state.polygonOffset[0]=e,this._state.polygonOffset[1]=t,this.gl.polygonOffset(e,t),this._stateTracker.invalidatePolygonOffset())}setCullFace(e){this._state.cullFace!==e&&(this.gl.cullFace(e),this._state.cullFace=e,this._stateTracker.invalidateCulling())}setFrontFace(e){this._state.frontFace!==e&&(this.gl.frontFace(e),this._state.frontFace=e,this._stateTracker.invalidateCulling())}setScissorTestEnabled(e){this._state.scissorTest!==e&&(e===!0?this.gl.enable(this.gl.SCISSOR_TEST):this.gl.disable(this.gl.SCISSOR_TEST),this._state.scissorTest=e)}setScissorRect(e,t,n,r){(this._state.scissorRect.x!==e||this._state.scissorRect.y!==t||this._state.scissorRect.width!==n||this._state.scissorRect.height!==r)&&(this.gl.scissor(e,t,n,r),this._state.scissorRect.x=e,this._state.scissorRect.y=t,this._state.scissorRect.width=n,this._state.scissorRect.height=r)}setDepthTestEnabled(e){this._state.depthTest!==e&&(e===!0?this.gl.enable(this.gl.DEPTH_TEST):this.gl.disable(this.gl.DEPTH_TEST),this._state.depthTest=e,this._stateTracker.invalidateDepthTest())}setClearDepth(e){this._state.clearDepth!==e&&(this.gl.clearDepth(e),this._state.clearDepth=e)}setDepthFunction(e){this._state.depthFunction!==e&&(this.gl.depthFunc(e),this._state.depthFunction=e,this._stateTracker.invalidateDepthTest())}setDepthWriteEnabled(e){this._state.depthWrite!==e&&(this.gl.depthMask(e),this._state.depthWrite=e,this._stateTracker.invalidateDepthWrite())}setDepthRange(e,t){(this._state.depthRange.zNear!==e||this._state.depthRange.zFar!==t)&&(this.gl.depthRange(e,t),this._state.depthRange.zNear=e,this._state.depthRange.zFar=t,this._stateTracker.invalidateDepthWrite())}setStencilTestEnabled(e){this._state.stencilTest!==e&&(e===!0?this.gl.enable(this.gl.STENCIL_TEST):this.gl.disable(this.gl.STENCIL_TEST),this._state.stencilTest=e,this._stateTracker.invalidateStencilTest())}setClearStencil(e){e!==this._state.clearStencil&&(this.gl.clearStencil(e),this._state.clearStencil=e)}setStencilFunction(e,t,n){(this._state.stencilFunction.face!==1032||this._state.stencilFunction.func!==e||this._state.stencilFunction.ref!==t||this._state.stencilFunction.mask!==n)&&(this.gl.stencilFunc(e,t,n),this._state.stencilFunction.face=1032,this._state.stencilFunction.func=e,this._state.stencilFunction.ref=t,this._state.stencilFunction.mask=n,this._stateTracker.invalidateStencilTest())}setStencilFunctionSeparate(e,t,n,r){(this._state.stencilFunction.face!==e||this._state.stencilFunction.func!==t||this._state.stencilFunction.ref!==n||this._state.stencilFunction.mask!==r)&&(this.gl.stencilFuncSeparate(e,t,n,r),this._state.stencilFunction.face=e,this._state.stencilFunction.func=t,this._state.stencilFunction.ref=n,this._state.stencilFunction.mask=r,this._stateTracker.invalidateStencilTest())}setStencilWriteMask(e){this._state.stencilWriteMask!==e&&(this.gl.stencilMask(e),this._state.stencilWriteMask=e,this._stateTracker.invalidateStencilWrite())}setStencilOp(e,t,n){(this._state.stencilOperation.face!==1032||this._state.stencilOperation.fail!==e||this._state.stencilOperation.zFail!==t||this._state.stencilOperation.zPass!==n)&&(this.gl.stencilOp(e,t,n),this._state.stencilOperation.face=1032,this._state.stencilOperation.fail=e,this._state.stencilOperation.zFail=t,this._state.stencilOperation.zPass=n,this._stateTracker.invalidateStencilTest())}setStencilOpSeparate(e,t,n,r){(this._state.stencilOperation.face!==e||this._state.stencilOperation.fail!==t||this._state.stencilOperation.zFail!==n||this._state.stencilOperation.zPass!==r)&&(this.gl.stencilOpSeparate(e,t,n,r),this._state.stencilOperation.face=e,this._state.stencilOperation.fail=t,this._state.stencilOperation.zFail=n,this._state.stencilOperation.zPass=r,this._stateTracker.invalidateStencilTest())}setActiveTexture(e,t=!1){let n=this._state.activeTexture;return e>=0&&(t||e!==this._state.activeTexture)&&(this.gl.activeTexture(l+e),this._state.activeTexture=e),n}setDrawBuffers(e){let t=this.drawBuffers;if(t.length===e.length&&t.every((t,n)=>t===e[n]))return t;if(e.length>this.parameters.maxDrawBuffers)return S().error(`Setting more active draw buffers (${e.length}) than GL.MAX_DRAW_BUFFERS allows ( ${this.parameters.maxDrawBuffers}).`),t;let n=this._state.drawFramebuffer,r=n===null;if(r){if(e.length>1)return S().error(`The default framebuffer can only have 1 active draw buffer but was requested with ${e.length}.`),t;if(e[0]!==u&&e[0]!==d)return S().error(`The default framebuffer can only use the constants GL.BACK or GL.NONE as draw buffers but got ${e[0]}`),t}else if(e.includes(u))return S().error(`A framebuffer object can only use the constants GL.COLOR_ATTACHMENTx or GL.NONE as draw buffers.`),t;return this.gl.drawBuffers(e),a(this.gl),r?this._state.drawBuffers.defaultFramebuffer=e:this._state.drawBuffers.fbos.set(n,e),t}get drawBuffers(){let e=this._state.drawFramebuffer;return e===null?this._state.drawBuffers.defaultFramebuffer:this._state.drawBuffers.fbos.get(e)??[]}clear(e,t=255){e&&(e&16384&&this.setColorMask(!0,!0,!0,!0),e&256&&this.setDepthWriteEnabled(!0),e&1024&&this.setStencilWriteMask(t),this.gl.clear(e))}clearFramebuffer(e,t=!1,n=!1){let r=0;if(e){let t=Math.max(1e-13,e[3]);this.setClearColor(e[0],e[1],e[2],t),r|=16384}t&&(r|=256),n===!1?n=0:(n===!0&&(n=255),r|=1024),r&&this.clear(r,n)}clearBuffer(e,t,n=6144,r){this.gl.clearBufferfv(n,e,t,r)}clearBufferInteger(e,t,n=6144,r){this.gl.clearBufferiv(n,e,t,r)}clearBufferUnsignedInteger(e,t,n=6144,r){this.gl.clearBufferuiv(n,e,t,r)}drawArrays(e,t,n){if(this._transformFeedbackRequestInfo){if(e!==this._transformFeedbackRequestInfo.primitiveType)throw Error(`DrawArrays called during transform feedback, but primitiveType does not match that of the current transform feedback request`);if(this._state.program?.hasTransformFeedbackVaryings==null)throw Error(`DrawArrays called during transform feedback, but the shader program was not linked with a transform feedback varying`)}if(i()&&(this._numOfDrawCalls++,this._numOfTriangles+=T(e,n),has(`enable-feature:webgl-debug:textureReadWrite`))){let e=this._state.textureUnitMap;for(let t=0;t<e.length;t++){let n=e[t];if(n!=null&&n===this._state.drawFramebuffer?.colorTexture)throw Error(`Detected readWrite. Texture already bound at index ${t}`)}}this.gl.drawArrays(e,t,n),a(this.gl)}drawArraysInstanced(e,t,n,r){this.gl.drawArraysInstanced(e,t,n,r),a(this.gl)}drawElements(e,t,n,r){if(this._transformFeedbackRequestInfo)throw Error(`Cannot called drawElements during a transform feedback request`);if(i()&&(this._numOfDrawCalls++,this._numOfTriangles+=T(e,t)),this.gl.drawElements(e,t,n,r),i()){let i=o(this.gl);if(i){let a=this.getBoundVAO(),o=a?.indexBuffer,s={indexBuffer:o,vertexBuffers:a?.buffers},c={mode:e,count:t,type:n,offset:r},l=o?.size??0,u=r+t,d=l<u?`. Buffer is too small. Attempted to draw index ${u} of ${l}`:``;S().error(`drawElements: ${i}${d}`,{args:c,vao:s})}}}drawElementsInstanced(e,t,n,r,i){this.gl.drawElementsInstanced(e,t,n,r,i),a(this.gl)}logInfo(){i()&&console.log(`DrawCalls: ${this._numOfDrawCalls}, Triangles: ${this._numOfTriangles}`)}resetInfo(){i()&&(this._numOfDrawCalls=0,this._numOfTriangles=0)}get capabilities(){return this._capabilities}setViewport(e,t,n,r){n=Math.max(Math.round(n),1),r=Math.max(Math.round(r),1);let i=this._state.viewport;(i.x!==e||i.y!==t||i.width!==n||i.height!==r)&&(i.x=e,i.y=t,i.width=n,i.height=r,this.gl.viewport(e,t,n,r))}setViewport4fv(e){this.setViewport(e[0],e[1],e[2],e[3])}restoreViewport({x:e,y:t,width:n,height:r}){this.setViewport(e,t,n,r)}getViewport(){let e=this._state.viewport;return{x:e.x,y:e.y,width:e.width,height:e.height}}useProgram(e){if(this._state.program!==e){if(e&&e.glName==null&&s())throw Error(`Attempting to use disposed or invalid Program`);this._state.program?.stop(),this._state.program=e,this.gl.useProgram(e?.glName??null)}}bindTexture(e,t,n=!1,r=null){(t>=this.parameters.maxTextureImageUnits||t<0)&&S().error(`Input texture unit (${t}) is out of range of available units (0...${this.parameters.maxTextureImageUnits})
|
|
3
3
|
`);let i=this._state.textureUnitMap[t],a=this._state.textureUnitSamplerMap[t],{gl:o}=this;return e?.glName==null?(i!=null&&(this.setActiveTexture(t,n),o.bindTexture(i.descriptor.target,null)),this._state.textureUnitMap[t]=null,a!=null&&(this._state.textureUnitSamplerMap[t]=null,o.bindSampler(t,null)),i):(a!==r&&(o.bindSampler(t,r?.glName??null),this._state.textureUnitSamplerMap[t]=r),!n&&i===e?(e.isDirty&&(this.setActiveTexture(t,n),e.applyChanges()),i):(this.setActiveTexture(t,n),o.bindTexture(e.descriptor.target,e.glName),e.applyChanges(),this._state.textureUnitMap[t]=e,i))}unbindTexture(e){if(e!=null)for(let t=0;t<this.parameters.maxTextureImageUnits;t++)this._state.textureUnitMap[t]===e&&(this.bindTexture(null,t),this._state.textureUnitMap[t]=null)}bindFramebuffer(e,t=!1){let n=E(e);!t&&this._state.readFramebuffer===e&&this._state.drawFramebuffer===e?this.setDrawBuffers(n):e==null?(this.gl.bindFramebuffer(36160,null),this._state.readFramebuffer=this._state.drawFramebuffer=null,this.setDrawBuffers(n)):(e.initializeAndBind(36160),this._state.readFramebuffer=e,this._state.drawFramebuffer=e,this.setDrawBuffers(n))}bindFramebufferSeparate(e,t,n=!1){let r=t===36008,i=r?this._state.readFramebuffer:this._state.drawFramebuffer;(n||i!==e)&&(e==null?this.gl.bindFramebuffer(t,null):e.initializeAndBind(t),r?this._state.readFramebuffer=e??null:(this._state.drawFramebuffer=e??null,this.setDrawBuffers(E(e))))}blitFramebuffer(e,t,n=16384,r=9728,i=0,a=0,o=e.width,s=e.height,c=0,l=0,u=t.width,d=t.height){this.bindFramebufferSeparate(e,36008,!0),this.bindFramebufferSeparate(t,36009,!0),this.gl.blitFramebuffer(i,a,o,s,c,l,u,d,n,r)}bindBuffer(e,t){if(e)switch(t??=e.bufferType,t){case 34962:this._state.vertexBuffer=w(this.gl,e,t,this._state.vertexBuffer);break;case 34963:this._state.indexBuffer=w(this.gl,e,t,this._state.indexBuffer);break;case 35345:this._state.uniformBuffer=w(this.gl,e,t,this._state.uniformBuffer);break;case 35051:this._state.pixelPackBuffer=w(this.gl,e,t,this._state.pixelPackBuffer);break;case 35052:this._state.pixelUnpackBuffer=w(this.gl,e,t,this._state.pixelUnpackBuffer);break;case 36662:this._state.copyReadBuffer=w(this.gl,e,t,this._state.copyReadBuffer);break;case 36663:this._state.copyWriteBuffer=w(this.gl,e,t,this._state.copyWriteBuffer);break;case 35982:this._state.transformFeedbackBuffer=w(this.gl,e,t,this._state.transformFeedbackBuffer)}}bindRenderbuffer(e){let t=this.gl;e||(t.bindRenderbuffer(t.RENDERBUFFER,null),this._state.renderbuffer=null),this._state.renderbuffer!==e&&(t.bindRenderbuffer(t.RENDERBUFFER,e.glName),this._state.renderbuffer=e)}_getBufferBinding(e,t){if(t>=this.parameters.maxUniformBufferBindings||t<0)return S().error(`Uniform buffer binding point (${t}) is out of range (0...${this.parameters.maxUniformBufferBindings})
|
|
4
4
|
`),null;let n=e===35345?this._state.uniformBufferBindingPoints:this._state.transformBufferBindingPoints,r=n[t];return r??(r={buffer:null,offset:0,size:0},n[t]=r),r}bindBufferBase(e,t,n){let r=this._getBufferBinding(e,t);r!=null&&(r.buffer!==n||r.offset!==0||r.size!==0)&&(this.gl.bindBufferBase(e,t,n?n.glName:null),e===35345?this._state.uniformBuffer=n:this._state.transformFeedbackBuffer=n,r.buffer=n,r.offset=0,r.size=0)}bindBufferRange(e,t,n,r,i){let a=this._getBufferBinding(e,t);a!=null&&(a.buffer!==n||a.offset!==r||a.size!==i)&&(r%this._parameters.uniformBufferOffsetAlignment===0?(this.gl.bindBufferRange(e,t,n.glName,r,i),this._state.uniformBuffer=n,a.buffer=n,a.offset=r,a.size=i):S().error(`Uniform buffer binding offset is not a multiple of the context offset alignment`))}bindUniformBufferBindingPoints(e){let t=this._state.uniformBufferBindingPoints,n=Math.max(t.length,e.length);t.length=0;for(let r=0;r<n;r++){let n=e[r];if(n?.buffer!=null){let{buffer:e,offset:t,size:i}=n;t===0&&i===0?this.gl.bindBufferBase(35345,r,e.glName):this.gl.bindBufferRange(35345,r,e.glName,t,i),this._state.uniformBuffer=e}else this.gl.bindBufferBase(35345,r,null),this._state.uniformBuffer=null;r<e.length&&(t[r]=n?{buffer:n.buffer,offset:n.offset,size:n.size}:{buffer:null,offset:0,size:0})}}bindUBO(e,t,n,r){t==null?this.bindBufferBase(35345,e,null):(i()&&(r??t.byteLength)>this._parameters.maxUniformBlockSize&&S().error(`Attempting to bind more data than the maximum uniform block size`),t.initialize(),n!==void 0&&r!==void 0?this.bindBufferRange(35345,e,t.buffer,n,r):this.bindBufferBase(35345,e,t.buffer))}unbindUBO(e){for(let t=0,n=this._state.uniformBufferBindingPoints.length;t<n;t++){let n=this._state.uniformBufferBindingPoints[t];n!=null&&n.buffer===e.buffer&&this.bindBufferBase(35345,t,null)}}unbindBuffer(e){switch(e){case 34962:this._state.vertexBuffer=w(this.gl,null,e,this._state.vertexBuffer);break;case 34963:this._state.indexBuffer=w(this.gl,null,e,this._state.indexBuffer);break;case 35345:this._state.uniformBuffer=w(this.gl,null,e,this._state.uniformBuffer);break;case 35051:this._state.pixelPackBuffer=w(this.gl,null,e,this._state.pixelPackBuffer);break;case 35052:this._state.pixelUnpackBuffer=w(this.gl,null,e,this._state.pixelUnpackBuffer);break;case 36662:this._state.copyReadBuffer=w(this.gl,null,e,this._state.copyReadBuffer);break;case 36663:this._state.copyWriteBuffer=w(this.gl,null,e,this._state.copyWriteBuffer)}}bindVAO(e,t){e==null?(this._state.vertexArrayObject?.unbind(),this._state.vertexArrayObject=null):this._state.vertexArrayObject!==e&&(e.bind(t),this._state.vertexArrayObject=e)}bindTransformFeedback(e){let{gl:t}=this;t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,e.glName)}beginTransformFeedback(e,t){if(this._transformFeedbackRequestInfo)throw Error(`Already in a transform feedback request`);let{gl:n}=this;n.bindTransformFeedback(n.TRANSFORM_FEEDBACK,e.glName),n.beginTransformFeedback(t),this._transformFeedbackRequestInfo={primitiveType:t}}endTransformFeedback(){if(!this._transformFeedbackRequestInfo)throw Error(`Not in a transform feedback request`);let{gl:e}=this;e.endTransformFeedback(),e.bindTransformFeedback(e.TRANSFORM_FEEDBACK,null),this._transformFeedbackRequestInfo=null}async clientWaitAsync(e=r(10),t){let{gl:i}=this,a=i.fenceSync(37143,0);if(!a)throw Error(`Client wait failed, could not create sync object`);this.instanceCounter.increment(f.Sync,a),i.flush();try{let r;do await n(e,null,t),r=i.clientWaitSync(a,0,0);while(r===37147);if(r===37149)throw Error(`Client wait failed`)}finally{this.instanceCounter.decrement(f.Sync,a),i.deleteSync(a)}}get boundFramebuffer(){return this._state.drawFramebuffer}get uniformBufferBindingPoints(){return this._state.uniformBufferBindingPoints.map(e=>e&&{buffer:e.buffer,offset:e.offset,size:e.size})}temporaryBindFramebuffer(e,t,n=!1){let r=this.boundFramebuffer,i={...this._state.viewport};try{this.bindFramebuffer(e,n),e&&this.setViewport(0,0,e.width,e.height),t()}finally{this.bindFramebuffer(r,n),e&&this.setViewport(i.x,i.y,i.width,i.height)}}getBoundVAO(){return this._state.vertexArrayObject}resetState(){this.useProgram(null),this.bindVAO(null),this.bindFramebuffer(null,!0),this.unbindBuffer(34962),this.unbindBuffer(34963),this.unbindBuffer(35345),this.bindUniformBufferBindingPoints([]),this.unbindBuffer(35051),this.unbindBuffer(35052),this.unbindBuffer(36662),this.unbindBuffer(36663);for(let e=0;e<this.parameters.maxTextureImageUnits;++e)this.bindTexture(null,e);this.setBlendingEnabled(!1),this.setBlendFunction(1,0),this.setBlendEquation(32774),this.setBlendColor(0,0,0,0),this.setFaceCullingEnabled(!1),this.setCullFace(1029),this.setFrontFace(2305),this.setPolygonOffsetFillEnabled(!1),this.setPolygonOffset(0,0),this.setScissorTestEnabled(!1),this.setScissorRect(0,0,this.gl.canvas.width,this.gl.canvas.height),this.setDepthTestEnabled(!1),this.setDepthFunction(513),this.setDepthRange(0,1),this.setStencilTestEnabled(!1),this.setStencilFunction(519,0,0),this.setStencilOp(7680,7680,7680),this.setClearColor(0,0,0,0),this.setClearDepth(1),this.setClearStencil(0),this.setColorMask(!0,!0,!0,!0),this.setStencilWriteMask(4294967295),this.setDepthWriteEnabled(!0),this.setViewport(0,0,this.gl.canvas.width,this.gl.canvas.height)}enforceState(){let{gl:e}=this;e.bindVertexArray(null);for(let t=0;t<this.parameters.maxVertexAttributes;t++)e.disableVertexAttribArray(t);this._state.vertexBuffer?e.bindBuffer(this._state.vertexBuffer.bufferType,this._state.vertexBuffer.glName):e.bindBuffer(34962,null),this._state.indexBuffer?e.bindBuffer(this._state.indexBuffer.bufferType,this._state.indexBuffer.glName):e.bindBuffer(34963,null);for(let t=0;t<this._parameters.maxUniformBufferBindings;t++){let n=this._state.uniformBufferBindingPoints[t];if(n!=null){let{buffer:r,offset:i,size:a}=n;r===null?e.bindBufferBase(35345,t,null):i===0&&a===0?e.bindBufferBase(35345,t,r.glName):e.bindBufferRange(35345,t,r.glName,i,a)}}if(this._state.uniformBuffer?e.bindBuffer(this._state.uniformBuffer.bufferType,this._state.uniformBuffer.glName):e.bindBuffer(35345,null),this._state.pixelPackBuffer?e.bindBuffer(this._state.pixelPackBuffer.bufferType,this._state.pixelPackBuffer.glName):e.bindBuffer(35051,null),this._state.pixelUnpackBuffer?e.bindBuffer(this._state.pixelUnpackBuffer.bufferType,this._state.pixelUnpackBuffer.glName):e.bindBuffer(35052,null),this._state.copyReadBuffer?e.bindBuffer(this._state.copyReadBuffer.bufferType,this._state.copyReadBuffer.glName):e.bindBuffer(36662,null),this._state.copyWriteBuffer?e.bindBuffer(this._state.copyWriteBuffer.bufferType,this._state.copyWriteBuffer.glName):e.bindBuffer(36663,null),e.bindFramebuffer(36008,null),e.readBuffer(e.BACK),this._state.readFramebuffer&&(e.bindFramebuffer(36008,this._state.readFramebuffer.glName),e.readBuffer(p)),e.bindFramebuffer(36009,this._state.drawFramebuffer?.glName??null),this._state.drawFramebuffer===null){let t=this._state.drawBuffers.defaultFramebuffer;e.drawBuffers(t??[u])}else{let t=this._state.drawBuffers.fbos.get(this._state.drawFramebuffer);e.drawBuffers(t??[p])}if(this._state.vertexArrayObject){let e=this._state.vertexArrayObject;this._state.vertexArrayObject&&(this._state.vertexArrayObject.unbind(),this._state.vertexArrayObject=null),this.bindVAO(e)}e.useProgram(this._state.program?.glName??null),e.blendColor(this._state.blendColor.r,this._state.blendColor.g,this._state.blendColor.b,this._state.blendColor.a),e.bindRenderbuffer(e.RENDERBUFFER,this._state.renderbuffer?.glName??null),this._state.blend===!0?e.enable(this.gl.BLEND):e.disable(this.gl.BLEND),e.blendEquationSeparate(this._state.blendEquation.mode,this._state.blendEquation.modeAlpha),e.blendFuncSeparate(this._state.blendFunction.srcRGB,this._state.blendFunction.dstRGB,this._state.blendFunction.srcAlpha,this._state.blendFunction.dstAlpha),e.clearColor(this._state.clearColor.r,this._state.clearColor.g,this._state.clearColor.b,this._state.clearColor.a),e.clearDepth(this._state.clearDepth),e.clearStencil(this._state.clearStencil),e.colorMask(this._state.colorMask.r,this._state.colorMask.g,this._state.colorMask.b,this._state.colorMask.a),e.cullFace(this._state.cullFace),e.depthFunc(this._state.depthFunction),e.depthRange(this._state.depthRange.zNear,this._state.depthRange.zFar),this._state.depthTest===!0?e.enable(e.DEPTH_TEST):e.disable(e.DEPTH_TEST),e.depthMask(this._state.depthWrite),e.frontFace(this._state.frontFace),e.lineWidth(1),this._state.faceCulling===!0?e.enable(e.CULL_FACE):e.disable(e.CULL_FACE),e.polygonOffset(this._state.polygonOffset[0],this._state.polygonOffset[1]),this._state.polygonOffsetFill===!0?e.enable(e.POLYGON_OFFSET_FILL):e.disable(e.POLYGON_OFFSET_FILL),e.scissor(this._state.scissorRect.x,this._state.scissorRect.y,this._state.scissorRect.width,this._state.scissorRect.height),this._state.scissorTest===!0?e.enable(e.SCISSOR_TEST):e.disable(e.SCISSOR_TEST),e.stencilFunc(this._state.stencilFunction.func,this._state.stencilFunction.ref,this._state.stencilFunction.mask),e.stencilOpSeparate(this._state.stencilOperation.face,this._state.stencilOperation.fail,this._state.stencilOperation.zFail,this._state.stencilOperation.zPass),this._state.stencilTest===!0?e.enable(e.STENCIL_TEST):e.disable(e.STENCIL_TEST),e.stencilMask(this._state.stencilWriteMask);for(let t=0;t<this.parameters.maxTextureImageUnits;t++){e.activeTexture(l+t),e.bindTexture(3553,null),e.bindTexture(34067,null),e.bindTexture(32879,null),e.bindTexture(35866,null),e.bindSampler(t,null);let n=this._state.textureUnitMap[t];n!=null&&e.bindTexture(n.descriptor.target,n.glName);let r=this._state.textureUnitSamplerMap[t];r!=null&&e.bindSampler(t,r?.glName)}e.activeTexture(l+this._state.activeTexture);let t=this._state.viewport;e.viewport(t.x,t.y,t.width,t.height),this.resetInfo()}};function w(e,t,n,r){return t?r!==t&&e.bindBuffer(n,t.glName):e.bindBuffer(n,null),t}function T(e,t){switch(e){case m.POINTS:return 2*t;case m.TRIANGLES:return t/3;case m.TRIANGLE_STRIP:return t-2;case m.TRIANGLE_FAN:return t-2;default:return 0}}function E(e){return e?e.colorAttachments.length>0?e.colorAttachments:[d]:[u]}export{C as RenderingContext,E as getFramebufferDrawBuffers};
|
package/views/webgl/Texture.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import e from"../../core/Error.js";import has from"../../core/has.js";import t from"../../core/Logger.js";import{abortMaybe as n}from"../../core/maybe.js";import{hasValue as r}from"../../core/object.js";import{throwIfAborted as i,isAbortError as a}from"../../core/promiseUtils.js";import{checkWebGLError as o}from"./checkWebGLError.js";import{ResourceType as s,CompressedTextureFormat as c}from"./enums.js";import{estimateMemory as l}from"./TextureDescriptor.js";import{isCompressedData as u,deriveInternalFormat as d,isTexImageSource as f,is3DTarget as p,validateTexture as m,isCompressedFormat as h,getDimensions as g,isSizedPixelFormat as _,calcMipmapLevels as v}from"./textureUtils.js";import{ValidatedTextureDescriptor as y}from"./ValidatedTextureDescriptor.js";const b=!!has(`esri-tests-disable-gpu-memory-measurements`),x=()=>t.getLogger(`esri/views/webgl/Texture`);class S{static{this.TEXTURE_UNIT_FOR_UPDATES=0}static{this.compressionWorkerHandle=null}constructor(t,n=null,r=null){if(this.type=1,this._glName=null,this._samplingModeDirty=!1,this._wrapModeDirty=!1,this._shadowFilterDirty=!1,this._wasImmutablyAllocated=!1,`context`in t)this._descriptor=t,r=n;else{let r=y.validate(t,n);if(!r)throw new e(`texture:invalid-descriptor`,`Texture descriptor invalid`);this._descriptor=r}this._descriptor.target===34067?this._setDataCubeMap(r):this.setData(r)}get glName(){return this._glName}get descriptor(){return this._descriptor}get usedMemory(){return b?0:l(this._descriptor)}get isDirty(){return this._samplingModeDirty||this._wrapModeDirty||this._shadowFilterDirty}get hasWebGLTextureObject(){return!!this._glName}dispose(){this.abortCompression(),this.hasWebGLTextureObject&&this._descriptor.context?.gl&&(this._descriptor.context.instanceCounter.decrement(s.Texture,this),this._descriptor.context.unbindTexture(this),this._descriptor.context.gl.deleteTexture(this._glName),this._glName=null)}release(){this.dispose()}[Symbol.dispose](){this.dispose()}resize(t,n){let r=this._descriptor;if(r.width!==t||r.height!==n){if(this._wasImmutablyAllocated)throw new e(`texture:immutable-resize`,`Immutable textures can't be resized!`);r.width=t,r.height=n,this._descriptor.target===34067?this._setDataCubeMap(null):this.setData(null)}}enableCompression(e){this._descriptor.compress=e}disableCompression(){this._descriptor.compress=void 0}setData(e){this.abortCompression(),!u(e)&&this._descriptor.internalFormat&&r(c,this._descriptor.internalFormat)&&(this._descriptor.internalFormat=void 0),this._setData(e),!u(e)&&this._descriptor.compress&&this._compressOnWorker(e)}updateData(t,n,r,i,a,o,s=0){o||x().error(`An attempt to use uninitialized data!`),this.hasWebGLTextureObject||x().error(`An attempt to update uninitialized texture!`);let c=this._descriptor;c.internalFormat=d(c);let{context:l,pixelFormat:p,dataType:m,target:h,isImmutable:g}=c;if(g&&!this._wasImmutablyAllocated)throw new e(`texture:uninitialized`,`Cannot update immutable texture before allocation!`);let _=l.bindTexture(this,S.TEXTURE_UNIT_FOR_UPDATES,!0);(n<0||r<0||n+i>c.width||r+a>c.height)&&x().error(`An attempt to update out of bounds of the texture!`),this._configurePixelStorage();let{gl:v}=l;s&&(i&&a||x().warn("Must pass width and height if `UNPACK_SKIP_ROWS` is used"),v.pixelStorei(v.UNPACK_SKIP_ROWS,s)),f(o)?v.texSubImage2D(h,t,n,r,i,a,p,m,o):u(o)?v.compressedTexSubImage2D(h,t,n,r,i,a,c.internalFormat,o.levels[t]):v.texSubImage2D(h,t,n,r,i,a,p,m,o),s&&v.pixelStorei(v.UNPACK_SKIP_ROWS,0),l.bindTexture(_,S.TEXTURE_UNIT_FOR_UPDATES)}updateData3D(t,n,r,i,a,o,s,c){c||x().error(`An attempt to use uninitialized data!`),this.hasWebGLTextureObject||x().error(`An attempt to update an uninitialized texture!`);let l=this._descriptor;l.internalFormat=d(l);let{context:f,pixelFormat:m,dataType:h,isImmutable:g,target:_}=l;if(g&&!this._wasImmutablyAllocated)throw new e(`texture:uninitialized`,`Cannot update immutable texture before allocation!`);p(_)||x().warn(`Attempting to set 3D texture data on a non-3D texture`);let v=f.bindTexture(this,S.TEXTURE_UNIT_FOR_UPDATES);f.setActiveTexture(S.TEXTURE_UNIT_FOR_UPDATES),(n<0||r<0||i<0||n+a>l.width||r+o>l.height||i+s>l.depth)&&x().error(`An attempt to update out of bounds of the texture!`),this._configurePixelStorage();let{gl:y}=f;if(u(c))c=c.levels[t],y.compressedTexSubImage3D(_,t,n,r,i,a,o,s,l.internalFormat,c);else{let e=c;y.texSubImage3D(_,t,n,r,i,a,o,s,m,h,e)}f.bindTexture(v,S.TEXTURE_UNIT_FOR_UPDATES)}generateMipmap(){let t=this._descriptor;if(t.width===0||t.height===0)return;if(!t.hasMipmap){if(this._wasImmutablyAllocated)throw new e(`texture:immutable-change`,`Cannot add mipmaps to immutable texture after allocation`);t.hasMipmap=!0,this._samplingModeDirty=!0,m(t)}t.samplingMode===9729?(this._samplingModeDirty=!0,t.samplingMode=9985):t.samplingMode===9728&&(this._samplingModeDirty=!0,t.samplingMode=9984);let n=this._descriptor.context.bindTexture(this,S.TEXTURE_UNIT_FOR_UPDATES);this._descriptor.context.setActiveTexture(S.TEXTURE_UNIT_FOR_UPDATES),this._descriptor.context.gl.generateMipmap(t.target),this._descriptor.context.bindTexture(n,S.TEXTURE_UNIT_FOR_UPDATES)}clearMipmap(){let t=this._descriptor;if(t.hasMipmap){if(this._wasImmutablyAllocated)throw new e(`texture:immutable-change`,`Cannot delete mipmaps to immutable texture after allocation`);t.hasMipmap=!1,this._samplingModeDirty=!0,m(t)}t.samplingMode===9985?(this._samplingModeDirty=!0,t.samplingMode=9729):t.samplingMode===9984&&(this._samplingModeDirty=!0,t.samplingMode=9728)}setSamplingMode(e){e!==this._descriptor.samplingMode&&(this._descriptor.samplingMode=e,this._samplingModeDirty=!0)}setWrapMode(e){e!==this._descriptor.wrapMode&&(this._descriptor.wrapMode=e,m(this._descriptor),this._wrapModeDirty=!0)}setShadowFiltering(e){e!==this._descriptor.linearFilterDepth&&(this._descriptor.linearFilterDepth=this._descriptor.compareEnabled=e,this.setSamplingMode(e?9729:9728),m(this._descriptor),this._shadowFilterDirty=!0)}applyChanges(){this._samplingModeDirty&&=(this._applySamplingMode(),!1),this._wrapModeDirty&&=(this._applyWrapMode(),!1),this._shadowFilterDirty&&=(this._applyShadowMode(),!1)}abortCompression(){this._compressionAbortController=n(this._compressionAbortController)}_setData(t,n){let r=this._descriptor,i=r.context?.gl;if(!i)return;o(i),this.hasWebGLTextureObject||(this._glName=i.createTexture(),r.context.instanceCounter.increment(s.Texture,this)),m(r);let a=r.context.bindTexture(this,S.TEXTURE_UNIT_FOR_UPDATES);r.context.setActiveTexture(S.TEXTURE_UNIT_FOR_UPDATES),this._configurePixelStorage(),o(i);let c=n??r.target,l=p(c);if(f(t))this._setDataFromTexImageSource(t,c);else{let{width:n,height:a,depth:s}=r;if(n==null||a==null)throw new e(`texture:missing-size`,`Width and height must be specified!`);if(l&&s==null)throw new e(`texture:missing-depth`,`Depth must be specified!`);if(r.internalFormat=d(r),r.isImmutable&&!this._wasImmutablyAllocated&&this._texStorage(c,r.internalFormat,r.hasMipmap,n,a,s),u(t)){if(!h(r.internalFormat))throw new e(`texture:format-mismatch`,`Attempting to use compressed data with an uncompressed format!`);this._setDataFromCompressedSource(t,r.internalFormat,c)}else this._texImage(c,0,r.internalFormat,n,a,s,t),o(i),r.hasMipmap&&this.generateMipmap()}this._applySamplingMode(),this._applyWrapMode(),this._applyAnisotropicFilteringParameters(),this._applyShadowMode(),o(i),r.context.bindTexture(a,S.TEXTURE_UNIT_FOR_UPDATES)}_setDataCubeMap(e=null){for(let t=34069;t<=34074;t++)this._setData(e,t)}_configurePixelStorage(){let e=this._descriptor.context.gl,{unpackAlignment:t,flipped:n,preMultiplyAlpha:r}=this._descriptor;e.pixelStorei(e.UNPACK_ALIGNMENT,t),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,+!!n),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,+!!r)}_setDataFromTexImageSource(e,t){let{gl:n}=this._descriptor.context,r=this._descriptor;r.internalFormat=d(r);let i=p(t),{width:a,height:s,depth:c}=g(e);r.width&&r.height,r.width||=a,r.height||=s,i&&r.depth,i&&(r.depth=c),r.isImmutable&&!this._wasImmutablyAllocated&&this._texStorage(t,r.internalFormat,r.hasMipmap,a,s,c),this._texImage(t,0,r.internalFormat,a,s,c,e),o(n),r.hasMipmap&&(this.generateMipmap(),o(n))}_setDataFromCompressedSource(e,t,n){let r=this._descriptor,{width:i,height:a,depth:o}=r,s=e.levels,c=v(n,i,a,o),l=Math.min(c,s.length)-1;this._descriptor.context.gl.texParameteri(r.target,33085,l),this._forEachMipmapLevel((e,r,i,a)=>{let o=s[Math.min(e,s.length-1)];this._compressedTexImage(n,e,t,r,i,a,o)},l)}_texStorage(t,n,r,i,a,o){let{gl:s}=this._descriptor.context;if(!_(n)&&!h(n))throw new e(`texture:missing-format`,`Immutable textures must have a sized or compressed internal format`);if(!this._descriptor.isImmutable)return;let c=r?v(t,i,a,o):1;if(p(t)){if(o==null)throw new e(`texture:missing-depth`,`Missing depth dimension for 3D texture upload`);s.texStorage3D(t,c,n,i,a,o)}else s.texStorage2D(t,c,n,i,a);this._wasImmutablyAllocated=!0}_texImage(t,n,r,i,a,o,s){let c=this._descriptor.context.gl,l=p(t),{isImmutable:u,pixelFormat:d,dataType:f}=this._descriptor;if(u){if(s!=null){let r=s;if(l){if(o==null)throw new e(`texture:missing-depth`,`Missing depth dimension for 3D texture upload`);c.texSubImage3D(t,n,0,0,0,i,a,o,d,f,r)}else c.texSubImage2D(t,n,0,0,i,a,d,f,r)}}else{let u=s;if(l){if(o==null)throw new e(`texture:missing-depth`,`Missing depth dimension for 3D texture upload`);c.texImage3D(t,n,r,i,a,o,0,d,f,u)}else c.texImage2D(t,n,r,i,a,0,d,f,u)}}_compressedTexImage(t,n,r,i,a,o,s){let c=this._descriptor.context.gl,l=p(t);if(this._descriptor.isImmutable){if(s!=null){if(l){if(o==null)throw new e(`texture:missing-depth`,`Missing depth dimension for 3D texture upload`);c.compressedTexSubImage3D(t,n,0,0,0,i,a,o,r,s)}else c.compressedTexSubImage2D(t,n,0,0,i,a,r,s)}}else if(l){if(o==null)throw new e(`texture:missing-depth`,`Missing depth dimension for 3D texture upload`);c.compressedTexImage3D(t,n,r,i,a,o,0,s)}else c.compressedTexImage2D(t,n,r,i,a,0,s)}async _compressOnWorker(e){let{width:t,height:n,context:r,flipped:o,preMultiplyAlpha:s,hasMipmap:c,compress:l}=this._descriptor;if(!l)return;let{compressionTracker:u,compressionCallback:d,preserveSourceBitmap:f}=l,{compressedTextureETC:p,compressedTextureS3TC:m}=r.capabilities;if(!S.compressionWorkerHandle?.isCompressible(e,this._descriptor)||!p&&!m)return;this.abortCompression();let h=new AbortController;this._compressionAbortController=h,u?.increment();let g,_=!1,v=!1;try{e instanceof ImageBitmap?f?(g=await createImageBitmap(e),i(h),v=!0):g=e:e instanceof Uint8Array?(g=e.buffer,_=this.descriptor.flipped):(g=await createImageBitmap(e,{imageOrientation:o?`flipY`:`none`}),i(h),v=!0);let r={data:g,width:t,height:n,needsFlip:_,components:this._descriptor.pixelFormat===6408?4:3,preMultiplyAlpha:s,isOpaque:this._descriptor.isOpaque,hasMipmap:c,hasETC:!!p,hasS3TC:!!m},a=await S.compressionWorkerHandle.invoke(r,h.signal,1);if(i(h),a.compressedTexture&&this.hasWebGLTextureObject){let e=this.usedMemory;this._descriptor.internalFormat=a.internalFormat,this._setData(a.compressedTexture),d?.(e-this.usedMemory)}}catch(e){a(e)||x().error(`Texture compression failed!`)}finally{u?.decrement(),this._compressionAbortController?.signal.aborted&&(this._compressionAbortController=null),v&&g instanceof ImageBitmap&&g.close()}}_forEachMipmapLevel(t,n=1/0){let{width:r,height:i,depth:a,hasMipmap:o,target:s}=this._descriptor,c=s===32879;if(r==null||i==null||c&&a==null)throw new e(`texture:missing-size`,`Missing texture dimensions for mipmap calculation`);for(let e=0;t(e,r,i,a),!(!o||r===1&&i===1&&(!c||a===1)||e>=n);++e)r=Math.max(1,r>>1),i=Math.max(1,i>>1),c&&(a=Math.max(1,a>>1))}_applySamplingMode(){let e=this._descriptor,t=e.context?.gl,n=e.samplingMode,r=e.samplingMode;n===9985||n===9987?(n=9729,e.hasMipmap||(r=9729)):(n===9984||n===9986)&&(n=9728,e.hasMipmap||(r=9728)),t.texParameteri(e.target,t.TEXTURE_MAG_FILTER,n),t.texParameteri(e.target,t.TEXTURE_MIN_FILTER,r),e.maxMipLevel!=null&&t.texParameteri(e.target,t.TEXTURE_MAX_LEVEL,e.maxMipLevel)}_applyWrapMode(){let e=this._descriptor,t=e.context?.gl;typeof e.wrapMode==`number`?(t.texParameteri(e.target,t.TEXTURE_WRAP_S,e.wrapMode),t.texParameteri(e.target,t.TEXTURE_WRAP_T,e.wrapMode)):(t.texParameteri(e.target,t.TEXTURE_WRAP_S,e.wrapMode.s),t.texParameteri(e.target,t.TEXTURE_WRAP_T,e.wrapMode.t))}_applyShadowMode(){let e=this._descriptor,t=e.context?.gl,n=e.compareEnabled?t.COMPARE_REF_TO_TEXTURE:t.NONE;t.texParameteri(e.target,t.TEXTURE_COMPARE_MODE,n),e.compareEnabled&&t.texParameteri(e.target,t.TEXTURE_COMPARE_FUNC,t.GREATER),o(t)}_applyAnisotropicFilteringParameters(){let e=this._descriptor,t=e.context.capabilities.textureFilterAnisotropic;t&&e.context.gl.texParameterf(e.target,t.TEXTURE_MAX_ANISOTROPY,e.maxAnisotropy??1)}}export{S as default};
|
|
2
|
+
import e from"../../core/Error.js";import has from"../../core/has.js";import t from"../../core/Logger.js";import{abortMaybe as n}from"../../core/maybe.js";import{hasValue as r}from"../../core/object.js";import{throwIfAborted as i,isAbortError as a}from"../../core/promiseUtils.js";import{checkWebGLError as o}from"./checkWebGLError.js";import{ResourceType as s,CompressedTextureFormat as c}from"./enums.js";import{estimateMemory as l}from"./TextureDescriptor.js";import{isCompressedData as u,deriveInternalFormat as d,isTexImageSource as f,is3DTarget as p,validateTexture as m,isCompressedFormat as h,getDimensions as g,isSizedPixelFormat as _,calcMipmapLevels as v}from"./textureUtils.js";import{ValidatedTextureDescriptor as y}from"./ValidatedTextureDescriptor.js";const b=!!has(`esri-tests-disable-gpu-memory-measurements`),x=()=>t.getLogger(`esri/views/webgl/Texture`);class S{static{this.TEXTURE_UNIT_FOR_UPDATES=0}static{this.compressionWorkerHandle=null}constructor(t,n=null,r=null){if(this.type=1,this._glName=null,this._samplingModeDirty=!1,this._wrapModeDirty=!1,this._shadowFilterDirty=!1,this._wasImmutablyAllocated=!1,`context`in t)this._descriptor=t,r=n;else{let r=y.validate(t,n);if(!r)throw new e(`texture:invalid-descriptor`,`Texture descriptor invalid`);this._descriptor=r}this._descriptor.target===34067?this._setDataCubeMap(r):this.setData(r)}get glName(){return this._glName}get descriptor(){return this._descriptor}get usedMemory(){return b?0:l(this._descriptor)}get isDirty(){return this._samplingModeDirty||this._wrapModeDirty||this._shadowFilterDirty}get hasWebGLTextureObject(){return!!this._glName}dispose(){this.abortCompression(),this.hasWebGLTextureObject&&this._descriptor.context?.gl&&(this._descriptor.context.instanceCounter.decrement(s.Texture,this),this._descriptor.context.unbindTexture(this),this._descriptor.context.gl.deleteTexture(this._glName),this._glName=null)}release(){this.dispose()}[Symbol.dispose](){this.dispose()}resize(t,n){let r=this._descriptor;if(r.width!==t||r.height!==n){if(this._wasImmutablyAllocated)throw new e(`texture:immutable-resize`,`Immutable textures can't be resized!`);r.width=t,r.height=n,this._descriptor.target===34067?this._setDataCubeMap(null):this.setData(null)}}enableCompression(e){this._descriptor.compress=e}disableCompression(){this._descriptor.compress=void 0}setData(e){this.abortCompression(),!u(e)&&this._descriptor.internalFormat&&r(c,this._descriptor.internalFormat)&&(this._descriptor.internalFormat=void 0),this._setData(e),!u(e)&&this._descriptor.compress&&this._compressOnWorker(e)}updateData(t,n,r,i,a,o,s=0){o||x().error(`An attempt to use uninitialized data!`),this.hasWebGLTextureObject||x().error(`An attempt to update uninitialized texture!`);let c=this._descriptor;c.internalFormat=d(c);let{context:l,pixelFormat:p,dataType:m,target:h,isImmutable:g}=c;if(g&&!this._wasImmutablyAllocated)throw new e(`texture:uninitialized`,`Cannot update immutable texture before allocation!`);let _=l.bindTexture(this,S.TEXTURE_UNIT_FOR_UPDATES,!0);(n<0||r<0||n+i>c.width||r+a>c.height)&&x().error(`An attempt to update out of bounds of the texture!`),this._configurePixelStorage();let{gl:v}=l;s&&(i&&a||x().warn("Must pass width and height if `UNPACK_SKIP_ROWS` is used"),v.pixelStorei(v.UNPACK_SKIP_ROWS,s)),f(o)?v.texSubImage2D(h,t,n,r,i,a,p,m,o):u(o)?v.compressedTexSubImage2D(h,t,n,r,i,a,c.internalFormat,o.levels[t]):v.texSubImage2D(h,t,n,r,i,a,p,m,o),s&&v.pixelStorei(v.UNPACK_SKIP_ROWS,0),l.bindTexture(_,S.TEXTURE_UNIT_FOR_UPDATES)}updateData3D(t,n,r,i,a,o,s,c){c||x().error(`An attempt to use uninitialized data!`),this.hasWebGLTextureObject||x().error(`An attempt to update an uninitialized texture!`);let l=this._descriptor;l.internalFormat=d(l);let{context:f,pixelFormat:m,dataType:h,isImmutable:g,target:_}=l;if(g&&!this._wasImmutablyAllocated)throw new e(`texture:uninitialized`,`Cannot update immutable texture before allocation!`);p(_)||x().warn(`Attempting to set 3D texture data on a non-3D texture`);let v=f.bindTexture(this,S.TEXTURE_UNIT_FOR_UPDATES);f.setActiveTexture(S.TEXTURE_UNIT_FOR_UPDATES),(n<0||r<0||i<0||n+a>l.width||r+o>l.height||i+s>l.depth)&&x().error(`An attempt to update out of bounds of the texture!`),this._configurePixelStorage();let{gl:y}=f;if(u(c))c=c.levels[t],y.compressedTexSubImage3D(_,t,n,r,i,a,o,s,l.internalFormat,c);else{let e=c;y.texSubImage3D(_,t,n,r,i,a,o,s,m,h,e)}f.bindTexture(v,S.TEXTURE_UNIT_FOR_UPDATES)}generateMipmap(){let t=this._descriptor;if(t.width===0||t.height===0)return;if(!t.hasMipmap){if(this._wasImmutablyAllocated)throw new e(`texture:immutable-change`,`Cannot add mipmaps to immutable texture after allocation`);t.hasMipmap=!0,this._samplingModeDirty=!0,m(t)}t.samplingMode===9729?(this._samplingModeDirty=!0,t.samplingMode=9985):t.samplingMode===9728&&(this._samplingModeDirty=!0,t.samplingMode=9984);let n=this._descriptor.context.bindTexture(this,S.TEXTURE_UNIT_FOR_UPDATES);this._descriptor.context.setActiveTexture(S.TEXTURE_UNIT_FOR_UPDATES),this._descriptor.context.gl.generateMipmap(t.target),this._descriptor.context.bindTexture(n,S.TEXTURE_UNIT_FOR_UPDATES)}clearMipmap(){let t=this._descriptor;if(t.hasMipmap){if(this._wasImmutablyAllocated)throw new e(`texture:immutable-change`,`Cannot delete mipmaps to immutable texture after allocation`);t.hasMipmap=!1,this._samplingModeDirty=!0,m(t)}t.samplingMode===9985?(this._samplingModeDirty=!0,t.samplingMode=9729):t.samplingMode===9984&&(this._samplingModeDirty=!0,t.samplingMode=9728)}setSamplingMode(e){e!==this._descriptor.samplingMode&&(this._descriptor.samplingMode=e,this._samplingModeDirty=!0)}setWrapMode(e){e!==this._descriptor.wrapMode&&(this._descriptor.wrapMode=e,m(this._descriptor),this._wrapModeDirty=!0)}setShadowFiltering(e){e!==this._descriptor.linearFilterDepth&&(this._descriptor.linearFilterDepth=this._descriptor.compareEnabled=e,this.setSamplingMode(e?9729:9728),m(this._descriptor),this._shadowFilterDirty=!0)}applyChanges(){this._samplingModeDirty&&=(this._applySamplingMode(),!1),this._wrapModeDirty&&=(this._applyWrapMode(),!1),this._shadowFilterDirty&&=(this._applyShadowMode(),!1)}abortCompression(){this._compressionAbortController=n(this._compressionAbortController)}_setData(t,n){let r=this._descriptor,i=r.context?.gl;if(!i)return;o(i),this.hasWebGLTextureObject||(this._glName=i.createTexture(),r.context.instanceCounter.increment(s.Texture,this)),m(r);let a=r.context.bindTexture(this,S.TEXTURE_UNIT_FOR_UPDATES);r.context.setActiveTexture(S.TEXTURE_UNIT_FOR_UPDATES),this._configurePixelStorage(),o(i);let c=n??r.target,l=p(c);if(f(t))this._setDataFromTexImageSource(t,c);else{let{width:n,height:a,depth:s}=r;if(n==null||a==null)throw new e(`texture:missing-size`,`Width and height must be specified!`);if(l&&s==null)throw new e(`texture:missing-depth`,`Depth must be specified!`);if(r.internalFormat=d(r),r.isImmutable&&!this._wasImmutablyAllocated&&this._texStorage(c,r.internalFormat,r.hasMipmap,n,a,s),u(t)){if(!h(r.internalFormat))throw new e(`texture:format-mismatch`,`Attempting to use compressed data with an uncompressed format!`);this._setDataFromCompressedSource(t,r.internalFormat,c)}else this._texImage(c,0,r.internalFormat,n,a,s,t),o(i),r.hasMipmap&&this.generateMipmap()}this._applySamplingMode(),this._applyWrapMode(),this._applyAnisotropicFilteringParameters(),this._applyShadowMode(),o(i),r.context.bindTexture(a,S.TEXTURE_UNIT_FOR_UPDATES)}_setDataCubeMap(e=null){for(let t=34069;t<=34074;t++)this._setData(e,t)}_configurePixelStorage(){let e=this._descriptor.context.gl,{unpackAlignment:t,flipped:n,preMultiplyAlpha:r}=this._descriptor;e.pixelStorei(e.UNPACK_ALIGNMENT,t),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,+!!n),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,+!!r)}_setDataFromTexImageSource(e,t){let{gl:n}=this._descriptor.context,r=this._descriptor;r.internalFormat=d(r);let i=p(t),{width:a,height:s,depth:c}=g(e);r.width&&r.height,r.width||=a,r.height||=s,i&&r.depth,i&&(r.depth=c),r.isImmutable&&!this._wasImmutablyAllocated&&this._texStorage(t,r.internalFormat,r.hasMipmap,a,s,c),this._texImage(t,0,r.internalFormat,a,s,c,e),o(n),r.hasMipmap&&(this.generateMipmap(),o(n))}_setDataFromCompressedSource(e,t,n){let r=this._descriptor,{width:i,height:a,depth:o}=r,s=e.levels,c=v(n,i,a,o),l=Math.min(c,s.length)-1;this._descriptor.context.gl.texParameteri(r.target,33085,l),this._forEachMipmapLevel((e,r,i,a)=>{let o=s[Math.min(e,s.length-1)];this._compressedTexImage(n,e,t,r,i,a,o)},l)}_texStorage(t,n,r,i,a,o){let{gl:s}=this._descriptor.context;if(!_(n)&&!h(n))throw new e(`texture:missing-format`,`Immutable textures must have a sized or compressed internal format`);if(!this._descriptor.isImmutable)return;let c=r?v(t,i,a,o):1;if(p(t)){if(o==null)throw new e(`texture:missing-depth`,`Missing depth dimension for 3D texture upload`);s.texStorage3D(t,c,n,i,a,o)}else s.texStorage2D(t,c,n,i,a);this._wasImmutablyAllocated=!0}_texImage(t,n,r,i,a,o,s){let c=this._descriptor.context.gl,l=p(t),{isImmutable:u,pixelFormat:d,dataType:f}=this._descriptor;if(u){if(s!=null){let r=s;if(l){if(o==null)throw new e(`texture:missing-depth`,`Missing depth dimension for 3D texture upload`);c.texSubImage3D(t,n,0,0,0,i,a,o,d,f,r)}else c.texSubImage2D(t,n,0,0,i,a,d,f,r)}}else{let u=s;if(l){if(o==null)throw new e(`texture:missing-depth`,`Missing depth dimension for 3D texture upload`);c.texImage3D(t,n,r,i,a,o,0,d,f,u)}else c.texImage2D(t,n,r,i,a,0,d,f,u)}}_compressedTexImage(t,n,r,i,a,o,s){let c=this._descriptor.context.gl,l=p(t);if(this._descriptor.isImmutable){if(s!=null){if(l){if(o==null)throw new e(`texture:missing-depth`,`Missing depth dimension for 3D texture upload`);c.compressedTexSubImage3D(t,n,0,0,0,i,a,o,r,s)}else c.compressedTexSubImage2D(t,n,0,0,i,a,r,s)}}else if(l){if(o==null)throw new e(`texture:missing-depth`,`Missing depth dimension for 3D texture upload`);c.compressedTexImage3D(t,n,r,i,a,o,0,s)}else c.compressedTexImage2D(t,n,r,i,a,0,s)}async _compressOnWorker(e){let{width:t,height:n,context:r,flipped:o,preMultiplyAlpha:s,hasMipmap:c,compress:l}=this._descriptor;if(!l)return;let{compressionTracker:u,compressionCallback:d,preserveSourceBitmap:f}=l,{compressedTextureETC:p,compressedTextureS3TC:m}=r.capabilities;if(!S.compressionWorkerHandle?.isCompressible(e,this._descriptor)||!p&&!m)return;this.abortCompression();let h=new AbortController;this._compressionAbortController=h,u?.increment();let g,_=!1,v=!1;try{e instanceof ImageBitmap?f?(g=await createImageBitmap(e),i(h),v=!0):g=e:e instanceof Uint8Array?(g=e.buffer,_=this.descriptor.flipped):(g=await createImageBitmap(e,{imageOrientation:o?`flipY`:`none`}),i(h),v=!0);let r={data:g,width:t,height:n,needsFlip:_,components:this._descriptor.pixelFormat===6408?4:3,preMultiplyAlpha:s,isOpaque:this._descriptor.isOpaque,hasMipmap:c,hasETC:!!p,hasS3TC:!!m},a=await S.compressionWorkerHandle.invoke(r,h.signal,1);if(i(h),a.compressedTexture&&this.hasWebGLTextureObject){let e=this.usedMemory;this._descriptor.internalFormat=a.internalFormat,this._setData(a.compressedTexture),d?.(e-this.usedMemory)}}catch(e){a(e)||x().error(`Texture compression failed!`)}finally{u?.decrement(),this._compressionAbortController?.signal.aborted&&(this._compressionAbortController=null),v&&g instanceof ImageBitmap&&g.close()}}_forEachMipmapLevel(t,n=1/0){let{width:r,height:i,depth:a,hasMipmap:o,target:s}=this._descriptor,c=s===32879;if(r==null||i==null||c&&a==null)throw new e(`texture:missing-size`,`Missing texture dimensions for mipmap calculation`);for(let e=0;t(e,r,i,a),!(!o||r===1&&i===1&&(!c||a===1)||e>=n);++e)r=Math.max(1,r>>1),i=Math.max(1,i>>1),c&&(a=Math.max(1,a>>1))}_applySamplingMode(){let e=this._descriptor,t=e.context?.gl,n=e.samplingMode,r=e.samplingMode;n===9985||n===9987?(n=9729,e.hasMipmap||(r=9729)):(n===9984||n===9986)&&(n=9728,e.hasMipmap||(r=9728)),t.texParameteri(e.target,t.TEXTURE_MAG_FILTER,n),t.texParameteri(e.target,t.TEXTURE_MIN_FILTER,r),e.maxMipLevel!=null&&t.texParameteri(e.target,t.TEXTURE_MAX_LEVEL,e.maxMipLevel)}_applyWrapMode(){let e=this._descriptor,t=e.context?.gl;typeof e.wrapMode==`number`?(t.texParameteri(e.target,t.TEXTURE_WRAP_S,e.wrapMode),t.texParameteri(e.target,t.TEXTURE_WRAP_T,e.wrapMode)):(t.texParameteri(e.target,t.TEXTURE_WRAP_S,e.wrapMode.s),t.texParameteri(e.target,t.TEXTURE_WRAP_T,e.wrapMode.t))}_applyShadowMode(){let e=this._descriptor,t=e.context?.gl,n=e.compareEnabled?t.COMPARE_REF_TO_TEXTURE:t.NONE;t.texParameteri(e.target,t.TEXTURE_COMPARE_MODE,n),e.compareEnabled&&t.texParameteri(e.target,t.TEXTURE_COMPARE_FUNC,t.GREATER),o(t)}_applyAnisotropicFilteringParameters(){let e=this._descriptor,t=e.context.capabilities.textureFilterAnisotropic;t&&e.context.gl.texParameterf(e.target,t.TEXTURE_MAX_ANISOTROPY,e.maxAnisotropy??1)}}export{S as Texture};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{ZEROS as e}from"../../core/libs/gl-matrix-2/factories/vec2f64.js";import{SizedPixelFormat as t,PixelType as n}from"./enums.js";import r
|
|
2
|
+
import{ZEROS as e}from"../../core/libs/gl-matrix-2/factories/vec2f64.js";import{SizedPixelFormat as t,PixelType as n}from"./enums.js";import{Texture as r}from"./Texture.js";import{TextureDescriptor as i}from"./TextureDescriptor.js";function a(e,a,o=`nearest`,s=!1){let c=!(s&&a.pixelType===`u8`),l=c?n.FLOAT:n.UNSIGNED_BYTE,u=a.pixels==null||a.pixels.length===0?null:c?a.getAsRGBAFloat():a.getAsRGBA(),d=e.capabilities.textureFloatLinear,f=new i(a.width,a.height);return f.internalFormat=c?t.RGBA32F:6408,f.samplingMode=d&&(o===`bilinear`||o===`cubic`)?9729:9728,f.dataType=l,f.wrapMode=33071,new r(e,f,u)}function o(e,a){let{spacing:o,offsets:s,coefficients:c,size:[l,u]}=a,d=o[0]>1,f=new i(d?l*4:l,u);f.internalFormat=t.RGBA32F,f.dataType=n.FLOAT,f.samplingMode=9728,f.wrapMode=33071;let p=new Float32Array(d?l*u*16:s.length*2);if(d&&c!=null)for(let e=0,t=0;e<c.length;e++)p[t++]=c[e],e%3==2&&(p[t++]=1);else for(let e=0;e<u;e++)for(let t=0;t<l;t++){let n=(e*l+t)*4,r=(t*u+e)*2;p[n]=s[r],p[n+1]=s[r+1],p[n+3]=s[r]===-1?0:1}return new r(e,f,p)}function s(e,t){let n=new i(t.length/4,1);return n.internalFormat=6408,n.samplingMode=9728,n.wrapMode=33071,new r(e,n,t)}function c(e,t,a){let o=new i(a[0],a[1]);return o.internalFormat=6406,o.pixelFormat=6406,o.dataType=n.UNSIGNED_BYTE,o.samplingMode=9728,o.wrapMode=33071,new r(e,o,t)}function l(t,n,r,i=1,a=!0){return{u_flipY:a,u_applyTransform:!!t,u_opacity:i,u_transformSpacing:t?t.spacing:e,u_transformGridSize:t?t.size:e,u_targetImageSize:n,u_srcImageSize:r}}function u(e,t){return{u_colormapOffset:t||0,u_colormapMaxIndex:e?e.length/4-1:0}}function d(e){return{u_bandCount:e.bandCount,u_minOutput:e.minOutput,u_maxOutput:e.maxOutput,u_minCutOff:e.minCutOff,u_maxCutOff:e.maxCutOff,u_factor:e.factor,u_useGamma:e.useGamma,u_gamma:e.gamma,u_gammaCorrection:e.gammaCorrection}}function f(e){return{u_hillshadeType:e.hillshadeType,u_sinZcosAs:e.sinZcosAs,u_sinZsinAs:e.sinZsinAs,u_cosZs:e.cosZs,u_weights:e.weights,u_factor:e.factor,u_minValue:e.minValue,u_maxValue:e.maxValue}}export{s as createColormapTexture,c as createPixelMaskTexture,a as createRasterTexture,o as createTransformTexture,u as getColormapUniforms,l as getCommonUniforms,f as getShadedReliefUniforms,d as getStretchUniforms};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{PrimitiveType as e,PixelType as t}from"./enums.js";import{DisposableFramebufferObject as n}from"./FramebufferObject.js";import r
|
|
2
|
+
import{PrimitiveType as e,PixelType as t}from"./enums.js";import{DisposableFramebufferObject as n}from"./FramebufferObject.js";import{Texture as r}from"./Texture.js";import{TextureDescriptor as i}from"./TextureDescriptor.js";import{VertexArrayObject as a}from"./VertexArrayObject.js";import{Pos2usLocations as o,Pos2us as s}from"./VertexAttributeLayouts.js";import{VertexBuffer as c}from"./VertexBuffer.js";import{WebGLDriverTestModule as l}from"./WebGLDriverTestModule.js";class u extends l{constructor(e){super(),this._rctx=e,this._program=e.programCache.get(`
|
|
3
3
|
precision highp float;
|
|
4
4
|
|
|
5
5
|
attribute vec2 position;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import e from"../../core/Error.js";import t from"../../core/Logger.js";import{hasValue as n}from"../../core/object.js";import{PixelType as r,SizedPixelFormat as i,SizedDepthStencilFormat as a,SizedDepthFormat as o,
|
|
2
|
+
import e from"../../core/Error.js";import t from"../../core/Logger.js";import{hasValue as n}from"../../core/object.js";import{PixelType as r,SizedPixelFormat as i,SizedDepthStencilFormat as a,SizedDepthFormat as o,sizedPixelFormatValues as s,CompressedTextureFormat as c}from"./enums.js";const l=()=>t.getLogger(`esri/views/webgl/textureUtils`);function u(e){let{width:t,height:n,depth:r}=e;(t!=null&&t<0||n!=null&&n<0||r!=null&&r<0)&&l().error(`Negative dimension parameters are not allowed!`);let{internalFormat:i}=e;if(i&&(p(i)||m(i))){let{linearFilterDepth:t,compareEnabled:n,samplingMode:r,hasMipmap:i}=e;i&&l().error(`Depth textures cannot have mipmaps`),t?r!==9729&&r!==9728&&l().error(`Depth textures cannot sample mipmaps`):(r!==9728&&l().error(`Depth textures without filtering must use NEAREST filtering`),n&&l().error(`Depth textures without filtering cannot use compare function`))}}function d(e){return f(e)||p(e)||m(e)}function f(e){return s.includes(e)}function p(e){return n(o,e)}function m(e){return n(a,e)}function h(e){return e!=null&&n(c,e)}function g(e){return e!=null&&`type`in e&&e.type===`compressed`}function _(e){return e!=null&&`byteLength`in e}function v(e){return e!=null&&!g(e)&&!_(e)}function y(e){return e===32879||e===35866}function b(e,t,n,r=1){let i=Math.max(t,n);return e===32879&&(i=Math.max(i,r)),Math.floor(Math.log2(i))+1}function x(t){if(t.internalFormat!=null)return t.internalFormat;switch(t.dataType){case r.FLOAT:switch(t.pixelFormat){case 6408:return i.RGBA32F;case 6407:return i.RGB32F;default:throw new e(`texture:unknown-format`,`Unable to derive format`)}case r.UNSIGNED_BYTE:switch(t.pixelFormat){case 6408:return i.RGBA8;case 6407:return i.RGB8}}let{pixelFormat:n}=t;return t.internalFormat=n===34041?a.DEPTH24_STENCIL8:n===6402?o.DEPTH_COMPONENT24:n,t.internalFormat}function S(e){let t=`width`in e?e.width:e.codedWidth,n=`height`in e?e.height:e.codedHeight;return e instanceof HTMLVideoElement&&(t=e.videoWidth,n=e.videoHeight),{width:t,height:n,depth:1}}export{b as calcMipmapLevels,x as deriveInternalFormat,S as getDimensions,y as is3DTarget,_ as isArrayBufferView,g as isCompressedData,h as isCompressedFormat,f as isSizedColorFormat,p as isSizedDepthFormat,m as isSizedDepthStencilFormat,d as isSizedPixelFormat,v as isTexImageSource,u as validateTexture};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{throwIfAborted as n}from"../../../core/promiseUtils.js";import{property as r,subclass as i}from"../../../core/accessorSupport/decorators.js";import a from"../../../geometry/Point.js";import{polygonCentroidPoint as o}from"../../../geometry/support/centroid.js";import s from"../../../layers/orientedImagery/core/ExposurePoint.js";import{createFeatureCoverage as c}from"../featureCoverage.js";import{NoSequenceFoundError as l,NoImageInSequenceError as u,InvalidDirectionError as d}from"./errors.js";import{queryNextLocationFeatures as f,queryAfterSequenceField as p,querySequenceFeaturesAroundPoint as m,queryOffsetSequenceFeatures as h}from"./queries.js";import{
|
|
2
|
+
import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{throwIfAborted as n}from"../../../core/promiseUtils.js";import{property as r,subclass as i}from"../../../core/accessorSupport/decorators.js";import a from"../../../geometry/Point.js";import{polygonCentroidPoint as o}from"../../../geometry/support/centroid.js";import s from"../../../layers/orientedImagery/core/ExposurePoint.js";import{createFeatureCoverage as c}from"../featureCoverage.js";import{NoSequenceFoundError as l,NoImageInSequenceError as u,InvalidDirectionError as d}from"./errors.js";import{queryNextLocationFeatures as f,queryAfterSequenceField as p,querySequenceFeaturesAroundPoint as m,queryOffsetSequenceFeatures as h}from"./queries.js";import{shouldQueryAndNavigate as g}from"./utils.js";let _=class extends t{constructor(e){super(e),this._navigating=!1,this.viewModel=null}get currentNode(){return this.viewModel.currentNode}get layer(){return this.viewModel.layer}get navigating(){return this._navigating}get navigationNodes(){return this.viewModel.navigationNodes}async _queryAndHandleFeatureResponse(e,t,r,i,a){let{error:o,nextLocation:s,response:c}=await f(e,t,r,i,a);if(n(a),o)throw o;this.viewModel.selectedPoint=s,await this.viewModel.processFeatureResponse(c,s,{signal:a?.signal,loadBestImage:!1})}async afterNavigate(e,t,n){return await this.viewModel.selectBestFeature(t.id,n),t}async navigate(e,t){this._navigating=!0;try{let n;if(`direction`in t?n=await this.navigateInDirection(e,t):(`step`in t||`goTo`in t)&&(n=await this.navigateInSequence(e,t)),this._navigating=!1,!n)throw Error(`No next node found`);return await this.afterNavigate(e,n,t)}catch(e){throw this._navigating=!1,e}}async navigateBySkippingSteps(e,t){let{step:n}=t,{layer:r}=this,{layerFloorFilterClause:i,layerTimeExtent:d,preloadMediaSize:f}=this.viewModel;if(!r)throw Error(`Layer is not defined`);let h=e.attributes.sequenceOrder;if(!h)throw new l;let{response:g,error:_}=await p(r,h,n>0?`next`:`previous`,f,i??void 0,d,{signal:t.signal});if(_)throw Error(`Error querying sequence features`);let v=g?.features[0];if(!v)throw new u(n>0?`end`:`start`);let y=s.fromJSON({...v.toJSON(),layer:r}),{polygon:b}=c(y),x=a.fromJSON(o(b)),{response:S,error:C,nextLocation:w}=await m(r,x,i??void 0,d,{signal:t.signal});if(C)throw Error(`Error querying sequence features`);let T=new Set(S.features.map(e=>e.attributes.objectId));S.features=[...g.features.filter(e=>!T.has(e.attributes.objectId)),...S.features],this.viewModel.selectedPoint=w;let E=v.attributes.objectId;await this.viewModel.processFeatureResponse(S,w,{signal:t.signal,loadBestImage:!1});let D=this.viewModel.navigationNodes.toArray();D.sort((e,t)=>{let n=e.attributes.sequenceOrder,r=t.attributes.sequenceOrder;if(!n||!r)return 0;let i=n.length;for(let e=0;e<i;e++){let{value:t,sortOrder:i}=n[e],{value:a}=r[e];if(i===`desc`){if(t<a)return 1;if(t>a)return-1}else{if(t<a)return-1;if(t>a)return 1}}return 0});let O=D.length;for(let e=0;e<O;e++){let t=D[e];t.previous=e>0?D[e-1]:null,t.next=e<O-1?D[e+1]:null}return this.viewModel.selectedPoint=w,this.viewModel.navigationNodes.find(e=>e.id===E)}async navigateInDirection(e,t){let{viewModel:n}=this,{layer:r,layerFloorFilterClause:i,layerTimeExtent:a}=n,{direction:o,signal:s}=t,c=e?.[o];if(!c)throw new d(o);return g(c,o)&&await this._queryAndHandleFeatureResponse(r,c,i??void 0,a,{signal:s}),c}async navigateInSequence(e,t){return`step`in t?this.navigateBySkippingSteps(e,t):this.navigateTo(t)}async navigateTo(e){let{goTo:t}=e,{layer:n}=this,{layerFloorFilterClause:r,layerTimeExtent:i}=this.viewModel;if(!n)throw Error(`Layer is not defined`);let l=typeof t==`number`?t:1,u=this.viewModel.navigationNodes.find(e=>e.id===l);if(u)return u;let{response:d,error:f}=await h(n,l,1,t===`end`?`DESC`:`ASC`,r??void 0,i,{signal:e.signal});if(f)throw Error(`Error querying sequence features`);let p=d?.features[0];if(!p)throw Error(`No next node found`);let g=s.fromJSON({...p.toJSON(),layer:n}),{polygon:_}=c(g),v=a.fromJSON(o(_)),{response:y,error:b,nextLocation:x}=await m(n,v,r??void 0,i,{signal:e.signal});if(b)throw Error(`Error querying sequence features`);let S=[...y.features];S.push(p),y.features=S,this.viewModel.selectedPoint=x;let C=p.attributes.objectId;return await this.viewModel.processFeatureResponse(y,x,{signal:e.signal,loadBestImage:!1}),this.viewModel.selectedPoint=x,this.viewModel.navigationNodes.find(e=>e.id===C)}};e([r()],_.prototype,`_navigating`,void 0),e([r()],_.prototype,`currentNode`,null),e([r()],_.prototype,`layer`,null),e([r()],_.prototype,`navigating`,null),e([r()],_.prototype,`navigationNodes`,null),e([r({constructOnly:!0})],_.prototype,`viewModel`,void 0),_=e([i(`esri.widgets.OrientedImageryViewer.navigation.NavigationManager`)],_);export{_ as default};
|