@swf2es/render 0.1.44 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/ramps.d.ts +31 -0
- package/dist/ramps.d.ts.map +1 -0
- package/dist/ramps.js +130 -0
- package/dist/ramps.js.map +1 -0
- package/dist/rows.d.ts +28 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +32 -1
- package/dist/rows.js.map +1 -1
- package/dist/scene.d.ts +6 -0
- package/dist/scene.d.ts.map +1 -1
- package/dist/scene.js +6 -0
- package/dist/scene.js.map +1 -1
- package/dist/spans.js +2 -2
- package/dist/spans.js.map +1 -1
- package/dist/textures.d.ts +42 -0
- package/dist/textures.d.ts.map +1 -1
- package/dist/textures.js +80 -14
- package/dist/textures.js.map +1 -1
- package/dist/webgl/backend.d.ts +7 -0
- package/dist/webgl/backend.d.ts.map +1 -1
- package/dist/webgl/backend.js +21 -5
- package/dist/webgl/backend.js.map +1 -1
- package/dist/webgl/draws.d.ts +50 -29
- package/dist/webgl/draws.d.ts.map +1 -1
- package/dist/webgl/draws.js +185 -85
- package/dist/webgl/draws.js.map +1 -1
- package/dist/webgl/gpu-textures.d.ts +31 -1
- package/dist/webgl/gpu-textures.d.ts.map +1 -1
- package/dist/webgl/gpu-textures.js +146 -4
- package/dist/webgl/gpu-textures.js.map +1 -1
- package/dist/webgl/programs.d.ts +40 -9
- package/dist/webgl/programs.d.ts.map +1 -1
- package/dist/webgl/programs.js +111 -18
- package/dist/webgl/programs.js.map +1 -1
- package/dist/webgl/ramps.d.ts +54 -0
- package/dist/webgl/ramps.d.ts.map +1 -0
- package/dist/webgl/ramps.js +277 -0
- package/dist/webgl/ramps.js.map +1 -0
- package/package.json +6 -2
- package/src/index.ts +11 -0
- package/src/ramps.ts +188 -0
- package/src/rows.ts +34 -1
- package/src/scene.ts +6 -0
- package/src/spans.ts +2 -2
- package/src/textures.ts +102 -14
- package/src/webgl/backend.ts +22 -5
- package/src/webgl/draws.ts +252 -91
- package/src/webgl/gpu-textures.ts +185 -5
- package/src/webgl/programs.ts +124 -18
- package/src/webgl/ramps.ts +338 -0
package/src/ramps.ts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// Gradient ramps built from their stops (Textures.addRamp): a record of a
|
|
2
|
+
// ramp's stops, from which the backend builds its 256 entries on the GPU,
|
|
3
|
+
// a line of the lines' texture, and rampOf, which builds the same entries
|
|
4
|
+
// on the CPU, entry for entry. The arithmetic is Flash's, as adl's ramps
|
|
5
|
+
// read back entry by entry show: each channel spanned between two stops in
|
|
6
|
+
// integers, c0 + floor((c1 - c0) * (k - r0) / (r1 - r0)); a span taking
|
|
7
|
+
// one entry at least, as Flash's loop does, so that a span of no width or
|
|
8
|
+
// going back takes its first stop's colour, and one ending behind where
|
|
9
|
+
// the ramp has got to is carried on past its end, wrapped into its byte;
|
|
10
|
+
// in linear RGB, the colour channels spanned in 8-bit linear light and
|
|
11
|
+
// taken back to sRGB by table. Each entry is then premultiplied as
|
|
12
|
+
// c * (a + 1) >> 8.
|
|
13
|
+
|
|
14
|
+
/** The most stops a record holds: as many as a gradient may have. */
|
|
15
|
+
export const RAMP_STOPS = 16;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Bytes of a record, a line of the stops' texture, RGBA: the count of its
|
|
19
|
+
* stops and whether they are spanned in linear light; their ratios, four a
|
|
20
|
+
* texel; then their colours, straight red, green, blue and alpha, a texel
|
|
21
|
+
* each, the colour channels in linear light already where they are spanned
|
|
22
|
+
* there (TO_LINEAR).
|
|
23
|
+
*/
|
|
24
|
+
export const RAMP_BYTES = 128;
|
|
25
|
+
export const RAMP_COUNT = 0;
|
|
26
|
+
export const RAMP_LINEAR = 1;
|
|
27
|
+
export const RAMP_RATIOS = 4;
|
|
28
|
+
export const RAMP_COLORS = 32;
|
|
29
|
+
|
|
30
|
+
function toLinear(c: number): number {
|
|
31
|
+
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function toSrgb(l: number): number {
|
|
35
|
+
return l <= 0.0031308 ? 12.92 * l : 1.055 * l ** (1 / 2.4) - 0.055;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Each sRGB byte in 8-bit linear light, and each such back in sRGB, both
|
|
40
|
+
* floored: Flash's, as every byte a ramp's ends come out as shows (255 to
|
|
41
|
+
* 254, 13 to 12).
|
|
42
|
+
*/
|
|
43
|
+
export const TO_LINEAR = Uint8Array.from({ length: 256 }, (_, c) =>
|
|
44
|
+
Math.floor(255 * toLinear(c / 255)),
|
|
45
|
+
);
|
|
46
|
+
export const TO_SRGB = Uint8Array.from({ length: 256 }, (_, l) =>
|
|
47
|
+
Math.min(255, Math.floor(255 * toSrgb(l / 255))),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
/** Each byte as it is: what an RGB ramp's colours come back as. */
|
|
51
|
+
const BYTES = Uint8Array.from({ length: 256 }, (_, c) => c);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The 256 entries of the ramp `record` holds, premultiplied ARGB, into
|
|
55
|
+
* `out`: the first stop's colour up to its ratio, a span from each stop to
|
|
56
|
+
* the next, the last stop's colour on to the end. With `swapped`, each
|
|
57
|
+
* entry's red and blue swapped, the word a little-endian machine keeps a
|
|
58
|
+
* texel's red, green, blue and alpha bytes in. From `offset` in `out`, so
|
|
59
|
+
* that a line of a larger texture's words needs no view of its own.
|
|
60
|
+
*/
|
|
61
|
+
export function rampOf(
|
|
62
|
+
record: Uint8Array,
|
|
63
|
+
out: Uint32Array,
|
|
64
|
+
swapped = false,
|
|
65
|
+
offset = 0,
|
|
66
|
+
): Uint32Array {
|
|
67
|
+
const count = record[RAMP_COUNT];
|
|
68
|
+
const back = record[RAMP_LINEAR] ? TO_SRGB : BYTES;
|
|
69
|
+
const red = swapped ? 0 : 16;
|
|
70
|
+
const blue = swapped ? 16 : 0;
|
|
71
|
+
|
|
72
|
+
let at = 0;
|
|
73
|
+
const firstRatio = record[RAMP_RATIOS];
|
|
74
|
+
const first = entryAt(record, 0, back, red, blue);
|
|
75
|
+
for (; at <= firstRatio; at++) {
|
|
76
|
+
out[offset + at] = first;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
for (let i = 1; i < count && at < 256; i++) {
|
|
80
|
+
at = span(record, i - 1, at, back, out, offset, red, blue);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const last = entryAt(record, count - 1, back, red, blue);
|
|
84
|
+
for (; at < 256; at++) {
|
|
85
|
+
out[offset + at] = last;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Stop `from`'s span to the next, from entry `at`, into `out` from `offset`: each channel
|
|
93
|
+
* c0 + floor(d * j / w) for the entry j past the stop, stepped on by
|
|
94
|
+
* floor(d / w) and the remainder carried (STEPS), the same integers as
|
|
95
|
+
* dividing for each. The entry after the last written.
|
|
96
|
+
*/
|
|
97
|
+
function span(
|
|
98
|
+
record: Uint8Array,
|
|
99
|
+
from: number,
|
|
100
|
+
at: number,
|
|
101
|
+
back: Uint8Array,
|
|
102
|
+
out: Uint32Array,
|
|
103
|
+
offset: number,
|
|
104
|
+
red: number,
|
|
105
|
+
blue: number,
|
|
106
|
+
): number {
|
|
107
|
+
const r0 = record[RAMP_RATIOS + from];
|
|
108
|
+
const width = record[RAMP_RATIOS + from + 1] - r0;
|
|
109
|
+
if (width <= 0) {
|
|
110
|
+
out[offset + at] = entryAt(record, from, back, red, blue);
|
|
111
|
+
return at + 1;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const x = RAMP_COLORS + from * 4;
|
|
115
|
+
const end = Math.max(at, Math.min(r0 + width, 255));
|
|
116
|
+
const j = at - r0;
|
|
117
|
+
for (let c = 0; c < 4; c++) {
|
|
118
|
+
start(c * 4, record[x + c], record[x + 4 + c], j, width);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const s = STEPS;
|
|
122
|
+
for (; at <= end; at++) {
|
|
123
|
+
out[offset + at] = packed(
|
|
124
|
+
s[12] & 0xff,
|
|
125
|
+
back[s[0] & 0xff],
|
|
126
|
+
back[s[4] & 0xff],
|
|
127
|
+
back[s[8] & 0xff],
|
|
128
|
+
red,
|
|
129
|
+
blue,
|
|
130
|
+
);
|
|
131
|
+
for (let c = 0; c < 16; c += 4) {
|
|
132
|
+
s[c] += s[c + 2];
|
|
133
|
+
s[c + 1] += s[c + 3];
|
|
134
|
+
if (s[c + 1] >= width) {
|
|
135
|
+
s[c + 1] -= width;
|
|
136
|
+
s[c]++;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return at;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Each channel of a span, red, green, blue and alpha, four numbers each:
|
|
146
|
+
* its value, the remainder over the span's width, and the whole and the
|
|
147
|
+
* remainder a step adds.
|
|
148
|
+
*/
|
|
149
|
+
const STEPS = new Int32Array(16);
|
|
150
|
+
|
|
151
|
+
/** Channel `c` of STEPS from c0 to c1 over `width` entries, at entry j: c0 + floor((c1 - c0) * j / width). */
|
|
152
|
+
function start(c: number, c0: number, c1: number, j: number, width: number): void {
|
|
153
|
+
const d = c1 - c0;
|
|
154
|
+
const n = d * j;
|
|
155
|
+
const q = Math.floor(n / width);
|
|
156
|
+
const whole = Math.floor(d / width);
|
|
157
|
+
STEPS[c] = c0 + q;
|
|
158
|
+
STEPS[c + 1] = n - q * width;
|
|
159
|
+
STEPS[c + 2] = whole;
|
|
160
|
+
STEPS[c + 3] = d - whole * width;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Stop `i`'s colour as an entry, its colour channels back from the span's bytes, premultiplied. */
|
|
164
|
+
function entryAt(
|
|
165
|
+
record: Uint8Array,
|
|
166
|
+
i: number,
|
|
167
|
+
back: Uint8Array,
|
|
168
|
+
red: number,
|
|
169
|
+
blue: number,
|
|
170
|
+
): number {
|
|
171
|
+
const x = RAMP_COLORS + i * 4;
|
|
172
|
+
return packed(
|
|
173
|
+
record[x + 3],
|
|
174
|
+
back[record[x]],
|
|
175
|
+
back[record[x + 1]],
|
|
176
|
+
back[record[x + 2]],
|
|
177
|
+
red,
|
|
178
|
+
blue,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Straight channels premultiplied, each times alpha + 1 over 256, red and blue at their shifts. */
|
|
183
|
+
function packed(a: number, r: number, g: number, b: number, red: number, blue: number): number {
|
|
184
|
+
const k = a + 1;
|
|
185
|
+
return (
|
|
186
|
+
((a << 24) | (((r * k) >> 8) << red) | (((g * k) >> 8) << 8) | (((b * k) >> 8) << blue)) >>> 0
|
|
187
|
+
);
|
|
188
|
+
}
|
package/src/rows.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Floats a row: an object's transform on the stage and its colour
|
|
3
3
|
* transform, four texels of a float texture. The linear part; the
|
|
4
|
-
* translation
|
|
4
|
+
* translation, then the line its draws read their texture on (line), or 0,
|
|
5
|
+
* and a radial gradient's focal point (radial), or 0; the multipliers; the
|
|
6
|
+
* offsets, over 255.
|
|
5
7
|
*/
|
|
6
8
|
export const ROW_FLOATS = 16;
|
|
9
|
+
/**
|
|
10
|
+
* What a radial gradient's row (radial) adds to its focal point in the
|
|
11
|
+
* translation's last float: 0 there is any other draw's.
|
|
12
|
+
*/
|
|
13
|
+
export const RADIAL = 2;
|
|
14
|
+
/**
|
|
15
|
+
* What it adds for each entry its ramp is read no lower than (radial's
|
|
16
|
+
* `least`): wider than a focal point's span, so that each is told apart.
|
|
17
|
+
*/
|
|
18
|
+
export const RADIAL_LEAST_STEP = 4;
|
|
7
19
|
/** Rows a line of the rows' texture. */
|
|
8
20
|
export const ROWS_A_LINE = 256;
|
|
9
21
|
/**
|
|
@@ -119,6 +131,27 @@ export class Rows {
|
|
|
119
131
|
return row;
|
|
120
132
|
}
|
|
121
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Row `row`'s draws read their texture on its line `line` alone, whatever
|
|
136
|
+
* their texels' v: a ramp kept as a line of a texture of many, so that
|
|
137
|
+
* instances whose ramps differ need not each take a texture of their own,
|
|
138
|
+
* each of which takes one of the fill program's slots and ends a run as
|
|
139
|
+
* they run out.
|
|
140
|
+
*/
|
|
141
|
+
line(row: number, line: number): void {
|
|
142
|
+
this.data[row * ROW_FLOATS + 6] = line + 0.5;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Row `row`'s draws are a radial gradient's, their texels its square's
|
|
147
|
+
* place (a unit its radius), from which the fill program finds each
|
|
148
|
+
* fragment's place on the ramp, out from `focal` on the x axis (-1 to 1),
|
|
149
|
+
* read no lower than entry `least`.
|
|
150
|
+
*/
|
|
151
|
+
radial(row: number, focal: number, least = 0): void {
|
|
152
|
+
this.data[row * ROW_FLOATS + 7] = focal + RADIAL + least * RADIAL_LEAST_STEP;
|
|
153
|
+
}
|
|
154
|
+
|
|
122
155
|
/** A row taken, the store grown for it: its index. */
|
|
123
156
|
private next(): number {
|
|
124
157
|
const row = this.count++;
|
package/src/scene.ts
CHANGED
|
@@ -146,6 +146,12 @@ export const SNAP = 32;
|
|
|
146
146
|
* draws one.
|
|
147
147
|
*/
|
|
148
148
|
export const SHADED = 64;
|
|
149
|
+
/**
|
|
150
|
+
* A radial gradient's draw, whose row says so (Rows.radial): drawn by a
|
|
151
|
+
* fill program that finds each fragment's place on its ramp, which the
|
|
152
|
+
* plain fill program leaves out (webgl/programs.ts, radialFillFragment).
|
|
153
|
+
*/
|
|
154
|
+
export const RADIAL_FILL = 128;
|
|
149
155
|
|
|
150
156
|
/**
|
|
151
157
|
* Which pixels a filtered layer's object covers (SceneList.wholes): those
|
package/src/spans.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface Span {
|
|
|
22
22
|
rowsEnd: number;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
/** A row's floats by name (rows.ts)
|
|
25
|
+
/** A row's floats by name (rows.ts): the line after the translation (Rows.line), one unused. */
|
|
26
26
|
const ROW_NAMES = [
|
|
27
27
|
"a",
|
|
28
28
|
"b",
|
|
@@ -30,7 +30,7 @@ const ROW_NAMES = [
|
|
|
30
30
|
"d",
|
|
31
31
|
"tx",
|
|
32
32
|
"ty",
|
|
33
|
-
"
|
|
33
|
+
"line",
|
|
34
34
|
"pad 7",
|
|
35
35
|
"rMul",
|
|
36
36
|
"gMul",
|
package/src/textures.ts
CHANGED
|
@@ -18,8 +18,22 @@ export interface TextureData {
|
|
|
18
18
|
fill: number | null;
|
|
19
19
|
/** Host image, interpreted only by the backend; core has no DOM dependency. */
|
|
20
20
|
source?: object | null;
|
|
21
|
+
/** Its line of the lines' texture where it is a line (addLine). */
|
|
22
|
+
line?: number;
|
|
23
|
+
/** Whether its pixels are a ramp's record, which the backend builds the line from (addRamp). */
|
|
24
|
+
ramp?: boolean;
|
|
21
25
|
}
|
|
22
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Texels a line texture has (addLine): a gradient's ramp's, 256 across. The
|
|
29
|
+
* lines' texture is as wide, so that a ramp wraps across it as across a
|
|
30
|
+
* texture of its own.
|
|
31
|
+
*/
|
|
32
|
+
export const LINE_TEXELS = 256;
|
|
33
|
+
|
|
34
|
+
/** The most lines there are at once: the lines' texture's height, which every WebGL 2 allows. */
|
|
35
|
+
const LINES_MOST = 2048;
|
|
36
|
+
|
|
23
37
|
/**
|
|
24
38
|
* How many frames a texture keeps the bytes it was last set from without
|
|
25
39
|
* being set again, and spare bytes wait for another texture: a texture set
|
|
@@ -60,6 +74,9 @@ export class Textures extends Registry {
|
|
|
60
74
|
private readonly lent = new WeakSet<Uint8Array>();
|
|
61
75
|
/** Added or set again since the backend last took them. */
|
|
62
76
|
pending: number[] = [];
|
|
77
|
+
/** Lines let go of, to give again, and how many have been given (addLine). */
|
|
78
|
+
private readonly freeLines: number[] = [];
|
|
79
|
+
private lineTop = 0;
|
|
63
80
|
|
|
64
81
|
/**
|
|
65
82
|
* `length` bytes to fill and add or set a texture from: those texture `id`
|
|
@@ -97,6 +114,51 @@ export class Textures extends Registry {
|
|
|
97
114
|
return handle;
|
|
98
115
|
}
|
|
99
116
|
|
|
117
|
+
/**
|
|
118
|
+
* A texture of `pixels`, LINE_TEXELS by 1, kept by the backend as a line of
|
|
119
|
+
* one texture of many (lineOf): drawn on that line by its row (Rows.line),
|
|
120
|
+
* all of them take one of the fill program's slots, and those a frame
|
|
121
|
+
* added or set are uploaded together, where many textures of their own, as
|
|
122
|
+
* a gradient's ramps under many colour transforms are, each took a slot,
|
|
123
|
+
* ending a run as they ran out, and an upload. Null where there are as
|
|
124
|
+
* many lines as there may be. It is set again as any other, at its size.
|
|
125
|
+
*/
|
|
126
|
+
addLine(pixels: Uint8Array, idle = IDLE_FRAMES): TextureHandle | null {
|
|
127
|
+
const line = this.freeLines.pop() ?? (this.lineTop < LINES_MOST ? this.lineTop++ : -1);
|
|
128
|
+
if (line < 0) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const handle = this.add(LINE_TEXELS, 1, pixels, idle);
|
|
133
|
+
(this.data[handle.id] as TextureData).line = line;
|
|
134
|
+
return handle;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* A line texture (addLine) whose texels the backend builds from `record`,
|
|
139
|
+
* a ramp's stops (ramps.ts), rather than uploads: RAMP_BYTES set in its
|
|
140
|
+
* place, and no span of a ramp in script. Set again, refilled, from
|
|
141
|
+
* another record. Null where there are as many lines as there may be.
|
|
142
|
+
*/
|
|
143
|
+
addRamp(record: Uint8Array, idle = IDLE_FRAMES): TextureHandle | null {
|
|
144
|
+
const handle = this.addLine(record, idle);
|
|
145
|
+
if (handle) {
|
|
146
|
+
(this.data[handle.id] as TextureData).ramp = true;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return handle;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** `id`'s line of the lines' texture, or -1 for a texture of its own. */
|
|
153
|
+
lineOf(id: number): number {
|
|
154
|
+
return this.data[id]?.line ?? -1;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** How many lines the lines' texture has room for at least: those given, the free among them. */
|
|
158
|
+
get lines(): number {
|
|
159
|
+
return this.lineTop;
|
|
160
|
+
}
|
|
161
|
+
|
|
100
162
|
/**
|
|
101
163
|
* A texture every texel of which is `pixel`, premultiplied ARGB, as a
|
|
102
164
|
* BitmapData is made: cleared to it on the GPU, with no bytes to fill
|
|
@@ -116,20 +178,17 @@ export class Textures extends Registry {
|
|
|
116
178
|
* let go of after as many undrawn frames where that is fewer.
|
|
117
179
|
*/
|
|
118
180
|
set(id: number, width: number, height: number, pixels: Uint8Array, idle?: number): void {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
this.idleWithin(id, idle);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
181
|
+
this.setAs(id, width, height, pixels, idle, true);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* As set, for pixels made anew whole each time, as a gradient's are for
|
|
186
|
+
* each colour transform taken into its stops: their bytes are spared once
|
|
187
|
+
* uploaded, as an added texture's are, not kept for KEEP_FRAMES, so that
|
|
188
|
+
* textures refilled every frame hold no more than the spare bytes' cap.
|
|
189
|
+
*/
|
|
190
|
+
refill(id: number, width: number, height: number, pixels: Uint8Array, idle?: number): void {
|
|
191
|
+
this.setAs(id, width, height, pixels, idle, false);
|
|
133
192
|
}
|
|
134
193
|
|
|
135
194
|
/** A host image uploaded directly, without making a CPU copy for the renderer. */
|
|
@@ -191,6 +250,11 @@ export class Textures extends Registry {
|
|
|
191
250
|
}
|
|
192
251
|
|
|
193
252
|
protected override dropped(id: number): void {
|
|
253
|
+
const line = this.data[id]?.line;
|
|
254
|
+
if (line !== undefined) {
|
|
255
|
+
this.freeLines.push(line);
|
|
256
|
+
}
|
|
257
|
+
|
|
194
258
|
this.data[id] = null;
|
|
195
259
|
const bytes = this.kept[id];
|
|
196
260
|
this.kept[id] = null;
|
|
@@ -199,6 +263,30 @@ export class Textures extends Registry {
|
|
|
199
263
|
}
|
|
200
264
|
}
|
|
201
265
|
|
|
266
|
+
private setAs(
|
|
267
|
+
id: number,
|
|
268
|
+
width: number,
|
|
269
|
+
height: number,
|
|
270
|
+
pixels: Uint8Array,
|
|
271
|
+
idle: number | undefined,
|
|
272
|
+
changing: boolean,
|
|
273
|
+
): void {
|
|
274
|
+
const data = this.data[id];
|
|
275
|
+
if (data) {
|
|
276
|
+
data.width = width;
|
|
277
|
+
data.height = height;
|
|
278
|
+
data.pixels = pixels;
|
|
279
|
+
data.source = null;
|
|
280
|
+
data.fill = null;
|
|
281
|
+
this.keep(id, pixels);
|
|
282
|
+
this.changing[id] = changing;
|
|
283
|
+
this.pending.push(id);
|
|
284
|
+
if (idle !== undefined) {
|
|
285
|
+
this.idleWithin(id, idle);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
202
290
|
/** `pixels` kept for `id` where `bytes` lent them; those it kept before spared. */
|
|
203
291
|
private keep(id: number, pixels: Uint8Array | Float32Array | null): void {
|
|
204
292
|
const before = this.kept[id];
|
package/src/webgl/backend.ts
CHANGED
|
@@ -35,6 +35,7 @@ import { KernelPrograms } from "./kernels.js";
|
|
|
35
35
|
import { LinkLosses } from "./losses.js";
|
|
36
36
|
import { ProgramQueue } from "./precompile.js";
|
|
37
37
|
import { LAYER_UNIT, TEXTURE_UNIT } from "./programs.js";
|
|
38
|
+
import { RampBuilder } from "./ramps.js";
|
|
38
39
|
import { Stage } from "./stage.js";
|
|
39
40
|
import { type Layer, type Open, objectOf, type Target, TargetPool } from "./targets.js";
|
|
40
41
|
|
|
@@ -96,6 +97,8 @@ export class WebGLBackend {
|
|
|
96
97
|
private readonly pool: TargetPool;
|
|
97
98
|
private readonly stage: Stage;
|
|
98
99
|
private readonly gpu: GpuTextures;
|
|
100
|
+
/** Ramps built from their records into the lines' texture (Textures.addRamp). */
|
|
101
|
+
private readonly ramps: RampBuilder;
|
|
99
102
|
private readonly atlas: GeometryAtlas;
|
|
100
103
|
private readonly compositor: Compositor;
|
|
101
104
|
private readonly draws: Draws;
|
|
@@ -156,6 +159,7 @@ export class WebGLBackend {
|
|
|
156
159
|
this.pool = new TargetPool(gl, this.state);
|
|
157
160
|
this.stage = new Stage(gl, this.state, this.pool);
|
|
158
161
|
this.gpu = new GpuTextures(gl, this.state);
|
|
162
|
+
this.ramps = new RampBuilder(gl, this.state);
|
|
159
163
|
this.atlas = new GeometryAtlas(gl, this.state);
|
|
160
164
|
this.compositor = new Compositor(
|
|
161
165
|
gl,
|
|
@@ -325,11 +329,13 @@ export class WebGLBackend {
|
|
|
325
329
|
this.stage.setUp();
|
|
326
330
|
this.atlas.setUp();
|
|
327
331
|
this.gpu.setUp();
|
|
332
|
+
this.ramps.setUp();
|
|
328
333
|
// The context's own, gone with it.
|
|
329
334
|
this.textureFramebuffers = [];
|
|
330
335
|
// Linked last: a context lost meanwhile throws here (gaveUp), the rest made, for destroy.
|
|
331
336
|
this.draws.setUp(textureMost);
|
|
332
337
|
this.compositor.setUp();
|
|
338
|
+
this.ramps.link();
|
|
333
339
|
}
|
|
334
340
|
|
|
335
341
|
/**
|
|
@@ -389,7 +395,7 @@ export class WebGLBackend {
|
|
|
389
395
|
const gl = this.gl;
|
|
390
396
|
this.frameFilters = filters;
|
|
391
397
|
this.atlas.place(geometries);
|
|
392
|
-
this.
|
|
398
|
+
this.uploadTextures(textures);
|
|
393
399
|
for (const id of keeps.removed) {
|
|
394
400
|
this.pool.release(id);
|
|
395
401
|
}
|
|
@@ -400,8 +406,7 @@ export class WebGLBackend {
|
|
|
400
406
|
const state = this.state;
|
|
401
407
|
state.scissor(null);
|
|
402
408
|
state.colorMask(15);
|
|
403
|
-
|
|
404
|
-
state.bindTexture(0, this.gpu.rowsTexture);
|
|
409
|
+
this.draws.useFill();
|
|
405
410
|
// As many samples as the GPU takes; a BitmapData's frame supersamples instead, as Flash's draw
|
|
406
411
|
// does. Its layers take the stage's, so that their edges are the stage's.
|
|
407
412
|
const stage = root ? null : this.stage.stageBuffers(target.width, target.height, this.samples);
|
|
@@ -843,7 +848,7 @@ export class WebGLBackend {
|
|
|
843
848
|
return false;
|
|
844
849
|
}
|
|
845
850
|
|
|
846
|
-
this.
|
|
851
|
+
this.uploadTextures(textures);
|
|
847
852
|
const framebuffer = this.textureFramebuffer(id);
|
|
848
853
|
if (!framebuffer) {
|
|
849
854
|
return false;
|
|
@@ -853,6 +858,17 @@ export class WebGLBackend {
|
|
|
853
858
|
return true;
|
|
854
859
|
}
|
|
855
860
|
|
|
861
|
+
/**
|
|
862
|
+
* The textures uploaded (GpuTextures' uploadTextures), then the lines set
|
|
863
|
+
* from ramps' records built from them (RampBuilder).
|
|
864
|
+
*/
|
|
865
|
+
private uploadTextures(textures: Textures): void {
|
|
866
|
+
this.gpu.uploadTextures(textures, this.clearTexture);
|
|
867
|
+
if (this.gpu.builds.length > 0) {
|
|
868
|
+
this.ramps.build(this.gpu, this.gpu.sampler(0));
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
856
872
|
/** A texture of one colour, `width` by `height`, made: cleared to it (GpuTextures' uploadTextures). */
|
|
857
873
|
private readonly clearTexture = (id: number, width: number, height: number, pixel: number) => {
|
|
858
874
|
const framebuffer = this.textureFramebuffer(id);
|
|
@@ -907,7 +923,7 @@ export class WebGLBackend {
|
|
|
907
923
|
return false;
|
|
908
924
|
}
|
|
909
925
|
|
|
910
|
-
this.
|
|
926
|
+
this.uploadTextures(textures);
|
|
911
927
|
const source = this.textureFramebuffer(from);
|
|
912
928
|
const target = source ? this.textureFramebuffer(to) : null;
|
|
913
929
|
if (!source || !target) {
|
|
@@ -1141,6 +1157,7 @@ export class WebGLBackend {
|
|
|
1141
1157
|
this.overProgram = null;
|
|
1142
1158
|
}
|
|
1143
1159
|
|
|
1160
|
+
this.ramps.destroy();
|
|
1144
1161
|
this.gpu.destroy();
|
|
1145
1162
|
this.state.forget();
|
|
1146
1163
|
}
|