micugl 0.0.13 → 0.0.16
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/core/managers/WebGLManager.d.ts +1 -1
- package/dist/core/managers/WebGLManager.js +1 -1
- package/dist/core/managers/WebGLManager.mjs +119 -92
- package/dist/react/components/engine/PingPongShaderEngine.d.ts +6 -1
- package/dist/react/components/engine/PingPongShaderEngine.js +1 -1
- package/dist/react/components/engine/PingPongShaderEngine.mjs +65 -53
- package/dist/react/components/engine/ShaderEngine.js +1 -1
- package/dist/react/components/engine/ShaderEngine.mjs +52 -48
- package/dist/react/hooks/usePingPongPasses.d.ts +4 -5
- package/dist/react/hooks/usePingPongPasses.js +1 -1
- package/dist/react/hooks/usePingPongPasses.mjs +93 -78
- package/package.json +7 -3
|
@@ -21,7 +21,7 @@ export declare class WebGLManager {
|
|
|
21
21
|
updateBuffer(programId: string, attributeName: string, data: Float32Array | Uint8Array | Uint16Array): void;
|
|
22
22
|
registerUniformUpdater<T extends UniformType>(programId: string, uniformName: string, type: T, updateFn: UniformUpdateFn<T>): void;
|
|
23
23
|
updateUniforms(programId: string, time: number): void;
|
|
24
|
-
setSize(
|
|
24
|
+
setSize(renderWidth: number, renderHeight: number, displayWidth?: number, displayHeight?: number): void;
|
|
25
25
|
prepareRender(programId: string, options?: RenderOptions): void;
|
|
26
26
|
fastRender(programId: string, time: number, clear?: boolean): void;
|
|
27
27
|
setUniform<T extends UniformType>(programId: string, uniformName: string, value: UniformTypeMap[T], type: T): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var b=Object.defineProperty;var A=(d,e,o)=>e in d?b(d,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):d[e]=o;var w=(d,e,o)=>A(d,typeof e!="symbol"?e+"":e,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("./FBOManager.js");class v{constructor(e,o){w(this,"gl");w(this,"fboManager");w(this,"resources",new Map);w(this,"compileCache",new Map);w(this,"uniformUpdateFns",new Map);w(this,"extensions",new Map);const t={alpha:!1,depth:!1,stencil:!1,antialias:!1,powerPreference:"low-power",preserveDrawingBuffer:!1},r=e.getContext("webgl",{...t,...o});if(!r)throw new Error("WebGL not supported");this.gl=r,this.fboManager=new E.FBOManager(r),this.getExtension("OES_texture_float"),this.getExtension("OES_texture_float_linear"),this.getExtension("OES_vertex_array_object"),this.getExtension("ANGLE_instanced_arrays")}getExtension(e){if(this.extensions.has(e))return this.extensions.get(e);const o=this.gl.getExtension(e);return this.extensions.set(e,o),o}createProgram(e,o){const{vertexShader:t,fragmentShader:r,uniforms:s,attributes:f}=o,n=this.gl,u=this.getOrCompileShader("vertex:"+t,n.VERTEX_SHADER,t),m=this.getOrCompileShader("fragment:"+r,n.FRAGMENT_SHADER,r),i=n.createProgram();if(!i)throw new Error("Failed to create WebGL program");if(n.attachShader(i,u),n.attachShader(i,m),n.linkProgram(i),!n.getProgramParameter(i,n.LINK_STATUS)){const a=n.getProgramInfoLog(i);throw n.deleteProgram(i),new Error(`Could not link shader program: ${a}`)}const l={};for(const a of s)l[a.name]=n.getUniformLocation(i,a.name);const h={};if(f)for(const a of f)h[a.name]=n.getAttribLocation(i,a.name);const c={program:i,uniforms:l,attributes:h,buffers:{}};return this.resources.set(e,c),this.uniformUpdateFns.set(e,new Map),c}getOrCompileShader(e,o,t){if(this.compileCache.has(e)){const s=this.compileCache.get(e);if(s)return s}const r=this.compileShader(o,t);return this.compileCache.set(e,r),r}compileShader(e,o){const t=this.gl,r=t.createShader(e);if(!r)throw new Error("Failed to create shader");if(t.shaderSource(r,o),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS)){const s=t.getShaderInfoLog(r);throw t.deleteShader(r),new Error(`Shader compilation failed: ${s}`)}return r}createBuffer(e,o,t){const r=this.gl,s=this.resources.get(e);if(!s)throw new Error(`Program with id ${e} not found`);const f=r.createBuffer();if(!f)throw new Error("Failed to create buffer");return r.bindBuffer(r.ARRAY_BUFFER,f),r.bufferData(r.ARRAY_BUFFER,t,r.STATIC_DRAW),s.buffers[o]={buffer:f,data:t},f}updateBuffer(e,o,t){const r=this.gl,s=this.resources.get(e);if(!s)throw new Error(`Program with id ${e} not found`);const f=s.buffers[o];if(!f)throw new Error(`Buffer for attribute ${o} not found`);r.bindBuffer(r.ARRAY_BUFFER,f.buffer),r.bufferData(r.ARRAY_BUFFER,t,r.STATIC_DRAW),f.data=t}registerUniformUpdater(e,o,t,r){const s=this.resources.get(e);if(!s)throw new Error(`Program with id ${e} not found`);const f=this.uniformUpdateFns.get(e);if(!f)throw new Error(`Program uniforms for id ${e} not found`);const n=s.uniforms[o];if(n===null)return;const u=this.gl;let m;switch(t){case"int":m=(i,l,h)=>{const c=r(i,l,h);return u.uniform1i(n,c),c};break;case"float":m=(i,l,h)=>{const c=r(i,l,h);return u.uniform1f(n,c),c};break;case"sampler2D":m=(i,l,h)=>{const c=r(i,l,h);return u.uniform1i(n,c),c};break;case"vec2":{const i=new Float32Array(2);m=(l,h,c)=>{const a=r(l,h,c);return Array.isArray(a)?(i[0]=a[0],i[1]=a[1],u.uniform2fv(n,i)):u.uniform2fv(n,a),i};break}case"vec3":{const i=new Float32Array(3);m=(l,h,c)=>{const a=r(l,h,c);return Array.isArray(a)?(i[0]=a[0],i[1]=a[1],i[2]=a[2],u.uniform3fv(n,i)):u.uniform3fv(n,a),i};break}case"vec4":{const i=new Float32Array(4);m=(l,h,c)=>{const a=r(l,h,c);return Array.isArray(a)?(i[0]=a[0],i[1]=a[1],i[2]=a[2],i[3]=a[3],u.uniform4fv(n,i)):u.uniform4fv(n,a),i};break}case"mat2":{const i=new Float32Array(4);m=(l,h,c)=>{const a=r(l,h,c);if(Array.isArray(a)){for(let g=0;g<4;g++)i[g]=a[g];u.uniformMatrix2fv(n,!1,i)}else u.uniformMatrix2fv(n,!1,a);return i};break}case"mat3":{const i=new Float32Array(9);m=(l,h,c)=>{const a=r(l,h,c);if(Array.isArray(a)){for(let g=0;g<9;g++)i[g]=a[g];u.uniformMatrix3fv(n,!1,i)}else u.uniformMatrix3fv(n,!1,a);return i};break}case"mat4":{const i=new Float32Array(16);m=(l,h,c)=>{const a=r(l,h,c);if(Array.isArray(a)){for(let g=0;g<16;g++)i[g]=a[g];u.uniformMatrix4fv(n,!1,i)}else u.uniformMatrix4fv(n,!1,a);return i};break}default:throw new Error(`Unsupported uniform type: ${t}`)}f.set(o,m)}updateUniforms(e,o){const t=this.uniformUpdateFns.get(e);if(!t)return;const r=this.gl.canvas,s=r.width,f=r.height;t.forEach(n=>{n(o,s,f)})}setSize(e,o,t,r){const s=this.gl.canvas,f=t??e,n=r??o;(s.width!==e||s.height!==o)&&(s.width=e,s.height=o,this.gl.viewport(0,0,e,o)),s.style.width=`${f}px`,s.style.height=`${n}px`}prepareRender(e,o={}){const{clear:t=!0,clearColor:r=[0,0,0,1]}=o,s=this.gl,f=this.resources.get(e);if(!f)throw new Error(`Program with id ${e} not found`);s.useProgram(f.program),t&&(s.clearColor(...r),s.clear(s.COLOR_BUFFER_BIT))}fastRender(e,o,t=!0){const r=this.gl,s=this.resources.get(e);if(!s)throw new Error(`Program with id ${e} not found`);r.useProgram(s.program),t&&r.clear(r.COLOR_BUFFER_BIT),this.updateUniforms(e,o)}setUniform(e,o,t,r){const s=this.gl,f=this.resources.get(e);if(!f)throw new Error(`Program with id ${e} not found`);const n=f.uniforms[o];if(n!==null)switch(s.useProgram(f.program),r){case"float":s.uniform1f(n,t);break;case"vec2":s.uniform2fv(n,t);break;case"vec3":s.uniform3fv(n,t);break;case"vec4":s.uniform4fv(n,t);break;case"int":s.uniform1i(n,t);break;case"mat2":s.uniformMatrix2fv(n,!1,t);break;case"mat3":s.uniformMatrix3fv(n,!1,t);break;case"mat4":s.uniformMatrix4fv(n,!1,t);break;case"sampler2D":s.uniform1i(n,t);break;default:throw new Error(`Unsupported uniform type: ${r}`)}}setAttributeOnce(e,o,t){const r=this.gl,s=this.resources.get(e);if(!s)throw new Error(`Program with id ${e} not found`);const f=s.attributes[o];if(f===-1){console.warn(`Attribute ${o} not found or is unused`);return}const n=s.buffers[o];if(!n)throw new Error(`Buffer for attribute ${o} not found`);if(r.bindBuffer(r.ARRAY_BUFFER,n.buffer),r.enableVertexAttribArray(f),r.vertexAttribPointer(f,t.size,r[t.type],t.normalized,t.stride,t.offset),t.instanced){const u=this.getExtension("ANGLE_instanced_arrays");if(u!=null&&u.vertexAttribDivisorANGLE)u.vertexAttribDivisorANGLE(f,1);else if(r.vertexAttribDivisor)r.vertexAttribDivisor(f,1);else throw new Error("Instanced rendering not supported")}}drawArrays(e,o,t){this.gl.drawArrays(e,o,t)}drawElements(e,o,t,r){this.gl.drawElements(e,o,t,r)}destroy(e){const o=this.gl,t=this.resources.get(e);t&&(Object.values(t.buffers).forEach(({buffer:r})=>{o.deleteBuffer(r)}),o.deleteProgram(t.program),this.resources.delete(e),this.uniformUpdateFns.delete(e))}destroyAll(){for(const e of Array.from(this.resources.keys()))this.destroy(e);this.compileCache.clear(),this.fboManager.destroyAll()}get context(){return this.gl}get fbo(){return this.fboManager}}exports.WebGLManager=v;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var b = Object.defineProperty;
|
|
2
|
+
var A = (d, e, o) => e in d ? b(d, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : d[e] = o;
|
|
3
|
+
var w = (d, e, o) => A(d, typeof e != "symbol" ? e + "" : e, o);
|
|
4
4
|
import { FBOManager as E } from "./FBOManager.mjs";
|
|
5
|
-
class
|
|
5
|
+
class x {
|
|
6
6
|
constructor(e, o) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
w(this, "gl");
|
|
8
|
+
w(this, "fboManager");
|
|
9
|
+
w(this, "resources", /* @__PURE__ */ new Map());
|
|
10
|
+
w(this, "compileCache", /* @__PURE__ */ new Map());
|
|
11
|
+
w(this, "uniformUpdateFns", /* @__PURE__ */ new Map());
|
|
12
|
+
w(this, "extensions", /* @__PURE__ */ new Map());
|
|
13
13
|
const t = {
|
|
14
14
|
alpha: !1,
|
|
15
15
|
depth: !1,
|
|
@@ -29,27 +29,27 @@ class A {
|
|
|
29
29
|
return this.extensions.set(e, o), o;
|
|
30
30
|
}
|
|
31
31
|
createProgram(e, o) {
|
|
32
|
-
const { vertexShader: t, fragmentShader: r, uniforms: s, attributes:
|
|
33
|
-
if (!
|
|
32
|
+
const { vertexShader: t, fragmentShader: r, uniforms: s, attributes: f } = o, n = this.gl, u = this.getOrCompileShader("vertex:" + t, n.VERTEX_SHADER, t), m = this.getOrCompileShader("fragment:" + r, n.FRAGMENT_SHADER, r), i = n.createProgram();
|
|
33
|
+
if (!i)
|
|
34
34
|
throw new Error("Failed to create WebGL program");
|
|
35
|
-
if (n.attachShader(
|
|
36
|
-
const
|
|
37
|
-
throw n.deleteProgram(
|
|
35
|
+
if (n.attachShader(i, u), n.attachShader(i, m), n.linkProgram(i), !n.getProgramParameter(i, n.LINK_STATUS)) {
|
|
36
|
+
const a = n.getProgramInfoLog(i);
|
|
37
|
+
throw n.deleteProgram(i), new Error(`Could not link shader program: ${a}`);
|
|
38
38
|
}
|
|
39
|
-
const
|
|
40
|
-
for (const
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
for (const
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
program:
|
|
48
|
-
uniforms:
|
|
49
|
-
attributes:
|
|
39
|
+
const l = {};
|
|
40
|
+
for (const a of s)
|
|
41
|
+
l[a.name] = n.getUniformLocation(i, a.name);
|
|
42
|
+
const h = {};
|
|
43
|
+
if (f)
|
|
44
|
+
for (const a of f)
|
|
45
|
+
h[a.name] = n.getAttribLocation(i, a.name);
|
|
46
|
+
const c = {
|
|
47
|
+
program: i,
|
|
48
|
+
uniforms: l,
|
|
49
|
+
attributes: h,
|
|
50
50
|
buffers: {}
|
|
51
51
|
};
|
|
52
|
-
return this.resources.set(e,
|
|
52
|
+
return this.resources.set(e, c), this.uniformUpdateFns.set(e, /* @__PURE__ */ new Map()), c;
|
|
53
53
|
}
|
|
54
54
|
getOrCompileShader(e, o, t) {
|
|
55
55
|
if (this.compileCache.has(e)) {
|
|
@@ -74,110 +74,137 @@ class A {
|
|
|
74
74
|
const r = this.gl, s = this.resources.get(e);
|
|
75
75
|
if (!s)
|
|
76
76
|
throw new Error(`Program with id ${e} not found`);
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
77
|
+
const f = r.createBuffer();
|
|
78
|
+
if (!f)
|
|
79
79
|
throw new Error("Failed to create buffer");
|
|
80
|
-
return r.bindBuffer(r.ARRAY_BUFFER,
|
|
80
|
+
return r.bindBuffer(r.ARRAY_BUFFER, f), r.bufferData(r.ARRAY_BUFFER, t, r.STATIC_DRAW), s.buffers[o] = { buffer: f, data: t }, f;
|
|
81
81
|
}
|
|
82
82
|
updateBuffer(e, o, t) {
|
|
83
83
|
const r = this.gl, s = this.resources.get(e);
|
|
84
84
|
if (!s)
|
|
85
85
|
throw new Error(`Program with id ${e} not found`);
|
|
86
|
-
const
|
|
87
|
-
if (!
|
|
86
|
+
const f = s.buffers[o];
|
|
87
|
+
if (!f)
|
|
88
88
|
throw new Error(`Buffer for attribute ${o} not found`);
|
|
89
|
-
r.bindBuffer(r.ARRAY_BUFFER,
|
|
89
|
+
r.bindBuffer(r.ARRAY_BUFFER, f.buffer), r.bufferData(r.ARRAY_BUFFER, t, r.STATIC_DRAW), f.data = t;
|
|
90
90
|
}
|
|
91
91
|
registerUniformUpdater(e, o, t, r) {
|
|
92
92
|
const s = this.resources.get(e);
|
|
93
93
|
if (!s)
|
|
94
94
|
throw new Error(`Program with id ${e} not found`);
|
|
95
|
-
const
|
|
96
|
-
if (!
|
|
95
|
+
const f = this.uniformUpdateFns.get(e);
|
|
96
|
+
if (!f)
|
|
97
97
|
throw new Error(`Program uniforms for id ${e} not found`);
|
|
98
98
|
const n = s.uniforms[o];
|
|
99
99
|
if (n === null)
|
|
100
100
|
return;
|
|
101
|
-
const
|
|
102
|
-
let
|
|
101
|
+
const u = this.gl;
|
|
102
|
+
let m;
|
|
103
103
|
switch (t) {
|
|
104
104
|
case "int":
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
return
|
|
105
|
+
m = (i, l, h) => {
|
|
106
|
+
const c = r(i, l, h);
|
|
107
|
+
return u.uniform1i(n, c), c;
|
|
108
108
|
};
|
|
109
109
|
break;
|
|
110
110
|
case "float":
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
return
|
|
111
|
+
m = (i, l, h) => {
|
|
112
|
+
const c = r(i, l, h);
|
|
113
|
+
return u.uniform1f(n, c), c;
|
|
114
114
|
};
|
|
115
115
|
break;
|
|
116
116
|
case "sampler2D":
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
return
|
|
117
|
+
m = (i, l, h) => {
|
|
118
|
+
const c = r(i, l, h);
|
|
119
|
+
return u.uniform1i(n, c), c;
|
|
120
120
|
};
|
|
121
121
|
break;
|
|
122
|
-
case "vec2":
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
case "vec2": {
|
|
123
|
+
const i = new Float32Array(2);
|
|
124
|
+
m = (l, h, c) => {
|
|
125
|
+
const a = r(l, h, c);
|
|
126
|
+
return Array.isArray(a) ? (i[0] = a[0], i[1] = a[1], u.uniform2fv(n, i)) : u.uniform2fv(n, a), i;
|
|
126
127
|
};
|
|
127
128
|
break;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
}
|
|
130
|
+
case "vec3": {
|
|
131
|
+
const i = new Float32Array(3);
|
|
132
|
+
m = (l, h, c) => {
|
|
133
|
+
const a = r(l, h, c);
|
|
134
|
+
return Array.isArray(a) ? (i[0] = a[0], i[1] = a[1], i[2] = a[2], u.uniform3fv(n, i)) : u.uniform3fv(n, a), i;
|
|
132
135
|
};
|
|
133
136
|
break;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
137
|
+
}
|
|
138
|
+
case "vec4": {
|
|
139
|
+
const i = new Float32Array(4);
|
|
140
|
+
m = (l, h, c) => {
|
|
141
|
+
const a = r(l, h, c);
|
|
142
|
+
return Array.isArray(a) ? (i[0] = a[0], i[1] = a[1], i[2] = a[2], i[3] = a[3], u.uniform4fv(n, i)) : u.uniform4fv(n, a), i;
|
|
138
143
|
};
|
|
139
144
|
break;
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
}
|
|
146
|
+
case "mat2": {
|
|
147
|
+
const i = new Float32Array(4);
|
|
148
|
+
m = (l, h, c) => {
|
|
149
|
+
const a = r(l, h, c);
|
|
150
|
+
if (Array.isArray(a)) {
|
|
151
|
+
for (let g = 0; g < 4; g++) i[g] = a[g];
|
|
152
|
+
u.uniformMatrix2fv(n, !1, i);
|
|
153
|
+
} else
|
|
154
|
+
u.uniformMatrix2fv(n, !1, a);
|
|
155
|
+
return i;
|
|
144
156
|
};
|
|
145
157
|
break;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
158
|
+
}
|
|
159
|
+
case "mat3": {
|
|
160
|
+
const i = new Float32Array(9);
|
|
161
|
+
m = (l, h, c) => {
|
|
162
|
+
const a = r(l, h, c);
|
|
163
|
+
if (Array.isArray(a)) {
|
|
164
|
+
for (let g = 0; g < 9; g++) i[g] = a[g];
|
|
165
|
+
u.uniformMatrix3fv(n, !1, i);
|
|
166
|
+
} else
|
|
167
|
+
u.uniformMatrix3fv(n, !1, a);
|
|
168
|
+
return i;
|
|
150
169
|
};
|
|
151
170
|
break;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
171
|
+
}
|
|
172
|
+
case "mat4": {
|
|
173
|
+
const i = new Float32Array(16);
|
|
174
|
+
m = (l, h, c) => {
|
|
175
|
+
const a = r(l, h, c);
|
|
176
|
+
if (Array.isArray(a)) {
|
|
177
|
+
for (let g = 0; g < 16; g++) i[g] = a[g];
|
|
178
|
+
u.uniformMatrix4fv(n, !1, i);
|
|
179
|
+
} else
|
|
180
|
+
u.uniformMatrix4fv(n, !1, a);
|
|
181
|
+
return i;
|
|
156
182
|
};
|
|
157
183
|
break;
|
|
184
|
+
}
|
|
158
185
|
default:
|
|
159
186
|
throw new Error(`Unsupported uniform type: ${t}`);
|
|
160
187
|
}
|
|
161
|
-
|
|
188
|
+
f.set(o, m);
|
|
162
189
|
}
|
|
163
190
|
updateUniforms(e, o) {
|
|
164
191
|
const t = this.uniformUpdateFns.get(e);
|
|
165
192
|
if (!t)
|
|
166
193
|
return;
|
|
167
|
-
const r = this.gl.canvas, s = r.width,
|
|
194
|
+
const r = this.gl.canvas, s = r.width, f = r.height;
|
|
168
195
|
t.forEach((n) => {
|
|
169
|
-
n(o, s,
|
|
196
|
+
n(o, s, f);
|
|
170
197
|
});
|
|
171
198
|
}
|
|
172
|
-
setSize(e, o, t
|
|
173
|
-
const
|
|
174
|
-
(
|
|
199
|
+
setSize(e, o, t, r) {
|
|
200
|
+
const s = this.gl.canvas, f = t ?? e, n = r ?? o;
|
|
201
|
+
(s.width !== e || s.height !== o) && (s.width = e, s.height = o, this.gl.viewport(0, 0, e, o)), s.style.width = `${f}px`, s.style.height = `${n}px`;
|
|
175
202
|
}
|
|
176
203
|
prepareRender(e, o = {}) {
|
|
177
|
-
const { clear: t = !0, clearColor: r = [0, 0, 0, 1] } = o, s = this.gl,
|
|
178
|
-
if (!
|
|
204
|
+
const { clear: t = !0, clearColor: r = [0, 0, 0, 1] } = o, s = this.gl, f = this.resources.get(e);
|
|
205
|
+
if (!f)
|
|
179
206
|
throw new Error(`Program with id ${e} not found`);
|
|
180
|
-
s.useProgram(
|
|
207
|
+
s.useProgram(f.program), t && (s.clearColor(...r), s.clear(s.COLOR_BUFFER_BIT));
|
|
181
208
|
}
|
|
182
209
|
fastRender(e, o, t = !0) {
|
|
183
210
|
const r = this.gl, s = this.resources.get(e);
|
|
@@ -186,12 +213,12 @@ class A {
|
|
|
186
213
|
r.useProgram(s.program), t && r.clear(r.COLOR_BUFFER_BIT), this.updateUniforms(e, o);
|
|
187
214
|
}
|
|
188
215
|
setUniform(e, o, t, r) {
|
|
189
|
-
const s = this.gl,
|
|
190
|
-
if (!
|
|
216
|
+
const s = this.gl, f = this.resources.get(e);
|
|
217
|
+
if (!f)
|
|
191
218
|
throw new Error(`Program with id ${e} not found`);
|
|
192
|
-
const n =
|
|
219
|
+
const n = f.uniforms[o];
|
|
193
220
|
if (n !== null)
|
|
194
|
-
switch (s.useProgram(
|
|
221
|
+
switch (s.useProgram(f.program), r) {
|
|
195
222
|
case "float":
|
|
196
223
|
s.uniform1f(n, t);
|
|
197
224
|
break;
|
|
@@ -227,27 +254,27 @@ class A {
|
|
|
227
254
|
const r = this.gl, s = this.resources.get(e);
|
|
228
255
|
if (!s)
|
|
229
256
|
throw new Error(`Program with id ${e} not found`);
|
|
230
|
-
const
|
|
231
|
-
if (
|
|
257
|
+
const f = s.attributes[o];
|
|
258
|
+
if (f === -1) {
|
|
232
259
|
console.warn(`Attribute ${o} not found or is unused`);
|
|
233
260
|
return;
|
|
234
261
|
}
|
|
235
262
|
const n = s.buffers[o];
|
|
236
263
|
if (!n)
|
|
237
264
|
throw new Error(`Buffer for attribute ${o} not found`);
|
|
238
|
-
if (r.bindBuffer(r.ARRAY_BUFFER, n.buffer), r.enableVertexAttribArray(
|
|
239
|
-
|
|
265
|
+
if (r.bindBuffer(r.ARRAY_BUFFER, n.buffer), r.enableVertexAttribArray(f), r.vertexAttribPointer(
|
|
266
|
+
f,
|
|
240
267
|
t.size,
|
|
241
268
|
r[t.type],
|
|
242
269
|
t.normalized,
|
|
243
270
|
t.stride,
|
|
244
271
|
t.offset
|
|
245
272
|
), t.instanced) {
|
|
246
|
-
const
|
|
247
|
-
if (
|
|
248
|
-
|
|
273
|
+
const u = this.getExtension("ANGLE_instanced_arrays");
|
|
274
|
+
if (u != null && u.vertexAttribDivisorANGLE)
|
|
275
|
+
u.vertexAttribDivisorANGLE(f, 1);
|
|
249
276
|
else if (r.vertexAttribDivisor)
|
|
250
|
-
r.vertexAttribDivisor(
|
|
277
|
+
r.vertexAttribDivisor(f, 1);
|
|
251
278
|
else
|
|
252
279
|
throw new Error("Instanced rendering not supported");
|
|
253
280
|
}
|
|
@@ -277,5 +304,5 @@ class A {
|
|
|
277
304
|
}
|
|
278
305
|
}
|
|
279
306
|
export {
|
|
280
|
-
|
|
307
|
+
x as WebGLManager
|
|
281
308
|
};
|
|
@@ -6,7 +6,12 @@ interface PingPongShaderEngineProps {
|
|
|
6
6
|
framebuffers?: Record<string, FramebufferOptions>;
|
|
7
7
|
className?: string;
|
|
8
8
|
style?: CSSProperties;
|
|
9
|
+
width?: number;
|
|
10
|
+
height?: number;
|
|
11
|
+
renderWidth?: number;
|
|
12
|
+
renderHeight?: number;
|
|
9
13
|
useDevicePixelRatio?: boolean;
|
|
14
|
+
pixelRatio?: number;
|
|
10
15
|
}
|
|
11
|
-
export declare const PingPongShaderEngine: ({ programConfigs, passes, framebuffers, className, style, useDevicePixelRatio }: PingPongShaderEngineProps) => import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export declare const PingPongShaderEngine: ({ programConfigs, passes, framebuffers, className, style, width, height, renderWidth, renderHeight, useDevicePixelRatio, pixelRatio }: PingPongShaderEngineProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
17
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("react/jsx-runtime"),r=require("react"),q=require("../../../core/managers/WebGLManager.js"),W=require("../../../core/systems/Passes.js"),x="",O={};function M(a){return a.map(c=>`${c.programId}|${c.outputFramebuffer??"screen"}|${c.inputTextures.map(o=>o.id).join(",")}`).join("||")}const k=({programConfigs:a,passes:c,framebuffers:o,className:A=x,style:F=O,width:w,height:g,renderWidth:h,renderHeight:R,useDevicePixelRatio:y=!0,pixelRatio:E})=>{const u=r.useRef(null),s=r.useRef(null),l=r.useRef(null),d=r.useRef(null),b=r.useRef(0),m=r.useRef(""),p=r.useRef(e=>{const t=s.current,n=l.current;if(!t||!n)return;const i=e-b.current;n.execute(i),d.current=requestAnimationFrame(p.current)}),f=r.useCallback(()=>{if(!u.current||!s.current)return;const e=w??window.innerWidth,t=g??window.innerHeight,n=E??(y?window.devicePixelRatio:1),i=h??Math.floor(e*n),L=R??Math.floor(t*n);s.current.setSize(i,L,e,t);const S=s.current,P=S.context.canvas;Object.entries(o??{}).forEach(([j,_])=>{const v=_.width||P.width,z=_.height||P.height;S.fbo.resizeFramebuffer(j,v,z)})},[o,w,g,h,R,y,E]);return r.useEffect(()=>{if(!u.current)return;const e=new q.WebGLManager(u.current);s.current=e,Object.entries(a).forEach(([n,i])=>{e.createProgram(n,i)}),Object.entries(o??{}).forEach(([n,i])=>{e.fbo.createFramebuffer(n,i)});const t=new W.Passes(e);return l.current=t,c.forEach(n=>{t.addPass(n)}),m.current=M(c),t.initializeResources(),f(),b.current=performance.now(),d.current=requestAnimationFrame(p.current),window.addEventListener("resize",f),()=>{window.removeEventListener("resize",f),d.current&&cancelAnimationFrame(d.current),s.current&&s.current.destroyAll()}},[a,o,f]),r.useEffect(()=>{const e=l.current;if(!e)return;const t=M(c);if(t===m.current){typeof window<"u"&&window.__micuglMetrics&&window.__micuglMetrics.engineSkippedInits++;return}m.current=t,typeof window<"u"&&window.__micuglMetrics&&window.__micuglMetrics.engineActualInits++,e.clearPasses(),c.forEach(n=>{e.addPass(n)}),e.initializeResources()},[c]),T.jsx("canvas",{ref:u,className:A,style:{width:"100%",height:"100%",display:"block",...F}})};exports.PingPongShaderEngine=k;
|
|
@@ -1,68 +1,80 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import { WebGLManager as
|
|
4
|
-
import { Passes as
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { jsx as x } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as s, useCallback as W, useEffect as F } from "react";
|
|
3
|
+
import { WebGLManager as k } from "../../../core/managers/WebGLManager.mjs";
|
|
4
|
+
import { Passes as H } from "../../../core/systems/Passes.mjs";
|
|
5
|
+
const I = "", O = {};
|
|
6
|
+
function z(a) {
|
|
7
|
+
return a.map(
|
|
8
|
+
(t) => `${t.programId}|${t.outputFramebuffer ?? "screen"}|${t.inputTextures.map((o) => o.id).join(",")}`
|
|
9
|
+
).join("||");
|
|
10
|
+
}
|
|
11
|
+
const C = ({
|
|
12
|
+
programConfigs: a,
|
|
13
|
+
passes: t,
|
|
8
14
|
framebuffers: o,
|
|
9
|
-
className:
|
|
10
|
-
style:
|
|
11
|
-
|
|
15
|
+
className: L = I,
|
|
16
|
+
style: M = O,
|
|
17
|
+
width: w,
|
|
18
|
+
height: h,
|
|
19
|
+
renderWidth: g,
|
|
20
|
+
renderHeight: p,
|
|
21
|
+
useDevicePixelRatio: y = !0,
|
|
22
|
+
pixelRatio: E
|
|
12
23
|
}) => {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
}),
|
|
19
|
-
if (!
|
|
20
|
-
const e = window.innerWidth,
|
|
21
|
-
c.current.setSize(
|
|
22
|
-
const
|
|
23
|
-
Object.entries(o ??
|
|
24
|
-
const
|
|
25
|
-
|
|
24
|
+
const u = s(null), c = s(null), m = s(null), d = s(null), R = s(0), l = s(""), _ = s((e) => {
|
|
25
|
+
const r = c.current, n = m.current;
|
|
26
|
+
if (!r || !n) return;
|
|
27
|
+
const i = e - R.current;
|
|
28
|
+
n.execute(i), d.current = requestAnimationFrame(_.current);
|
|
29
|
+
}), f = W(() => {
|
|
30
|
+
if (!u.current || !c.current) return;
|
|
31
|
+
const e = w ?? window.innerWidth, r = h ?? window.innerHeight, n = E ?? (y ? window.devicePixelRatio : 1), i = g ?? Math.floor(e * n), P = p ?? Math.floor(r * n);
|
|
32
|
+
c.current.setSize(i, P, e, r);
|
|
33
|
+
const b = c.current, S = b.context.canvas;
|
|
34
|
+
Object.entries(o ?? {}).forEach(([v, A]) => {
|
|
35
|
+
const j = A.width || S.width, T = A.height || S.height;
|
|
36
|
+
b.fbo.resizeFramebuffer(v, j, T);
|
|
26
37
|
});
|
|
27
|
-
}, [o,
|
|
28
|
-
return
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
38
|
+
}, [o, w, h, g, p, y, E]);
|
|
39
|
+
return F(() => {
|
|
40
|
+
if (!u.current) return;
|
|
41
|
+
const e = new k(u.current);
|
|
42
|
+
c.current = e, Object.entries(a).forEach(([n, i]) => {
|
|
43
|
+
e.createProgram(n, i);
|
|
44
|
+
}), Object.entries(o ?? {}).forEach(([n, i]) => {
|
|
45
|
+
e.fbo.createFramebuffer(n, i);
|
|
46
|
+
});
|
|
47
|
+
const r = new H(e);
|
|
48
|
+
return m.current = r, t.forEach((n) => {
|
|
49
|
+
r.addPass(n);
|
|
50
|
+
}), l.current = z(t), r.initializeResources(), f(), R.current = performance.now(), d.current = requestAnimationFrame(_.current), window.addEventListener("resize", f), () => {
|
|
51
|
+
window.removeEventListener("resize", f), d.current && cancelAnimationFrame(d.current), c.current && c.current.destroyAll();
|
|
52
|
+
};
|
|
53
|
+
}, [a, o, f]), F(() => {
|
|
54
|
+
const e = m.current;
|
|
55
|
+
if (!e) return;
|
|
56
|
+
const r = z(t);
|
|
57
|
+
if (r === l.current) {
|
|
58
|
+
typeof window < "u" && window.__micuglMetrics && window.__micuglMetrics.engineSkippedInits++;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
l.current = r, typeof window < "u" && window.__micuglMetrics && window.__micuglMetrics.engineActualInits++, e.clearPasses(), t.forEach((n) => {
|
|
62
|
+
e.addPass(n);
|
|
63
|
+
}), e.initializeResources();
|
|
64
|
+
}, [t]), /* @__PURE__ */ x(
|
|
53
65
|
"canvas",
|
|
54
66
|
{
|
|
55
|
-
ref:
|
|
56
|
-
className:
|
|
67
|
+
ref: u,
|
|
68
|
+
className: L,
|
|
57
69
|
style: {
|
|
58
70
|
width: "100%",
|
|
59
71
|
height: "100%",
|
|
60
72
|
display: "block",
|
|
61
|
-
...
|
|
73
|
+
...M
|
|
62
74
|
}
|
|
63
75
|
}
|
|
64
76
|
);
|
|
65
77
|
};
|
|
66
78
|
export {
|
|
67
|
-
|
|
79
|
+
C as PingPongShaderEngine
|
|
68
80
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react/jsx-runtime"),s=require("react"),h=require("../../../core/managers/WebGLManager.js"),I={},v="",M={},U={},q=({programConfigs:A,renderCallback:T,renderOptions:o=I,className:_=v,style:y=M,width:w,height:L,uniformUpdaters:f=U,useFastPath:g=!1,useDevicePixelRatio:F=!0,pixelRatio:S})=>{const l=s.useRef(null),a=s.useRef(null),d=s.useRef(null),i=s.useRef(null),E=s.useRef(0),m=s.useRef(n=>{const e=a.current,r=d.current;if(!e||!r)return;const t=n-E.current,c=e.context;if(g)e.fastRender(r,t,o.clear),c.drawArrays(c.TRIANGLE_STRIP,0,4);else{const u=e.resources.get(r);if(!u)return;e.prepareRender(r,o),p(t,u,c)}i.current=requestAnimationFrame(m.current)}),p=s.useCallback((n,e,r)=>{T(n,e,r)},[T]);s.useEffect(()=>{m.current=n=>{const e=a.current,r=d.current;if(!e||!r)return;const t=n-E.current,c=e.context;if(g)e.fastRender(r,t,o.clear),c.drawArrays(c.TRIANGLE_STRIP,0,4);else{const u=e.resources.get(r);if(!u)return;e.prepareRender(r,o),p(t,u,c)}i.current=requestAnimationFrame(m.current)}},[o,g,p]);const R=s.useCallback(()=>{if(!l.current||!a.current)return;const n=w??window.innerWidth,e=L??window.innerHeight,r=S??(F?window.devicePixelRatio:1),t=Math.floor(n*r),c=Math.floor(e*r);a.current.setSize(t,c,n,e)},[F,S,w,L]);return s.useEffect(()=>{if(!l.current)return;const n=new h.WebGLManager(l.current);a.current=n,R();const[[e,r]]=Object.entries(A);n.createProgram(e,r),n.createBuffer(e,"a_position",new Float32Array([-1,-1,1,-1,-1,1,1,1])),n.setAttributeOnce(e,"a_position",{name:"a_position",size:2,type:"FLOAT",normalized:!1,stride:0,offset:0}),d.current=e;const t=f[e];return t&&t.forEach(c=>{n.registerUniformUpdater(e,c.name,c.type,c.updateFn)}),E.current=performance.now(),i.current=requestAnimationFrame(m.current),window.addEventListener("resize",R),()=>{window.removeEventListener("resize",R),i.current&&cancelAnimationFrame(i.current),n.destroyAll()}},[A,R,f]),s.useEffect(()=>{const n=a.current,e=d.current;if(!n||!e)return;const r=f[e];r&&r.forEach(t=>{n.registerUniformUpdater(e,t.name,t.type,t.updateFn)})},[f]),b.jsx("canvas",{ref:l,className:_,style:y})};exports.ShaderEngine=q;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useRef as s, useCallback as
|
|
3
|
-
import { WebGLManager as
|
|
4
|
-
const
|
|
5
|
-
programConfigs:
|
|
6
|
-
renderCallback:
|
|
7
|
-
renderOptions: a =
|
|
8
|
-
className:
|
|
9
|
-
style:
|
|
10
|
-
width:
|
|
11
|
-
height:
|
|
12
|
-
uniformUpdaters:
|
|
1
|
+
import { jsx as U } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as s, useCallback as S, useEffect as E } from "react";
|
|
3
|
+
import { WebGLManager as v } from "../../../core/managers/WebGLManager.mjs";
|
|
4
|
+
const z = {}, N = "", b = {}, D = {}, q = ({
|
|
5
|
+
programConfigs: T,
|
|
6
|
+
renderCallback: w,
|
|
7
|
+
renderOptions: a = z,
|
|
8
|
+
className: I = N,
|
|
9
|
+
style: h = b,
|
|
10
|
+
width: L,
|
|
11
|
+
height: F,
|
|
12
|
+
uniformUpdaters: f = D,
|
|
13
13
|
useFastPath: A = !1,
|
|
14
|
-
useDevicePixelRatio:
|
|
15
|
-
pixelRatio:
|
|
14
|
+
useDevicePixelRatio: _ = !0,
|
|
15
|
+
pixelRatio: y
|
|
16
16
|
}) => {
|
|
17
|
-
const
|
|
18
|
-
const e = o.current, r =
|
|
17
|
+
const m = s(null), o = s(null), d = s(null), i = s(null), R = s(0), l = s((n) => {
|
|
18
|
+
const e = o.current, r = d.current;
|
|
19
19
|
if (!e || !r) return;
|
|
20
20
|
const t = n - R.current, c = e.context;
|
|
21
21
|
if (A)
|
|
@@ -23,15 +23,15 @@ const N = {}, b = "", D = {}, P = {}, M = ({
|
|
|
23
23
|
else {
|
|
24
24
|
const u = e.resources.get(r);
|
|
25
25
|
if (!u) return;
|
|
26
|
-
e.prepareRender(r, a),
|
|
26
|
+
e.prepareRender(r, a), g(t, u, c);
|
|
27
27
|
}
|
|
28
|
-
i.current = requestAnimationFrame(
|
|
29
|
-
}),
|
|
30
|
-
|
|
31
|
-
}, [
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const e = o.current, r =
|
|
28
|
+
i.current = requestAnimationFrame(l.current);
|
|
29
|
+
}), g = S((n, e, r) => {
|
|
30
|
+
w(n, e, r);
|
|
31
|
+
}, [w]);
|
|
32
|
+
E(() => {
|
|
33
|
+
l.current = (n) => {
|
|
34
|
+
const e = o.current, r = d.current;
|
|
35
35
|
if (!e || !r) return;
|
|
36
36
|
const t = n - R.current, c = e.context;
|
|
37
37
|
if (A)
|
|
@@ -39,47 +39,51 @@ const N = {}, b = "", D = {}, P = {}, M = ({
|
|
|
39
39
|
else {
|
|
40
40
|
const u = e.resources.get(r);
|
|
41
41
|
if (!u) return;
|
|
42
|
-
e.prepareRender(r, a),
|
|
42
|
+
e.prepareRender(r, a), g(t, u, c);
|
|
43
43
|
}
|
|
44
|
-
i.current = requestAnimationFrame(
|
|
44
|
+
i.current = requestAnimationFrame(l.current);
|
|
45
45
|
};
|
|
46
|
-
}, [a, A,
|
|
47
|
-
const
|
|
48
|
-
if (!
|
|
49
|
-
const n =
|
|
50
|
-
o.current.setSize(n, e
|
|
51
|
-
}, [
|
|
52
|
-
return
|
|
53
|
-
if (!
|
|
54
|
-
const n = new
|
|
55
|
-
o.current = n,
|
|
56
|
-
const [[e, r]] = Object.entries(
|
|
57
|
-
|
|
46
|
+
}, [a, A, g]);
|
|
47
|
+
const p = S(() => {
|
|
48
|
+
if (!m.current || !o.current) return;
|
|
49
|
+
const n = L ?? window.innerWidth, e = F ?? window.innerHeight, r = y ?? (_ ? window.devicePixelRatio : 1), t = Math.floor(n * r), c = Math.floor(e * r);
|
|
50
|
+
o.current.setSize(t, c, n, e);
|
|
51
|
+
}, [_, y, L, F]);
|
|
52
|
+
return E(() => {
|
|
53
|
+
if (!m.current) return;
|
|
54
|
+
const n = new v(m.current);
|
|
55
|
+
o.current = n, p();
|
|
56
|
+
const [[e, r]] = Object.entries(T);
|
|
57
|
+
n.createProgram(e, r), n.createBuffer(e, "a_position", new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1])), n.setAttributeOnce(e, "a_position", {
|
|
58
58
|
name: "a_position",
|
|
59
59
|
size: 2,
|
|
60
60
|
type: "FLOAT",
|
|
61
61
|
normalized: !1,
|
|
62
62
|
stride: 0,
|
|
63
63
|
offset: 0
|
|
64
|
-
}),
|
|
65
|
-
|
|
64
|
+
}), d.current = e;
|
|
65
|
+
const t = f[e];
|
|
66
|
+
return t && t.forEach((c) => {
|
|
67
|
+
n.registerUniformUpdater(e, c.name, c.type, c.updateFn);
|
|
68
|
+
}), R.current = performance.now(), i.current = requestAnimationFrame(l.current), window.addEventListener("resize", p), () => {
|
|
69
|
+
window.removeEventListener("resize", p), i.current && cancelAnimationFrame(i.current), n.destroyAll();
|
|
66
70
|
};
|
|
67
|
-
}, [
|
|
68
|
-
const n = o.current, e =
|
|
71
|
+
}, [T, p, f]), E(() => {
|
|
72
|
+
const n = o.current, e = d.current;
|
|
69
73
|
if (!n || !e) return;
|
|
70
|
-
const r =
|
|
74
|
+
const r = f[e];
|
|
71
75
|
r && r.forEach((t) => {
|
|
72
76
|
n.registerUniformUpdater(e, t.name, t.type, t.updateFn);
|
|
73
77
|
});
|
|
74
|
-
}, [
|
|
78
|
+
}, [f]), /* @__PURE__ */ U(
|
|
75
79
|
"canvas",
|
|
76
80
|
{
|
|
77
|
-
ref:
|
|
78
|
-
className:
|
|
79
|
-
style:
|
|
81
|
+
ref: m,
|
|
82
|
+
className: I,
|
|
83
|
+
style: h
|
|
80
84
|
}
|
|
81
85
|
);
|
|
82
86
|
};
|
|
83
87
|
export {
|
|
84
|
-
|
|
88
|
+
q as ShaderEngine
|
|
85
89
|
};
|
|
@@ -12,10 +12,9 @@ interface PingPongPassesOptions {
|
|
|
12
12
|
};
|
|
13
13
|
customPasses?: RenderPass[];
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
interface PingPongPassesResult {
|
|
16
16
|
passes: RenderPass[];
|
|
17
|
-
framebuffers:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
17
|
+
framebuffers: Record<string, FramebufferOptions>;
|
|
18
|
+
}
|
|
19
|
+
export declare const usePingPongPasses: ({ programId, secondaryProgramId, iterations, uniforms, secondaryUniforms, framebufferOptions, renderOptions, customPasses }: PingPongPassesOptions) => PingPongPassesResult;
|
|
21
20
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react"),R=require("./useUniformUpdaters.js"),C={width:0,height:0,textureCount:2,textureOptions:{minFilter:WebGLRenderingContext.LINEAR,magFilter:WebGLRenderingContext.LINEAR}},N={clear:!0};function A(e){return`${e.width}|${e.height}|${e.textureCount??1}|${JSON.stringify(e.textureOptions??{})}`}function L(e){return`${e.clear??!0}|${JSON.stringify(e.clearColor??[0,0,0,1])}`}function O(e,t,a,h,U,o,s,r){const i=`${e}-fb-a`,f=`${e}-fb-b`,c={[i]:o,[f]:o};let u=[];if(r)u=r;else{u.push({programId:e,inputTextures:[],outputFramebuffer:i,renderOptions:s});let b=i;for(let n=0;n<a;n++){const w=t&&n%2===1?t:e,_=n%2===0?i:f,p=n%2===0?f:i;b=p;const g=t&&n%2===1?U[t]:h[e],y={};g.forEach(x=>{const T=x.updateFn;y[x.name]={type:x.type,value:(d,E,M)=>T(d,E,M)}}),u.push({programId:w,inputTextures:[{id:_,textureUnit:0,bindingType:"read"}],outputFramebuffer:p,uniforms:y,renderOptions:s})}const F=b,l={};(t?U[t]:h[e]).forEach(n=>{const w=n.updateFn;l[n.name]={type:n.type,value:(_,p,g)=>w(_,p,g)}}),u.push({programId:t??e,inputTextures:[{id:F,textureUnit:0,bindingType:"read"}],outputFramebuffer:null,uniforms:l,renderOptions:s})}return{passes:u,framebuffers:c}}const k=({programId:e,secondaryProgramId:t,iterations:a=1,uniforms:h,secondaryUniforms:U={},framebufferOptions:o=C,renderOptions:s=N,customPasses:r})=>{const i=R.useUniformUpdaters(e,h),f=R.useUniformUpdaters(t??`${e}-secondary`,U),c=S.useRef(null),u=A(o),b=L(s),F=r?r.length.toString():"none",l=`${e}|${t??""}|${a}|${u}|${b}|${F}`;if(c.current&&c.current.key===l)return typeof window<"u"&&window.__micuglMetrics&&window.__micuglMetrics.hookCacheHits++,c.current.result;typeof window<"u"&&window.__micuglMetrics&&window.__micuglMetrics.hookCacheMisses++;const $=O(e,t,a,i,f,o,s,r);return c.current={key:l,result:$},$};exports.usePingPongPasses=k;
|
|
@@ -1,93 +1,108 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useUniformUpdaters as
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const v = h.updateFn;
|
|
44
|
-
T[h.name] = {
|
|
45
|
-
type: h.type,
|
|
46
|
-
value: (A, M, $) => v(A, M, $)
|
|
47
|
-
};
|
|
48
|
-
}), i.push({
|
|
49
|
-
programId: r,
|
|
50
|
-
inputTextures: [{
|
|
51
|
-
id: b,
|
|
52
|
-
textureUnit: 0,
|
|
53
|
-
bindingType: "read"
|
|
54
|
-
}],
|
|
55
|
-
outputFramebuffer: x,
|
|
56
|
-
uniforms: T,
|
|
57
|
-
renderOptions: s
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
const R = o % 2 === 0 ? f : u, a = {};
|
|
61
|
-
(n ? U[n] : p[t]).forEach((e) => {
|
|
62
|
-
const r = e.updateFn;
|
|
63
|
-
a[e.name] = {
|
|
64
|
-
type: e.type,
|
|
65
|
-
value: (b, x, F) => r(b, x, F)
|
|
1
|
+
import { useRef as N } from "react";
|
|
2
|
+
import { useUniformUpdaters as T } from "./useUniformUpdaters.mjs";
|
|
3
|
+
const d = {
|
|
4
|
+
width: 0,
|
|
5
|
+
height: 0,
|
|
6
|
+
textureCount: 2,
|
|
7
|
+
textureOptions: {
|
|
8
|
+
minFilter: WebGLRenderingContext.LINEAR,
|
|
9
|
+
magFilter: WebGLRenderingContext.LINEAR
|
|
10
|
+
}
|
|
11
|
+
}, A = { clear: !0 };
|
|
12
|
+
function L(t) {
|
|
13
|
+
return `${t.width}|${t.height}|${t.textureCount ?? 1}|${JSON.stringify(t.textureOptions ?? {})}`;
|
|
14
|
+
}
|
|
15
|
+
function S(t) {
|
|
16
|
+
return `${t.clear ?? !0}|${JSON.stringify(t.clearColor ?? [0, 0, 0, 1])}`;
|
|
17
|
+
}
|
|
18
|
+
function m(t, e, h, a, p, o, s, c) {
|
|
19
|
+
const i = `${t}-fb-a`, f = `${t}-fb-b`, r = {
|
|
20
|
+
[i]: o,
|
|
21
|
+
[f]: o
|
|
22
|
+
};
|
|
23
|
+
let u = [];
|
|
24
|
+
if (c)
|
|
25
|
+
u = c;
|
|
26
|
+
else {
|
|
27
|
+
u.push({
|
|
28
|
+
programId: t,
|
|
29
|
+
inputTextures: [],
|
|
30
|
+
outputFramebuffer: i,
|
|
31
|
+
renderOptions: s
|
|
32
|
+
});
|
|
33
|
+
let F = i;
|
|
34
|
+
for (let n = 0; n < h; n++) {
|
|
35
|
+
const U = e && n % 2 === 1 ? e : t, x = n % 2 === 0 ? i : f, $ = n % 2 === 0 ? f : i;
|
|
36
|
+
F = $;
|
|
37
|
+
const _ = e && n % 2 === 1 ? p[e] : a[t], E = {};
|
|
38
|
+
_.forEach((R) => {
|
|
39
|
+
const y = R.updateFn;
|
|
40
|
+
E[R.name] = {
|
|
41
|
+
type: R.type,
|
|
42
|
+
value: (M, g, C) => y(M, g, C)
|
|
66
43
|
};
|
|
67
|
-
}),
|
|
68
|
-
programId:
|
|
44
|
+
}), u.push({
|
|
45
|
+
programId: U,
|
|
69
46
|
inputTextures: [{
|
|
70
|
-
id:
|
|
47
|
+
id: x,
|
|
71
48
|
textureUnit: 0,
|
|
72
49
|
bindingType: "read"
|
|
73
50
|
}],
|
|
74
|
-
outputFramebuffer:
|
|
75
|
-
uniforms:
|
|
51
|
+
outputFramebuffer: $,
|
|
52
|
+
uniforms: E,
|
|
76
53
|
renderOptions: s
|
|
77
54
|
});
|
|
78
55
|
}
|
|
79
|
-
|
|
80
|
-
|
|
56
|
+
const b = F, l = {};
|
|
57
|
+
(e ? p[e] : a[t]).forEach((n) => {
|
|
58
|
+
const U = n.updateFn;
|
|
59
|
+
l[n.name] = {
|
|
60
|
+
type: n.type,
|
|
61
|
+
value: (x, $, _) => U(x, $, _)
|
|
62
|
+
};
|
|
63
|
+
}), u.push({
|
|
64
|
+
programId: e ?? t,
|
|
65
|
+
inputTextures: [{
|
|
66
|
+
id: b,
|
|
67
|
+
textureUnit: 0,
|
|
68
|
+
bindingType: "read"
|
|
69
|
+
}],
|
|
70
|
+
outputFramebuffer: null,
|
|
71
|
+
uniforms: l,
|
|
72
|
+
renderOptions: s
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return { passes: u, framebuffers: r };
|
|
76
|
+
}
|
|
77
|
+
const K = ({
|
|
78
|
+
programId: t,
|
|
79
|
+
secondaryProgramId: e,
|
|
80
|
+
iterations: h = 1,
|
|
81
|
+
uniforms: a,
|
|
82
|
+
secondaryUniforms: p = {},
|
|
83
|
+
framebufferOptions: o = d,
|
|
84
|
+
renderOptions: s = A,
|
|
85
|
+
customPasses: c
|
|
86
|
+
}) => {
|
|
87
|
+
const i = T(t, a), f = T(
|
|
88
|
+
e ?? `${t}-secondary`,
|
|
89
|
+
p
|
|
90
|
+
), r = N(null), u = L(o), F = S(s), b = c ? c.length.toString() : "none", l = `${t}|${e ?? ""}|${h}|${u}|${F}|${b}`;
|
|
91
|
+
if (r.current && r.current.key === l)
|
|
92
|
+
return typeof window < "u" && window.__micuglMetrics && window.__micuglMetrics.hookCacheHits++, r.current.result;
|
|
93
|
+
typeof window < "u" && window.__micuglMetrics && window.__micuglMetrics.hookCacheMisses++;
|
|
94
|
+
const w = m(
|
|
81
95
|
t,
|
|
82
|
-
|
|
96
|
+
e,
|
|
97
|
+
h,
|
|
98
|
+
i,
|
|
99
|
+
f,
|
|
83
100
|
o,
|
|
84
|
-
p,
|
|
85
|
-
U,
|
|
86
|
-
l,
|
|
87
101
|
s,
|
|
88
102
|
c
|
|
89
|
-
|
|
103
|
+
);
|
|
104
|
+
return r.current = { key: l, result: w }, w;
|
|
90
105
|
};
|
|
91
106
|
export {
|
|
92
|
-
|
|
107
|
+
K as usePingPongPasses
|
|
93
108
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "micugl",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "Micu gl - Small React shader library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
|
+
"dev": "vite --config demo/vite.config.ts",
|
|
30
31
|
"build": "vite build",
|
|
31
32
|
"test": "vitest run",
|
|
32
33
|
"lint": "eslint . --ext .ts,.tsx",
|
|
@@ -39,8 +40,11 @@
|
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@eslint/js": "^9.25.0",
|
|
41
42
|
"@types/node": "^22.14.0",
|
|
42
|
-
"@types/react": "^
|
|
43
|
-
"@types/react-dom": "^
|
|
43
|
+
"@types/react": "^19.0.0",
|
|
44
|
+
"@types/react-dom": "^19.0.0",
|
|
45
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
46
|
+
"react": "^19.0.0",
|
|
47
|
+
"react-dom": "^19.0.0",
|
|
44
48
|
"ajv": "^8",
|
|
45
49
|
"eslint": "^9.25.0",
|
|
46
50
|
"eslint-plugin-react-dom": "^1.48.4",
|