@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/effect.d.ts
CHANGED
|
@@ -64,45 +64,49 @@ export declare function createEffect(engine: GLEngineContext, options: GLEffectO
|
|
|
64
64
|
/** Poll the link state and, on first success, run finalization (uniform-
|
|
65
65
|
* location resolution + one-shot sampler-unit `uniform1i` assignment +
|
|
66
66
|
* `_onCompiled` callbacks). Returns `true` once the effect is usable. */
|
|
67
|
-
export declare function isEffectReady(
|
|
67
|
+
export declare function isEffectReady(effect: GLEffect): boolean;
|
|
68
68
|
/** Poll readiness once and return the recorded compile/link/restore diagnostic.
|
|
69
69
|
* Returns null while pending or when no failure has been recorded; this is
|
|
70
70
|
* not a readiness guarantee. Does not schedule polling. A successful restore
|
|
71
71
|
* allocation clears the previous diagnostic before the new link is checked. */
|
|
72
|
-
export declare function getEffectCompilationError(
|
|
72
|
+
export declare function getEffectCompilationError(effect: GLEffect): string | null;
|
|
73
73
|
/** Fires `cb` synchronously if the effect is already ready; otherwise queues
|
|
74
74
|
* it for the next finalization. Does not start polling: call `isEffectReady`
|
|
75
75
|
* from the render loop or opt into `waitForEffect`. */
|
|
76
|
-
export declare function executeWhenCompiled(
|
|
76
|
+
export declare function executeWhenCompiled(effect: GLEffect, cb: (e: GLEffect) => void): void;
|
|
77
77
|
/** Decrement the share count and, on the last release, delete the effect's
|
|
78
78
|
* program + shaders, unregister it from the context + cache, and clear the
|
|
79
79
|
* cached current-program if it pointed at this effect. A shared effect (still
|
|
80
80
|
* referenced by another `createEffect` caller) is kept alive. Call exactly ONCE
|
|
81
81
|
* per `createEffect` (each call decrements the ref count); safe (no-op) once the
|
|
82
82
|
* effect is fully torn down. */
|
|
83
|
-
export declare function disposeEffect(
|
|
84
|
-
/** Cached `gl.useProgram`.
|
|
85
|
-
|
|
83
|
+
export declare function disposeEffect(effect: GLEffect): void;
|
|
84
|
+
/** Cached `gl.useProgram`. Low-level: it does NOT check readiness, so poll
|
|
85
|
+
* {@link isEffectReady} first (binding a still-linking program can stall, and
|
|
86
|
+
* a failed one fails the next draw). `applyEffectWrapper` does that poll for
|
|
87
|
+
* wrappers. No-op when the effect is already current, disposed, or the
|
|
88
|
+
* context is lost/disposed. */
|
|
89
|
+
export declare function useEffect(effect: GLEffect): void;
|
|
86
90
|
/** Cached `gl.uniform1f`. No-op when context-lost, the effect isn't ready, the
|
|
87
91
|
* uniform is absent, or the value is unchanged since last upload. */
|
|
88
|
-
export declare function setEffectFloat(
|
|
92
|
+
export declare function setEffectFloat(effect: GLEffect, name: string, x: number): void;
|
|
89
93
|
/** Cached `gl.uniform2f`. No-op when context-lost, the effect isn't ready, the
|
|
90
94
|
* uniform is absent, or the value is unchanged since last upload. */
|
|
91
|
-
export declare function setEffectFloat2(
|
|
95
|
+
export declare function setEffectFloat2(effect: GLEffect, name: string, x: number, y: number): void;
|
|
92
96
|
/** Cached `gl.uniform3f`. No-op when context-lost, the effect isn't ready, the
|
|
93
97
|
* uniform is absent, or the value is unchanged since last upload. */
|
|
94
|
-
export declare function setEffectFloat3(
|
|
98
|
+
export declare function setEffectFloat3(effect: GLEffect, name: string, x: number, y: number, z: number): void;
|
|
95
99
|
/** Cached `gl.uniform4f`. No-op when context-lost, the effect isn't ready, the
|
|
96
100
|
* uniform is absent, or the value is unchanged since last upload. */
|
|
97
|
-
export declare function setEffectFloat4(
|
|
101
|
+
export declare function setEffectFloat4(effect: GLEffect, name: string, x: number, y: number, z: number, w: number): void;
|
|
98
102
|
/** Cached `gl.uniform3f` from an r/g/b color object. Delegates to `setEffectFloat3`. */
|
|
99
|
-
export declare function setEffectColor3(
|
|
103
|
+
export declare function setEffectColor3(effect: GLEffect, name: string, c: {
|
|
100
104
|
r: number;
|
|
101
105
|
g: number;
|
|
102
106
|
b: number;
|
|
103
107
|
}): void;
|
|
104
108
|
/** Cached `gl.uniform4f` from an r/g/b/a color object. Delegates to `setEffectFloat4`. */
|
|
105
|
-
export declare function setEffectColor4(
|
|
109
|
+
export declare function setEffectColor4(effect: GLEffect, name: string, c: {
|
|
106
110
|
r: number;
|
|
107
111
|
g: number;
|
|
108
112
|
b: number;
|
|
@@ -110,7 +114,7 @@ export declare function setEffectColor4(engine: GLEngineContext, effect: GLEffec
|
|
|
110
114
|
}): void;
|
|
111
115
|
/** Cached `gl.uniform2f` from an `{x,y}` vector object — the lite-gl equivalent
|
|
112
116
|
* of Babylon's `Effect.setVector2`. Delegates to `setEffectFloat2`. */
|
|
113
|
-
export declare function setEffectVector2(
|
|
117
|
+
export declare function setEffectVector2(effect: GLEffect, name: string, v: {
|
|
114
118
|
x: number;
|
|
115
119
|
y: number;
|
|
116
120
|
}): void;
|
|
@@ -119,7 +123,7 @@ export declare function setEffectVector2(engine: GLEngineContext, effect: GLEffe
|
|
|
119
123
|
* `setEffectFloat4` (lite-gl never premultiplies in the uniform setters, so
|
|
120
124
|
* this matches `setEffectColor4`; the distinct name eases the ShapeBuilder
|
|
121
125
|
* port). */
|
|
122
|
-
export declare function setEffectDirectColor4(
|
|
126
|
+
export declare function setEffectDirectColor4(effect: GLEffect, name: string, c: {
|
|
123
127
|
r: number;
|
|
124
128
|
g: number;
|
|
125
129
|
b: number;
|
|
@@ -127,23 +131,23 @@ export declare function setEffectDirectColor4(engine: GLEngineContext, effect: G
|
|
|
127
131
|
}): void;
|
|
128
132
|
/** Cached `gl.uniform1i`. No-op when context-lost, the effect isn't ready, the
|
|
129
133
|
* uniform is absent, or the value is unchanged since last upload. */
|
|
130
|
-
export declare function setEffectInt(
|
|
134
|
+
export declare function setEffectInt(effect: GLEffect, name: string, x: number): void;
|
|
131
135
|
/** `gl.uniformMatrix4fv` from a column-major 4×4 matrix — the lite-gl
|
|
132
136
|
* equivalent of Babylon's `Effect.setMatrix`. Not value-cached. */
|
|
133
|
-
export declare function setEffectMatrix(
|
|
137
|
+
export declare function setEffectMatrix(effect: GLEffect, name: string, matrix: Float32Array | number[]): void;
|
|
134
138
|
/** `gl.uniformMatrix3fv` from a column-major 3×3 matrix — the lite-gl
|
|
135
139
|
* equivalent of Babylon's `Effect.setMatrix3x3`. Not value-cached. */
|
|
136
|
-
export declare function setEffectMatrix3x3(
|
|
140
|
+
export declare function setEffectMatrix3x3(effect: GLEffect, name: string, matrix: Float32Array | number[]): void;
|
|
137
141
|
/** `gl.uniform1fv` — a flat float array (`Effect.setFloatArray` / `setArray`).
|
|
138
142
|
* Not value-cached. */
|
|
139
|
-
export declare function setEffectFloatArray(
|
|
143
|
+
export declare function setEffectFloatArray(effect: GLEffect, name: string, array: Float32Array | number[]): void;
|
|
140
144
|
/** `gl.uniform4fv` — an array of `vec4`s (`Effect.setFloatArray4` / `setArray4`).
|
|
141
145
|
* Not value-cached. */
|
|
142
|
-
export declare function setEffectFloatArray4(
|
|
146
|
+
export declare function setEffectFloatArray4(effect: GLEffect, name: string, array: Float32Array | number[]): void;
|
|
143
147
|
/** `gl.uniform1iv` — a flat int array (`Effect.setIntArray`). Not value-cached. */
|
|
144
|
-
export declare function setEffectIntArray(
|
|
148
|
+
export declare function setEffectIntArray(effect: GLEffect, name: string, array: Int32Array | number[]): void;
|
|
145
149
|
/** Bind a texture to the sampler's pre-assigned unit, or pass `null` to unbind
|
|
146
150
|
* that unit (§4.4). NO `gl.uniform1i` is issued — that was done exactly once per program lifetime during
|
|
147
151
|
* finalization. This is the key win over Babylon's `Effect.setTexture` which
|
|
148
152
|
* re-issues the sampler binding on every call. */
|
|
149
|
-
export declare function setEffectTexture(
|
|
153
|
+
export declare function setEffectTexture(effect: GLEffect, samplerName: string, tex: GLTexture | null): void;
|
package/effect.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { compileShader, getLinkError, isLinkComplete, linkProgram } from "./shader.js";
|
|
2
|
-
import {
|
|
2
|
+
import { bindTextureRaw } from "./texture.js";
|
|
3
3
|
/** Submit compilation + linking without querying their results. `isReady`
|
|
4
4
|
* starts false; poll `isEffectReady` or opt into `waitForEffect` to finalize.
|
|
5
5
|
* Allocation failures throw synchronously. Shader syntax/link errors are
|
|
@@ -37,6 +37,7 @@ export function createEffect(engine, options) {
|
|
|
37
37
|
_lastVec: {},
|
|
38
38
|
_lastI1: {},
|
|
39
39
|
isReady: false,
|
|
40
|
+
_engine: engine,
|
|
40
41
|
_compileError: null,
|
|
41
42
|
_disposed: false,
|
|
42
43
|
_refCount: 1,
|
|
@@ -87,33 +88,32 @@ function compileEffectProgram(gl, options, attribs) {
|
|
|
87
88
|
/** Poll the link state and, on first success, run finalization (uniform-
|
|
88
89
|
* location resolution + one-shot sampler-unit `uniform1i` assignment +
|
|
89
90
|
* `_onCompiled` callbacks). Returns `true` once the effect is usable. */
|
|
90
|
-
export function isEffectReady(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
recordCompilationError(effect, linkErr);
|
|
106
|
-
return false;
|
|
91
|
+
export function isEffectReady(effect) {
|
|
92
|
+
const engine = effect._engine;
|
|
93
|
+
if (!effect.isReady &&
|
|
94
|
+
!effect._disposed &&
|
|
95
|
+
!engine._isLost &&
|
|
96
|
+
!engine._disposed &&
|
|
97
|
+
effect._compileError === null &&
|
|
98
|
+
isLinkComplete(engine.gl, effect.program, engine.caps.parallelShaderCompile)) {
|
|
99
|
+
const linkErr = getLinkError(engine.gl, effect.program, effect._vs, effect._fs);
|
|
100
|
+
if (linkErr !== null) {
|
|
101
|
+
recordCompilationError(effect, linkErr);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
finalizeEffect(engine, effect);
|
|
105
|
+
}
|
|
107
106
|
}
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
// Read back rather than returning `true` after finalization: a ready
|
|
108
|
+
// callback may have disposed the effect or engine (or lost the context).
|
|
109
|
+
return effect.isReady;
|
|
110
110
|
}
|
|
111
111
|
/** Poll readiness once and return the recorded compile/link/restore diagnostic.
|
|
112
112
|
* Returns null while pending or when no failure has been recorded; this is
|
|
113
113
|
* not a readiness guarantee. Does not schedule polling. A successful restore
|
|
114
114
|
* allocation clears the previous diagnostic before the new link is checked. */
|
|
115
|
-
export function getEffectCompilationError(
|
|
116
|
-
isEffectReady(
|
|
115
|
+
export function getEffectCompilationError(effect) {
|
|
116
|
+
isEffectReady(effect);
|
|
117
117
|
return effect._compileError;
|
|
118
118
|
}
|
|
119
119
|
function recordCompilationError(effect, error) {
|
|
@@ -135,7 +135,7 @@ function finalizeEffect(engine, effect) {
|
|
|
135
135
|
}
|
|
136
136
|
// Switch to this program via the cached helper so _state.currentProgram
|
|
137
137
|
// stays consistent — no raw gl.useProgram outside useEffect.
|
|
138
|
-
useEffect(
|
|
138
|
+
useEffect(effect);
|
|
139
139
|
let unit = 0;
|
|
140
140
|
for (const name of effect.options.samplerNames) {
|
|
141
141
|
const loc = gl.getUniformLocation(program, name);
|
|
@@ -162,8 +162,8 @@ function finalizeEffect(engine, effect) {
|
|
|
162
162
|
/** Fires `cb` synchronously if the effect is already ready; otherwise queues
|
|
163
163
|
* it for the next finalization. Does not start polling: call `isEffectReady`
|
|
164
164
|
* from the render loop or opt into `waitForEffect`. */
|
|
165
|
-
export function executeWhenCompiled(
|
|
166
|
-
if (isEffectReady(
|
|
165
|
+
export function executeWhenCompiled(effect, cb) {
|
|
166
|
+
if (isEffectReady(effect)) {
|
|
167
167
|
cb(effect);
|
|
168
168
|
return;
|
|
169
169
|
}
|
|
@@ -175,7 +175,8 @@ export function executeWhenCompiled(engine, effect, cb) {
|
|
|
175
175
|
* referenced by another `createEffect` caller) is kept alive. Call exactly ONCE
|
|
176
176
|
* per `createEffect` (each call decrements the ref count); safe (no-op) once the
|
|
177
177
|
* effect is fully torn down. */
|
|
178
|
-
export function disposeEffect(
|
|
178
|
+
export function disposeEffect(effect) {
|
|
179
|
+
const engine = effect._engine;
|
|
179
180
|
if (effect._disposed) {
|
|
180
181
|
return;
|
|
181
182
|
}
|
|
@@ -199,8 +200,13 @@ export function disposeEffect(engine, effect) {
|
|
|
199
200
|
}
|
|
200
201
|
effect._onCompiled.length = 0;
|
|
201
202
|
}
|
|
202
|
-
/** Cached `gl.useProgram`.
|
|
203
|
-
|
|
203
|
+
/** Cached `gl.useProgram`. Low-level: it does NOT check readiness, so poll
|
|
204
|
+
* {@link isEffectReady} first (binding a still-linking program can stall, and
|
|
205
|
+
* a failed one fails the next draw). `applyEffectWrapper` does that poll for
|
|
206
|
+
* wrappers. No-op when the effect is already current, disposed, or the
|
|
207
|
+
* context is lost/disposed. */
|
|
208
|
+
export function useEffect(effect) {
|
|
209
|
+
const engine = effect._engine;
|
|
204
210
|
if (engine._isLost || engine._disposed || effect._disposed) {
|
|
205
211
|
return;
|
|
206
212
|
}
|
|
@@ -224,7 +230,8 @@ export function useEffect(engine, effect) {
|
|
|
224
230
|
*/
|
|
225
231
|
/** Cached `gl.uniform1f`. No-op when context-lost, the effect isn't ready, the
|
|
226
232
|
* uniform is absent, or the value is unchanged since last upload. */
|
|
227
|
-
export function setEffectFloat(
|
|
233
|
+
export function setEffectFloat(effect, name, x) {
|
|
234
|
+
const engine = effect._engine;
|
|
228
235
|
if (engine._isLost || !effect.isReady) {
|
|
229
236
|
return;
|
|
230
237
|
}
|
|
@@ -240,7 +247,8 @@ export function setEffectFloat(engine, effect, name, x) {
|
|
|
240
247
|
}
|
|
241
248
|
/** Cached `gl.uniform2f`. No-op when context-lost, the effect isn't ready, the
|
|
242
249
|
* uniform is absent, or the value is unchanged since last upload. */
|
|
243
|
-
export function setEffectFloat2(
|
|
250
|
+
export function setEffectFloat2(effect, name, x, y) {
|
|
251
|
+
const engine = effect._engine;
|
|
244
252
|
if (engine._isLost || !effect.isReady) {
|
|
245
253
|
return;
|
|
246
254
|
}
|
|
@@ -264,7 +272,8 @@ export function setEffectFloat2(engine, effect, name, x, y) {
|
|
|
264
272
|
}
|
|
265
273
|
/** Cached `gl.uniform3f`. No-op when context-lost, the effect isn't ready, the
|
|
266
274
|
* uniform is absent, or the value is unchanged since last upload. */
|
|
267
|
-
export function setEffectFloat3(
|
|
275
|
+
export function setEffectFloat3(effect, name, x, y, z) {
|
|
276
|
+
const engine = effect._engine;
|
|
268
277
|
if (engine._isLost || !effect.isReady) {
|
|
269
278
|
return;
|
|
270
279
|
}
|
|
@@ -289,7 +298,8 @@ export function setEffectFloat3(engine, effect, name, x, y, z) {
|
|
|
289
298
|
}
|
|
290
299
|
/** Cached `gl.uniform4f`. No-op when context-lost, the effect isn't ready, the
|
|
291
300
|
* uniform is absent, or the value is unchanged since last upload. */
|
|
292
|
-
export function setEffectFloat4(
|
|
301
|
+
export function setEffectFloat4(effect, name, x, y, z, w) {
|
|
302
|
+
const engine = effect._engine;
|
|
293
303
|
if (engine._isLost || !effect.isReady) {
|
|
294
304
|
return;
|
|
295
305
|
}
|
|
@@ -314,29 +324,30 @@ export function setEffectFloat4(engine, effect, name, x, y, z, w) {
|
|
|
314
324
|
engine.gl.uniform4f(loc, x, y, z, w);
|
|
315
325
|
}
|
|
316
326
|
/** Cached `gl.uniform3f` from an r/g/b color object. Delegates to `setEffectFloat3`. */
|
|
317
|
-
export function setEffectColor3(
|
|
318
|
-
setEffectFloat3(
|
|
327
|
+
export function setEffectColor3(effect, name, c) {
|
|
328
|
+
setEffectFloat3(effect, name, c.r, c.g, c.b);
|
|
319
329
|
}
|
|
320
330
|
/** Cached `gl.uniform4f` from an r/g/b/a color object. Delegates to `setEffectFloat4`. */
|
|
321
|
-
export function setEffectColor4(
|
|
322
|
-
setEffectFloat4(
|
|
331
|
+
export function setEffectColor4(effect, name, c) {
|
|
332
|
+
setEffectFloat4(effect, name, c.r, c.g, c.b, c.a);
|
|
323
333
|
}
|
|
324
334
|
/** Cached `gl.uniform2f` from an `{x,y}` vector object — the lite-gl equivalent
|
|
325
335
|
* of Babylon's `Effect.setVector2`. Delegates to `setEffectFloat2`. */
|
|
326
|
-
export function setEffectVector2(
|
|
327
|
-
setEffectFloat2(
|
|
336
|
+
export function setEffectVector2(effect, name, v) {
|
|
337
|
+
setEffectFloat2(effect, name, v.x, v.y);
|
|
328
338
|
}
|
|
329
339
|
/** Cached `gl.uniform4f` from an r/g/b/a color WITHOUT premultiplication — the
|
|
330
340
|
* lite-gl equivalent of Babylon's `Effect.setDirectColor4`. Delegates to
|
|
331
341
|
* `setEffectFloat4` (lite-gl never premultiplies in the uniform setters, so
|
|
332
342
|
* this matches `setEffectColor4`; the distinct name eases the ShapeBuilder
|
|
333
343
|
* port). */
|
|
334
|
-
export function setEffectDirectColor4(
|
|
335
|
-
setEffectFloat4(
|
|
344
|
+
export function setEffectDirectColor4(effect, name, c) {
|
|
345
|
+
setEffectFloat4(effect, name, c.r, c.g, c.b, c.a);
|
|
336
346
|
}
|
|
337
347
|
/** Cached `gl.uniform1i`. No-op when context-lost, the effect isn't ready, the
|
|
338
348
|
* uniform is absent, or the value is unchanged since last upload. */
|
|
339
|
-
export function setEffectInt(
|
|
349
|
+
export function setEffectInt(effect, name, x) {
|
|
350
|
+
const engine = effect._engine;
|
|
340
351
|
if (engine._isLost || !effect.isReady) {
|
|
341
352
|
return;
|
|
342
353
|
}
|
|
@@ -359,7 +370,8 @@ export function setEffectInt(engine, effect, name, x) {
|
|
|
359
370
|
* 4×4 matrix setter for any future mesh consumer. */
|
|
360
371
|
/** `gl.uniformMatrix4fv` from a column-major 4×4 matrix — the lite-gl
|
|
361
372
|
* equivalent of Babylon's `Effect.setMatrix`. Not value-cached. */
|
|
362
|
-
export function setEffectMatrix(
|
|
373
|
+
export function setEffectMatrix(effect, name, matrix) {
|
|
374
|
+
const engine = effect._engine;
|
|
363
375
|
if (engine._isLost || !effect.isReady) {
|
|
364
376
|
return;
|
|
365
377
|
}
|
|
@@ -371,7 +383,8 @@ export function setEffectMatrix(engine, effect, name, matrix) {
|
|
|
371
383
|
}
|
|
372
384
|
/** `gl.uniformMatrix3fv` from a column-major 3×3 matrix — the lite-gl
|
|
373
385
|
* equivalent of Babylon's `Effect.setMatrix3x3`. Not value-cached. */
|
|
374
|
-
export function setEffectMatrix3x3(
|
|
386
|
+
export function setEffectMatrix3x3(effect, name, matrix) {
|
|
387
|
+
const engine = effect._engine;
|
|
375
388
|
if (engine._isLost || !effect.isReady) {
|
|
376
389
|
return;
|
|
377
390
|
}
|
|
@@ -383,7 +396,8 @@ export function setEffectMatrix3x3(engine, effect, name, matrix) {
|
|
|
383
396
|
}
|
|
384
397
|
/** `gl.uniform1fv` — a flat float array (`Effect.setFloatArray` / `setArray`).
|
|
385
398
|
* Not value-cached. */
|
|
386
|
-
export function setEffectFloatArray(
|
|
399
|
+
export function setEffectFloatArray(effect, name, array) {
|
|
400
|
+
const engine = effect._engine;
|
|
387
401
|
if (engine._isLost || !effect.isReady) {
|
|
388
402
|
return;
|
|
389
403
|
}
|
|
@@ -395,7 +409,8 @@ export function setEffectFloatArray(engine, effect, name, array) {
|
|
|
395
409
|
}
|
|
396
410
|
/** `gl.uniform4fv` — an array of `vec4`s (`Effect.setFloatArray4` / `setArray4`).
|
|
397
411
|
* Not value-cached. */
|
|
398
|
-
export function setEffectFloatArray4(
|
|
412
|
+
export function setEffectFloatArray4(effect, name, array) {
|
|
413
|
+
const engine = effect._engine;
|
|
399
414
|
if (engine._isLost || !effect.isReady) {
|
|
400
415
|
return;
|
|
401
416
|
}
|
|
@@ -406,7 +421,8 @@ export function setEffectFloatArray4(engine, effect, name, array) {
|
|
|
406
421
|
engine.gl.uniform4fv(loc, array);
|
|
407
422
|
}
|
|
408
423
|
/** `gl.uniform1iv` — a flat int array (`Effect.setIntArray`). Not value-cached. */
|
|
409
|
-
export function setEffectIntArray(
|
|
424
|
+
export function setEffectIntArray(effect, name, array) {
|
|
425
|
+
const engine = effect._engine;
|
|
410
426
|
if (engine._isLost || !effect.isReady) {
|
|
411
427
|
return;
|
|
412
428
|
}
|
|
@@ -420,15 +436,16 @@ export function setEffectIntArray(engine, effect, name, array) {
|
|
|
420
436
|
* that unit (§4.4). NO `gl.uniform1i` is issued — that was done exactly once per program lifetime during
|
|
421
437
|
* finalization. This is the key win over Babylon's `Effect.setTexture` which
|
|
422
438
|
* re-issues the sampler binding on every call. */
|
|
423
|
-
export function setEffectTexture(
|
|
424
|
-
|
|
439
|
+
export function setEffectTexture(effect, samplerName, tex) {
|
|
440
|
+
const engine = effect._engine;
|
|
441
|
+
if (engine._isLost || engine._disposed || !effect.isReady) {
|
|
425
442
|
return;
|
|
426
443
|
}
|
|
427
444
|
const unit = effect.samplerUnits[samplerName];
|
|
428
|
-
if (unit === undefined) {
|
|
445
|
+
if (unit === undefined || tex?._disposed) {
|
|
429
446
|
return;
|
|
430
447
|
}
|
|
431
|
-
|
|
448
|
+
bindTextureRaw(engine, unit, tex === null ? null : tex.handle);
|
|
432
449
|
}
|
|
433
450
|
/** Resolve (and cache) a vertex-attribute location by name — the lite-gl
|
|
434
451
|
* equivalent of Babylon's `Effect.getAttributeLocationByName`. Locations for
|
|
@@ -436,7 +453,8 @@ export function setEffectTexture(engine, effect, samplerName, tex) {
|
|
|
436
453
|
* the mesh / instancing path, where attribute names are not declared up-front.
|
|
437
454
|
* Returns `-1` when the attribute is absent (matching `gl.getAttribLocation`).
|
|
438
455
|
* @internal */
|
|
439
|
-
export function getEffectAttributeLocation(
|
|
456
|
+
export function getEffectAttributeLocation(effect, name) {
|
|
457
|
+
const engine = effect._engine;
|
|
440
458
|
const cached = effect.attributeLocations[name];
|
|
441
459
|
if (cached !== undefined) {
|
|
442
460
|
return cached;
|
package/effect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect.js","sourceRoot":"","sources":["../src/effect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAA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IAAI,KAAK,SAAS,EAAE,CAAC;YACrB,SAAS;QACb,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YACrE,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;IACL,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\nimport { compileShader, getLinkError, isLinkComplete, linkProgram } from \"./shader.js\";\nimport { bindTexture, type GLTexture } from \"./texture.js\";\n\n/** Inputs to `createEffect`: shader sources plus the uniform, sampler and\n * attribute names whose locations are resolved during readiness finalization. */\nexport interface GLEffectOptions {\n /** Human-readable label, surfaced in compile/link error messages. */\n name: string;\n /** GLSL ES 3.00 source, ready for `gl.shaderSource`. */\n vertexSource: string;\n /** GLSL ES 3.00 source, ready for `gl.shaderSource`. */\n fragmentSource: string;\n /** Declared uniform names. Locations are resolved during readiness\n * finalization. Names not declared here are legal but allocate cache\n * slots lazily on first setter use. */\n uniformNames: readonly string[];\n /** Declared sampler names, in unit-assignment order. Each gets a fixed\n * texture unit assigned during readiness finalization, and\n * `gl.uniform1i(loc, unit)` is called exactly once per program lifetime\n * (re-run after `webglcontextrestored`). */\n samplerNames: readonly string[];\n /** Default `[\"position\"]`. The first attribute is bound to location 0 via\n * `gl.bindAttribLocation(program, 0, name)` BEFORE link, so the shared\n * fullscreen-quad VAO always feeds the same location. */\n attributeNames?: readonly string[];\n /** Optional `#define` block. Each unique `defines` string must be paired\n * with the same vertex/fragment source via a separate `createEffect` call —\n * the package does NOT cache compiled variants. */\n defines?: string;\n}\n\n/** A compiled + linked shader program with cached uniform, sampler and\n * attribute locations. Created by `createEffect`; most fields are managed\n * internally — drive it via `isEffectReady` / `useEffect` / the `setEffect*`\n * setters rather than mutating it directly. */\nexport interface GLEffect {\n /** The `name` from the originating `GLEffectOptions`. */\n readonly name: string;\n /** The options this effect was created from (retained for context-restore). */\n readonly options: GLEffectOptions;\n /** The live `WebGLProgram`. Swapped for a fresh handle after context-restore. */\n program: WebGLProgram;\n /** @internal */\n _vs: WebGLShader;\n /** @internal */\n _fs: WebGLShader;\n /** Resolved during readiness finalization. Missing names map to `null` —\n * setters with a `null` location are silent no-ops (matches Babylon). */\n uniformLocations: { [name: string]: WebGLUniformLocation | null };\n /** Fixed unit assignment for declared samplers, index into\n * `_state.boundTextures`. */\n samplerUnits: { [name: string]: number };\n /**\n * True once `gl.uniform1i(samplerLoc, unit)` has been issued for every\n * declared sampler. Cleared on context-lost so finalization re-runs.\n * @internal\n */\n _samplersAssigned: boolean;\n /** Resolved attribute locations, keyed by attribute name. */\n attributeLocations: { [name: string]: number };\n /**\n * Last-UPLOADED scalar floats. A setter that skips the upload must NOT\n * update this — otherwise a later real set with the same value would\n * incorrectly elide and the GPU would keep stale data.\n * @internal\n */\n readonly _lastF1: { [name: string]: number };\n /**\n * Last-UPLOADED vector floats (vec2/vec3/vec4). Plain `number[]` (NOT\n * `Float32Array`) so values like `0.1` compare equal across frames.\n * @internal\n */\n readonly _lastVec: { [name: string]: number[] };\n /** @internal */\n readonly _lastI1: { [name: string]: number };\n /** True once the program has linked and finalization has run; the\n * `setEffect*` setters are no-ops until then. Poll `isEffectReady` to advance it. */\n isReady: boolean;\n /** @internal */\n _compileError: string | null;\n /** @internal */\n _disposed: boolean;\n /**\n * Number of live `createEffect` callers sharing this effect (and its one\n * `WebGLProgram`). `createEffect` returns the cached effect and bumps this\n * when an identical descriptor is requested; `disposeEffect` decrements it\n * and only tears the program down when it reaches 0.\n * @internal\n */\n _refCount: number;\n /**\n * The `_effectCache` key this effect was stored under (the source\n * descriptor). Used by `disposeEffect` to evict the cache entry at refcount\n * 0.\n * @internal\n */\n _cacheKey: string;\n /**\n * Callbacks fired exactly once on the first transition to ready.\n * @internal\n */\n readonly _onCompiled: ((effect: GLEffect) => void)[];\n /**\n * Replay closure for context-restore. Re-compiles + relinks into a fresh\n * `program` field. Finalization happens lazily on the next `isEffectReady`\n * poll.\n * @internal\n */\n _restore: (engine: GLEngineContext) => void;\n}\n\n/** Submit compilation + linking without querying their results. `isReady`\n * starts false; poll `isEffectReady` or opt into `waitForEffect` to finalize.\n * Allocation failures throw synchronously. Shader syntax/link errors are\n * recorded during polling and exposed by `getEffectCompilationError`. */\nexport function createEffect(engine: GLEngineContext, options: GLEffectOptions): GLEffect {\n const attribs = options.attributeNames ?? [\"position\"];\n const gl = engine.gl;\n\n // Per-engine cache keyed by the source descriptor. Identical descriptors\n // share ONE GLEffect (and thus one WebGLProgram), so `useEffect`'s\n // current-program cache can elide redundant `gl.useProgram` across the\n // consumers. The key covers every input that affects the program or its\n // readiness finalization, joined by a NUL separator (cannot appear in GLSL).\n const cacheKey = [options.vertexSource, options.fragmentSource, options.defines ?? \"\", attribs.join(\",\"), options.uniformNames.join(\",\"), options.samplerNames.join(\",\")].join(\n \"\\u0000\"\n );\n const cached = engine._effectCache.get(cacheKey);\n if (cached !== undefined && !cached._disposed) {\n cached._refCount++;\n return cached;\n }\n\n const compiled = compileEffectProgram(gl, options, attribs);\n if (typeof compiled === \"string\") {\n throw new Error(`lite-gl: ${options.name} ${compiled}`);\n }\n const { vs, fs, program } = compiled;\n\n const effect: GLEffect = {\n name: options.name,\n options,\n program,\n _vs: vs,\n _fs: fs,\n uniformLocations: {},\n samplerUnits: {},\n _samplersAssigned: false,\n attributeLocations: {},\n _lastF1: {},\n _lastVec: {},\n _lastI1: {},\n isReady: false,\n _compileError: null,\n _disposed: false,\n _refCount: 1,\n _cacheKey: cacheKey,\n _onCompiled: [],\n _restore: () => {},\n };\n\n effect._restore = (target: GLEngineContext): void => {\n const restored = compileEffectProgram(target.gl, options, attribs);\n if (typeof restored === \"string\") {\n recordCompilationError(effect, `context-restore: ${restored}`);\n return;\n }\n effect.program = restored.program;\n effect._vs = restored.vs;\n effect._fs = restored.fs;\n effect.isReady = false;\n effect._samplersAssigned = false;\n effect.uniformLocations = {};\n effect.attributeLocations = {};\n effect._compileError = null;\n };\n\n engine._effects.push(effect);\n engine._effectCache.set(cacheKey, effect);\n return effect;\n}\n\n/** Shader/program handles allocated as one unit on creation and restoration. */\ninterface EffectProgram {\n vs: WebGLShader;\n fs: WebGLShader;\n program: WebGLProgram;\n}\n\n/** Share allocation and partial-failure cleanup between initial creation and\n * context restoration. Returns a diagnostic on allocation failure; compile\n * and link results are deliberately left to readiness polling. */\nfunction compileEffectProgram(gl: WebGL2RenderingContext, options: GLEffectOptions, attribs: readonly string[]): EffectProgram | string {\n const vs = compileShader(gl, applyDefines(options.vertexSource, options.defines), gl.VERTEX_SHADER);\n if (vs === null) {\n return \"vertex shader allocation failed\";\n }\n const fs = compileShader(gl, applyDefines(options.fragmentSource, options.defines), gl.FRAGMENT_SHADER);\n if (fs === null) {\n gl.deleteShader(vs);\n return \"fragment shader allocation failed\";\n }\n const program = linkProgram(gl, vs, fs, attribs);\n if (program === null) {\n gl.deleteShader(vs);\n gl.deleteShader(fs);\n return \"program allocation failed\";\n }\n return { vs, fs, program };\n}\n\n/** Poll the link state and, on first success, run finalization (uniform-\n * location resolution + one-shot sampler-unit `uniform1i` assignment +\n * `_onCompiled` callbacks). Returns `true` once the effect is usable. */\nexport function isEffectReady(engine: GLEngineContext, effect: GLEffect): boolean {\n if (effect.isReady) {\n return true;\n }\n if (effect._disposed || engine._isLost || engine._disposed) {\n return false;\n }\n if (effect._compileError !== null) {\n return false;\n }\n if (!isLinkComplete(engine.gl, effect.program, engine.caps.parallelShaderCompile)) {\n return false;\n }\n const linkErr = getLinkError(engine.gl, effect.program, effect._vs, effect._fs);\n if (linkErr !== null) {\n recordCompilationError(effect, linkErr);\n return false;\n }\n finalizeEffect(engine, effect);\n return true;\n}\n\n/** Poll readiness once and return the recorded compile/link/restore diagnostic.\n * Returns null while pending or when no failure has been recorded; this is\n * not a readiness guarantee. Does not schedule polling. A successful restore\n * allocation clears the previous diagnostic before the new link is checked. */\nexport function getEffectCompilationError(engine: GLEngineContext, effect: GLEffect): string | null {\n isEffectReady(engine, effect);\n return effect._compileError;\n}\n\nfunction recordCompilationError(effect: GLEffect, error: string): void {\n effect._compileError = error;\n effect.isReady = false;\n console.error(`lite-gl: ${effect.name} ${error}`);\n}\n\n/** Resolves uniform/attribute locations, binds the program (cached), and\n * issues the one-time `gl.uniform1i(samplerLoc, unit)` per declared sampler. */\nfunction finalizeEffect(engine: GLEngineContext, effect: GLEffect): void {\n const gl = engine.gl;\n const program = effect.program;\n for (const name of effect.options.uniformNames) {\n effect.uniformLocations[name] = gl.getUniformLocation(program, name);\n }\n const attribs = effect.options.attributeNames ?? [\"position\"];\n for (const name of attribs) {\n effect.attributeLocations[name] = gl.getAttribLocation(program, name);\n }\n // Switch to this program via the cached helper so _state.currentProgram\n // stays consistent — no raw gl.useProgram outside useEffect.\n useEffect(engine, effect);\n let unit = 0;\n for (const name of effect.options.samplerNames) {\n const loc = gl.getUniformLocation(program, name);\n if (loc !== null) {\n gl.uniform1i(loc, unit);\n }\n effect.samplerUnits[name] = unit;\n unit++;\n }\n effect._samplersAssigned = true;\n effect.isReady = true;\n // Fire and clear the one-shot ready callbacks.\n const cbs = effect._onCompiled.slice();\n effect._onCompiled.length = 0;\n for (const cb of cbs) {\n try {\n cb(effect);\n } catch (err) {\n console.error(`lite-gl: ${effect.name} onCompiled callback threw`, err);\n }\n }\n}\n\n/** Fires `cb` synchronously if the effect is already ready; otherwise queues\n * it for the next finalization. Does not start polling: call `isEffectReady`\n * from the render loop or opt into `waitForEffect`. */\nexport function executeWhenCompiled(engine: GLEngineContext, effect: GLEffect, cb: (e: GLEffect) => void): void {\n if (isEffectReady(engine, effect)) {\n cb(effect);\n return;\n }\n effect._onCompiled.push(cb);\n}\n\n/** Decrement the share count and, on the last release, delete the effect's\n * program + shaders, unregister it from the context + cache, and clear the\n * cached current-program if it pointed at this effect. A shared effect (still\n * referenced by another `createEffect` caller) is kept alive. Call exactly ONCE\n * per `createEffect` (each call decrements the ref count); safe (no-op) once the\n * effect is fully torn down. */\nexport function disposeEffect(engine: GLEngineContext, effect: GLEffect): void {\n if (effect._disposed) {\n return;\n }\n if (--effect._refCount > 0) {\n return;\n }\n effect._disposed = true;\n effect.isReady = false;\n const i = engine._effects.indexOf(effect);\n if (i !== -1) {\n engine._effects.splice(i, 1);\n }\n engine._effectCache.delete(effect._cacheKey);\n if (!engine._isLost && !engine._disposed) {\n engine.gl.deleteProgram(effect.program);\n engine.gl.deleteShader(effect._vs);\n engine.gl.deleteShader(effect._fs);\n }\n if (engine._state.currentProgram === effect.program) {\n engine._state.currentProgram = null;\n }\n effect._onCompiled.length = 0;\n}\n\n/** Cached `gl.useProgram`. No-op when the effect is not ready or already current. */\nexport function useEffect(engine: GLEngineContext, effect: GLEffect): void {\n if (engine._isLost || engine._disposed || effect._disposed) {\n return;\n }\n if (engine._state.currentProgram === effect.program) {\n return;\n }\n engine.gl.useProgram(effect.program);\n engine._state.currentProgram = effect.program;\n}\n\n/* ──────────────────────────── cached setters ────────────────────────────\n *\n * Each setter has the shape:\n * 1. bail when context lost / effect not ready (no cache write)\n * 2. lookup uniform location; bail on null (no cache write)\n * 3. compare against last-UPLOADED value; bail on equality\n * 4. write to cache, issue gl.uniform*\n *\n * Step 3's comparison is intentionally bit-equal (===) — NaN inputs re-upload\n * every frame because `NaN !== NaN`, which is the correct safety net for\n * caller bugs.\n */\n\n/** Cached `gl.uniform1f`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectFloat(engine: GLEngineContext, effect: GLEffect, name: string, x: number): void {\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n if (effect._lastF1[name] === x) {\n return;\n }\n effect._lastF1[name] = x;\n engine.gl.uniform1f(loc, x);\n}\n\n/** Cached `gl.uniform2f`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectFloat2(engine: GLEngineContext, effect: GLEffect, name: string, x: number, y: number): void {\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n let v = effect._lastVec[name];\n if (v !== undefined && v[0] === x && v[1] === y) {\n return;\n }\n if (v === undefined) {\n v = [x, y];\n effect._lastVec[name] = v;\n } else {\n v[0] = x;\n v[1] = y;\n }\n engine.gl.uniform2f(loc, x, y);\n}\n\n/** Cached `gl.uniform3f`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectFloat3(engine: GLEngineContext, effect: GLEffect, name: string, x: number, y: number, z: number): void {\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n let v = effect._lastVec[name];\n if (v !== undefined && v[0] === x && v[1] === y && v[2] === z) {\n return;\n }\n if (v === undefined) {\n v = [x, y, z];\n effect._lastVec[name] = v;\n } else {\n v[0] = x;\n v[1] = y;\n v[2] = z;\n }\n engine.gl.uniform3f(loc, x, y, z);\n}\n\n/** Cached `gl.uniform4f`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectFloat4(engine: GLEngineContext, effect: GLEffect, name: string, x: number, y: number, z: number, w: number): void {\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n let v = effect._lastVec[name];\n if (v !== undefined && v[0] === x && v[1] === y && v[2] === z && v[3] === w) {\n return;\n }\n if (v === undefined) {\n v = [x, y, z, w];\n effect._lastVec[name] = v;\n } else {\n v[0] = x;\n v[1] = y;\n v[2] = z;\n v[3] = w;\n }\n engine.gl.uniform4f(loc, x, y, z, w);\n}\n\n/** Cached `gl.uniform3f` from an r/g/b color object. Delegates to `setEffectFloat3`. */\nexport function setEffectColor3(engine: GLEngineContext, effect: GLEffect, name: string, c: { r: number; g: number; b: number }): void {\n setEffectFloat3(engine, effect, name, c.r, c.g, c.b);\n}\n\n/** Cached `gl.uniform4f` from an r/g/b/a color object. Delegates to `setEffectFloat4`. */\nexport function setEffectColor4(engine: GLEngineContext, effect: GLEffect, name: string, c: { r: number; g: number; b: number; a: number }): void {\n setEffectFloat4(engine, effect, name, c.r, c.g, c.b, c.a);\n}\n\n/** Cached `gl.uniform2f` from an `{x,y}` vector object — the lite-gl equivalent\n * of Babylon's `Effect.setVector2`. Delegates to `setEffectFloat2`. */\nexport function setEffectVector2(engine: GLEngineContext, effect: GLEffect, name: string, v: { x: number; y: number }): void {\n setEffectFloat2(engine, effect, name, v.x, v.y);\n}\n\n/** Cached `gl.uniform4f` from an r/g/b/a color WITHOUT premultiplication — the\n * lite-gl equivalent of Babylon's `Effect.setDirectColor4`. Delegates to\n * `setEffectFloat4` (lite-gl never premultiplies in the uniform setters, so\n * this matches `setEffectColor4`; the distinct name eases the ShapeBuilder\n * port). */\nexport function setEffectDirectColor4(engine: GLEngineContext, effect: GLEffect, name: string, c: { r: number; g: number; b: number; a: number }): void {\n setEffectFloat4(engine, effect, name, c.r, c.g, c.b, c.a);\n}\n\n/** Cached `gl.uniform1i`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectInt(engine: GLEngineContext, effect: GLEffect, name: string, x: number): void {\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n if (effect._lastI1[name] === x) {\n return;\n }\n effect._lastI1[name] = x;\n engine.gl.uniform1i(loc, x);\n}\n\n/* ── Matrix / array setters (uploaded every call — not value-cached) ──────────\n *\n * Matrices and arrays usually change every frame; element-wise caching would\n * cost more than the upload it saves, so these always issue the GL call (the\n * location lookup + ready guards still apply). They cover the ShapeBuilder\n * surface (`setMatrix3x3`, `setFloatArray`, `setFloatArray4`) plus a general\n * 4×4 matrix setter for any future mesh consumer. */\n\n/** `gl.uniformMatrix4fv` from a column-major 4×4 matrix — the lite-gl\n * equivalent of Babylon's `Effect.setMatrix`. Not value-cached. */\nexport function setEffectMatrix(engine: GLEngineContext, effect: GLEffect, name: string, matrix: Float32Array | number[]): void {\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniformMatrix4fv(loc, false, matrix);\n}\n\n/** `gl.uniformMatrix3fv` from a column-major 3×3 matrix — the lite-gl\n * equivalent of Babylon's `Effect.setMatrix3x3`. Not value-cached. */\nexport function setEffectMatrix3x3(engine: GLEngineContext, effect: GLEffect, name: string, matrix: Float32Array | number[]): void {\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniformMatrix3fv(loc, false, matrix);\n}\n\n/** `gl.uniform1fv` — a flat float array (`Effect.setFloatArray` / `setArray`).\n * Not value-cached. */\nexport function setEffectFloatArray(engine: GLEngineContext, effect: GLEffect, name: string, array: Float32Array | number[]): void {\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniform1fv(loc, array);\n}\n\n/** `gl.uniform4fv` — an array of `vec4`s (`Effect.setFloatArray4` / `setArray4`).\n * Not value-cached. */\nexport function setEffectFloatArray4(engine: GLEngineContext, effect: GLEffect, name: string, array: Float32Array | number[]): void {\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniform4fv(loc, array);\n}\n\n/** `gl.uniform1iv` — a flat int array (`Effect.setIntArray`). Not value-cached. */\nexport function setEffectIntArray(engine: GLEngineContext, effect: GLEffect, name: string, array: Int32Array | number[]): void {\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniform1iv(loc, array);\n}\n\n/** Bind a texture to the sampler's pre-assigned unit, or pass `null` to unbind\n * that unit (§4.4). NO `gl.uniform1i` is issued — that was done exactly once per program lifetime during\n * finalization. This is the key win over Babylon's `Effect.setTexture` which\n * re-issues the sampler binding on every call. */\nexport function setEffectTexture(engine: GLEngineContext, effect: GLEffect, samplerName: string, tex: GLTexture | null): void {\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const unit = effect.samplerUnits[samplerName];\n if (unit === undefined) {\n return;\n }\n bindTexture(engine, unit, tex);\n}\n\n/** Resolve (and cache) a vertex-attribute location by name — the lite-gl\n * equivalent of Babylon's `Effect.getAttributeLocationByName`. Locations for\n * declared `attributeNames` are resolved during finalization; this also serves\n * the mesh / instancing path, where attribute names are not declared up-front.\n * Returns `-1` when the attribute is absent (matching `gl.getAttribLocation`).\n * @internal */\nexport function getEffectAttributeLocation(engine: GLEngineContext, effect: GLEffect, name: string): number {\n const cached = effect.attributeLocations[name];\n if (cached !== undefined) {\n return cached;\n }\n const loc = engine.gl.getAttribLocation(effect.program, name);\n effect.attributeLocations[name] = loc;\n return loc;\n}\n\n/* ──────────────────────────── internal helpers ──────────────────────────── */\n\n/** Inject `options.defines` between the `#version`/precision header and the\n * user shader body. Supports a `// __DEFINES__` marker (preferred — keeps the\n * runtime regex-free, per spec §6.2) OR auto-detects the end of the leading\n * preprocessor / precision lines. */\nfunction applyDefines(source: string, defines: string | undefined): string {\n if (defines === undefined || defines.length === 0) {\n return source;\n }\n const marker = \"// __DEFINES__\";\n const idx = source.indexOf(marker);\n if (idx !== -1) {\n return source.slice(0, idx) + defines + source.slice(idx + marker.length);\n }\n // Fallback: insert after the last `precision` line (or after `#version`).\n const lines = source.split(\"\\n\");\n let insertAt = 0;\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (line === undefined) {\n continue;\n }\n const trimmed = line.trim();\n if (trimmed.startsWith(\"#version\") || trimmed.startsWith(\"precision \")) {\n insertAt = i + 1;\n }\n }\n lines.splice(insertAt, 0, defines);\n return lines.join(\"\\n\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"effect.js","sourceRoot":"","sources":["../src/effect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,EAAE,cAAc,EAAkB,MAAM,cAAc,CAAC;AAiH9D;;;0EAG0E;AAC1E,MAAM,UAAU,YAAY,CAAC,MAAuB,EAAE,OAAwB;IAC1E,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,IAAI,CAAC,UAAU,CAAC,CAAC;IACvD,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;IAErB,yEAAyE;IACzE,mEAAmE;IACnE,uEAAuE;IACvE,wEAAwE;IACxE,6EAA6E;IAC7E,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAC1K,QAAQ,CACX,CAAC;IACF,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACjD,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QAC5C,MAAM,CAAC,SAAS,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,MAAM,QAAQ,G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,CAAC,MAAc,EAAE,OAA2B;IAC7D,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChD,OAAO,MAAM,CAAC;IAClB,CAAC;IACD,MAAM,MAAM,GAAG,gBAAgB,CAAC;IAChC,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACnC,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;QACb,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9E,CAAC;IACD,0EAA0E;IAC1E,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACrB,SAAS;QACb,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YACrE,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;IACL,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\nimport { compileShader, getLinkError, isLinkComplete, linkProgram } from \"./shader.js\";\nimport { bindTextureRaw, type GLTexture } from \"./texture.js\";\n\n/** Inputs to `createEffect`: shader sources plus the uniform, sampler and\n * attribute names whose locations are resolved during readiness finalization. */\nexport interface GLEffectOptions {\n /** Human-readable label, surfaced in compile/link error messages. */\n name: string;\n /** GLSL ES 3.00 source, ready for `gl.shaderSource`. */\n vertexSource: string;\n /** GLSL ES 3.00 source, ready for `gl.shaderSource`. */\n fragmentSource: string;\n /** Declared uniform names. Locations are resolved during readiness\n * finalization. Names not declared here are legal but allocate cache\n * slots lazily on first setter use. */\n uniformNames: readonly string[];\n /** Declared sampler names, in unit-assignment order. Each gets a fixed\n * texture unit assigned during readiness finalization, and\n * `gl.uniform1i(loc, unit)` is called exactly once per program lifetime\n * (re-run after `webglcontextrestored`). */\n samplerNames: readonly string[];\n /** Default `[\"position\"]`. The first attribute is bound to location 0 via\n * `gl.bindAttribLocation(program, 0, name)` BEFORE link, so the shared\n * fullscreen-quad VAO always feeds the same location. */\n attributeNames?: readonly string[];\n /** Optional `#define` block. Each unique `defines` string must be paired\n * with the same vertex/fragment source via a separate `createEffect` call —\n * the package does NOT cache compiled variants. */\n defines?: string;\n}\n\n/** A compiled + linked shader program with cached uniform, sampler and\n * attribute locations. Created by `createEffect`; most fields are managed\n * internally — drive it via `isEffectReady` / `useEffect` / the `setEffect*`\n * setters rather than mutating it directly. */\nexport interface GLEffect {\n /** The `name` from the originating `GLEffectOptions`. */\n readonly name: string;\n /** The options this effect was created from (retained for context-restore). */\n readonly options: GLEffectOptions;\n /** The live `WebGLProgram`. Swapped for a fresh handle after context-restore. */\n program: WebGLProgram;\n /** @internal */\n _vs: WebGLShader;\n /** @internal */\n _fs: WebGLShader;\n /** Resolved during readiness finalization. Missing names map to `null` —\n * setters with a `null` location are silent no-ops (matches Babylon). */\n uniformLocations: { [name: string]: WebGLUniformLocation | null };\n /** Fixed unit assignment for declared samplers, index into\n * `_state.boundTextures`. */\n samplerUnits: { [name: string]: number };\n /**\n * True once `gl.uniform1i(samplerLoc, unit)` has been issued for every\n * declared sampler. Cleared on context-lost so finalization re-runs.\n * @internal\n */\n _samplersAssigned: boolean;\n /** Resolved attribute locations, keyed by attribute name. */\n attributeLocations: { [name: string]: number };\n /**\n * Last-UPLOADED scalar floats. A setter that skips the upload must NOT\n * update this — otherwise a later real set with the same value would\n * incorrectly elide and the GPU would keep stale data.\n * @internal\n */\n readonly _lastF1: { [name: string]: number };\n /**\n * Last-UPLOADED vector floats (vec2/vec3/vec4). Plain `number[]` (NOT\n * `Float32Array`) so values like `0.1` compare equal across frames.\n * @internal\n */\n readonly _lastVec: { [name: string]: number[] };\n /** @internal */\n readonly _lastI1: { [name: string]: number };\n /** True once the program has linked and finalization has run; the\n * `setEffect*` setters are no-ops until then. Poll `isEffectReady` to advance it. */\n isReady: boolean;\n /** The engine that created (and owns) this effect. Effect operations derive\n * their engine from it, so they take the effect alone. @internal */\n _engine: GLEngineContext;\n /** @internal */\n _compileError: string | null;\n /** @internal */\n _disposed: boolean;\n /**\n * Number of live `createEffect` callers sharing this effect (and its one\n * `WebGLProgram`). `createEffect` returns the cached effect and bumps this\n * when an identical descriptor is requested; `disposeEffect` decrements it\n * and only tears the program down when it reaches 0.\n * @internal\n */\n _refCount: number;\n /**\n * The `_effectCache` key this effect was stored under (the source\n * descriptor). Used by `disposeEffect` to evict the cache entry at refcount\n * 0.\n * @internal\n */\n _cacheKey: string;\n /**\n * Callbacks fired exactly once on the first transition to ready.\n * @internal\n */\n readonly _onCompiled: ((effect: GLEffect) => void)[];\n /**\n * Replay closure for context-restore. Re-compiles + relinks into a fresh\n * `program` field. Finalization happens lazily on the next `isEffectReady`\n * poll.\n * @internal\n */\n _restore: (engine: GLEngineContext) => void;\n}\n\n/** Submit compilation + linking without querying their results. `isReady`\n * starts false; poll `isEffectReady` or opt into `waitForEffect` to finalize.\n * Allocation failures throw synchronously. Shader syntax/link errors are\n * recorded during polling and exposed by `getEffectCompilationError`. */\nexport function createEffect(engine: GLEngineContext, options: GLEffectOptions): GLEffect {\n const attribs = options.attributeNames ?? [\"position\"];\n const gl = engine.gl;\n\n // Per-engine cache keyed by the source descriptor. Identical descriptors\n // share ONE GLEffect (and thus one WebGLProgram), so `useEffect`'s\n // current-program cache can elide redundant `gl.useProgram` across the\n // consumers. The key covers every input that affects the program or its\n // readiness finalization, joined by a NUL separator (cannot appear in GLSL).\n const cacheKey = [options.vertexSource, options.fragmentSource, options.defines ?? \"\", attribs.join(\",\"), options.uniformNames.join(\",\"), options.samplerNames.join(\",\")].join(\n \"\\u0000\"\n );\n const cached = engine._effectCache.get(cacheKey);\n if (cached !== undefined && !cached._disposed) {\n cached._refCount++;\n return cached;\n }\n\n const compiled = compileEffectProgram(gl, options, attribs);\n if (typeof compiled === \"string\") {\n throw new Error(`lite-gl: ${options.name} ${compiled}`);\n }\n const { vs, fs, program } = compiled;\n\n const effect: GLEffect = {\n name: options.name,\n options,\n program,\n _vs: vs,\n _fs: fs,\n uniformLocations: {},\n samplerUnits: {},\n _samplersAssigned: false,\n attributeLocations: {},\n _lastF1: {},\n _lastVec: {},\n _lastI1: {},\n isReady: false,\n _engine: engine,\n _compileError: null,\n _disposed: false,\n _refCount: 1,\n _cacheKey: cacheKey,\n _onCompiled: [],\n _restore: () => {},\n };\n\n effect._restore = (target: GLEngineContext): void => {\n const restored = compileEffectProgram(target.gl, options, attribs);\n if (typeof restored === \"string\") {\n recordCompilationError(effect, `context-restore: ${restored}`);\n return;\n }\n effect.program = restored.program;\n effect._vs = restored.vs;\n effect._fs = restored.fs;\n effect.isReady = false;\n effect._samplersAssigned = false;\n effect.uniformLocations = {};\n effect.attributeLocations = {};\n effect._compileError = null;\n };\n\n engine._effects.push(effect);\n engine._effectCache.set(cacheKey, effect);\n return effect;\n}\n\n/** Shader/program handles allocated as one unit on creation and restoration. */\ninterface EffectProgram {\n vs: WebGLShader;\n fs: WebGLShader;\n program: WebGLProgram;\n}\n\n/** Share allocation and partial-failure cleanup between initial creation and\n * context restoration. Returns a diagnostic on allocation failure; compile\n * and link results are deliberately left to readiness polling. */\nfunction compileEffectProgram(gl: WebGL2RenderingContext, options: GLEffectOptions, attribs: readonly string[]): EffectProgram | string {\n const vs = compileShader(gl, applyDefines(options.vertexSource, options.defines), gl.VERTEX_SHADER);\n if (vs === null) {\n return \"vertex shader allocation failed\";\n }\n const fs = compileShader(gl, applyDefines(options.fragmentSource, options.defines), gl.FRAGMENT_SHADER);\n if (fs === null) {\n gl.deleteShader(vs);\n return \"fragment shader allocation failed\";\n }\n const program = linkProgram(gl, vs, fs, attribs);\n if (program === null) {\n gl.deleteShader(vs);\n gl.deleteShader(fs);\n return \"program allocation failed\";\n }\n return { vs, fs, program };\n}\n\n/** Poll the link state and, on first success, run finalization (uniform-\n * location resolution + one-shot sampler-unit `uniform1i` assignment +\n * `_onCompiled` callbacks). Returns `true` once the effect is usable. */\nexport function isEffectReady(effect: GLEffect): boolean {\n const engine = effect._engine;\n if (\n !effect.isReady &&\n !effect._disposed &&\n !engine._isLost &&\n !engine._disposed &&\n effect._compileError === null &&\n isLinkComplete(engine.gl, effect.program, engine.caps.parallelShaderCompile)\n ) {\n const linkErr = getLinkError(engine.gl, effect.program, effect._vs, effect._fs);\n if (linkErr !== null) {\n recordCompilationError(effect, linkErr);\n } else {\n finalizeEffect(engine, effect);\n }\n }\n // Read back rather than returning `true` after finalization: a ready\n // callback may have disposed the effect or engine (or lost the context).\n return effect.isReady;\n}\n\n/** Poll readiness once and return the recorded compile/link/restore diagnostic.\n * Returns null while pending or when no failure has been recorded; this is\n * not a readiness guarantee. Does not schedule polling. A successful restore\n * allocation clears the previous diagnostic before the new link is checked. */\nexport function getEffectCompilationError(effect: GLEffect): string | null {\n isEffectReady(effect);\n return effect._compileError;\n}\n\nfunction recordCompilationError(effect: GLEffect, error: string): void {\n effect._compileError = error;\n effect.isReady = false;\n console.error(`lite-gl: ${effect.name} ${error}`);\n}\n\n/** Resolves uniform/attribute locations, binds the program (cached), and\n * issues the one-time `gl.uniform1i(samplerLoc, unit)` per declared sampler. */\nfunction finalizeEffect(engine: GLEngineContext, effect: GLEffect): void {\n const gl = engine.gl;\n const program = effect.program;\n for (const name of effect.options.uniformNames) {\n effect.uniformLocations[name] = gl.getUniformLocation(program, name);\n }\n const attribs = effect.options.attributeNames ?? [\"position\"];\n for (const name of attribs) {\n effect.attributeLocations[name] = gl.getAttribLocation(program, name);\n }\n // Switch to this program via the cached helper so _state.currentProgram\n // stays consistent — no raw gl.useProgram outside useEffect.\n useEffect(effect);\n let unit = 0;\n for (const name of effect.options.samplerNames) {\n const loc = gl.getUniformLocation(program, name);\n if (loc !== null) {\n gl.uniform1i(loc, unit);\n }\n effect.samplerUnits[name] = unit;\n unit++;\n }\n effect._samplersAssigned = true;\n effect.isReady = true;\n // Fire and clear the one-shot ready callbacks.\n const cbs = effect._onCompiled.slice();\n effect._onCompiled.length = 0;\n for (const cb of cbs) {\n try {\n cb(effect);\n } catch (err) {\n console.error(`lite-gl: ${effect.name} onCompiled callback threw`, err);\n }\n }\n}\n\n/** Fires `cb` synchronously if the effect is already ready; otherwise queues\n * it for the next finalization. Does not start polling: call `isEffectReady`\n * from the render loop or opt into `waitForEffect`. */\nexport function executeWhenCompiled(effect: GLEffect, cb: (e: GLEffect) => void): void {\n if (isEffectReady(effect)) {\n cb(effect);\n return;\n }\n effect._onCompiled.push(cb);\n}\n\n/** Decrement the share count and, on the last release, delete the effect's\n * program + shaders, unregister it from the context + cache, and clear the\n * cached current-program if it pointed at this effect. A shared effect (still\n * referenced by another `createEffect` caller) is kept alive. Call exactly ONCE\n * per `createEffect` (each call decrements the ref count); safe (no-op) once the\n * effect is fully torn down. */\nexport function disposeEffect(effect: GLEffect): void {\n const engine = effect._engine;\n if (effect._disposed) {\n return;\n }\n if (--effect._refCount > 0) {\n return;\n }\n effect._disposed = true;\n effect.isReady = false;\n const i = engine._effects.indexOf(effect);\n if (i !== -1) {\n engine._effects.splice(i, 1);\n }\n engine._effectCache.delete(effect._cacheKey);\n if (!engine._isLost && !engine._disposed) {\n engine.gl.deleteProgram(effect.program);\n engine.gl.deleteShader(effect._vs);\n engine.gl.deleteShader(effect._fs);\n }\n if (engine._state.currentProgram === effect.program) {\n engine._state.currentProgram = null;\n }\n effect._onCompiled.length = 0;\n}\n\n/** Cached `gl.useProgram`. Low-level: it does NOT check readiness, so poll\n * {@link isEffectReady} first (binding a still-linking program can stall, and\n * a failed one fails the next draw). `applyEffectWrapper` does that poll for\n * wrappers. No-op when the effect is already current, disposed, or the\n * context is lost/disposed. */\nexport function useEffect(effect: GLEffect): void {\n const engine = effect._engine;\n if (engine._isLost || engine._disposed || effect._disposed) {\n return;\n }\n if (engine._state.currentProgram === effect.program) {\n return;\n }\n engine.gl.useProgram(effect.program);\n engine._state.currentProgram = effect.program;\n}\n\n/* ──────────────────────────── cached setters ────────────────────────────\n *\n * Each setter has the shape:\n * 1. bail when context lost / effect not ready (no cache write)\n * 2. lookup uniform location; bail on null (no cache write)\n * 3. compare against last-UPLOADED value; bail on equality\n * 4. write to cache, issue gl.uniform*\n *\n * Step 3's comparison is intentionally bit-equal (===) — NaN inputs re-upload\n * every frame because `NaN !== NaN`, which is the correct safety net for\n * caller bugs.\n */\n\n/** Cached `gl.uniform1f`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectFloat(effect: GLEffect, name: string, x: number): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n if (effect._lastF1[name] === x) {\n return;\n }\n effect._lastF1[name] = x;\n engine.gl.uniform1f(loc, x);\n}\n\n/** Cached `gl.uniform2f`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectFloat2(effect: GLEffect, name: string, x: number, y: number): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n let v = effect._lastVec[name];\n if (v !== undefined && v[0] === x && v[1] === y) {\n return;\n }\n if (v === undefined) {\n v = [x, y];\n effect._lastVec[name] = v;\n } else {\n v[0] = x;\n v[1] = y;\n }\n engine.gl.uniform2f(loc, x, y);\n}\n\n/** Cached `gl.uniform3f`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectFloat3(effect: GLEffect, name: string, x: number, y: number, z: number): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n let v = effect._lastVec[name];\n if (v !== undefined && v[0] === x && v[1] === y && v[2] === z) {\n return;\n }\n if (v === undefined) {\n v = [x, y, z];\n effect._lastVec[name] = v;\n } else {\n v[0] = x;\n v[1] = y;\n v[2] = z;\n }\n engine.gl.uniform3f(loc, x, y, z);\n}\n\n/** Cached `gl.uniform4f`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectFloat4(effect: GLEffect, name: string, x: number, y: number, z: number, w: number): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n let v = effect._lastVec[name];\n if (v !== undefined && v[0] === x && v[1] === y && v[2] === z && v[3] === w) {\n return;\n }\n if (v === undefined) {\n v = [x, y, z, w];\n effect._lastVec[name] = v;\n } else {\n v[0] = x;\n v[1] = y;\n v[2] = z;\n v[3] = w;\n }\n engine.gl.uniform4f(loc, x, y, z, w);\n}\n\n/** Cached `gl.uniform3f` from an r/g/b color object. Delegates to `setEffectFloat3`. */\nexport function setEffectColor3(effect: GLEffect, name: string, c: { r: number; g: number; b: number }): void {\n setEffectFloat3(effect, name, c.r, c.g, c.b);\n}\n\n/** Cached `gl.uniform4f` from an r/g/b/a color object. Delegates to `setEffectFloat4`. */\nexport function setEffectColor4(effect: GLEffect, name: string, c: { r: number; g: number; b: number; a: number }): void {\n setEffectFloat4(effect, name, c.r, c.g, c.b, c.a);\n}\n\n/** Cached `gl.uniform2f` from an `{x,y}` vector object — the lite-gl equivalent\n * of Babylon's `Effect.setVector2`. Delegates to `setEffectFloat2`. */\nexport function setEffectVector2(effect: GLEffect, name: string, v: { x: number; y: number }): void {\n setEffectFloat2(effect, name, v.x, v.y);\n}\n\n/** Cached `gl.uniform4f` from an r/g/b/a color WITHOUT premultiplication — the\n * lite-gl equivalent of Babylon's `Effect.setDirectColor4`. Delegates to\n * `setEffectFloat4` (lite-gl never premultiplies in the uniform setters, so\n * this matches `setEffectColor4`; the distinct name eases the ShapeBuilder\n * port). */\nexport function setEffectDirectColor4(effect: GLEffect, name: string, c: { r: number; g: number; b: number; a: number }): void {\n setEffectFloat4(effect, name, c.r, c.g, c.b, c.a);\n}\n\n/** Cached `gl.uniform1i`. No-op when context-lost, the effect isn't ready, the\n * uniform is absent, or the value is unchanged since last upload. */\nexport function setEffectInt(effect: GLEffect, name: string, x: number): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n if (effect._lastI1[name] === x) {\n return;\n }\n effect._lastI1[name] = x;\n engine.gl.uniform1i(loc, x);\n}\n\n/* ── Matrix / array setters (uploaded every call — not value-cached) ──────────\n *\n * Matrices and arrays usually change every frame; element-wise caching would\n * cost more than the upload it saves, so these always issue the GL call (the\n * location lookup + ready guards still apply). They cover the ShapeBuilder\n * surface (`setMatrix3x3`, `setFloatArray`, `setFloatArray4`) plus a general\n * 4×4 matrix setter for any future mesh consumer. */\n\n/** `gl.uniformMatrix4fv` from a column-major 4×4 matrix — the lite-gl\n * equivalent of Babylon's `Effect.setMatrix`. Not value-cached. */\nexport function setEffectMatrix(effect: GLEffect, name: string, matrix: Float32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniformMatrix4fv(loc, false, matrix);\n}\n\n/** `gl.uniformMatrix3fv` from a column-major 3×3 matrix — the lite-gl\n * equivalent of Babylon's `Effect.setMatrix3x3`. Not value-cached. */\nexport function setEffectMatrix3x3(effect: GLEffect, name: string, matrix: Float32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniformMatrix3fv(loc, false, matrix);\n}\n\n/** `gl.uniform1fv` — a flat float array (`Effect.setFloatArray` / `setArray`).\n * Not value-cached. */\nexport function setEffectFloatArray(effect: GLEffect, name: string, array: Float32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniform1fv(loc, array);\n}\n\n/** `gl.uniform4fv` — an array of `vec4`s (`Effect.setFloatArray4` / `setArray4`).\n * Not value-cached. */\nexport function setEffectFloatArray4(effect: GLEffect, name: string, array: Float32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniform4fv(loc, array);\n}\n\n/** `gl.uniform1iv` — a flat int array (`Effect.setIntArray`). Not value-cached. */\nexport function setEffectIntArray(effect: GLEffect, name: string, array: Int32Array | number[]): void {\n const engine = effect._engine;\n if (engine._isLost || !effect.isReady) {\n return;\n }\n const loc = effect.uniformLocations[name];\n if (loc === null || loc === undefined) {\n return;\n }\n engine.gl.uniform1iv(loc, array);\n}\n\n/** Bind a texture to the sampler's pre-assigned unit, or pass `null` to unbind\n * that unit (§4.4). NO `gl.uniform1i` is issued — that was done exactly once per program lifetime during\n * finalization. This is the key win over Babylon's `Effect.setTexture` which\n * re-issues the sampler binding on every call. */\nexport function setEffectTexture(effect: GLEffect, samplerName: string, tex: GLTexture | null): void {\n const engine = effect._engine;\n if (engine._isLost || engine._disposed || !effect.isReady) {\n return;\n }\n const unit = effect.samplerUnits[samplerName];\n if (unit === undefined || tex?._disposed) {\n return;\n }\n bindTextureRaw(engine, unit, tex === null ? null : tex.handle);\n}\n\n/** Resolve (and cache) a vertex-attribute location by name — the lite-gl\n * equivalent of Babylon's `Effect.getAttributeLocationByName`. Locations for\n * declared `attributeNames` are resolved during finalization; this also serves\n * the mesh / instancing path, where attribute names are not declared up-front.\n * Returns `-1` when the attribute is absent (matching `gl.getAttribLocation`).\n * @internal */\nexport function getEffectAttributeLocation(effect: GLEffect, name: string): number {\n const engine = effect._engine;\n const cached = effect.attributeLocations[name];\n if (cached !== undefined) {\n return cached;\n }\n const loc = engine.gl.getAttribLocation(effect.program, name);\n effect.attributeLocations[name] = loc;\n return loc;\n}\n\n/* ──────────────────────────── internal helpers ──────────────────────────── */\n\n/** Inject `options.defines` between the `#version`/precision header and the\n * user shader body. Supports a `// __DEFINES__` marker (preferred — keeps the\n * runtime regex-free, per spec §6.2) OR auto-detects the end of the leading\n * preprocessor / precision lines. */\nfunction applyDefines(source: string, defines: string | undefined): string {\n if (defines === undefined || defines.length === 0) {\n return source;\n }\n const marker = \"// __DEFINES__\";\n const idx = source.indexOf(marker);\n if (idx !== -1) {\n return source.slice(0, idx) + defines + source.slice(idx + marker.length);\n }\n // Fallback: insert after the last `precision` line (or after `#version`).\n const lines = source.split(\"\\n\");\n let insertAt = 0;\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (line === undefined) {\n continue;\n }\n const trimmed = line.trim();\n if (trimmed.startsWith(\"#version\") || trimmed.startsWith(\"precision \")) {\n insertAt = i + 1;\n }\n }\n lines.splice(insertAt, 0, defines);\n return lines.join(\"\\n\");\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { GLEngineContext } from "./context.js";
|
|
2
|
+
/**
|
|
3
|
+
* Running statistics over a stream of samples — the data subset of Babylon's
|
|
4
|
+
* `PerfCounter`. For the GPU frame-time counter every value is in
|
|
5
|
+
* **nanoseconds** (as in Babylon); divide by `1e6` for milliseconds.
|
|
6
|
+
*
|
|
7
|
+
* All fields are read-only for callers; the owning feature updates them.
|
|
8
|
+
*/
|
|
9
|
+
export interface GLPerfCounter {
|
|
10
|
+
/** Most recent sample. */
|
|
11
|
+
current: number;
|
|
12
|
+
/** Mean of every sample since the counter was created. */
|
|
13
|
+
average: number;
|
|
14
|
+
/** Mean of the samples gathered during the last completed ~1 second window. */
|
|
15
|
+
lastSecAverage: number;
|
|
16
|
+
/** Smallest sample seen (0 until the first sample). */
|
|
17
|
+
min: number;
|
|
18
|
+
/** Largest sample seen (0 until the first sample). */
|
|
19
|
+
max: number;
|
|
20
|
+
/** Sum of every sample. */
|
|
21
|
+
total: number;
|
|
22
|
+
/** Number of samples. */
|
|
23
|
+
count: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns the GPU frame-time counter for `engine` (Babylon
|
|
27
|
+
* `engine.getGPUFrameTimeCounter()`), creating it on first use. The counter is
|
|
28
|
+
* only fed while `captureGPUFrameTime(engine, true)` is active and the
|
|
29
|
+
* `EXT_disjoint_timer_query_webgl2` extension is available; otherwise `count`
|
|
30
|
+
* stays at 0. Values are in nanoseconds.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getGPUFrameTimeCounter(engine: GLEngineContext): GLPerfCounter;
|
|
33
|
+
/**
|
|
34
|
+
* Enables or disables GPU frame-time measurement (Babylon
|
|
35
|
+
* `engine.captureGPUFrameTime(value)`). While enabled, each frame delimited by
|
|
36
|
+
* `beginFrame` / `endFrame` — which `runRenderLoop` calls automatically — is
|
|
37
|
+
* wrapped in a `TIME_ELAPSED_EXT` timer query. Results arrive asynchronously a
|
|
38
|
+
* few frames later and feed `getGPUFrameTimeCounter(engine)`. Only one query is
|
|
39
|
+
* in flight at a time, so not every frame is sampled.
|
|
40
|
+
*
|
|
41
|
+
* Silently does nothing useful when `EXT_disjoint_timer_query_webgl2` is
|
|
42
|
+
* unavailable (common outside desktop Chrome, and often disabled for privacy).
|
|
43
|
+
* Samples overlapping a disjoint GPU event are discarded. Survives context
|
|
44
|
+
* loss: the in-flight query is dropped and measurement resumes after restore.
|
|
45
|
+
*
|
|
46
|
+
* @param engine - The lite-gl engine.
|
|
47
|
+
* @param enabled - `true` to start measuring, `false` to stop and release the pending query.
|
|
48
|
+
*/
|
|
49
|
+
export declare function captureGPUFrameTime(engine: GLEngineContext, enabled: boolean): void;
|