melonjs 19.8.0 → 19.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/build/application/application.d.ts.map +1 -1
- package/build/audio/audio.d.ts +1 -1
- package/build/audio/audio.d.ts.map +1 -1
- package/build/audio/backend.d.ts +21 -2
- package/build/audio/backend.d.ts.map +1 -1
- package/build/audio/playback.d.ts +8 -28
- package/build/audio/playback.d.ts.map +1 -1
- package/build/geometries/path2d.d.ts +188 -75
- package/build/geometries/path2d.d.ts.map +1 -1
- package/build/geometries/rectangle.d.ts.map +1 -1
- package/build/index.d.ts +5 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3276 -594
- package/build/index.js.map +4 -4
- package/build/loader/cache.d.ts +1 -0
- package/build/loader/cache.d.ts.map +1 -1
- package/build/loader/loader.d.ts +61 -3
- package/build/loader/loader.d.ts.map +1 -1
- package/build/loader/parsers/fetchdata.d.ts +14 -0
- package/build/loader/parsers/fetchdata.d.ts.map +1 -1
- package/build/loader/parsers/shader.d.ts +47 -0
- package/build/loader/parsers/shader.d.ts.map +1 -0
- package/build/loader/parsers/video.d.ts.map +1 -1
- package/build/math/color.d.ts.map +1 -1
- package/build/math/matrix2d.d.ts.map +1 -1
- package/build/math/noise.d.ts +141 -0
- package/build/math/noise.d.ts.map +1 -0
- package/build/math/observableVector2d.d.ts +1 -1
- package/build/math/observableVector2d.d.ts.map +1 -1
- package/build/math/observableVector3d.d.ts +1 -1
- package/build/math/observableVector3d.d.ts.map +1 -1
- package/build/math/vector2d.d.ts +1 -1
- package/build/math/vector2d.d.ts.map +1 -1
- package/build/math/vector3d.d.ts +1 -1
- package/build/math/vector3d.d.ts.map +1 -1
- package/build/physics/adapter.d.ts +4 -3
- package/build/physics/adapter.d.ts.map +1 -1
- package/build/renderable/anchorPoint.d.ts +80 -0
- package/build/renderable/anchorPoint.d.ts.map +1 -0
- package/build/renderable/collectable.d.ts +7 -1
- package/build/renderable/collectable.d.ts.map +1 -1
- package/build/renderable/entity/entity.d.ts +5 -2
- package/build/renderable/entity/entity.d.ts.map +1 -1
- package/build/renderable/imagelayer.d.ts +5 -2
- package/build/renderable/imagelayer.d.ts.map +1 -1
- package/build/renderable/mesh.d.ts +26 -2
- package/build/renderable/mesh.d.ts.map +1 -1
- package/build/renderable/nineslicesprite.d.ts +5 -7
- package/build/renderable/nineslicesprite.d.ts.map +1 -1
- package/build/renderable/renderable.d.ts +6 -1
- package/build/renderable/renderable.d.ts.map +1 -1
- package/build/renderable/sprite.d.ts +10 -6
- package/build/renderable/sprite.d.ts.map +1 -1
- package/build/renderable/sprite3d.d.ts +41 -5
- package/build/renderable/sprite3d.d.ts.map +1 -1
- package/build/renderable/text/bitmaptext.d.ts +24 -12
- package/build/renderable/text/bitmaptext.d.ts.map +1 -1
- package/build/renderable/text/bitmaptextdata.d.ts +24 -1
- package/build/renderable/text/bitmaptextdata.d.ts.map +1 -1
- package/build/renderable/text/text.d.ts +50 -12
- package/build/renderable/text/text.d.ts.map +1 -1
- package/build/system/event.d.ts +18 -2
- package/build/system/event.d.ts.map +1 -1
- package/build/video/canvas/canvas_renderer.d.ts +4 -0
- package/build/video/canvas/canvas_renderer.d.ts.map +1 -1
- package/build/video/renderer.d.ts +41 -1
- package/build/video/renderer.d.ts.map +1 -1
- package/build/video/rendertarget/render_target_pool.d.ts +17 -6
- package/build/video/rendertarget/render_target_pool.d.ts.map +1 -1
- package/build/video/texture/atlas.d.ts +2 -1
- package/build/video/texture/atlas.d.ts.map +1 -1
- package/build/video/texture/cache.d.ts +55 -6
- package/build/video/texture/cache.d.ts.map +1 -1
- package/build/video/texture/frametexture.d.ts +73 -0
- package/build/video/texture/frametexture.d.ts.map +1 -0
- package/build/video/texture/noise_texture2d.d.ts +176 -0
- package/build/video/texture/noise_texture2d.d.ts.map +1 -0
- package/build/video/texture/parser/aseprite.d.ts.map +1 -1
- package/build/video/texture/texture2d.d.ts +83 -0
- package/build/video/texture/texture2d.d.ts.map +1 -0
- package/build/video/webgl/batchers/batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/lit_quad_batcher.d.ts +30 -4
- package/build/video/webgl/batchers/lit_quad_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/material_batcher.d.ts +39 -3
- package/build/video/webgl/batchers/material_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/mesh_batcher.d.ts +1 -1
- package/build/video/webgl/batchers/mesh_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/primitive_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/quad_batcher.d.ts.map +1 -1
- package/build/video/webgl/buffer/index.d.ts +13 -0
- package/build/video/webgl/buffer/index.d.ts.map +1 -1
- package/build/video/webgl/effects/hologram.d.ts +0 -5
- package/build/video/webgl/effects/hologram.d.ts.map +1 -1
- package/build/video/webgl/effects/shine.d.ts +0 -5
- package/build/video/webgl/effects/shine.d.ts.map +1 -1
- package/build/video/webgl/glshader.d.ts +29 -0
- package/build/video/webgl/glshader.d.ts.map +1 -1
- package/build/video/webgl/shadereffect.d.ts +183 -0
- package/build/video/webgl/shadereffect.d.ts.map +1 -1
- package/build/video/webgl/webgl_renderer.d.ts +41 -1
- package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-time-only brand key; no runtime value can hold it.
|
|
3
|
+
* @ignore
|
|
4
|
+
*/
|
|
5
|
+
declare const gpuResidentBrand: unique symbol;
|
|
6
|
+
/**
|
|
7
|
+
* An opaque, GPU-resident texture backing — the source a GPU-resident
|
|
8
|
+
* {@link Texture2d} resolves to (for example the framebuffer copy
|
|
9
|
+
* {@link WebGLRenderer#toFrameTexture} produces). Such a backing uploads/binds
|
|
10
|
+
* itself through the texture cache instead of being read back to the CPU. Its
|
|
11
|
+
* concrete shape is an engine internal that may change between releases:
|
|
12
|
+
* obtain values from the engine and pass them back to the engine — do not
|
|
13
|
+
* construct or inspect them.
|
|
14
|
+
*
|
|
15
|
+
* Nominally branded with a `unique symbol`, so only engine-provided values
|
|
16
|
+
* satisfy the type — a plain object is NOT assignable, keeping
|
|
17
|
+
* {@link Texture2dSource} (and {@link Texture2d#getTexture}) honestly typed.
|
|
18
|
+
*/
|
|
19
|
+
export interface GPUResidentTexture {
|
|
20
|
+
/**
|
|
21
|
+
* Phantom nominal brand — never present at runtime.
|
|
22
|
+
* @ignore
|
|
23
|
+
*/
|
|
24
|
+
readonly [gpuResidentBrand]: true;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The backing source a {@link Texture2d} resolves to through
|
|
28
|
+
* {@link Texture2d#getTexture}: a drawable (canvas/image) for CPU-backed
|
|
29
|
+
* assets, or an opaque {@link GPUResidentTexture} for GPU-resident ones.
|
|
30
|
+
*/
|
|
31
|
+
export type Texture2dSource = HTMLCanvasElement | HTMLImageElement | OffscreenCanvas | ImageBitmap | GPUResidentTexture;
|
|
32
|
+
/**
|
|
33
|
+
* Abstract base for a 2D texture asset — an object that owns a texture
|
|
34
|
+
* source and can be used anywhere the engine expects an image:
|
|
35
|
+
* {@link Sprite#image}, {@link Sprite#normalMap}, an {@link ImageLayer}, or
|
|
36
|
+
* bound as a sampler uniform in a custom shader (see
|
|
37
|
+
* {@link ShaderEffect#setTexture}).
|
|
38
|
+
*
|
|
39
|
+
* A `Texture2d` is recognized via `instanceof` and resolved to its backing
|
|
40
|
+
* source through {@link Texture2d#getTexture} — so passing the asset object
|
|
41
|
+
* directly (`{ image: myTexture }`) works the same as passing a raw
|
|
42
|
+
* `HTMLCanvasElement`. Raw DOM image/canvas sources and the loader's decoded
|
|
43
|
+
* `CompressedImage` data are accepted too, but are not part of this class
|
|
44
|
+
* hierarchy.
|
|
45
|
+
*
|
|
46
|
+
* Most assets are **CPU-backed** and resolve to a drawable canvas/image — those
|
|
47
|
+
* are the ones assignable to {@link Sprite#image} / {@link Sprite#normalMap} /
|
|
48
|
+
* an {@link ImageLayer} (which upload the drawable through the texture cache).
|
|
49
|
+
* Subclasses may also be **GPU-resident**, resolving to an opaque renderer
|
|
50
|
+
* backing that never leaves the GPU (e.g. the capture returned by
|
|
51
|
+
* `renderer.toFrameTexture()`). A GPU-resident texture is **not** a drawable
|
|
52
|
+
* source: use it as a custom-shader sampler via {@link ShaderEffect#setTexture}
|
|
53
|
+
* (which binds its live GL handle), NOT as `Sprite#image`. The contract admits
|
|
54
|
+
* both (a future WebGPU backend follows the same shape with a `GPUTexture`).
|
|
55
|
+
*
|
|
56
|
+
* Concrete implementations:
|
|
57
|
+
* - {@link TextureAtlas} — packed multi-region sprite sheet (CPU-backed)
|
|
58
|
+
* @category Game Objects
|
|
59
|
+
*/
|
|
60
|
+
export default abstract class Texture2d {
|
|
61
|
+
/**
|
|
62
|
+
* Return the backing source for this texture — a drawable canvas/image for
|
|
63
|
+
* CPU-backed assets (assignable to {@link Sprite#image} /
|
|
64
|
+
* {@link Sprite#normalMap} / an {@link ImageLayer}), or an opaque
|
|
65
|
+
* GPU-resident backing for GPU-resident ones (bind those as a custom-shader
|
|
66
|
+
* sampler via {@link ShaderEffect#setTexture}; they are not drawable sources).
|
|
67
|
+
* @returns the backing source
|
|
68
|
+
*/
|
|
69
|
+
abstract getTexture(): Texture2dSource;
|
|
70
|
+
/**
|
|
71
|
+
* Release any GPU/CPU resources held by this texture. The texture must not
|
|
72
|
+
* be used after calling destroy.
|
|
73
|
+
*
|
|
74
|
+
* Broadcasts {@link event.TEXTURE2D_DESTROYED} with the backing source so
|
|
75
|
+
* GPU-side caches keyed by source image (e.g. the lit batcher's normal-map
|
|
76
|
+
* textures) release what they hold for it. Subclasses that own additional
|
|
77
|
+
* resources override this and call `super.destroy()` FIRST — the source
|
|
78
|
+
* must still be resolvable when the event fires.
|
|
79
|
+
*/
|
|
80
|
+
destroy(): void;
|
|
81
|
+
}
|
|
82
|
+
export {};
|
|
83
|
+
//# sourceMappingURL=texture2d.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"texture2d.d.ts","sourceRoot":"","sources":["../../../src/video/texture/texture2d.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,OAAO,CAAC,MAAM,gBAAgB,EAAE,OAAO,MAAM,CAAC;AAE9C;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,kBAAkB;IAClC;;;OAGG;IACH,QAAQ,CAAC,CAAC,gBAAgB,CAAC,EAAE,IAAI,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,GACxB,iBAAiB,GACjB,gBAAgB,GAChB,eAAe,GACf,WAAW,GACX,kBAAkB,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,SAAS;IACtC;;;;;;;OAOG;IACH,QAAQ,CAAC,UAAU,IAAI,eAAe;IAEtC;;;;;;;;;OASG;IACH,OAAO,IAAI,IAAI;CAGf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batcher.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/batchers/batcher.js"],"names":[],"mappings":"AAmBA;;;;GAIG;AACH;IACC;;;;;;;;;;;;;;;OAeG;IACH,sBAfW,aAAa,YAErB;QAA2B,UAAU,EACrC;YAAoC,IAAI,EAAhC,MAAM;YACsB,IAAI,EAAhC,MAAM;YACsB,IAAI,EAAhC,MAAM;YACuB,UAAU,EAAvC,OAAO;YACqB,MAAM,EAAlC,MAAM;SACd;QAAyB,MAAM,EAC/B;YAAgC,MAAM,EAA9B,MAAM;YACkB,QAAQ,EAAhC,MAAM;SACd;QAA0B,WAAW;QACV,OAAO;QACR,iBAAiB;KAC7C,EAGA;IAED;;;OAGG;IACH,yCA6HC;IA3HA,cAAwB;IAGxB,QAAqB;IAGrB,gBAA2C;IAE3C;;;OAGG;IACH,oCAA8B;IAE9B;;;OAGG;IACH,oCAA8B;IAE9B;;;;OAIG;IACH,yBAA6B;IAE7B;;;;OAIG;IACH,iCAAoB;IAEpB;;;;;OAKG;IACH,2BAAe;IAEf;;;;;OAKG;IACH,+BAAmB;IAEnB;;;OAGG;IACH,0CAAsB;IAqCtB;;;OAGG;IACH,sCAA0E;IAE1E;;;OAGG;IACH,oCAA+C;IAE/C;;;;OAIG;IACH,+CAA0B;IAE1B;;;;OAIG;IACH,iDAAuB;IAUxB;;;OAGG;IACH,
|
|
1
|
+
{"version":3,"file":"batcher.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/batchers/batcher.js"],"names":[],"mappings":"AAmBA;;;;GAIG;AACH;IACC;;;;;;;;;;;;;;;OAeG;IACH,sBAfW,aAAa,YAErB;QAA2B,UAAU,EACrC;YAAoC,IAAI,EAAhC,MAAM;YACsB,IAAI,EAAhC,MAAM;YACsB,IAAI,EAAhC,MAAM;YACuB,UAAU,EAAvC,OAAO;YACqB,MAAM,EAAlC,MAAM;SACd;QAAyB,MAAM,EAC/B;YAAgC,MAAM,EAA9B,MAAM;YACkB,QAAQ,EAAhC,MAAM;SACd;QAA0B,WAAW;QACV,OAAO;QACR,iBAAiB;KAC7C,EAGA;IAED;;;OAGG;IACH,yCA6HC;IA3HA,cAAwB;IAGxB,QAAqB;IAGrB,gBAA2C;IAE3C;;;OAGG;IACH,oCAA8B;IAE9B;;;OAGG;IACH,oCAA8B;IAE9B;;;;OAIG;IACH,yBAA6B;IAE7B;;;;OAIG;IACH,iCAAoB;IAEpB;;;;;OAKG;IACH,2BAAe;IAEf;;;;;OAKG;IACH,+BAAmB;IAEnB;;;OAGG;IACH,0CAAsB;IAqCtB;;;OAGG;IACH,sCAA0E;IAE1E;;;OAGG;IACH,oCAA+C;IAE/C;;;;OAIG;IACH,+CAA0B;IAE1B;;;;OAIG;IACH,iDAAuB;IAUxB;;;OAGG;IACH,cAoBC;IAED;;OAEG;IACH,aAYC;IAED;;;;OAIG;IACH,eAaC;IAED;;;;OAIG;IACH,kBAFW,QAAQ,QA8BlB;IAHE,uCAA4B;IAK/B;;;;;;;OAOG;IACH,mBANW,MAAM,QACN,MAAM,QACN,MAAM,cACN,OAAO,UACP,MAAM,QA+BhB;IAED;;;OAGG;IACH,sBAFW,QAAQ,QAIlB;IAED;;;;OAIG;IACH,oBAFW,MAAM,EAAE,QAOlB;IAED;;;OAGG;IACH,aAFW,MAAM,QAgFhB;CACD;;qBA9ZoB,gBAAgB;8BAFP,wBAAwB;6BACzB,oBAAoB;8BAMtB,2BAA2B;+BADxB,wBAAwB"}
|
|
@@ -28,13 +28,38 @@ export default class LitQuadBatcher extends QuadBatcher {
|
|
|
28
28
|
*/
|
|
29
29
|
boundNormalMaps: (ImageBitmap | HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | null)[] | undefined;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* Per-slot content `version` of the normal map currently bound there. An
|
|
32
|
+
* animated source keeps a stable canvas reference across re-bakes but
|
|
33
|
+
* bumps its `version`, so `addQuad` compares this (not just the reference)
|
|
34
|
+
* to know when to re-bind/re-upload. `-1` = nothing bound.
|
|
35
|
+
* @type {number[]}
|
|
33
36
|
* @ignore
|
|
34
37
|
*/
|
|
35
|
-
|
|
38
|
+
boundNormalVersions: number[] | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Map from a normal-map source image to its uploaded GL texture and the
|
|
41
|
+
* source `version` it was uploaded at. A source that bumps its `version`
|
|
42
|
+
* (e.g. an animated {@link NoiseTexture2d}) is re-uploaded on next bind —
|
|
43
|
+
* the three.js `Texture.needsUpdate` model, scoped to normal maps which
|
|
44
|
+
* live outside the color `TextureCache`.
|
|
45
|
+
* @type {Map<HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap, {tex: WebGLTexture, version: number}>}
|
|
46
|
+
* @ignore
|
|
47
|
+
*/
|
|
48
|
+
normalMapTextures: Map<ImageBitmap | HTMLImageElement | HTMLCanvasElement | OffscreenCanvas, {
|
|
49
|
+
tex: WebGLTexture;
|
|
50
|
+
version: number;
|
|
51
|
+
}> | undefined;
|
|
36
52
|
_lightCount: number | undefined;
|
|
37
53
|
_maxLights: number | undefined;
|
|
54
|
+
_onTexture2dDestroyed: ((source: any) => void) | null | undefined;
|
|
55
|
+
_normalRangeReserved: boolean | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Release the cached GL texture uploaded for the given normal-map source
|
|
58
|
+
* and clear any slot bookkeeping referencing it. Safe to call for images
|
|
59
|
+
* that were never bound.
|
|
60
|
+
* @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap} image - normal-map source
|
|
61
|
+
*/
|
|
62
|
+
evictNormalMap(image: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap): void;
|
|
38
63
|
/**
|
|
39
64
|
* Bind the paired normal sampler uniforms (`uNormalSampler0..N-1`)
|
|
40
65
|
* to texture units `maxBatchTextures..2*maxBatchTextures-1`. Called
|
|
@@ -85,8 +110,9 @@ export default class LitQuadBatcher extends QuadBatcher {
|
|
|
85
110
|
* encoding for any non-opaque texel.
|
|
86
111
|
* @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap} image - normal-map source
|
|
87
112
|
* @param {number} unit - GL texture unit (already offset by `maxBatchTextures`)
|
|
113
|
+
* @param {number} [version=0] - the source revision being uploaded
|
|
88
114
|
*/
|
|
89
|
-
uploadNormalMap(image: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap, unit: number): void;
|
|
115
|
+
uploadNormalMap(image: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap, unit: number, version?: number): void;
|
|
90
116
|
/**
|
|
91
117
|
* Add a textured quad with optional paired normal map.
|
|
92
118
|
* @param {TextureAtlas} texture - Source texture atlas
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lit_quad_batcher.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/batchers/lit_quad_batcher.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lit_quad_batcher.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/batchers/lit_quad_batcher.js"],"names":[],"mappings":"AAMA;;;GAGG;AAEH;;;;;;;;;;;;;;;GAeG;AACH;IAsEE;;;;;;OAMG;IACH,6GAAmD;IAEnD;;;;;;;OAOG;IACH,0CAAqD;IAErD;;;;;;;;OAQG;IACH;aAHoF,YAAY;iBAAW,MAAM;mBAG/E;IAElC,gCAAoB;IACpB,+BAA4B;IAQ3B,kEAEC;IAiCD,0CAAgC;IAoBlC;;;;;OAKG;IACH,sBAFW,gBAAgB,GAAC,iBAAiB,GAAC,eAAe,GAAC,WAAW,QAcxE;IAED;;;;;OAKG;IACH,2BAOC;IA4DD;;;;;;;;;;;;;;OAcG;IACH,2BANG;QAA+B,SAAS,EAAhC,YAAY;QACW,MAAM,EAA7B,YAAY;QACY,OAAO;QACd,KAAK,EAAtB,MAAM;QACc,OAAO;KACrC,QAgBA;IAED;;;;;;;;;OASG;IACH,qBAHW,gBAAgB,GAAC,iBAAiB,GAAC,eAAe,GAAC,WAAW,QAC9D,MAAM,QAiBhB;IAED;;;;;;;;;;;OAWG;IACH,uBAJW,gBAAgB,GAAC,iBAAiB,GAAC,eAAe,GAAC,WAAW,QAC9D,MAAM,YACN,MAAM,QAwBhB;IAED;;;;;;;;;;;;;;OAcG;IACH,iBAbW,YAAY,KACZ,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QACN,MAAM,aACN,OAAO,cACP,gBAAgB,GAAC,iBAAiB,GAAC,IAAI,QAwIjD;CA8DD;wBA1kBoC,mBAAmB;kCAIzB,0BAA0B"}
|
|
@@ -8,17 +8,35 @@
|
|
|
8
8
|
* @category Rendering
|
|
9
9
|
*/
|
|
10
10
|
export class MaterialBatcher extends Batcher {
|
|
11
|
+
set currentTextureUnit(unit: number);
|
|
11
12
|
/**
|
|
12
|
-
*
|
|
13
|
+
* The GL texture unit currently active (`gl.activeTexture`). Tracked on
|
|
14
|
+
* the RENDERER, not per batcher: the active unit is global GL state
|
|
15
|
+
* shared by every batcher instance, and a per-batcher copy desyncs as
|
|
16
|
+
* soon as another batcher (or a blit, or an FBO pass) moves the active
|
|
17
|
+
* unit — the stale copy then lets `bindTexture2D` skip `gl.activeTexture`
|
|
18
|
+
* and bind (or upload) a texture onto whatever unit is REALLY active.
|
|
19
|
+
* Symptom was video force-re-uploads overwriting a mesh texture with
|
|
20
|
+
* video frames after a mesh pass.
|
|
21
|
+
* @type {number}
|
|
13
22
|
* @ignore
|
|
14
23
|
*/
|
|
15
|
-
currentTextureUnit:
|
|
24
|
+
get currentTextureUnit(): number;
|
|
16
25
|
/**
|
|
17
26
|
* bound textures by unit
|
|
18
27
|
* @ignore
|
|
19
28
|
*/
|
|
20
29
|
boundTextures: any[] | undefined;
|
|
21
30
|
_onCacheReset: (() => void) | null | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Drop every cached texture binding after a {@link GPU_TEXTURE_CACHE_RESET}
|
|
33
|
+
* (the shared texture cache reassigned units — our per-unit view is stale).
|
|
34
|
+
* Subclasses that pair extra samplers to units (lit normal maps) override to
|
|
35
|
+
* forget those too; without that they'd assume the extra texture is still
|
|
36
|
+
* resident and skip re-binding it after the reset.
|
|
37
|
+
* @ignore
|
|
38
|
+
*/
|
|
39
|
+
_onTextureCacheReset(): void;
|
|
22
40
|
/**
|
|
23
41
|
* Free resources used by the batcher. Currently unsubscribes the
|
|
24
42
|
* texture-cache-reset listener so a discarded batcher doesn't keep
|
|
@@ -64,6 +82,19 @@ export class MaterialBatcher extends Batcher {
|
|
|
64
82
|
* @returns {number} unit the unit number that was associated with the given texture
|
|
65
83
|
*/
|
|
66
84
|
unbindTexture2D(texture?: WebGLTexture, unit?: number): number;
|
|
85
|
+
/**
|
|
86
|
+
* Forget whatever texture this batcher believes is bound to `unit`, so the
|
|
87
|
+
* next bind to it re-issues the GL bind. Used when a GL texture unit is
|
|
88
|
+
* clobbered OUTSIDE this batcher's own accounting — e.g.
|
|
89
|
+
* {@link WebGLRenderer#toFrameTexture}, which binds its capture to a scratch
|
|
90
|
+
* unit directly (not via the shared texture cache), so a different batcher's
|
|
91
|
+
* unit cache would otherwise skip a needed re-bind. Subclasses that pair
|
|
92
|
+
* extra samplers to the same unit (lit normal maps) override to drop those
|
|
93
|
+
* too.
|
|
94
|
+
* @param {number} unit - the GL texture unit to invalidate
|
|
95
|
+
* @ignore
|
|
96
|
+
*/
|
|
97
|
+
invalidateUnit(unit: number): void;
|
|
67
98
|
/**
|
|
68
99
|
* @ignore
|
|
69
100
|
* @param {TextureAtlas|TextureResource} texture
|
|
@@ -73,8 +104,13 @@ export class MaterialBatcher extends Batcher {
|
|
|
73
104
|
* @param {number} [h] - same as `w`.
|
|
74
105
|
* @param {boolean} [force=false]
|
|
75
106
|
* @param {boolean} [flush=true]
|
|
107
|
+
* @param {string} [repeat] - per-use wrap-mode override (a mesh's
|
|
108
|
+
* `textureRepeat`, #1503) — sampled with this wrap without mutating
|
|
109
|
+
* the shared atlas's `repeat`. The texture-unit cache keys by
|
|
110
|
+
* `(source, repeat)`, so each wrap gets its own unit + GL texture.
|
|
111
|
+
* Omit to use `texture.repeat`.
|
|
76
112
|
*/
|
|
77
|
-
uploadTexture(texture: TextureAtlas | TextureResource, w?: number, h?: number, force?: boolean, flush?: boolean): any;
|
|
113
|
+
uploadTexture(texture: TextureAtlas | TextureResource, w?: number, h?: number, force?: boolean, flush?: boolean, repeat?: string): any;
|
|
78
114
|
}
|
|
79
115
|
import { Batcher } from "./batcher.js";
|
|
80
116
|
import type { TextureAtlas } from "./../../texture/atlas.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"material_batcher.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/batchers/material_batcher.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;;GAIG;AACH;
|
|
1
|
+
{"version":3,"file":"material_batcher.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/batchers/material_batcher.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;;GAIG;AACH;IA6EC,6BAPU,MAAM,EASf;IAlBD;;;;;;;;;;;OAWG;IACH,0BAHU,MAAM,CAKf;IA/DA;;;OAGG;IACH,iCAAuB;IAwBtB,+CAEC;IAKH;;;;;;;OAOG;IACH,6BAIC;IAsBD;;;;;;OAMG;IACH,gBAKC;IAmBD;;;;;;;;;;;OAWG;IACH,sBAVW,MAAM,WACN,8DAAM,iBAAiB,GAAC,SAAS,GAAC,UAAU,EAAE,GAAC,YAAY,EAAE,UAC7D,MAAM,WACN,MAAM,MACN,MAAM,MACN,MAAM,uBACN,OAAO,WACP,OAAO,kCACL,YAAY,CAmKxB;IAED;;;OAGG;IACH,yBAFW,YAAY,GAAC,YAAY,QAgCnC;IAED;;;;OAIG;IACH,mBAHW,MAAM,GACJ,YAAY,CAIxB;IAED;;;;OAIG;IACH,uBAHW,YAAY,QACZ,MAAM,yBAsBhB;IAED;;;;;OAKG;IACH,0BAJW,YAAY,SACZ,MAAM,GACJ,MAAM,CAalB;IAED;;;;;;;;;;;OAWG;IACH,qBAHW,MAAM,QAQhB;IAED;;;;;;;;;;;;;;OAcG;IACH,uBAbW,YAAY,GAAC,eAAe,MAC5B,MAAM,MAGN,MAAM,UACN,OAAO,UACP,OAAO,WACP,MAAM,OAsDhB;CACD;wBAzduB,cAAc;kCAIP,0BAA0B"}
|
|
@@ -33,7 +33,7 @@ export default class MeshBatcher extends MaterialBatcher {
|
|
|
33
33
|
currentEmissiveR: any;
|
|
34
34
|
currentEmissiveG: any;
|
|
35
35
|
currentEmissiveB: any;
|
|
36
|
-
_onTargetChanged: (() => void) | null | undefined;
|
|
36
|
+
_onTargetChanged: ((emitter: any) => void) | null | undefined;
|
|
37
37
|
/**
|
|
38
38
|
* The vertex attribute layout. The base (unlit) mesh batcher is
|
|
39
39
|
* `aVertex` (3) + `aRegion` (2) + `aColor` (4) = 9 floats. Subclasses
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mesh_batcher.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/batchers/mesh_batcher.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mesh_batcher.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/batchers/mesh_batcher.js"],"names":[],"mappings":"AAyFA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH;IACC;;;OAGG;IACH,0BAsCC;IA5BA,wBAA4B;IAI5B,sBAA0B;IAC1B,sBAA0B;IAC1B,sBAA0B;IAYzB,8DAOC;IAKH;;;;;OAKG;IACH;;;;;;QAgCC;IAED;;;;OAIG;IACH;;;MAEC;IAED;;;;;;;;;OASG;IACH,6BAWC;IAyDD;;;;;;;;;;;;;;;OAeG;IACH,wBAXW,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,SACN,MAAM,SACN,MAAM,OACN,MAAM,QAKhB;IAED;;;;;;;;;;;;;;OAcG;IACH,cAHW,MAAM,QACN,MAAM,QA+JhB;CACD;gCA3d+B,uBAAuB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitive_batcher.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/batchers/primitive_batcher.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;;GAIG;AACH;IACC;;;OAGG;IACH,0BAsCC;IALA;;;OAGG;IACH,sBAAyB;IA0B1B;;;;;OAKG;IACH,mBAJW,MAAM,SACN,KAAK,EAAE,gBACP,MAAM,
|
|
1
|
+
{"version":3,"file":"primitive_batcher.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/batchers/primitive_batcher.js"],"names":[],"mappings":"AAIA;;;GAGG;AAEH;;;;GAIG;AACH;IACC;;;OAGG;IACH,0BAsCC;IALA;;;OAGG;IACH,sBAAyB;IA0B1B;;;;;OAKG;IACH,mBAJW,MAAM,SACN,KAAK,EAAE,gBACP,MAAM,QAoDhB;;CAyMD;wBAjVuB,cAAc;2BAId,gCAAgC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quad_batcher.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/batchers/quad_batcher.js"],"names":[],"mappings":"AAMA;;;GAGG;AAUH,iCAKE;AAEF;;;;GAIG;AACH;IACC;;;OAGG;IACH,0BA0DC;IAzDA;;;;OAIG;IACH,qCAA0D;IA2C1D;;;;;OAKG;IACH,qCAA2B;IAK5B;;;;OAIG;IACH,
|
|
1
|
+
{"version":3,"file":"quad_batcher.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/batchers/quad_batcher.js"],"names":[],"mappings":"AAMA;;;GAGG;AAUH,iCAKE;AAEF;;;;GAIG;AACH;IACC;;;OAGG;IACH,0BA0DC;IAzDA;;;;OAIG;IACH,qCAA0D;IA2C1D;;;;;OAKG;IACH,qCAA2B;IAK5B;;;;OAIG;IACH,0BAcC;IAED;;;;OAIG;IACH,0BAIC;IAED;;;;;;;OAOG;IACH,kBAFW,QAAQ,GAAC,YAAY,QAK/B;IAyDD;;;;;;;;;;OAUG;IACH,oBAPW,YAAY,KACZ,MAAM,KACN,MAAM,SACN,MAAM,UACN,MAAM,UACN,QAAQ,GAAC,YAAY,QAkE/B;IAED;;;;;;;;;;;;;OAaG;IACH,iBAZW,YAAY,KACZ,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QACN,MAAM,aACN,OAAO,QAwEjB;CACD;yBAtWwB,2BAA2B;gCAIpB,uBAAuB;kCAIxB,0BAA0B"}
|
|
@@ -20,6 +20,19 @@ export default class WebGLIndexBuffer extends IndexBuffer {
|
|
|
20
20
|
* Bind this index buffer
|
|
21
21
|
*/
|
|
22
22
|
bind(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Replace the underlying GL buffer with a fresh one, deleting the old.
|
|
25
|
+
* Needed on context restore — the old buffer object belongs to the lost
|
|
26
|
+
* context and every upload through it would silently fail. Also keeps
|
|
27
|
+
* plain resets leak-free (`deleteBuffer` on a lost-context object is a
|
|
28
|
+
* harmless no-op).
|
|
29
|
+
*/
|
|
30
|
+
recreate(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Delete the underlying GL buffer. The index buffer must not be used
|
|
33
|
+
* after calling destroy.
|
|
34
|
+
*/
|
|
35
|
+
destroy(): void;
|
|
23
36
|
}
|
|
24
37
|
import IndexBuffer from "../../buffer/index.js";
|
|
25
38
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/buffer/index.js"],"names":[],"mappings":"AAEA;;;GAGG;AAEH;IACC;;;;OAIG;IACH,gBAJW,qBAAqB,GAAC,sBAAsB,cAC5C,MAAM,cACN,OAAO,EAOjB;IAHA,mDAAY;IACZ,kBAA2D;IAC3D,oBAA+B;IAiBhC;;OAEG;IACH,eAOC;IAED;;OAEG;IACH,aAEC;CACD;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/buffer/index.js"],"names":[],"mappings":"AAEA;;;GAGG;AAEH;IACC;;;;OAIG;IACH,gBAJW,qBAAqB,GAAC,sBAAsB,cAC5C,MAAM,cACN,OAAO,EAOjB;IAHA,mDAAY;IACZ,kBAA2D;IAC3D,oBAA+B;IAiBhC;;OAEG;IACH,eAOC;IAED;;OAEG;IACH,aAEC;IAED;;;;;;OAMG;IACH,iBAIC;IAED;;;OAGG;IACH,gBAGC;CACD;wBA1EuB,uBAAuB"}
|
|
@@ -22,11 +22,6 @@ export default class HologramEffect extends ShaderEffect {
|
|
|
22
22
|
color?: number[] | undefined;
|
|
23
23
|
intensity?: number | undefined;
|
|
24
24
|
});
|
|
25
|
-
/**
|
|
26
|
-
* set the current time (call each frame for animation)
|
|
27
|
-
* @param {number} time - time in seconds
|
|
28
|
-
*/
|
|
29
|
-
setTime(time: number): void;
|
|
30
25
|
/**
|
|
31
26
|
* set the hologram tint color
|
|
32
27
|
* @param {number[]} color - color as [r, g, b] (0.0–1.0)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hologram.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/effects/hologram.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH;IACC;;;;;OAKG;IACH,sBALW,OAAO,sBAAsB,EAAE,OAAO,YAE9C;QAA2B,KAAK;QACP,SAAS;KACpC,EAyBA;IAED;;;OAGG;IACH,
|
|
1
|
+
{"version":3,"file":"hologram.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/effects/hologram.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH;IACC;;;;;OAKG;IACH,sBALW,OAAO,sBAAsB,EAAE,OAAO,YAE9C;QAA2B,KAAK;QACP,SAAS;KACpC,EAyBA;IAED;;;OAGG;IACH,gBAFW,MAAM,EAAE,QAIlB;CACD;yBAvDwB,oBAAoB"}
|
|
@@ -57,11 +57,6 @@ export default class ShineEffect extends ShaderEffect {
|
|
|
57
57
|
pulseDepth?: number | undefined;
|
|
58
58
|
pulseSpeed?: number | undefined;
|
|
59
59
|
});
|
|
60
|
-
/**
|
|
61
|
-
* set the current time (call each frame for animation)
|
|
62
|
-
* @param {number} time - time in seconds
|
|
63
|
-
*/
|
|
64
|
-
setTime(time: number): void;
|
|
65
60
|
/**
|
|
66
61
|
* set the shine color
|
|
67
62
|
* @param {number[]} color - shine color as [r, g, b] (0.0–1.0)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shine.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/effects/shine.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH;IACC;;;;;;;;;;;OAWG;IACH,sBAXW,OAAO,sBAAsB,EAAE,OAAO,YAE9C;QAA2B,KAAK;QACP,KAAK;QACL,KAAK;QACL,SAAS;QACT,KAAK;QACL,KAAK;QACL,UAAU;QACV,UAAU;KACrC,EAuDA;IAED;;;OAGG;IACH,
|
|
1
|
+
{"version":3,"file":"shine.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/effects/shine.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH;IACC;;;;;;;;;;;OAWG;IACH,sBAXW,OAAO,sBAAsB,EAAE,OAAO,YAE9C;QAA2B,KAAK;QACP,KAAK;QACL,KAAK;QACL,SAAS;QACT,KAAK;QACL,KAAK;QACL,UAAU;QACV,UAAU;KACrC,EAuDA;IAED;;;OAGG;IACH,gBAFW,MAAM,EAAE,QAIlB;IAED;;;OAGG;IACH,gBAFW,MAAM,QAIhB;IAED;;;OAGG;IACH,oBAFW,MAAM,QAIhB;IAED;;;OAGG;IACH,gBAFW,MAAM,QAIhB;CACD;yBA1IwB,oBAAoB"}
|
|
@@ -45,6 +45,17 @@ export default class GLShader {
|
|
|
45
45
|
* @readonly
|
|
46
46
|
*/
|
|
47
47
|
readonly destroyed: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* When `true`, a renderable will NOT auto-destroy this shader when it is
|
|
50
|
+
* removed from its `postEffects` (via the `shader` setter,
|
|
51
|
+
* `removePostEffect`, `clearPostEffects`) or when the renderable itself
|
|
52
|
+
* is destroyed. Set this on a shader shared across several renderables so
|
|
53
|
+
* one of them going away doesn't free the GL program still used by the
|
|
54
|
+
* others — you then own its lifecycle and call {@link destroy} yourself.
|
|
55
|
+
* @type {boolean}
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
shared: boolean;
|
|
48
59
|
/**
|
|
49
60
|
* `true` while the WebGL context is lost (and until it's
|
|
50
61
|
* restored). The GL program/attributes/uniforms are released
|
|
@@ -113,6 +124,24 @@ export default class GLShader {
|
|
|
113
124
|
* @param {number} stride - the size of a single vertex in bytes
|
|
114
125
|
*/
|
|
115
126
|
setVertexAttributes(gl: WebGLRenderingContext, attributes: object[], stride: number): void;
|
|
127
|
+
/**
|
|
128
|
+
* Create an independent copy of this shader, compiled as its own GL
|
|
129
|
+
* program from the same vertex + fragment sources (and precision), with
|
|
130
|
+
* every uniform value set so far replayed onto the copy. Use it when
|
|
131
|
+
* several renderables need the same custom shader with *different*
|
|
132
|
+
* uniform values — a single instance has a single set of uniforms.
|
|
133
|
+
*
|
|
134
|
+
* Ownership and lifecycle state do NOT carry over: the clone's
|
|
135
|
+
* {@link shared} flag is **always reset to `false`**, even when cloning
|
|
136
|
+
* a shared shader — the clone is caller-owned and will be auto-destroyed
|
|
137
|
+
* by the renderable it is assigned to, unless you explicitly set
|
|
138
|
+
* `shared = true` on it yourself. Note that `ShaderEffect` (which wraps
|
|
139
|
+
* a GLShader by composition) has its own `clone()` with the same
|
|
140
|
+
* semantics, which additionally copies its effect-level state (extra
|
|
141
|
+
* `setTexture` bindings).
|
|
142
|
+
* @returns {GLShader} a new, caller-owned shader (`shared === false`)
|
|
143
|
+
*/
|
|
144
|
+
clone(): GLShader;
|
|
116
145
|
/**
|
|
117
146
|
* destroy this shader objects resources (program, attributes, uniforms).
|
|
118
147
|
* Idempotent — calling destroy twice (or after a context-lost suspend)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glshader.d.ts","sourceRoot":"","sources":["../../../src/video/webgl/glshader.js"],"names":[],"mappings":"AAYA;;;GAGG;AACH;IACC;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,gBA1BW,qBAAqB,UACrB,MAAM,YACN,MAAM,cACN,MAAM,
|
|
1
|
+
{"version":3,"file":"glshader.d.ts","sourceRoot":"","sources":["../../../src/video/webgl/glshader.js"],"names":[],"mappings":"AAYA;;;GAGG;AACH;IACC;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,gBA1BW,qBAAqB,UACrB,MAAM,YACN,MAAM,cACN,MAAM,EAqFhB;IA7DA;;;OAGG;IACH,IAFU,qBAAqB,CAEnB;IAEZ;;;;;;;OAOG;IACH,oBAHU,OAAO,CAGK;IAEtB;;;;;;;;;OASG;IACH,QAHU,OAAO,CAGE;IAEnB;;;;;;;;;;OAUG;IACH,oBAHU,OAAO,CAGK;IAGtB,sBAA2B;IAC3B,wBAA+B;IAC/B,+BAA2B;IAG3B,mBAAwC;IAKvC,sBAAmB;IACnB,iBAAoB;IACpB,qBAAsB;IASxB;;;;;;OAMG;IACH,iBA0CC;IAzCA,YAGC;IACD,cAGC;IAoCF;;;;;OAKG;IACH,uBAgBC;IAED;;;;;OAKG;IACH,2BAMC;IAED;;OAEG;IACH,aAKC;IAED;;;;OAIG;IACH,wBAHW,MAAM,GACJ,KAAK,CAYjB;IAED;;;;;;OAMG;IACH,iBALW,MAAM,SACN,MAAM,GAAC,YAAY,QA0C7B;IAED;;;;;OAKG;IACH,wBAJW,qBAAqB,cACrB,MAAM,EAAE,UACR,MAAM,QAmBhB;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,SAFa,QAAQ,CAyBpB;IAED;;;;;OAKG;IACH,gBA2BC;CACD"}
|
|
@@ -24,6 +24,23 @@
|
|
|
24
24
|
* mySprite.shader = pulse;
|
|
25
25
|
* // update the uniform each frame
|
|
26
26
|
* pulse.setUniform("uTime", time);
|
|
27
|
+
* @example
|
|
28
|
+
* // Shader builtins — no JS plumbing, no UV math:
|
|
29
|
+
* // `: screen_texture` keeps the sampler filled with everything drawn so
|
|
30
|
+
* // far (a back-buffer copy; one screen copy per draw of the effect),
|
|
31
|
+
* // `screen_uv` is this fragment's 0..1 screen position, and `noise_uv`
|
|
32
|
+
* // runs 0..1 across the sprite regardless of its atlas frame.
|
|
33
|
+
* const water = new ShaderEffect(renderer, `
|
|
34
|
+
* uniform sampler2D uNoise;
|
|
35
|
+
* uniform sampler2D screenTex : screen_texture;
|
|
36
|
+
* uniform float uTime;
|
|
37
|
+
* vec4 apply(vec4 color, vec2 uv) {
|
|
38
|
+
* vec2 flow = texture2D(uNoise, noise_uv + uTime * 0.25).rg;
|
|
39
|
+
* vec4 refracted = texture2D(screenTex, screen_uv + flow * 0.005);
|
|
40
|
+
* return refracted * texture2D(uSampler, uv + flow * 0.005);
|
|
41
|
+
* }
|
|
42
|
+
* `);
|
|
43
|
+
* water.setTexture("uNoise", noiseTexture.getTexture(), "repeat");
|
|
27
44
|
*/
|
|
28
45
|
export default class ShaderEffect {
|
|
29
46
|
/**
|
|
@@ -51,8 +68,56 @@ export default class ShaderEffect {
|
|
|
51
68
|
* @readonly
|
|
52
69
|
*/
|
|
53
70
|
readonly destroyed: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* When `true`, a renderable will NOT auto-destroy this effect when it is
|
|
73
|
+
* removed from its `postEffects` (via the `shader` setter,
|
|
74
|
+
* {@link Renderable#removePostEffect}, {@link Renderable#clearPostEffects})
|
|
75
|
+
* or when the renderable itself is destroyed. Set this on an effect shared
|
|
76
|
+
* across several renderables so one of them going away doesn't free the GL
|
|
77
|
+
* program still used by the others — you then own its lifecycle and call
|
|
78
|
+
* {@link destroy} yourself.
|
|
79
|
+
* @type {boolean}
|
|
80
|
+
* @default false
|
|
81
|
+
*/
|
|
82
|
+
shared: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* the renderer this effect was created for — kept so destroy and
|
|
85
|
+
* context-loss can release the texture units reserved on its cache
|
|
86
|
+
* for extra samplers ({@link setTexture}), and so {@link clone} can
|
|
87
|
+
* compile an independent copy
|
|
88
|
+
* @ignore
|
|
89
|
+
*/
|
|
90
|
+
_renderer: any;
|
|
91
|
+
/**
|
|
92
|
+
* the construction "recipe" (fragment body + precision), kept so
|
|
93
|
+
* {@link clone} can compile an independent copy. Stored before the
|
|
94
|
+
* Canvas-mode early return so cloning behaves consistently there too.
|
|
95
|
+
* @ignore
|
|
96
|
+
*/
|
|
97
|
+
_fragmentBody: string;
|
|
98
|
+
/** @ignore */
|
|
99
|
+
_precision: string | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* samplers annotated `: screen_texture` — the renderer checks this to
|
|
102
|
+
* know when to refresh the shared frame capture before the effect draws
|
|
103
|
+
* @type {Array<{name: string, repeat: string}>}
|
|
104
|
+
* @ignore
|
|
105
|
+
*/
|
|
106
|
+
_screenTextureUniforms: Array<{
|
|
107
|
+
name: string;
|
|
108
|
+
repeat: string;
|
|
109
|
+
}>;
|
|
110
|
+
/** @ignore */
|
|
111
|
+
_hasNoiseUV: boolean | undefined;
|
|
54
112
|
/** @ignore */
|
|
55
113
|
_shader: GLShader | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* extra texture samplers bound via {@link setTexture}, keyed by the
|
|
116
|
+
* uniform name → `{ image, repeat, tex }` (`tex` is the uploaded GL
|
|
117
|
+
* texture, created lazily on first draw)
|
|
118
|
+
* @ignore
|
|
119
|
+
*/
|
|
120
|
+
_extraTextures: Map<any, any> | undefined;
|
|
56
121
|
/** @private */
|
|
57
122
|
private _onContextLost;
|
|
58
123
|
_enabledBeforeSuspend: boolean | undefined;
|
|
@@ -64,6 +129,123 @@ export default class ShaderEffect {
|
|
|
64
129
|
* @param {object|Float32Array} value - the value to assign to that uniform
|
|
65
130
|
*/
|
|
66
131
|
setUniform(name: string, value: object | Float32Array): void;
|
|
132
|
+
/**
|
|
133
|
+
* Set the shader's `uTime` uniform (elapsed time, in seconds). A convenience
|
|
134
|
+
* over `setUniform("uTime", ...)`; call it once per frame from your update
|
|
135
|
+
* loop to animate a shader that declares `uniform float uTime` (e.g. scrolling
|
|
136
|
+
* a static noise texture's UVs, pulsing, waving). Drive it with whatever clock
|
|
137
|
+
* you like — real time, a paused/scaled/scrubbed one.
|
|
138
|
+
*
|
|
139
|
+
* No-op if the shader does not declare a `uTime` uniform (nothing to update),
|
|
140
|
+
* or in Canvas mode. The engine does NOT call this for you — animation is
|
|
141
|
+
* opt-in, exactly like re-baking a {@link NoiseTexture2d} with `update(dt)`.
|
|
142
|
+
* @param {number} seconds - elapsed time in seconds
|
|
143
|
+
* @returns {ShaderEffect} this effect for chaining
|
|
144
|
+
* @example
|
|
145
|
+
* // a shader that scrolls a static seamless noise texture over time
|
|
146
|
+
* const flow = new me.ShaderEffect(renderer, `
|
|
147
|
+
* uniform float uTime;
|
|
148
|
+
* vec4 apply(vec4 color, vec2 uv) {
|
|
149
|
+
* return texture2D(uSampler, uv + vec2(uTime * 0.05, 0.0));
|
|
150
|
+
* }`);
|
|
151
|
+
* mySprite.shader = flow;
|
|
152
|
+
* // then in your Stage's update(dt):
|
|
153
|
+
* flow.setTime(me.timer.getTime() / 1000);
|
|
154
|
+
*/
|
|
155
|
+
setTime(seconds: number): ShaderEffect;
|
|
156
|
+
/**
|
|
157
|
+
* Feed the `noise_uv` builtin's frame rect for the object about to draw:
|
|
158
|
+
* the source texture dimensions, the destination (object) dimensions, and
|
|
159
|
+
* the frame's top-left UV origin. Called by the quad batchers per draw;
|
|
160
|
+
* a no-op unless this effect's fragment actually uses `noise_uv` (the
|
|
161
|
+
* `ME_*` uniforms only exist — and are only active — then).
|
|
162
|
+
* @param {number} sourceWidth - source texture width in pixels
|
|
163
|
+
* @param {number} sourceHeight - source texture height in pixels
|
|
164
|
+
* @param {number} objectWidth - destination (object) width in pixels
|
|
165
|
+
* @param {number} objectHeight - destination (object) height in pixels
|
|
166
|
+
* @param {number} u0 - the frame's left UV coordinate (flip-normalized)
|
|
167
|
+
* @param {number} v0 - the frame's top UV coordinate (flip-normalized)
|
|
168
|
+
* @ignore
|
|
169
|
+
*/
|
|
170
|
+
_setNoiseUVRect(sourceWidth: number, sourceHeight: number, objectWidth: number, objectHeight: number, u0: number, v0: number): void;
|
|
171
|
+
/**
|
|
172
|
+
* Apply the wrap mode a `: screen_texture(<repeat>)` annotation asked for
|
|
173
|
+
* onto the live capture handle. Captures are NPOT (canvas-sized), which
|
|
174
|
+
* WebGL 1 cannot repeat — warn once and keep the clamp there. The unit is
|
|
175
|
+
* force-activated first: the batcher's bind may have been skipped as
|
|
176
|
+
* redundant while the GL active unit points elsewhere.
|
|
177
|
+
* @ignore
|
|
178
|
+
*/
|
|
179
|
+
_applyCaptureWrap(batcher: any, glTex: any, entry: any): void;
|
|
180
|
+
_captureWrapWarned: boolean | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* Bind an **extra** texture to a named `sampler2D` uniform in this shader, so
|
|
183
|
+
* a custom effect can read a *second* texture — a noise map, mask, gradient,
|
|
184
|
+
* flow/lookup table — besides the sprite/target it post-processes (`uSampler`).
|
|
185
|
+
* The engine uploads, caches, and re-binds it to a reserved texture unit each
|
|
186
|
+
* time the effect draws, and points the sampler uniform at it — no raw WebGL
|
|
187
|
+
* texture-unit juggling.
|
|
188
|
+
*
|
|
189
|
+
* Declare the sampler in your fragment (`uniform sampler2D <name>;`) and pass
|
|
190
|
+
* that name here. Any engine texture works — a {@link Texture2d} asset
|
|
191
|
+
* (`NoiseTexture2d`, `TextureAtlas`, …) can be passed directly, or a raw
|
|
192
|
+
* drawable source. No-op in Canvas mode.
|
|
193
|
+
* @param {string} name - the `sampler2D` uniform name declared in the fragment
|
|
194
|
+
* @param {Texture2d|HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap} image - the texture: an engine texture asset, or a raw drawable source
|
|
195
|
+
* @param {"repeat"|"repeat-x"|"repeat-y"|"no-repeat"} [repeat="no-repeat"] - wrap mode; use `"repeat"` for a tiled/scrolled texture (power-of-two size under WebGL 1)
|
|
196
|
+
* @returns {ShaderEffect} this effect for chaining
|
|
197
|
+
* @example
|
|
198
|
+
* // "water": distort the sprite by a static noise texture scrolled over time
|
|
199
|
+
* const noise = new me.NoiseTexture2d({ width: 256, height: 256, seamless: true });
|
|
200
|
+
* const water = new me.ShaderEffect(renderer, `
|
|
201
|
+
* uniform sampler2D uNoise;
|
|
202
|
+
* uniform float uTime;
|
|
203
|
+
* vec4 apply(vec4 color, vec2 uv) {
|
|
204
|
+
* vec2 flow = texture2D(uNoise, uv + uTime * 0.03).rg - 0.5;
|
|
205
|
+
* return texture2D(uSampler, uv + flow * 0.02);
|
|
206
|
+
* }`);
|
|
207
|
+
* water.setTexture("uNoise", noise, "repeat");
|
|
208
|
+
* waterSprite.shader = water;
|
|
209
|
+
* // each frame, in your Stage's update(dt):
|
|
210
|
+
* water.setTime(me.timer.getTime() / 1000);
|
|
211
|
+
*/
|
|
212
|
+
setTexture(name: string, image: Texture2d | HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap, repeat?: "repeat" | "repeat-x" | "repeat-y" | "no-repeat"): ShaderEffect;
|
|
213
|
+
/**
|
|
214
|
+
* (Re)bind this effect's extra textures ({@link setTexture}) to reserved GL
|
|
215
|
+
* texture units and point their sampler uniforms at them. Called by the
|
|
216
|
+
* renderer right after this effect's shader is bound — for both the
|
|
217
|
+
* post-effect blit and the single-effect `customShader` sprite path — so the
|
|
218
|
+
* bindings survive the batcher's rotating color-texture pool.
|
|
219
|
+
* @param {object} batcher - the active batcher (owns the GL texture units)
|
|
220
|
+
* @ignore
|
|
221
|
+
*/
|
|
222
|
+
_prepareTextures(batcher: object): void;
|
|
223
|
+
_textureOverflowWarned: boolean | undefined;
|
|
224
|
+
/**
|
|
225
|
+
* Create an independent copy of this effect, compiled as its own GL
|
|
226
|
+
* program. Use it when several renderables need the same effect with
|
|
227
|
+
* *different* uniform values — a single instance has a single set of
|
|
228
|
+
* uniforms, shared by everything it is assigned to.
|
|
229
|
+
*
|
|
230
|
+
* The clone copies the **recipe**: the fragment source, float precision,
|
|
231
|
+
* every uniform value set so far, and any extra textures bound via
|
|
232
|
+
* {@link setTexture} (the clone uploads and owns its own GL copies).
|
|
233
|
+
* It does NOT copy **ownership or lifecycle** state — in particular the
|
|
234
|
+
* clone's {@link shared} flag is **always reset to `false`**, even when
|
|
235
|
+
* cloning a shared shader (such as one returned by `loader.getShader()`):
|
|
236
|
+
* the clone is caller-owned and will be auto-destroyed by the renderable
|
|
237
|
+
* it is assigned to, exactly like a hand-constructed effect. Set
|
|
238
|
+
* `shared = true` on the clone yourself if you intend to reuse it across
|
|
239
|
+
* several renderables.
|
|
240
|
+
* @returns {ShaderEffect} a new, caller-owned effect (`shared === false`)
|
|
241
|
+
* @example
|
|
242
|
+
* // the loader's shader is ONE shared program — one uniform state for all
|
|
243
|
+
* sprite.shader = loader.getShader("flash");
|
|
244
|
+
* // the boss needs its own intensity — clone a private, caller-owned copy
|
|
245
|
+
* boss.shader = loader.getShader("flash").clone();
|
|
246
|
+
* boss.shader.setUniform("uIntensity", 0.9);
|
|
247
|
+
*/
|
|
248
|
+
clone(): ShaderEffect;
|
|
67
249
|
/** @ignore */
|
|
68
250
|
bind(): void;
|
|
69
251
|
/** @ignore */
|
|
@@ -88,4 +270,5 @@ export default class ShaderEffect {
|
|
|
88
270
|
destroy(): void;
|
|
89
271
|
}
|
|
90
272
|
import GLShader from "./glshader.js";
|
|
273
|
+
import Texture2d from "../texture/texture2d.ts";
|
|
91
274
|
//# sourceMappingURL=shadereffect.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadereffect.d.ts","sourceRoot":"","sources":["../../../src/video/webgl/shadereffect.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shadereffect.d.ts","sourceRoot":"","sources":["../../../src/video/webgl/shadereffect.js"],"names":[],"mappings":"AAoHA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH;IAiCC;;;;;;OAMG;IACH,sBANW,aAAa,GAAC,cAAc,gBAC5B,MAAM,cAGN,MAAM,EAyFhB;IA9HD;;;;;;OAMG;IACH,SAFU,OAAO,CAED;IAEhB;;;;;;;OAOG;IACH,oBAHU,OAAO,CAGC;IAElB;;;;;;;;;;OAUG;IACH,QAHU,OAAO,CAGF;IAUd;;;;;;OAMG;IACH,eAAyB;IAEzB;;;;;OAKG;IACH,sBAAiC;IACjC,cAAc;IACd,+BAA2B;IAc3B;;;;;OAKG;IACH,wBAHU,KAAK,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,CAAC,CAGM;IACrD,cAAc;IACd,iCAAmC;IAgBnC,cAAc;IACd,8BAKC;IAGD;;;;;OAKG;IACH,0CAA+B;IAkBhC,eAAe;IACf,uBAkBC;IAbA,2CAAyC;IAe1C,eAAe;IACf,2BAQC;IAED;;;;OAIG;IACH,iBAHW,MAAM,SACN,MAAM,GAAC,YAAY,QAY7B;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,iBAbW,MAAM,GACJ,YAAY,CA+BxB;IAED;;;;;;;;;;;;;OAaG;IACH,6BARW,MAAM,gBACN,MAAM,eACN,MAAM,gBACN,MAAM,MACN,MAAM,MACN,MAAM,QAyChB;IAED;;;;;;;OAOG;IACH,8DAwBC;IApBE,wCAA8B;IAsBjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,iBAnBW,MAAM,SACN,SAAS,GAAC,gBAAgB,GAAC,iBAAiB,GAAC,eAAe,GAAC,WAAW,WACxE,QAAQ,GAAC,UAAU,GAAC,UAAU,GAAC,WAAW,GACxC,YAAY,CA8DxB;IAED;;;;;;;;OAQG;IACH,0BAHW,MAAM,QAuFhB;IA3DI,4CAAkC;IA6DvC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,SARa,YAAY,CA0CxB;IAED,cAAc;IACd,aAIC;IAED,cAAc;IACd,qCAEC;IAED,cAAc;IACd,iEAIC;IAED,cAAc;IACd,mCAEC;IAED,cAAc;IACd,kBAEC;IAED,cAAc;IACd,oBAEC;IAED,cAAc;IACd,qBAEC;IAED,cAAc;IACd,uBAEC;IAED;;;;OAIG;IACH,gBA4BC;CACD;qBAvwBoB,eAAe;sBADd,yBAAyB"}
|