UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 2.14 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/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 o{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 o=this._draws.pushNew();o.geometry=t,o.geometryRanges=r,o.material=e,o.depthSquaredHint=i,o.indexType=(t.indexed?t.vao.indexBuffer.indexType:null)??0,o.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 o=this._rctx;this._previouslyBoundDraw.clear();let a=null;const h=this._draws.length,l=i.highlight?.name;for(let d=0;d<h;d++){const h=this._draws.data[d];if(e.identifier===t.Highlight){const e=h.highlightName;if(e){if(e!==l)continue}else if(!l||!i.overlay?.hasHighlight(l))continue}const u=s[d];u===a&&i.oitPass===r.NONE||(o.bindTechnique(u,i,e),a=u);const{geometryRanges:c,indexType:m,geometry:g,material:p}=h;o.bindVAO(g.vao),this._previouslyBoundDraw.get(u)!==p&&(u.program.bindDraw(i,e,p),this._previouslyBoundDraw.set(u,p));const y=c.length,{primitiveType:w}=g;for(let e=0;e<y;e+=2){const t=c[e],r=c[e+1];if(0!==m){const e=n.get(m);o.drawElements(w,r,m,t*e)}else o.drawArrays(w,t,r)}}}prepareSubmit(){this._draws.clear()}finishSubmit(){const e=this._sorting===s.FrontToBack?1:-1;this._draws.sort(((t,r)=>e*(t.depthSquaredHint-r.depthSquaredHint)||t.geometry.vao.usedMemory-r.geometry.vao.usedMemory))}get count(){return this._draws.length}}const n=new Map;n.set(i.UNSIGNED_BYTE,1),n.set(i.UNSIGNED_SHORT,2),n.set(i.UNSIGNED_INT,4);export{o as RenderPass,s as RenderPassSorting};