ris-framework 0.1.0 → 0.2.0-dev.12
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/CHANGELOG.md +42 -1
- package/README.md +27 -4
- package/dist/Framework.d.ts +34 -10
- package/dist/Framework.d.ts.map +1 -1
- package/dist/api/IFramework.d.ts +50 -6
- package/dist/api/IFramework.d.ts.map +1 -1
- package/dist/api/_export.d.ts +3 -1
- package/dist/api/_export.d.ts.map +1 -1
- package/dist/api/camera/CameraFactory.d.ts +3 -2
- package/dist/api/camera/CameraFactory.d.ts.map +1 -1
- package/dist/api/camera/ICamera.d.ts +5 -0
- package/dist/api/camera/ICamera.d.ts.map +1 -1
- package/dist/api/camera/ICameraFactory.d.ts +5 -6
- package/dist/api/camera/ICameraFactory.d.ts.map +1 -1
- package/dist/api/camera/OrthographicCamera.d.ts +7 -0
- package/dist/api/camera/OrthographicCamera.d.ts.map +1 -1
- package/dist/api/camera/PerspectiveCamera.d.ts +30 -6
- package/dist/api/camera/PerspectiveCamera.d.ts.map +1 -1
- package/dist/api/content/ContentManager.d.ts +15 -2
- package/dist/api/content/ContentManager.d.ts.map +1 -1
- package/dist/api/content/IContentManager.d.ts +35 -1
- package/dist/api/content/IContentManager.d.ts.map +1 -1
- package/dist/api/content/ShaderModuleContent.d.ts.map +1 -1
- package/dist/api/data/Color.d.ts +5 -0
- package/dist/api/data/Color.d.ts.map +1 -1
- package/dist/api/geometry/BaseGeometry.d.ts +9 -0
- package/dist/api/geometry/BaseGeometry.d.ts.map +1 -1
- package/dist/api/geometry/GeometryBuilder.d.ts +3 -1
- package/dist/api/geometry/GeometryBuilder.d.ts.map +1 -1
- package/dist/api/geometry/IGeometryBuilder.d.ts +24 -0
- package/dist/api/geometry/IGeometryBuilder.d.ts.map +1 -1
- package/dist/api/geometry/_export-geometry.d.ts +1 -0
- package/dist/api/geometry/_export-geometry.d.ts.map +1 -1
- package/dist/api/input/InputManager.d.ts +4 -0
- package/dist/api/input/InputManager.d.ts.map +1 -1
- package/dist/api/lights/AmbientLight.d.ts +35 -0
- package/dist/api/lights/AmbientLight.d.ts.map +1 -0
- package/dist/api/lights/DirectionalLight.d.ts +40 -0
- package/dist/api/lights/DirectionalLight.d.ts.map +1 -0
- package/dist/api/lights/LightFactory.d.ts +18 -0
- package/dist/api/lights/LightFactory.d.ts.map +1 -0
- package/dist/api/lights/LightId.d.ts +6 -0
- package/dist/api/lights/LightId.d.ts.map +1 -0
- package/dist/api/lights/LightsBuffer.d.ts +77 -0
- package/dist/api/lights/LightsBuffer.d.ts.map +1 -0
- package/dist/api/lights/PointLight.d.ts +59 -0
- package/dist/api/lights/PointLight.d.ts.map +1 -0
- package/dist/api/lights/_export.d.ts +6 -0
- package/dist/api/lights/_export.d.ts.map +1 -0
- package/dist/api/loaders/ObjGeometryMapper.d.ts +19 -0
- package/dist/api/loaders/ObjGeometryMapper.d.ts.map +1 -0
- package/dist/api/loaders/ObjLoader.d.ts +61 -0
- package/dist/api/loaders/ObjLoader.d.ts.map +1 -0
- package/dist/api/loaders/_export.d.ts +2 -0
- package/dist/api/loaders/_export.d.ts.map +1 -1
- package/dist/api/loaders/obj/ObjParser.d.ts +44 -0
- package/dist/api/loaders/obj/ObjParser.d.ts.map +1 -0
- package/dist/api/loaders/obj/ObjTypes.d.ts +119 -0
- package/dist/api/loaders/obj/ObjTypes.d.ts.map +1 -0
- package/dist/api/loaders/obj/index.d.ts +3 -0
- package/dist/api/loaders/obj/index.d.ts.map +1 -0
- package/dist/api/material/ForwardBlinnPhongMaterial.d.ts +138 -0
- package/dist/api/material/ForwardBlinnPhongMaterial.d.ts.map +1 -0
- package/dist/api/material/ICameraMaterial.d.ts +18 -0
- package/dist/api/material/ICameraMaterial.d.ts.map +1 -0
- package/dist/api/material/ILightsMaterial.d.ts +26 -0
- package/dist/api/material/ILightsMaterial.d.ts.map +1 -0
- package/dist/api/material/IMaterial.d.ts +13 -10
- package/dist/api/material/IMaterial.d.ts.map +1 -1
- package/dist/api/material/IMaterialFactory.d.ts +17 -2
- package/dist/api/material/IMaterialFactory.d.ts.map +1 -1
- package/dist/api/material/InspectTextureMipsMaterial.d.ts +18 -9
- package/dist/api/material/InspectTextureMipsMaterial.d.ts.map +1 -1
- package/dist/api/material/MaterialFactory.d.ts +6 -0
- package/dist/api/material/MaterialFactory.d.ts.map +1 -1
- package/dist/api/material/SpriteMaterial.d.ts +51 -0
- package/dist/api/material/SpriteMaterial.d.ts.map +1 -0
- package/dist/api/material/UnlitMaterial.d.ts +32 -13
- package/dist/api/material/UnlitMaterial.d.ts.map +1 -1
- package/dist/api/material/_export.d.ts +4 -0
- package/dist/api/material/_export.d.ts.map +1 -1
- package/dist/api/meshes/IMesh.d.ts +31 -6
- package/dist/api/meshes/IMesh.d.ts.map +1 -1
- package/dist/api/meshes/IMeshFactory.d.ts +30 -4
- package/dist/api/meshes/IMeshFactory.d.ts.map +1 -1
- package/dist/api/meshes/IRenderableMesh.d.ts +47 -0
- package/dist/api/meshes/IRenderableMesh.d.ts.map +1 -0
- package/dist/api/meshes/Mesh.d.ts +14 -8
- package/dist/api/meshes/Mesh.d.ts.map +1 -1
- package/dist/api/meshes/MeshFactory.d.ts +10 -3
- package/dist/api/meshes/MeshFactory.d.ts.map +1 -1
- package/dist/api/meshes/QuadMesh.d.ts +5 -3
- package/dist/api/meshes/QuadMesh.d.ts.map +1 -1
- package/dist/api/meshes/RenderableMesh.d.ts +95 -0
- package/dist/api/meshes/RenderableMesh.d.ts.map +1 -0
- package/dist/api/meshes/_export.d.ts +2 -0
- package/dist/api/meshes/_export.d.ts.map +1 -1
- package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts +8 -2
- package/dist/api/rendering/IGraphicsDeviceFeatures.d.ts.map +1 -1
- package/dist/api/rendering/IRenderer.d.ts +28 -1
- package/dist/api/rendering/IRenderer.d.ts.map +1 -1
- package/dist/api/rendering/enums.d.ts +7 -0
- package/dist/api/rendering/enums.d.ts.map +1 -1
- package/dist/api/rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.d.ts +56 -0
- package/dist/api/rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.d.ts.map +1 -0
- package/dist/api/rendering/render-pipelines/IRenderPipeline.d.ts +3 -0
- package/dist/api/rendering/render-pipelines/IRenderPipeline.d.ts.map +1 -1
- package/dist/api/rendering/render-pipelines/IRenderPipelineFactory.d.ts +29 -0
- package/dist/api/rendering/render-pipelines/IRenderPipelineFactory.d.ts.map +1 -1
- package/dist/api/rendering/render-pipelines/_export-render-pipelines.d.ts +1 -0
- package/dist/api/rendering/render-pipelines/_export-render-pipelines.d.ts.map +1 -1
- package/dist/api/rendering/renderer-interface.d.ts +1 -31
- package/dist/api/rendering/renderer-interface.d.ts.map +1 -1
- package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts +2 -6
- package/dist/api/rendering/renderpass/RenderPassDescriptor.d.ts.map +1 -1
- package/dist/api/rendering/swapchain/ISwapChain.d.ts +1 -3
- package/dist/api/rendering/swapchain/ISwapChain.d.ts.map +1 -1
- package/dist/api/rendering/texture/TextureFormat.d.ts +88 -14
- package/dist/api/rendering/texture/TextureFormat.d.ts.map +1 -1
- package/dist/api/rendering/texture/TextureUtilities.d.ts +23 -0
- package/dist/api/rendering/texture/TextureUtilities.d.ts.map +1 -1
- package/dist/api/scene/Scene.d.ts +113 -0
- package/dist/api/scene/Scene.d.ts.map +1 -0
- package/dist/api/scene/SceneMesh.d.ts +27 -0
- package/dist/api/scene/SceneMesh.d.ts.map +1 -0
- package/dist/api/shader/IShaderModuleLoader.d.ts +4 -1
- package/dist/api/shader/IShaderModuleLoader.d.ts.map +1 -1
- package/dist/api/shader/{shader-loader.d.ts → ShaderLoader.d.ts} +1 -1
- package/dist/api/shader/ShaderLoader.d.ts.map +1 -0
- package/dist/api/sprites/SpriteBatchDrawable.d.ts +1 -1
- package/dist/api/sprites/SpriteBatchDrawable.d.ts.map +1 -1
- package/dist/api/sprites/SpriteBatchMesh.d.ts +14 -1
- package/dist/api/sprites/SpriteBatchMesh.d.ts.map +1 -1
- package/dist/api/utilities/AlignUtilities.d.ts.map +1 -1
- package/dist/api/utilities/GeometryUtilities.d.ts.map +1 -1
- package/dist/api/window/WindowManager.d.ts +4 -0
- package/dist/api/window/WindowManager.d.ts.map +1 -1
- package/dist/core/rendering/ARenderer.d.ts +5 -5
- package/dist/core/rendering/ARenderer.d.ts.map +1 -1
- package/dist/core/rendering/vertex-buffer-layout.d.ts +1 -0
- package/dist/core/rendering/vertex-buffer-layout.d.ts.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9238 -4595
- package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts +4 -0
- package/dist/webgl/WebGLGraphicsDeviceFeatures.d.ts.map +1 -1
- package/dist/webgl/WebGlGraphicsDevice.d.ts.map +1 -1
- package/dist/webgl/WebGlRenderer.d.ts +1 -3
- package/dist/webgl/WebGlRenderer.d.ts.map +1 -1
- package/dist/webgl/lights/WebGlAmbientLightFactory.d.ts +17 -0
- package/dist/webgl/lights/WebGlAmbientLightFactory.d.ts.map +1 -0
- package/dist/webgl/lights/WebGlLightsBuffer.d.ts +59 -0
- package/dist/webgl/lights/WebGlLightsBuffer.d.ts.map +1 -0
- package/dist/webgl/render-pipelines/AWebGlRenderPipeline.d.ts +3 -1
- package/dist/webgl/render-pipelines/AWebGlRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts +5 -0
- package/dist/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/WebGlRenderPipelineFactory.d.ts +3 -1
- package/dist/webgl/render-pipelines/WebGlRenderPipelineFactory.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/inspect/WebGlInspectTextureMipsRenderPipeline.d.ts +3 -1
- package/dist/webgl/render-pipelines/inspect/WebGlInspectTextureMipsRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/material/WebGlBlinnPhongRenderPipeline.d.ts +88 -0
- package/dist/webgl/render-pipelines/material/WebGlBlinnPhongRenderPipeline.d.ts.map +1 -0
- package/dist/webgl/render-pipelines/material/WebGlUnlitRenderPipeline.d.ts +3 -1
- package/dist/webgl/render-pipelines/material/WebGlUnlitRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/render-pipelines/sprite/WebGlSpriteRenderPipeline.d.ts +3 -1
- package/dist/webgl/render-pipelines/sprite/WebGlSpriteRenderPipeline.d.ts.map +1 -1
- package/dist/webgl/shader/WebGlShaderModule.d.ts +4 -1
- package/dist/webgl/shader/WebGlShaderModule.d.ts.map +1 -1
- package/dist/webgl/shader/WebGlShaderModuleLoader.d.ts +16 -5
- package/dist/webgl/shader/WebGlShaderModuleLoader.d.ts.map +1 -1
- package/dist/webgl/swap-chain/WebGlSwapChain.d.ts +3 -2
- package/dist/webgl/swap-chain/WebGlSwapChain.d.ts.map +1 -1
- package/dist/webgl/texture/WebGlTexture2D.d.ts +8 -1
- package/dist/webgl/texture/WebGlTexture2D.d.ts.map +1 -1
- package/dist/webgl/texture/WebGlTextureFactory.d.ts +7 -0
- package/dist/webgl/texture/WebGlTextureFactory.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlConstants.d.ts +91 -0
- package/dist/webgl/utilities/WebGlConstants.d.ts.map +1 -0
- package/dist/webgl/utilities/WebGlConverter.d.ts +0 -7
- package/dist/webgl/utilities/WebGlConverter.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlErrorUtilities.d.ts +10 -0
- package/dist/webgl/utilities/WebGlErrorUtilities.d.ts.map +1 -0
- package/dist/webgl/utilities/WebGlTextureUtilities.d.ts.map +1 -1
- package/dist/webgl/utilities/WebGlUtilities.d.ts +3 -0
- package/dist/webgl/utilities/WebGlUtilities.d.ts.map +1 -1
- package/dist/webgl/utilities/webgl-filter-anisotropic-utilities.d.ts +0 -1
- package/dist/webgl/utilities/webgl-filter-anisotropic-utilities.d.ts.map +1 -1
- package/dist/webgpu/WebGpuGpuInfo.d.ts +28 -0
- package/dist/webgpu/WebGpuGpuInfo.d.ts.map +1 -0
- package/dist/webgpu/WebGpuGraphicsDevice.d.ts +80 -0
- package/dist/webgpu/WebGpuGraphicsDevice.d.ts.map +1 -0
- package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts +26 -0
- package/dist/webgpu/WebGpuGraphicsDeviceFeatures.d.ts.map +1 -0
- package/dist/webgpu/WebGpuRenderer.d.ts +26 -0
- package/dist/webgpu/WebGpuRenderer.d.ts.map +1 -0
- package/dist/webgpu/WebGpuTypes.d.ts +355 -0
- package/dist/webgpu/WebGpuTypes.d.ts.map +1 -0
- package/dist/webgpu/blending/WebGpuBlendState.d.ts +30 -0
- package/dist/webgpu/blending/WebGpuBlendState.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts +20 -0
- package/dist/webgpu/buffers/WebGpuBuffersFactory.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts +46 -0
- package/dist/webgpu/buffers/WebGpuIndexBuffer.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts +43 -0
- package/dist/webgpu/buffers/WebGpuUniformBuffer.d.ts.map +1 -0
- package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts +49 -0
- package/dist/webgpu/buffers/WebGpuVertexBuffer.d.ts.map +1 -0
- package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts +32 -0
- package/dist/webgpu/primitive/WebGpuPrimitiveState.d.ts.map +1 -0
- package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts +28 -0
- package/dist/webgpu/render-pass/WebGpuRenderPass.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts +50 -0
- package/dist/webgpu/render-pipelines/AWebGpuRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts +34 -0
- package/dist/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts +26 -0
- package/dist/webgpu/render-pipelines/WebGpuRenderPipelineFactory.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts +72 -0
- package/dist/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts +40 -0
- package/dist/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.d.ts.map +1 -0
- package/dist/webgpu/sampler/WebGpuSampler.d.ts +39 -0
- package/dist/webgpu/sampler/WebGpuSampler.d.ts.map +1 -0
- package/dist/webgpu/shader/WebGpuShaderModule.d.ts +29 -0
- package/dist/webgpu/shader/WebGpuShaderModule.d.ts.map +1 -0
- package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts +21 -0
- package/dist/webgpu/shader/WebGpuShaderModuleLoader.d.ts.map +1 -0
- package/dist/webgpu/shader/WgslShaderContent.d.ts +9 -0
- package/dist/webgpu/shader/WgslShaderContent.d.ts.map +1 -0
- package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts +41 -0
- package/dist/webgpu/swap-chain/WebGpuSwapChain.d.ts.map +1 -0
- package/dist/webgpu/texture/WebGpuTexture2D.d.ts +47 -0
- package/dist/webgpu/texture/WebGpuTexture2D.d.ts.map +1 -0
- package/dist/webgpu/texture/WebGpuTextureFactory.d.ts +21 -0
- package/dist/webgpu/texture/WebGpuTextureFactory.d.ts.map +1 -0
- package/dist/webgpu/texture/WebGpuTextureView.d.ts +25 -0
- package/dist/webgpu/texture/WebGpuTextureView.d.ts.map +1 -0
- package/dist/webgpu/utilities/WebGpuConverter.d.ts +45 -0
- package/dist/webgpu/utilities/WebGpuConverter.d.ts.map +1 -0
- package/package.json +4 -4
- package/shaders/glsl/forward_blinn_phong_material_fs.glsl +110 -0
- package/shaders/glsl/forward_blinn_phong_material_vs.glsl +32 -0
- package/shaders/glsl/main_render_target_flip_y_fs.glsl +35 -1
- package/shaders/glsl/sprite_fs.glsl +1 -1
- package/shaders/glsl/unlit_material_fs.glsl +1 -1
- package/shaders/wgsl/forward_blinn_phong_material.wgsl +150 -0
- package/shaders/wgsl/inspect_texture_mips.wgsl +51 -0
- package/shaders/wgsl/main_frame_buffer.wgsl +35 -0
- package/shaders/wgsl/main_render_target_flip_y.wgsl +35 -0
- package/shaders/wgsl/sprite.wgsl +40 -0
- package/shaders/wgsl/unlit_material.wgsl +49 -0
- package/src/Framework.ts +156 -48
- package/src/api/IFramework.ts +63 -6
- package/src/api/_export.ts +3 -1
- package/src/api/camera/CameraFactory.ts +6 -6
- package/src/api/camera/ICamera.ts +6 -0
- package/src/api/camera/ICameraFactory.ts +5 -10
- package/src/api/camera/OrthographicCamera.ts +23 -1
- package/src/api/camera/PerspectiveCamera.ts +60 -15
- package/src/api/content/ContentManager.ts +78 -16
- package/src/api/content/IContentManager.ts +37 -1
- package/src/api/content/ShaderModuleContent.ts +9 -0
- package/src/api/data/Color.ts +7 -1
- package/src/api/geometry/BaseGeometry.ts +23 -0
- package/src/api/geometry/GeometryBuilder.ts +14 -2
- package/src/api/geometry/IGeometryBuilder.ts +31 -1
- package/src/api/geometry/_export-geometry.ts +2 -1
- package/src/api/input/InputManager.ts +14 -5
- package/src/api/lights/AmbientLight.ts +53 -0
- package/src/api/lights/DirectionalLight.ts +60 -0
- package/src/api/lights/LightFactory.ts +21 -0
- package/src/api/lights/LightId.ts +9 -0
- package/src/api/lights/LightsBuffer.ts +94 -0
- package/src/api/lights/PointLight.ts +91 -0
- package/src/api/lights/_export.ts +5 -0
- package/src/api/loaders/ObjGeometryMapper.ts +28 -0
- package/src/api/loaders/ObjLoader.ts +126 -0
- package/src/api/loaders/_export.ts +3 -1
- package/src/api/loaders/obj/ObjParser.ts +301 -0
- package/src/api/loaders/obj/ObjTypes.ts +142 -0
- package/src/api/loaders/obj/index.ts +5 -0
- package/src/api/material/ForwardBlinnPhongMaterial.ts +328 -0
- package/src/api/material/ICameraMaterial.ts +22 -0
- package/src/api/material/ILightsMaterial.ts +32 -0
- package/src/api/material/IMaterial.ts +13 -10
- package/src/api/material/IMaterialFactory.ts +19 -2
- package/src/api/material/InspectTextureMipsMaterial.ts +65 -26
- package/src/api/material/MaterialFactory.ts +12 -0
- package/src/api/material/SpriteMaterial.ts +83 -0
- package/src/api/material/UnlitMaterial.ts +105 -32
- package/src/api/material/_export.ts +5 -1
- package/src/api/meshes/IMesh.ts +40 -6
- package/src/api/meshes/IMeshFactory.ts +33 -4
- package/src/api/meshes/IRenderableMesh.ts +58 -0
- package/src/api/meshes/Mesh.ts +50 -43
- package/src/api/meshes/MeshFactory.ts +37 -4
- package/src/api/meshes/QuadMesh.ts +6 -4
- package/src/api/meshes/RenderableMesh.ts +207 -0
- package/src/api/meshes/_export.ts +6 -4
- package/src/api/rendering/IGraphicsDeviceFeatures.ts +28 -21
- package/src/api/rendering/IRenderer.ts +34 -1
- package/src/api/rendering/enums.ts +10 -0
- package/src/api/rendering/render-pipelines/IForwardBlinnPhongRenderPipeline.ts +66 -0
- package/src/api/rendering/render-pipelines/IRenderPipeline.ts +4 -0
- package/src/api/rendering/render-pipelines/IRenderPipelineFactory.ts +39 -0
- package/src/api/rendering/render-pipelines/_export-render-pipelines.ts +2 -1
- package/src/api/rendering/renderer-interface.ts +1 -36
- package/src/api/rendering/renderpass/RenderPassDescriptor.ts +10 -14
- package/src/api/rendering/swapchain/ISwapChain.ts +1 -3
- package/src/api/rendering/texture/TextureFormat.ts +128 -14
- package/src/api/rendering/texture/TextureUtilities.ts +225 -10
- package/src/api/scene/Scene.ts +297 -0
- package/src/api/scene/SceneMesh.ts +61 -0
- package/src/api/shader/IShaderModuleLoader.ts +2 -1
- package/src/api/sprites/SpriteBatchDrawable.ts +12 -16
- package/src/api/sprites/SpriteBatchMesh.ts +22 -3
- package/src/api/utilities/AlignUtilities.ts +2 -1
- package/src/api/utilities/GeometryUtilities.ts +2 -0
- package/src/api/window/WindowManager.ts +23 -3
- package/src/core/rendering/ARenderer.ts +24 -15
- package/src/core/rendering/vertex-buffer-layout.ts +32 -1
- package/src/index.ts +0 -1
- package/src/main.ts +2 -4
- package/src/webgl/WebGLGraphicsDeviceFeatures.ts +12 -2
- package/src/webgl/WebGlGpuInfo.ts +1 -1
- package/src/webgl/WebGlGraphicsDevice.ts +0 -1
- package/src/webgl/WebGlRenderer.ts +2 -5
- package/src/webgl/lights/WebGlAmbientLightFactory.ts +35 -0
- package/src/webgl/lights/WebGlLightsBuffer.ts +225 -0
- package/src/webgl/render-pipelines/AWebGlRenderPipeline.ts +7 -1
- package/src/webgl/render-pipelines/WebGlMainRenderTargetRenderPipeline.ts +21 -1
- package/src/webgl/render-pipelines/WebGlRenderPipelineFactory.ts +24 -2
- package/src/webgl/render-pipelines/inspect/WebGlInspectTextureMipsRenderPipeline.ts +16 -6
- package/src/webgl/render-pipelines/material/WebGlBlinnPhongRenderPipeline.ts +300 -0
- package/src/webgl/render-pipelines/material/WebGlUnlitRenderPipeline.ts +16 -6
- package/src/webgl/render-pipelines/sprite/WebGlSpriteRenderPipeline.ts +11 -7
- package/src/webgl/shader/WebGlShaderModule.ts +11 -4
- package/src/webgl/shader/WebGlShaderModuleLoader.ts +29 -10
- package/src/webgl/swap-chain/WebGlSwapChain.ts +7 -6
- package/src/webgl/texture/WebGlTexture2D.ts +19 -5
- package/src/webgl/texture/WebGlTextureFactory.ts +49 -7
- package/src/webgl/utilities/WebGlConstants.ts +136 -0
- package/src/webgl/utilities/WebGlConverter.ts +91 -22
- package/src/webgl/utilities/WebGlErrorUtilities.ts +15 -0
- package/src/webgl/utilities/WebGlTextureUtilities.ts +5 -2
- package/src/webgl/utilities/WebGlUtilities.ts +4 -0
- package/src/webgl/utilities/webgl-filter-anisotropic-utilities.ts +9 -6
- package/src/webgpu/WebGpuGpuInfo.ts +61 -0
- package/src/webgpu/WebGpuGraphicsDevice.ts +199 -0
- package/src/webgpu/WebGpuGraphicsDeviceFeatures.ts +41 -0
- package/src/webgpu/WebGpuRenderer.ts +49 -0
- package/src/webgpu/WebGpuTypes.ts +288 -0
- package/src/webgpu/blending/WebGpuBlendState.ts +53 -0
- package/src/webgpu/buffers/WebGpuBuffersFactory.ts +46 -0
- package/src/webgpu/buffers/WebGpuIndexBuffer.ts +118 -0
- package/src/webgpu/buffers/WebGpuUniformBuffer.ts +102 -0
- package/src/webgpu/buffers/WebGpuVertexBuffer.ts +119 -0
- package/src/webgpu/primitive/WebGpuPrimitiveState.ts +52 -0
- package/src/webgpu/render-pass/WebGpuRenderPass.ts +131 -0
- package/src/webgpu/render-pipelines/AWebGpuRenderPipeline.ts +123 -0
- package/src/webgpu/render-pipelines/WebGpuMainRenderTargetRenderPipeline.ts +119 -0
- package/src/webgpu/render-pipelines/WebGpuRenderPipelineFactory.ts +66 -0
- package/src/webgpu/render-pipelines/material/AWebGpuMeshRenderPipeline.ts +249 -0
- package/src/webgpu/render-pipelines/material/WebGpuUnlitRenderPipeline.ts +101 -0
- package/src/webgpu/sampler/WebGpuSampler.ts +84 -0
- package/src/webgpu/shader/WebGpuShaderModule.ts +65 -0
- package/src/webgpu/shader/WebGpuShaderModuleLoader.ts +38 -0
- package/src/webgpu/shader/WgslShaderContent.ts +20 -0
- package/src/webgpu/swap-chain/WebGpuSwapChain.ts +93 -0
- package/src/webgpu/texture/WebGpuTexture2D.ts +197 -0
- package/src/webgpu/texture/WebGpuTextureFactory.ts +118 -0
- package/src/webgpu/texture/WebGpuTextureView.ts +43 -0
- package/src/webgpu/utilities/WebGpuConverter.ts +299 -0
- package/src/wgsl-raw.d.ts +4 -0
- package/dist/api/FrameworkConfiguration.d.ts +0 -23
- package/dist/api/FrameworkConfiguration.d.ts.map +0 -1
- package/dist/api/IFrameworkConfiguration.d.ts +0 -25
- package/dist/api/IFrameworkConfiguration.d.ts.map +0 -1
- package/dist/api/shader/shader-loader.d.ts.map +0 -1
- package/src/api/FrameworkConfiguration.ts +0 -29
- package/src/api/IFrameworkConfiguration.ts +0 -30
- /package/src/api/shader/{shader-loader.ts → ShaderLoader.ts} +0 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal hand-written WebGPU type declarations used by the WebGPU backend.
|
|
3
|
+
*
|
|
4
|
+
* TypeScript 5.9's `lib.dom` does not ship the WebGPU API, and the project avoids adding `@webgpu/types`.
|
|
5
|
+
* The types are module-scoped (prefixed with `Gpu`) instead of global, so they never clash with `@webgpu/types`
|
|
6
|
+
* in a consumer's project. Only what the backend uses is declared.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
11
|
+
|
|
12
|
+
/** `GPUBufferUsage` flags. */
|
|
13
|
+
export const GpuBufferUsage = {
|
|
14
|
+
MAP_READ: 0x0001,
|
|
15
|
+
MAP_WRITE: 0x0002,
|
|
16
|
+
COPY_SRC: 0x0004,
|
|
17
|
+
COPY_DST: 0x0008,
|
|
18
|
+
INDEX: 0x0010,
|
|
19
|
+
VERTEX: 0x0020,
|
|
20
|
+
UNIFORM: 0x0040,
|
|
21
|
+
STORAGE: 0x0080,
|
|
22
|
+
INDIRECT: 0x0100,
|
|
23
|
+
QUERY_RESOLVE: 0x0200,
|
|
24
|
+
} as const;
|
|
25
|
+
|
|
26
|
+
/** `GPUTextureUsage` flags. */
|
|
27
|
+
export const GpuTextureUsage = {
|
|
28
|
+
COPY_SRC: 0x01,
|
|
29
|
+
COPY_DST: 0x02,
|
|
30
|
+
TEXTURE_BINDING: 0x04,
|
|
31
|
+
STORAGE_BINDING: 0x08,
|
|
32
|
+
RENDER_ATTACHMENT: 0x10,
|
|
33
|
+
} as const;
|
|
34
|
+
|
|
35
|
+
/** `GPUShaderStage` flags. */
|
|
36
|
+
export const GpuShaderStage = {
|
|
37
|
+
VERTEX: 0x1,
|
|
38
|
+
FRAGMENT: 0x2,
|
|
39
|
+
COMPUTE: 0x4,
|
|
40
|
+
} as const;
|
|
41
|
+
|
|
42
|
+
export type GpuTextureFormat = string;
|
|
43
|
+
export type GpuPowerPreference = "low-power" | "high-performance";
|
|
44
|
+
export type GpuLoadOp = "load" | "clear";
|
|
45
|
+
export type GpuStoreOp = "store" | "discard";
|
|
46
|
+
export type GpuIndexFormat = "uint16" | "uint32";
|
|
47
|
+
export type GpuPrimitiveTopology = "point-list" | "line-list" | "line-strip" | "triangle-list" | "triangle-strip";
|
|
48
|
+
export type GpuCullMode = "none" | "front" | "back";
|
|
49
|
+
export type GpuFrontFace = "ccw" | "cw";
|
|
50
|
+
export type GpuBlendFactor = "zero" | "one" | "src-alpha" | "one-minus-src-alpha" | string;
|
|
51
|
+
export type GpuBlendOperation = "add" | "subtract" | "reverse-subtract" | "min" | "max";
|
|
52
|
+
export type GpuAddressMode = "clamp-to-edge" | "repeat" | "mirror-repeat";
|
|
53
|
+
export type GpuFilterMode = "nearest" | "linear";
|
|
54
|
+
export type GpuCompareFunction = "never" | "less" | "equal" | "less-equal" | "greater" | "not-equal" | "greater-equal" | "always";
|
|
55
|
+
export type GpuVertexFormat = "float32" | "float32x2" | "float32x3" | "float32x4" | string;
|
|
56
|
+
export type GpuVertexStepMode = "vertex" | "instance";
|
|
57
|
+
|
|
58
|
+
export interface GpuObjectBase {
|
|
59
|
+
label: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface GpuAdapterInfo {
|
|
63
|
+
readonly vendor: string;
|
|
64
|
+
readonly architecture: string;
|
|
65
|
+
readonly device: string;
|
|
66
|
+
readonly description: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface GpuSupportedFeatures {
|
|
70
|
+
has(feature: string): boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface Gpu {
|
|
74
|
+
requestAdapter(options?: { powerPreference?: GpuPowerPreference }): Promise<GpuAdapter | null>;
|
|
75
|
+
getPreferredCanvasFormat(): GpuTextureFormat;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface GpuAdapter {
|
|
79
|
+
readonly features: GpuSupportedFeatures;
|
|
80
|
+
readonly info?: GpuAdapterInfo;
|
|
81
|
+
requestDevice(descriptor?: { label?: string; requiredFeatures?: string[] }): Promise<GpuDevice>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface GpuError {
|
|
85
|
+
readonly message: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface GpuDevice extends GpuObjectBase {
|
|
89
|
+
readonly features: GpuSupportedFeatures;
|
|
90
|
+
readonly queue: GpuQueue;
|
|
91
|
+
readonly lost: Promise<{ reason: string; message: string }>;
|
|
92
|
+
createBuffer(descriptor: { label?: string; size: number; usage: number; mappedAtCreation?: boolean }): GpuBuffer;
|
|
93
|
+
createTexture(descriptor: {
|
|
94
|
+
label?: string;
|
|
95
|
+
size: [number, number, number?] | { width: number; height?: number; depthOrArrayLayers?: number };
|
|
96
|
+
mipLevelCount?: number;
|
|
97
|
+
sampleCount?: number;
|
|
98
|
+
dimension?: "1d" | "2d" | "3d";
|
|
99
|
+
format: GpuTextureFormat;
|
|
100
|
+
usage: number;
|
|
101
|
+
}): GpuTexture;
|
|
102
|
+
createSampler(descriptor?: {
|
|
103
|
+
label?: string;
|
|
104
|
+
addressModeU?: GpuAddressMode;
|
|
105
|
+
addressModeV?: GpuAddressMode;
|
|
106
|
+
addressModeW?: GpuAddressMode;
|
|
107
|
+
magFilter?: GpuFilterMode;
|
|
108
|
+
minFilter?: GpuFilterMode;
|
|
109
|
+
mipmapFilter?: GpuFilterMode;
|
|
110
|
+
lodMinClamp?: number;
|
|
111
|
+
lodMaxClamp?: number;
|
|
112
|
+
compare?: GpuCompareFunction;
|
|
113
|
+
maxAnisotropy?: number;
|
|
114
|
+
}): GpuSampler;
|
|
115
|
+
createBindGroupLayout(descriptor: { label?: string; entries: GpuBindGroupLayoutEntry[] }): GpuBindGroupLayout;
|
|
116
|
+
createPipelineLayout(descriptor: { label?: string; bindGroupLayouts: GpuBindGroupLayout[] }): GpuPipelineLayout;
|
|
117
|
+
createBindGroup(descriptor: { label?: string; layout: GpuBindGroupLayout; entries: GpuBindGroupEntry[] }): GpuBindGroup;
|
|
118
|
+
createShaderModule(descriptor: { label?: string; code: string }): GpuShaderModule;
|
|
119
|
+
createRenderPipeline(descriptor: GpuRenderPipelineDescriptor): GpuRenderPipeline;
|
|
120
|
+
createCommandEncoder(descriptor?: { label?: string }): GpuCommandEncoder;
|
|
121
|
+
pushErrorScope(filter: "validation" | "out-of-memory" | "internal"): void;
|
|
122
|
+
popErrorScope(): Promise<GpuError | null>;
|
|
123
|
+
addEventListener(type: "uncapturederror", listener: (event: { error: GpuError }) => void): void;
|
|
124
|
+
destroy(): void;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface GpuQueue {
|
|
128
|
+
submit(commandBuffers: GpuCommandBuffer[]): void;
|
|
129
|
+
writeBuffer(buffer: GpuBuffer, bufferOffset: number, data: ArrayBufferLike | ArrayBufferView, dataOffset?: number, size?: number): void;
|
|
130
|
+
writeTexture(
|
|
131
|
+
destination: { texture: GpuTexture; mipLevel?: number; origin?: [number, number, number?] },
|
|
132
|
+
data: ArrayBufferView | ArrayBufferLike,
|
|
133
|
+
dataLayout: { offset?: number; bytesPerRow?: number; rowsPerImage?: number },
|
|
134
|
+
size: [number, number, number?] | { width: number; height?: number; depthOrArrayLayers?: number }): void;
|
|
135
|
+
copyExternalImageToTexture(
|
|
136
|
+
source: { source: any; flipY?: boolean },
|
|
137
|
+
destination: { texture: GpuTexture; mipLevel?: number; premultipliedAlpha?: boolean },
|
|
138
|
+
copySize: [number, number, number?] | { width: number; height?: number; depthOrArrayLayers?: number }): void;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface GpuBuffer extends GpuObjectBase {
|
|
142
|
+
readonly size: number;
|
|
143
|
+
destroy(): void;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface GpuTexture extends GpuObjectBase {
|
|
147
|
+
readonly width: number;
|
|
148
|
+
readonly height: number;
|
|
149
|
+
readonly format: GpuTextureFormat;
|
|
150
|
+
createView(descriptor?: { label?: string; format?: GpuTextureFormat; dimension?: string }): GpuTextureView;
|
|
151
|
+
destroy(): void;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface GpuTextureView extends GpuObjectBase {
|
|
155
|
+
readonly __brand?: "GPUTextureView";
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface GpuSampler extends GpuObjectBase {
|
|
159
|
+
readonly __brand?: "GPUSampler";
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface GpuBindGroupLayout extends GpuObjectBase {
|
|
163
|
+
readonly __brand?: "GPUBindGroupLayout";
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface GpuPipelineLayout extends GpuObjectBase {
|
|
167
|
+
readonly __brand?: "GPUPipelineLayout";
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface GpuBindGroup extends GpuObjectBase {
|
|
171
|
+
readonly __brand?: "GPUBindGroup";
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface GpuShaderModule extends GpuObjectBase {
|
|
175
|
+
getCompilationInfo?(): Promise<{ messages: readonly { type: string; message: string; lineNum: number; linePos: number }[] }>;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface GpuRenderPipeline extends GpuObjectBase {
|
|
179
|
+
readonly __brand?: "GPURenderPipeline";
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface GpuCommandBuffer extends GpuObjectBase {
|
|
183
|
+
readonly __brand?: "GPUCommandBuffer";
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export interface GpuBindGroupLayoutEntry {
|
|
187
|
+
binding: number;
|
|
188
|
+
visibility: number;
|
|
189
|
+
buffer?: { type?: "uniform" | "storage" | "read-only-storage"; hasDynamicOffset?: boolean; minBindingSize?: number };
|
|
190
|
+
sampler?: { type?: "filtering" | "non-filtering" | "comparison" };
|
|
191
|
+
texture?: { sampleType?: "float" | "unfilterable-float" | "depth" | "sint" | "uint"; viewDimension?: string; multisampled?: boolean };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface GpuBindGroupEntry {
|
|
195
|
+
binding: number;
|
|
196
|
+
resource: GpuSampler | GpuTextureView | { buffer: GpuBuffer; offset?: number; size?: number };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface GpuVertexBufferLayout {
|
|
200
|
+
arrayStride: number;
|
|
201
|
+
stepMode?: GpuVertexStepMode;
|
|
202
|
+
attributes: { format: GpuVertexFormat; offset: number; shaderLocation: number }[];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface GpuBlendComponent {
|
|
206
|
+
operation?: GpuBlendOperation;
|
|
207
|
+
srcFactor?: GpuBlendFactor;
|
|
208
|
+
dstFactor?: GpuBlendFactor;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface GpuColorTargetState {
|
|
212
|
+
format: GpuTextureFormat;
|
|
213
|
+
blend?: { color: GpuBlendComponent; alpha: GpuBlendComponent };
|
|
214
|
+
writeMask?: number;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface GpuDepthStencilState {
|
|
218
|
+
format: GpuTextureFormat;
|
|
219
|
+
depthWriteEnabled?: boolean;
|
|
220
|
+
depthCompare?: GpuCompareFunction;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export interface GpuRenderPipelineDescriptor {
|
|
224
|
+
label?: string;
|
|
225
|
+
layout: GpuPipelineLayout | "auto";
|
|
226
|
+
vertex: { module: GpuShaderModule; entryPoint?: string; buffers?: GpuVertexBufferLayout[] };
|
|
227
|
+
fragment?: { module: GpuShaderModule; entryPoint?: string; targets: GpuColorTargetState[] };
|
|
228
|
+
primitive?: { topology?: GpuPrimitiveTopology; cullMode?: GpuCullMode; frontFace?: GpuFrontFace; stripIndexFormat?: GpuIndexFormat };
|
|
229
|
+
depthStencil?: GpuDepthStencilState;
|
|
230
|
+
multisample?: { count?: number };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export interface GpuRenderPassColorAttachment {
|
|
234
|
+
view: GpuTextureView;
|
|
235
|
+
resolveTarget?: GpuTextureView;
|
|
236
|
+
clearValue?: { r: number; g: number; b: number; a: number };
|
|
237
|
+
loadOp: GpuLoadOp;
|
|
238
|
+
storeOp: GpuStoreOp;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export interface GpuRenderPassDepthStencilAttachment {
|
|
242
|
+
view: GpuTextureView;
|
|
243
|
+
depthClearValue?: number;
|
|
244
|
+
depthLoadOp?: GpuLoadOp;
|
|
245
|
+
depthStoreOp?: GpuStoreOp;
|
|
246
|
+
stencilClearValue?: number;
|
|
247
|
+
stencilLoadOp?: GpuLoadOp;
|
|
248
|
+
stencilStoreOp?: GpuStoreOp;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export interface GpuRenderPassDescriptor {
|
|
252
|
+
label?: string;
|
|
253
|
+
colorAttachments: GpuRenderPassColorAttachment[];
|
|
254
|
+
depthStencilAttachment?: GpuRenderPassDepthStencilAttachment;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface GpuCommandEncoder extends GpuObjectBase {
|
|
258
|
+
beginRenderPass(descriptor: GpuRenderPassDescriptor): GpuRenderPassEncoder;
|
|
259
|
+
finish(descriptor?: { label?: string }): GpuCommandBuffer;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export interface GpuRenderPassEncoder extends GpuObjectBase {
|
|
263
|
+
setPipeline(pipeline: GpuRenderPipeline): void;
|
|
264
|
+
setVertexBuffer(slot: number, buffer: GpuBuffer, offset?: number, size?: number): void;
|
|
265
|
+
setIndexBuffer(buffer: GpuBuffer, format: GpuIndexFormat, offset?: number, size?: number): void;
|
|
266
|
+
setBindGroup(index: number, bindGroup: GpuBindGroup): void;
|
|
267
|
+
drawIndexed(indexCount: number, instanceCount?: number, firstIndex?: number, baseVertex?: number, firstInstance?: number): void;
|
|
268
|
+
draw(vertexCount: number, instanceCount?: number, firstVertex?: number, firstInstance?: number): void;
|
|
269
|
+
pushDebugGroup(label: string): void;
|
|
270
|
+
popDebugGroup(): void;
|
|
271
|
+
end(): void;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export interface GpuCanvasContext {
|
|
275
|
+
configure(configuration: { device: GpuDevice; format: GpuTextureFormat; usage?: number; alphaMode?: "opaque" | "premultiplied" }): void;
|
|
276
|
+
unconfigure(): void;
|
|
277
|
+
getCurrentTexture(): GpuTexture;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Returns `navigator.gpu`, or undefined when the browser has no WebGPU.
|
|
282
|
+
*/
|
|
283
|
+
export function getNavigatorGpu(): Gpu | undefined {
|
|
284
|
+
if (typeof navigator === "undefined") {
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
return (navigator as unknown as { gpu?: Gpu }).gpu ?? undefined;
|
|
288
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type {BlendStateDescriptor} from "../../core/rendering/blending/blend-state-descriptor.ts";
|
|
2
|
+
import type {IBlendState} from "../../api/index.ts";
|
|
3
|
+
import type {GpuBlendComponent} from "../WebGpuTypes.ts";
|
|
4
|
+
import {WebGpuConverter} from "../utilities/WebGpuConverter.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The WebGPU blend state. WebGPU bakes blending into the render pipeline, so this only holds the converted values.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export class WebGpuBlendState implements IBlendState {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The constructor.
|
|
14
|
+
* @param descriptor The blend state descriptor.
|
|
15
|
+
*/
|
|
16
|
+
public constructor(descriptor: BlendStateDescriptor) {
|
|
17
|
+
this.blendingEnabled = descriptor.blendingEnabled;
|
|
18
|
+
this.color = {
|
|
19
|
+
srcFactor: WebGpuConverter.convertBlendFactor(descriptor.color.srcFactor),
|
|
20
|
+
dstFactor: WebGpuConverter.convertBlendFactor(descriptor.color.dstFactor),
|
|
21
|
+
operation: WebGpuConverter.convertBlendOperation(descriptor.color.operation),
|
|
22
|
+
};
|
|
23
|
+
this.alpha = {
|
|
24
|
+
srcFactor: WebGpuConverter.convertBlendFactor(descriptor.alpha.srcFactor),
|
|
25
|
+
dstFactor: WebGpuConverter.convertBlendFactor(descriptor.alpha.dstFactor),
|
|
26
|
+
operation: WebGpuConverter.convertBlendOperation(descriptor.alpha.operation),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Whether blending is enabled. */
|
|
31
|
+
public readonly blendingEnabled: boolean;
|
|
32
|
+
|
|
33
|
+
/** The color blend component. */
|
|
34
|
+
public readonly color: GpuBlendComponent;
|
|
35
|
+
|
|
36
|
+
/** The alpha blend component. */
|
|
37
|
+
public readonly alpha: GpuBlendComponent;
|
|
38
|
+
|
|
39
|
+
/** The `GPUBlendState` for a color target, or undefined when blending is disabled. */
|
|
40
|
+
public get gpuBlendState(): { color: GpuBlendComponent; alpha: GpuBlendComponent } | undefined {
|
|
41
|
+
return this.blendingEnabled ? {color: this.color, alpha: this.alpha} : undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** @inheritDoc */
|
|
45
|
+
public get nativePtr(): any {
|
|
46
|
+
return this.gpuBlendState;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @inheritDoc */
|
|
50
|
+
public dispose(): void {
|
|
51
|
+
// Nothing to release.
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BufferUsage,
|
|
3
|
+
type IBufferFactory,
|
|
4
|
+
type IFramework,
|
|
5
|
+
type IIndexBuffer,
|
|
6
|
+
type IUniformBuffer,
|
|
7
|
+
type IVertexBuffer,
|
|
8
|
+
} from "../../api/index.ts";
|
|
9
|
+
import {WebGpuVertexBuffer} from "./WebGpuVertexBuffer.ts";
|
|
10
|
+
import {WebGpuIndexBuffer} from "./WebGpuIndexBuffer.ts";
|
|
11
|
+
import {WebGpuUniformBuffer} from "./WebGpuUniformBuffer.ts";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The WebGPU buffers factory.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export class WebGpuBuffersFactory implements IBufferFactory {
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The constructor.
|
|
21
|
+
* @param _framework The framework.
|
|
22
|
+
*/
|
|
23
|
+
public constructor(private readonly _framework: IFramework) {
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @inheritDoc */
|
|
27
|
+
public createVertexBuffer(data: ArrayLike<number>, vertexStride: number, usage: BufferUsage = BufferUsage.VERTEX | BufferUsage.COPY_DST, label?: string): IVertexBuffer {
|
|
28
|
+
const buffer = new WebGpuVertexBuffer(this._framework, data, vertexStride, usage, label);
|
|
29
|
+
buffer.initialize();
|
|
30
|
+
return buffer;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** @inheritDoc */
|
|
34
|
+
public createUniformBuffer(data: ArrayLike<number>, usage: BufferUsage = BufferUsage.UNIFORM | BufferUsage.COPY_DST, label?: string): IUniformBuffer {
|
|
35
|
+
const buffer = new WebGpuUniformBuffer(this._framework, data, usage, label);
|
|
36
|
+
buffer.initialize();
|
|
37
|
+
return buffer;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** @inheritDoc */
|
|
41
|
+
public createIndexBuffer(data: ArrayLike<number>, label?: string): IIndexBuffer {
|
|
42
|
+
const buffer = new WebGpuIndexBuffer(this._framework, label);
|
|
43
|
+
buffer.initialize(data);
|
|
44
|
+
return buffer;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import {BufferUsage, type IFramework, type IIndexBuffer, IndexBufferType} from "../../api/index.ts";
|
|
2
|
+
import type {WebGpuGraphicsDevice} from "../WebGpuGraphicsDevice.ts";
|
|
3
|
+
import {GpuBufferUsage, type GpuBuffer, type GpuIndexFormat} from "../WebGpuTypes.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The WebGPU index buffer. Uses uint16 when every index fits, otherwise uint32.
|
|
7
|
+
* The allocation and the write are padded to 4 bytes, because WebGPU requires it (odd uint16 counts).
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export class WebGpuIndexBuffer implements IIndexBuffer {
|
|
11
|
+
|
|
12
|
+
private readonly _graphicsDevice: WebGpuGraphicsDevice;
|
|
13
|
+
private readonly _label?: string;
|
|
14
|
+
private _type = IndexBufferType.UINT_16;
|
|
15
|
+
private _elementByteSize = 0;
|
|
16
|
+
private _indicesCount = 0;
|
|
17
|
+
private _byteSize = 0;
|
|
18
|
+
private _gpuBuffer: GpuBuffer | null = null;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The constructor.
|
|
22
|
+
* @param framework The framework.
|
|
23
|
+
* @param label The label.
|
|
24
|
+
*/
|
|
25
|
+
public constructor(framework: IFramework, label?: string) {
|
|
26
|
+
this._graphicsDevice = framework.renderer.graphicsDevice as WebGpuGraphicsDevice;
|
|
27
|
+
this._label = label;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @inheritDoc */
|
|
31
|
+
public readonly usage: BufferUsage = BufferUsage.INDEX;
|
|
32
|
+
|
|
33
|
+
/** The WebGPU buffer. */
|
|
34
|
+
public get gpuBuffer(): GpuBuffer {
|
|
35
|
+
if (!this._gpuBuffer) {
|
|
36
|
+
throw new Error("WebGpuIndexBuffer: the buffer is not initialized or is disposed.");
|
|
37
|
+
}
|
|
38
|
+
return this._gpuBuffer;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The WebGPU index format. */
|
|
42
|
+
public get gpuIndexFormat(): GpuIndexFormat {
|
|
43
|
+
return this._type === IndexBufferType.UINT_16 ? "uint16" : "uint32";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The buffer size padded to 4 bytes, as used for `setIndexBuffer`. */
|
|
47
|
+
public get paddedByteSize(): number {
|
|
48
|
+
return (this._byteSize + 3) & ~3;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** @inheritDoc */
|
|
52
|
+
public get type(): IndexBufferType {
|
|
53
|
+
return this._type;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @inheritDoc */
|
|
57
|
+
public get elementByteSize(): number {
|
|
58
|
+
return this._elementByteSize;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @inheritDoc */
|
|
62
|
+
public get label(): string {
|
|
63
|
+
return this._label ?? "";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @inheritDoc */
|
|
67
|
+
public get indicesCount(): number {
|
|
68
|
+
return this._indicesCount;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @inheritDoc */
|
|
72
|
+
public get byteSize(): number {
|
|
73
|
+
return this._byteSize;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private static _canUseUint16(values: ArrayLike<number>): boolean {
|
|
77
|
+
for (let i = 0; i < values.length; i++) {
|
|
78
|
+
const v = values[i];
|
|
79
|
+
if (v < 0 || v > 0xFFFF) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** @inheritDoc */
|
|
87
|
+
public initialize(data: ArrayLike<number>): void {
|
|
88
|
+
this._gpuBuffer?.destroy();
|
|
89
|
+
const use16 = WebGpuIndexBuffer._canUseUint16(data);
|
|
90
|
+
this._type = use16 ? IndexBufferType.UINT_16 : IndexBufferType.UINT_32;
|
|
91
|
+
this._elementByteSize = use16 ? 2 : 4;
|
|
92
|
+
this._indicesCount = data.length;
|
|
93
|
+
this._byteSize = this._indicesCount * this._elementByteSize;
|
|
94
|
+
|
|
95
|
+
const padded = Math.max(4, this.paddedByteSize);
|
|
96
|
+
// Allocate the padded size so the write below can include the padding.
|
|
97
|
+
const bytes = new ArrayBuffer(padded);
|
|
98
|
+
if (use16) {
|
|
99
|
+
new Uint16Array(bytes, 0, data.length).set(data);
|
|
100
|
+
} else {
|
|
101
|
+
new Uint32Array(bytes, 0, data.length).set(data);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const device = this._graphicsDevice.device;
|
|
105
|
+
this._gpuBuffer = device.createBuffer({
|
|
106
|
+
label: this._label,
|
|
107
|
+
size: padded,
|
|
108
|
+
usage: GpuBufferUsage.INDEX | GpuBufferUsage.COPY_DST,
|
|
109
|
+
});
|
|
110
|
+
device.queue.writeBuffer(this._gpuBuffer, 0, bytes, 0, padded);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** @inheritDoc */
|
|
114
|
+
public dispose(): void {
|
|
115
|
+
this._gpuBuffer?.destroy();
|
|
116
|
+
this._gpuBuffer = null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {type BufferUsage, type IFramework, type IUniformBuffer} from "../../api/index.ts";
|
|
2
|
+
import type {WebGpuGraphicsDevice} from "../WebGpuGraphicsDevice.ts";
|
|
3
|
+
import {GpuBufferUsage, type GpuBuffer} from "../WebGpuTypes.ts";
|
|
4
|
+
import {WebGpuConverter} from "../utilities/WebGpuConverter.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The WebGPU uniform buffer. The size is aligned to 16 bytes and the buffer always has UNIFORM | COPY_DST.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export class WebGpuUniformBuffer implements IUniformBuffer {
|
|
11
|
+
|
|
12
|
+
private static _nextId = 1;
|
|
13
|
+
|
|
14
|
+
private readonly _graphicsDevice: WebGpuGraphicsDevice;
|
|
15
|
+
private readonly _data: Float32Array;
|
|
16
|
+
private readonly _byteSize: number;
|
|
17
|
+
private _gpuBuffer: GpuBuffer | null = null;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The constructor.
|
|
21
|
+
* @param framework The framework.
|
|
22
|
+
* @param dataOrFloatCount The initial float data, or the number of floats.
|
|
23
|
+
* @param bufferUsage The buffer usage.
|
|
24
|
+
* @param label The label.
|
|
25
|
+
*/
|
|
26
|
+
public constructor(framework: IFramework, dataOrFloatCount: ArrayLike<number> | number, bufferUsage: BufferUsage, label?: string) {
|
|
27
|
+
this._graphicsDevice = framework.renderer.graphicsDevice as WebGpuGraphicsDevice;
|
|
28
|
+
this.usage = bufferUsage;
|
|
29
|
+
this.label = label;
|
|
30
|
+
this.id = WebGpuUniformBuffer._nextId++;
|
|
31
|
+
const floatCount = typeof dataOrFloatCount === "number" ? dataOrFloatCount : dataOrFloatCount.length;
|
|
32
|
+
// Uniform buffer bindings must be a multiple of 16 bytes.
|
|
33
|
+
const alignedFloats = Math.max(4, Math.ceil(floatCount / 4) * 4);
|
|
34
|
+
this._data = new Float32Array(alignedFloats);
|
|
35
|
+
if (typeof dataOrFloatCount !== "number") {
|
|
36
|
+
this._data.set(dataOrFloatCount);
|
|
37
|
+
}
|
|
38
|
+
this._byteSize = this._data.byteLength;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A unique id, used to cache bind groups. */
|
|
42
|
+
public readonly id: number;
|
|
43
|
+
|
|
44
|
+
/** @inheritDoc */
|
|
45
|
+
public readonly label?: string;
|
|
46
|
+
|
|
47
|
+
/** @inheritDoc */
|
|
48
|
+
public readonly usage: BufferUsage;
|
|
49
|
+
|
|
50
|
+
/** @inheritDoc */
|
|
51
|
+
public get byteSize(): number {
|
|
52
|
+
return this._byteSize;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The WebGPU buffer. */
|
|
56
|
+
public get gpuBuffer(): GpuBuffer {
|
|
57
|
+
if (!this._gpuBuffer) {
|
|
58
|
+
throw new Error("WebGpuUniformBuffer: the buffer is not initialized or is disposed.");
|
|
59
|
+
}
|
|
60
|
+
return this._gpuBuffer;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** @inheritDoc */
|
|
64
|
+
public initialize(): void {
|
|
65
|
+
const device = this._graphicsDevice.device;
|
|
66
|
+
this._gpuBuffer = device.createBuffer({
|
|
67
|
+
label: this.label,
|
|
68
|
+
size: this._byteSize,
|
|
69
|
+
usage: WebGpuConverter.convertBufferUsage(this.usage) | GpuBufferUsage.UNIFORM | GpuBufferUsage.COPY_DST,
|
|
70
|
+
});
|
|
71
|
+
device.queue.writeBuffer(this._gpuBuffer, 0, this._data.buffer, this._data.byteOffset, this._data.byteLength);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Updates the buffer. Only the data's length is written.
|
|
76
|
+
* @param data The float data.
|
|
77
|
+
* @param offset The first float to write.
|
|
78
|
+
* @param length The number of floats to write; defaults to the data's length after the offset.
|
|
79
|
+
*/
|
|
80
|
+
public update(data: ArrayLike<number>, offset: number = 0, length?: number): void {
|
|
81
|
+
let count = length ?? data.length - offset;
|
|
82
|
+
count = Math.min(count, this._data.length - offset, data.length - offset);
|
|
83
|
+
if (count <= 0) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
for (let i = 0; i < count; i++) {
|
|
87
|
+
this._data[offset + i] = data[offset + i];
|
|
88
|
+
}
|
|
89
|
+
this._graphicsDevice.device.queue.writeBuffer(
|
|
90
|
+
this.gpuBuffer,
|
|
91
|
+
offset * Float32Array.BYTES_PER_ELEMENT,
|
|
92
|
+
this._data.buffer,
|
|
93
|
+
this._data.byteOffset + offset * Float32Array.BYTES_PER_ELEMENT,
|
|
94
|
+
count * Float32Array.BYTES_PER_ELEMENT);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** @inheritDoc */
|
|
98
|
+
public dispose(): void {
|
|
99
|
+
this._gpuBuffer?.destroy();
|
|
100
|
+
this._gpuBuffer = null;
|
|
101
|
+
}
|
|
102
|
+
}
|