@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
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import type { GlState } from "@swf2es/context3d/device";
|
|
2
|
+
import { RAMP_BYTES, rampOf } from "../ramps.js";
|
|
2
3
|
import { ROW_FLOATS, ROWS_A_LINE, type Rows } from "../rows.js";
|
|
3
4
|
import { MIRROR, REPEAT, SMOOTH } from "../scene.js";
|
|
4
|
-
import type
|
|
5
|
+
import { LINE_TEXELS, type Textures } from "../textures.js";
|
|
5
6
|
import { OUTLINE_ROW, OUTLINE_UNIT, ROW_TEXELS, TEXTURE_UNIT } from "./programs.js";
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Fewer ramps than this set in a frame (Textures.addRamp) are built on the
|
|
10
|
+
* CPU (rampOf) into the lines' bytes, uploaded with the other lines, so
|
|
11
|
+
* that a frame making a ramp or two, as most do, draws nothing more for
|
|
12
|
+
* them; as many or more, as instances under changing tints make, are
|
|
13
|
+
* built by the backend's pass on the GPU. Both make the same bytes.
|
|
14
|
+
*/
|
|
15
|
+
const RAMPS_ON_GPU = 16;
|
|
16
|
+
|
|
17
|
+
/** Whether the machine keeps a word's low byte first, as a texel's red is in rampOf's swapped words. */
|
|
18
|
+
const LITTLE_ENDIAN = new Uint8Array(Uint32Array.of(1).buffer)[0] === 1;
|
|
19
|
+
|
|
7
20
|
/**
|
|
8
21
|
* The textures the programs read: the registry's, uploaded as they are
|
|
9
22
|
* added or change, and the samplers they are read through; the rows, a
|
|
@@ -24,6 +37,25 @@ export class GpuTextures {
|
|
|
24
37
|
private outlineEpoch = -1;
|
|
25
38
|
private outlineCount = 0;
|
|
26
39
|
private outlineRows = 0;
|
|
40
|
+
/**
|
|
41
|
+
* The lines' texture (Textures.addLine), which each line texture's id
|
|
42
|
+
* names in `textures`, the bytes of its lines as uploaded, and how many
|
|
43
|
+
* lines it has room for.
|
|
44
|
+
*/
|
|
45
|
+
lines: WebGLTexture | null = null;
|
|
46
|
+
private lineBytes = new Uint8Array(0);
|
|
47
|
+
/** lineBytes as words, which a ramp spanned on the CPU is written into (rampOf). */
|
|
48
|
+
private lineWords = new Uint32Array(0);
|
|
49
|
+
lineRoom = 0;
|
|
50
|
+
/**
|
|
51
|
+
* The records of the lines built from them (Textures.addRamp), a line's at
|
|
52
|
+
* its line's place; which lines are built so; and those to build in the
|
|
53
|
+
* backend's next pass (WebGLBackend's ramps), each once.
|
|
54
|
+
*/
|
|
55
|
+
rampRecords = new Uint8Array(0);
|
|
56
|
+
private built = new Uint8Array(0);
|
|
57
|
+
readonly builds: number[] = [];
|
|
58
|
+
private building = new Uint8Array(0);
|
|
27
59
|
|
|
28
60
|
constructor(gl: WebGL2RenderingContext, state: GlState) {
|
|
29
61
|
this.gl = gl;
|
|
@@ -37,6 +69,14 @@ export class GpuTextures {
|
|
|
37
69
|
this.outlineEpoch = -1;
|
|
38
70
|
this.outlineCount = 0;
|
|
39
71
|
this.outlineRows = 0;
|
|
72
|
+
this.lines = null;
|
|
73
|
+
this.lineBytes = new Uint8Array(0);
|
|
74
|
+
this.lineWords = new Uint32Array(0);
|
|
75
|
+
this.lineRoom = 0;
|
|
76
|
+
this.rampRecords = new Uint8Array(0);
|
|
77
|
+
this.built = new Uint8Array(0);
|
|
78
|
+
this.builds.length = 0;
|
|
79
|
+
this.building = new Uint8Array(0);
|
|
40
80
|
this.textures = [];
|
|
41
81
|
this.samplers = [];
|
|
42
82
|
this.rowsTexture = gl.createTexture() as WebGLTexture;
|
|
@@ -113,21 +153,70 @@ export class GpuTextures {
|
|
|
113
153
|
const gl = this.gl;
|
|
114
154
|
for (const id of textures.removed) {
|
|
115
155
|
const texture = this.textures[id];
|
|
116
|
-
|
|
156
|
+
// A line's is the lines' texture, which others' lines are in.
|
|
157
|
+
if (texture && texture !== this.lines) {
|
|
117
158
|
this.state.dropTexture(texture);
|
|
118
159
|
gl.deleteTexture(texture);
|
|
119
|
-
this.textures[id] = null;
|
|
120
160
|
}
|
|
161
|
+
|
|
162
|
+
this.textures[id] = null;
|
|
121
163
|
}
|
|
122
164
|
|
|
123
165
|
textures.removed.length = 0;
|
|
124
|
-
|
|
166
|
+
|
|
167
|
+
// The lines a frame added or set, from the first to the one past the last, uploaded in one
|
|
168
|
+
// call after the rest; all of them where the texture was made larger.
|
|
169
|
+
let linesFrom = Number.POSITIVE_INFINITY;
|
|
170
|
+
let linesTo = 0;
|
|
171
|
+
const grown = textures.lines > this.lineRoom;
|
|
172
|
+
if (grown) {
|
|
173
|
+
this.growLines(textures.lines);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const pending = textures.pending;
|
|
177
|
+
let ramps = 0;
|
|
178
|
+
for (let k = 0; k < pending.length; k++) {
|
|
179
|
+
ramps += textures.get(pending[k])?.ramp ? 1 : 0;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const onGpu = ramps >= RAMPS_ON_GPU || !LITTLE_ENDIAN;
|
|
183
|
+
for (let k = 0; k < pending.length; k++) {
|
|
184
|
+
const id = pending[k];
|
|
125
185
|
const data = textures.get(id);
|
|
126
186
|
const fill = data?.pixels ? null : (data?.fill ?? null);
|
|
127
187
|
if (!data || (!data.pixels && !data.source && fill === null)) {
|
|
128
188
|
continue;
|
|
129
189
|
}
|
|
130
190
|
|
|
191
|
+
if (data.line !== undefined && data.pixels instanceof Uint8Array && data.ramp) {
|
|
192
|
+
const line = data.line;
|
|
193
|
+
const record =
|
|
194
|
+
data.pixels.length === RAMP_BYTES ? data.pixels : data.pixels.subarray(0, RAMP_BYTES);
|
|
195
|
+
this.rampRecords.set(record, line * RAMP_BYTES);
|
|
196
|
+
this.built[line] = onGpu ? 1 : 0;
|
|
197
|
+
this.textures[id] = this.lines;
|
|
198
|
+
data.pixels = null;
|
|
199
|
+
if (onGpu) {
|
|
200
|
+
this.build(line);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
rampOf(record, this.lineWords, true, line * LINE_TEXELS);
|
|
205
|
+
linesFrom = Math.min(linesFrom, line);
|
|
206
|
+
linesTo = Math.max(linesTo, line + 1);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (data.line !== undefined && data.pixels instanceof Uint8Array) {
|
|
211
|
+
this.lineBytes.set(data.pixels.subarray(0, LINE_TEXELS * 4), data.line * LINE_TEXELS * 4);
|
|
212
|
+
this.built[data.line] = 0;
|
|
213
|
+
this.textures[id] = this.lines;
|
|
214
|
+
linesFrom = Math.min(linesFrom, data.line);
|
|
215
|
+
linesTo = Math.max(linesTo, data.line + 1);
|
|
216
|
+
data.pixels = null;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
|
|
131
220
|
let texture = this.textures[id];
|
|
132
221
|
if (!texture) {
|
|
133
222
|
texture = gl.createTexture() as WebGLTexture;
|
|
@@ -256,6 +345,93 @@ export class GpuTextures {
|
|
|
256
345
|
}
|
|
257
346
|
|
|
258
347
|
textures.pending.length = 0;
|
|
348
|
+
|
|
349
|
+
if (grown || linesTo > 0) {
|
|
350
|
+
const from = grown ? 0 : linesFrom;
|
|
351
|
+
const to = grown ? this.lineRoom : linesTo;
|
|
352
|
+
this.uploadLines(from, to);
|
|
353
|
+
// Lines built from records in between had their bytes overwritten with none: built again.
|
|
354
|
+
for (let line = from; line < to; line++) {
|
|
355
|
+
if (this.built[line]) {
|
|
356
|
+
this.build(line);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** Line `line` built from its record in the backend's next pass, once however often asked. */
|
|
363
|
+
private build(line: number): void {
|
|
364
|
+
if (!this.building[line]) {
|
|
365
|
+
this.building[line] = 1;
|
|
366
|
+
this.builds.push(line);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** The lines built (builds), done with. */
|
|
371
|
+
builtAll(): void {
|
|
372
|
+
const builds = this.builds;
|
|
373
|
+
for (let i = 0; i < builds.length; i++) {
|
|
374
|
+
this.building[builds[i]] = 0;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
this.builds.length = 0;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* The lines' texture made with room for `lines` at least, twice what it had
|
|
382
|
+
* or more, its lines kept: the same texture, which every line's id names.
|
|
383
|
+
*/
|
|
384
|
+
private growLines(lines: number): void {
|
|
385
|
+
const room = Math.max(32, lines, this.lineRoom * 2);
|
|
386
|
+
const bytes = new Uint8Array(room * LINE_TEXELS * 4);
|
|
387
|
+
bytes.set(this.lineBytes);
|
|
388
|
+
this.lineBytes = bytes;
|
|
389
|
+
this.lineWords = new Uint32Array(bytes.buffer);
|
|
390
|
+
const records = new Uint8Array(room * RAMP_BYTES);
|
|
391
|
+
records.set(this.rampRecords);
|
|
392
|
+
this.rampRecords = records;
|
|
393
|
+
const built = new Uint8Array(room);
|
|
394
|
+
built.set(this.built);
|
|
395
|
+
this.built = built;
|
|
396
|
+
const building = new Uint8Array(room);
|
|
397
|
+
building.set(this.building);
|
|
398
|
+
this.building = building;
|
|
399
|
+
this.lineRoom = room;
|
|
400
|
+
this.lines ??= this.gl.createTexture() as WebGLTexture;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** Lines `from` up to `to` of the lines' texture uploaded; all of them, made anew, from 0 to its room. */
|
|
404
|
+
private uploadLines(from: number, to: number): void {
|
|
405
|
+
const gl = this.gl;
|
|
406
|
+
this.state.bindTexture(TEXTURE_UNIT, this.lines);
|
|
407
|
+
this.state.activeTexture(TEXTURE_UNIT);
|
|
408
|
+
if (from === 0 && to === this.lineRoom) {
|
|
409
|
+
gl.texImage2D(
|
|
410
|
+
gl.TEXTURE_2D,
|
|
411
|
+
0,
|
|
412
|
+
gl.RGBA8,
|
|
413
|
+
LINE_TEXELS,
|
|
414
|
+
this.lineRoom,
|
|
415
|
+
0,
|
|
416
|
+
gl.RGBA,
|
|
417
|
+
gl.UNSIGNED_BYTE,
|
|
418
|
+
this.lineBytes,
|
|
419
|
+
);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
gl.texSubImage2D(
|
|
424
|
+
gl.TEXTURE_2D,
|
|
425
|
+
0,
|
|
426
|
+
0,
|
|
427
|
+
from,
|
|
428
|
+
LINE_TEXELS,
|
|
429
|
+
to - from,
|
|
430
|
+
gl.RGBA,
|
|
431
|
+
gl.UNSIGNED_BYTE,
|
|
432
|
+
this.lineBytes,
|
|
433
|
+
from * LINE_TEXELS * 4,
|
|
434
|
+
);
|
|
259
435
|
}
|
|
260
436
|
|
|
261
437
|
/** The sampler for `bits` (SMOOTH, and REPEAT or MIRROR), made as first asked for. */
|
|
@@ -314,11 +490,15 @@ export class GpuTextures {
|
|
|
314
490
|
}
|
|
315
491
|
|
|
316
492
|
for (const texture of this.textures) {
|
|
317
|
-
if (texture) {
|
|
493
|
+
if (texture && texture !== this.lines) {
|
|
318
494
|
gl.deleteTexture(texture);
|
|
319
495
|
}
|
|
320
496
|
}
|
|
321
497
|
|
|
498
|
+
if (this.lines) {
|
|
499
|
+
gl.deleteTexture(this.lines);
|
|
500
|
+
}
|
|
501
|
+
|
|
322
502
|
for (const sampler of this.samplers) {
|
|
323
503
|
if (sampler) {
|
|
324
504
|
gl.deleteSampler(sampler);
|
package/src/webgl/programs.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TARGET_TEXEL } from "../geometry.js";
|
|
2
|
-
import { ROWS_A_LINE } from "../rows.js";
|
|
2
|
+
import { RADIAL, RADIAL_LEAST_STEP, ROWS_A_LINE } from "../rows.js";
|
|
3
3
|
import {
|
|
4
4
|
ADD,
|
|
5
5
|
ALPHA,
|
|
@@ -109,11 +109,20 @@ if (FILL_TEXTURES >= STAGE_TEXEL) {
|
|
|
109
109
|
* `multi`, a merged fill's vertices carry as aDraw where its packed row is
|
|
110
110
|
* in uMergedRows, which the stream keeps for its copy, so that the row
|
|
111
111
|
* changes from frame to frame where the vertices need not; the atlas leaves
|
|
112
|
-
* that attribute disabled and negative.
|
|
113
|
-
*
|
|
114
|
-
*
|
|
112
|
+
* that attribute disabled and negative. A row's line (Rows.line) puts the
|
|
113
|
+
* texel on that line of its texture. With `radial`, a radial gradient's
|
|
114
|
+
* row (Rows.radial) passes on its focal point and its ramp's line in
|
|
115
|
+
* vRadial, the texel its square's place, which the fragment takes to the
|
|
116
|
+
* ramp (radialFillFragment). With `stage`, the stage fill program's
|
|
117
|
+
* (stageFillFragment), a texel of TARGET_TEXEL or below samples the
|
|
118
|
+
* stage's pixel under the fragment instead.
|
|
115
119
|
*/
|
|
116
|
-
export const fillVertex = (
|
|
120
|
+
export const fillVertex = (
|
|
121
|
+
multi: boolean,
|
|
122
|
+
merged = multi,
|
|
123
|
+
stage = false,
|
|
124
|
+
radial = false,
|
|
125
|
+
) => `#version 300 es
|
|
117
126
|
${multi ? "#extension GL_ANGLE_multi_draw : require" : ""}
|
|
118
127
|
precision highp float;
|
|
119
128
|
layout(location = ${POSITION_AT}) in vec2 aPosition;
|
|
@@ -129,6 +138,7 @@ out vec2 vTexel;
|
|
|
129
138
|
flat out vec4 vMul;
|
|
130
139
|
flat out vec4 vAdd;
|
|
131
140
|
flat out int vSlot;
|
|
141
|
+
${radial ? "flat out vec3 vRadial;" : ""}
|
|
132
142
|
|
|
133
143
|
void main(void) {
|
|
134
144
|
int draw = ${merged ? `aDraw >= 0 ? texelFetch(uMergedRows, ivec2(aDraw & ${MERGED_LINE - 1}, aDraw >> ${Math.log2(MERGED_LINE)}), 0).r : ` : ""}${multi ? `texelFetch(uRunTable, ivec2((uRunBase + gl_DrawID) & ${RUN_MOST - 1}, (uRunBase + gl_DrawID) >> ${Math.log2(RUN_MOST)}), 0).r` : "uRow"};
|
|
@@ -146,13 +156,26 @@ void main(void) {
|
|
|
146
156
|
|
|
147
157
|
gl_Position = vec4(p * uView.xy + uView.zw, 0.0, 1.0);
|
|
148
158
|
vColor = aColor;
|
|
159
|
+
// A ramp kept as a line of a texture of many (Rows.line) is read on that line's centre, a
|
|
160
|
+
// texture of its own on its middle${radial ? "; a radial gradient's, at the place the fragment finds" : ""}.
|
|
161
|
+
${
|
|
162
|
+
radial
|
|
163
|
+
? ` // Its x the least the place is read at, the middle of the row's least entry: above 0, which
|
|
164
|
+
// tells the fragment to take its place to the ramp.
|
|
165
|
+
bool radial = t.w > 0.0;
|
|
166
|
+
float least = floor((t.w - ${(RADIAL - 1).toFixed(1)}) / ${RADIAL_LEAST_STEP.toFixed(1)});
|
|
167
|
+
float focal = t.w - ${RADIAL.toFixed(1)} - least * ${RADIAL_LEAST_STEP.toFixed(1)};
|
|
168
|
+
vRadial = radial ? vec3(least + 0.5, focal, t.z > 0.0 ? t.z : 0.5) : vec3(0.0);
|
|
169
|
+
vec2 texel = !radial && t.z > 0.0 ? vec2(aTexel.x, t.z) : aTexel;`
|
|
170
|
+
: " vec2 texel = t.z > 0.0 ? vec2(aTexel.x, t.z) : aTexel;"
|
|
171
|
+
}
|
|
149
172
|
${
|
|
150
173
|
stage
|
|
151
174
|
? ` // The fragment finds the stage's pixel from its place (STAGE_TEXEL in vSlot).
|
|
152
175
|
bool onStage = aTexel.x <= ${TARGET_TEXEL / 2};
|
|
153
|
-
vTexel = onStage ? p :
|
|
176
|
+
vTexel = onStage ? p : texel;
|
|
154
177
|
vSlot |= onStage ? ${STAGE_TEXEL} : 0;`
|
|
155
|
-
: " vTexel =
|
|
178
|
+
: " vTexel = texel;"
|
|
156
179
|
}
|
|
157
180
|
}
|
|
158
181
|
`;
|
|
@@ -172,20 +195,68 @@ const slotTexel = Array.from(
|
|
|
172
195
|
break;`,
|
|
173
196
|
).join("\n");
|
|
174
197
|
|
|
198
|
+
/** Texels a gradient's ramp has across, its line's (Textures.addLine) or a texture's of its own. */
|
|
199
|
+
const RAMP_TEXELS = 256;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Where p, in the gradient square's place (a unit its radius), lies out
|
|
203
|
+
* from the focal point (f, 0) to the circle along the ray through it, as
|
|
204
|
+
* display/gradients.ts's radialPlace finds it: 0 at the focus, 1 on the
|
|
205
|
+
* circle; on a focus off the centre 1, the last stop, and on the centre of
|
|
206
|
+
* one centred 0, which the row's least entry raises (Rows.radial: 8 for a
|
|
207
|
+
* padded one). 1 / s where the ray f + s d meets the circle, in whichever
|
|
208
|
+
* of its two forms subtracts nothing, as a float's few digits would lose a
|
|
209
|
+
* focus near the circle's. A point so far out that its square overflows,
|
|
210
|
+
* as a matrix all but collapsed puts one, is as far out as it is across.
|
|
211
|
+
*/
|
|
212
|
+
export const radialPlace = `float radialPlace(vec2 p, float f) {
|
|
213
|
+
vec2 d = vec2(p.x - f, p.y);
|
|
214
|
+
float across = max(abs(d.x), abs(d.y));
|
|
215
|
+
if (across > 1e18) {
|
|
216
|
+
return across;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
float dd = dot(d, d);
|
|
220
|
+
if (dd < 1e-12) {
|
|
221
|
+
return f != 0.0 ? 1.0 : 0.0;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
float fd = f * d.x;
|
|
225
|
+
float k = 1.0 - f * f;
|
|
226
|
+
float root = sqrt(max(fd * fd + dd * k, 0.0));
|
|
227
|
+
if (fd <= 0.0) {
|
|
228
|
+
float den = root - fd;
|
|
229
|
+
return den > 0.0 ? dd / den : 1.0;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return k > 0.0 ? (root + fd) / k : 1.0;
|
|
233
|
+
}`;
|
|
234
|
+
|
|
235
|
+
/** A radial gradient's texel moved to its ramp's entry at the fragment's place (radialPlace). */
|
|
236
|
+
const radialAt = ` if (vRadial.x > 0.0) {
|
|
237
|
+
// Rounded to the nearest entry, as Flash reads a radial's ramp (radialIndex).
|
|
238
|
+
float entry = radialPlace(vTexel, vRadial.y) * ${RAMP_TEXELS.toFixed(1)} + 0.5;
|
|
239
|
+
at = vec2(max(entry, vRadial.x), vRadial.z);
|
|
240
|
+
}
|
|
241
|
+
`;
|
|
242
|
+
|
|
175
243
|
/**
|
|
176
244
|
* Flash's colour transform on the straight colour, clamped, then
|
|
177
245
|
* premultiplied for blending: the vertex' colour, or with a texture the
|
|
178
246
|
* texel's (premultiplied in the texture) times it, as the colour batcher
|
|
179
|
-
* did, a clear texel staying clear. With `
|
|
180
|
-
* (
|
|
247
|
+
* did, a clear texel staying clear. With `radial`, a radial gradient's
|
|
248
|
+
* texel is its ramp's at the fragment's place (radialPlace), each pixel's
|
|
249
|
+
* own as Flash finds it (radialFillFragment). With `stage`, the stage fill
|
|
250
|
+
* program's (stageFillFragment).
|
|
181
251
|
*/
|
|
182
|
-
const fillFragmentOf = (stage: boolean) => `#version 300 es
|
|
252
|
+
const fillFragmentOf = (stage: boolean, radial: boolean) => `#version 300 es
|
|
183
253
|
precision highp float;
|
|
184
254
|
in vec4 vColor;
|
|
185
255
|
in vec2 vTexel;
|
|
186
256
|
flat in vec4 vMul;
|
|
187
257
|
flat in vec4 vAdd;
|
|
188
258
|
flat in int vSlot;
|
|
259
|
+
${radial ? "flat in vec3 vRadial;" : ""}
|
|
189
260
|
uniform sampler2D uTextures[${FILL_TEXTURES}];
|
|
190
261
|
${stage ? "uniform vec4 uStage;\n" : ""}out vec4 finalColor;
|
|
191
262
|
|
|
@@ -211,10 +282,14 @@ ${slotTexel}
|
|
|
211
282
|
return t;
|
|
212
283
|
}
|
|
213
284
|
|
|
285
|
+
${radial ? radialPlace : ""}
|
|
286
|
+
|
|
214
287
|
void main(void) {
|
|
215
288
|
vec4 straight = vColor;
|
|
216
289
|
if (${stage ? `(vSlot & ${STAGE_TEXEL - 1})` : "vSlot"} != 0) {
|
|
217
|
-
|
|
290
|
+
vec2 at = vTexel;
|
|
291
|
+
${radial ? radialAt : ""}
|
|
292
|
+
vec4 t = texel(at);
|
|
218
293
|
if (t.a == 0.0) {
|
|
219
294
|
finalColor = vec4(0.0);
|
|
220
295
|
return;
|
|
@@ -228,8 +303,21 @@ void main(void) {
|
|
|
228
303
|
}
|
|
229
304
|
`;
|
|
230
305
|
|
|
231
|
-
/**
|
|
232
|
-
|
|
306
|
+
/**
|
|
307
|
+
* The fill program's fragment shader, which every fill draws with but a
|
|
308
|
+
* radial gradient's (radialFillFragment) and those of stageFillFragment.
|
|
309
|
+
* A program of its own: in it, the radial gradient's path, though no fill
|
|
310
|
+
* took it, made a frame of plain fills take Intel's GPUs some tenth as long
|
|
311
|
+
* again (bench.ts --shapes 2000, Iris Xe).
|
|
312
|
+
*/
|
|
313
|
+
export const fillFragment = fillFragmentOf(false, false);
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* The radial fill program's, for runs of fills one of which is a radial
|
|
317
|
+
* gradient's (RADIAL_FILL): every fill as fillFragment draws it, and a radial
|
|
318
|
+
* gradient's texel at the fragment's place.
|
|
319
|
+
*/
|
|
320
|
+
export const radialFillFragment = fillFragmentOf(false, true);
|
|
233
321
|
|
|
234
322
|
/**
|
|
235
323
|
* The stage fill program's, for a fill some of whose texels are the
|
|
@@ -240,7 +328,7 @@ export const fillFragment = fillFragmentOf(false);
|
|
|
240
328
|
* its own: in the fill program, that path, though no fill took it, made a
|
|
241
329
|
* frame of plain fills take Intel's GPUs over half as long again.
|
|
242
330
|
*/
|
|
243
|
-
export const stageFillFragment = fillFragmentOf(true);
|
|
331
|
+
export const stageFillFragment = fillFragmentOf(true, true);
|
|
244
332
|
|
|
245
333
|
/**
|
|
246
334
|
* drawTriangles' textured triangles (MESH), placed as fills are, their u
|
|
@@ -735,16 +823,18 @@ ${BLEND_FRONT}}
|
|
|
735
823
|
/**
|
|
736
824
|
* A fill drawn straight onto what is below it in a blend mode, where its
|
|
737
825
|
* layer would hold it alone (a flat fill, GeometryData.flat): its pixel as
|
|
738
|
-
* fillFragment has it, then as
|
|
739
|
-
*
|
|
826
|
+
* fillFragment, or with `radial` radialFillFragment, has it, then as
|
|
827
|
+
* compositeFragment composites its layer's, coloured by the layer's row
|
|
828
|
+
* (uLayerRow, -1 for none) and blended by uMode.
|
|
740
829
|
*/
|
|
741
|
-
|
|
830
|
+
const blendFillFragmentOf = (radial: boolean) => `#version 300 es
|
|
742
831
|
precision highp float;
|
|
743
832
|
in vec4 vColor;
|
|
744
833
|
in vec2 vTexel;
|
|
745
834
|
flat in vec4 vMul;
|
|
746
835
|
flat in vec4 vAdd;
|
|
747
836
|
flat in int vSlot;
|
|
837
|
+
${radial ? "flat in vec3 vRadial;" : ""}
|
|
748
838
|
uniform sampler2D uTextures[${FILL_TEXTURES}];
|
|
749
839
|
uniform sampler2D uBack;
|
|
750
840
|
uniform highp sampler2D uRows;
|
|
@@ -763,12 +853,16 @@ ${slotTexel}
|
|
|
763
853
|
return t;
|
|
764
854
|
}
|
|
765
855
|
|
|
856
|
+
${radial ? radialPlace : ""}
|
|
857
|
+
|
|
766
858
|
void main(void) {
|
|
767
859
|
vec4 front = vec4(0.0);
|
|
768
860
|
vec4 fill = vColor;
|
|
769
861
|
bool clear = false;
|
|
770
862
|
if (vSlot != 0) {
|
|
771
|
-
|
|
863
|
+
vec2 at = vTexel;
|
|
864
|
+
${radial ? radialAt : ""}
|
|
865
|
+
vec4 t = texel(at);
|
|
772
866
|
clear = t.a == 0.0;
|
|
773
867
|
fill = clear ? fill : vec4(t.rgb / t.a * vColor.rgb, t.a * vColor.a);
|
|
774
868
|
}
|
|
@@ -781,3 +875,15 @@ void main(void) {
|
|
|
781
875
|
${layerColor("uLayerRow")}
|
|
782
876
|
${BLEND_FRONT}}
|
|
783
877
|
`;
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* The blend program's fragment shader, for every fill drawn straight in a
|
|
881
|
+
* blend mode but a radial gradient's (radialBlendFillFragment). A program of
|
|
882
|
+
* its own, as fillFragment is: the radial path in it, though no fill took
|
|
883
|
+
* it, made SwiftShader's frames of 500 shapes in blend modes 3 % longer
|
|
884
|
+
* (bench.ts --blends 500).
|
|
885
|
+
*/
|
|
886
|
+
export const blendFillFragment = blendFillFragmentOf(false);
|
|
887
|
+
|
|
888
|
+
/** The radial blend program's, for a radial gradient's fill drawn straight in a blend mode. */
|
|
889
|
+
export const radialBlendFillFragment = blendFillFragmentOf(true);
|