@babylonjs/lite-gl 0.1.0 → 0.2.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.
Files changed (61) hide show
  1. package/README.md +10 -34
  2. package/apply-states.d.ts +1 -0
  3. package/apply-states.js +30 -0
  4. package/apply-states.js.map +1 -0
  5. package/blend.d.ts +123 -0
  6. package/blend.js +194 -0
  7. package/blend.js.map +1 -0
  8. package/context.d.ts +130 -0
  9. package/context.js +354 -0
  10. package/context.js.map +1 -0
  11. package/depth-stencil.d.ts +155 -231
  12. package/depth-stencil.js +399 -262
  13. package/depth-stencil.js.map +1 -1
  14. package/dynamic-texture.d.ts +59 -149
  15. package/dynamic-texture.js +123 -69
  16. package/dynamic-texture.js.map +1 -1
  17. package/effect-renderer.d.ts +65 -0
  18. package/effect-renderer.js +132 -0
  19. package/effect-renderer.js.map +1 -0
  20. package/effect.d.ts +142 -0
  21. package/effect.js +465 -0
  22. package/effect.js.map +1 -0
  23. package/html-texture.d.ts +44 -143
  24. package/html-texture.js +87 -81
  25. package/html-texture.js.map +1 -1
  26. package/index.d.ts +23 -1482
  27. package/index.js +42 -263
  28. package/index.js.map +1 -1
  29. package/mesh.d.ts +210 -307
  30. package/mesh.js +436 -311
  31. package/mesh.js.map +1 -1
  32. package/package.json +5 -29
  33. package/render-loop.d.ts +8 -0
  34. package/render-loop.js +62 -0
  35. package/render-loop.js.map +1 -0
  36. package/render-target.d.ts +233 -290
  37. package/render-target.js +534 -335
  38. package/render-target.js.map +1 -1
  39. package/scissor.d.ts +30 -72
  40. package/scissor.js +47 -33
  41. package/scissor.js.map +1 -1
  42. package/shader.d.ts +22 -0
  43. package/shader.js +65 -0
  44. package/shader.js.map +1 -0
  45. package/sprites.d.ts +182 -263
  46. package/sprites.js +426 -10
  47. package/sprites.js.map +1 -1
  48. package/state.d.ts +126 -0
  49. package/state.js +153 -0
  50. package/state.js.map +1 -0
  51. package/texture.d.ts +142 -0
  52. package/texture.js +433 -0
  53. package/texture.js.map +1 -0
  54. package/effect-BxxwfB_O.js +0 -737
  55. package/effect-BxxwfB_O.js.map +0 -1
  56. package/sprites--1oyVtJ3.js +0 -437
  57. package/sprites--1oyVtJ3.js.map +0 -1
  58. package/state--j_ncWIi.js +0 -155
  59. package/state--j_ncWIi.js.map +0 -1
  60. package/texture-DaMd1gGm.js +0 -329
  61. package/texture-DaMd1gGm.js.map +0 -1
package/index.js CHANGED
@@ -1,263 +1,42 @@
1
- import { u as useEffect, c as createEffect, d as disposeEffect } from "./effect-BxxwfB_O.js";
2
- import { a, b, e, g, f, h, i, j, o, k, l, m, r, s, n, p, q, t, v, w, x, y, z, A, B, C, D, E, F, G, H } from "./effect-BxxwfB_O.js";
3
- import { a as applyGLStates } from "./state--j_ncWIi.js";
4
- import { b as b2, c, a as a2, d, e as e2, g as g2, l as l2, u, f as f2, h as h2 } from "./texture-DaMd1gGm.js";
5
- import { clearDynamicTextureSource, createDynamicTexture, updateDynamicTexture } from "./dynamic-texture.js";
6
- import { bindRenderTarget, createFloatRenderTarget, createPingPong, createRenderTarget, disposePingPong, disposeRenderTarget, generateRenderTargetMipMaps, readRenderTargetPixels, resizePingPong, resizeRenderTarget } from "./render-target.js";
7
- import { bindAttributes, bindIndexBuffer, bindMeshVao, createIndexBuffer, createMeshVao, createVertexBuffer, disposeBuffer, disposeMeshVao, drawIndexed, drawMesh, unbindInstanceAttributes, updateVertexBuffer } from "./mesh.js";
8
- import { G as G2, a as a3, c as c2, d as d2, b as b3, r as r2, s as s2, e as e3, f as f3 } from "./sprites--1oyVtJ3.js";
9
- import { clearEngine, generateRenderTargetStencil, setColorMask, setCullState, setDepthState, setStencilState } from "./depth-stencil.js";
10
- import { disableScissor, setScissor } from "./scissor.js";
11
- import { GLSamplingMode, createHtmlElementTexture, updateHtmlElementTexture } from "./html-texture.js";
12
- function runRenderLoop(engine, fn) {
13
- if (engine._disposed) {
14
- return;
15
- }
16
- if (engine._scheduleFrame === null) {
17
- engine._scheduleFrame = scheduleFrame;
18
- }
19
- if (engine._loops.indexOf(fn) !== -1) {
20
- return;
21
- }
22
- engine._loops.push(fn);
23
- if (engine._rafId === 0 && !engine._isLost) {
24
- scheduleFrame(engine);
25
- }
26
- }
27
- function stopRenderLoop(engine, fn) {
28
- if (fn === void 0) {
29
- engine._loops.length = 0;
30
- } else {
31
- const i2 = engine._loops.indexOf(fn);
32
- if (i2 !== -1) {
33
- engine._loops.splice(i2, 1);
34
- }
35
- }
36
- if (engine._loops.length === 0 && engine._rafId !== 0) {
37
- cancelAnimationFrame(engine._rafId);
38
- engine._rafId = 0;
39
- }
40
- }
41
- function scheduleFrame(engine) {
42
- engine._prevNow = performance.now();
43
- engine._rafId = requestAnimationFrame((now) => tick(engine, now));
44
- }
45
- function tick(engine, now) {
46
- engine._rafId = 0;
47
- if (engine._disposed || engine._isLost || engine._loops.length === 0) {
48
- return;
49
- }
50
- const dt = now - engine._prevNow;
51
- engine._prevNow = now;
52
- const loops = engine._loops.slice();
53
- for (const cb of loops) {
54
- try {
55
- cb(dt);
56
- } catch (err) {
57
- console.error("lite-gl: render loop callback threw", err);
58
- }
59
- }
60
- if (engine._loops.length > 0 && !engine._disposed && !engine._isLost) {
61
- engine._rafId = requestAnimationFrame((nextNow) => tick(engine, nextNow));
62
- }
63
- }
64
- const DEFAULT_FULLSCREEN_VERTEX_SOURCE = `#version 300 es
65
- layout(location = 0) in vec2 position;
66
- out vec2 vUv;
67
- void main() {
68
- vUv = position * 0.5 + 0.5;
69
- gl_Position = vec4(position, 0.0, 1.0);
70
- }`;
71
- function createEffectWrapper(engine, options) {
72
- const name = options.name ?? "effect-wrapper";
73
- const effect = createEffect(engine, {
74
- name,
75
- vertexSource: options.vertexSource ?? DEFAULT_FULLSCREEN_VERTEX_SOURCE,
76
- fragmentSource: options.fragmentSource,
77
- uniformNames: options.uniformNames ?? [],
78
- samplerNames: options.samplerNames ?? [],
79
- attributeNames: options.attributeNames,
80
- defines: options.defines
81
- });
82
- return { name, effect, _engine: engine, _disposed: false };
83
- }
84
- function disposeEffectWrapper(wrapper) {
85
- if (wrapper._disposed) {
86
- return;
87
- }
88
- wrapper._disposed = true;
89
- disposeEffect(wrapper._engine, wrapper.effect);
90
- }
91
- function setViewport(engine, viewport) {
92
- if (engine._isLost || engine._disposed) {
93
- return;
94
- }
95
- const x2 = (viewport == null ? void 0 : viewport.x) ?? 0;
96
- const y2 = (viewport == null ? void 0 : viewport.y) ?? 0;
97
- const w2 = (viewport == null ? void 0 : viewport.w) ?? engine.canvas.width;
98
- const h3 = (viewport == null ? void 0 : viewport.h) ?? engine.canvas.height;
99
- const s3 = engine._state;
100
- if (s3.viewportX === x2 && s3.viewportY === y2 && s3.viewportW === w2 && s3.viewportH === h3) {
101
- return;
102
- }
103
- s3.viewportX = x2;
104
- s3.viewportY = y2;
105
- s3.viewportW = w2;
106
- s3.viewportH = h3;
107
- engine.gl.viewport(x2, y2, w2, h3);
108
- }
109
- function applyEffectWrapper(wrapper) {
110
- const engine = wrapper._engine;
111
- if (engine._isLost || engine._disposed || wrapper._disposed) {
112
- return;
113
- }
114
- ensureQuad(engine);
115
- useEffect(engine, wrapper.effect);
116
- }
117
- function drawEffect(engine) {
118
- if (engine._isLost || engine._disposed) {
119
- return;
120
- }
121
- if (engine._state.currentProgram === null) {
122
- return;
123
- }
124
- applyGLStates(engine);
125
- engine.gl.drawElements(engine.gl.TRIANGLES, 6, engine.gl.UNSIGNED_SHORT, 0);
126
- }
127
- function ensureQuad(engine) {
128
- const s3 = engine._state;
129
- const gl = engine.gl;
130
- if (s3.quadVao !== null) {
131
- if (s3.boundVao !== s3.quadVao) {
132
- gl.bindVertexArray(s3.quadVao);
133
- s3.boundVao = s3.quadVao;
134
- }
135
- return;
136
- }
137
- const vao = gl.createVertexArray();
138
- if (vao === null) {
139
- throw new Error("lite-gl: gl.createVertexArray returned null");
140
- }
141
- s3.quadVao = vao;
142
- gl.bindVertexArray(vao);
143
- s3.boundVao = vao;
144
- const vbo = gl.createBuffer();
145
- if (vbo === null) {
146
- throw new Error("lite-gl: gl.createBuffer returned null (VBO)");
147
- }
148
- s3.quadVbo = vbo;
149
- gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
150
- s3.boundArrayBuffer = vbo;
151
- gl.bufferData(gl.ARRAY_BUFFER, QUAD_POSITIONS, gl.STATIC_DRAW);
152
- const ibo = gl.createBuffer();
153
- if (ibo === null) {
154
- throw new Error("lite-gl: gl.createBuffer returned null (IBO)");
155
- }
156
- s3.quadIbo = ibo;
157
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo);
158
- s3.boundElementBuffer = ibo;
159
- gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, QUAD_INDICES, gl.STATIC_DRAW);
160
- gl.enableVertexAttribArray(0);
161
- gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
162
- }
163
- const QUAD_POSITIONS = new Float32Array([1, 1, -1, 1, -1, -1, 1, -1]);
164
- const QUAD_INDICES = new Uint16Array([0, 1, 2, 0, 2, 3]);
165
- export {
166
- G2 as GLBlendEquation,
167
- a3 as GLBlendMode,
168
- GLSamplingMode,
169
- applyEffectWrapper,
170
- bindAttributes,
171
- bindIndexBuffer,
172
- bindMeshVao,
173
- bindRenderTarget,
174
- b2 as bindTexture,
175
- clearDynamicTextureSource,
176
- clearEngine,
177
- createDynamicTexture,
178
- createEffect,
179
- createEffectWrapper,
180
- createFloatRenderTarget,
181
- c as createFloatTexture,
182
- a as createGLEngine,
183
- createHtmlElementTexture,
184
- createIndexBuffer,
185
- createMeshVao,
186
- createPingPong,
187
- a2 as createRawTexture,
188
- createRenderTarget,
189
- c2 as createSpriteRenderer,
190
- d as createTextureFromHandle,
191
- createVertexBuffer,
192
- d2 as disableBlend,
193
- disableScissor,
194
- disposeBuffer,
195
- disposeEffect,
196
- disposeEffectWrapper,
197
- b as disposeGLEngine,
198
- disposeMeshVao,
199
- disposePingPong,
200
- disposeRenderTarget,
201
- b3 as disposeSpriteRenderer,
202
- e2 as disposeTexture,
203
- drawEffect,
204
- drawIndexed,
205
- drawMesh,
206
- e as executeWhenCompiled,
207
- generateRenderTargetMipMaps,
208
- generateRenderTargetStencil,
209
- g2 as generateTextureMipMaps,
210
- g as getHardwareScalingLevel,
211
- f as getRenderHeight,
212
- h as getRenderWidth,
213
- i as getRenderingCanvas,
214
- j as isEffectReady,
215
- l2 as loadTexture2D,
216
- o as offContextLost,
217
- k as offContextRestored,
218
- l as onContextLost,
219
- m as onContextRestored,
220
- readRenderTargetPixels,
221
- r2 as renderSprites,
222
- r as resizeGLEngine,
223
- resizePingPong,
224
- resizeRenderTarget,
225
- runRenderLoop,
226
- s2 as setBlendMode,
227
- e3 as setBlendState,
228
- setColorMask,
229
- setCullState,
230
- setDepthState,
231
- s as setEffectColor3,
232
- n as setEffectColor4,
233
- p as setEffectDirectColor4,
234
- q as setEffectFloat,
235
- t as setEffectFloat2,
236
- v as setEffectFloat3,
237
- w as setEffectFloat4,
238
- x as setEffectFloatArray,
239
- y as setEffectFloatArray4,
240
- z as setEffectInt,
241
- A as setEffectIntArray,
242
- B as setEffectMatrix,
243
- C as setEffectMatrix3x3,
244
- D as setEffectTexture,
245
- E as setEffectVector2,
246
- F as setGLEngineSize,
247
- G as setHardwareScalingLevel,
248
- setScissor,
249
- f3 as setSpriteRendererTexture,
250
- setStencilState,
251
- setViewport,
252
- stopRenderLoop,
253
- unbindInstanceAttributes,
254
- updateDynamicTexture,
255
- updateHtmlElementTexture,
256
- u as updateRawTexture,
257
- f2 as updateTextureSamplingMode,
258
- h2 as updateTextureWrapMode,
259
- updateVertexBuffer,
260
- useEffect,
261
- H as wipeGLStateCache
262
- };
263
- //# sourceMappingURL=index.js.map
1
+ // @babylonjs/lite-gl Public API
2
+ // Function-based, tree-shakeable WebGL2 micro-engine. Import only what you use.
3
+ //
4
+ // Convention (mirrors @babylonjs/lite): the public API is re-exported EXPLICITLY
5
+ // by name never `export *`. This keeps the public surface intentional and
6
+ // reviewable, lets `export type` mark type-only re-exports (required under
7
+ // `isolatedModules`), and keeps internal helpers (e.g. `bindTextureRaw`,
8
+ // `bindTextureForUpload`) out of consumers' bundles + `.d.ts`.
9
+ //
10
+ // The package is `sideEffects: false` and no module has top-level side effects,
11
+ // so a consumer that imports only the symbols it needs tree-shakes everything
12
+ // else (sprites, html-texture, …) away.
13
+ // ─── Engine / context ────────────────────────────────────────────────
14
+ export { createGLEngine, disposeGLEngine, resizeGLEngine, setGLEngineSize, wipeGLStateCache, getRenderWidth, getRenderHeight, getHardwareScalingLevel, setHardwareScalingLevel, getRenderingCanvas, onContextLost, offContextLost, onContextRestored, offContextRestored, } from "./context.js";
15
+ // ─── Render loop ─────────────────────────────────────────────────────
16
+ export { runRenderLoop, stopRenderLoop } from "./render-loop.js";
17
+ // ─── Effects ─────────────────────────────────────────────────────────
18
+ export { createEffect, useEffect, isEffectReady, executeWhenCompiled, disposeEffect, setEffectFloat, setEffectFloat2, setEffectFloat3, setEffectFloat4, setEffectColor3, setEffectColor4, setEffectVector2, setEffectDirectColor4, setEffectInt, setEffectTexture, setEffectMatrix, setEffectMatrix3x3, setEffectFloatArray, setEffectFloatArray4, setEffectIntArray, } from "./effect.js";
19
+ // ─── Effect renderer (fullscreen quad) ───────────────────────────────
20
+ export { createEffectWrapper, applyEffectWrapper, drawEffect, setViewport, disposeEffectWrapper } from "./effect-renderer.js";
21
+ // ─── Textures ────────────────────────────────────────────────────────
22
+ export { createRawTexture, createFloatTexture, generateTextureMipMaps, loadTexture2D, bindTexture, disposeTexture, updateRawTexture, updateTextureSamplingMode, updateTextureWrapMode, createTextureFromHandle, } from "./texture.js";
23
+ // ─── Dynamic textures ────────────────────────────────────────────────
24
+ export { createDynamicTexture, updateDynamicTexture, clearDynamicTextureSource } from "./dynamic-texture.js";
25
+ // ─── Render targets ──────────────────────────────────────────────────
26
+ export { createRenderTarget, createFloatRenderTarget, bindRenderTarget, generateRenderTargetMipMaps, resizeRenderTarget, readRenderTargetPixels, disposeRenderTarget, createPingPong, resizePingPong, disposePingPong, } from "./render-target.js";
27
+ // ─── Meshes / buffers / instancing ───────────────────────────────────
28
+ export { createVertexBuffer, updateVertexBuffer, createIndexBuffer, disposeBuffer, bindIndexBuffer, bindAttributes, unbindInstanceAttributes, drawIndexed, createMeshVao, bindMeshVao, drawMesh, disposeMeshVao, } from "./mesh.js";
29
+ // ─── Blend modes ─────────────────────────────────────────────────────
30
+ // GLBlendMode / GLBlendEquation are const + same-name type; one value
31
+ // re-export carries both.
32
+ export { GLBlendMode, GLBlendEquation, setBlendMode, setBlendState, disableBlend } from "./blend.js";
33
+ // ─── Depth / stencil / color-mask / clear ────────────────────────────
34
+ export { setDepthState, setCullState, setStencilState, setColorMask, clearEngine, generateRenderTargetStencil } from "./depth-stencil.js";
35
+ // ─── Scissor ─────────────────────────────────────────────────────────
36
+ export { setScissor, disableScissor } from "./scissor.js";
37
+ // ─── Sprites ─────────────────────────────────────────────────────────
38
+ export { createSpriteRenderer, renderSprites, setSpriteRendererTexture, disposeSpriteRenderer } from "./sprites.js";
39
+ // ─── HTML-element textures ───────────────────────────────────────────
40
+ // GLSamplingMode is a const + same-name type; one value re-export carries both.
41
+ export { createHtmlElementTexture, updateHtmlElementTexture, GLSamplingMode } from "./html-texture.js";
42
+ //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/render-loop.ts","../src/effect-renderer.ts"],"sourcesContent":["import { type GLEngineContext } from \"./context.js\";\n\n/** Register a per-frame callback. **No-op if `fn` is already registered**\n * (matches Babylon `AbstractEngine.runRenderLoop`). Starts the rAF if this is\n * the first registration. */\nexport function runRenderLoop(engine: GLEngineContext, fn: (dt: number) => void): void {\n if (engine._disposed) {\n return;\n }\n // Install the resume hook on the context (no module-level side effects).\n if (engine._scheduleFrame === null) {\n engine._scheduleFrame = scheduleFrame;\n }\n if (engine._loops.indexOf(fn) !== -1) {\n return;\n }\n engine._loops.push(fn);\n if (engine._rafId === 0 && !engine._isLost) {\n scheduleFrame(engine);\n }\n}\n\n/** Stop one (or all when omitted) registered callbacks. Cancels the rAF if\n * no callbacks remain. */\nexport function stopRenderLoop(engine: GLEngineContext, fn?: (dt: number) => void): void {\n if (fn === undefined) {\n engine._loops.length = 0;\n } else {\n const i = engine._loops.indexOf(fn);\n if (i !== -1) {\n engine._loops.splice(i, 1);\n }\n }\n if (engine._loops.length === 0 && engine._rafId !== 0) {\n cancelAnimationFrame(engine._rafId);\n engine._rafId = 0;\n }\n}\n\nfunction scheduleFrame(engine: GLEngineContext): void {\n engine._prevNow = performance.now();\n engine._rafId = requestAnimationFrame((now) => tick(engine, now));\n}\n\nfunction tick(engine: GLEngineContext, now: number): void {\n engine._rafId = 0;\n if (engine._disposed || engine._isLost || engine._loops.length === 0) {\n return;\n }\n const dt = now - engine._prevNow;\n engine._prevNow = now;\n // Snapshot — a callback may call stopRenderLoop on itself or others.\n const loops = engine._loops.slice();\n for (const cb of loops) {\n try {\n cb(dt);\n } catch (err) {\n console.error(\"lite-gl: render loop callback threw\", err);\n }\n }\n if (engine._loops.length > 0 && !engine._disposed && !engine._isLost) {\n engine._rafId = requestAnimationFrame((nextNow) => tick(engine, nextNow));\n }\n}\n","import type { GLEngineContext } from \"./context.js\";\nimport { createEffect, disposeEffect, type GLEffect, useEffect } from \"./effect.js\";\nimport { applyGLStates } from \"./apply-states.js\";\n\n/** Built-in fullscreen-quad vertex shader, used when `GLEffectWrapperOptions`\n * omits `vertexSource`. Maps the package's fullscreen-quad positions\n * (attribute location 0) to clip space and forwards a 0..1 `vUv` varying —\n * the WebGL counterpart of lite's default `vertexWGSL`, so callers can pass\n * only `fragmentSource`. */\nconst DEFAULT_FULLSCREEN_VERTEX_SOURCE = `#version 300 es\nlayout(location = 0) in vec2 position;\nout vec2 vUv;\nvoid main() {\n vUv = position * 0.5 + 0.5;\n gl_Position = vec4(position, 0.0, 1.0);\n}`;\n\n/** Inputs to `createEffectWrapper`. Mirrors lite's `EffectWrapperOptions`: the\n * wrapper compiles and OWNS the effect built from this shader source. */\nexport interface GLEffectWrapperOptions {\n /** Human-readable label for the wrapper and its effect. Defaults to\n * `\"effect-wrapper\"`. */\n name?: string;\n /** GLSL ES 3.00 vertex source. Defaults to a built-in fullscreen-quad\n * vertex shader (exposing a `vUv` varying), mirroring lite's default\n * `vertexWGSL`. */\n vertexSource?: string;\n /** GLSL ES 3.00 fragment source (≙ lite's `fragmentWGSL`). Required. */\n fragmentSource: string;\n /** Declared uniform names. Defaults to none. */\n uniformNames?: readonly string[];\n /** Declared sampler names, in unit-assignment order. Defaults to none. */\n samplerNames?: readonly string[];\n /** Attribute names; the first is bound to location 0. Defaults to\n * `[\"position\"]`. */\n attributeNames?: readonly string[];\n /** Optional `#define` block prepended to both shader stages. */\n defines?: string;\n}\n\n/** A reusable fullscreen effect that compiles and OWNS its `GLEffect` — the\n * WebGL counterpart of lite's `EffectWrapper`. The wrapper retains the engine\n * it was created for, so `disposeEffectWrapper` / `applyEffectWrapper` take\n * only the wrapper. */\nexport interface GLEffectWrapper {\n /** Name alias for the wrapper (and its effect). */\n readonly name: string;\n /** The compiled effect this wrapper owns. Exposed so the per-uniform\n * setters (`setEffectFloat`/`setEffectTexture`/…) can target it — the\n * WebGL divergence from lite's UBO-based `setEffectUniforms(wrapper, …)`. */\n readonly effect: GLEffect;\n /** @internal The engine the wrapper was created for. */\n _engine: GLEngineContext;\n /** @internal */\n _disposed: boolean;\n}\n\n/** Compile a fullscreen effect from shader source and wrap it; the wrapper OWNS\n * the resulting `GLEffect`. Mirrors lite's `createEffectWrapper(engine, options)`.\n * When `vertexSource` is omitted, a built-in fullscreen-quad vertex shader is\n * used, so callers can supply only `fragmentSource`. */\nexport function createEffectWrapper(engine: GLEngineContext, options: GLEffectWrapperOptions): GLEffectWrapper {\n const name = options.name ?? \"effect-wrapper\";\n const effect = createEffect(engine, {\n name,\n vertexSource: options.vertexSource ?? DEFAULT_FULLSCREEN_VERTEX_SOURCE,\n fragmentSource: options.fragmentSource,\n uniformNames: options.uniformNames ?? [],\n samplerNames: options.samplerNames ?? [],\n attributeNames: options.attributeNames,\n defines: options.defines,\n });\n return { name, effect, _engine: engine, _disposed: false };\n}\n\n/** Dispose the wrapper and the effect it owns (idempotent). Mirrors lite's\n * `disposeEffectWrapper(wrapper)`. */\nexport function disposeEffectWrapper(wrapper: GLEffectWrapper): void {\n if (wrapper._disposed) {\n return;\n }\n wrapper._disposed = true;\n disposeEffect(wrapper._engine, wrapper.effect);\n}\n\n/** Pixel-space viewport rectangle passed to `setViewport`. */\nexport interface GLViewport {\n /** Lower-left X origin in physical pixels. */\n x: number;\n /** Lower-left Y origin in physical pixels. */\n y: number;\n /** Width in physical pixels. */\n w: number;\n /** Height in physical pixels. */\n h: number;\n}\n\n/** Cached `gl.viewport`. Defaults to the full canvas in pixel coordinates. */\nexport function setViewport(engine: GLEngineContext, viewport?: GLViewport): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const x = viewport?.x ?? 0;\n const y = viewport?.y ?? 0;\n const w = viewport?.w ?? engine.canvas.width;\n const h = viewport?.h ?? engine.canvas.height;\n const s = engine._state;\n if (s.viewportX === x && s.viewportY === y && s.viewportW === w && s.viewportH === h) {\n return;\n }\n s.viewportX = x;\n s.viewportY = y;\n s.viewportW = w;\n s.viewportH = h;\n engine.gl.viewport(x, y, w, h);\n}\n\n/** Make `wrapper.effect` current and ensure the shared fullscreen quad VAO\n * is bound. This MUST be called BEFORE any `setEffect*` call for the same\n * effect in the current frame (uniform setters write to the currently bound\n * program). */\nexport function applyEffectWrapper(wrapper: GLEffectWrapper): void {\n const engine = wrapper._engine;\n if (engine._isLost || engine._disposed || wrapper._disposed) {\n return;\n }\n ensureQuad(engine);\n useEffect(engine, wrapper.effect);\n}\n\n/** `gl.drawElements(TRIANGLES, 6, UNSIGNED_SHORT, 0)`. No-op when the\n * context is lost or there is no current program. */\nexport function drawEffect(engine: GLEngineContext): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n if (engine._state.currentProgram === null) {\n return;\n }\n applyGLStates(engine);\n engine.gl.drawElements(engine.gl.TRIANGLES, 6, engine.gl.UNSIGNED_SHORT, 0);\n}\n\n/** Lazy fullscreen quad. Built on first call; thereafter the VAO is cached on\n * `_state.quadVao` and rebinding is a single cached call. Cleared by\n * `webglcontextlost` and transparently rebuilt by the next\n * `applyEffectWrapper` after restore.\n *\n * Position attribute is enabled at location 0 — every effect's\n * `createEffect` calls `gl.bindAttribLocation(program, 0, attributeNames[0])`\n * BEFORE link, so the shared VAO is correct across all programs. */\nfunction ensureQuad(engine: GLEngineContext): void {\n const s = engine._state;\n const gl = engine.gl;\n if (s.quadVao !== null) {\n if (s.boundVao !== s.quadVao) {\n gl.bindVertexArray(s.quadVao);\n s.boundVao = s.quadVao;\n }\n return;\n }\n const vao = gl.createVertexArray();\n if (vao === null) {\n throw new Error(\"lite-gl: gl.createVertexArray returned null\");\n }\n s.quadVao = vao;\n gl.bindVertexArray(vao);\n s.boundVao = vao;\n\n const vbo = gl.createBuffer();\n if (vbo === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (VBO)\");\n }\n s.quadVbo = vbo;\n gl.bindBuffer(gl.ARRAY_BUFFER, vbo);\n s.boundArrayBuffer = vbo;\n gl.bufferData(gl.ARRAY_BUFFER, QUAD_POSITIONS, gl.STATIC_DRAW);\n\n const ibo = gl.createBuffer();\n if (ibo === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (IBO)\");\n }\n s.quadIbo = ibo;\n gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo);\n s.boundElementBuffer = ibo;\n gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, QUAD_INDICES, gl.STATIC_DRAW);\n\n gl.enableVertexAttribArray(0);\n gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n}\n\n/** Typed-array literal — pure per bundler convention. Matches Babylon's\n * `EffectRenderer` default geometry exactly. */\nconst QUAD_POSITIONS = new Float32Array([1, 1, -1, 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AM,cAAc,CAAC;AAGpH,wEAAwE;AACxE,gFAAgF;AAChF,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["// @babylonjs/lite-gl — Public API\n// Function-based, tree-shakeable WebGL2 micro-engine. Import only what you use.\n//\n// Convention (mirrors @babylonjs/lite): the public API is re-exported EXPLICITLY\n// by name — never `export *`. This keeps the public surface intentional and\n// reviewable, lets `export type` mark type-only re-exports (required under\n// `isolatedModules`), and keeps internal helpers (e.g. `bindTextureRaw`,\n// `bindTextureForUpload`) out of consumers' bundles + `.d.ts`.\n//\n// The package is `sideEffects: false` and no module has top-level side effects,\n// so a consumer that imports only the symbols it needs tree-shakes everything\n// else (sprites, html-texture, …) away.\n\n// ─── Engine / context ────────────────────────────────────────────────\nexport {\n createGLEngine,\n disposeGLEngine,\n resizeGLEngine,\n setGLEngineSize,\n wipeGLStateCache,\n getRenderWidth,\n getRenderHeight,\n getHardwareScalingLevel,\n setHardwareScalingLevel,\n getRenderingCanvas,\n onContextLost,\n offContextLost,\n onContextRestored,\n offContextRestored,\n} from \"./context.js\";\nexport type { GLEngineOptions, GLEngineCaps, GLEngineContext } from \"./context.js\";\n\n// ─── Render loop ─────────────────────────────────────────────────────\nexport { runRenderLoop, stopRenderLoop } from \"./render-loop.js\";\n\n// ─── Effects ─────────────────────────────────────────────────────────\nexport {\n createEffect,\n useEffect,\n isEffectReady,\n executeWhenCompiled,\n disposeEffect,\n setEffectFloat,\n setEffectFloat2,\n setEffectFloat3,\n setEffectFloat4,\n setEffectColor3,\n setEffectColor4,\n setEffectVector2,\n setEffectDirectColor4,\n setEffectInt,\n setEffectTexture,\n setEffectMatrix,\n setEffectMatrix3x3,\n setEffectFloatArray,\n setEffectFloatArray4,\n setEffectIntArray,\n} from \"./effect.js\";\nexport type { GLEffectOptions, GLEffect } from \"./effect.js\";\n\n// ─── Effect renderer (fullscreen quad) ───────────────────────────────\nexport { createEffectWrapper, applyEffectWrapper, drawEffect, setViewport, disposeEffectWrapper } from \"./effect-renderer.js\";\nexport type { GLEffectWrapperOptions, GLEffectWrapper, GLViewport } from \"./effect-renderer.js\";\n\n// ─── Textures ────────────────────────────────────────────────────────\nexport {\n createRawTexture,\n createFloatTexture,\n generateTextureMipMaps,\n loadTexture2D,\n bindTexture,\n disposeTexture,\n updateRawTexture,\n updateTextureSamplingMode,\n updateTextureWrapMode,\n createTextureFromHandle,\n} from \"./texture.js\";\nexport type { GLTextureOptions, GLFloatTextureOptions, GLTexture } from \"./texture.js\";\n\n// ─── Dynamic textures ────────────────────────────────────────────────\nexport { createDynamicTexture, updateDynamicTexture, clearDynamicTextureSource } from \"./dynamic-texture.js\";\n\n// ─── Render targets ──────────────────────────────────────────────────\nexport {\n createRenderTarget,\n createFloatRenderTarget,\n bindRenderTarget,\n generateRenderTargetMipMaps,\n resizeRenderTarget,\n readRenderTargetPixels,\n disposeRenderTarget,\n createPingPong,\n resizePingPong,\n disposePingPong,\n} from \"./render-target.js\";\nexport type { GLRenderTarget, GLRenderTargetOptions, GLFloatRenderTargetOptions, GLPingPong } from \"./render-target.js\";\n\n// ─── Meshes / buffers / instancing ───────────────────────────────────\nexport {\n createVertexBuffer,\n updateVertexBuffer,\n createIndexBuffer,\n disposeBuffer,\n bindIndexBuffer,\n bindAttributes,\n unbindInstanceAttributes,\n drawIndexed,\n createMeshVao,\n bindMeshVao,\n drawMesh,\n disposeMeshVao,\n} from \"./mesh.js\";\nexport type { GLVertexBuffer, GLIndexBuffer, GLAttributeDescriptor, GLMeshVertexBuffer, GLMeshVao } from \"./mesh.js\";\n\n// ─── Blend modes ─────────────────────────────────────────────────────\n// GLBlendMode / GLBlendEquation are const + same-name type; one value\n// re-export carries both.\nexport { GLBlendMode, GLBlendEquation, setBlendMode, setBlendState, disableBlend } from \"./blend.js\";\nexport type { GLBlendState } from \"./blend.js\";\n\n// ─── Depth / stencil / color-mask / clear ────────────────────────────\nexport { setDepthState, setCullState, setStencilState, setColorMask, clearEngine, generateRenderTargetStencil } from \"./depth-stencil.js\";\nexport type { GLDepthState, GLStencilState, GLClearOptions } from \"./depth-stencil.js\";\n\n// ─── Scissor ─────────────────────────────────────────────────────────\nexport { setScissor, disableScissor } from \"./scissor.js\";\n\n// ─── Sprites ─────────────────────────────────────────────────────────\nexport { createSpriteRenderer, renderSprites, setSpriteRendererTexture, disposeSpriteRenderer } from \"./sprites.js\";\nexport type { GLSprite, GLSpriteColor, GLSpriteRendererOptions, GLSpriteRenderer } from \"./sprites.js\";\n\n// ─── HTML-element textures ───────────────────────────────────────────\n// GLSamplingMode is a const + same-name type; one value re-export carries both.\nexport { createHtmlElementTexture, updateHtmlElementTexture, GLSamplingMode } from \"./html-texture.js\";\nexport type { GLHtmlElementTextureOptions } from \"./html-texture.js\";\n"]}