UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 4.36 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{_ as e}from"../../../../../chunks/tslib.es6.js";import{disposeMaybe as r}from"../../../../../core/maybe.js";import{throwIfAborted as t}from"../../../../../core/promiseUtils.js";import{watch as s,syncAndInitial as i}from"../../../../../core/reactiveUtils.js";import{property as a}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/has.js";import"../../../../../core/Logger.js";import"../../../../../core/RandomLCG.js";import{subclass as o}from"../../../../../core/accessorSupport/decorators/subclass.js";import{requestImage as n}from"../../../../../support/requestImageUtils.js";import{InternalRenderCategory as c,RenderCategory as h}from"../../../webgl.js";import{ColorFormat as m}from"../../../webgl/formats.js";import l from"../../../webgl/RenderNode.js";import{SMAABlendWeightsTechnique as u}from"./SMAABlendWeightsTechnique.js";import{SMAABlurTechnique as p}from"./SMAABlurTechnique.js";import{SMAAEdgeDetectTechnique as d}from"./SMAAEdgeDetectTechnique.js";import{SMAAPassParameters as f}from"./SMAAPassParameters.js";import{RenderRequestType as b}from"../../lib/basicInterfaces.js";import{PixelFormat as T,TextureSamplingMode as x,FramebufferBit as _,TextureWrapMode as g}from"../../../../webgl/enums.js";import{Texture as A}from"../../../../webgl/Texture.js";import{TextureDescriptor as C}from"../../../../webgl/TextureDescriptor.js";let w=class extends l{constructor(e){super(e),this.produces="disabled",this.consumes={required:[c.ANTIALIASING],optional:[h.COMPOSITE]},this._areaTexture=null,this._searchTexture=null,this._smaaParameters=new f}initialize(){this.addHandles([s((()=>this.isEnabled()),(e=>e?this.enable():this.disable()),i)])}async enable(){if(this.produces=c.ANTIALIASING,this._abortController||this._areaTexture&&this._searchTexture)return;this._abortController=new AbortController;const e=this._abortController.signal;try{const r=await import("./SMAAData.js");await this._loadTextures(r,e),this.requestRender(b.UPDATE)}catch{}this._abortController=null}async _loadTextures(e,r){t(r);const[s,i]=await Promise.allSettled([n(e.areaTexture,{signal:r}),n(e.searchTexure,{signal:r})]);if(t(r),"fulfilled"!==s.status||"fulfilled"!==i.status)return;const a=this.renderingContext;this._areaTexture=j(a,x.LINEAR,T.RGB,s.value),this._searchTexture=j(a,x.NEAREST,T.LUMINANCE,i.value)}disable(){this.produces="disabled"}destroy(){this._searchTexture=r(this._searchTexture),this._areaTexture=r(this._areaTexture)}precompile(){this.techniques.precompile(d),this.techniques.precompile(u),this.techniques.precompile(p)}render(e){const r=e.find((({name:e})=>e===c.ANTIALIASING));if(!this._areaTexture||!this._searchTexture)return this.requestRender(b.UPDATE),r;const t=this.techniques.get(d),s=this.techniques.get(u),i=this.techniques.get(p);if(!t.compiled||!s.compiled||!i.compiled)return this.requestRender(b.UPDATE),r;const a=e.find((({name:e})=>e===h.COMPOSITE));if(!a)return r;const o=a.fbo.width,n=a.fbo.height,l=this.renderingContext;l.setViewport(0,0,o,n);const f=this.fboCache.acquire(o,n,"smaa edges",m.RG);l.bindFramebuffer(f.fbo),l.setClearColor(0,0,0,1),l.clear(_.COLOR),this._smaaParameters.color=a.getTexture();const T=this.bindParameters;l.bindTechnique(t,T,this._smaaParameters),l.screen.draw();const x=this.fboCache.acquire(o,n,"smaa blend");return l.bindFramebuffer(x.fbo),l.setClearColor(0,0,1,1),l.clear(_.COLOR),this._smaaParameters.inputTexture=f.getTexture(),this._smaaParameters.areaTexture=this._areaTexture,this._smaaParameters.searchTexture=this._searchTexture,l.bindTechnique(s,T,this._smaaParameters),l.screen.draw(),f.release(),l.bindFramebuffer(r.fbo),l.setClearColor(0,1,0,1),l.clear(_.COLOR),this._smaaParameters.inputTexture=x.getTexture(),l.bindTechnique(i,T,this._smaaParameters),l.screen.draw(),x.release(),r}};function j(e,r,t,s){const i=new C;return i.pixelFormat=t,i.wrapMode=g.CLAMP_TO_EDGE,i.width=s.width,i.height=s.height,i.samplingMode=r,new A(e,i,s)}e([a()],w.prototype,"produces",void 0),e([a()],w.prototype,"consumes",void 0),e([a({constructOnly:!0})],w.prototype,"isEnabled",void 0),e([a()],w.prototype,"_abortController",void 0),w=e([o("esri.views.3d.webgl-engine.effects.smaa.SMAA")],w);export{w as SMAA};