You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
10 KiB
23 lines
10 KiB
// All material copyright Esri, All Rights Reserved, unless otherwise specified. |
|
// See https://js.arcgis.com/4.30/esri/copyright.txt for details. |
|
//>>built |
|
define("exports ../../core/has ../../core/Logger ../../core/maybe ./BufferObject ./checkWebGLError ./enums ./GLObjectType ./Renderbuffer ./Texture".split(" "),function(r,A,u,v,x,y,d,p,z,m){function q(a){return null!=a&&"type"in a&&a.type===p.GLObjectType.Texture}function n(a,b){const c=Math.max(a.width,a.height);return c>b?(u.getLogger("esri.views.webgl.FramebufferObject").warn(`Resizing FBO attachment size ${a.width}x${a.height} to device limit ${b}`),b/=c,a.width=Math.round(a.width*b),a.height= |
|
Math.round(a.height*b),!1):!0}function w(a){return a.descriptor.target===d.TextureType.TEXTURE_CUBE_MAP?d.TextureType.TEXTURE_CUBE_MAP_POSITIVE_X:d.TextureType.TEXTURE_2D}class l{constructor(a,b,c=null){this._context=a;this._glName=null;this._colorAttachments=new Map;this._depthStencilTexture=this._depthStencilBuffer=null;this._initialized=!1;a.instanceCounter.increment(d.ResourceType.FramebufferObject,this);a=q(b)?b:new m.Texture(this._context,b);this._colorAttachments.set(d.ColorAttachment.COLOR_ATTACHMENT0, |
|
a);this._validateTextureDescriptor(a.descriptor);this._validateColorAttachmentPoint(d.ColorAttachment.COLOR_ATTACHMENT0);null!=c&&(q(c)||null!=c&&"pixelFormat"in c?(this._depthStencilTexture=q(c)?c:new m.Texture(this._context,c),this._validateTextureDescriptor(this._depthStencilTexture.descriptor)):(this._depthStencilBuffer=c=null!=c&&"type"in c&&c.type===p.GLObjectType.RenderBuffer?c:new z.Renderbuffer(this._context,c),this._validateRenderBufferDescriptor(c.descriptor)))}dispose(){if(0!==this._colorAttachments.size|| |
|
this._glName){var a=this._context.getBoundFramebufferObject();this._colorAttachments.forEach((b,c)=>this.detachColorTexture(c)?.dispose());this.detachDepthStencilBuffer()?.dispose();this.detachDepthStencilTexture()?.dispose();this._glName&&(this._context.gl.deleteFramebuffer(this._glName),this._glName=null);this._context.bindFramebuffer(a);this._context.instanceCounter.decrement(d.ResourceType.FramebufferObject,this)}}get glName(){return this._glName}get colorTexture(){return this._colorAttachments.get(d.ColorAttachment.COLOR_ATTACHMENT0)}get depthStencil(){return this._depthStencilTexture|| |
|
this._depthStencilBuffer}get depthStencilTexture(){return this._depthStencilTexture}get width(){return this._colorAttachments.get(d.ColorAttachment.COLOR_ATTACHMENT0)?.descriptor?.width??0}get height(){return this._colorAttachments.get(d.ColorAttachment.COLOR_ATTACHMENT0)?.descriptor?.height??0}get usedMemory(){return[...this._colorAttachments].reduce((a,[,b])=>a+b.usedMemory,this.depthStencil?.usedMemory??0)}getColorTexture(a){return(a=this._colorAttachments.get(a))&&q(a)?a:null}get colorAttachments(){return[...this._colorAttachments.keys()]}attachColorTexture(a, |
|
b=d.ColorAttachment.COLOR_ATTACHMENT0){a&&(this._validateColorAttachmentPoint(b),this._validateTextureDescriptor(a.descriptor),this.detachColorTexture(b)?.dispose(),this._initialized&&(this._context.bindFramebuffer(this),this._framebufferTexture2D(a.glName,b)),this._colorAttachments.set(b,a))}detachColorTexture(a=d.ColorAttachment.COLOR_ATTACHMENT0){const b=this._colorAttachments.get(a);if(b){if(this._initialized){const c=this._context.getBoundFramebufferObject();this._context.bindFramebuffer(this); |
|
this._framebufferTexture2D(null,a);this._context.bindFramebuffer(c)}this._colorAttachments.delete(a);return b}}setColorTextureTarget(a,b=d.ColorAttachment.COLOR_ATTACHMENT0){const c=this._colorAttachments.get(b);c&&this._framebufferTexture2D(c.glName,b,a)}attachDepthStencil(a){if(a)switch(a.type){case p.GLObjectType.Texture:return this._attachDepthStencilTexture(a);case p.GLObjectType.RenderBuffer:return this._attachDepthStencilBuffer(a)}}_attachDepthStencilTexture(a){if(null!=a){var b=a.descriptor; |
|
b.pixelFormat!==d.PixelFormat.DEPTH_STENCIL&&b.pixelFormat!==d.PixelFormat.DEPTH24_STENCIL8&&console.error("Depth/Stencil texture must have a pixel type of DEPTH_STENCIL!");b.dataType!==d.PixelType.UNSIGNED_INT_24_8&&console.error("Depth/Stencil texture must have data type of UNSIGNED_INT_24_8!");this._validateTextureDescriptor(b);this._disposeDepthStencilAttachments();this._initialized&&(this._context.bindFramebuffer(this),this._framebufferTexture2D(a.glName,d.DepthStencilAttachment));this._depthStencilTexture?.dispose(); |
|
this._depthStencilTexture=a}}detachDepthStencilTexture(){const a=this._depthStencilTexture;if(a&&this._initialized){const b=this._context.getBoundFramebufferObject();this._context.bindFramebuffer(this);this._framebufferTexture2D(null,d.DepthStencilAttachment);this._context.bindFramebuffer(b)}this._depthStencilTexture=null;return a}_attachDepthStencilBuffer(a){if(null!=a){var b=a.descriptor;this._validateRenderBufferDescriptor(b);this._disposeDepthStencilAttachments();if(this._initialized){this._context.bindFramebuffer(this); |
|
const c=this._context.gl;b=this._getGLAttachmentPoint(b);c.framebufferRenderbuffer(d.FramebufferTarget.FRAMEBUFFER,b,c.RENDERBUFFER,a.glName)}this._depthStencilBuffer=a}}detachDepthStencilBuffer(){const a=this._depthStencilBuffer;if(a&&this._initialized){const b=this._context.getBoundFramebufferObject();this._context.bindFramebuffer(this);const c=this._context.gl,e=this._getGLAttachmentPoint(a.descriptor);c.framebufferRenderbuffer(d.FramebufferTarget.FRAMEBUFFER,e,c.RENDERBUFFER,null);this._context.bindFramebuffer(b)}this._depthStencilBuffer= |
|
null;return a}copyToTexture(a,b,c,e,g,k,h){(0>a||0>b||0>g||0>k)&&console.error("Offsets cannot be negative!");(0>=c||0>=e)&&console.error("Copy width and height must be greater than zero!");var f=h.descriptor;h.descriptor.target!==d.TextureType.TEXTURE_2D&&console.error("Texture target must be TEXTURE_2D!");(null==f?.width||null==f?.height||a+c>this.width||b+e>this.height||g+c>f.width||k+e>f.height)&&console.error("Bad dimensions, the current input values will attempt to read or copy out of bounds!"); |
|
f=this._context;h=f.bindTexture(h,m.Texture.TEXTURE_UNIT_FOR_UPDATES);f.setActiveTexture(m.Texture.TEXTURE_UNIT_FOR_UPDATES);f.bindFramebuffer(this);f.gl.copyTexSubImage2D(d.TextureType.TEXTURE_2D,0,g,k,a,b,c,e);f.bindTexture(h,m.Texture.TEXTURE_UNIT_FOR_UPDATES)}readPixels(a,b,c,e,g,k,h){(0>=c||0>=e)&&console.error("Copy width and height must be greater than zero!");h||console.error("Target memory is not initialized!");this._context.bindFramebuffer(this);this._context.gl.readPixels(a,b,c,e,g,k,h)}async readPixelsAsync(a, |
|
b,c,e,g,k,h){const {gl:f}=this._context,t=x.BufferObject.createPixelPack(this._context,d.Usage.STREAM_READ,h.byteLength);this._context.bindBuffer(t);this._context.bindFramebuffer(this);f.readPixels(a,b,c,e,g,k,0);this._context.unbindBuffer(d.BufferType.PIXEL_PACK_BUFFER);await t.getSubDataAsync(h);t.dispose()}resize(a,b){if(this.width!==a||this.height!==b){var c={width:a,height:b};n(c,this._context.parameters.maxTextureSize);this._colorAttachments.forEach(e=>e.resize(c.width,c.height));this._depthStencilTexture?.resize(c.width, |
|
c.height);this._initialized&&(n(c,this._context.parameters.maxRenderbufferSize),this._depthStencilBuffer?.resize(c.width,c.height),this._context.getBoundFramebufferObject()===this&&this._context.bindFramebuffer(null),this._initialized=!1)}}initializeAndBind(a=d.FramebufferTarget.FRAMEBUFFER){const b=this._context.gl;if(this._initialized)b.bindFramebuffer(a,this.glName);else{this._glName&&b.deleteFramebuffer(this._glName);var c=b.createFramebuffer();b.bindFramebuffer(a,c);this._colorAttachments.forEach((e, |
|
g)=>this._framebufferTexture2D(e.glName,g,w(e),a));if(this._depthStencilBuffer){const e=this._getGLAttachmentPoint(this._depthStencilBuffer.descriptor);b.framebufferRenderbuffer(a,e,b.RENDERBUFFER,this._depthStencilBuffer.glName)}else this._depthStencilTexture&&this._framebufferTexture2D(this._depthStencilTexture.glName,b.DEPTH_STENCIL_ATTACHMENT,w(this._depthStencilTexture),a);y.webglDebugEnabled()&&b.checkFramebufferStatus(a)!==b.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer is incomplete!"); |
|
this._glName=c;this._initialized=!0}}_framebufferTexture2D(a,b=d.ColorAttachment.COLOR_ATTACHMENT0,c=d.TextureType.TEXTURE_2D,e=d.FramebufferTarget.FRAMEBUFFER,g=0){this._context.gl.framebufferTexture2D(e,b,c,a,g)}_disposeDepthStencilAttachments(){const a=this._context.gl;if(this._depthStencilBuffer){if(this._initialized){this._context.bindFramebuffer(this);const b=this._getGLAttachmentPoint(this._depthStencilBuffer.descriptor);a.framebufferRenderbuffer(d.FramebufferTarget.FRAMEBUFFER,b,a.RENDERBUFFER, |
|
null)}this._depthStencilBuffer=v.disposeMaybe(this._depthStencilBuffer)}this._depthStencilTexture&&(this._initialized&&(this._context.bindFramebuffer(this),this._framebufferTexture2D(null,a.DEPTH_STENCIL_ATTACHMENT)),this._depthStencilTexture=v.disposeMaybe(this._depthStencilTexture))}_validateTextureDescriptor(a){a.target!==d.TextureType.TEXTURE_2D&&a.target!==d.TextureType.TEXTURE_CUBE_MAP&&console.error("Texture type must be TEXTURE_2D or TEXTURE_CUBE_MAP!");n(a,this._context.parameters.maxTextureSize); |
|
this._validateBufferDimensions(a)}_validateRenderBufferDescriptor(a){n(a,this._context.parameters.maxRenderbufferSize);this._validateBufferDimensions(a)}_validateBufferDimensions(a){0>=a.width&&(a.width=this.width);0>=a.height&&(a.height=this.height);0<this.width&&0<this.height&&(this.width!==a.width||this.height!==a.height)&&console.error("Attachment size must match framebuffer size!")}_getGLAttachmentPoint(a){switch(a.internalFormat){case d.RenderbufferFormat.DEPTH_COMPONENT16:case d.RenderbufferFormat.DEPTH_COMPONENT24:case d.RenderbufferFormat.DEPTH_COMPONENT32F:return this._context.gl.DEPTH_ATTACHMENT; |
|
case d.RenderbufferFormat.DEPTH24_STENCIL8:case d.RenderbufferFormat.DEPTH32F_STENCIL8:case d.RenderbufferFormat.DEPTH_STENCIL:return this._context.gl.DEPTH_STENCIL_ATTACHMENT;case d.RenderbufferFormat.STENCIL_INDEX8:return this._context.gl.STENCIL_ATTACHMENT}}_validateColorAttachmentPoint(a){if(-1===l._MAX_COLOR_ATTACHMENTS){const {gl:b}=this._context;l._MAX_COLOR_ATTACHMENTS=b.getParameter(b.MAX_COLOR_ATTACHMENTS)}a-=d.ColorAttachment.COLOR_ATTACHMENT0;a+1>l._MAX_COLOR_ATTACHMENTS&&u.getLogger("esri.views.webgl.FrameBufferObject").error("esri.FrameBufferObject", |
|
`illegal attachment point for color attachment: ${a+1}. Implementation supports up to ${l._MAX_COLOR_ATTACHMENTS} color attachments`)}}l._MAX_COLOR_ATTACHMENTS=-1;r.FramebufferObject=l;r.ensureAttachmentMaxSize=n;Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}); |