@elementalfx/gl 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +11 -2
- package/dist/context.d.ts +14 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +313 -0
- package/dist/index.js.map +7 -0
- package/dist/program.d.ts +20 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/targets.d.ts +62 -0
- package/dist/targets.d.ts.map +1 -0
- package/dist/texture.d.ts +24 -0
- package/dist/texture.d.ts.map +1 -0
- package/package.json +50 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 aviyer42
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @elementalfx/gl
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A small WebGL2 toolkit used by [elementalfx](https://github.com/iyerav42/elementalfx) effects.
|
|
4
|
+
|
|
5
|
+
- `getWebGL2(canvas)`, `isWebGL2Supported()`, `watchContextLoss(canvas, onLost, onRestored)`
|
|
6
|
+
- `createProgram(gl, vertex, fragment, defines)` with uniform lookup, `FULLSCREEN_VERTEX`, `createFullscreenDraw(gl)`
|
|
7
|
+
- `simulationFormat(gl)`: picks RGBA32F, RGBA16F or packed RGBA8, verifying each with a real framebuffer
|
|
8
|
+
- `RenderTarget`, `PingPong`: textures with framebuffers for simulation passes
|
|
9
|
+
- `PACKING_GLSL`: encode/decode signed values in two 8-bit channels for devices without float render targets
|
|
10
|
+
- `createTexture`, `uploadTexture`, `loadImage`, `sourceSize`, `isSourceReady`
|
|
11
|
+
|
|
12
|
+
MIT License
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ContextOptions {
|
|
2
|
+
/** Default 'default'. Decorative effects can pass 'low-power' to favour battery life. */
|
|
3
|
+
powerPreference?: WebGLPowerPreference;
|
|
4
|
+
}
|
|
5
|
+
/** Creates a WebGL2 context tuned for 2D effects, or returns null if unavailable. */
|
|
6
|
+
export declare function getWebGL2(canvas: HTMLCanvasElement, options?: ContextOptions): WebGL2RenderingContext | null;
|
|
7
|
+
/** Whether this browser can create a WebGL2 context. Cached after the first call. */
|
|
8
|
+
export declare function isWebGL2Supported(): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Watches for context loss and restoration. On loss the default is prevented so
|
|
11
|
+
* the browser may restore the context later; effects then rebuild GPU resources.
|
|
12
|
+
*/
|
|
13
|
+
export declare function watchContextLoss(canvas: HTMLCanvasElement, onLost: () => void, onRestored: () => void): () => void;
|
|
14
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,yFAAyF;IACzF,eAAe,CAAC,EAAE,oBAAoB,CAAC;CACxC;AAED,qFAAqF;AACrF,wBAAgB,SAAS,CACvB,MAAM,EAAE,iBAAiB,EACzB,OAAO,GAAE,cAAmB,GAC3B,sBAAsB,GAAG,IAAI,CAc/B;AAID,qFAAqF;AACrF,wBAAgB,iBAAiB,IAAI,OAAO,CAQ3C;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,iBAAiB,EACzB,MAAM,EAAE,MAAM,IAAI,EAClB,UAAU,EAAE,MAAM,IAAI,GACrB,MAAM,IAAI,CAWZ"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { getWebGL2, isWebGL2Supported, watchContextLoss, type ContextOptions } from './context';
|
|
2
|
+
export { createProgram, createFullscreenDraw, FULLSCREEN_VERTEX, type Program } from './program';
|
|
3
|
+
export { simulationFormat, RenderTarget, PingPong, PACKING_GLSL, type TargetFormat, } from './targets';
|
|
4
|
+
export { createTexture, uploadTexture, loadImage, sourceSize, isSourceReady, type ImageSource, } from './texture';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAChG,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AACjG,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,KAAK,YAAY,GAClB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,aAAa,EACb,aAAa,EACb,SAAS,EACT,UAAU,EACV,aAAa,EACb,KAAK,WAAW,GACjB,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
// packages/gl/src/context.ts
|
|
2
|
+
import { isBrowser } from "@elementalfx/core";
|
|
3
|
+
function getWebGL2(canvas, options = {}) {
|
|
4
|
+
try {
|
|
5
|
+
return canvas.getContext("webgl2", {
|
|
6
|
+
alpha: true,
|
|
7
|
+
premultipliedAlpha: true,
|
|
8
|
+
antialias: false,
|
|
9
|
+
depth: false,
|
|
10
|
+
stencil: false,
|
|
11
|
+
preserveDrawingBuffer: false,
|
|
12
|
+
powerPreference: options.powerPreference ?? "default"
|
|
13
|
+
});
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
var supported;
|
|
19
|
+
function isWebGL2Supported() {
|
|
20
|
+
if (supported !== void 0) return supported;
|
|
21
|
+
if (!isBrowser) return false;
|
|
22
|
+
const canvas = document.createElement("canvas");
|
|
23
|
+
const gl = getWebGL2(canvas);
|
|
24
|
+
supported = gl !== null;
|
|
25
|
+
gl?.getExtension("WEBGL_lose_context")?.loseContext();
|
|
26
|
+
return supported;
|
|
27
|
+
}
|
|
28
|
+
function watchContextLoss(canvas, onLost, onRestored) {
|
|
29
|
+
const lost = (event) => {
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
onLost();
|
|
32
|
+
};
|
|
33
|
+
canvas.addEventListener("webglcontextlost", lost);
|
|
34
|
+
canvas.addEventListener("webglcontextrestored", onRestored);
|
|
35
|
+
return () => {
|
|
36
|
+
canvas.removeEventListener("webglcontextlost", lost);
|
|
37
|
+
canvas.removeEventListener("webglcontextrestored", onRestored);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// packages/gl/src/program.ts
|
|
42
|
+
var FULLSCREEN_VERTEX = `#version 300 es
|
|
43
|
+
out vec2 vUv;
|
|
44
|
+
void main() {
|
|
45
|
+
vec2 corner = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
|
|
46
|
+
vUv = corner;
|
|
47
|
+
gl_Position = vec4(corner * 2.0 - 1.0, 0.0, 1.0);
|
|
48
|
+
}`;
|
|
49
|
+
function compile(gl, type, source) {
|
|
50
|
+
const shader = gl.createShader(type);
|
|
51
|
+
if (!shader) throw new Error("[elementalfx] Could not create shader");
|
|
52
|
+
gl.shaderSource(shader, source);
|
|
53
|
+
gl.compileShader(shader);
|
|
54
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS) && !gl.isContextLost()) {
|
|
55
|
+
const log = gl.getShaderInfoLog(shader);
|
|
56
|
+
gl.deleteShader(shader);
|
|
57
|
+
throw new Error(`[elementalfx] Shader failed to compile: ${log ?? "unknown error"}`);
|
|
58
|
+
}
|
|
59
|
+
return shader;
|
|
60
|
+
}
|
|
61
|
+
function createProgram(gl, vertexSource, fragmentSource, defines = {}) {
|
|
62
|
+
const header = Object.entries(defines).filter(([, value]) => value !== false).map(([name, value]) => `#define ${name} ${value === true ? "" : value}`).join("\n");
|
|
63
|
+
const withDefines = (source) => header ? source.replace(/^(#version[^\n]*\n)/, `$1${header}
|
|
64
|
+
`) : source;
|
|
65
|
+
const vertex = compile(gl, gl.VERTEX_SHADER, withDefines(vertexSource));
|
|
66
|
+
const fragment = compile(gl, gl.FRAGMENT_SHADER, withDefines(fragmentSource));
|
|
67
|
+
const program = gl.createProgram();
|
|
68
|
+
if (!program) throw new Error("[elementalfx] Could not create program");
|
|
69
|
+
gl.attachShader(program, vertex);
|
|
70
|
+
gl.attachShader(program, fragment);
|
|
71
|
+
gl.linkProgram(program);
|
|
72
|
+
gl.deleteShader(vertex);
|
|
73
|
+
gl.deleteShader(fragment);
|
|
74
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS) && !gl.isContextLost()) {
|
|
75
|
+
const log = gl.getProgramInfoLog(program);
|
|
76
|
+
gl.deleteProgram(program);
|
|
77
|
+
throw new Error(`[elementalfx] Program failed to link: ${log ?? "unknown error"}`);
|
|
78
|
+
}
|
|
79
|
+
const uniforms = {};
|
|
80
|
+
const count = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS) ?? 0;
|
|
81
|
+
for (let i = 0; i < count; i++) {
|
|
82
|
+
const info = gl.getActiveUniform(program, i);
|
|
83
|
+
if (!info) continue;
|
|
84
|
+
const name = info.name.replace(/\[0\]$/, "");
|
|
85
|
+
const location = gl.getUniformLocation(program, info.name);
|
|
86
|
+
if (location) uniforms[name] = location;
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
program,
|
|
90
|
+
uniforms,
|
|
91
|
+
use: () => gl.useProgram(program),
|
|
92
|
+
delete: () => gl.deleteProgram(program)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function createFullscreenDraw(gl) {
|
|
96
|
+
const vao = gl.createVertexArray();
|
|
97
|
+
return {
|
|
98
|
+
draw() {
|
|
99
|
+
gl.bindVertexArray(vao);
|
|
100
|
+
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
101
|
+
},
|
|
102
|
+
delete() {
|
|
103
|
+
gl.deleteVertexArray(vao);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// packages/gl/src/targets.ts
|
|
109
|
+
function simulationFormat(gl, request = {}) {
|
|
110
|
+
const packed = {
|
|
111
|
+
internalFormat: gl.RGBA8,
|
|
112
|
+
format: gl.RGBA,
|
|
113
|
+
type: gl.UNSIGNED_BYTE,
|
|
114
|
+
filterable: false,
|
|
115
|
+
packed: true
|
|
116
|
+
};
|
|
117
|
+
if (request.forcePacked) return packed;
|
|
118
|
+
const colorBufferFloat = gl.getExtension("EXT_color_buffer_float") !== null;
|
|
119
|
+
const colorBufferHalf = colorBufferFloat || gl.getExtension("EXT_color_buffer_half_float") !== null;
|
|
120
|
+
if ((request.precision ?? "float") === "float" && colorBufferFloat) {
|
|
121
|
+
const full = {
|
|
122
|
+
internalFormat: gl.RGBA32F,
|
|
123
|
+
format: gl.RGBA,
|
|
124
|
+
type: gl.FLOAT,
|
|
125
|
+
filterable: gl.getExtension("OES_texture_float_linear") !== null,
|
|
126
|
+
packed: false
|
|
127
|
+
};
|
|
128
|
+
if (canRenderTo(gl, full)) return full;
|
|
129
|
+
}
|
|
130
|
+
if (colorBufferHalf) {
|
|
131
|
+
const half = {
|
|
132
|
+
internalFormat: gl.RGBA16F,
|
|
133
|
+
format: gl.RGBA,
|
|
134
|
+
type: gl.HALF_FLOAT,
|
|
135
|
+
filterable: true,
|
|
136
|
+
packed: false
|
|
137
|
+
};
|
|
138
|
+
if (canRenderTo(gl, half)) return half;
|
|
139
|
+
}
|
|
140
|
+
return packed;
|
|
141
|
+
}
|
|
142
|
+
function canRenderTo(gl, format) {
|
|
143
|
+
const texture = gl.createTexture();
|
|
144
|
+
const framebuffer = gl.createFramebuffer();
|
|
145
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
146
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, format.internalFormat, 4, 4, 0, format.format, format.type, null);
|
|
147
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
148
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
149
|
+
const complete = gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE;
|
|
150
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
151
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
152
|
+
gl.deleteFramebuffer(framebuffer);
|
|
153
|
+
gl.deleteTexture(texture);
|
|
154
|
+
return complete;
|
|
155
|
+
}
|
|
156
|
+
var RenderTarget = class {
|
|
157
|
+
constructor(gl, width, height, format, filter = format.filterable ? gl.LINEAR : gl.NEAREST) {
|
|
158
|
+
this.gl = gl;
|
|
159
|
+
this.width = width;
|
|
160
|
+
this.height = height;
|
|
161
|
+
this.format = format;
|
|
162
|
+
const texture = gl.createTexture();
|
|
163
|
+
const framebuffer = gl.createFramebuffer();
|
|
164
|
+
if (!texture || !framebuffer) throw new Error("[elementalfx] Could not allocate render target");
|
|
165
|
+
this.texture = texture;
|
|
166
|
+
this.framebuffer = framebuffer;
|
|
167
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
168
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter);
|
|
169
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);
|
|
170
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
171
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
172
|
+
gl.texImage2D(
|
|
173
|
+
gl.TEXTURE_2D,
|
|
174
|
+
0,
|
|
175
|
+
format.internalFormat,
|
|
176
|
+
width,
|
|
177
|
+
height,
|
|
178
|
+
0,
|
|
179
|
+
format.format,
|
|
180
|
+
format.type,
|
|
181
|
+
null
|
|
182
|
+
);
|
|
183
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
184
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
185
|
+
this.clear();
|
|
186
|
+
}
|
|
187
|
+
/** Binds this target for drawing and sets the viewport to its size. */
|
|
188
|
+
bind() {
|
|
189
|
+
this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.framebuffer);
|
|
190
|
+
this.gl.viewport(0, 0, this.width, this.height);
|
|
191
|
+
}
|
|
192
|
+
/** Clears to zero (or to the packed encoding of zero). */
|
|
193
|
+
clear() {
|
|
194
|
+
const gl = this.gl;
|
|
195
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
|
|
196
|
+
if (this.format.packed) gl.clearColor(127 / 255, 1, 127 / 255, 1);
|
|
197
|
+
else gl.clearColor(0, 0, 0, 0);
|
|
198
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
199
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
200
|
+
}
|
|
201
|
+
delete() {
|
|
202
|
+
this.gl.deleteFramebuffer(this.framebuffer);
|
|
203
|
+
this.gl.deleteTexture(this.texture);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
var PingPong = class {
|
|
207
|
+
constructor(gl, width, height, format) {
|
|
208
|
+
this.read = new RenderTarget(gl, width, height, format);
|
|
209
|
+
this.write = new RenderTarget(gl, width, height, format);
|
|
210
|
+
}
|
|
211
|
+
get width() {
|
|
212
|
+
return this.read.width;
|
|
213
|
+
}
|
|
214
|
+
get height() {
|
|
215
|
+
return this.read.height;
|
|
216
|
+
}
|
|
217
|
+
swap() {
|
|
218
|
+
const read = this.read;
|
|
219
|
+
this.read = this.write;
|
|
220
|
+
this.write = read;
|
|
221
|
+
}
|
|
222
|
+
clear() {
|
|
223
|
+
this.read.clear();
|
|
224
|
+
this.write.clear();
|
|
225
|
+
}
|
|
226
|
+
delete() {
|
|
227
|
+
this.read.delete();
|
|
228
|
+
this.write.delete();
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
var PACKING_GLSL = `
|
|
232
|
+
const float PACK_QUANTUM = 2.0 / 65534.0;
|
|
233
|
+
vec2 packSigned(float value) {
|
|
234
|
+
float v = floor(clamp(value * 0.5 + 0.5, 0.0, 1.0) * 65534.0 + 0.5);
|
|
235
|
+
float hi = floor(v / 256.0);
|
|
236
|
+
float lo = v - hi * 256.0;
|
|
237
|
+
return vec2(hi, lo) / 255.0;
|
|
238
|
+
}
|
|
239
|
+
float unpackSigned(vec2 bytes) {
|
|
240
|
+
vec2 b = floor(bytes * 255.0 + 0.5);
|
|
241
|
+
return (b.x * 256.0 + b.y) / 65534.0 * 2.0 - 1.0;
|
|
242
|
+
}
|
|
243
|
+
`;
|
|
244
|
+
|
|
245
|
+
// packages/gl/src/texture.ts
|
|
246
|
+
function sourceSize(source) {
|
|
247
|
+
if (source instanceof HTMLImageElement) {
|
|
248
|
+
return { width: source.naturalWidth, height: source.naturalHeight };
|
|
249
|
+
}
|
|
250
|
+
if (source instanceof HTMLVideoElement) {
|
|
251
|
+
return { width: source.videoWidth, height: source.videoHeight };
|
|
252
|
+
}
|
|
253
|
+
return { width: source.width, height: source.height };
|
|
254
|
+
}
|
|
255
|
+
function isSourceReady(source) {
|
|
256
|
+
if (source instanceof HTMLImageElement) return source.complete && source.naturalWidth > 0;
|
|
257
|
+
if (source instanceof HTMLVideoElement) return source.readyState >= 2 && source.videoWidth > 0;
|
|
258
|
+
const { width, height } = sourceSize(source);
|
|
259
|
+
return width > 0 && height > 0;
|
|
260
|
+
}
|
|
261
|
+
function createTexture(gl) {
|
|
262
|
+
const texture = gl.createTexture();
|
|
263
|
+
if (!texture) throw new Error("[elementalfx] Could not allocate texture");
|
|
264
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
265
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
266
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
267
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
268
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
269
|
+
return texture;
|
|
270
|
+
}
|
|
271
|
+
function uploadTexture(gl, texture, source, mipmaps = false) {
|
|
272
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
273
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
274
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
275
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
|
|
276
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
277
|
+
if (mipmaps) {
|
|
278
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
279
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
|
|
280
|
+
} else {
|
|
281
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function loadImage(url, crossOrigin = "anonymous") {
|
|
285
|
+
return new Promise((resolve, reject) => {
|
|
286
|
+
const image = new Image();
|
|
287
|
+
if (crossOrigin !== null && !url.startsWith("data:") && !url.startsWith("blob:")) {
|
|
288
|
+
image.crossOrigin = crossOrigin;
|
|
289
|
+
}
|
|
290
|
+
image.decoding = "async";
|
|
291
|
+
image.onload = () => resolve(image);
|
|
292
|
+
image.onerror = () => reject(new Error(`[elementalfx] Could not load image: ${url}`));
|
|
293
|
+
image.src = url;
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
export {
|
|
297
|
+
FULLSCREEN_VERTEX,
|
|
298
|
+
PACKING_GLSL,
|
|
299
|
+
PingPong,
|
|
300
|
+
RenderTarget,
|
|
301
|
+
createFullscreenDraw,
|
|
302
|
+
createProgram,
|
|
303
|
+
createTexture,
|
|
304
|
+
getWebGL2,
|
|
305
|
+
isSourceReady,
|
|
306
|
+
isWebGL2Supported,
|
|
307
|
+
loadImage,
|
|
308
|
+
simulationFormat,
|
|
309
|
+
sourceSize,
|
|
310
|
+
uploadTexture,
|
|
311
|
+
watchContextLoss
|
|
312
|
+
};
|
|
313
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/context.ts", "../src/program.ts", "../src/targets.ts", "../src/texture.ts"],
|
|
4
|
+
"sourcesContent": ["import { isBrowser } from '@elementalfx/core';\n\nexport interface ContextOptions {\n /** Default 'default'. Decorative effects can pass 'low-power' to favour battery life. */\n powerPreference?: WebGLPowerPreference;\n}\n\n/** Creates a WebGL2 context tuned for 2D effects, or returns null if unavailable. */\nexport function getWebGL2(\n canvas: HTMLCanvasElement,\n options: ContextOptions = {},\n): WebGL2RenderingContext | null {\n try {\n return canvas.getContext('webgl2', {\n alpha: true,\n premultipliedAlpha: true,\n antialias: false,\n depth: false,\n stencil: false,\n preserveDrawingBuffer: false,\n powerPreference: options.powerPreference ?? 'default',\n });\n } catch {\n return null;\n }\n}\n\nlet supported: boolean | undefined;\n\n/** Whether this browser can create a WebGL2 context. Cached after the first call. */\nexport function isWebGL2Supported(): boolean {\n if (supported !== undefined) return supported;\n if (!isBrowser) return false;\n const canvas = document.createElement('canvas');\n const gl = getWebGL2(canvas);\n supported = gl !== null;\n gl?.getExtension('WEBGL_lose_context')?.loseContext();\n return supported;\n}\n\n/**\n * Watches for context loss and restoration. On loss the default is prevented so\n * the browser may restore the context later; effects then rebuild GPU resources.\n */\nexport function watchContextLoss(\n canvas: HTMLCanvasElement,\n onLost: () => void,\n onRestored: () => void,\n): () => void {\n const lost = (event: Event): void => {\n event.preventDefault();\n onLost();\n };\n canvas.addEventListener('webglcontextlost', lost);\n canvas.addEventListener('webglcontextrestored', onRestored);\n return () => {\n canvas.removeEventListener('webglcontextlost', lost);\n canvas.removeEventListener('webglcontextrestored', onRestored);\n };\n}\n", "/** A linked shader program with its active uniform locations looked up by name. */\nexport interface Program {\n readonly program: WebGLProgram;\n readonly uniforms: Record<string, WebGLUniformLocation>;\n use(): void;\n delete(): void;\n}\n\n/** A vertex shader that covers the viewport with one triangle and passes `vUv` in [0, 1]. */\nexport const FULLSCREEN_VERTEX = `#version 300 es\nout vec2 vUv;\nvoid main() {\n vec2 corner = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));\n vUv = corner;\n gl_Position = vec4(corner * 2.0 - 1.0, 0.0, 1.0);\n}`;\n\nfunction compile(gl: WebGL2RenderingContext, type: number, source: string): WebGLShader {\n const shader = gl.createShader(type);\n if (!shader) throw new Error('[elementalfx] Could not create shader');\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS) && !gl.isContextLost()) {\n const log = gl.getShaderInfoLog(shader);\n gl.deleteShader(shader);\n throw new Error(`[elementalfx] Shader failed to compile: ${log ?? 'unknown error'}`);\n }\n return shader;\n}\n\n/** Compiles and links a program. Prepends `defines` as `#define` lines after the version line. */\nexport function createProgram(\n gl: WebGL2RenderingContext,\n vertexSource: string,\n fragmentSource: string,\n defines: Record<string, string | number | boolean> = {},\n): Program {\n const header = Object.entries(defines)\n .filter(([, value]) => value !== false)\n .map(([name, value]) => `#define ${name} ${value === true ? '' : value}`)\n .join('\\n');\n const withDefines = (source: string): string =>\n header ? source.replace(/^(#version[^\\n]*\\n)/, `$1${header}\\n`) : source;\n\n const vertex = compile(gl, gl.VERTEX_SHADER, withDefines(vertexSource));\n const fragment = compile(gl, gl.FRAGMENT_SHADER, withDefines(fragmentSource));\n const program = gl.createProgram();\n if (!program) throw new Error('[elementalfx] Could not create program');\n gl.attachShader(program, vertex);\n gl.attachShader(program, fragment);\n gl.linkProgram(program);\n gl.deleteShader(vertex);\n gl.deleteShader(fragment);\n if (!gl.getProgramParameter(program, gl.LINK_STATUS) && !gl.isContextLost()) {\n const log = gl.getProgramInfoLog(program);\n gl.deleteProgram(program);\n throw new Error(`[elementalfx] Program failed to link: ${log ?? 'unknown error'}`);\n }\n\n const uniforms: Record<string, WebGLUniformLocation> = {};\n const count = (gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS) as number) ?? 0;\n for (let i = 0; i < count; i++) {\n const info = gl.getActiveUniform(program, i);\n if (!info) continue;\n const name = info.name.replace(/\\[0\\]$/, '');\n const location = gl.getUniformLocation(program, info.name);\n if (location) uniforms[name] = location;\n }\n\n return {\n program,\n uniforms,\n use: () => gl.useProgram(program),\n delete: () => gl.deleteProgram(program),\n };\n}\n\n/**\n * Draws one fullscreen triangle. WebGL2 can draw without vertex buffers;\n * an empty vertex array object keeps every driver happy.\n */\nexport function createFullscreenDraw(gl: WebGL2RenderingContext): {\n draw(): void;\n delete(): void;\n} {\n const vao = gl.createVertexArray();\n return {\n draw() {\n gl.bindVertexArray(vao);\n gl.drawArrays(gl.TRIANGLES, 0, 3);\n },\n delete() {\n gl.deleteVertexArray(vao);\n },\n };\n}\n", "/** Storage format for a simulation texture. */\nexport interface TargetFormat {\n internalFormat: number;\n format: number;\n type: number;\n /** Linear filtering is supported. */\n filterable: boolean;\n /**\n * True when values must be packed into 8-bit channels because the device\n * cannot render to floating-point textures. Shaders must encode and decode.\n */\n packed: boolean;\n}\n\nexport interface FormatRequest {\n /**\n * 'float' prefers 32-bit floats (best for slowly-decaying waves), falling back\n * to half floats. 'half' starts at half floats (enough for fluids, less memory).\n */\n precision?: 'float' | 'half';\n /** Skip float formats entirely. Used by tests to exercise the 8-bit path. */\n forcePacked?: boolean;\n}\n\n/**\n * Picks the best renderable format for simulation data, verifying each candidate\n * with a real framebuffer because some drivers advertise formats they can't render:\n * RGBA32F, then RGBA16F, then RGBA8 with values packed by the shader.\n */\nexport function simulationFormat(\n gl: WebGL2RenderingContext,\n request: FormatRequest = {},\n): TargetFormat {\n const packed: TargetFormat = {\n internalFormat: gl.RGBA8,\n format: gl.RGBA,\n type: gl.UNSIGNED_BYTE,\n filterable: false,\n packed: true,\n };\n if (request.forcePacked) return packed;\n\n const colorBufferFloat = gl.getExtension('EXT_color_buffer_float') !== null;\n const colorBufferHalf = colorBufferFloat || gl.getExtension('EXT_color_buffer_half_float') !== null;\n\n if ((request.precision ?? 'float') === 'float' && colorBufferFloat) {\n const full: TargetFormat = {\n internalFormat: gl.RGBA32F,\n format: gl.RGBA,\n type: gl.FLOAT,\n filterable: gl.getExtension('OES_texture_float_linear') !== null,\n packed: false,\n };\n if (canRenderTo(gl, full)) return full;\n }\n if (colorBufferHalf) {\n const half: TargetFormat = {\n internalFormat: gl.RGBA16F,\n format: gl.RGBA,\n type: gl.HALF_FLOAT,\n filterable: true,\n packed: false,\n };\n if (canRenderTo(gl, half)) return half;\n }\n return packed;\n}\n\nfunction canRenderTo(gl: WebGL2RenderingContext, format: TargetFormat): boolean {\n const texture = gl.createTexture();\n const framebuffer = gl.createFramebuffer();\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texImage2D(gl.TEXTURE_2D, 0, format.internalFormat, 4, 4, 0, format.format, format.type, null);\n gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);\n const complete = gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE;\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n gl.bindTexture(gl.TEXTURE_2D, null);\n gl.deleteFramebuffer(framebuffer);\n gl.deleteTexture(texture);\n return complete;\n}\n\n/** A texture with a framebuffer attached, for rendering simulation steps into. */\nexport class RenderTarget {\n readonly texture: WebGLTexture;\n readonly framebuffer: WebGLFramebuffer;\n\n constructor(\n private readonly gl: WebGL2RenderingContext,\n readonly width: number,\n readonly height: number,\n readonly format: TargetFormat,\n filter: number = format.filterable ? gl.LINEAR : gl.NEAREST,\n ) {\n const texture = gl.createTexture();\n const framebuffer = gl.createFramebuffer();\n if (!texture || !framebuffer) throw new Error('[elementalfx] Could not allocate render target');\n this.texture = texture;\n this.framebuffer = framebuffer;\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n gl.texImage2D(\n gl.TEXTURE_2D,\n 0,\n format.internalFormat,\n width,\n height,\n 0,\n format.format,\n format.type,\n null,\n );\n gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);\n this.clear();\n }\n\n /** Binds this target for drawing and sets the viewport to its size. */\n bind(): void {\n this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.framebuffer);\n this.gl.viewport(0, 0, this.width, this.height);\n }\n\n /** Clears to zero (or to the packed encoding of zero). */\n clear(): void {\n const gl = this.gl;\n gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);\n // Packed values store 0 as 32767 (hi 127, lo 255) in each channel pair.\n if (this.format.packed) gl.clearColor(127 / 255, 1, 127 / 255, 1);\n else gl.clearColor(0, 0, 0, 0);\n gl.clear(gl.COLOR_BUFFER_BIT);\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n }\n\n delete(): void {\n this.gl.deleteFramebuffer(this.framebuffer);\n this.gl.deleteTexture(this.texture);\n }\n}\n\n/** Two render targets that swap roles each step: read from one, write to the other. */\nexport class PingPong {\n read: RenderTarget;\n write: RenderTarget;\n\n constructor(gl: WebGL2RenderingContext, width: number, height: number, format: TargetFormat) {\n this.read = new RenderTarget(gl, width, height, format);\n this.write = new RenderTarget(gl, width, height, format);\n }\n\n get width(): number {\n return this.read.width;\n }\n\n get height(): number {\n return this.read.height;\n }\n\n swap(): void {\n const read = this.read;\n this.read = this.write;\n this.write = read;\n }\n\n clear(): void {\n this.read.clear();\n this.write.clear();\n }\n\n delete(): void {\n this.read.delete();\n this.write.delete();\n }\n}\n\n/**\n * GLSL helpers for packing a signed value in [-1, 1] into two 8-bit channels\n * (16-bit precision) when float render targets are unavailable. Zero maps to\n * exactly 32767 so a cleared texture decodes to exactly 0.\n * `PACK_QUANTUM` is the smallest representable step.\n */\nexport const PACKING_GLSL = `\nconst float PACK_QUANTUM = 2.0 / 65534.0;\nvec2 packSigned(float value) {\n float v = floor(clamp(value * 0.5 + 0.5, 0.0, 1.0) * 65534.0 + 0.5);\n float hi = floor(v / 256.0);\n float lo = v - hi * 256.0;\n return vec2(hi, lo) / 255.0;\n}\nfloat unpackSigned(vec2 bytes) {\n vec2 b = floor(bytes * 255.0 + 0.5);\n return (b.x * 256.0 + b.y) / 65534.0 * 2.0 - 1.0;\n}\n`;\n", "/** Anything WebGL can upload as a texture that effects accept as a source. */\nexport type ImageSource =\n | HTMLImageElement\n | HTMLCanvasElement\n | HTMLVideoElement\n | ImageBitmap\n | OffscreenCanvas;\n\n/** Natural pixel size of a source, or 0\u00D70 if it isn't ready yet. */\nexport function sourceSize(source: ImageSource): { width: number; height: number } {\n if (source instanceof HTMLImageElement) {\n return { width: source.naturalWidth, height: source.naturalHeight };\n }\n if (source instanceof HTMLVideoElement) {\n return { width: source.videoWidth, height: source.videoHeight };\n }\n return { width: source.width, height: source.height };\n}\n\n/** Whether the source has pixels that can be uploaded right now. */\nexport function isSourceReady(source: ImageSource): boolean {\n if (source instanceof HTMLImageElement) return source.complete && source.naturalWidth > 0;\n if (source instanceof HTMLVideoElement) return source.readyState >= 2 && source.videoWidth > 0;\n const { width, height } = sourceSize(source);\n return width > 0 && height > 0;\n}\n\n/** Creates a texture with linear filtering and clamped edges. */\nexport function createTexture(gl: WebGL2RenderingContext): WebGLTexture {\n const texture = gl.createTexture();\n if (!texture) throw new Error('[elementalfx] Could not allocate texture');\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n return texture;\n}\n\n/**\n * Uploads a source with premultiplied alpha, top row first (so v = 0 is the\n * top of the image). Builds mipmaps when `mipmaps` is set, which keeps large\n * photos from shimmering when drawn small. Throws a SecurityError for\n * cross-origin pixels without CORS approval.\n */\nexport function uploadTexture(\n gl: WebGL2RenderingContext,\n texture: WebGLTexture,\n source: ImageSource,\n mipmaps = false,\n): void {\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);\n gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);\n if (mipmaps) {\n gl.generateMipmap(gl.TEXTURE_2D);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);\n } else {\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n }\n}\n\n/**\n * Loads an image URL for use as a texture. Requests CORS by default so\n * cross-origin images work when the server allows it.\n */\nexport function loadImage(url: string, crossOrigin: string | null = 'anonymous'): Promise<HTMLImageElement> {\n return new Promise((resolve, reject) => {\n const image = new Image();\n if (crossOrigin !== null && !url.startsWith('data:') && !url.startsWith('blob:')) {\n image.crossOrigin = crossOrigin;\n }\n image.decoding = 'async';\n image.onload = () => resolve(image);\n image.onerror = () => reject(new Error(`[elementalfx] Could not load image: ${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5C,KAAG,YAAY,GAAG,gCAAgC,IAAI;AACtD,KAAG,WAAW,GAAG,YAAY,GAAG,GAAG,MAAM,GAAG,MAAM,GAAG,eAAe,MAAM;AAC1E,KAAG,YAAY,GAAG,gCAAgC,KAAK;AACvD,MAAI,SAAS;AACX,OAAG,eAAe,GAAG,UAAU;AAC/B,OAAG,cAAc,GAAG,YAAY,GAAG,oBAAoB,GAAG,oBAAoB;AAAA,EAChF,OAAO;AACL,OAAG,cAAc,GAAG,YAAY,GAAG,oBAAoB,GAAG,MAAM;AAAA,EAClE;AACF;AAMO,SAAS,UAAU,KAAa,cAA6B,aAAwC;AAC1G,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,QAAQ,IAAI,MAAM;AACxB,QAAI,gBAAgB,QAAQ,CAAC,IAAI,WAAW,OAAO,KAAK,CAAC,IAAI,WAAW,OAAO,GAAG;AAChF,YAAM,cAAc;AAAA,IACtB;AACA,UAAM,WAAW;AACjB,UAAM,SAAS,MAAM,QAAQ,KAAK;AAClC,UAAM,UAAU,MAAM,OAAO,IAAI,MAAM,uCAAuC,GAAG,EAAE,CAAC;AACpF,UAAM,MAAM;AAAA,EACd,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** A linked shader program with its active uniform locations looked up by name. */
|
|
2
|
+
export interface Program {
|
|
3
|
+
readonly program: WebGLProgram;
|
|
4
|
+
readonly uniforms: Record<string, WebGLUniformLocation>;
|
|
5
|
+
use(): void;
|
|
6
|
+
delete(): void;
|
|
7
|
+
}
|
|
8
|
+
/** A vertex shader that covers the viewport with one triangle and passes `vUv` in [0, 1]. */
|
|
9
|
+
export declare const FULLSCREEN_VERTEX = "#version 300 es\nout vec2 vUv;\nvoid main() {\n vec2 corner = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));\n vUv = corner;\n gl_Position = vec4(corner * 2.0 - 1.0, 0.0, 1.0);\n}";
|
|
10
|
+
/** Compiles and links a program. Prepends `defines` as `#define` lines after the version line. */
|
|
11
|
+
export declare function createProgram(gl: WebGL2RenderingContext, vertexSource: string, fragmentSource: string, defines?: Record<string, string | number | boolean>): Program;
|
|
12
|
+
/**
|
|
13
|
+
* Draws one fullscreen triangle. WebGL2 can draw without vertex buffers;
|
|
14
|
+
* an empty vertex array object keeps every driver happy.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createFullscreenDraw(gl: WebGL2RenderingContext): {
|
|
17
|
+
draw(): void;
|
|
18
|
+
delete(): void;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=program.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IACxD,GAAG,IAAI,IAAI,CAAC;IACZ,MAAM,IAAI,IAAI,CAAC;CAChB;AAED,6FAA6F;AAC7F,eAAO,MAAM,iBAAiB,yMAM5B,CAAC;AAeH,kGAAkG;AAClG,wBAAgB,aAAa,CAC3B,EAAE,EAAE,sBAAsB,EAC1B,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,MAAM,EACtB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAM,GACtD,OAAO,CAuCT;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,sBAAsB,GAAG;IAChE,IAAI,IAAI,IAAI,CAAC;IACb,MAAM,IAAI,IAAI,CAAC;CAChB,CAWA"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** Storage format for a simulation texture. */
|
|
2
|
+
export interface TargetFormat {
|
|
3
|
+
internalFormat: number;
|
|
4
|
+
format: number;
|
|
5
|
+
type: number;
|
|
6
|
+
/** Linear filtering is supported. */
|
|
7
|
+
filterable: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* True when values must be packed into 8-bit channels because the device
|
|
10
|
+
* cannot render to floating-point textures. Shaders must encode and decode.
|
|
11
|
+
*/
|
|
12
|
+
packed: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface FormatRequest {
|
|
15
|
+
/**
|
|
16
|
+
* 'float' prefers 32-bit floats (best for slowly-decaying waves), falling back
|
|
17
|
+
* to half floats. 'half' starts at half floats (enough for fluids, less memory).
|
|
18
|
+
*/
|
|
19
|
+
precision?: 'float' | 'half';
|
|
20
|
+
/** Skip float formats entirely. Used by tests to exercise the 8-bit path. */
|
|
21
|
+
forcePacked?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Picks the best renderable format for simulation data, verifying each candidate
|
|
25
|
+
* with a real framebuffer because some drivers advertise formats they can't render:
|
|
26
|
+
* RGBA32F, then RGBA16F, then RGBA8 with values packed by the shader.
|
|
27
|
+
*/
|
|
28
|
+
export declare function simulationFormat(gl: WebGL2RenderingContext, request?: FormatRequest): TargetFormat;
|
|
29
|
+
/** A texture with a framebuffer attached, for rendering simulation steps into. */
|
|
30
|
+
export declare class RenderTarget {
|
|
31
|
+
private readonly gl;
|
|
32
|
+
readonly width: number;
|
|
33
|
+
readonly height: number;
|
|
34
|
+
readonly format: TargetFormat;
|
|
35
|
+
readonly texture: WebGLTexture;
|
|
36
|
+
readonly framebuffer: WebGLFramebuffer;
|
|
37
|
+
constructor(gl: WebGL2RenderingContext, width: number, height: number, format: TargetFormat, filter?: number);
|
|
38
|
+
/** Binds this target for drawing and sets the viewport to its size. */
|
|
39
|
+
bind(): void;
|
|
40
|
+
/** Clears to zero (or to the packed encoding of zero). */
|
|
41
|
+
clear(): void;
|
|
42
|
+
delete(): void;
|
|
43
|
+
}
|
|
44
|
+
/** Two render targets that swap roles each step: read from one, write to the other. */
|
|
45
|
+
export declare class PingPong {
|
|
46
|
+
read: RenderTarget;
|
|
47
|
+
write: RenderTarget;
|
|
48
|
+
constructor(gl: WebGL2RenderingContext, width: number, height: number, format: TargetFormat);
|
|
49
|
+
get width(): number;
|
|
50
|
+
get height(): number;
|
|
51
|
+
swap(): void;
|
|
52
|
+
clear(): void;
|
|
53
|
+
delete(): void;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* GLSL helpers for packing a signed value in [-1, 1] into two 8-bit channels
|
|
57
|
+
* (16-bit precision) when float render targets are unavailable. Zero maps to
|
|
58
|
+
* exactly 32767 so a cleared texture decodes to exactly 0.
|
|
59
|
+
* `PACK_QUANTUM` is the smallest representable step.
|
|
60
|
+
*/
|
|
61
|
+
export declare const PACKING_GLSL = "\nconst float PACK_QUANTUM = 2.0 / 65534.0;\nvec2 packSigned(float value) {\n float v = floor(clamp(value * 0.5 + 0.5, 0.0, 1.0) * 65534.0 + 0.5);\n float hi = floor(v / 256.0);\n float lo = v - hi * 256.0;\n return vec2(hi, lo) / 255.0;\n}\nfloat unpackSigned(vec2 bytes) {\n vec2 b = floor(bytes * 255.0 + 0.5);\n return (b.x * 256.0 + b.y) / 65534.0 * 2.0 - 1.0;\n}\n";
|
|
62
|
+
//# sourceMappingURL=targets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"targets.d.ts","sourceRoot":"","sources":["../src/targets.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,UAAU,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC7B,6EAA6E;IAC7E,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,sBAAsB,EAC1B,OAAO,GAAE,aAAkB,GAC1B,YAAY,CAkCd;AAiBD,kFAAkF;AAClF,qBAAa,YAAY;IAKrB,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,MAAM,EAAE,YAAY;IAP/B,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAAC;gBAGpB,EAAE,EAAE,sBAAsB,EAClC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,YAAY,EAC7B,MAAM,GAAE,MAAmD;IA4B7D,uEAAuE;IACvE,IAAI,IAAI,IAAI;IAKZ,0DAA0D;IAC1D,KAAK,IAAI,IAAI;IAUb,MAAM,IAAI,IAAI;CAIf;AAED,uFAAuF;AACvF,qBAAa,QAAQ;IACnB,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,EAAE,YAAY,CAAC;gBAER,EAAE,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY;IAK3F,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,IAAI,IAAI;IAMZ,KAAK,IAAI,IAAI;IAKb,MAAM,IAAI,IAAI;CAIf;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,6XAYxB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Anything WebGL can upload as a texture that effects accept as a source. */
|
|
2
|
+
export type ImageSource = HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageBitmap | OffscreenCanvas;
|
|
3
|
+
/** Natural pixel size of a source, or 0×0 if it isn't ready yet. */
|
|
4
|
+
export declare function sourceSize(source: ImageSource): {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
};
|
|
8
|
+
/** Whether the source has pixels that can be uploaded right now. */
|
|
9
|
+
export declare function isSourceReady(source: ImageSource): boolean;
|
|
10
|
+
/** Creates a texture with linear filtering and clamped edges. */
|
|
11
|
+
export declare function createTexture(gl: WebGL2RenderingContext): WebGLTexture;
|
|
12
|
+
/**
|
|
13
|
+
* Uploads a source with premultiplied alpha, top row first (so v = 0 is the
|
|
14
|
+
* top of the image). Builds mipmaps when `mipmaps` is set, which keeps large
|
|
15
|
+
* photos from shimmering when drawn small. Throws a SecurityError for
|
|
16
|
+
* cross-origin pixels without CORS approval.
|
|
17
|
+
*/
|
|
18
|
+
export declare function uploadTexture(gl: WebGL2RenderingContext, texture: WebGLTexture, source: ImageSource, mipmaps?: boolean): void;
|
|
19
|
+
/**
|
|
20
|
+
* Loads an image URL for use as a texture. Requests CORS by default so
|
|
21
|
+
* cross-origin images work when the server allows it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function loadImage(url: string, crossOrigin?: string | null): Promise<HTMLImageElement>;
|
|
24
|
+
//# sourceMappingURL=texture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"texture.d.ts","sourceRoot":"","sources":["../src/texture.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,MAAM,MAAM,WAAW,GACnB,gBAAgB,GAChB,iBAAiB,GACjB,gBAAgB,GAChB,WAAW,GACX,eAAe,CAAC;AAEpB,oEAAoE;AACpE,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAQjF;AAED,oEAAoE;AACpE,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAK1D;AAED,iEAAiE;AACjE,wBAAgB,aAAa,CAAC,EAAE,EAAE,sBAAsB,GAAG,YAAY,CAStE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,EAAE,EAAE,sBAAsB,EAC1B,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,WAAW,EACnB,OAAO,UAAQ,GACd,IAAI,CAYN;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,GAAE,MAAM,GAAG,IAAkB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAW1G"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementalfx/gl",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Small WebGL2 toolkit used by elementalfx effects: programs, ping-pong render targets with an 8-bit fallback, texture helpers.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"module": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"webgl2",
|
|
24
|
+
"gpgpu",
|
|
25
|
+
"shader",
|
|
26
|
+
"render-target",
|
|
27
|
+
"elementalfx",
|
|
28
|
+
"effects",
|
|
29
|
+
"animation",
|
|
30
|
+
"web-animation",
|
|
31
|
+
"webgl",
|
|
32
|
+
"web-components",
|
|
33
|
+
"custom-elements",
|
|
34
|
+
"framework-agnostic",
|
|
35
|
+
"reduced-motion",
|
|
36
|
+
"typescript"
|
|
37
|
+
],
|
|
38
|
+
"homepage": "https://iyerav42.github.io/elementalfx/",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/iyerav42/elementalfx.git",
|
|
42
|
+
"directory": "packages/gl"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/iyerav42/elementalfx/issues"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@elementalfx/core": "^0.1.0"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
}
|
|
6
53
|
}
|