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,119 @@
|
|
|
1
|
+
import {BufferUsage, type IFramework, type IVertexBuffer} 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 vertex buffer. Always created with COPY_DST so it can be updated.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export class WebGpuVertexBuffer implements IVertexBuffer {
|
|
11
|
+
|
|
12
|
+
private readonly _graphicsDevice: WebGpuGraphicsDevice;
|
|
13
|
+
private readonly _data: Float32Array;
|
|
14
|
+
private readonly _vertexCount: number;
|
|
15
|
+
private readonly _byteSize: number;
|
|
16
|
+
private _gpuBuffer: GpuBuffer | null = null;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The constructor.
|
|
20
|
+
* @param framework The framework.
|
|
21
|
+
* @param dataOrVertexCount The float vertex data, or the number of vertices to allocate.
|
|
22
|
+
* @param _byteStride The vertex stride in bytes.
|
|
23
|
+
* @param _bufferUsage The buffer usage.
|
|
24
|
+
* @param _label The label.
|
|
25
|
+
*/
|
|
26
|
+
public constructor(framework: IFramework,
|
|
27
|
+
dataOrVertexCount: ArrayLike<number> | number,
|
|
28
|
+
private readonly _byteStride: number,
|
|
29
|
+
private readonly _bufferUsage: BufferUsage,
|
|
30
|
+
private readonly _label?: string) {
|
|
31
|
+
this._graphicsDevice = framework.renderer.graphicsDevice as WebGpuGraphicsDevice;
|
|
32
|
+
if (typeof dataOrVertexCount === "number") {
|
|
33
|
+
this._vertexCount = dataOrVertexCount;
|
|
34
|
+
this._byteSize = dataOrVertexCount * this._byteStride;
|
|
35
|
+
this._data = new Float32Array(this._byteSize / Float32Array.BYTES_PER_ELEMENT);
|
|
36
|
+
} else {
|
|
37
|
+
this._data = new Float32Array(dataOrVertexCount);
|
|
38
|
+
this._byteSize = this._data.byteLength;
|
|
39
|
+
this._vertexCount = this._byteSize / this._byteStride;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The WebGPU buffer. */
|
|
44
|
+
public get gpuBuffer(): GpuBuffer {
|
|
45
|
+
if (!this._gpuBuffer) {
|
|
46
|
+
throw new Error("WebGpuVertexBuffer: the buffer is not initialized or is disposed.");
|
|
47
|
+
}
|
|
48
|
+
return this._gpuBuffer;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** @inheritDoc */
|
|
52
|
+
public get label(): string | undefined {
|
|
53
|
+
return this._label;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @inheritDoc */
|
|
57
|
+
public get vertexCount(): number {
|
|
58
|
+
return this._vertexCount;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @inheritDoc */
|
|
62
|
+
public get byteSize(): number {
|
|
63
|
+
return this._byteSize;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @inheritDoc */
|
|
67
|
+
public get byteStride(): number {
|
|
68
|
+
return this._byteStride;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @inheritDoc */
|
|
72
|
+
public get usage(): BufferUsage {
|
|
73
|
+
return this._bufferUsage;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** @inheritDoc */
|
|
77
|
+
public initialize(): void {
|
|
78
|
+
const device = this._graphicsDevice.device;
|
|
79
|
+
// WebGPU buffer sizes must be a multiple of 4; float data always is.
|
|
80
|
+
this._gpuBuffer = device.createBuffer({
|
|
81
|
+
label: this._label,
|
|
82
|
+
size: Math.max(4, this._byteSize),
|
|
83
|
+
usage: WebGpuConverter.convertBufferUsage(this._bufferUsage) | GpuBufferUsage.VERTEX | GpuBufferUsage.COPY_DST,
|
|
84
|
+
});
|
|
85
|
+
if (this._data.length > 0) {
|
|
86
|
+
device.queue.writeBuffer(this._gpuBuffer, 0, this._data.buffer, this._data.byteOffset, this._data.byteLength);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Updates the buffer.
|
|
92
|
+
* @param data The float data.
|
|
93
|
+
* @param offset The first float to write (in floats, like WebGL).
|
|
94
|
+
* @param length The number of floats to write; 0 writes the whole data.
|
|
95
|
+
*/
|
|
96
|
+
public update(data: number[], offset: number = 0, length: number = 0): void {
|
|
97
|
+
length = length > 0 ? length : data.length - offset;
|
|
98
|
+
length = Math.min(length, this._data.length - offset, data.length - offset);
|
|
99
|
+
if (length <= 0) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
for (let i = 0; i < length; ++i) {
|
|
103
|
+
this._data[offset + i] = data[offset + i];
|
|
104
|
+
}
|
|
105
|
+
// Write only the changed range, not the whole buffer.
|
|
106
|
+
this._graphicsDevice.device.queue.writeBuffer(
|
|
107
|
+
this.gpuBuffer,
|
|
108
|
+
offset * Float32Array.BYTES_PER_ELEMENT,
|
|
109
|
+
this._data.buffer,
|
|
110
|
+
this._data.byteOffset + offset * Float32Array.BYTES_PER_ELEMENT,
|
|
111
|
+
length * Float32Array.BYTES_PER_ELEMENT);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** @inheritDoc */
|
|
115
|
+
public dispose(): void {
|
|
116
|
+
this._gpuBuffer?.destroy();
|
|
117
|
+
this._gpuBuffer = null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CullMode,
|
|
3
|
+
type FrontFace,
|
|
4
|
+
type IPrimitiveState,
|
|
5
|
+
type PrimitiveStateDescriptor,
|
|
6
|
+
type PrimitiveTopology,
|
|
7
|
+
} from "../../api/index.ts";
|
|
8
|
+
import type {GpuCullMode, GpuFrontFace, GpuPrimitiveTopology} from "../WebGpuTypes.ts";
|
|
9
|
+
import {WebGpuConverter} from "../utilities/WebGpuConverter.ts";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The WebGPU primitive state. WebGPU bakes it into the render pipeline, so this only holds the converted values.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export class WebGpuPrimitiveState implements IPrimitiveState {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The constructor.
|
|
19
|
+
* @param descriptor The primitive state descriptor.
|
|
20
|
+
*/
|
|
21
|
+
public constructor(descriptor: PrimitiveStateDescriptor) {
|
|
22
|
+
this.topology = descriptor.topology;
|
|
23
|
+
this.cullFace = descriptor.cullFace;
|
|
24
|
+
this.frontFace = descriptor.frontFace;
|
|
25
|
+
this.gpuTopology = WebGpuConverter.convertTopology(this.topology);
|
|
26
|
+
this.gpuCullMode = WebGpuConverter.convertCullMode(this.cullFace);
|
|
27
|
+
this.gpuFrontFace = WebGpuConverter.convertFrontFace(this.frontFace);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @inheritDoc */
|
|
31
|
+
public readonly topology: PrimitiveTopology;
|
|
32
|
+
|
|
33
|
+
/** @inheritDoc */
|
|
34
|
+
public readonly cullFace: CullMode;
|
|
35
|
+
|
|
36
|
+
/** @inheritDoc */
|
|
37
|
+
public readonly frontFace: FrontFace;
|
|
38
|
+
|
|
39
|
+
/** The WebGPU topology. */
|
|
40
|
+
public readonly gpuTopology: GpuPrimitiveTopology;
|
|
41
|
+
|
|
42
|
+
/** The WebGPU cull mode. */
|
|
43
|
+
public readonly gpuCullMode: GpuCullMode;
|
|
44
|
+
|
|
45
|
+
/** The WebGPU front face. */
|
|
46
|
+
public readonly gpuFrontFace: GpuFrontFace;
|
|
47
|
+
|
|
48
|
+
/** The `GPUPrimitiveState` for a render pipeline. */
|
|
49
|
+
public get gpuPrimitiveState(): { topology: GpuPrimitiveTopology; cullMode: GpuCullMode; frontFace: GpuFrontFace } {
|
|
50
|
+
return {topology: this.gpuTopology, cullMode: this.gpuCullMode, frontFace: this.gpuFrontFace};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type IRenderPass,
|
|
3
|
+
LoadAction,
|
|
4
|
+
type RenderPassDescriptor,
|
|
5
|
+
StoreAction,
|
|
6
|
+
} from "../../api/index.ts";
|
|
7
|
+
import type {WebGpuGraphicsDevice} from "../WebGpuGraphicsDevice.ts";
|
|
8
|
+
import type {
|
|
9
|
+
GpuCommandEncoder,
|
|
10
|
+
GpuRenderPassColorAttachment,
|
|
11
|
+
GpuRenderPassDepthStencilAttachment,
|
|
12
|
+
GpuRenderPassDescriptor,
|
|
13
|
+
} from "../WebGpuTypes.ts";
|
|
14
|
+
import {WebGpuConverter} from "../utilities/WebGpuConverter.ts";
|
|
15
|
+
import {WebGpuTexture2D} from "../texture/WebGpuTexture2D.ts";
|
|
16
|
+
import {WebGpuTextureView} from "../texture/WebGpuTextureView.ts";
|
|
17
|
+
import type {WebGpuSwapChain} from "../swap-chain/WebGpuSwapChain.ts";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The WebGPU render pass. `beginPass` creates a command encoder and begins a render pass,
|
|
21
|
+
* `endPass` ends it and submits the command buffer, like the C# `WebGPURenderPass`.
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export class WebGpuRenderPass implements IRenderPass {
|
|
25
|
+
|
|
26
|
+
private readonly _graphicsDevice: WebGpuGraphicsDevice;
|
|
27
|
+
private readonly _descriptor: RenderPassDescriptor;
|
|
28
|
+
private _commandEncoder: GpuCommandEncoder | null = null;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The constructor.
|
|
32
|
+
* @param graphicsDevice The graphics device.
|
|
33
|
+
* @param descriptor The render pass descriptor.
|
|
34
|
+
*/
|
|
35
|
+
public constructor(graphicsDevice: WebGpuGraphicsDevice, descriptor: RenderPassDescriptor) {
|
|
36
|
+
this._graphicsDevice = graphicsDevice;
|
|
37
|
+
this._descriptor = descriptor;
|
|
38
|
+
if (!descriptor.colorAttachments || descriptor.colorAttachments.length === 0) {
|
|
39
|
+
throw new Error("WebGpuRenderPass: at least one color attachment is required.");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private _buildDescriptor(): GpuRenderPassDescriptor {
|
|
44
|
+
const colorAttachments: GpuRenderPassColorAttachment[] = this._descriptor.colorAttachments!.map(attachment => {
|
|
45
|
+
let view;
|
|
46
|
+
if (attachment.swapChain) {
|
|
47
|
+
view = (attachment.swapChain as WebGpuSwapChain).currentTextureView;
|
|
48
|
+
} else if (attachment.view) {
|
|
49
|
+
view = (attachment.view as WebGpuTextureView).gpuTextureView;
|
|
50
|
+
} else if (attachment.texture) {
|
|
51
|
+
view = (attachment.texture as WebGpuTexture2D).gpuDefaultView;
|
|
52
|
+
} else {
|
|
53
|
+
throw new Error("WebGpuRenderPass: a color attachment needs a swap chain, view or texture.");
|
|
54
|
+
}
|
|
55
|
+
const c = attachment.clearColor;
|
|
56
|
+
return {
|
|
57
|
+
view,
|
|
58
|
+
resolveTarget: attachment.resolveView
|
|
59
|
+
? (attachment.resolveView as WebGpuTextureView).gpuTextureView
|
|
60
|
+
: attachment.resolveTexture ? (attachment.resolveTexture as WebGpuTexture2D).gpuDefaultView : undefined,
|
|
61
|
+
clearValue: {r: c.r, g: c.g, b: c.b, a: c.a},
|
|
62
|
+
loadOp: WebGpuConverter.convertLoadAction(attachment.loadAction),
|
|
63
|
+
storeOp: WebGpuConverter.convertStoreAction(attachment.storeAction),
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const result: GpuRenderPassDescriptor = {
|
|
68
|
+
label: this._descriptor.label,
|
|
69
|
+
colorAttachments,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const depth = this._descriptor.depthStencilAttachment;
|
|
73
|
+
if (depth && (depth.texture || depth.view)) {
|
|
74
|
+
const texture = depth.texture as WebGpuTexture2D | undefined;
|
|
75
|
+
const format = depth.view?.textureFormat ?? texture!.textureFormat;
|
|
76
|
+
const attachment: GpuRenderPassDepthStencilAttachment = {
|
|
77
|
+
view: depth.view ? (depth.view as WebGpuTextureView).gpuTextureView : texture!.gpuDefaultView,
|
|
78
|
+
depthClearValue: depth.depthClearValue,
|
|
79
|
+
depthLoadOp: WebGpuConverter.convertLoadAction(depth.depthLoadAction),
|
|
80
|
+
depthStoreOp: WebGpuConverter.convertStoreAction(depth.depthStoreAction),
|
|
81
|
+
};
|
|
82
|
+
// Stencil ops are only valid when the format has a stencil aspect.
|
|
83
|
+
if (WebGpuConverter.hasStencil(format)) {
|
|
84
|
+
attachment.stencilClearValue = depth.stencilClearValue;
|
|
85
|
+
attachment.stencilLoadOp = depth.stencilLoadAction === LoadAction.LOAD ? "load" : "clear";
|
|
86
|
+
attachment.stencilStoreOp = depth.stencilStoreAction === StoreAction.DISCARD ? "discard" : "store";
|
|
87
|
+
}
|
|
88
|
+
result.depthStencilAttachment = attachment;
|
|
89
|
+
}
|
|
90
|
+
// A depth attachment without a texture would need an internal depth buffer (WebGL uses a renderbuffer).
|
|
91
|
+
// TODO: create an internal depth texture for that case.
|
|
92
|
+
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Whether the pass has a depth attachment. */
|
|
97
|
+
public get hasDepthStencil(): boolean {
|
|
98
|
+
const depth = this._descriptor.depthStencilAttachment;
|
|
99
|
+
return !!depth && !!(depth.texture || depth.view);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** @inheritDoc */
|
|
103
|
+
public beginPass(): void {
|
|
104
|
+
if (this._commandEncoder) {
|
|
105
|
+
throw new Error("WebGpuRenderPass: the pass is already open.");
|
|
106
|
+
}
|
|
107
|
+
const device = this._graphicsDevice.device;
|
|
108
|
+
this._commandEncoder = device.createCommandEncoder({label: this._descriptor.label});
|
|
109
|
+
this._graphicsDevice.currentRenderPassEncoder = this._commandEncoder.beginRenderPass(this._buildDescriptor());
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** @inheritDoc */
|
|
113
|
+
public endPass(): void {
|
|
114
|
+
if (!this._commandEncoder) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
this._graphicsDevice.currentRenderPassEncoder?.end();
|
|
118
|
+
this._graphicsDevice.currentRenderPassEncoder = null;
|
|
119
|
+
this._graphicsDevice.device.queue.submit([this._commandEncoder.finish()]);
|
|
120
|
+
this._commandEncoder = null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** @inheritDoc */
|
|
124
|
+
public dispose(): void {
|
|
125
|
+
if (this._commandEncoder) {
|
|
126
|
+
this._graphicsDevice.currentRenderPassEncoder?.end();
|
|
127
|
+
this._graphicsDevice.currentRenderPassEncoder = null;
|
|
128
|
+
this._commandEncoder = null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GeometryFormat,
|
|
3
|
+
type IBlendState,
|
|
4
|
+
type IFramework,
|
|
5
|
+
type IIndexBuffer,
|
|
6
|
+
type IPrimitiveState,
|
|
7
|
+
type IRenderPipeline,
|
|
8
|
+
type IVertexBuffer,
|
|
9
|
+
TextureFormat,
|
|
10
|
+
} from "../../api/index.ts";
|
|
11
|
+
import type {VertexBufferLayout} from "../../core/rendering/vertex-buffer-layout.ts";
|
|
12
|
+
import type {WebGpuGraphicsDevice} from "../WebGpuGraphicsDevice.ts";
|
|
13
|
+
import type {WebGpuBlendState} from "../blending/WebGpuBlendState.ts";
|
|
14
|
+
import type {WebGpuPrimitiveState} from "../primitive/WebGpuPrimitiveState.ts";
|
|
15
|
+
import type {WebGpuSampler} from "../sampler/WebGpuSampler.ts";
|
|
16
|
+
import type {
|
|
17
|
+
GpuBindGroupLayout,
|
|
18
|
+
GpuPipelineLayout,
|
|
19
|
+
GpuRenderPipeline,
|
|
20
|
+
GpuShaderModule,
|
|
21
|
+
} from "../WebGpuTypes.ts";
|
|
22
|
+
import {WebGpuConverter} from "../utilities/WebGpuConverter.ts";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The base WebGPU render pipeline. Holds the device, the states and the vertex layouts,
|
|
26
|
+
* and builds the `GPURenderPipeline` from them.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export abstract class AWebGpuRenderPipeline implements IRenderPipeline {
|
|
30
|
+
|
|
31
|
+
protected readonly _framework: IFramework;
|
|
32
|
+
protected readonly _graphicsDevice: WebGpuGraphicsDevice;
|
|
33
|
+
protected readonly _defaultTextureSampler: WebGpuSampler;
|
|
34
|
+
protected _blendState: WebGpuBlendState;
|
|
35
|
+
protected _gpuPipeline: GpuRenderPipeline | null = null;
|
|
36
|
+
protected _pipelineLayout: GpuPipelineLayout | null = null;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The constructor.
|
|
40
|
+
* @param framework The framework.
|
|
41
|
+
* @param primitiveState The optional primitive state; defaults to the device's.
|
|
42
|
+
*/
|
|
43
|
+
protected constructor(framework: IFramework, primitiveState?: IPrimitiveState) {
|
|
44
|
+
this._framework = framework;
|
|
45
|
+
this._graphicsDevice = framework.renderer.graphicsDevice as WebGpuGraphicsDevice;
|
|
46
|
+
this._blendState = this._graphicsDevice.defaultBlendState as WebGpuBlendState;
|
|
47
|
+
this._defaultTextureSampler = this._graphicsDevice.defaultTextureSampler as WebGpuSampler;
|
|
48
|
+
this.primitiveState = (primitiveState ?? this._graphicsDevice.defaultPrimitiveState) as WebGpuPrimitiveState;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** @inheritDoc */
|
|
52
|
+
public abstract readonly geometryFormat: GeometryFormat;
|
|
53
|
+
|
|
54
|
+
/** @inheritDoc */
|
|
55
|
+
public get blendState(): IBlendState {
|
|
56
|
+
return this._blendState;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @inheritDoc */
|
|
60
|
+
public readonly primitiveState: WebGpuPrimitiveState;
|
|
61
|
+
|
|
62
|
+
/** @inheritDoc */
|
|
63
|
+
public vertexBufferLayouts: VertexBufferLayout[] = null!;
|
|
64
|
+
|
|
65
|
+
/** @inheritDoc */
|
|
66
|
+
public abstract initialize(): void;
|
|
67
|
+
|
|
68
|
+
/** @inheritDoc */
|
|
69
|
+
public abstract render(vertexBuffer: IVertexBuffer, indexBuffer: IIndexBuffer, indicesCount?: number, indicesOffset?: number): void;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Creates the pipeline layout and the render pipeline.
|
|
73
|
+
* @param label The label.
|
|
74
|
+
* @param module The WGSL module with `main_vs` and `main_fs`.
|
|
75
|
+
* @param bindGroupLayouts The bind group layouts, in group order.
|
|
76
|
+
* @param colorFormat The color target format.
|
|
77
|
+
* @param depthStencilFormat The depth format, or undefined when the pass has no depth attachment.
|
|
78
|
+
*/
|
|
79
|
+
protected _createGpuPipeline(
|
|
80
|
+
label: string,
|
|
81
|
+
module: GpuShaderModule,
|
|
82
|
+
bindGroupLayouts: GpuBindGroupLayout[],
|
|
83
|
+
colorFormat: TextureFormat,
|
|
84
|
+
depthStencilFormat?: TextureFormat): void {
|
|
85
|
+
|
|
86
|
+
if (!this.vertexBufferLayouts || this.vertexBufferLayouts.length === 0) {
|
|
87
|
+
throw new Error("At least one vertex buffer layout must be provided for the render pipeline.");
|
|
88
|
+
}
|
|
89
|
+
const device = this._graphicsDevice.device;
|
|
90
|
+
this._pipelineLayout = device.createPipelineLayout({label: `${label} layout`, bindGroupLayouts});
|
|
91
|
+
this._gpuPipeline = device.createRenderPipeline({
|
|
92
|
+
label,
|
|
93
|
+
layout: this._pipelineLayout,
|
|
94
|
+
vertex: {
|
|
95
|
+
module,
|
|
96
|
+
entryPoint: "main_vs",
|
|
97
|
+
buffers: this.vertexBufferLayouts.map(l => WebGpuConverter.convertVertexBufferLayout(l)),
|
|
98
|
+
},
|
|
99
|
+
fragment: {
|
|
100
|
+
module,
|
|
101
|
+
entryPoint: "main_fs",
|
|
102
|
+
targets: [{
|
|
103
|
+
format: WebGpuConverter.convertTextureFormat(colorFormat),
|
|
104
|
+
blend: this._blendState.gpuBlendState,
|
|
105
|
+
}],
|
|
106
|
+
},
|
|
107
|
+
primitive: this.primitiveState.gpuPrimitiveState,
|
|
108
|
+
depthStencil: depthStencilFormat !== undefined ? {
|
|
109
|
+
format: WebGpuConverter.convertTextureFormat(depthStencilFormat),
|
|
110
|
+
depthWriteEnabled: true,
|
|
111
|
+
// Matches the WebGL backend's LEQUAL.
|
|
112
|
+
depthCompare: "less-equal",
|
|
113
|
+
} : undefined,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** @inheritDoc */
|
|
118
|
+
public dispose(): void {
|
|
119
|
+
// Pipelines and layouts have no destroy() in WebGPU.
|
|
120
|
+
this._gpuPipeline = null;
|
|
121
|
+
this._pipelineLayout = null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {vec2} from "gl-matrix";
|
|
2
|
+
import {
|
|
3
|
+
BufferUsage,
|
|
4
|
+
GeometryFormat,
|
|
5
|
+
type IFramework,
|
|
6
|
+
type IMainRenderTargetRenderPipeline,
|
|
7
|
+
type ITexture2D,
|
|
8
|
+
} from "../../api/index.ts";
|
|
9
|
+
import {VertexBufferLayout} from "../../core/rendering/vertex-buffer-layout.ts";
|
|
10
|
+
import {AWebGpuRenderPipeline} from "./AWebGpuRenderPipeline.ts";
|
|
11
|
+
import type {WebGpuTexture2D} from "../texture/WebGpuTexture2D.ts";
|
|
12
|
+
import type {WebGpuVertexBuffer} from "../buffers/WebGpuVertexBuffer.ts";
|
|
13
|
+
import type {WebGpuIndexBuffer} from "../buffers/WebGpuIndexBuffer.ts";
|
|
14
|
+
import type {WebGpuShaderModule} from "../shader/WebGpuShaderModule.ts";
|
|
15
|
+
import {GpuShaderStage, type GpuBindGroup, type GpuBindGroupLayout} from "../WebGpuTypes.ts";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Draws the main render target to the swap chain with `main_frame_buffer.wgsl`.
|
|
19
|
+
* No Y flip: in WebGPU texture (0,0) is the top-left, which matches the quad's UVs (same as the C# backend).
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export class WebGpuMainRenderTargetRenderPipeline extends AWebGpuRenderPipeline implements IMainRenderTargetRenderPipeline {
|
|
23
|
+
|
|
24
|
+
private _vertexBuffer: WebGpuVertexBuffer = null!;
|
|
25
|
+
private _indexBuffer: WebGpuIndexBuffer = null!;
|
|
26
|
+
private _mainRenderTarget: WebGpuTexture2D;
|
|
27
|
+
private _bindGroupLayout: GpuBindGroupLayout = null!;
|
|
28
|
+
private _bindGroup: GpuBindGroup | null = null;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The constructor.
|
|
32
|
+
* @param framework The framework.
|
|
33
|
+
* @param mainRenderTarget The main render target.
|
|
34
|
+
*/
|
|
35
|
+
public constructor(framework: IFramework, mainRenderTarget: ITexture2D) {
|
|
36
|
+
super(framework);
|
|
37
|
+
this._mainRenderTarget = mainRenderTarget as WebGpuTexture2D;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** @inheritDoc */
|
|
41
|
+
public readonly geometryFormat = GeometryFormat.POS3_TEXTURECOORDS2;
|
|
42
|
+
|
|
43
|
+
/** @inheritDoc */
|
|
44
|
+
public get mainRenderTarget(): ITexture2D {
|
|
45
|
+
return this._mainRenderTarget;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Sets the main render target and rebuilds the bind group. */
|
|
49
|
+
public set mainRenderTarget(value: ITexture2D) {
|
|
50
|
+
this._mainRenderTarget = value as WebGpuTexture2D;
|
|
51
|
+
this._bindGroup = null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** @inheritDoc */
|
|
55
|
+
public initialize(): void {
|
|
56
|
+
const module = this._framework.content.loadShaderModule("main_frame_buffer") as WebGpuShaderModule;
|
|
57
|
+
|
|
58
|
+
const geometry = this._framework.geometryBuilder.quadGeometry(vec2.fromValues(2, 2));
|
|
59
|
+
const data = geometry.toInterleaved(GeometryFormat.POS3_TEXTURECOORDS2);
|
|
60
|
+
this._vertexBuffer = this._framework.bufferFactory.createVertexBuffer(
|
|
61
|
+
data, (3 + 2) * Float32Array.BYTES_PER_ELEMENT, BufferUsage.VERTEX,
|
|
62
|
+
"Main Frame Buffer Render Pipeline Vertex Buffer") as WebGpuVertexBuffer;
|
|
63
|
+
this._indexBuffer = this._framework.bufferFactory.createIndexBuffer(
|
|
64
|
+
geometry.indices!, "Main Frame Buffer Render Pipeline Index Buffer") as WebGpuIndexBuffer;
|
|
65
|
+
|
|
66
|
+
this.vertexBufferLayouts = [VertexBufferLayout.createFloat3Float2Layout()];
|
|
67
|
+
|
|
68
|
+
this._bindGroupLayout = this._graphicsDevice.device.createBindGroupLayout({
|
|
69
|
+
label: "Main Frame Buffer bind group layout",
|
|
70
|
+
entries: [
|
|
71
|
+
{binding: 0, visibility: GpuShaderStage.FRAGMENT, texture: {sampleType: "float"}},
|
|
72
|
+
{binding: 1, visibility: GpuShaderStage.FRAGMENT, sampler: {type: "filtering"}},
|
|
73
|
+
],
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Drawn in the swap chain pass, which has no depth attachment.
|
|
77
|
+
this._createGpuPipeline(
|
|
78
|
+
"Main Frame Buffer Render Pipeline",
|
|
79
|
+
module.gpuShaderModule,
|
|
80
|
+
[this._bindGroupLayout],
|
|
81
|
+
this._graphicsDevice.swapChain?.textureFormat ?? this._framework.renderer.preferredTextureFormat);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private _getBindGroup(): GpuBindGroup {
|
|
85
|
+
if (!this._bindGroup) {
|
|
86
|
+
this._bindGroup = this._graphicsDevice.device.createBindGroup({
|
|
87
|
+
label: "Main Frame Buffer bind group",
|
|
88
|
+
layout: this._bindGroupLayout,
|
|
89
|
+
entries: [
|
|
90
|
+
{binding: 0, resource: this._mainRenderTarget.gpuDefaultView},
|
|
91
|
+
{binding: 1, resource: this._defaultTextureSampler.gpuSampler},
|
|
92
|
+
],
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return this._bindGroup;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** @inheritDoc */
|
|
99
|
+
public render(): void {
|
|
100
|
+
if (!this._gpuPipeline) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const encoder = this._graphicsDevice.renderPassEncoder;
|
|
104
|
+
encoder.setPipeline(this._gpuPipeline);
|
|
105
|
+
encoder.setVertexBuffer(0, this._vertexBuffer.gpuBuffer, 0, this._vertexBuffer.byteSize);
|
|
106
|
+
encoder.setIndexBuffer(this._indexBuffer.gpuBuffer, this._indexBuffer.gpuIndexFormat, 0, this._indexBuffer.paddedByteSize);
|
|
107
|
+
encoder.setBindGroup(0, this._getBindGroup());
|
|
108
|
+
encoder.drawIndexed(this._indexBuffer.indicesCount, 1, 0);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** @inheritDoc */
|
|
112
|
+
public override dispose(): void {
|
|
113
|
+
// ARenderer recreates this pipeline on every resize, so release the quad buffers too.
|
|
114
|
+
this._vertexBuffer?.dispose();
|
|
115
|
+
this._indexBuffer?.dispose();
|
|
116
|
+
this._bindGroup = null;
|
|
117
|
+
super.dispose();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ForwardBlinnPhongRenderPipelineDescriptor,
|
|
3
|
+
IForwardBlinnPhongRenderPipeline,
|
|
4
|
+
IFramework,
|
|
5
|
+
IInspectTextureMipsRenderPipeline,
|
|
6
|
+
IMainRenderTargetRenderPipeline,
|
|
7
|
+
IPrimitiveState,
|
|
8
|
+
IRenderPipelineFactory,
|
|
9
|
+
ISpriteRenderPipeline,
|
|
10
|
+
ITexture2D,
|
|
11
|
+
IUniformBuffer,
|
|
12
|
+
IUnlitRenderPipeline,
|
|
13
|
+
} from "../../api/index.ts";
|
|
14
|
+
import {WebGpuMainRenderTargetRenderPipeline} from "./WebGpuMainRenderTargetRenderPipeline.ts";
|
|
15
|
+
import {WebGpuUnlitRenderPipeline} from "./material/WebGpuUnlitRenderPipeline.ts";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The WebGPU render pipeline factory. Slice 1 implements the main render target and unlit pipelines.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export class WebGpuRenderPipelineFactory implements IRenderPipelineFactory {
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The constructor.
|
|
25
|
+
* @param _framework The framework.
|
|
26
|
+
*/
|
|
27
|
+
public constructor(private readonly _framework: IFramework) {
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @inheritDoc */
|
|
31
|
+
public createMainFrameBufferPipeline(mainFrameBuffer: ITexture2D): IMainRenderTargetRenderPipeline {
|
|
32
|
+
const pipeline = new WebGpuMainRenderTargetRenderPipeline(this._framework, mainFrameBuffer);
|
|
33
|
+
pipeline.initialize();
|
|
34
|
+
return pipeline;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Same as {@link createMainFrameBufferPipeline}, mirroring the WebGL factory. */
|
|
38
|
+
public createMainRenderTargetRenderPipeline(renderTarget: ITexture2D): IMainRenderTargetRenderPipeline {
|
|
39
|
+
return this.createMainFrameBufferPipeline(renderTarget);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** @inheritDoc */
|
|
43
|
+
public createUnlitRenderPipeline(projectionViewBuffer: IUniformBuffer,
|
|
44
|
+
modelBuffer: IUniformBuffer,
|
|
45
|
+
materialBuffer: IUniformBuffer,
|
|
46
|
+
primitiveState?: IPrimitiveState): IUnlitRenderPipeline {
|
|
47
|
+
const pipeline = new WebGpuUnlitRenderPipeline(this._framework, projectionViewBuffer, modelBuffer, materialBuffer, primitiveState);
|
|
48
|
+
pipeline.initialize();
|
|
49
|
+
return pipeline;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @inheritDoc */
|
|
53
|
+
public createSpriteRenderPipeline(_projectionViewBuffer: IUniformBuffer): ISpriteRenderPipeline {
|
|
54
|
+
throw new Error("The sprite render pipeline is not implemented for WebGPU.");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @inheritDoc */
|
|
58
|
+
public createInspectTextureMipsRenderPipeline(_projectionViewBuffer: IUniformBuffer, _modelBuffer: IUniformBuffer, _textureConstantsBuffer: IUniformBuffer): IInspectTextureMipsRenderPipeline {
|
|
59
|
+
throw new Error("The inspect texture mips render pipeline is not implemented for WebGPU.");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** @inheritDoc */
|
|
63
|
+
public createForwardBlinnPhongRenderPipeline(_descriptor: ForwardBlinnPhongRenderPipelineDescriptor): IForwardBlinnPhongRenderPipeline {
|
|
64
|
+
throw new Error("The forward Blinn-Phong render pipeline is not implemented for WebGPU.");
|
|
65
|
+
}
|
|
66
|
+
}
|