@babylonjs/lite-gl 1.15.0 → 1.16.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 +82 -1
- package/context.js +8 -8
- package/context.js.map +1 -1
- package/dynamic-texture.js +1 -1
- package/dynamic-texture.js.map +1 -1
- package/effect-ready.d.ts +20 -0
- package/effect-ready.js +94 -0
- package/effect-ready.js.map +1 -0
- package/effect.d.ts +11 -4
- package/effect.js +52 -39
- package/effect.js.map +1 -1
- package/html-texture.d.ts +2 -1
- package/html-texture.js +3 -2
- package/html-texture.js.map +1 -1
- package/index.d.ts +5 -1
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/mesh.d.ts +4 -3
- package/mesh.js +9 -5
- package/mesh.js.map +1 -1
- package/package.json +3 -3
- package/shader.d.ts +10 -8
- package/shader.js +18 -15
- package/shader.js.map +1 -1
- package/state.d.ts +1 -0
- package/state.js.map +1 -1
- package/texture-3d.d.ts +3 -1
- package/texture-3d.js +5 -6
- package/texture-3d.js.map +1 -1
- package/texture-source.d.ts +61 -0
- package/texture-source.js +165 -0
- package/texture-source.js.map +1 -0
- package/texture.d.ts +5 -1
- package/texture.js +8 -7
- package/texture.js.map +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { GLEngineContext } from "./context.js";
|
|
2
|
+
import { type GLTexture, type GLTextureOptions } from "./texture.js";
|
|
3
|
+
/** Upload and sampling options for {@link createTextureFromSource}. */
|
|
4
|
+
export interface GLTextureSourceOptions extends Omit<GLTextureOptions, "internalFormat"> {
|
|
5
|
+
/**
|
|
6
|
+
* Keep the source for automatic context-restore replay. Default true.
|
|
7
|
+
* With false, release the reference after upload and restore transparent
|
|
8
|
+
* black at the original size instead; the caller must recreate content
|
|
9
|
+
* (for example from an `onContextRestored` callback).
|
|
10
|
+
*/
|
|
11
|
+
retainSource?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create an immediately ready RGBA 2D texture from already-decoded pixels with
|
|
15
|
+
* one source upload, no placeholder or blank pre-allocation. Sampling defaults
|
|
16
|
+
* to linear filtering and clamp-to-edge wrapping; mipmaps are a separate opt-in
|
|
17
|
+
* via `generateTextureMipMaps`.
|
|
18
|
+
*
|
|
19
|
+
* The source is retained for context restoration by default. Keep it usable
|
|
20
|
+
* while the texture is live; mutable sources replay their current content and
|
|
21
|
+
* intrinsic size. If a retained source has become unusable by restore time
|
|
22
|
+
* (for example a closed `ImageBitmap`), the error is logged, the source is
|
|
23
|
+
* dropped and the texture restores transparent black at its last uploaded size
|
|
24
|
+
* so the rest of the engine still restores. With `retainSource: false`, the
|
|
25
|
+
* source reference is dropped after upload and restoration creates a ready,
|
|
26
|
+
* transparent-black texture at the original size; re-upload content from an
|
|
27
|
+
* `onContextRestored` callback. This function never closes a bitmap or video
|
|
28
|
+
* frame.
|
|
29
|
+
*
|
|
30
|
+
* Restoration replays level 0 and the sampling parameters only. When using a
|
|
31
|
+
* mipmapped `minFilter`, call `generateTextureMipMaps` after creation and
|
|
32
|
+
* again from an `onContextRestored` callback, otherwise the restored texture
|
|
33
|
+
* is mipmap-incomplete and samples black.
|
|
34
|
+
*
|
|
35
|
+
* WebGL ignores unpack flip/premultiplication for `ImageBitmap`; select
|
|
36
|
+
* `imageOrientation` / `premultiplyAlpha` when decoding those sources instead.
|
|
37
|
+
*
|
|
38
|
+
* The texture is immutable from the API's point of view: to change its pixels,
|
|
39
|
+
* dispose it and create a new one. Do not pass it to `updateDynamicTexture`
|
|
40
|
+
* (the new source would be ignored) or `updateHtmlElementTexture` (it would
|
|
41
|
+
* run the context-restore replay on the live texture).
|
|
42
|
+
*
|
|
43
|
+
* Image elements are sized from `naturalWidth` / `naturalHeight`. For SVG
|
|
44
|
+
* images and density-selected (`srcset` / `x` descriptor) images, WebGL may
|
|
45
|
+
* upload a different pixel size, so the reported and restored dimensions can
|
|
46
|
+
* be wrong; convert those to an `ImageBitmap` (`createImageBitmap`) first.
|
|
47
|
+
* Video elements must have a decoded current frame (`readyState >= 2`,
|
|
48
|
+
* `HAVE_CURRENT_DATA`); positive metadata dimensions alone are insufficient.
|
|
49
|
+
*
|
|
50
|
+
* @param engine - The live engine that will own the texture.
|
|
51
|
+
* @param source - An ImageBitmap, ImageData (with an attached buffer), canvas,
|
|
52
|
+
* OffscreenCanvas, decoded raster image, video with a decoded current frame,
|
|
53
|
+
* or VideoFrame with positive intrinsic dimensions.
|
|
54
|
+
* @param options - Unpack and sampling overrides; defaults are invertY false,
|
|
55
|
+
* premultiplyAlpha false, unpackAlignment 4 and retainSource true.
|
|
56
|
+
* @returns A managed texture disposed with {@link disposeTexture}.
|
|
57
|
+
* @throws If the engine is lost/disposed, dimensions exceed the texture limit
|
|
58
|
+
* or are not positive integers, the source is detached or has no decoded
|
|
59
|
+
* current frame, unpack alignment is invalid, or allocation fails.
|
|
60
|
+
*/
|
|
61
|
+
export declare function createTextureFromSource(engine: GLEngineContext, source: TexImageSource, options?: GLTextureSourceOptions): GLTexture;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { bindTextureForUpload, disposeTexture, setBoundTextureParams, setUnpackState } from "./texture.js";
|
|
2
|
+
/**
|
|
3
|
+
* Create an immediately ready RGBA 2D texture from already-decoded pixels with
|
|
4
|
+
* one source upload, no placeholder or blank pre-allocation. Sampling defaults
|
|
5
|
+
* to linear filtering and clamp-to-edge wrapping; mipmaps are a separate opt-in
|
|
6
|
+
* via `generateTextureMipMaps`.
|
|
7
|
+
*
|
|
8
|
+
* The source is retained for context restoration by default. Keep it usable
|
|
9
|
+
* while the texture is live; mutable sources replay their current content and
|
|
10
|
+
* intrinsic size. If a retained source has become unusable by restore time
|
|
11
|
+
* (for example a closed `ImageBitmap`), the error is logged, the source is
|
|
12
|
+
* dropped and the texture restores transparent black at its last uploaded size
|
|
13
|
+
* so the rest of the engine still restores. With `retainSource: false`, the
|
|
14
|
+
* source reference is dropped after upload and restoration creates a ready,
|
|
15
|
+
* transparent-black texture at the original size; re-upload content from an
|
|
16
|
+
* `onContextRestored` callback. This function never closes a bitmap or video
|
|
17
|
+
* frame.
|
|
18
|
+
*
|
|
19
|
+
* Restoration replays level 0 and the sampling parameters only. When using a
|
|
20
|
+
* mipmapped `minFilter`, call `generateTextureMipMaps` after creation and
|
|
21
|
+
* again from an `onContextRestored` callback, otherwise the restored texture
|
|
22
|
+
* is mipmap-incomplete and samples black.
|
|
23
|
+
*
|
|
24
|
+
* WebGL ignores unpack flip/premultiplication for `ImageBitmap`; select
|
|
25
|
+
* `imageOrientation` / `premultiplyAlpha` when decoding those sources instead.
|
|
26
|
+
*
|
|
27
|
+
* The texture is immutable from the API's point of view: to change its pixels,
|
|
28
|
+
* dispose it and create a new one. Do not pass it to `updateDynamicTexture`
|
|
29
|
+
* (the new source would be ignored) or `updateHtmlElementTexture` (it would
|
|
30
|
+
* run the context-restore replay on the live texture).
|
|
31
|
+
*
|
|
32
|
+
* Image elements are sized from `naturalWidth` / `naturalHeight`. For SVG
|
|
33
|
+
* images and density-selected (`srcset` / `x` descriptor) images, WebGL may
|
|
34
|
+
* upload a different pixel size, so the reported and restored dimensions can
|
|
35
|
+
* be wrong; convert those to an `ImageBitmap` (`createImageBitmap`) first.
|
|
36
|
+
* Video elements must have a decoded current frame (`readyState >= 2`,
|
|
37
|
+
* `HAVE_CURRENT_DATA`); positive metadata dimensions alone are insufficient.
|
|
38
|
+
*
|
|
39
|
+
* @param engine - The live engine that will own the texture.
|
|
40
|
+
* @param source - An ImageBitmap, ImageData (with an attached buffer), canvas,
|
|
41
|
+
* OffscreenCanvas, decoded raster image, video with a decoded current frame,
|
|
42
|
+
* or VideoFrame with positive intrinsic dimensions.
|
|
43
|
+
* @param options - Unpack and sampling overrides; defaults are invertY false,
|
|
44
|
+
* premultiplyAlpha false, unpackAlignment 4 and retainSource true.
|
|
45
|
+
* @returns A managed texture disposed with {@link disposeTexture}.
|
|
46
|
+
* @throws If the engine is lost/disposed, dimensions exceed the texture limit
|
|
47
|
+
* or are not positive integers, the source is detached or has no decoded
|
|
48
|
+
* current frame, unpack alignment is invalid, or allocation fails.
|
|
49
|
+
*/
|
|
50
|
+
export function createTextureFromSource(engine, source, options = {}) {
|
|
51
|
+
if (engine._isLost || engine._disposed) {
|
|
52
|
+
throw new Error("lite-gl: cannot create a source texture on a lost or disposed engine");
|
|
53
|
+
}
|
|
54
|
+
const [width, height] = sourceSize(engine, source);
|
|
55
|
+
const alignment = options.unpackAlignment ?? 4;
|
|
56
|
+
if (alignment !== 1 && alignment !== 2 && alignment !== 4 && alignment !== 8) {
|
|
57
|
+
throw new Error("lite-gl: texture unpackAlignment must be 1, 2, 4 or 8");
|
|
58
|
+
}
|
|
59
|
+
const gl = engine.gl;
|
|
60
|
+
const minFilter = options.minFilter ?? gl.LINEAR;
|
|
61
|
+
const magFilter = options.magFilter ?? gl.LINEAR;
|
|
62
|
+
const wrapS = options.wrapS ?? gl.CLAMP_TO_EDGE;
|
|
63
|
+
const wrapT = options.wrapT ?? gl.CLAMP_TO_EDGE;
|
|
64
|
+
const invertY = options.invertY ?? false;
|
|
65
|
+
const premultiplyAlpha = options.premultiplyAlpha ?? false;
|
|
66
|
+
let retainedSource = source;
|
|
67
|
+
const handle = gl.createTexture();
|
|
68
|
+
if (handle === null) {
|
|
69
|
+
throw new Error("lite-gl: gl.createTexture returned null");
|
|
70
|
+
}
|
|
71
|
+
const uploadSource = (target, src, w, h) => {
|
|
72
|
+
const g = target.gl;
|
|
73
|
+
setUnpackState(target, invertY, premultiplyAlpha, alignment);
|
|
74
|
+
bindTextureForUpload(target, tex.handle);
|
|
75
|
+
g.texImage2D(g.TEXTURE_2D, 0, g.RGBA, g.RGBA, g.UNSIGNED_BYTE, src);
|
|
76
|
+
tex.width = w;
|
|
77
|
+
tex.height = h;
|
|
78
|
+
};
|
|
79
|
+
// Context-restore replay. A retained source that became unusable (closed
|
|
80
|
+
// bitmap, emptied video, tainted image) must not abort the engine-wide
|
|
81
|
+
// restore, so fall back to transparent black at the last uploaded size.
|
|
82
|
+
const restore = (target) => {
|
|
83
|
+
if (retainedSource !== null) {
|
|
84
|
+
try {
|
|
85
|
+
const [w, h] = sourceSize(target, retainedSource);
|
|
86
|
+
uploadSource(target, retainedSource, w, h);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
console.error("lite-gl: retained texture source unusable on restore; restored blank", err);
|
|
91
|
+
retainedSource = null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const g = target.gl;
|
|
95
|
+
setUnpackState(target, invertY, premultiplyAlpha, alignment);
|
|
96
|
+
bindTextureForUpload(target, tex.handle);
|
|
97
|
+
g.texImage2D(g.TEXTURE_2D, 0, g.RGBA8, tex.width, tex.height, 0, g.RGBA, g.UNSIGNED_BYTE, null);
|
|
98
|
+
};
|
|
99
|
+
const initializeParameters = (target) => {
|
|
100
|
+
setBoundTextureParams(target.gl, minFilter, magFilter, wrapS, wrapT);
|
|
101
|
+
};
|
|
102
|
+
const tex = {
|
|
103
|
+
handle,
|
|
104
|
+
target: gl.TEXTURE_2D,
|
|
105
|
+
width,
|
|
106
|
+
height,
|
|
107
|
+
isReady: true,
|
|
108
|
+
_disposed: false,
|
|
109
|
+
_refCount: 1,
|
|
110
|
+
_upload: restore,
|
|
111
|
+
_initializeParameters: initializeParameters,
|
|
112
|
+
_wasReady: true,
|
|
113
|
+
};
|
|
114
|
+
try {
|
|
115
|
+
uploadSource(engine, source, width, height);
|
|
116
|
+
initializeParameters(engine);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
disposeTexture(engine, tex);
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
if (options.retainSource === false) {
|
|
123
|
+
retainedSource = null;
|
|
124
|
+
}
|
|
125
|
+
engine._textures.add(tex);
|
|
126
|
+
return tex;
|
|
127
|
+
}
|
|
128
|
+
/** Use intrinsic upload dimensions without depending on DOM constructor globals.
|
|
129
|
+
* Also rejects sources WebGL would fail on without throwing (a detached
|
|
130
|
+
* `ImageData` buffer or video without a current frame raises `INVALID_VALUE`), so creation throws and
|
|
131
|
+
* restore takes the blank fallback instead of marking empty storage ready. */
|
|
132
|
+
function sourceSize(engine, source) {
|
|
133
|
+
let width;
|
|
134
|
+
let height;
|
|
135
|
+
if ("videoWidth" in source) {
|
|
136
|
+
// HAVE_CURRENT_DATA: dimensions alone do not guarantee a decoded frame.
|
|
137
|
+
if (source.readyState < 2) {
|
|
138
|
+
throw new Error("lite-gl: source video has no decoded current frame");
|
|
139
|
+
}
|
|
140
|
+
width = source.videoWidth;
|
|
141
|
+
height = source.videoHeight;
|
|
142
|
+
}
|
|
143
|
+
else if ("naturalWidth" in source) {
|
|
144
|
+
width = source.naturalWidth;
|
|
145
|
+
height = source.naturalHeight;
|
|
146
|
+
}
|
|
147
|
+
else if ("displayWidth" in source) {
|
|
148
|
+
width = source.displayWidth;
|
|
149
|
+
height = source.displayHeight;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
// ImageData is never zero-sized, so an empty pixel array means its buffer was transferred.
|
|
153
|
+
if ("data" in source && source.data.length === 0) {
|
|
154
|
+
throw new Error("lite-gl: source ImageData buffer is detached");
|
|
155
|
+
}
|
|
156
|
+
width = source.width;
|
|
157
|
+
height = source.height;
|
|
158
|
+
}
|
|
159
|
+
const maxSize = engine.caps.maxTextureSize;
|
|
160
|
+
if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || width < 1 || height < 1 || width > maxSize || height > maxSize) {
|
|
161
|
+
throw new Error(`lite-gl: source texture dimensions must be positive integers <= ${maxSize} (got ${width}x${height})`);
|
|
162
|
+
}
|
|
163
|
+
return [width, height];
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=texture-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"texture-source.js","sourceRoot":"","sources":["../src/texture-source.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAA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;IACD,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\nimport { bindTextureForUpload, disposeTexture, setBoundTextureParams, setUnpackState, type GLTexture, type GLTextureOptions } from \"./texture.js\";\n\n/** Upload and sampling options for {@link createTextureFromSource}. */\nexport interface GLTextureSourceOptions extends Omit<GLTextureOptions, \"internalFormat\"> {\n /**\n * Keep the source for automatic context-restore replay. Default true.\n * With false, release the reference after upload and restore transparent\n * black at the original size instead; the caller must recreate content\n * (for example from an `onContextRestored` callback).\n */\n retainSource?: boolean;\n}\n\n/**\n * Create an immediately ready RGBA 2D texture from already-decoded pixels with\n * one source upload, no placeholder or blank pre-allocation. Sampling defaults\n * to linear filtering and clamp-to-edge wrapping; mipmaps are a separate opt-in\n * via `generateTextureMipMaps`.\n *\n * The source is retained for context restoration by default. Keep it usable\n * while the texture is live; mutable sources replay their current content and\n * intrinsic size. If a retained source has become unusable by restore time\n * (for example a closed `ImageBitmap`), the error is logged, the source is\n * dropped and the texture restores transparent black at its last uploaded size\n * so the rest of the engine still restores. With `retainSource: false`, the\n * source reference is dropped after upload and restoration creates a ready,\n * transparent-black texture at the original size; re-upload content from an\n * `onContextRestored` callback. This function never closes a bitmap or video\n * frame.\n *\n * Restoration replays level 0 and the sampling parameters only. When using a\n * mipmapped `minFilter`, call `generateTextureMipMaps` after creation and\n * again from an `onContextRestored` callback, otherwise the restored texture\n * is mipmap-incomplete and samples black.\n *\n * WebGL ignores unpack flip/premultiplication for `ImageBitmap`; select\n * `imageOrientation` / `premultiplyAlpha` when decoding those sources instead.\n *\n * The texture is immutable from the API's point of view: to change its pixels,\n * dispose it and create a new one. Do not pass it to `updateDynamicTexture`\n * (the new source would be ignored) or `updateHtmlElementTexture` (it would\n * run the context-restore replay on the live texture).\n *\n * Image elements are sized from `naturalWidth` / `naturalHeight`. For SVG\n * images and density-selected (`srcset` / `x` descriptor) images, WebGL may\n * upload a different pixel size, so the reported and restored dimensions can\n * be wrong; convert those to an `ImageBitmap` (`createImageBitmap`) first.\n * Video elements must have a decoded current frame (`readyState >= 2`,\n * `HAVE_CURRENT_DATA`); positive metadata dimensions alone are insufficient.\n *\n * @param engine - The live engine that will own the texture.\n * @param source - An ImageBitmap, ImageData (with an attached buffer), canvas,\n * OffscreenCanvas, decoded raster image, video with a decoded current frame,\n * or VideoFrame with positive intrinsic dimensions.\n * @param options - Unpack and sampling overrides; defaults are invertY false,\n * premultiplyAlpha false, unpackAlignment 4 and retainSource true.\n * @returns A managed texture disposed with {@link disposeTexture}.\n * @throws If the engine is lost/disposed, dimensions exceed the texture limit\n * or are not positive integers, the source is detached or has no decoded\n * current frame, unpack alignment is invalid, or allocation fails.\n */\nexport function createTextureFromSource(engine: GLEngineContext, source: TexImageSource, options: GLTextureSourceOptions = {}): GLTexture {\n if (engine._isLost || engine._disposed) {\n throw new Error(\"lite-gl: cannot create a source texture on a lost or disposed engine\");\n }\n const [width, height] = sourceSize(engine, source);\n const alignment = options.unpackAlignment ?? 4;\n if (alignment !== 1 && alignment !== 2 && alignment !== 4 && alignment !== 8) {\n throw new Error(\"lite-gl: texture unpackAlignment must be 1, 2, 4 or 8\");\n }\n const gl = engine.gl;\n const minFilter = options.minFilter ?? gl.LINEAR;\n const magFilter = options.magFilter ?? gl.LINEAR;\n const wrapS = options.wrapS ?? gl.CLAMP_TO_EDGE;\n const wrapT = options.wrapT ?? gl.CLAMP_TO_EDGE;\n const invertY = options.invertY ?? false;\n const premultiplyAlpha = options.premultiplyAlpha ?? false;\n let retainedSource: TexImageSource | null = source;\n const handle = gl.createTexture();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createTexture returned null\");\n }\n\n const uploadSource = (target: GLEngineContext, src: TexImageSource, w: number, h: number): void => {\n const g = target.gl;\n setUnpackState(target, invertY, premultiplyAlpha, alignment);\n bindTextureForUpload(target, tex.handle);\n g.texImage2D(g.TEXTURE_2D, 0, g.RGBA, g.RGBA, g.UNSIGNED_BYTE, src);\n tex.width = w;\n tex.height = h;\n };\n // Context-restore replay. A retained source that became unusable (closed\n // bitmap, emptied video, tainted image) must not abort the engine-wide\n // restore, so fall back to transparent black at the last uploaded size.\n const restore = (target: GLEngineContext): void => {\n if (retainedSource !== null) {\n try {\n const [w, h] = sourceSize(target, retainedSource);\n uploadSource(target, retainedSource, w, h);\n return;\n } catch (err) {\n console.error(\"lite-gl: retained texture source unusable on restore; restored blank\", err);\n retainedSource = null;\n }\n }\n const g = target.gl;\n setUnpackState(target, invertY, premultiplyAlpha, alignment);\n bindTextureForUpload(target, tex.handle);\n g.texImage2D(g.TEXTURE_2D, 0, g.RGBA8, tex.width, tex.height, 0, g.RGBA, g.UNSIGNED_BYTE, null);\n };\n const initializeParameters = (target: GLEngineContext): void => {\n setBoundTextureParams(target.gl, minFilter, magFilter, wrapS, wrapT);\n };\n const tex: GLTexture = {\n handle,\n target: gl.TEXTURE_2D,\n width,\n height,\n isReady: true,\n _disposed: false,\n _refCount: 1,\n _upload: restore,\n _initializeParameters: initializeParameters,\n _wasReady: true,\n };\n try {\n uploadSource(engine, source, width, height);\n initializeParameters(engine);\n } catch (error) {\n disposeTexture(engine, tex);\n throw error;\n }\n if (options.retainSource === false) {\n retainedSource = null;\n }\n engine._textures.add(tex);\n return tex;\n}\n\n/** Use intrinsic upload dimensions without depending on DOM constructor globals.\n * Also rejects sources WebGL would fail on without throwing (a detached\n * `ImageData` buffer or video without a current frame raises `INVALID_VALUE`), so creation throws and\n * restore takes the blank fallback instead of marking empty storage ready. */\nfunction sourceSize(engine: GLEngineContext, source: TexImageSource): [number, number] {\n let width: number;\n let height: number;\n if (\"videoWidth\" in source) {\n // HAVE_CURRENT_DATA: dimensions alone do not guarantee a decoded frame.\n if (source.readyState < 2) {\n throw new Error(\"lite-gl: source video has no decoded current frame\");\n }\n width = source.videoWidth;\n height = source.videoHeight;\n } else if (\"naturalWidth\" in source) {\n width = source.naturalWidth;\n height = source.naturalHeight;\n } else if (\"displayWidth\" in source) {\n width = source.displayWidth;\n height = source.displayHeight;\n } else {\n // ImageData is never zero-sized, so an empty pixel array means its buffer was transferred.\n if (\"data\" in source && source.data.length === 0) {\n throw new Error(\"lite-gl: source ImageData buffer is detached\");\n }\n width = source.width;\n height = source.height;\n }\n const maxSize = engine.caps.maxTextureSize;\n if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || width < 1 || height < 1 || width > maxSize || height > maxSize) {\n throw new Error(`lite-gl: source texture dimensions must be positive integers <= ${maxSize} (got ${width}x${height})`);\n }\n return [width, height];\n}\n"]}
|
package/texture.d.ts
CHANGED
|
@@ -138,5 +138,9 @@ export declare function loadTexture2D(engine: GLEngineContext, url: string, opti
|
|
|
138
138
|
export declare function bindTexture(engine: GLEngineContext, unit: number, tex: GLTexture | null): void;
|
|
139
139
|
/** Disposes the texture. Walks `_state.boundTextures` and clears every slot
|
|
140
140
|
* that still references the handle — otherwise a later `bindTexture(unit, B)`
|
|
141
|
-
* to the same unit would be wrongly elided when slot still showed handle A.
|
|
141
|
+
* to the same unit would be wrongly elided when slot still showed handle A.
|
|
142
|
+
* Deregistration is expected O(1), independent of the live texture count.
|
|
143
|
+
* Shared references keep the texture registered until its final release;
|
|
144
|
+
* repeated disposal is a no-op. Unregistered wrappers keep their existing
|
|
145
|
+
* handle-deletion semantics without affecting the live registry. */
|
|
142
146
|
export declare function disposeTexture(engine: GLEngineContext, tex: GLTexture): void;
|
package/texture.js
CHANGED
|
@@ -90,7 +90,7 @@ export function createRawTexture(engine, data, width, height, format, type, opti
|
|
|
90
90
|
};
|
|
91
91
|
upload(engine);
|
|
92
92
|
initializeParameters(engine);
|
|
93
|
-
engine._textures.
|
|
93
|
+
engine._textures.add(tex);
|
|
94
94
|
return tex;
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
@@ -264,7 +264,7 @@ export function loadTexture2D(engine, url, options, onLoad, onError) {
|
|
|
264
264
|
// Placeholder upload — makes the texture sampleable before the real image arrives.
|
|
265
265
|
upload(engine);
|
|
266
266
|
initializeParameters(engine);
|
|
267
|
-
engine._textures.
|
|
267
|
+
engine._textures.add(tex);
|
|
268
268
|
// Fetch + decode the real image. Re-uploads via the same closure once the
|
|
269
269
|
// bitmap is in hand (so context-restore replay sees the real image too).
|
|
270
270
|
fetch(url)
|
|
@@ -352,7 +352,11 @@ export function bindTextureForUpload(engine, handle) {
|
|
|
352
352
|
}
|
|
353
353
|
/** Disposes the texture. Walks `_state.boundTextures` and clears every slot
|
|
354
354
|
* that still references the handle — otherwise a later `bindTexture(unit, B)`
|
|
355
|
-
* to the same unit would be wrongly elided when slot still showed handle A.
|
|
355
|
+
* to the same unit would be wrongly elided when slot still showed handle A.
|
|
356
|
+
* Deregistration is expected O(1), independent of the live texture count.
|
|
357
|
+
* Shared references keep the texture registered until its final release;
|
|
358
|
+
* repeated disposal is a no-op. Unregistered wrappers keep their existing
|
|
359
|
+
* handle-deletion semantics without affecting the live registry. */
|
|
356
360
|
export function disposeTexture(engine, tex) {
|
|
357
361
|
if (tex._disposed) {
|
|
358
362
|
return;
|
|
@@ -362,10 +366,7 @@ export function disposeTexture(engine, tex) {
|
|
|
362
366
|
return;
|
|
363
367
|
}
|
|
364
368
|
tex._disposed = true;
|
|
365
|
-
|
|
366
|
-
if (i !== -1) {
|
|
367
|
-
engine._textures.splice(i, 1);
|
|
368
|
-
}
|
|
369
|
+
engine._textures.delete(tex);
|
|
369
370
|
if (!engine._isLost && !engine._disposed) {
|
|
370
371
|
engine.gl.deleteTexture(tex.handle);
|
|
371
372
|
}
|
package/texture.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"texture.js","sourceRoot":"","sources":["../src/texture.ts"],"names":[],"mappings":"AAoGA;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,MAAuB,EAAE,KAAc,EAAE,gBAAyB,EAAE,SAAS,GAAG,CAAC;IAC5G,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;IACrB,MAAM,CAAC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G,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC,MAAM,CAAC;QACrB,CAAC;IACL,CAAC;IACD,IAAI,IAAI,KAAK,EAAE,CAAC,UAAU,EAAE,CAAC;QACzB,IAAI,MAAM,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;YACrB,OAAO,EAAE,CAAC,OAAO,CAAC;QACtB,CAAC;QACD,IAAI,MAAM,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC,MAAM,CAAC;QACrB,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\n\n/** Texture sampling / wrap options. All have GL-spec defaults. Mipmaps are NOT\n * a create option — generate the chain explicitly via {@link generateTextureMipMaps}. */\nexport interface GLTextureOptions {\n /** Default: false (matches Babylon's default raw-texture behaviour). */\n invertY?: boolean;\n /** Default: gl.LINEAR. */\n minFilter?: GLenum;\n /** Default: gl.LINEAR. */\n magFilter?: GLenum;\n /** Default: gl.CLAMP_TO_EDGE. May be `gl.REPEAT` / `gl.MIRRORED_REPEAT`\n * (NPOT-safe in WebGL2). */\n wrapS?: GLenum;\n /** Default: gl.CLAMP_TO_EDGE. May be `gl.REPEAT` / `gl.MIRRORED_REPEAT`. */\n wrapT?: GLenum;\n /** `gl.pixelStorei(UNPACK_ALIGNMENT)` for the upload (1/2/4/8). Default 4.\n * Use 1 for tightly-packed non-RGBA rows. */\n unpackAlignment?: number;\n /** Premultiply alpha at upload (`UNPACK_PREMULTIPLY_ALPHA_WEBGL`). Default\n * false. */\n premultiplyAlpha?: boolean;\n /** Explicit sized internalFormat for `texImage2D`. When provided it is used\n * verbatim and the inline LDR resolver is bypassed — this is how\n * {@link createFloatTexture} injects its `RGBA16F` / `RGBA32F` choice\n * without the byte path ever referencing the float-format table (keeping it\n * tree-shakeable out of RGBA8-only bundles). Default: derived from\n * `format`/`type` via the LDR resolver. */\n internalFormat?: GLenum;\n}\n\n/**\n * Pure-state texture handle. The `handle` field is MUTABLE so the same logical\n * texture survives a `webglcontextrestored` event — every consumer keeps the\n * same `GLTexture` reference; only the internal `WebGLTexture` is swapped.\n *\n * `loadTexture2D` also uses the same handle for the 1×1 placeholder upload AND\n * the final image upload — so a `bindTexture(engine, unit, tex)` made before the\n * image has decoded remains valid once the image arrives.\n */\nexport interface GLTexture {\n /** The live `WebGLTexture`. MUTABLE — swapped for a fresh handle on\n * `webglcontextrestored` while consumers keep the same `GLTexture` reference. */\n handle: WebGLTexture;\n /** GL texture target (normally `gl.TEXTURE_2D`); 3D textures use their own API. */\n readonly target: GLenum;\n /** Texture width in texels. Updated once an async upload resolves. */\n width: number;\n /** Texture height in texels. Updated once an async upload resolves. */\n height: number;\n /** True when the texture is safe to sample with final content (placeholders\n * read as not-ready until their image/upload completes). */\n isReady: boolean;\n /** @internal */\n _disposed: boolean;\n /** @internal */\n _refCount: number;\n /** Replays the latest pixel content into the currently bound texture handle. @internal */\n _upload: (engine: GLEngineContext) => void;\n /** Initializes creation-time sampling state on the bound texture handle. @internal */\n _initializeParameters?: (engine: GLEngineContext) => void;\n /**\n * Snapshot of `isReady` captured on `webglcontextlost` so the restore\n * handler knows whether to flip it back on after `_upload`. Textures\n * that were still mid-load (e.g. `loadTexture2D` whose bitmap hadn't\n * arrived) stay not-ready; the async path will set `isReady=true` once\n * the bitmap finishes decoding into the new handle.\n * @internal\n */\n _wasReady: boolean;\n /**\n * Live re-upload hook installed by `createRawTexture` — lets\n * `updateRawTexture` replace the pixel data (and optionally the size)\n * through the same closure that the context-restore replay uses, keeping\n * restore correct. Absent on image / HTML-element / external textures.\n * @internal\n */\n _updateRaw?: (engine: GLEngineContext, data: ArrayBufferView | null, width: number, height: number, unpackAlignment: number) => void;\n /**\n * Dynamic-texture source captured by `updateDynamicTexture`\n * (`@babylonjs/lite-gl`) and replayed into the fresh handle\n * on `webglcontextrestored`. Null/absent on non-dynamic textures.\n * @internal\n */\n _dynSource?: TexImageSource | null;\n /** UNPACK_FLIP_Y applied when replaying {@link GLTexture._dynSource}. @internal */\n _dynInvertY?: boolean;\n /** UNPACK_PREMULTIPLY_ALPHA applied when replaying {@link GLTexture._dynSource}. @internal */\n _dynPremultiplyAlpha?: boolean;\n /**\n * The `handle` the dynamic texture's `texParameteri` filter/wrap state was\n * last applied to. `texParameteri` is per-texture GL state that survives pixel\n * re-uploads, so the dynamic-texture `_upload` re-applies it ONLY when this no\n * longer matches `handle` — i.e. at creation and after `webglcontextrestored`\n * installs a fresh handle — not on every per-frame `updateDynamicTexture`.\n * @internal\n */\n _dynParamsHandle?: WebGLTexture | null;\n}\n\n/**\n * Apply the three `UNPACK_*` pixel-store flags through the GL-state cache,\n * eliding redundant `pixelStorei` calls. Centralising this guarantees EVERY\n * upload path sets all three explicitly, so a premultiplying / flipping upload\n * never leaks its flag into a later upload that forgot to set it.\n * @internal\n */\nexport function setUnpackState(engine: GLEngineContext, flipY: boolean, premultiplyAlpha: boolean, alignment = 4): void {\n const gl = engine.gl;\n const s = engine._state;\n const fy = flipY ? 1 : 0;\n if (s.unpackFlipY !== fy) {\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, fy);\n s.unpackFlipY = fy;\n }\n const pm = premultiplyAlpha ? 1 : 0;\n if (s.unpackPremultiplyAlpha !== pm) {\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, pm);\n s.unpackPremultiplyAlpha = pm;\n }\n if (s.unpackAlignment !== alignment) {\n gl.pixelStorei(gl.UNPACK_ALIGNMENT, alignment);\n s.unpackAlignment = alignment;\n }\n}\n\n/** Apply sampling and wrap state to the texture currently bound for upload. @internal */\nexport function setBoundTextureParams(gl: WebGL2RenderingContext, minFilter: GLenum, magFilter: GLenum, wrapS: GLenum, wrapT: GLenum): void {\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapT);\n}\n\n/** Uint8 / float raw texture upload. The pixel data can be replaced later via\n * {@link updateRawTexture}; the sampling and wrap can be changed via\n * {@link updateTextureSamplingMode} / {@link updateTextureWrapMode}. */\nexport function createRawTexture(\n engine: GLEngineContext,\n data: ArrayBufferView | null,\n width: number,\n height: number,\n format: GLenum,\n type: GLenum,\n options?: GLTextureOptions\n): GLTexture {\n const gl = engine.gl;\n const handle = gl.createTexture();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createTexture returned null\");\n }\n const opts = options ?? {};\n const minFilter = opts.minFilter ?? gl.LINEAR;\n const magFilter = opts.magFilter ?? gl.LINEAR;\n const wrapS = opts.wrapS ?? gl.CLAMP_TO_EDGE;\n const wrapT = opts.wrapT ?? gl.CLAMP_TO_EDGE;\n const invertY = opts.invertY ?? false;\n const premultiply = opts.premultiplyAlpha ?? false;\n // LDR byte formats are resolved INLINE here; the float-format table in\n // `pickSizedInternalFormat` is deliberately NOT referenced from this path so\n // it tree-shakes out of byte-only bundles. `createFloatTexture` injects its\n // sized float format via `opts.internalFormat`.\n const internalFormat = opts.internalFormat ?? resolveLdrInternalFormat(gl, format, type);\n\n // Mutable upload state — `updateRawTexture` mutates these and re-runs\n // `upload`, so the context-restore replay (which calls the same `upload`)\n // always reproduces the latest contents.\n let curData = data;\n let curWidth = width;\n let curHeight = height;\n let curAlign = opts.unpackAlignment ?? 4;\n\n const upload = (target: GLEngineContext): void => {\n const g = target.gl;\n setUnpackState(target, invertY, premultiply, curAlign);\n bindTextureForUpload(target, tex.handle);\n g.texImage2D(g.TEXTURE_2D, 0, internalFormat, curWidth, curHeight, 0, format, type, curData);\n };\n\n const initializeParameters = (target: GLEngineContext): void => {\n setBoundTextureParams(target.gl, minFilter, magFilter, wrapS, wrapT);\n };\n\n const tex: GLTexture = {\n handle,\n target: gl.TEXTURE_2D,\n width,\n height,\n isReady: true,\n _disposed: false,\n _refCount: 1,\n _upload: upload,\n _initializeParameters: initializeParameters,\n _wasReady: true,\n };\n tex._updateRaw = (target: GLEngineContext, newData: ArrayBufferView | null, newWidth: number, newHeight: number, unpackAlignment: number): void => {\n curData = newData;\n curWidth = newWidth;\n curHeight = newHeight;\n curAlign = unpackAlignment;\n tex.width = newWidth;\n tex.height = newHeight;\n upload(target);\n };\n upload(engine);\n initializeParameters(engine);\n engine._textures.push(tex);\n return tex;\n}\n\n/** Options for {@link createFloatTexture} — the shared {@link GLTextureOptions}\n * plus the float-specific `type` / `format`. */\nexport interface GLFloatTextureOptions extends GLTextureOptions {\n /** Float texel type — `gl.HALF_FLOAT` (default) or `gl.FLOAT`. */\n type?: GLenum;\n /** Color format. Default `gl.RGBA`. */\n format?: GLenum;\n}\n\n/**\n * Create a float / half-float raw texture — the HDR counterpart of\n * {@link createRawTexture}. This is the ONLY texture factory that carries the\n * `RGBA16F` / `RGBA32F` sized-format knowledge (via {@link pickSizedInternalFormat}),\n * so byte-only consumers calling {@link createRawTexture} ship none of it.\n * Defaults to `gl.HALF_FLOAT`; pass `options.type = gl.FLOAT` for full 32-bit.\n * The caller is responsible for the matching engine cap (e.g.\n * `caps.textureFloatLinearFiltering`) when sampling these with `LINEAR`.\n *\n * @param engine - The engine.\n * @param data - Initial pixels (`Float32Array` for FLOAT, `Uint16Array` for\n * HALF_FLOAT), or `null` for an uninitialised allocation.\n * @param width - Texture width in texels (≥ 1).\n * @param height - Texture height in texels (≥ 1).\n * @param options - See {@link GLFloatTextureOptions}.\n * @returns The new {@link GLTexture}.\n */\nexport function createFloatTexture(engine: GLEngineContext, data: ArrayBufferView | null, width: number, height: number, options?: GLFloatTextureOptions): GLTexture {\n const gl = engine.gl;\n const o = options ?? {};\n const format = o.format ?? gl.RGBA;\n const type = o.type ?? gl.HALF_FLOAT;\n // Precompute the sized float internalFormat HERE and pass it through, so\n // `createRawTexture`'s inline LDR resolver is bypassed and the float table\n // stays out of byte-only bundles.\n const internalFormat = pickSizedInternalFormat(gl, format, type);\n return createRawTexture(engine, data, width, height, format, type, { ...o, internalFormat });\n}\n\n/** Generate the mip chain for a texture from its level-0 contents — mipmaps as\n * an explicit opt-in function rather than baked into the create path. Binds for\n * upload (unit 0). No-op on a lost/disposed context or a handle-less texture. */\nexport function generateTextureMipMaps(engine: GLEngineContext, tex: GLTexture): void {\n if (engine._isLost || engine._disposed || tex._disposed || tex.handle === null) {\n return;\n }\n bindTextureForUpload(engine, tex.handle);\n engine.gl.generateMipmap(engine.gl.TEXTURE_2D);\n}\n\n/**\n * Re-upload the pixel data (and optionally resize) of a texture created by\n * {@link createRawTexture} — the lite-gl equivalent of Babylon's\n * `updateRawTexture` / `_uploadDataToTextureDirectly`. Goes through the same\n * upload closure used by context-restore, so the new contents survive a context\n * loss. No-op on a lost/disposed/non-raw texture.\n *\n * @param engine - The engine.\n * @param tex - The raw texture to update.\n * @param data - New pixel data (must match the original `format`/`type`).\n * @param options - Optional new `width`/`height` (default: unchanged) and\n * `unpackAlignment` (default 4).\n */\nexport function updateRawTexture(\n engine: GLEngineContext,\n tex: GLTexture,\n data: ArrayBufferView | null,\n options?: { width?: number; height?: number; unpackAlignment?: number }\n): void {\n if (engine._isLost || engine._disposed || tex._disposed || tex._updateRaw === undefined) {\n return;\n }\n const o = options ?? {};\n tex._updateRaw(engine, data, o.width ?? tex.width, o.height ?? tex.height, o.unpackAlignment ?? 4);\n}\n\n/** Update a texture's min/mag sampling filters — the lite-gl equivalent of\n * Babylon's `updateTextureSamplingMode`. Binds for upload (unit 0) so the\n * `texParameteri` lands on this texture. No-op on a lost/disposed context. */\nexport function updateTextureSamplingMode(engine: GLEngineContext, tex: GLTexture, minFilter: GLenum, magFilter: GLenum): void {\n if (engine._isLost || engine._disposed || tex._disposed) {\n return;\n }\n const gl = engine.gl;\n bindTextureForUpload(engine, tex.handle);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);\n}\n\n/** Update a texture's S/T wrap modes (`gl.CLAMP_TO_EDGE` / `gl.REPEAT` /\n * `gl.MIRRORED_REPEAT`) — the lite-gl equivalent of Babylon's\n * `updateTextureWrappingMode`. No-op on a lost/disposed context. */\nexport function updateTextureWrapMode(engine: GLEngineContext, tex: GLTexture, wrapS: GLenum, wrapT: GLenum): void {\n if (engine._isLost || engine._disposed || tex._disposed) {\n return;\n }\n const gl = engine.gl;\n bindTextureForUpload(engine, tex.handle);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapT);\n}\n\n/**\n * Wrap an existing raw `WebGLTexture` (e.g. one created by a host renderer or a\n * previous engine) as a {@link GLTexture} — the lite-gl equivalent of\n * ShapeBuilder's `createTextureGraphicsResourceFromExternalWebGLTexture`.\n *\n * The wrapper does NOT own the underlying handle's upload — it is NOT registered\n * for context-restore replay (the external owner is responsible for that) and is\n * marked ready immediately. `disposeTexture` will still `gl.deleteTexture` it, so\n * only wrap a handle whose deletion you intend lite-gl to manage.\n *\n * @param engine - The engine.\n * @param handle - The external `WebGLTexture`.\n * @param width - Texture width in texels.\n * @param height - Texture height in texels.\n * @param options - Optional sampling/wrap to apply once (min/mag/wrapS/wrapT).\n * @returns A {@link GLTexture} wrapping the handle.\n */\nexport function createTextureFromHandle(engine: GLEngineContext, handle: WebGLTexture, width: number, height: number, options?: GLTextureOptions): GLTexture {\n const tex: GLTexture = {\n handle,\n target: engine.gl.TEXTURE_2D,\n width,\n height,\n isReady: true,\n _disposed: false,\n _refCount: 1,\n // External handle — restore replay is the external owner's job.\n _upload: () => {},\n _wasReady: true,\n };\n if (options !== undefined) {\n const gl = engine.gl;\n bindTextureForUpload(engine, handle);\n setBoundTextureParams(gl, options.minFilter ?? gl.LINEAR, options.magFilter ?? gl.LINEAR, options.wrapS ?? gl.CLAMP_TO_EDGE, options.wrapT ?? gl.CLAMP_TO_EDGE);\n }\n return tex;\n}\n\n/** Asynchronous image upload.The returned texture is immediately usable (1×1\n * transparent placeholder); `isReady` flips true once the image has been\n * decoded and uploaded. The decoded `ImageBitmap` is retained on the texture\n * for offline-safe `webglcontextrestored` replay. */\nexport function loadTexture2D(engine: GLEngineContext, url: string, options?: GLTextureOptions, onLoad?: (tex: GLTexture) => void, onError?: (err: Error) => void): GLTexture {\n const gl = engine.gl;\n const handle = gl.createTexture();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createTexture returned null\");\n }\n const opts = options ?? {};\n const minFilter = opts.minFilter ?? gl.LINEAR;\n const magFilter = opts.magFilter ?? gl.LINEAR;\n const wrapS = opts.wrapS ?? gl.CLAMP_TO_EDGE;\n const wrapT = opts.wrapT ?? gl.CLAMP_TO_EDGE;\n const invertY = opts.invertY ?? false;\n\n let bitmap: ImageBitmap | null = null;\n const placeholderPixels = new Uint8Array([0, 0, 0, 0]);\n\n const upload = (target: GLEngineContext): void => {\n const g = target.gl;\n // invertY is applied at decode time via createImageBitmap({ imageOrientation })\n // because UNPACK_FLIP_Y_WEBGL is IGNORED for ImageBitmap sources (and the 1×1\n // placeholder is flip-invariant), so keep flip + premultiply off here.\n setUnpackState(target, false, false);\n bindTextureForUpload(target, tex.handle);\n if (bitmap !== null) {\n g.texImage2D(g.TEXTURE_2D, 0, g.RGBA, g.RGBA, g.UNSIGNED_BYTE, bitmap);\n tex.width = bitmap.width;\n tex.height = bitmap.height;\n } else {\n g.texImage2D(g.TEXTURE_2D, 0, g.RGBA, 1, 1, 0, g.RGBA, g.UNSIGNED_BYTE, placeholderPixels);\n }\n };\n\n const initializeParameters = (target: GLEngineContext): void => {\n setBoundTextureParams(target.gl, minFilter, magFilter, wrapS, wrapT);\n };\n\n const tex: GLTexture = {\n handle,\n target: gl.TEXTURE_2D,\n width: 1,\n height: 1,\n isReady: false,\n _disposed: false,\n _refCount: 1,\n _upload: upload,\n _initializeParameters: initializeParameters,\n _wasReady: false,\n };\n // Placeholder upload — makes the texture sampleable before the real image arrives.\n upload(engine);\n initializeParameters(engine);\n engine._textures.push(tex);\n\n // Fetch + decode the real image. Re-uploads via the same closure once the\n // bitmap is in hand (so context-restore replay sees the real image too).\n fetch(url)\n .then((r) => {\n if (!r.ok) {\n throw new Error(`lite-gl: fetch ${url} -> HTTP ${r.status}`);\n }\n return r.blob();\n })\n .then((blob) => createImageBitmap(blob, { premultiplyAlpha: \"none\", imageOrientation: invertY ? \"flipY\" : \"none\" }))\n .then((bm) => {\n if (tex._disposed) {\n bm.close();\n return;\n }\n bitmap = bm;\n // If the context is lost mid-flight, defer the upload — the restore\n // handler will call _upload again, which will then see `bitmap !== null`\n // and replay the real image.\n if (!engine._isLost) {\n upload(engine);\n tex.isReady = true;\n }\n tex._wasReady = true;\n if (onLoad !== undefined) {\n onLoad(tex);\n }\n })\n .catch((err: unknown) => {\n const e = err instanceof Error ? err : new Error(String(err));\n if (onError !== undefined) {\n onError(e);\n } else {\n console.error(\"lite-gl: loadTexture2D failed\", e);\n }\n });\n\n return tex;\n}\n\n/** Cached bind. Skips `gl.activeTexture` and/or `gl.bindTexture` when nothing\n * changes. No-op when `tex._disposed` or `engine._isLost`. */\nexport function bindTexture(engine: GLEngineContext, unit: number, tex: GLTexture | null): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n if (tex !== null && tex._disposed) {\n return;\n }\n bindTextureRaw(engine, unit, tex === null ? null : tex.handle);\n}\n\n/** @internal — for callers that already hold a raw `WebGLTexture`. Not part of\n * the public API: `bindTexture` (public) and the texture `_upload` closures bind\n * through the cache, so consumers never call this directly. */\nexport function bindTextureRaw(engine: GLEngineContext, unit: number, handle: WebGLTexture | null): void {\n const s = engine._state;\n const gl = engine.gl;\n if (s.boundTextures[unit] === handle) {\n return;\n }\n if (s.activeTextureUnit !== unit) {\n gl.activeTexture(gl.TEXTURE0 + unit);\n s.activeTextureUnit = unit;\n }\n gl.bindTexture(gl.TEXTURE_2D, handle);\n s.boundTextures[unit] = handle;\n}\n\n/** @internal Bind `handle` on texture unit 0 **for an upload** (`texImage2D`).\n * Unlike {@link bindTextureRaw} — which elides the entire bind when the handle is\n * already bound on the unit (correct for *sampling*, where the active unit is\n * irrelevant) — an upload writes into the texture on the ACTIVE unit. A prior\n * multi-sampler draw may have left a non-zero unit active while this handle is\n * still bound on unit 0, so we must force unit 0 active even on a bind cache-hit,\n * keeping the `_state` cache coherent. */\nexport function bindTextureForUpload(engine: GLEngineContext, handle: WebGLTexture): void {\n const s = engine._state;\n const gl = engine.gl;\n if (s.activeTextureUnit !== 0) {\n gl.activeTexture(gl.TEXTURE0);\n s.activeTextureUnit = 0;\n }\n if (s.boundTextures[0] !== handle) {\n gl.bindTexture(gl.TEXTURE_2D, handle);\n s.boundTextures[0] = handle;\n }\n}\n\n/** Disposes the texture. Walks `_state.boundTextures` and clears every slot\n * that still references the handle — otherwise a later `bindTexture(unit, B)`\n * to the same unit would be wrongly elided when slot still showed handle A. */\nexport function disposeTexture(engine: GLEngineContext, tex: GLTexture): void {\n if (tex._disposed) {\n return;\n }\n if (tex._refCount > 1) {\n tex._refCount--;\n return;\n }\n tex._disposed = true;\n const i = engine._textures.indexOf(tex);\n if (i !== -1) {\n engine._textures.splice(i, 1);\n }\n if (!engine._isLost && !engine._disposed) {\n engine.gl.deleteTexture(tex.handle);\n }\n const bound = engine._state.boundTextures;\n for (let u = 0; u < bound.length; u++) {\n if (bound[u] === tex.handle) {\n bound[u] = null;\n }\n }\n}\n\n/** Internal — resolve the sized internalFormat for the LDR (byte) `texImage2D`\n * paths ONLY: RGBA→RGBA8, RGB→RGB8, RG→RG8, RED→R8, LUMINANCE passthrough.\n * Deliberately knows nothing about FLOAT / HALF_FLOAT so the float-format table\n * in {@link pickSizedInternalFormat} tree-shakes out of byte-only bundles.\n * @internal */\nfunction resolveLdrInternalFormat(gl: WebGL2RenderingContext, format: GLenum, type: GLenum): GLenum {\n if (type === gl.UNSIGNED_BYTE) {\n if (format === gl.RGBA) {\n return gl.RGBA8;\n }\n if (format === gl.RGB) {\n return gl.RGB8;\n }\n if (format === gl.RG) {\n return gl.RG8;\n }\n if (format === gl.RED) {\n return gl.R8;\n }\n if (format === gl.LUMINANCE) {\n return gl.LUMINANCE;\n }\n }\n return format;\n}\n\n/** Internal — pick a sized internalFormat for `texImage2D`. WebGL2 prefers\n * sized formats for non-color-renderable / non-readback paths; for the\n * NeonBrush use cases (sample-only) the unsized format works too, but sized\n * is more portable. Shared with the render-target module.\n * @internal */\nexport function pickSizedInternalFormat(gl: WebGL2RenderingContext, format: GLenum, type: GLenum): GLenum {\n if (type === gl.UNSIGNED_BYTE) {\n if (format === gl.RGBA) {\n return gl.RGBA8;\n }\n if (format === gl.RGB) {\n return gl.RGB8;\n }\n if (format === gl.LUMINANCE) {\n return gl.LUMINANCE;\n }\n }\n if (type === gl.FLOAT) {\n if (format === gl.RGBA) {\n return gl.RGBA32F;\n }\n if (format === gl.RGB) {\n return gl.RGB32F;\n }\n }\n if (type === gl.HALF_FLOAT) {\n if (format === gl.RGBA) {\n return gl.RGBA16F;\n }\n if (format === gl.RGB) {\n return gl.RGB16F;\n }\n }\n return format;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"texture.js","sourceRoot":"","sources":["../src/texture.ts"],"names":[],"mappings":"AAoGA;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,MAAuB,EAAE,KAAc,EAAE,gBAAyB,EAAE,SAAS,GAAG,CAAC;IAC5G,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;IACrB,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzB,IAAI,CAAC,CAAC,WAAW,KAAK,EAAE,EAAE,CAAC;QACvB,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,mBAAm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AC;AAClB,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\n\n/** Texture sampling / wrap options. All have GL-spec defaults. Mipmaps are NOT\n * a create option — generate the chain explicitly via {@link generateTextureMipMaps}. */\nexport interface GLTextureOptions {\n /** Default: false (matches Babylon's default raw-texture behaviour). */\n invertY?: boolean;\n /** Default: gl.LINEAR. */\n minFilter?: GLenum;\n /** Default: gl.LINEAR. */\n magFilter?: GLenum;\n /** Default: gl.CLAMP_TO_EDGE. May be `gl.REPEAT` / `gl.MIRRORED_REPEAT`\n * (NPOT-safe in WebGL2). */\n wrapS?: GLenum;\n /** Default: gl.CLAMP_TO_EDGE. May be `gl.REPEAT` / `gl.MIRRORED_REPEAT`. */\n wrapT?: GLenum;\n /** `gl.pixelStorei(UNPACK_ALIGNMENT)` for the upload (1/2/4/8). Default 4.\n * Use 1 for tightly-packed non-RGBA rows. */\n unpackAlignment?: number;\n /** Premultiply alpha at upload (`UNPACK_PREMULTIPLY_ALPHA_WEBGL`). Default\n * false. */\n premultiplyAlpha?: boolean;\n /** Explicit sized internalFormat for `texImage2D`. When provided it is used\n * verbatim and the inline LDR resolver is bypassed — this is how\n * {@link createFloatTexture} injects its `RGBA16F` / `RGBA32F` choice\n * without the byte path ever referencing the float-format table (keeping it\n * tree-shakeable out of RGBA8-only bundles). Default: derived from\n * `format`/`type` via the LDR resolver. */\n internalFormat?: GLenum;\n}\n\n/**\n * Pure-state texture handle. The `handle` field is MUTABLE so the same logical\n * texture survives a `webglcontextrestored` event — every consumer keeps the\n * same `GLTexture` reference; only the internal `WebGLTexture` is swapped.\n *\n * `loadTexture2D` also uses the same handle for the 1×1 placeholder upload AND\n * the final image upload — so a `bindTexture(engine, unit, tex)` made before the\n * image has decoded remains valid once the image arrives.\n */\nexport interface GLTexture {\n /** The live `WebGLTexture`. MUTABLE — swapped for a fresh handle on\n * `webglcontextrestored` while consumers keep the same `GLTexture` reference. */\n handle: WebGLTexture;\n /** GL texture target (normally `gl.TEXTURE_2D`); 3D textures use their own API. */\n readonly target: GLenum;\n /** Texture width in texels. Updated once an async upload resolves. */\n width: number;\n /** Texture height in texels. Updated once an async upload resolves. */\n height: number;\n /** True when the texture is safe to sample with final content (placeholders\n * read as not-ready until their image/upload completes). */\n isReady: boolean;\n /** @internal */\n _disposed: boolean;\n /** @internal */\n _refCount: number;\n /** Replays the latest pixel content into the currently bound texture handle. @internal */\n _upload: (engine: GLEngineContext) => void;\n /** Initializes creation-time sampling state on the bound texture handle. @internal */\n _initializeParameters?: (engine: GLEngineContext) => void;\n /**\n * Snapshot of `isReady` captured on `webglcontextlost` so the restore\n * handler knows whether to flip it back on after `_upload`. Textures\n * that were still mid-load (e.g. `loadTexture2D` whose bitmap hadn't\n * arrived) stay not-ready; the async path will set `isReady=true` once\n * the bitmap finishes decoding into the new handle.\n * @internal\n */\n _wasReady: boolean;\n /**\n * Live re-upload hook installed by `createRawTexture` — lets\n * `updateRawTexture` replace the pixel data (and optionally the size)\n * through the same closure that the context-restore replay uses, keeping\n * restore correct. Absent on image / HTML-element / external textures.\n * @internal\n */\n _updateRaw?: (engine: GLEngineContext, data: ArrayBufferView | null, width: number, height: number, unpackAlignment: number) => void;\n /**\n * Dynamic-texture source captured by `updateDynamicTexture`\n * (`@babylonjs/lite-gl`) and replayed into the fresh handle\n * on `webglcontextrestored`. Null/absent on non-dynamic textures.\n * @internal\n */\n _dynSource?: TexImageSource | null;\n /** UNPACK_FLIP_Y applied when replaying {@link GLTexture._dynSource}. @internal */\n _dynInvertY?: boolean;\n /** UNPACK_PREMULTIPLY_ALPHA applied when replaying {@link GLTexture._dynSource}. @internal */\n _dynPremultiplyAlpha?: boolean;\n /**\n * The `handle` the dynamic texture's `texParameteri` filter/wrap state was\n * last applied to. `texParameteri` is per-texture GL state that survives pixel\n * re-uploads, so the dynamic-texture `_upload` re-applies it ONLY when this no\n * longer matches `handle` — i.e. at creation and after `webglcontextrestored`\n * installs a fresh handle — not on every per-frame `updateDynamicTexture`.\n * @internal\n */\n _dynParamsHandle?: WebGLTexture | null;\n}\n\n/**\n * Apply the three `UNPACK_*` pixel-store flags through the GL-state cache,\n * eliding redundant `pixelStorei` calls. Centralising this guarantees EVERY\n * upload path sets all three explicitly, so a premultiplying / flipping upload\n * never leaks its flag into a later upload that forgot to set it.\n * @internal\n */\nexport function setUnpackState(engine: GLEngineContext, flipY: boolean, premultiplyAlpha: boolean, alignment = 4): void {\n const gl = engine.gl;\n const s = engine._state;\n const fy = flipY ? 1 : 0;\n if (s.unpackFlipY !== fy) {\n gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, fy);\n s.unpackFlipY = fy;\n }\n const pm = premultiplyAlpha ? 1 : 0;\n if (s.unpackPremultiplyAlpha !== pm) {\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, pm);\n s.unpackPremultiplyAlpha = pm;\n }\n if (s.unpackAlignment !== alignment) {\n gl.pixelStorei(gl.UNPACK_ALIGNMENT, alignment);\n s.unpackAlignment = alignment;\n }\n}\n\n/** Apply sampling and wrap state to the texture currently bound for upload. @internal */\nexport function setBoundTextureParams(gl: WebGL2RenderingContext, minFilter: GLenum, magFilter: GLenum, wrapS: GLenum, wrapT: GLenum): void {\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapT);\n}\n\n/** Uint8 / float raw texture upload. The pixel data can be replaced later via\n * {@link updateRawTexture}; the sampling and wrap can be changed via\n * {@link updateTextureSamplingMode} / {@link updateTextureWrapMode}. */\nexport function createRawTexture(\n engine: GLEngineContext,\n data: ArrayBufferView | null,\n width: number,\n height: number,\n format: GLenum,\n type: GLenum,\n options?: GLTextureOptions\n): GLTexture {\n const gl = engine.gl;\n const handle = gl.createTexture();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createTexture returned null\");\n }\n const opts = options ?? {};\n const minFilter = opts.minFilter ?? gl.LINEAR;\n const magFilter = opts.magFilter ?? gl.LINEAR;\n const wrapS = opts.wrapS ?? gl.CLAMP_TO_EDGE;\n const wrapT = opts.wrapT ?? gl.CLAMP_TO_EDGE;\n const invertY = opts.invertY ?? false;\n const premultiply = opts.premultiplyAlpha ?? false;\n // LDR byte formats are resolved INLINE here; the float-format table in\n // `pickSizedInternalFormat` is deliberately NOT referenced from this path so\n // it tree-shakes out of byte-only bundles. `createFloatTexture` injects its\n // sized float format via `opts.internalFormat`.\n const internalFormat = opts.internalFormat ?? resolveLdrInternalFormat(gl, format, type);\n\n // Mutable upload state — `updateRawTexture` mutates these and re-runs\n // `upload`, so the context-restore replay (which calls the same `upload`)\n // always reproduces the latest contents.\n let curData = data;\n let curWidth = width;\n let curHeight = height;\n let curAlign = opts.unpackAlignment ?? 4;\n\n const upload = (target: GLEngineContext): void => {\n const g = target.gl;\n setUnpackState(target, invertY, premultiply, curAlign);\n bindTextureForUpload(target, tex.handle);\n g.texImage2D(g.TEXTURE_2D, 0, internalFormat, curWidth, curHeight, 0, format, type, curData);\n };\n\n const initializeParameters = (target: GLEngineContext): void => {\n setBoundTextureParams(target.gl, minFilter, magFilter, wrapS, wrapT);\n };\n\n const tex: GLTexture = {\n handle,\n target: gl.TEXTURE_2D,\n width,\n height,\n isReady: true,\n _disposed: false,\n _refCount: 1,\n _upload: upload,\n _initializeParameters: initializeParameters,\n _wasReady: true,\n };\n tex._updateRaw = (target: GLEngineContext, newData: ArrayBufferView | null, newWidth: number, newHeight: number, unpackAlignment: number): void => {\n curData = newData;\n curWidth = newWidth;\n curHeight = newHeight;\n curAlign = unpackAlignment;\n tex.width = newWidth;\n tex.height = newHeight;\n upload(target);\n };\n upload(engine);\n initializeParameters(engine);\n engine._textures.add(tex);\n return tex;\n}\n\n/** Options for {@link createFloatTexture} — the shared {@link GLTextureOptions}\n * plus the float-specific `type` / `format`. */\nexport interface GLFloatTextureOptions extends GLTextureOptions {\n /** Float texel type — `gl.HALF_FLOAT` (default) or `gl.FLOAT`. */\n type?: GLenum;\n /** Color format. Default `gl.RGBA`. */\n format?: GLenum;\n}\n\n/**\n * Create a float / half-float raw texture — the HDR counterpart of\n * {@link createRawTexture}. This is the ONLY texture factory that carries the\n * `RGBA16F` / `RGBA32F` sized-format knowledge (via {@link pickSizedInternalFormat}),\n * so byte-only consumers calling {@link createRawTexture} ship none of it.\n * Defaults to `gl.HALF_FLOAT`; pass `options.type = gl.FLOAT` for full 32-bit.\n * The caller is responsible for the matching engine cap (e.g.\n * `caps.textureFloatLinearFiltering`) when sampling these with `LINEAR`.\n *\n * @param engine - The engine.\n * @param data - Initial pixels (`Float32Array` for FLOAT, `Uint16Array` for\n * HALF_FLOAT), or `null` for an uninitialised allocation.\n * @param width - Texture width in texels (≥ 1).\n * @param height - Texture height in texels (≥ 1).\n * @param options - See {@link GLFloatTextureOptions}.\n * @returns The new {@link GLTexture}.\n */\nexport function createFloatTexture(engine: GLEngineContext, data: ArrayBufferView | null, width: number, height: number, options?: GLFloatTextureOptions): GLTexture {\n const gl = engine.gl;\n const o = options ?? {};\n const format = o.format ?? gl.RGBA;\n const type = o.type ?? gl.HALF_FLOAT;\n // Precompute the sized float internalFormat HERE and pass it through, so\n // `createRawTexture`'s inline LDR resolver is bypassed and the float table\n // stays out of byte-only bundles.\n const internalFormat = pickSizedInternalFormat(gl, format, type);\n return createRawTexture(engine, data, width, height, format, type, { ...o, internalFormat });\n}\n\n/** Generate the mip chain for a texture from its level-0 contents — mipmaps as\n * an explicit opt-in function rather than baked into the create path. Binds for\n * upload (unit 0). No-op on a lost/disposed context or a handle-less texture. */\nexport function generateTextureMipMaps(engine: GLEngineContext, tex: GLTexture): void {\n if (engine._isLost || engine._disposed || tex._disposed || tex.handle === null) {\n return;\n }\n bindTextureForUpload(engine, tex.handle);\n engine.gl.generateMipmap(engine.gl.TEXTURE_2D);\n}\n\n/**\n * Re-upload the pixel data (and optionally resize) of a texture created by\n * {@link createRawTexture} — the lite-gl equivalent of Babylon's\n * `updateRawTexture` / `_uploadDataToTextureDirectly`. Goes through the same\n * upload closure used by context-restore, so the new contents survive a context\n * loss. No-op on a lost/disposed/non-raw texture.\n *\n * @param engine - The engine.\n * @param tex - The raw texture to update.\n * @param data - New pixel data (must match the original `format`/`type`).\n * @param options - Optional new `width`/`height` (default: unchanged) and\n * `unpackAlignment` (default 4).\n */\nexport function updateRawTexture(\n engine: GLEngineContext,\n tex: GLTexture,\n data: ArrayBufferView | null,\n options?: { width?: number; height?: number; unpackAlignment?: number }\n): void {\n if (engine._isLost || engine._disposed || tex._disposed || tex._updateRaw === undefined) {\n return;\n }\n const o = options ?? {};\n tex._updateRaw(engine, data, o.width ?? tex.width, o.height ?? tex.height, o.unpackAlignment ?? 4);\n}\n\n/** Update a texture's min/mag sampling filters — the lite-gl equivalent of\n * Babylon's `updateTextureSamplingMode`. Binds for upload (unit 0) so the\n * `texParameteri` lands on this texture. No-op on a lost/disposed context. */\nexport function updateTextureSamplingMode(engine: GLEngineContext, tex: GLTexture, minFilter: GLenum, magFilter: GLenum): void {\n if (engine._isLost || engine._disposed || tex._disposed) {\n return;\n }\n const gl = engine.gl;\n bindTextureForUpload(engine, tex.handle);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);\n}\n\n/** Update a texture's S/T wrap modes (`gl.CLAMP_TO_EDGE` / `gl.REPEAT` /\n * `gl.MIRRORED_REPEAT`) — the lite-gl equivalent of Babylon's\n * `updateTextureWrappingMode`. No-op on a lost/disposed context. */\nexport function updateTextureWrapMode(engine: GLEngineContext, tex: GLTexture, wrapS: GLenum, wrapT: GLenum): void {\n if (engine._isLost || engine._disposed || tex._disposed) {\n return;\n }\n const gl = engine.gl;\n bindTextureForUpload(engine, tex.handle);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapT);\n}\n\n/**\n * Wrap an existing raw `WebGLTexture` (e.g. one created by a host renderer or a\n * previous engine) as a {@link GLTexture} — the lite-gl equivalent of\n * ShapeBuilder's `createTextureGraphicsResourceFromExternalWebGLTexture`.\n *\n * The wrapper does NOT own the underlying handle's upload — it is NOT registered\n * for context-restore replay (the external owner is responsible for that) and is\n * marked ready immediately. `disposeTexture` will still `gl.deleteTexture` it, so\n * only wrap a handle whose deletion you intend lite-gl to manage.\n *\n * @param engine - The engine.\n * @param handle - The external `WebGLTexture`.\n * @param width - Texture width in texels.\n * @param height - Texture height in texels.\n * @param options - Optional sampling/wrap to apply once (min/mag/wrapS/wrapT).\n * @returns A {@link GLTexture} wrapping the handle.\n */\nexport function createTextureFromHandle(engine: GLEngineContext, handle: WebGLTexture, width: number, height: number, options?: GLTextureOptions): GLTexture {\n const tex: GLTexture = {\n handle,\n target: engine.gl.TEXTURE_2D,\n width,\n height,\n isReady: true,\n _disposed: false,\n _refCount: 1,\n // External handle — restore replay is the external owner's job.\n _upload: () => {},\n _wasReady: true,\n };\n if (options !== undefined) {\n const gl = engine.gl;\n bindTextureForUpload(engine, handle);\n setBoundTextureParams(gl, options.minFilter ?? gl.LINEAR, options.magFilter ?? gl.LINEAR, options.wrapS ?? gl.CLAMP_TO_EDGE, options.wrapT ?? gl.CLAMP_TO_EDGE);\n }\n return tex;\n}\n\n/** Asynchronous image upload.The returned texture is immediately usable (1×1\n * transparent placeholder); `isReady` flips true once the image has been\n * decoded and uploaded. The decoded `ImageBitmap` is retained on the texture\n * for offline-safe `webglcontextrestored` replay. */\nexport function loadTexture2D(engine: GLEngineContext, url: string, options?: GLTextureOptions, onLoad?: (tex: GLTexture) => void, onError?: (err: Error) => void): GLTexture {\n const gl = engine.gl;\n const handle = gl.createTexture();\n if (handle === null) {\n throw new Error(\"lite-gl: gl.createTexture returned null\");\n }\n const opts = options ?? {};\n const minFilter = opts.minFilter ?? gl.LINEAR;\n const magFilter = opts.magFilter ?? gl.LINEAR;\n const wrapS = opts.wrapS ?? gl.CLAMP_TO_EDGE;\n const wrapT = opts.wrapT ?? gl.CLAMP_TO_EDGE;\n const invertY = opts.invertY ?? false;\n\n let bitmap: ImageBitmap | null = null;\n const placeholderPixels = new Uint8Array([0, 0, 0, 0]);\n\n const upload = (target: GLEngineContext): void => {\n const g = target.gl;\n // invertY is applied at decode time via createImageBitmap({ imageOrientation })\n // because UNPACK_FLIP_Y_WEBGL is IGNORED for ImageBitmap sources (and the 1×1\n // placeholder is flip-invariant), so keep flip + premultiply off here.\n setUnpackState(target, false, false);\n bindTextureForUpload(target, tex.handle);\n if (bitmap !== null) {\n g.texImage2D(g.TEXTURE_2D, 0, g.RGBA, g.RGBA, g.UNSIGNED_BYTE, bitmap);\n tex.width = bitmap.width;\n tex.height = bitmap.height;\n } else {\n g.texImage2D(g.TEXTURE_2D, 0, g.RGBA, 1, 1, 0, g.RGBA, g.UNSIGNED_BYTE, placeholderPixels);\n }\n };\n\n const initializeParameters = (target: GLEngineContext): void => {\n setBoundTextureParams(target.gl, minFilter, magFilter, wrapS, wrapT);\n };\n\n const tex: GLTexture = {\n handle,\n target: gl.TEXTURE_2D,\n width: 1,\n height: 1,\n isReady: false,\n _disposed: false,\n _refCount: 1,\n _upload: upload,\n _initializeParameters: initializeParameters,\n _wasReady: false,\n };\n // Placeholder upload — makes the texture sampleable before the real image arrives.\n upload(engine);\n initializeParameters(engine);\n engine._textures.add(tex);\n\n // Fetch + decode the real image. Re-uploads via the same closure once the\n // bitmap is in hand (so context-restore replay sees the real image too).\n fetch(url)\n .then((r) => {\n if (!r.ok) {\n throw new Error(`lite-gl: fetch ${url} -> HTTP ${r.status}`);\n }\n return r.blob();\n })\n .then((blob) => createImageBitmap(blob, { premultiplyAlpha: \"none\", imageOrientation: invertY ? \"flipY\" : \"none\" }))\n .then((bm) => {\n if (tex._disposed) {\n bm.close();\n return;\n }\n bitmap = bm;\n // If the context is lost mid-flight, defer the upload — the restore\n // handler will call _upload again, which will then see `bitmap !== null`\n // and replay the real image.\n if (!engine._isLost) {\n upload(engine);\n tex.isReady = true;\n }\n tex._wasReady = true;\n if (onLoad !== undefined) {\n onLoad(tex);\n }\n })\n .catch((err: unknown) => {\n const e = err instanceof Error ? err : new Error(String(err));\n if (onError !== undefined) {\n onError(e);\n } else {\n console.error(\"lite-gl: loadTexture2D failed\", e);\n }\n });\n\n return tex;\n}\n\n/** Cached bind. Skips `gl.activeTexture` and/or `gl.bindTexture` when nothing\n * changes. No-op when `tex._disposed` or `engine._isLost`. */\nexport function bindTexture(engine: GLEngineContext, unit: number, tex: GLTexture | null): void {\n if (engine._isLost || engine._disposed) {\n return;\n }\n if (tex !== null && tex._disposed) {\n return;\n }\n bindTextureRaw(engine, unit, tex === null ? null : tex.handle);\n}\n\n/** @internal — for callers that already hold a raw `WebGLTexture`. Not part of\n * the public API: `bindTexture` (public) and the texture `_upload` closures bind\n * through the cache, so consumers never call this directly. */\nexport function bindTextureRaw(engine: GLEngineContext, unit: number, handle: WebGLTexture | null): void {\n const s = engine._state;\n const gl = engine.gl;\n if (s.boundTextures[unit] === handle) {\n return;\n }\n if (s.activeTextureUnit !== unit) {\n gl.activeTexture(gl.TEXTURE0 + unit);\n s.activeTextureUnit = unit;\n }\n gl.bindTexture(gl.TEXTURE_2D, handle);\n s.boundTextures[unit] = handle;\n}\n\n/** @internal Bind `handle` on texture unit 0 **for an upload** (`texImage2D`).\n * Unlike {@link bindTextureRaw} — which elides the entire bind when the handle is\n * already bound on the unit (correct for *sampling*, where the active unit is\n * irrelevant) — an upload writes into the texture on the ACTIVE unit. A prior\n * multi-sampler draw may have left a non-zero unit active while this handle is\n * still bound on unit 0, so we must force unit 0 active even on a bind cache-hit,\n * keeping the `_state` cache coherent. */\nexport function bindTextureForUpload(engine: GLEngineContext, handle: WebGLTexture): void {\n const s = engine._state;\n const gl = engine.gl;\n if (s.activeTextureUnit !== 0) {\n gl.activeTexture(gl.TEXTURE0);\n s.activeTextureUnit = 0;\n }\n if (s.boundTextures[0] !== handle) {\n gl.bindTexture(gl.TEXTURE_2D, handle);\n s.boundTextures[0] = handle;\n }\n}\n\n/** Disposes the texture. Walks `_state.boundTextures` and clears every slot\n * that still references the handle — otherwise a later `bindTexture(unit, B)`\n * to the same unit would be wrongly elided when slot still showed handle A.\n * Deregistration is expected O(1), independent of the live texture count.\n * Shared references keep the texture registered until its final release;\n * repeated disposal is a no-op. Unregistered wrappers keep their existing\n * handle-deletion semantics without affecting the live registry. */\nexport function disposeTexture(engine: GLEngineContext, tex: GLTexture): void {\n if (tex._disposed) {\n return;\n }\n if (tex._refCount > 1) {\n tex._refCount--;\n return;\n }\n tex._disposed = true;\n engine._textures.delete(tex);\n if (!engine._isLost && !engine._disposed) {\n engine.gl.deleteTexture(tex.handle);\n }\n const bound = engine._state.boundTextures;\n for (let u = 0; u < bound.length; u++) {\n if (bound[u] === tex.handle) {\n bound[u] = null;\n }\n }\n}\n\n/** Internal — resolve the sized internalFormat for the LDR (byte) `texImage2D`\n * paths ONLY: RGBA→RGBA8, RGB→RGB8, RG→RG8, RED→R8, LUMINANCE passthrough.\n * Deliberately knows nothing about FLOAT / HALF_FLOAT so the float-format table\n * in {@link pickSizedInternalFormat} tree-shakes out of byte-only bundles.\n * @internal */\nfunction resolveLdrInternalFormat(gl: WebGL2RenderingContext, format: GLenum, type: GLenum): GLenum {\n if (type === gl.UNSIGNED_BYTE) {\n if (format === gl.RGBA) {\n return gl.RGBA8;\n }\n if (format === gl.RGB) {\n return gl.RGB8;\n }\n if (format === gl.RG) {\n return gl.RG8;\n }\n if (format === gl.RED) {\n return gl.R8;\n }\n if (format === gl.LUMINANCE) {\n return gl.LUMINANCE;\n }\n }\n return format;\n}\n\n/** Internal — pick a sized internalFormat for `texImage2D`. WebGL2 prefers\n * sized formats for non-color-renderable / non-readback paths; for the\n * NeonBrush use cases (sample-only) the unsized format works too, but sized\n * is more portable. Shared with the render-target module.\n * @internal */\nexport function pickSizedInternalFormat(gl: WebGL2RenderingContext, format: GLenum, type: GLenum): GLenum {\n if (type === gl.UNSIGNED_BYTE) {\n if (format === gl.RGBA) {\n return gl.RGBA8;\n }\n if (format === gl.RGB) {\n return gl.RGB8;\n }\n if (format === gl.LUMINANCE) {\n return gl.LUMINANCE;\n }\n }\n if (type === gl.FLOAT) {\n if (format === gl.RGBA) {\n return gl.RGBA32F;\n }\n if (format === gl.RGB) {\n return gl.RGB32F;\n }\n }\n if (type === gl.HALF_FLOAT) {\n if (format === gl.RGBA) {\n return gl.RGBA16F;\n }\n if (format === gl.RGB) {\n return gl.RGB16F;\n }\n }\n return format;\n}\n"]}
|