@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.
Files changed (43) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/rows.d.ts +28 -1
  6. package/dist/rows.d.ts.map +1 -1
  7. package/dist/rows.js +32 -1
  8. package/dist/rows.js.map +1 -1
  9. package/dist/scene.d.ts +6 -0
  10. package/dist/scene.d.ts.map +1 -1
  11. package/dist/scene.js +6 -0
  12. package/dist/scene.js.map +1 -1
  13. package/dist/spans.js +2 -2
  14. package/dist/spans.js.map +1 -1
  15. package/dist/textures.d.ts +33 -0
  16. package/dist/textures.d.ts.map +1 -1
  17. package/dist/textures.js +67 -14
  18. package/dist/textures.js.map +1 -1
  19. package/dist/webgl/backend.d.ts.map +1 -1
  20. package/dist/webgl/backend.js +1 -2
  21. package/dist/webgl/backend.js.map +1 -1
  22. package/dist/webgl/draws.d.ts +50 -29
  23. package/dist/webgl/draws.d.ts.map +1 -1
  24. package/dist/webgl/draws.js +185 -85
  25. package/dist/webgl/draws.js.map +1 -1
  26. package/dist/webgl/gpu-textures.d.ts +16 -1
  27. package/dist/webgl/gpu-textures.d.ts.map +1 -1
  28. package/dist/webgl/gpu-textures.js +61 -3
  29. package/dist/webgl/gpu-textures.js.map +1 -1
  30. package/dist/webgl/programs.d.ts +40 -9
  31. package/dist/webgl/programs.d.ts.map +1 -1
  32. package/dist/webgl/programs.js +111 -18
  33. package/dist/webgl/programs.js.map +1 -1
  34. package/package.json +2 -2
  35. package/src/index.ts +1 -0
  36. package/src/rows.ts +34 -1
  37. package/src/scene.ts +6 -0
  38. package/src/spans.ts +2 -2
  39. package/src/textures.ts +85 -14
  40. package/src/webgl/backend.ts +1 -2
  41. package/src/webgl/draws.ts +252 -91
  42. package/src/webgl/gpu-textures.ts +91 -4
  43. package/src/webgl/programs.ts +124 -18
@@ -1,4 +1,10 @@
1
- import { beginProgram, endProgram, type GlState, linkProgram } from "@swf2es/context3d/device";
1
+ import {
2
+ beginProgram,
3
+ endProgram,
4
+ type GlState,
5
+ linkProgram,
6
+ type PendingProgram,
7
+ } from "@swf2es/context3d/device";
2
8
  import { type Commands, RUN, STENCIL_POP, STENCIL_PUSH } from "../commands.js";
3
9
  import { FILL_SHADER, type Filters } from "../filters.js";
4
10
  import { fillKernel, kernelImagesFit } from "../kernel-shaders.js";
@@ -9,6 +15,7 @@ import {
9
15
  MIRROR,
10
16
  NORMAL,
11
17
  PLANE,
18
+ RADIAL_FILL,
12
19
  REPEAT,
13
20
  type SceneList,
14
21
  SHADED,
@@ -38,6 +45,8 @@ import {
38
45
  OUTLINE_UNIT,
39
46
  RUN_MOST,
40
47
  RUN_UNIT,
48
+ radialBlendFillFragment,
49
+ radialFillFragment,
41
50
  SNAP_BIT,
42
51
  stageFillFragment,
43
52
  TABLE_UNIT,
@@ -45,6 +54,40 @@ import {
45
54
  } from "./programs.js";
46
55
  import { framebufferOf, type Open, type Target, type TargetPool } from "./targets.js";
47
56
 
57
+ /**
58
+ * A bit of a run's units (runUnits) above theirs: one of its fills is a
59
+ * radial gradient's (RADIAL_FILL), which the radial fill program draws.
60
+ */
61
+ const RADIAL_RUN = 1 << 30;
62
+
63
+ /**
64
+ * A fill program, plain or radial (fillFragment, radialFillFragment): where
65
+ * it takes its row, view, Flash's pixels a stage pixel and its run's start
66
+ * in the run table; the row and start it was told last, -1 for none; and
67
+ * the count of views (Draws.views) it was told the view of.
68
+ */
69
+ interface FillProgram {
70
+ program: WebGLProgram;
71
+ row: WebGLUniformLocation | null;
72
+ view: WebGLUniformLocation | null;
73
+ unit: WebGLUniformLocation | null;
74
+ runBase: WebGLUniformLocation | null;
75
+ lastRow: number;
76
+ base: number;
77
+ viewed: number;
78
+ }
79
+
80
+ /** A blend program (drawBlended) and where it takes its uniforms. */
81
+ interface BlendProgram {
82
+ program: WebGLProgram;
83
+ row: WebGLUniformLocation | null;
84
+ view: WebGLUniformLocation | null;
85
+ unit: WebGLUniformLocation | null;
86
+ mode: WebGLUniformLocation | null;
87
+ layerRow: WebGLUniformLocation | null;
88
+ back: WebGLUniformLocation | null;
89
+ }
90
+
48
91
  /** What the backend calls of WEBGL_multi_draw. */
49
92
  interface MultiDraw {
50
93
  multiDrawElementsWEBGL(
@@ -98,11 +141,17 @@ export class Draws {
98
141
  private readonly batches: FillBatches;
99
142
  private readonly gpu: GpuTextures;
100
143
  private readonly pool: TargetPool;
101
- /** The fill program, and where it takes its row, view and Flash's pixels a stage pixel. */
102
- program!: WebGLProgram;
103
- private rowLocation: WebGLUniformLocation | null = null;
104
- private viewLocation: WebGLUniformLocation | null = null;
105
- private fillUnitLocation: WebGLUniformLocation | null = null;
144
+ /**
145
+ * The fill program; the radial one, linked as a run of a radial
146
+ * gradient's fill first needs it, from radialPending, begun with the rest;
147
+ * and the one in use.
148
+ */
149
+ private plain!: FillProgram;
150
+ private radial: FillProgram | null = null;
151
+ private radialPending: PendingProgram | null = null;
152
+ private fill!: FillProgram;
153
+ /** Views given (drawInto), which a fill program is told as it is next used. */
154
+ private views = 0;
106
155
  /**
107
156
  * The stage fill program (stageFillFragment), for fills that sample the
108
157
  * stage's pixel (Place.stage), each drawn alone: linked as one is first
@@ -115,18 +164,15 @@ export class Draws {
115
164
  private stageUnitLocation: WebGLUniformLocation | null = null;
116
165
  private stageLocation: WebGLUniformLocation | null = null;
117
166
  /**
118
- * The fill program that blends a fill straight onto what is below it
119
- * (drawBlended), a draw a call, and where it takes what the fill program
120
- * does and the blend's mode, its layer's row and where the copy of what
121
- * is below lies.
167
+ * The fill programs that blend a fill straight onto what is below it
168
+ * (drawBlended), a draw a call, taking what the fill program does and the
169
+ * blend's mode, its layer's row and where the copy of what is below lies:
170
+ * the plain one, and the radial one for a radial gradient's fill, linked
171
+ * as one is first drawn from radialBlendPending, begun with the rest.
122
172
  */
123
- private blendProgram!: WebGLProgram;
124
- private blendRowLocation: WebGLUniformLocation | null = null;
125
- private blendViewLocation: WebGLUniformLocation | null = null;
126
- private blendUnitLocation: WebGLUniformLocation | null = null;
127
- private blendModeLocation: WebGLUniformLocation | null = null;
128
- private blendLayerRowLocation: WebGLUniformLocation | null = null;
129
- private blendBackLocation: WebGLUniformLocation | null = null;
173
+ private blend!: BlendProgram;
174
+ private radialBlend: BlendProgram | null = null;
175
+ private radialBlendPending: PendingProgram | null = null;
130
176
  /** WEBGL_multi_draw, which draws a run of fills alike a call (drawEntries), where there is. */
131
177
  private multi: MultiDraw | null = null;
132
178
  /**
@@ -136,9 +182,6 @@ export class Draws {
136
182
  merging = true;
137
183
  /** Avoid the dynamically indexed uniform table used in the Intel GPU hang reproducer. */
138
184
  private runTable: WebGLTexture | null = null;
139
- private runBaseLocation: WebGLUniformLocation | null = null;
140
- /** The table start the fill program was told last (uRunBase), -1 for none. */
141
- private runBase = -1;
142
185
  private runTableHeight = 0;
143
186
  private runTableMost = 0;
144
187
  private tableRows = new Int32Array(RUN_MOST);
@@ -198,11 +241,6 @@ export class Draws {
198
241
  private glyphTable = -1;
199
242
  /** Flash's pixels a stage pixel: the target's pixels a stage pixel over those a pixel of Flash's. */
200
243
  private unit = 1;
201
- /**
202
- * The row a fill drawn alone (without WEBGL_multi_draw) last told the fill
203
- * program, so that it is not told again; -1 for none (forgetRow).
204
- */
205
- private lastRow = -1;
206
244
 
207
245
  /** Each shader fill's fragment shader by its entry in the frame's filters, for the generation it is of. */
208
246
  private readonly fillShaders = new Map<number, string | null>();
@@ -239,11 +277,12 @@ export class Draws {
239
277
  // All begun before any is asked after, so that a driver that compiles on threads of its own
240
278
  // (KHR_parallel_shader_compile) compiles them at once.
241
279
  const fill = beginProgram(gl, fillVertex(this.multi !== null, true), fillFragment);
242
- const blend = beginProgram(gl, fillVertex(false), blendFillFragment);
280
+ const blend = beginProgram(gl, fillVertex(false, false), blendFillFragment);
243
281
  const mesh = beginProgram(gl, meshVertex, meshFragment);
244
282
  const glyphs = beginProgram(gl, glyphsVertex, glyphsFragment);
283
+ let program: WebGLProgram;
245
284
  try {
246
- this.program = endProgram(gl, fill);
285
+ program = endProgram(gl, fill);
247
286
  } catch (e) {
248
287
  // Not where the context is flagged lost, whose every link fails.
249
288
  if (!this.multi || gl.isContextLost()) {
@@ -252,48 +291,38 @@ export class Draws {
252
291
 
253
292
  // An extension offered whose shader directive the compiler refuses: runs merged alone.
254
293
  this.multi = null;
255
- this.program = linkProgram(gl, fillVertex(false, true), fillFragment);
294
+ program = linkProgram(gl, fillVertex(false, true), fillFragment);
256
295
  }
257
296
 
297
+ // Begun once the extension is known to compile, compiled while the rest are linked.
298
+ this.radialPending = beginProgram(
299
+ gl,
300
+ fillVertex(this.multi !== null, true, false, true),
301
+ radialFillFragment,
302
+ );
303
+ this.radial = null;
304
+ this.radialBlendPending = beginProgram(
305
+ gl,
306
+ fillVertex(false, false, false, true),
307
+ radialBlendFillFragment,
308
+ );
309
+ this.radialBlend = null;
310
+ this.views = 0;
258
311
  this.unitIds.fill(-1);
259
- this.rowLocation = gl.getUniformLocation(this.program, "uRow");
260
- this.viewLocation = gl.getUniformLocation(this.program, "uView");
261
312
  // The context's own, gone with it, or not made yet.
262
313
  this.stageProgram = null;
263
- this.state.useProgram(this.program);
264
- gl.uniform1i(gl.getUniformLocation(this.program, "uRows"), 0);
265
- gl.uniform1iv(
266
- gl.getUniformLocation(this.program, "uTextures"),
267
- Array.from({ length: FILL_TEXTURES }, (_, k) => FILL_UNIT + k),
268
- );
269
314
  this.runTable = null;
270
315
  this.runTableHeight = 0;
271
316
  this.runTableMost = textureMost;
272
317
  this.prepared = false;
273
- this.runBaseLocation = gl.getUniformLocation(this.program, "uRunBase");
274
- this.runBase = -1;
275
318
  this.batches.setUp(textureMost);
276
- gl.uniform1i(gl.getUniformLocation(this.program, "uMergedRows"), MERGED_UNIT);
277
319
  if (this.multi) {
278
320
  this.sizeRunTable(1);
279
- gl.uniform1i(gl.getUniformLocation(this.program, "uRunTable"), RUN_UNIT);
280
321
  }
281
322
 
282
- this.fillUnitLocation = gl.getUniformLocation(this.program, "uUnit");
283
- this.blendProgram = endProgram(gl, blend);
284
- this.blendRowLocation = gl.getUniformLocation(this.blendProgram, "uRow");
285
- this.blendViewLocation = gl.getUniformLocation(this.blendProgram, "uView");
286
- this.blendUnitLocation = gl.getUniformLocation(this.blendProgram, "uUnit");
287
- this.blendModeLocation = gl.getUniformLocation(this.blendProgram, "uMode");
288
- this.blendLayerRowLocation = gl.getUniformLocation(this.blendProgram, "uLayerRow");
289
- this.blendBackLocation = gl.getUniformLocation(this.blendProgram, "uBackOffset");
290
- this.state.useProgram(this.blendProgram);
291
- gl.uniform1i(gl.getUniformLocation(this.blendProgram, "uRows"), 0);
292
- gl.uniform1i(gl.getUniformLocation(this.blendProgram, "uBack"), BACK_UNIT);
293
- gl.uniform1iv(
294
- gl.getUniformLocation(this.blendProgram, "uTextures"),
295
- Array.from({ length: FILL_TEXTURES }, (_, k) => FILL_UNIT + k),
296
- );
323
+ this.plain = this.fillProgram(program);
324
+ this.fill = this.plain;
325
+ this.blend = this.blendProgram(endProgram(gl, blend));
297
326
  this.mesh = endProgram(gl, mesh);
298
327
  this.meshRowLocation = gl.getUniformLocation(this.mesh, "uRow");
299
328
  this.meshViewLocation = gl.getUniformLocation(this.mesh, "uView");
@@ -317,7 +346,74 @@ export class Draws {
317
346
  this.glyphStale = true;
318
347
  this.glyphRow = -1;
319
348
  this.glyphTable = -1;
320
- this.lastRow = -1;
349
+ }
350
+
351
+ /**
352
+ * Blend program `program` linked, made the current program: its samplers
353
+ * told their units, its uniforms found. The radial one is so made as it is
354
+ * first drawn with, which changes the current program in the middle of
355
+ * drawBlended, before drawBlended makes it current itself.
356
+ */
357
+ private blendProgram(program: WebGLProgram): BlendProgram {
358
+ const gl = this.gl;
359
+ this.state.useProgram(program);
360
+ gl.uniform1i(gl.getUniformLocation(program, "uRows"), 0);
361
+ gl.uniform1i(gl.getUniformLocation(program, "uBack"), BACK_UNIT);
362
+ gl.uniform1iv(
363
+ gl.getUniformLocation(program, "uTextures"),
364
+ Array.from({ length: FILL_TEXTURES }, (_, k) => FILL_UNIT + k),
365
+ );
366
+ return {
367
+ program,
368
+ row: gl.getUniformLocation(program, "uRow"),
369
+ view: gl.getUniformLocation(program, "uView"),
370
+ unit: gl.getUniformLocation(program, "uUnit"),
371
+ mode: gl.getUniformLocation(program, "uMode"),
372
+ layerRow: gl.getUniformLocation(program, "uLayerRow"),
373
+ back: gl.getUniformLocation(program, "uBackOffset"),
374
+ };
375
+ }
376
+
377
+ /**
378
+ * The radial blend program, linked as first drawn with: from
379
+ * radialBlendPending, or begun again where its link failed, as radialFill.
380
+ */
381
+ private radialBlendProgram(): BlendProgram {
382
+ if (!this.radialBlend) {
383
+ const pending =
384
+ this.radialBlendPending ??
385
+ beginProgram(this.gl, fillVertex(false, false, false, true), radialBlendFillFragment);
386
+ this.radialBlendPending = null;
387
+ this.radialBlend = this.blendProgram(endProgram(this.gl, pending));
388
+ }
389
+
390
+ return this.radialBlend;
391
+ }
392
+
393
+ /** Fill program `program` linked, in use: its samplers told their units, its uniforms found. */
394
+ private fillProgram(program: WebGLProgram): FillProgram {
395
+ const gl = this.gl;
396
+ this.state.useProgram(program);
397
+ gl.uniform1i(gl.getUniformLocation(program, "uRows"), 0);
398
+ gl.uniform1iv(
399
+ gl.getUniformLocation(program, "uTextures"),
400
+ Array.from({ length: FILL_TEXTURES }, (_, k) => FILL_UNIT + k),
401
+ );
402
+ gl.uniform1i(gl.getUniformLocation(program, "uMergedRows"), MERGED_UNIT);
403
+ if (this.multi) {
404
+ gl.uniform1i(gl.getUniformLocation(program, "uRunTable"), RUN_UNIT);
405
+ }
406
+
407
+ return {
408
+ program,
409
+ row: gl.getUniformLocation(program, "uRow"),
410
+ view: gl.getUniformLocation(program, "uView"),
411
+ unit: gl.getUniformLocation(program, "uUnit"),
412
+ runBase: gl.getUniformLocation(program, "uRunBase"),
413
+ lastRow: -1,
414
+ base: -1,
415
+ viewed: -1,
416
+ };
321
417
  }
322
418
 
323
419
  /**
@@ -482,20 +578,17 @@ export class Draws {
482
578
  * down in a layer. The fill program takes the view.
483
579
  */
484
580
  drawInto(open: Open, target: Target): void {
485
- const gl = this.gl;
486
581
  const state = this.state;
487
582
  const ox = open.ox ?? 0;
488
583
  const oy = open.oy ?? 0;
489
584
  state.bindFramebuffer(framebufferOf(open));
490
585
  state.viewport(ox, oy, open.width, open.height);
491
- state.useProgram(this.program);
492
586
  const down = open.layer ? 1 : -1;
493
587
  const view = this.view;
494
588
  view[0] = (2 * target.scale) / open.width;
495
589
  view[1] = (down * 2 * target.scale) / open.height;
496
590
  view[2] = -1 + (2 * (target.x - open.x)) / open.width;
497
591
  view[3] = -down * (1 - (2 * (target.y - open.y)) / open.height);
498
- gl.uniform4fv(this.viewLocation, view);
499
592
  // A layer's rows run down from its corner; the canvas' up from its bottom.
500
593
  const frag = this.frag;
501
594
  frag[0] = open.x - target.x - ox;
@@ -508,21 +601,59 @@ export class Draws {
508
601
  stage[2] = down;
509
602
  stage[3] = 1 / target.scale;
510
603
  this.unit = target.scale / target.pixel;
511
- gl.uniform1f(this.fillUnitLocation, this.unit);
604
+ this.views++;
605
+ this.useFill();
512
606
  this.stageStale = true;
513
607
  this.meshStale = true;
514
608
  this.glyphStale = true;
515
609
  }
516
610
 
517
- /** The row the fill program was told forgotten, so that the next fill tells it again. */
611
+ /** The row the fill programs were told forgotten, so that the next fill tells it again. */
518
612
  forgetRow(): void {
519
- this.lastRow = -1;
613
+ this.plain.lastRow = -1;
614
+ if (this.radial) {
615
+ this.radial.lastRow = -1;
616
+ }
520
617
  }
521
618
 
522
- /** The fill program and rows bound; each run selects its vertex array. */
523
- useFill(): void {
524
- this.state.useProgram(this.program);
619
+ /**
620
+ * The fill program, or with `radial` the radial one, by default the one
621
+ * last used, so that a run of one kind after another switches programs
622
+ * once, and rows bound, the program told the view where it has not been;
623
+ * each run selects its vertex array.
624
+ */
625
+ useFill(radial = this.fill === this.radial): void {
626
+ const fill = radial ? this.radialFill() : this.plain;
627
+ const gl = this.gl;
628
+ this.fill = fill;
629
+ this.state.useProgram(fill.program);
525
630
  this.state.bindTexture(0, this.gpu.rowsTexture);
631
+ if (fill.viewed !== this.views) {
632
+ fill.viewed = this.views;
633
+ gl.uniform4fv(fill.view, this.view);
634
+ gl.uniform1f(fill.unit, this.unit);
635
+ }
636
+ }
637
+
638
+ /**
639
+ * The radial fill program, linked as first asked for: from radialPending,
640
+ * or begun again where its link failed and the frame was conceded without
641
+ * a setUp (LinkLosses), as endProgram deletes a program it cannot link.
642
+ */
643
+ private radialFill(): FillProgram {
644
+ if (!this.radial) {
645
+ const pending =
646
+ this.radialPending ??
647
+ beginProgram(
648
+ this.gl,
649
+ fillVertex(this.multi !== null, true, false, true),
650
+ radialFillFragment,
651
+ );
652
+ this.radialPending = null;
653
+ this.radial = this.fillProgram(endProgram(this.gl, pending));
654
+ }
655
+
656
+ return this.radial;
526
657
  }
527
658
 
528
659
  /** Entries `first` up to `end` drawn as fills, where the masks pushed pass. */
@@ -578,17 +709,15 @@ export class Draws {
578
709
  ): void {
579
710
  const gl = this.gl;
580
711
  const state = this.state;
581
- state.useProgram(this.blendProgram);
712
+ const blend = scene.sampler[i] & RADIAL_FILL ? this.radialBlendProgram() : this.blend;
713
+ state.useProgram(blend.program);
582
714
  state.bindTexture(0, this.gpu.rowsTexture);
583
- gl.uniform4fv(this.blendViewLocation, this.view);
584
- gl.uniform1f(this.blendUnitLocation, this.unit);
715
+ gl.uniform4fv(blend.view, this.view);
716
+ gl.uniform1f(blend.unit, this.unit);
585
717
  // Its pixel alone where GL's blending computes the mode (readsBelow).
586
- gl.uniform1i(
587
- this.blendModeLocation,
588
- (reads ? mode : NORMAL) + (fresh ? FRESH : 0) + below * BELOW_STEP,
589
- );
590
- gl.uniform1i(this.blendLayerRowLocation, layerRow);
591
- gl.uniform2i(this.blendBackLocation, backX, backY);
718
+ gl.uniform1i(blend.mode, (reads ? mode : NORMAL) + (fresh ? FRESH : 0) + below * BELOW_STEP);
719
+ gl.uniform1i(blend.layerRow, layerRow);
720
+ gl.uniform2i(blend.back, backX, backY);
592
721
  this.gatherRun(scene, i, i + 1, false);
593
722
  if (this.runCount === 0) {
594
723
  return;
@@ -602,7 +731,7 @@ export class Draws {
602
731
  }
603
732
  }
604
733
 
605
- gl.uniform1i(this.blendRowLocation, this.runRows[0]);
734
+ gl.uniform1i(blend.row, this.runRows[0]);
606
735
  setModeBlend(gl, state, reads ? -1 : mode);
607
736
  gl.drawElements(gl.TRIANGLES, this.runCounts[0], gl.UNSIGNED_INT, this.runOffsets[0]);
608
737
  }
@@ -693,11 +822,6 @@ export class Draws {
693
822
  continue;
694
823
  }
695
824
 
696
- if (other) {
697
- this.useFill();
698
- other = false;
699
- }
700
-
701
825
  let base = 0;
702
826
  let draws: number;
703
827
  let units: number;
@@ -722,6 +846,13 @@ export class Draws {
722
846
  continue;
723
847
  }
724
848
 
849
+ // A mask's coverage by either.
850
+ const radial = stencil ? this.fill === this.radial : (units & RADIAL_RUN) !== 0;
851
+ if (other || radial !== (this.fill === this.radial)) {
852
+ this.useFill(radial);
853
+ other = false;
854
+ }
855
+
725
856
  for (let k = 0; k < FILL_TEXTURES; k++) {
726
857
  if (units & (1 << k)) {
727
858
  const id = this.prepared ? this.runs[bindings + k * 2] : this.unitIds[k];
@@ -746,10 +877,11 @@ export class Draws {
746
877
  const rows = this.prepared ? this.tableRows : this.runRows;
747
878
  const counts = this.prepared ? this.tableCounts : this.runCounts;
748
879
  const offsets = this.prepared ? this.tableOffsets : this.runOffsets;
880
+ const fill = this.fill;
749
881
  for (let k = base; k < base + draws; k++) {
750
- if (rows[k] !== this.lastRow) {
751
- this.lastRow = rows[k];
752
- gl.uniform1i(this.rowLocation, this.lastRow);
882
+ if (rows[k] !== fill.lastRow) {
883
+ fill.lastRow = rows[k];
884
+ gl.uniform1i(fill.row, fill.lastRow);
753
885
  }
754
886
 
755
887
  gl.drawElements(gl.TRIANGLES, counts[k], gl.UNSIGNED_INT, offsets[k]);
@@ -782,11 +914,12 @@ export class Draws {
782
914
  }
783
915
  }
784
916
 
785
- /** The fill program told where its run starts in the run table, if it was told another. */
917
+ /** The fill program in use told where its run starts in the run table, if it was told another. */
786
918
  private tellRunBase(base: number): void {
787
- if (base !== this.runBase) {
788
- this.runBase = base;
789
- this.gl.uniform1i(this.runBaseLocation, base);
919
+ const fill = this.fill;
920
+ if (base !== fill.base) {
921
+ fill.base = base;
922
+ this.gl.uniform1i(fill.runBase, base);
790
923
  }
791
924
  }
792
925
 
@@ -857,6 +990,10 @@ export class Draws {
857
990
  }
858
991
  }
859
992
 
993
+ if (!stencil && scene.sampler[j] & RADIAL_FILL) {
994
+ this.runUnits |= RADIAL_RUN;
995
+ }
996
+
860
997
  this.runCounts[draws] = place.indices;
861
998
  this.runPlaces[draws] = place;
862
999
  // A short-lived geometry drawn more than once keeps its arrays (atlas.ts, settle).
@@ -879,11 +1016,18 @@ export class Draws {
879
1016
  * The slot (FILL_SLOT) of the unit texture `id` is sampled from so in the
880
1017
  * run: the one it was left on, else one the run has not taken, an empty
881
1018
  * one first, so that a texture stays where it is from run to run; 0 when
882
- * the run has taken all.
1019
+ * the run has taken all. Line textures (Textures.addLine), all one texture
1020
+ * here, share a unit.
883
1021
  */
884
1022
  private runSlot(id: number, sampling: number): number {
1023
+ const textures = this.gpu.textures;
1024
+ const texture = textures[id];
885
1025
  for (let k = 0; k < FILL_TEXTURES; k++) {
886
- if (this.unitIds[k] === id && this.unitSampling[k] === sampling) {
1026
+ const at = this.unitIds[k];
1027
+ if (
1028
+ (at === id || (at >= 0 && textures[at] === texture)) &&
1029
+ this.unitSampling[k] === sampling
1030
+ ) {
887
1031
  this.runUnits |= 1 << k;
888
1032
  return k + 1;
889
1033
  }
@@ -926,7 +1070,7 @@ export class Draws {
926
1070
  const state = this.state;
927
1071
  if (!this.stageProgram) {
928
1072
  // A link that fails is given up on as the fill program's would be (WebGLBackend.gaveUp).
929
- const program = linkProgram(gl, fillVertex(false, false, true), stageFillFragment);
1073
+ const program = linkProgram(gl, fillVertex(false, false, true, true), stageFillFragment);
930
1074
  this.stageProgram = program;
931
1075
  this.stageRowLocation = gl.getUniformLocation(program, "uRow");
932
1076
  this.stageViewLocation = gl.getUniformLocation(program, "uView");
@@ -1123,7 +1267,24 @@ export class Draws {
1123
1267
  }
1124
1268
 
1125
1269
  const gl = this.gl;
1126
- gl.deleteProgram(this.program);
1270
+ gl.deleteProgram(this.plain.program);
1271
+ gl.deleteProgram(this.radial?.program ?? null);
1272
+ if (this.radialPending) {
1273
+ gl.deleteProgram(this.radialPending.program);
1274
+ gl.deleteShader(this.radialPending.vertex);
1275
+ gl.deleteShader(this.radialPending.fragment);
1276
+ this.radialPending = null;
1277
+ }
1278
+
1279
+ gl.deleteProgram(this.blend.program);
1280
+ gl.deleteProgram(this.radialBlend?.program ?? null);
1281
+ if (this.radialBlendPending) {
1282
+ gl.deleteProgram(this.radialBlendPending.program);
1283
+ gl.deleteShader(this.radialBlendPending.vertex);
1284
+ gl.deleteShader(this.radialBlendPending.fragment);
1285
+ this.radialBlendPending = null;
1286
+ }
1287
+
1127
1288
  gl.deleteProgram(this.stageProgram);
1128
1289
  gl.deleteProgram(this.mesh);
1129
1290
  gl.deleteProgram(this.glyphProgram);
@@ -1,7 +1,7 @@
1
1
  import type { GlState } from "@swf2es/context3d/device";
2
2
  import { ROW_FLOATS, ROWS_A_LINE, type Rows } from "../rows.js";
3
3
  import { MIRROR, REPEAT, SMOOTH } from "../scene.js";
4
- import type { Textures } from "../textures.js";
4
+ import { LINE_TEXELS, type Textures } from "../textures.js";
5
5
  import { OUTLINE_ROW, OUTLINE_UNIT, ROW_TEXELS, TEXTURE_UNIT } from "./programs.js";
6
6
 
7
7
  /**
@@ -24,6 +24,14 @@ export class GpuTextures {
24
24
  private outlineEpoch = -1;
25
25
  private outlineCount = 0;
26
26
  private outlineRows = 0;
27
+ /**
28
+ * The lines' texture (Textures.addLine), which each line texture's id
29
+ * names in `textures`, the bytes of its lines as uploaded, and how many
30
+ * lines it has room for.
31
+ */
32
+ private lines: WebGLTexture | null = null;
33
+ private lineBytes = new Uint8Array(0);
34
+ private lineRoom = 0;
27
35
 
28
36
  constructor(gl: WebGL2RenderingContext, state: GlState) {
29
37
  this.gl = gl;
@@ -37,6 +45,9 @@ export class GpuTextures {
37
45
  this.outlineEpoch = -1;
38
46
  this.outlineCount = 0;
39
47
  this.outlineRows = 0;
48
+ this.lines = null;
49
+ this.lineBytes = new Uint8Array(0);
50
+ this.lineRoom = 0;
40
51
  this.textures = [];
41
52
  this.samplers = [];
42
53
  this.rowsTexture = gl.createTexture() as WebGLTexture;
@@ -113,14 +124,26 @@ export class GpuTextures {
113
124
  const gl = this.gl;
114
125
  for (const id of textures.removed) {
115
126
  const texture = this.textures[id];
116
- if (texture) {
127
+ // A line's is the lines' texture, which others' lines are in.
128
+ if (texture && texture !== this.lines) {
117
129
  this.state.dropTexture(texture);
118
130
  gl.deleteTexture(texture);
119
- this.textures[id] = null;
120
131
  }
132
+
133
+ this.textures[id] = null;
121
134
  }
122
135
 
123
136
  textures.removed.length = 0;
137
+
138
+ // The lines a frame added or set, from the first to the one past the last, uploaded in one
139
+ // call after the rest; all of them where the texture was made larger.
140
+ let linesFrom = Number.POSITIVE_INFINITY;
141
+ let linesTo = 0;
142
+ const grown = textures.lines > this.lineRoom;
143
+ if (grown) {
144
+ this.growLines(textures.lines);
145
+ }
146
+
124
147
  for (const id of textures.pending) {
125
148
  const data = textures.get(id);
126
149
  const fill = data?.pixels ? null : (data?.fill ?? null);
@@ -128,6 +151,15 @@ export class GpuTextures {
128
151
  continue;
129
152
  }
130
153
 
154
+ if (data.line !== undefined && data.pixels instanceof Uint8Array) {
155
+ this.lineBytes.set(data.pixels.subarray(0, LINE_TEXELS * 4), data.line * LINE_TEXELS * 4);
156
+ this.textures[id] = this.lines;
157
+ linesFrom = Math.min(linesFrom, data.line);
158
+ linesTo = Math.max(linesTo, data.line + 1);
159
+ data.pixels = null;
160
+ continue;
161
+ }
162
+
131
163
  let texture = this.textures[id];
132
164
  if (!texture) {
133
165
  texture = gl.createTexture() as WebGLTexture;
@@ -256,6 +288,57 @@ export class GpuTextures {
256
288
  }
257
289
 
258
290
  textures.pending.length = 0;
291
+
292
+ if (grown || linesTo > 0) {
293
+ this.uploadLines(grown ? 0 : linesFrom, grown ? this.lineRoom : linesTo);
294
+ }
295
+ }
296
+
297
+ /**
298
+ * The lines' texture made with room for `lines` at least, twice what it had
299
+ * or more, its lines kept: the same texture, which every line's id names.
300
+ */
301
+ private growLines(lines: number): void {
302
+ const room = Math.max(32, lines, this.lineRoom * 2);
303
+ const bytes = new Uint8Array(room * LINE_TEXELS * 4);
304
+ bytes.set(this.lineBytes);
305
+ this.lineBytes = bytes;
306
+ this.lineRoom = room;
307
+ this.lines ??= this.gl.createTexture() as WebGLTexture;
308
+ }
309
+
310
+ /** Lines `from` up to `to` of the lines' texture uploaded; all of them, made anew, from 0 to its room. */
311
+ private uploadLines(from: number, to: number): void {
312
+ const gl = this.gl;
313
+ this.state.bindTexture(TEXTURE_UNIT, this.lines);
314
+ this.state.activeTexture(TEXTURE_UNIT);
315
+ if (from === 0 && to === this.lineRoom) {
316
+ gl.texImage2D(
317
+ gl.TEXTURE_2D,
318
+ 0,
319
+ gl.RGBA8,
320
+ LINE_TEXELS,
321
+ this.lineRoom,
322
+ 0,
323
+ gl.RGBA,
324
+ gl.UNSIGNED_BYTE,
325
+ this.lineBytes,
326
+ );
327
+ return;
328
+ }
329
+
330
+ gl.texSubImage2D(
331
+ gl.TEXTURE_2D,
332
+ 0,
333
+ 0,
334
+ from,
335
+ LINE_TEXELS,
336
+ to - from,
337
+ gl.RGBA,
338
+ gl.UNSIGNED_BYTE,
339
+ this.lineBytes,
340
+ from * LINE_TEXELS * 4,
341
+ );
259
342
  }
260
343
 
261
344
  /** The sampler for `bits` (SMOOTH, and REPEAT or MIRROR), made as first asked for. */
@@ -314,11 +397,15 @@ export class GpuTextures {
314
397
  }
315
398
 
316
399
  for (const texture of this.textures) {
317
- if (texture) {
400
+ if (texture && texture !== this.lines) {
318
401
  gl.deleteTexture(texture);
319
402
  }
320
403
  }
321
404
 
405
+ if (this.lines) {
406
+ gl.deleteTexture(this.lines);
407
+ }
408
+
322
409
  for (const sampler of this.samplers) {
323
410
  if (sampler) {
324
411
  gl.deleteSampler(sampler);