text: // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  // See https://js.arcgis.com/4.10/esri/copyright.txt for details.
  //>>built
  define("require exports ../../../../core/tsSupport/assignHelper ../../../../core/has ../../../../core/Logger ../../../../core/promiseUtils ../../../../core/libs/gl-matrix-2/gl-matrix ../lib/DrapedRenderer ../lib/GLMaterialRep ../lib/GLTextureRep ../lib/ProgramRepository ../lib/tracer ../lighting/Lightsources ./Model ./Viewport ../../../support/screenshotUtils ../../../webgl/context-util ../../../webgl/FramebufferObject ../../../webgl/RenderingContext".split(" "),function(q,H,r,t,u,v,m,w,x,y,z,n,A,
  B,C,l,D,E,F){var G=u.getLogger("esri.views.3d.webgl-engine.parts.View");q=function(){function b(a,e,b,c){var d=this;this.options=c;this._backgroundColor=m.vec4f64.fromValues(1,1,1,1);this._lightDirection=m.vec3f64.fromValues(0,1,0);this._didRender=!1;this._idleSuspend=this._needsRender=!0;this._shouldRender=!1;this._supersampleScreenshots=!0;this._screenshotQueue=[];this._container=a;this._stage=e;this._initializeContext(c);this._programRepository=new z(this._rctx);this._programRepository.globalOptions.viewingMode=
  c.viewingMode;this._textureRep=new y(e.getAll(B.ContentType.TEXTURE),this._programRepository,function(){return d._viewport.getCamera().viewport},this._rctx);this._materialRep=new x(this._textureRep,this._programRepository);this._viewport=new C(this._stage,this._programRepository,this._materialRep,this._textureRep,this._rctx);this._initializeViewportCamera();this._drapedRenderer=new w(this._rctx,this._canvas,this._programRepository,this._materialRep,this._textureRep,b);this._initializeFrameTask()}
  Object.defineProperty(b.prototype,"isLoadingResources",{get:function(){return this._viewport.isLoadingResources},enumerable:!0,configurable:!0});b.prototype._initializeFrameTask=function(){var a=this;this._frameTask={preRender:function(){n.begin();a._stage.processDirty();a.needsRender()?(a._shouldRender=!0,a._viewport.getCamera().setGLViewport(a._rctx),a._rctx.setClearColor.apply(a._rctx,a._backgroundColor),a._rctx.clear(16640)):a._shouldRender=!1},render:function(){a._shouldRender&&(a._didRender=
  !0,p.lightDirection=a._lightDirection,p.disableSlice=!1,a._viewport.render(p))},postRender:function(){n.end()},update:function(){a.resetNeedsRender();a._performScreenshots()}}};b.prototype._initializeViewportCamera=function(){var a=this._container.getBoundingClientRect(),e=this._viewport.getCamera();e.viewport[2]=a.width;e.viewport[3]=a.height;this._viewport.setCamera(e)};b.prototype._initializeContext=function(a){this._canvas=a.canvas;this._canvas||(this._canvas=document.createElement("canvas"));
  this._canvas.setAttribute("style","width: 100%; height:100%; display:block;");var e=D.createContextOrErrorHTML(this._canvas,{alpha:a.alpha||!1,premultipliedAlpha:!0,antialias:!1,depth:!0,stencil:null==a.stencil?!0:a.stencil},a.renderContext);this._gl=n.instrumentContext(e);this._rctx=new F(this._gl,{disabledExtensions:a.deactivatedWebGLExtensions||{}});!a.alpha&&this._rctx.contextAttributes.alpha&&G.error("WebGL context has alpha channel even though no alpha channel was requested");!this._rctx.contextAttributes.alpha&&
  11<=t("safari")&&(this._container.style.backgroundColor="black");this._container.appendChild(this._canvas);null!=a.supersampleScreenshots&&(this._supersampleScreenshots=a.supersampleScreenshots)};b.prototype.dispose=function(){this._viewport.dispose();this._viewport=null;this._drapedRenderer.dispose();this._drapedRenderer=null;this._programRepository.dispose();this._programRepository=null;this._container.contains(this._canvas)&&this._container.removeChild(this._canvas);this._frameTask=this._gl=this._canvas=
  this._container=null};b.prototype.getCombinedStats=function(){return this._viewport.getCombinedStats()};b.prototype.setNeedsRender=function(){this._didRender=!1;this._needsRender=!0};b.prototype.resetNeedsRender=function(){this._didRender&&(this._didRender=this._needsRender=!1);this._viewport.resetNeedsRender();this._textureRep.resetNeedsRender()};b.prototype.needsRender=function(){return this._needsRender||!this._idleSuspend||this._viewport.needsRender()||this._textureRep.needsRender()};b.prototype.getFrameTask=
  function(){return this._frameTask};b.prototype.setLighting=function(a){m.vec3.set(this._lightDirection,0,0,0);for(var e=0,b=a.lights;e<b.length;e++){var c=b[e];if(c instanceof A.MainLight){m.vec3.negate(this._lightDirection,c.direction);break}}this._viewport.setLighting(a);this._needsRender=!0};b.prototype.getEdgeView=function(){return this._viewport.getEdgeView()};b.prototype.getMainLightDirection=function(){return this._lightDirection};b.prototype.getViewParams=function(a){var e={};if(!a||a.backgroundColor)e.backgroundColor=
  this._backgroundColor;return e};b.prototype.setViewParams=function(a){this._needsRender=!0;a.backgroundColor&&(this._backgroundColor=a.backgroundColor)};b.prototype.setRenderParams=function(a){this._needsRender=!0;void 0!==a.idleSuspend&&(this._idleSuspend=!!a.idleSuspend);this._viewport.setRenderParams(a)};b.prototype.getRenderParams=function(){var a=this._viewport.getRenderParams();a.anisotropicFiltering=this._textureRep.getMaxAnisotropy();a.idleSuspend=this._idleSuspend;return a};b.prototype.getIdleSuspend=
  function(){return this._idleSuspend};Object.defineProperty(b.prototype,"renderingContext",{get:function(){return this._rctx},enumerable:!0,configurable:!0});b.prototype.has=function(a){return"s3tc"===a?!!this._rctx.capabilities.compressedTextureS3TC:"shaderTextureLOD"===a?!!this._rctx.capabilities.shaderTextureLOD:!1};b.prototype.modify=function(a,e,b,c){this._viewport.modify(a,e,b,c)};b.prototype.setCamera=function(a){this._viewport.setCamera(a)};b.prototype.getCamera=function(){return this._viewport.getCamera()};
  b.prototype.getCanvas=function(){return this._canvas};b.prototype.getDrapedTextureRenderer=function(){return this._drapedRenderer};b.prototype.takeScreenshot=function(a){var b=this,d=v.createResolver(function(){b._screenshotQueue=b._screenshotQueue.filter(function(a){return a.resolver!==d})});this._screenshotQueue.push({settings:a,resolver:d});this._needsRender=!0;return d.promise};b.prototype.getFramebufferTexture=function(a){return this._viewport.getFramebufferTexture(a)};Object.defineProperty(b.prototype,
  "renderPlugins",{get:function(){return this._viewport.renderPlugins},enumerable:!0,configurable:!0});b.prototype._renderScreenshotOverlay=function(a,b,d){if(this.options.renderScreenshotOverlay){a.width=b.width;a.height=b.height;var c=a.getContext("2d");c.save();c.translate(0,b.height);c.scale(1,-1);d.region&&c.translate(-d.region.x,-d.region.y);c.scale(d.pixelRatio,d.pixelRatio);this.options.renderScreenshotOverlay(a,b);c.restore()}};b.prototype._readbackScreenshot=function(a){var b=a.framebufferWidth,
  d=a.framebufferHeight,c=a.region,g=a.resample,k=this._ensureScreenshotEncodeCanvas();if(g){var f=l.createEmptyImageData(b,d,k);this._gl.readPixels(0,0,b,d,6408,5121,new Uint8Array(f.data.buffer));this._renderScreenshotOverlay(k,f,r({},a,{region:null}));a=l.createEmptyImageData(c.width,c.height,k);return l.resampleHermite(f,a,!0,g.region.x,d-(g.region.y+g.region.height),g.region.width,g.region.height)}f=l.createEmptyImageData(c.width,c.height,k);this._gl.readPixels(c.x,d-(c.y+c.height),c.width,c.height,
  6408,5121,new Uint8Array(f.data.buffer));this._renderScreenshotOverlay(k,f,a);return f};b.prototype._renderScreenshot=function(a){var b=null,d=this._viewport.getCamera(),c=l.screenshotSuperSampleSettings(a,this._supersampleScreenshots),g=c.framebufferWidth,k=c.framebufferHeight,f=!1;if(g!==d.fullWidth||k!==d.fullHeight||a.disableSlice){var h=d.copy();h.fullWidth=g;h.fullHeight=k;b=d.fovX-h.fovX;f=d.fovY-h.fovY;0>b&&b<f?h.fovX=d.fovX:0>f&&f<b&&(h.fovY=d.fovY);this._drapedRenderer.forceUpdate&&this._drapedRenderer.forceUpdate(h);
  f=!0;b=new E(this._rctx,{width:h.fullWidth,height:h.fullHeight,colorTarget:0,depthStencilTarget:3});this._rctx.bindFramebuffer(b);h.setGLViewport(this._rctx);this._rctx.setClearColor.apply(this._rctx,this._backgroundColor);this._rctx.clear(16640);this._viewport.render({lightDirection:this._lightDirection,fbo:b,camera:h,pixelRatio:c.pixelRatio,disableSlice:a.disableSlice})}a=this._readbackScreenshot(c);b&&b.dispose();this._rctx.bindFramebuffer(null);f&&this._drapedRenderer.forceUpdate&&this._drapedRenderer.forceUpdate(d);
  return a};b.prototype._performScreenshots=function(){if(0!==this._screenshotQueue.length){for(var a=0,b=this._screenshotQueue;a<b.length;a++){var d=b[a],c=d.settings;if(this._gl){var g=this._ensureScreenshotEncodeCanvas(),k=this._renderScreenshot(c),c=l.encodeResult(k,c,g,{flipY:!0,premultipliedAlpha:!0});d.resolver(c)}else d.resolver.reject()}this._screenshotQueue=[]}};b.prototype._ensureScreenshotEncodeCanvas=function(){this._screenshotEncodeCanvas||(this._screenshotEncodeCanvas=document.createElement("canvas"));
  return this._screenshotEncodeCanvas};return b}();var p={lightDirection:m.vec3f64.create(),camera:null,fbo:null,pixelRatio:1,disableSlice:!1};return q});