@lightningjs/renderer 3.0.0-beta1 → 3.0.0-beta3
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/index.d.ts +1 -0
- package/dist/exports/index.js +1 -0
- package/dist/exports/index.js.map +1 -1
- package/dist/src/core/CoreNode.d.ts +1 -0
- package/dist/src/core/CoreNode.js +17 -13
- package/dist/src/core/CoreNode.js.map +1 -1
- package/dist/src/core/CoreShaderManager.d.ts +3 -5
- package/dist/src/core/CoreShaderManager.js.map +1 -1
- package/dist/src/core/CoreTextNode.js +0 -7
- package/dist/src/core/CoreTextNode.js.map +1 -1
- package/dist/src/core/Stage.js +2 -4
- package/dist/src/core/Stage.js.map +1 -1
- package/dist/src/core/lib/ImageWorker.js +2 -1
- package/dist/src/core/lib/ImageWorker.js.map +1 -1
- package/dist/src/core/lib/RenderCoords.d.ts +9 -10
- package/dist/src/core/lib/RenderCoords.js +43 -55
- package/dist/src/core/lib/RenderCoords.js.map +1 -1
- package/dist/src/core/lib/WebGlContextWrapper.d.ts +22 -0
- package/dist/src/core/lib/WebGlContextWrapper.js +27 -0
- package/dist/src/core/lib/WebGlContextWrapper.js.map +1 -1
- package/dist/src/core/lib/utils.d.ts +1 -0
- package/dist/src/core/lib/utils.js +20 -0
- package/dist/src/core/lib/utils.js.map +1 -1
- package/dist/src/core/renderers/CoreShaderNode.d.ts +2 -3
- package/dist/src/core/renderers/CoreShaderNode.js +0 -3
- package/dist/src/core/renderers/CoreShaderNode.js.map +1 -1
- package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +1 -1
- package/dist/src/core/renderers/canvas/CanvasTexture.js +3 -2
- package/dist/src/core/renderers/canvas/CanvasTexture.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlRenderOp.d.ts +10 -2
- package/dist/src/core/renderers/webgl/WebGlRenderOp.js +27 -16
- package/dist/src/core/renderers/webgl/WebGlRenderOp.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlRenderer.js +14 -13
- package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlShaderNode.d.ts +2 -1
- package/dist/src/core/renderers/webgl/WebGlShaderNode.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.d.ts +1 -1
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.js +32 -26
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +1 -1
- package/dist/src/core/shaders/webgl/SdfShader.js +1 -1
- package/dist/src/core/shaders/webgl/SdfShader.js.map +1 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js.map +1 -1
- package/dist/src/core/textures/ImageTexture.d.ts +2 -2
- package/dist/src/core/textures/ImageTexture.js +24 -4
- package/dist/src/core/textures/ImageTexture.js.map +1 -1
- package/dist/src/main-api/INode.d.ts +2 -2
- package/dist/src/main-api/Renderer.d.ts +1 -1
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/exports/index.ts +1 -0
- package/package.json +2 -2
- package/src/core/CoreNode.ts +24 -14
- package/src/core/CoreShaderManager.ts +5 -10
- package/src/core/CoreTextNode.ts +0 -9
- package/src/core/Stage.ts +2 -4
- package/src/core/lib/ImageWorker.ts +2 -1
- package/src/core/lib/RenderCoords.ts +52 -67
- package/src/core/lib/WebGlContextWrapper.ts +50 -0
- package/src/core/lib/utils.ts +25 -0
- package/src/core/renderers/CoreShaderNode.ts +2 -8
- package/src/core/renderers/canvas/CanvasRenderer.ts +0 -1
- package/src/core/renderers/canvas/CanvasTexture.ts +5 -2
- package/src/core/renderers/webgl/WebGlRenderOp.ts +32 -16
- package/src/core/renderers/webgl/WebGlRenderer.ts +22 -17
- package/src/core/renderers/webgl/WebGlShaderNode.ts +5 -1
- package/src/core/renderers/webgl/WebGlShaderProgram.ts +39 -31
- package/src/core/shaders/webgl/SdfShader.ts +1 -4
- package/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.ts +0 -1
- package/src/core/textures/ImageTexture.ts +31 -8
- package/src/main-api/INode.ts +4 -3
- package/src/main-api/Renderer.ts +1 -1
|
@@ -1,33 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Comcast Cable Communications Management, LLC
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*
|
|
15
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
*/
|
|
10
17
|
export class RenderCoords {
|
|
11
|
-
public
|
|
18
|
+
public x1: number;
|
|
19
|
+
public y1: number;
|
|
20
|
+
public x2: number;
|
|
21
|
+
public y2: number;
|
|
22
|
+
public x3: number;
|
|
23
|
+
public y3: number;
|
|
24
|
+
public x4: number;
|
|
25
|
+
public y4: number;
|
|
26
|
+
|
|
12
27
|
constructor(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
28
|
+
x1: number,
|
|
29
|
+
y1: number,
|
|
30
|
+
x2: number,
|
|
31
|
+
y2: number,
|
|
32
|
+
x3: number,
|
|
33
|
+
y3: number,
|
|
34
|
+
x4: number,
|
|
35
|
+
y4: number,
|
|
16
36
|
) {
|
|
17
|
-
this.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.data[ry3] = entries[ry3];
|
|
26
|
-
this.data[ry4] = entries[ry4];
|
|
27
|
-
}
|
|
37
|
+
this.x1 = x1;
|
|
38
|
+
this.y1 = y1;
|
|
39
|
+
this.x2 = x2;
|
|
40
|
+
this.y2 = y2;
|
|
41
|
+
this.x3 = x3;
|
|
42
|
+
this.y3 = y3;
|
|
43
|
+
this.x4 = x4;
|
|
44
|
+
this.y4 = y4;
|
|
28
45
|
}
|
|
29
46
|
|
|
30
|
-
|
|
47
|
+
static translate(
|
|
31
48
|
x1: number,
|
|
32
49
|
y1: number,
|
|
33
50
|
x2: number,
|
|
@@ -38,49 +55,17 @@ export class RenderCoords {
|
|
|
38
55
|
y4: number,
|
|
39
56
|
out?: RenderCoords,
|
|
40
57
|
): RenderCoords {
|
|
41
|
-
if (
|
|
42
|
-
|
|
58
|
+
if (out === undefined) {
|
|
59
|
+
return new RenderCoords(x1, y1, x2, y2, x3, y3, x4, y4);
|
|
43
60
|
}
|
|
44
|
-
out.
|
|
45
|
-
out.
|
|
46
|
-
out.
|
|
47
|
-
out.
|
|
48
|
-
out.
|
|
49
|
-
out.
|
|
50
|
-
out.
|
|
51
|
-
out.
|
|
61
|
+
out.x1 = x1;
|
|
62
|
+
out.y1 = y1;
|
|
63
|
+
out.x2 = x2;
|
|
64
|
+
out.y2 = y2;
|
|
65
|
+
out.x3 = x3;
|
|
66
|
+
out.y3 = y3;
|
|
67
|
+
out.x4 = x4;
|
|
68
|
+
out.y4 = y4;
|
|
52
69
|
return out;
|
|
53
70
|
}
|
|
54
|
-
|
|
55
|
-
get x1(): number {
|
|
56
|
-
return this.data[rx1]!;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
get x2(): number {
|
|
60
|
-
return this.data[rx2]!;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
get x3(): number {
|
|
64
|
-
return this.data[rx3]!;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
get x4(): number {
|
|
68
|
-
return this.data[rx4]!;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
get y1(): number {
|
|
72
|
-
return this.data[ry1]!;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
get y2(): number {
|
|
76
|
-
return this.data[ry2]!;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
get y3(): number {
|
|
80
|
-
return this.data[ry3]!;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
get y4(): number {
|
|
84
|
-
return this.data[ry4]!;
|
|
85
|
-
}
|
|
86
71
|
}
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
4
4
|
|
|
5
5
|
import { assertTruthy } from '../../utils.js';
|
|
6
|
+
import type {
|
|
7
|
+
Vec2,
|
|
8
|
+
Vec3,
|
|
9
|
+
Vec4,
|
|
10
|
+
} from '../renderers/webgl/internal/ShaderUtils.js';
|
|
6
11
|
import { isWebGl2 } from '../renderers/webgl/internal/WebGlUtils.js';
|
|
7
12
|
|
|
8
13
|
/**
|
|
@@ -800,6 +805,20 @@ export class WebGlContextWrapper {
|
|
|
800
805
|
);
|
|
801
806
|
}
|
|
802
807
|
|
|
808
|
+
/**
|
|
809
|
+
* Sets the value of a vec3 uniform variable.
|
|
810
|
+
*
|
|
811
|
+
* @param location - The location of the uniform variable.
|
|
812
|
+
* @param v - array of 4 numbers.
|
|
813
|
+
*/
|
|
814
|
+
uniform2fa(location: string, value: Vec2) {
|
|
815
|
+
this.gl.uniform2f(
|
|
816
|
+
this.gl.getUniformLocation(this.curProgram!, location),
|
|
817
|
+
value[0],
|
|
818
|
+
value[1],
|
|
819
|
+
);
|
|
820
|
+
}
|
|
821
|
+
|
|
803
822
|
/**
|
|
804
823
|
* Sets the value of a vec2 array uniform variable.
|
|
805
824
|
*
|
|
@@ -858,6 +877,21 @@ export class WebGlContextWrapper {
|
|
|
858
877
|
);
|
|
859
878
|
}
|
|
860
879
|
|
|
880
|
+
/**
|
|
881
|
+
* Sets the value of a vec3 uniform variable.
|
|
882
|
+
*
|
|
883
|
+
* @param location - The location of the uniform variable.
|
|
884
|
+
* @param v - array of 4 numbers.
|
|
885
|
+
*/
|
|
886
|
+
uniform3fa(location: string, value: Vec3) {
|
|
887
|
+
this.gl.uniform3f(
|
|
888
|
+
this.gl.getUniformLocation(this.curProgram!, location),
|
|
889
|
+
value[0],
|
|
890
|
+
value[1],
|
|
891
|
+
value[2],
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
|
|
861
895
|
/**
|
|
862
896
|
* Sets the value of a vec3 array uniform variable.
|
|
863
897
|
*
|
|
@@ -920,6 +954,22 @@ export class WebGlContextWrapper {
|
|
|
920
954
|
);
|
|
921
955
|
}
|
|
922
956
|
|
|
957
|
+
/**
|
|
958
|
+
* Sets the value of a vec4 uniform variable.
|
|
959
|
+
*
|
|
960
|
+
* @param location - The location of the uniform variable.
|
|
961
|
+
* @param v - array of 4 numbers.
|
|
962
|
+
*/
|
|
963
|
+
uniform4fa(location: string, value: Vec4) {
|
|
964
|
+
this.gl.uniform4f(
|
|
965
|
+
this.gl.getUniformLocation(this.curProgram!, location),
|
|
966
|
+
value[0],
|
|
967
|
+
value[1],
|
|
968
|
+
value[2],
|
|
969
|
+
value[3],
|
|
970
|
+
);
|
|
971
|
+
}
|
|
972
|
+
|
|
923
973
|
/**
|
|
924
974
|
* Sets the value of a vec4 array uniform variable.
|
|
925
975
|
*
|
package/src/core/lib/utils.ts
CHANGED
|
@@ -359,3 +359,28 @@ export function calcFactoredRadiusArray(
|
|
|
359
359
|
result[3] *= factor;
|
|
360
360
|
return result;
|
|
361
361
|
}
|
|
362
|
+
|
|
363
|
+
export function dataURIToBlob(dataURI: string): Blob {
|
|
364
|
+
dataURI = dataURI.replace(/^data:/, '');
|
|
365
|
+
|
|
366
|
+
const type = dataURI.match(/image\/[^;]+/)?.[0] || '';
|
|
367
|
+
const base64 = dataURI.replace(/^[^,]+,/, '');
|
|
368
|
+
|
|
369
|
+
const sliceSize = 1024;
|
|
370
|
+
const byteCharacters = atob(base64);
|
|
371
|
+
const bytesLength = byteCharacters.length;
|
|
372
|
+
const slicesCount = Math.ceil(bytesLength / sliceSize);
|
|
373
|
+
const byteArrays = new Array(slicesCount);
|
|
374
|
+
|
|
375
|
+
for (let sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
|
|
376
|
+
const begin = sliceIndex * sliceSize;
|
|
377
|
+
const end = Math.min(begin + sliceSize, bytesLength);
|
|
378
|
+
|
|
379
|
+
const bytes = new Array(end - begin);
|
|
380
|
+
for (let offset = begin, i = 0; offset < end; ++i, ++offset) {
|
|
381
|
+
bytes[i] = byteCharacters[offset]?.charCodeAt(0);
|
|
382
|
+
}
|
|
383
|
+
byteArrays[sliceIndex] = new Uint8Array(bytes);
|
|
384
|
+
}
|
|
385
|
+
return new Blob(byteArrays, { type });
|
|
386
|
+
}
|
|
@@ -66,9 +66,7 @@ export function resolveShaderProps(
|
|
|
66
66
|
* You could view a ShaderType as a configuration object that contains methods,
|
|
67
67
|
* and values that you can use to alter the way a node is drawn by the Renderer.
|
|
68
68
|
*/
|
|
69
|
-
export interface CoreShaderType<
|
|
70
|
-
Props extends object = Record<string, unknown>,
|
|
71
|
-
> {
|
|
69
|
+
export interface CoreShaderType<Props extends object = any> {
|
|
72
70
|
/**
|
|
73
71
|
* Values you use to draw the Shader
|
|
74
72
|
*/
|
|
@@ -88,7 +86,7 @@ export class CoreShaderNode<Props extends object = Record<string, unknown>> {
|
|
|
88
86
|
readonly stage: Stage;
|
|
89
87
|
readonly shaderType: CoreShaderType<Props>;
|
|
90
88
|
protected propsConfig: ShaderProps<Props> | undefined;
|
|
91
|
-
|
|
89
|
+
readonly resolvedProps: Props | undefined = undefined;
|
|
92
90
|
protected definedProps: Props | undefined = undefined;
|
|
93
91
|
protected node: CoreNode | null = null;
|
|
94
92
|
update: (() => void) | undefined = undefined;
|
|
@@ -152,10 +150,6 @@ export class CoreShaderNode<Props extends object = Record<string, unknown>> {
|
|
|
152
150
|
this.node = node;
|
|
153
151
|
}
|
|
154
152
|
|
|
155
|
-
getResolvedProps() {
|
|
156
|
-
return this.resolvedProps;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
153
|
get props(): Props | undefined {
|
|
160
154
|
return this.definedProps;
|
|
161
155
|
}
|
|
@@ -33,7 +33,6 @@ import {
|
|
|
33
33
|
} from './internal/ColorUtils.js';
|
|
34
34
|
import { assertTruthy } from '../../../utils.js';
|
|
35
35
|
import { CanvasShaderNode, type CanvasShaderType } from './CanvasShaderNode.js';
|
|
36
|
-
import type { CoreShaderType } from '../CoreShaderNode.js';
|
|
37
36
|
|
|
38
37
|
export class CanvasRenderer extends CoreRenderer {
|
|
39
38
|
private context: CanvasRenderingContext2D;
|
|
@@ -64,8 +64,11 @@ export class CanvasTexture extends CoreContextTexture {
|
|
|
64
64
|
// - tinted image
|
|
65
65
|
const mult = this.tintCache ? 8 : 4;
|
|
66
66
|
if (this.textureSource.dimensions) {
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
this.setTextureMemUse(
|
|
68
|
+
this.textureSource.dimensions.width *
|
|
69
|
+
this.textureSource.dimensions.height *
|
|
70
|
+
mult,
|
|
71
|
+
);
|
|
69
72
|
}
|
|
70
73
|
}
|
|
71
74
|
|
|
@@ -24,6 +24,8 @@ import type { BufferCollection } from './internal/BufferCollection.js';
|
|
|
24
24
|
import type { WebGlShaderNode } from './WebGlShaderNode.js';
|
|
25
25
|
import type { QuadOptions } from '../CoreRenderer.js';
|
|
26
26
|
import type { CoreTextNode } from '../../CoreTextNode.js';
|
|
27
|
+
import type { RectWithValid } from '../../lib/utils.js';
|
|
28
|
+
import type { Dimensions } from '../../../common/CommonTypes.js';
|
|
27
29
|
|
|
28
30
|
type ReqQuad =
|
|
29
31
|
| 'alpha'
|
|
@@ -44,7 +46,6 @@ type RenderOpQuadOptions = Pick<QuadOptions, ReqQuad> &
|
|
|
44
46
|
*
|
|
45
47
|
*/
|
|
46
48
|
export class WebGlRenderOp extends CoreRenderOp {
|
|
47
|
-
length = 0;
|
|
48
49
|
numQuads = 0;
|
|
49
50
|
textures: WebGlCtxTexture[] = [];
|
|
50
51
|
|
|
@@ -56,15 +57,32 @@ export class WebGlRenderOp extends CoreRenderOp {
|
|
|
56
57
|
readonly maxTextures: number;
|
|
57
58
|
readonly buffers: BufferCollection;
|
|
58
59
|
readonly shader: WebGlShaderNode;
|
|
60
|
+
readonly width: number;
|
|
61
|
+
readonly height: number;
|
|
62
|
+
readonly clippingRect: RectWithValid;
|
|
63
|
+
readonly rtt: boolean;
|
|
64
|
+
readonly parentHasRenderTexture: boolean;
|
|
65
|
+
readonly framebufferDimensions?: Dimensions;
|
|
66
|
+
readonly alpha: number;
|
|
67
|
+
readonly pixelRatio: number;
|
|
59
68
|
|
|
60
69
|
constructor(
|
|
61
70
|
readonly renderer: WebGlRenderer,
|
|
62
|
-
|
|
71
|
+
quad: RenderOpQuadOptions,
|
|
63
72
|
readonly bufferIdx: number,
|
|
64
73
|
) {
|
|
65
74
|
super();
|
|
66
75
|
this.buffers = quad.sdfBuffers || renderer.quadBufferCollection;
|
|
67
76
|
this.shader = quad.shader as WebGlShaderNode;
|
|
77
|
+
this.width = quad.width;
|
|
78
|
+
this.height = quad.height;
|
|
79
|
+
this.clippingRect = quad.clippingRect;
|
|
80
|
+
this.parentHasRenderTexture = quad.parentHasRenderTexture;
|
|
81
|
+
this.framebufferDimensions = quad.framebufferDimensions;
|
|
82
|
+
this.rtt = quad.rtt;
|
|
83
|
+
this.alpha = quad.alpha;
|
|
84
|
+
this.pixelRatio =
|
|
85
|
+
this.parentHasRenderTexture === true ? 1 : renderer.stage.pixelRatio;
|
|
68
86
|
|
|
69
87
|
/**
|
|
70
88
|
* related to line 51
|
|
@@ -110,22 +128,20 @@ export class WebGlRenderOp extends CoreRenderOp {
|
|
|
110
128
|
// TODO: Reduce calculations required
|
|
111
129
|
const quadIdx = (this.bufferIdx / 32) * 6 * 2;
|
|
112
130
|
// Clipping
|
|
113
|
-
if (this.
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const clipHeight = Math.round(height * pixelRatio);
|
|
123
|
-
let clipY = Math.round(canvasHeight - clipHeight - y * pixelRatio);
|
|
131
|
+
if (this.clippingRect.valid === true) {
|
|
132
|
+
const clipX = Math.round(this.clippingRect.x * this.pixelRatio);
|
|
133
|
+
const clipWidth = Math.round(this.clippingRect.width * this.pixelRatio);
|
|
134
|
+
const clipHeight = Math.round(this.clippingRect.height * this.pixelRatio);
|
|
135
|
+
let clipY = Math.round(
|
|
136
|
+
options.canvas.height -
|
|
137
|
+
clipHeight -
|
|
138
|
+
this.clippingRect.y * this.pixelRatio,
|
|
139
|
+
);
|
|
124
140
|
// if parent has render texture, we need to adjust the scissor rect
|
|
125
141
|
// to be relative to the parent's framebuffer
|
|
126
|
-
if (this.
|
|
127
|
-
clipY = this.
|
|
128
|
-
? this.
|
|
142
|
+
if (this.parentHasRenderTexture) {
|
|
143
|
+
clipY = this.framebufferDimensions
|
|
144
|
+
? this.framebufferDimensions.height - this.height
|
|
129
145
|
: 0;
|
|
130
146
|
}
|
|
131
147
|
|
|
@@ -50,7 +50,7 @@ import type { WebGlShaderType } from './WebGlShaderNode.js';
|
|
|
50
50
|
import { WebGlShaderNode } from './WebGlShaderNode.js';
|
|
51
51
|
import type { CoreShaderType } from '../CoreShaderNode.js';
|
|
52
52
|
|
|
53
|
-
const WORDS_PER_QUAD =
|
|
53
|
+
const WORDS_PER_QUAD = 32;
|
|
54
54
|
// const BYTES_PER_QUAD = WORDS_PER_QUAD * 4;
|
|
55
55
|
|
|
56
56
|
export type WebGlRendererOptions = CoreRendererOptions;
|
|
@@ -252,12 +252,10 @@ export class WebGlRenderer extends CoreRenderer {
|
|
|
252
252
|
|
|
253
253
|
assertTruthy(texture !== null, 'Texture is required');
|
|
254
254
|
|
|
255
|
-
let { curBufferIdx: bufferIdx
|
|
255
|
+
let { curBufferIdx: bufferIdx } = this;
|
|
256
256
|
|
|
257
257
|
if (this.reuseRenderOp(params) === false) {
|
|
258
258
|
this.newRenderOp(params, bufferIdx);
|
|
259
|
-
curRenderOp = this.curRenderOp;
|
|
260
|
-
assertTruthy(curRenderOp);
|
|
261
259
|
}
|
|
262
260
|
|
|
263
261
|
let texCoordX1 = 0;
|
|
@@ -374,7 +372,6 @@ export class WebGlRenderer extends CoreRenderer {
|
|
|
374
372
|
fQuadBuffer[bufferIdx++] = 1; //node y coord
|
|
375
373
|
|
|
376
374
|
// Update the length of the current render op
|
|
377
|
-
this.curRenderOp.length += WORDS_PER_QUAD;
|
|
378
375
|
this.curRenderOp.numQuads++;
|
|
379
376
|
this.curBufferIdx = bufferIdx;
|
|
380
377
|
}
|
|
@@ -386,7 +383,7 @@ export class WebGlRenderer extends CoreRenderer {
|
|
|
386
383
|
* @param shader
|
|
387
384
|
* @param bufferIdx
|
|
388
385
|
*/
|
|
389
|
-
private newRenderOp(quad: QuadOptions, bufferIdx: number) {
|
|
386
|
+
private newRenderOp(quad: QuadOptions | WebGlRenderOp, bufferIdx: number) {
|
|
390
387
|
const curRenderOp = new WebGlRenderOp(this, quad, bufferIdx);
|
|
391
388
|
this.curRenderOp = curRenderOp;
|
|
392
389
|
this.renderOps.push(curRenderOp);
|
|
@@ -416,7 +413,7 @@ export class WebGlRenderer extends CoreRenderer {
|
|
|
416
413
|
if (recursive) {
|
|
417
414
|
throw new Error('Unable to add texture to render op');
|
|
418
415
|
}
|
|
419
|
-
this.newRenderOp(this.curRenderOp
|
|
416
|
+
this.newRenderOp(this.curRenderOp, bufferIdx);
|
|
420
417
|
return this.addTexture(texture, bufferIdx, true);
|
|
421
418
|
}
|
|
422
419
|
return textureIdx;
|
|
@@ -428,19 +425,17 @@ export class WebGlRenderer extends CoreRenderer {
|
|
|
428
425
|
* @returns
|
|
429
426
|
*/
|
|
430
427
|
reuseRenderOp(params: QuadOptions): boolean {
|
|
431
|
-
const { shader, parentHasRenderTexture, rtt, clippingRect } = params;
|
|
432
|
-
|
|
433
428
|
// Switching shader program will require a new render operation
|
|
434
429
|
if (
|
|
435
430
|
this.curRenderOp?.shader.shaderKey !==
|
|
436
|
-
(shader as WebGlShaderNode).shaderKey
|
|
431
|
+
(params.shader as WebGlShaderNode).shaderKey
|
|
437
432
|
) {
|
|
438
433
|
return false;
|
|
439
434
|
}
|
|
440
435
|
|
|
441
436
|
// Switching clipping rect will require a new render operation
|
|
442
437
|
if (
|
|
443
|
-
compareRect(this.curRenderOp.
|
|
438
|
+
compareRect(this.curRenderOp.clippingRect, params.clippingRect) === false
|
|
444
439
|
) {
|
|
445
440
|
return false;
|
|
446
441
|
}
|
|
@@ -448,16 +443,26 @@ export class WebGlRenderer extends CoreRenderer {
|
|
|
448
443
|
// Force new render operation if rendering to texture
|
|
449
444
|
// @todo: This needs to be improved, render operations could also be reused
|
|
450
445
|
// for rendering to texture
|
|
451
|
-
if (
|
|
446
|
+
if (
|
|
447
|
+
params.parentHasRenderTexture !== undefined ||
|
|
448
|
+
params.rtt !== undefined
|
|
449
|
+
) {
|
|
452
450
|
return false;
|
|
453
451
|
}
|
|
454
452
|
|
|
453
|
+
if (
|
|
454
|
+
this.curRenderOp.shader.shaderKey === 'default' &&
|
|
455
|
+
params.shader?.shaderKey === 'default'
|
|
456
|
+
) {
|
|
457
|
+
return true;
|
|
458
|
+
}
|
|
459
|
+
|
|
455
460
|
// Check if the shader can batch the shader properties
|
|
456
461
|
if (
|
|
457
|
-
|
|
462
|
+
this.curRenderOp.shader.program.reuseRenderOp(
|
|
458
463
|
params,
|
|
459
|
-
this.curRenderOp
|
|
460
|
-
)
|
|
464
|
+
this.curRenderOp,
|
|
465
|
+
) === false
|
|
461
466
|
) {
|
|
462
467
|
return false;
|
|
463
468
|
}
|
|
@@ -682,9 +687,9 @@ export class WebGlRenderer extends CoreRenderer {
|
|
|
682
687
|
if (this.defaultShaderNode !== null) {
|
|
683
688
|
return this.defaultShaderNode as WebGlShaderNode;
|
|
684
689
|
}
|
|
685
|
-
this.stage.shManager.registerShaderType('
|
|
690
|
+
this.stage.shManager.registerShaderType('default', Default);
|
|
686
691
|
this.defaultShaderNode = this.stage.shManager.createShader(
|
|
687
|
-
'
|
|
692
|
+
'default',
|
|
688
693
|
) as WebGlShaderNode;
|
|
689
694
|
return this.defaultShaderNode;
|
|
690
695
|
}
|
|
@@ -11,6 +11,7 @@ import type {
|
|
|
11
11
|
Vec4,
|
|
12
12
|
} from './internal/ShaderUtils.js';
|
|
13
13
|
import type { WebGlRenderer } from './WebGlRenderer.js';
|
|
14
|
+
import type { WebGlRenderOp } from './WebGlRenderOp.js';
|
|
14
15
|
import type { WebGlShaderProgram } from './WebGlShaderProgram.js';
|
|
15
16
|
|
|
16
17
|
export type ShaderSource<T> =
|
|
@@ -46,7 +47,10 @@ export type WebGlShaderType<T extends object = Record<string, unknown>> =
|
|
|
46
47
|
* This function is used to check if the shader can be reused based on quad info
|
|
47
48
|
* @param props
|
|
48
49
|
*/
|
|
49
|
-
canBatch?: (
|
|
50
|
+
canBatch?: (
|
|
51
|
+
incomingQuad: QuadOptions,
|
|
52
|
+
currentRenderOp: WebGlRenderOp,
|
|
53
|
+
) => boolean;
|
|
50
54
|
/**
|
|
51
55
|
* extensions required for specific shader?
|
|
52
56
|
*/
|
|
@@ -141,31 +141,45 @@ export class WebGlShaderProgram implements CoreShaderProgram {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
reuseRenderOp(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (
|
|
149
|
-
return
|
|
144
|
+
reuseRenderOp(
|
|
145
|
+
incomingQuad: QuadOptions,
|
|
146
|
+
currentRenderOp: WebGlRenderOp,
|
|
147
|
+
): boolean {
|
|
148
|
+
if (this.lifecycle.canBatch !== undefined) {
|
|
149
|
+
return this.lifecycle.canBatch(incomingQuad, currentRenderOp);
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
if (this.useSystemAlpha) {
|
|
153
|
-
if (
|
|
152
|
+
if (this.useSystemAlpha === true) {
|
|
153
|
+
if (incomingQuad.alpha !== currentRenderOp.alpha) {
|
|
154
154
|
return false;
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
if (this.useSystemDimensions) {
|
|
158
|
+
if (this.useSystemDimensions === true) {
|
|
159
159
|
if (
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
incomingQuad.width !== currentRenderOp.width ||
|
|
161
|
+
incomingQuad.height !== currentRenderOp.height
|
|
162
162
|
) {
|
|
163
163
|
return false;
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
+
let shaderPropsA: Record<string, unknown> | undefined = undefined;
|
|
167
|
+
let shaderPropsB: Record<string, unknown> | undefined = undefined;
|
|
168
|
+
|
|
169
|
+
if (incomingQuad.shader !== null) {
|
|
170
|
+
shaderPropsA = incomingQuad.shader.resolvedProps;
|
|
171
|
+
}
|
|
172
|
+
if (currentRenderOp.shader !== null) {
|
|
173
|
+
shaderPropsB = currentRenderOp.shader.resolvedProps;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (
|
|
177
|
+
(shaderPropsA === undefined && shaderPropsB !== undefined) ||
|
|
178
|
+
(shaderPropsA !== undefined && shaderPropsB === undefined)
|
|
179
|
+
) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
166
182
|
|
|
167
|
-
const shaderPropsA = renderOpA.shader?.getResolvedProps();
|
|
168
|
-
const shaderPropsB = renderOpB.shader?.getResolvedProps();
|
|
169
183
|
if (shaderPropsA !== undefined && shaderPropsB !== undefined) {
|
|
170
184
|
for (const key in shaderPropsA) {
|
|
171
185
|
if (shaderPropsA[key] !== shaderPropsB[key]) {
|
|
@@ -181,17 +195,17 @@ export class WebGlShaderProgram implements CoreShaderProgram {
|
|
|
181
195
|
this.bindBufferCollection(renderOp.buffers);
|
|
182
196
|
this.bindTextures(renderOp.textures);
|
|
183
197
|
|
|
184
|
-
const { parentHasRenderTexture } = renderOp
|
|
198
|
+
const { parentHasRenderTexture } = renderOp;
|
|
185
199
|
|
|
186
200
|
// Skip if the parent and current operation both have render textures
|
|
187
|
-
if (renderOp.
|
|
201
|
+
if (renderOp.rtt === true && parentHasRenderTexture === true) {
|
|
188
202
|
return;
|
|
189
203
|
}
|
|
190
204
|
|
|
191
205
|
// Bind render texture framebuffer dimensions as resolution
|
|
192
206
|
// if the parent has a render texture
|
|
193
|
-
if (parentHasRenderTexture) {
|
|
194
|
-
const { width, height } = renderOp.
|
|
207
|
+
if (parentHasRenderTexture === true) {
|
|
208
|
+
const { width, height } = renderOp.framebufferDimensions!;
|
|
195
209
|
// Force pixel ratio to 1.0 for render textures since they are always 1:1
|
|
196
210
|
// the final render texture will be rendered to the screen with the correct pixel ratio
|
|
197
211
|
this.glw.uniform1f('u_pixelRatio', 1.0);
|
|
@@ -207,19 +221,13 @@ export class WebGlShaderProgram implements CoreShaderProgram {
|
|
|
207
221
|
);
|
|
208
222
|
}
|
|
209
223
|
|
|
210
|
-
this.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
this.glw.uniform1f('u_alpha', renderOp.quad.alpha);
|
|
214
|
-
}
|
|
224
|
+
// if (this.useSystemAlpha) {
|
|
225
|
+
this.glw.uniform1f('u_alpha', renderOp.alpha);
|
|
226
|
+
// }
|
|
215
227
|
|
|
216
|
-
if (this.useSystemDimensions) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
renderOp.quad.width,
|
|
220
|
-
renderOp.quad.height,
|
|
221
|
-
);
|
|
222
|
-
}
|
|
228
|
+
// if (this.useSystemDimensions) {
|
|
229
|
+
this.glw.uniform2f('u_dimensions', renderOp.width, renderOp.height);
|
|
230
|
+
// }
|
|
223
231
|
|
|
224
232
|
/**temporary fix to make sdf texts work */
|
|
225
233
|
if (renderOp.sdfShaderProps !== undefined) {
|
|
@@ -230,7 +238,7 @@ export class WebGlShaderProgram implements CoreShaderProgram {
|
|
|
230
238
|
return;
|
|
231
239
|
}
|
|
232
240
|
|
|
233
|
-
if (renderOp.shader.props) {
|
|
241
|
+
if (renderOp.shader.props !== undefined) {
|
|
234
242
|
/**
|
|
235
243
|
* loop over all precalculated uniform types
|
|
236
244
|
*/
|
|
@@ -276,7 +284,7 @@ export class WebGlShaderProgram implements CoreShaderProgram {
|
|
|
276
284
|
const name = attribs[i]!;
|
|
277
285
|
const resolvedBuffer = buffer.getBuffer(name);
|
|
278
286
|
const resolvedInfo = buffer.getAttributeInfo(name);
|
|
279
|
-
if (
|
|
287
|
+
if (resolvedBuffer === undefined || resolvedInfo === undefined) {
|
|
280
288
|
continue;
|
|
281
289
|
}
|
|
282
290
|
glw.enableVertexAttribArray(i);
|
|
@@ -62,10 +62,7 @@ export const Sdf: WebGlShaderType<SdfShaderProps> = {
|
|
|
62
62
|
onSdfBind(props) {
|
|
63
63
|
this.uniformMatrix3fv('u_transform', props.transform);
|
|
64
64
|
this.uniform1f('u_scrollY', props.scrollY);
|
|
65
|
-
this.
|
|
66
|
-
'u_color',
|
|
67
|
-
new Float32Array(getNormalizedRgbaComponents(props.color)),
|
|
68
|
-
);
|
|
65
|
+
this.uniform4fa('u_color', getNormalizedRgbaComponents(props.color));
|
|
69
66
|
this.uniform1f('u_size', props.size);
|
|
70
67
|
this.uniform1f('u_distanceRange', props.distanceRange);
|
|
71
68
|
this.uniform1i('u_debug', props.debug ? 1 : 0);
|
|
@@ -712,7 +712,6 @@ export class SdfTextRenderer extends TextRenderer<SdfTextRendererState> {
|
|
|
712
712
|
const ctxTexture = texture.ctxTexture;
|
|
713
713
|
|
|
714
714
|
renderOp.addTexture(ctxTexture as WebGlCtxTexture);
|
|
715
|
-
renderOp.length = state.bufferNumFloats;
|
|
716
715
|
renderOp.numQuads = state.bufferNumQuads;
|
|
717
716
|
|
|
718
717
|
renderer.addRenderOp(renderOp);
|