@swf2es/render 0.1.41 → 0.1.43
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/commands.d.ts +27 -5
- package/dist/commands.d.ts.map +1 -1
- package/dist/commands.js +43 -5
- package/dist/commands.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/measure.d.ts +7 -2
- package/dist/measure.d.ts.map +1 -1
- package/dist/measure.js +189 -5
- package/dist/measure.js.map +1 -1
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +8 -4
- package/dist/plan.js.map +1 -1
- package/dist/scene.d.ts +45 -7
- package/dist/scene.d.ts.map +1 -1
- package/dist/scene.js +54 -7
- package/dist/scene.js.map +1 -1
- package/dist/webgl/backdrops.d.ts +60 -0
- package/dist/webgl/backdrops.d.ts.map +1 -0
- package/dist/webgl/backdrops.js +130 -0
- package/dist/webgl/backdrops.js.map +1 -0
- package/dist/webgl/backend.d.ts +19 -1
- package/dist/webgl/backend.d.ts.map +1 -1
- package/dist/webgl/backend.js +88 -28
- package/dist/webgl/backend.js.map +1 -1
- package/dist/webgl/composite.d.ts +29 -2
- package/dist/webgl/composite.d.ts.map +1 -1
- package/dist/webgl/composite.js +96 -27
- package/dist/webgl/composite.js.map +1 -1
- package/dist/webgl/draws.d.ts +6 -3
- package/dist/webgl/draws.d.ts.map +1 -1
- package/dist/webgl/draws.js +8 -5
- package/dist/webgl/draws.js.map +1 -1
- package/dist/webgl/holds.d.ts +5 -2
- package/dist/webgl/holds.d.ts.map +1 -1
- package/dist/webgl/holds.js +9 -4
- package/dist/webgl/holds.js.map +1 -1
- package/dist/webgl/programs.d.ts +16 -0
- package/dist/webgl/programs.d.ts.map +1 -1
- package/dist/webgl/programs.js +82 -9
- package/dist/webgl/programs.js.map +1 -1
- package/dist/webgl/targets.d.ts +6 -0
- package/dist/webgl/targets.d.ts.map +1 -1
- package/dist/webgl/targets.js.map +1 -1
- package/package.json +2 -2
- package/src/commands.ts +48 -5
- package/src/index.ts +9 -0
- package/src/measure.ts +247 -2
- package/src/plan.ts +24 -3
- package/src/scene.ts +55 -6
- package/src/webgl/backdrops.ts +150 -0
- package/src/webgl/backend.ts +115 -31
- package/src/webgl/composite.ts +121 -48
- package/src/webgl/draws.ts +13 -3
- package/src/webgl/holds.ts +11 -3
- package/src/webgl/programs.ts +87 -8
- package/src/webgl/targets.ts +6 -0
package/src/webgl/backend.ts
CHANGED
|
@@ -7,8 +7,13 @@ import {
|
|
|
7
7
|
HELD,
|
|
8
8
|
HOLD_POP,
|
|
9
9
|
HOLD_PUSH,
|
|
10
|
+
LAYER_FILTERED,
|
|
10
11
|
LAYER_POP,
|
|
11
12
|
LAYER_PUSH,
|
|
13
|
+
LAYER_SOLID,
|
|
14
|
+
operandBelow,
|
|
15
|
+
operandMode,
|
|
16
|
+
operandSolid,
|
|
12
17
|
RUN,
|
|
13
18
|
STENCIL_POP,
|
|
14
19
|
STENCIL_PUSH,
|
|
@@ -20,6 +25,7 @@ import type { Rows } from "../rows.js";
|
|
|
20
25
|
import { blendsDirect, NORMAL, type SceneList } from "../scene.js";
|
|
21
26
|
import type { Textures } from "../textures.js";
|
|
22
27
|
import { GeometryAtlas } from "./atlas.js";
|
|
28
|
+
import { Backdrops } from "./backdrops.js";
|
|
23
29
|
import { Compositor, readsBelow } from "./composite.js";
|
|
24
30
|
import { Draws, type Masks } from "./draws.js";
|
|
25
31
|
import { FilterRunner } from "./filters.js";
|
|
@@ -113,6 +119,8 @@ export class WebGLBackend {
|
|
|
113
119
|
private readonly masks: Masks = { depth: 0, past: 0 };
|
|
114
120
|
/** A layer's rectangle, as blendDirect reads it. */
|
|
115
121
|
private readonly rect = { x: 0, y: 0, width: 0, height: 0 };
|
|
122
|
+
/** The blends drawn direct that share the copy of what is below made last (shareCopy). */
|
|
123
|
+
private readonly backdrops = new Backdrops();
|
|
116
124
|
/** The mask counts of the targets below the layers drawn into now, two numbers each. */
|
|
117
125
|
private readonly below: number[] = [];
|
|
118
126
|
/** The program `compositeOver` draws with, linked ahead (programs); null till then and after a lost context. */
|
|
@@ -411,6 +419,7 @@ export class WebGLBackend {
|
|
|
411
419
|
opaque: commands.opaqueStage,
|
|
412
420
|
};
|
|
413
421
|
this.layers.length = 0;
|
|
422
|
+
this.backdrops.begin(false);
|
|
414
423
|
this.draws.drawInto(canvas, target);
|
|
415
424
|
|
|
416
425
|
this.draws.forgetRow();
|
|
@@ -482,7 +491,7 @@ export class WebGLBackend {
|
|
|
482
491
|
const from = ops[at + 1];
|
|
483
492
|
const width = p[from + 2];
|
|
484
493
|
const height = p[from + 3];
|
|
485
|
-
const filtered = ops[at + 2]
|
|
494
|
+
const filtered = (ops[at + 2] & LAYER_FILTERED) !== 0;
|
|
486
495
|
// A filtered one of the size its filters' targets take for it, which they read alike.
|
|
487
496
|
const layer = this.pool.takeLayer(width, height, filtered);
|
|
488
497
|
const open: Open = {
|
|
@@ -493,6 +502,9 @@ export class WebGLBackend {
|
|
|
493
502
|
width,
|
|
494
503
|
height,
|
|
495
504
|
object: objectOf(p, from + 4),
|
|
505
|
+
fresh: (ops[at + 3] & 1) === 1,
|
|
506
|
+
below: ops[at + 3] >> 1,
|
|
507
|
+
solid: (ops[at + 2] & LAYER_SOLID) !== 0,
|
|
496
508
|
};
|
|
497
509
|
this.layers.push(open);
|
|
498
510
|
this.draws.drawInto(open, target);
|
|
@@ -562,12 +574,14 @@ export class WebGLBackend {
|
|
|
562
574
|
y: p[from + 1],
|
|
563
575
|
width: p[from + 2],
|
|
564
576
|
height: p[from + 3],
|
|
577
|
+
below: operandBelow(ops[at + 2]),
|
|
578
|
+
solid: operandSolid(ops[at + 2]),
|
|
565
579
|
};
|
|
566
580
|
this.draws.maskBy(masks);
|
|
567
581
|
this.compositor.compositeLayer(
|
|
568
582
|
kept,
|
|
569
583
|
this.layers.at(-1) ?? canvas,
|
|
570
|
-
ops[at + 2],
|
|
584
|
+
operandMode(ops[at + 2]),
|
|
571
585
|
ops[at + 3],
|
|
572
586
|
);
|
|
573
587
|
}
|
|
@@ -1129,59 +1143,129 @@ export class WebGLBackend {
|
|
|
1129
1143
|
* inside a pixel, each blended by what it covers there is as adl blends
|
|
1130
1144
|
* them, not the pixel they make together, which a layer would blend. A
|
|
1131
1145
|
* layer and its resolve and composite left out, what reads what is below
|
|
1132
|
-
* copies it as the composite would
|
|
1146
|
+
* copies it as the composite would, or shares the copy made for one
|
|
1147
|
+
* drawn direct before it (shareCopy). Whether it was.
|
|
1133
1148
|
*/
|
|
1134
1149
|
private blendDirect(commands: Commands, k: number, scene: SceneList, canvas: Open): boolean {
|
|
1135
|
-
|
|
1136
|
-
const at = k * 4;
|
|
1137
|
-
const run = at + 4;
|
|
1138
|
-
const pop = at + 8;
|
|
1139
|
-
if (
|
|
1140
|
-
k + 2 >= commands.length ||
|
|
1141
|
-
ops[at + 2] !== 0 ||
|
|
1142
|
-
ops[run] !== RUN ||
|
|
1143
|
-
ops[run + 2] !== 1 ||
|
|
1144
|
-
ops[run + 3] !== NORMAL ||
|
|
1145
|
-
ops[pop] !== LAYER_POP ||
|
|
1146
|
-
ops[pop + 3] >= 0 ||
|
|
1147
|
-
!blendsDirect(ops[pop + 1]) ||
|
|
1148
|
-
!this.draws.blendable(scene, ops[run + 1])
|
|
1149
|
-
) {
|
|
1150
|
+
if (!this.drawsDirect(commands, k, scene)) {
|
|
1150
1151
|
return false;
|
|
1151
1152
|
}
|
|
1152
1153
|
|
|
1153
|
-
const
|
|
1154
|
-
const
|
|
1154
|
+
const ops = commands.ops;
|
|
1155
|
+
const pop = k * 4 + 8;
|
|
1155
1156
|
const under = this.layers.at(-1) ?? canvas;
|
|
1156
|
-
const rect = this.rect;
|
|
1157
|
-
rect.x = p[from];
|
|
1158
|
-
rect.y = p[from + 1];
|
|
1159
|
-
rect.width = p[from + 2];
|
|
1160
|
-
rect.height = p[from + 3];
|
|
1161
1157
|
const mode = ops[pop + 1];
|
|
1158
|
+
const below = ops[k * 4 + 3] >> 1;
|
|
1162
1159
|
const compositor = this.compositor;
|
|
1163
|
-
if (!compositor.cover(
|
|
1160
|
+
if (!compositor.cover(this.rectAt(commands, k), under)) {
|
|
1164
1161
|
return true;
|
|
1165
1162
|
}
|
|
1166
1163
|
|
|
1167
1164
|
// Drawn into already, as a kept output is composited (COMPOSITE); a copy of what is below
|
|
1168
1165
|
// binds its framebuffer back.
|
|
1169
|
-
const reads = readsBelow(mode, under.opaque);
|
|
1170
|
-
|
|
1166
|
+
const reads = readsBelow(mode, under.opaque, below);
|
|
1167
|
+
let box = -1;
|
|
1168
|
+
if (reads) {
|
|
1169
|
+
// Shared only while the copy is the last made, which nothing but blends sharing it come
|
|
1170
|
+
// between.
|
|
1171
|
+
const backdrops = this.backdrops;
|
|
1172
|
+
box = backdrops.copy === compositor.copies ? backdrops.boxFor(k) : -1;
|
|
1173
|
+
if (box < 0) {
|
|
1174
|
+
box = this.shareCopy(commands, k, scene, under);
|
|
1175
|
+
} else {
|
|
1176
|
+
compositor.bindBack();
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1171
1180
|
this.draws.maskBy(this.masks);
|
|
1172
1181
|
const place = compositor.place;
|
|
1173
1182
|
// Kept to the layer's rectangle, as the composite is, past which nothing below is copied.
|
|
1174
1183
|
this.state.scissor([place.fx, place.fy, place.width, place.height]);
|
|
1175
1184
|
this.draws.drawBlended(
|
|
1176
1185
|
scene,
|
|
1177
|
-
ops[
|
|
1186
|
+
ops[k * 4 + 5],
|
|
1178
1187
|
mode,
|
|
1179
1188
|
reads,
|
|
1189
|
+
under.fresh,
|
|
1190
|
+
below,
|
|
1180
1191
|
ops[pop + 2],
|
|
1181
|
-
|
|
1182
|
-
|
|
1192
|
+
reads ? compositor.offsets[box * 2] : 0,
|
|
1193
|
+
reads ? compositor.offsets[box * 2 + 1] : 0,
|
|
1183
1194
|
);
|
|
1184
1195
|
this.state.scissor(null);
|
|
1185
1196
|
return true;
|
|
1186
1197
|
}
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* Whether the layer pushed at command `k` may be drawn straight onto the
|
|
1201
|
+
* target below (blendDirect): unfiltered, not kept, one run of a flat
|
|
1202
|
+
* geometry alone drawn normally in it, in a mode that blendsDirect.
|
|
1203
|
+
*/
|
|
1204
|
+
private drawsDirect(commands: Commands, k: number, scene: SceneList): boolean {
|
|
1205
|
+
const ops = commands.ops;
|
|
1206
|
+
const at = k * 4;
|
|
1207
|
+
const run = at + 4;
|
|
1208
|
+
const pop = at + 8;
|
|
1209
|
+
return (
|
|
1210
|
+
k + 2 < commands.length &&
|
|
1211
|
+
ops[at] === LAYER_PUSH &&
|
|
1212
|
+
ops[at + 2] === 0 &&
|
|
1213
|
+
ops[run] === RUN &&
|
|
1214
|
+
ops[run + 2] === 1 &&
|
|
1215
|
+
ops[run + 3] === NORMAL &&
|
|
1216
|
+
ops[pop] === LAYER_POP &&
|
|
1217
|
+
ops[pop + 3] < 0 &&
|
|
1218
|
+
blendsDirect(ops[pop + 1]) &&
|
|
1219
|
+
this.draws.blendable(scene, ops[run + 1])
|
|
1220
|
+
);
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
/** The rectangle of the layer pushed at command `k`, into rect. */
|
|
1224
|
+
private rectAt(
|
|
1225
|
+
commands: Commands,
|
|
1226
|
+
k: number,
|
|
1227
|
+
): { x: number; y: number; width: number; height: number } {
|
|
1228
|
+
const p = commands.params;
|
|
1229
|
+
const from = commands.ops[k * 4 + 1];
|
|
1230
|
+
const rect = this.rect;
|
|
1231
|
+
rect.x = p[from];
|
|
1232
|
+
rect.y = p[from + 1];
|
|
1233
|
+
rect.width = p[from + 2];
|
|
1234
|
+
rect.height = p[from + 3];
|
|
1235
|
+
return rect;
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
/**
|
|
1239
|
+
* What is below the blend drawn direct at command `k`, which reads it,
|
|
1240
|
+
* copied once for it and for the blends drawn direct right after it that
|
|
1241
|
+
* may share the copy (Backdrops): the box that holds its rectangle, and
|
|
1242
|
+
* the compositor's place its own again.
|
|
1243
|
+
*/
|
|
1244
|
+
private shareCopy(commands: Commands, k: number, scene: SceneList, under: Open): number {
|
|
1245
|
+
const compositor = this.compositor;
|
|
1246
|
+
const backdrops = this.backdrops;
|
|
1247
|
+
const place = compositor.place;
|
|
1248
|
+
backdrops.begin(compositor.copiesWhereLying(under));
|
|
1249
|
+
|
|
1250
|
+
for (let j = k; j < commands.length && this.drawsDirect(commands, j, scene); j += 3) {
|
|
1251
|
+
if (
|
|
1252
|
+
compositor.cover(this.rectAt(commands, j), under) &&
|
|
1253
|
+
!backdrops.offer(
|
|
1254
|
+
j,
|
|
1255
|
+
place.fx,
|
|
1256
|
+
place.fy,
|
|
1257
|
+
place.width,
|
|
1258
|
+
place.height,
|
|
1259
|
+
readsBelow(commands.ops[j * 4 + 9], under.opaque, commands.ops[j * 4 + 3] >> 1),
|
|
1260
|
+
)
|
|
1261
|
+
) {
|
|
1262
|
+
break;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
compositor.copyBoxes(under, backdrops.boxes, backdrops.boxCount);
|
|
1267
|
+
backdrops.copy = compositor.copies;
|
|
1268
|
+
compositor.cover(this.rectAt(commands, k), under);
|
|
1269
|
+
return backdrops.boxFor(k);
|
|
1270
|
+
}
|
|
1187
1271
|
}
|
package/src/webgl/composite.ts
CHANGED
|
@@ -5,10 +5,13 @@ import { ADD, ALPHA_MASK, KERNEL, LAYER, MULTIPLY, NORMAL, SCREEN } from "../sce
|
|
|
5
5
|
import type { KernelHost, KernelProgram, KernelPrograms } from "./kernels.js";
|
|
6
6
|
import {
|
|
7
7
|
BACK_UNIT,
|
|
8
|
+
BELOW_STEP,
|
|
8
9
|
compositeFragment,
|
|
9
10
|
compositeVertex,
|
|
11
|
+
FRESH,
|
|
10
12
|
LAYER_COLOR,
|
|
11
13
|
LAYER_UNIT,
|
|
14
|
+
SOLID_FRONT,
|
|
12
15
|
} from "./programs.js";
|
|
13
16
|
import { framebufferOf, LAYER_STEP, type Layer, type Open } from "./targets.js";
|
|
14
17
|
|
|
@@ -17,16 +20,19 @@ import { framebufferOf, LAYER_STEP, type Layer, type Open } from "./targets.js";
|
|
|
17
20
|
* not compute, onto a target `opaque` throughout or not. Over an opaque
|
|
18
21
|
* one, multiply's src × (1 − da) term is none, and premultiplied it is
|
|
19
22
|
* s × d + d × (1 − sa), alpha as normal's: GL's blending (setModeBlend).
|
|
20
|
-
* An alpha mask's is d × sa (ALPHA_MASK).
|
|
23
|
+
* An alpha mask's is d × sa (ALPHA_MASK). Any mode reads what is below in
|
|
24
|
+
* a layer drawn for its blend mode alone where that reads otherwise than
|
|
25
|
+
* it is stored (`below`, SceneList.below), which GL's blending cannot.
|
|
21
26
|
*/
|
|
22
|
-
export function readsBelow(mode: number, opaque = false): boolean {
|
|
27
|
+
export function readsBelow(mode: number, opaque = false, below = 0): boolean {
|
|
23
28
|
return !(
|
|
24
|
-
|
|
25
|
-
mode ===
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
below === 0 &&
|
|
30
|
+
(mode === NORMAL ||
|
|
31
|
+
mode === ALPHA_MASK ||
|
|
32
|
+
mode === LAYER ||
|
|
33
|
+
mode === ADD ||
|
|
34
|
+
mode === SCREEN ||
|
|
35
|
+
(mode === MULTIPLY && opaque))
|
|
30
36
|
);
|
|
31
37
|
}
|
|
32
38
|
|
|
@@ -85,6 +91,16 @@ export class Compositor {
|
|
|
85
91
|
private backFramebuffer: WebGLFramebuffer | null = null;
|
|
86
92
|
private backWidth = 0;
|
|
87
93
|
private backHeight = 0;
|
|
94
|
+
/** Copies made (copyBoxes), so that a blend sharing one knows it is still the last. */
|
|
95
|
+
copies = 0;
|
|
96
|
+
/** The rectangle copyBelow copies, as copyBoxes takes it. */
|
|
97
|
+
private readonly one = [0, 0, 0, 0];
|
|
98
|
+
/**
|
|
99
|
+
* Where the copy copyBoxes made has each box's corner, less where the
|
|
100
|
+
* target has it, two numbers a box: a blend's `backX` and `backY`.
|
|
101
|
+
*/
|
|
102
|
+
readonly offsets: number[] = [];
|
|
103
|
+
|
|
88
104
|
constructor(
|
|
89
105
|
gl: WebGL2RenderingContext,
|
|
90
106
|
state: GlState,
|
|
@@ -131,7 +147,8 @@ export class Compositor {
|
|
|
131
147
|
const kernel = given >= KERNEL ? this.useKernel(given - KERNEL) : null;
|
|
132
148
|
const mode = given >= KERNEL && !kernel ? NORMAL : given;
|
|
133
149
|
const state = this.state;
|
|
134
|
-
const
|
|
150
|
+
const below = kernel ? 0 : (open.below ?? 0);
|
|
151
|
+
const reads = readsBelow(mode, under.opaque, below);
|
|
135
152
|
if (!this.cover(open, under) || (reads && !this.copyBelow(under))) {
|
|
136
153
|
return;
|
|
137
154
|
}
|
|
@@ -160,7 +177,13 @@ export class Compositor {
|
|
|
160
177
|
} else {
|
|
161
178
|
state.useProgram(this.composite);
|
|
162
179
|
// Its pixel alone where GL's blending computes the mode (MULTIPLY over an opaque target).
|
|
163
|
-
gl.uniform1i(
|
|
180
|
+
gl.uniform1i(
|
|
181
|
+
this.modeLocation,
|
|
182
|
+
(reads ? mode : NORMAL) +
|
|
183
|
+
(under.fresh ? FRESH : 0) +
|
|
184
|
+
(open.solid ? SOLID_FRONT : 0) +
|
|
185
|
+
below * BELOW_STEP,
|
|
186
|
+
);
|
|
164
187
|
gl.uniform1i(this.compositeRowLocation, row);
|
|
165
188
|
gl.uniform2i(this.offsetLocation, dx + ox, offsetY);
|
|
166
189
|
gl.uniform1i(this.flipLocation, flip ? 1 : 0);
|
|
@@ -229,40 +252,78 @@ export class Compositor {
|
|
|
229
252
|
* where the target has it, into place, and `under`'s framebuffer bound again.
|
|
230
253
|
*/
|
|
231
254
|
copyBelow(under: Open): boolean {
|
|
255
|
+
const place = this.place;
|
|
256
|
+
const one = this.one;
|
|
257
|
+
one[0] = place.fx;
|
|
258
|
+
one[1] = place.fy;
|
|
259
|
+
one[2] = place.width;
|
|
260
|
+
one[3] = place.height;
|
|
261
|
+
this.copyBoxes(under, one, 1);
|
|
262
|
+
place.backX = this.offsets[0];
|
|
263
|
+
place.backY = this.offsets[1];
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Whether copyBoxes copies its boxes where they lie on `under`, so that
|
|
269
|
+
* it may copy more than one (Backdrops' `spread`); else it copies one,
|
|
270
|
+
* from its corner.
|
|
271
|
+
*/
|
|
272
|
+
copiesWhereLying(under: Open): boolean {
|
|
273
|
+
return under.msaa !== null && !(under.layer !== null && under.ox !== undefined);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* What is below `count` boxes of `under`'s framebuffer copied in one go,
|
|
278
|
+
* x, y, width and height each, for blends that read it
|
|
279
|
+
* (Backdrops): bound to BACK_UNIT, each box's offset into offsets, and
|
|
280
|
+
* `under`'s framebuffer bound again. More than one only where
|
|
281
|
+
* copiesWhereLying.
|
|
282
|
+
*/
|
|
283
|
+
copyBoxes(under: Open, boxes: readonly number[], count: number): void {
|
|
284
|
+
// Boxes copied from the corner would all land on it.
|
|
285
|
+
const lying = this.copiesWhereLying(under);
|
|
286
|
+
if (count > 1 && !lying) {
|
|
287
|
+
throw new Error("more than one backdrop box copied other than where they lie");
|
|
288
|
+
}
|
|
289
|
+
|
|
232
290
|
const gl = this.gl;
|
|
233
291
|
const state = this.state;
|
|
234
|
-
|
|
235
|
-
// Out of a multisampled page, its
|
|
236
|
-
//
|
|
292
|
+
this.copies++;
|
|
293
|
+
// Out of a multisampled page, its boxes resolved into the page's own texture first, which a
|
|
294
|
+
// blit may then copy anywhere: copied where it lies, the copy would stay as large as the
|
|
237
295
|
// page's far corner.
|
|
238
296
|
let from = framebufferOf(under);
|
|
239
297
|
const paged = under.msaa !== null && under.layer !== null && under.ox !== undefined;
|
|
240
298
|
if (paged) {
|
|
241
299
|
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, from);
|
|
242
300
|
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, (under.layer as Layer).framebuffer);
|
|
243
|
-
|
|
244
|
-
fx
|
|
245
|
-
fy
|
|
246
|
-
fx +
|
|
247
|
-
fy +
|
|
248
|
-
fx,
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
fy + height,
|
|
252
|
-
gl.COLOR_BUFFER_BIT,
|
|
253
|
-
gl.NEAREST,
|
|
254
|
-
);
|
|
301
|
+
for (let b = 0; b < count; b++) {
|
|
302
|
+
const fx = boxes[b * 4];
|
|
303
|
+
const fy = boxes[b * 4 + 1];
|
|
304
|
+
const right = fx + boxes[b * 4 + 2];
|
|
305
|
+
const top = fy + boxes[b * 4 + 3];
|
|
306
|
+
gl.blitFramebuffer(fx, fy, right, top, fx, fy, right, top, gl.COLOR_BUFFER_BIT, gl.NEAREST);
|
|
307
|
+
}
|
|
308
|
+
|
|
255
309
|
from = (under.layer as Layer).framebuffer;
|
|
256
310
|
}
|
|
257
311
|
|
|
258
312
|
// Copied from its corner, or out of a multisampled target to where it lies, as a blit
|
|
259
|
-
// resolving must keep its rectangle: then as large as the
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
313
|
+
// resolving must keep its rectangle: then as large as the boxes' far corner.
|
|
314
|
+
const offsets = this.offsets;
|
|
315
|
+
offsets.length = count * 2;
|
|
316
|
+
let right = 0;
|
|
317
|
+
let top = 0;
|
|
318
|
+
|
|
319
|
+
for (let b = 0; b < count; b++) {
|
|
320
|
+
const at = b * 4;
|
|
321
|
+
offsets[b * 2] = lying ? 0 : boxes[at];
|
|
322
|
+
offsets[b * 2 + 1] = lying ? 0 : boxes[at + 1];
|
|
323
|
+
right = Math.max(right, (lying ? boxes[at] : 0) + boxes[at + 2]);
|
|
324
|
+
top = Math.max(top, (lying ? boxes[at + 1] : 0) + boxes[at + 3]);
|
|
325
|
+
}
|
|
326
|
+
|
|
266
327
|
if (!this.back || this.backWidth < right || this.backHeight < top) {
|
|
267
328
|
if (this.back) {
|
|
268
329
|
state.dropTexture(this.back);
|
|
@@ -293,7 +354,7 @@ export class Compositor {
|
|
|
293
354
|
|
|
294
355
|
// Blitted, not copied: the canvas' colour may have no alpha, which copyTexSubImage2D into an
|
|
295
356
|
// RGBA texture refuses, where a blit fills it in.
|
|
296
|
-
// Out of a multisampled target the blit resolves the
|
|
357
|
+
// Out of a multisampled target the blit resolves the box alone.
|
|
297
358
|
if (!this.backFramebuffer) {
|
|
298
359
|
this.backFramebuffer = gl.createFramebuffer() as WebGLFramebuffer;
|
|
299
360
|
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, this.backFramebuffer);
|
|
@@ -309,23 +370,35 @@ export class Compositor {
|
|
|
309
370
|
}
|
|
310
371
|
|
|
311
372
|
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, from);
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
373
|
+
for (let b = 0; b < count; b++) {
|
|
374
|
+
const at = b * 4;
|
|
375
|
+
const fx = boxes[at];
|
|
376
|
+
const fy = boxes[at + 1];
|
|
377
|
+
const bx = fx - offsets[b * 2];
|
|
378
|
+
const by = fy - offsets[b * 2 + 1];
|
|
379
|
+
gl.blitFramebuffer(
|
|
380
|
+
fx,
|
|
381
|
+
fy,
|
|
382
|
+
fx + boxes[at + 2],
|
|
383
|
+
fy + boxes[at + 3],
|
|
384
|
+
bx,
|
|
385
|
+
by,
|
|
386
|
+
bx + boxes[at + 2],
|
|
387
|
+
by + boxes[at + 3],
|
|
388
|
+
gl.COLOR_BUFFER_BIT,
|
|
389
|
+
gl.NEAREST,
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
|
|
324
393
|
// Both bindings back as the state cache has them.
|
|
325
394
|
gl.bindFramebuffer(gl.FRAMEBUFFER, framebufferOf(under));
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
395
|
+
this.bindBack();
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/** The copy copyBoxes made bound to BACK_UNIT again, for a blend after another that shares it. */
|
|
399
|
+
bindBack(): void {
|
|
400
|
+
this.state.bindTexture(BACK_UNIT, this.back);
|
|
401
|
+
this.state.bindSampler(BACK_UNIT, null);
|
|
329
402
|
}
|
|
330
403
|
|
|
331
404
|
/**
|
package/src/webgl/draws.ts
CHANGED
|
@@ -22,10 +22,12 @@ import type { GpuTextures } from "./gpu-textures.js";
|
|
|
22
22
|
import type { KernelHost, KernelPrograms } from "./kernels.js";
|
|
23
23
|
import {
|
|
24
24
|
BACK_UNIT,
|
|
25
|
+
BELOW_STEP,
|
|
25
26
|
blendFillFragment,
|
|
26
27
|
FILL_SLOT,
|
|
27
28
|
FILL_TEXTURES,
|
|
28
29
|
FILL_UNIT,
|
|
30
|
+
FRESH,
|
|
29
31
|
fillFragment,
|
|
30
32
|
fillVertex,
|
|
31
33
|
glyphsFragment,
|
|
@@ -554,17 +556,22 @@ export class Draws {
|
|
|
554
556
|
|
|
555
557
|
/**
|
|
556
558
|
* Entry `i`, blendable, drawn onto the target bound in blend mode `mode`,
|
|
559
|
+
* a layer drawn for its blend mode alone where `fresh` (SceneList.fresh),
|
|
560
|
+
* what is below read as `below` says there (SceneList.below),
|
|
557
561
|
* coloured by its layer's row `layerRow` (or -1), where the masks pushed
|
|
558
562
|
* pass: GL's blending computing add, screen and, where it does not
|
|
559
563
|
* `reads` below, multiply, the program the rest from the copy of what is
|
|
560
|
-
* below (Compositor.
|
|
561
|
-
*
|
|
564
|
+
* below (Compositor.copyBoxes, made for it or shared with the blends
|
|
565
|
+
* drawn direct before it: Backdrops), whose texel at a fragment is
|
|
566
|
+
* (`backX`, `backY`) short of it.
|
|
562
567
|
*/
|
|
563
568
|
drawBlended(
|
|
564
569
|
scene: SceneList,
|
|
565
570
|
i: number,
|
|
566
571
|
mode: number,
|
|
567
572
|
reads: boolean,
|
|
573
|
+
fresh: boolean | undefined,
|
|
574
|
+
below: number,
|
|
568
575
|
layerRow: number,
|
|
569
576
|
backX: number,
|
|
570
577
|
backY: number,
|
|
@@ -576,7 +583,10 @@ export class Draws {
|
|
|
576
583
|
gl.uniform4fv(this.blendViewLocation, this.view);
|
|
577
584
|
gl.uniform1f(this.blendUnitLocation, this.unit);
|
|
578
585
|
// Its pixel alone where GL's blending computes the mode (readsBelow).
|
|
579
|
-
gl.uniform1i(
|
|
586
|
+
gl.uniform1i(
|
|
587
|
+
this.blendModeLocation,
|
|
588
|
+
(reads ? mode : NORMAL) + (fresh ? FRESH : 0) + below * BELOW_STEP,
|
|
589
|
+
);
|
|
580
590
|
gl.uniform1i(this.blendLayerRowLocation, layerRow);
|
|
581
591
|
gl.uniform2i(this.blendBackLocation, backX, backY);
|
|
582
592
|
this.gatherRun(scene, i, i + 1, false);
|
package/src/webgl/holds.ts
CHANGED
|
@@ -4,6 +4,9 @@ import {
|
|
|
4
4
|
HELD,
|
|
5
5
|
HOLD_POP,
|
|
6
6
|
HOLD_PUSH,
|
|
7
|
+
operandBelow,
|
|
8
|
+
operandMode,
|
|
9
|
+
operandSolid,
|
|
7
10
|
RUN,
|
|
8
11
|
STENCIL_POP,
|
|
9
12
|
STENCIL_PUSH,
|
|
@@ -545,8 +548,11 @@ export class HeldLayers {
|
|
|
545
548
|
state.stencil(null);
|
|
546
549
|
}
|
|
547
550
|
|
|
548
|
-
/**
|
|
549
|
-
|
|
551
|
+
/**
|
|
552
|
+
* Held output `held` composited onto `under`, bound, in blend mode and
|
|
553
|
+
* below `operand` (modeWithBelow), coloured by `row`.
|
|
554
|
+
*/
|
|
555
|
+
compositeHeld(held: number, under: Open, operand: number, row: number): void {
|
|
550
556
|
const hold = this.holds[held];
|
|
551
557
|
const result = hold.result;
|
|
552
558
|
if (!result) {
|
|
@@ -561,7 +567,9 @@ export class HeldLayers {
|
|
|
561
567
|
open.height = hold.height;
|
|
562
568
|
open.ox = result.x;
|
|
563
569
|
open.oy = result.y;
|
|
564
|
-
|
|
570
|
+
open.below = operandBelow(operand);
|
|
571
|
+
open.solid = operandSolid(operand);
|
|
572
|
+
this.compositor.compositeLayer(open, under, operandMode(operand), row);
|
|
565
573
|
}
|
|
566
574
|
|
|
567
575
|
/**
|