UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 4.16 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */ import{__decorate as t}from"tslib";import e from"../../../../../core/Accessor.js";import"../../../../../core/has.js";import{disposeMaybe as s}from"../../../../../core/maybe.js";import{property as i,subclass as a}from"../../../../../core/accessorSupport/decorators.js";import{GLMaterials as r}from"../../lib/GLMaterials.js";import{DrawParameters as n}from"../DrawParameters.js";import{defaultHighlightName as o}from"../../../../support/HighlightDefaults.js";let h=class extends e{constructor(t){super(t),this._glMaterials=null,this._drawParameters=new n,this._highlightNames=new Set,this._produces=new Map}initialize(){this._updateProduces()}destroy(){this.uninitializeRenderContext()}get _hasHighlights(){return this._highlightNames.size>0}hasHighlight(t){return this._highlightNames.has(t)}get produces(){return this._produces}_updateProduces(){this.material.produces.forEach((t,e)=>{this._produces.set(e,e=>!(0===this.dataByBaseInstance.size||!(8!==e&&4!==e||this._hasHighlights))&&t(e))})}initializeRenderContext(t){this._glMaterials=new r(this.material,t.materials)}uninitializeRenderContext(){this._glMaterials=s(this._glMaterials)}acquireTechniques(t){if(!this.material.shouldRender(t))return null;const{output:e,bind:s}=t,i=this.material.produces.get(s.slot);if(!i?.(e))return null;const{highlight:a,slot:r}=s,n=4===e,h=8===e,l=h||n,d=a?.name;if(l&&(0===this._highlightNames.size||h&&d&&!this._highlightNames.has(d)))return null;const u=t=>h&&!!d&&!t.has(d),c=5===e,g=!(l||c);for(const m of this.dataByBaseInstance.values())for(const i of m.dataByOrigin.values())for(const a of i.buffers){if(u(a.highlightNames))continue;const i=n?a.drawCommandsHighlights.get(o):l?d?a.drawCommandsHighlights.get(d):a.drawCommandsHighlights.size>0:((c&&a.needsMultipleCommands?a.drawCommandsShadowHighlightRest:a.drawCommandsDefault)||null)?.length??!1,h=g&&a.drawCommandsOccludees||null;if(i||h?.length){const i=this._glMaterials.load(t.rctx,r,e),a=i?.beginSlot(s);if(a)return a}}return null}render(t,e){const{output:s,bind:i}=t,{highlight:a}=i,r=8===s,n=a?.name??"";if(r&&!a)return;const h=4===s,g=r||h,m=5===s,w=!(g||m),{rctx:_}=t;_.runAppleAmdDriverHelper();const C=_.bindTechnique(e,i,this.material.parameters);for(const b of this.dataByBaseInstance.values()){const{baseInstanceData:t}=b,s=null!=t,a=s?c:u,y=s?d:l;for(const l of b.dataByOrigin.values()){this._drawParameters.origin=l.origin;for(const s of l.buffers){if(r&&(!s.hasHighlights||!s.drawCommandsHighlights.has(n)))continue;if(h&&(!s.hasHighlights||!s.drawCommandsHighlights.has(o)))continue;this._drawParameters.textureBuffer=s.textureBuffer?.texture;const l=y(s),d=f(l,s.needsMultipleCommands,n,h,g,m),u=p(l,w);(d?.length||u?.length)&&(C.bindDraw(i,this.material.parameters,this._drawParameters),a(_,s,t,e,d,u,i)),this._drawParameters.textureBuffer=null}}}}updateHighlights(){const{_highlightNames:t}=this;t.clear();for(const e of this.dataByBaseInstance.values())for(const s of e.dataByOrigin.values())for(const e of s.buffers)for(const s of e.highlightNames)t.add(s);this._updateProduces()}get test(){}};t([i({constructOnly:!0})],h.prototype,"material",void 0),t([i({constructOnly:!0})],h.prototype,"dataByBaseInstance",void 0),h=t([a("esri.views.3d.webgl-engine.materials.renderers.VaoRenderer")],h);const l=t=>t,d=t=>t.instancedCommandVAOs,u=(t,{vao:e},s,i,a,r,n)=>{i.ensureAttributeLocations(e),t.bindVAO(e),g(t,i,a,n,!1),g(t,i,r,n,!0)},c=(t,e,{baseCommand:s},i,a,r,n)=>{m(t,i,s,a,n,!1),m(t,i,s,r,n,!0)};function g(t,e,s,i,a){if(s?.length){t.setPipelineState(e.getPipeline(i,a));for(const i of s)t.drawArrays(e.primitiveType,i.first,i.count)}}function m(t,e,{first:s,count:i},a,r,n){if(a?.length){t.setPipelineState(e.getPipeline(r,n));for(const{vao:r,instanceCount:n}of a)e.ensureAttributeLocations(r),t.bindVAO(r),t.drawArraysInstanced(e.primitiveType,s,i,n)}}function f(t,e,s,i,a,r){const n=a&&!i?t.drawCommandsHighlights.get(s)??null:null;return i?t.drawCommandsHighlights.get(o):a?n:r&&e?t.drawCommandsShadowHighlightRest:t.drawCommandsDefault}function p(t,e){return e&&t.drawCommandsOccludees||null}export{h as VaoRenderer};