import{f as H,d as p}from"./WGLContainer-21aabd6b.js";import{n as nt,e as at}from"./programUtils-90c90c70.js";import{M as g,Y as G,eA as L,bU as z,z as lt,gU as ot,bz as ht}from"./index-b5c8f851.js";import{e as P,T as st,b,u as Y,d as _t}from"./Texture-507d5ea8.js";import{R,T as k,N as B,S as it,O as U,I as m,V as T,F as x,A as a,E,C as S,D as w,L as O,G as X,U as N,P as ut,f as ft,X as j,Y as D,_ as v,n as d,r as ct,e as K,M}from"./enums-bdecffa2.js";import{o as q,S as dt,s as Et,G as gt}from"./OrderIndependentTransparency-6ae10952.js";import{h as C,E as y}from"./FramebufferObject-4be671ef.js";import{t as I,f as pt,T as Ft}from"./testSVGPremultipliedAlpha-eac2b0ee.js";import{r as bt}from"./floatRGBA-ba8d5dad.js";import{t as Z}from"./doublePrecisionUtils-e3c3d0d8.js";import{f as W}from"./ProgramTemplate-a9187eb2.js";import{t as $}from"./VertexElementDescriptor-2925c6af.js";const Bt=e=>{let t="";t+=e[0].toUpperCase();for(let s=1;s{const t={};for(const s in e)t[Bt(s)]=e[s];return nt(t)},ee=(e,t,s,i)=>{const r=e+e.substring(e.lastIndexOf("/")),n=t+t.substring(t.lastIndexOf("/")),o=Rt(i);return{attributes:s,shaders:{vertexShader:o+H(`${r}.vert`),fragmentShader:o+H(`${n}.frag`)}}};let Q=class{constructor(){this.blend=!1,this.blendColor={r:0,g:0,b:0,a:0},this.blendFunction={srcRGB:R.ONE,dstRGB:R.ZERO,srcAlpha:R.ONE,dstAlpha:R.ZERO},this.blendEquation={mode:k.ADD,modeAlpha:k.ADD},this.colorMask={r:!0,g:!0,b:!0,a:!0},this.faceCulling=!1,this.cullFace=B.BACK,this.frontFace=it.CCW,this.scissorTest=!1,this.scissorRect={x:0,y:0,width:0,height:0},this.depthTest=!1,this.depthFunction=U.LESS,this.clearDepth=1,this.depthWrite=!0,this.depthRange={zNear:0,zFar:1},this.viewport=null,this.stencilTest=!1,this.polygonOffsetFill=!1,this.polygonOffset=[0,0],this.stencilFunction={face:B.FRONT_AND_BACK,func:U.ALWAYS,ref:0,mask:1},this.clearStencil=0,this.stencilWriteMask=1,this.stencilOperation={face:B.FRONT_AND_BACK,fail:m.KEEP,zFail:m.KEEP,zPass:m.KEEP},this.clearColor={r:0,g:0,b:0,a:0},this.program=null,this.vertexBuffer=null,this.indexBuffer=null,this.uniformBuffer=null,this.pixelPackBuffer=null,this.pixelUnpackBuffer=null,this.copyReadBuffer=null,this.copyWriteBuffer=null,this.uniformBufferBindingPoints=new Array,this.readFramebuffer=null,this.drawFramebuffer=null,this.renderbuffer=null,this.activeTexture=0,this.textureUnitMap=new Array,this.vertexArrayObject=null}},Tt=class{constructor(t){this._allocations=new Map,t?Error.stackTraceLimit=1/0:(this.add=()=>{},this.remove=()=>{})}add(t){this._allocations.set(t,new Error().stack)}remove(t){this._allocations.delete(t)}get information(){let t="";if(this._allocations.size>0){t+=`${this._allocations.size} live object allocations: `;const s=new Map;this._allocations.forEach(i=>{s.set(i,(s.get(i)??0)+1)}),s.forEach((i,r)=>{const n=r.split(` `);n.shift(),n.shift(),t+=`${i}: ${n.shift()} `,n.forEach(o=>t+=` ${o} `)})}return t}};const mt={RECORD_ALLOCATIONS:!1};let At=class{constructor(){for(this._current=new Array,this._allocations=new Tt(mt.RECORD_ALLOCATIONS);this._current.lengtht+(i0){t+=`Live objects: `;for(let s=0;s0&&(t+=`${T[s]}: ${i} `)}}return t+=this._allocations.information,t}};class xt{constructor(t,s,i){const r=s.textureFilterAnisotropic,n=i.maxAnisotropy??1/0;this.versionString=t.getParameter(t.VERSION),this.maxVertexTextureImageUnits=t.getParameter(t.MAX_VERTEX_TEXTURE_IMAGE_UNITS),this.maxVertexAttributes=t.getParameter(t.MAX_VERTEX_ATTRIBS),this.maxMaxAnisotropy=r?Math.min(t.getParameter(r.MAX_TEXTURE_MAX_ANISOTROPY),n):1,this.maxTextureImageUnits=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),this.maxTextureSize=t.getParameter(t.MAX_TEXTURE_SIZE),this.maxRenderbufferSize=t.getParameter(t.MAX_RENDERBUFFER_SIZE),this.maxViewportDims=t.getParameter(t.MAX_VIEWPORT_DIMS),p(t)?(this.maxUniformBufferBindings=t.getParameter(t.MAX_UNIFORM_BUFFER_BINDINGS),this.maxVertexUniformBlocks=t.getParameter(t.MAX_VERTEX_UNIFORM_BLOCKS),this.maxFragmentUniformBlocks=t.getParameter(t.MAX_FRAGMENT_UNIFORM_BLOCKS),this.maxUniformBlockSize=t.getParameter(t.MAX_UNIFORM_BLOCK_SIZE),this.uniformBufferOffsetAlignment=t.getParameter(t.UNIFORM_BUFFER_OFFSET_ALIGNMENT),this.maxArrayTextureLayers=t.getParameter(t.MAX_ARRAY_TEXTURE_LAYERS),this.maxSamples=t.getParameter(t.MAX_SAMPLES)):(this.maxUniformBufferBindings=0,this.maxVertexUniformBlocks=0,this.maxFragmentUniformBlocks=0,this.maxUniformBlockSize=0,this.uniformBufferOffsetAlignment=1,this.maxArrayTextureLayers=1,this.maxSamples=1)}}let St=class rt{constructor(t){this._rctx=t,this._indexBuffer=this._createIndexbuffer(),this._program=this._createHelperProgram()}static getShaderSources(){return{vertex:`#version 300 es precision highp float; void main(void) { gl_Position = vec4(0.0, 0.0, float(gl_VertexID)-2.0, 1.0); }`,fragment:`#version 300 es precision highp float; out vec4 fragColor; void main(void) { fragColor = vec4(0.0, 0.0, 0.0, 1.0); }`}}_createHelperProgram(){const t=rt.getShaderSources();return this._rctx.programCache.acquire(t.vertex,t.fragment,new Map([]))}_createIndexbuffer(){return C.createIndex(this._rctx,x.STATIC_DRAW,new Uint32Array([0]))}run(){this._program.compiled&&this._indexBuffer&&(this._rctx.bindVAO(null),this._rctx.useProgram(this._program),this._rctx.bindBuffer(this._indexBuffer,a.ELEMENT_ARRAY_BUFFER),this._rctx.drawElements(E.POINTS,1,S.UNSIGNED_INT,0))}dispose(){this._program.dispose(),this._indexBuffer.dispose()}get test(){var t;return{cachedWebGLObjects:(t=this._indexBuffer)!=null&&t.glName?1:0}}};class Ot extends I{constructor(t){super(),this._rctx=t,this._helperProgram=null,this._rctx.type===g.WEBGL2&&G("mac")&&G("chrome")&&(this._program=this._prepareProgram(),this._helperProgram=this._prepareHelperProgram())}dispose(){var t;super.dispose(),(t=this._helperProgram)==null||t.dispose(),this._helperProgram=null}_test(t){const s=this._rctx,i=s.getBoundFramebufferObject(),{x:r,y:n,width:o,height:l}=s.getViewport();s.resetState();const h=new P(1);h.wrapMode=w.CLAMP_TO_EDGE,h.samplingMode=O.NEAREST;const _=new y(s,h),u=C.createIndex(this._rctx,x.STATIC_DRAW,new Uint8Array([0]));s.bindFramebuffer(_),s.setViewport(0,0,1,1),s.useProgram(this._helperProgram),s.bindBuffer(u,a.ELEMENT_ARRAY_BUFFER),s.drawElements(E.POINTS,1,S.UNSIGNED_BYTE,0),s.useProgram(t),s.bindVAO(null),s.drawArrays(E.TRIANGLES,0,258);const f=new Uint8Array(4);return _.readPixels(0,0,1,1,X.RGBA,N.UNSIGNED_BYTE,f),s.setViewport(r,n,o,l),s.bindFramebuffer(i),_.dispose(),u.dispose(),f[0]===255}_prepareProgram(){const s=`#version 300 es precision highp float; out float triangleId; const vec3 triangleVertices[3] = vec3[3](vec3(-0.5, -0.5, 0.0), vec3(0.5, -0.5, 0.0), vec3(0.0, 0.5, 0.0)); void main(void) { triangleId = floor(float(gl_VertexID)/3.0); vec3 position = triangleVertices[gl_VertexID % 3]; float offset = triangleId / ${q.float(85)}; position.z = 0.5 - offset; gl_Position = vec4(position, 1.0); } `,i=`#version 300 es precision highp float; in float triangleId; out vec4 fragColor; void main(void) { fragColor = triangleId == ${q.float(85)} ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0); } `;return this._rctx.programCache.acquire(s,i,new Map([]))}_prepareHelperProgram(){const t=St.getShaderSources();return this._rctx.programCache.acquire(t.vertex,t.fragment,new Map([]))}}let Ct=class extends I{constructor(t){super(),this._rctx=t,this._program=J(this._rctx,!1),this._obfuscated=J(this._rctx,!0)}dispose(){super.dispose(),this._obfuscated=L(this._obfuscated)}_test(t){if(G("force-double-precision-obfuscation"))return!0;if(this._obfuscated==null)return!1;const s=this._runProgram(t),i=this._runProgram(this._obfuscated);return s!==0&&(i===0||s/i>5)}_runProgram(t){const s=this._rctx;s.resetState();const i=new P(1);i.wrapMode=w.CLAMP_TO_EDGE,i.samplingMode=O.NEAREST;const r=new y(s,i),n=C.createVertex(s,x.STATIC_DRAW,new Uint16Array([0,0,1,0,0,1,1,1])),o=new W(s,new Map([["position",0]]),{geometry:[new $("position",2,S.UNSIGNED_SHORT,0,4)]},{geometry:n}),l=z(5633261287538229e-9,2626832878767164e-9,1.4349880495278358e6),h=z(563327146742708e-8,2.6268736381334523e6,1434963231608387e-9),_=new Float32Array(6);Z(l,_,3);const u=new Float32Array(6);Z(h,u,3),s.useProgram(t),t.setUniform3f("u_highA",_[0],_[2],_[4]),t.setUniform3f("u_lowA",_[1],_[3],_[5]),t.setUniform3f("u_highB",u[0],u[2],u[4]),t.setUniform3f("u_lowB",u[1],u[3],u[5]),s.bindFramebuffer(r),s.setViewport(0,0,1,1),s.bindVAO(o),s.drawArrays(E.TRIANGLE_STRIP,0,4);const f=new Uint8Array(4);r.readPixels(0,0,1,1,X.RGBA,N.UNSIGNED_BYTE,f),o.dispose(),r.dispose();const F=(l[2]-h[2])/25,A=bt(f);return Math.abs(F-A)}};function J(e,t){const s=` precision highp float; attribute vec2 position; uniform vec3 u_highA; uniform vec3 u_lowA; uniform vec3 u_highB; uniform vec3 u_lowB; varying vec4 v_color; ${t?"#define DOUBLE_PRECISION_REQUIRES_OBFUSCATION":""} #ifdef DOUBLE_PRECISION_REQUIRES_OBFUSCATION vec3 dpPlusFrc(vec3 a, vec3 b) { return mix(a, a + b, vec3(notEqual(b, vec3(0)))); } vec3 dpMinusFrc(vec3 a, vec3 b) { return mix(vec3(0), a - b, vec3(notEqual(a, b))); } vec3 dpAdd(vec3 hiA, vec3 loA, vec3 hiB, vec3 loB) { vec3 t1 = dpPlusFrc(hiA, hiB); vec3 e = dpMinusFrc(t1, hiA); vec3 t2 = dpMinusFrc(hiB, e) + dpMinusFrc(hiA, dpMinusFrc(t1, e)) + loA + loB; return t1 + t2; } #else vec3 dpAdd(vec3 hiA, vec3 loA, vec3 hiB, vec3 loB) { vec3 t1 = hiA + hiB; vec3 e = t1 - hiA; vec3 t2 = ((hiB - e) + (hiA - (t1 - e))) + loA + loB; return t1 + t2; } #endif const float MAX_RGBA_FLOAT = 255.0 / 256.0 + 255.0 / 256.0 / 256.0 + 255.0 / 256.0 / 256.0 / 256.0 + 255.0 / 256.0 / 256.0 / 256.0 / 256.0; const vec4 FIXED_POINT_FACTORS = vec4(1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0); vec4 float2rgba(const float value) { // Make sure value is in the domain we can represent float valueInValidDomain = clamp(value, 0.0, MAX_RGBA_FLOAT); // Decompose value in 32bit fixed point parts represented as // uint8 rgba components. Decomposition uses the fractional part after multiplying // by a power of 256 (this removes the bits that are represented in the previous // component) and then converts the fractional part to 8bits. vec4 fixedPointU8 = floor(fract(valueInValidDomain * FIXED_POINT_FACTORS) * 256.0); // Convert uint8 values (from 0 to 255) to floating point representation for // the shader const float toU8AsFloat = 1.0 / 255.0; return fixedPointU8 * toU8AsFloat; } void main() { vec3 val = dpAdd(u_highA, u_lowA, -u_highB, -u_lowB); v_color = float2rgba(val.z / 25.0); gl_Position = vec4(position * 2.0 - 1.0, 0.0, 1.0); } `,i=` precision highp float; varying vec4 v_color; void main() { gl_FragColor = v_color; } `;return e.programCache.acquire(s,i,new Map([["position",0]]))}let vt=class extends I{constructor(t){var r,n,o,l,h;if(super(),this._rctx=t,!t.gl)return;if(t.type===g.WEBGL1)return void(this._result=!(!((r=t.capabilities.textureFloat)!=null&&r.textureFloat)||!((n=t.capabilities.colorBufferFloat)!=null&&n.textureFloat)));if(!((o=t.capabilities.textureFloat)!=null&&o.textureFloat&&((l=t.capabilities.colorBufferFloat)!=null&&l.textureFloat)&&((h=t.capabilities.colorBufferFloat)!=null&&h.floatBlend)))return;const s=` precision highp float; attribute vec2 a_pos; void main() { gl_Position = vec4(a_pos * 2.0 - 1.0, 0.0, 1.0); } `,i=` precision highp float; void main() { gl_FragColor = vec4(0.5, 0.5, 0.5, 0.5); } `;this._program=t.programCache.acquire(s,i,new Map([["a_pos",0]]))}_test(t){const s=this._rctx,i=new P(1);i.wrapMode=w.CLAMP_TO_EDGE,i.dataType=N.FLOAT,i.internalFormat=ut.RGBA32F,i.samplingMode=O.NEAREST;const r=new y(s,i),n=C.createVertex(s,x.STATIC_DRAW,new Uint16Array([0,0,1,0,0,1,1,1])),o=new W(s,new Map([["a_pos",0]]),{geometry:[new $("a_pos",2,S.UNSIGNED_SHORT,0,4)]},{geometry:n});s.useProgram(t);const l=s.getBoundFramebufferObject(),{x:h,y:_,width:u,height:f}=s.getViewport();s.bindFramebuffer(r),s.setViewport(0,0,1,1),s.bindVAO(o),s.drawArrays(E.TRIANGLE_STRIP,0,4);const F=dt({blending:Et});s.setPipelineState(F),s.drawArrays(E.TRIANGLE_STRIP,0,4);const A=s.gl.getError();return s.setViewport(h,_,u,f),s.bindFramebuffer(l),o.dispose(),r.dispose(),A!==1282||(console.warn("Device claims support for WebGL extension EXT_float_blend but does not support it. Using fall back."),!1)}};class Mt extends I{constructor(t){super(),this._rctx=t;const s=` precision highp float; attribute vec2 a_pos; uniform highp sampler2D u_texture; varying vec4 v_color; float getBit(in float bitset, in int bitIndex) { float offset = pow(2.0, float(bitIndex)); return mod(floor(bitset / offset), 2.0); } void main() { vec4 value = texture2D(u_texture, vec2(0.0)); float bit = getBit(value.x * 255.0, 1); v_color = bit * vec4(1.0); gl_Position = vec4(a_pos * 2.0 - 1.0, 0.0, 1.0); } `,i=` precision highp float; varying vec4 v_color; void main() { gl_FragColor = v_color; } `;this._program=t.programCache.acquire(s,i,new Map([["a_pos",0]]))}_test(t){const s=this._rctx,i=new P(1);i.wrapMode=w.CLAMP_TO_EDGE,i.samplingMode=O.NEAREST;const r=new y(s,i),n=new Uint8Array(4),o=C.createVertex(s,x.STATIC_DRAW,new Uint16Array([0,0,1,0,0,1,1,1])),l=new W(s,new Map([["a_position",0]]),{geometry:[new $("a_position",2,S.SHORT,0,4)]},{geometry:o});s.useProgram(t);const h=new st(s,i,new Uint8Array([2,255,0,0]));t.setUniform1i("u_texture",0),s.bindTexture(h,0);const _=s.getBoundFramebufferObject();s.bindFramebuffer(r),s.useProgram(t);const{x:u,y:f,width:F,height:A}=s.getViewport();s.setViewport(0,0,1,1),s.bindVAO(l),s.drawArrays(E.TRIANGLE_STRIP,0,4),s.setViewport(u,f,F,A),r.readPixels(0,0,1,1,X.RGBA,N.UNSIGNED_BYTE,n),l.dispose(),r.dispose();const V=n[0]!==255||n[1]!==255||n[2]!==255||n[3]!==255;return V&<.getLogger("esri.views.webgl.testSamplerPrecision").warn(`A problem was detected with your graphics driver. Your driver does not appear to honor sampler precision specifiers, which may result in rendering issues due to numerical instability. We recommend ensuring that your drivers have been updated to the latest version. Applying lowp sampler workaround. [${n[0]}.${n[1]}.${n[2]}.${n[3]}]`),s.bindFramebuffer(_),V}}let Ut=class{constructor(t){this.rctx=t,this.floatBufferBlend=new vt(t),this.svgPremultipliesAlpha=new pt(t),this.doublePrecisionRequiresObfuscation=new Ct(t),this.ignoresSamplerPrecision=new Mt(t),this.drawArraysRequiresIndicesTypeReset=new Ot(t)}dispose(){this.ignoresSamplerPrecision.dispose(),this.doublePrecisionRequiresObfuscation.dispose(),this.svgPremultipliesAlpha.dispose(),this.floatBufferBlend.dispose(),this.drawArraysRequiresIndicesTypeReset.dispose()}};function Pt(e,t){if(t.disjointTimerQuery)return null;if(p(e))return{drawBuffers:e.drawBuffers.bind(e),MAX_DRAW_BUFFERS:e.MAX_DRAW_BUFFERS,MAX_COLOR_ATTACHMENTS:e.MAX_COLOR_ATTACHMENTS};if(t.drawBuffers)return null;const s=e.getExtension("WEBGL_draw_buffers");return s?{drawBuffers:s.drawBuffersWEBGL.bind(s),MAX_DRAW_BUFFERS:s.MAX_DRAW_BUFFERS_WEBGL,MAX_COLOR_ATTACHMENTS:s.MAX_COLOR_ATTACHMENTS_WEBGL}:null}function wt(e,t){if(t.compressedTextureETC)return null;const s=e.getExtension("WEBGL_compressed_texture_etc");return s?{COMPRESSED_R11_EAC:s.COMPRESSED_R11_EAC,COMPRESSED_SIGNED_R11_EAC:s.COMPRESSED_SIGNED_R11_EAC,COMPRESSED_RG11_EAC:s.COMPRESSED_RG11_EAC,COMPRESSED_SIGNED_RG11_EAC:s.COMPRESSED_SIGNED_RG11_EAC,COMPRESSED_RGB8_ETC2:s.COMPRESSED_RGB8_ETC2,COMPRESSED_SRGB8_ETC2:s.COMPRESSED_SRGB8_ETC2,COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:s.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:s.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,COMPRESSED_RGBA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC,COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC}:null}function Nt(e,t){if(t.compressedTextureS3TC)return null;const s=e.getExtension("WEBGL_compressed_texture_s3tc");return s?{COMPRESSED_RGB_S3TC_DXT1:s.COMPRESSED_RGB_S3TC_DXT1_EXT,COMPRESSED_RGBA_S3TC_DXT1:s.COMPRESSED_RGBA_S3TC_DXT1_EXT,COMPRESSED_RGBA_S3TC_DXT3:s.COMPRESSED_RGBA_S3TC_DXT3_EXT,COMPRESSED_RGBA_S3TC_DXT5:s.COMPRESSED_RGBA_S3TC_DXT5_EXT}:null}function yt(e,t){if(p(e))return{MIN:e.MIN,MAX:e.MAX};if(t.blendMinMax)return null;{const s=e.getExtension("EXT_blend_minmax");return s?{MIN:s.MIN_EXT,MAX:s.MAX_EXT}:null}}function It(e,t){if(t.textureFilterAnisotropic)return null;const s=e.getExtension("EXT_texture_filter_anisotropic")||e.getExtension("MOZ_EXT_texture_filter_anisotropic")||e.getExtension("WEBKIT_EXT_texture_filter_anisotropic");return s?{MAX_TEXTURE_MAX_ANISOTROPY:s.MAX_TEXTURE_MAX_ANISOTROPY_EXT,TEXTURE_MAX_ANISOTROPY:s.TEXTURE_MAX_ANISOTROPY_EXT}:null}function Dt(e,t){if(p(e))return{textureFloat:!0,textureFloatLinear:!t.textureFloatLinear&&!!e.getExtension("OES_texture_float_linear"),textureHalfFloat:!0,textureHalfFloatLinear:!0,HALF_FLOAT:e.HALF_FLOAT,R16F:e.R16F,RG16F:e.RG16F,RGBA16F:e.RGBA16F,R32F:e.R32F,RG32F:e.RG32F,RGBA32F:e.RGBA32F,R11F_G11F_B10F:e.R11F_G11F_B10F,RGB16F:e.RGB16F};if(e instanceof WebGLRenderingContext){const s=!t.textureHalfFloat&&e.getExtension("OES_texture_half_float");return{textureFloat:!t.textureFloat&&!!e.getExtension("OES_texture_float"),textureFloatLinear:!t.textureFloatLinear&&!!e.getExtension("OES_texture_float_linear"),textureHalfFloat:!!s,textureHalfFloatLinear:!t.textureHalfFloatLinear&&!!e.getExtension("OES_texture_half_float_linear"),HALF_FLOAT:s?s.HALF_FLOAT_OES:void 0}}return null}function Gt(e,t){if(p(e)){const s=!t.colorBufferHalfFloat&&e.getExtension("EXT_color_buffer_half_float")||!t.colorBufferFloat&&e.getExtension("EXT_color_buffer_float"),i=!t.colorBufferFloat&&e.getExtension("EXT_color_buffer_float"),r=!t.floatBlend&&!t.colorBufferFloat&&e.getExtension("EXT_float_blend");return s||i||r?{textureFloat:!!i,textureHalfFloat:!!s,floatBlend:!!r,R16F:e.R16F,RG16F:e.RG16F,RGBA16F:e.RGBA16F,R32F:e.R32F,RG32F:e.RG32F,RGBA32F:e.RGBA32F,R11F_G11F_B10F:e.R11F_G11F_B10F,RGB16F:e.RGB16F}:null}if(e instanceof WebGLRenderingContext){const s=!t.colorBufferHalfFloat&&e.getExtension("EXT_color_buffer_half_float"),i=!t.colorBufferFloat&&e.getExtension("WEBGL_color_buffer_float"),r=!t.floatBlend&&!t.colorBufferFloat&&e.getExtension("EXT_float_blend");return s||i||r?{textureFloat:!!i,textureHalfFloat:!!s,floatBlend:!!r,RGBA16F:s?s.RGBA16F_EXT:void 0,RGB16F:s?s.RGB16F_EXT:void 0,RGBA32F:i?i.RGBA32F_EXT:void 0}:null}return null}function tt(e,t,s,i,r){if(i&&p(e))return!0;if(t[s])return!1;for(const n of r)if(e.getExtension(n))return!0;return!1}function Lt(e,t){if(!p(e)||t.textureNorm16)return null;const s=e.getExtension("EXT_texture_norm16");return s?{R16:s.R16_EXT,RG16:s.RG16_EXT,RGB16:s.RGB16_EXT,RGBA16:s.RGBA16_EXT,R16_SNORM:s.R16_SNORM_EXT,RG16_SNORM:s.RG16_SNORM_EXT,RGB16_SNORM:s.RGB16_SNORM_EXT,RGBA16_SNORM:s.RGBA16_SNORM_EXT}:null}function kt(e,t){const s=t.loseContext&&e.getExtension("WEBGL_lose_context");return s?{loseRenderingContext:()=>s.loseContext()}:null}function Xt(e,t){if(p(e))return{createVertexArray:e.createVertexArray.bind(e),deleteVertexArray:e.deleteVertexArray.bind(e),bindVertexArray:e.bindVertexArray.bind(e)};if(t.vao)return null;const s=e.getExtension("OES_vertex_array_object")||e.getExtension("MOZ_OES_vertex_array_object")||e.getExtension("WEBKIT_OES_vertex_array_object");return s?{createVertexArray:s.createVertexArrayOES.bind(s),deleteVertexArray:s.deleteVertexArrayOES.bind(s),bindVertexArray:s.bindVertexArrayOES.bind(s)}:null}class Wt{constructor(t,s){this._gl=t,this._vertexArrayObject=null,this._compressedTextureETC=null,this._compressedTextureS3TC=null,this._textureFilterAnisotropic=null,this._textureFloat=null,this._colorBufferFloat=null,this._minMaxBlending=null,this._loseContext=null,this._drawBuffers=null,this._textureNorm16=null,this._depthTexture=null,this._textureFloatLinear=null,this._disabledExtensions=s.disabledExtensions||{},this._debugWebGLExtensions=s.debugWebGLExtensions||{}}get drawBuffers(){return this._drawBuffers||(this._drawBuffers=Pt(this._gl,this._disabledExtensions)),this._drawBuffers}get vao(){return this._vertexArrayObject||(this._vertexArrayObject=Xt(this._gl,this._disabledExtensions)),this._vertexArrayObject}get compressedTextureETC(){return this._compressedTextureETC||(this._compressedTextureETC=wt(this._gl,this._disabledExtensions)),this._compressedTextureETC}get compressedTextureS3TC(){return this._compressedTextureS3TC||(this._compressedTextureS3TC=Nt(this._gl,this._disabledExtensions)),this._compressedTextureS3TC}get textureFilterAnisotropic(){return this._textureFilterAnisotropic||(this._textureFilterAnisotropic=It(this._gl,this._disabledExtensions)),this._textureFilterAnisotropic}get disjointTimerQuery(){return this._disjointTimerQuery||(this._disjointTimerQuery=Ft(this._gl,this._disabledExtensions)),this._disjointTimerQuery}get textureFloat(){return this._textureFloat||(this._textureFloat=Dt(this._gl,this._disabledExtensions)),this._textureFloat}get colorBufferFloat(){return this._colorBufferFloat||(this._colorBufferFloat=Gt(this._gl,this._disabledExtensions)),this._colorBufferFloat}get blendMinMax(){return this._minMaxBlending||(this._minMaxBlending=yt(this._gl,this._disabledExtensions)),this._minMaxBlending}get depthTexture(){return this._depthTexture===null&&(this._depthTexture=tt(this._gl,this._disabledExtensions,"depthTexture",!0,["WEBGL_depth_texture","MOZ_WEBGL_depth_texture","WEBKIT_WEBGL_depth_texture"])),this._depthTexture}get loseContext(){return this._loseContext||(this._loseContext=kt(this._gl,this._debugWebGLExtensions)),this._loseContext}get textureNorm16(){return this._textureNorm16||(this._textureNorm16=Lt(this._gl,this._disabledExtensions)),this._textureNorm16}get textureFloatLinear(){return this._textureFloatLinear===null&&(this._textureFloatLinear=tt(this._gl,this._disabledExtensions,"textureFloatLinear",!1,["OES_texture_float_linear"])),this._textureFloatLinear}enable(t){return this[t]}}let oe=class{constructor(e,t){this.gl=e,this.instanceCounter=new At,this.programCache=new at(this),this._state=new Q,this._numOfDrawCalls=0,this._numOfTriangles=0,this.type=p(e)?g.WEBGL2:g.WEBGL1,this._loadExtensions(),this.configure(t)}get gl2(){return this.type===g.WEBGL1?null:this.gl}configure(e){this._capabilities=new Wt(this.gl,e),this._parameters=new xt(this.gl,this._capabilities,e),st.TEXTURE_UNIT_FOR_UPDATES=this._parameters.maxTextureImageUnits-1;const t=this.gl.getParameter(this.gl.VIEWPORT);this._state=new Q,this._state.viewport={x:t[0],y:t[1],width:t[2],height:t[3]},this._stateTracker=new gt({setBlending:s=>{if(s){this.setBlendingEnabled(!0),this.setBlendEquationSeparate(s.opRgb,s.opAlpha),this.setBlendFunctionSeparate(s.srcRgb,s.dstRgb,s.srcAlpha,s.dstAlpha);const i=s.color;this.setBlendColor(i.r,i.g,i.b,i.a)}else this.setBlendingEnabled(!1)},setCulling:s=>{s?(this.setFaceCullingEnabled(!0),this.setCullFace(s.face),this.setFrontFace(s.mode)):this.setFaceCullingEnabled(!1)},setPolygonOffset:s=>{s?(this.setPolygonOffsetFillEnabled(!0),this.setPolygonOffset(s.factor,s.units)):this.setPolygonOffsetFillEnabled(!1)},setDepthTest:s=>{s?(this.setDepthTestEnabled(!0),this.setDepthFunction(s.func)):this.setDepthTestEnabled(!1)},setStencilTest:s=>{if(s){this.setStencilTestEnabled(!0);const i=s.function;this.setStencilFunction(i.func,i.ref,i.mask);const r=s.operation;this.setStencilOp(r.fail,r.zFail,r.zPass)}else this.setStencilTestEnabled(!1)},setDepthWrite:s=>{s?(this.setDepthWriteEnabled(!0),this.setDepthRange(s.zNear,s.zFar)):this.setDepthWriteEnabled(!1)},setColorWrite:s=>{s?this.setColorMask(s.r,s.g,s.b,s.a):this.setColorMask(!1,!1,!1,!1)},setStencilWrite:s=>{s?this.setStencilWriteMask(s.mask):this.setStencilWriteMask(0)},setDrawBuffers:s=>{const{drawBuffers:i}=this._capabilities;if(s)i==null||i.drawBuffers(s.buffers);else{const{drawFramebuffer:r}=this._state;r===null||r.colorAttachments.length===0?i==null||i.drawBuffers([ft.BACK]):i==null||i.drawBuffers([j.COLOR_ATTACHMENT0])}}}),this.enforceState(),L(this._driverTest),this._driverTest=new Ut(this)}dispose(){L(this._driverTest),this.programCache.dispose(),this.bindVAO(null),this.unbindBuffer(a.ARRAY_BUFFER),this.unbindBuffer(a.ELEMENT_ARRAY_BUFFER),this.type===g.WEBGL2&&(this.unbindBuffer(a.UNIFORM_BUFFER),this._state.uniformBufferBindingPoints.length=0,this.unbindBuffer(a.PIXEL_PACK_BUFFER),this.unbindBuffer(a.PIXEL_UNPACK_BUFFER),this.unbindBuffer(a.COPY_READ_BUFFER),this.unbindBuffer(a.COPY_WRITE_BUFFER)),this._state.textureUnitMap.length=0,b()&&console.log(this.instanceCounter.resourceInformation)}get driverTest(){return this._driverTest}get contextAttributes(){return this.gl.getContextAttributes()}get parameters(){return this._parameters}setPipelineState(e){this._stateTracker.setPipeline(e)}setBlendingEnabled(e){this._state.blend!==e&&(e===!0?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this._state.blend=e,this._stateTracker.invalidateBlending())}externalProgramUpdate(){var e;(e=this._state.program)==null||e.stop(),this._state.program=null}externalTextureUnitUpdate(e,t){for(let s=0;s=0&&(this._state.activeTexture=t)}externalVertexArrayObjectUpdate(){const e=this.capabilities.vao;e&&(e.bindVertexArray(null),this._state.vertexArrayObject=null),this._state.vertexBuffer=null,this._state.indexBuffer=null}externalVertexBufferUpdate(){this._state.vertexBuffer=null}externalIndexBufferUpdate(){this._state.indexBuffer=null}setBlendColor(e,t,s,i){e===this._state.blendColor.r&&t===this._state.blendColor.g&&s===this._state.blendColor.b&&i===this._state.blendColor.a||(this.gl.blendColor(e,t,s,i),this._state.blendColor.r=e,this._state.blendColor.g=t,this._state.blendColor.b=s,this._state.blendColor.a=i,this._stateTracker.invalidateBlending())}setBlendFunction(e,t){e===this._state.blendFunction.srcRGB&&t===this._state.blendFunction.dstRGB||(this.gl.blendFunc(e,t),this._state.blendFunction.srcRGB=e,this._state.blendFunction.srcAlpha=e,this._state.blendFunction.dstRGB=t,this._state.blendFunction.dstAlpha=t,this._stateTracker.invalidateBlending())}setBlendFunctionSeparate(e,t,s,i){this._state.blendFunction.srcRGB===e&&this._state.blendFunction.srcAlpha===s&&this._state.blendFunction.dstRGB===t&&this._state.blendFunction.dstAlpha===i||(this.gl.blendFuncSeparate(e,t,s,i),this._state.blendFunction.srcRGB=e,this._state.blendFunction.srcAlpha=s,this._state.blendFunction.dstRGB=t,this._state.blendFunction.dstAlpha=i,this._stateTracker.invalidateBlending())}setBlendEquation(e){this._state.blendEquation.mode!==e&&(this.gl.blendEquation(e),this._state.blendEquation.mode=e,this._state.blendEquation.modeAlpha=e,this._stateTracker.invalidateBlending())}setBlendEquationSeparate(e,t){this._state.blendEquation.mode===e&&this._state.blendEquation.modeAlpha===t||(this.gl.blendEquationSeparate(e,t),this._state.blendEquation.mode=e,this._state.blendEquation.modeAlpha=t,this._stateTracker.invalidateBlending())}setColorMask(e,t,s,i){this._state.colorMask.r===e&&this._state.colorMask.g===t&&this._state.colorMask.b===s&&this._state.colorMask.a===i||(this.gl.colorMask(e,t,s,i),this._state.colorMask.r=e,this._state.colorMask.g=t,this._state.colorMask.b=s,this._state.colorMask.a=i,this._stateTracker.invalidateColorWrite())}setClearColor(e,t,s,i){this._state.clearColor.r===e&&this._state.clearColor.g===t&&this._state.clearColor.b===s&&this._state.clearColor.a===i||(this.gl.clearColor(e,t,s,i),this._state.clearColor.r=e,this._state.clearColor.g=t,this._state.clearColor.b=s,this._state.clearColor.a=i)}setFaceCullingEnabled(e){this._state.faceCulling!==e&&(e===!0?this.gl.enable(this.gl.CULL_FACE):this.gl.disable(this.gl.CULL_FACE),this._state.faceCulling=e,this._stateTracker.invalidateCulling())}setPolygonOffsetFillEnabled(e){this._state.polygonOffsetFill!==e&&(e===!0?this.gl.enable(this.gl.POLYGON_OFFSET_FILL):this.gl.disable(this.gl.POLYGON_OFFSET_FILL),this._state.polygonOffsetFill=e,this._stateTracker.invalidatePolygonOffset())}setPolygonOffset(e,t){this._state.polygonOffset[0]===e&&this._state.polygonOffset[1]===t||(this._state.polygonOffset[0]=e,this._state.polygonOffset[1]=t,this.gl.polygonOffset(e,t),this._stateTracker.invalidatePolygonOffset())}setCullFace(e){this._state.cullFace!==e&&(this.gl.cullFace(e),this._state.cullFace=e,this._stateTracker.invalidateCulling())}setFrontFace(e){this._state.frontFace!==e&&(this.gl.frontFace(e),this._state.frontFace=e,this._stateTracker.invalidateCulling())}setScissorTestEnabled(e){this._state.scissorTest!==e&&(e===!0?this.gl.enable(this.gl.SCISSOR_TEST):this.gl.disable(this.gl.SCISSOR_TEST),this._state.scissorTest=e)}setScissorRect(e,t,s,i){this._state.scissorRect.x===e&&this._state.scissorRect.y===t&&this._state.scissorRect.width===s&&this._state.scissorRect.height===i||(this.gl.scissor(e,t,s,i),this._state.scissorRect.x=e,this._state.scissorRect.y=t,this._state.scissorRect.width=s,this._state.scissorRect.height=i)}setDepthTestEnabled(e){this._state.depthTest!==e&&(e===!0?this.gl.enable(this.gl.DEPTH_TEST):this.gl.disable(this.gl.DEPTH_TEST),this._state.depthTest=e,this._stateTracker.invalidateDepthTest())}setClearDepth(e){this._state.clearDepth!==e&&(this.gl.clearDepth(e),this._state.clearDepth=e)}setDepthFunction(e){this._state.depthFunction!==e&&(this.gl.depthFunc(e),this._state.depthFunction=e,this._stateTracker.invalidateDepthTest())}setDepthWriteEnabled(e){this._state.depthWrite!==e&&(this.gl.depthMask(e),this._state.depthWrite=e,this._stateTracker.invalidateDepthWrite())}setDepthRange(e,t){this._state.depthRange.zNear===e&&this._state.depthRange.zFar===t||(this.gl.depthRange(e,t),this._state.depthRange.zNear=e,this._state.depthRange.zFar=t,this._stateTracker.invalidateDepthWrite())}setStencilTestEnabled(e){this._state.stencilTest!==e&&(e===!0?this.gl.enable(this.gl.STENCIL_TEST):this.gl.disable(this.gl.STENCIL_TEST),this._state.stencilTest=e,this._stateTracker.invalidateStencilTest())}setClearStencil(e){e!==this._state.clearStencil&&(this.gl.clearStencil(e),this._state.clearStencil=e)}setStencilFunction(e,t,s){this._state.stencilFunction.func===e&&this._state.stencilFunction.ref===t&&this._state.stencilFunction.mask===s||(this.gl.stencilFunc(e,t,s),this._state.stencilFunction.face=B.FRONT_AND_BACK,this._state.stencilFunction.func=e,this._state.stencilFunction.ref=t,this._state.stencilFunction.mask=s,this._stateTracker.invalidateStencilTest())}setStencilFunctionSeparate(e,t,s,i){this._state.stencilFunction.face===e&&this._state.stencilFunction.func===t&&this._state.stencilFunction.ref===s&&this._state.stencilFunction.mask===i||(this.gl.stencilFuncSeparate(e,t,s,i),this._state.stencilFunction.face=e,this._state.stencilFunction.func=t,this._state.stencilFunction.ref=s,this._state.stencilFunction.mask=i,this._stateTracker.invalidateStencilTest())}setStencilWriteMask(e){this._state.stencilWriteMask!==e&&(this.gl.stencilMask(e),this._state.stencilWriteMask=e,this._stateTracker.invalidateStencilWrite())}setStencilOp(e,t,s){this._state.stencilOperation.face===B.FRONT_AND_BACK&&this._state.stencilOperation.fail===e&&this._state.stencilOperation.zFail===t&&this._state.stencilOperation.zPass===s||(this.gl.stencilOp(e,t,s),this._state.stencilOperation.face=B.FRONT_AND_BACK,this._state.stencilOperation.fail=e,this._state.stencilOperation.zFail=t,this._state.stencilOperation.zPass=s,this._stateTracker.invalidateStencilTest())}setStencilOpSeparate(e,t,s,i){this._state.stencilOperation.face===e&&this._state.stencilOperation.fail===t&&this._state.stencilOperation.zFail===s&&this._state.stencilOperation.zPass===i||(this.gl.stencilOpSeparate(e,t,s,i),this._state.stencilOperation.face=e,this._state.stencilOperation.fail=t,this._state.stencilOperation.zFail=s,this._state.stencilOperation.zPass=i,this._stateTracker.invalidateStencilTest())}setActiveTexture(e,t=!1){const s=this._state.activeTexture;return e>=0&&(t||e!==this._state.activeTexture)&&(this.gl.activeTexture(D+e),this._state.activeTexture=e),s}clear(e){e&&this.gl.clear(e)}clearSafe(e,t=255){e&&(e&v.COLOR_BUFFER_BIT&&this.setColorMask(!0,!0,!0,!0),e&v.DEPTH_BUFFER_BIT&&this.setDepthWriteEnabled(!0),e&v.STENCIL_BUFFER_BIT&&this.setStencilWriteMask(t),this.gl.clear(e))}drawArrays(e,t,s){b()&&(this._numOfDrawCalls++,this._numOfTriangles+=et(e,s)),this.gl.drawArrays(e,t,s),Y(this.gl)}drawArraysInstanced(e,t,s,i){var r;(r=this.gl2)==null||r.drawArraysInstanced(e,t,s,i),Y(this.gl)}drawElements(e,t,s,i){if(b()&&(this._numOfDrawCalls++,this._numOfTriangles+=et(e,t)),this.gl.drawElements(e,t,s,i),b()){const r=_t(this);if(r){const n=this.getBoundVAO(),o=n==null?void 0:n.indexBuffer,l=n==null?void 0:n.vertexBuffers,h={indexBuffer:o,vertexBuffers:l},_={mode:e,count:t,type:s,offset:i},u=(o==null?void 0:o.size)??0,f=i+t,F=u=this.parameters.maxTextureImageUnits||t<0)&&console.error("Input texture unit is out of range of available units!");const i=this._state.textureUnitMap[t];return(e==null?void 0:e.glName)==null?(i!=null&&(this.setActiveTexture(t,s),this.gl.bindTexture(i.descriptor.target,null)),this._state.textureUnitMap[t]=null,i):s||i!==e?(this.setActiveTexture(t,s),this.gl.bindTexture(e.descriptor.target,e.glName),e.applyChanges(),this._state.textureUnitMap[t]=e,i):(e.isDirty&&(this.setActiveTexture(t,s),e.applyChanges()),i)}unbindTexture(e){if(e!=null)for(let t=0;t=this.parameters.maxUniformBufferBindings||t<0)return console.error("Uniform buffer binding point is out of range!"),null;const s=this._state.uniformBufferBindingPoints;let i=s[t];return i==null&&(i={buffer:null,offset:0,size:0},s[t]=i),i}bindBufferBase(e,t,s){const i=this._getBufferBinding(e,t);i!=null&&(i.buffer===s&&i.offset===0&&i.size===0||(this.gl.bindBufferBase(e,t,s?s.glName:null),i.buffer=s,i.offset=0,i.size=0))}bindBufferRange(e,t,s,i,r){const n=this._getBufferBinding(e,t);if(n!=null&&!(n.buffer===s&&n.offset===i&&n.size===r)){if(i%this._parameters.uniformBufferOffsetAlignment!=0)return void console.error("Uniform buffer binding offset is not a multiple of the context offset alignment");this.gl.bindBufferRange(e,t,s.glName,i,r),n.buffer=s,n.offset=i,n.size=r}}bindUBO(e,t,s,i){t!=null?(b()&&(i??t.byteLength)>this._parameters.maxUniformBlockSize&&console.error("Attempting to bind more data than the maximum uniform block size"),t.initialize(),s!==void 0&&i!==void 0?this.bindBufferRange(a.UNIFORM_BUFFER,e,t.buffer,s,i):this.bindBufferBase(a.UNIFORM_BUFFER,e,t.buffer)):this.bindBufferBase(a.UNIFORM_BUFFER,e,null)}unbindUBO(e){for(let t=0,s=this._state.uniformBufferBindingPoints.length;t