@swf2es/render 0.1.44 → 0.1.45
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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- 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 +33 -0
- package/dist/textures.d.ts.map +1 -1
- package/dist/textures.js +67 -14
- package/dist/textures.js.map +1 -1
- package/dist/webgl/backend.d.ts.map +1 -1
- package/dist/webgl/backend.js +1 -2
- 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 +16 -1
- package/dist/webgl/gpu-textures.d.ts.map +1 -1
- package/dist/webgl/gpu-textures.js +61 -3
- 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/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/rows.ts +34 -1
- package/src/scene.ts +6 -0
- package/src/spans.ts +2 -2
- package/src/textures.ts +85 -14
- package/src/webgl/backend.ts +1 -2
- package/src/webgl/draws.ts +252 -91
- package/src/webgl/gpu-textures.ts +91 -4
- package/src/webgl/programs.ts +124 -18
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,20 @@ 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;
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Texels a line texture has (addLine): a gradient's ramp's, 256 across. The
|
|
27
|
+
* lines' texture is as wide, so that a ramp wraps across it as across a
|
|
28
|
+
* texture of its own.
|
|
29
|
+
*/
|
|
30
|
+
export const LINE_TEXELS = 256;
|
|
31
|
+
|
|
32
|
+
/** The most lines there are at once: the lines' texture's height, which every WebGL 2 allows. */
|
|
33
|
+
const LINES_MOST = 2048;
|
|
34
|
+
|
|
23
35
|
/**
|
|
24
36
|
* How many frames a texture keeps the bytes it was last set from without
|
|
25
37
|
* being set again, and spare bytes wait for another texture: a texture set
|
|
@@ -60,6 +72,9 @@ export class Textures extends Registry {
|
|
|
60
72
|
private readonly lent = new WeakSet<Uint8Array>();
|
|
61
73
|
/** Added or set again since the backend last took them. */
|
|
62
74
|
pending: number[] = [];
|
|
75
|
+
/** Lines let go of, to give again, and how many have been given (addLine). */
|
|
76
|
+
private readonly freeLines: number[] = [];
|
|
77
|
+
private lineTop = 0;
|
|
63
78
|
|
|
64
79
|
/**
|
|
65
80
|
* `length` bytes to fill and add or set a texture from: those texture `id`
|
|
@@ -97,6 +112,36 @@ export class Textures extends Registry {
|
|
|
97
112
|
return handle;
|
|
98
113
|
}
|
|
99
114
|
|
|
115
|
+
/**
|
|
116
|
+
* A texture of `pixels`, LINE_TEXELS by 1, kept by the backend as a line of
|
|
117
|
+
* one texture of many (lineOf): drawn on that line by its row (Rows.line),
|
|
118
|
+
* all of them take one of the fill program's slots, and those a frame
|
|
119
|
+
* added or set are uploaded together, where many textures of their own, as
|
|
120
|
+
* a gradient's ramps under many colour transforms are, each took a slot,
|
|
121
|
+
* ending a run as they ran out, and an upload. Null where there are as
|
|
122
|
+
* many lines as there may be. It is set again as any other, at its size.
|
|
123
|
+
*/
|
|
124
|
+
addLine(pixels: Uint8Array, idle = IDLE_FRAMES): TextureHandle | null {
|
|
125
|
+
const line = this.freeLines.pop() ?? (this.lineTop < LINES_MOST ? this.lineTop++ : -1);
|
|
126
|
+
if (line < 0) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const handle = this.add(LINE_TEXELS, 1, pixels, idle);
|
|
131
|
+
(this.data[handle.id] as TextureData).line = line;
|
|
132
|
+
return handle;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** `id`'s line of the lines' texture, or -1 for a texture of its own. */
|
|
136
|
+
lineOf(id: number): number {
|
|
137
|
+
return this.data[id]?.line ?? -1;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** How many lines the lines' texture has room for at least: those given, the free among them. */
|
|
141
|
+
get lines(): number {
|
|
142
|
+
return this.lineTop;
|
|
143
|
+
}
|
|
144
|
+
|
|
100
145
|
/**
|
|
101
146
|
* A texture every texel of which is `pixel`, premultiplied ARGB, as a
|
|
102
147
|
* BitmapData is made: cleared to it on the GPU, with no bytes to fill
|
|
@@ -116,20 +161,17 @@ export class Textures extends Registry {
|
|
|
116
161
|
* let go of after as many undrawn frames where that is fewer.
|
|
117
162
|
*/
|
|
118
163
|
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
|
-
}
|
|
164
|
+
this.setAs(id, width, height, pixels, idle, true);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* As set, for pixels made anew whole each time, as a gradient's are for
|
|
169
|
+
* each colour transform taken into its stops: their bytes are spared once
|
|
170
|
+
* uploaded, as an added texture's are, not kept for KEEP_FRAMES, so that
|
|
171
|
+
* textures refilled every frame hold no more than the spare bytes' cap.
|
|
172
|
+
*/
|
|
173
|
+
refill(id: number, width: number, height: number, pixels: Uint8Array, idle?: number): void {
|
|
174
|
+
this.setAs(id, width, height, pixels, idle, false);
|
|
133
175
|
}
|
|
134
176
|
|
|
135
177
|
/** A host image uploaded directly, without making a CPU copy for the renderer. */
|
|
@@ -191,6 +233,11 @@ export class Textures extends Registry {
|
|
|
191
233
|
}
|
|
192
234
|
|
|
193
235
|
protected override dropped(id: number): void {
|
|
236
|
+
const line = this.data[id]?.line;
|
|
237
|
+
if (line !== undefined) {
|
|
238
|
+
this.freeLines.push(line);
|
|
239
|
+
}
|
|
240
|
+
|
|
194
241
|
this.data[id] = null;
|
|
195
242
|
const bytes = this.kept[id];
|
|
196
243
|
this.kept[id] = null;
|
|
@@ -199,6 +246,30 @@ export class Textures extends Registry {
|
|
|
199
246
|
}
|
|
200
247
|
}
|
|
201
248
|
|
|
249
|
+
private setAs(
|
|
250
|
+
id: number,
|
|
251
|
+
width: number,
|
|
252
|
+
height: number,
|
|
253
|
+
pixels: Uint8Array,
|
|
254
|
+
idle: number | undefined,
|
|
255
|
+
changing: boolean,
|
|
256
|
+
): void {
|
|
257
|
+
const data = this.data[id];
|
|
258
|
+
if (data) {
|
|
259
|
+
data.width = width;
|
|
260
|
+
data.height = height;
|
|
261
|
+
data.pixels = pixels;
|
|
262
|
+
data.source = null;
|
|
263
|
+
data.fill = null;
|
|
264
|
+
this.keep(id, pixels);
|
|
265
|
+
this.changing[id] = changing;
|
|
266
|
+
this.pending.push(id);
|
|
267
|
+
if (idle !== undefined) {
|
|
268
|
+
this.idleWithin(id, idle);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
202
273
|
/** `pixels` kept for `id` where `bytes` lent them; those it kept before spared. */
|
|
203
274
|
private keep(id: number, pixels: Uint8Array | Float32Array | null): void {
|
|
204
275
|
const before = this.kept[id];
|
package/src/webgl/backend.ts
CHANGED
|
@@ -400,8 +400,7 @@ export class WebGLBackend {
|
|
|
400
400
|
const state = this.state;
|
|
401
401
|
state.scissor(null);
|
|
402
402
|
state.colorMask(15);
|
|
403
|
-
|
|
404
|
-
state.bindTexture(0, this.gpu.rowsTexture);
|
|
403
|
+
this.draws.useFill();
|
|
405
404
|
// As many samples as the GPU takes; a BitmapData's frame supersamples instead, as Flash's draw
|
|
406
405
|
// does. Its layers take the stage's, so that their edges are the stage's.
|
|
407
406
|
const stage = root ? null : this.stage.stageBuffers(target.width, target.height, this.samples);
|