@swf2es/render 0.0.0-stage → 0.1.1

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 (143) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +17 -2
  3. package/dist/commands.d.ts +67 -0
  4. package/dist/commands.d.ts.map +1 -0
  5. package/dist/commands.js +93 -0
  6. package/dist/commands.js.map +1 -0
  7. package/dist/filter-plan.d.ts +110 -0
  8. package/dist/filter-plan.d.ts.map +1 -0
  9. package/dist/filter-plan.js +480 -0
  10. package/dist/filter-plan.js.map +1 -0
  11. package/dist/filter-shaders.d.ts +63 -0
  12. package/dist/filter-shaders.d.ts.map +1 -0
  13. package/dist/filter-shaders.js +350 -0
  14. package/dist/filter-shaders.js.map +1 -0
  15. package/dist/filters.d.ts +107 -0
  16. package/dist/filters.d.ts.map +1 -0
  17. package/dist/filters.js +187 -0
  18. package/dist/filters.js.map +1 -0
  19. package/dist/geometry.d.ts +83 -0
  20. package/dist/geometry.d.ts.map +1 -0
  21. package/dist/geometry.js +93 -0
  22. package/dist/geometry.js.map +1 -0
  23. package/dist/index.d.ts +11 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +13 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/keeps.d.ts +17 -0
  28. package/dist/keeps.d.ts.map +1 -0
  29. package/dist/keeps.js +17 -0
  30. package/dist/keeps.js.map +1 -0
  31. package/dist/kernel-shaders.d.ts +74 -0
  32. package/dist/kernel-shaders.d.ts.map +1 -0
  33. package/dist/kernel-shaders.js +323 -0
  34. package/dist/kernel-shaders.js.map +1 -0
  35. package/dist/measure.d.ts +56 -0
  36. package/dist/measure.d.ts.map +1 -0
  37. package/dist/measure.js +287 -0
  38. package/dist/measure.js.map +1 -0
  39. package/dist/plan.d.ts +14 -0
  40. package/dist/plan.d.ts.map +1 -0
  41. package/dist/plan.js +247 -0
  42. package/dist/plan.js.map +1 -0
  43. package/dist/registry.d.ts +49 -0
  44. package/dist/registry.d.ts.map +1 -0
  45. package/dist/registry.js +87 -0
  46. package/dist/registry.js.map +1 -0
  47. package/dist/rows.d.ts +39 -0
  48. package/dist/rows.d.ts.map +1 -0
  49. package/dist/rows.js +60 -0
  50. package/dist/rows.js.map +1 -0
  51. package/dist/scene.d.ts +179 -0
  52. package/dist/scene.d.ts.map +1 -0
  53. package/dist/scene.js +265 -0
  54. package/dist/scene.js.map +1 -0
  55. package/dist/shelves.d.ts +23 -0
  56. package/dist/shelves.d.ts.map +1 -0
  57. package/dist/shelves.js +63 -0
  58. package/dist/shelves.js.map +1 -0
  59. package/dist/textures.d.ts +72 -0
  60. package/dist/textures.d.ts.map +1 -0
  61. package/dist/textures.js +160 -0
  62. package/dist/textures.js.map +1 -0
  63. package/dist/webgl/atlas.d.ts +63 -0
  64. package/dist/webgl/atlas.d.ts.map +1 -0
  65. package/dist/webgl/atlas.js +328 -0
  66. package/dist/webgl/atlas.js.map +1 -0
  67. package/dist/webgl/backend.d.ts +141 -0
  68. package/dist/webgl/backend.d.ts.map +1 -0
  69. package/dist/webgl/backend.js +659 -0
  70. package/dist/webgl/backend.js.map +1 -0
  71. package/dist/webgl/composite.d.ts +101 -0
  72. package/dist/webgl/composite.d.ts.map +1 -0
  73. package/dist/webgl/composite.js +293 -0
  74. package/dist/webgl/composite.js.map +1 -0
  75. package/dist/webgl/draws.d.ts +213 -0
  76. package/dist/webgl/draws.d.ts.map +1 -0
  77. package/dist/webgl/draws.js +714 -0
  78. package/dist/webgl/draws.js.map +1 -0
  79. package/dist/webgl/filters.d.ts +107 -0
  80. package/dist/webgl/filters.d.ts.map +1 -0
  81. package/dist/webgl/filters.js +351 -0
  82. package/dist/webgl/filters.js.map +1 -0
  83. package/dist/webgl/gpu-textures.d.ts +44 -0
  84. package/dist/webgl/gpu-textures.d.ts.map +1 -0
  85. package/dist/webgl/gpu-textures.js +178 -0
  86. package/dist/webgl/gpu-textures.js.map +1 -0
  87. package/dist/webgl/holds.d.ts +97 -0
  88. package/dist/webgl/holds.d.ts.map +1 -0
  89. package/dist/webgl/holds.js +453 -0
  90. package/dist/webgl/holds.js.map +1 -0
  91. package/dist/webgl/index.d.ts +2 -0
  92. package/dist/webgl/index.d.ts.map +1 -0
  93. package/dist/webgl/index.js +4 -0
  94. package/dist/webgl/index.js.map +1 -0
  95. package/dist/webgl/kernels.d.ts +64 -0
  96. package/dist/webgl/kernels.d.ts.map +1 -0
  97. package/dist/webgl/kernels.js +160 -0
  98. package/dist/webgl/kernels.js.map +1 -0
  99. package/dist/webgl/pool.d.ts +71 -0
  100. package/dist/webgl/pool.d.ts.map +1 -0
  101. package/dist/webgl/pool.js +192 -0
  102. package/dist/webgl/pool.js.map +1 -0
  103. package/dist/webgl/programs.d.ts +130 -0
  104. package/dist/webgl/programs.d.ts.map +1 -0
  105. package/dist/webgl/programs.js +582 -0
  106. package/dist/webgl/programs.js.map +1 -0
  107. package/dist/webgl/stage.d.ts +67 -0
  108. package/dist/webgl/stage.d.ts.map +1 -0
  109. package/dist/webgl/stage.js +173 -0
  110. package/dist/webgl/stage.js.map +1 -0
  111. package/dist/webgl/targets.d.ts +172 -0
  112. package/dist/webgl/targets.d.ts.map +1 -0
  113. package/dist/webgl/targets.js +323 -0
  114. package/dist/webgl/targets.js.map +1 -0
  115. package/package.json +35 -3
  116. package/src/commands.ts +98 -0
  117. package/src/filter-plan.ts +755 -0
  118. package/src/filter-shaders.ts +360 -0
  119. package/src/filters.ts +220 -0
  120. package/src/geometry.ts +143 -0
  121. package/src/index.ts +87 -0
  122. package/src/keeps.ts +21 -0
  123. package/src/kernel-shaders.ts +375 -0
  124. package/src/measure.ts +400 -0
  125. package/src/plan.ts +331 -0
  126. package/src/registry.ts +105 -0
  127. package/src/rows.ts +93 -0
  128. package/src/scene.ts +297 -0
  129. package/src/shelves.ts +70 -0
  130. package/src/textures.ts +198 -0
  131. package/src/webgl/atlas.ts +370 -0
  132. package/src/webgl/backend.ts +973 -0
  133. package/src/webgl/composite.ts +372 -0
  134. package/src/webgl/draws.ts +902 -0
  135. package/src/webgl/filters.ts +502 -0
  136. package/src/webgl/gpu-textures.ts +253 -0
  137. package/src/webgl/holds.ts +624 -0
  138. package/src/webgl/index.ts +3 -0
  139. package/src/webgl/kernels.ts +205 -0
  140. package/src/webgl/pool.ts +245 -0
  141. package/src/webgl/programs.ts +620 -0
  142. package/src/webgl/stage.ts +214 -0
  143. package/src/webgl/targets.ts +464 -0
@@ -0,0 +1,160 @@
1
+ import { linkProgram, ShaderError } from "@swf2es/context3d/device";
2
+ import { CLAMP } from "../scene.js";
3
+ /**
4
+ * The first unit a kernel's own images are bound to, as many as
5
+ * kernel-shaders.ts's KERNEL_IMAGES: past every unit the other programs
6
+ * use (programs.ts's, and the filter passes' 4 to 6), as WebGL 2 has 32
7
+ * for a draw's programs together.
8
+ */
9
+ export const KERNEL_UNIT = 16;
10
+ /** The most kernels' programs kept, the one used longest ago deleted for another. */
11
+ const KERNEL_PROGRAMS = 32;
12
+ /**
13
+ * The programs of Pixel Bender kernels, a ShaderFilter's, a blend
14
+ * shader's or a shader fill's, by their fragment shaders, each a use's
15
+ * own and so with one vertex shader:
16
+ * linked as first used, the one used longest ago deleted past
17
+ * KERNEL_PROGRAMS; null for one the GPU would not link, which its user
18
+ * draws otherwise. One for the backend, which its users share.
19
+ */
20
+ export class KernelPrograms {
21
+ gl;
22
+ state;
23
+ programs = new Map();
24
+ ints = new Int32Array(4);
25
+ constructor(gl, state) {
26
+ this.gl = gl;
27
+ this.state = state;
28
+ }
29
+ /**
30
+ * The program of `vertex` and `fragment`, in use; null where it would
31
+ * not link. `prepare` is told it as it is linked, to set its samplers.
32
+ */
33
+ use(vertex, fragment, prepare) {
34
+ const gl = this.gl;
35
+ // By the fragment shader alone, a use's own, which a frame gives again as the same string.
36
+ const key = fragment;
37
+ let kernel = this.programs.get(key);
38
+ if (kernel !== undefined) {
39
+ // Used last now.
40
+ this.programs.delete(key);
41
+ }
42
+ else {
43
+ if (this.programs.size >= KERNEL_PROGRAMS) {
44
+ const [oldest, old] = this.programs.entries().next().value;
45
+ if (old) {
46
+ gl.deleteProgram(old.program);
47
+ }
48
+ this.programs.delete(oldest);
49
+ }
50
+ kernel = null;
51
+ try {
52
+ const program = linkProgram(gl, vertex, fragment);
53
+ const uniforms = new Map();
54
+ kernel = {
55
+ program,
56
+ uniforms,
57
+ told: new Map(),
58
+ at(name) {
59
+ let location = uniforms.get(name);
60
+ if (location === undefined) {
61
+ location = gl.getUniformLocation(program, name);
62
+ uniforms.set(name, location);
63
+ }
64
+ return location;
65
+ },
66
+ };
67
+ this.state.useProgram(program);
68
+ prepare(program);
69
+ }
70
+ catch (e) {
71
+ if (!(e instanceof ShaderError)) {
72
+ throw e;
73
+ }
74
+ }
75
+ }
76
+ this.programs.set(key, kernel);
77
+ if (kernel) {
78
+ this.state.useProgram(kernel.program);
79
+ }
80
+ return kernel;
81
+ }
82
+ /** Texture `id` bound to a kernel's own image unit `k`, which its sampler at `location` names. */
83
+ bindImage(location, k, id, host) {
84
+ this.state.bindTexture(KERNEL_UNIT + k, host.texture(id));
85
+ // Nearest: a float texture with a linear sampler is incomplete, and texelFetch reads either.
86
+ this.state.bindSampler(KERNEL_UNIT + k, host.sampler(CLAMP));
87
+ this.gl.uniform1i(location, KERNEL_UNIT + k);
88
+ }
89
+ /** `count` ints of `source` from `at` set as the ivec4 array at `location`, its program in use. */
90
+ setInts(location, source, at, count) {
91
+ let values = this.ints;
92
+ if (count > values.length) {
93
+ values = new Int32Array(count);
94
+ }
95
+ values.set(source.subarray(at, at + count));
96
+ this.gl.uniform4iv(location, values, 0, count);
97
+ }
98
+ /** What readImages reads into, its records kept from call to call. */
99
+ images = [];
100
+ /**
101
+ * The images of the kernel at entry `i` of `filters`, a blend shader's
102
+ * or a shader fill's, its values laid out as a ShaderFilter's
103
+ * (filters.ts, SHADER): -1 for what is below, -2 for the layer blended.
104
+ * Null where a texture of its own is gone, as such a kernel is left out.
105
+ */
106
+ readImages(filters, i, host) {
107
+ const v = filters.values;
108
+ const at = filters.start[i];
109
+ const count = v[at + 7];
110
+ const images = this.images;
111
+ for (let k = 0; k < count; k++) {
112
+ const id = v[at + 9 + k * 3];
113
+ if (id >= 0 && !host.texture(id)) {
114
+ return null;
115
+ }
116
+ if (!images[k]) {
117
+ images[k] = { texture: 0, layer: false, float: false, back: false };
118
+ }
119
+ const image = images[k];
120
+ image.texture = v[at + 8 + k * 3];
121
+ image.layer = id < 0;
122
+ image.back = id === -1;
123
+ image.float = v[at + 10 + k * 3] > 0;
124
+ }
125
+ images.length = count;
126
+ return images;
127
+ }
128
+ /** The parameters and own images of the kernel at entry `i` of `filters` set on `kernel`, in use. */
129
+ setUniforms(kernel, filters, i, host) {
130
+ const v = filters.values;
131
+ const at = filters.start[i];
132
+ const count = v[at + 7];
133
+ let unit = 0;
134
+ for (let k = 0; k < count; k++) {
135
+ const id = v[at + 9 + k * 3];
136
+ if (id >= 0) {
137
+ this.bindImage(kernel.at(`pbImage${v[at + 8 + k * 3]}`), unit++, id, host);
138
+ }
139
+ }
140
+ const floats = at + 8 + count * 3;
141
+ if (v[floats] > 0) {
142
+ this.gl.uniform4fv(kernel.at("pbFloats"), v, floats + 1, v[floats]);
143
+ }
144
+ const ints = filters.intStart[i];
145
+ const n = filters.intStart[i + 1] - ints;
146
+ if (n > 0) {
147
+ this.setInts(kernel.at("pbInts"), filters.ints, ints, n);
148
+ }
149
+ }
150
+ /** Every program deleted, as the backend goes; none kept, as a lost context comes back. */
151
+ clear() {
152
+ for (const kernel of this.programs.values()) {
153
+ if (kernel) {
154
+ this.gl.deleteProgram(kernel.program);
155
+ }
156
+ }
157
+ this.programs.clear();
158
+ }
159
+ }
160
+ //# sourceMappingURL=kernels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernels.js","sourceRoot":"","sources":["../../src/webgl/kernels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,WAAW,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGl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size, and the frame it was last freed in; where
3
+ * it may be used as smaller than it is, its own size, which it is pooled by.
4
+ */
5
+ export interface Pooled {
6
+ width: number;
7
+ height: number;
8
+ textureWidth?: number;
9
+ textureHeight?: number;
10
+ usedAt: number;
11
+ }
12
+ /**
13
+ * Free targets kept by their size (and samples) for the next to take them:
14
+ * an exact one found at once, a larger one among the sizes there are, each
15
+ * size's list in the order they were freed. A frame's end lets go of those
16
+ * idle too long, then of the least lately freed past a budget, oldest first
17
+ * from the lists' heads, as the frame's own working set may pass it for a
18
+ * while without what it gives back being made again.
19
+ */
20
+ export declare class SizedPool<T extends Pooled> {
21
+ private readonly lists;
22
+ private readonly bytesOf;
23
+ /** The bytes all held take together. */
24
+ bytes: number;
25
+ constructor(bytesOf: (item: T) => number);
26
+ /** One of just `width` by `height` (and `samples`), the latest freed; none for none. */
27
+ take(width: number, height: number, samples?: number): T | null;
28
+ /** The smallest target that fits, at these samples and within `maxArea`; none for none. */
29
+ takeFitting(width: number, height: number, samples?: number, maxArea?: number): T | null;
30
+ private takeAt;
31
+ /** `item` free again, freed in frame `frame`, of `samples` where they count. */
32
+ give(item: T, frame: number, samples?: number): void;
33
+ /**
34
+ * Those freed more than `idle` frames before `frame` let go of, then the
35
+ * least lately freed till they take `budget` bytes at most, each `drop`ped.
36
+ */
37
+ trim(frame: number, idle: number, budget: number, drop: (item: T) => void): void;
38
+ /** Those freed more than `idle` frames before `frame` let go of, each `drop`ped. */
39
+ trimIdle(frame: number, idle: number, drop: (item: T) => void): void;
40
+ /**
41
+ * The key of the list whose head goes first past a budget: the least
42
+ * lately freed, and of those freed in one frame the largest, so that as
43
+ * few go as may; -1 for none.
44
+ */
45
+ firstOut(): number;
46
+ /** The head of list `key` (firstOut), as `firstOut` found it. */
47
+ headOf(key: number): T;
48
+ /** The head of list `key` (firstOut) let go of, `drop`ped. */
49
+ dropHead(key: number, drop: (item: T) => void): void;
50
+ /** The bytes those freed in frame `frame` take, which that frame drew with. */
51
+ bytesFreedIn(frame: number): number;
52
+ /** The bytes `item` takes, as this pool counts them. */
53
+ bytesFor(item: T): number;
54
+ /** Every one held let go of, as the context goes. */
55
+ clear(drop: (item: T) => void): void;
56
+ }
57
+ /** A pool and how what it lets go of is deleted. */
58
+ interface Trimmed {
59
+ pool: SizedPool<any>;
60
+ drop: (item: any) => void;
61
+ }
62
+ /**
63
+ * `pools` let go of till together they take `budget` bytes at most: the
64
+ * least lately freed of all first, of those freed in one frame the
65
+ * largest. One budget for all, as trimming one pool against what another
66
+ * holds dropped a frame's own small layers while large multisampled
67
+ * buffers idle for many frames stayed, each frame making them again.
68
+ */
69
+ export declare function trimTogether(pools: readonly Trimmed[], budget: number): void;
70
+ export {};
71
+ //# sourceMappingURL=pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/webgl/pool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB;AAMD;;;;;;;GAOG;AACH,qBAAa,SAAS,CAAC,CAAC,SAAS,MAAM;IACrC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA0B;IAChD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAC9C,wCAAwC;IACxC,KAAK,SAAK;IAEV,YAAY,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,EAEvC;IAED,wFAAwF;IACxF,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,SAAI,GAAG,CAAC,GAAG,IAAI,CAEzD;IAED,2FAA2F;IAC3F,WAAW,CACT,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,SAAI,EACX,OAAO,SAA2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-0,0 +1,192 @@
1
+ /** What a size, and samples where they count, are keyed by. */
2
+ const SIZE_KEY = 65536;
3
+ const SAMPLES_KEY = 32;
4
+ /**
5
+ * Free targets kept by their size (and samples) for the next to take them:
6
+ * an exact one found at once, a larger one among the sizes there are, each
7
+ * size's list in the order they were freed. A frame's end lets go of those
8
+ * idle too long, then of the least lately freed past a budget, oldest first
9
+ * from the lists' heads, as the frame's own working set may pass it for a
10
+ * while without what it gives back being made again.
11
+ */
12
+ export class SizedPool {
13
+ lists = new Map();
14
+ bytesOf;
15
+ /** The bytes all held take together. */
16
+ bytes = 0;
17
+ constructor(bytesOf) {
18
+ this.bytesOf = bytesOf;
19
+ }
20
+ /** One of just `width` by `height` (and `samples`), the latest freed; none for none. */
21
+ take(width, height, samples = 0) {
22
+ return this.takeAt((width * SIZE_KEY + height) * SAMPLES_KEY + samples);
23
+ }
24
+ /** The smallest target that fits, at these samples and within `maxArea`; none for none. */
25
+ takeFitting(width, height, samples = 0, maxArea = Number.POSITIVE_INFINITY) {
26
+ let best = -1;
27
+ let least = Number.POSITIVE_INFINITY;
28
+ for (const key of this.lists.keys()) {
29
+ const size = Math.floor(key / SAMPLES_KEY);
30
+ const w = Math.floor(size / SIZE_KEY);
31
+ const h = size % SIZE_KEY;
32
+ if (key % SAMPLES_KEY === samples &&
33
+ w >= width &&
34
+ h >= height &&
35
+ w * h <= maxArea &&
36
+ w * h < least) {
37
+ least = w * h;
38
+ best = key;
39
+ }
40
+ }
41
+ return best < 0 ? null : this.takeAt(best);
42
+ }
43
+ takeAt(key) {
44
+ const list = this.lists.get(key);
45
+ const item = list?.pop() ?? null;
46
+ if (!item) {
47
+ return null;
48
+ }
49
+ // An emptied size goes, so that finding a larger one looks at those held alone.
50
+ if (list.length === 0) {
51
+ this.lists.delete(key);
52
+ }
53
+ this.bytes -= this.bytesOf(item);
54
+ return item;
55
+ }
56
+ /** `item` free again, freed in frame `frame`, of `samples` where they count. */
57
+ give(item, frame, samples = 0) {
58
+ item.usedAt = frame;
59
+ const key = ((item.textureWidth ?? item.width) * SIZE_KEY + (item.textureHeight ?? item.height)) *
60
+ SAMPLES_KEY +
61
+ samples;
62
+ let list = this.lists.get(key);
63
+ if (!list) {
64
+ list = [];
65
+ this.lists.set(key, list);
66
+ }
67
+ list.push(item);
68
+ this.bytes += this.bytesOf(item);
69
+ }
70
+ /**
71
+ * Those freed more than `idle` frames before `frame` let go of, then the
72
+ * least lately freed till they take `budget` bytes at most, each `drop`ped.
73
+ */
74
+ trim(frame, idle, budget, drop) {
75
+ this.trimIdle(frame, idle, drop);
76
+ trimTogether([{ pool: this, drop }], budget);
77
+ }
78
+ /** Those freed more than `idle` frames before `frame` let go of, each `drop`ped. */
79
+ trimIdle(frame, idle, drop) {
80
+ for (const [key, list] of this.lists) {
81
+ let gone = 0;
82
+ while (gone < list.length && frame - list[gone].usedAt > idle) {
83
+ this.bytes -= this.bytesOf(list[gone]);
84
+ drop(list[gone]);
85
+ gone++;
86
+ }
87
+ if (gone === list.length) {
88
+ this.lists.delete(key);
89
+ }
90
+ else if (gone > 0) {
91
+ list.splice(0, gone);
92
+ }
93
+ }
94
+ }
95
+ /**
96
+ * The key of the list whose head goes first past a budget: the least
97
+ * lately freed, and of those freed in one frame the largest, so that as
98
+ * few go as may; -1 for none.
99
+ */
100
+ firstOut() {
101
+ let best = -1;
102
+ let bestAt = 0;
103
+ let bestBytes = 0;
104
+ for (const [key, list] of this.lists) {
105
+ const head = list[0];
106
+ const bytes = this.bytesOf(head);
107
+ if (best < 0 || head.usedAt < bestAt || (head.usedAt === bestAt && bytes > bestBytes)) {
108
+ best = key;
109
+ bestAt = head.usedAt;
110
+ bestBytes = bytes;
111
+ }
112
+ }
113
+ return best;
114
+ }
115
+ /** The head of list `key` (firstOut), as `firstOut` found it. */
116
+ headOf(key) {
117
+ return this.lists.get(key)[0];
118
+ }
119
+ /** The head of list `key` (firstOut) let go of, `drop`ped. */
120
+ dropHead(key, drop) {
121
+ const list = this.lists.get(key);
122
+ const item = list.shift();
123
+ this.bytes -= this.bytesOf(item);
124
+ drop(item);
125
+ if (list.length === 0) {
126
+ this.lists.delete(key);
127
+ }
128
+ }
129
+ /** The bytes those freed in frame `frame` take, which that frame drew with. */
130
+ bytesFreedIn(frame) {
131
+ let bytes = 0;
132
+ for (const list of this.lists.values()) {
133
+ for (let i = list.length - 1; i >= 0 && list[i].usedAt === frame; i--) {
134
+ bytes += this.bytesOf(list[i]);
135
+ }
136
+ }
137
+ return bytes;
138
+ }
139
+ /** The bytes `item` takes, as this pool counts them. */
140
+ bytesFor(item) {
141
+ return this.bytesOf(item);
142
+ }
143
+ /** Every one held let go of, as the context goes. */
144
+ clear(drop) {
145
+ for (const list of this.lists.values()) {
146
+ for (const item of list) {
147
+ drop(item);
148
+ }
149
+ }
150
+ this.lists.clear();
151
+ this.bytes = 0;
152
+ }
153
+ }
154
+ /**
155
+ * `pools` let go of till together they take `budget` bytes at most: the
156
+ * least lately freed of all first, of those freed in one frame the
157
+ * largest. One budget for all, as trimming one pool against what another
158
+ * holds dropped a frame's own small layers while large multisampled
159
+ * buffers idle for many frames stayed, each frame making them again.
160
+ */
161
+ export function trimTogether(pools, budget) {
162
+ let bytes = 0;
163
+ for (const { pool } of pools) {
164
+ bytes += pool.bytes;
165
+ }
166
+ while (bytes > budget) {
167
+ let from = null;
168
+ let key = -1;
169
+ let at = 0;
170
+ let size = 0;
171
+ for (const trimmed of pools) {
172
+ const k = trimmed.pool.firstOut();
173
+ if (k < 0) {
174
+ continue;
175
+ }
176
+ const head = trimmed.pool.headOf(k);
177
+ const headBytes = trimmed.pool.bytesFor(head);
178
+ if (!from || head.usedAt < at || (head.usedAt === at && headBytes > size)) {
179
+ from = trimmed;
180
+ key = k;
181
+ at = head.usedAt;
182
+ size = headBytes;
183
+ }
184
+ }
185
+ if (!from) {
186
+ break;
187
+ }
188
+ bytes -= size;
189
+ from.pool.dropHead(key, from.drop);
190
+ }
191
+ }
192
+ //# sourceMappingURL=pool.js.map
@@ -0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ACb,KAAK,MAAM,OAAO,IAAI,KAAK,EAAE,CAAC;YAC5B,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;gBACV,SAAS;YACX,CAAC;YAED,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACpC,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC9C,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,EAAE,IAAI,SAAS,GAAG,IAAI,CAAC,EAAE,CAAC;gBAC1E,IAAI,GAAG,OAAO,CAAC;gBACf,GAAG,GAAG,CAAC,CAAC;gBACR,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;gBACjB,IAAI,GAAG,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;QAED,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM;QACR,CAAC;QAED,KAAK,IAAI,IAAI,CAAC;QACd,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;AACH,CAAC"}
@@ -0,0 +1,130 @@
1
+ /** Texels a row (ROW_FLOATS over four). */
2
+ export declare const ROW_TEXELS = 4;
3
+ /**
4
+ * The vertex atlas' attributes, where both the fill and the mesh programs
5
+ * read them: a mesh's depth is the four bytes of its colour, as a float.
6
+ */
7
+ export declare const POSITION_AT = 0;
8
+ export declare const TEXEL_AT = 1;
9
+ export declare const COLOR_AT = 2;
10
+ export declare const DEPTH_AT = 3;
11
+ /** Advanced text's glyph quads' attributes past their position (GeometryData.glyphs), in theirs. */
12
+ export declare const ORIGIN_AT = 4;
13
+ export declare const GLYPH_AT = 5;
14
+ export declare const RUN_AT = 6;
15
+ export declare const TINT_AT = 7;
16
+ /** The most cutoff table entries a text's draw takes, as the player's text/saffron.ts builds them. */
17
+ export declare const TABLE_ENTRIES = 48;
18
+ /** Segments a row of the outlines' texture, as the player's text/saffron.ts stores them. */
19
+ export declare const OUTLINE_ROW = 1024;
20
+ /**
21
+ * The most draws a multi-draw of the fill program makes, their rows in its
22
+ * integer texture, a line of it. A power of two: the vertex shader splits a
23
+ * draw's place in the table into column and line with a mask and a shift.
24
+ */
25
+ export declare const RUN_MOST = 256;
26
+ /** Textures the fill program samples in one draw call, each on a unit of its own. */
27
+ export declare const FILL_TEXTURES = 8;
28
+ /**
29
+ * A fill draw's row and how it is drawn, in one int: the row in the bits
30
+ * below FILL_SLOT, then which of the fill program's textures it samples, one
31
+ * past its index or 0 for none, then SNAP_BIT where it snaps (SNAP). Rows
32
+ * are fewer: ROWS_A_LINE to a line of a texture of at most 16384 lines.
33
+ */
34
+ export declare const FILL_SLOT = 24;
35
+ export declare const SNAP_BIT: number;
36
+ /** The texture unit a mesh's texture is bound to, and textures are uploaded on; the rows are on 0. */
37
+ export declare const TEXTURE_UNIT = 1;
38
+ /** The units a composite reads its layer and what is below from. */
39
+ export declare const LAYER_UNIT = 2;
40
+ export declare const BACK_UNIT = 3;
41
+ /** The unit advanced text's outlines are on (uploadOutlines); the filters take 4 to 6. */
42
+ export declare const OUTLINE_UNIT = 7;
43
+ /** The first of the units the fill program's textures are bound to (FILL_TEXTURES). */
44
+ export declare const FILL_UNIT = 8;
45
+ /** The multi-draw row table's unit, past the fill textures. */
46
+ export declare const RUN_UNIT: number;
47
+ /**
48
+ * Places a vertex by its row's transform, on a quarter of a pixel of
49
+ * Flash's (uUnit of them a stage pixel, from the stage's origin) where it
50
+ * snaps (SNAP), then on the target by uView (scale and offset into clip
51
+ * space), and passes on its straight colour, the row's colour transform
52
+ * and the texture it samples. uRow names the draw's row (FILL_SLOT); with
53
+ * `multi` (WEBGL_multi_draw), uRunTable names each draw's of a multi-draw by
54
+ * gl_DrawID, which is 0 in a draw of its own.
55
+ */
56
+ export declare const fillVertex: (multi: boolean) => string;
57
+ /**
58
+ * Flash's colour transform on the straight colour, clamped, then
59
+ * premultiplied for blending: the vertex' colour, or with a texture the
60
+ * texel's (premultiplied in the texture) times it, as the colour batcher
61
+ * did, a clear texel staying clear.
62
+ */
63
+ export declare const fillFragment: string;
64
+ /**
65
+ * drawTriangles' textured triangles (MESH), placed as fills are, their u
66
+ * and v carried times their depth t, and t, which the GPU interpolates
67
+ * straight across the screen for each pixel to divide.
68
+ */
69
+ export declare const meshVertex: string;
70
+ /**
71
+ * drawTriangles' bitmap as adl samples it: u and v from 0 to 1 onto the first
72
+ * texel's centre to the last's, wrapped into that or clamped to it, read
73
+ * once a pixel of Flash's, at its top left corner; not smoothed, the nearer
74
+ * texel, the lower of two as near; smoothed, the four around, weighed.
75
+ * uFrag takes a fragment to the target's pixels from the stage's origin,
76
+ * down (x + uFrag.x, uFrag.y + uFrag.z * y), and is a pixel of Flash's
77
+ * that many of them (w). uMode: whether it repeats, whether it is smoothed,
78
+ * and whether it is a 3D object's quad (PLANE), which reads its bitmap
79
+ * otherwise. The colour transform then as on a fill.
80
+ */
81
+ export declare const meshFragment = "#version 300 es\nprecision highp float;\nin vec3 vUVT;\nflat in vec4 vMul;\nflat in vec4 vAdd;\nuniform sampler2D uTexture;\nuniform vec4 uFrag;\nuniform ivec3 uMode;\nout vec4 finalColor;\n\nvec4 texel(ivec2 at) {\n return texelFetch(uTexture, at, 0);\n}\n\nvoid main(void) {\n float pixel = uFrag.w;\n vec2 f = vec2(gl_FragCoord.x + uFrag.x, uFrag.y + uFrag.z * gl_FragCoord.y);\n vec2 size = vec2(textureSize(uTexture, 0));\n if (uMode.z != 0) {\n // A 3D object's quad (PLANE): its bitmap read smoothed at the pixel's centre, in its texels.\n vec2 centre = (floor(f / pixel) + 0.5) * pixel;\n vec3 at = vUVT + dFdx(vUVT) * (centre.x - f.x) + dFdy(vUVT) * ((centre.y - f.y) * uFrag.z);\n vec4 shown = texture(uTexture, (at.z != 0.0 ? at.xy / at.z : vec2(0.0)) / size);\n if (shown.a == 0.0) {\n finalColor = vec4(0.0);\n return;\n }\n\n vec4 s = clamp(vec4(shown.rgb / shown.a, shown.a) * vMul + vAdd, 0.0, 1.0);\n finalColor = vec4(s.rgb * s.a, s.a);\n return;\n }\n\n vec2 corner = floor(f / pixel) * pixel;\n vec3 uvt = vUVT + dFdx(vUVT) * (corner.x - f.x) + dFdy(vUVT) * ((corner.y - f.y) * uFrag.z);\n vec2 uv = uvt.z != 0.0 ? uvt.xy / uvt.z : vec2(0.0);\n // As adl draws one, a bitmap a texel high shows its first texel throughout.\n if (size.y == 1.0) {\n uv = vec2(0.0);\n }\n\n // A hair nearer 0, as adl's come out, stepped across the triangle in fixed point: 1 wraps to\n // the last texel, not the first, and a corner halfway between texels takes the one nearer 0.\n uv -= sign(uv) / 16384.0;\n uv = uMode.x != 0 ? fract(uv) : clamp(uv, 0.0, 1.0);\n vec2 p = uv * (size - 1.0);\n vec4 color;\n if (uMode.y != 0) {\n vec2 below = floor(p);\n vec2 w = p - below;\n ivec2 a = ivec2(below);\n ivec2 b = min(a + 1, ivec2(size) - 1);\n color = mix(\n mix(texel(a), texel(ivec2(b.x, a.y)), w.x),\n mix(texel(ivec2(a.x, b.y)), texel(b), w.x),\n w.y\n );\n } else {\n color = texel(ivec2(floor(p + 0.5)));\n }\n\n if (color.a == 0.0) {\n finalColor = vec4(0.0);\n return;\n }\n\n vec4 c = clamp(vec4(color.rgb / color.a, color.a) * vMul + vAdd, 0.0, 1.0);\n finalColor = vec4(c.rgb * c.a, c.a);\n}\n";
82
+ /**
83
+ * Advanced text's glyph quads (player's text/saffron.ts), placed by the
84
+ * row's transform: the text's
85
+ * pixels to Flash's, uUnit of them a stage pixel, on their grid from the
86
+ * stage's origin, a BitmapData's in a draw. A glyph's pen stands where its
87
+ * text's origin, at a whole pixel, puts it, snapped as its grid fits it
88
+ * (uMode: gridFitType 0 none, 1 pixel, 2 subpixel, thickness, sharpness),
89
+ * and its quad reaches out past its outline by the furthest cutoff. Its
90
+ * colour is drawn under the row's colour transform, light or dark as adl
91
+ * chooses its table. aOrigin: the pen, and its light and dark tables, each
92
+ * its first entry plus 64 times its entries; aGlyph: a corner of its
93
+ * outline's bounds and the way out from it; aRun: its segments, first and
94
+ * count, the pixels of a unit of its outline, and its size.
95
+ */
96
+ export declare const glyphsVertex: string;
97
+ /**
98
+ * Each pixel of Flash's a glyph's quad covers, by its signed distance to
99
+ * the glyph's outline (the segments of its run in uSegments, the nearest
100
+ * and, by parity, whether it is inside), between the cutoffs, as Saffron
101
+ * covers it. Nothing outside: in a mask, which
102
+ * writes the stencil wherever it draws, a glyph is its shape.
103
+ */
104
+ export declare const glyphsFragment: string;
105
+ /**
106
+ * Two triangles over a layer's rectangle of the target, uRect its corners
107
+ * in clip space: a rasteriser then steps over those pixels alone, as a
108
+ * software one does not for a triangle over the whole target cut by the
109
+ * scissor.
110
+ */
111
+ export declare const compositeVertex = "#version 300 es\nuniform vec4 uRect;\nvoid main(void) {\n int k = gl_VertexID;\n vec2 p = vec2(k == 1 || k == 2 || k == 4 ? 1.0 : 0.0, k == 2 || k == 4 || k == 5 ? 1.0 : 0.0);\n gl_Position = vec4(mix(uRect.xy, uRect.zw, p), 0.0, 1.0);\n}\n";
112
+ /** A composited layer's pixel, `front`, coloured by its row's colour transform where it has one (uRow not -1). */
113
+ export declare const LAYER_COLOR: string;
114
+ /**
115
+ * A layer composited onto what is below over its rectangle, pixel for
116
+ * pixel: its rows run down, as the filters read them, and the target's up
117
+ * where it is the canvas (uFlip), from uOffset in its framebuffer. Coloured
118
+ * by its row's colour transform where it has one (uRow not -1), on its
119
+ * straight colour where it covers anything; then blended by its mode
120
+ * (BLEND_FRONT).
121
+ */
122
+ export declare const compositeFragment: string;
123
+ /**
124
+ * A fill drawn straight onto what is below it in a blend mode, where its
125
+ * layer would hold it alone (a flat fill, GeometryData.flat): its pixel as
126
+ * fillFragment has it, then as compositeFragment composites its layer's,
127
+ * coloured by the layer's row (uLayerRow, -1 for none) and blended by uMode.
128
+ */
129
+ export declare const blendFillFragment: string;
130
+ //# sourceMappingURL=programs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"programs.d.ts","sourceRoot":"","sources":["../../src/webgl/programs.ts"],"names":[],"mappings":"AAkBA,2CAA2C;AAC3C,eAAO,MAAM,UAAU,IAAI,CAAC;AAE5B;;;GAGG;AACH,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,QAAQ,IAAI,CAAC;AAC1B,eAAO,MAAM,QAAQ,IAAI,CAAC;AAC1B,eAAO,MAAM,QAAQ,IAAI,CAAC;AAC1B,oGAAoG;AACpG,eAAO,MAAM,SAAS,IAAI,CAAC;AAC3B,eAAO,MAAM,QAAQ,IAAI,CAAC;AAC1B,eAAO,MAAM,MAAM,IAAI,CAAC;AACxB,eAAO,MAAM,OAAO,IAAI,CAAC;AAEzB,sGAAsG;AACtG,eAAO,MAAM,aAAa,KAAK,CAAC;AAChC,4FAA4F;AAC5F,eAAO,MAAM,WAAW,OAAO,CAAC;AAEhC;;;;GAIG;AACH,eAAO,MAAM,QAAQ,MAAM,CAAC;AAE5B,qFAAqF;AACrF,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B;;;;;GAKG;AACH,eAAO,MAAM,SAAS,KAAK,CAAC;AAC5B,eAAO,MAAM,QAAQ,QAAU,CAAC;AAEhC,sGAAsG;AACtG,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,oEAAoE;AACpE,eAAO,MAAM,UAAU,IAAI,CAAC;AAC5B,eAAO,MAAM,SAAS,IAAI,CAAC;AAC3B,0FAA0F;AAC1F,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,uFAAuF;AACvF,eAAO,MAAM,SAAS,IAAI,CAAC;AAC3B,+DAA+D;AAC/D,eAAO,MAAM,QAAQ,QAA4B,CAAC;AAElD;;;;;;;;GAQG;AACH,eAAO,MAAM,UAA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