@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.39 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{disposeMaybe as e}from"../../../../core/maybe.js";import{hasSource as t}from"./RasterBitmap.js";import{getColorizer as r}from"./colorizer/rasterColorizer.js";import{process as s,createTextureDescriptor as i}from"./processor/rasterProcessor.js";import{tileSize as o}from"../webgl/definitions.js";import n from"../webgl/VertexStream.js";import a from"../webgl/brushes/WGLBrush.js";import{BlendFactor as d,CompareFunction as m}from"../../../webgl/enums.js";import{FramebufferObject as c}from"../../../webgl/FramebufferObject.js";import{getCommonUniforms as f,getUniformLocationInfos as u,getBasicGridUniforms as p}from"../../../webgl/rasterUtils.js";class h extends a{constructor(){super(...arguments),this.name="raster",this._quad=null,this._rendererUniformInfos=new Map,this._fbo=null}dispose(){e(this._quad),e(this._fbo)}prepareState(e){const{context:t,renderPass:r}=e,s="raster"===r;t.setBlendingEnabled(!s),t.setBlendFunctionSeparate(d.ONE,d.ONE_MINUS_SRC_ALPHA,d.ONE,d.ONE_MINUS_SRC_ALPHA),t.setColorMask(!0,!0,!0,!0),t.setStencilWriteMask(0),t.setStencilTestEnabled(!s)}draw(e,r){if(!t(r)||r.suspended)return;const{renderPass:s}=e;if("raster-bitmap"!==s)return"raster"===s?this._process(e,r):void this._drawBitmap(e,r,!0);this._drawBitmap(e,r)}_process(t,r){const{rasterFunction:i}=t,o="Reproject"===i.name;if(!(o?!(r.rasterTexture&&r.projected):!r.processed))return;const{timeline:n,context:a}=t;n.begin(this.name);const d=a.getBoundFramebufferObject(),c=a.getViewport();o||(r.processedTexture=e(r.processedTexture)),a.setStencilFunction(m.EQUAL,r.stencilRef,255),r.updateTexture(t),this._initQuad(a);const[f,u]=r.getRasterTextureSize(o),{isStandardRasterTileSize:p,fbo:h}=this._getRasterFBO(a,f,u);s(t,this._quad,h,r),p||h.dispose(),a.bindFramebuffer(d),a.setViewport(c.x,c.y,c.width,c.height),n.end(this.name)}_drawBitmap(e,t,s=!1){const{timeline:i,context:o}=e;if(i.begin(this.name),o.setStencilFunction(m.EQUAL,t.stencilRef,255),t.updateTexture(e),s&&!t.processedTexture){if(t.updateProcessedTexture(),!t.processedTexture)return void i.end(this.name);t.processed=!0}this._initBitmapCommonUniforms(t);const a=t.symbolizerParameters.type,d=r(a),{requestRender:c,allowDelayedRender:f}=e,{defines:u,program:p}=d.createProgram(e,t,t.projected&&s);if(f&&null!=c&&!p.compiled)return void c();o.useProgram(p);const h=this._getUniformInfos(a,o,p,u);this._quad||(this._quad=new n(o,[0,0,1,0,0,1,1,1])),d.bindTextureAndUniforms(e,p,t,h,s),this._quad.draw(),i.end(this.name)}_initBitmapCommonUniforms(e){if(!e.commonUniforms){const t=p(1,[0,0]),{transformGrid:r,width:s,height:i}=e,o=f(r,[s,i],[e.source.width,e.source.height],1,!1);e.commonUniforms={...t,...o,u_coordScale:e.coordScale}}}_getRasterFBO(e,t,r){const s=t===o&&r===o;return s?(this._fbo||(this._fbo=this._createNewFBO(e,t,r)),{isStandardRasterTileSize:s,fbo:this._fbo}):{isStandardRasterTileSize:s,fbo:this._createNewFBO(e,t,r)}}_createNewFBO(e,t,r){const s=i(t,r);return new c(e,s)}_initQuad(e){this._quad||(this._quad=new n(e,[0,0,1,0,0,1,1,1]))}_getUniformInfos(e,t,r,s){const i=s.length>0?e+"-"+s.join("-"):e;if(this._rendererUniformInfos.has(i))return this._rendererUniformInfos.get(i);const o=u(t,r);return this._rendererUniformInfos.set(i,o),o}}export{h as default};