@lightningjs/renderer 2.20.0 → 2.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/canvas-shaders.d.ts +10 -0
- package/dist/exports/canvas-shaders.js +27 -0
- package/dist/exports/canvas-shaders.js.map +1 -0
- package/dist/exports/webgl-shaders.d.ts +11 -0
- package/dist/exports/webgl-shaders.js +28 -0
- package/dist/exports/webgl-shaders.js.map +1 -0
- package/dist/src/common/CommonTypes.d.ts +11 -0
- package/dist/src/core/AutosizeManager.d.ts +29 -0
- package/dist/src/core/AutosizeManager.js +171 -0
- package/dist/src/core/AutosizeManager.js.map +1 -0
- package/dist/src/core/CoreNode.d.ts +1 -1
- package/dist/src/core/CoreNode.js +8 -0
- package/dist/src/core/CoreNode.js.map +1 -1
- package/dist/src/core/Stage.js +2 -1
- package/dist/src/core/Stage.js.map +1 -1
- package/dist/src/core/animations/Animation.d.ts +16 -0
- package/dist/src/core/animations/Animation.js +111 -0
- package/dist/src/core/animations/Animation.js.map +1 -0
- package/dist/src/core/animations/CoreTransition.d.ts +24 -0
- package/dist/src/core/animations/CoreTransition.js +63 -0
- package/dist/src/core/animations/CoreTransition.js.map +1 -0
- package/dist/src/core/animations/Playback.d.ts +62 -0
- package/dist/src/core/animations/Playback.js +155 -0
- package/dist/src/core/animations/Playback.js.map +1 -0
- package/dist/src/core/animations/Transition.d.ts +25 -0
- package/dist/src/core/animations/Transition.js +63 -0
- package/dist/src/core/animations/Transition.js.map +1 -0
- package/dist/src/core/animations/utils.d.ts +2 -0
- package/dist/src/core/animations/utils.js +137 -0
- package/dist/src/core/animations/utils.js.map +1 -0
- package/dist/src/core/lib/WebGlContextWrapper.d.ts +5 -5
- package/dist/src/core/lib/collectionUtils.d.ts +5 -0
- package/dist/src/core/lib/collectionUtils.js +100 -0
- package/dist/src/core/lib/collectionUtils.js.map +1 -0
- package/dist/src/core/lib/colorCache.d.ts +1 -0
- package/dist/src/core/lib/colorCache.js +19 -0
- package/dist/src/core/lib/colorCache.js.map +1 -0
- package/dist/src/core/lib/colorParser.d.ts +21 -0
- package/dist/src/core/lib/colorParser.js +72 -0
- package/dist/src/core/lib/colorParser.js.map +1 -0
- package/dist/src/core/platforms/Platform.d.ts +42 -0
- package/dist/src/core/platforms/Platform.js +22 -0
- package/dist/src/core/platforms/Platform.js.map +1 -0
- package/dist/src/core/platforms/web/WebPlatform.d.ts +10 -0
- package/dist/src/core/platforms/web/WebPlatform.js +87 -0
- package/dist/src/core/platforms/web/WebPlatform.js.map +1 -0
- package/dist/src/core/renderers/CoreShaderNode.d.ts +59 -0
- package/dist/src/core/renderers/CoreShaderNode.js +113 -0
- package/dist/src/core/renderers/CoreShaderNode.js.map +1 -0
- package/dist/src/core/renderers/CoreShaderProgram.d.ts +4 -0
- package/dist/src/core/renderers/CoreShaderProgram.js +20 -0
- package/dist/src/core/renderers/CoreShaderProgram.js.map +1 -0
- package/dist/src/core/renderers/canvas/CanvasRenderer.d.ts +35 -0
- package/dist/src/core/renderers/canvas/CanvasRenderer.js +201 -0
- package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +1 -0
- package/dist/src/core/renderers/canvas/CanvasShaderNode.d.ts +21 -0
- package/dist/src/core/renderers/canvas/CanvasShaderNode.js +58 -0
- package/dist/src/core/renderers/canvas/CanvasShaderNode.js.map +1 -0
- package/dist/src/core/renderers/canvas/CanvasTexture.d.ts +16 -0
- package/dist/src/core/renderers/canvas/CanvasTexture.js +125 -0
- package/dist/src/core/renderers/canvas/CanvasTexture.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.d.ts +12 -0
- package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js +57 -0
- package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.d.ts +22 -0
- package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js +67 -0
- package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlCtxTexture.d.ts +56 -0
- package/dist/src/core/renderers/webgl/WebGlCtxTexture.js +236 -0
- package/dist/src/core/renderers/webgl/WebGlCtxTexture.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlRenderOp.d.ts +44 -0
- package/dist/src/core/renderers/webgl/WebGlRenderOp.js +125 -0
- package/dist/src/core/renderers/webgl/WebGlRenderOp.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlRenderer.d.ts +136 -0
- package/dist/src/core/renderers/webgl/WebGlRenderer.js +573 -0
- package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlShaderNode.d.ts +222 -0
- package/dist/src/core/renderers/webgl/WebGlShaderNode.js +331 -0
- package/dist/src/core/renderers/webgl/WebGlShaderNode.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.d.ts +37 -0
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.js +218 -0
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +1 -0
- package/dist/src/core/renderers/webgl/shaders/effects/RadiusEffect.js +5 -5
- package/dist/src/core/shaders/canvas/Border.d.ts +9 -0
- package/dist/src/core/shaders/canvas/Border.js +57 -0
- package/dist/src/core/shaders/canvas/Border.js.map +1 -0
- package/dist/src/core/shaders/canvas/HolePunch.d.ts +7 -0
- package/dist/src/core/shaders/canvas/HolePunch.js +38 -0
- package/dist/src/core/shaders/canvas/HolePunch.js.map +1 -0
- package/dist/src/core/shaders/canvas/LinearGradient.d.ts +10 -0
- package/dist/src/core/shaders/canvas/LinearGradient.js +48 -0
- package/dist/src/core/shaders/canvas/LinearGradient.js.map +1 -0
- package/dist/src/core/shaders/canvas/RadialGradient.d.ts +11 -0
- package/dist/src/core/shaders/canvas/RadialGradient.js +70 -0
- package/dist/src/core/shaders/canvas/RadialGradient.js.map +1 -0
- package/dist/src/core/shaders/canvas/Rounded.d.ts +7 -0
- package/dist/src/core/shaders/canvas/Rounded.js +33 -0
- package/dist/src/core/shaders/canvas/Rounded.js.map +1 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorder.d.ts +7 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorder.js +43 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorder.js.map +1 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.d.ts +8 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js +41 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js.map +1 -0
- package/dist/src/core/shaders/canvas/RoundedWithShadow.d.ts +7 -0
- package/dist/src/core/shaders/canvas/RoundedWithShadow.js +40 -0
- package/dist/src/core/shaders/canvas/RoundedWithShadow.js.map +1 -0
- package/dist/src/core/shaders/canvas/Shadow.d.ts +8 -0
- package/dist/src/core/shaders/canvas/Shadow.js +31 -0
- package/dist/src/core/shaders/canvas/Shadow.js.map +1 -0
- package/dist/src/core/shaders/canvas/utils/render.d.ts +5 -0
- package/dist/src/core/shaders/canvas/utils/render.js +84 -0
- package/dist/src/core/shaders/canvas/utils/render.js.map +1 -0
- package/dist/src/core/shaders/templates/BorderTemplate.d.ts +37 -0
- package/dist/src/core/shaders/templates/BorderTemplate.js +73 -0
- package/dist/src/core/shaders/templates/BorderTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/HolePunchTemplate.d.ts +46 -0
- package/dist/src/core/shaders/templates/HolePunchTemplate.js +35 -0
- package/dist/src/core/shaders/templates/HolePunchTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/LinearGradientTemplate.d.ts +23 -0
- package/dist/src/core/shaders/templates/LinearGradientTemplate.js +47 -0
- package/dist/src/core/shaders/templates/LinearGradientTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/RadialGradientTemplate.d.ts +31 -0
- package/dist/src/core/shaders/templates/RadialGradientTemplate.js +49 -0
- package/dist/src/core/shaders/templates/RadialGradientTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/RoundedTemplate.d.ts +29 -0
- package/dist/src/core/shaders/templates/RoundedTemplate.js +67 -0
- package/dist/src/core/shaders/templates/RoundedTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.d.ts +7 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.js +24 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.d.ts +6 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.js +23 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.d.ts +6 -0
- package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.js +23 -0
- package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/ShadowTemplate.d.ts +34 -0
- package/dist/src/core/shaders/templates/ShadowTemplate.js +66 -0
- package/dist/src/core/shaders/templates/ShadowTemplate.js.map +1 -0
- package/dist/src/core/shaders/utils.d.ts +5 -0
- package/dist/src/core/shaders/utils.js +41 -0
- package/dist/src/core/shaders/utils.js.map +1 -0
- package/dist/src/core/shaders/webgl/Border.d.ts +3 -0
- package/dist/src/core/shaders/webgl/Border.js +110 -0
- package/dist/src/core/shaders/webgl/Border.js.map +1 -0
- package/dist/src/core/shaders/webgl/Default.d.ts +2 -0
- package/dist/src/core/shaders/webgl/Default.js +86 -0
- package/dist/src/core/shaders/webgl/Default.js.map +1 -0
- package/dist/src/core/shaders/webgl/DefaultBatched.d.ts +2 -0
- package/dist/src/core/shaders/webgl/DefaultBatched.js +104 -0
- package/dist/src/core/shaders/webgl/DefaultBatched.js.map +1 -0
- package/dist/src/core/shaders/webgl/HolePunch.d.ts +3 -0
- package/dist/src/core/shaders/webgl/HolePunch.js +65 -0
- package/dist/src/core/shaders/webgl/HolePunch.js.map +1 -0
- package/dist/src/core/shaders/webgl/LinearGradient.d.ts +3 -0
- package/dist/src/core/shaders/webgl/LinearGradient.js +100 -0
- package/dist/src/core/shaders/webgl/LinearGradient.js.map +1 -0
- package/dist/src/core/shaders/webgl/RadialGradient.d.ts +3 -0
- package/dist/src/core/shaders/webgl/RadialGradient.js +97 -0
- package/dist/src/core/shaders/webgl/RadialGradient.js.map +1 -0
- package/dist/src/core/shaders/webgl/Rounded.d.ts +7 -0
- package/dist/src/core/shaders/webgl/Rounded.js +86 -0
- package/dist/src/core/shaders/webgl/Rounded.js.map +1 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorder.d.ts +3 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorder.js +140 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorder.js.map +1 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.d.ts +3 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +162 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js.map +1 -0
- package/dist/src/core/shaders/webgl/RoundedWithShadow.d.ts +3 -0
- package/dist/src/core/shaders/webgl/RoundedWithShadow.js +84 -0
- package/dist/src/core/shaders/webgl/RoundedWithShadow.js.map +1 -0
- package/dist/src/core/shaders/webgl/SdfShader.d.ts +30 -0
- package/dist/src/core/shaders/webgl/SdfShader.js +107 -0
- package/dist/src/core/shaders/webgl/SdfShader.js.map +1 -0
- package/dist/src/core/shaders/webgl/Shadow.d.ts +3 -0
- package/dist/src/core/shaders/webgl/Shadow.js +110 -0
- package/dist/src/core/shaders/webgl/Shadow.js.map +1 -0
- package/dist/src/core/text-rendering/CanvasFontHandler.d.ts +59 -0
- package/dist/src/core/text-rendering/CanvasFontHandler.js +224 -0
- package/dist/src/core/text-rendering/CanvasFontHandler.js.map +1 -0
- package/dist/src/core/text-rendering/CanvasTextRenderer.d.ts +17 -0
- package/dist/src/core/text-rendering/CanvasTextRenderer.js +157 -0
- package/dist/src/core/text-rendering/CanvasTextRenderer.js.map +1 -0
- package/dist/src/core/text-rendering/SdfFontHandler.d.ts +182 -0
- package/dist/src/core/text-rendering/SdfFontHandler.js +391 -0
- package/dist/src/core/text-rendering/SdfFontHandler.js.map +1 -0
- package/dist/src/core/text-rendering/SdfTextRenderer.d.ts +17 -0
- package/dist/src/core/text-rendering/SdfTextRenderer.js +311 -0
- package/dist/src/core/text-rendering/SdfTextRenderer.js.map +1 -0
- package/dist/src/core/text-rendering/TextLayoutEngine.d.ts +18 -0
- package/dist/src/core/text-rendering/TextLayoutEngine.js +380 -0
- package/dist/src/core/text-rendering/TextLayoutEngine.js.map +1 -0
- package/dist/src/core/text-rendering/TextRenderer.d.ts +383 -0
- package/dist/src/core/text-rendering/TextRenderer.js +20 -0
- package/dist/src/core/text-rendering/TextRenderer.js.map +1 -0
- package/dist/src/core/text-rendering/Utils.d.ts +30 -0
- package/dist/src/core/text-rendering/Utils.js +84 -0
- package/dist/src/core/text-rendering/Utils.js.map +1 -0
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/common/CommonTypes.ts +16 -0
- package/src/core/CoreNode.test.ts +49 -0
- package/src/core/CoreNode.ts +10 -0
- package/src/core/Stage.ts +3 -1
- package/src/core/renderers/webgl/shaders/effects/RadiusEffect.ts +5 -5
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* If not stated otherwise in this file or this component's LICENSE file the
|
|
3
|
+
* following copyright and licenses apply:
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2023 Comcast Cable Communications Management, LLC.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the License);
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { assertTruthy } from '../../../utils.js';
|
|
20
|
+
import { formatRgba } from '../../lib/colorParser.js';
|
|
21
|
+
import { CoreContextTexture } from '../CoreContextTexture.js';
|
|
22
|
+
export class CanvasTexture extends CoreContextTexture {
|
|
23
|
+
image;
|
|
24
|
+
tintCache;
|
|
25
|
+
async load() {
|
|
26
|
+
this.textureSource.setState('loading');
|
|
27
|
+
try {
|
|
28
|
+
const size = await this.onLoadRequest();
|
|
29
|
+
this.textureSource.setState('loaded', size);
|
|
30
|
+
this.textureSource.freeTextureData();
|
|
31
|
+
this.updateMemSize();
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
this.textureSource.setState('failed', err);
|
|
35
|
+
this.textureSource.freeTextureData();
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
free() {
|
|
40
|
+
this.image = undefined;
|
|
41
|
+
this.tintCache = undefined;
|
|
42
|
+
this.textureSource.setState('freed');
|
|
43
|
+
this.setTextureMemUse(0);
|
|
44
|
+
this.textureSource.freeTextureData();
|
|
45
|
+
}
|
|
46
|
+
updateMemSize() {
|
|
47
|
+
// Counting memory usage for:
|
|
48
|
+
// - main image
|
|
49
|
+
// - tinted image
|
|
50
|
+
const mult = this.tintCache ? 8 : 4;
|
|
51
|
+
if (this.textureSource.dimensions) {
|
|
52
|
+
this.setTextureMemUse(this.textureSource.dimensions.w *
|
|
53
|
+
this.textureSource.dimensions.h *
|
|
54
|
+
mult);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
hasImage() {
|
|
58
|
+
return this.image !== undefined;
|
|
59
|
+
}
|
|
60
|
+
getImage(color) {
|
|
61
|
+
const image = this.image;
|
|
62
|
+
assertTruthy(image, 'Attempt to get unloaded image texture');
|
|
63
|
+
if (color.isWhite) {
|
|
64
|
+
if (this.tintCache) {
|
|
65
|
+
this.tintCache = undefined;
|
|
66
|
+
this.updateMemSize();
|
|
67
|
+
}
|
|
68
|
+
return image;
|
|
69
|
+
}
|
|
70
|
+
const key = formatRgba(color);
|
|
71
|
+
if (this.tintCache?.key === key) {
|
|
72
|
+
return this.tintCache.image;
|
|
73
|
+
}
|
|
74
|
+
const tintedImage = this.tintTexture(image, key);
|
|
75
|
+
this.tintCache = {
|
|
76
|
+
key,
|
|
77
|
+
image: tintedImage,
|
|
78
|
+
};
|
|
79
|
+
this.updateMemSize();
|
|
80
|
+
return tintedImage;
|
|
81
|
+
}
|
|
82
|
+
tintTexture(source, color) {
|
|
83
|
+
const { width, height } = source;
|
|
84
|
+
const canvas = document.createElement('canvas');
|
|
85
|
+
canvas.width = width;
|
|
86
|
+
canvas.height = height;
|
|
87
|
+
const ctx = canvas.getContext('2d');
|
|
88
|
+
if (ctx) {
|
|
89
|
+
// fill with target color
|
|
90
|
+
ctx.fillStyle = color;
|
|
91
|
+
ctx.globalCompositeOperation = 'copy';
|
|
92
|
+
ctx.fillRect(0, 0, width, height);
|
|
93
|
+
// multiply with image, resulting in non-transparent tinted image
|
|
94
|
+
ctx.globalCompositeOperation = 'multiply';
|
|
95
|
+
ctx.drawImage(source, 0, 0, width, height, 0, 0, width, height);
|
|
96
|
+
// apply original image alpha
|
|
97
|
+
ctx.globalCompositeOperation = 'destination-in';
|
|
98
|
+
ctx.drawImage(source, 0, 0, width, height, 0, 0, width, height);
|
|
99
|
+
}
|
|
100
|
+
return canvas;
|
|
101
|
+
}
|
|
102
|
+
async onLoadRequest() {
|
|
103
|
+
assertTruthy(this.textureSource?.textureData?.data, 'Texture data is null');
|
|
104
|
+
const { data } = this.textureSource.textureData;
|
|
105
|
+
// TODO: canvas from text renderer should be able to provide the canvas directly
|
|
106
|
+
// instead of having to re-draw it into a new canvas...
|
|
107
|
+
if (data instanceof ImageData) {
|
|
108
|
+
const canvas = document.createElement('canvas');
|
|
109
|
+
canvas.width = data.width;
|
|
110
|
+
canvas.height = data.height;
|
|
111
|
+
const ctx = canvas.getContext('2d');
|
|
112
|
+
if (ctx)
|
|
113
|
+
ctx.putImageData(data, 0, 0);
|
|
114
|
+
this.image = canvas;
|
|
115
|
+
return { w: data.width, h: data.height };
|
|
116
|
+
}
|
|
117
|
+
else if ((typeof ImageBitmap !== 'undefined' && data instanceof ImageBitmap) ||
|
|
118
|
+
data instanceof HTMLImageElement) {
|
|
119
|
+
this.image = data;
|
|
120
|
+
return { w: data.width, h: data.height };
|
|
121
|
+
}
|
|
122
|
+
return { w: 0, h: 0 };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=CanvasTexture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CanvasTexture.js","sourceRoot":"","sources":["../../../../../src/core/renderers/canvas/CanvasTexture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAqB,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,MAAM,OAAO,aAAc,SAAQ,kBAAkB;IACzC,KAAK,CAID;IACJ,SAAS,CAKL;IAEd,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAEvC,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;YACxC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAC5C,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,CAAC;YACrC,IAAI,CAAC,aAAa,EAAE,CAA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AC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Dimensions } from '../../../common/CommonTypes.js';
|
|
2
|
+
import type { TextureMemoryManager } from '../../TextureMemoryManager.js';
|
|
3
|
+
import type { WebGlContextWrapper } from '../../lib/WebGlContextWrapper.js';
|
|
4
|
+
import type { RenderTexture } from '../../textures/RenderTexture.js';
|
|
5
|
+
import { WebGlCtxTexture } from './WebGlCtxTexture.js';
|
|
6
|
+
export declare class WebGlCtxRenderTexture extends WebGlCtxTexture {
|
|
7
|
+
textureSource: RenderTexture;
|
|
8
|
+
framebuffer: WebGLFramebuffer | null;
|
|
9
|
+
constructor(glw: WebGlContextWrapper, memManager: TextureMemoryManager, textureSource: RenderTexture);
|
|
10
|
+
onLoadRequest(): Promise<Dimensions>;
|
|
11
|
+
free(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* If not stated otherwise in this file or this component's LICENSE file the
|
|
3
|
+
* following copyright and licenses apply:
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2024 Comcast Cable Communications Management, LLC.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the License);
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { WebGlCtxTexture } from './WebGlCtxTexture.js';
|
|
20
|
+
export class WebGlCtxRenderTexture extends WebGlCtxTexture {
|
|
21
|
+
framebuffer = null;
|
|
22
|
+
constructor(glw, memManager, textureSource) {
|
|
23
|
+
super(glw, memManager, textureSource);
|
|
24
|
+
}
|
|
25
|
+
async onLoadRequest() {
|
|
26
|
+
const { glw } = this;
|
|
27
|
+
const nativeTexture = (this._nativeCtxTexture =
|
|
28
|
+
this.createNativeCtxTexture());
|
|
29
|
+
if (!nativeTexture) {
|
|
30
|
+
throw new Error('Failed to create native texture for RenderTexture');
|
|
31
|
+
}
|
|
32
|
+
const { w, h } = this.textureSource;
|
|
33
|
+
// Create Framebuffer object
|
|
34
|
+
this.framebuffer = glw.createFramebuffer();
|
|
35
|
+
// Set the dimensions of the render texture
|
|
36
|
+
glw.texImage2D(0, glw.RGBA, w, h, 0, glw.RGBA, glw.UNSIGNED_BYTE, null);
|
|
37
|
+
// Update the texture memory manager
|
|
38
|
+
this.setTextureMemUse(w * h * 4);
|
|
39
|
+
// Bind the framebuffer
|
|
40
|
+
glw.bindFramebuffer(this.framebuffer);
|
|
41
|
+
// Attach the texture to the framebuffer
|
|
42
|
+
glw.framebufferTexture2D(glw.COLOR_ATTACHMENT0, nativeTexture, 0);
|
|
43
|
+
// Unbind the framebuffer
|
|
44
|
+
glw.bindFramebuffer(null);
|
|
45
|
+
return {
|
|
46
|
+
w,
|
|
47
|
+
h,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
free() {
|
|
51
|
+
super.free();
|
|
52
|
+
// Delete the framebuffer
|
|
53
|
+
this.glw.deleteFramebuffer(this.framebuffer);
|
|
54
|
+
this.framebuffer = null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=WebGlCtxRenderTexture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebGlCtxRenderTexture.js","sourceRoot":"","sources":["../../../../../src/core/renderers/webgl/WebGlCtxRenderTexture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,OAAO,EAAE,e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;QACX,KAAK,CAAC,IAAI,EAAE,CAAC;QAEb,yBAAyB;QACzB,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC7C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Dimensions } from '../../../common/CommonTypes.js';
|
|
2
|
+
import type { TextureMemoryManager } from '../../TextureMemoryManager.js';
|
|
3
|
+
import type { WebGlContextWrapper } from '../../lib/WebGlContextWrapper.js';
|
|
4
|
+
import type { SubTexture } from '../../textures/SubTexture.js';
|
|
5
|
+
import { WebGlCtxTexture } from './WebGlCtxTexture.js';
|
|
6
|
+
export declare class WebGlCtxSubTexture extends WebGlCtxTexture {
|
|
7
|
+
constructor(glw: WebGlContextWrapper, memManager: TextureMemoryManager, textureSource: SubTexture);
|
|
8
|
+
onLoadRequest(): Promise<Dimensions>;
|
|
9
|
+
/**
|
|
10
|
+
* Efficiently extracts width/height from polymorphic texture data
|
|
11
|
+
* Optimized for performance by using type guards and avoiding unnecessary property access
|
|
12
|
+
*/
|
|
13
|
+
private extractDimensions;
|
|
14
|
+
/**
|
|
15
|
+
* Type guard for objects with width/height properties
|
|
16
|
+
*/
|
|
17
|
+
private hasWidthHeight;
|
|
18
|
+
/**
|
|
19
|
+
* Type guard for objects with w/h properties
|
|
20
|
+
*/
|
|
21
|
+
private hasWH;
|
|
22
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* If not stated otherwise in this file or this component's LICENSE file the
|
|
3
|
+
* following copyright and licenses apply:
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2023 Comcast Cable Communications Management, LLC.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the License);
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { assertTruthy } from '../../../utils.js';
|
|
20
|
+
import { WebGlCtxTexture } from './WebGlCtxTexture.js';
|
|
21
|
+
export class WebGlCtxSubTexture extends WebGlCtxTexture {
|
|
22
|
+
constructor(glw, memManager, textureSource) {
|
|
23
|
+
super(glw, memManager, textureSource);
|
|
24
|
+
}
|
|
25
|
+
async onLoadRequest() {
|
|
26
|
+
const props = this.textureSource.textureData;
|
|
27
|
+
assertTruthy(props, 'SubTexture must have texture data');
|
|
28
|
+
if (props.data instanceof Uint8Array) {
|
|
29
|
+
// its a 1x1 Color Texture
|
|
30
|
+
return { w: 1, h: 1 };
|
|
31
|
+
}
|
|
32
|
+
return this.extractDimensions(props.data);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Efficiently extracts width/height from polymorphic texture data
|
|
36
|
+
* Optimized for performance by using type guards and avoiding unnecessary property access
|
|
37
|
+
*/
|
|
38
|
+
extractDimensions(data) {
|
|
39
|
+
if (data === null) {
|
|
40
|
+
return { w: 0, h: 0 };
|
|
41
|
+
}
|
|
42
|
+
// Check for standard web API objects first (most common case)
|
|
43
|
+
// These use width/height properties: ImageBitmap, ImageData, HTMLImageElement
|
|
44
|
+
if (this.hasWidthHeight(data) === true) {
|
|
45
|
+
return { w: data.width, h: data.height };
|
|
46
|
+
}
|
|
47
|
+
// Check for internal objects that use w/h properties: SubTextureProps, CompressedData
|
|
48
|
+
if (this.hasWH(data) === true) {
|
|
49
|
+
return { w: data.w, h: data.h };
|
|
50
|
+
}
|
|
51
|
+
// Fallback
|
|
52
|
+
return { w: 0, h: 0 };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Type guard for objects with width/height properties
|
|
56
|
+
*/
|
|
57
|
+
hasWidthHeight(data) {
|
|
58
|
+
return typeof data.width === 'number' && typeof data.height === 'number';
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Type guard for objects with w/h properties
|
|
62
|
+
*/
|
|
63
|
+
hasWH(data) {
|
|
64
|
+
return typeof data.w === 'number' && typeof data.h === 'number';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=WebGlCtxSubTexture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebGlCtxSubTexture.js","sourceRoot":"","sources":["../../../../../src/core/renderers/webgl/WebGlCtxSubTexture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAMjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,OAAO,kBAAmB,SAAQ,eAAe;IACrD,YACE,GAAwB,EACxB,UAAgC,EAChC,aAAyB;QAEzB,KAAK,CAAC,GAAG,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;IACxC,CAAC;IAEQ,KAAK,CAAC,aAAa;QAC1B,MAAM,KAAK,GAAI,IAAI,CAAC,aAA4B,CAAC,WAAW,CAAC;QAC7D,YAAY,CAAC,KAAK,EAAE,mCAAmC,CAAC,CAAC;QAEzD,IAAI,KAAK,CAAC,IAAI,YAAY,UAAU,EAAE,CAAC;YACrC,0BAA0B;YAC1B,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACxB,CAAC;QAED,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACK,iBAAiB,CACvB,IAMQ;QAER,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACxB,CAAC;QAED,8DAA8D;QAC9D,8EAA8E;QAC9E,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YACvC,OAAO,EAAE,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;QAC3C,CAAC;QAED,sFAAsF;QACtF,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YAC9B,OAAO,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;QAClC,CAAC;QAED,WAAW;QACX,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACxB,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,IAAS;QAC9B,OAAO,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC;IAC3E,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,IAAS;QACrB,OAAO,OAAO,IAAI,CAAC,CAAC,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,CAAC,KAAK,QAAQ,CAAC;IAClE,CAAC;CACF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Dimensions } from '../../../common/CommonTypes.js';
|
|
2
|
+
import type { TextureMemoryManager } from '../../TextureMemoryManager.js';
|
|
3
|
+
import type { WebGlContextWrapper } from '../../lib/WebGlContextWrapper.js';
|
|
4
|
+
import type { Texture } from '../../textures/Texture.js';
|
|
5
|
+
import { CoreContextTexture } from '../CoreContextTexture.js';
|
|
6
|
+
/**
|
|
7
|
+
* A wrapper around a WebGLTexture that handles loading the texture data
|
|
8
|
+
* from a Texture source and uploading it to the GPU as well as freeing
|
|
9
|
+
* the uploaded texture.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* When accessing the ctxTexture property, the texture will be loaded if
|
|
13
|
+
* it hasn't been already. ctxTexture will always return a valid WebGLTexture
|
|
14
|
+
* and trigger the loading/uploading of the texture's data if it hasn't been
|
|
15
|
+
* loaded yet.
|
|
16
|
+
*/
|
|
17
|
+
export declare class WebGlCtxTexture extends CoreContextTexture {
|
|
18
|
+
protected glw: WebGlContextWrapper;
|
|
19
|
+
protected _nativeCtxTexture: WebGLTexture | null;
|
|
20
|
+
private _w;
|
|
21
|
+
private _h;
|
|
22
|
+
constructor(glw: WebGlContextWrapper, memManager: TextureMemoryManager, textureSource: Texture);
|
|
23
|
+
get ctxTexture(): WebGLTexture | null;
|
|
24
|
+
get w(): number;
|
|
25
|
+
get h(): number;
|
|
26
|
+
/**
|
|
27
|
+
* Load the texture data from the Texture source and upload it to the GPU
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* This method is called automatically when accessing the ctxTexture property
|
|
31
|
+
* if the texture hasn't been loaded yet. But it can also be called manually
|
|
32
|
+
* to force the texture to be pre-loaded prior to accessing the ctxTexture
|
|
33
|
+
* property.
|
|
34
|
+
*/
|
|
35
|
+
load(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Called when the texture data needs to be loaded and uploaded to a texture
|
|
38
|
+
*/
|
|
39
|
+
onLoadRequest(): Promise<Dimensions>;
|
|
40
|
+
/**
|
|
41
|
+
* Free the WebGLTexture from the GPU
|
|
42
|
+
*
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
free(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Create native context texture asynchronously
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* When this method resolves, the returned texture will be bound to the GL context state
|
|
51
|
+
* and fully ready for use. This ensures proper GPU resource allocation timing.
|
|
52
|
+
*
|
|
53
|
+
* @returns Promise that resolves to the native WebGL texture or null on failure
|
|
54
|
+
*/
|
|
55
|
+
protected createNativeCtxTexture(): WebGLTexture | null;
|
|
56
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* If not stated otherwise in this file or this component's LICENSE file the
|
|
3
|
+
* following copyright and licenses apply:
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2023 Comcast Cable Communications Management, LLC.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the License);
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { CoreContextTexture } from '../CoreContextTexture.js';
|
|
20
|
+
import { isHTMLImageElement } from './internal/RendererUtils.js';
|
|
21
|
+
const TRANSPARENT_TEXTURE_DATA = new Uint8Array([0, 0, 0, 0]);
|
|
22
|
+
/**
|
|
23
|
+
* A wrapper around a WebGLTexture that handles loading the texture data
|
|
24
|
+
* from a Texture source and uploading it to the GPU as well as freeing
|
|
25
|
+
* the uploaded texture.
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* When accessing the ctxTexture property, the texture will be loaded if
|
|
29
|
+
* it hasn't been already. ctxTexture will always return a valid WebGLTexture
|
|
30
|
+
* and trigger the loading/uploading of the texture's data if it hasn't been
|
|
31
|
+
* loaded yet.
|
|
32
|
+
*/
|
|
33
|
+
export class WebGlCtxTexture extends CoreContextTexture {
|
|
34
|
+
glw;
|
|
35
|
+
_nativeCtxTexture = null;
|
|
36
|
+
_w = 0;
|
|
37
|
+
_h = 0;
|
|
38
|
+
constructor(glw, memManager, textureSource) {
|
|
39
|
+
super(memManager, textureSource);
|
|
40
|
+
this.glw = glw;
|
|
41
|
+
}
|
|
42
|
+
get ctxTexture() {
|
|
43
|
+
if (this.state === 'freed') {
|
|
44
|
+
this.load();
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return this._nativeCtxTexture;
|
|
48
|
+
}
|
|
49
|
+
get w() {
|
|
50
|
+
return this._w;
|
|
51
|
+
}
|
|
52
|
+
get h() {
|
|
53
|
+
return this._h;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Load the texture data from the Texture source and upload it to the GPU
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* This method is called automatically when accessing the ctxTexture property
|
|
60
|
+
* if the texture hasn't been loaded yet. But it can also be called manually
|
|
61
|
+
* to force the texture to be pre-loaded prior to accessing the ctxTexture
|
|
62
|
+
* property.
|
|
63
|
+
*/
|
|
64
|
+
async load() {
|
|
65
|
+
// If the texture is already loading or loaded, return resolved promise
|
|
66
|
+
if (this.state === 'loading' || this.state === 'loaded') {
|
|
67
|
+
return Promise.resolve();
|
|
68
|
+
}
|
|
69
|
+
this.state = 'loading';
|
|
70
|
+
this.textureSource.setState('loading');
|
|
71
|
+
// Await the native texture creation to ensure GPU buffer is fully allocated
|
|
72
|
+
this._nativeCtxTexture = this.createNativeCtxTexture();
|
|
73
|
+
if (this._nativeCtxTexture === null) {
|
|
74
|
+
this.state = 'failed';
|
|
75
|
+
const error = new Error('Could not create WebGL Texture');
|
|
76
|
+
this.textureSource.setState('failed', error);
|
|
77
|
+
console.error('Could not create WebGL Texture');
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const { w, h } = await this.onLoadRequest();
|
|
82
|
+
// If the texture has been freed while loading, return early.
|
|
83
|
+
// Type assertion needed because state could change during async operations
|
|
84
|
+
if (this.state === 'freed') {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
this.state = 'loaded';
|
|
88
|
+
this._w = w;
|
|
89
|
+
this._h = h;
|
|
90
|
+
// Update the texture source's width and height so that it can be used
|
|
91
|
+
// for rendering.
|
|
92
|
+
this.textureSource.setState('loaded', { w, h });
|
|
93
|
+
// cleanup source texture data next tick
|
|
94
|
+
// This is done using queueMicrotask to ensure it runs after the current
|
|
95
|
+
// event loop tick, allowing the texture to be fully loaded and bound
|
|
96
|
+
// to the GL context before freeing the source data.
|
|
97
|
+
// This is important to avoid issues with the texture data being
|
|
98
|
+
// freed while the texture is still being loaded or used.
|
|
99
|
+
queueMicrotask(() => {
|
|
100
|
+
this.textureSource.freeTextureData();
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
// If the texture has been freed while loading, return early.
|
|
105
|
+
// Type assertion needed because state could change during async operations
|
|
106
|
+
if (this.state === 'freed') {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
this.state = 'failed';
|
|
110
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
111
|
+
this.textureSource.setState('failed', error);
|
|
112
|
+
this.textureSource.freeTextureData();
|
|
113
|
+
console.error(err);
|
|
114
|
+
throw error; // Re-throw to propagate the error
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Called when the texture data needs to be loaded and uploaded to a texture
|
|
119
|
+
*/
|
|
120
|
+
async onLoadRequest() {
|
|
121
|
+
const { glw } = this;
|
|
122
|
+
const textureData = this.textureSource.textureData;
|
|
123
|
+
if (textureData === null || this._nativeCtxTexture === null) {
|
|
124
|
+
throw new Error('Texture data or native texture is null ' + this.textureSource.type);
|
|
125
|
+
}
|
|
126
|
+
// Set to a 1x1 transparent texture
|
|
127
|
+
glw.texImage2D(0, glw.RGBA, 1, 1, 0, glw.RGBA, glw.UNSIGNED_BYTE, null);
|
|
128
|
+
this.setTextureMemUse(TRANSPARENT_TEXTURE_DATA.byteLength);
|
|
129
|
+
let w = 0;
|
|
130
|
+
let h = 0;
|
|
131
|
+
glw.activeTexture(0);
|
|
132
|
+
const tdata = textureData.data;
|
|
133
|
+
const format = glw.RGBA;
|
|
134
|
+
const formatBytes = 4;
|
|
135
|
+
const memoryPadding = 1.1; // Add padding to account for GPU Padding
|
|
136
|
+
// If textureData is null, the texture is empty (0, 0) and we don't need to
|
|
137
|
+
// upload any data to the GPU.
|
|
138
|
+
if ((typeof ImageBitmap !== 'undefined' && tdata instanceof ImageBitmap) ||
|
|
139
|
+
tdata instanceof ImageData ||
|
|
140
|
+
// not using typeof HTMLI mageElement due to web worker
|
|
141
|
+
isHTMLImageElement(tdata) === true) {
|
|
142
|
+
w = tdata.width;
|
|
143
|
+
h = tdata.height;
|
|
144
|
+
glw.bindTexture(this._nativeCtxTexture);
|
|
145
|
+
glw.pixelStorei(glw.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !!textureData.premultiplyAlpha);
|
|
146
|
+
glw.texImage2D(0, format, format, glw.UNSIGNED_BYTE, tdata);
|
|
147
|
+
this.setTextureMemUse(h * w * formatBytes * memoryPadding);
|
|
148
|
+
}
|
|
149
|
+
else if (tdata === null) {
|
|
150
|
+
w = 0;
|
|
151
|
+
h = 0;
|
|
152
|
+
// Reset to a 1x1 transparent texture
|
|
153
|
+
glw.bindTexture(this._nativeCtxTexture);
|
|
154
|
+
glw.texImage2D(0, format, 1, 1, 0, format, glw.UNSIGNED_BYTE, TRANSPARENT_TEXTURE_DATA);
|
|
155
|
+
this.setTextureMemUse(TRANSPARENT_TEXTURE_DATA.byteLength);
|
|
156
|
+
}
|
|
157
|
+
else if ('mipmaps' in tdata && tdata.mipmaps) {
|
|
158
|
+
const { mipmaps, w = 0, h = 0, type, glInternalFormat } = tdata;
|
|
159
|
+
const view = type === 'ktx'
|
|
160
|
+
? new DataView(mipmaps[0] ?? new ArrayBuffer(0))
|
|
161
|
+
: mipmaps[0];
|
|
162
|
+
glw.bindTexture(this._nativeCtxTexture);
|
|
163
|
+
glw.compressedTexImage2D(0, glInternalFormat, w, h, 0, view);
|
|
164
|
+
glw.texParameteri(glw.TEXTURE_WRAP_S, glw.CLAMP_TO_EDGE);
|
|
165
|
+
glw.texParameteri(glw.TEXTURE_WRAP_T, glw.CLAMP_TO_EDGE);
|
|
166
|
+
glw.texParameteri(glw.TEXTURE_MAG_FILTER, glw.LINEAR);
|
|
167
|
+
glw.texParameteri(glw.TEXTURE_MIN_FILTER, glw.LINEAR);
|
|
168
|
+
this.setTextureMemUse(view.byteLength);
|
|
169
|
+
}
|
|
170
|
+
else if (tdata && tdata instanceof Uint8Array) {
|
|
171
|
+
// Color Texture
|
|
172
|
+
w = 1;
|
|
173
|
+
h = 1;
|
|
174
|
+
glw.bindTexture(this._nativeCtxTexture);
|
|
175
|
+
glw.pixelStorei(glw.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !!textureData.premultiplyAlpha);
|
|
176
|
+
glw.texImage2D(0, format, w, h, 0, format, glw.UNSIGNED_BYTE, tdata);
|
|
177
|
+
this.setTextureMemUse(w * h * formatBytes);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
console.error(`WebGlCoreCtxTexture.onLoadRequest: Unexpected textureData returned`, textureData);
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
w,
|
|
184
|
+
h,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Free the WebGLTexture from the GPU
|
|
189
|
+
*
|
|
190
|
+
* @returns
|
|
191
|
+
*/
|
|
192
|
+
free() {
|
|
193
|
+
if (this.state === 'freed') {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
this.state = 'freed';
|
|
197
|
+
this.textureSource.setState('freed');
|
|
198
|
+
this._w = 0;
|
|
199
|
+
this._h = 0;
|
|
200
|
+
if (this._nativeCtxTexture !== null) {
|
|
201
|
+
this.glw.deleteTexture(this._nativeCtxTexture);
|
|
202
|
+
this.setTextureMemUse(0);
|
|
203
|
+
this._nativeCtxTexture = null;
|
|
204
|
+
}
|
|
205
|
+
// if the texture still has source data, free it
|
|
206
|
+
this.textureSource.freeTextureData();
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Create native context texture asynchronously
|
|
210
|
+
*
|
|
211
|
+
* @remarks
|
|
212
|
+
* When this method resolves, the returned texture will be bound to the GL context state
|
|
213
|
+
* and fully ready for use. This ensures proper GPU resource allocation timing.
|
|
214
|
+
*
|
|
215
|
+
* @returns Promise that resolves to the native WebGL texture or null on failure
|
|
216
|
+
*/
|
|
217
|
+
createNativeCtxTexture() {
|
|
218
|
+
const { glw } = this;
|
|
219
|
+
const nativeTexture = glw.createTexture();
|
|
220
|
+
if (!nativeTexture) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
// On initial load request, create a 1x1 transparent texture to use until
|
|
224
|
+
// the texture data is finally loaded.
|
|
225
|
+
glw.activeTexture(0);
|
|
226
|
+
glw.bindTexture(nativeTexture);
|
|
227
|
+
// linear texture filtering
|
|
228
|
+
glw.texParameteri(glw.TEXTURE_MAG_FILTER, glw.LINEAR);
|
|
229
|
+
glw.texParameteri(glw.TEXTURE_MIN_FILTER, glw.LINEAR);
|
|
230
|
+
// texture wrapping method
|
|
231
|
+
glw.texParameteri(glw.TEXTURE_WRAP_S, glw.CLAMP_TO_EDGE);
|
|
232
|
+
glw.texParameteri(glw.TEXTURE_WRAP_T, glw.CLAMP_TO_EDGE);
|
|
233
|
+
return nativeTexture;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=WebGlCtxTexture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebGlCtxTexture.js","sourceRoot":"","sources":["../../../../../src/core/renderers/webgl/WebGlCtxTexture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0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E,GAAG,CAAC,MAAM,CAAC,CAAC;QAEtD,0BAA0B;QAC1B,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,cAAc,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;QACzD,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,cAAc,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;QAEzD,OAAO,aAAa,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { CoreRenderOp } from '../CoreRenderOp.js';
|
|
2
|
+
import type { WebGlCtxTexture } from './WebGlCtxTexture.js';
|
|
3
|
+
import type { WebGlRenderer } from './WebGlRenderer.js';
|
|
4
|
+
import type { BufferCollection } from './internal/BufferCollection.js';
|
|
5
|
+
import type { WebGlShaderNode } from './WebGlShaderNode.js';
|
|
6
|
+
import type { QuadOptions } from '../CoreRenderer.js';
|
|
7
|
+
import type { CoreTextNode } from '../../CoreTextNode.js';
|
|
8
|
+
import type { RectWithValid } from '../../lib/utils.js';
|
|
9
|
+
import type { Dimensions } from '../../../common/CommonTypes.js';
|
|
10
|
+
type ReqQuad = 'alpha' | 'shader' | 'parentHasRenderTexture' | 'rtt' | 'clippingRect' | 'height' | 'width';
|
|
11
|
+
type RenderOpQuadOptions = Pick<QuadOptions, ReqQuad> & Partial<Omit<QuadOptions, ReqQuad>> & {
|
|
12
|
+
sdfShaderProps?: Record<string, unknown>;
|
|
13
|
+
sdfBuffers?: BufferCollection;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Can render multiple quads with multiple textures (up to vertex shader texture limit)
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
export declare class WebGlRenderOp extends CoreRenderOp {
|
|
20
|
+
readonly renderer: WebGlRenderer;
|
|
21
|
+
readonly bufferIdx: number;
|
|
22
|
+
numQuads: number;
|
|
23
|
+
textures: WebGlCtxTexture[];
|
|
24
|
+
/**
|
|
25
|
+
* need to improve this when TextRenderers are refactored
|
|
26
|
+
*/
|
|
27
|
+
readonly sdfShaderProps: Record<string, unknown> | undefined;
|
|
28
|
+
readonly sdfNode: CoreTextNode | undefined;
|
|
29
|
+
readonly maxTextures: number;
|
|
30
|
+
readonly buffers: BufferCollection;
|
|
31
|
+
readonly shader: WebGlShaderNode;
|
|
32
|
+
readonly width: number;
|
|
33
|
+
readonly height: number;
|
|
34
|
+
readonly clippingRect: RectWithValid;
|
|
35
|
+
readonly rtt: boolean;
|
|
36
|
+
readonly parentHasRenderTexture: boolean;
|
|
37
|
+
readonly framebufferDimensions?: Dimensions | null;
|
|
38
|
+
readonly alpha: number;
|
|
39
|
+
readonly pixelRatio: number;
|
|
40
|
+
constructor(renderer: WebGlRenderer, quad: RenderOpQuadOptions, bufferIdx: number);
|
|
41
|
+
addTexture(texture: WebGlCtxTexture): number;
|
|
42
|
+
draw(): void;
|
|
43
|
+
}
|
|
44
|
+
export {};
|