@swf2es/render 0.1.43 → 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 (54) hide show
  1. package/dist/filter-shaders.d.ts +2 -2
  2. package/dist/filter-shaders.d.ts.map +1 -1
  3. package/dist/filter-shaders.js +7 -4
  4. package/dist/filter-shaders.js.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/registry.d.ts +12 -0
  10. package/dist/registry.d.ts.map +1 -1
  11. package/dist/registry.js +19 -0
  12. package/dist/registry.js.map +1 -1
  13. package/dist/rows.d.ts +28 -1
  14. package/dist/rows.d.ts.map +1 -1
  15. package/dist/rows.js +32 -1
  16. package/dist/rows.js.map +1 -1
  17. package/dist/scene.d.ts +6 -0
  18. package/dist/scene.d.ts.map +1 -1
  19. package/dist/scene.js +6 -0
  20. package/dist/scene.js.map +1 -1
  21. package/dist/spans.js +2 -2
  22. package/dist/spans.js.map +1 -1
  23. package/dist/textures.d.ts +33 -0
  24. package/dist/textures.d.ts.map +1 -1
  25. package/dist/textures.js +67 -14
  26. package/dist/textures.js.map +1 -1
  27. package/dist/webgl/backend.d.ts +15 -3
  28. package/dist/webgl/backend.d.ts.map +1 -1
  29. package/dist/webgl/backend.js +63 -14
  30. package/dist/webgl/backend.js.map +1 -1
  31. package/dist/webgl/draws.d.ts +50 -29
  32. package/dist/webgl/draws.d.ts.map +1 -1
  33. package/dist/webgl/draws.js +185 -85
  34. package/dist/webgl/draws.js.map +1 -1
  35. package/dist/webgl/gpu-textures.d.ts +16 -1
  36. package/dist/webgl/gpu-textures.d.ts.map +1 -1
  37. package/dist/webgl/gpu-textures.js +61 -3
  38. package/dist/webgl/gpu-textures.js.map +1 -1
  39. package/dist/webgl/programs.d.ts +40 -9
  40. package/dist/webgl/programs.d.ts.map +1 -1
  41. package/dist/webgl/programs.js +111 -18
  42. package/dist/webgl/programs.js.map +1 -1
  43. package/package.json +2 -2
  44. package/src/filter-shaders.ts +7 -4
  45. package/src/index.ts +1 -0
  46. package/src/registry.ts +21 -0
  47. package/src/rows.ts +34 -1
  48. package/src/scene.ts +6 -0
  49. package/src/spans.ts +2 -2
  50. package/src/textures.ts +85 -14
  51. package/src/webgl/backend.ts +73 -15
  52. package/src/webgl/draws.ts +252 -91
  53. package/src/webgl/gpu-textures.ts +91 -4
  54. package/src/webgl/programs.ts +124 -18
@@ -121,6 +121,17 @@ export class WebGLBackend {
121
121
  private readonly rect = { x: 0, y: 0, width: 0, height: 0 };
122
122
  /** The blends drawn direct that share the copy of what is below made last (shareCopy). */
123
123
  private readonly backdrops = new Backdrops();
124
+ /**
125
+ * The blends drawn direct that shareCopy's look-ahead found, from command
126
+ * `aheadFrom` to before `aheadTo`, one every three commands: where each
127
+ * lies on its target (Compositor.cover), four numbers each in aheadPlaces
128
+ * (x and y in its framebuffer, width and height, of no size off it). As
129
+ * nothing draws between them but they, blendDirect takes these rather
130
+ * than finding them again. This frame's commands alone (execute).
131
+ */
132
+ private aheadFrom = 0;
133
+ private aheadTo = 0;
134
+ private readonly aheadPlaces: number[] = [];
124
135
  /** The mask counts of the targets below the layers drawn into now, two numbers each. */
125
136
  private readonly below: number[] = [];
126
137
  /** The program `compositeOver` draws with, linked ahead (programs); null till then and after a lost context. */
@@ -389,8 +400,7 @@ export class WebGLBackend {
389
400
  const state = this.state;
390
401
  state.scissor(null);
391
402
  state.colorMask(15);
392
- state.useProgram(this.draws.program);
393
- state.bindTexture(0, this.gpu.rowsTexture);
403
+ this.draws.useFill();
394
404
  // As many samples as the GPU takes; a BitmapData's frame supersamples instead, as Flash's draw
395
405
  // does. Its layers take the stage's, so that their edges are the stage's.
396
406
  const stage = root ? null : this.stage.stageBuffers(target.width, target.height, this.samples);
@@ -420,6 +430,8 @@ export class WebGLBackend {
420
430
  };
421
431
  this.layers.length = 0;
422
432
  this.backdrops.begin(false);
433
+ this.aheadFrom = 0;
434
+ this.aheadTo = 0;
423
435
  this.draws.drawInto(canvas, target);
424
436
 
425
437
  this.draws.forgetRow();
@@ -1147,7 +1159,9 @@ export class WebGLBackend {
1147
1159
  * drawn direct before it (shareCopy). Whether it was.
1148
1160
  */
1149
1161
  private blendDirect(commands: Commands, k: number, scene: SceneList, canvas: Open): boolean {
1150
- if (!this.drawsDirect(commands, k, scene)) {
1162
+ const ahead = k - this.aheadFrom;
1163
+ const known = k < this.aheadTo && ahead >= 0 && ahead % 3 === 0;
1164
+ if (!known && !this.drawsDirect(commands, k, scene)) {
1151
1165
  return false;
1152
1166
  }
1153
1167
 
@@ -1157,7 +1171,27 @@ export class WebGLBackend {
1157
1171
  const mode = ops[pop + 1];
1158
1172
  const below = ops[k * 4 + 3] >> 1;
1159
1173
  const compositor = this.compositor;
1160
- if (!compositor.cover(this.rectAt(commands, k), under)) {
1174
+ let fx: number;
1175
+ let fy: number;
1176
+ let width: number;
1177
+ let height: number;
1178
+ if (known) {
1179
+ const places = this.aheadPlaces;
1180
+ const at = (ahead / 3) * 4;
1181
+ fx = places[at];
1182
+ fy = places[at + 1];
1183
+ width = places[at + 2];
1184
+ height = places[at + 3];
1185
+ } else {
1186
+ const place = compositor.place;
1187
+ compositor.cover(this.rectAt(commands, k), under);
1188
+ fx = place.fx;
1189
+ fy = place.fy;
1190
+ width = place.width;
1191
+ height = place.height;
1192
+ }
1193
+
1194
+ if (!(width > 0 && height > 0)) {
1161
1195
  return true;
1162
1196
  }
1163
1197
 
@@ -1171,16 +1205,15 @@ export class WebGLBackend {
1171
1205
  const backdrops = this.backdrops;
1172
1206
  box = backdrops.copy === compositor.copies ? backdrops.boxFor(k) : -1;
1173
1207
  if (box < 0) {
1174
- box = this.shareCopy(commands, k, scene, under);
1208
+ box = this.shareCopy(commands, k, scene, under, fx, fy, width, height);
1175
1209
  } else {
1176
1210
  compositor.bindBack();
1177
1211
  }
1178
1212
  }
1179
1213
 
1180
1214
  this.draws.maskBy(this.masks);
1181
- const place = compositor.place;
1182
1215
  // Kept to the layer's rectangle, as the composite is, past which nothing below is copied.
1183
- this.state.scissor([place.fx, place.fy, place.width, place.height]);
1216
+ this.state.scissor([fx, fy, width, height]);
1184
1217
  this.draws.drawBlended(
1185
1218
  scene,
1186
1219
  ops[k * 4 + 5],
@@ -1236,20 +1269,44 @@ export class WebGLBackend {
1236
1269
  }
1237
1270
 
1238
1271
  /**
1239
- * What is below the blend drawn direct at command `k`, which reads it,
1272
+ * What is below the blend drawn direct at command `k`, which reads it and
1273
+ * lies at `fx`, `fy`, `width` by `height` of its target's framebuffer,
1240
1274
  * copied once for it and for the blends drawn direct right after it that
1241
- * may share the copy (Backdrops): the box that holds its rectangle, and
1242
- * the compositor's place its own again.
1275
+ * may share the copy (Backdrops): the box that holds its rectangle. What
1276
+ * the look-ahead finds of those blends is kept for them (aheadPlaces).
1243
1277
  */
1244
- private shareCopy(commands: Commands, k: number, scene: SceneList, under: Open): number {
1278
+ private shareCopy(
1279
+ commands: Commands,
1280
+ k: number,
1281
+ scene: SceneList,
1282
+ under: Open,
1283
+ fx: number,
1284
+ fy: number,
1285
+ width: number,
1286
+ height: number,
1287
+ ): number {
1245
1288
  const compositor = this.compositor;
1246
1289
  const backdrops = this.backdrops;
1247
1290
  const place = compositor.place;
1291
+ const places = this.aheadPlaces;
1248
1292
  backdrops.begin(compositor.copiesWhereLying(under));
1249
-
1250
- for (let j = k; j < commands.length && this.drawsDirect(commands, j, scene); j += 3) {
1293
+ // Drawn direct and placed already (blendDirect), and the first offered always takes the copy.
1294
+ backdrops.offer(k, fx, fy, width, height, true);
1295
+ places[0] = fx;
1296
+ places[1] = fy;
1297
+ places[2] = width;
1298
+ places[3] = height;
1299
+ let n = 1;
1300
+
1301
+ for (let j = k + 3; j < commands.length && this.drawsDirect(commands, j, scene); j += 3) {
1302
+ const lies = compositor.cover(this.rectAt(commands, j), under);
1303
+ const at = n++ * 4;
1304
+ places[at] = place.fx;
1305
+ places[at + 1] = place.fy;
1306
+ places[at + 2] = place.width;
1307
+ places[at + 3] = place.height;
1251
1308
  if (
1252
- compositor.cover(this.rectAt(commands, j), under) &&
1309
+ lies &&
1253
1310
  !backdrops.offer(
1254
1311
  j,
1255
1312
  place.fx,
@@ -1263,9 +1320,10 @@ export class WebGLBackend {
1263
1320
  }
1264
1321
  }
1265
1322
 
1323
+ this.aheadFrom = k;
1324
+ this.aheadTo = k + n * 3;
1266
1325
  compositor.copyBoxes(under, backdrops.boxes, backdrops.boxCount);
1267
1326
  backdrops.copy = compositor.copies;
1268
- compositor.cover(this.rectAt(commands, k), under);
1269
1327
  return backdrops.boxFor(k);
1270
1328
  }
1271
1329
  }