/*
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","../../../../../core/PooledArray","../../lib/basicInterfaces","../../../../webgl/enums"],(function(e,t,r,n,a,i){"use strict";var s;e.RenderPassSorting=void 0,(s=e.RenderPassSorting||(e.RenderPassSorting={}))[s.FrontToBack=0]="FrontToBack",s[s.BackToFront=1]="BackToFront";let o=function(){function i(t,r,a=e.RenderPassSorting.FrontToBack){this._rctx=t,this._techniqueRepository=r,this._sorting=a,this._draws=new n({initialSize:32,allocator:e=>e||{material:null,geometry:null,geometryRanges:null,bindDrawParams:null,depthSquaredHint:0,indexType:0}}),this._previouslyBoundDraw=new Map}var s=i.prototype;return s.submitDraw=function(e,t,n,a){const i=this._draws.pushNew();i.geometry=t,i.geometryRanges=n,i.material=e,i.depthSquaredHint=a,i.indexType=t.indexed?r.unwrap(t.vao.indexBuffer).indexType:0},s.dispatch=function(e,t){const r=this._rctx;this._previouslyBoundDraw.clear();let n=null;const i=this._draws.map((r=>r.material.prepareTechnique(this._techniqueRepository,e,t,r.geometry.parameters))),s=this._draws.length;for(let o=0;o<s;o++){const s=i[o];s===n&&s.configuration.transparencyPassType===a.TransparencyPassType.NONE||(r.bindTechnique(s,e,t),n=s);const l=this._draws.data[o],u=l.geometry;r.bindVAO(u.vao),this._previouslyBoundDraw.get(s)!==l.material&&(s.bindDraw(l.material,t),this._previouslyBoundDraw.set(s,l.material));const c=l.geometryRanges,p=c.length;if(0!==l.indexType){const e=d.get(l.indexType);for(let t=0;t<p;t+=2){const n=c[t],a=c[t+1];r.drawElements(u.primitiveType,a,l.indexType,n*e)}}else for(let e=0;e<p;e+=2){const t=c[e],n=c[e+1];r.drawArrays(u.primitiveType,t,n)}}},s.prepareSubmit=function(){this._draws.clear()},s.finishSubmit=function(){const t=this._sorting===e.RenderPassSorting.FrontToBack?1:-1;this._draws.sort(((e,r)=>{const n=t*(e.depthSquaredHint-r.depthSquaredHint);return 0!==n?n:e.geometry.vao.size-r.geometry.vao.size}))},t._createClass(i,[{key:"count",get:function(){return this._draws.length}}]),i}();const d=new Map;d.set(i.DataType.UNSIGNED_BYTE,1),d.set(i.DataType.UNSIGNED_SHORT,2),d.set(i.DataType.UNSIGNED_INT,4),e.RenderPass=o,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
