@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,173 @@
1
+ import { LAYER_UNIT } from "./programs.js";
2
+ import { fittingSamples, LAYER_IDLE_FRAMES, } from "./targets.js";
3
+ /**
4
+ * The stage's own targets and their way onto the canvas: multisampled
5
+ * buffers the canvas's size and the texture they resolve into, the layer a
6
+ * frame that clears the stage is drawn into before an opaque canvas, and
7
+ * the copies onto the canvas.
8
+ */
9
+ export class Stage {
10
+ gl;
11
+ state;
12
+ pool;
13
+ /** The most samples the GPU takes, and whether the canvas has alpha, asked once. */
14
+ maxSamples = 1;
15
+ hasAlpha = false;
16
+ /**
17
+ * The stage's multisampled buffers, and the texture they resolve into before a canvas they may
18
+ * not be resolved onto (present), made as first needed.
19
+ */
20
+ stageMsaa = null;
21
+ stageResolved = null;
22
+ /**
23
+ * Whether the driver resolves the stage straight onto a canvas with alpha, found as it first does
24
+ * (present): null till then. SwiftShader refuses it.
25
+ */
26
+ directResolve = null;
27
+ /** The layer a frame that clears the stage is drawn into before an opaque canvas (stageAlpha). */
28
+ stageLayer = null;
29
+ constructor(gl, state, pool) {
30
+ this.gl = gl;
31
+ this.state = state;
32
+ this.pool = pool;
33
+ }
34
+ /** Whether the canvas has alpha, as asked of the context in setUp. */
35
+ get canvasAlpha() {
36
+ return this.hasAlpha;
37
+ }
38
+ /** Nothing made yet, and the GPU and the canvas asked again, as the context comes or comes back. */
39
+ setUp() {
40
+ const gl = this.gl;
41
+ this.stageMsaa = null;
42
+ this.stageResolved = null;
43
+ this.directResolve = null;
44
+ this.stageLayer = null;
45
+ this.maxSamples = gl.getParameter(gl.MAX_SAMPLES);
46
+ this.hasAlpha = gl.getContextAttributes()?.alpha ?? false;
47
+ }
48
+ /**
49
+ * The stage's multisampled pixels onto the canvas: resolved straight onto one with alpha where
50
+ * the driver lets a resolve go there, else into a texture first, as an opaque canvas's must be, a
51
+ * resolve keeping its format. Whether the driver lets it is found once, by the error it raises.
52
+ */
53
+ present(msaa) {
54
+ const gl = this.gl;
55
+ const { width, height } = msaa;
56
+ if (this.hasAlpha && this.directResolve !== false) {
57
+ const finding = this.directResolve === null;
58
+ if (finding) {
59
+ gl.getError();
60
+ }
61
+ this.toCanvas(msaa.framebuffer, width, height, false);
62
+ if (finding) {
63
+ this.directResolve = gl.getError() !== gl.INVALID_OPERATION;
64
+ }
65
+ if (this.directResolve) {
66
+ return;
67
+ }
68
+ }
69
+ const resolved = this.resolveTarget(width, height);
70
+ this.state.bindFramebuffer(msaa.framebuffer);
71
+ gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, resolved.framebuffer);
72
+ gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, gl.COLOR_BUFFER_BIT, gl.NEAREST);
73
+ this.toCanvas(resolved.framebuffer, width, height, false);
74
+ }
75
+ /** The texture the stage resolves into before the canvas (present), made as first needed. */
76
+ resolveTarget(width, height) {
77
+ if (this.stageResolved) {
78
+ return this.stageResolved;
79
+ }
80
+ const gl = this.gl;
81
+ const texture = gl.createTexture();
82
+ this.state.bindTexture(LAYER_UNIT, texture);
83
+ this.state.activeTexture(LAYER_UNIT);
84
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
85
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
86
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
87
+ const framebuffer = gl.createFramebuffer();
88
+ this.state.bindFramebuffer(framebuffer);
89
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
90
+ this.stageResolved = { framebuffer, texture };
91
+ return this.stageResolved;
92
+ }
93
+ /**
94
+ * The first `width` by `height` pixels of `source` copied onto the canvas,
95
+ * upside down where `flip`. Bound through the state cache first and as
96
+ * it was after, so the cache holds what is bound, whatever it held.
97
+ */
98
+ toCanvas(source, width, height, flip) {
99
+ const gl = this.gl;
100
+ this.state.bindFramebuffer(source);
101
+ gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null);
102
+ const top = flip ? 0 : height;
103
+ gl.blitFramebuffer(0, 0, width, height, 0, height - top, width, top, gl.COLOR_BUFFER_BIT, gl.NEAREST);
104
+ gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, source);
105
+ }
106
+ /**
107
+ * The layer the canvas' size a frame that clears the stage is drawn into
108
+ * before an opaque canvas (execute): its own, kept apart from the free
109
+ * layers so that none smaller takes it, made again for another size, let
110
+ * go of once idle as they are.
111
+ */
112
+ stageAlpha(width, height) {
113
+ const known = this.stageLayer;
114
+ if (known && known.width === width && known.height === height) {
115
+ known.usedAt = this.pool.frame;
116
+ return known;
117
+ }
118
+ if (known) {
119
+ this.pool.deleteLayer(known);
120
+ }
121
+ const layer = this.pool.makeLayer(width, height);
122
+ this.stageLayer = layer;
123
+ return layer;
124
+ }
125
+ /**
126
+ * The stage's multisampled buffers, made again for another size or samples, their resolve's
127
+ * texture let go of; none where it takes no samples.
128
+ */
129
+ stageBuffers(width, height, wanted) {
130
+ const samples = fittingSamples(width, height, Math.min(wanted, this.maxSamples), 4);
131
+ const known = this.stageMsaa;
132
+ if (known && known.width === width && known.height === height && known.samples === samples) {
133
+ return known;
134
+ }
135
+ this.dropStageBuffers();
136
+ const msaa = samples > 1 ? this.pool.multisampled(width, height, samples) : null;
137
+ if (!msaa) {
138
+ return null;
139
+ }
140
+ this.stageMsaa = msaa;
141
+ return msaa;
142
+ }
143
+ /** The stage's multisampled buffers and their resolve let go of, as samples or size change. */
144
+ dropStageBuffers() {
145
+ const gl = this.gl;
146
+ if (this.stageMsaa) {
147
+ this.pool.deleteMultisampled(this.stageMsaa);
148
+ this.stageMsaa = null;
149
+ }
150
+ if (this.stageResolved) {
151
+ this.state.dropTexture(this.stageResolved.texture);
152
+ gl.deleteTexture(this.stageResolved.texture);
153
+ gl.deleteFramebuffer(this.stageResolved.framebuffer);
154
+ this.stageResolved = null;
155
+ }
156
+ }
157
+ /** The stage's layer (stageAlpha) let go of, undrawn into for LAYER_IDLE_FRAMES. */
158
+ dropIdleLayer() {
159
+ const stage = this.stageLayer;
160
+ if (stage && this.pool.frame - stage.usedAt > LAYER_IDLE_FRAMES) {
161
+ this.pool.deleteLayer(stage);
162
+ this.stageLayer = null;
163
+ }
164
+ }
165
+ /** What the stage made on the context, deleted. */
166
+ destroy() {
167
+ this.dropStageBuffers();
168
+ if (this.stageLayer) {
169
+ this.pool.deleteLayer(this.stageLayer);
170
+ }
171
+ }
172
+ }
173
+ //# sourceMappingURL=stage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stage.js","sourceRoot":"","sources":["../../src/webgl/stage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EACL,cAAc,EACd,iBAAiB,GAIlB,MAAM,cAAc,CAAC;AAEtB;;;;;GAKG;AACH,MAAM,OAAO,KAAK;IACC,EAAE,CAAyB;IAC3B,KAAK,CAAU;IACf,IAAI,CAAa;IAClC,oFAAoF;IAC5E,UAAU,GAAG,CAAC,CAAC;IACf,QAAQ,GAAG,KAAK,CAAC;IACzB;;;OAGG;IACK,SAAS,GAAwB,IAAI,CAAC;IACtC,aAAa,GAAoE,IAAI,CAAC;IAC9F;;;OAGG;IACK,aAAa,GAAmB,IAAI,CAAC;IAC7C,kGAAkG;IAC1F,UAAU,GAAiB,IAAI,CAAC;IAExC,YAAY,EAA0B,EAAE,KAAc,EAAE,IAAgB;QACtE,IA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** Where a frame is drawn: the target's size in pixels, and how stage pixels map onto it. */
4
+ export interface Target {
5
+ width: number;
6
+ height: number;
7
+ /** Target pixels a stage pixel, and where the stage's origin lies on the target. */
8
+ scale: number;
9
+ x: number;
10
+ y: number;
11
+ /** Target pixels a unit of the target's own, which filters read their input's size in. */
12
+ resolution: number;
13
+ /**
14
+ * Target pixels a side of a pixel of Flash's, which a mesh's texture is
15
+ * read once in: a pixel of the screen, or a BitmapData's draw's sample.
16
+ */
17
+ pixel: number;
18
+ }
19
+ /**
20
+ * A target a layer is drawn into: a texture at least its rectangle's size,
21
+ * with a stencil of its own for masks within it. Its rows run down, the
22
+ * first the rectangle's top, as filters read them.
23
+ */
24
+ export interface Layer {
25
+ framebuffer: WebGLFramebuffer;
26
+ texture: WebGLTexture;
27
+ /** Its stencil, made as it is first drawn into unmultisampled; filters' targets take none. */
28
+ stencil: WebGLRenderbuffer | null;
29
+ /**
30
+ * The size it is used as, which filters read it as a texture of: its
31
+ * texture's, or less where a filter's target takes a larger one (takeLayer).
32
+ */
33
+ width: number;
34
+ height: number;
35
+ /** Its texture's size, and its stencil's. */
36
+ textureWidth: number;
37
+ textureHeight: number;
38
+ /** The frame it was last drawn into. */
39
+ usedAt: number;
40
+ }
41
+ /**
42
+ * Multisampled colour and depth-stencil a target is drawn into, its edges
43
+ * covered by `samples` a pixel, then resolved into a texture to be read.
44
+ */
45
+ export interface Multisampled {
46
+ framebuffer: WebGLFramebuffer;
47
+ color: WebGLRenderbuffer;
48
+ depthStencil: WebGLRenderbuffer;
49
+ width: number;
50
+ height: number;
51
+ samples: number;
52
+ /** The frame it was last drawn into. */
53
+ usedAt: number;
54
+ }
55
+ /**
56
+ * The most a multisampled target may take, colour and depth-stencil
57
+ * together, 8 bytes a sample, as web's fittingSamples has for the
58
+ * canvas.
59
+ */
60
+ export declare const MSAA_BYTES: number;
61
+ /**
62
+ * The samples a target of `width` by `height` takes for `samples`, a power
63
+ * of two, as a driver rounds others for colour and depth-stencil alike
64
+ * or not: halved till its buffers fit MSAA_BYTES, none (1) where two would
65
+ * not. A layer goes so far, as one padded as far as a texture goes would
66
+ * take gigabytes; the stage, as web's canvas, keeps 4 at least.
67
+ */
68
+ export declare function fittingSamples(width: number, height: number, samples: number, least?: number): number;
69
+ /** The sizes a layer's texture is made in: rounded up to a multiple, so that one serves many. */
70
+ export declare const LAYER_STEP = 128;
71
+ /** A side of a layer made for `n` pixels: rounded up to SMALL_STEP, past LAYER_STEP to that. */
72
+ export declare function layerSide(n: number): number;
73
+ /** Frames a free layer is kept undrawn into before it is let go of. */
74
+ export declare const LAYER_IDLE_FRAMES = 60;
75
+ /**
76
+ * A target drawn into: its rectangle of the canvas, in pixels from the
77
+ * top left, and the layer it is drawn into, or none for the canvas itself.
78
+ */
79
+ export interface Open {
80
+ layer: Layer | null;
81
+ /** What it is drawn into while it is multisampled, resolved before it is read. */
82
+ msaa: Multisampled | null;
83
+ x: number;
84
+ y: number;
85
+ width: number;
86
+ height: number;
87
+ /** Where its rectangle's corner is in its framebuffer, a page's (HOLD_PUSH); else 0, 0. */
88
+ ox?: number;
89
+ oy?: number;
90
+ /** Where a whole layer's object lies in it, which its ShaderFilters read (filter-plan.ts). */
91
+ object?: KernelObject | null;
92
+ /** Whether it is opaque throughout, as the stage is (Commands.opaqueStage). */
93
+ opaque?: boolean;
94
+ }
95
+ /** A whole layer's object from params `p` from `at` (plan.ts, layerParams): null for none. */
96
+ export declare function objectOf(p: Float32Array, at: number): KernelObject | null;
97
+ /** The framebuffer `open` is drawn into: its multisampled one while it has one, else its own. */
98
+ export declare function framebufferOf(open: Open): WebGLFramebuffer | null;
99
+ /**
100
+ * The backend's render targets: layers and the multisampled buffers they
101
+ * are drawn through, pooled by their size and samples, taken for a frame's
102
+ * layers, given back and let go of once idle; and the layers kept from
103
+ * frame to frame.
104
+ */
105
+ export declare class TargetPool {
106
+ private readonly gl;
107
+ private readonly state;
108
+ /** Frames executed, which a layer's idleness is counted in. */
109
+ private frameCount;
110
+ /**
111
+ * The samples the layers of the frame drawing take: the stage's, which a
112
+ * BitmapData's frame draws with none of.
113
+ */
114
+ private layerSamples;
115
+ /** Layers free to draw into, by their size. */
116
+ private freeLayers;
117
+ /** Multisampled buffers free to draw a layer into, kept while drawn into often enough. */
118
+ private freeMsaa;
119
+ /** The layers kept from frame to frame, by their ids in Keeps. */
120
+ private kept;
121
+ /** The widest and the tallest multisampled buffers found complete, by their samples. */
122
+ private completeMsaa;
123
+ constructor(gl: WebGL2RenderingContext, state: GlState);
124
+ /** The pools and the kept layers emptied, as the context comes or comes back. */
125
+ setUp(): void;
126
+ get frame(): number;
127
+ get frameSamples(): number;
128
+ /** A frame begun, its layers taking `samples`: the stage's, 1 for a BitmapData's frame. */
129
+ beginFrame(samples: number): void;
130
+ /**
131
+ * A frame of the canvas' ended: the free layers and multisampled buffers
132
+ * undrawn into for LAYER_IDLE_FRAMES let go of, and the frame counted.
133
+ */
134
+ endFrame(): void;
135
+ /** The layer kept as output `id` (Keeps), or none. */
136
+ keptLayer(id: number): Layer | null;
137
+ /** `layer` kept as output `id` (Keeps) for the frames after, the one kept before given back. */
138
+ keep(id: number, layer: Layer): void;
139
+ /** The layer kept as output `id` given back, as Keeps let go of it. */
140
+ release(id: number): void;
141
+ /**
142
+ * `open`'s multisampled pixels resolved into its layer's texture, its
143
+ * first `width` by `height`, once: what reads it after reads them.
144
+ */
145
+ resolve(open: Open, width: number, height: number): void;
146
+ /**
147
+ * Multisampled buffers to draw `layer` into at `wanted` samples, as many
148
+ * as fit, reusing its size or a slightly larger buffer; none where it
149
+ * takes none, its own stencil then made if it has none.
150
+ */
151
+ layerMsaa(layer: Layer, wanted: number): Multisampled | null;
152
+ /** Multisampled buffers, or none where the driver leaves their framebuffer incomplete. */
153
+ multisampled(width: number, height: number, samples: number): Multisampled | null;
154
+ deleteMultisampled(msaa: Multisampled): void;
155
+ /**
156
+ * A layer of at least `width` by `height`, the smallest of those free
157
+ * that is, or one made, its sides rounded as layerSide rounds them;
158
+ * `exact`, used as just the rounded size, which filters take so that a
159
+ * frame's targets are alike: a larger texture serves it as one of that
160
+ * size, as filters read it within its size (FilterTarget), so that a
161
+ * layer whose size changes as its content moves finds one free.
162
+ */
163
+ takeLayer(width: number, height: number, exact?: boolean): Layer;
164
+ /** A layer just `width` by `height`, made. */
165
+ makeLayer(width: number, height: number): Layer;
166
+ /** A layer free again, kept for the layers after it while it is drawn into often enough. */
167
+ giveLayer(layer: Layer): void;
168
+ deleteLayer(layer: Layer): void;
169
+ /** The free and the kept layers, and the free multisampled buffers, deleted. */
170
+ destroy(): void;
171
+ }
172
+ //# sourceMappingURL=targets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"targets.d.ts","sourceRoot":"","sources":["../../src/webgl/targets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAItD,6FAA6F;AAC7F,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,oFAAoF;IACpF,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,0FAA0F;IAC1F,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,MAAM,WAAW,KAAK;IACpB,WAAW,EAAE,gBAAgB,CAAC;IAC9B,OAAO,EAAE,YAAY,CAAC;IACtB,8FAA8F;IAC9F,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAClC;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,wCAAwC;IACxC,MAAM,EAA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