@swf2es/render 0.1.19 → 0.1.21

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 (40) hide show
  1. package/dist/filter-plan.d.ts +5 -2
  2. package/dist/filter-plan.d.ts.map +1 -1
  3. package/dist/filter-plan.js +9 -6
  4. package/dist/filter-plan.js.map +1 -1
  5. package/dist/filter-shaders.d.ts +1 -1
  6. package/dist/filter-shaders.d.ts.map +1 -1
  7. package/dist/filter-shaders.js +3 -3
  8. package/dist/webgl/atlas.d.ts +8 -1
  9. package/dist/webgl/atlas.d.ts.map +1 -1
  10. package/dist/webgl/atlas.js +17 -2
  11. package/dist/webgl/atlas.js.map +1 -1
  12. package/dist/webgl/batches.d.ts +68 -18
  13. package/dist/webgl/batches.d.ts.map +1 -1
  14. package/dist/webgl/batches.js +252 -63
  15. package/dist/webgl/batches.js.map +1 -1
  16. package/dist/webgl/draws.d.ts +32 -11
  17. package/dist/webgl/draws.d.ts.map +1 -1
  18. package/dist/webgl/draws.js +114 -43
  19. package/dist/webgl/draws.js.map +1 -1
  20. package/dist/webgl/filters.d.ts +10 -0
  21. package/dist/webgl/filters.d.ts.map +1 -1
  22. package/dist/webgl/filters.js +50 -1
  23. package/dist/webgl/filters.js.map +1 -1
  24. package/dist/webgl/glyph-tables.d.ts +44 -0
  25. package/dist/webgl/glyph-tables.d.ts.map +1 -0
  26. package/dist/webgl/glyph-tables.js +148 -0
  27. package/dist/webgl/glyph-tables.js.map +1 -0
  28. package/dist/webgl/programs.d.ts +27 -8
  29. package/dist/webgl/programs.d.ts.map +1 -1
  30. package/dist/webgl/programs.js +49 -22
  31. package/dist/webgl/programs.js.map +1 -1
  32. package/package.json +2 -2
  33. package/src/filter-plan.ts +9 -6
  34. package/src/filter-shaders.ts +3 -3
  35. package/src/webgl/atlas.ts +23 -4
  36. package/src/webgl/batches.ts +316 -68
  37. package/src/webgl/draws.ts +129 -47
  38. package/src/webgl/filters.ts +55 -0
  39. package/src/webgl/glyph-tables.ts +179 -0
  40. package/src/webgl/programs.ts +49 -22
@@ -37,6 +37,13 @@ export const DRAW_AT = 8;
37
37
 
38
38
  /** The most cutoff table entries a text's draw takes, as the player's text/saffron.ts builds them. */
39
39
  export const TABLE_ENTRIES = 48;
40
+ /**
41
+ * Texels a text's slot in the glyph tables' texture (GlyphTables): its mode,
42
+ * then its table's entries; and texels a line of it. Powers of two, which
43
+ * the vertex shader splits a slot's texel into column and line with.
44
+ */
45
+ export const TABLE_SLOT = 64;
46
+ export const TABLE_LINE = 1024;
40
47
  /** Segments a row of the outlines' texture, as the player's text/saffron.ts stores them. */
41
48
  export const OUTLINE_ROW = 1024;
42
49
 
@@ -70,6 +77,12 @@ export const OUTLINE_UNIT = 7;
70
77
  export const FILL_UNIT = 8;
71
78
  /** The multi-draw row table's unit, past the fill textures. */
72
79
  export const RUN_UNIT = FILL_UNIT + FILL_TEXTURES;
80
+ /** The merged fills' rows' unit (FillBatches), past the run table. */
81
+ export const MERGED_UNIT = RUN_UNIT + 1;
82
+ /** The merged fills' rows a line of their integer texture: a power of two, as for RUN_MOST. */
83
+ export const MERGED_LINE = 1024;
84
+ /** The glyph tables' unit (GlyphTables), past the merged fills' rows. */
85
+ export const TABLE_UNIT = MERGED_UNIT + 1;
73
86
 
74
87
  /**
75
88
  * Places a vertex by its row's transform, on a quarter of a pixel of
@@ -78,17 +91,21 @@ export const RUN_UNIT = FILL_UNIT + FILL_TEXTURES;
78
91
  * space), and passes on its straight colour, the row's colour transform
79
92
  * and the texture it samples. uRow names the draw's row (FILL_SLOT); with
80
93
  * `multi` (WEBGL_multi_draw), uRunTable names each draw's of a multi-draw by
81
- * gl_DrawID, which is 0 in a draw of its own. Merged fills supply the packed
82
- * row as aDraw; the atlas leaves that attribute disabled and negative.
94
+ * gl_DrawID, which is 0 in a draw of its own. With `merged`, as with
95
+ * `multi`, a merged fill's vertices carry as aDraw where its packed row is
96
+ * in uMergedRows, which the stream keeps for its copy, so that the row
97
+ * changes from frame to frame where the vertices need not; the atlas leaves
98
+ * that attribute disabled and negative.
83
99
  */
84
- export const fillVertex = (multi: boolean) => `#version 300 es
100
+ export const fillVertex = (multi: boolean, merged = multi) => `#version 300 es
85
101
  ${multi ? "#extension GL_ANGLE_multi_draw : require" : ""}
86
102
  precision highp float;
87
103
  layout(location = ${POSITION_AT}) in vec2 aPosition;
88
104
  layout(location = ${TEXEL_AT}) in vec2 aTexel;
89
105
  layout(location = ${COLOR_AT}) in vec4 aColor;
90
106
  uniform highp sampler2D uRows;
91
- ${multi ? `layout(location = ${DRAW_AT}) in int aDraw;\nuniform highp isampler2D uRunTable;\nuniform int uRunBase;` : "uniform int uRow;"}
107
+ ${merged ? `layout(location = ${DRAW_AT}) in int aDraw;\nuniform highp isampler2D uMergedRows;` : ""}
108
+ ${multi ? "uniform highp isampler2D uRunTable;\nuniform int uRunBase;" : "uniform int uRow;"}
92
109
  uniform vec4 uView;
93
110
  uniform float uUnit;
94
111
  out vec4 vColor;
@@ -98,7 +115,7 @@ flat out vec4 vAdd;
98
115
  flat out int vSlot;
99
116
 
100
117
  void main(void) {
101
- int draw = ${multi ? `aDraw >= 0 ? aDraw : texelFetch(uRunTable, ivec2((uRunBase + gl_DrawID) & ${RUN_MOST - 1}, (uRunBase + gl_DrawID) >> ${Math.log2(RUN_MOST)}), 0).r` : "uRow"};
118
+ 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"};
102
119
  int row = draw & ${(1 << FILL_SLOT) - 1};
103
120
  vSlot = (draw >> ${FILL_SLOT}) & 15;
104
121
  ivec2 at = ivec2((row & ${ROWS_A_LINE - 1}) * ${ROW_TEXELS}, row >> ${Math.log2(ROWS_A_LINE)});
@@ -291,11 +308,14 @@ void main(void) {
291
308
  * pixels to Flash's, uUnit of them a stage pixel, on their grid from the
292
309
  * stage's origin, a BitmapData's in a draw. A glyph's pen stands where its
293
310
  * text's origin, at a whole pixel, puts it, snapped as its grid fits it
294
- * (uMode: gridFitType 0 none, 1 pixel, 2 subpixel, thickness, sharpness),
295
- * and its quad reaches out past its outline by the furthest cutoff. Its
296
- * colour is drawn under the row's colour transform, light or dark as adl
297
- * chooses its table. aOrigin: the pen, and its light and dark tables, each
298
- * its first entry plus 64 times its entries; aGlyph: a corner of its
311
+ * (its mode: gridFitType 0 none, 1 pixel, 2 subpixel, thickness,
312
+ * sharpness), and its quad reaches out past its outline by the furthest
313
+ * cutoff. Its colour is drawn under the row's colour transform, light or
314
+ * dark as adl chooses its table. The text's mode and tables are in its slot
315
+ * of uTables (uTable; GlyphTables), read by texelFetch: not a uniform array
316
+ * indexed by each glyph's table start, the access that hung Intel's GPUs
317
+ * in the fill program's run table. aOrigin: the pen, and its light and dark tables,
318
+ * each its first entry plus 64 times its entries; aGlyph: a corner of its
299
319
  * outline's bounds and the way out from it; aRun: its segments, first and
300
320
  * count, the pixels of a unit of its outline, and its size.
301
321
  */
@@ -310,8 +330,8 @@ uniform highp sampler2D uRows;
310
330
  uniform int uRow;
311
331
  uniform vec4 uView;
312
332
  uniform float uUnit;
313
- uniform vec4 uMode;
314
- uniform vec4 uTable[${TABLE_ENTRIES}];
333
+ uniform highp sampler2D uTables;
334
+ uniform int uTable;
315
335
  out vec2 vPixel;
316
336
  flat out vec2 vPen;
317
337
  flat out vec4 vToGlyph;
@@ -319,10 +339,16 @@ flat out vec4 vToPixel;
319
339
  flat out vec4 vCut;
320
340
  flat out vec4 vShown;
321
341
 
342
+ // Texel i of the text's slot: its mode, then its tables' entries.
343
+ vec4 slot(int i) {
344
+ int at = uTable * ${TABLE_SLOT} + i;
345
+ return texelFetch(uTables, ivec2(at & ${TABLE_LINE - 1}, at >> ${Math.log2(TABLE_LINE)}), 0);
346
+ }
347
+
322
348
  // The cutoffs at ppem by the table of entries start to start + count, as text/csm.ts' cutoffs.
323
- vec2 cutoffs(int start, int count, float ppem) {
324
- vec4 first = uTable[start];
325
- vec4 last = uTable[start + count - 1];
349
+ vec2 cutoffs(vec4 mode, int start, int count, float ppem) {
350
+ vec4 first = slot(1 + start);
351
+ vec4 last = slot(start + count);
326
352
  vec2 c = first.yz;
327
353
  if (ppem >= last.x) {
328
354
  c = last.yz;
@@ -332,9 +358,9 @@ vec2 cutoffs(int start, int count, float ppem) {
332
358
  break;
333
359
  }
334
360
 
335
- vec4 b = uTable[start + i];
361
+ vec4 b = slot(1 + start + i);
336
362
  if (ppem <= b.x) {
337
- vec4 a = uTable[start + i - 1];
363
+ vec4 a = slot(start + i);
338
364
  c = mix(a.yz, b.yz, (ppem - a.x) / (b.x - a.x));
339
365
  break;
340
366
  }
@@ -342,8 +368,8 @@ vec2 cutoffs(int start, int count, float ppem) {
342
368
  }
343
369
 
344
370
  float unit = 0.0001 * ppem;
345
- float t = clamp(uMode.y, -200.0, 200.0);
346
- float s = clamp(uMode.z, -400.0, 400.0);
371
+ float t = clamp(mode.y, -200.0, 200.0);
372
+ float s = clamp(mode.z, -400.0, 400.0);
347
373
  c -= unit * vec2(t + s * 0.5, t - s * 0.5);
348
374
  if (c.x < c.y) {
349
375
  c = vec2((c.x + c.y) * 0.5);
@@ -358,6 +384,7 @@ void main(void) {
358
384
  vec4 t = texelFetch(uRows, at + ivec2(1, 0), 0);
359
385
  vec4 mul = texelFetch(uRows, at + ivec2(2, 0), 0);
360
386
  vec4 add = texelFetch(uRows, at + ivec2(3, 0), 0);
387
+ vec4 mode = slot(0);
361
388
  // The text's pixels to Flash's.
362
389
  mat2 linear = mat2(m.xy, m.zw) * uUnit;
363
390
  vec2 origin = t.xy * uUnit;
@@ -365,9 +392,9 @@ void main(void) {
365
392
  float across = max(abs(linear[0][1]), abs(linear[1][0]));
366
393
  if (across > max(abs(linear[0][0]), abs(linear[1][1])) / 65536.0) {
367
394
  // Turned or skewed: no grid.
368
- } else if (uMode.x == 1.0) {
395
+ } else if (mode.x == 1.0) {
369
396
  pen = vec2(roundEven(pen.x * 8.0) / 8.0 + 0.5, roundEven(pen.y));
370
- } else if (uMode.x == 2.0) {
397
+ } else if (mode.x == 2.0) {
371
398
  pen = vec2(roundEven(pen.x * 4.0) / 4.0 + 0.5, roundEven(pen.y));
372
399
  } else {
373
400
  pen = roundEven(pen * 4.0) / 4.0 + vec2(0.5, 0.0);
@@ -378,7 +405,7 @@ void main(void) {
378
405
  vec4 shown = clamp(aColor * mul + add, 0.0, 1.0);
379
406
  bool light = dot(floor(shown.rgb * 255.0 + 0.5), vec3(30.0, 59.0, 11.0)) > 20000.0;
380
407
  int table = int(light ? aOrigin.z : aOrigin.w);
381
- vec2 cut = cutoffs(table & 63, table >> 6, ppem);
408
+ vec2 cut = cutoffs(mode, table & 63, table >> 6, ppem);
382
409
  mat2 toPixel = linear * aRun.z;
383
410
  float margin = max(abs(cut.x), abs(cut.y)) + 1.0;
384
411
  float det = determinant(toPixel);