/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{DataType as e}from"../../../../webgl/enums.js";class t{constructor(e,t,s=0){this._rctx=e,this._techniques=t,this._sorting=s,this._draws=new Array,this._previouslyBoundDraw=new Map}submitDraw(e,t,i,r,n){const a=(t.indexed?t.vao.indexBuffer.indexType:null)??0,o=new s(e,t,i,r,a,n);this._draws.push(o)}acquire(e,t){return this._draws.map(s=>s.material.acquireTechnique(this._techniques,e,t,s.geometry.parameters))}dispatch(e,t,s){const r=this._rctx;this._previouslyBoundDraw.clear();let n=null;const a=this._draws.length,o=t.highlight?.name;for(let h=0;h<a;h++){const a=this._draws[h];if(2===e.identifier){const e=a.highlightName;if(e){if(e!==o)continue}else if(!o||!t.overlay?.hasHighlight(o))continue}const u=s[h];u===n&&0===t.oitPass||(r.bindTechnique(u,t,e),n=u);const{geometryRanges:d,indexType:c,geometry:l,material:g}=a;r.bindVAO(l.vao),this._previouslyBoundDraw.get(u)!==g&&(u.program.bindDraw(t,e,g),this._previouslyBoundDraw.set(u,g));const m=d.length,{primitiveType:p}=l;for(let e=0;e<m;e+=2){const t=d[e],s=d[e+1];if(0!==c){const e=i.get(c);r.drawElements(p,s,c,t*e)}else r.drawArrays(p,t,s)}}}prepareSubmit(){this._draws.length=0}finishSubmit(){const e=0===this._sorting?1:-1;this._draws.sort((t,s)=>e*(t.depthSquaredHint-s.depthSquaredHint)||t.geometry.vao.usedMemory-s.geometry.vao.usedMemory)}get count(){return this._draws.length}}class s{constructor(e,t,s,i,r,n){this.material=e,this.geometry=t,this.geometryRanges=s,this.depthSquaredHint=i,this.indexType=r,this.highlightName=n}}const i=new Map;i.set(e.UNSIGNED_BYTE,1),i.set(e.UNSIGNED_SHORT,2),i.set(e.UNSIGNED_INT,4);export{t as RenderPass};
