@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
@@ -1,231 +1,155 @@
1
- /**
2
- * Clear the currently-bound framebuffer's color / depth / stencil buffers — the
3
- * lite-gl equivalent of Babylon's `clear(color, backBuffer, depth, stencil)`.
4
- * Depth/stencil clears respect the current write masks (set them first via
5
- * {@link setDepthState} / {@link setStencilState}). No-op when nothing is
6
- * requested or the context is lost/disposed.
7
- *
8
- * @param engine - The engine.
9
- * @param options - Which buffers to clear (and the color value).
10
- */
11
- export declare function clearEngine(engine: GLEngineContext, options: GLClearOptions): void;
12
-
13
- /**
14
- * Opt-in: give a `/render-target` {@link GLRenderTarget} a stencil attachment,
15
- * replacing the core's depth-only `DEPTH_COMPONENT16` renderbuffer with either a
16
- * packed **`DEPTH24_STENCIL8`** buffer (default depth *and* stencil) or a
17
- * stencil-only **`STENCIL_INDEX8`** buffer.
18
- *
19
- * Stencil is intentionally NOT a {@link createRenderTarget} option: keeping this
20
- * helper in the `/depth-stencil` sub-entry means the stencil/packed renderbuffer
21
- * code tree-shakes out of every bundle that only needs a color (and optional
22
- * depth) target.
23
- *
24
- * The attachment is **restore-correct**: it is rebuilt automatically — at the new
25
- * size on {@link resizeRenderTarget}, and into the fresh framebuffer after a
26
- * `webglcontextrestored` event so the stencil survives for the life of the
27
- * target, and {@link disposeRenderTarget} releases it along with the target.
28
- *
29
- * No-op on a lost/disposed context or a disposed target.
30
- *
31
- * @param engine - The engine that owns `rt`.
32
- * @param rt - The render target to attach the stencil buffer to.
33
- * @param options - `depth` (default `true`): when `true` the attachment is a
34
- * packed depth+stencil buffer (`DEPTH24_STENCIL8` on `DEPTH_STENCIL_ATTACHMENT`)
35
- * — the common case, and the correct choice when the target was created with
36
- * `generateDepthBuffer: true`. When `false` the attachment is stencil-only
37
- * (`STENCIL_INDEX8` on `STENCIL_ATTACHMENT`).
38
- * @throws If a renderbuffer handle could not be allocated or the framebuffer is
39
- * incomplete after attaching.
40
- */
41
- export declare function generateRenderTargetStencil(engine: GLEngineContext, rt: GLRenderTarget, options?: {
42
- depth?: boolean;
43
- }): void;
44
-
45
- /** Options for {@link clearEngine}. */
46
- export declare interface GLClearOptions {
47
- /** When set, clears the color buffer to this RGBA color (alpha default 1). */
48
- color?: {
49
- r: number;
50
- g: number;
51
- b: number;
52
- a?: number;
53
- };
54
- /** Clear the depth buffer (respects the current depth write mask). */
55
- depth?: boolean;
56
- /** Clear the stencil buffer (respects the current stencil write mask). */
57
- stencil?: boolean;
58
- }
59
-
60
- /** Depth-buffer configuration for {@link setDepthState}. Omitted fields are
61
- * left unchanged. */
62
- export declare interface GLDepthState {
63
- /** Enable/disable the depth test (`gl.enable/disable(DEPTH_TEST)`). */
64
- test?: boolean;
65
- /** Enable/disable depth writes (`gl.depthMask`). */
66
- write?: boolean;
67
- /** Depth comparison function (`gl.depthFunc`), e.g. `gl.LESS`. */
68
- func?: GLenum;
69
- }
70
-
71
- /** Read-only WebGL2 capability limits, queried once at context creation. */
72
- declare interface GLEngineCaps {
73
- /** `gl.MAX_TEXTURE_SIZE` largest supported texture dimension, in texels. */
74
- readonly maxTextureSize: number;
75
- /** `gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS` number of sampler binding slots. */
76
- readonly maxTextureUnits: number;
77
- /** The `KHR_parallel_shader_compile` extension used for async link polling,
78
- * or null when unsupported linking is then treated as synchronous. */
79
- readonly parallelShaderCompile: {
80
- COMPLETION_STATUS_KHR: number;
81
- } | null;
82
- /** True when 32-bit float color attachments are renderable
83
- * (`EXT_color_buffer_float`). Mirrors Babylon's `caps.textureFloatRender`. */
84
- readonly textureFloatRender: boolean;
85
- /** True when 32-bit float textures support linear filtering
86
- * (`OES_texture_float_linear`). Mirrors `caps.textureFloatLinearFiltering`. */
87
- readonly textureFloatLinearFiltering: boolean;
88
- /** True when 16-bit half-float color attachments are renderable
89
- * (`EXT_color_buffer_float` or `EXT_color_buffer_half_float`). Mirrors
90
- * `caps.textureHalfFloatRender`. */
91
- readonly textureHalfFloatRender: boolean;
92
- /** Half-float linear filtering always `true` in WebGL2 (it is core).
93
- * Kept as a field to mirror Babylon's `caps.textureHalfFloatLinearFiltering`. */
94
- readonly textureHalfFloatLinearFiltering: boolean;
95
- /** Whether non-power-of-two textures need POT dimensions for mips / wrap.
96
- * Always `false` in WebGL2 (NPOT is core). Mirrors `engine.needPOTTextures`. */
97
- readonly needPOTTextures: boolean;
98
- }
99
-
100
- /**
101
- * Pure-state handle for a WebGL2 canvas + its cached GL state.
102
- *
103
- * INVARIANT: consumers MUST NOT mutate GL state directly through `engine.gl`.
104
- * Doing so silently corrupts the cache in `_state`. The package owns every
105
- * GL call. (`engine.gl` is exposed only so downstream code that already has the
106
- * pattern of poking `engine._gl.getExtension(...)` can do that, but must NOT
107
- * call `bindTexture`/`useProgram`/`bindBuffer`/`viewport`/etc.)
108
- */
109
- declare interface GLEngineContext {
110
- /** The canvas the WebGL2 context was acquired from. An `OffscreenCanvas` is
111
- * supported for worker render paths (e.g. the Lottie player); it has no CSS
112
- * box, so it must be sized explicitly via `setGLEngineSize` rather than the
113
- * CSS-derived `resizeGLEngine`. */
114
- readonly canvas: HTMLCanvasElement | OffscreenCanvas;
115
- /** The raw WebGL2 context. Do NOT mutate GL state through itsee the
116
- * type-level invariant above; the package owns every state-changing call. */
117
- readonly gl: WebGL2RenderingContext;
118
- /** Queried capability limits for this context. */
119
- readonly caps: GLEngineCaps;
120
-
121
- /**
122
- * An offscreen render target a `WebGLFramebuffer` wrapping a color
123
- * {@link GLTexture} and an optional depth / stencil renderbuffer. The lite-gl
124
- * counterpart of Babylon's `RenderTargetWrapper`.
125
- */
126
- declare interface GLRenderTarget {
127
- /** The color attachment, sampleable like any other {@link GLTexture}
128
- * (`setEffectTexture` / `bindTexture`). For an owned attachment its handle
129
- * is swapped on `webglcontextrestored` while consumers keep this same
130
- * reference. */
131
- texture: GLTexture_2;
132
- /** Color attachment width in texels. */
133
- width: number;
134
- /** Color attachment height in texels. */
135
- height: number;
136
- /** True once the color attachment + framebuffer are allocated. */
137
- isReady: boolean;
138
-
139
- /** Stencil configuration for {@link setStencilState}. Omitted fields are left
140
- * unchanged. The `func`/`ref`/`funcMask` triple and the
141
- * `opFail`/`opZFail`/`opZPass` triple are each applied as a unit (any member
142
- * present re-issues that GL call, merging the unspecified members from cache). */
143
- export declare interface GLStencilState {
144
- /** Enable/disable the stencil test (`gl.enable/disable(STENCIL_TEST)`). */
145
- test?: boolean;
146
- /** Stencil write mask (`gl.stencilMask`). */
147
- mask?: number;
148
- /** Comparison function (`gl.stencilFunc` arg 1), e.g. `gl.ALWAYS`. */
149
- func?: GLenum;
150
- /** Reference value (`gl.stencilFunc` arg 2). */
151
- ref?: number;
152
- /** Comparison mask (`gl.stencilFunc` arg 3). */
153
- funcMask?: number;
154
- /** Op when the stencil test fails (`gl.stencilOp` arg 1). */
155
- opFail?: GLenum;
156
- /** Op when the stencil test passes but depth fails (`gl.stencilOp` arg 2). */
157
- opZFail?: GLenum;
158
- /** Op when both stencil and depth pass (`gl.stencilOp` arg 3). */
159
- opZPass?: GLenum;
160
- }
161
-
162
- /**
163
- * Pure-state texture handle. The `handle` field is MUTABLE so the same logical
164
- * texture survives a `webglcontextrestored` event — every consumer keeps the
165
- * same `GLTexture` reference; only the internal `WebGLTexture` is swapped.
166
- *
167
- * `loadTexture2D` also uses the same handle for the 1×1 placeholder upload AND
168
- * the final image upload — so a `bindTexture(engine, unit, tex)` made before the
169
- * image has decoded remains valid once the image arrives.
170
- */
171
- declare interface GLTexture_2 {
172
- /** The live `WebGLTexture`. MUTABLE — swapped for a fresh handle on
173
- * `webglcontextrestored` while consumers keep the same `GLTexture` reference. */
174
- handle: WebGLTexture;
175
- /** GL texture target (always `gl.TEXTURE_2D` for this package). */
176
- readonly target: GLenum;
177
- /** Texture width in texels. Updated once an async upload resolves. */
178
- width: number;
179
- /** Texture height in texels. Updated once an async upload resolves. */
180
- height: number;
181
- /** True when the texture is safe to sample with final content (placeholders
182
- * read as not-ready until their image/upload completes). */
183
- isReady: boolean;
184
-
185
- /**
186
- * Buffer the color write mask into the DESIRED state — the lite-gl equivalent of
187
- * Babylon's `setColorWrite` (which passes the same flag to all four channels).
188
- * Flushed to GL (`gl.colorMask`) by `applyGLStates` before the next draw /
189
- * clear.
190
- *
191
- * @param engine - The engine.
192
- * @param r - Write red.
193
- * @param g - Write green.
194
- * @param b - Write blue.
195
- * @param a - Write alpha.
196
- */
197
- export declare function setColorMask(engine: GLEngineContext, r: boolean, g: boolean, b: boolean, a: boolean): void;
198
-
199
- /**
200
- * Enable/disable face culling and (optionally) set the cull face — the lite-gl
201
- * equivalent of `engine.depthCullingState.cull` + `cullFace`.
202
- *
203
- * @param engine - The engine.
204
- * @param enabled - Enable (`true`) or disable (`false`) `gl.CULL_FACE`.
205
- * @param face - Optional cull face (`gl.BACK` / `gl.FRONT` / `gl.FRONT_AND_BACK`).
206
- */
207
- export declare function setCullState(engine: GLEngineContext, enabled: boolean, face?: GLenum): void;
208
-
209
- /**
210
- * Buffer depth-buffer state (test enable, write mask, comparison function) into
211
- * the DESIRED state — the lite-gl equivalent of mutating Babylon's
212
- * `engine.depthCullingState.{depthTest,depthMask,depthFunc}`. Flushed to GL by
213
- * `applyGLStates` before the next draw / clear; omitted fields are untouched.
214
- *
215
- * @param engine - The engine.
216
- * @param state - The depth fields to change. Omitted fields are untouched.
217
- */
218
- export declare function setDepthState(engine: GLEngineContext, state: GLDepthState): void;
219
-
220
- /**
221
- * Buffer stencil state (test enable, write mask, comparison func triple, op
222
- * triple) into the DESIRED state — the lite-gl equivalent of mutating Babylon's
223
- * `engine.stencilState.*`. Flushed by `applyGLStates` before the next draw /
224
- * clear; omitted fields are untouched (merge-from-desired).
225
- *
226
- * @param engine - The engine.
227
- * @param state - The stencil fields to change. Omitted fields are untouched.
228
- */
229
- export declare function setStencilState(engine: GLEngineContext, state: GLStencilState): void;
230
-
231
- export { }
1
+ /**
2
+ * Depth, stencil, color-mask and clear state the lite-gl counterpart of
3
+ * Babylon's `_depthCullingState` / `_stencilState` / `setColorWrite` / `clear`.
4
+ *
5
+ * Like Babylon, these setters are DEFERRED: they buffer the requested values
6
+ * into the DESIRED (`d*`) mirror fields of `GLState` and raise `statesDirty`,
7
+ * issuing NO `gl.*` calls themselves. `applyGLStates` (apply-states.ts) flushes
8
+ * the diff to GL right before each draw (and before `clearEngine`'s `gl.clear`,
9
+ * since a clear respects the current write masks). Every field is reconciled
10
+ * independently, so a flush that changes only one sub-state (e.g. just the
11
+ * stencil op triple) issues only that GL call. Omitted setter fields leave the
12
+ * corresponding desired value untouched (merge-from-desired).
13
+ *
14
+ * All setters are no-ops on a lost/disposed context.
15
+ *
16
+ * This module also hosts {@link generateRenderTargetStencil} the tree-shakeable
17
+ * opt-in that gives a `/render-target` {@link GLRenderTarget} a stencil (or packed
18
+ * depth+stencil) attachment. Keeping the STENCIL_INDEX8 / DEPTH24_STENCIL8
19
+ * renderbuffer code here (rather than in the render-target core) means a consumer
20
+ * that only needs a depth buffer never ships it. The one-way type import below
21
+ * (`depth-stencil` importing `render-target`) introduces NO cycle: render-target
22
+ * must not import this module.
23
+ */
24
+ import type { GLEngineContext } from "./context.js";
25
+ import type { GLRenderTarget } from "./render-target.js";
26
+ /** Depth-buffer configuration for {@link setDepthState}. Omitted fields are
27
+ * left unchanged. */
28
+ export interface GLDepthState {
29
+ /** Enable/disable the depth test (`gl.enable/disable(DEPTH_TEST)`). */
30
+ test?: boolean;
31
+ /** Enable/disable depth writes (`gl.depthMask`). */
32
+ write?: boolean;
33
+ /** Depth comparison function (`gl.depthFunc`), e.g. `gl.LESS`. */
34
+ func?: GLenum;
35
+ }
36
+ /** Stencil configuration for {@link setStencilState}. Omitted fields are left
37
+ * unchanged. The `func`/`ref`/`funcMask` triple and the
38
+ * `opFail`/`opZFail`/`opZPass` triple are each applied as a unit (any member
39
+ * present re-issues that GL call, merging the unspecified members from cache). */
40
+ export interface GLStencilState {
41
+ /** Enable/disable the stencil test (`gl.enable/disable(STENCIL_TEST)`). */
42
+ test?: boolean;
43
+ /** Stencil write mask (`gl.stencilMask`). */
44
+ mask?: number;
45
+ /** Comparison function (`gl.stencilFunc` arg 1), e.g. `gl.ALWAYS`. */
46
+ func?: GLenum;
47
+ /** Reference value (`gl.stencilFunc` arg 2). */
48
+ ref?: number;
49
+ /** Comparison mask (`gl.stencilFunc` arg 3). */
50
+ funcMask?: number;
51
+ /** Op when the stencil test fails (`gl.stencilOp` arg 1). */
52
+ opFail?: GLenum;
53
+ /** Op when the stencil test passes but depth fails (`gl.stencilOp` arg 2). */
54
+ opZFail?: GLenum;
55
+ /** Op when both stencil and depth pass (`gl.stencilOp` arg 3). */
56
+ opZPass?: GLenum;
57
+ }
58
+ /** Options for {@link clearEngine}. */
59
+ export interface GLClearOptions {
60
+ /** When set, clears the color buffer to this RGBA color (alpha default 1). */
61
+ color?: {
62
+ r: number;
63
+ g: number;
64
+ b: number;
65
+ a?: number;
66
+ };
67
+ /** Clear the depth buffer (respects the current depth write mask). */
68
+ depth?: boolean;
69
+ /** Clear the stencil buffer (respects the current stencil write mask). */
70
+ stencil?: boolean;
71
+ }
72
+ /**
73
+ * Buffer depth-buffer state (test enable, write mask, comparison function) into
74
+ * the DESIRED state — the lite-gl equivalent of mutating Babylon's
75
+ * `engine.depthCullingState.{depthTest,depthMask,depthFunc}`. Flushed to GL by
76
+ * `applyGLStates` before the next draw / clear; omitted fields are untouched.
77
+ *
78
+ * @param engine - The engine.
79
+ * @param state - The depth fields to change. Omitted fields are untouched.
80
+ */
81
+ export declare function setDepthState(engine: GLEngineContext, state: GLDepthState): void;
82
+ /**
83
+ * Enable/disable face culling and (optionally) set the cull face — the lite-gl
84
+ * equivalent of `engine.depthCullingState.cull` + `cullFace`.
85
+ *
86
+ * @param engine - The engine.
87
+ * @param enabled - Enable (`true`) or disable (`false`) `gl.CULL_FACE`.
88
+ * @param face - Optional cull face (`gl.BACK` / `gl.FRONT` / `gl.FRONT_AND_BACK`).
89
+ */
90
+ export declare function setCullState(engine: GLEngineContext, enabled: boolean, face?: GLenum): void;
91
+ /**
92
+ * Buffer stencil state (test enable, write mask, comparison func triple, op
93
+ * triple) into the DESIRED state — the lite-gl equivalent of mutating Babylon's
94
+ * `engine.stencilState.*`. Flushed by `applyGLStates` before the next draw /
95
+ * clear; omitted fields are untouched (merge-from-desired).
96
+ *
97
+ * @param engine - The engine.
98
+ * @param state - The stencil fields to change. Omitted fields are untouched.
99
+ */
100
+ export declare function setStencilState(engine: GLEngineContext, state: GLStencilState): void;
101
+ /**
102
+ * Buffer the color write mask into the DESIRED state — the lite-gl equivalent of
103
+ * Babylon's `setColorWrite` (which passes the same flag to all four channels).
104
+ * Flushed to GL (`gl.colorMask`) by `applyGLStates` before the next draw /
105
+ * clear.
106
+ *
107
+ * @param engine - The engine.
108
+ * @param r - Write red.
109
+ * @param g - Write green.
110
+ * @param b - Write blue.
111
+ * @param a - Write alpha.
112
+ */
113
+ export declare function setColorMask(engine: GLEngineContext, r: boolean, g: boolean, b: boolean, a: boolean): void;
114
+ /**
115
+ * Clear the currently-bound framebuffer's color / depth / stencil buffers — the
116
+ * lite-gl equivalent of Babylon's `clear(color, backBuffer, depth, stencil)`.
117
+ * Depth/stencil clears respect the current write masks (set them first via
118
+ * {@link setDepthState} / {@link setStencilState}). No-op when nothing is
119
+ * requested or the context is lost/disposed.
120
+ *
121
+ * @param engine - The engine.
122
+ * @param options - Which buffers to clear (and the color value).
123
+ */
124
+ export declare function clearEngine(engine: GLEngineContext, options: GLClearOptions): void;
125
+ /**
126
+ * Opt-in: give a `/render-target` {@link GLRenderTarget} a stencil attachment,
127
+ * replacing the core's depth-only `DEPTH_COMPONENT16` renderbuffer with either a
128
+ * packed **`DEPTH24_STENCIL8`** buffer (default depth *and* stencil) or a
129
+ * stencil-only **`STENCIL_INDEX8`** buffer.
130
+ *
131
+ * Stencil is intentionally NOT a {@link createRenderTarget} option: keeping this
132
+ * helper in the depth-stencil module means the stencil/packed renderbuffer
133
+ * code tree-shakes out of every bundle that only needs a color (and optional
134
+ * depth) target.
135
+ *
136
+ * The attachment is **restore-correct**: it is rebuilt automatically — at the new
137
+ * size on {@link resizeRenderTarget}, and into the fresh framebuffer after a
138
+ * `webglcontextrestored` event — so the stencil survives for the life of the
139
+ * target, and {@link disposeRenderTarget} releases it along with the target.
140
+ *
141
+ * No-op on a lost/disposed context or a disposed target.
142
+ *
143
+ * @param engine - The engine that owns `rt`.
144
+ * @param rt - The render target to attach the stencil buffer to.
145
+ * @param options - `depth` (default `true`): when `true` the attachment is a
146
+ * packed depth+stencil buffer (`DEPTH24_STENCIL8` on `DEPTH_STENCIL_ATTACHMENT`)
147
+ * — the common case, and the correct choice when the target was created with
148
+ * `generateDepthBuffer: true`. When `false` the attachment is stencil-only
149
+ * (`STENCIL_INDEX8` on `STENCIL_ATTACHMENT`).
150
+ * @throws If a renderbuffer handle could not be allocated or the framebuffer is
151
+ * incomplete after attaching.
152
+ */
153
+ export declare function generateRenderTargetStencil(engine: GLEngineContext, rt: GLRenderTarget, options?: {
154
+ depth?: boolean;
155
+ }): void;