/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../chunks/_rollupPluginBabelHelpers","../../../../chunks/tslib.es6","../../../../core/Accessor","../../../../core/maybe","../../../../core/accessorSupport/decorators/property","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/ensureType","../../../../core/accessorSupport/decorators/subclass","../../../../chunks/vec4","../../../../chunks/vec4f64","./glUtil3D","../shaders/ShadowCastVisualizeTechnique","../shaders/ShadowCastVisualizeTechniqueConfiguration","../../../webgl/Util"],(function(e,t,s,i,n,a,o,r,h,u,c,l,d,_,p,b){"use strict";const f=l.fromValues(.01,0,.25,1),m=4e4,v=5e4,q=1/512;e.ShadowCastRenderer=function(e){function s(t,s,i,n){var a;return(a=e.call(this,{})||this)._techniqueRepository=t,a._rctx=s,a._shadowAccumulator=i,a._requestRender=n,a._passParameters={shadowCastMap:a._shadowCastTexture,sampleScale:0,color:f,threshold:.5,bandSize:.1,opacityFromElevation:1,__tagStrict:"NoParameters"},a._techniqueConfig=new p.ShadowCastVisualizeTechniqueConfiguration,a._enabled=!1,a._vao=d.createQuadVAO(s),a._techniqueConfig.visualization=p.ShadowCastVisualization.Gradient,a}t._inheritsLoose(s,e);var i=s.prototype;return i.normalizeCtorArgs=function(){return{}},i.dispose=function(){this._stop(),this._vao=n.disposeMaybe(this._vao),this._techniqueRepository.release(this._technique),this._technique=null,this._shadowAccumulator=null},i.render=function(e){if(!this._isRenderingVisualization)return;this._passParameters.sampleScale=1/this._computedSamples;const t=this.visualizeShadowCastTechnique;this._rctx.bindVAO(this._vao),this._rctx.bindTechnique(t,this._passParameters,e),this._rctx.drawArrays(t.primitiveType,0,b.vertexCount(this._vao,"geometry"))},i.setOptions=function(e){void 0!==e.enabled&&this._setEnabled(e.enabled),void 0!==e.color&&this._setColor(e.color),void 0!==e.threshold&&(this._threshold=e.threshold),void 0!==e.visualization&&(this._visualization=e.visualization),void 0!==e.bandSize&&(this._bandSize=e.bandSize),void 0!==e.bandsEnabled&&(this._bandsEnabled=e.bandsEnabled)},i._setColor=function(e){const t=this._passParameters.color;c.exactEquals(e,t)||(c.copy(this._passParameters.color,e),this._requestRenderIfRunning())},i._setEnabled=function(e){e!==this._enabled&&(e?this._start():this._stop())},i._requestRenderIfRunning=function(){this._enabled&&this._requestRender()},i._start=function(){this._enabled=!0,this._requestRender()},i._stop=function(){this._enabled=!1,this._requestRender()},t._createClass(s,[{key:"visualizeShadowCastTechnique",get:function(){return this._technique=this._techniqueRepository.releaseAndAcquire(_.ShadowCastVisualizeTechnique,this._techniqueConfig,this._technique),this._technique}},{key:"opacityFromElevation",get:function(){return this._passParameters.opacityFromElevation},set:function(e){this._passParameters.opacityFromElevation!==e&&(this._passParameters.opacityFromElevation=e,this.notifyChange("opacityFromElevation"))}},{key:"_isRenderingVisualization",get:function(){return this._enabled&&this._computedSamples>0&&this.opacityFromElevation>q}},{key:"_computedSamples",get:function(){return this._shadowAccumulator.computedSamples}},{key:"_shadowCastTexture",get:function(){return this._shadowAccumulator.shadowCastTexture}},{key:"_threshold",get:function(){return this._passParameters.threshold},set:function(e){this._threshold!==e&&(this._passParameters.threshold=e,this._requestRenderIfRunning())}},{key:"_visualization",get:function(){return this._techniqueConfig.visualization},set:function(e){e!==this._visualization&&(this._techniqueConfig.visualization=e,this._techniqueRepository.release(this._technique),this._technique=null,this._requestRenderIfRunning())}},{key:"_bandSize",get:function(){return this._passParameters.bandSize},set:function(e){e!==this._bandSize&&(this._passParameters.bandSize=e,this._requestRenderIfRunning())}},{key:"_bandsEnabled",get:function(){return this._techniqueConfig.bandsEnabled},set:function(e){e!==this._bandsEnabled&&(this._techniqueConfig.bandsEnabled=e,this._techniqueRepository.release(this._technique),this._technique=null,this._requestRenderIfRunning())}}]),s}(i),s.__decorate([a.property()],e.ShadowCastRenderer.prototype,"opacityFromElevation",null),e.ShadowCastRenderer=s.__decorate([u.subclass("esri.views.3d.webgl-engine.lib.ShadowCastRenderer")],e.ShadowCastRenderer),e.shadowCastDisableElevationMax=v,e.shadowCastDisableElevationMin=m,e.shadowCastDisabledElevationThreshold=q,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
