@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.
- package/README.md +10 -34
- package/apply-states.d.ts +1 -0
- package/apply-states.js +30 -0
- package/apply-states.js.map +1 -0
- package/blend.d.ts +123 -0
- package/blend.js +194 -0
- package/blend.js.map +1 -0
- package/context.d.ts +130 -0
- package/context.js +354 -0
- package/context.js.map +1 -0
- package/depth-stencil.d.ts +155 -231
- package/depth-stencil.js +399 -262
- package/depth-stencil.js.map +1 -1
- package/dynamic-texture.d.ts +59 -149
- package/dynamic-texture.js +123 -69
- package/dynamic-texture.js.map +1 -1
- package/effect-renderer.d.ts +65 -0
- package/effect-renderer.js +132 -0
- package/effect-renderer.js.map +1 -0
- package/effect.d.ts +142 -0
- package/effect.js +465 -0
- package/effect.js.map +1 -0
- package/html-texture.d.ts +44 -143
- package/html-texture.js +87 -81
- package/html-texture.js.map +1 -1
- package/index.d.ts +23 -1482
- package/index.js +42 -263
- package/index.js.map +1 -1
- package/mesh.d.ts +210 -307
- package/mesh.js +436 -311
- package/mesh.js.map +1 -1
- package/package.json +5 -29
- package/render-loop.d.ts +8 -0
- package/render-loop.js +62 -0
- package/render-loop.js.map +1 -0
- package/render-target.d.ts +233 -290
- package/render-target.js +534 -335
- package/render-target.js.map +1 -1
- package/scissor.d.ts +30 -72
- package/scissor.js +47 -33
- package/scissor.js.map +1 -1
- package/shader.d.ts +22 -0
- package/shader.js +65 -0
- package/shader.js.map +1 -0
- package/sprites.d.ts +182 -263
- package/sprites.js +426 -10
- package/sprites.js.map +1 -1
- package/state.d.ts +126 -0
- package/state.js +153 -0
- package/state.js.map +1 -0
- package/texture.d.ts +142 -0
- package/texture.js +433 -0
- package/texture.js.map +1 -0
- package/effect-BxxwfB_O.js +0 -737
- package/effect-BxxwfB_O.js.map +0 -1
- package/sprites--1oyVtJ3.js +0 -437
- package/sprites--1oyVtJ3.js.map +0 -1
- package/state--j_ncWIi.js +0 -155
- package/state--j_ncWIi.js.map +0 -1
- package/texture-DaMd1gGm.js +0 -329
- package/texture-DaMd1gGm.js.map +0 -1
package/mesh.d.ts
CHANGED
|
@@ -1,307 +1,210 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configure vertex attributes from `vb`, reproducing Babylon's
|
|
3
|
-
* `bindInstancesBuffer` exactly. For each descriptor: resolves the location
|
|
4
|
-
* (explicit `index` or via the effect), enables the attribute array, issues
|
|
5
|
-
* `vertexAttribPointer`, and sets the vertex divisor (`undefined → 1`). Every
|
|
6
|
-
* touched location is tracked so {@link unbindInstanceAttributes} can reset its
|
|
7
|
-
* divisor afterwards.
|
|
8
|
-
*
|
|
9
|
-
* `computeStride` controls the GL stride passed to `vertexAttribPointer`:
|
|
10
|
-
* - `false` (default) → stride `0`: each attribute is independently tightly
|
|
11
|
-
* packed. Combined with overlapping `offset`s this yields the "sliding window"
|
|
12
|
-
* ShapeBuilder uses for distance-field tape buffers.
|
|
13
|
-
* - `true` → stride = Σ(`size`·4 bytes): interleaved per-vertex/per-instance.
|
|
14
|
-
*
|
|
15
|
-
* Runs on the default (null) VAO — never corrupts the quad / sprite VAOs.
|
|
16
|
-
* No-op on a lost/disposed context or before the effect is ready.
|
|
17
|
-
*
|
|
18
|
-
* @param engine - The engine.
|
|
19
|
-
* @param vb - The buffer supplying the attribute data.
|
|
20
|
-
* @param descriptors - The attribute layout.
|
|
21
|
-
* @param effect - The effect whose attribute locations resolve unnamed indices.
|
|
22
|
-
* @param computeStride - See above. Default `false`.
|
|
23
|
-
*/
|
|
24
|
-
export declare function bindAttributes(engine: GLEngineContext, vb: GLVertexBuffer, descriptors: readonly GLAttributeDescriptor[], effect: GLEffect, computeStride?: boolean): void;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Bind an index buffer as the current element-array buffer (on the default
|
|
28
|
-
* VAO). Cached. The lite-gl equivalent of Babylon's `_bindIndexBufferWithCache`.
|
|
29
|
-
*
|
|
30
|
-
* @param engine - The engine.
|
|
31
|
-
* @param ib - The index buffer to bind.
|
|
32
|
-
*/
|
|
33
|
-
export declare function bindIndexBuffer(engine: GLEngineContext, ib: GLIndexBuffer): void;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Bind a {@link GLMeshVao} (cached `gl.bindVertexArray`). Rarely called directly —
|
|
37
|
-
* {@link drawMesh} binds it for you. Binding restores the VAO's recorded element
|
|
38
|
-
* binding, so the element-buffer cache is updated in lock-step.
|
|
39
|
-
*
|
|
40
|
-
* @param engine - The engine.
|
|
41
|
-
* @param vao - The mesh VAO to bind.
|
|
42
|
-
*/
|
|
43
|
-
export declare function bindMeshVao(engine: GLEngineContext, vao: GLMeshVao): void;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Create a GPU index buffer. `Uint16Array` → 16-bit indices, `Uint32Array` →
|
|
47
|
-
* 32-bit. Binds the default VAO first so it never corrupts the quad / sprite
|
|
48
|
-
* VAO element bindings.
|
|
49
|
-
*
|
|
50
|
-
* @param engine - The engine.
|
|
51
|
-
* @param data - The index data. Retained by reference for context-restore.
|
|
52
|
-
* @returns The new {@link GLIndexBuffer}.
|
|
53
|
-
*/
|
|
54
|
-
export declare function createIndexBuffer(engine: GLEngineContext, data: Uint16Array | Uint32Array): GLIndexBuffer;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Record a static mesh's attribute layout + index binding into a new VAO. The
|
|
58
|
-
* effect MUST be ready (its attribute locations are resolved here, once). Returns
|
|
59
|
-
* a {@link GLMeshVao} to draw with {@link drawMesh}.
|
|
60
|
-
*
|
|
61
|
-
* @param engine - The engine.
|
|
62
|
-
* @param vertexBuffers - One or more buffers + their attribute layouts.
|
|
63
|
-
* @param indexBuffer - The index buffer recorded into the VAO.
|
|
64
|
-
* @param effect - The effect whose attribute locations resolve unnamed indices.
|
|
65
|
-
* @returns The recorded {@link GLMeshVao}.
|
|
66
|
-
*/
|
|
67
|
-
export declare function createMeshVao(engine: GLEngineContext, vertexBuffers: readonly GLMeshVertexBuffer[], indexBuffer: GLIndexBuffer, effect: GLEffect): GLMeshVao;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Create a GPU vertex buffer from interleaved float data.
|
|
71
|
-
*
|
|
72
|
-
* @param engine - The engine.
|
|
73
|
-
* @param data - The vertex data. Retained by reference for context-restore — do
|
|
74
|
-
* not mutate it in place; use {@link updateVertexBuffer} to change contents.
|
|
75
|
-
* @param dynamic - Hint that the buffer will be updated frequently
|
|
76
|
-
* (`DYNAMIC_DRAW`). Default `false` (`STATIC_DRAW`).
|
|
77
|
-
* @returns The new {@link GLVertexBuffer}.
|
|
78
|
-
*/
|
|
79
|
-
export declare function createVertexBuffer(engine: GLEngineContext, data: Float32Array, dynamic?: boolean): GLVertexBuffer;
|
|
80
|
-
|
|
81
|
-
/** Dispose a vertex or index buffer (delete the GL buffer + unregister). Clears
|
|
82
|
-
* the array/element-buffer cache slot if it pointed at this buffer. Idempotent. */
|
|
83
|
-
export declare function disposeBuffer(engine: GLEngineContext, buffer: GLVertexBuffer | GLIndexBuffer): void;
|
|
84
|
-
|
|
85
|
-
/** Dispose a {@link GLMeshVao}: delete the VAO and unregister its restore hook.
|
|
86
|
-
* Does NOT dispose the vertex/index buffers (the caller owns those). Idempotent. */
|
|
87
|
-
export declare function disposeMeshVao(engine: GLEngineContext, vao: GLMeshVao): void;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Draw indexed triangles from `ib` — the lite-gl equivalent of Babylon's
|
|
91
|
-
* `drawElementsType` (triangle fill mode). When `instanceCount > 0` issues
|
|
92
|
-
* `drawElementsInstanced`, otherwise `drawElements`. No-op on a lost/disposed
|
|
93
|
-
* context or when no program is current.
|
|
94
|
-
*
|
|
95
|
-
* @param engine - The engine.
|
|
96
|
-
* @param ib - The index buffer (also bound as a side-effect, cached).
|
|
97
|
-
* @param indexCount - Number of indices to draw.
|
|
98
|
-
* @param indexStart - First index offset (in indices, not bytes). Default 0.
|
|
99
|
-
* @param instanceCount - Instance count for instanced draws. Default 0
|
|
100
|
-
* (non-instanced).
|
|
101
|
-
*/
|
|
102
|
-
export declare function drawIndexed(engine: GLEngineContext, ib: GLIndexBuffer, indexCount: number, indexStart?: number, instanceCount?: number): void;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Draw a static mesh recorded with {@link createMeshVao}: binds its VAO (cached),
|
|
106
|
-
* flushes deferred GL state, and issues ONE `drawElements` (or
|
|
107
|
-
* `drawElementsInstanced` when `instanceCount > 0`) over the VAO's full index
|
|
108
|
-
* buffer. No per-draw attribute (re)binding. No-op on a lost/disposed context, a
|
|
109
|
-
* disposed VAO, or when no program is current.
|
|
110
|
-
*
|
|
111
|
-
* @param engine - The engine.
|
|
112
|
-
* @param vao - The mesh VAO to draw.
|
|
113
|
-
* @param instanceCount - Instance count for instanced draws. Default 0 (non-instanced).
|
|
114
|
-
*/
|
|
115
|
-
export declare function drawMesh(engine: GLEngineContext, vao: GLMeshVao, instanceCount?: number): void;
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Describes one vertex attribute fed from a buffer — the lite-gl equivalent of
|
|
119
|
-
* Babylon's `InstancingAttributeInfo`. Pass an array of these to
|
|
120
|
-
* {@link bindAttributes}.
|
|
121
|
-
*/
|
|
122
|
-
export declare interface GLAttributeDescriptor {
|
|
123
|
-
/** Attribute name; resolved to a location via the effect when `index` is
|
|
124
|
-
* omitted (`Effect.getAttributeLocationByName`). */
|
|
125
|
-
name?: string;
|
|
126
|
-
/** Explicit attribute location. When set, overrides the `name` lookup. */
|
|
127
|
-
index?: number;
|
|
128
|
-
/** Number of components, 1–4. */
|
|
129
|
-
size: number;
|
|
130
|
-
/** Byte offset of this attribute's first element within the buffer. Default 0. */
|
|
131
|
-
offset?: number;
|
|
132
|
-
/**
|
|
133
|
-
* Per-instance vertex divisor. **Omitted/`undefined` → `1` (instanced)**,
|
|
134
|
-
* matching Babylon's `bindInstancesBuffer`. Pass `0` explicitly for a
|
|
135
|
-
* per-vertex attribute (e.g. the base mesh position).
|
|
136
|
-
*/
|
|
137
|
-
divisor?: number;
|
|
138
|
-
/** GL component type. Default `gl.FLOAT`. */
|
|
139
|
-
type?: GLenum;
|
|
140
|
-
/** Normalize fixed-point integer data to `[0,1]`/`[-1,1]`. Default `false`. */
|
|
141
|
-
normalized?: boolean;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/** A compiled + linked shader program with cached uniform, sampler and
|
|
145
|
-
* attribute locations. Created by `createEffect`; most fields are managed
|
|
146
|
-
* internally — drive it via `isEffectReady` / `useEffect` / the `setEffect*`
|
|
147
|
-
* setters rather than mutating it directly. */
|
|
148
|
-
declare interface GLEffect {
|
|
149
|
-
/** The `name` from the originating `GLEffectOptions`. */
|
|
150
|
-
readonly name: string;
|
|
151
|
-
/** The options this effect was created from (retained for context-restore). */
|
|
152
|
-
readonly options: GLEffectOptions;
|
|
153
|
-
/** The live `WebGLProgram`. Swapped for a fresh handle after context-restore. */
|
|
154
|
-
program: WebGLProgram;
|
|
155
1
|
/** Resolved during readiness finalization. Missing names map to `null` —
|
|
156
|
-
* setters with a `null` location are silent no-ops (matches Babylon). */
|
|
157
|
-
uniformLocations: {
|
|
158
|
-
[name: string]: WebGLUniformLocation | null;
|
|
159
|
-
};
|
|
160
|
-
/** Fixed unit assignment for declared samplers, index into
|
|
161
|
-
* `_state.boundTextures`. */
|
|
162
|
-
samplerUnits: {
|
|
163
|
-
[name: string]: number;
|
|
164
|
-
};
|
|
165
2
|
/** Resolved attribute locations, keyed by attribute name. */
|
|
166
|
-
attributeLocations: {
|
|
167
|
-
[name: string]: number;
|
|
168
|
-
};
|
|
169
3
|
/** True once the program has linked and finalization has run; the
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
*
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
*
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
*
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
*
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
export declare
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
*
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Indexed meshes, dynamic vertex/index buffers, and hardware instancing.
|
|
6
|
+
*
|
|
7
|
+
* Part of the public API via the `@babylonjs/lite-gl` barrel. The package is
|
|
8
|
+
* `sideEffects: false`, so consumers that only render the fullscreen quad /
|
|
9
|
+
* sprites tree-shake the mesh code out.
|
|
10
|
+
*
|
|
11
|
+
* This is the lite-gl equivalent of Babylon's `ThinEngine.createVertexBuffer` /
|
|
12
|
+
* `createIndexBuffer` / `_releaseBuffer` / `bindIndexBuffer` /
|
|
13
|
+
* `bindInstancesBuffer` / `unbindInstanceAttributes` / `drawElementsType`. The
|
|
14
|
+
* attribute binder reproduces Babylon's instancing semantics EXACTLY, including
|
|
15
|
+
* the `computeStride = false → stride 0` "sliding window" used by ShapeBuilder's
|
|
16
|
+
* tape buffers (consecutive instances read overlapping vec4 windows) and the
|
|
17
|
+
* `divisor === undefined → 1` default.
|
|
18
|
+
*
|
|
19
|
+
* The mesh path runs on the DEFAULT (null) VAO — every buffer/attribute op binds
|
|
20
|
+
* `gl.bindVertexArray(null)` first, so it never corrupts the quad / sprite VAOs.
|
|
21
|
+
* Vertex and index buffers retain their CPU data and re-upload automatically on
|
|
22
|
+
* `webglcontextrestored`.
|
|
23
|
+
*/
|
|
24
|
+
import type { GLEngineContext } from "./context.js";
|
|
25
|
+
import { type GLEffect } from "./effect.js";
|
|
26
|
+
/** A GPU vertex buffer holding interleaved float vertex data. The lite-gl
|
|
27
|
+
* counterpart of Babylon's `DataBuffer` for vertex data. */
|
|
28
|
+
export interface GLVertexBuffer {
|
|
29
|
+
/** The live `WebGLBuffer`. Swapped on `webglcontextrestored`. */
|
|
30
|
+
handle: WebGLBuffer;
|
|
31
|
+
/** Size of the GL buffer in bytes. */
|
|
32
|
+
byteLength: number;
|
|
33
|
+
}
|
|
34
|
+
/** A GPU index buffer. The lite-gl counterpart of Babylon's `DataBuffer` for
|
|
35
|
+
* index data. */
|
|
36
|
+
export interface GLIndexBuffer {
|
|
37
|
+
/** The live `WebGLBuffer`. Swapped on `webglcontextrestored`. */
|
|
38
|
+
handle: WebGLBuffer;
|
|
39
|
+
/** Number of indices. */
|
|
40
|
+
count: number;
|
|
41
|
+
/** `true` for 32-bit (`Uint32Array`) indices, `false` for 16-bit. */
|
|
42
|
+
is32Bits: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Describes one vertex attribute fed from a buffer — the lite-gl equivalent of
|
|
46
|
+
* Babylon's `InstancingAttributeInfo`. Pass an array of these to
|
|
47
|
+
* {@link bindAttributes}.
|
|
48
|
+
*/
|
|
49
|
+
export interface GLAttributeDescriptor {
|
|
50
|
+
/** Attribute name; resolved to a location via the effect when `index` is
|
|
51
|
+
* omitted (`Effect.getAttributeLocationByName`). */
|
|
52
|
+
name?: string;
|
|
53
|
+
/** Explicit attribute location. When set, overrides the `name` lookup. */
|
|
54
|
+
index?: number;
|
|
55
|
+
/** Number of components, 1–4. */
|
|
56
|
+
size: number;
|
|
57
|
+
/** Byte offset of this attribute's first element within the buffer. Default 0. */
|
|
58
|
+
offset?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Per-instance vertex divisor. **Omitted/`undefined` → `1` (instanced)**,
|
|
61
|
+
* matching Babylon's `bindInstancesBuffer`. Pass `0` explicitly for a
|
|
62
|
+
* per-vertex attribute (e.g. the base mesh position).
|
|
63
|
+
*/
|
|
64
|
+
divisor?: number;
|
|
65
|
+
/** GL component type. Default `gl.FLOAT`. */
|
|
66
|
+
type?: GLenum;
|
|
67
|
+
/** Normalize fixed-point integer data to `[0,1]`/`[-1,1]`. Default `false`. */
|
|
68
|
+
normalized?: boolean;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create a GPU vertex buffer from interleaved float data.
|
|
72
|
+
*
|
|
73
|
+
* @param engine - The engine.
|
|
74
|
+
* @param data - The vertex data. Retained by reference for context-restore — do
|
|
75
|
+
* not mutate it in place; use {@link updateVertexBuffer} to change contents.
|
|
76
|
+
* @param dynamic - Hint that the buffer will be updated frequently
|
|
77
|
+
* (`DYNAMIC_DRAW`). Default `false` (`STATIC_DRAW`).
|
|
78
|
+
* @returns The new {@link GLVertexBuffer}.
|
|
79
|
+
*/
|
|
80
|
+
export declare function createVertexBuffer(engine: GLEngineContext, data: Float32Array, dynamic?: boolean): GLVertexBuffer;
|
|
81
|
+
/**
|
|
82
|
+
* Upload new contents into (part of) a vertex buffer via `bufferSubData`. A
|
|
83
|
+
* full-buffer update from offset 0 also refreshes the retained CPU data used
|
|
84
|
+
* for context-restore.
|
|
85
|
+
*
|
|
86
|
+
* @param engine - The engine.
|
|
87
|
+
* @param vb - The vertex buffer to update.
|
|
88
|
+
* @param data - The new float data.
|
|
89
|
+
* @param dstByteOffset - Destination byte offset within the buffer. Default 0.
|
|
90
|
+
*/
|
|
91
|
+
export declare function updateVertexBuffer(engine: GLEngineContext, vb: GLVertexBuffer, data: Float32Array, dstByteOffset?: number): void;
|
|
92
|
+
/**
|
|
93
|
+
* Create a GPU index buffer. `Uint16Array` → 16-bit indices, `Uint32Array` →
|
|
94
|
+
* 32-bit. Binds the default VAO first so it never corrupts the quad / sprite
|
|
95
|
+
* VAO element bindings.
|
|
96
|
+
*
|
|
97
|
+
* @param engine - The engine.
|
|
98
|
+
* @param data - The index data. Retained by reference for context-restore.
|
|
99
|
+
* @returns The new {@link GLIndexBuffer}.
|
|
100
|
+
*/
|
|
101
|
+
export declare function createIndexBuffer(engine: GLEngineContext, data: Uint16Array | Uint32Array): GLIndexBuffer;
|
|
102
|
+
/** Dispose a vertex or index buffer (delete the GL buffer + unregister). Clears
|
|
103
|
+
* the array/element-buffer cache slot if it pointed at this buffer. Idempotent. */
|
|
104
|
+
export declare function disposeBuffer(engine: GLEngineContext, buffer: GLVertexBuffer | GLIndexBuffer): void;
|
|
105
|
+
/**
|
|
106
|
+
* Bind an index buffer as the current element-array buffer (on the default
|
|
107
|
+
* VAO). Cached. The lite-gl equivalent of Babylon's `_bindIndexBufferWithCache`.
|
|
108
|
+
*
|
|
109
|
+
* @param engine - The engine.
|
|
110
|
+
* @param ib - The index buffer to bind.
|
|
111
|
+
*/
|
|
112
|
+
export declare function bindIndexBuffer(engine: GLEngineContext, ib: GLIndexBuffer): void;
|
|
113
|
+
/**
|
|
114
|
+
* Configure vertex attributes from `vb`, reproducing Babylon's
|
|
115
|
+
* `bindInstancesBuffer` exactly. For each descriptor: resolves the location
|
|
116
|
+
* (explicit `index` or via the effect), enables the attribute array, issues
|
|
117
|
+
* `vertexAttribPointer`, and sets the vertex divisor (`undefined → 1`). Every
|
|
118
|
+
* touched location is tracked so {@link unbindInstanceAttributes} can reset its
|
|
119
|
+
* divisor afterwards.
|
|
120
|
+
*
|
|
121
|
+
* `computeStride` controls the GL stride passed to `vertexAttribPointer`:
|
|
122
|
+
* - `false` (default) → stride `0`: each attribute is independently tightly
|
|
123
|
+
* packed. Combined with overlapping `offset`s this yields the "sliding window"
|
|
124
|
+
* ShapeBuilder uses for distance-field tape buffers.
|
|
125
|
+
* - `true` → stride = Σ(`size`·4 bytes): interleaved per-vertex/per-instance.
|
|
126
|
+
*
|
|
127
|
+
* Runs on the default (null) VAO — never corrupts the quad / sprite VAOs.
|
|
128
|
+
* No-op on a lost/disposed context or before the effect is ready.
|
|
129
|
+
*
|
|
130
|
+
* @param engine - The engine.
|
|
131
|
+
* @param vb - The buffer supplying the attribute data.
|
|
132
|
+
* @param descriptors - The attribute layout.
|
|
133
|
+
* @param effect - The effect whose attribute locations resolve unnamed indices.
|
|
134
|
+
* @param computeStride - See above. Default `false`.
|
|
135
|
+
*/
|
|
136
|
+
export declare function bindAttributes(engine: GLEngineContext, vb: GLVertexBuffer, descriptors: readonly GLAttributeDescriptor[], effect: GLEffect, computeStride?: boolean): void;
|
|
137
|
+
/**
|
|
138
|
+
* Reset the vertex divisor of every attribute touched by {@link bindAttributes}
|
|
139
|
+
* back to 0 — the lite-gl equivalent of Babylon's `unbindInstanceAttributes`.
|
|
140
|
+
* Call after an instanced draw so a following non-instanced draw is not skewed.
|
|
141
|
+
* No-op on a lost/disposed context.
|
|
142
|
+
*
|
|
143
|
+
* @param engine - The engine.
|
|
144
|
+
*/
|
|
145
|
+
export declare function unbindInstanceAttributes(engine: GLEngineContext): void;
|
|
146
|
+
/**
|
|
147
|
+
* Draw indexed triangles from `ib` — the lite-gl equivalent of Babylon's
|
|
148
|
+
* `drawElementsType` (triangle fill mode). When `instanceCount > 0` issues
|
|
149
|
+
* `drawElementsInstanced`, otherwise `drawElements`. No-op on a lost/disposed
|
|
150
|
+
* context or when no program is current.
|
|
151
|
+
*
|
|
152
|
+
* @param engine - The engine.
|
|
153
|
+
* @param ib - The index buffer (also bound as a side-effect, cached).
|
|
154
|
+
* @param indexCount - Number of indices to draw.
|
|
155
|
+
* @param indexStart - First index offset (in indices, not bytes). Default 0.
|
|
156
|
+
* @param instanceCount - Instance count for instanced draws. Default 0
|
|
157
|
+
* (non-instanced).
|
|
158
|
+
*/
|
|
159
|
+
export declare function drawIndexed(engine: GLEngineContext, ib: GLIndexBuffer, indexCount: number, indexStart?: number, instanceCount?: number): void;
|
|
160
|
+
/** One vertex buffer + its attribute layout, for {@link createMeshVao}. */
|
|
161
|
+
export interface GLMeshVertexBuffer {
|
|
162
|
+
/** The buffer supplying this group's attributes. */
|
|
163
|
+
buffer: GLVertexBuffer;
|
|
164
|
+
/** The attributes read from `buffer` (same shape as {@link bindAttributes}). */
|
|
165
|
+
attributes: readonly GLAttributeDescriptor[];
|
|
166
|
+
/** Stride mode (see {@link bindAttributes}): `false` (default) → stride `0`
|
|
167
|
+
* per attribute; `true` → interleaved stride = Σ(`size`·4). */
|
|
168
|
+
computeStride?: boolean;
|
|
169
|
+
}
|
|
170
|
+
/** A recorded Vertex Array Object capturing a static mesh's attribute layout +
|
|
171
|
+
* index binding. Bind + draw it with {@link drawMesh} each frame — the GPU
|
|
172
|
+
* replays the entire attribute setup from one `bindVertexArray`. Re-recorded
|
|
173
|
+
* automatically on `webglcontextrestored`. */
|
|
174
|
+
export interface GLMeshVao {
|
|
175
|
+
/** The live `WebGLVertexArrayObject`. Swapped on `webglcontextrestored`. */
|
|
176
|
+
handle: WebGLVertexArrayObject;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Record a static mesh's attribute layout + index binding into a new VAO. The
|
|
180
|
+
* effect MUST be ready (its attribute locations are resolved here, once). Returns
|
|
181
|
+
* a {@link GLMeshVao} to draw with {@link drawMesh}.
|
|
182
|
+
*
|
|
183
|
+
* @param engine - The engine.
|
|
184
|
+
* @param vertexBuffers - One or more buffers + their attribute layouts.
|
|
185
|
+
* @param indexBuffer - The index buffer recorded into the VAO.
|
|
186
|
+
* @param effect - The effect whose attribute locations resolve unnamed indices.
|
|
187
|
+
* @returns The recorded {@link GLMeshVao}.
|
|
188
|
+
*/
|
|
189
|
+
export declare function createMeshVao(engine: GLEngineContext, vertexBuffers: readonly GLMeshVertexBuffer[], indexBuffer: GLIndexBuffer, effect: GLEffect): GLMeshVao;
|
|
190
|
+
/**
|
|
191
|
+
* Bind a {@link GLMeshVao} (cached `gl.bindVertexArray`). Rarely called directly —
|
|
192
|
+
* {@link drawMesh} binds it for you. Binding restores the VAO's recorded element
|
|
193
|
+
* binding, so the element-buffer cache is updated in lock-step.
|
|
194
|
+
*
|
|
195
|
+
* @param engine - The engine.
|
|
196
|
+
* @param vao - The mesh VAO to bind.
|
|
197
|
+
*/
|
|
198
|
+
export declare function bindMeshVao(engine: GLEngineContext, vao: GLMeshVao): void;
|
|
199
|
+
/**
|
|
200
|
+
* Draw a static mesh recorded with {@link createMeshVao}: binds its VAO (cached),
|
|
201
|
+
* flushes deferred GL state, and issues ONE `drawElements` (or
|
|
202
|
+
* `drawElementsInstanced` when `instanceCount > 0`) over the VAO's full index
|
|
203
|
+
* buffer. No per-draw attribute (re)binding. No-op on a lost/disposed context, a
|
|
204
|
+
* disposed VAO, or when no program is current.
|
|
205
|
+
*
|
|
206
|
+
* @param engine - The engine.
|
|
207
|
+
* @param vao - The mesh VAO to draw.
|
|
208
|
+
* @param instanceCount - Instance count for instanced draws. Default 0 (non-instanced).
|
|
209
|
+
*/
|
|
210
|
+
export declare function drawMesh(engine: GLEngineContext, vao: GLMeshVao, instanceCount?: number): void;
|
|
211
|
+
/** Dispose a {@link GLMeshVao}: delete the VAO and unregister its restore hook.
|
|
212
|
+
* Does NOT dispose the vertex/index buffers (the caller owns those). Idempotent. */
|
|
213
|
+
export declare function disposeMeshVao(engine: GLEngineContext, vao: GLMeshVao): void;
|