// 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/maybe ../../core/promiseUtils ../../core/time ./checkWebGLError ./ContextState ./enums ./InstanceCounter ./Parameters ./ProgramCache ./renderState ./Texture ./Util ./WebGLDriverTest ./capabilities/Capabilities".split(" "),function(p,q,u,v,k,r,d,w,x,y,z,A,B,C,D){function h(a,b,c,e){b?e!==b&&a.bindBuffer(c,b.glName):a.bindBuffer(c,null);return b}function t(a,b){switch(a){case d.PrimitiveType.POINTS:return 2*b;case d.PrimitiveType.TRIANGLES:return b/3;case d.PrimitiveType.TRIANGLE_STRIP:return b- 2;case d.PrimitiveType.TRIANGLE_FAN:return b-2;default:return 0}}p.RenderingContext=class{constructor(a,b){this.gl=a;this.instanceCounter=new w.InstanceCounter;this.programCache=new y.ProgramCache(this);this._transformFeedbackRequestInfo=null;this._state=new r.ContextState;this._numOfTriangles=this._numOfDrawCalls=0;this._loadExtensions();this.configure(b)}configure(a){this._capabilities=new D.Capabilities(this.gl,a);this._parameters=new x.Parameters(this.gl,this._capabilities,a);A.Texture.TEXTURE_UNIT_FOR_UPDATES= this._parameters.maxTextureImageUnits-1;a=this.gl.getParameter(this.gl.VIEWPORT);this._state=new r.ContextState;this._state.viewport={x:a[0],y:a[1],width:a[2],height:a[3]};this._stateTracker=new z.StateTracker({setBlending:b=>{b?(this.setBlendingEnabled(!0),this.setBlendEquationSeparate(b.opRgb,b.opAlpha),this.setBlendFunctionSeparate(b.srcRgb,b.dstRgb,b.srcAlpha,b.dstAlpha),b=b.color,this.setBlendColor(b.r,b.g,b.b,b.a)):this.setBlendingEnabled(!1)},setCulling:b=>{b?(this.setFaceCullingEnabled(!0), this.setCullFace(b.face),this.setFrontFace(b.mode)):this.setFaceCullingEnabled(!1)},setPolygonOffset:b=>{b?(this.setPolygonOffsetFillEnabled(!0),this.setPolygonOffset(b.factor,b.units)):this.setPolygonOffsetFillEnabled(!1)},setDepthTest:b=>{b?(this.setDepthTestEnabled(!0),this.setDepthFunction(b.func)):this.setDepthTestEnabled(!1)},setStencilTest:b=>{if(b){this.setStencilTestEnabled(!0);const c=b.function;this.setStencilFunction(c.func,c.ref,c.mask);b=b.operation;this.setStencilOp(b.fail,b.zFail, b.zPass)}else this.setStencilTestEnabled(!1)},setDepthWrite:b=>{b?(this.setDepthWriteEnabled(!0),this.setDepthRange(b.zNear,b.zFar)):this.setDepthWriteEnabled(!1)},setColorWrite:b=>{b?this.setColorMask(b.r,b.g,b.b,b.a):this.setColorMask(!1,!1,!1,!1)},setStencilWrite:b=>{b?this.setStencilWriteMask(b.mask):this.setStencilWriteMask(0)},setDrawBuffers:b=>{b?this.setDrawBuffers(b.buffers):({drawFramebuffer:b}=this._state,null===b?this.setDrawBuffers([d.SpecialDrawBuffers.BACK]):0===b.colorAttachments.length? this.setDrawBuffers([d.SpecialDrawBuffers.NONE]):this.setDrawBuffers([d.ColorAttachment.COLOR_ATTACHMENT0]))}});this.enforceState();q.disposeMaybe(this._driverTest);this._driverTest=new C.WebGLDriverTest(this)}dispose(){q.disposeMaybe(this._driverTest);this.programCache.dispose();this.bindVAO(null);this.unbindBuffer(d.BufferType.ARRAY_BUFFER);this.unbindBuffer(d.BufferType.ELEMENT_ARRAY_BUFFER);this.unbindBuffer(d.BufferType.UNIFORM_BUFFER);this._state.uniformBufferBindingPoints.length=0;this.unbindBuffer(d.BufferType.PIXEL_PACK_BUFFER); this.unbindBuffer(d.BufferType.PIXEL_UNPACK_BUFFER);this.unbindBuffer(d.BufferType.COPY_READ_BUFFER);this.unbindBuffer(d.BufferType.COPY_WRITE_BUFFER);this._state.textureUnitMap.length=0;k.webglDebugEnabled()&&console.log(this.instanceCounter.resourceInformation)}get driverTest(){return this._driverTest}get contextAttributes(){return this.gl.getContextAttributes()}get parameters(){return this._parameters}setPipelineState(a){this._stateTracker.setPipeline(a)}setBlendingEnabled(a){this._state.blend!== a&&(!0===a?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this._state.blend=a,this._stateTracker.invalidateBlending())}externalProgramUpdate(){this._state.program?.stop();this._state.program=null}externalTextureUnitUpdate(a,b){for(let c=0;cf===a[g]))if(a.length>this.parameters.maxDrawBuffers)console.error("Setting more active draw buffers than GL.MAX_DRAW_BUFFERS allows.");else{if(c){if(1=this.parameters.maxTextureImageUnits|| 0>b)&&console.error("Input texture unit is out of range of available units!");const e=this._state.textureUnitMap[b];if(null==a?.glName)return null!=e&&(this.setActiveTexture(b,c),this.gl.bindTexture(e.descriptor.target,null)),this._state.textureUnitMap[b]=null,e;if(!c&&e===a)return a.isDirty&&(this.setActiveTexture(b,c),a.applyChanges()),e;this.setActiveTexture(b,c);this.gl.bindTexture(a.descriptor.target,a.glName);a.applyChanges();this._state.textureUnitMap[b]=a;return e}unbindTexture(a){if(null!= a)for(let b=0;b=this.parameters.maxUniformBufferBindings||0>b)return console.error("Uniform buffer binding point is out of range!"),null;a=a===d.BufferType.UNIFORM_BUFFER?this._state.uniformBufferBindingPoints:this._state.transformBufferBindingPoints; let c=a[b];null==c&&(c={buffer:null,offset:0,size:0},a[b]=c);return c}bindBufferBase(a,b,c){const e=this._getBufferBinding(a,b);null==e||e.buffer===c&&0===e.offset&&0===e.size||(this.gl.bindBufferBase(a,b,c?c.glName:null),e.buffer=c,e.offset=0,e.size=0)}bindBufferRange(a,b,c,e,f){const g=this._getBufferBinding(a,b);null==g||g.buffer===c&&g.offset===e&&g.size===f||(0!==e%this._parameters.uniformBufferOffsetAlignment?console.error("Uniform buffer binding offset is not a multiple of the context offset alignment"): (this.gl.bindBufferRange(a,b,c.glName,e,f),g.buffer=c,g.offset=e,g.size=f))}bindUBO(a,b,c,e){null==b?this.bindBufferBase(d.BufferType.UNIFORM_BUFFER,a,null):(k.webglDebugEnabled()&&(e??b.byteLength)>this._parameters.maxUniformBlockSize&&console.error("Attempting to bind more data than the maximum uniform block size"),b.initialize(),void 0!==c&&void 0!==e?this.bindBufferRange(d.BufferType.UNIFORM_BUFFER,a,b.buffer,c,e):this.bindBufferBase(d.BufferType.UNIFORM_BUFFER,a,b.buffer))}unbindUBO(a){for(let b= 0,c=this._state.uniformBufferBindingPoints.length;b