@babylonjs/lite-gl 1.20.0 → 1.20.1
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 +58 -19
- package/context.js +2 -0
- package/context.js.map +1 -1
- package/depth-stencil.d.ts +1 -2
- package/depth-stencil.js +2 -2
- package/depth-stencil.js.map +1 -1
- package/dynamic-texture.d.ts +18 -18
- package/dynamic-texture.js +28 -24
- package/dynamic-texture.js.map +1 -1
- package/effect-ready.d.ts +1 -3
- package/effect-ready.js +3 -3
- package/effect-ready.js.map +1 -1
- package/effect-renderer.d.ts +39 -12
- package/effect-renderer.js +47 -17
- package/effect-renderer.js.map +1 -1
- package/effect.d.ts +25 -21
- package/effect.js +69 -51
- package/effect.js.map +1 -1
- package/gpu-frame-time.d.ts +49 -0
- package/gpu-frame-time.js +130 -0
- package/gpu-frame-time.js.map +1 -0
- package/html-texture.d.ts +24 -34
- package/html-texture.js +34 -55
- package/html-texture.js.map +1 -1
- package/index.d.ts +9 -8
- package/index.js +9 -6
- package/index.js.map +1 -1
- package/mesh.d.ts +8 -14
- package/mesh.js +23 -19
- package/mesh.js.map +1 -1
- package/package.json +3 -3
- package/render-loop.d.ts +14 -0
- package/render-loop.js +23 -0
- package/render-loop.js.map +1 -1
- package/render-target.d.ts +109 -39
- package/render-target.js +136 -58
- package/render-target.js.map +1 -1
- package/sprites.d.ts +8 -2
- package/sprites.js +17 -13
- package/sprites.js.map +1 -1
- package/state.d.ts +1 -1
- package/state.js.map +1 -1
- package/text/_gpu/text-effect.js +5 -5
- package/text/_gpu/text-effect.js.map +1 -1
- package/text/_gpu/text-instances.js +4 -4
- package/text/_gpu/text-instances.js.map +1 -1
- package/text/_gpu/text-textures.js +5 -3
- package/text/_gpu/text-textures.js.map +1 -1
- package/text/glyph-storage.js +3 -3
- package/text/glyph-storage.js.map +1 -1
- package/text/text-data.js +2 -2
- package/text/text-data.js.map +1 -1
- package/text/text-renderer.js +11 -11
- package/text/text-renderer.js.map +1 -1
- package/texture-3d.d.ts +10 -7
- package/texture-3d.js +27 -12
- package/texture-3d.js.map +1 -1
- package/texture-source.d.ts +3 -4
- package/texture-source.js +5 -5
- package/texture-source.js.map +1 -1
- package/texture.d.ts +195 -31
- package/texture.js +215 -35
- package/texture.js.map +1 -1
package/mesh.d.ts
CHANGED
|
@@ -80,12 +80,11 @@ export declare function createVertexBuffer(engine: GLEngineContext, data: Float3
|
|
|
80
80
|
* full-buffer update from offset 0 also refreshes the retained CPU data used
|
|
81
81
|
* for context-restore.
|
|
82
82
|
*
|
|
83
|
-
* @param engine - The engine.
|
|
84
83
|
* @param vb - The vertex buffer to update.
|
|
85
84
|
* @param data - The new float data.
|
|
86
85
|
* @param dstByteOffset - Destination byte offset within the buffer. Default 0.
|
|
87
86
|
*/
|
|
88
|
-
export declare function updateVertexBuffer(
|
|
87
|
+
export declare function updateVertexBuffer(vb: GLVertexBuffer, data: Float32Array, dstByteOffset?: number): void;
|
|
89
88
|
/**
|
|
90
89
|
* Create a GPU index buffer. `Uint16Array` → 16-bit indices, `Uint32Array` →
|
|
91
90
|
* 32-bit. Binds the default VAO first so it never corrupts the quad / sprite
|
|
@@ -98,15 +97,14 @@ export declare function updateVertexBuffer(engine: GLEngineContext, vb: GLVertex
|
|
|
98
97
|
export declare function createIndexBuffer(engine: GLEngineContext, data: Uint16Array | Uint32Array): GLIndexBuffer;
|
|
99
98
|
/** Dispose a vertex or index buffer (delete the GL buffer + unregister). Clears
|
|
100
99
|
* the array/element-buffer cache slot if it pointed at this buffer. Idempotent. */
|
|
101
|
-
export declare function disposeBuffer(
|
|
100
|
+
export declare function disposeBuffer(buffer: GLVertexBuffer | GLIndexBuffer): void;
|
|
102
101
|
/**
|
|
103
102
|
* Bind an index buffer as the current element-array buffer (on the default
|
|
104
103
|
* VAO). Cached. The lite-gl equivalent of Babylon's `_bindIndexBufferWithCache`.
|
|
105
104
|
*
|
|
106
|
-
* @param engine - The engine.
|
|
107
105
|
* @param ib - The index buffer to bind.
|
|
108
106
|
*/
|
|
109
|
-
export declare function bindIndexBuffer(
|
|
107
|
+
export declare function bindIndexBuffer(ib: GLIndexBuffer): void;
|
|
110
108
|
/**
|
|
111
109
|
* Configure vertex attributes from `vb`, reproducing Babylon's
|
|
112
110
|
* `bindInstancesBuffer` exactly. For each descriptor: resolves the location
|
|
@@ -125,13 +123,12 @@ export declare function bindIndexBuffer(engine: GLEngineContext, ib: GLIndexBuff
|
|
|
125
123
|
* Runs on the default (null) VAO — never corrupts the quad / sprite VAOs.
|
|
126
124
|
* No-op on a lost/disposed context or before the effect is ready.
|
|
127
125
|
*
|
|
128
|
-
* @param engine - The engine.
|
|
129
126
|
* @param vb - The buffer supplying the attribute data.
|
|
130
127
|
* @param descriptors - The attribute layout.
|
|
131
128
|
* @param effect - The effect whose attribute locations resolve unnamed indices.
|
|
132
129
|
* @param computeStride - See above. Default `false`.
|
|
133
130
|
*/
|
|
134
|
-
export declare function bindAttributes(
|
|
131
|
+
export declare function bindAttributes(vb: GLVertexBuffer, descriptors: readonly GLAttributeDescriptor[], effect: GLEffect, computeStride?: boolean): void;
|
|
135
132
|
/**
|
|
136
133
|
* Reset the vertex divisor of every attribute touched by {@link bindAttributes}
|
|
137
134
|
* back to 0 — the lite-gl equivalent of Babylon's `unbindInstanceAttributes`.
|
|
@@ -147,14 +144,13 @@ export declare function unbindInstanceAttributes(engine: GLEngineContext): void;
|
|
|
147
144
|
* `drawElementsInstanced`, otherwise `drawElements`. No-op on a lost/disposed
|
|
148
145
|
* context or when no program is current.
|
|
149
146
|
*
|
|
150
|
-
* @param engine - The engine.
|
|
151
147
|
* @param ib - The index buffer (also bound as a side-effect, cached).
|
|
152
148
|
* @param indexCount - Number of indices to draw.
|
|
153
149
|
* @param indexStart - First index offset (in indices, not bytes). Default 0.
|
|
154
150
|
* @param instanceCount - Instance count for instanced draws. Default 0
|
|
155
151
|
* (non-instanced).
|
|
156
152
|
*/
|
|
157
|
-
export declare function drawIndexed(
|
|
153
|
+
export declare function drawIndexed(ib: GLIndexBuffer, indexCount: number, indexStart?: number, instanceCount?: number): void;
|
|
158
154
|
/** One vertex buffer + its attribute layout, for {@link createMeshVao}. */
|
|
159
155
|
export interface GLMeshVertexBuffer {
|
|
160
156
|
/** The buffer supplying this group's attributes. */
|
|
@@ -190,10 +186,9 @@ export declare function createMeshVao(engine: GLEngineContext, vertexBuffers: re
|
|
|
190
186
|
* {@link drawMesh} binds it for you. Binding restores the VAO's recorded element
|
|
191
187
|
* binding, so the element-buffer cache is updated in lock-step.
|
|
192
188
|
*
|
|
193
|
-
* @param engine - The engine.
|
|
194
189
|
* @param vao - The mesh VAO to bind.
|
|
195
190
|
*/
|
|
196
|
-
export declare function bindMeshVao(
|
|
191
|
+
export declare function bindMeshVao(vao: GLMeshVao): void;
|
|
197
192
|
/**
|
|
198
193
|
* Draw a static mesh recorded with {@link createMeshVao}: binds its VAO (cached),
|
|
199
194
|
* flushes deferred GL state, and issues ONE `drawElements` (or
|
|
@@ -201,11 +196,10 @@ export declare function bindMeshVao(engine: GLEngineContext, vao: GLMeshVao): vo
|
|
|
201
196
|
* buffer. No per-draw attribute (re)binding. No-op on a lost/disposed context, a
|
|
202
197
|
* disposed VAO, or when no program is current.
|
|
203
198
|
*
|
|
204
|
-
* @param engine - The engine.
|
|
205
199
|
* @param vao - The mesh VAO to draw.
|
|
206
200
|
* @param instanceCount - Instance count for instanced draws. Default 0 (non-instanced).
|
|
207
201
|
*/
|
|
208
|
-
export declare function drawMesh(
|
|
202
|
+
export declare function drawMesh(vao: GLMeshVao, instanceCount?: number): void;
|
|
209
203
|
/** Dispose a {@link GLMeshVao}: delete the VAO and unregister its restore hook.
|
|
210
204
|
* Does NOT dispose the vertex/index buffers (the caller owns those). Idempotent. */
|
|
211
|
-
export declare function disposeMeshVao(
|
|
205
|
+
export declare function disposeMeshVao(vao: GLMeshVao): void;
|
package/mesh.js
CHANGED
|
@@ -39,6 +39,7 @@ export function createVertexBuffer(engine, data, dynamic = false) {
|
|
|
39
39
|
byteLength: data.byteLength,
|
|
40
40
|
_data: data,
|
|
41
41
|
_dynamic: dynamic,
|
|
42
|
+
_engine: engine,
|
|
42
43
|
_disposed: false,
|
|
43
44
|
_deleteGpu: () => { },
|
|
44
45
|
_restore: () => { },
|
|
@@ -66,12 +67,12 @@ export function createVertexBuffer(engine, data, dynamic = false) {
|
|
|
66
67
|
* full-buffer update from offset 0 also refreshes the retained CPU data used
|
|
67
68
|
* for context-restore.
|
|
68
69
|
*
|
|
69
|
-
* @param engine - The engine.
|
|
70
70
|
* @param vb - The vertex buffer to update.
|
|
71
71
|
* @param data - The new float data.
|
|
72
72
|
* @param dstByteOffset - Destination byte offset within the buffer. Default 0.
|
|
73
73
|
*/
|
|
74
|
-
export function updateVertexBuffer(
|
|
74
|
+
export function updateVertexBuffer(vb, data, dstByteOffset = 0) {
|
|
75
|
+
const engine = vb._engine;
|
|
75
76
|
if (engine._isLost || engine._disposed || vb._disposed) {
|
|
76
77
|
return;
|
|
77
78
|
}
|
|
@@ -103,6 +104,7 @@ export function createIndexBuffer(engine, data) {
|
|
|
103
104
|
count: data.length,
|
|
104
105
|
is32Bits: is32,
|
|
105
106
|
_data: data,
|
|
107
|
+
_engine: engine,
|
|
106
108
|
_disposed: false,
|
|
107
109
|
_deleteGpu: () => { },
|
|
108
110
|
_restore: () => { },
|
|
@@ -131,7 +133,8 @@ export function createIndexBuffer(engine, data) {
|
|
|
131
133
|
}
|
|
132
134
|
/** Dispose a vertex or index buffer (delete the GL buffer + unregister). Clears
|
|
133
135
|
* the array/element-buffer cache slot if it pointed at this buffer. Idempotent. */
|
|
134
|
-
export function disposeBuffer(
|
|
136
|
+
export function disposeBuffer(buffer) {
|
|
137
|
+
const engine = buffer._engine;
|
|
135
138
|
if (buffer._disposed) {
|
|
136
139
|
return;
|
|
137
140
|
}
|
|
@@ -156,10 +159,10 @@ export function disposeBuffer(engine, buffer) {
|
|
|
156
159
|
* Bind an index buffer as the current element-array buffer (on the default
|
|
157
160
|
* VAO). Cached. The lite-gl equivalent of Babylon's `_bindIndexBufferWithCache`.
|
|
158
161
|
*
|
|
159
|
-
* @param engine - The engine.
|
|
160
162
|
* @param ib - The index buffer to bind.
|
|
161
163
|
*/
|
|
162
|
-
export function bindIndexBuffer(
|
|
164
|
+
export function bindIndexBuffer(ib) {
|
|
165
|
+
const engine = ib._engine;
|
|
163
166
|
if (engine._isLost || engine._disposed || ib._disposed) {
|
|
164
167
|
return;
|
|
165
168
|
}
|
|
@@ -189,13 +192,13 @@ export function bindIndexBuffer(engine, ib) {
|
|
|
189
192
|
* Runs on the default (null) VAO — never corrupts the quad / sprite VAOs.
|
|
190
193
|
* No-op on a lost/disposed context or before the effect is ready.
|
|
191
194
|
*
|
|
192
|
-
* @param engine - The engine.
|
|
193
195
|
* @param vb - The buffer supplying the attribute data.
|
|
194
196
|
* @param descriptors - The attribute layout.
|
|
195
197
|
* @param effect - The effect whose attribute locations resolve unnamed indices.
|
|
196
198
|
* @param computeStride - See above. Default `false`.
|
|
197
199
|
*/
|
|
198
|
-
export function bindAttributes(
|
|
200
|
+
export function bindAttributes(vb, descriptors, effect, computeStride = false) {
|
|
201
|
+
const engine = vb._engine;
|
|
199
202
|
if (engine._isLost || engine._disposed || vb._disposed || !effect.isReady) {
|
|
200
203
|
return;
|
|
201
204
|
}
|
|
@@ -211,7 +214,7 @@ export function bindAttributes(engine, vb, descriptors, effect, computeStride =
|
|
|
211
214
|
}
|
|
212
215
|
for (let i = 0; i < descriptors.length; i++) {
|
|
213
216
|
const d = descriptors[i];
|
|
214
|
-
const loc = d.index !== undefined ? d.index : d.name !== undefined ? getEffectAttributeLocation(
|
|
217
|
+
const loc = d.index !== undefined ? d.index : d.name !== undefined ? getEffectAttributeLocation(effect, d.name) : -1;
|
|
215
218
|
if (loc < 0) {
|
|
216
219
|
continue;
|
|
217
220
|
}
|
|
@@ -252,21 +255,21 @@ export function unbindInstanceAttributes(engine) {
|
|
|
252
255
|
* `drawElementsInstanced`, otherwise `drawElements`. No-op on a lost/disposed
|
|
253
256
|
* context or when no program is current.
|
|
254
257
|
*
|
|
255
|
-
* @param engine - The engine.
|
|
256
258
|
* @param ib - The index buffer (also bound as a side-effect, cached).
|
|
257
259
|
* @param indexCount - Number of indices to draw.
|
|
258
260
|
* @param indexStart - First index offset (in indices, not bytes). Default 0.
|
|
259
261
|
* @param instanceCount - Instance count for instanced draws. Default 0
|
|
260
262
|
* (non-instanced).
|
|
261
263
|
*/
|
|
262
|
-
export function drawIndexed(
|
|
264
|
+
export function drawIndexed(ib, indexCount, indexStart = 0, instanceCount = 0) {
|
|
265
|
+
const engine = ib._engine;
|
|
263
266
|
if (engine._isLost || engine._disposed || ib._disposed) {
|
|
264
267
|
return;
|
|
265
268
|
}
|
|
266
269
|
if (engine._state.currentProgram === null) {
|
|
267
270
|
return;
|
|
268
271
|
}
|
|
269
|
-
bindIndexBuffer(
|
|
272
|
+
bindIndexBuffer(ib);
|
|
270
273
|
const gl = engine.gl;
|
|
271
274
|
const type = ib.is32Bits ? UNSIGNED_INT : UNSIGNED_SHORT;
|
|
272
275
|
const byteOffset = indexStart * (ib.is32Bits ? 4 : 2);
|
|
@@ -314,7 +317,7 @@ export function createMeshVao(engine, vertexBuffers, indexBuffer, effect) {
|
|
|
314
317
|
const attrs = [];
|
|
315
318
|
for (let i = 0; i < vbb.attributes.length; i++) {
|
|
316
319
|
const d = vbb.attributes[i];
|
|
317
|
-
const loc = d.index !== undefined ? d.index : d.name !== undefined ? getEffectAttributeLocation(
|
|
320
|
+
const loc = d.index !== undefined ? d.index : d.name !== undefined ? getEffectAttributeLocation(effect, d.name) : -1;
|
|
318
321
|
if (loc < 0) {
|
|
319
322
|
continue;
|
|
320
323
|
}
|
|
@@ -330,7 +333,7 @@ export function createMeshVao(engine, vertexBuffers, indexBuffer, effect) {
|
|
|
330
333
|
}
|
|
331
334
|
bindings.push({ buffer: vbb.buffer, attrs });
|
|
332
335
|
}
|
|
333
|
-
const vao = { handle, _disposed: false, _indexBuffer: indexBuffer, _bindings: bindings, _restore: () => { } };
|
|
336
|
+
const vao = { handle, _engine: engine, _disposed: false, _indexBuffer: indexBuffer, _bindings: bindings, _restore: () => { } };
|
|
334
337
|
vao._restore = () => {
|
|
335
338
|
if (engine._isLost || engine._disposed || vao._disposed) {
|
|
336
339
|
return;
|
|
@@ -351,10 +354,10 @@ export function createMeshVao(engine, vertexBuffers, indexBuffer, effect) {
|
|
|
351
354
|
* {@link drawMesh} binds it for you. Binding restores the VAO's recorded element
|
|
352
355
|
* binding, so the element-buffer cache is updated in lock-step.
|
|
353
356
|
*
|
|
354
|
-
* @param engine - The engine.
|
|
355
357
|
* @param vao - The mesh VAO to bind.
|
|
356
358
|
*/
|
|
357
|
-
export function bindMeshVao(
|
|
359
|
+
export function bindMeshVao(vao) {
|
|
360
|
+
const engine = vao._engine;
|
|
358
361
|
if (engine._isLost || engine._disposed || vao._disposed) {
|
|
359
362
|
return;
|
|
360
363
|
}
|
|
@@ -373,18 +376,18 @@ export function bindMeshVao(engine, vao) {
|
|
|
373
376
|
* buffer. No per-draw attribute (re)binding. No-op on a lost/disposed context, a
|
|
374
377
|
* disposed VAO, or when no program is current.
|
|
375
378
|
*
|
|
376
|
-
* @param engine - The engine.
|
|
377
379
|
* @param vao - The mesh VAO to draw.
|
|
378
380
|
* @param instanceCount - Instance count for instanced draws. Default 0 (non-instanced).
|
|
379
381
|
*/
|
|
380
|
-
export function drawMesh(
|
|
382
|
+
export function drawMesh(vao, instanceCount = 0) {
|
|
383
|
+
const engine = vao._engine;
|
|
381
384
|
if (engine._isLost || engine._disposed || vao._disposed) {
|
|
382
385
|
return;
|
|
383
386
|
}
|
|
384
387
|
if (engine._state.currentProgram === null) {
|
|
385
388
|
return;
|
|
386
389
|
}
|
|
387
|
-
bindMeshVao(
|
|
390
|
+
bindMeshVao(vao);
|
|
388
391
|
applyGLStates(engine);
|
|
389
392
|
const ib = vao._indexBuffer;
|
|
390
393
|
const gl = engine.gl;
|
|
@@ -398,7 +401,8 @@ export function drawMesh(engine, vao, instanceCount = 0) {
|
|
|
398
401
|
}
|
|
399
402
|
/** Dispose a {@link GLMeshVao}: delete the VAO and unregister its restore hook.
|
|
400
403
|
* Does NOT dispose the vertex/index buffers (the caller owns those). Idempotent. */
|
|
401
|
-
export function disposeMeshVao(
|
|
404
|
+
export function disposeMeshVao(vao) {
|
|
405
|
+
const engine = vao._engine;
|
|
402
406
|
if (vao._disposed) {
|
|
403
407
|
return;
|
|
404
408
|
}
|
package/mesh.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mesh.js","sourceRoot":"","sources":["../src/mesh.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAiB,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,4BAA4B;AAC5B,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,oCAAoC;AACpC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AACpC,2BAA2B;AAC3B,MAAM,WAAW,GAAG,MAAM,CAAC;AAC3B,4BAA4B;AAC5B,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,qBAAqB;AACrB,MAAM,KAAK,GAAG,MAAM,CAAC;AACrB,yBAAyB;AACzB,MAAM,SAAS,GAAG,MAAM,CAAC;AACzB,8BAA8B;AAC9B,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,4BAA4B;AAC5B,MAAM,YAAY,GAAG,MAAM,CAAC;AAoE5B,iFAAiF;AAEjF;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAuB,EAAE,IAAkB,EAAE,OAAO,GAAG,KAAK;IAC3F,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;IACrB,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC;IAC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,CAAC;YAChF,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;IACL,CAAC;IACD,EAAE,CAAC,UAAU,CAAC,oBAAoB,EAAE,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC7D,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC;IAClB,CAAC,CAAC,kBAAkB,GAAG,IAAI,CAAC;AAChC,CAAC;AAED,kFAAkF;AAElF;;;oDAGoD;AACpD,SAAS,cAAc,CAAC,MAAuB;IAC3C,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtB,MAAM,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC;QAClB,CAAC,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAChC,CAAC;AACL,CAAC;AAED;iEACiE;AACjE,SAAS,kBAAkB,CAAC,MAAuB,EAAE,MAAmB;IACpE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,IAAI,CAAC,CAAC,gBAAgB,KAAK,MAAM,EAAE,CAAC;QAChC,OAAO;IACX,CAAC;IACD,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC,CAAC,gBAAgB,GAAG,MAAM,CAAC;AAChC,CAAC","sourcesContent":["/**\n * Indexed meshes, dynamic vertex/index buffers, and hardware instancing.\n *\n * Part of the public API via the `@babylonjs/lite-gl` barrel. The package is\n * `sideEffects: false`, so consumers that only render the fullscreen quad /\n * sprites tree-shake the mesh code out.\n *\n * This is the lite-gl equivalent of Babylon's `ThinEngine.createVertexBuffer` /\n * `createIndexBuffer` / `_releaseBuffer` / `bindIndexBuffer` /\n * `bindInstancesBuffer` / `unbindInstanceAttributes` / `drawElementsType`. The\n * attribute binder reproduces Babylon's instancing semantics EXACTLY, including\n * the `computeStride = false → stride 0` \"sliding window\" used by ShapeBuilder's\n * tape buffers (consecutive instances read overlapping vec4 windows) and the\n * `divisor === undefined → 1` default.\n *\n * The mesh path runs on the DEFAULT (null) VAO — every buffer/attribute op binds\n * `gl.bindVertexArray(null)` first, so it never corrupts the quad / sprite VAOs.\n * Vertex and index buffers retain their CPU data and re-upload automatically on\n * `webglcontextrestored`.\n */\nimport type { GLEngineContext } from \"./context.js\";\nimport { onContextRestored, offContextRestored } from \"./context.js\";\nimport { getEffectAttributeLocation, type GLEffect } from \"./effect.js\";\nimport { applyGLStates } from \"./apply-states.js\";\n\n/** GL `gl.ARRAY_BUFFER`. */\nconst ARRAY_BUFFER = 0x8892;\n/** GL `gl.ELEMENT_ARRAY_BUFFER`. */\nconst ELEMENT_ARRAY_BUFFER = 0x8893;\n/** GL `gl.STATIC_DRAW`. */\nconst STATIC_DRAW = 0x88e4;\n/** GL `gl.DYNAMIC_DRAW`. */\nconst DYNAMIC_DRAW = 0x88e8;\n/** GL `gl.FLOAT`. */\nconst FLOAT = 0x1406;\n/** GL `gl.TRIANGLES`. */\nconst TRIANGLES = 0x0004;\n/** GL `gl.UNSIGNED_SHORT`. */\nconst UNSIGNED_SHORT = 0x1403;\n/** GL `gl.UNSIGNED_INT`. */\nconst UNSIGNED_INT = 0x1405;\n\n/** A GPU vertex buffer holding interleaved float vertex data. The lite-gl\n * counterpart of Babylon's `DataBuffer` for vertex data. */\nexport interface GLVertexBuffer {\n /** The live `WebGLBuffer`. Swapped on `webglcontextrestored`. */\n handle: WebGLBuffer;\n /** Size of the GL buffer in bytes. */\n byteLength: number;\n /** @internal */\n _disposed: boolean;\n /** @internal Delete the underlying GL buffer. */\n _deleteGpu: (gl: WebGL2RenderingContext) => void;\n /** @internal Re-create + re-upload the retained CPU data into a fresh handle. */\n _restore: (engine: GLEngineContext) => void;\n /** @internal Retained CPU data for context-restore replay (the creation /\n * last full-buffer upload). */\n _data: Float32Array;\n /** @internal `true` for `DYNAMIC_DRAW` (updated via `updateVertexBuffer`). */\n _dynamic: boolean;\n}\n\n/** A GPU index buffer. The lite-gl counterpart of Babylon's `DataBuffer` for\n * index data. */\nexport interface GLIndexBuffer {\n /** The live `WebGLBuffer`. Swapped on `webglcontextrestored`. */\n handle: WebGLBuffer;\n /** Number of indices. */\n count: number;\n /** `true` for 32-bit (`Uint32Array`) indices, `false` for 16-bit. */\n is32Bits: boolean;\n /** @internal */\n _disposed: boolean;\n /** @internal Delete the underlying GL buffer. */\n _deleteGpu: (gl: WebGL2RenderingContext) => void;\n /** @internal Re-create + re-upload the retained CPU data into a fresh handle. */\n _restore: (engine: GLEngineContext) => void;\n /** @internal Retained CPU data for context-restore replay. */\n _data: Uint16Array | Uint32Array;\n}\n\n/**\n * Describes one vertex attribute fed from a buffer — the lite-gl equivalent of\n * Babylon's `InstancingAttributeInfo`. Pass an array of these to\n * {@link bindAttributes}.\n */\nexport interface GLAttributeDescriptor {\n /** Attribute name; resolved to a location via the effect when `index` is\n * omitted (`Effect.getAttributeLocationByName`). */\n name?: string;\n /** Explicit attribute location. When set, overrides the `name` lookup. */\n index?: number;\n /** Number of components, 1–4. */\n size: number;\n /** Byte offset of this attribute's first element within the buffer. Default 0. */\n offset?: number;\n /**\n * Per-instance vertex divisor. **Omitted/`undefined` → `1` (instanced)**,\n * matching Babylon's `bindInstancesBuffer`. Pass `0` explicitly for a\n * per-vertex attribute (e.g. the base mesh position).\n */\n divisor?: number;\n /** GL component type. Default `gl.FLOAT`. */\n type?: GLenum;\n /** Normalize fixed-point integer data to `[0,1]`/`[-1,1]`. Default `false`. */\n normalized?: boolean;\n}\n\n/* ──────────────────────────────── buffers ──────────────────────────────── */\n\n/**\n * Create a GPU vertex buffer from interleaved float data.\n *\n * @param engine - The engine.\n * @param data - The vertex data. Retained by reference for context-restore — do\n * not mutate it in place; use {@link updateVertexBuffer} to change contents.\n * @param dynamic - Hint that the buffer will be updated frequently\n * (`DYNAMIC_DRAW`). Default `false` (`STATIC_DRAW`).\n * @returns The new {@link GLVertexBuffer}.\n */\nexport function createVertexBuffer(engine: GLEngineContext, data: Float32Array, dynamic = false): GLVertexBuffer {\n const gl = engine.gl;\n const handle = gl.createBuffer();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (vertex buffer)\");\n }\n const vb: GLVertexBuffer = {\n handle,\n byteLength: data.byteLength,\n _data: data,\n _dynamic: dynamic,\n _disposed: false,\n _deleteGpu: () => {},\n _restore: () => {},\n };\n vb._deleteGpu = (g: WebGL2RenderingContext): void => {\n g.deleteBuffer(vb.handle);\n };\n vb._restore = (target: GLEngineContext): void => {\n const g = target.gl;\n const fresh = g.createBuffer();\n if (fresh === null) {\n return;\n }\n vb.handle = fresh;\n bindArrayBufferRaw(target, fresh);\n g.bufferData(ARRAY_BUFFER, vb._data, vb._dynamic ? DYNAMIC_DRAW : STATIC_DRAW);\n };\n bindArrayBufferRaw(engine, handle);\n gl.bufferData(ARRAY_BUFFER, data, dynamic ? DYNAMIC_DRAW : STATIC_DRAW);\n engine._buffers.push(vb);\n return vb;\n}\n\n/**\n * Upload new contents into (part of) a vertex buffer via `bufferSubData`. A\n * full-buffer update from offset 0 also refreshes the retained CPU data used\n * for context-restore.\n *\n * @param engine - The engine.\n * @param vb - The vertex buffer to update.\n * @param data - The new float data.\n * @param dstByteOffset - Destination byte offset within the buffer. Default 0.\n */\nexport function updateVertexBuffer(engine: GLEngineContext, vb: GLVertexBuffer, data: Float32Array, dstByteOffset = 0): void {\n if (engine._isLost || engine._disposed || vb._disposed) {\n return;\n }\n bindArrayBufferRaw(engine, vb.handle);\n engine.gl.bufferSubData(ARRAY_BUFFER, dstByteOffset, data);\n if (dstByteOffset === 0 && data.byteLength >= vb.byteLength) {\n vb._data = data;\n vb.byteLength = data.byteLength;\n }\n}\n\n/**\n * Create a GPU index buffer. `Uint16Array` → 16-bit indices, `Uint32Array` →\n * 32-bit. Binds the default VAO first so it never corrupts the quad / sprite\n * VAO element bindings.\n *\n * @param engine - The engine.\n * @param data - The index data. Retained by reference for context-restore.\n * @returns The new {@link GLIndexBuffer}.\n */\nexport function createIndexBuffer(engine: GLEngineContext, data: Uint16Array | Uint32Array): GLIndexBuffer {\n const gl = engine.gl;\n const handle = gl.createBuffer();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (index buffer)\");\n }\n const is32 = data instanceof Uint32Array;\n const ib: GLIndexBuffer = {\n handle,\n count: data.length,\n is32Bits: is32,\n _data: data,\n _disposed: false,\n _deleteGpu: () => {},\n _restore: () => {},\n };\n ib._deleteGpu = (g: WebGL2RenderingContext): void => {\n g.deleteBuffer(ib.handle);\n };\n ib._restore = (target: GLEngineContext): void => {\n const g = target.gl;\n const fresh = g.createBuffer();\n if (fresh === null) {\n return;\n }\n ib.handle = fresh;\n bindDefaultVao(target);\n g.bindBuffer(ELEMENT_ARRAY_BUFFER, fresh);\n target._state.boundElementBuffer = fresh;\n g.bufferData(ELEMENT_ARRAY_BUFFER, ib._data, STATIC_DRAW);\n };\n bindDefaultVao(engine);\n gl.bindBuffer(ELEMENT_ARRAY_BUFFER, handle);\n engine._state.boundElementBuffer = handle;\n gl.bufferData(ELEMENT_ARRAY_BUFFER, data, STATIC_DRAW);\n engine._buffers.push(ib);\n return ib;\n}\n\n/** Dispose a vertex or index buffer (delete the GL buffer + unregister). Clears\n * the array/element-buffer cache slot if it pointed at this buffer. Idempotent. */\nexport function disposeBuffer(engine: GLEngineContext, buffer: GLVertexBuffer | GLIndexBuffer): void {\n if (buffer._disposed) {\n return;\n }\n buffer._disposed = true;\n const i = engine._buffers.indexOf(buffer);\n if (i !== -1) {\n engine._buffers.splice(i, 1);\n }\n const s = engine._state;\n if (!engine._isLost && !engine._disposed) {\n engine.gl.deleteBuffer(buffer.handle);\n }\n if (s.boundArrayBuffer === buffer.handle) {\n s.boundArrayBuffer = null;\n }\n if (s.boundElementBuffer === buffer.handle) {\n s.boundElementBuffer = null;\n }\n}\n\n/* ────────────────────────────── binding + draw ──────────────────────────── */\n\n/**\n * Bind an index buffer as the current element-array buffer (on the default\n * VAO). Cached. The lite-gl equivalent of Babylon's `_bindIndexBufferWithCache`.\n *\n * @param engine - The engine.\n * @param ib - The index buffer to bind.\n */\nexport function bindIndexBuffer(engine: GLEngineContext, ib: GLIndexBuffer): void {\n if (engine._isLost || engine._disposed || ib._disposed) {\n return;\n }\n bindDefaultVao(engine);\n const s = engine._state;\n if (s.boundElementBuffer === ib.handle) {\n return;\n }\n engine.gl.bindBuffer(ELEMENT_ARRAY_BUFFER, ib.handle);\n s.boundElementBuffer = ib.handle;\n}\n\n/**\n * Configure vertex attributes from `vb`, reproducing Babylon's\n * `bindInstancesBuffer` exactly. For each descriptor: resolves the location\n * (explicit `index` or via the effect), enables the attribute array, issues\n * `vertexAttribPointer`, and sets the vertex divisor (`undefined → 1`). Each\n * instanced location (divisor ≠ 0) is tracked once so {@link unbindInstanceAttributes}\n * can reset its divisor afterwards; per-vertex locations already have divisor 0 and are\n * not tracked, so callers that never instance can rebind every frame without growth.\n *\n * `computeStride` controls the GL stride passed to `vertexAttribPointer`:\n * - `false` (default) → stride `0`: each attribute is independently tightly\n * packed. Combined with overlapping `offset`s this yields the \"sliding window\"\n * ShapeBuilder uses for distance-field tape buffers.\n * - `true` → stride = Σ(`size`·4 bytes): interleaved per-vertex/per-instance.\n *\n * Runs on the default (null) VAO — never corrupts the quad / sprite VAOs.\n * No-op on a lost/disposed context or before the effect is ready.\n *\n * @param engine - The engine.\n * @param vb - The buffer supplying the attribute data.\n * @param descriptors - The attribute layout.\n * @param effect - The effect whose attribute locations resolve unnamed indices.\n * @param computeStride - See above. Default `false`.\n */\nexport function bindAttributes(engine: GLEngineContext, vb: GLVertexBuffer, descriptors: readonly GLAttributeDescriptor[], effect: GLEffect, computeStride = false): void {\n if (engine._isLost || engine._disposed || vb._disposed || !effect.isReady) {\n return;\n }\n const gl = engine.gl;\n const s = engine._state;\n bindDefaultVao(engine);\n bindArrayBufferRaw(engine, vb.handle);\n\n let stride = 0;\n if (computeStride) {\n for (let i = 0; i < descriptors.length; i++) {\n stride += (descriptors[i] as GLAttributeDescriptor).size * 4;\n }\n }\n\n for (let i = 0; i < descriptors.length; i++) {\n const d = descriptors[i] as GLAttributeDescriptor;\n const loc = d.index !== undefined ? d.index : d.name !== undefined ? getEffectAttributeLocation(engine, effect, d.name) : -1;\n if (loc < 0) {\n continue;\n }\n if (!s.enabledAttribs[loc]) {\n gl.enableVertexAttribArray(loc);\n s.enabledAttribs[loc] = true;\n }\n gl.vertexAttribPointer(loc, d.size, d.type ?? FLOAT, d.normalized ?? false, stride, d.offset ?? 0);\n const divisor = d.divisor ?? 1;\n gl.vertexAttribDivisor(loc, divisor);\n if (divisor !== 0 && !s.instanceLocations.includes(loc)) {\n s.instanceLocations.push(loc);\n }\n }\n}\n\n/**\n * Reset the vertex divisor of every attribute touched by {@link bindAttributes}\n * back to 0 — the lite-gl equivalent of Babylon's `unbindInstanceAttributes`.\n * Call after an instanced draw so a following non-instanced draw is not skewed.\n * No-op on a lost/disposed context.\n *\n * @param engine - The engine.\n */\nexport function unbindInstanceAttributes(engine: GLEngineContext): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const gl = engine.gl;\n const locs = engine._state.instanceLocations;\n for (let i = 0; i < locs.length; i++) {\n gl.vertexAttribDivisor(locs[i] as number, 0);\n }\n locs.length = 0;\n}\n\n/**\n * Draw indexed triangles from `ib` — the lite-gl equivalent of Babylon's\n * `drawElementsType` (triangle fill mode). When `instanceCount > 0` issues\n * `drawElementsInstanced`, otherwise `drawElements`. No-op on a lost/disposed\n * context or when no program is current.\n *\n * @param engine - The engine.\n * @param ib - The index buffer (also bound as a side-effect, cached).\n * @param indexCount - Number of indices to draw.\n * @param indexStart - First index offset (in indices, not bytes). Default 0.\n * @param instanceCount - Instance count for instanced draws. Default 0\n * (non-instanced).\n */\nexport function drawIndexed(engine: GLEngineContext, ib: GLIndexBuffer, indexCount: number, indexStart = 0, instanceCount = 0): void {\n if (engine._isLost || engine._disposed || ib._disposed) {\n return;\n }\n if (engine._state.currentProgram === null) {\n return;\n }\n bindIndexBuffer(engine, ib);\n const gl = engine.gl;\n const type = ib.is32Bits ? UNSIGNED_INT : UNSIGNED_SHORT;\n const byteOffset = indexStart * (ib.is32Bits ? 4 : 2);\n applyGLStates(engine);\n if (instanceCount > 0) {\n gl.drawElementsInstanced(TRIANGLES, indexCount, type, byteOffset, instanceCount);\n } else {\n gl.drawElements(TRIANGLES, indexCount, type, byteOffset);\n }\n}\n\n/* ────────────────────────── static mesh VAO ─────────────────────────────\n * The VAO-cached counterpart of the manual `bindAttributes` path above — Babylon's\n * `recordVertexArrayObject` / `_cachedVertexArrayObject` for STATIC meshes. A\n * `GLMeshVao` records the whole attribute layout (enable + pointer + divisor for\n * every attribute, across one or more vertex buffers) AND the index binding into a\n * single VAO ONCE. The per-frame draw is then just `bindVertexArray` +\n * `drawElements[Instanced]` — zero per-draw `vertexAttribPointer`/`vertexAttribDivisor`,\n * and no `unbindInstanceAttributes` (the VAO isolates the divisors from the default\n * VAO). Use this for fixed-layout meshes; keep `bindAttributes` for dynamic layouts\n * (e.g. ShapeBuilder's per-draw sliding-window tape buffers). */\n\n/** One vertex buffer + its attribute layout, for {@link createMeshVao}. */\nexport interface GLMeshVertexBuffer {\n /** The buffer supplying this group's attributes. */\n buffer: GLVertexBuffer;\n /** The attributes read from `buffer` (same shape as {@link bindAttributes}). */\n attributes: readonly GLAttributeDescriptor[];\n /** Stride mode (see {@link bindAttributes}): `false` (default) → stride `0`\n * per attribute; `true` → interleaved stride = Σ(`size`·4). */\n computeStride?: boolean;\n}\n\n/** A recorded Vertex Array Object capturing a static mesh's attribute layout +\n * index binding. Bind + draw it with {@link drawMesh} each frame — the GPU\n * replays the entire attribute setup from one `bindVertexArray`. Re-recorded\n * automatically on `webglcontextrestored`. */\nexport interface GLMeshVao {\n /** The live `WebGLVertexArrayObject`. Swapped on `webglcontextrestored`. */\n handle: WebGLVertexArrayObject;\n /** @internal */\n _disposed: boolean;\n /** @internal The index buffer recorded into the VAO. */\n _indexBuffer: GLIndexBuffer;\n /** @internal Resolved attribute bindings, reused to re-record on restore. */\n _bindings: _ResolvedBinding[];\n /** @internal `webglcontextrestored` re-record hook. */\n _restore: () => void;\n}\n\n/** @internal A single attribute with its location resolved once at record time\n * (locations are stable across re-link via `bindAttribLocation`, so the VAO can\n * re-record on context-restore without the effect). */\ninterface _ResolvedAttr {\n loc: number;\n size: number;\n type: number;\n normalized: boolean;\n stride: number;\n offset: number;\n divisor: number;\n}\n\n/** @internal A vertex buffer + its resolved attributes. */\ninterface _ResolvedBinding {\n buffer: GLVertexBuffer;\n attrs: _ResolvedAttr[];\n}\n\n/**\n * Record a static mesh's attribute layout + index binding into a new VAO. The\n * effect MUST be ready (its attribute locations are resolved here, once). Returns\n * a {@link GLMeshVao} to draw with {@link drawMesh}.\n *\n * @param engine - The engine.\n * @param vertexBuffers - One or more buffers + their attribute layouts.\n * @param indexBuffer - The index buffer recorded into the VAO.\n * @param effect - The effect whose attribute locations resolve unnamed indices.\n * @returns The recorded {@link GLMeshVao}.\n */\nexport function createMeshVao(engine: GLEngineContext, vertexBuffers: readonly GLMeshVertexBuffer[], indexBuffer: GLIndexBuffer, effect: GLEffect): GLMeshVao {\n const gl = engine.gl;\n // The effect's attribute locations are resolved (once) below; an unready effect\n // would resolve every name to -1 → a silently-empty VAO. Fail fast — callers\n // must gate on isEffectReady (see scene10's first-ready-frame creation).\n if (!effect.isReady) {\n throw new Error(\"lite-gl: createMeshVao requires a ready effect (poll isEffectReady first)\");\n }\n const handle = gl.createVertexArray();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createVertexArray returned null (mesh VAO)\");\n }\n // Resolve every attribute location ONCE (stable across re-link), so a restore\n // re-record needs only the buffer handles, not the effect.\n const bindings: _ResolvedBinding[] = [];\n for (const vbb of vertexBuffers) {\n let stride = 0;\n if (vbb.computeStride) {\n for (let i = 0; i < vbb.attributes.length; i++) {\n stride += (vbb.attributes[i] as GLAttributeDescriptor).size * 4;\n }\n }\n const attrs: _ResolvedAttr[] = [];\n for (let i = 0; i < vbb.attributes.length; i++) {\n const d = vbb.attributes[i] as GLAttributeDescriptor;\n const loc = d.index !== undefined ? d.index : d.name !== undefined ? getEffectAttributeLocation(engine, effect, d.name) : -1;\n if (loc < 0) {\n continue;\n }\n attrs.push({\n loc,\n size: d.size,\n type: d.type ?? FLOAT,\n normalized: d.normalized ?? false,\n stride,\n offset: d.offset ?? 0,\n divisor: d.divisor === undefined ? 1 : d.divisor,\n });\n }\n bindings.push({ buffer: vbb.buffer, attrs });\n }\n const vao: GLMeshVao = { handle, _disposed: false, _indexBuffer: indexBuffer, _bindings: bindings, _restore: () => {} };\n vao._restore = (): void => {\n if (engine._isLost || engine._disposed || vao._disposed) {\n return;\n }\n const fresh = engine.gl.createVertexArray();\n if (fresh === null) {\n return;\n }\n vao.handle = fresh;\n recordMeshVao(engine, vao);\n };\n recordMeshVao(engine, vao);\n onContextRestored(engine, vao._restore);\n return vao;\n}\n\n/**\n * Bind a {@link GLMeshVao} (cached `gl.bindVertexArray`). Rarely called directly —\n * {@link drawMesh} binds it for you. Binding restores the VAO's recorded element\n * binding, so the element-buffer cache is updated in lock-step.\n *\n * @param engine - The engine.\n * @param vao - The mesh VAO to bind.\n */\nexport function bindMeshVao(engine: GLEngineContext, vao: GLMeshVao): void {\n if (engine._isLost || engine._disposed || vao._disposed) {\n return;\n }\n const s = engine._state;\n if (s.boundVao === vao.handle) {\n return;\n }\n engine.gl.bindVertexArray(vao.handle);\n s.boundVao = vao.handle;\n s.boundElementBuffer = vao._indexBuffer.handle;\n}\n\n/**\n * Draw a static mesh recorded with {@link createMeshVao}: binds its VAO (cached),\n * flushes deferred GL state, and issues ONE `drawElements` (or\n * `drawElementsInstanced` when `instanceCount > 0`) over the VAO's full index\n * buffer. No per-draw attribute (re)binding. No-op on a lost/disposed context, a\n * disposed VAO, or when no program is current.\n *\n * @param engine - The engine.\n * @param vao - The mesh VAO to draw.\n * @param instanceCount - Instance count for instanced draws. Default 0 (non-instanced).\n */\nexport function drawMesh(engine: GLEngineContext, vao: GLMeshVao, instanceCount = 0): void {\n if (engine._isLost || engine._disposed || vao._disposed) {\n return;\n }\n if (engine._state.currentProgram === null) {\n return;\n }\n bindMeshVao(engine, vao);\n applyGLStates(engine);\n const ib = vao._indexBuffer;\n const gl = engine.gl;\n const type = ib.is32Bits ? UNSIGNED_INT : UNSIGNED_SHORT;\n if (instanceCount > 0) {\n gl.drawElementsInstanced(TRIANGLES, ib.count, type, 0, instanceCount);\n } else {\n gl.drawElements(TRIANGLES, ib.count, type, 0);\n }\n}\n\n/** Dispose a {@link GLMeshVao}: delete the VAO and unregister its restore hook.\n * Does NOT dispose the vertex/index buffers (the caller owns those). Idempotent. */\nexport function disposeMeshVao(engine: GLEngineContext, vao: GLMeshVao): void {\n if (vao._disposed) {\n return;\n }\n vao._disposed = true;\n offContextRestored(engine, vao._restore);\n if (!engine._isLost && !engine._disposed) {\n const s = engine._state;\n engine.gl.deleteVertexArray(vao.handle);\n if (s.boundVao === vao.handle) {\n // Return to the default VAO so the cache stays coherent.\n engine.gl.bindVertexArray(null);\n s.boundVao = null;\n s.boundElementBuffer = null;\n }\n }\n}\n\n/** @internal Record `vao._bindings` + the index binding into `vao.handle`. Leaves\n * the default (null) VAO bound afterwards (so the mesh VAO is not left current),\n * forgetting the element-buffer cache. Touches neither `s.enabledAttribs` (those\n * track the DEFAULT VAO) nor the divisor reset — all of that lives in the VAO. */\nfunction recordMeshVao(engine: GLEngineContext, vao: GLMeshVao): void {\n const gl = engine.gl;\n const s = engine._state;\n gl.bindVertexArray(vao.handle);\n s.boundVao = vao.handle;\n for (const b of vao._bindings) {\n bindArrayBufferRaw(engine, b.buffer.handle);\n for (const a of b.attrs) {\n gl.enableVertexAttribArray(a.loc);\n gl.vertexAttribPointer(a.loc, a.size, a.type, a.normalized, a.stride, a.offset);\n gl.vertexAttribDivisor(a.loc, a.divisor);\n }\n }\n gl.bindBuffer(ELEMENT_ARRAY_BUFFER, vao._indexBuffer.handle);\n gl.bindVertexArray(null);\n s.boundVao = null;\n s.boundElementBuffer = null;\n}\n\n/* ──────────────────────────── internal helpers ──────────────────────────── */\n\n/** Bind the default (null) VAO if not already bound. The mesh path lives here so\n * it never disturbs the quad / sprite VAO state. Binding a VAO restores ITS\n * element-array binding, so the element-buffer cache is forgotten on the\n * switch (the next `bindIndexBuffer` re-binds). */\nfunction bindDefaultVao(engine: GLEngineContext): void {\n const s = engine._state;\n if (s.boundVao !== null) {\n engine.gl.bindVertexArray(null);\n s.boundVao = null;\n s.boundElementBuffer = null;\n }\n}\n\n/** Cached `gl.bindBuffer(ARRAY_BUFFER, …)`. ARRAY_BUFFER binding is global (not\n * VAO state), so this cache is coherent across VAO switches. */\nfunction bindArrayBufferRaw(engine: GLEngineContext, handle: WebGLBuffer): void {\n const s = engine._state;\n if (s.boundArrayBuffer === handle) {\n return;\n }\n engine.gl.bindBuffer(ARRAY_BUFFER, handle);\n s.boundArrayBuffer = handle;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mesh.js","sourceRoot":"","sources":["../src/mesh.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAiB,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,4BAA4B;AAC5B,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,oCAAoC;AACpC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AACpC,2BAA2B;AAC3B,MAAM,WAAW,GAAG,MAAM,CAAC;AAC3B,4BAA4B;AAC5B,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,qBAAqB;AACrB,MAAM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C,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC;QAClB,CAAC,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAChC,CAAC;AACL,CAAC;AAED;iEACiE;AACjE,SAAS,kBAAkB,CAAC,MAAuB,EAAE,MAAmB;IACpE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,IAAI,CAAC,CAAC,gBAAgB,KAAK,MAAM,EAAE,CAAC;QAChC,OAAO;IACX,CAAC;IACD,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC,CAAC,gBAAgB,GAAG,MAAM,CAAC;AAChC,CAAC","sourcesContent":["/**\n * Indexed meshes, dynamic vertex/index buffers, and hardware instancing.\n *\n * Part of the public API via the `@babylonjs/lite-gl` barrel. The package is\n * `sideEffects: false`, so consumers that only render the fullscreen quad /\n * sprites tree-shake the mesh code out.\n *\n * This is the lite-gl equivalent of Babylon's `ThinEngine.createVertexBuffer` /\n * `createIndexBuffer` / `_releaseBuffer` / `bindIndexBuffer` /\n * `bindInstancesBuffer` / `unbindInstanceAttributes` / `drawElementsType`. The\n * attribute binder reproduces Babylon's instancing semantics EXACTLY, including\n * the `computeStride = false → stride 0` \"sliding window\" used by ShapeBuilder's\n * tape buffers (consecutive instances read overlapping vec4 windows) and the\n * `divisor === undefined → 1` default.\n *\n * The mesh path runs on the DEFAULT (null) VAO — every buffer/attribute op binds\n * `gl.bindVertexArray(null)` first, so it never corrupts the quad / sprite VAOs.\n * Vertex and index buffers retain their CPU data and re-upload automatically on\n * `webglcontextrestored`.\n */\nimport type { GLEngineContext } from \"./context.js\";\nimport { onContextRestored, offContextRestored } from \"./context.js\";\nimport { getEffectAttributeLocation, type GLEffect } from \"./effect.js\";\nimport { applyGLStates } from \"./apply-states.js\";\n\n/** GL `gl.ARRAY_BUFFER`. */\nconst ARRAY_BUFFER = 0x8892;\n/** GL `gl.ELEMENT_ARRAY_BUFFER`. */\nconst ELEMENT_ARRAY_BUFFER = 0x8893;\n/** GL `gl.STATIC_DRAW`. */\nconst STATIC_DRAW = 0x88e4;\n/** GL `gl.DYNAMIC_DRAW`. */\nconst DYNAMIC_DRAW = 0x88e8;\n/** GL `gl.FLOAT`. */\nconst FLOAT = 0x1406;\n/** GL `gl.TRIANGLES`. */\nconst TRIANGLES = 0x0004;\n/** GL `gl.UNSIGNED_SHORT`. */\nconst UNSIGNED_SHORT = 0x1403;\n/** GL `gl.UNSIGNED_INT`. */\nconst UNSIGNED_INT = 0x1405;\n\n/** A GPU vertex buffer holding interleaved float vertex data. The lite-gl\n * counterpart of Babylon's `DataBuffer` for vertex data. */\nexport interface GLVertexBuffer {\n /** The live `WebGLBuffer`. Swapped on `webglcontextrestored`. */\n handle: WebGLBuffer;\n /** Size of the GL buffer in bytes. */\n byteLength: number;\n /** The engine that created (and owns) this buffer. Operations on it derive\n * their engine from here, so they take the buffer alone. @internal */\n _engine: GLEngineContext;\n /** @internal */\n _disposed: boolean;\n /** @internal Delete the underlying GL buffer. */\n _deleteGpu: (gl: WebGL2RenderingContext) => void;\n /** @internal Re-create + re-upload the retained CPU data into a fresh handle. */\n _restore: (engine: GLEngineContext) => void;\n /** @internal Retained CPU data for context-restore replay (the creation /\n * last full-buffer upload). */\n _data: Float32Array;\n /** @internal `true` for `DYNAMIC_DRAW` (updated via `updateVertexBuffer`). */\n _dynamic: boolean;\n}\n\n/** A GPU index buffer. The lite-gl counterpart of Babylon's `DataBuffer` for\n * index data. */\nexport interface GLIndexBuffer {\n /** The live `WebGLBuffer`. Swapped on `webglcontextrestored`. */\n handle: WebGLBuffer;\n /** Number of indices. */\n count: number;\n /** `true` for 32-bit (`Uint32Array`) indices, `false` for 16-bit. */\n is32Bits: boolean;\n /** The engine that created (and owns) this buffer. Operations on it derive\n * their engine from here, so they take the buffer alone. @internal */\n _engine: GLEngineContext;\n /** @internal */\n _disposed: boolean;\n /** @internal Delete the underlying GL buffer. */\n _deleteGpu: (gl: WebGL2RenderingContext) => void;\n /** @internal Re-create + re-upload the retained CPU data into a fresh handle. */\n _restore: (engine: GLEngineContext) => void;\n /** @internal Retained CPU data for context-restore replay. */\n _data: Uint16Array | Uint32Array;\n}\n\n/**\n * Describes one vertex attribute fed from a buffer — the lite-gl equivalent of\n * Babylon's `InstancingAttributeInfo`. Pass an array of these to\n * {@link bindAttributes}.\n */\nexport interface GLAttributeDescriptor {\n /** Attribute name; resolved to a location via the effect when `index` is\n * omitted (`Effect.getAttributeLocationByName`). */\n name?: string;\n /** Explicit attribute location. When set, overrides the `name` lookup. */\n index?: number;\n /** Number of components, 1–4. */\n size: number;\n /** Byte offset of this attribute's first element within the buffer. Default 0. */\n offset?: number;\n /**\n * Per-instance vertex divisor. **Omitted/`undefined` → `1` (instanced)**,\n * matching Babylon's `bindInstancesBuffer`. Pass `0` explicitly for a\n * per-vertex attribute (e.g. the base mesh position).\n */\n divisor?: number;\n /** GL component type. Default `gl.FLOAT`. */\n type?: GLenum;\n /** Normalize fixed-point integer data to `[0,1]`/`[-1,1]`. Default `false`. */\n normalized?: boolean;\n}\n\n/* ──────────────────────────────── buffers ──────────────────────────────── */\n\n/**\n * Create a GPU vertex buffer from interleaved float data.\n *\n * @param engine - The engine.\n * @param data - The vertex data. Retained by reference for context-restore — do\n * not mutate it in place; use {@link updateVertexBuffer} to change contents.\n * @param dynamic - Hint that the buffer will be updated frequently\n * (`DYNAMIC_DRAW`). Default `false` (`STATIC_DRAW`).\n * @returns The new {@link GLVertexBuffer}.\n */\nexport function createVertexBuffer(engine: GLEngineContext, data: Float32Array, dynamic = false): GLVertexBuffer {\n const gl = engine.gl;\n const handle = gl.createBuffer();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (vertex buffer)\");\n }\n const vb: GLVertexBuffer = {\n handle,\n byteLength: data.byteLength,\n _data: data,\n _dynamic: dynamic,\n _engine: engine,\n _disposed: false,\n _deleteGpu: () => {},\n _restore: () => {},\n };\n vb._deleteGpu = (g: WebGL2RenderingContext): void => {\n g.deleteBuffer(vb.handle);\n };\n vb._restore = (target: GLEngineContext): void => {\n const g = target.gl;\n const fresh = g.createBuffer();\n if (fresh === null) {\n return;\n }\n vb.handle = fresh;\n bindArrayBufferRaw(target, fresh);\n g.bufferData(ARRAY_BUFFER, vb._data, vb._dynamic ? DYNAMIC_DRAW : STATIC_DRAW);\n };\n bindArrayBufferRaw(engine, handle);\n gl.bufferData(ARRAY_BUFFER, data, dynamic ? DYNAMIC_DRAW : STATIC_DRAW);\n engine._buffers.push(vb);\n return vb;\n}\n\n/**\n * Upload new contents into (part of) a vertex buffer via `bufferSubData`. A\n * full-buffer update from offset 0 also refreshes the retained CPU data used\n * for context-restore.\n *\n * @param vb - The vertex buffer to update.\n * @param data - The new float data.\n * @param dstByteOffset - Destination byte offset within the buffer. Default 0.\n */\nexport function updateVertexBuffer(vb: GLVertexBuffer, data: Float32Array, dstByteOffset = 0): void {\n const engine = vb._engine;\n if (engine._isLost || engine._disposed || vb._disposed) {\n return;\n }\n bindArrayBufferRaw(engine, vb.handle);\n engine.gl.bufferSubData(ARRAY_BUFFER, dstByteOffset, data);\n if (dstByteOffset === 0 && data.byteLength >= vb.byteLength) {\n vb._data = data;\n vb.byteLength = data.byteLength;\n }\n}\n\n/**\n * Create a GPU index buffer. `Uint16Array` → 16-bit indices, `Uint32Array` →\n * 32-bit. Binds the default VAO first so it never corrupts the quad / sprite\n * VAO element bindings.\n *\n * @param engine - The engine.\n * @param data - The index data. Retained by reference for context-restore.\n * @returns The new {@link GLIndexBuffer}.\n */\nexport function createIndexBuffer(engine: GLEngineContext, data: Uint16Array | Uint32Array): GLIndexBuffer {\n const gl = engine.gl;\n const handle = gl.createBuffer();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createBuffer returned null (index buffer)\");\n }\n const is32 = data instanceof Uint32Array;\n const ib: GLIndexBuffer = {\n handle,\n count: data.length,\n is32Bits: is32,\n _data: data,\n _engine: engine,\n _disposed: false,\n _deleteGpu: () => {},\n _restore: () => {},\n };\n ib._deleteGpu = (g: WebGL2RenderingContext): void => {\n g.deleteBuffer(ib.handle);\n };\n ib._restore = (target: GLEngineContext): void => {\n const g = target.gl;\n const fresh = g.createBuffer();\n if (fresh === null) {\n return;\n }\n ib.handle = fresh;\n bindDefaultVao(target);\n g.bindBuffer(ELEMENT_ARRAY_BUFFER, fresh);\n target._state.boundElementBuffer = fresh;\n g.bufferData(ELEMENT_ARRAY_BUFFER, ib._data, STATIC_DRAW);\n };\n bindDefaultVao(engine);\n gl.bindBuffer(ELEMENT_ARRAY_BUFFER, handle);\n engine._state.boundElementBuffer = handle;\n gl.bufferData(ELEMENT_ARRAY_BUFFER, data, STATIC_DRAW);\n engine._buffers.push(ib);\n return ib;\n}\n\n/** Dispose a vertex or index buffer (delete the GL buffer + unregister). Clears\n * the array/element-buffer cache slot if it pointed at this buffer. Idempotent. */\nexport function disposeBuffer(buffer: GLVertexBuffer | GLIndexBuffer): void {\n const engine = buffer._engine;\n if (buffer._disposed) {\n return;\n }\n buffer._disposed = true;\n const i = engine._buffers.indexOf(buffer);\n if (i !== -1) {\n engine._buffers.splice(i, 1);\n }\n const s = engine._state;\n if (!engine._isLost && !engine._disposed) {\n engine.gl.deleteBuffer(buffer.handle);\n }\n if (s.boundArrayBuffer === buffer.handle) {\n s.boundArrayBuffer = null;\n }\n if (s.boundElementBuffer === buffer.handle) {\n s.boundElementBuffer = null;\n }\n}\n\n/* ────────────────────────────── binding + draw ──────────────────────────── */\n\n/**\n * Bind an index buffer as the current element-array buffer (on the default\n * VAO). Cached. The lite-gl equivalent of Babylon's `_bindIndexBufferWithCache`.\n *\n * @param ib - The index buffer to bind.\n */\nexport function bindIndexBuffer(ib: GLIndexBuffer): void {\n const engine = ib._engine;\n if (engine._isLost || engine._disposed || ib._disposed) {\n return;\n }\n bindDefaultVao(engine);\n const s = engine._state;\n if (s.boundElementBuffer === ib.handle) {\n return;\n }\n engine.gl.bindBuffer(ELEMENT_ARRAY_BUFFER, ib.handle);\n s.boundElementBuffer = ib.handle;\n}\n\n/**\n * Configure vertex attributes from `vb`, reproducing Babylon's\n * `bindInstancesBuffer` exactly. For each descriptor: resolves the location\n * (explicit `index` or via the effect), enables the attribute array, issues\n * `vertexAttribPointer`, and sets the vertex divisor (`undefined → 1`). Each\n * instanced location (divisor ≠ 0) is tracked once so {@link unbindInstanceAttributes}\n * can reset its divisor afterwards; per-vertex locations already have divisor 0 and are\n * not tracked, so callers that never instance can rebind every frame without growth.\n *\n * `computeStride` controls the GL stride passed to `vertexAttribPointer`:\n * - `false` (default) → stride `0`: each attribute is independently tightly\n * packed. Combined with overlapping `offset`s this yields the \"sliding window\"\n * ShapeBuilder uses for distance-field tape buffers.\n * - `true` → stride = Σ(`size`·4 bytes): interleaved per-vertex/per-instance.\n *\n * Runs on the default (null) VAO — never corrupts the quad / sprite VAOs.\n * No-op on a lost/disposed context or before the effect is ready.\n *\n * @param vb - The buffer supplying the attribute data.\n * @param descriptors - The attribute layout.\n * @param effect - The effect whose attribute locations resolve unnamed indices.\n * @param computeStride - See above. Default `false`.\n */\nexport function bindAttributes(vb: GLVertexBuffer, descriptors: readonly GLAttributeDescriptor[], effect: GLEffect, computeStride = false): void {\n const engine = vb._engine;\n if (engine._isLost || engine._disposed || vb._disposed || !effect.isReady) {\n return;\n }\n const gl = engine.gl;\n const s = engine._state;\n bindDefaultVao(engine);\n bindArrayBufferRaw(engine, vb.handle);\n\n let stride = 0;\n if (computeStride) {\n for (let i = 0; i < descriptors.length; i++) {\n stride += (descriptors[i] as GLAttributeDescriptor).size * 4;\n }\n }\n\n for (let i = 0; i < descriptors.length; i++) {\n const d = descriptors[i] as GLAttributeDescriptor;\n const loc = d.index !== undefined ? d.index : d.name !== undefined ? getEffectAttributeLocation(effect, d.name) : -1;\n if (loc < 0) {\n continue;\n }\n if (!s.enabledAttribs[loc]) {\n gl.enableVertexAttribArray(loc);\n s.enabledAttribs[loc] = true;\n }\n gl.vertexAttribPointer(loc, d.size, d.type ?? FLOAT, d.normalized ?? false, stride, d.offset ?? 0);\n const divisor = d.divisor ?? 1;\n gl.vertexAttribDivisor(loc, divisor);\n if (divisor !== 0 && !s.instanceLocations.includes(loc)) {\n s.instanceLocations.push(loc);\n }\n }\n}\n\n/**\n * Reset the vertex divisor of every attribute touched by {@link bindAttributes}\n * back to 0 — the lite-gl equivalent of Babylon's `unbindInstanceAttributes`.\n * Call after an instanced draw so a following non-instanced draw is not skewed.\n * No-op on a lost/disposed context.\n *\n * @param engine - The engine.\n */\nexport function unbindInstanceAttributes(engine: GLEngineContext): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n const gl = engine.gl;\n const locs = engine._state.instanceLocations;\n for (let i = 0; i < locs.length; i++) {\n gl.vertexAttribDivisor(locs[i] as number, 0);\n }\n locs.length = 0;\n}\n\n/**\n * Draw indexed triangles from `ib` — the lite-gl equivalent of Babylon's\n * `drawElementsType` (triangle fill mode). When `instanceCount > 0` issues\n * `drawElementsInstanced`, otherwise `drawElements`. No-op on a lost/disposed\n * context or when no program is current.\n *\n * @param ib - The index buffer (also bound as a side-effect, cached).\n * @param indexCount - Number of indices to draw.\n * @param indexStart - First index offset (in indices, not bytes). Default 0.\n * @param instanceCount - Instance count for instanced draws. Default 0\n * (non-instanced).\n */\nexport function drawIndexed(ib: GLIndexBuffer, indexCount: number, indexStart = 0, instanceCount = 0): void {\n const engine = ib._engine;\n if (engine._isLost || engine._disposed || ib._disposed) {\n return;\n }\n if (engine._state.currentProgram === null) {\n return;\n }\n bindIndexBuffer(ib);\n const gl = engine.gl;\n const type = ib.is32Bits ? UNSIGNED_INT : UNSIGNED_SHORT;\n const byteOffset = indexStart * (ib.is32Bits ? 4 : 2);\n applyGLStates(engine);\n if (instanceCount > 0) {\n gl.drawElementsInstanced(TRIANGLES, indexCount, type, byteOffset, instanceCount);\n } else {\n gl.drawElements(TRIANGLES, indexCount, type, byteOffset);\n }\n}\n\n/* ────────────────────────── static mesh VAO ─────────────────────────────\n * The VAO-cached counterpart of the manual `bindAttributes` path above — Babylon's\n * `recordVertexArrayObject` / `_cachedVertexArrayObject` for STATIC meshes. A\n * `GLMeshVao` records the whole attribute layout (enable + pointer + divisor for\n * every attribute, across one or more vertex buffers) AND the index binding into a\n * single VAO ONCE. The per-frame draw is then just `bindVertexArray` +\n * `drawElements[Instanced]` — zero per-draw `vertexAttribPointer`/`vertexAttribDivisor`,\n * and no `unbindInstanceAttributes` (the VAO isolates the divisors from the default\n * VAO). Use this for fixed-layout meshes; keep `bindAttributes` for dynamic layouts\n * (e.g. ShapeBuilder's per-draw sliding-window tape buffers). */\n\n/** One vertex buffer + its attribute layout, for {@link createMeshVao}. */\nexport interface GLMeshVertexBuffer {\n /** The buffer supplying this group's attributes. */\n buffer: GLVertexBuffer;\n /** The attributes read from `buffer` (same shape as {@link bindAttributes}). */\n attributes: readonly GLAttributeDescriptor[];\n /** Stride mode (see {@link bindAttributes}): `false` (default) → stride `0`\n * per attribute; `true` → interleaved stride = Σ(`size`·4). */\n computeStride?: boolean;\n}\n\n/** A recorded Vertex Array Object capturing a static mesh's attribute layout +\n * index binding. Bind + draw it with {@link drawMesh} each frame — the GPU\n * replays the entire attribute setup from one `bindVertexArray`. Re-recorded\n * automatically on `webglcontextrestored`. */\nexport interface GLMeshVao {\n /** The live `WebGLVertexArrayObject`. Swapped on `webglcontextrestored`. */\n handle: WebGLVertexArrayObject;\n /** The engine that created (and owns) this VAO. Operations on it derive\n * their engine from here, so they take the VAO alone. @internal */\n _engine: GLEngineContext;\n /** @internal */\n _disposed: boolean;\n /** @internal The index buffer recorded into the VAO. */\n _indexBuffer: GLIndexBuffer;\n /** @internal Resolved attribute bindings, reused to re-record on restore. */\n _bindings: _ResolvedBinding[];\n /** @internal `webglcontextrestored` re-record hook. */\n _restore: () => void;\n}\n\n/** @internal A single attribute with its location resolved once at record time\n * (locations are stable across re-link via `bindAttribLocation`, so the VAO can\n * re-record on context-restore without the effect). */\ninterface _ResolvedAttr {\n loc: number;\n size: number;\n type: number;\n normalized: boolean;\n stride: number;\n offset: number;\n divisor: number;\n}\n\n/** @internal A vertex buffer + its resolved attributes. */\ninterface _ResolvedBinding {\n buffer: GLVertexBuffer;\n attrs: _ResolvedAttr[];\n}\n\n/**\n * Record a static mesh's attribute layout + index binding into a new VAO. The\n * effect MUST be ready (its attribute locations are resolved here, once). Returns\n * a {@link GLMeshVao} to draw with {@link drawMesh}.\n *\n * @param engine - The engine.\n * @param vertexBuffers - One or more buffers + their attribute layouts.\n * @param indexBuffer - The index buffer recorded into the VAO.\n * @param effect - The effect whose attribute locations resolve unnamed indices.\n * @returns The recorded {@link GLMeshVao}.\n */\nexport function createMeshVao(engine: GLEngineContext, vertexBuffers: readonly GLMeshVertexBuffer[], indexBuffer: GLIndexBuffer, effect: GLEffect): GLMeshVao {\n const gl = engine.gl;\n // The effect's attribute locations are resolved (once) below; an unready effect\n // would resolve every name to -1 → a silently-empty VAO. Fail fast — callers\n // must gate on isEffectReady (see scene10's first-ready-frame creation).\n if (!effect.isReady) {\n throw new Error(\"lite-gl: createMeshVao requires a ready effect (poll isEffectReady first)\");\n }\n const handle = gl.createVertexArray();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createVertexArray returned null (mesh VAO)\");\n }\n // Resolve every attribute location ONCE (stable across re-link), so a restore\n // re-record needs only the buffer handles, not the effect.\n const bindings: _ResolvedBinding[] = [];\n for (const vbb of vertexBuffers) {\n let stride = 0;\n if (vbb.computeStride) {\n for (let i = 0; i < vbb.attributes.length; i++) {\n stride += (vbb.attributes[i] as GLAttributeDescriptor).size * 4;\n }\n }\n const attrs: _ResolvedAttr[] = [];\n for (let i = 0; i < vbb.attributes.length; i++) {\n const d = vbb.attributes[i] as GLAttributeDescriptor;\n const loc = d.index !== undefined ? d.index : d.name !== undefined ? getEffectAttributeLocation(effect, d.name) : -1;\n if (loc < 0) {\n continue;\n }\n attrs.push({\n loc,\n size: d.size,\n type: d.type ?? FLOAT,\n normalized: d.normalized ?? false,\n stride,\n offset: d.offset ?? 0,\n divisor: d.divisor === undefined ? 1 : d.divisor,\n });\n }\n bindings.push({ buffer: vbb.buffer, attrs });\n }\n const vao: GLMeshVao = { handle, _engine: engine, _disposed: false, _indexBuffer: indexBuffer, _bindings: bindings, _restore: () => {} };\n vao._restore = (): void => {\n if (engine._isLost || engine._disposed || vao._disposed) {\n return;\n }\n const fresh = engine.gl.createVertexArray();\n if (fresh === null) {\n return;\n }\n vao.handle = fresh;\n recordMeshVao(engine, vao);\n };\n recordMeshVao(engine, vao);\n onContextRestored(engine, vao._restore);\n return vao;\n}\n\n/**\n * Bind a {@link GLMeshVao} (cached `gl.bindVertexArray`). Rarely called directly —\n * {@link drawMesh} binds it for you. Binding restores the VAO's recorded element\n * binding, so the element-buffer cache is updated in lock-step.\n *\n * @param vao - The mesh VAO to bind.\n */\nexport function bindMeshVao(vao: GLMeshVao): void {\n const engine = vao._engine;\n if (engine._isLost || engine._disposed || vao._disposed) {\n return;\n }\n const s = engine._state;\n if (s.boundVao === vao.handle) {\n return;\n }\n engine.gl.bindVertexArray(vao.handle);\n s.boundVao = vao.handle;\n s.boundElementBuffer = vao._indexBuffer.handle;\n}\n\n/**\n * Draw a static mesh recorded with {@link createMeshVao}: binds its VAO (cached),\n * flushes deferred GL state, and issues ONE `drawElements` (or\n * `drawElementsInstanced` when `instanceCount > 0`) over the VAO's full index\n * buffer. No per-draw attribute (re)binding. No-op on a lost/disposed context, a\n * disposed VAO, or when no program is current.\n *\n * @param vao - The mesh VAO to draw.\n * @param instanceCount - Instance count for instanced draws. Default 0 (non-instanced).\n */\nexport function drawMesh(vao: GLMeshVao, instanceCount = 0): void {\n const engine = vao._engine;\n if (engine._isLost || engine._disposed || vao._disposed) {\n return;\n }\n if (engine._state.currentProgram === null) {\n return;\n }\n bindMeshVao(vao);\n applyGLStates(engine);\n const ib = vao._indexBuffer;\n const gl = engine.gl;\n const type = ib.is32Bits ? UNSIGNED_INT : UNSIGNED_SHORT;\n if (instanceCount > 0) {\n gl.drawElementsInstanced(TRIANGLES, ib.count, type, 0, instanceCount);\n } else {\n gl.drawElements(TRIANGLES, ib.count, type, 0);\n }\n}\n\n/** Dispose a {@link GLMeshVao}: delete the VAO and unregister its restore hook.\n * Does NOT dispose the vertex/index buffers (the caller owns those). Idempotent. */\nexport function disposeMeshVao(vao: GLMeshVao): void {\n const engine = vao._engine;\n if (vao._disposed) {\n return;\n }\n vao._disposed = true;\n offContextRestored(engine, vao._restore);\n if (!engine._isLost && !engine._disposed) {\n const s = engine._state;\n engine.gl.deleteVertexArray(vao.handle);\n if (s.boundVao === vao.handle) {\n // Return to the default VAO so the cache stays coherent.\n engine.gl.bindVertexArray(null);\n s.boundVao = null;\n s.boundElementBuffer = null;\n }\n }\n}\n\n/** @internal Record `vao._bindings` + the index binding into `vao.handle`. Leaves\n * the default (null) VAO bound afterwards (so the mesh VAO is not left current),\n * forgetting the element-buffer cache. Touches neither `s.enabledAttribs` (those\n * track the DEFAULT VAO) nor the divisor reset — all of that lives in the VAO. */\nfunction recordMeshVao(engine: GLEngineContext, vao: GLMeshVao): void {\n const gl = engine.gl;\n const s = engine._state;\n gl.bindVertexArray(vao.handle);\n s.boundVao = vao.handle;\n for (const b of vao._bindings) {\n bindArrayBufferRaw(engine, b.buffer.handle);\n for (const a of b.attrs) {\n gl.enableVertexAttribArray(a.loc);\n gl.vertexAttribPointer(a.loc, a.size, a.type, a.normalized, a.stride, a.offset);\n gl.vertexAttribDivisor(a.loc, a.divisor);\n }\n }\n gl.bindBuffer(ELEMENT_ARRAY_BUFFER, vao._indexBuffer.handle);\n gl.bindVertexArray(null);\n s.boundVao = null;\n s.boundElementBuffer = null;\n}\n\n/* ──────────────────────────── internal helpers ──────────────────────────── */\n\n/** Bind the default (null) VAO if not already bound. The mesh path lives here so\n * it never disturbs the quad / sprite VAO state. Binding a VAO restores ITS\n * element-array binding, so the element-buffer cache is forgotten on the\n * switch (the next `bindIndexBuffer` re-binds). */\nfunction bindDefaultVao(engine: GLEngineContext): void {\n const s = engine._state;\n if (s.boundVao !== null) {\n engine.gl.bindVertexArray(null);\n s.boundVao = null;\n s.boundElementBuffer = null;\n }\n}\n\n/** Cached `gl.bindBuffer(ARRAY_BUFFER, …)`. ARRAY_BUFFER binding is global (not\n * VAO state), so this cache is coherent across VAO switches. */\nfunction bindArrayBufferRaw(engine: GLEngineContext, handle: WebGLBuffer): void {\n const s = engine._state;\n if (s.boundArrayBuffer === handle) {\n return;\n }\n engine.gl.bindBuffer(ARRAY_BUFFER, handle);\n s.boundArrayBuffer = handle;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babylonjs/lite-gl",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.1",
|
|
4
4
|
"description": "Function-based, tree-shakeable WebGL2 micro-engine for fullscreen effects, sprites and dynamic textures — the WebGL counterpart of @babylonjs/lite.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"babylon",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"babylonLiteRelease": {
|
|
38
|
-
"azureBuildId": "
|
|
39
|
-
"sourceVersion": "
|
|
38
|
+
"azureBuildId": "62048",
|
|
39
|
+
"sourceVersion": "d0ac56430d4a6d340e7550eec08a0188c7dec8a6"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/render-loop.d.ts
CHANGED
|
@@ -6,3 +6,17 @@ export declare function runRenderLoop(engine: GLEngineContext, fn: (dt: number)
|
|
|
6
6
|
/** Stop one (or all when omitted) registered callbacks. Cancels the rAF if
|
|
7
7
|
* no callbacks remain. */
|
|
8
8
|
export declare function stopRenderLoop(engine: GLEngineContext, fn?: (dt: number) => void): void;
|
|
9
|
+
/**
|
|
10
|
+
* Marks the start of a frame (Babylon `engine.beginFrame()`). `runRenderLoop`
|
|
11
|
+
* calls this automatically before its callbacks; call it yourself only when
|
|
12
|
+
* driving frames from your own `requestAnimationFrame` loop. A no-op unless a
|
|
13
|
+
* frame-level feature such as `captureGPUFrameTime` is enabled.
|
|
14
|
+
*/
|
|
15
|
+
export declare function beginFrame(engine: GLEngineContext): void;
|
|
16
|
+
/**
|
|
17
|
+
* Marks the end of a frame (Babylon `engine.endFrame()`). `runRenderLoop`
|
|
18
|
+
* calls this automatically after its callbacks; pair it with `beginFrame` in
|
|
19
|
+
* manual loops. A no-op unless a frame-level feature such as
|
|
20
|
+
* `captureGPUFrameTime` is enabled.
|
|
21
|
+
*/
|
|
22
|
+
export declare function endFrame(engine: GLEngineContext): void;
|
package/render-loop.js
CHANGED
|
@@ -34,6 +34,24 @@ export function stopRenderLoop(engine, fn) {
|
|
|
34
34
|
engine._rafId = 0;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Marks the start of a frame (Babylon `engine.beginFrame()`). `runRenderLoop`
|
|
39
|
+
* calls this automatically before its callbacks; call it yourself only when
|
|
40
|
+
* driving frames from your own `requestAnimationFrame` loop. A no-op unless a
|
|
41
|
+
* frame-level feature such as `captureGPUFrameTime` is enabled.
|
|
42
|
+
*/
|
|
43
|
+
export function beginFrame(engine) {
|
|
44
|
+
engine._frameHooks?._begin();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Marks the end of a frame (Babylon `engine.endFrame()`). `runRenderLoop`
|
|
48
|
+
* calls this automatically after its callbacks; pair it with `beginFrame` in
|
|
49
|
+
* manual loops. A no-op unless a frame-level feature such as
|
|
50
|
+
* `captureGPUFrameTime` is enabled.
|
|
51
|
+
*/
|
|
52
|
+
export function endFrame(engine) {
|
|
53
|
+
engine._frameHooks?._end();
|
|
54
|
+
}
|
|
37
55
|
function scheduleFrame(engine) {
|
|
38
56
|
engine._prevNow = performance.now();
|
|
39
57
|
engine._rafId = requestAnimationFrame((now) => tick(engine, now));
|
|
@@ -47,6 +65,10 @@ function tick(engine, now) {
|
|
|
47
65
|
engine._prevNow = now;
|
|
48
66
|
// Snapshot — a callback may call stopRenderLoop on itself or others.
|
|
49
67
|
const loops = engine._loops.slice();
|
|
68
|
+
// Inlined beginFrame / endFrame so unused exports tree-shake out. The
|
|
69
|
+
// snapshot pairs begin/end on the same hooks if a callback toggles capture.
|
|
70
|
+
const hooks = engine._frameHooks;
|
|
71
|
+
hooks?._begin();
|
|
50
72
|
for (const cb of loops) {
|
|
51
73
|
try {
|
|
52
74
|
cb(dt);
|
|
@@ -55,6 +77,7 @@ function tick(engine, now) {
|
|
|
55
77
|
console.error("lite-gl: render loop callback threw", err);
|
|
56
78
|
}
|
|
57
79
|
}
|
|
80
|
+
hooks?._end();
|
|
58
81
|
if (engine._loops.length > 0 && !engine._disposed && !engine._isLost) {
|
|
59
82
|
engine._rafId = requestAnimationFrame((nextNow) => tick(engine, nextNow));
|
|
60
83
|
}
|
package/render-loop.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-loop.js","sourceRoot":"","sources":["../src/render-loop.ts"],"names":[],"mappings":"AAEA;;8BAE8B;AAC9B,MAAM,UAAU,aAAa,CAAC,MAAuB,EAAE,EAAwB;IAC3E,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACnB,OAAO;IACX,CAAC;IACD,yEAAyE;IACzE,IAAI,MAAM,CAAC,cAAc,KAAK,IAAI,EAAE,CAAC;QACjC,MAAM,CAAC,cAAc,GAAG,aAAa,CAAC;IAC1C,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QACnC,OAAO;IACX,CAAC;IACD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACzC,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;AACL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AAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACpC,KAAK,MAAM,EAAE,IAAI,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC;YACD,EAAE,CAAC,EAAE,CAAC,CAAC;QACX,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,GAAG,CAAC,CAAC;QAC9D,CAAC;IACL,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACnE,MAAM,CAAC,MAAM,GAAG,qBAAqB,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC9E,CAAC;AACL,CAAC","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"]}
|
|
1
|
+
{"version":3,"file":"render-loop.js","sourceRoot":"","sources":["../src/render-loop.ts"],"names":[],"mappings":"AAEA;;8BAE8B;AAC9B,MAAM,UAAU,aAAa,CAAC,MAAuB,EAAE,EAAwB;IAC3E,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACnB,OAAO;IACX,CAAC;IACD,yEAAyE;IACzE,IAAI,MAAM,CAAC,cAAc,KAAK,IAAI,EAAE,CAAC;QACjC,MAAM,CAAC,cAAc,GAAG,aAAa,CAAC;IAC1C,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QACnC,OAAO;IACX,CAAC;IACD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACzC,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;AACL,CAAC;AAED;2BAC2B;AAC3B,MAAM,UAAU,cAAc,CAAC,MAAuB,EAAE,EAAyB;IAC7E,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;QACnB,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAC7B,CAAC;SAAM,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qEAAqE;IACrE,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACpC,sEAAsE;IACtE,4EAA4E;IAC5E,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC;IACjC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,MAAM,EAAE,IAAI,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC;YACD,EAAE,CAAC,EAAE,CAAC,CAAC;QACX,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,GAAG,CAAC,CAAC;QAC9D,CAAC;IACL,CAAC;IACD,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACnE,MAAM,CAAC,MAAM,GAAG,qBAAqB,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC9E,CAAC;AACL,CAAC","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\n/**\n * Marks the start of a frame (Babylon `engine.beginFrame()`). `runRenderLoop`\n * calls this automatically before its callbacks; call it yourself only when\n * driving frames from your own `requestAnimationFrame` loop. A no-op unless a\n * frame-level feature such as `captureGPUFrameTime` is enabled.\n */\nexport function beginFrame(engine: GLEngineContext): void {\n engine._frameHooks?._begin();\n}\n\n/**\n * Marks the end of a frame (Babylon `engine.endFrame()`). `runRenderLoop`\n * calls this automatically after its callbacks; pair it with `beginFrame` in\n * manual loops. A no-op unless a frame-level feature such as\n * `captureGPUFrameTime` is enabled.\n */\nexport function endFrame(engine: GLEngineContext): void {\n engine._frameHooks?._end();\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 // Inlined beginFrame / endFrame so unused exports tree-shake out. The\n // snapshot pairs begin/end on the same hooks if a callback toggles capture.\n const hooks = engine._frameHooks;\n hooks?._begin();\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 hooks?._end();\n if (engine._loops.length > 0 && !engine._disposed && !engine._isLost) {\n engine._rafId = requestAnimationFrame((nextNow) => tick(engine, nextNow));\n }\n}\n"]}
|