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,249 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type IFramework,
|
|
3
|
+
type IIndexBuffer,
|
|
4
|
+
type IPrimitiveState,
|
|
5
|
+
type ISampler,
|
|
6
|
+
type ITexture2D,
|
|
7
|
+
type IUniformBuffer,
|
|
8
|
+
type IVertexBuffer,
|
|
9
|
+
State,
|
|
10
|
+
} from "../../../api/index.ts";
|
|
11
|
+
import {AWebGpuRenderPipeline} from "../AWebGpuRenderPipeline.ts";
|
|
12
|
+
import {WebGpuTexture2D} from "../../texture/WebGpuTexture2D.ts";
|
|
13
|
+
import type {WebGpuSampler} from "../../sampler/WebGpuSampler.ts";
|
|
14
|
+
import type {WebGpuUniformBuffer} from "../../buffers/WebGpuUniformBuffer.ts";
|
|
15
|
+
import type {WebGpuVertexBuffer} from "../../buffers/WebGpuVertexBuffer.ts";
|
|
16
|
+
import type {WebGpuIndexBuffer} from "../../buffers/WebGpuIndexBuffer.ts";
|
|
17
|
+
import type {WebGpuShaderModule} from "../../shader/WebGpuShaderModule.ts";
|
|
18
|
+
import {
|
|
19
|
+
GpuShaderStage,
|
|
20
|
+
type GpuBindGroup,
|
|
21
|
+
type GpuBindGroupLayout,
|
|
22
|
+
type GpuBuffer,
|
|
23
|
+
} from "../../WebGpuTypes.ts";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* One uniform buffer binding of a uniform bind group.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export interface IWebGpuUniformBinding {
|
|
30
|
+
/** The WGSL `@binding`. */
|
|
31
|
+
binding: number;
|
|
32
|
+
/** The shader stages that read it. */
|
|
33
|
+
visibility: number;
|
|
34
|
+
/** Returns the current buffer. */
|
|
35
|
+
buffer: () => IUniformBuffer;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A uniform-buffer-only bind group. The bind group is rebuilt when any of its buffers change (dirty check).
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
export interface IWebGpuUniformGroup {
|
|
43
|
+
/** The WGSL `@group`. */
|
|
44
|
+
group: number;
|
|
45
|
+
/** The bindings. */
|
|
46
|
+
bindings: IWebGpuUniformBinding[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface UniformGroupState {
|
|
50
|
+
descriptor: IWebGpuUniformGroup;
|
|
51
|
+
layout: GpuBindGroupLayout;
|
|
52
|
+
bindGroup: GpuBindGroup | null;
|
|
53
|
+
lastBuffers: GpuBuffer[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The base of WebGPU mesh pipelines, like the C# `AWebGPUMeshRenderPipeline`:
|
|
58
|
+
* uniform groups with dirty checks, plus one texture + sampler group cached per texture and sampler id.
|
|
59
|
+
* A 1x1 white texture is used when no texture is set.
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
export abstract class AWebGpuMeshRenderPipeline extends AWebGpuRenderPipeline {
|
|
63
|
+
|
|
64
|
+
private _uniformGroups: UniformGroupState[] = [];
|
|
65
|
+
private _textureGroupIndex = 1;
|
|
66
|
+
private _textureGroupLayout: GpuBindGroupLayout = null!;
|
|
67
|
+
private readonly _textureBindGroups = new Map<string, GpuBindGroup>();
|
|
68
|
+
private readonly _watchedTextures = new Set<ITexture2D>();
|
|
69
|
+
private readonly _onTextureDisposed = (texture: ITexture2D) => this._forgetTexture(texture);
|
|
70
|
+
|
|
71
|
+
protected _texture: WebGpuTexture2D | null = null;
|
|
72
|
+
protected _sampler?: WebGpuSampler;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The constructor.
|
|
76
|
+
* @param framework The framework.
|
|
77
|
+
* @param primitiveState The optional primitive state.
|
|
78
|
+
*/
|
|
79
|
+
protected constructor(framework: IFramework, primitiveState?: IPrimitiveState) {
|
|
80
|
+
super(framework, primitiveState);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The shader id to load. */
|
|
84
|
+
protected abstract readonly _shaderId: string;
|
|
85
|
+
|
|
86
|
+
/** The uniform groups. */
|
|
87
|
+
protected abstract _describeUniformGroups(): IWebGpuUniformGroup[];
|
|
88
|
+
|
|
89
|
+
/** The group index used for texture + sampler. */
|
|
90
|
+
protected get _textureGroup(): number {
|
|
91
|
+
return 1;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** @inheritDoc */
|
|
95
|
+
public get diffuseTexture(): ITexture2D {
|
|
96
|
+
return this._texture ?? WebGpuTexture2D.getOrCreateDefault(this._framework);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** @inheritDoc */
|
|
100
|
+
public set diffuseTexture(value: ITexture2D) {
|
|
101
|
+
this._texture = (value as WebGpuTexture2D) ?? null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** @inheritDoc */
|
|
105
|
+
public get diffuseTextureSampler(): ISampler | undefined {
|
|
106
|
+
return this._sampler;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** @inheritDoc */
|
|
110
|
+
public set diffuseTextureSampler(value: ISampler | undefined) {
|
|
111
|
+
this._sampler = value as WebGpuSampler | undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** @inheritDoc */
|
|
115
|
+
public initialize(): void {
|
|
116
|
+
const device = this._graphicsDevice.device;
|
|
117
|
+
const module = this._framework.content.loadShaderModule(this._shaderId) as WebGpuShaderModule;
|
|
118
|
+
|
|
119
|
+
this._textureGroupIndex = this._textureGroup;
|
|
120
|
+
this._textureGroupLayout = device.createBindGroupLayout({
|
|
121
|
+
label: `${this._shaderId} texture group layout`,
|
|
122
|
+
entries: [
|
|
123
|
+
{binding: 0, visibility: GpuShaderStage.FRAGMENT, texture: {sampleType: "float"}},
|
|
124
|
+
{binding: 1, visibility: GpuShaderStage.FRAGMENT, sampler: {type: "filtering"}},
|
|
125
|
+
],
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
this._uniformGroups = this._describeUniformGroups().map(descriptor => ({
|
|
129
|
+
descriptor,
|
|
130
|
+
layout: device.createBindGroupLayout({
|
|
131
|
+
label: `${this._shaderId} group ${descriptor.group} layout`,
|
|
132
|
+
entries: descriptor.bindings.map(b => ({binding: b.binding, visibility: b.visibility, buffer: {type: "uniform"}})),
|
|
133
|
+
}),
|
|
134
|
+
bindGroup: null,
|
|
135
|
+
lastBuffers: [],
|
|
136
|
+
}));
|
|
137
|
+
|
|
138
|
+
const groupCount = Math.max(this._textureGroupIndex, ...this._uniformGroups.map(g => g.descriptor.group)) + 1;
|
|
139
|
+
const layouts: GpuBindGroupLayout[] = [];
|
|
140
|
+
for (let i = 0; i < groupCount; i++) {
|
|
141
|
+
const layout = i === this._textureGroupIndex
|
|
142
|
+
? this._textureGroupLayout
|
|
143
|
+
: this._uniformGroups.find(g => g.descriptor.group === i)?.layout;
|
|
144
|
+
if (!layout) {
|
|
145
|
+
throw new Error(`${this._shaderId}: bind group ${i} has no layout.`);
|
|
146
|
+
}
|
|
147
|
+
layouts.push(layout);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const renderer = this._framework.renderer;
|
|
151
|
+
this._createGpuPipeline(
|
|
152
|
+
`${this._shaderId} pipeline`,
|
|
153
|
+
module.gpuShaderModule,
|
|
154
|
+
layouts,
|
|
155
|
+
renderer.preferredTextureFormat,
|
|
156
|
+
renderer.preferredDepthStencilFormat);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private _getUniformBindGroup(state: UniformGroupState): GpuBindGroup {
|
|
160
|
+
const buffers = state.descriptor.bindings.map(b => (b.buffer() as WebGpuUniformBuffer).gpuBuffer);
|
|
161
|
+
const dirty = !state.bindGroup
|
|
162
|
+
|| buffers.length !== state.lastBuffers.length
|
|
163
|
+
|| buffers.some((buffer, i) => buffer !== state.lastBuffers[i]);
|
|
164
|
+
if (dirty) {
|
|
165
|
+
state.bindGroup = this._graphicsDevice.device.createBindGroup({
|
|
166
|
+
label: `${this._shaderId} group ${state.descriptor.group}`,
|
|
167
|
+
layout: state.layout,
|
|
168
|
+
entries: state.descriptor.bindings.map((b, i) => ({
|
|
169
|
+
binding: b.binding,
|
|
170
|
+
resource: {buffer: buffers[i], offset: 0, size: buffers[i].size},
|
|
171
|
+
})),
|
|
172
|
+
});
|
|
173
|
+
state.lastBuffers = buffers;
|
|
174
|
+
}
|
|
175
|
+
return state.bindGroup!;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private _getTextureBindGroup(): GpuBindGroup {
|
|
179
|
+
const texture = (this._texture && this._texture.textureState !== State.DISPOSED)
|
|
180
|
+
? this._texture
|
|
181
|
+
: WebGpuTexture2D.getOrCreateDefault(this._framework);
|
|
182
|
+
const sampler = this._sampler ?? this._defaultTextureSampler;
|
|
183
|
+
const key = `${texture.id}:${sampler.id}`;
|
|
184
|
+
let bindGroup = this._textureBindGroups.get(key);
|
|
185
|
+
if (!bindGroup) {
|
|
186
|
+
bindGroup = this._graphicsDevice.device.createBindGroup({
|
|
187
|
+
label: `${this._shaderId} texture group ${key}`,
|
|
188
|
+
layout: this._textureGroupLayout,
|
|
189
|
+
entries: [
|
|
190
|
+
{binding: 0, resource: texture.gpuDefaultView},
|
|
191
|
+
{binding: 1, resource: sampler.gpuSampler},
|
|
192
|
+
],
|
|
193
|
+
});
|
|
194
|
+
this._textureBindGroups.set(key, bindGroup);
|
|
195
|
+
if (!this._watchedTextures.has(texture)) {
|
|
196
|
+
this._watchedTextures.add(texture);
|
|
197
|
+
texture.addOnDisposedListener(this._onTextureDisposed);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return bindGroup;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private _forgetTexture(texture: ITexture2D): void {
|
|
204
|
+
const prefix = `${texture.id}:`;
|
|
205
|
+
for (const key of [...this._textureBindGroups.keys()]) {
|
|
206
|
+
if (key.startsWith(prefix)) {
|
|
207
|
+
this._textureBindGroups.delete(key);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
this._watchedTextures.delete(texture);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** @inheritDoc */
|
|
214
|
+
public render(vertexBuffer: IVertexBuffer, indexBuffer: IIndexBuffer, indicesCount: number = -1, indicesOffset: number = 0): void {
|
|
215
|
+
if (indicesCount == 0 || !this._gpuPipeline) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const vb = vertexBuffer as WebGpuVertexBuffer;
|
|
219
|
+
const ib = indexBuffer as WebGpuIndexBuffer;
|
|
220
|
+
const encoder = this._graphicsDevice.renderPassEncoder;
|
|
221
|
+
|
|
222
|
+
encoder.setPipeline(this._gpuPipeline);
|
|
223
|
+
encoder.setVertexBuffer(0, vb.gpuBuffer, 0, vb.byteSize);
|
|
224
|
+
// The index buffer was allocated padded to 4 bytes; bind the padded size.
|
|
225
|
+
encoder.setIndexBuffer(ib.gpuBuffer, ib.gpuIndexFormat, 0, ib.paddedByteSize);
|
|
226
|
+
|
|
227
|
+
for (const state of this._uniformGroups) {
|
|
228
|
+
encoder.setBindGroup(state.descriptor.group, this._getUniformBindGroup(state));
|
|
229
|
+
}
|
|
230
|
+
encoder.setBindGroup(this._textureGroupIndex, this._getTextureBindGroup());
|
|
231
|
+
|
|
232
|
+
// Range draws: firstIndex is the index offset, count defaults to the rest of the buffer.
|
|
233
|
+
const count = indicesCount < 0 ? ib.indicesCount - indicesOffset : indicesCount;
|
|
234
|
+
encoder.drawIndexed(count, 1, indicesOffset);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** @inheritDoc */
|
|
238
|
+
public override dispose(): void {
|
|
239
|
+
for (const texture of this._watchedTextures) {
|
|
240
|
+
texture.removeOnDisposedListener(this._onTextureDisposed);
|
|
241
|
+
}
|
|
242
|
+
this._watchedTextures.clear();
|
|
243
|
+
this._textureBindGroups.clear();
|
|
244
|
+
for (const state of this._uniformGroups) {
|
|
245
|
+
state.bindGroup = null;
|
|
246
|
+
}
|
|
247
|
+
super.dispose();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GeometryFormat,
|
|
3
|
+
type IFramework,
|
|
4
|
+
type IPrimitiveState,
|
|
5
|
+
type IUniformBuffer,
|
|
6
|
+
type IUnlitRenderPipeline,
|
|
7
|
+
} from "../../../api/index.ts";
|
|
8
|
+
import {VertexBufferLayout} from "../../../core/rendering/vertex-buffer-layout.ts";
|
|
9
|
+
import {AWebGpuMeshRenderPipeline, type IWebGpuUniformGroup} from "./AWebGpuMeshRenderPipeline.ts";
|
|
10
|
+
import {GpuShaderStage} from "../../WebGpuTypes.ts";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The WebGPU unlit pipeline (`unlit_material.wgsl`).
|
|
14
|
+
* Group 0: projection-view (0), model (1). Group 1: texture (0), sampler (1). Group 2: material (2).
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export class WebGpuUnlitRenderPipeline extends AWebGpuMeshRenderPipeline implements IUnlitRenderPipeline {
|
|
18
|
+
|
|
19
|
+
private _projectionViewBuffer: IUniformBuffer;
|
|
20
|
+
private _modelBuffer: IUniformBuffer;
|
|
21
|
+
private _materialBuffer: IUniformBuffer;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The constructor.
|
|
25
|
+
* @param framework The framework.
|
|
26
|
+
* @param projectionViewBuffer The projection-view buffer.
|
|
27
|
+
* @param modelBuffer The model buffer.
|
|
28
|
+
* @param materialBuffer The material buffer.
|
|
29
|
+
* @param primitiveState The optional primitive state.
|
|
30
|
+
*/
|
|
31
|
+
public constructor(framework: IFramework,
|
|
32
|
+
projectionViewBuffer: IUniformBuffer,
|
|
33
|
+
modelBuffer: IUniformBuffer,
|
|
34
|
+
materialBuffer: IUniformBuffer,
|
|
35
|
+
primitiveState?: IPrimitiveState) {
|
|
36
|
+
if (!modelBuffer) {
|
|
37
|
+
throw new Error("WebGpuUnlitRenderPipeline: modelBuffer is required (the mesh's model buffer, mat4).");
|
|
38
|
+
}
|
|
39
|
+
super(framework, primitiveState);
|
|
40
|
+
this._projectionViewBuffer = projectionViewBuffer;
|
|
41
|
+
this._modelBuffer = modelBuffer;
|
|
42
|
+
this._materialBuffer = materialBuffer;
|
|
43
|
+
this.vertexBufferLayouts = [VertexBufferLayout.createFloat3Float4Float2Layout()];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @inheritDoc */
|
|
47
|
+
public readonly geometryFormat = GeometryFormat.POS3_COLOR4_TEXTURECOORDS2;
|
|
48
|
+
|
|
49
|
+
/** @inheritDoc */
|
|
50
|
+
protected readonly _shaderId = "unlit_material";
|
|
51
|
+
|
|
52
|
+
/** @inheritDoc */
|
|
53
|
+
protected _describeUniformGroups(): IWebGpuUniformGroup[] {
|
|
54
|
+
return [
|
|
55
|
+
{
|
|
56
|
+
group: 0, bindings: [
|
|
57
|
+
{binding: 0, visibility: GpuShaderStage.VERTEX, buffer: () => this._projectionViewBuffer},
|
|
58
|
+
{binding: 1, visibility: GpuShaderStage.VERTEX, buffer: () => this._modelBuffer},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
group: 2, bindings: [
|
|
63
|
+
{binding: 2, visibility: GpuShaderStage.FRAGMENT, buffer: () => this._materialBuffer},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** @inheritDoc */
|
|
70
|
+
public get projectionViewBuffer(): IUniformBuffer {
|
|
71
|
+
return this._projectionViewBuffer;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** @inheritDoc */
|
|
75
|
+
public set projectionViewBuffer(value: IUniformBuffer) {
|
|
76
|
+
this._projectionViewBuffer = value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** @inheritDoc */
|
|
80
|
+
public get modelBuffer(): IUniformBuffer {
|
|
81
|
+
return this._modelBuffer;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** @inheritDoc */
|
|
85
|
+
public set modelBuffer(value: IUniformBuffer) {
|
|
86
|
+
if (!value) {
|
|
87
|
+
throw new Error("WebGpuUnlitRenderPipeline: modelBuffer is required (the mesh's model buffer, mat4).");
|
|
88
|
+
}
|
|
89
|
+
this._modelBuffer = value;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** @inheritDoc */
|
|
93
|
+
public get materialBuffer(): IUniformBuffer {
|
|
94
|
+
return this._materialBuffer;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** @inheritDoc */
|
|
98
|
+
public set materialBuffer(value: IUniformBuffer) {
|
|
99
|
+
this._materialBuffer = value;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {SamplerDescriptor} from "../../core/rendering/sampler/sampler-descriptor.ts";
|
|
2
|
+
import {type ISampler, MipMapSamplerFilter} from "../../api/index.ts";
|
|
3
|
+
import type {WebGpuGraphicsDevice} from "../WebGpuGraphicsDevice.ts";
|
|
4
|
+
import type {GpuSampler} from "../WebGpuTypes.ts";
|
|
5
|
+
import {WebGpuConverter} from "../utilities/WebGpuConverter.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The WebGPU sampler.
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export class WebGpuSampler implements ISampler {
|
|
12
|
+
|
|
13
|
+
private static _nextId = 0;
|
|
14
|
+
|
|
15
|
+
private _gpuSampler: GpuSampler | null;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The constructor.
|
|
19
|
+
* @param graphicsDevice The graphics device.
|
|
20
|
+
* @param descriptor The sampler descriptor.
|
|
21
|
+
*/
|
|
22
|
+
public constructor(graphicsDevice: WebGpuGraphicsDevice, descriptor?: SamplerDescriptor) {
|
|
23
|
+
descriptor = descriptor ?? new SamplerDescriptor();
|
|
24
|
+
this.id = WebGpuSampler._nextId++;
|
|
25
|
+
this.minFilter = descriptor.minFilter;
|
|
26
|
+
this.magFilter = descriptor.magFilter;
|
|
27
|
+
this.mipmapFilter = descriptor.mipMapFilter;
|
|
28
|
+
this.addressModeU = descriptor.addressModeU;
|
|
29
|
+
this.addressModeV = descriptor.addressModeV;
|
|
30
|
+
this.addressModeW = descriptor.addressModeW;
|
|
31
|
+
|
|
32
|
+
this._gpuSampler = graphicsDevice.device.createSampler({
|
|
33
|
+
label: `WebGpuSampler ${this.id}`,
|
|
34
|
+
minFilter: WebGpuConverter.convertFilter(this.minFilter),
|
|
35
|
+
magFilter: WebGpuConverter.convertFilter(this.magFilter),
|
|
36
|
+
mipmapFilter: WebGpuConverter.convertMipMapFilter(this.mipmapFilter),
|
|
37
|
+
addressModeU: WebGpuConverter.convertAddressMode(this.addressModeU),
|
|
38
|
+
addressModeV: WebGpuConverter.convertAddressMode(this.addressModeV),
|
|
39
|
+
addressModeW: WebGpuConverter.convertAddressMode(this.addressModeW),
|
|
40
|
+
// Without mip filtering only the base level is sampled.
|
|
41
|
+
lodMaxClamp: this.mipmapFilter === MipMapSamplerFilter.NONE ? 0 : 32,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** @inheritDoc */
|
|
46
|
+
public readonly id: number;
|
|
47
|
+
|
|
48
|
+
/** @inheritDoc */
|
|
49
|
+
public readonly minFilter;
|
|
50
|
+
|
|
51
|
+
/** @inheritDoc */
|
|
52
|
+
public readonly magFilter;
|
|
53
|
+
|
|
54
|
+
/** @inheritDoc */
|
|
55
|
+
public readonly mipmapFilter;
|
|
56
|
+
|
|
57
|
+
/** @inheritDoc */
|
|
58
|
+
public readonly addressModeU;
|
|
59
|
+
|
|
60
|
+
/** @inheritDoc */
|
|
61
|
+
public readonly addressModeV;
|
|
62
|
+
|
|
63
|
+
/** @inheritDoc */
|
|
64
|
+
public readonly addressModeW;
|
|
65
|
+
|
|
66
|
+
/** The WebGPU sampler. */
|
|
67
|
+
public get gpuSampler(): GpuSampler {
|
|
68
|
+
if (!this._gpuSampler) {
|
|
69
|
+
throw new Error("WebGpuSampler: the sampler is disposed.");
|
|
70
|
+
}
|
|
71
|
+
return this._gpuSampler;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** @inheritDoc */
|
|
75
|
+
public get handle(): any {
|
|
76
|
+
return this._gpuSampler;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** @inheritDoc */
|
|
80
|
+
public dispose(): void {
|
|
81
|
+
// WebGPU samplers have no destroy(); dropping the reference lets the browser collect it.
|
|
82
|
+
this._gpuSampler = null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {type IFramework, type IShaderModule, ShaderStage} from "../../api/index.ts";
|
|
2
|
+
import type {WebGpuGraphicsDevice} from "../WebGpuGraphicsDevice.ts";
|
|
3
|
+
import type {GpuShaderModule} from "../WebGpuTypes.ts";
|
|
4
|
+
import {WgslShaderContent} from "./WgslShaderContent.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A WGSL shader module. One module holds both stages (`main_vs` and `main_fs`).
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export class WebGpuShaderModule implements IShaderModule {
|
|
11
|
+
|
|
12
|
+
private _gpuShaderModule: GpuShaderModule | null;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The constructor.
|
|
16
|
+
* @param framework The framework.
|
|
17
|
+
* @param id The built-in shader id, for example `unlit_material`.
|
|
18
|
+
* @param keyValueDictionary Optional `##KEY##` replacements, like the WebGL loader.
|
|
19
|
+
*/
|
|
20
|
+
public constructor(framework: IFramework, id: string, keyValueDictionary?: { [id: string]: number }) {
|
|
21
|
+
let code = WgslShaderContent[id];
|
|
22
|
+
if (code === undefined) {
|
|
23
|
+
throw new Error(`WGSL shader '${id}' is not implemented for WebGPU.`);
|
|
24
|
+
}
|
|
25
|
+
if (keyValueDictionary) {
|
|
26
|
+
for (const key in keyValueDictionary) {
|
|
27
|
+
code = code.split(`##${key}##`).join(String(keyValueDictionary[key]));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const device = (framework.renderer.graphicsDevice as WebGpuGraphicsDevice).device;
|
|
31
|
+
this._gpuShaderModule = device.createShaderModule({label: id, code});
|
|
32
|
+
this.label = id;
|
|
33
|
+
this._gpuShaderModule.getCompilationInfo?.().then(info => {
|
|
34
|
+
for (const message of info.messages) {
|
|
35
|
+
if (message.type === "error") {
|
|
36
|
+
console.error(`WGSL ${id}:${message.lineNum}:${message.linePos} ${message.message}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}).catch(() => { /* ignore */ });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The shader id. */
|
|
43
|
+
public readonly label: string;
|
|
44
|
+
|
|
45
|
+
/** @inheritDoc */
|
|
46
|
+
public readonly stages: ShaderStage[] = [ShaderStage.VERTEX, ShaderStage.FRAGMENT];
|
|
47
|
+
|
|
48
|
+
/** The WebGPU shader module. */
|
|
49
|
+
public get gpuShaderModule(): GpuShaderModule {
|
|
50
|
+
if (!this._gpuShaderModule) {
|
|
51
|
+
throw new Error("WebGpuShaderModule: the module is disposed.");
|
|
52
|
+
}
|
|
53
|
+
return this._gpuShaderModule;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @inheritDoc */
|
|
57
|
+
public get nativeHandle(): any {
|
|
58
|
+
return this._gpuShaderModule;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @inheritDoc */
|
|
62
|
+
public dispose(): void {
|
|
63
|
+
this._gpuShaderModule = null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type {IFramework, IShaderModule, IShaderModuleLoader} from "../../api/index.ts";
|
|
2
|
+
import {shaderModuleCacheKey} from "../../webgl/shader/WebGlShaderModuleLoader.ts";
|
|
3
|
+
import {WebGpuShaderModule} from "./WebGpuShaderModule.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Loads and caches WGSL shader modules by id.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export class WebGpuShaderModuleLoader implements IShaderModuleLoader {
|
|
10
|
+
|
|
11
|
+
private readonly _shaderModules = new Map<string, WebGpuShaderModule>();
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The constructor.
|
|
15
|
+
* @param _framework The framework.
|
|
16
|
+
*/
|
|
17
|
+
public constructor(private readonly _framework: IFramework) {
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** @inheritDoc */
|
|
21
|
+
public load(shaderModuleId: string, keyValueDictionary?: { [id: string]: number }): IShaderModule {
|
|
22
|
+
const key = shaderModuleCacheKey(shaderModuleId, keyValueDictionary);
|
|
23
|
+
let module = this._shaderModules.get(key);
|
|
24
|
+
if (!module) {
|
|
25
|
+
module = new WebGpuShaderModule(this._framework, shaderModuleId, keyValueDictionary);
|
|
26
|
+
this._shaderModules.set(key, module);
|
|
27
|
+
}
|
|
28
|
+
return module;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Disposes every cached module. */
|
|
32
|
+
public dispose(): void {
|
|
33
|
+
for (const module of this._shaderModules.values()) {
|
|
34
|
+
module.dispose();
|
|
35
|
+
}
|
|
36
|
+
this._shaderModules.clear();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import mainFrameBuffer from "../../../shaders/wgsl/main_frame_buffer.wgsl?raw";
|
|
2
|
+
import mainRenderTargetFlipY from "../../../shaders/wgsl/main_render_target_flip_y.wgsl?raw";
|
|
3
|
+
import unlitMaterial from "../../../shaders/wgsl/unlit_material.wgsl?raw";
|
|
4
|
+
import forwardBlinnPhongMaterial from "../../../shaders/wgsl/forward_blinn_phong_material.wgsl?raw";
|
|
5
|
+
import sprite from "../../../shaders/wgsl/sprite.wgsl?raw";
|
|
6
|
+
import inspectTextureMips from "../../../shaders/wgsl/inspect_texture_mips.wgsl?raw";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The framework's built-in WGSL shaders, keyed by the same ids the WebGL backend uses where one exists.
|
|
10
|
+
* Every shader has `main_vs` and `main_fs` entry points.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export const WgslShaderContent: { [id: string]: string } = {
|
|
14
|
+
"main_frame_buffer": mainFrameBuffer,
|
|
15
|
+
"main_render_target_flip_y": mainRenderTargetFlipY,
|
|
16
|
+
"unlit_material": unlitMaterial,
|
|
17
|
+
"forward_blinn_phong_material": forwardBlinnPhongMaterial,
|
|
18
|
+
"sprite": sprite,
|
|
19
|
+
"inspect_texture_mips": inspectTextureMips,
|
|
20
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {vec2} from "gl-matrix";
|
|
2
|
+
import {type ISwapChain, SwapChainDescriptor, TextureFormat} from "../../api/index.ts";
|
|
3
|
+
import type {WebGpuGraphicsDevice} from "../WebGpuGraphicsDevice.ts";
|
|
4
|
+
import {GpuTextureUsage, type GpuCanvasContext, type GpuTextureView} from "../WebGpuTypes.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The WebGPU swap chain, backed by the canvas' `webgpu` context.
|
|
8
|
+
*
|
|
9
|
+
* The canvas is configured as `rgba8unorm` instead of `navigator.gpu.getPreferredCanvasFormat()` (often `bgra8unorm`),
|
|
10
|
+
* because the framework's {@link TextureFormat} has no BGRA format and the main render target uses the swap chain format.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export class WebGpuSwapChain implements ISwapChain {
|
|
14
|
+
|
|
15
|
+
private readonly _canvas: HTMLCanvasElement;
|
|
16
|
+
private readonly _graphicsDevice: WebGpuGraphicsDevice;
|
|
17
|
+
private readonly _context: GpuCanvasContext;
|
|
18
|
+
private readonly _backBufferSize: vec2;
|
|
19
|
+
private _currentView: GpuTextureView | null = null;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The constructor.
|
|
23
|
+
* @param canvas The canvas.
|
|
24
|
+
* @param graphicsDevice The graphics device.
|
|
25
|
+
* @param _descriptor The swap chain descriptor. WebGPU canvases always present with FIFO.
|
|
26
|
+
*/
|
|
27
|
+
public constructor(canvas: HTMLCanvasElement, graphicsDevice: WebGpuGraphicsDevice, _descriptor?: SwapChainDescriptor) {
|
|
28
|
+
this._canvas = canvas;
|
|
29
|
+
this._graphicsDevice = graphicsDevice;
|
|
30
|
+
const context = canvas.getContext("webgpu" as "webgl2") as unknown as GpuCanvasContext | null;
|
|
31
|
+
if (!context) {
|
|
32
|
+
throw new Error("WebGPU canvas context is not available.");
|
|
33
|
+
}
|
|
34
|
+
this._context = context;
|
|
35
|
+
this._backBufferSize = vec2.fromValues(canvas.width, canvas.height);
|
|
36
|
+
this._configure();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private _configure(): void {
|
|
40
|
+
this._context.configure({
|
|
41
|
+
device: this._graphicsDevice.device,
|
|
42
|
+
format: "rgba8unorm",
|
|
43
|
+
usage: GpuTextureUsage.RENDER_ATTACHMENT,
|
|
44
|
+
alphaMode: this._graphicsDevice.alpha ? "premultiplied" : "opaque",
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @inheritDoc */
|
|
49
|
+
public get textureFormat(): TextureFormat {
|
|
50
|
+
return TextureFormat.RGBA_8_UNORM;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** @inheritDoc */
|
|
54
|
+
public get backBufferSize(): vec2 {
|
|
55
|
+
return this._backBufferSize;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The view of the current canvas texture. Acquired once per frame and released on {@link present}.
|
|
60
|
+
*/
|
|
61
|
+
public get currentTextureView(): GpuTextureView {
|
|
62
|
+
if (!this._currentView) {
|
|
63
|
+
this._currentView = this._context.getCurrentTexture().createView();
|
|
64
|
+
}
|
|
65
|
+
return this._currentView;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** @inheritDoc */
|
|
69
|
+
public resize(width: number, height: number): void {
|
|
70
|
+
if (width <= 0 || height <= 0) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this._currentView = null;
|
|
74
|
+
this._canvas.width = width;
|
|
75
|
+
this._canvas.height = height;
|
|
76
|
+
this._backBufferSize[0] = width;
|
|
77
|
+
this._backBufferSize[1] = height;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** @inheritDoc */
|
|
81
|
+
public present(): void {
|
|
82
|
+
// The browser presents the canvas texture after the task; the next frame needs a fresh texture.
|
|
83
|
+
this._currentView = null;
|
|
84
|
+
this._backBufferSize[0] = this._canvas.width;
|
|
85
|
+
this._backBufferSize[1] = this._canvas.height;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** @inheritDoc */
|
|
89
|
+
public dispose(): void {
|
|
90
|
+
this._currentView = null;
|
|
91
|
+
this._context.unconfigure();
|
|
92
|
+
}
|
|
93
|
+
}
|