@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,323 @@
|
|
|
1
|
+
import { SizedPool, trimTogether } from "./pool.js";
|
|
2
|
+
import { LAYER_UNIT } from "./programs.js";
|
|
3
|
+
/**
|
|
4
|
+
* The most a multisampled target may take, colour and depth-stencil
|
|
5
|
+
* together, 8 bytes a sample, as web's fittingSamples has for the
|
|
6
|
+
* canvas.
|
|
7
|
+
*/
|
|
8
|
+
export const MSAA_BYTES = 256 * 1024 * 1024;
|
|
9
|
+
/**
|
|
10
|
+
* The samples a target of `width` by `height` takes for `samples`, a power
|
|
11
|
+
* of two, as a driver rounds others for colour and depth-stencil alike
|
|
12
|
+
* or not: halved till its buffers fit MSAA_BYTES, none (1) where two would
|
|
13
|
+
* not. A layer goes so far, as one padded as far as a texture goes would
|
|
14
|
+
* take gigabytes; the stage, as web's canvas, keeps 4 at least.
|
|
15
|
+
*/
|
|
16
|
+
export function fittingSamples(width, height, samples, least = 1) {
|
|
17
|
+
let fitting = 1;
|
|
18
|
+
while (fitting * 2 <= samples) {
|
|
19
|
+
fitting *= 2;
|
|
20
|
+
}
|
|
21
|
+
const floor = Math.min(fitting, least);
|
|
22
|
+
while (fitting > floor && width * height * fitting * 8 > MSAA_BYTES) {
|
|
23
|
+
fitting /= 2;
|
|
24
|
+
}
|
|
25
|
+
return fitting;
|
|
26
|
+
}
|
|
27
|
+
/** The sizes a layer's texture is made in: rounded up to a multiple, so that one serves many. */
|
|
28
|
+
export const LAYER_STEP = 128;
|
|
29
|
+
/**
|
|
30
|
+
* The sizes a small layer's side is made in, under LAYER_STEP: a glow of a
|
|
31
|
+
* few dozen pixels took a texture of 128 a side, and a crowd keeps
|
|
32
|
+
* thousands of them as their filters' outputs.
|
|
33
|
+
*/
|
|
34
|
+
const SMALL_STEP = 16;
|
|
35
|
+
/**
|
|
36
|
+
* The free layers and multisampled buffers kept between frames past what
|
|
37
|
+
* the last frame drew with, the least lately freed going first as a frame
|
|
38
|
+
* ends; and the most kept in all. A stretch of frames each drawing
|
|
39
|
+
* full-screen multisampled layers drew with 150 to 300 MiB a frame, and
|
|
40
|
+
* trimmed to 128 MiB in all, made seven targets a frame again, as many as
|
|
41
|
+
* it let go of.
|
|
42
|
+
*/
|
|
43
|
+
const FREE_BYTES = 128 * 1024 * 1024;
|
|
44
|
+
const WORKING_BYTES = 512 * 1024 * 1024;
|
|
45
|
+
/** A side of a layer made for `n` pixels: rounded up to SMALL_STEP, past LAYER_STEP to that. */
|
|
46
|
+
export function layerSide(n) {
|
|
47
|
+
return n <= LAYER_STEP
|
|
48
|
+
? Math.max(SMALL_STEP, Math.ceil(n / SMALL_STEP) * SMALL_STEP)
|
|
49
|
+
: Math.ceil(n / LAYER_STEP) * LAYER_STEP;
|
|
50
|
+
}
|
|
51
|
+
/** The bytes multisampled buffers take: colour and depth-stencil, 8 a sample. */
|
|
52
|
+
function msaaBytes(msaa) {
|
|
53
|
+
return msaa.width * msaa.height * msaa.samples * 8;
|
|
54
|
+
}
|
|
55
|
+
/** The bytes a layer takes: its colour, and its stencil where it has one. */
|
|
56
|
+
function layerBytes(layer) {
|
|
57
|
+
return layer.textureWidth * layer.textureHeight * (layer.stencil ? 8 : 4);
|
|
58
|
+
}
|
|
59
|
+
/** Frames a free layer is kept undrawn into before it is let go of. */
|
|
60
|
+
export const LAYER_IDLE_FRAMES = 60;
|
|
61
|
+
/** A whole layer's object from params `p` from `at` (plan.ts, layerParams): null for none. */
|
|
62
|
+
export function objectOf(p, at) {
|
|
63
|
+
return p[at + 2] < 0 ? null : { x: p[at], y: p[at + 1], width: p[at + 2], height: p[at + 3] };
|
|
64
|
+
}
|
|
65
|
+
/** The framebuffer `open` is drawn into: its multisampled one while it has one, else its own. */
|
|
66
|
+
export function framebufferOf(open) {
|
|
67
|
+
return open.msaa?.framebuffer ?? open.layer?.framebuffer ?? null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The backend's render targets: layers and the multisampled buffers they
|
|
71
|
+
* are drawn through, pooled by their size and samples, taken for a frame's
|
|
72
|
+
* layers, given back and let go of once idle; and the layers kept from
|
|
73
|
+
* frame to frame.
|
|
74
|
+
*/
|
|
75
|
+
export class TargetPool {
|
|
76
|
+
gl;
|
|
77
|
+
state;
|
|
78
|
+
/** Frames executed, which a layer's idleness is counted in. */
|
|
79
|
+
frameCount = 0;
|
|
80
|
+
/**
|
|
81
|
+
* The samples the layers of the frame drawing take: the stage's, which a
|
|
82
|
+
* BitmapData's frame draws with none of.
|
|
83
|
+
*/
|
|
84
|
+
layerSamples = 1;
|
|
85
|
+
/** Layers free to draw into, by their size. */
|
|
86
|
+
freeLayers = new SizedPool(layerBytes);
|
|
87
|
+
/** Multisampled buffers free to draw a layer into, kept while drawn into often enough. */
|
|
88
|
+
freeMsaa = new SizedPool(msaaBytes);
|
|
89
|
+
/** The layers kept from frame to frame, by their ids in Keeps. */
|
|
90
|
+
kept = [];
|
|
91
|
+
/** The widest and the tallest multisampled buffers found complete, by their samples. */
|
|
92
|
+
completeMsaa = new Map();
|
|
93
|
+
constructor(gl, state) {
|
|
94
|
+
this.gl = gl;
|
|
95
|
+
this.state = state;
|
|
96
|
+
}
|
|
97
|
+
/** The pools and the kept layers emptied, as the context comes or comes back. */
|
|
98
|
+
setUp() {
|
|
99
|
+
this.freeLayers = new SizedPool(layerBytes);
|
|
100
|
+
this.kept = [];
|
|
101
|
+
this.freeMsaa = new SizedPool(msaaBytes);
|
|
102
|
+
this.completeMsaa = new Map();
|
|
103
|
+
}
|
|
104
|
+
get frame() {
|
|
105
|
+
return this.frameCount;
|
|
106
|
+
}
|
|
107
|
+
get frameSamples() {
|
|
108
|
+
return this.layerSamples;
|
|
109
|
+
}
|
|
110
|
+
/** A frame begun, its layers taking `samples`: the stage's, 1 for a BitmapData's frame. */
|
|
111
|
+
beginFrame(samples) {
|
|
112
|
+
this.layerSamples = samples;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* A frame of the canvas' ended: the free layers and multisampled buffers
|
|
116
|
+
* undrawn into for LAYER_IDLE_FRAMES let go of, and the frame counted.
|
|
117
|
+
*/
|
|
118
|
+
endFrame() {
|
|
119
|
+
const drop = (l) => this.deleteLayer(l);
|
|
120
|
+
const dropMsaa = (m) => this.deleteMultisampled(m);
|
|
121
|
+
this.freeLayers.trimIdle(this.frameCount, LAYER_IDLE_FRAMES, drop);
|
|
122
|
+
this.freeMsaa.trimIdle(this.frameCount, LAYER_IDLE_FRAMES, dropMsaa);
|
|
123
|
+
trimTogether([
|
|
124
|
+
{ pool: this.freeLayers, drop },
|
|
125
|
+
{ pool: this.freeMsaa, drop: dropMsaa },
|
|
126
|
+
],
|
|
127
|
+
// What this frame drew with stays for the next, which likely draws alike: holding it adds
|
|
128
|
+
// nothing to what the frame itself took.
|
|
129
|
+
Math.min(WORKING_BYTES, FREE_BYTES +
|
|
130
|
+
this.freeLayers.bytesFreedIn(this.frameCount) +
|
|
131
|
+
this.freeMsaa.bytesFreedIn(this.frameCount)));
|
|
132
|
+
this.frameCount++;
|
|
133
|
+
}
|
|
134
|
+
/** The layer kept as output `id` (Keeps), or none. */
|
|
135
|
+
keptLayer(id) {
|
|
136
|
+
return this.kept[id] ?? null;
|
|
137
|
+
}
|
|
138
|
+
/** `layer` kept as output `id` (Keeps) for the frames after, the one kept before given back. */
|
|
139
|
+
keep(id, layer) {
|
|
140
|
+
const before = this.kept[id];
|
|
141
|
+
if (before && before !== layer) {
|
|
142
|
+
this.giveLayer(before);
|
|
143
|
+
}
|
|
144
|
+
this.kept[id] = layer;
|
|
145
|
+
}
|
|
146
|
+
/** The layer kept as output `id` given back, as Keeps let go of it. */
|
|
147
|
+
release(id) {
|
|
148
|
+
const layer = this.kept[id];
|
|
149
|
+
if (layer) {
|
|
150
|
+
this.giveLayer(layer);
|
|
151
|
+
this.kept[id] = null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* `open`'s multisampled pixels resolved into its layer's texture, its
|
|
156
|
+
* first `width` by `height`, once: what reads it after reads them.
|
|
157
|
+
*/
|
|
158
|
+
resolve(open, width, height) {
|
|
159
|
+
const msaa = open.msaa;
|
|
160
|
+
const layer = open.layer;
|
|
161
|
+
if (!msaa || !layer) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const gl = this.gl;
|
|
165
|
+
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, msaa.framebuffer);
|
|
166
|
+
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, layer.framebuffer);
|
|
167
|
+
// The blit writes the whole rectangle, so what the layer held there goes:
|
|
168
|
+
// said so, as ANGLE's Vulkan back end, SwiftShader's and a GPU's alike,
|
|
169
|
+
// otherwise left a reused layer's old pixels where the blit had written
|
|
170
|
+
// (tests/player/packed-filters.ts, once the pool keeps layers a frame).
|
|
171
|
+
gl.invalidateSubFramebuffer(gl.DRAW_FRAMEBUFFER, [gl.COLOR_ATTACHMENT0], 0, 0, width, height);
|
|
172
|
+
gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, gl.COLOR_BUFFER_BIT, gl.NEAREST);
|
|
173
|
+
// Bound as the state cache has it.
|
|
174
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, msaa.framebuffer);
|
|
175
|
+
open.msaa = null;
|
|
176
|
+
// Free for the next layer: only those drawn into now hold multisampled buffers.
|
|
177
|
+
this.freeMsaa.give(msaa, this.frameCount, msaa.samples);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Multisampled buffers to draw `layer` into at `wanted` samples, as many
|
|
181
|
+
* as fit, reusing its size or a slightly larger buffer; none where it
|
|
182
|
+
* takes none, its own stencil then made if it has none.
|
|
183
|
+
*/
|
|
184
|
+
layerMsaa(layer, wanted) {
|
|
185
|
+
const samples = fittingSamples(layer.width, layer.height, wanted);
|
|
186
|
+
// The resolve copies only the layer's rectangle. A larger MSAA buffer can serve it,
|
|
187
|
+
// but bounding its area avoids clearing a large page for a small layer.
|
|
188
|
+
const kept = samples > 1
|
|
189
|
+
? (this.freeMsaa.take(layer.width, layer.height, samples) ??
|
|
190
|
+
this.freeMsaa.takeFitting(layer.width, layer.height, samples, layer.width * layer.height * 2))
|
|
191
|
+
: null;
|
|
192
|
+
if (kept) {
|
|
193
|
+
return kept;
|
|
194
|
+
}
|
|
195
|
+
const msaa = samples > 1 ? this.multisampled(layer.width, layer.height, samples) : null;
|
|
196
|
+
if (!msaa && !layer.stencil) {
|
|
197
|
+
const gl = this.gl;
|
|
198
|
+
const stencil = gl.createRenderbuffer();
|
|
199
|
+
gl.bindRenderbuffer(gl.RENDERBUFFER, stencil);
|
|
200
|
+
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH24_STENCIL8, layer.textureWidth, layer.textureHeight);
|
|
201
|
+
this.state.bindFramebuffer(layer.framebuffer);
|
|
202
|
+
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, stencil);
|
|
203
|
+
layer.stencil = stencil;
|
|
204
|
+
}
|
|
205
|
+
return msaa;
|
|
206
|
+
}
|
|
207
|
+
/** Multisampled buffers, or none where the driver leaves their framebuffer incomplete. */
|
|
208
|
+
multisampled(width, height, samples) {
|
|
209
|
+
const gl = this.gl;
|
|
210
|
+
const color = gl.createRenderbuffer();
|
|
211
|
+
gl.bindRenderbuffer(gl.RENDERBUFFER, color);
|
|
212
|
+
gl.renderbufferStorageMultisample(gl.RENDERBUFFER, samples, gl.RGBA8, width, height);
|
|
213
|
+
const depthStencil = gl.createRenderbuffer();
|
|
214
|
+
gl.bindRenderbuffer(gl.RENDERBUFFER, depthStencil);
|
|
215
|
+
gl.renderbufferStorageMultisample(gl.RENDERBUFFER, samples, gl.DEPTH24_STENCIL8, width, height);
|
|
216
|
+
const framebuffer = gl.createFramebuffer();
|
|
217
|
+
this.state.bindFramebuffer(framebuffer);
|
|
218
|
+
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, color);
|
|
219
|
+
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, depthStencil);
|
|
220
|
+
const msaa = {
|
|
221
|
+
framebuffer,
|
|
222
|
+
color,
|
|
223
|
+
depthStencil,
|
|
224
|
+
width,
|
|
225
|
+
height,
|
|
226
|
+
samples,
|
|
227
|
+
usedAt: this.frameCount,
|
|
228
|
+
};
|
|
229
|
+
// Asking waits for the GPU process, milliseconds at a time, and the
|
|
230
|
+
// answer hangs on the formats and the samples, which are always these,
|
|
231
|
+
// and on each side against the largest a renderbuffer may have: one no
|
|
232
|
+
// wider than the widest found complete of its samples, and no taller
|
|
233
|
+
// than the tallest, which may be another, is not asked about.
|
|
234
|
+
const complete = this.completeMsaa.get(samples);
|
|
235
|
+
if (complete && width <= complete.width && height <= complete.height) {
|
|
236
|
+
return msaa;
|
|
237
|
+
}
|
|
238
|
+
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE) {
|
|
239
|
+
this.deleteMultisampled(msaa);
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
this.completeMsaa.set(samples, {
|
|
243
|
+
width: Math.max(width, complete?.width ?? 0),
|
|
244
|
+
height: Math.max(height, complete?.height ?? 0),
|
|
245
|
+
});
|
|
246
|
+
return msaa;
|
|
247
|
+
}
|
|
248
|
+
deleteMultisampled(msaa) {
|
|
249
|
+
this.gl.deleteFramebuffer(msaa.framebuffer);
|
|
250
|
+
this.gl.deleteRenderbuffer(msaa.color);
|
|
251
|
+
this.gl.deleteRenderbuffer(msaa.depthStencil);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* A layer of at least `width` by `height`, the smallest of those free
|
|
255
|
+
* that is, or one made, its sides rounded as layerSide rounds them;
|
|
256
|
+
* `exact`, used as just the rounded size, which filters take so that a
|
|
257
|
+
* frame's targets are alike: a larger texture serves it as one of that
|
|
258
|
+
* size, as filters read it within its size (FilterTarget), so that a
|
|
259
|
+
* layer whose size changes as its content moves finds one free.
|
|
260
|
+
*/
|
|
261
|
+
takeLayer(width, height, exact = false) {
|
|
262
|
+
width = layerSide(width);
|
|
263
|
+
height = layerSide(height);
|
|
264
|
+
// Bound excess area: oversized texture reuse also enlarges the MSAA target and clears. An
|
|
265
|
+
// exact one takes its multisampled buffers and clears at its own size, so may go further.
|
|
266
|
+
const found = this.freeLayers.take(width, height) ??
|
|
267
|
+
this.freeLayers.takeFitting(width, height, 0, width * height * (exact ? 4 : 2));
|
|
268
|
+
if (found) {
|
|
269
|
+
found.usedAt = this.frameCount;
|
|
270
|
+
found.width = exact ? width : found.textureWidth;
|
|
271
|
+
found.height = exact ? height : found.textureHeight;
|
|
272
|
+
return found;
|
|
273
|
+
}
|
|
274
|
+
return this.makeLayer(width, height);
|
|
275
|
+
}
|
|
276
|
+
/** A layer just `width` by `height`, made. */
|
|
277
|
+
makeLayer(width, height) {
|
|
278
|
+
const gl = this.gl;
|
|
279
|
+
const texture = gl.createTexture();
|
|
280
|
+
this.state.bindTexture(LAYER_UNIT, texture);
|
|
281
|
+
this.state.activeTexture(LAYER_UNIT);
|
|
282
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
283
|
+
// Read texel by texel: with no mipmaps, the default filter would leave it incomplete, reading 0.
|
|
284
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
285
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
286
|
+
const framebuffer = gl.createFramebuffer();
|
|
287
|
+
this.state.bindFramebuffer(framebuffer);
|
|
288
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
289
|
+
return {
|
|
290
|
+
framebuffer,
|
|
291
|
+
texture,
|
|
292
|
+
stencil: null,
|
|
293
|
+
width,
|
|
294
|
+
height,
|
|
295
|
+
textureWidth: width,
|
|
296
|
+
textureHeight: height,
|
|
297
|
+
usedAt: this.frameCount,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
/** A layer free again, kept for the layers after it while it is drawn into often enough. */
|
|
301
|
+
giveLayer(layer) {
|
|
302
|
+
this.freeLayers.give(layer, this.frameCount);
|
|
303
|
+
}
|
|
304
|
+
deleteLayer(layer) {
|
|
305
|
+
this.state.dropTexture(layer.texture);
|
|
306
|
+
this.gl.deleteFramebuffer(layer.framebuffer);
|
|
307
|
+
this.gl.deleteTexture(layer.texture);
|
|
308
|
+
if (layer.stencil) {
|
|
309
|
+
this.gl.deleteRenderbuffer(layer.stencil);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/** The free and the kept layers, and the free multisampled buffers, deleted. */
|
|
313
|
+
destroy() {
|
|
314
|
+
this.freeLayers.clear((l) => this.deleteLayer(l));
|
|
315
|
+
for (const layer of this.kept) {
|
|
316
|
+
if (layer) {
|
|
317
|
+
this.deleteLayer(layer);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
this.freeMsaa.clear((m) => this.deleteMultisampled(m));
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
//# sourceMappingURL=targets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"targets.js","sourceRoot":"","sources":["../../src/webgl/targets.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAyD3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,MAAc,EAAE,OAAe,EAAE,KAAK,GAAG,CAAC;IACtF,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,OAAO,OAAO,GAAG,CAAC,IAAI,OAAO,EAAE,CAAC;QAC9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MAAM;YACrB,MAAM,EAAE,IAAI,CAAC,UAAU;SACxB,CAAC;IACJ,CAAC;IAED,4FAA4F;IAC5F,SAAS,CAAC,KAAY;QACpB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC/C,CAAC;IAED,WAAW,CAAC,KAAY;QACtB,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACtC,IAAI,CAAC,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC7C,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YAClB,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IAED,gFAAgF;IAChF,OAAO;QACL,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;QAClD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YAC9B,IAAI,KAAK,EAAE,CAAC;gBACV,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;IACzD,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swf2es/render",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "swf2es's own renderer: a scene list, a planner and a WebGL 2 backend (docs/renderer.md)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"swf",
|
|
7
|
+
"flash",
|
|
8
|
+
"renderer",
|
|
9
|
+
"webgl2"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://swf2es.github.io/swf2es/",
|
|
12
|
+
"bugs": "https://github.com/swf2es/swf2es/issues",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/swf2es/swf2es.git",
|
|
16
|
+
"directory": "packages/render"
|
|
17
|
+
},
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./webgl": {
|
|
26
|
+
"types": "./dist/webgl/index.d.ts",
|
|
27
|
+
"default": "./dist/webgl/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"!dist/**/.tsbuildinfo",
|
|
33
|
+
"src"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@swf2es/context3d": "0.1.1"
|
|
37
|
+
}
|
|
6
38
|
}
|
package/src/commands.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** Clear the target to a colour: params red, green, blue, alpha. */
|
|
2
|
+
export const CLEAR = 1;
|
|
3
|
+
/** Draw the scene list's entries from `a`, `b` of them, under blend mode `c`. */
|
|
4
|
+
export const RUN = 2;
|
|
5
|
+
/**
|
|
6
|
+
* A mask: entries from `a`, `b` of them, drawn into the stencil, where what
|
|
7
|
+
* follows is drawn; and taken out again, the same entries, once it is.
|
|
8
|
+
*/
|
|
9
|
+
export const STENCIL_PUSH = 3;
|
|
10
|
+
export const STENCIL_POP = 4;
|
|
11
|
+
/**
|
|
12
|
+
* A layer begun, drawn into a target of its own over the rectangle of the
|
|
13
|
+
* target whose x, y, width and height are params from `a`, `b` 1 where
|
|
14
|
+
* filters will read it past that rectangle, which is then clear too; and
|
|
15
|
+
* composited onto the one below in blend mode `a`, coloured by row `b`
|
|
16
|
+
* (or -1), its output kept as kept output `c` (Keeps), or not (-1).
|
|
17
|
+
*/
|
|
18
|
+
export const LAYER_PUSH = 5;
|
|
19
|
+
export const LAYER_POP = 6;
|
|
20
|
+
/** The filters of chain `a` of the frame's filter list run over the layer drawn into, in turn. */
|
|
21
|
+
export const FILTER = 7;
|
|
22
|
+
/**
|
|
23
|
+
* A kept output (Keeps) composited again onto the target drawn into, in
|
|
24
|
+
* blend mode `b`, coloured by row `c` (or -1): its rectangle's x, y, width
|
|
25
|
+
* and height, then its id, are params from `a`.
|
|
26
|
+
*/
|
|
27
|
+
export const COMPOSITE = 8;
|
|
28
|
+
/**
|
|
29
|
+
* A filtered layer drawn ahead of the stage (plan), its draws, masks and
|
|
30
|
+
* held layers' composites the operations between: begun over the
|
|
31
|
+
* rectangle of params from `a`, its output held as held output `b`, at
|
|
32
|
+
* level `c`, one past the deepest held layer in it; ended with chain `a`
|
|
33
|
+
* of the frame's filters run over it, held output `b`. Held layers come
|
|
34
|
+
* before the stage's CLEAR, a level's after those it holds, and the
|
|
35
|
+
* backend draws a level's side by side, their passes too.
|
|
36
|
+
*/
|
|
37
|
+
export const HOLD_PUSH = 9;
|
|
38
|
+
export const HOLD_POP = 10;
|
|
39
|
+
/** Held output `a` composited onto the target drawn into, in blend mode `b`, coloured by row `c` (or -1). */
|
|
40
|
+
export const HELD = 11;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* What a frame asks of the backend, in order: each operation an opcode and
|
|
44
|
+
* three integers, with the floats some take apart.
|
|
45
|
+
*/
|
|
46
|
+
export class Commands {
|
|
47
|
+
ops = new Int32Array(256);
|
|
48
|
+
params = new Float32Array(64);
|
|
49
|
+
length = 0;
|
|
50
|
+
paramLength = 0;
|
|
51
|
+
/**
|
|
52
|
+
* Whether a layer is composited onto the target itself in erase or alpha,
|
|
53
|
+
* which leaves it less than opaque where it covers, as adl clears the
|
|
54
|
+
* stage, for the blends after it to read.
|
|
55
|
+
*/
|
|
56
|
+
clearsTarget = false;
|
|
57
|
+
/**
|
|
58
|
+
* Whether the stage stays opaque throughout: cleared to an opaque colour,
|
|
59
|
+
* and nothing composited onto it that leaves less, erase, alpha or a
|
|
60
|
+
* blend shader. GL's blending computes more of Flash's blends over it.
|
|
61
|
+
*/
|
|
62
|
+
opaqueStage = false;
|
|
63
|
+
|
|
64
|
+
reset(): void {
|
|
65
|
+
this.length = 0;
|
|
66
|
+
this.paramLength = 0;
|
|
67
|
+
this.clearsTarget = false;
|
|
68
|
+
this.opaqueStage = false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
push(op: number, a = 0, b = 0, c = 0): void {
|
|
72
|
+
if ((this.length + 1) * 4 > this.ops.length) {
|
|
73
|
+
const grown = new Int32Array(this.ops.length * 2);
|
|
74
|
+
grown.set(this.ops);
|
|
75
|
+
this.ops = grown;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const at = this.length++ * 4;
|
|
79
|
+
this.ops[at] = op;
|
|
80
|
+
this.ops[at + 1] = a;
|
|
81
|
+
this.ops[at + 2] = b;
|
|
82
|
+
this.ops[at + 3] = c;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Floats for the operation pushed next, where it reads them from. */
|
|
86
|
+
param(...values: number[]): number {
|
|
87
|
+
const at = this.paramLength;
|
|
88
|
+
if (at + values.length > this.params.length) {
|
|
89
|
+
const grown = new Float32Array(Math.max(this.params.length * 2, at + values.length));
|
|
90
|
+
grown.set(this.params);
|
|
91
|
+
this.params = grown;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
this.params.set(values, at);
|
|
95
|
+
this.paramLength += values.length;
|
|
96
|
+
return at;
|
|
97
|
+
}
|
|
98
|
+
}
|