@egret/engine 7.0.1-rc.3 → 7.0.2

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 (304) hide show
  1. package/dist/Engine.js +7 -2
  2. package/dist/animation/sequenceResetTypes.d.ts +6 -0
  3. package/dist/animation/types.d.ts +6 -0
  4. package/dist/assetBundle.d.ts +2 -0
  5. package/dist/assetGroupTypes.d.ts +2 -0
  6. package/dist/audioCues.d.ts +4 -0
  7. package/dist/audioTypes.d.ts +13 -0
  8. package/dist/bitmapButtonTypes.d.ts +2 -0
  9. package/dist/bitmapFontTypes.d.ts +3 -0
  10. package/dist/bitmapResourceSlot.d.ts +1 -0
  11. package/dist/camera2d.js +10 -2
  12. package/dist/cameraTypes.d.ts +12 -0
  13. package/dist/contentTypes.d.ts +2 -0
  14. package/dist/createEngineForProfile.js +8 -5
  15. package/dist/fontContentTypes.d.ts +5 -0
  16. package/dist/gameClockTypes.d.ts +6 -0
  17. package/dist/gameRun.d.ts +3 -0
  18. package/dist/gamepadTypes.d.ts +8 -0
  19. package/dist/hoverInputTypes.d.ts +10 -0
  20. package/dist/index.d.ts +5 -2
  21. package/dist/index.js +2 -1
  22. package/dist/inputActions.d.ts +5 -0
  23. package/dist/internal/uiFactoryState.d.ts +4 -0
  24. package/dist/internal/uiFactoryState.js +18 -2
  25. package/dist/keyboardInput.d.ts +1 -0
  26. package/dist/keyboardInput.js +1 -0
  27. package/dist/keyboardInputTypes.d.ts +12 -0
  28. package/dist/kit.d.ts +3 -1
  29. package/dist/kit.js +2 -1
  30. package/dist/manifestResourceState.d.ts +1 -0
  31. package/dist/manifestResourceState.js +1 -0
  32. package/dist/manifestResourceTypes.d.ts +1 -0
  33. package/dist/motion.d.ts +2 -0
  34. package/dist/mouseInputTypes.d.ts +4 -0
  35. package/dist/particleEmitter.js +8 -0
  36. package/dist/particleTypes.d.ts +8 -0
  37. package/dist/physics2d.d.ts +2 -2
  38. package/dist/physics2d.js +1 -1
  39. package/dist/physics2dTypes.d.ts +55 -1
  40. package/dist/physics2dWorld.js +209 -9
  41. package/dist/pointerInput.d.ts +1 -0
  42. package/dist/pointerInput.js +1 -0
  43. package/dist/pointerInputTypes.d.ts +3 -0
  44. package/dist/random.d.ts +1 -0
  45. package/dist/rendering/packSharedDraws2D.js +53 -5
  46. package/dist/rendering/prepareSharedDraws2D.d.ts +2 -0
  47. package/dist/rendering/prepareSharedDraws2D.js +17 -6
  48. package/dist/rendering/sharedColor2D.d.ts +35 -1
  49. package/dist/rendering/sharedColor2D.js +131 -8
  50. package/dist/rendering/sharedEffects2D.js +16 -8
  51. package/dist/rendering/world3d/Animation3D.d.ts +9 -0
  52. package/dist/rendering/world3d/Animation3D.js +4 -0
  53. package/dist/rendering/world3d/AnimationTexture3D.d.ts +6 -0
  54. package/dist/rendering/world3d/AnimationTexture3D.js +2 -0
  55. package/dist/rendering/world3d/Batch3D.d.ts +4 -0
  56. package/dist/rendering/world3d/Batch3D.js +3 -0
  57. package/dist/rendering/world3d/Camera3D.d.ts +5 -0
  58. package/dist/rendering/world3d/Camera3D.js +3 -0
  59. package/dist/rendering/world3d/Character3D.d.ts +4 -0
  60. package/dist/rendering/world3d/Character3D.js +2 -0
  61. package/dist/rendering/world3d/Cloth3D.d.ts +18 -3
  62. package/dist/rendering/world3d/Cloth3D.js +6 -1
  63. package/dist/rendering/world3d/Compression3D.d.ts +1 -0
  64. package/dist/rendering/world3d/Compression3D.js +1 -0
  65. package/dist/rendering/world3d/Curves3D.d.ts +8 -0
  66. package/dist/rendering/world3d/Curves3D.js +5 -0
  67. package/dist/rendering/world3d/Decal3D.d.ts +2 -0
  68. package/dist/rendering/world3d/Decal3D.js +1 -0
  69. package/dist/rendering/world3d/Export3D.d.ts +13 -0
  70. package/dist/rendering/world3d/Export3D.js +263 -0
  71. package/dist/rendering/world3d/Geometry3D.d.ts +11 -1
  72. package/dist/rendering/world3d/Geometry3D.js +10 -1
  73. package/dist/rendering/world3d/GeometryBuilder3D.d.ts +2 -0
  74. package/dist/rendering/world3d/Gizmo3D.d.ts +5 -0
  75. package/dist/rendering/world3d/Gizmo3D.js +2 -0
  76. package/dist/rendering/world3d/Gltf3D.d.ts +6 -0
  77. package/dist/rendering/world3d/Gltf3D.js +25 -5
  78. package/dist/rendering/world3d/GpuParticles3D.d.ts +2 -0
  79. package/dist/rendering/world3d/GpuParticles3D.js +1 -0
  80. package/dist/rendering/world3d/Hdr3D.d.ts +2 -0
  81. package/dist/rendering/world3d/Hdr3D.js +1 -0
  82. package/dist/rendering/world3d/Jelly3D.d.ts +2 -0
  83. package/dist/rendering/world3d/Jelly3D.js +1 -0
  84. package/dist/rendering/world3d/Ktx23D.d.ts +3 -0
  85. package/dist/rendering/world3d/Light3D.d.ts +9 -0
  86. package/dist/rendering/world3d/Light3D.js +4 -0
  87. package/dist/rendering/world3d/Material3D.d.ts +10 -0
  88. package/dist/rendering/world3d/Material3D.js +2 -0
  89. package/dist/rendering/world3d/Mesh3D.d.ts +4 -0
  90. package/dist/rendering/world3d/Mesh3D.js +16 -2
  91. package/dist/rendering/world3d/Meshopt3D.d.ts +3 -0
  92. package/dist/rendering/world3d/Meshopt3D.js +1 -0
  93. package/dist/rendering/world3d/Navigation3D.d.ts +41 -1
  94. package/dist/rendering/world3d/Navigation3D.js +74 -2
  95. package/dist/rendering/world3d/Object3D.d.ts +11 -0
  96. package/dist/rendering/world3d/Object3D.js +10 -0
  97. package/dist/rendering/world3d/Particles3D.d.ts +5 -0
  98. package/dist/rendering/world3d/Particles3D.js +3 -0
  99. package/dist/rendering/world3d/Physics3D.d.ts +14 -0
  100. package/dist/rendering/world3d/Physics3D.js +5 -0
  101. package/dist/rendering/world3d/PhysicsHull3D.d.ts +2 -0
  102. package/dist/rendering/world3d/PhysicsHull3D.js +2 -0
  103. package/dist/rendering/world3d/PhysicsMesh3D.d.ts +2 -0
  104. package/dist/rendering/world3d/PhysicsMesh3D.js +2 -0
  105. package/dist/rendering/world3d/PhysicsRemote3D.d.ts +5 -0
  106. package/dist/rendering/world3d/PhysicsRemote3D.js +2 -0
  107. package/dist/rendering/world3d/Ragdoll3D.d.ts +5 -0
  108. package/dist/rendering/world3d/Ragdoll3D.js +2 -0
  109. package/dist/rendering/world3d/Raycast3D.d.ts +3 -0
  110. package/dist/rendering/world3d/Raycast3D.js +1 -0
  111. package/dist/rendering/world3d/RenderList3D.d.ts +3 -0
  112. package/dist/rendering/world3d/RenderList3D.js +12 -0
  113. package/dist/rendering/world3d/Retarget3D.d.ts +1 -0
  114. package/dist/rendering/world3d/Rig3D.d.ts +57 -0
  115. package/dist/rendering/world3d/Rig3D.js +219 -0
  116. package/dist/rendering/world3d/Sdf3D.d.ts +181 -0
  117. package/dist/rendering/world3d/Sdf3D.js +1136 -0
  118. package/dist/rendering/world3d/SdfLod3D.d.ts +17 -0
  119. package/dist/rendering/world3d/SdfLod3D.js +56 -0
  120. package/dist/rendering/world3d/Serialize3D.d.ts +17 -0
  121. package/dist/rendering/world3d/Serialize3D.js +22 -0
  122. package/dist/rendering/world3d/Simplify3D.d.ts +29 -0
  123. package/dist/rendering/world3d/Simplify3D.js +426 -0
  124. package/dist/rendering/world3d/StateMachine3D.d.ts +9 -0
  125. package/dist/rendering/world3d/StateMachine3D.js +3 -0
  126. package/dist/rendering/world3d/SurfaceMaterial3D.d.ts +26 -0
  127. package/dist/rendering/world3d/SurfaceMaterial3D.js +138 -0
  128. package/dist/rendering/world3d/Terrain3D.d.ts +21 -0
  129. package/dist/rendering/world3d/Terrain3D.js +25 -1
  130. package/dist/rendering/world3d/Text3D.d.ts +5 -0
  131. package/dist/rendering/world3d/Text3D.js +2 -0
  132. package/dist/rendering/world3d/Texture3D.d.ts +16 -1
  133. package/dist/rendering/world3d/Texture3D.js +19 -1
  134. package/dist/rendering/world3d/Trail3D.d.ts +3 -0
  135. package/dist/rendering/world3d/Trail3D.js +2 -0
  136. package/dist/rendering/world3d/Vehicle3D.d.ts +5 -0
  137. package/dist/rendering/world3d/Vehicle3D.js +2 -0
  138. package/dist/rendering/world3d/VolumetricFog3D.d.ts +2 -0
  139. package/dist/rendering/world3d/VolumetricFog3D.js +1 -0
  140. package/dist/rendering/world3d/Water3D.d.ts +2 -0
  141. package/dist/rendering/world3d/Water3D.js +1 -0
  142. package/dist/rendering/world3d/core3D.d.ts +2 -0
  143. package/dist/rendering/world3d/debug3D.d.ts +5 -0
  144. package/dist/rendering/world3d/debug3D.js +5 -0
  145. package/dist/rendering/world3d/geometries3D.d.ts +12 -0
  146. package/dist/rendering/world3d/geometries3D.js +5 -0
  147. package/dist/rendering/world3d/helpers3D.d.ts +2 -0
  148. package/dist/rendering/world3d/helpers3D.js +1 -0
  149. package/dist/rendering/world3d/index.d.ts +12 -0
  150. package/dist/rendering/world3d/index.js +6 -0
  151. package/dist/rendering/world3d/math3D.d.ts +36 -0
  152. package/dist/rendering/world3d/math3D.js +35 -0
  153. package/dist/rendering/world3d/primitives3D.d.ts +7 -0
  154. package/dist/rendering/world3d/primitives3D.js +1 -0
  155. package/dist/saveStore.d.ts +18 -3
  156. package/dist/saveStore.js +23 -4
  157. package/dist/semanticList.d.ts +4 -0
  158. package/dist/semanticList.js +1 -0
  159. package/dist/semanticTree.js +11 -4
  160. package/dist/semanticTypes.d.ts +8 -0
  161. package/dist/sequencePlaybackTypes.d.ts +3 -0
  162. package/dist/text.d.ts +1 -0
  163. package/dist/textTable.d.ts +41 -0
  164. package/dist/textTable.js +114 -0
  165. package/dist/tilemapTypes.d.ts +13 -0
  166. package/dist/timer.d.ts +34 -0
  167. package/dist/timer.js +119 -0
  168. package/dist/tweenTypes.d.ts +4 -0
  169. package/dist/ui/controlKeys.d.ts +4 -0
  170. package/dist/ui/controlKeys.js +1 -0
  171. package/dist/ui/controls.d.ts +6 -0
  172. package/dist/ui/controls.js +2 -0
  173. package/dist/ui/layerTypes.d.ts +7 -0
  174. package/dist/ui/rangeControl.d.ts +3 -0
  175. package/dist/ui/rangeControl.js +1 -0
  176. package/dist/ui/scrollControl.d.ts +12 -0
  177. package/dist/ui/scrollControl.js +5 -1
  178. package/dist/ui/stateControls.d.ts +8 -0
  179. package/dist/ui/stateControls.js +3 -0
  180. package/dist/ui/textEditor.d.ts +1 -0
  181. package/dist/ui/textEditor.js +1 -0
  182. package/dist/ui/textEditorTypes.d.ts +7 -0
  183. package/dist/ui/textFieldControl.d.ts +4 -0
  184. package/dist/ui/textFieldControl.js +1 -0
  185. package/dist/ui/theme.d.ts +5 -0
  186. package/dist/ui/theme.js +1 -0
  187. package/dist/ui/types.d.ts +20 -0
  188. package/dist/ui/uiRoot.js +38 -9
  189. package/dist/ui/uiRootModel.d.ts +3 -1
  190. package/dist/ui/uiRootModel.js +8 -2
  191. package/dist/videoTypes.d.ts +3 -0
  192. package/dist/web/BrowserAssetBundle.d.ts +2 -0
  193. package/dist/web/BrowserAudio.d.ts +34 -1
  194. package/dist/web/BrowserAudio.js +69 -39
  195. package/dist/web/BrowserFrameLoop.d.ts +4 -0
  196. package/dist/web/BrowserGame.d.ts +64 -2
  197. package/dist/web/BrowserGame.js +129 -8
  198. package/dist/web/BrowserGamepadInput.d.ts +3 -0
  199. package/dist/web/BrowserHoverInput.d.ts +1 -0
  200. package/dist/web/BrowserImageTextures.d.ts +6 -0
  201. package/dist/web/BrowserInputActions.d.ts +10 -0
  202. package/dist/web/BrowserInputActions.js +4 -1
  203. package/dist/web/BrowserPlay.d.ts +130 -2
  204. package/dist/web/BrowserPlay.js +366 -19
  205. package/dist/web/BrowserPreferences.d.ts +10 -0
  206. package/dist/web/BrowserPreferences.js +39 -0
  207. package/dist/web/BrowserSemantics.d.ts +2 -0
  208. package/dist/web/BrowserStatsPanel.d.ts +10 -0
  209. package/dist/web/BrowserStatsPanel.js +9 -3
  210. package/dist/web/BrowserStorage.d.ts +2 -0
  211. package/dist/web/BrowserTextEditor.d.ts +3 -0
  212. package/dist/web/BrowserTextInput.d.ts +6 -0
  213. package/dist/web/BrowserTextureProvider.d.ts +6 -0
  214. package/dist/web/BrowserVideo.d.ts +13 -1
  215. package/dist/web/BrowserVideo.js +28 -2
  216. package/dist/web/CanvasKitFontSetProvider.d.ts +3 -0
  217. package/dist/web/CanvasKitParagraphProvider.d.ts +4 -0
  218. package/dist/web/CanvasKitParagraphProvider.js +1 -0
  219. package/dist/web/ManifestByteSource.d.ts +4 -0
  220. package/dist/web/ManifestByteSource.js +1 -0
  221. package/dist/web/ManifestFontContentLoader.d.ts +1 -0
  222. package/dist/web/WebGL2Host.js +64 -25
  223. package/dist/web/WebGPUHost.d.ts +13 -0
  224. package/dist/web/WebGPUHost.js +117 -36
  225. package/dist/web/audio.d.ts +2 -2
  226. package/dist/web/audio.js +1 -1
  227. package/dist/web/editorFonts.d.ts +4 -0
  228. package/dist/web/game.d.ts +1 -1
  229. package/dist/web/imageProjections2D.d.ts +2 -0
  230. package/dist/web/kit.d.ts +1 -0
  231. package/dist/web/kit.js +1 -0
  232. package/dist/web/play.d.ts +6 -1
  233. package/dist/web/play.js +4 -1
  234. package/dist/web/playMusic.d.ts +33 -0
  235. package/dist/web/playMusic.js +194 -0
  236. package/dist/web/playTouch.d.ts +45 -0
  237. package/dist/web/playTouch.js +141 -0
  238. package/dist/web/playWidgets.d.ts +71 -0
  239. package/dist/web/playWidgets.js +431 -0
  240. package/dist/web/prepareSharedSubmission2D.js +9 -3
  241. package/dist/web/resources.d.ts +2 -0
  242. package/dist/web/sharedEffectShaders.d.ts +6 -2
  243. package/dist/web/sharedEffectShaders.js +23 -7
  244. package/dist/web/sharedSubmissionStorage2D.js +1 -1
  245. package/dist/web/sharedWebGL2Options.d.ts +3 -0
  246. package/dist/web/sharedWebGL2Options.js +8 -2
  247. package/dist/web/sharedWebGL2Shaders.d.ts +15 -2
  248. package/dist/web/sharedWebGL2Shaders.js +108 -14
  249. package/dist/web/sharedWebGPUOptions.d.ts +5 -1
  250. package/dist/web/sharedWebGPUOptions.js +6 -2
  251. package/dist/web/video.d.ts +1 -1
  252. package/dist/web/webgl2Native.d.ts +3 -1
  253. package/dist/web/webgl2Native.js +9 -5
  254. package/dist/web/webgl2Types.d.ts +18 -0
  255. package/dist/web/webgpuImageResidency.d.ts +5 -2
  256. package/dist/web/webgpuImageResidency.js +7 -3
  257. package/dist/web/webgpuRetentionPool.d.ts +2 -2
  258. package/dist/web/webgpuRetentionPool.js +2 -1
  259. package/dist/web/webgpuSharedPass.d.ts +1 -1
  260. package/dist/web/webgpuSharedPass.js +87 -5
  261. package/dist/web/webgpuSharedResolvePass.d.ts +1 -1
  262. package/dist/web/webgpuSharedResolvePass.js +9 -4
  263. package/dist/web/world3d/Audio3D.d.ts +18 -1
  264. package/dist/web/world3d/Audio3D.js +62 -3
  265. package/dist/web/world3d/BrowserPlay3D.d.ts +115 -2
  266. package/dist/web/world3d/BrowserPlay3D.js +448 -43
  267. package/dist/web/world3d/FlyControls3D.d.ts +4 -0
  268. package/dist/web/world3d/FlyControls3D.js +2 -0
  269. package/dist/web/world3d/FollowControls3D.d.ts +3 -0
  270. package/dist/web/world3d/FollowControls3D.js +2 -0
  271. package/dist/web/world3d/OrbitControls3D.d.ts +3 -0
  272. package/dist/web/world3d/OrbitControls3D.js +2 -0
  273. package/dist/web/world3d/TransformControls3D.d.ts +5 -2
  274. package/dist/web/world3d/TransformControls3D.js +7 -4
  275. package/dist/web/world3d/WebGL2Renderer3D.d.ts +3 -0
  276. package/dist/web/world3d/WebGL2Renderer3D.js +2 -0
  277. package/dist/web/world3d/WebGPURenderer3D.d.ts +2 -0
  278. package/dist/web/world3d/WebGPURenderer3D.js +1 -0
  279. package/dist/web/world3d/World3DView.d.ts +3 -0
  280. package/dist/web/world3d/World3DView.js +2 -0
  281. package/dist/web/world3d/app3D.d.ts +7 -0
  282. package/dist/web/world3d/app3D.js +1 -0
  283. package/dist/web/world3d/assets3D.d.ts +1 -0
  284. package/dist/web/world3d/atmosphere3D.d.ts +9 -0
  285. package/dist/web/world3d/atmosphere3D.js +19 -4
  286. package/dist/web/world3d/canvasFont3D.d.ts +21 -0
  287. package/dist/web/world3d/canvasFont3D.js +165 -0
  288. package/dist/web/world3d/frame3D.d.ts +2 -0
  289. package/dist/web/world3d/host3D.d.ts +1 -0
  290. package/dist/web/world3d/index.d.ts +4 -2
  291. package/dist/web/world3d/index.js +2 -1
  292. package/dist/web/world3d/loaders3D.d.ts +1 -0
  293. package/dist/web/world3d/markers3D.d.ts +4 -0
  294. package/dist/web/world3d/overlay3D.d.ts +19 -0
  295. package/dist/web/world3d/overlay3D.js +21 -4
  296. package/dist/web/world3d/post3D.d.ts +4 -0
  297. package/dist/web/world3d/post3D.js +3 -0
  298. package/dist/web/world3d/probe3D.d.ts +1 -0
  299. package/dist/web/world3d/stats3D.d.ts +3 -0
  300. package/dist/web/world3d/stats3D.js +1 -0
  301. package/dist/web/world3d/webGL2FrameMetrics3D.d.ts +5 -0
  302. package/dist/web/world3d/webgpu.d.ts +2 -0
  303. package/dist/web/world3d/webgpu.js +1 -0
  304. package/package.json +3 -3
@@ -10,13 +10,13 @@ import { GeometryPreparationError } from '../rendering/prepareRectangles2D.js';
10
10
  import { packSharedDraws2D, packSharedRegions2D, SHARED_BATCH_PAGES_2D, SHARED_REGION_WINDOW_BYTES_2D } from '../rendering/packSharedDraws2D.js';
11
11
  import { PreparedBatchScratch2D } from '../rendering/preparedBatches2D.js';
12
12
  import { prepareSharedBatches2D } from '../rendering/preparedSharedBatches2D.js';
13
- import { decodeSharedSRGBByte } from '../rendering/sharedColor2D.js';
13
+ import { sharedBlendSpace2D, sharedPageLevelLayout2D, sharedPageChainBytes2D, sharedTargetChannel2D } from '../rendering/sharedColor2D.js';
14
14
  import { runOwnedPreparationScope } from '../rendering/ownedPreparationFailure2D.js';
15
15
  import { planSharedStorageFees2D, withSharedReadbackLayout2D, checkSharedCapacity2D, materializeSharedPages2D, SharedStorageError2D } from './sharedSubmissionStorage2D.js';
16
16
  import { planSharedWebGL2Arenas, checkSharedWebGL2ArenaCapacity, qualifySharedWebGL2Alignment } from './sharedWebGL2Arena.js';
17
17
  import { createRetentionLedger } from './sharedRetentionLedger.js';
18
18
  import { GLNativeSession, glFailure, isGLFailure } from './webgl2Native.js';
19
- import { sharedWebGL2VertexSource, sharedWebGL2FragmentSource, sharedWebGL2PagedFragmentSource, sharedWebGL2SolidVertexSource, sharedWebGL2SolidFragmentSource, sharedWebGL2ResolveVertexSource, sharedWebGL2ResolveFragmentSource, sharedWebGL2BlendFactors } from './sharedWebGL2Shaders.js';
19
+ import { sharedWebGL2VertexSource, sampledFragmentSource, sharedWebGL2SolidVertexSource, sharedWebGL2SolidFragment, sharedWebGL2ResolveVertexSource, sharedWebGL2ResolveFragment, sharedWebGL2BlendFactors } from './sharedWebGL2Shaders.js';
20
20
  import { MAX_LAYER_HANDLES, MAX_LAYER_EXTENT, MAX_LAYER_BYTES, createWebGL2LayerProgram, readWebGL2LayerEffect, readWebGL2LayerPlacement } from './webgl2LayerState.js';
21
21
  const schedule = globalThis.setTimeout.bind(globalThis), cancel = globalThis.clearTimeout.bind(globalThis);
22
22
  const invoke = Reflect.apply;
@@ -65,6 +65,8 @@ const DRAW_UNIFORM_MEMBERS = [
65
65
  class SharedGLHost {
66
66
  surface;
67
67
  sharedFrameProfile = SHARED_FRAME_PROFILE_2D;
68
+ /** The space this Host mixes in; an Engine's frames record it. */
69
+ sharedBlendSpace;
68
70
  options;
69
71
  callback;
70
72
  state = 'new';
@@ -192,12 +194,15 @@ class SharedGLHost {
192
194
  removeListeners;
193
195
  unsafe = false;
194
196
  retiredUnknownBytes = 0;
197
+ /** Draw calls of the last frame drawn: its draws, effect passes, layers and the resolve to the canvas. */
198
+ frameDrawCalls = 0;
195
199
  retiredUnknownObjects = 0;
196
200
  constructor(input) {
197
201
  try {
198
202
  const admitted = admitSharedWebGL2Options(input);
199
203
  this.surface = admitted.surface;
200
204
  this.options = admitted.configuration;
205
+ this.sharedBlendSpace = admitted.configuration.blendSpace;
201
206
  this.callback = admitted.callback;
202
207
  this.frameTiming = admitted.measureSharedFrames ? createFrameTiming() : undefined;
203
208
  }
@@ -206,6 +211,7 @@ class SharedGLHost {
206
211
  }
207
212
  Object.defineProperty(this, 'surface', { writable: false, configurable: false });
208
213
  Object.defineProperty(this, 'sharedFrameProfile', { writable: false, configurable: false });
214
+ Object.defineProperty(this, 'sharedBlendSpace', { writable: false, configurable: false });
209
215
  this.cpu.resolve();
210
216
  }
211
217
  recordTiming(phase, startMs, generation, serial) {
@@ -615,6 +621,7 @@ class SharedGLHost {
615
621
  this.bindListeners();
616
622
  const generation = this.generation;
617
623
  const native = new GLNativeSession(context, () => this.generationGate(token), this.resourceNative, this.frameTiming ? (phase, started, serial) => this.recordTiming(phase, started, generation, serial) : undefined);
624
+ native.codedTargets = this.options.blendSpace === 'srgb';
618
625
  this.native = native;
619
626
  const gl = native.gl, attrs = gl.getContextAttributes();
620
627
  if (context.canvas !== this.surface ||
@@ -678,15 +685,16 @@ class SharedGLHost {
678
685
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
679
686
  if (!native.cleanup(target))
680
687
  throw glFailure('WEBGL2_CLOSE_UNSAFE', native.cleanupFailure?.cause);
681
- this.program = native.program(sharedWebGL2VertexSource, sharedWebGL2FragmentSource);
688
+ const coded = native.codedTargets;
689
+ this.program = native.program(sharedWebGL2VertexSource, sampledFragmentSource(false, coded));
682
690
  native.block(this.program, 'DrawUniform', DRAW_UNIFORM_MEMBERS, 128);
683
691
  native.block(this.program, 'RegionWindow', ['regions'], SHARED_REGION_WINDOW_BYTES_2D, 1);
684
- this.solidProgram = native.program(sharedWebGL2SolidVertexSource, sharedWebGL2SolidFragmentSource);
692
+ this.solidProgram = native.program(sharedWebGL2SolidVertexSource, sharedWebGL2SolidFragment(coded));
685
693
  native.block(this.solidProgram, 'DrawUniform', DRAW_UNIFORM_MEMBERS, 128);
686
- this.resolveProgram = native.program(sharedWebGL2ResolveVertexSource, sharedWebGL2ResolveFragmentSource);
694
+ this.resolveProgram = native.program(sharedWebGL2ResolveVertexSource, sharedWebGL2ResolveFragment(coded));
687
695
  if (this.options.enableEffects)
688
696
  for (const mode of EFFECT_PASSES) {
689
- const program = native.program(sharedWebGL2ResolveVertexSource, sharedEffectGLSL(mode));
697
+ const program = native.program(sharedWebGL2ResolveVertexSource, sharedEffectGLSL(mode, coded));
690
698
  const index = gl.getUniformBlockIndex(program, 'Effect');
691
699
  if (index === gl.INVALID_INDEX)
692
700
  throw glFailure('WEBGL2_CONTEXT_LIMIT');
@@ -694,7 +702,7 @@ class SharedGLHost {
694
702
  this.effectPrograms.set(mode, program);
695
703
  }
696
704
  // The program of a batch of several pages. Its eight page samplers name the eight units once, here.
697
- this.pagedProgram = native.program(sharedWebGL2VertexSource, sharedWebGL2PagedFragmentSource);
705
+ this.pagedProgram = native.program(sharedWebGL2VertexSource, sampledFragmentSource(true, coded));
698
706
  native.block(this.pagedProgram, 'DrawUniform', DRAW_UNIFORM_MEMBERS, 128);
699
707
  native.block(this.pagedProgram, 'RegionWindow', ['regions'], SHARED_REGION_WINDOW_BYTES_2D, 1);
700
708
  gl.useProgram(this.pagedProgram);
@@ -982,7 +990,8 @@ class SharedGLHost {
982
990
  : undefined;
983
991
  const options = layerWrite ? { ...this.options, pixelRatio: 1 } : this.options;
984
992
  const alpha = layerWrite ? 'premultiplied' : options.outputAlpha;
985
- if (frame.outputAlpha !== alpha ||
993
+ if (sharedBlendSpace2D(frame) !== this.options.blendSpace ||
994
+ frame.outputAlpha !== alpha ||
986
995
  frame.outputRepresentation !==
987
996
  (alpha === 'opaque' ? 'egret.srgb-opaque-unorm8/1' : 'egret.srgb-premultiplied-unorm8/1'))
988
997
  throw glFailure('WEBGL2_FRAME_PROFILE_UNSUPPORTED');
@@ -1026,11 +1035,15 @@ class SharedGLHost {
1026
1035
  height > limits.viewportHeight)
1027
1036
  throw glFailure('WEBGL2_CONTEXT_LIMIT');
1028
1037
  const projectionPlan = {
1029
- views: frame.pages.map(({ source: image }) => ({
1030
- image,
1031
- region: { x: 0, y: 0, width: image.width, height: image.height },
1032
- byteLength: image.byteLength
1033
- })),
1038
+ views: frame.pages.map(({ source: image }, index) => {
1039
+ const levels = prepared.pageLevels?.[index] ?? 1;
1040
+ return {
1041
+ image,
1042
+ region: { x: 0, y: 0, width: image.width, height: image.height },
1043
+ byteLength: levels === 1 ? image.byteLength : sharedPageChainBytes2D(image.width, image.height, levels),
1044
+ levels
1045
+ };
1046
+ }),
1034
1047
  commandViews: [],
1035
1048
  projectionBytes: prepared.pageBytes,
1036
1049
  scratchBytes: 0
@@ -1044,7 +1057,11 @@ class SharedGLHost {
1044
1057
  const cold = new Set(), hits = new Map();
1045
1058
  const trackPage = (index) => {
1046
1059
  const hit = this.pages.get(projectionPlan.views[index].image);
1047
- if (hit?.ready && hit.generation === this.generation && hit.native.outcome === 'owned')
1060
+ // A page kept without the smaller copies a draw now samples is uploaded again, with them.
1061
+ if (hit?.ready &&
1062
+ hit.generation === this.generation &&
1063
+ hit.native.outcome === 'owned' &&
1064
+ hit.levels >= (projectionPlan.views[index].levels ?? 1))
1048
1065
  hits.set(index, hit);
1049
1066
  else
1050
1067
  cold.add(index);
@@ -1475,19 +1492,29 @@ class SharedGLHost {
1475
1492
  const pixels = record.projections[index];
1476
1493
  if (!pixels)
1477
1494
  continue;
1478
- const source = record.storage.projectionPlan.views[index].image, owner = native.create('Texture', source.byteLength, undefined, record);
1495
+ const view = record.storage.projectionPlan.views[index], source = view.image, levels = view.levels ?? 1, owner = native.create('Texture', view.byteLength, undefined, record);
1479
1496
  const page = {
1480
1497
  source,
1481
1498
  native: owner,
1482
1499
  generation: record.generation,
1483
1500
  white: whitePixel(source, pixels),
1501
+ levels,
1484
1502
  ready: false,
1485
1503
  pins: 1
1486
1504
  };
1487
1505
  record.pages.push(page);
1488
1506
  work.layout.pageTextures.set(index, page);
1489
- native.texture(owner, source.width, source.height, false);
1490
- work.writes.push({ kind: 'page', page, pixels, row: 0 });
1507
+ native.texture(owner, source.width, source.height, false, levels);
1508
+ for (const [level, { width, height, offset }] of sharedPageLevelLayout2D(source.width, source.height, levels).entries())
1509
+ work.writes.push({
1510
+ kind: 'page',
1511
+ page,
1512
+ pixels: pixels.subarray(offset, offset + 4 * width * height),
1513
+ row: 0,
1514
+ level,
1515
+ width,
1516
+ height
1517
+ });
1491
1518
  }
1492
1519
  const buffer = (target, lease, offset, data, unit) => {
1493
1520
  if (data.byteLength)
@@ -1529,18 +1556,18 @@ class SharedGLHost {
1529
1556
  while (work.writeIndex < work.writes.length) {
1530
1557
  const write = work.writes[work.writeIndex];
1531
1558
  if (write.kind === 'page') {
1532
- const { source } = write.page, stride = source.width * 4;
1559
+ const stride = write.width * 4;
1533
1560
  if (stride > 4194304)
1534
1561
  throw glFailure('WEBGL2_FRAME_BUDGET');
1535
- const rows = Math.min(source.height - write.row, Math.floor(remaining / stride));
1562
+ const rows = Math.min(write.height - write.row, Math.floor(remaining / stride));
1536
1563
  if (rows === 0)
1537
1564
  break;
1538
1565
  gl.bindTexture(gl.TEXTURE_2D, write.page.native.value);
1539
1566
  const bytes = rows * stride, offset = write.row * stride;
1540
- gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, write.row, source.width, rows, gl.RGBA, gl.UNSIGNED_BYTE, write.pixels.subarray(offset, offset + bytes));
1567
+ gl.texSubImage2D(gl.TEXTURE_2D, write.level, 0, write.row, write.width, rows, gl.RGBA, gl.UNSIGNED_BYTE, write.pixels.subarray(offset, offset + bytes));
1541
1568
  write.row += rows;
1542
1569
  remaining -= bytes;
1543
- if (write.row === source.height)
1570
+ if (write.row === write.height)
1544
1571
  work.writeIndex++;
1545
1572
  }
1546
1573
  else {
@@ -1790,19 +1817,21 @@ class SharedGLHost {
1790
1817
  const pixels = p.projections[index];
1791
1818
  if (!pixels)
1792
1819
  continue;
1793
- const source = p.storage.projectionPlan.views[index].image, owner = native.create('Texture', source.byteLength, undefined, record);
1820
+ const view = p.storage.projectionPlan.views[index], source = view.image, levels = view.levels ?? 1, owner = native.create('Texture', view.byteLength, undefined, record);
1794
1821
  const page = {
1795
1822
  source,
1796
1823
  native: owner,
1797
1824
  generation: this.generation,
1798
1825
  white: whitePixel(source, pixels),
1826
+ levels,
1799
1827
  ready: false,
1800
1828
  pins: 1
1801
1829
  };
1802
1830
  record.pages.push(page);
1803
1831
  pageTextures.set(index, page);
1804
- native.texture(owner, source.width, source.height, false);
1805
- gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, source.width, source.height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
1832
+ native.texture(owner, source.width, source.height, false, levels);
1833
+ for (const [level, { width, height, offset }] of sharedPageLevelLayout2D(source.width, source.height, levels).entries())
1834
+ gl.texSubImage2D(gl.TEXTURE_2D, level, 0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels.subarray(offset, offset + 4 * width * height));
1806
1835
  }
1807
1836
  if (vertex >= 0) {
1808
1837
  gl.bindBuffer(gl.ARRAY_BUFFER, record.leases[vertex].handle.resource.value);
@@ -1918,6 +1947,7 @@ class SharedGLHost {
1918
1947
  gl.uniform2f(variant.origin, read.x, read.y);
1919
1948
  gl.uniform2f(variant.extent, read.width, read.height);
1920
1949
  gl.drawArrays(gl.TRIANGLES, 0, 6);
1950
+ this.frameDrawCalls++;
1921
1951
  }
1922
1952
  gl.bindTexture(gl.TEXTURE_2D, null);
1923
1953
  }
@@ -1933,6 +1963,7 @@ class SharedGLHost {
1933
1963
  return variant;
1934
1964
  }
1935
1965
  drawRecord(record, layout, arena) {
1966
+ this.frameDrawCalls = 0;
1936
1967
  const native = record.native, gl = native.gl, { width, height, frame } = record.storage.prepared;
1937
1968
  const { vertex, uniform, regions, color, pageTextures } = layout;
1938
1969
  const colorTexture = (record.layerWrite?.revision?.owner ?? record.leases[color].handle.resource)
@@ -1943,7 +1974,9 @@ class SharedGLHost {
1943
1974
  native.workingAttachment(colorTexture, null);
1944
1975
  gl.drawBuffers([gl.COLOR_ATTACHMENT0]);
1945
1976
  const c = frame.clearColor, a = frame.clearAlpha;
1946
- gl.clearColor(a * decodeSharedSRGBByte(c >>> 16), a * decodeSharedSRGBByte(c >>> 8), a * decodeSharedSRGBByte(c), a);
1977
+ // The clear colour as the target holds it: light, or the codes of a target that mixes them.
1978
+ const space = this.options.blendSpace;
1979
+ gl.clearColor(a * sharedTargetChannel2D(space, c >>> 16), a * sharedTargetChannel2D(space, c >>> 8), a * sharedTargetChannel2D(space, c), a);
1947
1980
  gl.clear(gl.COLOR_BUFFER_BIT);
1948
1981
  // The program and the window of the region table that are current; both change only between batches.
1949
1982
  let program, bound = -1;
@@ -2016,6 +2049,7 @@ class SharedGLHost {
2016
2049
  const blend = sharedWebGL2BlendFactors(draw.prepared.material.blend);
2017
2050
  gl.blendFuncSeparate(...blend);
2018
2051
  gl.drawArrays(gl.TRIANGLES, range.firstVertex, draw.vertexCount);
2052
+ this.frameDrawCalls++;
2019
2053
  };
2020
2054
  this.drawLayers(record, width, height);
2021
2055
  bindDraw();
@@ -2064,6 +2098,7 @@ class SharedGLHost {
2064
2098
  gl.disable(gl.BLEND);
2065
2099
  gl.bindBufferRange(gl.UNIFORM_BUFFER, 0, record.leases[layout.effectUniforms[groups.indexOf(group)]].handle.resource.value, 0, EFFECT_UNIFORM_BYTES);
2066
2100
  gl.drawArrays(gl.TRIANGLES, 0, 3);
2101
+ this.frameDrawCalls++;
2067
2102
  gl.activeTexture(gl.TEXTURE0 + 2);
2068
2103
  gl.bindTexture(gl.TEXTURE_2D, null);
2069
2104
  gl.activeTexture(gl.TEXTURE1);
@@ -2118,6 +2153,7 @@ class SharedGLHost {
2118
2153
  gl.uniform1i(gl.getUniformLocation(this.resolveProgram, 'workingTexture'), 0);
2119
2154
  gl.uniform1i(gl.getUniformLocation(this.resolveProgram, 'opaque'), this.options.outputAlpha === 'opaque' ? 1 : 0);
2120
2155
  gl.drawArrays(gl.TRIANGLES, 0, 3);
2156
+ this.frameDrawCalls++;
2121
2157
  if (record.ticket) {
2122
2158
  record.pbo = native.create('Buffer', record.storage.staging);
2123
2159
  gl.bindBuffer(gl.PIXEL_PACK_BUFFER, record.pbo.value);
@@ -2644,6 +2680,9 @@ class SharedGLHost {
2644
2680
  cleanupOutcome: this.cleanupOutcome
2645
2681
  });
2646
2682
  }
2683
+ getFrameDrawCalls() {
2684
+ return this.frameDrawCalls;
2685
+ }
2647
2686
  getSharedStatus() {
2648
2687
  const owner = this.snapshot(), unknown = this.native?.unknown() ?? { bytes: 0, objects: 0 }, retention = this.pool.getStatus();
2649
2688
  return Object.freeze({
@@ -3,17 +3,22 @@ import type { SharedFrameUploadOptions, SharedFrameUpload } from './sharedFrameU
3
3
  import type { SharedRenderFrame2D, SharedRenderHostAdapter } from '@egret/contracts';
4
4
  import type { SharedWebGPUHostOptions } from './sharedWebGPUOptions.js';
5
5
  export type { SharedWebGPUHostOptions } from './sharedWebGPUOptions.js';
6
+ /** Where a WebGPU host is: new, starting, active, stopped, failed, closing or closed. */
6
7
  export type WebGPUHostState = 'new' | 'starting' | 'active' | 'stopped' | 'failed' | 'closing' | 'closed';
8
+ /** What went wrong in a WebGPU host. */
7
9
  export type WebGPUHostErrorCode = 'WEBGPU_OPTIONS_INVALID' | 'WEBGPU_UNAVAILABLE' | 'WEBGPU_ADAPTER_UNAVAILABLE' | 'WEBGPU_DEVICE_FAILED' | 'WEBGPU_CONTEXT_UNAVAILABLE' | 'WEBGPU_FORMAT_UNSUPPORTED' | 'WEBGPU_START_FAILED' | 'WEBGPU_START_CANCELLED' | 'WEBGPU_NOT_STARTED' | 'WEBGPU_STOPPED' | 'WEBGPU_CLOSED' | 'WEBGPU_FAILED' | 'WEBGPU_REENTRANT' | 'WEBGPU_FRAME_PROFILE_UNSUPPORTED' | 'WEBGPU_FRAME_INVALID' | 'WEBGPU_BACKING_LIMIT' | 'WEBGPU_GEOMETRY_RANGE' | 'WEBGPU_PRECISION_UNSUPPORTED' | 'WEBGPU_FRAME_BUDGET' | 'WEBGPU_BACKPRESSURE' | 'WEBGPU_DEVICE_LIMIT' | 'WEBGPU_SERIAL_EXHAUSTED' | 'WEBGPU_RENDER_FAILED' | 'WEBGPU_VALIDATION' | 'WEBGPU_OUT_OF_MEMORY' | 'WEBGPU_INTERNAL' | 'WEBGPU_SCOPE_FAILED' | 'WEBGPU_QUEUE_FAILED' | 'WEBGPU_DEVICE_LOST' | 'WEBGPU_UNCAPTURED_ERROR' | 'WEBGPU_READBACK_DISABLED' | 'WEBGPU_READBACK_PENDING' | 'WEBGPU_READBACK_FAILED' | 'WEBGPU_DIAGNOSTIC_CALLBACK_FAILED' | 'WEBGPU_CLOSE_UNSAFE' | 'WEBGPU_UPLOAD_INVALID' | 'WEBGPU_UPLOAD_OPTIONS_INVALID' | 'WEBGPU_UPLOAD_NOT_READY' | 'WEBGPU_UPLOAD_USED' | 'WEBGPU_UPLOAD_DISPOSED' | 'WEBGPU_UPLOAD_ABORTED' | 'WEBGPU_UPLOAD_EXPIRED' | 'WEBGPU_UPLOAD_STALE' | 'WEBGPU_RECOVERY_DISABLED' | 'WEBGPU_RECOVERY_STATE_INVALID' | 'WEBGPU_RECOVERY_DEVICE_INVALID' | 'WEBGPU_RECOVERY_TIMEOUT' | 'WEBGPU_RECOVERY_FAILED' | 'WEBGPU_RECOVERY_LIMIT' | 'WEBGPU_GENERATION_EXHAUSTED';
10
+ /** A failure of a WebGPU host: its code, the frame it happened at, the phase, and its cause. */
8
11
  export interface WebGPUHostFailure {
9
12
  readonly code: WebGPUHostErrorCode;
10
13
  readonly serial: number | null;
11
14
  readonly phase: 'startup' | 'frame' | 'readback' | 'device' | 'cleanup' | 'callback';
12
15
  readonly cause: unknown;
13
16
  }
17
+ /** Something a WebGPU host reports: a failure, with how serious it is. */
14
18
  export interface WebGPUHostDiagnostic extends WebGPUHostFailure {
15
19
  readonly severity: 'error';
16
20
  }
21
+ /** A WebGPU host to make: its canvas and device, its pixel ratio, its limits, whether it reads back, and what it reports to. */
17
22
  export interface WebGPUHostOptions {
18
23
  readonly canvas: HTMLCanvasElement;
19
24
  readonly device?: {
@@ -35,6 +40,7 @@ export interface WebGPUHostOptions {
35
40
  readonly enableReadback?: boolean;
36
41
  readonly onDiagnostic?: (diagnostic: WebGPUHostDiagnostic) => unknown;
37
42
  }
43
+ /** The pixels of a frame read back: its frame, size, format, color space and alpha, and its bytes. */
38
44
  export interface WebGPUReadback {
39
45
  readonly serial: number;
40
46
  readonly frameId: number;
@@ -46,6 +52,7 @@ export interface WebGPUReadback {
46
52
  readonly alphaMode: 'premultiplied';
47
53
  readonly bytes: Uint8Array;
48
54
  }
55
+ /** A WebGPU host as it is now: its state, frames and bytes pending, and its failures. */
49
56
  export interface WebGPUHostStatus {
50
57
  readonly state: WebGPUHostState;
51
58
  readonly lastSerial: number;
@@ -57,10 +64,12 @@ export interface WebGPUHostStatus {
57
64
  readonly lastCallbackFailure: WebGPUHostFailure | null;
58
65
  readonly cleanupOutcome: 'not-started' | 'pending' | 'safe' | 'unsafe';
59
66
  }
67
+ /** Pixels read back from a shared frame, with their alpha mode and device generation. */
60
68
  export interface SharedWebGPUReadback extends Omit<WebGPUReadback, 'alphaMode'> {
61
69
  readonly alphaMode: 'premultiplied' | 'opaque';
62
70
  readonly generation: number;
63
71
  }
72
+ /** A shared WebGPU host as it is now: its host status, the bytes pending, and its resources. */
64
73
  export interface SharedWebGPUHostStatus {
65
74
  readonly host: WebGPUHostStatus;
66
75
  readonly pendingGeometryBytes: number;
@@ -68,6 +77,7 @@ export interface SharedWebGPUHostStatus {
68
77
  readonly pendingCanonicalBytes: number;
69
78
  readonly resources: SharedHostResourceStatus;
70
79
  }
80
+ /** A host that draws shared frames with WebGPU: start and stop it, stage frames, read them back, and recover from a lost device. */
71
81
  export interface SharedWebGPUHost extends Pick<SharedRenderHostAdapter, 'sharedFrameProfile' | 'renderSharedFrame'> {
72
82
  readonly surface: HTMLCanvasElement;
73
83
  start(): Promise<void>;
@@ -82,6 +92,9 @@ export interface SharedWebGPUHost extends Pick<SharedRenderHostAdapter, 'sharedF
82
92
  stageSharedFrame(frame: SharedRenderFrame2D, options?: SharedFrameUploadOptions): SharedFrameUpload;
83
93
  requestReadback(): Promise<SharedWebGPUReadback>;
84
94
  getSharedStatus(): SharedWebGPUHostStatus;
95
+ /** Draw calls of the last frame encoded: its batches, a pass for each effect and the copy to the canvas. */
96
+ getFrameDrawCalls(): number;
85
97
  }
98
+ /** A host that draws shared frames with WebGPU on a canvas. */
86
99
  export declare function createSharedWebGPUHost(options: SharedWebGPUHostOptions): SharedWebGPUHost;
87
100
  //# sourceMappingURL=WebGPUHost.d.ts.map