@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 4.34 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{disposeMaybe as e}from"../../../../core/maybe.js";import{create as t}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{create as r}from"../../../../core/libs/gl-matrix-2/factories/vec4f32.js";import o from"../../../../geometry/Point.js";import{load as s,execute as i}from"../../../../geometry/operators/projectOperator.js";import{DisplayObject as a}from"../DisplayObject.js";import{VideoScreenTechnique as n}from"./shaderGraph/techniques/videoScreenRenderer/VideoScreenTechnique.js";import{TextureSamplingMode as c,TextureWrapMode as h,ColorAttachment0 as d,SizedPixelFormat as u}from"../../../webgl/enums.js";import{FramebufferObject as l}from"../../../webgl/FramebufferObject.js";import{Texture as m}from"../../../webgl/Texture.js";import{TextureDescriptor as _}from"../../../webgl/TextureDescriptor.js";class x extends a{constructor(e,t){super(),this._controlPointsOwner=t,this.readbackScreenCoords=r(),this.videoTextureCoords=new Array(36),this.overlayTextureCoords=new Array(36),this._prevFBO=null,this._acquiredFBO=null,this._isBound=!1,this._hasCoordinates=!1,this._geIsLoaded=!1,this._ndcRect=[0,0,2,2],this._technique=new n,this.visible=!1,this.stage=e;for(let r=0;r<6;r++){const e=r/5;for(let t=0;t<6;t++){const o=t/5;this.videoTextureCoords[6*r+t]={u:o,v:e}}}}getMesh(e){throw new Error("Method not implemented.")}destroy(){e(this._readbackTexture)}bind(e){const{context:t,pixelRatio:r,state:o}=e;if(this._update(e),!this.ready||0===this.readbackScreenCoords[2]||0===this.readbackScreenCoords[3])return this.requestRender(),!1;const{size:s}=o,i=Math.round(r*s[0]),a=Math.round(r*s[1]),n=new _(i,a);return n.samplingMode=c.LINEAR,n.wrapMode=h.CLAMP_TO_EDGE,this._acquiredFBO||(this._acquiredFBO=new l(t,n)),this._acquiredFBO.resize(i,a),t.bindFramebuffer(this._acquiredFBO),this._isBound=!0,!0}unbind(e){if(!this._isBound)return;const{context:t,pixelRatio:r,state:o}=e,{size:s}=o,i=this._acquiredFBO;if(!i.getColorTexture(d))throw new Error("Failed to get color texture from FBO.");const a=this._getReadbackTexture(e),n=this.readbackScreenCoords,c=Math.round(r*n[0]),h=Math.round(r*(s[1]-n[1]))-a.descriptor.height,u=c+a.descriptor.width,l=h+a.descriptor.height,m=Math.max(c,0),_=Math.max(h,0),x=Math.min(u,i.width)-m,b=Math.min(l,i.height)-_;x>0&&b>0&&i.copyToTexture(m,_,x,b,m-c,_-h,a),t.bindFramebuffer(this._prevFBO)}_update(e){const{state:r}=e,a=this._controlPointsOwner,n=a.groundControlPoints(),c=a.getSize(),h=r.size,d=n?.length;if(!d)return;if(s().then((()=>{this._geIsLoaded=!0})),!this._geIsLoaded)return void this.requestRender();const u=c[0],l=c[1],m=h[0],_=l/h[1],x=u/m;if(_>x){const e=x/_*2,t=(2-e)/2;this._ndcRect[0]=-1+t,this._ndcRect[1]=1,this._ndcRect[2]=e,this._ndcRect[3]=2}else{const e=_/x*2,t=(2-e)/2;this._ndcRect[0]=-1,this._ndcRect[1]=1-t,this._ndcRect[2]=2,this._ndcRect[3]=e}const b=new Array(d),f=r.spatialReference;for(let t=0;t<d;t++){const{lat:e,lon:r}=n[t],s=new o(r,e);b[t]=i(s,f)}const p=[];let M=1/0,g=1/0,C=-1/0,R=-1/0;for(const o of b){const e=t();r.toScreen(e,o.x,o.y),p.push({x:e[0],y:e[1]}),M=Math.min(M,e[0]),g=Math.min(g,e[1]),C=Math.max(C,e[0]),R=Math.max(R,e[1])}const T=[M,R],w=[C,g];this.readbackScreenCoords[0]=Math.max(Math.floor(T[0]),0),this.readbackScreenCoords[1]=Math.max(Math.floor(w[1]),0),this.readbackScreenCoords[2]=Math.ceil(w[0]),this.readbackScreenCoords[3]=Math.ceil(T[1]);for(let t=0;t<p.length;t++){const e=p[t],r=(e.x-M)/(C-M),o=(R-e.y)/(R-g);this.overlayTextureCoords[t]={u:r,v:o}}this._hasCoordinates=!0}_createTransforms(){return null}doRender(e){this._readbackTexture&&this._hasCoordinates?this._technique.render(e,{texture:this._readbackTexture,textureCoords:this.overlayTextureCoords,opacity:1,ndcRect:this._ndcRect}):this.requestRender()}_getReadbackTexture(e){const{context:t,pixelRatio:r}=e,o=Math.round(r*Math.abs(this.readbackScreenCoords[2]-this.readbackScreenCoords[0])),s=Math.round(r*Math.abs(this.readbackScreenCoords[3]-this.readbackScreenCoords[1]));if(this._readbackTexture)this._readbackTexture.resize(o,s);else{const e=new _(o,s);e.wrapMode=h.CLAMP_TO_EDGE,e.internalFormat=u.RGBA8,this._readbackTexture=new m(t,e)}return this._readbackTexture}}export{x as default};