@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.35 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{getContinuousIndexArray as e}from"../../../../../../geometry/support/Indices.js";import{createHudMaterial as r}from"./FeaturePipelineRenderManager.js";import{RenderGeometryBufferWriter as t}from"./RenderGeometryBufferWriter.js";import{BoundingInfo as n}from"../../../../webgl-engine/lib/BoundingInfo.js";import{VertexAttribute as a}from"../../../../webgl-engine/lib/VertexAttribute.js";import{DefaultMaterial as s}from"../../../../webgl-engine/materials/DefaultMaterial.js";class o{constructor(e){this._context=e,this._commands=[],this._transferables=new Set}createMaterial(e){const n=this._context,a=n.generateId("material");switch(e){case"default":{const e=new s({},{spherical:this._context.globalViewingMode,doublePrecisionRequiresObfuscation:!0}),r=new t(e);n.registerRenderGeometryBufferWriter(a,r)}break;case"hud":{const e=r(null,this._context.globalViewingMode)[0],s=new t(e);n.registerRenderGeometryBufferWriter(a,s)}}return this._commands.push({id:"create-material",type:e,materialId:a}),a}createDirectRenderer(e){const r=this._context.generateId("material-renderer");return this._commands.push({id:"create-direct-renderer",materialRendererId:r,materialId:e}),r}addDirectRendererGeometry(e,r,t){const n=r.materialId,a=this._context.getRenderGeometryBufferWriter(n);if(null==a)throw new Error(`no bufferwriter found for material ${n}`);const s=a.createBuffer(r,t);this._transferables.add(s.data),this._commands.push({id:"add-direct-renderer-geometry",renderGeometryId:e,materialId:n,renderGeometryBuffer:s,localOrigin:t})}removeDirectRendererGeometry(e){this._commands.push({id:"remove-direct-renderer-geometry",renderGeometryId:e})}createLodRenderer(r){const t=this._context.generateId("lod-renderer"),s={levels:r.levels.map((r=>({components:r.components.map((r=>{const t=r.attributes.get(a.POSITION);if(!t||0===t.indices.length)throw new Error("positions attribute expected");const s=3,o=e(t.indices.length/s),d=new n(o,s,t),i=this._context.getRenderGeometryBufferWriter(r.materialId);if(null==i)throw new Error("writer not found");const c=i.createBuffer(r,null);this._transferables.add(c.data);return{materialId:r.materialId,renderGeometryBuffer:c,boundingInfo:{bbMax:d.bbMax,bbMin:d.bbMin}}})),minScreenSpaceRadius:r.minScreenSpaceRadius})))};return this._commands.push({id:"create-lod-renderer",lodRendererId:t,lodRenderGeometry:s}),t}addLodInstances(e,r){this._commands.push({id:"add-lod-instances",lodRendererId:e,data:r}),this._transferables.add(r.featureIds.buffer),this._transferables.add(r.globalTransforms.buffer),this._transferables.add(r.localTransforms.buffer)}removeLodInstances(e,r){this._commands.push({id:"remove-lod-instances",lodRendererId:e,featureIds:r}),this._transferables.add(r.buffer)}append(e){if(e._context!==this._context)throw new Error("Cannot append encoders from different contexts");const{_commands:r,_transferables:t}=this;for(const n of e._commands)r.push(n);for(const n of e._transferables)t.add(n)}async dispatch(){const e=this._commands,r=Array.from(this._transferables);this._clearCommandBuffer(),await this._context.dispatchRenderCommands(e,r)}_clearCommandBuffer(){this._commands=[],this._transferables.clear()}}export{o as RenderCommandEncoder};