@egret/engine 0.0.0-stage → 7.0.1-rc.3
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 +201 -0
- package/NOTICE +21 -0
- package/README.md +101 -2
- package/README.zh-CN.md +102 -0
- package/dist/Engine.d.ts +77 -0
- package/dist/Engine.js +464 -0
- package/dist/animation/index.d.ts +6 -0
- package/dist/animation/index.js +5 -0
- package/dist/animation/sequenceController.d.ts +22 -0
- package/dist/animation/sequenceController.js +618 -0
- package/dist/animation/sequenceCoordinator.d.ts +26 -0
- package/dist/animation/sequenceCoordinator.js +161 -0
- package/dist/animation/sequenceInput.d.ts +25 -0
- package/dist/animation/sequenceInput.js +108 -0
- package/dist/animation/sequenceMath.d.ts +35 -0
- package/dist/animation/sequenceMath.js +164 -0
- package/dist/animation/sequenceResetSlot.d.ts +7 -0
- package/dist/animation/sequenceResetSlot.js +367 -0
- package/dist/animation/sequenceResetTypes.d.ts +42 -0
- package/dist/animation/sequenceResetTypes.js +2 -0
- package/dist/animation/types.d.ts +69 -0
- package/dist/animation/types.js +2 -0
- package/dist/assetBundle.d.ts +52 -0
- package/dist/assetBundle.js +173 -0
- package/dist/assetGroup.d.ts +17 -0
- package/dist/assetGroup.js +332 -0
- package/dist/assetGroupTypes.d.ts +15 -0
- package/dist/assetGroupTypes.js +2 -0
- package/dist/audio.d.ts +4 -0
- package/dist/audio.js +4 -0
- package/dist/audioCues.d.ts +43 -0
- package/dist/audioCues.js +127 -0
- package/dist/audioMixer.d.ts +7 -0
- package/dist/audioMixer.js +785 -0
- package/dist/audioTypes.d.ts +233 -0
- package/dist/audioTypes.js +3 -0
- package/dist/bitmapBindingTicket.d.ts +24 -0
- package/dist/bitmapBindingTicket.js +215 -0
- package/dist/bitmapButton.d.ts +4 -0
- package/dist/bitmapButton.js +407 -0
- package/dist/bitmapButtonTypes.d.ts +29 -0
- package/dist/bitmapButtonTypes.js +2 -0
- package/dist/bitmapFontParse.d.ts +10 -0
- package/dist/bitmapFontParse.js +246 -0
- package/dist/bitmapFontTypes.d.ts +109 -0
- package/dist/bitmapFontTypes.js +2 -0
- package/dist/bitmapResourceSlot.d.ts +25 -0
- package/dist/bitmapResourceSlot.js +340 -0
- package/dist/bitmapText.d.ts +6 -0
- package/dist/bitmapText.js +320 -0
- package/dist/bitmapfont.d.ts +5 -0
- package/dist/bitmapfont.js +5 -0
- package/dist/camera.d.ts +4 -0
- package/dist/camera.js +4 -0
- package/dist/camera2d.d.ts +7 -0
- package/dist/camera2d.js +411 -0
- package/dist/cameraTypes.d.ts +114 -0
- package/dist/cameraTypes.js +2 -0
- package/dist/closeHost.d.ts +4 -0
- package/dist/closeHost.js +66 -0
- package/dist/contentArtifacts.d.ts +12 -0
- package/dist/contentArtifacts.js +153 -0
- package/dist/contentAtlasPages.d.ts +13 -0
- package/dist/contentAtlasPages.js +117 -0
- package/dist/contentLoader.d.ts +6 -0
- package/dist/contentLoader.js +327 -0
- package/dist/contentTypes.d.ts +33 -0
- package/dist/contentTypes.js +2 -0
- package/dist/createEngine.d.ts +7 -0
- package/dist/createEngine.js +25 -0
- package/dist/createEngineForProfile.d.ts +5 -0
- package/dist/createEngineForProfile.js +42 -0
- package/dist/displaySubtreeTicket.d.ts +25 -0
- package/dist/displaySubtreeTicket.js +76 -0
- package/dist/fontContentLoader.d.ts +6 -0
- package/dist/fontContentLoader.js +298 -0
- package/dist/fontContentTypes.d.ts +34 -0
- package/dist/fontContentTypes.js +2 -0
- package/dist/gameClock.d.ts +24 -0
- package/dist/gameClock.js +246 -0
- package/dist/gameClockTypes.d.ts +31 -0
- package/dist/gameClockTypes.js +2 -0
- package/dist/gameRun.d.ts +50 -0
- package/dist/gameRun.js +97 -0
- package/dist/gamepad.d.ts +5 -0
- package/dist/gamepad.js +5 -0
- package/dist/gamepadInput.d.ts +4 -0
- package/dist/gamepadInput.js +281 -0
- package/dist/gamepadKeys.d.ts +4 -0
- package/dist/gamepadKeys.js +205 -0
- package/dist/gamepadTypes.d.ts +134 -0
- package/dist/gamepadTypes.js +3 -0
- package/dist/hover.d.ts +4 -0
- package/dist/hover.js +4 -0
- package/dist/hoverInput.d.ts +8 -0
- package/dist/hoverInput.js +503 -0
- package/dist/hoverInputTypes.d.ts +119 -0
- package/dist/hoverInputTypes.js +2 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +20 -0
- package/dist/input.d.ts +6 -0
- package/dist/input.js +5 -0
- package/dist/inputActions.d.ts +81 -0
- package/dist/inputActions.js +330 -0
- package/dist/internal/contentFactoryState.d.ts +19 -0
- package/dist/internal/contentFactoryState.js +42 -0
- package/dist/internal/mouseInputFactoryState.d.ts +57 -0
- package/dist/internal/mouseInputFactoryState.js +125 -0
- package/dist/internal/sequenceControllerFactoryState.d.ts +42 -0
- package/dist/internal/sequenceControllerFactoryState.js +98 -0
- package/dist/internal/textFieldFactoryState.d.ts +11 -0
- package/dist/internal/textFieldFactoryState.js +32 -0
- package/dist/internal/texturedFrameState.d.ts +4 -0
- package/dist/internal/texturedFrameState.js +12 -0
- package/dist/internal/uiFactoryState.d.ts +64 -0
- package/dist/internal/uiFactoryState.js +157 -0
- package/dist/internal/uiRootState.d.ts +67 -0
- package/dist/internal/uiRootState.js +103 -0
- package/dist/keyboardInput.d.ts +12 -0
- package/dist/keyboardInput.js +578 -0
- package/dist/keyboardInputTypes.d.ts +81 -0
- package/dist/keyboardInputTypes.js +2 -0
- package/dist/kit.d.ts +14 -0
- package/dist/kit.js +9 -0
- package/dist/layout.d.ts +5 -0
- package/dist/layout.js +132 -0
- package/dist/layoutTypes.d.ts +28 -0
- package/dist/layoutTypes.js +2 -0
- package/dist/manifestAssetGroup.d.ts +10 -0
- package/dist/manifestAssetGroup.js +477 -0
- package/dist/manifestResourceState.d.ts +16 -0
- package/dist/manifestResourceState.js +57 -0
- package/dist/manifestResourceTypes.d.ts +25 -0
- package/dist/manifestResourceTypes.js +2 -0
- package/dist/motion.d.ts +33 -0
- package/dist/motion.js +206 -0
- package/dist/mouseInput.d.ts +102 -0
- package/dist/mouseInput.js +562 -0
- package/dist/mouseInputTypes.d.ts +37 -0
- package/dist/mouseInputTypes.js +2 -0
- package/dist/paragraph.d.ts +8 -0
- package/dist/paragraph.js +7 -0
- package/dist/particleEmitter.d.ts +4 -0
- package/dist/particleEmitter.js +292 -0
- package/dist/particleTypes.d.ts +107 -0
- package/dist/particleTypes.js +2 -0
- package/dist/particles.d.ts +4 -0
- package/dist/particles.js +4 -0
- package/dist/physics2d.d.ts +4 -0
- package/dist/physics2d.js +4 -0
- package/dist/physics2dGeometry.d.ts +39 -0
- package/dist/physics2dGeometry.js +230 -0
- package/dist/physics2dTypes.d.ts +167 -0
- package/dist/physics2dTypes.js +2 -0
- package/dist/physics2dWorld.d.ts +4 -0
- package/dist/physics2dWorld.js +623 -0
- package/dist/pointerInput.d.ts +11 -0
- package/dist/pointerInput.js +299 -0
- package/dist/pointerInputTypes.d.ts +38 -0
- package/dist/pointerInputTypes.js +2 -0
- package/dist/random.d.ts +29 -0
- package/dist/random.js +131 -0
- package/dist/rendering/ownedPreparationFailure2D.d.ts +5 -0
- package/dist/rendering/ownedPreparationFailure2D.js +33 -0
- package/dist/rendering/packSharedDraws2D.d.ts +50 -0
- package/dist/rendering/packSharedDraws2D.js +331 -0
- package/dist/rendering/packedOrientation.d.ts +4 -0
- package/dist/rendering/packedOrientation.js +7 -0
- package/dist/rendering/prepareRectangles2D.d.ts +92 -0
- package/dist/rendering/prepareRectangles2D.js +481 -0
- package/dist/rendering/prepareSharedDraws2D.d.ts +88 -0
- package/dist/rendering/prepareSharedDraws2D.js +652 -0
- package/dist/rendering/preparedBatches2D.d.ts +17 -0
- package/dist/rendering/preparedBatches2D.js +30 -0
- package/dist/rendering/preparedSharedBatches2D.d.ts +44 -0
- package/dist/rendering/preparedSharedBatches2D.js +247 -0
- package/dist/rendering/sharedColor2D.d.ts +18 -0
- package/dist/rendering/sharedColor2D.js +68 -0
- package/dist/rendering/sharedEffects2D.d.ts +23 -0
- package/dist/rendering/sharedEffects2D.js +118 -0
- package/dist/rendering/sharedPreparationRetention2D.d.ts +120 -0
- package/dist/rendering/sharedPreparationRetention2D.js +357 -0
- package/dist/rendering/srgbBytes.d.ts +3 -0
- package/dist/rendering/srgbBytes.js +64 -0
- package/dist/rendering/texturedPreparationBudget2D.d.ts +31 -0
- package/dist/rendering/texturedPreparationBudget2D.js +81 -0
- package/dist/rendering/world3d/Animation3D.d.ts +95 -0
- package/dist/rendering/world3d/Animation3D.js +380 -0
- package/dist/rendering/world3d/AnimationTexture3D.d.ts +157 -0
- package/dist/rendering/world3d/AnimationTexture3D.js +601 -0
- package/dist/rendering/world3d/Batch3D.d.ts +71 -0
- package/dist/rendering/world3d/Batch3D.js +329 -0
- package/dist/rendering/world3d/Camera3D.d.ts +57 -0
- package/dist/rendering/world3d/Camera3D.js +129 -0
- package/dist/rendering/world3d/Character3D.d.ts +123 -0
- package/dist/rendering/world3d/Character3D.js +303 -0
- package/dist/rendering/world3d/Cloth3D.d.ts +115 -0
- package/dist/rendering/world3d/Cloth3D.js +498 -0
- package/dist/rendering/world3d/Compression3D.d.ts +21 -0
- package/dist/rendering/world3d/Compression3D.js +702 -0
- package/dist/rendering/world3d/Curves3D.d.ts +111 -0
- package/dist/rendering/world3d/Curves3D.js +455 -0
- package/dist/rendering/world3d/Decal3D.d.ts +41 -0
- package/dist/rendering/world3d/Decal3D.js +241 -0
- package/dist/rendering/world3d/Geometry3D.d.ts +85 -0
- package/dist/rendering/world3d/Geometry3D.js +326 -0
- package/dist/rendering/world3d/GeometryBuilder3D.d.ts +51 -0
- package/dist/rendering/world3d/GeometryBuilder3D.js +196 -0
- package/dist/rendering/world3d/Gizmo3D.d.ts +75 -0
- package/dist/rendering/world3d/Gizmo3D.js +512 -0
- package/dist/rendering/world3d/Gltf3D.d.ts +67 -0
- package/dist/rendering/world3d/Gltf3D.js +976 -0
- package/dist/rendering/world3d/GpuParticles3D.d.ts +107 -0
- package/dist/rendering/world3d/GpuParticles3D.js +400 -0
- package/dist/rendering/world3d/Hdr3D.d.ts +33 -0
- package/dist/rendering/world3d/Hdr3D.js +190 -0
- package/dist/rendering/world3d/Jelly3D.d.ts +75 -0
- package/dist/rendering/world3d/Jelly3D.js +266 -0
- package/dist/rendering/world3d/Ktx23D.d.ts +27 -0
- package/dist/rendering/world3d/Ktx23D.js +112 -0
- package/dist/rendering/world3d/Light3D.d.ts +75 -0
- package/dist/rendering/world3d/Light3D.js +93 -0
- package/dist/rendering/world3d/Material3D.d.ts +243 -0
- package/dist/rendering/world3d/Material3D.js +267 -0
- package/dist/rendering/world3d/Mesh3D.d.ts +108 -0
- package/dist/rendering/world3d/Mesh3D.js +323 -0
- package/dist/rendering/world3d/Meshopt3D.d.ts +12 -0
- package/dist/rendering/world3d/Meshopt3D.js +275 -0
- package/dist/rendering/world3d/Navigation3D.d.ts +173 -0
- package/dist/rendering/world3d/Navigation3D.js +971 -0
- package/dist/rendering/world3d/Object3D.d.ts +107 -0
- package/dist/rendering/world3d/Object3D.js +305 -0
- package/dist/rendering/world3d/Particles3D.d.ts +85 -0
- package/dist/rendering/world3d/Particles3D.js +274 -0
- package/dist/rendering/world3d/Physics3D.d.ts +416 -0
- package/dist/rendering/world3d/Physics3D.js +2835 -0
- package/dist/rendering/world3d/PhysicsHull3D.d.ts +35 -0
- package/dist/rendering/world3d/PhysicsHull3D.js +227 -0
- package/dist/rendering/world3d/PhysicsMesh3D.d.ts +39 -0
- package/dist/rendering/world3d/PhysicsMesh3D.js +338 -0
- package/dist/rendering/world3d/PhysicsQueries3D.d.ts +24 -0
- package/dist/rendering/world3d/PhysicsQueries3D.js +323 -0
- package/dist/rendering/world3d/PhysicsRemote3D.d.ts +174 -0
- package/dist/rendering/world3d/PhysicsRemote3D.js +534 -0
- package/dist/rendering/world3d/Ragdoll3D.d.ts +69 -0
- package/dist/rendering/world3d/Ragdoll3D.js +200 -0
- package/dist/rendering/world3d/Raycast3D.d.ts +37 -0
- package/dist/rendering/world3d/Raycast3D.js +246 -0
- package/dist/rendering/world3d/RenderList3D.d.ts +88 -0
- package/dist/rendering/world3d/RenderList3D.js +490 -0
- package/dist/rendering/world3d/Retarget3D.d.ts +20 -0
- package/dist/rendering/world3d/Retarget3D.js +185 -0
- package/dist/rendering/world3d/Serialize3D.d.ts +49 -0
- package/dist/rendering/world3d/Serialize3D.js +607 -0
- package/dist/rendering/world3d/StateMachine3D.d.ts +78 -0
- package/dist/rendering/world3d/StateMachine3D.js +277 -0
- package/dist/rendering/world3d/Terrain3D.d.ts +227 -0
- package/dist/rendering/world3d/Terrain3D.js +803 -0
- package/dist/rendering/world3d/Text3D.d.ts +90 -0
- package/dist/rendering/world3d/Text3D.js +558 -0
- package/dist/rendering/world3d/Texture3D.d.ts +133 -0
- package/dist/rendering/world3d/Texture3D.js +252 -0
- package/dist/rendering/world3d/Trail3D.d.ts +59 -0
- package/dist/rendering/world3d/Trail3D.js +193 -0
- package/dist/rendering/world3d/Vehicle3D.d.ts +97 -0
- package/dist/rendering/world3d/Vehicle3D.js +226 -0
- package/dist/rendering/world3d/VolumetricFog3D.d.ts +55 -0
- package/dist/rendering/world3d/VolumetricFog3D.js +229 -0
- package/dist/rendering/world3d/Water3D.d.ts +163 -0
- package/dist/rendering/world3d/Water3D.js +606 -0
- package/dist/rendering/world3d/core3D.d.ts +34 -0
- package/dist/rendering/world3d/core3D.js +99 -0
- package/dist/rendering/world3d/debug3D.d.ts +64 -0
- package/dist/rendering/world3d/debug3D.js +257 -0
- package/dist/rendering/world3d/decoders3D.d.ts +42 -0
- package/dist/rendering/world3d/decoders3D.js +133 -0
- package/dist/rendering/world3d/geometries3D.d.ts +99 -0
- package/dist/rendering/world3d/geometries3D.js +605 -0
- package/dist/rendering/world3d/helpers3D.d.ts +65 -0
- package/dist/rendering/world3d/helpers3D.js +177 -0
- package/dist/rendering/world3d/index.d.ts +91 -0
- package/dist/rendering/world3d/index.js +56 -0
- package/dist/rendering/world3d/math3D.d.ts +78 -0
- package/dist/rendering/world3d/math3D.js +640 -0
- package/dist/rendering/world3d/primitives3D.d.ts +60 -0
- package/dist/rendering/world3d/primitives3D.js +196 -0
- package/dist/resources.d.ts +8 -0
- package/dist/resources.js +6 -0
- package/dist/saveStore.d.ts +56 -0
- package/dist/saveStore.js +163 -0
- package/dist/semanticList.d.ts +122 -0
- package/dist/semanticList.js +174 -0
- package/dist/semanticTree.d.ts +10 -0
- package/dist/semanticTree.js +532 -0
- package/dist/semanticTypes.d.ts +167 -0
- package/dist/semanticTypes.js +2 -0
- package/dist/semantics.d.ts +6 -0
- package/dist/semantics.js +5 -0
- package/dist/sequencePlayback.d.ts +19 -0
- package/dist/sequencePlayback.js +391 -0
- package/dist/sequencePlaybackTypes.d.ts +21 -0
- package/dist/sequencePlaybackTypes.js +2 -0
- package/dist/sequenceTargetClaims.d.ts +10 -0
- package/dist/sequenceTargetClaims.js +31 -0
- package/dist/srgbBytes.d.ts +3 -0
- package/dist/srgbBytes.js +64 -0
- package/dist/startEngine.d.ts +5 -0
- package/dist/startEngine.js +31 -0
- package/dist/surfaceOwnership.d.ts +3 -0
- package/dist/surfaceOwnership.js +15 -0
- package/dist/text.d.ts +23 -0
- package/dist/text.js +4 -0
- package/dist/textField.d.ts +6 -0
- package/dist/textField.js +6 -0
- package/dist/tileMapDraw.d.ts +7 -0
- package/dist/tileMapDraw.js +310 -0
- package/dist/tiledImport.d.ts +9 -0
- package/dist/tiledImport.js +357 -0
- package/dist/tilemap.d.ts +5 -0
- package/dist/tilemap.js +5 -0
- package/dist/tilemapTypes.d.ts +169 -0
- package/dist/tilemapTypes.js +2 -0
- package/dist/tween.d.ts +15 -0
- package/dist/tween.js +329 -0
- package/dist/tweenTypes.d.ts +27 -0
- package/dist/tweenTypes.js +2 -0
- package/dist/ui/controlKeys.d.ts +109 -0
- package/dist/ui/controlKeys.js +249 -0
- package/dist/ui/controls.d.ts +52 -0
- package/dist/ui/controls.js +288 -0
- package/dist/ui/editing.d.ts +3 -0
- package/dist/ui/editing.js +3 -0
- package/dist/ui/index.d.ts +19 -0
- package/dist/ui/index.js +11 -0
- package/dist/ui/keyboardFocus.d.ts +32 -0
- package/dist/ui/keyboardFocus.js +146 -0
- package/dist/ui/layerTypes.d.ts +91 -0
- package/dist/ui/layerTypes.js +2 -0
- package/dist/ui/layers.d.ts +4 -0
- package/dist/ui/layers.js +586 -0
- package/dist/ui/leafContent.d.ts +21 -0
- package/dist/ui/leafContent.js +136 -0
- package/dist/ui/rangeControl.d.ts +50 -0
- package/dist/ui/rangeControl.js +167 -0
- package/dist/ui/scrollControl.d.ts +72 -0
- package/dist/ui/scrollControl.js +218 -0
- package/dist/ui/stateControls.d.ts +82 -0
- package/dist/ui/stateControls.js +328 -0
- package/dist/ui/textEditor.d.ts +53 -0
- package/dist/ui/textEditor.js +370 -0
- package/dist/ui/textEditorTypes.d.ts +78 -0
- package/dist/ui/textEditorTypes.js +2 -0
- package/dist/ui/textFieldControl.d.ts +96 -0
- package/dist/ui/textFieldControl.js +259 -0
- package/dist/ui/theme.d.ts +59 -0
- package/dist/ui/theme.js +165 -0
- package/dist/ui/types.d.ts +265 -0
- package/dist/ui/types.js +2 -0
- package/dist/ui/uiRoot.d.ts +4 -0
- package/dist/ui/uiRoot.js +1497 -0
- package/dist/ui/uiRootDisplay.d.ts +46 -0
- package/dist/ui/uiRootDisplay.js +148 -0
- package/dist/ui/uiRootModel.d.ts +112 -0
- package/dist/ui/uiRootModel.js +60 -0
- package/dist/ui/virtualList.d.ts +20 -0
- package/dist/ui/virtualList.js +105 -0
- package/dist/video.d.ts +4 -0
- package/dist/video.js +4 -0
- package/dist/videoPlayer.d.ts +4 -0
- package/dist/videoPlayer.js +215 -0
- package/dist/videoTypes.d.ts +74 -0
- package/dist/videoTypes.js +2 -0
- package/dist/web/BrowserAssetBundle.d.ts +39 -0
- package/dist/web/BrowserAssetBundle.js +136 -0
- package/dist/web/BrowserAudio.d.ts +41 -0
- package/dist/web/BrowserAudio.js +473 -0
- package/dist/web/BrowserFrameLoop.d.ts +65 -0
- package/dist/web/BrowserFrameLoop.js +125 -0
- package/dist/web/BrowserGame.d.ts +112 -0
- package/dist/web/BrowserGame.js +352 -0
- package/dist/web/BrowserGamepadInput.d.ts +35 -0
- package/dist/web/BrowserGamepadInput.js +134 -0
- package/dist/web/BrowserHoverInput.d.ts +24 -0
- package/dist/web/BrowserHoverInput.js +266 -0
- package/dist/web/BrowserImageTextures.d.ts +66 -0
- package/dist/web/BrowserImageTextures.js +169 -0
- package/dist/web/BrowserInputActions.d.ts +53 -0
- package/dist/web/BrowserInputActions.js +342 -0
- package/dist/web/BrowserKeyboardInput.d.ts +4 -0
- package/dist/web/BrowserKeyboardInput.js +223 -0
- package/dist/web/BrowserPlay.d.ts +289 -0
- package/dist/web/BrowserPlay.js +1301 -0
- package/dist/web/BrowserPointerInput.d.ts +4 -0
- package/dist/web/BrowserPointerInput.js +511 -0
- package/dist/web/BrowserSemantics.d.ts +34 -0
- package/dist/web/BrowserSemantics.js +418 -0
- package/dist/web/BrowserStatsPanel.d.ts +46 -0
- package/dist/web/BrowserStatsPanel.js +137 -0
- package/dist/web/BrowserStorage.d.ts +33 -0
- package/dist/web/BrowserStorage.js +132 -0
- package/dist/web/BrowserTextEditor.d.ts +49 -0
- package/dist/web/BrowserTextEditor.js +839 -0
- package/dist/web/BrowserTextInput.d.ts +83 -0
- package/dist/web/BrowserTextInput.js +524 -0
- package/dist/web/BrowserTextureProvider.d.ts +52 -0
- package/dist/web/BrowserTextureProvider.js +935 -0
- package/dist/web/BrowserVideo.d.ts +28 -0
- package/dist/web/BrowserVideo.js +211 -0
- package/dist/web/CanvasKitFontSetProvider.d.ts +29 -0
- package/dist/web/CanvasKitFontSetProvider.js +215 -0
- package/dist/web/CanvasKitParagraphProvider.d.ts +169 -0
- package/dist/web/CanvasKitParagraphProvider.js +691 -0
- package/dist/web/CanvasTextRasterProvider.d.ts +4 -0
- package/dist/web/CanvasTextRasterProvider.js +312 -0
- package/dist/web/ManifestByteSource.d.ts +147 -0
- package/dist/web/ManifestByteSource.js +974 -0
- package/dist/web/ManifestFontContentLoader.d.ts +12 -0
- package/dist/web/ManifestFontContentLoader.js +30 -0
- package/dist/web/MouseInput.d.ts +4 -0
- package/dist/web/MouseInput.js +218 -0
- package/dist/web/WebGL2Host.d.ts +5 -0
- package/dist/web/WebGL2Host.js +2672 -0
- package/dist/web/WebGPUHost.d.ts +87 -0
- package/dist/web/WebGPUHost.js +3349 -0
- package/dist/web/audio.d.ts +3 -0
- package/dist/web/audio.js +4 -0
- package/dist/web/canvasKitParagraphGeometry.d.ts +27 -0
- package/dist/web/canvasKitParagraphGeometry.js +83 -0
- package/dist/web/editing.d.ts +5 -0
- package/dist/web/editing.js +4 -0
- package/dist/web/editorFonts.d.ts +50 -0
- package/dist/web/editorFonts.js +297 -0
- package/dist/web/game.d.ts +5 -0
- package/dist/web/game.js +6 -0
- package/dist/web/gamepad.d.ts +3 -0
- package/dist/web/gamepad.js +4 -0
- package/dist/web/hover.d.ts +3 -0
- package/dist/web/hover.js +4 -0
- package/dist/web/image.d.ts +4 -0
- package/dist/web/image.js +4 -0
- package/dist/web/imageProjections2D.d.ts +14 -0
- package/dist/web/imageProjections2D.js +2 -0
- package/dist/web/input.d.ts +6 -0
- package/dist/web/input.js +4 -0
- package/dist/web/keyboard.d.ts +3 -0
- package/dist/web/keyboard.js +3 -0
- package/dist/web/kit.d.ts +10 -0
- package/dist/web/kit.js +7 -0
- package/dist/web/loop.d.ts +3 -0
- package/dist/web/loop.js +4 -0
- package/dist/web/paragraph.d.ts +6 -0
- package/dist/web/paragraph.js +4 -0
- package/dist/web/play.d.ts +5 -0
- package/dist/web/play.js +6 -0
- package/dist/web/playSfx.d.ts +36 -0
- package/dist/web/playSfx.js +112 -0
- package/dist/web/pointer.d.ts +3 -0
- package/dist/web/pointer.js +3 -0
- package/dist/web/prepareSharedSubmission2D.d.ts +27 -0
- package/dist/web/prepareSharedSubmission2D.js +57 -0
- package/dist/web/resources.d.ts +27 -0
- package/dist/web/resources.js +96 -0
- package/dist/web/semantics.d.ts +3 -0
- package/dist/web/semantics.js +4 -0
- package/dist/web/sharedDeviceSession.d.ts +64 -0
- package/dist/web/sharedDeviceSession.js +2 -0
- package/dist/web/sharedEffectShaders.d.ts +9 -0
- package/dist/web/sharedEffectShaders.js +165 -0
- package/dist/web/sharedFrameUpload.d.ts +25 -0
- package/dist/web/sharedFrameUpload.js +2 -0
- package/dist/web/sharedHostDeferred.d.ts +7 -0
- package/dist/web/sharedHostDeferred.js +12 -0
- package/dist/web/sharedRetentionLedger.d.ts +85 -0
- package/dist/web/sharedRetentionLedger.js +391 -0
- package/dist/web/sharedSubmissionStorage2D.d.ts +56 -0
- package/dist/web/sharedSubmissionStorage2D.js +73 -0
- package/dist/web/sharedWebGL2Arena.d.ts +40 -0
- package/dist/web/sharedWebGL2Arena.js +77 -0
- package/dist/web/sharedWebGL2Options.d.ts +30 -0
- package/dist/web/sharedWebGL2Options.js +96 -0
- package/dist/web/sharedWebGL2Shaders.d.ts +20 -0
- package/dist/web/sharedWebGL2Shaders.js +314 -0
- package/dist/web/sharedWebGPUOptions.d.ts +37 -0
- package/dist/web/sharedWebGPUOptions.js +126 -0
- package/dist/web/text.d.ts +3 -0
- package/dist/web/text.js +3 -0
- package/dist/web/textInput.d.ts +3 -0
- package/dist/web/textInput.js +3 -0
- package/dist/web/video.d.ts +3 -0
- package/dist/web/video.js +4 -0
- package/dist/web/webgl2.d.ts +7 -0
- package/dist/web/webgl2.js +4 -0
- package/dist/web/webgl2LayerState.d.ts +50 -0
- package/dist/web/webgl2LayerState.js +102 -0
- package/dist/web/webgl2Native.d.ts +70 -0
- package/dist/web/webgl2Native.js +568 -0
- package/dist/web/webgl2Types.d.ts +132 -0
- package/dist/web/webgl2Types.js +2 -0
- package/dist/web/webgpu.d.ts +6 -0
- package/dist/web/webgpu.js +2 -0
- package/dist/web/webgpuBindingCache.d.ts +26 -0
- package/dist/web/webgpuBindingCache.js +223 -0
- package/dist/web/webgpuBufferPool.d.ts +51 -0
- package/dist/web/webgpuBufferPool.js +58 -0
- package/dist/web/webgpuImageResidency.d.ts +53 -0
- package/dist/web/webgpuImageResidency.js +61 -0
- package/dist/web/webgpuLifetime.d.ts +45 -0
- package/dist/web/webgpuLifetime.js +64 -0
- package/dist/web/webgpuRetentionPool.d.ts +66 -0
- package/dist/web/webgpuRetentionPool.js +84 -0
- package/dist/web/webgpuSharedPass.d.ts +7 -0
- package/dist/web/webgpuSharedPass.js +211 -0
- package/dist/web/webgpuSharedResolvePass.d.ts +3 -0
- package/dist/web/webgpuSharedResolvePass.js +29 -0
- package/dist/web/world3d/Audio3D.d.ts +68 -0
- package/dist/web/world3d/Audio3D.js +212 -0
- package/dist/web/world3d/BrowserPlay3D.d.ts +182 -0
- package/dist/web/world3d/BrowserPlay3D.js +851 -0
- package/dist/web/world3d/FlyControls3D.d.ts +55 -0
- package/dist/web/world3d/FlyControls3D.js +160 -0
- package/dist/web/world3d/FollowControls3D.d.ts +28 -0
- package/dist/web/world3d/FollowControls3D.js +117 -0
- package/dist/web/world3d/OrbitControls3D.d.ts +55 -0
- package/dist/web/world3d/OrbitControls3D.js +187 -0
- package/dist/web/world3d/TransformControls3D.d.ts +34 -0
- package/dist/web/world3d/TransformControls3D.js +125 -0
- package/dist/web/world3d/WebGL2Renderer3D.d.ts +133 -0
- package/dist/web/world3d/WebGL2Renderer3D.js +1173 -0
- package/dist/web/world3d/WebGPURenderer3D.d.ts +110 -0
- package/dist/web/world3d/WebGPURenderer3D.js +1915 -0
- package/dist/web/world3d/World3DView.d.ts +51 -0
- package/dist/web/world3d/World3DView.js +77 -0
- package/dist/web/world3d/app3D.d.ts +136 -0
- package/dist/web/world3d/app3D.js +304 -0
- package/dist/web/world3d/assets3D.d.ts +38 -0
- package/dist/web/world3d/assets3D.js +112 -0
- package/dist/web/world3d/atmosphere3D.d.ts +47 -0
- package/dist/web/world3d/atmosphere3D.js +178 -0
- package/dist/web/world3d/frame3D.d.ts +142 -0
- package/dist/web/world3d/frame3D.js +388 -0
- package/dist/web/world3d/gpuResources3D.d.ts +98 -0
- package/dist/web/world3d/gpuResources3D.js +901 -0
- package/dist/web/world3d/host3D.d.ts +23 -0
- package/dist/web/world3d/host3D.js +61 -0
- package/dist/web/world3d/index.d.ts +38 -0
- package/dist/web/world3d/index.js +23 -0
- package/dist/web/world3d/loaders3D.d.ts +26 -0
- package/dist/web/world3d/loaders3D.js +138 -0
- package/dist/web/world3d/markers3D.d.ts +49 -0
- package/dist/web/world3d/markers3D.js +130 -0
- package/dist/web/world3d/materialWebGL23D.d.ts +34 -0
- package/dist/web/world3d/materialWebGL23D.js +218 -0
- package/dist/web/world3d/overlay3D.d.ts +28 -0
- package/dist/web/world3d/overlay3D.js +170 -0
- package/dist/web/world3d/post3D.d.ts +112 -0
- package/dist/web/world3d/post3D.js +459 -0
- package/dist/web/world3d/postWebGL23D.d.ts +24 -0
- package/dist/web/world3d/postWebGL23D.js +237 -0
- package/dist/web/world3d/postWebGPU3D.d.ts +23 -0
- package/dist/web/world3d/postWebGPU3D.js +255 -0
- package/dist/web/world3d/probe3D.d.ts +14 -0
- package/dist/web/world3d/probe3D.js +66 -0
- package/dist/web/world3d/shaders3D.d.ts +43 -0
- package/dist/web/world3d/shaders3D.js +851 -0
- package/dist/web/world3d/stats3D.d.ts +31 -0
- package/dist/web/world3d/stats3D.js +80 -0
- package/dist/web/world3d/webGL2FrameMetrics3D.d.ts +66 -0
- package/dist/web/world3d/webGL2FrameMetrics3D.js +185 -0
- package/dist/web/world3d/webgpu.d.ts +35 -0
- package/dist/web/world3d/webgpu.js +22 -0
- package/dist/web/world3d/webgpuPacking3D.d.ts +13 -0
- package/dist/web/world3d/webgpuPacking3D.js +85 -0
- package/dist/web/world3d/wgsl3D.d.ts +68 -0
- package/dist/web/world3d/wgsl3D.js +781 -0
- package/package.json +220 -4
|
@@ -0,0 +1,901 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// GPU-side caches for the WebGL2 world3d renderer: linked programs, vertex
|
|
3
|
+
// arrays and buffers, textures, bone and morph data. Entries follow the CPU
|
|
4
|
+
// resources' version counters and are retired through their onDispose hooks,
|
|
5
|
+
// so the scene core never holds a WebGL object.
|
|
6
|
+
import { World3DError } from '../../rendering/world3d/core3D.js';
|
|
7
|
+
import { instanceStreamRevisions3D } from '../../rendering/world3d/Mesh3D.js';
|
|
8
|
+
import { SkinnedInstancedMesh3D } from '../../rendering/world3d/AnimationTexture3D.js';
|
|
9
|
+
import { RenderTarget3D, isCompressedPixels3D, isTexturePixels3D } from '../../rendering/world3d/Texture3D.js';
|
|
10
|
+
import { ATTRIBUTE_LOCATIONS_3D, TEXTURE_UNITS_3D } from './shaders3D.js';
|
|
11
|
+
const ATTRIBUTE_NAMES = ['position', 'normal', 'uv', 'tangent', 'color', 'joints', 'weights', 'uv1'];
|
|
12
|
+
const PRUNE_INTERVAL = 600;
|
|
13
|
+
export class GpuResources3D {
|
|
14
|
+
#gl;
|
|
15
|
+
#programs = new Map();
|
|
16
|
+
#pendingPrograms = new Map();
|
|
17
|
+
#programsRetired;
|
|
18
|
+
#geometries = new Map();
|
|
19
|
+
#instances = new Map();
|
|
20
|
+
#animations = new Map();
|
|
21
|
+
#textures = new Map();
|
|
22
|
+
#bones = new Map();
|
|
23
|
+
#targets = new Map();
|
|
24
|
+
#anisotropy;
|
|
25
|
+
#maxAnisotropy;
|
|
26
|
+
#maxTextureSize;
|
|
27
|
+
/** True when half-float color targets can be rendered to. */
|
|
28
|
+
floatTargets;
|
|
29
|
+
#nextProgramId = 1;
|
|
30
|
+
constructor(gl) {
|
|
31
|
+
this.#gl = gl;
|
|
32
|
+
this.#anisotropy = gl.getExtension('EXT_texture_filter_anisotropic');
|
|
33
|
+
this.#maxAnisotropy = this.#anisotropy ? gl.getParameter(0x84ff) : 1;
|
|
34
|
+
this.#maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
|
35
|
+
this.floatTargets =
|
|
36
|
+
gl.getExtension('EXT_color_buffer_float') !== null || gl.getExtension('EXT_color_buffer_half_float') !== null;
|
|
37
|
+
}
|
|
38
|
+
get counts() {
|
|
39
|
+
return { programs: this.#programs.size, geometries: this.#geometries.size, textures: this.#textures.size };
|
|
40
|
+
}
|
|
41
|
+
// ---- programs ------------------------------------------------------------
|
|
42
|
+
program(key, sources) {
|
|
43
|
+
const cached = this.#programs.get(key);
|
|
44
|
+
if (cached)
|
|
45
|
+
return cached;
|
|
46
|
+
return this.finishProgram(this.startProgram(key, sources), false);
|
|
47
|
+
}
|
|
48
|
+
async preparePrograms(requests) {
|
|
49
|
+
const gl = this.#gl;
|
|
50
|
+
this.requireProgramContext();
|
|
51
|
+
if (!requests.some(({ key }) => !this.#programs.has(key)))
|
|
52
|
+
return;
|
|
53
|
+
const completion = gl.getExtension('KHR_parallel_shader_compile')?.COMPLETION_STATUS_KHR;
|
|
54
|
+
const pending = new Set();
|
|
55
|
+
let failure;
|
|
56
|
+
try {
|
|
57
|
+
for (const { key, sources } of requests)
|
|
58
|
+
if (!this.#programs.has(key))
|
|
59
|
+
pending.add(this.startProgram(key, sources));
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
// A later submission can fail after a shared program has already started.
|
|
63
|
+
// Drain the submitted entries so all waiters see a terminal result.
|
|
64
|
+
failure = { error };
|
|
65
|
+
}
|
|
66
|
+
while (pending.size) {
|
|
67
|
+
// The extension reports completion even for lost contexts. Never finalize an old handle.
|
|
68
|
+
this.requireProgramContext();
|
|
69
|
+
for (const entry of pending) {
|
|
70
|
+
if (!entry.result && completion !== undefined && !gl.getProgramParameter(entry.program, completion))
|
|
71
|
+
continue;
|
|
72
|
+
try {
|
|
73
|
+
this.finishProgram(entry, true);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
failure ??= { error };
|
|
77
|
+
}
|
|
78
|
+
pending.delete(entry);
|
|
79
|
+
}
|
|
80
|
+
if (pending.size)
|
|
81
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
82
|
+
}
|
|
83
|
+
if (failure)
|
|
84
|
+
throw failure.error;
|
|
85
|
+
}
|
|
86
|
+
requireProgramContext() {
|
|
87
|
+
if (this.#programsRetired === 'disposed')
|
|
88
|
+
throw new World3DError('WORLD3D_DISPOSED', 'renderer');
|
|
89
|
+
if (this.#programsRetired === 'lost' || this.#gl.isContextLost())
|
|
90
|
+
throw new World3DError('WORLD3D_CONTEXT_LOST', 'program preparation');
|
|
91
|
+
}
|
|
92
|
+
startProgram(key, sources) {
|
|
93
|
+
this.requireProgramContext();
|
|
94
|
+
const existing = this.#pendingPrograms.get(key);
|
|
95
|
+
if (existing)
|
|
96
|
+
return existing;
|
|
97
|
+
const gl = this.#gl;
|
|
98
|
+
const { vertex, fragment } = sources();
|
|
99
|
+
const shaders = [];
|
|
100
|
+
let program = null;
|
|
101
|
+
try {
|
|
102
|
+
for (const [type, source] of [
|
|
103
|
+
[gl.VERTEX_SHADER, vertex],
|
|
104
|
+
[gl.FRAGMENT_SHADER, fragment]
|
|
105
|
+
]) {
|
|
106
|
+
const shader = gl.createShader(type);
|
|
107
|
+
if (!shader)
|
|
108
|
+
throw new World3DError('WORLD3D_CONTEXT_LOST', 'createShader');
|
|
109
|
+
shaders.push(shader);
|
|
110
|
+
gl.shaderSource(shader, source);
|
|
111
|
+
gl.compileShader(shader);
|
|
112
|
+
}
|
|
113
|
+
program = gl.createProgram();
|
|
114
|
+
if (!program)
|
|
115
|
+
throw new World3DError('WORLD3D_CONTEXT_LOST', 'createProgram');
|
|
116
|
+
for (const shader of shaders)
|
|
117
|
+
gl.attachShader(program, shader);
|
|
118
|
+
gl.linkProgram(program);
|
|
119
|
+
const entry = { key, program, shaders };
|
|
120
|
+
this.#pendingPrograms.set(key, entry);
|
|
121
|
+
return entry;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (!gl.isContextLost()) {
|
|
125
|
+
for (const shader of shaders)
|
|
126
|
+
gl.deleteShader(shader);
|
|
127
|
+
if (program)
|
|
128
|
+
gl.deleteProgram(program);
|
|
129
|
+
}
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
finishProgram(entry, restoreProgram) {
|
|
134
|
+
this.requireProgramContext();
|
|
135
|
+
const cached = entry.result;
|
|
136
|
+
if (cached) {
|
|
137
|
+
if ('error' in cached)
|
|
138
|
+
throw cached.error;
|
|
139
|
+
return cached.value;
|
|
140
|
+
}
|
|
141
|
+
const gl = this.#gl;
|
|
142
|
+
const { key, program, shaders } = entry;
|
|
143
|
+
try {
|
|
144
|
+
const linked = gl.getProgramParameter(program, gl.LINK_STATUS);
|
|
145
|
+
this.requireProgramContext();
|
|
146
|
+
if (!linked) {
|
|
147
|
+
// Shader logs are needed only when link validation has already failed.
|
|
148
|
+
const log = [...shaders.map(shader => gl.getShaderInfoLog(shader)), gl.getProgramInfoLog(program)]
|
|
149
|
+
.filter(Boolean)
|
|
150
|
+
.join('\n');
|
|
151
|
+
throw new World3DError('WORLD3D_SHADER_FAILED', key + '\n' + log);
|
|
152
|
+
}
|
|
153
|
+
const value = this.initializeProgram(program, restoreProgram);
|
|
154
|
+
this.requireProgramContext();
|
|
155
|
+
entry.result = { value };
|
|
156
|
+
this.#programs.set(key, value);
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
entry.result = { error };
|
|
161
|
+
if (!gl.isContextLost())
|
|
162
|
+
gl.deleteProgram(program);
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
this.#pendingPrograms.delete(key);
|
|
167
|
+
if (!gl.isContextLost())
|
|
168
|
+
for (const shader of shaders)
|
|
169
|
+
gl.deleteShader(shader);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
initializeProgram(program, restoreProgram) {
|
|
173
|
+
const gl = this.#gl;
|
|
174
|
+
const uniforms = {};
|
|
175
|
+
const count = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
|
|
176
|
+
for (let i = 0; i < count; i++) {
|
|
177
|
+
const info = gl.getActiveUniform(program, i);
|
|
178
|
+
if (!info)
|
|
179
|
+
continue;
|
|
180
|
+
const name = info.name.replace(/\[0\]$/, ''), location = gl.getUniformLocation(program, info.name);
|
|
181
|
+
if (location)
|
|
182
|
+
uniforms[name] = location;
|
|
183
|
+
}
|
|
184
|
+
const block = gl.getUniformBlockIndex(program, 'Frame');
|
|
185
|
+
if (block !== gl.INVALID_INDEX)
|
|
186
|
+
gl.uniformBlockBinding(program, block, 0);
|
|
187
|
+
const samplers = {
|
|
188
|
+
uMap: TEXTURE_UNITS_3D.map,
|
|
189
|
+
uNormalMap: TEXTURE_UNITS_3D.normalMap,
|
|
190
|
+
uMetallicRoughnessMap: TEXTURE_UNITS_3D.metallicRoughnessMap,
|
|
191
|
+
uOcclusionMap: TEXTURE_UNITS_3D.occlusionMap,
|
|
192
|
+
uEmissiveMap: TEXTURE_UNITS_3D.emissiveMap,
|
|
193
|
+
uLightMap: TEXTURE_UNITS_3D.lightMap,
|
|
194
|
+
uReflectionMap: TEXTURE_UNITS_3D.reflectionMap,
|
|
195
|
+
uSceneDepth: TEXTURE_UNITS_3D.sceneDepth,
|
|
196
|
+
uTiledLights: TEXTURE_UNITS_3D.tiledLights,
|
|
197
|
+
uSplatWeights: TEXTURE_UNITS_3D.lightMap,
|
|
198
|
+
uSplat0: TEXTURE_UNITS_3D.map,
|
|
199
|
+
uSplat1: TEXTURE_UNITS_3D.emissiveMap,
|
|
200
|
+
uSplat2: TEXTURE_UNITS_3D.occlusionMap,
|
|
201
|
+
uSplat3: TEXTURE_UNITS_3D.metallicRoughnessMap,
|
|
202
|
+
uEnvironment: TEXTURE_UNITS_3D.environment,
|
|
203
|
+
uShadowMap: TEXTURE_UNITS_3D.shadow,
|
|
204
|
+
uBoneTexture: TEXTURE_UNITS_3D.bones,
|
|
205
|
+
uMorphTexture: TEXTURE_UNITS_3D.morph,
|
|
206
|
+
uSceneColor: TEXTURE_UNITS_3D.sceneColor
|
|
207
|
+
};
|
|
208
|
+
// Preparation runs between draws, so keep the program tracked by the renderer bound.
|
|
209
|
+
const previous = restoreProgram ? gl.getParameter(gl.CURRENT_PROGRAM) : undefined;
|
|
210
|
+
gl.useProgram(program);
|
|
211
|
+
try {
|
|
212
|
+
for (const name in samplers)
|
|
213
|
+
if (uniforms[name])
|
|
214
|
+
gl.uniform1i(uniforms[name], samplers[name]);
|
|
215
|
+
}
|
|
216
|
+
finally {
|
|
217
|
+
if (previous !== undefined && previous !== program && !gl.isContextLost())
|
|
218
|
+
gl.useProgram(previous);
|
|
219
|
+
}
|
|
220
|
+
return { id: this.#nextProgramId++, program, uniforms };
|
|
221
|
+
}
|
|
222
|
+
// ---- geometry ----------------------------------------------------------------
|
|
223
|
+
upload(target, entry, attribute) {
|
|
224
|
+
if (entry.version === attribute.version)
|
|
225
|
+
return;
|
|
226
|
+
const gl = this.#gl, data = attribute.data;
|
|
227
|
+
gl.bindBuffer(target, entry.buffer);
|
|
228
|
+
if (entry.byteLength === data.byteLength)
|
|
229
|
+
gl.bufferSubData(target, 0, data);
|
|
230
|
+
else
|
|
231
|
+
gl.bufferData(target, data, attribute.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW);
|
|
232
|
+
entry.byteLength = data.byteLength;
|
|
233
|
+
entry.version = attribute.version;
|
|
234
|
+
}
|
|
235
|
+
glType(data) {
|
|
236
|
+
const gl = this.#gl;
|
|
237
|
+
return data instanceof Float32Array
|
|
238
|
+
? gl.FLOAT
|
|
239
|
+
: data instanceof Uint16Array
|
|
240
|
+
? gl.UNSIGNED_SHORT
|
|
241
|
+
: data instanceof Uint32Array
|
|
242
|
+
? gl.UNSIGNED_INT
|
|
243
|
+
: data instanceof Uint8Array
|
|
244
|
+
? gl.UNSIGNED_BYTE
|
|
245
|
+
: data instanceof Int16Array
|
|
246
|
+
? gl.SHORT
|
|
247
|
+
: gl.BYTE;
|
|
248
|
+
}
|
|
249
|
+
buffer() {
|
|
250
|
+
const buffer = this.#gl.createBuffer();
|
|
251
|
+
if (!buffer)
|
|
252
|
+
throw new World3DError('WORLD3D_CONTEXT_LOST', 'createBuffer');
|
|
253
|
+
return buffer;
|
|
254
|
+
}
|
|
255
|
+
/** Bind every known attribute of a geometry into the currently bound vertex array. */
|
|
256
|
+
bindAttributes(geometry, entry) {
|
|
257
|
+
const gl = this.#gl;
|
|
258
|
+
for (const name of ATTRIBUTE_NAMES) {
|
|
259
|
+
const location = ATTRIBUTE_LOCATIONS_3D[name], attribute = geometry.getAttribute(name), buffer = entry.buffers.get(name);
|
|
260
|
+
if (!attribute || !buffer) {
|
|
261
|
+
gl.disableVertexAttribArray(location);
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer.buffer);
|
|
265
|
+
gl.enableVertexAttribArray(location);
|
|
266
|
+
if (name === 'joints')
|
|
267
|
+
gl.vertexAttribIPointer(location, attribute.itemSize, this.glType(attribute.data), 0, 0);
|
|
268
|
+
else
|
|
269
|
+
gl.vertexAttribPointer(location, attribute.itemSize, this.glType(attribute.data), attribute.normalized, 0, 0);
|
|
270
|
+
}
|
|
271
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, entry.index ? entry.index.buffer : null);
|
|
272
|
+
}
|
|
273
|
+
/** Create or refresh GPU buffers for a geometry and return its vertex array. */
|
|
274
|
+
geometry(geometry) {
|
|
275
|
+
const gl = this.#gl;
|
|
276
|
+
let entry = this.#geometries.get(geometry);
|
|
277
|
+
if (entry && entry.version === geometry.version && entry.layoutVersion === geometry.layoutVersion) {
|
|
278
|
+
// Attribute data may still have changed through Attribute3D.touch().
|
|
279
|
+
let stale = false;
|
|
280
|
+
for (const [name, buffer] of entry.buffers)
|
|
281
|
+
if (geometry.getAttribute(name)?.version !== buffer.version) {
|
|
282
|
+
stale = true;
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
if (!stale && (!entry.index || entry.index.version === geometry.index?.version))
|
|
286
|
+
return entry;
|
|
287
|
+
}
|
|
288
|
+
if (!entry) {
|
|
289
|
+
const vao = gl.createVertexArray();
|
|
290
|
+
if (!vao)
|
|
291
|
+
throw new World3DError('WORLD3D_CONTEXT_LOST', 'createVertexArray');
|
|
292
|
+
const created = {
|
|
293
|
+
vao,
|
|
294
|
+
buffers: new Map(),
|
|
295
|
+
index: undefined,
|
|
296
|
+
wire: undefined,
|
|
297
|
+
layoutVersion: -1,
|
|
298
|
+
version: -1,
|
|
299
|
+
indexType: gl.UNSIGNED_SHORT,
|
|
300
|
+
indexed: false,
|
|
301
|
+
morph: undefined,
|
|
302
|
+
unsubscribe: geometry.onDispose(() => this.releaseGeometry(geometry))
|
|
303
|
+
};
|
|
304
|
+
this.#geometries.set(geometry, (entry = created));
|
|
305
|
+
}
|
|
306
|
+
const layoutChanged = entry.layoutVersion !== geometry.layoutVersion;
|
|
307
|
+
gl.bindVertexArray(null);
|
|
308
|
+
for (const name of ATTRIBUTE_NAMES) {
|
|
309
|
+
const attribute = geometry.getAttribute(name);
|
|
310
|
+
let buffer = entry.buffers.get(name);
|
|
311
|
+
if (!attribute) {
|
|
312
|
+
if (buffer) {
|
|
313
|
+
gl.deleteBuffer(buffer.buffer);
|
|
314
|
+
entry.buffers.delete(name);
|
|
315
|
+
}
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
if (!buffer)
|
|
319
|
+
entry.buffers.set(name, (buffer = { buffer: this.buffer(), version: -1, byteLength: -1 }));
|
|
320
|
+
this.upload(gl.ARRAY_BUFFER, buffer, attribute);
|
|
321
|
+
}
|
|
322
|
+
const index = geometry.index;
|
|
323
|
+
if (index) {
|
|
324
|
+
entry.index ??= { buffer: this.buffer(), version: -1, byteLength: -1 };
|
|
325
|
+
// Element buffers are vertex-array state: upload with the array bound.
|
|
326
|
+
gl.bindVertexArray(entry.vao);
|
|
327
|
+
this.upload(gl.ELEMENT_ARRAY_BUFFER, entry.index, index);
|
|
328
|
+
entry.indexType = this.glType(index.data);
|
|
329
|
+
}
|
|
330
|
+
else if (entry.index) {
|
|
331
|
+
gl.deleteBuffer(entry.index.buffer);
|
|
332
|
+
entry.index = undefined;
|
|
333
|
+
}
|
|
334
|
+
entry.indexed = index !== undefined;
|
|
335
|
+
if (layoutChanged) {
|
|
336
|
+
gl.bindVertexArray(entry.vao);
|
|
337
|
+
this.bindAttributes(geometry, entry);
|
|
338
|
+
this.buildMorph(geometry, entry);
|
|
339
|
+
this.releaseWire(entry);
|
|
340
|
+
}
|
|
341
|
+
gl.bindVertexArray(null);
|
|
342
|
+
entry.layoutVersion = geometry.layoutVersion;
|
|
343
|
+
entry.version = geometry.version;
|
|
344
|
+
return entry;
|
|
345
|
+
}
|
|
346
|
+
buildMorph(geometry, entry) {
|
|
347
|
+
const gl = this.#gl, targets = geometry.morphTargets;
|
|
348
|
+
if (entry.morph) {
|
|
349
|
+
gl.deleteTexture(entry.morph.texture);
|
|
350
|
+
entry.morph = undefined;
|
|
351
|
+
}
|
|
352
|
+
if (targets.length === 0)
|
|
353
|
+
return;
|
|
354
|
+
const vertexCount = geometry.vertexCount, attributes = targets.some(target => target.normal) ? 2 : 1;
|
|
355
|
+
const texels = targets.length * attributes * vertexCount;
|
|
356
|
+
const width = Math.min(this.#maxTextureSize, Math.max(1, Math.ceil(Math.sqrt(texels)))), height = Math.ceil(texels / width);
|
|
357
|
+
if (height > this.#maxTextureSize)
|
|
358
|
+
throw new World3DError('WORLD3D_BUDGET', 'morph target data');
|
|
359
|
+
const data = new Float32Array(width * height * 4);
|
|
360
|
+
targets.forEach((target, t) => {
|
|
361
|
+
[target.position, target.normal].slice(0, attributes).forEach((source, k) => {
|
|
362
|
+
if (!source)
|
|
363
|
+
return;
|
|
364
|
+
const base = (t * attributes + k) * vertexCount * 4;
|
|
365
|
+
for (let v = 0; v < vertexCount; v++) {
|
|
366
|
+
data[base + v * 4] = source[v * 3];
|
|
367
|
+
data[base + v * 4 + 1] = source[v * 3 + 1];
|
|
368
|
+
data[base + v * 4 + 2] = source[v * 3 + 2];
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
const texture = this.dataTexture(width, height, data);
|
|
373
|
+
entry.morph = { texture, width, attributes, vertexCount };
|
|
374
|
+
}
|
|
375
|
+
dataTexture(width, height, data) {
|
|
376
|
+
const gl = this.#gl, texture = gl.createTexture();
|
|
377
|
+
if (!texture)
|
|
378
|
+
throw new World3DError('WORLD3D_CONTEXT_LOST', 'createTexture');
|
|
379
|
+
gl.activeTexture(gl.TEXTURE0 + TEXTURE_UNITS_3D.morph);
|
|
380
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
381
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
382
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, width, height, 0, gl.RGBA, gl.FLOAT, data);
|
|
383
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
384
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
385
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
386
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
387
|
+
return texture;
|
|
388
|
+
}
|
|
389
|
+
/** Vertex array whose element buffer lists every triangle edge, for wireframe drawing. */
|
|
390
|
+
wireframe(geometry) {
|
|
391
|
+
const entry = this.#geometries.get(geometry);
|
|
392
|
+
if (entry.wire && entry.wire.version === geometry.version)
|
|
393
|
+
return entry.wire;
|
|
394
|
+
const gl = this.#gl, source = geometry.index?.data, triangles = Math.floor(geometry.drawCount / 3);
|
|
395
|
+
const lines = geometry.vertexCount > 65535 ? new Uint32Array(triangles * 6) : new Uint16Array(triangles * 6);
|
|
396
|
+
for (let t = 0; t < triangles; t++) {
|
|
397
|
+
const a = source ? source[t * 3] : t * 3, b = source ? source[t * 3 + 1] : t * 3 + 1, c = source ? source[t * 3 + 2] : t * 3 + 2;
|
|
398
|
+
lines.set([a, b, b, c, c, a], t * 6);
|
|
399
|
+
}
|
|
400
|
+
this.releaseWire(entry);
|
|
401
|
+
const buffer = this.buffer(), vao = gl.createVertexArray();
|
|
402
|
+
if (!vao)
|
|
403
|
+
throw new World3DError('WORLD3D_CONTEXT_LOST', 'createVertexArray');
|
|
404
|
+
// A dedicated vertex array keeps the geometry's own element binding untouched.
|
|
405
|
+
gl.bindVertexArray(vao);
|
|
406
|
+
this.bindAttributes(geometry, entry);
|
|
407
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer);
|
|
408
|
+
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, lines, gl.STATIC_DRAW);
|
|
409
|
+
gl.bindVertexArray(null);
|
|
410
|
+
const wire = {
|
|
411
|
+
vao,
|
|
412
|
+
buffer,
|
|
413
|
+
version: geometry.version,
|
|
414
|
+
byteLength: lines.byteLength,
|
|
415
|
+
count: lines.length,
|
|
416
|
+
type: this.glType(lines)
|
|
417
|
+
};
|
|
418
|
+
entry.wire = wire;
|
|
419
|
+
return wire;
|
|
420
|
+
}
|
|
421
|
+
releaseWire(entry) {
|
|
422
|
+
if (!entry.wire)
|
|
423
|
+
return;
|
|
424
|
+
this.#gl.deleteBuffer(entry.wire.buffer);
|
|
425
|
+
this.#gl.deleteVertexArray(entry.wire.vao);
|
|
426
|
+
entry.wire = undefined;
|
|
427
|
+
}
|
|
428
|
+
releaseGeometry(geometry) {
|
|
429
|
+
const entry = this.#geometries.get(geometry), gl = this.#gl;
|
|
430
|
+
if (!entry)
|
|
431
|
+
return;
|
|
432
|
+
this.#geometries.delete(geometry);
|
|
433
|
+
for (const buffer of entry.buffers.values())
|
|
434
|
+
gl.deleteBuffer(buffer.buffer);
|
|
435
|
+
if (entry.index)
|
|
436
|
+
gl.deleteBuffer(entry.index.buffer);
|
|
437
|
+
this.releaseWire(entry);
|
|
438
|
+
if (entry.morph)
|
|
439
|
+
gl.deleteTexture(entry.morph.texture);
|
|
440
|
+
gl.deleteVertexArray(entry.vao);
|
|
441
|
+
}
|
|
442
|
+
// ---- instancing ---------------------------------------------------------------
|
|
443
|
+
instanceBuffer() {
|
|
444
|
+
return { buffer: this.buffer(), source: undefined, version: -1, byteLength: -1, uploadedCount: 0 };
|
|
445
|
+
}
|
|
446
|
+
uploadInstances(entry, source, width, count, version) {
|
|
447
|
+
if (entry.source === source && entry.version === version && count <= entry.uploadedCount)
|
|
448
|
+
return;
|
|
449
|
+
const gl = this.#gl;
|
|
450
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, entry.buffer);
|
|
451
|
+
if (entry.byteLength !== source.byteLength) {
|
|
452
|
+
gl.bufferData(gl.ARRAY_BUFFER, source, gl.DYNAMIC_DRAW);
|
|
453
|
+
entry.byteLength = source.byteLength;
|
|
454
|
+
entry.uploadedCount = source.length / width;
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
// A partial upload covers only the active prefix of this stream's revision.
|
|
458
|
+
if (count > 0)
|
|
459
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, 0, source, 0, count * width);
|
|
460
|
+
entry.uploadedCount = count;
|
|
461
|
+
}
|
|
462
|
+
entry.source = source;
|
|
463
|
+
entry.version = version;
|
|
464
|
+
}
|
|
465
|
+
/** Vertex array combining a geometry's attributes with per-instance transforms and colors. */
|
|
466
|
+
instances(mesh, frame) {
|
|
467
|
+
const gl = this.#gl, geometry = mesh.geometry;
|
|
468
|
+
this.geometry(geometry);
|
|
469
|
+
const base = this.#geometries.get(geometry);
|
|
470
|
+
let entry = this.#instances.get(mesh);
|
|
471
|
+
if (!entry) {
|
|
472
|
+
const vao = gl.createVertexArray();
|
|
473
|
+
if (!vao)
|
|
474
|
+
throw new World3DError('WORLD3D_CONTEXT_LOST', 'createVertexArray');
|
|
475
|
+
this.#instances.set(mesh, (entry = {
|
|
476
|
+
vao,
|
|
477
|
+
matrices: this.instanceBuffer(),
|
|
478
|
+
colors: undefined,
|
|
479
|
+
layoutVersion: -1,
|
|
480
|
+
geometryId: -1,
|
|
481
|
+
lastFrame: frame
|
|
482
|
+
}));
|
|
483
|
+
}
|
|
484
|
+
entry.lastFrame = frame;
|
|
485
|
+
const crowd = mesh instanceof SkinnedInstancedMesh3D ? mesh : undefined;
|
|
486
|
+
const matrices = crowd?.drawMatrices ?? mesh.instanceMatrices;
|
|
487
|
+
const colors = crowd ? crowd.drawColors : mesh.instanceColors;
|
|
488
|
+
const count = crowd?.drawCount ?? mesh.count;
|
|
489
|
+
const animated = crowd?.drawAnimation;
|
|
490
|
+
const rebind = entry.layoutVersion !== geometry.layoutVersion ||
|
|
491
|
+
entry.geometryId !== geometry.id ||
|
|
492
|
+
Boolean(colors) !== Boolean(entry.colors?.source) ||
|
|
493
|
+
(animated !== undefined && !entry.animation);
|
|
494
|
+
const revisions = crowd ? undefined : instanceStreamRevisions3D(mesh);
|
|
495
|
+
// Crowd compaction can repack all three streams when a view changes.
|
|
496
|
+
const matrixVersion = revisions?.matrices ?? mesh.instanceVersion;
|
|
497
|
+
const colorVersion = revisions?.colors ?? mesh.instanceVersion;
|
|
498
|
+
this.uploadInstances(entry.matrices, matrices, 16, count, matrixVersion);
|
|
499
|
+
if (colors) {
|
|
500
|
+
entry.colors ??= this.instanceBuffer();
|
|
501
|
+
this.uploadInstances(entry.colors, colors, mesh.instanceColorSize, count, colorVersion);
|
|
502
|
+
}
|
|
503
|
+
else if (entry.colors)
|
|
504
|
+
entry.colors.source = undefined;
|
|
505
|
+
if (animated) {
|
|
506
|
+
entry.animation ??= this.instanceBuffer();
|
|
507
|
+
this.uploadInstances(entry.animation, animated, 12, count, mesh.instanceVersion);
|
|
508
|
+
}
|
|
509
|
+
if (rebind) {
|
|
510
|
+
gl.bindVertexArray(entry.vao);
|
|
511
|
+
this.bindAttributes(geometry, base);
|
|
512
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, entry.matrices.buffer);
|
|
513
|
+
for (let column = 0; column < 4; column++) {
|
|
514
|
+
const location = ATTRIBUTE_LOCATIONS_3D.instanceMatrix + column;
|
|
515
|
+
gl.enableVertexAttribArray(location);
|
|
516
|
+
gl.vertexAttribPointer(location, 4, gl.FLOAT, false, 64, column * 16);
|
|
517
|
+
gl.vertexAttribDivisor(location, 1);
|
|
518
|
+
}
|
|
519
|
+
if (entry.colors?.source) {
|
|
520
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, entry.colors.buffer);
|
|
521
|
+
gl.enableVertexAttribArray(ATTRIBUTE_LOCATIONS_3D.instanceColor);
|
|
522
|
+
gl.vertexAttribPointer(ATTRIBUTE_LOCATIONS_3D.instanceColor, mesh.instanceColorSize, gl.FLOAT, false, 0, 0);
|
|
523
|
+
gl.vertexAttribDivisor(ATTRIBUTE_LOCATIONS_3D.instanceColor, 1);
|
|
524
|
+
}
|
|
525
|
+
else if (entry.colors)
|
|
526
|
+
gl.disableVertexAttribArray(ATTRIBUTE_LOCATIONS_3D.instanceColor);
|
|
527
|
+
if (entry.animation) {
|
|
528
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, entry.animation.buffer);
|
|
529
|
+
for (let part = 0; part < 3; part++) {
|
|
530
|
+
gl.enableVertexAttribArray(ATTRIBUTE_LOCATIONS_3D.instanceAnimation + part);
|
|
531
|
+
gl.vertexAttribPointer(ATTRIBUTE_LOCATIONS_3D.instanceAnimation + part, 4, gl.FLOAT, false, 48, part * 16);
|
|
532
|
+
gl.vertexAttribDivisor(ATTRIBUTE_LOCATIONS_3D.instanceAnimation + part, 1);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
gl.bindVertexArray(null);
|
|
536
|
+
entry.layoutVersion = geometry.layoutVersion;
|
|
537
|
+
entry.geometryId = geometry.id;
|
|
538
|
+
}
|
|
539
|
+
return entry.vao;
|
|
540
|
+
}
|
|
541
|
+
// ---- skinning ------------------------------------------------------------------
|
|
542
|
+
/** Float texture holding one 4x4 matrix per row (four RGBA texels). */
|
|
543
|
+
bones(skeleton, frame) {
|
|
544
|
+
const gl = this.#gl, count = skeleton.bones.length;
|
|
545
|
+
let entry = this.#bones.get(skeleton);
|
|
546
|
+
if (!entry || entry.count !== count) {
|
|
547
|
+
if (entry)
|
|
548
|
+
gl.deleteTexture(entry.texture);
|
|
549
|
+
this.#bones.set(skeleton, (entry = { texture: this.dataTexture(4, Math.max(count, 1), null), version: -1, count, lastFrame: frame }));
|
|
550
|
+
}
|
|
551
|
+
entry.lastFrame = frame;
|
|
552
|
+
if (entry.version !== skeleton.version && count > 0) {
|
|
553
|
+
gl.activeTexture(gl.TEXTURE0 + TEXTURE_UNITS_3D.bones);
|
|
554
|
+
gl.bindTexture(gl.TEXTURE_2D, entry.texture);
|
|
555
|
+
// Row order here is data, not an image: never let an earlier image upload's flip apply.
|
|
556
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
557
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 4, count, gl.RGBA, gl.FLOAT, skeleton.boneMatrices);
|
|
558
|
+
entry.version = skeleton.version;
|
|
559
|
+
}
|
|
560
|
+
return entry.texture;
|
|
561
|
+
}
|
|
562
|
+
/** Float texture holding every baked frame: four texels per bone matrix, wrapped into rows of 2048. */
|
|
563
|
+
animations(source) {
|
|
564
|
+
let texture = this.#animations.get(source);
|
|
565
|
+
if (!texture) {
|
|
566
|
+
const width = 2048, height = Math.max(1, Math.ceil(source.data.length / 4 / width));
|
|
567
|
+
let data = source.data;
|
|
568
|
+
if (data.length !== width * height * 4) {
|
|
569
|
+
data = new Float32Array(width * height * 4);
|
|
570
|
+
data.set(source.data);
|
|
571
|
+
}
|
|
572
|
+
texture = this.dataTexture(width, height, data);
|
|
573
|
+
this.#animations.set(source, texture);
|
|
574
|
+
const gl = this.#gl, created = texture;
|
|
575
|
+
source.onDispose(() => {
|
|
576
|
+
if (this.#animations.get(source) === created) {
|
|
577
|
+
gl.deleteTexture(created);
|
|
578
|
+
this.#animations.delete(source);
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
return texture;
|
|
583
|
+
}
|
|
584
|
+
// ---- textures ----------------------------------------------------------------------
|
|
585
|
+
applySampler(target, texture) {
|
|
586
|
+
const gl = this.#gl;
|
|
587
|
+
const wrap = (mode) => mode === 'clamp' ? gl.CLAMP_TO_EDGE : mode === 'mirror' ? gl.MIRRORED_REPEAT : gl.REPEAT;
|
|
588
|
+
gl.texParameteri(target, gl.TEXTURE_WRAP_S, wrap(texture.wrapS));
|
|
589
|
+
gl.texParameteri(target, gl.TEXTURE_WRAP_T, wrap(texture.wrapT));
|
|
590
|
+
gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, texture.magFilter === 'nearest' ? gl.NEAREST : gl.LINEAR);
|
|
591
|
+
const min = texture.mipmaps
|
|
592
|
+
? texture.minFilter === 'nearest'
|
|
593
|
+
? gl.NEAREST_MIPMAP_LINEAR
|
|
594
|
+
: gl.LINEAR_MIPMAP_LINEAR
|
|
595
|
+
: texture.minFilter === 'nearest'
|
|
596
|
+
? gl.NEAREST
|
|
597
|
+
: gl.LINEAR;
|
|
598
|
+
gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, min);
|
|
599
|
+
if (this.#anisotropy && texture.anisotropy > 1) {
|
|
600
|
+
gl.texParameterf(target, this.#anisotropy.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, this.#maxAnisotropy));
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
image(target, source, internalFormat) {
|
|
604
|
+
const gl = this.#gl;
|
|
605
|
+
if (isTexturePixels3D(source)) {
|
|
606
|
+
gl.texImage2D(target, 0, internalFormat, source.width, source.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, source.data);
|
|
607
|
+
return Math.max(source.width, source.height);
|
|
608
|
+
}
|
|
609
|
+
gl.texImage2D(target, 0, internalFormat, gl.RGBA, gl.UNSIGNED_BYTE, source);
|
|
610
|
+
const size = source;
|
|
611
|
+
return Math.max(size.videoWidth ?? size.width ?? 1, size.videoHeight ?? size.height ?? 1);
|
|
612
|
+
}
|
|
613
|
+
textureEntry(texture) {
|
|
614
|
+
let entry = this.#textures.get(texture);
|
|
615
|
+
if (!entry) {
|
|
616
|
+
const handle = this.#gl.createTexture();
|
|
617
|
+
if (!handle)
|
|
618
|
+
throw new World3DError('WORLD3D_CONTEXT_LOST', 'createTexture');
|
|
619
|
+
const created = {
|
|
620
|
+
texture: handle,
|
|
621
|
+
version: -1,
|
|
622
|
+
maxMip: 0,
|
|
623
|
+
unsubscribe: texture.onDispose(() => {
|
|
624
|
+
if (this.#textures.delete(texture))
|
|
625
|
+
this.#gl.deleteTexture(handle);
|
|
626
|
+
})
|
|
627
|
+
};
|
|
628
|
+
this.#textures.set(texture, (entry = created));
|
|
629
|
+
}
|
|
630
|
+
return entry;
|
|
631
|
+
}
|
|
632
|
+
/** Bind a 2D texture to a unit, uploading new content first when its version changed. */
|
|
633
|
+
bindTexture(unit, texture) {
|
|
634
|
+
const gl = this.#gl;
|
|
635
|
+
if (texture.source instanceof RenderTarget3D) {
|
|
636
|
+
// A target's texture samples the framebuffer color attachment directly.
|
|
637
|
+
const color = this.target(texture.source).color;
|
|
638
|
+
gl.activeTexture(gl.TEXTURE0 + unit);
|
|
639
|
+
gl.bindTexture(gl.TEXTURE_2D, color);
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
const entry = this.textureEntry(texture);
|
|
643
|
+
gl.activeTexture(gl.TEXTURE0 + unit);
|
|
644
|
+
gl.bindTexture(gl.TEXTURE_2D, entry.texture);
|
|
645
|
+
if (entry.version === texture.version)
|
|
646
|
+
return;
|
|
647
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, texture.flipY);
|
|
648
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
649
|
+
gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
|
|
650
|
+
if (isCompressedPixels3D(texture.source))
|
|
651
|
+
this.compressedImage(texture.source, texture.colorSpace === 'srgb');
|
|
652
|
+
else {
|
|
653
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAX_LEVEL, 1000);
|
|
654
|
+
this.image(gl.TEXTURE_2D, texture.source, texture.colorSpace === 'srgb' ? gl.SRGB8_ALPHA8 : gl.RGBA8);
|
|
655
|
+
if (texture.mipmaps)
|
|
656
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
657
|
+
}
|
|
658
|
+
this.applySampler(gl.TEXTURE_2D, texture);
|
|
659
|
+
// The flip belongs to this upload only; leave the context as every other upload expects it.
|
|
660
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
661
|
+
entry.version = texture.version;
|
|
662
|
+
}
|
|
663
|
+
/** Internal format for a compressed format on this context, or undefined when its extension is missing. */
|
|
664
|
+
compressedFormat(format, srgb) {
|
|
665
|
+
const gl = this.#gl;
|
|
666
|
+
// Enumerants are fixed by the extension specifications; the extension only has to be enabled.
|
|
667
|
+
const table = {
|
|
668
|
+
'bc1': [['WEBGL_compressed_texture_s3tc', 'WEBGL_compressed_texture_s3tc_srgb'], 0x83f1, 0x8c4d],
|
|
669
|
+
'bc3': [['WEBGL_compressed_texture_s3tc', 'WEBGL_compressed_texture_s3tc_srgb'], 0x83f3, 0x8c4f],
|
|
670
|
+
'bc7': [['EXT_texture_compression_bptc'], 0x8e8c, 0x8e8d],
|
|
671
|
+
'etc2-rgb8': [['WEBGL_compressed_texture_etc'], 0x9274, 0x9275],
|
|
672
|
+
'etc2-rgba8': [['WEBGL_compressed_texture_etc'], 0x9278, 0x9279],
|
|
673
|
+
'astc-4x4': [['WEBGL_compressed_texture_astc'], 0x93b0, 0x93d0]
|
|
674
|
+
};
|
|
675
|
+
const entry = table[format];
|
|
676
|
+
if (!entry)
|
|
677
|
+
return undefined;
|
|
678
|
+
const needed = entry[0].length === 2 ? [entry[0][srgb ? 1 : 0]] : entry[0];
|
|
679
|
+
for (const name of needed)
|
|
680
|
+
if (!gl.getExtension(name))
|
|
681
|
+
return undefined;
|
|
682
|
+
return srgb ? entry[2] : entry[1];
|
|
683
|
+
}
|
|
684
|
+
compressedImage(source, srgb) {
|
|
685
|
+
const gl = this.#gl, internal = this.compressedFormat(source.format, srgb);
|
|
686
|
+
if (internal === undefined)
|
|
687
|
+
throw new World3DError('WORLD3D_RESOURCE_FAILED', 'compressed format ' + source.format + ' is not supported by this device');
|
|
688
|
+
let width = source.width, height = source.height;
|
|
689
|
+
source.levels.forEach((level, index) => {
|
|
690
|
+
gl.compressedTexImage2D(gl.TEXTURE_2D, index, internal, width, height, 0, level);
|
|
691
|
+
width = Math.max(1, width >> 1);
|
|
692
|
+
height = Math.max(1, height >> 1);
|
|
693
|
+
});
|
|
694
|
+
// Sampling must stay inside the stored chain: no further levels can be generated.
|
|
695
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAX_LEVEL, source.levels.length - 1);
|
|
696
|
+
}
|
|
697
|
+
/** Bind a cube texture and return its highest mip level (used as a roughness scale). */
|
|
698
|
+
bindCube(unit, texture) {
|
|
699
|
+
const gl = this.#gl, entry = this.textureEntry(texture);
|
|
700
|
+
gl.activeTexture(gl.TEXTURE0 + unit);
|
|
701
|
+
gl.bindTexture(gl.TEXTURE_CUBE_MAP, entry.texture);
|
|
702
|
+
if (entry.version === texture.version)
|
|
703
|
+
return entry.maxMip;
|
|
704
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
705
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
706
|
+
gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
|
|
707
|
+
let size = 1;
|
|
708
|
+
texture.faces.forEach((face, i) => {
|
|
709
|
+
size = this.image(gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, face, texture.colorSpace === 'srgb' ? gl.SRGB8_ALPHA8 : gl.RGBA8);
|
|
710
|
+
});
|
|
711
|
+
if (texture.mipmaps)
|
|
712
|
+
gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
|
|
713
|
+
this.applySampler(gl.TEXTURE_CUBE_MAP, texture);
|
|
714
|
+
entry.maxMip = texture.mipmaps ? Math.floor(Math.log2(size)) : 0;
|
|
715
|
+
entry.version = texture.version;
|
|
716
|
+
return entry.maxMip;
|
|
717
|
+
}
|
|
718
|
+
// ---- render targets -----------------------------------------------------------------
|
|
719
|
+
/** Create or resize the framebuffer of a render target. */
|
|
720
|
+
target(target) {
|
|
721
|
+
const gl = this.#gl;
|
|
722
|
+
if (target.isDisposed)
|
|
723
|
+
throw new World3DError('WORLD3D_DISPOSED', 'render target');
|
|
724
|
+
let entry = this.#targets.get(target);
|
|
725
|
+
if (entry && entry.version === target.version)
|
|
726
|
+
return entry;
|
|
727
|
+
if (target.width > this.#maxTextureSize || target.height > this.#maxTextureSize)
|
|
728
|
+
throw new World3DError('WORLD3D_BUDGET', 'render target size');
|
|
729
|
+
const isNew = !entry;
|
|
730
|
+
if (!entry) {
|
|
731
|
+
const framebuffer = gl.createFramebuffer(), color = gl.createTexture();
|
|
732
|
+
if (!framebuffer || !color) {
|
|
733
|
+
if (framebuffer)
|
|
734
|
+
gl.deleteFramebuffer(framebuffer);
|
|
735
|
+
if (color)
|
|
736
|
+
gl.deleteTexture(color);
|
|
737
|
+
throw new World3DError('WORLD3D_CONTEXT_LOST', 'createFramebuffer');
|
|
738
|
+
}
|
|
739
|
+
entry = {
|
|
740
|
+
framebuffer,
|
|
741
|
+
color,
|
|
742
|
+
depth: undefined,
|
|
743
|
+
depthTexture: undefined,
|
|
744
|
+
version: -1,
|
|
745
|
+
unsubscribe: target.onDispose(() => this.releaseTarget(target))
|
|
746
|
+
};
|
|
747
|
+
this.#targets.set(target, entry);
|
|
748
|
+
}
|
|
749
|
+
// A sampled target can allocate here while a different target is being drawn.
|
|
750
|
+
// Keep the current texture unit and preserve both the draw target and its bindings.
|
|
751
|
+
const previousDraw = gl.getParameter(gl.DRAW_FRAMEBUFFER_BINDING);
|
|
752
|
+
const previousTexture = gl.getParameter(gl.TEXTURE_BINDING_2D);
|
|
753
|
+
const previousDepth = gl.getParameter(gl.RENDERBUFFER_BINDING);
|
|
754
|
+
try {
|
|
755
|
+
gl.bindTexture(gl.TEXTURE_2D, entry.color);
|
|
756
|
+
// Mutable storage lets setSize() reallocate the same texture object.
|
|
757
|
+
if (target.format === 'rgba16f' && this.floatTargets)
|
|
758
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA16F, target.width, target.height, 0, gl.RGBA, gl.HALF_FLOAT, null);
|
|
759
|
+
else
|
|
760
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.SRGB8_ALPHA8, target.width, target.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
761
|
+
this.applySampler(gl.TEXTURE_2D, target.texture);
|
|
762
|
+
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, entry.framebuffer);
|
|
763
|
+
gl.framebufferTexture2D(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, entry.color, 0);
|
|
764
|
+
if (target.depthTexture) {
|
|
765
|
+
entry.depthTexture ??= gl.createTexture() ?? undefined;
|
|
766
|
+
if (!entry.depthTexture)
|
|
767
|
+
throw new World3DError('WORLD3D_CONTEXT_LOST', 'createTexture');
|
|
768
|
+
gl.bindTexture(gl.TEXTURE_2D, entry.depthTexture);
|
|
769
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_COMPONENT24, target.width, target.height, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_INT, null);
|
|
770
|
+
// Depth textures cannot be filtered; they are read texel by texel.
|
|
771
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
772
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
773
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
774
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
775
|
+
gl.framebufferTexture2D(gl.DRAW_FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, entry.depthTexture, 0);
|
|
776
|
+
}
|
|
777
|
+
else if (target.depth) {
|
|
778
|
+
entry.depth ??= gl.createRenderbuffer() ?? undefined;
|
|
779
|
+
if (!entry.depth)
|
|
780
|
+
throw new World3DError('WORLD3D_CONTEXT_LOST', 'createRenderbuffer');
|
|
781
|
+
gl.bindRenderbuffer(gl.RENDERBUFFER, entry.depth);
|
|
782
|
+
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT24, target.width, target.height);
|
|
783
|
+
gl.framebufferRenderbuffer(gl.DRAW_FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, entry.depth);
|
|
784
|
+
}
|
|
785
|
+
if (gl.checkFramebufferStatus(gl.DRAW_FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE && !gl.isContextLost()) {
|
|
786
|
+
throw new World3DError('WORLD3D_RESOURCE_FAILED', 'render target is incomplete');
|
|
787
|
+
}
|
|
788
|
+
entry.version = target.version;
|
|
789
|
+
return entry;
|
|
790
|
+
}
|
|
791
|
+
catch (error) {
|
|
792
|
+
if (isNew) {
|
|
793
|
+
entry.unsubscribe();
|
|
794
|
+
this.releaseTarget(target);
|
|
795
|
+
}
|
|
796
|
+
throw error;
|
|
797
|
+
}
|
|
798
|
+
finally {
|
|
799
|
+
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, previousDraw);
|
|
800
|
+
gl.bindTexture(gl.TEXTURE_2D, previousTexture);
|
|
801
|
+
gl.bindRenderbuffer(gl.RENDERBUFFER, previousDepth);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
releaseTarget(target) {
|
|
805
|
+
const entry = this.#targets.get(target), gl = this.#gl;
|
|
806
|
+
if (!entry)
|
|
807
|
+
return;
|
|
808
|
+
this.#targets.delete(target);
|
|
809
|
+
gl.deleteFramebuffer(entry.framebuffer);
|
|
810
|
+
gl.deleteTexture(entry.color);
|
|
811
|
+
if (entry.depth)
|
|
812
|
+
gl.deleteRenderbuffer(entry.depth);
|
|
813
|
+
if (entry.depthTexture)
|
|
814
|
+
gl.deleteTexture(entry.depthTexture);
|
|
815
|
+
}
|
|
816
|
+
// ---- lifetime -----------------------------------------------------------------------
|
|
817
|
+
/** Retire per-mesh and per-skeleton data that has not been drawn recently. */
|
|
818
|
+
prune(frame) {
|
|
819
|
+
if (frame % PRUNE_INTERVAL !== 0)
|
|
820
|
+
return;
|
|
821
|
+
const gl = this.#gl;
|
|
822
|
+
for (const [mesh, entry] of this.#instances) {
|
|
823
|
+
if (frame - entry.lastFrame < PRUNE_INTERVAL)
|
|
824
|
+
continue;
|
|
825
|
+
gl.deleteBuffer(entry.matrices.buffer);
|
|
826
|
+
if (entry.colors)
|
|
827
|
+
gl.deleteBuffer(entry.colors.buffer);
|
|
828
|
+
if (entry.animation)
|
|
829
|
+
gl.deleteBuffer(entry.animation.buffer);
|
|
830
|
+
gl.deleteVertexArray(entry.vao);
|
|
831
|
+
this.#instances.delete(mesh);
|
|
832
|
+
}
|
|
833
|
+
for (const [skeleton, entry] of this.#bones) {
|
|
834
|
+
if (frame - entry.lastFrame < PRUNE_INTERVAL)
|
|
835
|
+
continue;
|
|
836
|
+
gl.deleteTexture(entry.texture);
|
|
837
|
+
this.#bones.delete(skeleton);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
/** Forget every GPU handle without deleting it; used after the context was lost. */
|
|
841
|
+
reset() {
|
|
842
|
+
this.#programsRetired = 'lost';
|
|
843
|
+
this.#pendingPrograms.clear();
|
|
844
|
+
for (const entry of this.#geometries.values())
|
|
845
|
+
entry.unsubscribe();
|
|
846
|
+
for (const entry of this.#textures.values())
|
|
847
|
+
entry.unsubscribe();
|
|
848
|
+
for (const entry of this.#targets.values())
|
|
849
|
+
entry.unsubscribe();
|
|
850
|
+
this.#programs.clear();
|
|
851
|
+
this.#geometries.clear();
|
|
852
|
+
this.#instances.clear();
|
|
853
|
+
this.#textures.clear();
|
|
854
|
+
this.#bones.clear();
|
|
855
|
+
this.#targets.clear();
|
|
856
|
+
this.#animations.clear();
|
|
857
|
+
}
|
|
858
|
+
/** Delete every GPU object owned by this cache. */
|
|
859
|
+
dispose() {
|
|
860
|
+
const gl = this.#gl;
|
|
861
|
+
this.#programsRetired = 'disposed';
|
|
862
|
+
for (const { program, shaders } of this.#pendingPrograms.values()) {
|
|
863
|
+
for (const shader of shaders)
|
|
864
|
+
gl.deleteShader(shader);
|
|
865
|
+
gl.deleteProgram(program);
|
|
866
|
+
}
|
|
867
|
+
this.#pendingPrograms.clear();
|
|
868
|
+
for (const geometry of [...this.#geometries.keys()]) {
|
|
869
|
+
this.#geometries.get(geometry).unsubscribe();
|
|
870
|
+
this.releaseGeometry(geometry);
|
|
871
|
+
}
|
|
872
|
+
for (const entry of this.#textures.values()) {
|
|
873
|
+
entry.unsubscribe();
|
|
874
|
+
gl.deleteTexture(entry.texture);
|
|
875
|
+
}
|
|
876
|
+
for (const entry of this.#instances.values()) {
|
|
877
|
+
gl.deleteBuffer(entry.matrices.buffer);
|
|
878
|
+
if (entry.colors)
|
|
879
|
+
gl.deleteBuffer(entry.colors.buffer);
|
|
880
|
+
if (entry.animation)
|
|
881
|
+
gl.deleteBuffer(entry.animation.buffer);
|
|
882
|
+
gl.deleteVertexArray(entry.vao);
|
|
883
|
+
}
|
|
884
|
+
for (const texture of this.#animations.values())
|
|
885
|
+
gl.deleteTexture(texture);
|
|
886
|
+
this.#animations.clear();
|
|
887
|
+
for (const entry of this.#bones.values())
|
|
888
|
+
gl.deleteTexture(entry.texture);
|
|
889
|
+
for (const target of [...this.#targets.keys()]) {
|
|
890
|
+
this.#targets.get(target).unsubscribe();
|
|
891
|
+
this.releaseTarget(target);
|
|
892
|
+
}
|
|
893
|
+
for (const entry of this.#programs.values())
|
|
894
|
+
gl.deleteProgram(entry.program);
|
|
895
|
+
this.#programs.clear();
|
|
896
|
+
this.#textures.clear();
|
|
897
|
+
this.#instances.clear();
|
|
898
|
+
this.#bones.clear();
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
//# sourceMappingURL=gpuResources3D.js.map
|