UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 2.16 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import e from"../../../../../core/PooledArray.js";import{RenderPassIdentifier as t}from"./RenderPassIdentifier.js";import{OITPass as r}from"../../lib/OITPass.js";import{DataType as i}from"../../../../webgl/enums.js";var s;!function(e){e[e.FrontToBack=0]="FrontToBack",e[e.BackToFront=1]="BackToFront"}(s||(s={}));class n{constructor(t,r,i=s.FrontToBack){this._rctx=t,this._techniques=r,this._sorting=i,this._draws=new e({allocator:e=>e??{material:null,geometry:null,geometryRanges:null,bindDrawParams:null,depthSquaredHint:0,indexType:0}}),this._previouslyBoundDraw=new Map}submitDraw(e,t,r,i,s){const n=this._draws.pushNew();n.geometry=t,n.geometryRanges=r,n.material=e,n.depthSquaredHint=i,n.indexType=(t.indexed?t.vao.indexBuffer.indexType:null)??0,n.highlightName=s}acquire(e,t){return this._draws.map((r=>r.material.acquireTechnique(this._techniques,e,t,r.geometry.parameters)))}dispatch(e,i,s){const n=this._rctx;this._previouslyBoundDraw.clear();let a=null;const h=this._draws.length,l=i.highlight?.name;for(let c=0;c<h;c++){const h=this._draws.data[c];if(e.identifier===t.Highlight){const e=h.highlightName;if(e){if(e!==l)continue}else if(!l||!i.overlay?.hasHighlightOptions(l))continue}const d=s[c];d===a&&i.oitPass===r.NONE||(n.bindTechnique(d,i,e),a=d);const{geometryRanges:u,indexType:m,geometry:g,material:p}=h;n.bindVAO(g.vao),this._previouslyBoundDraw.get(d)!==p&&(d.program.bindDraw(i,e,p),this._previouslyBoundDraw.set(d,p));const y=u.length,{primitiveType:w}=g;for(let e=0;e<y;e+=2){const t=u[e],r=u[e+1];if(0!==m){const e=o.get(m);n.drawElements(w,r,m,t*e)}else n.drawArrays(w,t,r)}}}prepareSubmit(){this._draws.clear()}finishSubmit(){const e=this._sorting===s.FrontToBack?1:-1;this._draws.sort(((t,r)=>{const i=e*(t.depthSquaredHint-r.depthSquaredHint);return 0!==i?i:t.geometry.vao.byteSize-r.geometry.vao.byteSize}))}get count(){return this._draws.length}}const o=new Map;o.set(i.UNSIGNED_BYTE,1),o.set(i.UNSIGNED_SHORT,2),o.set(i.UNSIGNED_INT,4);export{n as RenderPass,s as RenderPassSorting};