const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./index-T8LZyOXI.js","./index-BkylzejB.js","./index-BePrKqlS.css","./pass.fragment-DcYb4VZg.js"])))=>i.map(i=>d[i]);
import{af as y}from"./index-BkylzejB.js";import{aB as A,d,L as v,aC as b,aq as g,aD as T,aE as C,_ as I,aF as x}from"./index-T8LZyOXI.js";let c=null;async function S(){const n=g.LastCreatedEngine?.createCanvas(100,100)??new OffscreenCanvas(100,100);n instanceof OffscreenCanvas&&v.Warn("DumpData: OffscreenCanvas will be used for dumping data. This may result in lossy alpha values.");const{ThinEngine:i}=await y(async()=>{const{ThinEngine:t}=await import("./index-T8LZyOXI.js").then(a=>a.cv);return{ThinEngine:t}},__vite__mapDeps([0,1,2]),import.meta.url);if(!i.IsSupported)throw new Error("DumpData: No WebGL context available. Cannot dump data.");const r={preserveDrawingBuffer:!0,depth:!1,stencil:!1,alpha:!0,premultipliedAlpha:!1,antialias:!1,failIfMajorPerformanceCaveat:!1},e=new i(n,!1,r);g.Instances.pop(),g.OnEnginesDisposedObservable.add(t=>{e&&t!==e&&!e.isDisposed&&g.Instances.length===0&&_()}),e.getCaps().parallelShaderCompile=void 0;const o=new T(e),{passPixelShader:s}=await y(async()=>{const{passPixelShader:t}=await import("./pass.fragment-DcYb4VZg.js");return{passPixelShader:t}},__vite__mapDeps([3,0,1,2]),import.meta.url),p=new C({engine:e,name:s.name,fragmentShader:s.shader,samplerNames:["textureSampler"]});return{canvas:n,dumpEngine:{engine:e,renderer:o,wrapper:p}}}async function P(){return c||(c=S()),await c}class E{static async EncodeImageAsync(i,r,e,o,s,p){const t=await P(),a=t.dumpEngine;a.engine.setSize(r,e,!0);const f=a.engine.createRawTexture(i,r,e,5,!1,!s,1);return a.renderer.setViewport(),a.renderer.applyEffectWrapper(a.wrapper),a.wrapper.effect._bindTexture("textureSampler",f),a.renderer.draw(),f.dispose(),await new Promise((l,u)=>{d.ToBlob(t.canvas,m=>{m?l(m):u(new Error("EncodeImageAsync: Failed to convert canvas to blob."))},o,p)})}}I([x],E,"EncodeImageAsync",null);const R=E.EncodeImageAsync;async function h(n,i,r,e,o="image/png",s,p){const t=await r.readPixels(0,0,n,i),a=new Uint8Array(t.buffer);D(n,i,a,e,o,s,!0,void 0,p)}async function w(n,i,r,e="image/png",o,s=!1,p=!1,t){if(r instanceof Float32Array){const l=new Uint8Array(r.length);let u=r.length;for(;u--;){const m=r[u];l[u]=Math.round(A(m)*255)}r=l}const a=await E.EncodeImageAsync(r,n,i,e,s,t);o!==void 0&&d.DownloadBlob(a,o),a.type!==e&&v.Warn(`DumpData: The requested mimeType '${e}' is not supported. The result has mimeType '${a.type}' instead.`);const f=await a.arrayBuffer();return p?f:`data:${e};base64,${b(f)}`}function D(n,i,r,e,o="image/png",s,p=!1,t=!1,a){s===void 0&&!e&&(s=""),w(n,i,r,o,s,p,t,a).then(f=>{e&&e(f)})}function _(){c&&(c?.then(n=>{n.canvas instanceof HTMLCanvasElement&&n.canvas.remove(),n.dumpEngine&&(n.dumpEngine.engine.dispose(),n.dumpEngine.renderer.dispose(),n.dumpEngine.wrapper.dispose())}),c=null)}const F={DumpData:D,DumpDataAsync:w,DumpFramebuffer:h,Dispose:_},O=()=>{d.DumpData=D,d.DumpDataAsync=w,d.DumpFramebuffer=h};O();export{_ as Dispose,D as DumpData,w as DumpDataAsync,h as DumpFramebuffer,F as DumpTools,R as EncodeImageAsync};
