@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.
- package/LICENSE +202 -0
- package/README.md +17 -2
- package/dist/commands.d.ts +67 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +93 -0
- package/dist/commands.js.map +1 -0
- package/dist/filter-plan.d.ts +110 -0
- package/dist/filter-plan.d.ts.map +1 -0
- package/dist/filter-plan.js +480 -0
- package/dist/filter-plan.js.map +1 -0
- package/dist/filter-shaders.d.ts +63 -0
- package/dist/filter-shaders.d.ts.map +1 -0
- package/dist/filter-shaders.js +350 -0
- package/dist/filter-shaders.js.map +1 -0
- package/dist/filters.d.ts +107 -0
- package/dist/filters.d.ts.map +1 -0
- package/dist/filters.js +187 -0
- package/dist/filters.js.map +1 -0
- package/dist/geometry.d.ts +83 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +93 -0
- package/dist/geometry.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/keeps.d.ts +17 -0
- package/dist/keeps.d.ts.map +1 -0
- package/dist/keeps.js +17 -0
- package/dist/keeps.js.map +1 -0
- package/dist/kernel-shaders.d.ts +74 -0
- package/dist/kernel-shaders.d.ts.map +1 -0
- package/dist/kernel-shaders.js +323 -0
- package/dist/kernel-shaders.js.map +1 -0
- package/dist/measure.d.ts +56 -0
- package/dist/measure.d.ts.map +1 -0
- package/dist/measure.js +287 -0
- package/dist/measure.js.map +1 -0
- package/dist/plan.d.ts +14 -0
- package/dist/plan.d.ts.map +1 -0
- package/dist/plan.js +247 -0
- package/dist/plan.js.map +1 -0
- package/dist/registry.d.ts +49 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +87 -0
- package/dist/registry.js.map +1 -0
- package/dist/rows.d.ts +39 -0
- package/dist/rows.d.ts.map +1 -0
- package/dist/rows.js +60 -0
- package/dist/rows.js.map +1 -0
- package/dist/scene.d.ts +179 -0
- package/dist/scene.d.ts.map +1 -0
- package/dist/scene.js +265 -0
- package/dist/scene.js.map +1 -0
- package/dist/shelves.d.ts +23 -0
- package/dist/shelves.d.ts.map +1 -0
- package/dist/shelves.js +63 -0
- package/dist/shelves.js.map +1 -0
- package/dist/textures.d.ts +72 -0
- package/dist/textures.d.ts.map +1 -0
- package/dist/textures.js +160 -0
- package/dist/textures.js.map +1 -0
- package/dist/webgl/atlas.d.ts +63 -0
- package/dist/webgl/atlas.d.ts.map +1 -0
- package/dist/webgl/atlas.js +328 -0
- package/dist/webgl/atlas.js.map +1 -0
- package/dist/webgl/backend.d.ts +141 -0
- package/dist/webgl/backend.d.ts.map +1 -0
- package/dist/webgl/backend.js +659 -0
- package/dist/webgl/backend.js.map +1 -0
- package/dist/webgl/composite.d.ts +101 -0
- package/dist/webgl/composite.d.ts.map +1 -0
- package/dist/webgl/composite.js +293 -0
- package/dist/webgl/composite.js.map +1 -0
- package/dist/webgl/draws.d.ts +213 -0
- package/dist/webgl/draws.d.ts.map +1 -0
- package/dist/webgl/draws.js +714 -0
- package/dist/webgl/draws.js.map +1 -0
- package/dist/webgl/filters.d.ts +107 -0
- package/dist/webgl/filters.d.ts.map +1 -0
- package/dist/webgl/filters.js +351 -0
- package/dist/webgl/filters.js.map +1 -0
- package/dist/webgl/gpu-textures.d.ts +44 -0
- package/dist/webgl/gpu-textures.d.ts.map +1 -0
- package/dist/webgl/gpu-textures.js +178 -0
- package/dist/webgl/gpu-textures.js.map +1 -0
- package/dist/webgl/holds.d.ts +97 -0
- package/dist/webgl/holds.d.ts.map +1 -0
- package/dist/webgl/holds.js +453 -0
- package/dist/webgl/holds.js.map +1 -0
- package/dist/webgl/index.d.ts +2 -0
- package/dist/webgl/index.d.ts.map +1 -0
- package/dist/webgl/index.js +4 -0
- package/dist/webgl/index.js.map +1 -0
- package/dist/webgl/kernels.d.ts +64 -0
- package/dist/webgl/kernels.d.ts.map +1 -0
- package/dist/webgl/kernels.js +160 -0
- package/dist/webgl/kernels.js.map +1 -0
- package/dist/webgl/pool.d.ts +71 -0
- package/dist/webgl/pool.d.ts.map +1 -0
- package/dist/webgl/pool.js +192 -0
- package/dist/webgl/pool.js.map +1 -0
- package/dist/webgl/programs.d.ts +130 -0
- package/dist/webgl/programs.d.ts.map +1 -0
- package/dist/webgl/programs.js +582 -0
- package/dist/webgl/programs.js.map +1 -0
- package/dist/webgl/stage.d.ts +67 -0
- package/dist/webgl/stage.d.ts.map +1 -0
- package/dist/webgl/stage.js +173 -0
- package/dist/webgl/stage.js.map +1 -0
- package/dist/webgl/targets.d.ts +172 -0
- package/dist/webgl/targets.d.ts.map +1 -0
- package/dist/webgl/targets.js +323 -0
- package/dist/webgl/targets.js.map +1 -0
- package/package.json +35 -3
- package/src/commands.ts +98 -0
- package/src/filter-plan.ts +755 -0
- package/src/filter-shaders.ts +360 -0
- package/src/filters.ts +220 -0
- package/src/geometry.ts +143 -0
- package/src/index.ts +87 -0
- package/src/keeps.ts +21 -0
- package/src/kernel-shaders.ts +375 -0
- package/src/measure.ts +400 -0
- package/src/plan.ts +331 -0
- package/src/registry.ts +105 -0
- package/src/rows.ts +93 -0
- package/src/scene.ts +297 -0
- package/src/shelves.ts +70 -0
- package/src/textures.ts +198 -0
- package/src/webgl/atlas.ts +370 -0
- package/src/webgl/backend.ts +973 -0
- package/src/webgl/composite.ts +372 -0
- package/src/webgl/draws.ts +902 -0
- package/src/webgl/filters.ts +502 -0
- package/src/webgl/gpu-textures.ts +253 -0
- package/src/webgl/holds.ts +624 -0
- package/src/webgl/index.ts +3 -0
- package/src/webgl/kernels.ts +205 -0
- package/src/webgl/pool.ts +245 -0
- package/src/webgl/programs.ts +620 -0
- package/src/webgl/stage.ts +214 -0
- package/src/webgl/targets.ts +464 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { ROW_FLOATS, ROWS_A_LINE } from "../rows.js";
|
|
2
|
+
import { MIRROR, REPEAT, SMOOTH } from "../scene.js";
|
|
3
|
+
import { OUTLINE_ROW, OUTLINE_UNIT, ROW_TEXELS, TEXTURE_UNIT } from "./programs.js";
|
|
4
|
+
/**
|
|
5
|
+
* The textures the programs read: the registry's, uploaded as they are
|
|
6
|
+
* added or change, and the samplers they are read through; the rows, a
|
|
7
|
+
* float texture uploaded once a frame; and advanced text's outlines.
|
|
8
|
+
*/
|
|
9
|
+
export class GpuTextures {
|
|
10
|
+
gl;
|
|
11
|
+
state;
|
|
12
|
+
/** The textures uploaded, by the registry's ids, and their sizes; the samplers made, by their bits. */
|
|
13
|
+
textures = [];
|
|
14
|
+
sizes = [];
|
|
15
|
+
samplers = [];
|
|
16
|
+
rowsTexture;
|
|
17
|
+
rowLines = 0;
|
|
18
|
+
/** Advanced text's outlines (uploadOutlines), on OUTLINE_UNIT for the glyph program. */
|
|
19
|
+
outlines = null;
|
|
20
|
+
/** The outlines uploaded: of which epoch, how many segments, and the texture's rows. */
|
|
21
|
+
outlineEpoch = -1;
|
|
22
|
+
outlineCount = 0;
|
|
23
|
+
outlineRows = 0;
|
|
24
|
+
constructor(gl, state) {
|
|
25
|
+
this.gl = gl;
|
|
26
|
+
this.state = state;
|
|
27
|
+
}
|
|
28
|
+
/** The rows' texture made, and none other yet, as the context comes or comes back. */
|
|
29
|
+
setUp() {
|
|
30
|
+
const gl = this.gl;
|
|
31
|
+
this.outlines = null;
|
|
32
|
+
this.outlineEpoch = -1;
|
|
33
|
+
this.outlineCount = 0;
|
|
34
|
+
this.outlineRows = 0;
|
|
35
|
+
this.textures = [];
|
|
36
|
+
this.samplers = [];
|
|
37
|
+
this.rowsTexture = gl.createTexture();
|
|
38
|
+
this.state.bindTexture(0, this.rowsTexture);
|
|
39
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
40
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
41
|
+
this.rowLines = 0;
|
|
42
|
+
}
|
|
43
|
+
/** Whether texture `id` of the frame's is there, for a filter that reads it. */
|
|
44
|
+
hasTexture = (id) => id >= 0 && (this.textures[id] ?? null) !== null;
|
|
45
|
+
/**
|
|
46
|
+
* Advanced text's outlines (GeometryData.glyphs), `count` segments of four floats each
|
|
47
|
+
* in `data`, as the player's store holds them: uploaded whole for another
|
|
48
|
+
* `epoch` or a larger store, else the rows added since.
|
|
49
|
+
*/
|
|
50
|
+
uploadOutlines(data, count, epoch) {
|
|
51
|
+
const gl = this.gl;
|
|
52
|
+
if (gl.isContextLost() || count === 0) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const rows = data.length / 4 / OUTLINE_ROW;
|
|
56
|
+
let from = epoch === this.outlineEpoch ? this.outlineCount : 0;
|
|
57
|
+
if (!this.outlines || rows !== this.outlineRows) {
|
|
58
|
+
if (this.outlines) {
|
|
59
|
+
this.state.dropTexture(this.outlines);
|
|
60
|
+
gl.deleteTexture(this.outlines);
|
|
61
|
+
}
|
|
62
|
+
this.outlines = gl.createTexture();
|
|
63
|
+
this.state.bindTexture(OUTLINE_UNIT, this.outlines);
|
|
64
|
+
this.state.activeTexture(OUTLINE_UNIT);
|
|
65
|
+
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA32F, OUTLINE_ROW, rows);
|
|
66
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
67
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
68
|
+
this.outlineRows = rows;
|
|
69
|
+
from = 0;
|
|
70
|
+
}
|
|
71
|
+
if (from < count) {
|
|
72
|
+
const first = Math.floor(from / OUTLINE_ROW);
|
|
73
|
+
const height = Math.ceil(count / OUTLINE_ROW) - first;
|
|
74
|
+
this.state.bindTexture(OUTLINE_UNIT, this.outlines);
|
|
75
|
+
this.state.activeTexture(OUTLINE_UNIT);
|
|
76
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, first, OUTLINE_ROW, height, gl.RGBA, gl.FLOAT, data, first * OUTLINE_ROW * 4);
|
|
77
|
+
}
|
|
78
|
+
this.outlineEpoch = epoch;
|
|
79
|
+
this.outlineCount = count;
|
|
80
|
+
}
|
|
81
|
+
/** The textures removed since the last frame deleted, and those added or changed uploaded, their pixels let go. */
|
|
82
|
+
uploadTextures(textures) {
|
|
83
|
+
const gl = this.gl;
|
|
84
|
+
for (const id of textures.removed) {
|
|
85
|
+
const texture = this.textures[id];
|
|
86
|
+
if (texture) {
|
|
87
|
+
this.state.dropTexture(texture);
|
|
88
|
+
gl.deleteTexture(texture);
|
|
89
|
+
this.textures[id] = null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
textures.removed.length = 0;
|
|
93
|
+
for (const id of textures.pending) {
|
|
94
|
+
const data = textures.get(id);
|
|
95
|
+
if (!data?.pixels) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
let texture = this.textures[id];
|
|
99
|
+
if (!texture) {
|
|
100
|
+
texture = gl.createTexture();
|
|
101
|
+
this.textures[id] = texture;
|
|
102
|
+
this.sizes[id * 2] = -1;
|
|
103
|
+
}
|
|
104
|
+
this.state.bindTexture(TEXTURE_UNIT, texture);
|
|
105
|
+
this.state.activeTexture(TEXTURE_UNIT);
|
|
106
|
+
// Floats, a kernel's image, make the texture again each time, as bytes may follow them.
|
|
107
|
+
if (data.pixels instanceof Float32Array) {
|
|
108
|
+
this.sizes[id * 2] = -1;
|
|
109
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, data.width, data.height, 0, gl.RGBA, gl.FLOAT, data.pixels);
|
|
110
|
+
data.pixels = null;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
// Pixels of the same size go into the texture there is; another size makes it again.
|
|
114
|
+
if (this.sizes[id * 2] === data.width && this.sizes[id * 2 + 1] === data.height) {
|
|
115
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, data.width, data.height, gl.RGBA, gl.UNSIGNED_BYTE, data.pixels);
|
|
116
|
+
data.pixels = null;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
this.sizes[id * 2] = data.width;
|
|
120
|
+
this.sizes[id * 2 + 1] = data.height;
|
|
121
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, data.width, data.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, data.pixels);
|
|
122
|
+
data.pixels = null;
|
|
123
|
+
}
|
|
124
|
+
textures.pending.length = 0;
|
|
125
|
+
}
|
|
126
|
+
/** The sampler for `bits` (SMOOTH, and REPEAT or MIRROR), made as first asked for. */
|
|
127
|
+
sampler(bits) {
|
|
128
|
+
const known = this.samplers[bits];
|
|
129
|
+
if (known) {
|
|
130
|
+
return known;
|
|
131
|
+
}
|
|
132
|
+
const gl = this.gl;
|
|
133
|
+
const sampler = gl.createSampler();
|
|
134
|
+
const filter = bits & SMOOTH ? gl.LINEAR : gl.NEAREST;
|
|
135
|
+
const wrap = bits & REPEAT ? gl.REPEAT : bits & MIRROR ? gl.MIRRORED_REPEAT : gl.CLAMP_TO_EDGE;
|
|
136
|
+
gl.samplerParameteri(sampler, gl.TEXTURE_MIN_FILTER, filter);
|
|
137
|
+
gl.samplerParameteri(sampler, gl.TEXTURE_MAG_FILTER, filter);
|
|
138
|
+
gl.samplerParameteri(sampler, gl.TEXTURE_WRAP_S, wrap);
|
|
139
|
+
gl.samplerParameteri(sampler, gl.TEXTURE_WRAP_T, wrap);
|
|
140
|
+
this.samplers[bits] = sampler;
|
|
141
|
+
return sampler;
|
|
142
|
+
}
|
|
143
|
+
/** The rows a frame wrote, uploaded in one call, the texture made taller first if they need it. */
|
|
144
|
+
uploadRows(rows) {
|
|
145
|
+
const gl = this.gl;
|
|
146
|
+
const lines = Math.max(1, Math.ceil(rows.count / ROWS_A_LINE));
|
|
147
|
+
const width = ROWS_A_LINE * ROW_TEXELS;
|
|
148
|
+
this.state.bindTexture(0, this.rowsTexture);
|
|
149
|
+
this.state.activeTexture(0);
|
|
150
|
+
if (lines > this.rowLines) {
|
|
151
|
+
this.rowLines = Math.max(lines, this.rowLines * 2);
|
|
152
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, width, this.rowLines, 0, gl.RGBA, gl.FLOAT, null);
|
|
153
|
+
}
|
|
154
|
+
if (rows.count > 0) {
|
|
155
|
+
// Whole lines: the data holds ROW_FLOATS a row for as many rows as its lines hold.
|
|
156
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, lines, gl.RGBA, gl.FLOAT, rows.data.subarray(0, lines * ROWS_A_LINE * ROW_FLOATS));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/** The textures made on the context, deleted. */
|
|
160
|
+
destroy() {
|
|
161
|
+
const gl = this.gl;
|
|
162
|
+
gl.deleteTexture(this.rowsTexture);
|
|
163
|
+
if (this.outlines) {
|
|
164
|
+
gl.deleteTexture(this.outlines);
|
|
165
|
+
}
|
|
166
|
+
for (const texture of this.textures) {
|
|
167
|
+
if (texture) {
|
|
168
|
+
gl.deleteTexture(texture);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
for (const sampler of this.samplers) {
|
|
172
|
+
if (sampler) {
|
|
173
|
+
gl.deleteSampler(sampler);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=gpu-textures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gpu-textures.js","sourceRoot":"","sources":["../../src/webgl/gpu-textures.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAa,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,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CAAC;YAC5B,CAAC;QACH,CAAC;QAED,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACpC,IAAI,OAAO,EAAE,CAAC;gBACZ,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { GlState } from "@swf2es/context3d/device";
|
|
2
|
+
import { type Commands } from "../commands.js";
|
|
3
|
+
import type { Filters } from "../filters.js";
|
|
4
|
+
import type { SceneList } from "../scene.js";
|
|
5
|
+
import type { Compositor } from "./composite.js";
|
|
6
|
+
import type { Draws } from "./draws.js";
|
|
7
|
+
import type { FilterRunner } from "./filters.js";
|
|
8
|
+
import type { GpuTextures } from "./gpu-textures.js";
|
|
9
|
+
import { type Layer, type Open, type Target, type TargetPool } from "./targets.js";
|
|
10
|
+
/**
|
|
11
|
+
* The frame's held layers (HOLD_PUSH), drawn ahead of the stage a level at
|
|
12
|
+
* a time: their content side by side on pages, then their filters' passes
|
|
13
|
+
* in waves, each wave's targets on pages of their own; their outputs left
|
|
14
|
+
* on the pages for the frame's HELD composites.
|
|
15
|
+
*/
|
|
16
|
+
export declare class HeldLayers {
|
|
17
|
+
private readonly gl;
|
|
18
|
+
private readonly state;
|
|
19
|
+
private readonly pool;
|
|
20
|
+
private readonly draws;
|
|
21
|
+
private readonly compositor;
|
|
22
|
+
private readonly gpu;
|
|
23
|
+
/** The filters' passes, the backend's. */
|
|
24
|
+
private filters;
|
|
25
|
+
/**
|
|
26
|
+
* The frame's held layers (HOLD_PUSH); the pages they took, null once
|
|
27
|
+
* given back; the last wave each is read in, and whether an output is on
|
|
28
|
+
* it, which keeps it for the frame.
|
|
29
|
+
*/
|
|
30
|
+
private readonly holds;
|
|
31
|
+
private readonly pages;
|
|
32
|
+
private readonly pageUntil;
|
|
33
|
+
private readonly pageKept;
|
|
34
|
+
/** A page drawn into whole, a held layer's rectangle of one, and a held output composited. */
|
|
35
|
+
private readonly pageOpen;
|
|
36
|
+
private readonly holdOpen;
|
|
37
|
+
private readonly heldOpen;
|
|
38
|
+
private readonly shelves;
|
|
39
|
+
/** The masks pushed on the held layer whose content is drawn (drawHoldContent). */
|
|
40
|
+
private readonly masks;
|
|
41
|
+
/** The largest side a texture may have. */
|
|
42
|
+
private textureMost;
|
|
43
|
+
constructor(gl: WebGL2RenderingContext, state: GlState, pool: TargetPool, draws: Draws, compositor: Compositor, gpu: GpuTextures);
|
|
44
|
+
/**
|
|
45
|
+
* The filters' passes and the largest side a texture may have, as the
|
|
46
|
+
* context comes or comes back.
|
|
47
|
+
*/
|
|
48
|
+
setUp(filters: FilterRunner<Layer>, textureMost: number): void;
|
|
49
|
+
/**
|
|
50
|
+
* The frame's held layers (HOLD_PUSH), drawn ahead of the stage side by
|
|
51
|
+
* side: their content on pages of their own, one bind, clear and resolve
|
|
52
|
+
* a page; then their filters' passes in waves, the k-th pass of every
|
|
53
|
+
* chain at once, each wave's targets on pages of its own, which no pass
|
|
54
|
+
* of it reads. Each layer's output is left on its page for HELD. A layer
|
|
55
|
+
* larger than a page is drawn alone, as a layer of its own.
|
|
56
|
+
*/
|
|
57
|
+
drawHolds(commands: Commands, scene: SceneList, filters: Filters, target: Target): void;
|
|
58
|
+
/** Held layers `from` up to `to`, of one level, drawn side by side (drawHolds). */
|
|
59
|
+
private drawHoldLevel;
|
|
60
|
+
/**
|
|
61
|
+
* The width of a page for rectangles of `area` in all, the widest `widest`:
|
|
62
|
+
* about square, in LAYER_STEP's steps, at most PAGE_WIDTH.
|
|
63
|
+
*/
|
|
64
|
+
private pageWidth;
|
|
65
|
+
/** A page of at least `width` by `height` taken for the frame: its index in `pages`. */
|
|
66
|
+
private takePage;
|
|
67
|
+
/**
|
|
68
|
+
* `layer` added to the frame's pages, read by no pass yet, kept for the
|
|
69
|
+
* frame where `kept`: its index in `pages`.
|
|
70
|
+
*/
|
|
71
|
+
private addPage;
|
|
72
|
+
/** Slot `slot` of `hold` noted on its page: read until its last pass, or kept as its output. */
|
|
73
|
+
private notePage;
|
|
74
|
+
/** The held layers' rectangles and operations (HOLD_PUSH), which the commands begin with: how many. */
|
|
75
|
+
private gatherHolds;
|
|
76
|
+
/**
|
|
77
|
+
* Slot `slot` of `hold`'s targets: the rectangle of page `index` from (x,
|
|
78
|
+
* y) a target of `width` by `height` takes, as its own layer would; its
|
|
79
|
+
* record kept from frame to frame.
|
|
80
|
+
*/
|
|
81
|
+
private slotOf;
|
|
82
|
+
/**
|
|
83
|
+
* Held layer `hold`'s draws, masks and held layers' composites into
|
|
84
|
+
* `open`, bound, its stencil starting clear.
|
|
85
|
+
*/
|
|
86
|
+
private drawHoldContent;
|
|
87
|
+
/** Held output `held` composited onto `under`, bound, in blend mode `mode`, coloured by `row`. */
|
|
88
|
+
compositeHeld(held: number, under: Open, mode: number, row: number): void;
|
|
89
|
+
/**
|
|
90
|
+
* Held layer `hold`, too large for a page, drawn as a layer of its own and
|
|
91
|
+
* filtered there, its output left in a page of its own.
|
|
92
|
+
*/
|
|
93
|
+
private drawHoldAlone;
|
|
94
|
+
/** The pages the frame took given back, as it ends. */
|
|
95
|
+
givePages(): void;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=holds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"holds.d.ts","sourceRoot":"","sources":["../../src/webgl/holds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EACL,KAAK,QAAQ,EAOd,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,KAAK,EAAS,MAAM,YAAY,CA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