@swf2es/context3d 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 (88) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +219 -2
  3. package/dist/agal.d.ts +23 -0
  4. package/dist/agal.d.ts.map +1 -0
  5. package/dist/agal.js +410 -0
  6. package/dist/agal.js.map +1 -0
  7. package/dist/backend.d.ts +122 -0
  8. package/dist/backend.d.ts.map +1 -0
  9. package/dist/backend.js +63 -0
  10. package/dist/backend.js.map +1 -0
  11. package/dist/device/index.d.ts +3 -0
  12. package/dist/device/index.d.ts.map +1 -0
  13. package/dist/device/index.js +6 -0
  14. package/dist/device/index.js.map +1 -0
  15. package/dist/device/programs.d.ts +13 -0
  16. package/dist/device/programs.d.ts.map +1 -0
  17. package/dist/device/programs.js +59 -0
  18. package/dist/device/programs.js.map +1 -0
  19. package/dist/device/state.d.ts +53 -0
  20. package/dist/device/state.d.ts.map +1 -0
  21. package/dist/device/state.js +196 -0
  22. package/dist/device/state.js.map +1 -0
  23. package/dist/dxt.d.ts +22 -0
  24. package/dist/dxt.d.ts.map +1 -0
  25. package/dist/dxt.js +304 -0
  26. package/dist/dxt.js.map +1 -0
  27. package/dist/errors.d.ts +7 -0
  28. package/dist/errors.d.ts.map +1 -0
  29. package/dist/errors.js +8 -0
  30. package/dist/errors.js.map +1 -0
  31. package/dist/index.d.ts +6 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +6 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/webgl/buffers.d.ts +27 -0
  36. package/dist/webgl/buffers.d.ts.map +1 -0
  37. package/dist/webgl/buffers.js +53 -0
  38. package/dist/webgl/buffers.js.map +1 -0
  39. package/dist/webgl/context.d.ts +123 -0
  40. package/dist/webgl/context.d.ts.map +1 -0
  41. package/dist/webgl/context.js +1368 -0
  42. package/dist/webgl/context.js.map +1 -0
  43. package/dist/webgl/index.d.ts +3 -0
  44. package/dist/webgl/index.d.ts.map +1 -0
  45. package/dist/webgl/index.js +2 -0
  46. package/dist/webgl/index.js.map +1 -0
  47. package/dist/webgl/limits.d.ts +23 -0
  48. package/dist/webgl/limits.d.ts.map +1 -0
  49. package/dist/webgl/limits.js +35 -0
  50. package/dist/webgl/limits.js.map +1 -0
  51. package/dist/webgl/programs.d.ts +22 -0
  52. package/dist/webgl/programs.d.ts.map +1 -0
  53. package/dist/webgl/programs.js +110 -0
  54. package/dist/webgl/programs.js.map +1 -0
  55. package/dist/webgl/state.d.ts +42 -0
  56. package/dist/webgl/state.d.ts.map +1 -0
  57. package/dist/webgl/state.js +55 -0
  58. package/dist/webgl/state.js.map +1 -0
  59. package/dist/webgl/targets.d.ts +20 -0
  60. package/dist/webgl/targets.d.ts.map +1 -0
  61. package/dist/webgl/targets.js +138 -0
  62. package/dist/webgl/targets.js.map +1 -0
  63. package/dist/webgl/textures.d.ts +28 -0
  64. package/dist/webgl/textures.d.ts.map +1 -0
  65. package/dist/webgl/textures.js +119 -0
  66. package/dist/webgl/textures.js.map +1 -0
  67. package/dist/webgl/validation.d.ts +4 -0
  68. package/dist/webgl/validation.d.ts.map +1 -0
  69. package/dist/webgl/validation.js +52 -0
  70. package/dist/webgl/validation.js.map +1 -0
  71. package/package.json +37 -3
  72. package/src/agal.ts +496 -0
  73. package/src/backend.ts +210 -0
  74. package/src/device/index.ts +5 -0
  75. package/src/device/programs.ts +66 -0
  76. package/src/device/state.ts +214 -0
  77. package/src/dxt.ts +349 -0
  78. package/src/errors.ts +68 -0
  79. package/src/index.ts +35 -0
  80. package/src/webgl/buffers.ts +102 -0
  81. package/src/webgl/context.ts +1803 -0
  82. package/src/webgl/index.ts +2 -0
  83. package/src/webgl/limits.ts +61 -0
  84. package/src/webgl/programs.ts +145 -0
  85. package/src/webgl/state.ts +65 -0
  86. package/src/webgl/targets.ts +229 -0
  87. package/src/webgl/textures.ts +200 -0
  88. package/src/webgl/validation.ts +72 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 The swf2es authors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
package/README.md CHANGED
@@ -1,3 +1,220 @@
1
- # Temporary Holding Version
1
+ # Experimental Context3D backend
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@swf2es/context3d` provides resource/lifecycle contracts and AGAL v1 to GLSL
4
+ translation. Its core has no dependencies or browser types. The optional
5
+ `@swf2es/context3d/webgl` entry exports `WebGLContext3D`, which owns the supplied
6
+ WebGL2 context exclusively. It does not share GL state or resources with the
7
+ display list's renderer.
8
+
9
+ The WebGL entry re-exports the context owner from `webgl/context.ts`. That owner
10
+ keeps resource maps, byte accounting, bindings and draw/present ordering together.
11
+ `buffers.ts` and `textures.ts` handle uploads; `programs.ts` handles shader linking
12
+ and uniform locations; `targets.ts` handles framebuffer allocation and resolves. Limits
13
+ and render-state constants live beside those modules. These are internal splits;
14
+ the package entries and ownership contracts stay the same.
15
+
16
+ This package does not enable Stage3D playback. The separate
17
+ `@swf2es/player/context3d` entry installs experimental Flash bindings, and
18
+ `@swf2es/player-hosts/stage3d` places canvases and attaches browser loss/restoration
19
+ listeners. Install the bindings before loading playerglobal, and call their
20
+ returned teardown before destroying Scripting. Default playback still reports
21
+ unavailable Context3D through ErrorEvent #3702.
22
+
23
+ The host supplies a positioned, clipped stage container, with the transparent
24
+ display-list canvas above Stage3D slots 0..3. Supply a surface factory to
25
+ `stage3DCanvasHost`; it returns a canvas and a backend for each requested slot.
26
+ Create the WebGL2 context with `alpha: false`, `antialias: false`, `depth: false`,
27
+ `stencil: false` and `preserveDrawingBuffer: true`. The backend manages its own
28
+ back-buffer attachments and copies to the canvas only at `present()`.
29
+
30
+ An optional second constructor argument sets resource budgets, for example
31
+ `new WebGLContext3D(gl, { maxTextureBytes: 32 * 1024 * 1024 })`.
32
+ Default counts match AIR's 4,096 resources independently for vertex buffers,
33
+ index buffers, programs, 2D textures, rectangle textures and cube textures.
34
+ `maxVertexBuffers`, `maxIndexBuffers`, `maxPrograms`, `max2DTextures`,
35
+ `maxRectangleTextures` and `maxCubeTextures` change those limits. `maxBuffers`
36
+ and `maxTextures` retain aggregate caps, defaulting to 8,192 and 12,288; an
37
+ explicit lower cap still limits the combined types.
38
+
39
+ Byte limits are independent by resource type and follow the observed AIR baseline
40
+ allowances for buffers and BGRA textures:
41
+
42
+ | Resource | Default | Constructor option |
43
+ | --- | --- | --- |
44
+ | Vertex buffers | 256 MiB | `maxVertexBufferBytes` |
45
+ | Index buffers | 128 MiB | `maxIndexBufferBytes` |
46
+ | 2D textures | 512 MiB | `max2DTextureBytes` |
47
+ | Rectangle textures | 512 MiB | `maxRectangleTextureBytes` |
48
+ | Cube textures | 256 MiB | `maxCubeTextureBytes` |
49
+
50
+ AIR probes with BGRA textures at multiple sizes show a mip reservation of half the base size
51
+ for ordinary and cube textures. Their per-type quota charge uses that reservation;
52
+ rectangles charge only their base level. The aggregate `maxTextureBytes` budget
53
+ still tracks the complete mip chains actually allocated, defaulting to 1,280 MiB.
54
+ `maxBufferBytes` defaults to 384 MiB. Explicit lower aggregate overrides continue
55
+ to bound combined storage independently of these allowances.
56
+
57
+ Target depth/stencil and multisample color storage retain separate 64 MiB host
58
+ policies (`maxTargetDepthBytes`, `maxTargetColorBytes`); equivalent AIR attachment
59
+ accounting remains unverified. Multisample storage counts actual samples and cube
60
+ targets include their cached single-sample resolve surface. All options must be
61
+ nonnegative safe integers, are copied at creation and allocate nothing eagerly.
62
+ Disposal returns both quota and storage capacity. These are logical allocation
63
+ accounts, not physical driver VRAM, and exclude back-buffer attachments.
64
+ Compressed textures ("compressed", "compressedAlpha") hold S3TC's DXT1 and
65
+ DXT5, which `Texture3D.uploadCompressed` takes as blocks; the player decodes
66
+ ATF to them (`@swf2es/native/atf`). The backend stores them with
67
+ `WEBGL_compressed_texture_s3tc` where the context has it, DXT1 with its bit of
68
+ alpha, as AIR draws a three-colour block's fourth texel transparent, and
69
+ decodes them to RGBA on the CPU (`dxt.ts`) where it has not. AIR charges their
70
+ quota at DXT1's eighth of the BGRA reservation and DXT5's quarter (a 2048
71
+ texture 3 MiB and 6 MiB: 170 and 85 fit), and the aggregate counts their
72
+ chains as S3TC's blocks even where the CPU decodes them to RGBA, so that every
73
+ GPU allocates alike. Compressed textures are at least 4x4 (Error #3745, here
74
+ `compressedSize`). A compressed texture also takes pixels, as AIR's does, and as AIR
75
+ compresses them, they are encoded to its blocks (`dxt.ts`), so that a GPU with
76
+ S3TC and one without draw them alike. The player injects its native whole-level
77
+ encoder through `setDxtEncoder`; standalone backends and native refusals use the
78
+ TypeScript encoder. `context3d` retains no dependency on `native`.
79
+ The RGBA staging array a texture uploads
80
+ through is made at its first pixel upload or CPU decoding, so compressed
81
+ textures uploaded as blocks on S3TC have none. Samplers must
82
+ read a texture as what it is, AGAL's format DXT1 or DXT5 for a compressed one
83
+ (#3763), where `samplerFormats` is set, as the player sets it for content from
84
+ SWF 17 on. `rgbaHalfFloat` and the packed formats remain unsupported and return
85
+ Error #3708 before backend allocation.
86
+
87
+ Core failures carry typed reasons. The Flash adapter maps them to catchable AS3
88
+ errors, including resource limits (#3691), disposed objects (#3694), draw bounds
89
+ and AGAL validation/linkage. Known unavailable modes or profiles report an
90
+ asynchronous ErrorEvent #3702 so content can retry baseline. Concurrent requests
91
+ coalesce; requesting again after creation retires the preceding context and
92
+ creates a new one. Broader unchecked-error precedence remains experimental.
93
+ The constructor rejects antialiased host contexts before allocating GPU handles:
94
+ its explicit resolve/present path requires `antialias: false`.
95
+
96
+ The adapter disposes GPU resources before the host removes the surface. After
97
+ browser context loss, the old surface stays attached so restoration can trigger
98
+ creation of a new context. The host detaches both listeners when removing it.
99
+ Uploads copy source storage before returning; `read()` reuses its output until
100
+ the next read. No AS objects or DOM objects cross the backend's core interface.
101
+ Bitmap uploads for 2D, rectangle and cube textures copy the top-left source
102
+ region and clear uncovered pixels without scaling. A mip upload can reuse a
103
+ larger bitmap; the backend preserves its row stride and reuses the texture's
104
+ base-sized staging array. Cube uploads update only the selected face and mip.
105
+ ByteArray uploads keep their exact selected-mip byte requirements.
106
+ An optional `Stage3DSurface.destroy` hook runs once when the surface is removed,
107
+ after backend disposal and listener removal; it also runs after failed attachment.
108
+ Use it to release the browser context without interfering with loss/restoration.
109
+
110
+ Sampler filters include nearest, linear and 2×/4×/8×/16× anisotropic filtering.
111
+ WebGL uses cached sampler objects and clamps anisotropy to the extension's
112
+ hardware limit. Without `EXT_texture_filter_anisotropic`, those requests use
113
+ linear filtering with the requested mip mode. Capability queries happen only on
114
+ the first anisotropic draw; warmed sampler changes allocate no new GPU objects.
115
+
116
+ Texture targets support hardware-dependent antialiasing requests up to 4×,
117
+ falling back to single-sample rendering when no compatible count is available.
118
+ The backend caches target attachments, retains color/depth across rebindings,
119
+ and resolves changed color before generating mipmaps. Warm target switches
120
+ allocate no GPU handles. Cube resolves use a cached 2D surface and a GPU copy,
121
+ which avoids corrupted direct multisample-to-cube blits in SwiftShader.
122
+
123
+ The Flash adapter reclaims resources after their AS wrappers become unreachable.
124
+ Active vertex, program, texture and render-target bindings keep their wrappers
125
+ alive until replaced, cleared or disposed. Explicit disposal and context teardown
126
+ release storage immediately. Allocation failures also reclaim already collected
127
+ wrappers whose finalizers have not run, then retry once. Garbage collection is
128
+ not prompt or guaranteed; explicit disposal remains preferable, and the hard
129
+ resource budgets still apply. Direct backend callers own their resources and
130
+ must dispose them or the context.
131
+
132
+ The current API and validation are experimental. Supported operations, AIR
133
+ references, unsupported formats/profiles and lifecycle stress tests are tracked
134
+ in [tests/context3d](../../tests/context3d/README.md). Stage3D playback remains off
135
+ by default. A web host can explicitly opt in before loading its first player:
136
+
137
+ ```ts
138
+ import { configure } from "@swf2es/web";
139
+ import { WebGLContext3D } from "@swf2es/context3d/webgl";
140
+
141
+ configure({
142
+ stage3D: () => {
143
+ const canvas = document.createElement("canvas");
144
+ const gl = canvas.getContext("webgl2", {
145
+ alpha: false, antialias: false, depth: false, stencil: false,
146
+ preserveDrawingBuffer: true,
147
+ });
148
+ if (!gl) {
149
+ throw new Error("WebGL2 is unavailable");
150
+ }
151
+
152
+ return {
153
+ canvas,
154
+ context: new WebGLContext3D(gl, {
155
+ maxBufferBytes: 64 * 1024 * 1024,
156
+ maxTextureBytes: 128 * 1024 * 1024,
157
+ maxTargetDepthBytes: 16 * 1024 * 1024,
158
+ maxTargetColorBytes: 16 * 1024 * 1024,
159
+ }),
160
+ destroy: () => gl.getExtension("WEBGL_lose_context")?.loseContext(),
161
+ };
162
+ },
163
+ });
164
+ ```
165
+
166
+ Each requested slot needs a fresh surface. `configure({ stage3D: null })` disables
167
+ the experiment for subsequent loads. The web element owns native installation,
168
+ composition, cancellation, restoration and teardown for each load. GPU backend
169
+ selection stays with the host; the default web entry does not eagerly import
170
+ the optional bindings or a backend. No new dependencies are required by `web`.
171
+
172
+ The web package sets no backend budgets: a factory using `new WebGLContext3D(gl)`
173
+ inherits the larger AIR-sized defaults, as the desktop factory does. This browser
174
+ example explicitly selects lower aggregate and attachment budgets per context;
175
+ they are host policy, not AIR limits or a guarantee against context loss. Tune
176
+ them for the workload and account for concurrent slots and players. The limits
177
+ exclude driver overhead and back-buffer attachments, so the browser can still
178
+ lose a context before a logical allocation limit is reached. The public demo
179
+ keeps Stage3D off by default; its experimental checkbox opts in with these lower budgets.
180
+
181
+ Stage3D positions follow the embedding's `scale`/`salign` placement. Configured
182
+ buffer sizes remain in pixels; resizing or changing device pixel ratio never
183
+ implicitly reallocates them. The host clips the viewports, makes the display
184
+ list transparent while contexts exist, and keeps overlapping players' canvases
185
+ in separate stacks. With Stage3D opted in, the web host honors ActionScript
186
+ changes to `Stage.scaleMode` and `Stage.align`. Ordinary playback retains dev's
187
+ fixed Stage getters, ignored setters and authored dimensions, including its
188
+ existing embedding alignment when both opposite edges are named. In `noScale`, Stage dimensions follow the
189
+ embedding's CSS size and resize events are synchronous after placement updates;
190
+ other modes report the authored dimensions. Display-list pixels and input use
191
+ the same viewport, including coordinates outside the authored rectangle.
192
+ A DPR change affects display-list resolution without changing Stage dimensions
193
+ or reallocating Stage3D buffers. Script settings override embedding defaults
194
+ independently. The desktop app offers the same host through View › Stage3D
195
+ (Experimental), off by default, with a remembered choice that restarts the
196
+ movie when changed. It uses the backend's per-type resource count limits and
197
+ byte budgets. The public demo lazily loads the backend when Stage3D is selected
198
+ and restarts the current SWF when the option changes. Its Restart and Close
199
+ controls release the preceding contexts. Best-resolution buffers remain later
200
+ work. None of this changes the ActionScript Worker API.
201
+
202
+ A future WebGPU backend can reuse the Flash adapter, resource contracts and AIR
203
+ fixtures. It still needs AGAL-to-WGSL translation, GPU resource/binding handling,
204
+ render-pipeline caching and device-loss recovery. Immediate readback needs a
205
+ separate execution design: `Context3D.read()` returns synchronously to Flash,
206
+ while WebGPU's [`GPUBuffer.mapAsync`](https://gpuweb.github.io/types/interfaces/GPUBuffer.html#mapAsync)
207
+ provides CPU access asynchronously. A worker bridge or another way to suspend
208
+ Flash execution would need validation before full compatibility could be claimed.
209
+
210
+ The display list and Stage3D use separate canvases. Display-list blend effects
211
+ sample the transparent 2D back buffer rather than Stage3D color, so blending
212
+ across those layers is an experimental limitation. `Playback.destroy()` disposes
213
+ the display-list scene before the renderer on ordinary loads as well as Stage3D
214
+ loads; this intentional shared cleanup releases cached text-style listeners.
215
+
216
+ Draw validation caches index-range summaries by upload version. Fully uploaded
217
+ vertex prefixes need no per-attribute index scan; sparse validation caches also
218
+ include the vertex version. Uploads, changed ranges/bindings and disposal
219
+ invalidate the relevant records. Warm draws add no validation arrays or GPU
220
+ handles.
package/dist/agal.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ export type ProgramType = "vertex" | "fragment";
2
+ export interface SamplerSource {
3
+ index: number;
4
+ /** What the sampler reads: 0 RGBA, 1 DXT1 ("compressed"), 2 DXT5 ("compressedAlpha"). */
5
+ format: number;
6
+ filter: number;
7
+ repeat: boolean;
8
+ mip: number;
9
+ cube: boolean;
10
+ ignore: boolean;
11
+ bias: number;
12
+ }
13
+ export interface ShaderSource {
14
+ source: string;
15
+ /** Written lanes for vertex programs, read lanes for fragment programs. */
16
+ varyings: Uint8Array;
17
+ attributes: number[];
18
+ constants: number[];
19
+ indirect: boolean;
20
+ samplers: SamplerSource[];
21
+ }
22
+ export declare function translate(bytes: Uint8Array, stage: ProgramType): ShaderSource;
23
+ //# sourceMappingURL=agal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agal.d.ts","sourceRoot":"","sources":["../src/agal.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEhD,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,yFAAyF;IACzF,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,QAAQ,EAAE,UAAU,CAAC;IACrB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,aAAa,EAAE,CAAC;CAC3B;AAQD,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,GAAG,YAAY,CA4c7E"}