UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 3.32 kB
import{disposeMaybe as e,isSome as t}from"../../../../core/maybe.js";import{hasSource as r}from"./RasterBitmap.js";import{getColorizer as s}from"./colorizer/rasterColorizer.js";import{process as i,createTexture as o}from"./processor/rasterProcessor.js";import{TILE_SIZE as n}from"../webgl/definitions.js";import a from"../webgl/VertexStream.js";import d from"../webgl/brushes/WGLBrush.js";import{BlendFactor as m,CompareFunction as c,TargetType as f,DepthStencilTargetType as u}from"../../../webgl/enums.js";import{FramebufferObject as h}from"../../../webgl/FramebufferObject.js";import{getCommonUniforms as p,getUniformLocationInfos as l,getBasicGridUniforms as _}from"../../../webgl/rasterUtils.js";class b extends d{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(m.ONE,m.ONE_MINUS_SRC_ALPHA,m.ONE,m.ONE_MINUS_SRC_ALPHA),t.setColorMask(!0,!0,!0,!0),t.setStencilWriteMask(0),t.setStencilTestEnabled(!s)}draw(e,t){if(!r(t)||t.suspended)return;const{renderPass:s}=e;if("raster-bitmap"!==s)return"raster"===s?this._process(e,t):void this._drawBitmap(e,t,!0);this._drawBitmap(e,t)}_process(t,r){const{rasterFunction:s}=t,o="Reproject"===s.name;if(!(o?!(r.rasterTexture&&r.projected):!r.processed))return;const{timeline:n,context:a}=t;n.begin(this.name);const d=a.getBoundFramebufferObject(),m=a.getViewport();o||(r.processedTexture=e(r.processedTexture)),a.setStencilFunction(c.EQUAL,r.stencilRef,255),r.updateTexture(t),this._initQuad(a);const{isStandardRasterTileSize:f,fbo:u}=this._getRasterFBO(a,r.width,r.height);i(t,this._quad,u,r),f||u.dispose(),a.bindFramebuffer(d),a.setViewport(m.x,m.y,m.width,m.height),n.end(this.name)}_drawBitmap(e,r,i=!1){const{timeline:o,context:n}=e;if(o.begin(this.name),n.setStencilFunction(c.EQUAL,r.stencilRef,255),r.updateTexture(e),i&&!r.processedTexture){if(r.updateProcessedTexture(),!r.processedTexture)return void o.end(this.name);r.processed=!0}this._initBitmapCommonUniforms(r);const d=r.symbolizerParameters.type,m=s(d),{requestRender:f,allowDelayedRender:u}=e,{defines:h,program:p}=m.createProgram(e,r,i);if(u&&t(f)&&!p.compiled)return void f();n.useProgram(p);const l=this._getUniformInfos(d,n,p,h);this._quad||(this._quad=new a(n,[0,0,1,0,0,1,1,1])),m.bindTextureAndUniforms(e,p,r,l,i),this._quad.draw(),o.end(this.name)}_initBitmapCommonUniforms(e){if(!e.commonUniforms){const t=_(1,[0,0]),{transformGrid:r,width:s,height:i}=e,o=p(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===n||r===n;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=o(e,t,r);return new h(e,{colorTarget:f.TEXTURE,depthStencilTarget:u.NONE,width:t,height:r},s)}_initQuad(e){this._quad||(this._quad=new a(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=l(t,r);return this._rendererUniformInfos.set(i,o),o}}export{b as default};