/*
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","../../../../../core/maybe","../definitions","./Effect","../../../../webgl/enums"],(function(t,e,i,n,s,o){"use strict";let r=function(t){function s(){var e;return(e=t.apply(this,arguments)||this).name=e.constructor.name,e.defines=["hittest"],e}e._inheritsLoose(s,t);var r=s.prototype;return r.dispose=function(){i.isSome(this._fbo)&&this._fbo.dispose()},r.createOptions=function({pixelRatio:t},e,i=n.HITTEST_RADIUS){if(!e.length)return null;const s=e.shift(),o=s.point.x,r=s.point.y;return this._outstanding=s,{type:"hittest",distance:i*t,position:[o,r]}},r.bind=function(t){const{context:e,attributeView:s}=t;if(!s.size)return;const o=s.getBlock(n.ATTRIBUTE_DATA_GPGPU);if(i.isNone(o))return;const r=o.getFBO(e);e.setViewport(0,0,s.size,s.size),e.bindFramebuffer(r),e.setColorMask(!0,!0,!0,!0),e.setClearColor(0,0,0,0),e.clear(e.gl.COLOR_BUFFER_BIT|e.gl.DEPTH_BUFFER_BIT)},r.unbind=function(t){},r.draw=function(t){const{context:e,attributeView:s}=t,r=s.getBlock(n.ATTRIBUTE_DATA_GPGPU);if(i.isNone(this._outstanding))return;const u=this._outstanding.resolver;if(i.isNone(r))return u.resolve([]),void(this._outstanding=null);const c=r.getFBO(e),l=new Uint8Array(c.width*c.height*4);c.readPixels(0,0,c.width,c.height,o.PixelFormat.RGBA,o.PixelType.UNSIGNED_BYTE,l);const d=[];for(let i=0;i<l.length;i+=4){const t=l[i],e=l[i+3];t&&d.push({id:i/4,directHits:e})}this._outstanding=null,d.sort(((t,e)=>e.directHits===t.directHits?e.id-t.id:e.directHits-t.directHits)),u.resolve(d.map((t=>t.id)))},s}(s.Effect);t.HittestEffect=r,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
