@gis_victory/gismap 2.0.64 → 2.0.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gismap.css +1 -1
- package/dist/index-BM_uMd_q.js +1 -0
- package/dist/index-BWubh7Yt.js +1 -0
- package/dist/index-D-1yhK6a.js +12 -0
- package/dist/index.d.ts +161 -0
- package/dist/index.es.js +1 -12
- package/dist/index.umd.js +1 -1
- package/dist/webgl-developer-tools-XiIH8Rtv.js +1 -0
- package/dist/webgl-device-Ck4EhfeB.js +1 -0
- package/package.json +11 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{aU as e,bj as t,bk as r,Q as i,R as s,T as n,a4 as a,a0 as o,bl as c,aD as l,bm as u,bn as h,U as d,a5 as f,a7 as m,aS as g,bo as p,bp as b}from"./webgl-developer-tools-XiIH8Rtv.js";class y{props;_resizeObserver;_intersectionObserver;_observeDevicePixelRatioTimeout=null;_observeDevicePixelRatioMediaQuery=null;_handleDevicePixelRatioChange=()=>this._refreshDevicePixelRatio();_trackPositionInterval=null;_started=!1;get started(){return this._started}constructor(e){this.props=e}start(){if(!this._started&&this.props.canvas){this._started=!0,this._intersectionObserver||=new IntersectionObserver(e=>this.props.onIntersection(e)),this._resizeObserver||=new ResizeObserver(e=>this.props.onResize(e)),this._intersectionObserver.observe(this.props.canvas);try{this._resizeObserver.observe(this.props.canvas,{box:"device-pixel-content-box"})}catch{this._resizeObserver.observe(this.props.canvas,{box:"content-box"})}this._observeDevicePixelRatioTimeout=setTimeout(()=>this._refreshDevicePixelRatio(),0),this.props.trackPosition&&this._trackPosition()}}stop(){this._started&&(this._started=!1,this._observeDevicePixelRatioTimeout&&(clearTimeout(this._observeDevicePixelRatioTimeout),this._observeDevicePixelRatioTimeout=null),this._observeDevicePixelRatioMediaQuery&&(this._observeDevicePixelRatioMediaQuery.removeEventListener("change",this._handleDevicePixelRatioChange),this._observeDevicePixelRatioMediaQuery=null),this._trackPositionInterval&&(clearInterval(this._trackPositionInterval),this._trackPositionInterval=null),this._resizeObserver?.disconnect(),this._intersectionObserver?.disconnect())}_refreshDevicePixelRatio(){this._started&&(this.props.onDevicePixelRatioChange(),this._observeDevicePixelRatioMediaQuery?.removeEventListener("change",this._handleDevicePixelRatioChange),this._observeDevicePixelRatioMediaQuery=matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`),this._observeDevicePixelRatioMediaQuery.addEventListener("change",this._handleDevicePixelRatioChange,{once:!0}))}_trackPosition(e=100){this._trackPositionInterval||(this._trackPositionInterval=setInterval(()=>{this._started?this.props.onPositionChange():this._trackPositionInterval&&(clearInterval(this._trackPositionInterval),this._trackPositionInterval=null)},e))}}function v(e,t){if(!e){const e=new Error(t??"luma.gl assertion failed.");throw Error.captureStackTrace?.(e,v),e}}function x(e,t){return v(e,t),e}class w{static isHTMLCanvas(e){return"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement}static isOffscreenCanvas(e){return"undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas}static defaultProps={id:void 0,canvas:null,width:800,height:600,useDevicePixels:!0,autoResize:!0,container:null,visible:!0,alphaMode:"opaque",colorSpace:"srgb",trackPosition:!1};id;props;canvas;htmlCanvas;offscreenCanvas;type;initialized;isInitialized=!1;isVisible=!0;cssWidth;cssHeight;devicePixelRatio;devicePixelWidth;devicePixelHeight;drawingBufferWidth;drawingBufferHeight;_initializedResolvers=function(){let e,t;return{promise:new Promise((r,i)=>{e=r,t=i}),resolve:e,reject:t}}();_canvasObserver;_position=[0,0];destroyed=!1;_needsDrawingBufferResize=!0;toString(){return`${this[Symbol.toStringTag]}(${this.id})`}constructor(t){this.props={...w.defaultProps,...t},t=this.props,this.initialized=this._initializedResolvers.promise,e()?t.canvas?"string"==typeof t.canvas?this.canvas=function(e){const t=document.getElementById(e);if(!w.isHTMLCanvas(t))throw new Error("Object is not a canvas element");return t}(t.canvas):this.canvas=t.canvas:this.canvas=function(e){const{width:t,height:r}=e,s=document.createElement("canvas");s.id=i("lumagl-auto-created-canvas"),s.width=t||1,s.height=r||1,s.style.width=Number.isFinite(t)?`${t}px`:"100%",s.style.height=Number.isFinite(r)?`${r}px`:"100%",e?.visible||(s.style.visibility="hidden");const n=function(e){if("string"==typeof e){const t=document.getElementById(e);if(!t)throw new Error(`${e} is not an HTML element`);return t}if(e)return e;return document.body}(e?.container||null);return n.insertBefore(s,n.firstChild),s}(t):this.canvas={width:t.width||1,height:t.height||1},w.isHTMLCanvas(this.canvas)?(this.id=t.id||this.canvas.id,this.type="html-canvas",this.htmlCanvas=this.canvas):w.isOffscreenCanvas(this.canvas)?(this.id=t.id||"offscreen-canvas",this.type="offscreen-canvas",this.offscreenCanvas=this.canvas):(this.id=t.id||"node-canvas-context",this.type="node"),this.cssWidth=this.htmlCanvas?.clientWidth||this.canvas.width,this.cssHeight=this.htmlCanvas?.clientHeight||this.canvas.height,this.devicePixelWidth=this.canvas.width,this.devicePixelHeight=this.canvas.height,this.drawingBufferWidth=this.canvas.width,this.drawingBufferHeight=this.canvas.height,this.devicePixelRatio=globalThis.devicePixelRatio||1,this._position=[0,0],this._canvasObserver=new y({canvas:this.htmlCanvas,trackPosition:this.props.trackPosition,onResize:e=>this._handleResize(e),onIntersection:e=>this._handleIntersection(e),onDevicePixelRatioChange:()=>this._observeDevicePixelRatio(),onPositionChange:()=>this.updatePosition()})}destroy(){this.destroyed||(this.destroyed=!0,this._stopObservers(),this.device=null)}setProps(e){return"useDevicePixels"in e&&(this.props.useDevicePixels=e.useDevicePixels||!1,this._updateDrawingBufferSize()),this}getCurrentFramebuffer(e){return this._resizeDrawingBufferIfNeeded(),this._getCurrentFramebuffer(e)}getCSSSize(){return[this.cssWidth,this.cssHeight]}getPosition(){return this._position}getDevicePixelSize(){return[this.devicePixelWidth,this.devicePixelHeight]}getDrawingBufferSize(){return[this.drawingBufferWidth,this.drawingBufferHeight]}getMaxDrawingBufferSize(){const e=this.device.limits.maxTextureDimension2D;return[e,e]}setDrawingBufferSize(e,t){e=Math.floor(e),t=Math.floor(t),this.drawingBufferWidth===e&&this.drawingBufferHeight===t||(this.drawingBufferWidth=e,this.drawingBufferHeight=t,this._needsDrawingBufferResize=!0)}getDevicePixelRatio(){return"undefined"!=typeof window&&window.devicePixelRatio||1}cssToDevicePixels(e,t=!0){const r=this.cssToDeviceRatio(),[i,s]=this.getDrawingBufferSize();return function(e,t,r,i,s){const n=e,a=S(n[0],t,r);let o=_(n[1],t,i,s),c=S(n[0]+1,t,r);const l=c===r-1?c:c-1;let u;c=_(n[1]+1,t,i,s),s?(c=0===c?c:c+1,u=o,o=c):u=c===i-1?c:c-1;return{x:a,y:o,width:Math.max(l-a+1,1),height:Math.max(u-o+1,1)}}(e,r,i,s,t)}getPixelSize(){return this.getDevicePixelSize()}getAspect(){const[e,t]=this.getDrawingBufferSize();return e>0&&t>0?e/t:1}cssToDeviceRatio(){try{const[e]=this.getDrawingBufferSize(),[t]=this.getCSSSize();return t?e/t:1}catch{return 1}}resize(e){this.setDrawingBufferSize(e.width,e.height)}_setAutoCreatedCanvasId(e){"lumagl-auto-created-canvas"===this.htmlCanvas?.id&&(this.htmlCanvas.id=e)}_startObservers(){this.destroyed||this._canvasObserver.start()}_stopObservers(){this._canvasObserver.stop()}_handleIntersection(e){if(this.destroyed)return;const t=e.find(e=>e.target===this.canvas);if(!t)return;const r=t.isIntersecting;this.isVisible!==r&&(this.isVisible=r,this.device.props.onVisibilityChange(this))}_handleResize(e){if(this.destroyed)return;const t=e.find(e=>e.target===this.canvas);if(!t)return;const r=x(t.contentBoxSize?.[0]);this.cssWidth=r.inlineSize,this.cssHeight=r.blockSize;const i=this.getDevicePixelSize(),s=t.devicePixelContentBoxSize?.[0]?.inlineSize||r.inlineSize*devicePixelRatio,n=t.devicePixelContentBoxSize?.[0]?.blockSize||r.blockSize*devicePixelRatio,[a,o]=this.getMaxDrawingBufferSize();this.devicePixelWidth=Math.max(1,Math.min(s,a)),this.devicePixelHeight=Math.max(1,Math.min(n,o)),this._updateDrawingBufferSize(),this.device.props.onResize(this,{oldPixelSize:i})}_updateDrawingBufferSize(){if(this.props.autoResize)if("number"==typeof this.props.useDevicePixels){const e=this.props.useDevicePixels;this.setDrawingBufferSize(this.cssWidth*e,this.cssHeight*e)}else this.props.useDevicePixels?this.setDrawingBufferSize(this.devicePixelWidth,this.devicePixelHeight):this.setDrawingBufferSize(this.cssWidth,this.cssHeight);this._initializedResolvers.resolve(),this.isInitialized=!0,this.updatePosition()}_resizeDrawingBufferIfNeeded(){if(this._needsDrawingBufferResize){this._needsDrawingBufferResize=!1;(this.drawingBufferWidth!==this.canvas.width||this.drawingBufferHeight!==this.canvas.height)&&(this.canvas.width=this.drawingBufferWidth,this.canvas.height=this.drawingBufferHeight,this._configureDevice())}}_observeDevicePixelRatio(){if(this.destroyed||!this._canvasObserver.started)return;const e=this.devicePixelRatio;this.devicePixelRatio=window.devicePixelRatio,this.updatePosition(),this.device.props.onDevicePixelRatioChange?.(this,{oldRatio:e})}updatePosition(){if(this.destroyed)return;const e=this.htmlCanvas?.getBoundingClientRect();if(e){const t=[e.left,e.top];this._position??=t;if(t[0]!==this._position[0]||t[1]!==this._position[1]){const e=this._position;this._position=t,this.device.props.onPositionChange?.(this,{oldPosition:e})}}}}function S(e,t,r){return Math.min(Math.round(e*t),r-1)}function _(e,t,r,i){return i?Math.max(0,r-1-Math.round(e*t)):Math.min(Math.round(e*t),r-1)}class P extends w{static defaultProps=w.defaultProps}class T extends w{}class A extends s{get[Symbol.toStringTag](){return"TextureView"}constructor(e,t){super(e,t,A.defaultProps)}static defaultProps={...s.defaultProps,format:void 0,dimension:void 0,aspect:"all",baseMipLevel:0,mipLevelCount:void 0,baseArrayLayer:0,arrayLayerCount:void 0}}function B(e,t,r,i){if(i?.inlineSource){const i=function(e,t,r){let i="";for(let s=t-2;s<=t;s++){const n=e[s-1];void 0!==n&&(i+=C(n,t,r))}return i}(t,r);return`\n${i}${e.linePos>0?`${" ".repeat(e.linePos+5)}^^^\n`:""}${e.type.toUpperCase()}: ${e.message}\n\n`}const s="error"===e.type?"red":"orange";return i?.html?`<div class='luma-compiler-log-${e.type}' style="color:${s};"><b> ${e.type.toUpperCase()}: ${e.message}</b></div>`:`${e.type.toUpperCase()}: ${e.message}`}function C(e,t,r){const i=r?.html?e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'"):e;return`${function(e,t){let r="";for(let i=e.length;i<t;++i)r+=" ";return r+e}(String(t),4)}: ${i}${r?.html?"<br/>":"\n"}`}class E extends s{get[Symbol.toStringTag](){return"Shader"}stage;source;compilationStatus="pending";constructor(e,t){super(e,{id:L(t={...t,debugShaders:t.debugShaders||e.props.debugShaders||"errors"}),...t},E.defaultProps),this.stage=this.props.stage,this.source=this.props.source}getCompilationInfoSync(){return null}getTranslatedSource(){return null}async debugShader(){const e=this.props.debugShaders;switch(e){case"never":return;case"errors":if("success"===this.compilationStatus)return}const t=await this.getCompilationInfo();"warnings"===e&&0===t?.length||this._displayShaderLog(t,this.id)}_displayShaderLog(e,t){if("undefined"==typeof document||!document?.createElement)return;const r=t,i=`${this.stage} shader "${r}"`,s=function(e,t,r){let i="";const s=t.split(/\r?\n/),n=e.slice().sort((e,t)=>e.lineNum-t.lineNum);switch(r?.showSourceCode||"no"){case"all":let t=0;for(let e=1;e<=s.length;e++){const a=s[e-1],o=n[t];for(a&&o&&(i+=C(a,e,r));n.length>t&&o.lineNum===e;){const e=n[t++];e&&(i+=B(e,s,e.lineNum,{...r,inlineSource:!1}))}}for(;n.length>t;){const e=n[t++];e&&(i+=B(e,[],0,{...r,inlineSource:!1}))}return i;case"issues":case"no":for(const n of e)i+=B(n,s,n.lineNum,{inlineSource:"no"!==r?.showSourceCode});return i}}(e,this.source,{showSourceCode:"all",html:!0}),n=this.getTranslatedSource(),a=document.createElement("div");a.innerHTML=`<h1>Compilation error in ${i}</h1>\n<div style="display:flex;position:fixed;top:10px;right:20px;gap:2px;">\n<button id="copy">Copy source</button><br/>\n<button id="close">Close</button>\n</div>\n<code><pre>${s}</pre></code>`,n&&(a.innerHTML+=`<br /><h1>Translated Source</h1><br /><br /><code><pre>${n}</pre></code>`),a.style.top="0",a.style.left="0",a.style.background="white",a.style.position="fixed",a.style.zIndex="9999",a.style.maxWidth="100vw",a.style.maxHeight="100vh",a.style.overflowY="auto",document.body.appendChild(a);const o=a.querySelector(".luma-compiler-log-error");o?.scrollIntoView(),a.querySelector("button#close").onclick=()=>{a.remove()},a.querySelector("button#copy").onclick=()=>{navigator.clipboard.writeText(this.source)}}static defaultProps={...s.defaultProps,language:"auto",stage:void 0,source:"",sourceMap:null,entryPoint:"main",debugShaders:void 0}}function L(e){return function(e,t="unnamed"){const r=/#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/.exec(e);return r?.[1]??t}(e.source)||e.id||i(`unnamed ${e.stage}-shader`)}class D extends s{get[Symbol.toStringTag](){return"Framebuffer"}width;height;constructor(e,t={}){super(e,t,D.defaultProps),this.width=this.props.width,this.height=this.props.height}clone(e){const t=this.colorAttachments.map(t=>t.texture.clone(e)),r=this.depthStencilAttachment&&this.depthStencilAttachment.texture.clone(e);return this.device.createFramebuffer({...this.props,...e,colorAttachments:t,depthStencilAttachment:r})}resize(e){let t=!e;if(e){const[r,i]=Array.isArray(e)?e:[e.width,e.height];t=t||i!==this.height||r!==this.width,this.width=r,this.height=i}t&&(n.log(2,`Resizing framebuffer ${this.id} to ${this.width}x${this.height}`)(),this.resizeAttachments(this.width,this.height))}autoCreateAttachmentTextures(){if(0===this.props.colorAttachments.length&&!this.props.depthStencilAttachment)throw new Error("Framebuffer has noattachments");this.colorAttachments=this.props.colorAttachments.map((e,t)=>{if("string"==typeof e){const r=this.createColorTexture(e,t);return this.attachResource(r),r.view}return e instanceof a?e.view:e});const e=this.props.depthStencilAttachment;if(e)if("string"==typeof e){const t=this.createDepthStencilTexture(e);this.attachResource(t),this.depthStencilAttachment=t.view}else this.depthStencilAttachment=e instanceof a?e.view:e}createColorTexture(e,t){return this.device.createTexture({id:`${this.id}-color-attachment-${t}`,usage:a.RENDER_ATTACHMENT,format:e,width:this.width,height:this.height,sampler:{magFilter:"linear",minFilter:"linear"}})}createDepthStencilTexture(e){return this.device.createTexture({id:`${this.id}-depth-stencil-attachment`,usage:a.RENDER_ATTACHMENT,format:e,width:this.width,height:this.height})}resizeAttachments(e,t){if(this.colorAttachments.forEach((r,i)=>{const s=r.texture.clone({width:e,height:t});this.destroyAttachedResource(r),this.colorAttachments[i]=s.view,this.attachResource(s.view)}),this.depthStencilAttachment){const r=this.depthStencilAttachment.texture.clone({width:e,height:t});this.destroyAttachedResource(this.depthStencilAttachment),this.depthStencilAttachment=r.view,this.attachResource(r)}this.updateAttachments()}static defaultProps={...s.defaultProps,width:1,height:1,colorAttachments:[],depthStencilAttachment:null}}class F extends s{get[Symbol.toStringTag](){return"RenderPipeline"}shaderLayout;bufferLayout;linkStatus="pending";hash="";sharedRenderPipeline=null;get isPending(){return"pending"===this.linkStatus||"pending"===this.vs.compilationStatus||"pending"===this.fs?.compilationStatus}get isErrored(){return"error"===this.linkStatus||"error"===this.vs.compilationStatus||"error"===this.fs?.compilationStatus}constructor(e,t){super(e,t,F.defaultProps),this.shaderLayout=this.props.shaderLayout,this.bufferLayout=this.props.bufferLayout||[],this.sharedRenderPipeline=this.props._sharedRenderPipeline||null}static defaultProps={...s.defaultProps,vs:null,vertexEntryPoint:"vertexMain",vsConstants:{},fs:null,fragmentEntryPoint:"fragmentMain",fsConstants:{},shaderLayout:null,bufferLayout:[],topology:"triangle-list",colorAttachmentFormats:void 0,depthStencilAttachmentFormat:void 0,parameters:{},varyings:void 0,bufferMode:void 0,disableWarnings:!1,_sharedRenderPipeline:void 0,bindings:void 0,bindGroups:void 0}}class k extends s{get[Symbol.toStringTag](){return"SharedRenderPipeline"}constructor(e,t){super(e,t,{...s.defaultProps,handle:void 0,vs:void 0,fs:void 0,varyings:void 0,bufferMode:void 0})}}function R(e,t,r){const i=e.bindings.find(e=>e.name===t||`${e.name.toLocaleLowerCase()}uniforms`===t.toLocaleLowerCase());return i||n.warn(`Binding ${t} not set: Not found in shader layout.`)(),i||null}function M(e,t){if(!t)return{};if(function(e){const t=Object.keys(e);return t.length>0&&t.every(e=>/^\d+$/.test(e))}(t)){const e=t;return Object.fromEntries(Object.entries(e).map(([e,t])=>[Number(e),{...t}]))}const r={};for(const[i,s]of Object.entries(t)){const t=R(e,i),n=t?.group??0;r[n]||={},r[n][i]=s}return r}function O(e){const t={};for(const r of Object.values(e))Object.assign(t,r);return t}class I extends s{static defaultClearColor=[0,0,0,1];static defaultClearDepth=1;static defaultClearStencil=0;get[Symbol.toStringTag](){return"RenderPass"}constructor(e,t){super(e,t=I.normalizeProps(e,t),I.defaultProps)}static normalizeProps(e,t){return t}static defaultProps={...s.defaultProps,framebuffer:null,parameters:void 0,clearColor:I.defaultClearColor,clearColors:void 0,clearDepth:I.defaultClearDepth,clearStencil:I.defaultClearStencil,depthReadOnly:!1,stencilReadOnly:!1,discard:!1,occlusionQuerySet:void 0,timestampQuerySet:void 0,beginTimestampIndex:void 0,endTimestampIndex:void 0}}class $ extends s{get[Symbol.toStringTag](){return"CommandEncoder"}_timeProfilingQuerySet=null;_timeProfilingSlotCount=0;_gpuTimeMs;constructor(e,t){super(e,t,$.defaultProps),this._timeProfilingQuerySet=t.timeProfilingQuerySet??null,this._timeProfilingSlotCount=0,this._gpuTimeMs=void 0}async resolveTimeProfilingQuerySet(){if(this._gpuTimeMs=void 0,!this._timeProfilingQuerySet)return;const e=Math.floor(this._timeProfilingSlotCount/2);if(e<=0)return;const t=2*e,r=await this._timeProfilingQuerySet.readResults({firstQuery:0,queryCount:t});let i=0n;for(let s=0;s<t;s+=2)i+=r[s+1]-r[s];this._gpuTimeMs=Number(i)/1e6}getTimeProfilingSlotCount(){return this._timeProfilingSlotCount}getTimeProfilingQuerySet(){return this._timeProfilingQuerySet}_applyTimeProfilingToPassProps(e){const t=e||{};if(!this._supportsTimestampQueries()||!this._timeProfilingQuerySet)return t;if(void 0!==t.timestampQuerySet||void 0!==t.beginTimestampIndex||void 0!==t.endTimestampIndex)return t;const r=this._timeProfilingSlotCount;return r+1>=this._timeProfilingQuerySet.props.count?t:(this._timeProfilingSlotCount+=2,{...t,timestampQuerySet:this._timeProfilingQuerySet,beginTimestampIndex:r,endTimestampIndex:r+1})}_supportsTimestampQueries(){return this.device.features.has("timestamp-query")}static defaultProps={...s.defaultProps,measureExecutionTime:void 0,timeProfilingQuerySet:void 0}}class W extends s{get[Symbol.toStringTag](){return"CommandBuffer"}constructor(e,t){super(e,t,W.defaultProps)}static defaultProps={...s.defaultProps}}function z(e){const t=Q(e),r=j[t];if(!r)throw new Error(`Unsupported variable shader type: ${e}`);return r}function G(e){return q[e]||e}function Q(e){return H[e]||e}const N=new class{getVariableShaderTypeInfo(e){return z(e)}getAttributeShaderTypeInfo(e){return function(e){const t=G(e),r=V[t];if(!r)throw new Error(`Unsupported attribute shader type: ${e}`);const[i,s]=r,n="i32"===i||"u32"===i,a="u32"!==i;return{primitiveType:i,components:s,byteLength:U[i]*s,integer:n,signed:a}}(e)}makeShaderAttributeType(e,t){return function(e,t){return 1===t?e:`vec${t}<${e}>`}(e,t)}resolveAttributeShaderTypeAlias(e){return G(e)}resolveVariableShaderTypeAlias(e){return Q(e)}},U={f32:4,f16:2,i32:4,u32:4},V={f32:["f32",1],"vec2<f32>":["f32",2],"vec3<f32>":["f32",3],"vec4<f32>":["f32",4],f16:["f16",1],"vec2<f16>":["f16",2],"vec3<f16>":["f16",3],"vec4<f16>":["f16",4],i32:["i32",1],"vec2<i32>":["i32",2],"vec3<i32>":["i32",3],"vec4<i32>":["i32",4],u32:["u32",1],"vec2<u32>":["u32",2],"vec3<u32>":["u32",3],"vec4<u32>":["u32",4]},j={f32:{type:"f32",components:1},f16:{type:"f16",components:1},i32:{type:"i32",components:1},u32:{type:"u32",components:1},"vec2<f32>":{type:"f32",components:2},"vec3<f32>":{type:"f32",components:3},"vec4<f32>":{type:"f32",components:4},"vec2<f16>":{type:"f16",components:2},"vec3<f16>":{type:"f16",components:3},"vec4<f16>":{type:"f16",components:4},"vec2<i32>":{type:"i32",components:2},"vec3<i32>":{type:"i32",components:3},"vec4<i32>":{type:"i32",components:4},"vec2<u32>":{type:"u32",components:2},"vec3<u32>":{type:"u32",components:3},"vec4<u32>":{type:"u32",components:4},"mat2x2<f32>":{type:"f32",components:4},"mat2x3<f32>":{type:"f32",components:6},"mat2x4<f32>":{type:"f32",components:8},"mat3x2<f32>":{type:"f32",components:6},"mat3x3<f32>":{type:"f32",components:9},"mat3x4<f32>":{type:"f32",components:12},"mat4x2<f32>":{type:"f32",components:8},"mat4x3<f32>":{type:"f32",components:12},"mat4x4<f32>":{type:"f32",components:16},"mat2x2<f16>":{type:"f16",components:4},"mat2x3<f16>":{type:"f16",components:6},"mat2x4<f16>":{type:"f16",components:8},"mat3x2<f16>":{type:"f16",components:6},"mat3x3<f16>":{type:"f16",components:9},"mat3x4<f16>":{type:"f16",components:12},"mat4x2<f16>":{type:"f16",components:8},"mat4x3<f16>":{type:"f16",components:12},"mat4x4<f16>":{type:"f16",components:16},"mat2x2<i32>":{type:"i32",components:4},"mat2x3<i32>":{type:"i32",components:6},"mat2x4<i32>":{type:"i32",components:8},"mat3x2<i32>":{type:"i32",components:6},"mat3x3<i32>":{type:"i32",components:9},"mat3x4<i32>":{type:"i32",components:12},"mat4x2<i32>":{type:"i32",components:8},"mat4x3<i32>":{type:"i32",components:12},"mat4x4<i32>":{type:"i32",components:16},"mat2x2<u32>":{type:"u32",components:4},"mat2x3<u32>":{type:"u32",components:6},"mat2x4<u32>":{type:"u32",components:8},"mat3x2<u32>":{type:"u32",components:6},"mat3x3<u32>":{type:"u32",components:9},"mat3x4<u32>":{type:"u32",components:12},"mat4x2<u32>":{type:"u32",components:8},"mat4x3<u32>":{type:"u32",components:12},"mat4x4<u32>":{type:"u32",components:16}},q={vec2i:"vec2<i32>",vec3i:"vec3<i32>",vec4i:"vec4<i32>",vec2u:"vec2<u32>",vec3u:"vec3<u32>",vec4u:"vec4<u32>",vec2f:"vec2<f32>",vec3f:"vec3<f32>",vec4f:"vec4<f32>",vec2h:"vec2<f16>",vec3h:"vec3<f16>",vec4h:"vec4<f16>"},H={vec2i:"vec2<i32>",vec3i:"vec3<i32>",vec4i:"vec4<i32>",vec2u:"vec2<u32>",vec3u:"vec3<u32>",vec4u:"vec4<u32>",vec2f:"vec2<f32>",vec3f:"vec3<f32>",vec4f:"vec4<f32>",vec2h:"vec2<f16>",vec3h:"vec3<f16>",vec4h:"vec4<f16>",mat2x2f:"mat2x2<f32>",mat2x3f:"mat2x3<f32>",mat2x4f:"mat2x4<f32>",mat3x2f:"mat3x2<f32>",mat3x3f:"mat3x3<f32>",mat3x4f:"mat3x4<f32>",mat4x2f:"mat4x2<f32>",mat4x3f:"mat4x3<f32>",mat4x4f:"mat4x4<f32>",mat2x2i:"mat2x2<i32>",mat2x3i:"mat2x3<i32>",mat2x4i:"mat2x4<i32>",mat3x2i:"mat3x2<i32>",mat3x3i:"mat3x3<i32>",mat3x4i:"mat3x4<i32>",mat4x2i:"mat4x2<i32>",mat4x3i:"mat4x3<i32>",mat4x4i:"mat4x4<i32>",mat2x2u:"mat2x2<u32>",mat2x3u:"mat2x3<u32>",mat2x4u:"mat2x4<u32>",mat3x2u:"mat3x2<u32>",mat3x3u:"mat3x3<u32>",mat3x4u:"mat3x4<u32>",mat4x2u:"mat4x2<u32>",mat4x3u:"mat4x3<u32>",mat4x4u:"mat4x4<u32>",mat2x2h:"mat2x2<f16>",mat2x3h:"mat2x3<f16>",mat2x4h:"mat2x4<f16>",mat3x2h:"mat3x2<f16>",mat3x3h:"mat3x3<f16>",mat3x4h:"mat3x4<f16>",mat4x2h:"mat4x2<f16>",mat4x3h:"mat4x3<f16>",mat4x4h:"mat4x4<f16>"};function X(e,t){const r={};for(const i of e.attributes){const s=Y(e,t,i.name);s&&(r[i.name]=s)}return r}function Y(e,t,r){const i=function(e,t){const r=e.attributes.find(e=>e.name===t);r||n.warn(`shader layout attribute "${t}" not present in shader`);return r||null}(e,r),s=function(e,t){!function(e){for(const t of e)(t.attributes&&t.format||!t.attributes&&!t.format)&&n.warn(`BufferLayout ${name} must have either 'attributes' or 'format' field`)}(e);let r=function(e,t){for(const r of e)if(r.format&&r.name===t)return{attributeName:r.name,bufferName:t,stepMode:r.stepMode,vertexFormat:r.format,byteOffset:0,byteStride:r.byteStride||0};return null}(e,t);if(r)return r;if(r=function(e,t){for(const r of e){let e=r.byteStride;if("number"!=typeof r.byteStride)for(const t of r.attributes||[]){e+=o.getVertexFormatInfo(t.format).byteLength}const i=r.attributes?.find(e=>e.attribute===t);if(i)return{attributeName:i.attribute,bufferName:r.name,stepMode:r.stepMode,vertexFormat:i.format,byteOffset:i.byteOffset,byteStride:e}}return null}(e,t),r)return r;return n.warn(`layout for attribute "${t}" not present in buffer layout`),null}(t,r);if(!i)return null;const a=N.getAttributeShaderTypeInfo(i.type),c=o.getCompatibleVertexFormat(a),l=s?.vertexFormat||c,u=o.getVertexFormatInfo(l);return{attributeName:s?.attributeName||i.name,bufferName:s?.bufferName||i.name,location:i.location,shaderType:i.type,primitiveType:a.primitiveType,shaderComponents:a.components,vertexFormat:l,bufferDataType:u.type,bufferComponents:u.components,normalized:u.normalized,integer:a.integer,stepMode:s?.stepMode||i.stepMode||"vertex",byteOffset:s?.byteOffset||0,byteStride:s?.byteStride||0}}class K extends s{static defaultProps={...s.defaultProps,shaderLayout:void 0,bufferLayout:[]};get[Symbol.toStringTag](){return"VertexArray"}maxVertexAttributes;attributeInfos;indexBuffer=null;attributes;constructor(e,t){super(e,t,K.defaultProps),this.maxVertexAttributes=e.limits.maxVertexAttributes,this.attributes=new Array(this.maxVertexAttributes).fill(null),this.attributeInfos=function(e,t,r=16){const i=X(e,t),s=new Array(r).fill(null);for(const n of Object.values(i))s[n.location]=n;return s}(t.shaderLayout,t.bufferLayout,this.maxVertexAttributes)}setConstantWebGL(e,t){this.device.reportError(new Error("constant attributes not supported"),this)()}}class Z extends s{static defaultProps={...s.defaultProps,layout:void 0,buffers:{}};get[Symbol.toStringTag](){return"TransformFeedback"}constructor(e,t){super(e,t,Z.defaultProps)}}class J extends s{get[Symbol.toStringTag](){return"QuerySet"}constructor(e,t){super(e,t,J.defaultProps)}static defaultProps={...s.defaultProps,type:void 0,count:void 0}}class ee extends s{static defaultProps={...s.defaultProps};get[Symbol.toStringTag](){return"Fence"}constructor(e,t={}){super(e,t,ee.defaultProps)}}function te(e,t){switch(t){case 1:return e;case 2:return e+e%2;default:return e+(4-e%4)%4}}function re(e){const[,,,,t]=ie[e];return t}const ie={uint8:["uint8","u32",1,!1,Uint8Array],sint8:["sint8","i32",1,!1,Int8Array],unorm8:["uint8","f32",1,!0,Uint8Array],snorm8:["sint8","f32",1,!0,Int8Array],uint16:["uint16","u32",2,!1,Uint16Array],sint16:["sint16","i32",2,!1,Int16Array],unorm16:["uint16","u32",2,!0,Uint16Array],snorm16:["sint16","i32",2,!0,Int16Array],float16:["float16","f16",2,!1,Uint16Array],float32:["float32","f32",4,!1,Float32Array],uint32:["uint32","u32",4,!1,Uint32Array],sint32:["sint32","i32",4,!1,Int32Array]};let se;function ne(e){return(!se||se.byteLength<e)&&(se=new ArrayBuffer(e)),se}const ae={3042:!1,32773:new Float32Array([0,0,0,0]),32777:32774,34877:32774,32969:1,32968:0,32971:1,32970:0,3106:new Float32Array([0,0,0,0]),3107:[!0,!0,!0,!0],2884:!1,2885:1029,2929:!1,2931:1,2932:513,2928:new Float32Array([0,1]),2930:!0,3024:!0,35725:null,36006:null,36007:null,34229:null,34964:null,2886:2305,33170:4352,2849:1,32823:!1,32824:0,10752:0,32926:!1,32928:!1,32938:1,32939:!1,3089:!1,3088:new Int32Array([0,0,1024,1024]),2960:!1,2961:0,2968:4294967295,36005:4294967295,2962:519,2967:0,2963:4294967295,34816:519,36003:0,36004:4294967295,2964:7680,2965:7680,2966:7680,34817:7680,34818:7680,34819:7680,2978:[0,0,1024,1024],36389:null,36662:null,36663:null,35053:null,35055:null,35723:4352,36010:null,35977:!1,3333:4,3317:4,37440:!1,37441:!1,37443:37444,3330:0,3332:0,3331:0,3314:0,32878:0,3316:0,3315:0,32877:0},oe=(e,t,r)=>t?e.enable(r):e.disable(r),ce=(e,t,r)=>e.hint(r,t),le=(e,t,r)=>e.pixelStorei(r,t),ue=(e,t,r)=>{const i=36006===r?36009:36008;return e.bindFramebuffer(i,t)},he=(e,t,r)=>{const i={34964:34962,36662:36662,36663:36663,35053:35051,35055:35052}[r];e.bindBuffer(i,t)};function de(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}const fe={3042:oe,32773:(e,t)=>e.blendColor(...t),32777:"blendEquation",34877:"blendEquation",32969:"blendFunc",32968:"blendFunc",32971:"blendFunc",32970:"blendFunc",3106:(e,t)=>e.clearColor(...t),3107:(e,t)=>e.colorMask(...t),2884:oe,2885:(e,t)=>e.cullFace(t),2929:oe,2931:(e,t)=>e.clearDepth(t),2932:(e,t)=>e.depthFunc(t),2928:(e,t)=>e.depthRange(...t),2930:(e,t)=>e.depthMask(t),3024:oe,35723:ce,35725:(e,t)=>e.useProgram(t),36007:(e,t)=>e.bindRenderbuffer(36161,t),36389:(e,t)=>e.bindTransformFeedback?.(36386,t),34229:(e,t)=>e.bindVertexArray(t),36006:ue,36010:ue,34964:he,36662:he,36663:he,35053:he,35055:he,2886:(e,t)=>e.frontFace(t),33170:ce,2849:(e,t)=>e.lineWidth(t),32823:oe,32824:"polygonOffset",10752:"polygonOffset",35977:oe,32926:oe,32928:oe,32938:"sampleCoverage",32939:"sampleCoverage",3089:oe,3088:(e,t)=>e.scissor(...t),2960:oe,2961:(e,t)=>e.clearStencil(t),2968:(e,t)=>e.stencilMaskSeparate(1028,t),36005:(e,t)=>e.stencilMaskSeparate(1029,t),2962:"stencilFuncFront",2967:"stencilFuncFront",2963:"stencilFuncFront",34816:"stencilFuncBack",36003:"stencilFuncBack",36004:"stencilFuncBack",2964:"stencilOpFront",2965:"stencilOpFront",2966:"stencilOpFront",34817:"stencilOpBack",34818:"stencilOpBack",34819:"stencilOpBack",2978:(e,t)=>e.viewport(...t),34383:oe,10754:oe,12288:oe,12289:oe,12290:oe,12291:oe,12292:oe,12293:oe,12294:oe,12295:oe,3333:le,3317:le,37440:le,37441:le,37443:le,3330:le,3332:le,3331:le,3314:le,32878:le,3316:le,3315:le,32877:le,framebuffer:(e,t)=>{const r=t&&"handle"in t?t.handle:t;return e.bindFramebuffer(36160,r)},blend:(e,t)=>t?e.enable(3042):e.disable(3042),blendColor:(e,t)=>e.blendColor(...t),blendEquation:(e,t)=>{const r="number"==typeof t?[t,t]:t;e.blendEquationSeparate(...r)},blendFunc:(e,t)=>{const r=2===t?.length?[...t,...t]:t;e.blendFuncSeparate(...r)},clearColor:(e,t)=>e.clearColor(...t),clearDepth:(e,t)=>e.clearDepth(t),clearStencil:(e,t)=>e.clearStencil(t),colorMask:(e,t)=>e.colorMask(...t),cull:(e,t)=>t?e.enable(2884):e.disable(2884),cullFace:(e,t)=>e.cullFace(t),depthTest:(e,t)=>t?e.enable(2929):e.disable(2929),depthFunc:(e,t)=>e.depthFunc(t),depthMask:(e,t)=>e.depthMask(t),depthRange:(e,t)=>e.depthRange(...t),dither:(e,t)=>t?e.enable(3024):e.disable(3024),derivativeHint:(e,t)=>{e.hint(35723,t)},frontFace:(e,t)=>e.frontFace(t),mipmapHint:(e,t)=>e.hint(33170,t),lineWidth:(e,t)=>e.lineWidth(t),polygonOffsetFill:(e,t)=>t?e.enable(32823):e.disable(32823),polygonOffset:(e,t)=>e.polygonOffset(...t),sampleCoverage:(e,t)=>e.sampleCoverage(t[0],t[1]||!1),scissorTest:(e,t)=>t?e.enable(3089):e.disable(3089),scissor:(e,t)=>e.scissor(...t),stencilTest:(e,t)=>t?e.enable(2960):e.disable(2960),stencilMask:(e,t)=>{t=de(t)?t:[t,t];const[r,i]=t;e.stencilMaskSeparate(1028,r),e.stencilMaskSeparate(1029,i)},stencilFunc:(e,t)=>{t=de(t)&&3===t.length?[...t,...t]:t;const[r,i,s,n,a,o]=t;e.stencilFuncSeparate(1028,r,i,s),e.stencilFuncSeparate(1029,n,a,o)},stencilOp:(e,t)=>{t=de(t)&&3===t.length?[...t,...t]:t;const[r,i,s,n,a,o]=t;e.stencilOpSeparate(1028,r,i,s),e.stencilOpSeparate(1029,n,a,o)},viewport:(e,t)=>e.viewport(...t)};function me(e,t,r){return void 0!==t[e]?t[e]:r[e]}const ge={blendEquation:(e,t,r)=>e.blendEquationSeparate(me(32777,t,r),me(34877,t,r)),blendFunc:(e,t,r)=>e.blendFuncSeparate(me(32969,t,r),me(32968,t,r),me(32971,t,r),me(32970,t,r)),polygonOffset:(e,t,r)=>e.polygonOffset(me(32824,t,r),me(10752,t,r)),sampleCoverage:(e,t,r)=>e.sampleCoverage(me(32938,t,r),me(32939,t,r)),stencilFuncFront:(e,t,r)=>e.stencilFuncSeparate(1028,me(2962,t,r),me(2967,t,r),me(2963,t,r)),stencilFuncBack:(e,t,r)=>e.stencilFuncSeparate(1029,me(34816,t,r),me(36003,t,r),me(36004,t,r)),stencilOpFront:(e,t,r)=>e.stencilOpSeparate(1028,me(2964,t,r),me(2965,t,r),me(2966,t,r)),stencilOpBack:(e,t,r)=>e.stencilOpSeparate(1029,me(34817,t,r),me(34818,t,r),me(34819,t,r))},pe={enable:(e,t)=>e({[t]:!0}),disable:(e,t)=>e({[t]:!1}),pixelStorei:(e,t,r)=>e({[t]:r}),hint:(e,t,r)=>e({[t]:r}),useProgram:(e,t)=>e({35725:t}),bindRenderbuffer:(e,t,r)=>e({36007:r}),bindTransformFeedback:(e,t,r)=>e({36389:r}),bindVertexArray:(e,t)=>e({34229:t}),bindFramebuffer:(e,t,r)=>{switch(t){case 36160:return e({36006:r,36010:r});case 36009:return e({36006:r});case 36008:return e({36010:r});default:return null}},bindBuffer:(e,t,r)=>{const i={34962:[34964],36662:[36662],36663:[36663],35051:[35053],35052:[35055]}[t];return i?e({[i]:r}):{valueChanged:!0}},blendColor:(e,t,r,i,s)=>e({32773:new Float32Array([t,r,i,s])}),blendEquation:(e,t)=>e({32777:t,34877:t}),blendEquationSeparate:(e,t,r)=>e({32777:t,34877:r}),blendFunc:(e,t,r)=>e({32969:t,32968:r,32971:t,32970:r}),blendFuncSeparate:(e,t,r,i,s)=>e({32969:t,32968:r,32971:i,32970:s}),clearColor:(e,t,r,i,s)=>e({3106:new Float32Array([t,r,i,s])}),clearDepth:(e,t)=>e({2931:t}),clearStencil:(e,t)=>e({2961:t}),colorMask:(e,t,r,i,s)=>e({3107:[t,r,i,s]}),cullFace:(e,t)=>e({2885:t}),depthFunc:(e,t)=>e({2932:t}),depthRange:(e,t,r)=>e({2928:new Float32Array([t,r])}),depthMask:(e,t)=>e({2930:t}),frontFace:(e,t)=>e({2886:t}),lineWidth:(e,t)=>e({2849:t}),polygonOffset:(e,t,r)=>e({32824:t,10752:r}),sampleCoverage:(e,t,r)=>e({32938:t,32939:r}),scissor:(e,t,r,i,s)=>e({3088:new Int32Array([t,r,i,s])}),stencilMask:(e,t)=>e({2968:t,36005:t}),stencilMaskSeparate:(e,t,r)=>e({[1028===t?2968:36005]:r}),stencilFunc:(e,t,r,i)=>e({2962:t,2967:r,2963:i,34816:t,36003:r,36004:i}),stencilFuncSeparate:(e,t,r,i,s)=>e({[1028===t?2962:34816]:r,[1028===t?2967:36003]:i,[1028===t?2963:36004]:s}),stencilOp:(e,t,r,i)=>e({2964:t,2965:r,2966:i,34817:t,34818:r,34819:i}),stencilOpSeparate:(e,t,r,i,s)=>e({[1028===t?2964:34817]:r,[1028===t?2965:34818]:i,[1028===t?2966:34819]:s}),viewport:(e,t,r,i,s)=>e({2978:[t,r,i,s]})},be=(e,t)=>e.isEnabled(t),ye={3042:be,2884:be,2929:be,3024:be,32823:be,32926:be,32928:be,3089:be,2960:be,35977:be},ve=/* @__PURE__ */new Set([34016,36388,36387,35983,35368,34965,35739,35738,3074,34853,34854,34855,34856,34857,34858,34859,34860,34861,34862,34863,34864,34865,34866,34867,34868,35097,32873,35869,32874,34068]);function xe(e,t){if(function(e){for(const t in e)return!1;return!0}(t))return;const r={};for(const s in t){const i=Number(s),n=fe[s];n&&("string"==typeof n?r[n]=!0:n(e,t[s],i))}const i=e.lumaState?.cache;if(i)for(const s in r){(0,ge[s])(e,t,i)}}function we(e,t=ae){if("number"==typeof t){const r=t,i=ye[r];return i?i(e,r):e.getParameter(r)}const r=Array.isArray(t)?t:Object.keys(t),i={};for(const s of r){const t=ye[s];i[s]=t?t(e,Number(s)):e.getParameter(Number(s))}return i}function Se(e,t){if(e===t)return!0;if(_e(e)&&_e(t)&&e.length===t.length){for(let r=0;r<e.length;++r)if(e[r]!==t[r])return!1;return!0}return!1}function _e(e){return Array.isArray(e)||ArrayBuffer.isView(e)}class Pe{static get(e){return e.lumaState}gl;program=null;stateStack=[];enable=!0;cache=null;log;initialized=!1;constructor(e,t){this.gl=e,this.log=t?.log||(()=>{}),this._updateCache=this._updateCache.bind(this),Object.seal(this)}push(e={}){this.stateStack.push({})}pop(){const e=this.stateStack[this.stateStack.length-1];xe(this.gl,e),this.stateStack.pop()}trackState(e,t){if(this.cache=t?.copyState?we(e):Object.assign({},ae),this.initialized)throw new Error("WebGLStateTracker");this.initialized=!0,this.gl.lumaState=this,function(e){const t=e.useProgram.bind(e);e.useProgram=function(r){const i=Pe.get(e);i.program!==r&&(t(r),i.program=r)}}(e);for(const r in pe){Ae(e,r,pe[r])}Te(e,"getParameter"),Te(e,"isEnabled")}_updateCache(e){let t,r=!1;const i=this.stateStack.length>0?this.stateStack[this.stateStack.length-1]:null;for(const s in e){const n=e[s],a=this.cache[s];Se(n,a)||(r=!0,t=a,i&&!(s in i)&&(i[s]=a),this.cache[s]=n)}return{valueChanged:r,oldValue:t}}}function Te(e,t){const r=e[t].bind(e);e[t]=function(t){if(void 0===t||ve.has(t))return r(t);const i=Pe.get(e);return t in i.cache||(i.cache[t]=r(t)),i.enable?i.cache[t]:r(t)},Object.defineProperty(e[t],"name",{value:`${t}-from-cache`,configurable:!1})}function Ae(e,t,r){if(!e[t])return;const i=e[t].bind(e);e[t]=function(...t){const s=Pe.get(e),{valueChanged:n,oldValue:a}=r(s._updateCache,...t);return n&&i(...t),a},Object.defineProperty(e[t],"name",{value:`${t}-to-cache`,configurable:!1})}function Be(e,t,r){return void 0===r[t]&&(r[t]=e.getExtension(t)||null),r[t]}function Ce(e,t){const r=e.getParameter(7936),i=e.getParameter(7937);Be(e,"WEBGL_debug_renderer_info",t);const s=t.WEBGL_debug_renderer_info,n=e.getParameter(s?s.UNMASKED_VENDOR_WEBGL:7936)||r,a=e.getParameter(s?s.UNMASKED_RENDERER_WEBGL:7937)||i,o=e.getParameter(7938),c=Ee(n,a),l=function(e,t){if(/Metal/i.exec(e)||/Metal/i.exec(t))return"metal";if(/ANGLE/i.exec(e)||/ANGLE/i.exec(t))return"opengl";return"unknown"}(n,a),u=function(e,t){if(/SwiftShader/i.exec(e)||/SwiftShader/i.exec(t))return"cpu";switch(Ee(e,t)){case"apple":return function(e,t){return/Apple (M\d|A\d|GPU)/i.test(`${e} ${t}`)}(e,t)?"integrated":"unknown";case"intel":return"integrated";case"software":return"cpu";case"unknown":return"unknown";default:return"discrete"}}(n,a);return{type:"webgl",gpu:c,gpuType:u,gpuBackend:l,vendor:n,renderer:a,version:o,shadingLanguage:"glsl",shadingLanguageVersion:300}}function Ee(e,t){return/NVIDIA/i.exec(e)||/NVIDIA/i.exec(t)?"nvidia":/INTEL/i.exec(e)||/INTEL/i.exec(t)?"intel":/Apple/i.exec(e)||/Apple/i.exec(t)?"apple":/AMD/i.exec(e)||/AMD/i.exec(t)||/ATI/i.exec(e)||/ATI/i.exec(t)?"amd":/SwiftShader/i.exec(e)||/SwiftShader/i.exec(t)?"software":"unknown"}function Le(e){switch(e){case"uint8":case"unorm8":return 5121;case"sint8":case"snorm8":return 5120;case"uint16":case"unorm16":return 5123;case"sint16":case"snorm16":return 5122;case"uint32":return 5125;case"sint32":return 5124;case"float16":return 5131;case"float32":return 5126}throw new Error(String(e))}const De="WEBGL_compressed_texture_s3tc",Fe="WEBGL_compressed_texture_s3tc_srgb",ke="EXT_texture_compression_rgtc",Re="EXT_texture_compression_bptc",Me="EXT_render_snorm",Oe="EXT_color_buffer_float",Ie="snorm8-renderable-webgl",$e="norm16-renderable-webgl",We="snorm16-renderable-webgl",ze="float16-renderable-webgl",Ge="float32-renderable-webgl",Qe={"float32-renderable-webgl":{extensions:[Oe]},"float16-renderable-webgl":{extensions:["EXT_color_buffer_half_float"]},"rgb9e5ufloat-renderable-webgl":{extensions:["WEBGL_render_shared_exponent"]},"snorm8-renderable-webgl":{extensions:[Me]},"norm16-webgl":{extensions:["EXT_texture_norm16"]},"norm16-renderable-webgl":{features:["norm16-webgl"]},"snorm16-renderable-webgl":{features:["norm16-webgl"],extensions:[Me]},"float32-filterable":{extensions:["OES_texture_float_linear"]},"float16-filterable-webgl":{extensions:["OES_texture_half_float_linear"]},"texture-filterable-anisotropic-webgl":{extensions:["EXT_texture_filter_anisotropic"]},"texture-blend-float-webgl":{extensions:["EXT_float_blend"]},"texture-compression-bc":{extensions:[De,Fe,ke,Re]},"texture-compression-bc5-webgl":{extensions:[ke]},"texture-compression-bc7-webgl":{extensions:[Re]},"texture-compression-etc2":{extensions:["WEBGL_compressed_texture_etc"]},"texture-compression-astc":{extensions:["WEBGL_compressed_texture_astc"]},"texture-compression-etc1-webgl":{extensions:["WEBGL_compressed_texture_etc1"]},"texture-compression-pvrtc-webgl":{extensions:["WEBGL_compressed_texture_pvrtc"]},"texture-compression-atc-webgl":{extensions:["WEBGL_compressed_texture_atc"]}};function Ne(e,t,r){return Ue(e,t,r,/* @__PURE__ */new Set)}function Ue(e,t,r,i){const s=Qe[t];if(!s)return!1;if(i.has(t))return!1;i.add(t);const n=(s.features||[]).every(t=>Ue(e,t,r,i));return i.delete(t),!!n&&(s.extensions||[]).every(t=>Boolean(Be(e,t,r)))}const Ve={r8unorm:{gl:33321,rb:!0},r8snorm:{gl:36756,r:Ie},r8uint:{gl:33330,rb:!0},r8sint:{gl:33329,rb:!0},rg8unorm:{gl:33323,rb:!0},rg8snorm:{gl:36757,r:Ie},rg8uint:{gl:33336,rb:!0},rg8sint:{gl:33335,rb:!0},r16uint:{gl:33332,rb:!0},r16sint:{gl:33331,rb:!0},r16float:{gl:33325,rb:!0,r:ze},r16unorm:{gl:33322,rb:!0,r:$e},r16snorm:{gl:36760,r:We},"rgba4unorm-webgl":{gl:32854,rb:!0},"rgb565unorm-webgl":{gl:36194,rb:!0},"rgb5a1unorm-webgl":{gl:32855,rb:!0},"rgb8unorm-webgl":{gl:32849},"rgb8snorm-webgl":{gl:36758},rgba8unorm:{gl:32856},"rgba8unorm-srgb":{gl:35907},rgba8snorm:{gl:36759,r:Ie},rgba8uint:{gl:36220},rgba8sint:{gl:36238},bgra8unorm:{},"bgra8unorm-srgb":{},rg16uint:{gl:33338},rg16sint:{gl:33337},rg16float:{gl:33327,rb:!0,r:ze},rg16unorm:{gl:33324,r:$e},rg16snorm:{gl:36761,r:We},r32uint:{gl:33334,rb:!0},r32sint:{gl:33333,rb:!0},r32float:{gl:33326,r:Ge},rgb9e5ufloat:{gl:35901,r:"rgb9e5ufloat-renderable-webgl"},rg11b10ufloat:{gl:35898,rb:!0},rgb10a2unorm:{gl:32857,rb:!0},rgb10a2uint:{gl:36975,rb:!0},"rgb16unorm-webgl":{gl:32852,r:!1},"rgb16snorm-webgl":{gl:36762,r:!1},rg32uint:{gl:33340,rb:!0},rg32sint:{gl:33339,rb:!0},rg32float:{gl:33328,rb:!0,r:Ge},rgba16uint:{gl:36214,rb:!0},rgba16sint:{gl:36232,rb:!0},rgba16float:{gl:34842,r:ze},rgba16unorm:{gl:32859,rb:!0,r:$e},rgba16snorm:{gl:36763,r:We},"rgb32float-webgl":{gl:34837,x:Oe,r:Ge,dataFormat:6407,types:[5126]},rgba32uint:{gl:36208,rb:!0},rgba32sint:{gl:36226,rb:!0},rgba32float:{gl:34836,rb:!0,r:Ge},stencil8:{gl:36168,rb:!0},depth16unorm:{gl:33189,dataFormat:6402,types:[5123],rb:!0},depth24plus:{gl:33190,dataFormat:6402,types:[5125]},depth32float:{gl:36012,dataFormat:6402,types:[5126],rb:!0},"depth24plus-stencil8":{gl:35056,rb:!0,depthTexture:!0,dataFormat:34041,types:[34042]},"depth32float-stencil8":{gl:36013,dataFormat:34041,types:[36269],rb:!0},"bc1-rgb-unorm-webgl":{gl:33776,x:De},"bc1-rgb-unorm-srgb-webgl":{gl:35916,x:Fe},"bc1-rgba-unorm":{gl:33777,x:De},"bc1-rgba-unorm-srgb":{gl:35916,x:Fe},"bc2-rgba-unorm":{gl:33778,x:De},"bc2-rgba-unorm-srgb":{gl:35918,x:Fe},"bc3-rgba-unorm":{gl:33779,x:De},"bc3-rgba-unorm-srgb":{gl:35919,x:Fe},"bc4-r-unorm":{gl:36283,x:ke},"bc4-r-snorm":{gl:36284,x:ke},"bc5-rg-unorm":{gl:36285,x:ke},"bc5-rg-snorm":{gl:36286,x:ke},"bc6h-rgb-ufloat":{gl:36495,x:Re},"bc6h-rgb-float":{gl:36494,x:Re},"bc7-rgba-unorm":{gl:36492,x:Re},"bc7-rgba-unorm-srgb":{gl:36493,x:Re},"etc2-rgb8unorm":{gl:37492},"etc2-rgb8unorm-srgb":{gl:37494},"etc2-rgb8a1unorm":{gl:37496},"etc2-rgb8a1unorm-srgb":{gl:37497},"etc2-rgba8unorm":{gl:37493},"etc2-rgba8unorm-srgb":{gl:37495},"eac-r11unorm":{gl:37488},"eac-r11snorm":{gl:37489},"eac-rg11unorm":{gl:37490},"eac-rg11snorm":{gl:37491},"astc-4x4-unorm":{gl:37808},"astc-4x4-unorm-srgb":{gl:37840},"astc-5x4-unorm":{gl:37809},"astc-5x4-unorm-srgb":{gl:37841},"astc-5x5-unorm":{gl:37810},"astc-5x5-unorm-srgb":{gl:37842},"astc-6x5-unorm":{gl:37811},"astc-6x5-unorm-srgb":{gl:37843},"astc-6x6-unorm":{gl:37812},"astc-6x6-unorm-srgb":{gl:37844},"astc-8x5-unorm":{gl:37813},"astc-8x5-unorm-srgb":{gl:37845},"astc-8x6-unorm":{gl:37814},"astc-8x6-unorm-srgb":{gl:37846},"astc-8x8-unorm":{gl:37815},"astc-8x8-unorm-srgb":{gl:37847},"astc-10x5-unorm":{gl:37816},"astc-10x5-unorm-srgb":{gl:37848},"astc-10x6-unorm":{gl:37817},"astc-10x6-unorm-srgb":{gl:37849},"astc-10x8-unorm":{gl:37818},"astc-10x8-unorm-srgb":{gl:37850},"astc-10x10-unorm":{gl:37819},"astc-10x10-unorm-srgb":{gl:37851},"astc-12x10-unorm":{gl:37820},"astc-12x10-unorm-srgb":{gl:37852},"astc-12x12-unorm":{gl:37821},"astc-12x12-unorm-srgb":{gl:37853},"pvrtc-rgb4unorm-webgl":{gl:35840},"pvrtc-rgba4unorm-webgl":{gl:35842},"pvrtc-rgb2unorm-webgl":{gl:35841},"pvrtc-rgba2unorm-webgl":{gl:35843},"etc1-rbg-unorm-webgl":{gl:36196},"atc-rgb-unorm-webgl":{gl:35986},"atc-rgba-unorm-webgl":{gl:35986},"atc-rgbai-unorm-webgl":{gl:34798}};function je(e,t,r){let i=t.create;const s=Ve[t.format];void 0===s?.gl&&(i=!1),s?.x&&(i=i&&Boolean(Be(e,s.x,r))),"stencil8"===t.format&&(i=!1);const n=!1!==s?.r&&(void 0===s?.r||Ne(e,s.r,r)),a=i&&t.render&&n&&function(e,t,r){const i=Ve[t],s=i?.gl;if(void 0===s)return!1;if(i?.x&&!Be(e,i.x,r))return!1;const n=e.getParameter(32873),a=e.getParameter(36006),o=e.createTexture(),c=e.createFramebuffer();if(!o||!c)return!1;const l=Number(0);let u=Number(e.getError());for(;u!==l;)u=e.getError();let h=!1;try{if(e.bindTexture(3553,o),e.texStorage2D(3553,1,s,1,1),Number(e.getError())!==l)return!1;e.bindFramebuffer(36160,c),e.framebufferTexture2D(36160,36064,3553,o,0),h=Number(e.checkFramebufferStatus(36160))===Number(36053)&&Number(e.getError())===l}finally{e.bindFramebuffer(36160,a),e.deleteFramebuffer(c),e.bindTexture(3553,n),e.deleteTexture(o)}return h}(e,t.format,r);return{format:t.format,create:i&&t.create,render:a,filter:i&&t.filter,blend:i&&t.blend,store:i&&t.store}}function qe(e){const t=Ve[e],r=function(e){const t=Ve[e],r=t?.gl;if(void 0===r)throw new Error(`Unsupported texture format ${e}`);return r}(e),i=l.getInfo(e);return i.compressed&&(t.dataFormat=r),{internalFormat:r,format:t?.dataFormat||He(i.channels,i.integer,i.normalized,r),type:i.dataType?Le(i.dataType):t?.types?.[0]||5121,compressed:i.compressed||!1}}function He(e,t,r,i){if(6408===i||6407===i)return i;switch(e){case"r":return t&&!r?36244:6403;case"rg":return t&&!r?33320:33319;case"rgb":return t&&!r?36248:6407;case"rgba":return t&&!r?36249:6408;case"bgra":throw new Error("bgra pixels not supported by WebGL");default:return 6408}}const Xe={"depth-clip-control":"EXT_depth_clamp","timestamp-query":"EXT_disjoint_timer_query_webgl2","compilation-status-async-webgl":"KHR_parallel_shader_compile","polygon-mode-webgl":"WEBGL_polygon_mode","provoking-vertex-webgl":"WEBGL_provoking_vertex","shader-clip-cull-distance-webgl":"WEBGL_clip_cull_distance","shader-noperspective-interpolation-webgl":"NV_shader_noperspective_interpolation","shader-conservative-depth-webgl":"EXT_conservative_depth"};class Ye extends u{gl;extensions;testedFeatures=/* @__PURE__ */new Set;constructor(e,t,r){super([],r),this.gl=e,this.extensions=t,Be(e,"EXT_color_buffer_float",t)}*[Symbol.iterator](){const e=this.getFeatures();for(const t of e)this.has(t)&&(yield t);return[]}has(e){return!this.disabledFeatures?.[e]&&(this.testedFeatures.has(e)||(this.testedFeatures.add(e),function(e){return e in Qe}(e)&&Ne(this.gl,e,this.extensions)&&this.features.add(e),this.getWebGLFeature(e)&&this.features.add(e)),this.features.has(e))}initializeFeatures(){const e=this.getFeatures().filter(e=>"polygon-mode-webgl"!==e);for(const t of e)this.has(t)}getFeatures(){return[...Object.keys(Xe),...Object.keys(Qe)]}getWebGLFeature(e){const t=Xe[e];return"string"==typeof t?Boolean(Be(this.gl,t,this.extensions)):Boolean(t)}}class Ke extends h{get maxTextureDimension1D(){return 0}get maxTextureDimension2D(){return this.getParameter(3379)}get maxTextureDimension3D(){return this.getParameter(32883)}get maxTextureArrayLayers(){return this.getParameter(35071)}get maxBindGroups(){return 0}get maxDynamicUniformBuffersPerPipelineLayout(){return 0}get maxDynamicStorageBuffersPerPipelineLayout(){return 0}get maxSampledTexturesPerShaderStage(){return this.getParameter(35660)}get maxSamplersPerShaderStage(){return this.getParameter(35661)}get maxStorageBuffersPerShaderStage(){return 0}get maxStorageTexturesPerShaderStage(){return 0}get maxUniformBuffersPerShaderStage(){return this.getParameter(35375)}get maxUniformBufferBindingSize(){return this.getParameter(35376)}get maxStorageBufferBindingSize(){return 0}get minUniformBufferOffsetAlignment(){return this.getParameter(35380)}get minStorageBufferOffsetAlignment(){return 0}get maxVertexBuffers(){return 16}get maxVertexAttributes(){return this.getParameter(34921)}get maxVertexBufferArrayStride(){return 2048}get maxInterStageShaderVariables(){return this.getParameter(35659)}get maxComputeWorkgroupStorageSize(){return 0}get maxComputeInvocationsPerWorkgroup(){return 0}get maxComputeWorkgroupSizeX(){return 0}get maxComputeWorkgroupSizeY(){return 0}get maxComputeWorkgroupSizeZ(){return 0}get maxComputeWorkgroupsPerDimension(){return 0}gl;limits={};constructor(e){super(),this.gl=e}getParameter(e){return void 0===this.limits[e]&&(this.limits[e]=this.gl.getParameter(e)),this.limits[e]||0}}class Ze extends D{device;gl;handle;colorAttachments=[];depthStencilAttachment=null;constructor(e,t){super(e,t);const r=null===t.handle;this.device=e,this.gl=e.gl,this.handle=this.props.handle||r?this.props.handle:this.gl.createFramebuffer(),r||(e._setWebGLDebugMetadata(this.handle,this,{spector:this.props}),t.handle||(this.autoCreateAttachmentTextures(),this.updateAttachments()))}destroy(){super.destroy(),this.destroyed||null===this.handle||this.props.handle||this.gl.deleteFramebuffer(this.handle)}updateAttachments(){const e=this.gl.bindFramebuffer(36160,this.handle);for(let t=0;t<this.colorAttachments.length;++t){const e=this.colorAttachments[t];if(e){const r=36064+t;this._attachTextureView(r,e)}}if(this.depthStencilAttachment){const e=function(e){switch(l.getInfo(e).attachment){case"depth":return 36096;case"stencil":return 36128;case"depth-stencil":return 33306;default:throw new Error(`Not a depth stencil format: ${e}`)}}(this.depthStencilAttachment.props.format);this._attachTextureView(e,this.depthStencilAttachment)}if(this.device.props.debug){const e=this.gl.checkFramebufferStatus(36160);if(36053!==e)throw new Error(`Framebuffer ${function(e){switch(e){case 36053:return"success";case 36054:return"Mismatched attachments";case 36055:return"No attachments";case 36057:return"Height/width mismatch";case 36061:return"Unsupported or split attachments";case 36182:return"Samples mismatch";default:return`${e}`}}(e)}`)}this.gl.bindFramebuffer(36160,e)}_attachTextureView(e,t){const{gl:r}=this.device,{texture:i}=t,s=t.props.baseMipLevel,n=t.props.baseArrayLayer;switch(r.bindTexture(i.glTarget,i.handle),i.glTarget){case 35866:case 32879:r.framebufferTextureLayer(36160,e,i.handle,s,n);break;case 34067:const t=function(e){return e<34069?e+34069:e}(n);r.framebufferTexture2D(36160,e,t,i.handle,s);break;case 3553:r.framebufferTexture2D(36160,e,3553,i.handle,s);break;default:throw new Error("Illegal texture type")}r.bindTexture(i.glTarget,null)}resizeAttachments(e,t){if(null===this.handle)return this.width=e,void(this.height=t);super.resizeAttachments(e,t)}}class Je extends P{device;handle=null;_framebuffer=null;get[Symbol.toStringTag](){return"WebGLCanvasContext"}constructor(e,t){super(t),this.device=e,this._setAutoCreatedCanvasId(`${this.device.id}-canvas`),this._configureDevice()}_configureDevice(){(this.drawingBufferWidth!==this._framebuffer?.width||this.drawingBufferHeight!==this._framebuffer?.height)&&this._framebuffer?.resize([this.drawingBufferWidth,this.drawingBufferHeight])}_getCurrentFramebuffer(){return this._framebuffer||=new Ze(this.device,{id:"canvas-context-framebuffer",handle:null,width:this.drawingBufferWidth,height:this.drawingBufferHeight}),this._framebuffer}}class et extends T{device;handle=null;context2d;get[Symbol.toStringTag](){return"WebGLPresentationContext"}constructor(e,t={}){super(t),this.device=e;const r=`${this[Symbol.toStringTag]}(${this.id})`;if(!this.device.getDefaultCanvasContext().offscreenCanvas)throw new Error(`${r}: WebGL PresentationContext requires the default CanvasContext canvas to be an OffscreenCanvas`);const i=this.canvas.getContext("2d");if(!i)throw new Error(`${r}: Failed to create 2d presentation context`);this.context2d=i,this._setAutoCreatedCanvasId(`${this.device.id}-presentation-canvas`),this._configureDevice(),this._startObservers()}present(){this._resizeDrawingBufferIfNeeded(),this.device.submit();const e=this.device.getDefaultCanvasContext(),[t,r]=e.getDrawingBufferSize();if(0!==this.drawingBufferWidth&&0!==this.drawingBufferHeight&&0!==t&&0!==r&&0!==e.canvas.width&&0!==e.canvas.height){if(t!==this.drawingBufferWidth||r!==this.drawingBufferHeight||e.canvas.width!==this.drawingBufferWidth||e.canvas.height!==this.drawingBufferHeight)throw new Error(`${this[Symbol.toStringTag]}(${this.id}): Default canvas context size ${t}x${r} does not match presentation size ${this.drawingBufferWidth}x${this.drawingBufferHeight}`);this.context2d.clearRect(0,0,this.drawingBufferWidth,this.drawingBufferHeight),this.context2d.drawImage(e.canvas,0,0)}}_configureDevice(){}_getCurrentFramebuffer(e){const t=this.device.getDefaultCanvasContext();return t.setDrawingBufferSize(this.drawingBufferWidth,this.drawingBufferHeight),t.getCurrentFramebuffer(e)}}const tt={};function rt(e="id"){tt[e]=tt[e]||1;return`${e}-${tt[e]++}`}class it extends d{device;gl;handle;glTarget;glUsage;glIndexType=5123;byteLength=0;bytesUsed=0;constructor(e,t={}){super(e,t),this.device=e,this.gl=this.device.gl;const r="object"==typeof t?t.handle:void 0;this.handle=r||this.gl.createBuffer(),e._setWebGLDebugMetadata(this.handle,this,{spector:{...this.props,data:typeof this.props.data}}),this.glTarget=function(e){if(e&d.INDEX)return 34963;if(e&d.VERTEX)return 34962;if(e&d.UNIFORM)return 35345;return 34962}(this.props.usage),this.glUsage=function(e){if(e&d.INDEX)return 35044;if(e&d.VERTEX)return 35044;if(e&d.UNIFORM)return 35048;return 35044}(this.props.usage),this.glIndexType="uint32"===this.props.indexType?5125:5123,t.data?this._initWithData(t.data,t.byteOffset,t.byteLength):this._initWithByteLength(t.byteLength||0)}destroy(){!this.destroyed&&this.handle&&(this.removeStats(),this.props.handle?this.trackDeallocatedReferencedMemory("Buffer"):(this.trackDeallocatedMemory(),this.gl.deleteBuffer(this.handle)),this.destroyed=!0,this.handle=null)}_initWithData(e,t=0,r=e.byteLength+t){const i=this.glTarget;this.gl.bindBuffer(i,this.handle),this.gl.bufferData(i,r,this.glUsage),this.gl.bufferSubData(i,t,e),this.gl.bindBuffer(i,null),this.bytesUsed=r,this.byteLength=r,this._setDebugData(e,t,r),this.props.handle?this.trackReferencedMemory(r,"Buffer"):this.trackAllocatedMemory(r)}_initWithByteLength(e){let t=e;0===e&&(t=new Float32Array(0));const r=this.glTarget;return this.gl.bindBuffer(r,this.handle),this.gl.bufferData(r,t,this.glUsage),this.gl.bindBuffer(r,null),this.bytesUsed=e,this.byteLength=e,this._setDebugData(null,0,e),this.props.handle?this.trackReferencedMemory(e,"Buffer"):this.trackAllocatedMemory(e),this}write(e,t=0){const r=ArrayBuffer.isView(e)?e:new Uint8Array(e),i=36663;this.gl.bindBuffer(i,this.handle),this.gl.bufferSubData(i,t,r),this.gl.bindBuffer(i,null),this._setDebugData(e,t,e.byteLength)}async mapAndWriteAsync(e,t=0,r=this.byteLength-t){const i=new ArrayBuffer(r);await e(i,"copied"),this.write(i,t)}async readAsync(e=0,t){return this.readSyncWebGL(e,t)}async mapAndReadAsync(e,t=0,r){const i=await this.readAsync(t,r);return await e(i.buffer,"copied")}readSyncWebGL(e=0,t){t=t??this.byteLength-e;const r=new Uint8Array(t);return this.gl.bindBuffer(36662,this.handle),this.gl.getBufferSubData(36662,e,r,0,t),this.gl.bindBuffer(36662,null),this._setDebugData(r,e,t),r}}function st(e){const t=e.toLowerCase();return["warning","error","info"].includes(t)?t:"info"}class nt extends E{device;handle;constructor(e,t){switch(super(e,t),this.device=e,this.props.stage){case"vertex":this.handle=this.props.handle||this.device.gl.createShader(35633);break;case"fragment":this.handle=this.props.handle||this.device.gl.createShader(35632);break;default:throw new Error(this.props.stage)}e._setWebGLDebugMetadata(this.handle,this,{spector:this.props});const r=this._compile(this.source);r&&"function"==typeof r.catch&&r.catch(()=>{this.compilationStatus="error"})}destroy(){this.handle&&(this.removeStats(),this.device.gl.deleteShader(this.handle),this.destroyed=!0,this.handle.destroyed=!0)}get asyncCompilationStatus(){return this._waitForCompilationComplete().then(()=>(this._getCompilationStatus(),this.compilationStatus))}async getCompilationInfo(){return await this._waitForCompilationComplete(),this.getCompilationInfoSync()}getCompilationInfoSync(){const e=this.device.gl.getShaderInfoLog(this.handle);return e?function(e){const t=e.split(/\r?\n/),r=[];for(const i of t){if(i.length<=1)continue;const e=i.trim(),t=i.split(":"),s=t[0]?.trim();if(2===t.length){const[i,n]=t;if(!i||!n){r.push({message:e,type:st(s||"info"),lineNum:0,linePos:0});continue}r.push({message:n.trim(),type:st(i),lineNum:0,linePos:0});continue}const[n,a,o,...c]=t;if(!n||!a||!o){r.push({message:t.slice(1).join(":").trim()||e,type:st(s||"info"),lineNum:0,linePos:0});continue}let l=parseInt(o,10);Number.isNaN(l)&&(l=0);let u=parseInt(a,10);Number.isNaN(u)&&(u=0),r.push({message:c.join(":").trim(),type:st(n),lineNum:l,linePos:u})}return r}(e):[]}getTranslatedSource(){const e=this.device.getExtension("WEBGL_debug_shaders").WEBGL_debug_shaders;return e?.getTranslatedShaderSource(this.handle)||null}_compile(e){e=e.startsWith("#version ")?e:`#version 300 es\n${e}`;const{gl:t}=this.device;if(t.shaderSource(this.handle,e),t.compileShader(this.handle),this.device.props.debug){if(this.device.features.has("compilation-status-async-webgl"))return n.once(1,"Shader compilation is asynchronous")(),this._waitForCompilationComplete().then(()=>{n.info(2,`Shader ${this.id} - async compilation complete: ${this.compilationStatus}`)(),this._getCompilationStatus(),this.debugShader()});if(this._getCompilationStatus(),this.debugShader(),"error"===this.compilationStatus)throw new Error(`GLSL compilation errors in ${this.props.stage} shader ${this.props.id}`)}else this.compilationStatus="pending"}async _waitForCompilationComplete(){const e=async e=>await new Promise(t=>setTimeout(t,e));if(!this.device.features.has("compilation-status-async-webgl"))return void(await e(10));const{gl:t}=this.device;for(;;){if(t.getShaderParameter(this.handle,37297))return;await e(10)}}_getCompilationStatus(){this.compilationStatus=this.device.gl.getShaderParameter(this.handle,35713)?"success":"error"}}function at(e,t,r,i){if(function(e){let t=!0;for(const r in e){t=!1;break}return t}(t))return i(e);const s=e;s.pushState();try{return function(e,t){const r=e,{gl:i}=r;if(t.cullMode)switch(t.cullMode){case"none":i.disable(2884);break;case"front":i.enable(2884),i.cullFace(1028);break;case"back":i.enable(2884),i.cullFace(1029)}t.frontFace&&i.frontFace(ht("frontFace",t.frontFace,{ccw:2305,cw:2304}));t.unclippedDepth&&e.features.has("depth-clip-control")&&i.enable(34383);void 0!==t.depthBias&&(i.enable(32823),i.polygonOffset(t.depthBias,t.depthBiasSlopeScale||0));if(t.provokingVertex&&e.features.has("provoking-vertex-webgl")){const e=r.getExtension("WEBGL_provoking_vertex").WEBGL_provoking_vertex,i=ht("provokingVertex",t.provokingVertex,{first:36429,last:36430});e?.provokingVertexWEBGL(i)}if((t.polygonMode||t.polygonOffsetLine)&&e.features.has("polygon-mode-webgl")){if(t.polygonMode){const e=r.getExtension("WEBGL_polygon_mode").WEBGL_polygon_mode,i=ht("polygonMode",t.polygonMode,{fill:6914,line:6913});e?.polygonModeWEBGL(1028,i),e?.polygonModeWEBGL(1029,i)}t.polygonOffsetLine&&i.enable(10754)}e.features.has("shader-clip-cull-distance-webgl")&&(t.clipDistance0&&i.enable(12288),t.clipDistance1&&i.enable(12289),t.clipDistance2&&i.enable(12290),t.clipDistance3&&i.enable(12291),t.clipDistance4&&i.enable(12292),t.clipDistance5&&i.enable(12293),t.clipDistance6&&i.enable(12294),t.clipDistance7&&i.enable(12295));void 0!==t.depthWriteEnabled&&i.depthMask(t.depthWriteEnabled);t.depthCompare&&("always"!==t.depthCompare?i.enable(2929):i.disable(2929),i.depthFunc(ot("depthCompare",t.depthCompare)));void 0!==t.clearDepth&&i.clearDepth(t.clearDepth);if(t.stencilWriteMask){const e=t.stencilWriteMask;i.stencilMaskSeparate(1028,e),i.stencilMaskSeparate(1029,e)}t.stencilReadMask&&n.warn("stencilReadMask not supported under WebGL");if(t.stencilCompare){const e=t.stencilReadMask||4294967295,r=ot("depthCompare",t.stencilCompare);"always"!==t.stencilCompare?i.enable(2960):i.disable(2960),i.stencilFuncSeparate(1028,r,0,e),i.stencilFuncSeparate(1029,r,0,e)}if(t.stencilPassOperation&&t.stencilFailOperation&&t.stencilDepthFailOperation){const e=ct("stencilPassOperation",t.stencilPassOperation),r=ct("stencilFailOperation",t.stencilFailOperation),s=ct("stencilDepthFailOperation",t.stencilDepthFailOperation);i.stencilOpSeparate(1028,r,s,e),i.stencilOpSeparate(1029,r,s,e)}switch(t.blend){case!0:i.enable(3042);break;case!1:i.disable(3042)}if(t.blendColorOperation||t.blendAlphaOperation){const e=lt("blendColorOperation",t.blendColorOperation||"add"),r=lt("blendAlphaOperation",t.blendAlphaOperation||"add");i.blendEquationSeparate(e,r);const s=ut("blendColorSrcFactor",t.blendColorSrcFactor||"one"),n=ut("blendColorDstFactor",t.blendColorDstFactor||"zero"),a=ut("blendAlphaSrcFactor",t.blendAlphaSrcFactor||"one"),o=ut("blendAlphaDstFactor",t.blendAlphaDstFactor||"zero");i.blendFuncSeparate(s,n,a,o)}}(e,t),xe(s.gl,r),i(e)}finally{s.popState()}}function ot(e,t){return ht(e,t,{never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519})}function ct(e,t){return ht(e,t,{keep:7680,zero:0,replace:7681,invert:5386,"increment-clamp":7682,"decrement-clamp":7683,"increment-wrap":34055,"decrement-wrap":34056})}function lt(e,t){return ht(e,t,{add:32774,subtract:32778,"reverse-subtract":32779,min:32775,max:32776})}function ut(e,t,r="color"){return ht(e,t,{one:1,zero:0,src:768,"one-minus-src":769,dst:774,"one-minus-dst":775,"src-alpha":770,"one-minus-src-alpha":771,"dst-alpha":772,"one-minus-dst-alpha":773,"src-alpha-saturated":776,constant:"color"===r?32769:32771,"one-minus-constant":"color"===r?32770:32772,src1:768,"one-minus-src1":769,"src1-alpha":770,"one-minus-src1-alpha":771})}function ht(e,t,r){if(!(t in r))throw new Error(function(e,t){return`Illegal parameter ${t} for ${e}`}(e,t));return r[t]}function dt(e){const t={};return e.addressModeU&&(t[10242]=ft(e.addressModeU)),e.addressModeV&&(t[10243]=ft(e.addressModeV)),e.addressModeW&&(t[32882]=ft(e.addressModeW)),e.magFilter&&(t[10240]=mt(e.magFilter)),(e.minFilter||e.mipmapFilter)&&(t[10241]=function(e,t="none"){if(!t)return mt(e);switch(t){case"none":return mt(e);case"nearest":switch(e){case"nearest":return 9984;case"linear":return 9985}break;case"linear":switch(e){case"nearest":return 9986;case"linear":return 9987}}}(e.minFilter||"linear",e.mipmapFilter)),void 0!==e.lodMinClamp&&(t[33082]=e.lodMinClamp),void 0!==e.lodMaxClamp&&(t[33083]=e.lodMaxClamp),"comparison-sampler"===e.type&&(t[34892]=34894),e.compare&&(t[34893]=ot("compare",e.compare)),e.maxAnisotropy&&(t[34046]=e.maxAnisotropy),t}function ft(e){switch(e){case"clamp-to-edge":return 33071;case"repeat":return 10497;case"mirror-repeat":return 33648}}function mt(e){switch(e){case"nearest":return 9728;case"linear":return 9729}}class gt extends f{device;handle;parameters;constructor(e,t){super(e,t),this.device=e,this.parameters=dt(t),this.handle=t.handle||this.device.gl.createSampler(),this._setSamplerParameters(this.parameters)}destroy(){this.handle&&(this.device.gl.deleteSampler(this.handle),this.handle=void 0)}toString(){return`Sampler(${this.id},${JSON.stringify(this.props)})`}_setSamplerParameters(e){for(const[t,r]of Object.entries(e)){const e=Number(t);switch(e){case 33082:case 33083:this.device.gl.samplerParameterf(this.handle,e,r);break;default:this.device.gl.samplerParameteri(this.handle,e,r)}}}}function pt(e,t,r){if(function(e){for(const t in e)return!1;return!0}(t))return r(e);const{nocatch:i=!0}=t,s=Pe.get(e);let n;if(s.push(),xe(e,t),i)n=r(e),s.pop();else try{n=r(e)}finally{s.pop()}return n}class bt extends A{device;gl;handle;texture;constructor(e,t){super(e,{...a.defaultProps,...t}),this.device=e,this.gl=this.device.gl,this.handle=null,this.texture=t.texture}}function yt(e){return vt[e]}const vt={5124:"sint32",5125:"uint32",5122:"sint16",5123:"uint16",5120:"sint8",5121:"uint8",5126:"float32",5131:"float16",33635:"uint16",32819:"uint16",32820:"uint16",33640:"uint32",35899:"uint32",35902:"uint32",34042:"uint32",36269:"uint32"};class xt extends a{device;gl;handle;sampler=void 0;view;glTarget;glFormat;glType;glInternalFormat;compressed;_textureUnit=0;_framebuffer=null;_framebufferAttachmentKey=null;constructor(e,t){super(e,t,{byteAlignment:1}),this.device=e,this.gl=this.device.gl;const r=qe(this.props.format);this.glTarget=function(e){switch(e){case"1d":break;case"2d":return 3553;case"3d":return 32879;case"cube":return 34067;case"2d-array":return 35866}throw new Error(e)}(this.props.dimension),this.glInternalFormat=r.internalFormat,this.glFormat=r.format,this.glType=r.type,this.compressed=r.compressed,this.handle=this.props.handle||this.gl.createTexture(),this.device._setWebGLDebugMetadata(this.handle,this,{spector:this.props}),this.gl.bindTexture(this.glTarget,this.handle);const{dimension:i,width:s,height:n,depth:a,mipLevels:o,glTarget:c,glInternalFormat:l}=this;if(!this.compressed)switch(i){case"2d":case"cube":this.gl.texStorage2D(c,o,l,s,n);break;case"2d-array":case"3d":this.gl.texStorage3D(c,o,l,s,n,a);break;default:throw new Error(i)}this.gl.bindTexture(this.glTarget,null),this._initializeData(t.data),this.props.handle?this.trackReferencedMemory(this.getAllocatedByteLength(),"Texture"):this.trackAllocatedMemory(this.getAllocatedByteLength(),"Texture"),this.setSampler(this.props.sampler),this.view=new bt(this.device,{...this.props,texture:this}),Object.seal(this)}destroy(){this.handle&&(this._framebuffer?.destroy(),this._framebuffer=null,this._framebufferAttachmentKey=null,this.removeStats(),this.props.handle?this.trackDeallocatedReferencedMemory("Texture"):(this.gl.deleteTexture(this.handle),this.trackDeallocatedMemory("Texture")),this.destroyed=!0)}createView(e){return new bt(this.device,{...e,texture:this})}setSampler(e={}){super.setSampler(e);const t=dt(this.sampler.props);this._setSamplerParameters(t)}copyExternalImage(e){const t=this._normalizeCopyExternalImageOptions(e);if(t.sourceX||t.sourceY)throw new Error("WebGL does not support sourceX/sourceY)");const{glFormat:r,glType:i}=this,{image:s,depth:n,mipLevel:a,x:o,y:c,z:l,width:u,height:h}=t,d=wt(this.glTarget,this.dimension,l),f=t.flipY?{37440:!0}:{};return this.gl.bindTexture(this.glTarget,this.handle),pt(this.gl,f,()=>{switch(this.dimension){case"2d":case"cube":this.gl.texSubImage2D(d,a,o,c,u,h,r,i,s);break;case"2d-array":case"3d":this.gl.texSubImage3D(d,a,o,c,l,u,h,n,r,i,s)}}),this.gl.bindTexture(this.glTarget,null),{width:t.width,height:t.height}}copyImageData(e){super.copyImageData(e)}readBuffer(e={},t){if(!t)throw new Error(`${this} readBuffer requires a destination buffer`);const r=this._getSupportedColorReadOptions(e),i=e.byteOffset??0,s=this.computeMemoryLayout(r);if(t.byteLength<i+s.byteLength)throw new Error(`${this} readBuffer target is too small (${t.byteLength} < ${i+s.byteLength})`);const n=t;this.gl.bindBuffer(35051,n.handle);try{this._readColorTextureLayers(r,s,e=>{this.gl.readPixels(r.x,r.y,r.width,r.height,this.glFormat,this.glType,i+e)})}finally{this.gl.bindBuffer(35051,null)}return t}async readDataAsync(e={}){throw new Error(`${this} readDataAsync is deprecated; use readBuffer() with an explicit destination buffer or DynamicTexture.readAsync()`)}writeBuffer(e,t={}){const r=this._normalizeTextureWriteOptions(t),{width:i,height:s,depthOrArrayLayers:n,mipLevel:a,byteOffset:o,x:c,y:l,z:u}=r,{glFormat:h,glType:d,compressed:f}=this,m=wt(this.glTarget,this.dimension,u);if(f)throw new Error("writeBuffer for compressed textures is not implemented in WebGL");const{bytesPerPixel:g}=this.device.getTextureFormatInfo(this.format),p=g?r.bytesPerRow/g:void 0,b={3317:this.byteAlignment,...void 0!==p?{3314:p}:{},32878:r.rowsPerImage};this.gl.bindTexture(this.glTarget,this.handle),this.gl.bindBuffer(35052,e.handle),pt(this.gl,b,()=>{switch(this.dimension){case"2d":case"cube":this.gl.texSubImage2D(m,a,c,l,i,s,h,d,o);break;case"2d-array":case"3d":this.gl.texSubImage3D(m,a,c,l,u,i,s,n,h,d,o)}}),this.gl.bindBuffer(35052,null),this.gl.bindTexture(this.glTarget,null)}writeData(e,t={}){const r=this._normalizeTextureWriteOptions(t),i=ArrayBuffer.isView(e)?e:new Uint8Array(e),{width:s,height:n,depthOrArrayLayers:a,mipLevel:o,x:c,y:l,z:u,byteOffset:h}=r,{glFormat:d,glType:f,compressed:m}=this,g=wt(this.glTarget,this.dimension,u);let p;if(!m){const{bytesPerPixel:e}=this.device.getTextureFormatInfo(this.format);e&&(p=r.bytesPerRow/e)}const b=this.compressed?{}:{3317:this.byteAlignment,...void 0!==p?{3314:p}:{},32878:r.rowsPerImage},y=function(e,t){if(t%e.BYTES_PER_ELEMENT!==0)throw new Error(`Texture byteOffset ${t} must align to typed array element size ${e.BYTES_PER_ELEMENT}`);return t/e.BYTES_PER_ELEMENT}(i,h),v=m?function(e,t=0){if(!t)return e;return new e.constructor(e.buffer,e.byteOffset+t,(e.byteLength-t)/e.BYTES_PER_ELEMENT)}(i,h):i,x=this._getMipLevelSize(o),w=0===c&&0===l&&0===u&&s===x.width&&n===x.height&&a===x.depthOrArrayLayers;this.gl.bindTexture(this.glTarget,this.handle),this.gl.bindBuffer(35052,null),pt(this.gl,b,()=>{switch(this.dimension){case"2d":case"cube":m?w?this.gl.compressedTexImage2D(g,o,d,s,n,0,v):this.gl.compressedTexSubImage2D(g,o,c,l,s,n,d,v):this.gl.texSubImage2D(g,o,c,l,s,n,d,f,i,y);break;case"2d-array":case"3d":m?w?this.gl.compressedTexImage3D(g,o,d,s,n,a,0,v):this.gl.compressedTexSubImage3D(g,o,c,l,u,s,n,a,d,v):this.gl.texSubImage3D(g,o,c,l,u,s,n,a,d,f,i,y)}}),this.gl.bindTexture(this.glTarget,null)}_getRowByteAlignment(e,t){return 1}_getFramebuffer(){return this._framebuffer||=this.device.createFramebuffer({id:`framebuffer-for-${this.id}`,width:this.width,height:this.height,colorAttachments:[this]}),this._framebuffer}readDataSyncWebGL(e={}){const t=this._getSupportedColorReadOptions(e),r=this.computeMemoryLayout(t),i=re(yt(this.glType)),s=new i(r.byteLength/i.BYTES_PER_ELEMENT);return this._readColorTextureLayers(t,r,e=>{const n=new i(s.buffer,s.byteOffset+e,r.bytesPerImage/i.BYTES_PER_ELEMENT);this.gl.readPixels(t.x,t.y,t.width,t.height,this.glFormat,this.glType,n)}),s.buffer}_readColorTextureLayers(e,t,r){const i=this._getFramebuffer(),s=t.bytesPerRow/t.bytesPerPixel,n={3333:this.byteAlignment,...s!==e.width?{3330:s}:{}},a=this.gl.getParameter(3074),o=this.gl.bindFramebuffer(36160,i.handle);try{this.gl.readBuffer(36064),pt(this.gl,n,()=>{for(let s=0;s<e.depthOrArrayLayers;s++)this._attachReadSubresource(i,e.mipLevel,e.z+s),r(s*t.bytesPerImage)})}finally{this.gl.bindFramebuffer(36160,o||null),this.gl.readBuffer(a)}}_attachReadSubresource(e,t,r){const i=`${t}:${r}`;if(this._framebufferAttachmentKey!==i){switch(this.dimension){case"2d":this.gl.framebufferTexture2D(36160,36064,3553,this.handle,t);break;case"cube":this.gl.framebufferTexture2D(36160,36064,wt(this.glTarget,this.dimension,r),this.handle,t);break;case"2d-array":case"3d":this.gl.framebufferTextureLayer(36160,36064,this.handle,t,r);break;default:throw new Error(`${this} color readback does not support ${this.dimension} textures`)}if(this.device.props.debug){const t=Number(this.gl.checkFramebufferStatus(36160));if(t!==Number(36053))throw new Error(`${e} incomplete for ${this} readback (${t})`)}this._framebufferAttachmentKey=i}}generateMipmapsWebGL(e){if(this.device.isTextureFormatRenderable(this.props.format)&&this.device.isTextureFormatFilterable(this.props.format)||(n.warn(`${this} is not renderable or filterable, may not be able to generate mipmaps`)(),e?.force))try{this.gl.bindTexture(this.glTarget,this.handle),this.gl.generateMipmap(this.glTarget)}catch(t){n.warn(`Error generating mipmap for ${this}: ${t.message}`)()}finally{this.gl.bindTexture(this.glTarget,null)}}_setSamplerParameters(e){n.log(2,`${this.id} sampler parameters`,this.device.getGLKeys(e))(),this.gl.bindTexture(this.glTarget,this.handle);for(const[t,r]of Object.entries(e)){const e=Number(t),i=r;switch(e){case 33082:case 33083:this.gl.texParameterf(this.glTarget,e,i);break;case 10240:case 10241:case 10242:case 10243:case 32882:case 34892:case 34893:this.gl.texParameteri(this.glTarget,e,i);break;case 34046:this.device.features.has("texture-filterable-anisotropic-webgl")&&this.gl.texParameteri(this.glTarget,e,i)}}this.gl.bindTexture(this.glTarget,null)}_getActiveUnit(){return this.gl.getParameter(34016)-33984}_bind(e){const{gl:t}=this;return void 0!==e&&(this._textureUnit=e,t.activeTexture(33984+e)),t.bindTexture(this.glTarget,this.handle),e}_unbind(e){const{gl:t}=this;return void 0!==e&&(this._textureUnit=e,t.activeTexture(33984+e)),t.bindTexture(this.glTarget,null),e}}function wt(e,t,r){return"cube"===t?34069+r:e}function St(e,t,r,i){const s=e;let n=i;!0===n&&(n=1),!1===n&&(n=0);const a="number"==typeof n?[n]:n;switch(r){case 35678:case 35680:case 35679:case 35682:case 36289:case 36292:case 36293:case 36298:case 36299:case 36300:case 36303:case 36306:case 36307:case 36308:case 36311:if("number"!=typeof i)throw new Error("samplers must be set to integers");return e.uniform1i(t,i);case 5126:return e.uniform1fv(t,a);case 35664:return e.uniform2fv(t,a);case 35665:return e.uniform3fv(t,a);case 35666:return e.uniform4fv(t,a);case 5124:case 35670:return e.uniform1iv(t,a);case 35667:case 35671:return e.uniform2iv(t,a);case 35668:case 35672:return e.uniform3iv(t,a);case 35669:case 35673:return e.uniform4iv(t,a);case 5125:return s.uniform1uiv(t,a,1);case 36294:return s.uniform2uiv(t,a,2);case 36295:return s.uniform3uiv(t,a,3);case 36296:return s.uniform4uiv(t,a,4);case 35674:return e.uniformMatrix2fv(t,!1,a);case 35675:return e.uniformMatrix3fv(t,!1,a);case 35676:return e.uniformMatrix4fv(t,!1,a);case 35685:return s.uniformMatrix2x3fv(t,!1,a);case 35686:return s.uniformMatrix2x4fv(t,!1,a);case 35687:return s.uniformMatrix3x2fv(t,!1,a);case 35688:return s.uniformMatrix3x4fv(t,!1,a);case 35689:return s.uniformMatrix4x2fv(t,!1,a);case 35690:return s.uniformMatrix4x3fv(t,!1,a)}throw new Error("Illegal uniform")}class _t extends F{device;handle;vs;fs;introspectedLayout;bindings={};uniforms={};varyings=null;_uniformCount=0;_uniformSetters={};get[Symbol.toStringTag](){return"WEBGLRenderPipeline"}constructor(e,t){super(e,t),this.device=e;const r=this.sharedRenderPipeline||this.device._createSharedRenderPipelineWebGL(t);this.sharedRenderPipeline=r,this.handle=r.handle,this.vs=r.vs,this.fs=r.fs,this.linkStatus=r.linkStatus,this.introspectedLayout=r.introspectedLayout,this.device._setWebGLDebugMetadata(this.handle,this,{spector:{id:this.props.id}}),this.shaderLayout=t.shaderLayout?function(e,t){const r={...e,attributes:e.attributes.map(e=>({...e})),bindings:e.bindings.map(e=>({...e}))};for(const i of t?.attributes||[]){const e=r.attributes.find(e=>e.name===i.name);e?(e.type=i.type||e.type,e.stepMode=i.stepMode||e.stepMode):n.warn(`shader layout attribute ${i.name} not present in shader`)}for(const i of t?.bindings||[]){const e=Pt(r,i.name);e?Object.assign(e,i):n.warn(`shader layout binding ${i.name} not present in shader`)}return r}(this.introspectedLayout,t.shaderLayout):this.introspectedLayout}destroy(){this.destroyed||(this.sharedRenderPipeline&&!this.props._sharedRenderPipeline&&this.sharedRenderPipeline.destroy(),this.destroyResource())}setBindings(e,t){const r=O(M(this.shaderLayout,e));for(const[i,s]of Object.entries(r)){const e=Pt(this.shaderLayout,i);if(e){switch(s||n.warn(`Unsetting binding "${i}" in render pipeline "${this.id}"`)(),e.type){case"uniform":if(!(s instanceof it||s.buffer instanceof it))throw new Error("buffer value");break;case"texture":if(!(s instanceof bt||s instanceof xt||s instanceof Ze))throw new Error(`${this} Bad texture binding for ${i}`);break;case"sampler":n.warn(`Ignoring sampler ${i}`)();break;default:throw new Error(e.type)}this.bindings[i]=s}else{const e=this.shaderLayout.bindings.map(e=>`"${e.name}"`).join(", ");t?.disableWarnings||n.warn(`No binding "${i}" in render pipeline "${this.id}", expected one of ${e}`,s)()}}}draw(e){this._syncLinkStatus();const t=e.bindGroups?O(e.bindGroups):e.bindings||this.bindings,{renderPass:r,parameters:i=this.props.parameters,topology:s=this.props.topology,vertexArray:a,vertexCount:o,instanceCount:c,isInstanced:l=!1,firstVertex:u=0,transformFeedback:h,uniforms:d=this.uniforms}=e,f=function(e){switch(e){case"point-list":return 0;case"line-list":return 1;case"line-strip":return 3;case"triangle-list":return 4;case"triangle-strip":return 5;default:throw new Error(e)}}(s),m=Boolean(a.indexBuffer),g=a.indexBuffer?.glIndexType;if("success"!==this.linkStatus)return n.info(2,`RenderPipeline:${this.id}.draw() aborted - waiting for shader linking`)(),!1;if(!this._areTexturesRenderable(t))return n.info(2,`RenderPipeline:${this.id}.draw() aborted - textures not yet loaded`)(),!1;this.device.gl.useProgram(this.handle),a.bindBeforeRender(r),h&&h.begin(this.props.topology),this._applyBindings(t,{disableWarnings:this.props.disableWarnings}),this._applyUniforms(d);const p=r;return at(this.device,i,p.glParameters,()=>{m&&l?this.device.gl.drawElementsInstanced(f,o||0,g,u,c||0):m?this.device.gl.drawElements(f,o||0,g,u):l?this.device.gl.drawArraysInstanced(f,u,o||0,c||0):this.device.gl.drawArrays(f,u,o||0),h&&h.end()}),a.unbindAfterRender(r),!0}_areTexturesRenderable(e){let t=!0;for(const r of this.shaderLayout.bindings)Tt(e,r.name)||(n.warn(`Binding ${r.name} not found in ${this.id}`)(),t=!1);return t}_applyBindings(e,t){if(this._syncLinkStatus(),"success"!==this.linkStatus)return;const{gl:r}=this.device;r.useProgram(this.handle);let i=0,s=0;for(const a of this.shaderLayout.bindings){const t=Tt(e,a.name);if(!t)throw new Error(`No value for binding ${a.name} in ${this.id}`);switch(a.type){case"uniform":const{name:e}=a,o=r.getUniformBlockIndex(this.handle,e);if(4294967295===o)throw new Error(`Invalid uniform block name ${e}`);if(r.uniformBlockBinding(this.handle,o,s),t instanceof it)r.bindBufferBase(35345,s,t.handle);else{const e=t;r.bindBufferRange(35345,s,e.buffer.handle,e.offset||0,e.size||e.buffer.byteLength-(e.offset||0))}s+=1;break;case"texture":if(!(t instanceof bt||t instanceof xt||t instanceof Ze))throw new Error("texture");let c;if(t instanceof bt)c=t.texture;else if(t instanceof xt)c=t;else{if(!(t instanceof Ze&&t.colorAttachments[0]instanceof bt))throw new Error("No texture");n.warn("Passing framebuffer in texture binding may be deprecated. Use fbo.colorAttachments[0] instead")(),c=t.colorAttachments[0].texture}r.activeTexture(33984+i),r.bindTexture(c.glTarget,c.handle),i+=1;break;case"sampler":break;case"storage":case"read-only-storage":throw new Error(`binding type '${a.type}' not supported in WebGL`)}}}_applyUniforms(e){for(const t of this.shaderLayout.uniforms||[]){const{name:r,location:i,type:s,textureUnit:n}=t,a=e[r]??n;void 0!==a&&St(this.device.gl,i,s,a)}}_syncLinkStatus(){this.linkStatus=this.sharedRenderPipeline.linkStatus}}function Pt(e,t){return e.bindings.find(e=>e.name===t||e.name===`${t}Uniforms`||`${e.name}Uniforms`===t)}function Tt(e,t){return e[t]||e[`${t}Uniforms`]||e[t.replace(/Uniforms$/,"")]}function At(e){return Et[e]}function Bt(e){return Boolean(Lt[e])}function Ct(e){return Lt[e]}const Et={5126:"f32",35664:"vec2<f32>",35665:"vec3<f32>",35666:"vec4<f32>",5124:"i32",35667:"vec2<i32>",35668:"vec3<i32>",35669:"vec4<i32>",5125:"u32",36294:"vec2<u32>",36295:"vec3<u32>",36296:"vec4<u32>",35670:"f32",35671:"vec2<f32>",35672:"vec3<f32>",35673:"vec4<f32>",35674:"mat2x2<f32>",35685:"mat2x3<f32>",35686:"mat2x4<f32>",35687:"mat3x2<f32>",35675:"mat3x3<f32>",35688:"mat3x4<f32>",35689:"mat4x2<f32>",35690:"mat4x3<f32>",35676:"mat4x4<f32>"},Lt={35678:{viewDimension:"2d",sampleType:"float"},35680:{viewDimension:"cube",sampleType:"float"},35679:{viewDimension:"3d",sampleType:"float"},35682:{viewDimension:"3d",sampleType:"depth"},36289:{viewDimension:"2d-array",sampleType:"float"},36292:{viewDimension:"2d-array",sampleType:"depth"},36293:{viewDimension:"cube",sampleType:"float"},36298:{viewDimension:"2d",sampleType:"sint"},36299:{viewDimension:"3d",sampleType:"sint"},36300:{viewDimension:"cube",sampleType:"sint"},36303:{viewDimension:"2d-array",sampleType:"uint"},36306:{viewDimension:"2d",sampleType:"uint"},36307:{viewDimension:"3d",sampleType:"uint"},36308:{viewDimension:"cube",sampleType:"uint"},36311:{viewDimension:"2d-array",sampleType:"uint"}},Dt={uint8:5121,sint8:5120,unorm8:5121,snorm8:5120,uint16:5123,sint16:5122,unorm16:5123,snorm16:5122,uint32:5125,sint32:5124,float16:5131,float32:5126};function Ft(e,t){const r={attributes:[],bindings:[]};r.attributes=function(e,t){const r=[],i=e.getProgramParameter(t,35721);for(let s=0;s<i;s++){const i=e.getActiveAttrib(t,s);if(!i)throw new Error("activeInfo");const{name:n,type:a}=i,o=e.getAttribLocation(t,n);if(o>=0){const e=At(a),t=/instance/i.test(n)?"instance":"vertex";r.push({name:n,location:o,stepMode:t,type:e})}}return r.sort((e,t)=>e.location-t.location),r}(e,t);const i=function(e,t){const r=(r,i)=>e.getActiveUniformBlockParameter(t,r,i),i=[],s=e.getProgramParameter(t,35382);for(let a=0;a<s;a++){const s={name:e.getActiveUniformBlockName(t,a)||"",location:r(a,35391),byteLength:r(a,35392),vertex:r(a,35396),fragment:r(a,35398),uniformCount:r(a,35394),uniforms:[]},o=r(a,35395)||[],c=e.getActiveUniforms(t,o,35383),l=e.getActiveUniforms(t,o,35384),u=e.getActiveUniforms(t,o,35387),h=e.getActiveUniforms(t,o,35388);for(let r=0;r<s.uniformCount;++r){const i=o[r];if(void 0!==i){const n=e.getActiveUniform(t,i);if(!n)throw new Error("activeInfo");const a=At(c[r]);s.uniforms.push({name:n.name,format:a,type:c[r],arrayLength:l[r],byteOffset:u[r],byteStride:h[r]})}}const d=new Set(s.uniforms.map(e=>e.name.split(".")[0]).filter(e=>Boolean(e))),f=s.name.replace(/Uniforms$/,"");if(1===d.size&&!d.has(s.name)&&!d.has(f)){const[e]=d;n.warn(`Uniform block "${s.name}" uses GLSL instance "${e}". luma.gl binds uniform buffers by block name ("${s.name}") and alias ("${f}"). Prefer matching the instance name to one of those to avoid confusing silent mismatches.`)()}i.push(s)}return i.sort((e,t)=>e.location-t.location),i}(e,t);for(const n of i){const e=n.uniforms.map(e=>({name:e.name,format:e.format,byteOffset:e.byteOffset,byteStride:e.byteStride,arrayLength:e.arrayLength}));r.bindings.push({type:"uniform",name:n.name,group:0,location:n.location,visibility:(n.vertex?1:0)&(n.fragment?2:0),minBindingSize:n.byteLength,uniforms:e})}const s=function(e,t){const r=[],i=e.getProgramParameter(t,35718);for(let s=0;s<i;s++){const i=e.getActiveUniform(t,s);if(!i)throw new Error("activeInfo");const{name:n,size:a,type:o}=i,{name:c,isArray:l}=kt(n);let u=e.getUniformLocation(t,c);const h={location:u,name:c,size:a,type:o,isArray:l};if(r.push(h),h.size>1)for(let s=0;s<h.size;s++){const i=`${c}[${s}]`;u=e.getUniformLocation(t,i);const n={...h,name:i,location:u};r.push(n)}}return r}(e,t);let a=0;for(const n of s)if(Bt(n.type)){const{viewDimension:e,sampleType:t}=Ct(n.type);r.bindings.push({type:"texture",name:n.name,group:0,location:a,viewDimension:e,sampleType:t}),n.textureUnit=a,a+=1}s.length&&(r.uniforms=s);const o=function(e,t){const r=[],i=e.getProgramParameter(t,35971);for(let s=0;s<i;s++){const i=e.getTransformFeedbackVarying(t,s);if(!i)throw new Error("activeInfo");const{name:n,type:a,size:o}=i,c=At(a),{type:l,components:u}=z(c);r.push({location:s,name:n,type:l,size:o*u})}return r.sort((e,t)=>e.location-t.location),r}(e,t);return o?.length&&(r.varyings=o),r}function kt(e){if("]"!==e[e.length-1])return{name:e,length:1,isArray:!1};const t=/([^[]*)(\[[0-9]+\])?/.exec(e);return{name:x(t?.[1],`Failed to parse GLSL uniform name ${e}`),length:t?.[2]?1:0,isArray:Boolean(t?.[2])}}class Rt extends k{device;handle;vs;fs;introspectedLayout={attributes:[],bindings:[],uniforms:[]};linkStatus="pending";constructor(e,t){super(e,t),this.device=e,this.handle=t.handle||this.device.gl.createProgram(),this.vs=t.vs,this.fs=t.fs,t.varyings&&t.varyings.length>0&&this.device.gl.transformFeedbackVaryings(this.handle,t.varyings,t.bufferMode||35981),this._linkShaders(),n.time(3,`RenderPipeline ${this.id} - shaderLayout introspection`)(),this.introspectedLayout=Ft(this.device.gl,this.handle),n.timeEnd(3,`RenderPipeline ${this.id} - shaderLayout introspection`)()}destroy(){this.destroyed||(this.device.gl.useProgram(null),this.device.gl.deleteProgram(this.handle),this.handle.destroyed=!0,this.destroyResource())}async _linkShaders(){const{gl:e}=this.device;if(e.attachShader(this.handle,this.vs.handle),e.attachShader(this.handle,this.fs.handle),n.time(4,`linkProgram for ${this.id}`)(),e.linkProgram(this.handle),n.timeEnd(4,`linkProgram for ${this.id}`)(),!this.device.features.has("compilation-status-async-webgl")){const e=this._getLinkStatus();return void this._reportLinkStatus(e)}n.once(1,"RenderPipeline linking is asynchronous")(),await this._waitForLinkComplete(),n.info(2,`RenderPipeline ${this.id} - async linking complete: ${this.linkStatus}`)();const t=this._getLinkStatus();this._reportLinkStatus(t)}async _reportLinkStatus(e){if("success"!==e){const t="link-error"===e?"Link error":"Validation error";switch(this.vs.compilationStatus){case"error":throw this.vs.debugShader(),new Error(`${this} ${t} during compilation of ${this.vs}`);case"pending":await this.vs.asyncCompilationStatus,this.vs.debugShader()}switch(this.fs?.compilationStatus){case"error":throw this.fs.debugShader(),new Error(`${this} ${t} during compilation of ${this.fs}`);case"pending":await this.fs.asyncCompilationStatus,this.fs.debugShader()}const r=this.device.gl.getProgramInfoLog(this.handle);this.device.reportError(new Error(`${t} during ${e}: ${r}`),this)(),this.device.debug()}}_getLinkStatus(){const{gl:e}=this.device;if(!e.getProgramParameter(this.handle,35714))return this.linkStatus="error","link-error";this._initializeSamplerUniforms(),e.validateProgram(this.handle);return e.getProgramParameter(this.handle,35715)?(this.linkStatus="success","success"):(this.linkStatus="error","validation-error")}_initializeSamplerUniforms(){const{gl:e}=this.device;e.useProgram(this.handle);let t=0;const r=e.getProgramParameter(this.handle,35718);for(let i=0;i<r;i++){const r=e.getActiveUniform(this.handle,i);if(r&&Bt(r.type)){const i=r.name.endsWith("[0]"),s=i?r.name.slice(0,-3):r.name,n=e.getUniformLocation(this.handle,s);null!==n&&(t=this._assignSamplerUniform(n,r,i,t))}}}_assignSamplerUniform(e,t,r,i){const{gl:s}=this.device;if(r&&t.size>1){const r=Int32Array.from({length:t.size},(e,t)=>i+t);return s.uniform1iv(e,r),i+t.size}return s.uniform1i(e,i),i+1}async _waitForLinkComplete(){const e=async e=>await new Promise(t=>setTimeout(t,e));if(!this.device.features.has("compilation-status-async-webgl"))return void(await e(10));const{gl:t}=this.device;for(;;){if(t.getProgramParameter(this.handle,37297))return;await e(10)}}}class Mt extends W{device;handle=null;commands=[];constructor(e,t={}){super(e,t),this.device=e}_executeCommands(e=this.commands){for(const t of e)switch(t.name){case"copy-buffer-to-buffer":Ot(this.device,t.options);break;case"copy-buffer-to-texture":It(this.device,t.options);break;case"copy-texture-to-buffer":$t(this.device,t.options);break;case"copy-texture-to-texture":Wt(this.device,t.options);break;default:throw new Error(t.name)}}}function Ot(e,t){const r=t.sourceBuffer,i=t.destinationBuffer;e.gl.bindBuffer(36662,r.handle),e.gl.bindBuffer(36663,i.handle),e.gl.copyBufferSubData(36662,36663,t.sourceOffset??0,t.destinationOffset??0,t.size),e.gl.bindBuffer(36662,null),e.gl.bindBuffer(36663,null)}function It(e,t){throw new Error("copyBufferToTexture is not supported in WebGL")}function $t(e,t){const{sourceTexture:r,mipLevel:i=0,aspect:s="all",width:n=t.sourceTexture.width,height:o=t.sourceTexture.height,depthOrArrayLayers:c,origin:l=[0,0,0],destinationBuffer:u,byteOffset:h=0,bytesPerRow:d,rowsPerImage:f}=t;if(r instanceof a)return void r.readBuffer({x:l[0]??0,y:l[1]??0,z:l[2]??0,width:n,height:o,depthOrArrayLayers:c,mipLevel:i,aspect:s,byteOffset:h},u);if("all"!==s)throw new Error("aspect not supported in WebGL");if(0!==i||void 0!==c||d||f)throw new Error("not implemented");const{framebuffer:m,destroyFramebuffer:g}=zt(r);let p;try{const t=u,r=n||m.width,i=o||m.height,s=qe(x(m.colorAttachments[0]).texture.props.format),a=s.format,c=s.type;e.gl.bindBuffer(35051,t.handle),p=e.gl.bindFramebuffer(36160,m.handle),e.gl.readPixels(l[0],l[1],r,i,a,c,h)}finally{e.gl.bindBuffer(35051,null),void 0!==p&&e.gl.bindFramebuffer(36160,p),g&&m.destroy()}}function Wt(e,t){const{sourceTexture:r,destinationMipLevel:i=0,origin:s=[0,0],destinationOrigin:n=[0,0,0],destinationTexture:a}=t;let{width:o=t.destinationTexture.width,height:c=t.destinationTexture.height}=t;const{framebuffer:l,destroyFramebuffer:u}=zt(r),[h=0,d=0]=s,[f,m,g]=n,p=e.gl.bindFramebuffer(36160,l.handle);let b,y;if(!(a instanceof xt))throw new Error("invalid destination");switch(b=a,o=Number.isFinite(o)?o:b.width,c=Number.isFinite(c)?c:b.height,b._bind(0),y=b.glTarget,y){case 3553:case 34067:e.gl.copyTexSubImage2D(y,i,f,m,h,d,o,c);break;case 35866:case 32879:e.gl.copyTexSubImage3D(y,i,f,m,g,h,d,o,c)}b&&b._unbind(),e.gl.bindFramebuffer(36160,p),u&&l.destroy()}function zt(e){if(e instanceof a){const{width:t,height:r,id:i}=e;return{framebuffer:e.device.createFramebuffer({id:`framebuffer-for-${i}`,width:t,height:r,colorAttachments:[e]}),destroyFramebuffer:!0}}return{framebuffer:e,destroyFramebuffer:!1}}const Gt=[1,2,4,8];class Qt extends I{device;handle=null;glParameters={};constructor(e,t){super(e,t),this.device=e;const r=this.props.framebuffer,i=!r||null===r.handle;let s;if(i&&e.getDefaultCanvasContext()._resizeDrawingBufferIfNeeded(),!t?.parameters?.viewport)if(!i&&r){const{width:e,height:t}=r;s=[0,0,e,t]}else{const[t,r]=e.getDefaultCanvasContext().getDrawingBufferSize();s=[0,0,t,r]}if(this.device.pushState(),this.setParameters({viewport:s,...this.props.parameters}),!i&&r?.colorAttachments.length){const e=r.colorAttachments.map((e,t)=>36064+t);this.device.gl.drawBuffers(e)}else i&&this.device.gl.drawBuffers([1029]);if(this.clear(),this.props.timestampQuerySet&&void 0!==this.props.beginTimestampIndex){this.props.timestampQuerySet.writeTimestamp(this.props.beginTimestampIndex)}}end(){if(!this.destroyed){if(this.props.timestampQuerySet&&void 0!==this.props.endTimestampIndex){this.props.timestampQuerySet.writeTimestamp(this.props.endTimestampIndex)}this.device.popState(),this.destroy()}}pushDebugGroup(e){}popDebugGroup(){}insertDebugMarker(e){}setParameters(e={}){const t={...this.glParameters};t.framebuffer=this.props.framebuffer||null,this.props.depthReadOnly&&(t.depthMask=!this.props.depthReadOnly),t.stencilMask=this.props.stencilReadOnly?0:1,t[35977]=this.props.discard,e.viewport&&(e.viewport.length>=6?(t.viewport=e.viewport.slice(0,4),t.depthRange=[e.viewport[4],e.viewport[5]]):t.viewport=e.viewport),e.scissorRect&&(t.scissorTest=!0,t.scissor=e.scissorRect),e.blendConstant&&(t.blendColor=e.blendConstant),void 0!==e.stencilReference&&(t[2967]=e.stencilReference,t[36003]=e.stencilReference),"colorMask"in e&&(t.colorMask=Gt.map(t=>Boolean(t&e.colorMask))),this.glParameters=t,xe(this.device.gl,t)}beginOcclusionQuery(e){const t=this.props.occlusionQuerySet;t?.beginOcclusionQuery()}endOcclusionQuery(){const e=this.props.occlusionQuerySet;e?.endOcclusionQuery()}clear(){const e={...this.glParameters};let t=0;this.props.clearColors&&this.props.clearColors.forEach((e,t)=>{e&&this.clearColorBuffer(t,e)}),!1!==this.props.clearColor&&void 0===this.props.clearColors&&(t|=16384,e.clearColor=this.props.clearColor),!1!==this.props.clearDepth&&(t|=256,e.clearDepth=this.props.clearDepth),!1!==this.props.clearStencil&&(t|=1024,e.clearStencil=this.props.clearStencil),0!==t&&pt(this.device.gl,e,()=>{this.device.gl.clear(t)})}clearColorBuffer(e=0,t=[0,0,0,0]){pt(this.device.gl,{framebuffer:this.props.framebuffer},()=>{switch(t.constructor){case Int8Array:case Int16Array:case Int32Array:this.device.gl.clearBufferiv(6144,e,t);break;case Uint8Array:case Uint8ClampedArray:case Uint16Array:case Uint32Array:this.device.gl.clearBufferuiv(6144,e,t);break;case Float32Array:this.device.gl.clearBufferfv(6144,e,t);break;default:throw new Error("clearColorBuffer: color must be typed array")}})}}class Nt extends ${device;handle=null;commandBuffer;constructor(e,t){super(e,t),this.device=e,this.commandBuffer=new Mt(e,{id:`${this.props.id}-command-buffer`})}destroy(){this.destroyResource()}finish(e){return e?.id&&this.commandBuffer.id!==e.id&&(this.commandBuffer.id=e.id,this.commandBuffer.props.id=e.id),this.destroy(),this.commandBuffer}beginRenderPass(e={}){return new Qt(this.device,this._applyTimeProfilingToPassProps(e))}beginComputePass(e={}){throw new Error("ComputePass not supported in WebGL")}copyBufferToBuffer(e){this.commandBuffer.commands.push({name:"copy-buffer-to-buffer",options:e})}copyBufferToTexture(e){this.commandBuffer.commands.push({name:"copy-buffer-to-texture",options:e})}copyTextureToBuffer(e){this.commandBuffer.commands.push({name:"copy-texture-to-buffer",options:e})}copyTextureToTexture(e){this.commandBuffer.commands.push({name:"copy-texture-to-texture",options:e})}pushDebugGroup(e){}popDebugGroup(){}insertDebugMarker(e){}resolveQuerySet(e,t,r){throw new Error("resolveQuerySet is not supported in WebGL")}writeTimestamp(e,t){e.writeTimestamp(t)}}class Ut extends K{get[Symbol.toStringTag](){return"VertexArray"}device;handle;buffer=null;bufferValue=null;static isConstantAttributeZeroSupported(i){return"Chrome"==(e()?t()?"Electron":(r.userAgent||"").indexOf("Edge")>-1?"Edge":globalThis.chrome?"Chrome":globalThis.safari?"Safari":globalThis.mozInnerScreenX?"Firefox":"Unknown":"Node")}constructor(e,t){super(e,t),this.device=e,this.handle=this.device.gl.createVertexArray()}destroy(){super.destroy(),this.buffer&&this.buffer?.destroy(),this.handle&&(this.device.gl.deleteVertexArray(this.handle),this.handle=void 0)}setIndexBuffer(e){const t=e;if(t&&34963!==t.glTarget)throw new Error("Use .setBuffer()");this.device.gl.bindVertexArray(this.handle),this.device.gl.bindBuffer(34963,t?t.handle:null),this.indexBuffer=t,this.device.gl.bindVertexArray(null)}setBuffer(e,t){const r=t;if(34963===r.glTarget)throw new Error("Use .setIndexBuffer()");const{size:i,type:s,stride:n,offset:a,normalized:o,integer:c,divisor:l}=this._getAccessor(e);this.device.gl.bindVertexArray(this.handle),this.device.gl.bindBuffer(34962,r.handle),c?this.device.gl.vertexAttribIPointer(e,i,s,n,a):this.device.gl.vertexAttribPointer(e,i,s,o,n,a),this.device.gl.bindBuffer(34962,null),this.device.gl.enableVertexAttribArray(e),this.device.gl.vertexAttribDivisor(e,l||0),this.attributes[e]=r,this.device.gl.bindVertexArray(null)}setConstantWebGL(e,t){this._enable(e,!1),this.attributes[e]=t}bindBeforeRender(){this.device.gl.bindVertexArray(this.handle),this._applyConstantAttributes()}unbindAfterRender(){this.device.gl.bindVertexArray(null)}_applyConstantAttributes(){for(let e=0;e<this.maxVertexAttributes;++e){const t=this.attributes[e];ArrayBuffer.isView(t)&&this.device.setConstantAttributeWebGL(e,t)}}_getAccessor(e){const t=this.attributeInfos[e];if(!t)throw new Error(`Unknown attribute location ${e}`);const r=Le(t.bufferDataType);return{size:t.bufferComponents,type:r,stride:t.byteStride,offset:t.byteOffset,normalized:t.normalized,integer:t.integer,divisor:"instance"===t.stepMode?1:0}}_enable(e,t=!0){const r=Ut.isConstantAttributeZeroSupported(this.device);(t||(r||0!==e))&&(e=Number(e),this.device.gl.bindVertexArray(this.handle),t?this.device.gl.enableVertexAttribArray(e):this.device.gl.disableVertexAttribArray(e),this.device.gl.bindVertexArray(null))}getConstantBuffer(e,t){const r=function(e){if(Array.isArray(e))return new Float32Array(e);return e}(t),i=r.byteLength*e,s=r.length*e;if(this.buffer&&i!==this.buffer.byteLength)throw new Error(`Buffer size is immutable, byte length ${i} !== ${this.buffer.byteLength}.`);let n=!this.buffer;if(this.buffer=this.buffer||this.device.createBuffer({byteLength:i}),n||=!function(e,t){if(!e||!t||e.length!==t.length||e.constructor!==t.constructor)return!1;for(let r=0;r<e.length;++r)if(e[r]!==t[r])return!1;return!0}(r,this.bufferValue),n){const e=function(e,t){return new e(ne(e.BYTES_PER_ELEMENT*t),0,t)}(t.constructor,s);!function(e){const{target:t,source:r,start:i=0,count:s=1}=e,n=r.length,a=s*n;let o=0;for(let c=i;o<n;o++)t[c++]=r[o]??0;for(;o<a;)o<a-o?(t.copyWithin(i+o,i,i+o),o*=2):(t.copyWithin(i+o,i,i+a-o),o=a);e.target}({target:e,source:r,start:0,count:s}),this.buffer.write(e),this.bufferValue=t}return this.buffer}}class Vt extends Z{device;gl;handle;layout;buffers={};unusedBuffers={};bindOnUse=!0;_bound=!1;constructor(e,t){super(e,t),this.device=e,this.gl=e.gl,this.handle=this.props.handle||this.gl.createTransformFeedback(),this.layout=this.props.layout,t.buffers&&this.setBuffers(t.buffers),Object.seal(this)}destroy(){this.gl.deleteTransformFeedback(this.handle),super.destroy()}begin(e="point-list"){this.gl.bindTransformFeedback(36386,this.handle),this.bindOnUse&&this._bindBuffers(),this.gl.beginTransformFeedback(function(e){switch(e){case"point-list":return 0;case"line-list":case"line-strip":return 1;case"triangle-list":case"triangle-strip":return 4;default:throw new Error(e)}}(e))}end(){this.gl.endTransformFeedback(),this.bindOnUse&&this._unbindBuffers(),this.gl.bindTransformFeedback(36386,null)}setBuffers(e){this.buffers={},this.unusedBuffers={},this.bind(()=>{for(const[t,r]of Object.entries(e))this.setBuffer(t,r)})}setBuffer(e,t){const r=this._getVaryingIndex(e),{buffer:i,byteLength:s,byteOffset:a}=this._getBufferRange(t);if(r<0)return this.unusedBuffers[e]=i,void n.warn(`${this.id} unusedBuffers varying buffer ${e}`)();this.buffers[r]={buffer:i,byteLength:s,byteOffset:a},this.bindOnUse||this._bindBuffer(r,i,a,s)}getBuffer(e){if(jt(e))return this.buffers[e]||null;const t=this._getVaryingIndex(e);return this.buffers[t]??null}bind(e=this.handle){if("function"!=typeof e)return this.gl.bindTransformFeedback(36386,e),this;let t;return this._bound?t=e():(this.gl.bindTransformFeedback(36386,this.handle),this._bound=!0,t=e(),this._bound=!1,this.gl.bindTransformFeedback(36386,null)),t}unbind(){this.bind(null)}_getBufferRange(e){if(e instanceof it)return{buffer:e,byteOffset:0,byteLength:e.byteLength};const{buffer:t,byteOffset:r=0,byteLength:i=e.buffer.byteLength}=e;return{buffer:t,byteOffset:r,byteLength:i}}_getVaryingIndex(e){if(jt(e))return Number(e);for(const t of this.layout.varyings||[])if(e===t.name)return t.location;return-1}_bindBuffers(){for(const[e,t]of Object.entries(this.buffers)){const{buffer:r,byteLength:i,byteOffset:s}=this._getBufferRange(t);this._bindBuffer(Number(e),r,s,i)}}_unbindBuffers(){for(const e in this.buffers)this.gl.bindBufferBase(35982,Number(e),null)}_bindBuffer(e,t,r=0,i){const s=t&&t.handle;s&&void 0!==i?this.gl.bindBufferRange(35982,e,s,r,i):this.gl.bindBufferBase(35982,e,s)}}function jt(e){return"number"==typeof e?Number.isInteger(e):/^\d+$/.test(e)}class qt extends J{device;handle;_timestampPairs=[];_pendingReads=/* @__PURE__ */new Set;_occlusionQuery=null;_occlusionActive=!1;get[Symbol.toStringTag](){return"QuerySet"}constructor(e,t){if(super(e,t),this.device=e,"timestamp"===t.type){if(t.count<2)throw new Error("Timestamp QuerySet requires at least two query slots");this._timestampPairs=new Array(Math.ceil(t.count/2)).fill(null).map(()=>({activeQuery:null,completedQueries:[]})),this.handle=null}else{if(t.count>1)throw new Error("WebGL occlusion QuerySet can only have one value");const e=this.device.gl.createQuery();if(!e)throw new Error("WebGL query not supported");this.handle=e}Object.seal(this)}destroy(){if(!this.destroyed){this.handle&&this.device.gl.deleteQuery(this.handle);for(const e of this._timestampPairs){e.activeQuery&&(this._cancelPendingQuery(e.activeQuery),this.device.gl.deleteQuery(e.activeQuery.handle));for(const t of e.completedQueries)this._cancelPendingQuery(t),this.device.gl.deleteQuery(t.handle)}this._occlusionQuery&&(this._cancelPendingQuery(this._occlusionQuery),this.device.gl.deleteQuery(this._occlusionQuery.handle));for(const e of Array.from(this._pendingReads))this._cancelPendingQuery(e);this.destroyResource()}}isResultAvailable(e){return"timestamp"===this.props.type?void 0===e?this._timestampPairs.some((e,t)=>this._isTimestampPairAvailable(t)):this._isTimestampPairAvailable(this._getTimestampPairIndex(e)):!!this._occlusionQuery&&this._pollQueryAvailability(this._occlusionQuery)}async readResults(e){const t=e?.firstQuery||0,r=e?.queryCount||this.props.count-t;if(this._validateRange(t,r),"timestamp"===this.props.type){const e=new Array(r).fill(0n),i=Math.floor(t/2),s=Math.floor((t+r-1)/2);for(let n=i;n<=s;n++){const i=await this._consumeTimestampPairResult(n),s=2*n,a=s+1;s>=t&&s<t+r&&(e[s-t]=0n),a>=t&&a<t+r&&(e[a-t]=i)}return e}if(!this._occlusionQuery)throw new Error("Occlusion query has not been started");return[await this._consumeQueryResult(this._occlusionQuery)]}async readTimestampDuration(e,t){if("timestamp"!==this.props.type)throw new Error("Timestamp durations require a timestamp QuerySet");if(e<0||t>=this.props.count||t<=e)throw new Error("Timestamp duration range is out of bounds");if(e%2!=0||t!==e+1)throw new Error("WebGL timestamp durations require adjacent even/odd query indices");const r=await this._consumeTimestampPairResult(this._getTimestampPairIndex(e));return Number(r)/1e6}beginOcclusionQuery(){if("occlusion"!==this.props.type)throw new Error("Occlusion queries require an occlusion QuerySet");if(!this.handle)throw new Error("WebGL occlusion query is not available");if(this._occlusionActive)throw new Error("Occlusion query is already active");this.device.gl.beginQuery(35887,this.handle),this._occlusionQuery={handle:this.handle,promise:null,result:null,disjoint:!1,cancelled:!1,pollRequestId:null,resolve:null,reject:null},this._occlusionActive=!0}endOcclusionQuery(){if(!this._occlusionActive)throw new Error("Occlusion query is not active");this.device.gl.endQuery(35887),this._occlusionActive=!1}writeTimestamp(e){if("timestamp"!==this.props.type)throw new Error("Timestamp writes require a timestamp QuerySet");const t=this._getTimestampPairIndex(e),r=this._timestampPairs[t];if(e%2==0){if(r.activeQuery)throw new Error("Timestamp query pair is already active");const e=this.device.gl.createQuery();if(!e)throw new Error("WebGL query not supported");const t={handle:e,promise:null,result:null,disjoint:!1,cancelled:!1,pollRequestId:null,resolve:null,reject:null};return this.device.gl.beginQuery(35007,e),void(r.activeQuery=t)}if(!r.activeQuery)throw new Error("Timestamp query pair was ended before it was started");this.device.gl.endQuery(35007),r.completedQueries.push(r.activeQuery),r.activeQuery=null}_validateRange(e,t){if(e<0||t<0||e+t>this.props.count)throw new Error("Query read range is out of bounds")}_getTimestampPairIndex(e){if(e<0||e>=this.props.count)throw new Error("Query index is out of bounds");return Math.floor(e/2)}_isTimestampPairAvailable(e){const t=this._timestampPairs[e];return!(!t||0===t.completedQueries.length)&&this._pollQueryAvailability(t.completedQueries[0])}_pollQueryAvailability(e){if(e.cancelled||this.destroyed)return e.result=0n,!0;if(null!==e.result||e.disjoint)return!0;if(!this.device.gl.getQueryParameter(e.handle,34919))return!1;const t=Boolean(this.device.gl.getParameter(36795));return e.disjoint=t,e.result=t?0n:BigInt(this.device.gl.getQueryParameter(e.handle,34918)),!0}async _consumeTimestampPairResult(e){const t=this._timestampPairs[e];if(!t||0===t.completedQueries.length)throw new Error("Timestamp query pair has no completed result");const r=t.completedQueries.shift();try{return await this._consumeQueryResult(r)}finally{this.device.gl.deleteQuery(r.handle)}}_consumeQueryResult(e){return e.promise||(this._pendingReads.add(e),e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r;const i=()=>{if(e.pollRequestId=null,e.cancelled||this.destroyed)return this._pendingReads.delete(e),e.promise=null,e.resolve=null,e.reject=null,void t(0n);this._pollQueryAvailability(e)?(this._pendingReads.delete(e),e.promise=null,e.resolve=null,e.reject=null,e.disjoint?r(new Error("GPU timestamp query was invalidated by a disjoint event")):t(e.result||0n)):e.pollRequestId=this._requestAnimationFrame(i)};i()})),e.promise}_cancelPendingQuery(e){if(this._pendingReads.delete(e),e.cancelled=!0,null!==e.pollRequestId&&(this._cancelAnimationFrame(e.pollRequestId),e.pollRequestId=null),e.resolve){const t=e.resolve;e.promise=null,e.resolve=null,e.reject=null,t(0n)}}_requestAnimationFrame(e){return requestAnimationFrame(e)}_cancelAnimationFrame(e){cancelAnimationFrame(e)}}class Ht extends ee{device;gl;handle;signaled;_signaled=!1;constructor(e,t={}){super(e,{}),this.device=e,this.gl=e.gl;const r=this.props.handle||this.gl.fenceSync(this.gl.SYNC_GPU_COMMANDS_COMPLETE,0);if(!r)throw new Error("Failed to create WebGL fence");this.handle=r,this.signaled=new Promise(e=>{const t=()=>{const r=this.gl.clientWaitSync(this.handle,0,0);r===this.gl.ALREADY_SIGNALED||r===this.gl.CONDITION_SATISFIED?(this._signaled=!0,e()):setTimeout(t,1)};t()})}isSignaled(){if(this._signaled)return!0;const e=this.gl.getSyncParameter(this.handle,this.gl.SYNC_STATUS);return this._signaled=e===this.gl.SIGNALED,this._signaled}destroy(){this.destroyed||this.gl.deleteSync(this.handle)}}function Xt(e){switch(e){case 6406:case 33326:case 6403:case 36244:return 1;case 33339:case 33340:case 33328:case 33320:case 33319:return 2;case 6407:case 36248:case 34837:return 3;case 6408:case 36249:case 34836:return 4;default:return 0}}function Yt(e,t){const{sourceX:r=0,sourceY:i=0,sourceAttachment:s=0}=t||{};let{target:n=null,sourceWidth:a,sourceHeight:o,sourceDepth:c,sourceFormat:l,sourceType:u}=t||{};const{framebuffer:h,deleteFramebuffer:d}=Kt(e),{gl:f,handle:g}=h;a||=h.width,o||=h.height;const p=h.colorAttachments[s]?.texture;if(!p)throw new Error(`Invalid framebuffer attachment ${s}`);c=p?.depth||1,l||=p?.glFormat||6408,u||=p?.glType||5121,n=function(e,t,r,i,s){if(e)return e;t||=5121;const n=yt(t),a=m.getTypedArrayConstructor(n),o=Xt(r);return new a(i*s*o)}(n,u,l,a,o);const b=m.getDataType(n);u=u||Dt[b];const y=f.bindFramebuffer(36160,g);return f.readBuffer(36064+s),f.readPixels(r,i,a,o,l,u,n),f.readBuffer(36064),f.bindFramebuffer(36160,y||null),d&&h.destroy(),n}function Kt(e){return e instanceof D?{framebuffer:e,deleteFramebuffer:!1}:{framebuffer:Zt(e),deleteFramebuffer:!0}}function Zt(e,t){const{device:r,width:i,height:s,id:n}=e;return r.createFramebuffer({...t,id:`framebuffer-for-${n}`,width:i,height:s,colorAttachments:[e]})}class Jt extends g{static getDeviceFromContext(e){return e?e.luma?.device??null:null}type="webgl";handle;features;limits;info;canvasContext;preferredColorFormat="rgba8unorm";preferredDepthFormat="depth24plus";commandEncoder;lost;_resolveContextLost;gl;_constants;extensions;_polyfilled=!1;spectorJS;get[Symbol.toStringTag](){return"WebGLDevice"}toString(){return`${this[Symbol.toStringTag]}(${this.id})`}isVertexFormatSupported(e){return"unorm8x4-bgra"!==e}constructor(e){super({...e,id:e.id||rt("webgl-device")});const t=g._getCanvasContextProps(e);if(!t)throw new Error("WebGLDevice requires props.createCanvasContext to be set");const r=t.canvas?.gl??null;let i=Jt.getDeviceFromContext(r);if(i)throw new Error(`WebGL context already attached to device ${i.id}`);this.canvasContext=new Je(this,t),this.lost=new Promise(e=>{this._resolveContextLost=e});const s={...e.webgl};"premultiplied"===t.alphaMode&&(s.premultipliedAlpha=!0),void 0!==e.powerPreference&&(s.powerPreference=e.powerPreference),void 0!==e.failIfMajorPerformanceCaveat&&(s.failIfMajorPerformanceCaveat=e.failIfMajorPerformanceCaveat);const a=this.props._handle||function(e,t,r){let i="";const s=e=>{const t=e.statusMessage;t&&(i||=t)};e.addEventListener("webglcontextcreationerror",s,!1);const n=!0!==r.failIfMajorPerformanceCaveat,a={preserveDrawingBuffer:!0,...r,failIfMajorPerformanceCaveat:!0};let o=null;try{o||=e.getContext("webgl2",a),!o&&a.failIfMajorPerformanceCaveat&&(i||="Only software GPU is available. Set `failIfMajorPerformanceCaveat: false` to allow.");let r=!1;if(!o&&n&&(a.failIfMajorPerformanceCaveat=!1,o=e.getContext("webgl2",a),r=!0),o||(o=e.getContext("webgl",{}),o&&(o=null,i||="Your browser only supports WebGL1")),!o)throw i||="Your browser does not support WebGL",new Error(`Failed to create WebGL context: ${i}`);c(o).softwareRenderer=r;const{onContextLost:s,onContextRestored:l}=t;return e.addEventListener("webglcontextlost",e=>s(e),!1),e.addEventListener("webglcontextrestored",e=>l(e),!1),o}finally{e.removeEventListener("webglcontextcreationerror",s,!1)}}(this.canvasContext.canvas,{onContextLost:e=>this._resolveContextLost?.({reason:"destroyed",message:"Entered sleep mode, or too many apps or browser tabs are using the GPU."}),onContextRestored:e=>{}},s);if(!a)throw new Error("WebGL context creation failed");if(i=Jt.getDeviceFromContext(a),i){if(e._reuseDevices)return n.log(1,`Not creating a new Device, instead returning a reference to Device ${i.id} already attached to WebGL context`,i)(),this.canvasContext.destroy(),i._reused=!0,i;throw new Error(`WebGL context already attached to device ${i.id}`)}this.handle=a,this.gl=a,this.spectorJS=p({...this.props,gl:this.handle});const o=c(this.handle);o.device=this,o.extensions||(o.extensions={}),this.extensions=o.extensions,this.info=Ce(this.gl,this.extensions),this.limits=new Ke(this.gl),this.features=new Ye(this.gl,this.extensions,this.props._disabledFeatures),this.props._initializeFeatures&&this.features.initializeFeatures();new Pe(this.gl,{log:(...e)=>n.log(1,...e)()}).trackState(this.gl,{copyState:!1}),(e.debug||e.debugWebGL)&&(this.gl=b(this.gl,{debugWebGL:!0,traceWebGL:e.debugWebGL}),n.warn("WebGL debug mode activated. Performance reduced.")()),e.debugWebGL&&(n.level=Math.max(n.level,1)),this.commandEncoder=new Nt(this,{id:`${this}-command-encoder`}),this.canvasContext._startObservers()}destroy(){if(this.commandEncoder?.destroy(),!this.props._reuseDevices&&!this._reused){c(this.handle).device=null}}get isLost(){return this.gl.isContextLost()}createCanvasContext(e){throw new Error("WebGL only supports a single canvas")}createPresentationContext(e){return new et(this,e||{})}createBuffer(e){const t=this._normalizeBufferProps(e);return new it(this,t)}createTexture(e){return new xt(this,e)}createExternalTexture(e){throw new Error("createExternalTexture() not implemented")}createSampler(e){return new gt(this,e)}createShader(e){return new nt(this,e)}createFramebuffer(e){return new Ze(this,e)}createVertexArray(e){return new Ut(this,e)}createTransformFeedback(e){return new Vt(this,e)}createQuerySet(e){return new qt(this,e)}createFence(){return new Ht(this)}createRenderPipeline(e){return new _t(this,e)}_createSharedRenderPipelineWebGL(e){return new Rt(this,e)}createComputePipeline(e){throw new Error("ComputePipeline not supported in WebGL")}createCommandEncoder(e={}){return new Nt(this,e)}submit(e){let t=null;e||({submittedCommandEncoder:t,commandBuffer:e}=this._finalizeDefaultCommandEncoderForSubmit());try{e._executeCommands(),t&&t.resolveTimeProfilingQuerySet().then(()=>{this.commandEncoder._gpuTimeMs=t._gpuTimeMs}).catch(()=>{})}finally{e.destroy()}}_finalizeDefaultCommandEncoderForSubmit(){const e=this.commandEncoder,t=e.finish();return this.commandEncoder.destroy(),this.commandEncoder=this.createCommandEncoder({id:e.props.id,timeProfilingQuerySet:e.getTimeProfilingQuerySet()}),{submittedCommandEncoder:e,commandBuffer:t}}readPixelsToArrayWebGL(e,t){return Yt(e,t)}readPixelsToBufferWebGL(e,t){return function(e,t){const{target:r,sourceX:i=0,sourceY:s=0,sourceFormat:n=6408,targetByteOffset:a=0}=t||{};let{sourceWidth:o,sourceHeight:c,sourceType:l}=t||{};const{framebuffer:u,deleteFramebuffer:h}=Kt(e);o=o||u.width,c=c||u.height;const d=u;l=l||5121;let f=r;if(!f){const e=a+o*c*Xt(n)*function(e){switch(e){case 5121:return 1;case 33635:case 32819:case 32820:return 2;case 5126:return 4;default:return 0}}(l);f=d.device.createBuffer({byteLength:e})}const m=e.device.createCommandEncoder();return m.copyTextureToBuffer({sourceTexture:e,width:o,height:c,origin:[i,s],destinationBuffer:f,byteOffset:a}),m.destroy(),h&&u.destroy(),f}(e,t)}setParametersWebGL(e){xe(this.gl,e)}getParametersWebGL(e){return we(this.gl,e)}withParametersWebGL(e,t){return pt(this.gl,e,t)}resetWebGL(){n.warn("WebGLDevice.resetWebGL is deprecated, use only for debugging")(),xe(this.gl,ae)}_getDeviceSpecificTextureFormatCapabilities(e){return je(this.gl,e,this.extensions)}loseDevice(){let e=!1;const t=this.getExtension("WEBGL_lose_context").WEBGL_lose_context;return t&&(e=!0,t.loseContext()),this._resolveContextLost?.({reason:"destroyed",message:"Application triggered context loss"}),e}pushState(){Pe.get(this.gl).push()}popState(){Pe.get(this.gl).pop()}getGLKey(e,t){const r=Number(e);for(const i in this.gl)if(this.gl[i]===r)return`GL.${i}`;return t?.emptyIfUnknown?"":String(e)}getGLKeys(e){const t={emptyIfUnknown:!0};return Object.entries(e).reduce((e,[r,i])=>(e[`${r}:${this.getGLKey(r,t)}`]=`${i}:${this.getGLKey(i,t)}`,e),{})}setConstantAttributeWebGL(e,t){const r=this.limits.maxVertexAttributes;this._constants=this._constants||new Array(r).fill(null);const i=this._constants[e];switch(i&&function(e,t){if(!e||!t||e.length!==t.length||e.constructor!==t.constructor)return!1;for(let r=0;r<e.length;++r)if(e[r]!==t[r])return!1;return!0}(i,t)&&n.info(1,`setConstantAttributeWebGL(${e}) could have been skipped, value unchanged`)(),this._constants[e]=t,t.constructor){case Float32Array:!function(e,t,r){switch(r.length){case 1:e.gl.vertexAttrib1fv(t,r);break;case 2:e.gl.vertexAttrib2fv(t,r);break;case 3:e.gl.vertexAttrib3fv(t,r);break;case 4:e.gl.vertexAttrib4fv(t,r)}}(this,e,t);break;case Int32Array:!function(e,t,r){e.gl.vertexAttribI4iv(t,r)}(this,e,t);break;case Uint32Array:!function(e,t,r){e.gl.vertexAttribI4uiv(t,r)}(this,e,t);break;default:throw new Error("constant")}}getExtension(e){return Be(this.gl,e,this.extensions),this.extensions}_setWebGLDebugMetadata(e,t,r){e.luma=t;const i={props:r.spector,id:r.spector.id};e.__SPECTOR_Metadata=i}}const er=/* @__PURE__ */Object.freeze(/* @__PURE__ */Object.defineProperty({__proto__:null,WebGLDevice:Jt},Symbol.toStringTag,{value:"Module"}));export{F as R,E as S,A as T,Jt as W,te as a,ne as b,X as c,re as d,z as g,M as n,Q as r,er as w};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gis_victory/gismap",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.66",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -27,8 +27,11 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@gis_victory/mapbox-gl": "^3.14.13",
|
|
30
|
+
"@loaders.gl/3d-tiles": "^4.4.2",
|
|
31
|
+
"@luma.gl/core": "^9.3.3",
|
|
32
|
+
"@luma.gl/engine": "^9.3.3",
|
|
30
33
|
"@turf/turf": "^7.2.0",
|
|
31
|
-
"deck.gl": "^9.
|
|
34
|
+
"deck.gl": "^9.3.2",
|
|
32
35
|
"html2canvas": "^1.4.1",
|
|
33
36
|
"jsencrypt": "^3.5.4",
|
|
34
37
|
"reflect-metadata": "^0.2.2",
|
|
@@ -40,6 +43,11 @@
|
|
|
40
43
|
"wellknown": "^0.5.0"
|
|
41
44
|
},
|
|
42
45
|
"devDependencies": {
|
|
46
|
+
"@deck.gl/core": "^9.3.2",
|
|
47
|
+
"@deck.gl/geo-layers": "^9.3.2",
|
|
48
|
+
"@deck.gl/mapbox": "^9.3.2",
|
|
49
|
+
"@loaders.gl/core": "^4.4.2",
|
|
50
|
+
"@loaders.gl/gltf": "^4.4.2",
|
|
43
51
|
"@types/shpjs": "^3.4.7",
|
|
44
52
|
"@vitejs/plugin-vue": "^6.0.1",
|
|
45
53
|
"@vue/tsconfig": "^0.7.0",
|
|
@@ -55,4 +63,4 @@
|
|
|
55
63
|
"vite-plugin-static-copy": "^2.2.0",
|
|
56
64
|
"vue-tsc": "^3.0.5"
|
|
57
65
|
}
|
|
58
|
-
}
|
|
66
|
+
}
|