From 24d2ddff19867c5ed4ee7d725f517c900daf0564 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Tue, 1 Dec 2020 18:35:19 +0100 Subject: [PATCH] debug --- .travis.yml | 2 +- Directory.Build.props | 4 +- addons/Directory.Build.props | 7 ---- samples/ClearScreen/README.md | 10 +++-- samples/ClearScreen/main.cs | 2 +- samples/DistanceFieldFontTest/Program.cs | 8 ++-- samples/Textured/README.md | 27 ++++++++---- samples/Textured/main.cs | 12 +++--- samples/TexturedCube/main.cs | 8 ++-- samples/Triangle/README.md | 10 ++--- samples/Triangle/main.cs | 14 +++---- samples/deferred/main.cs | 15 ++++--- samples/pbr/PbrModel.cs | 39 ------------------ samples/pbr/PbrPipeline.cs | 52 +++++++++++++++++------- samples/pbr/main.cs | 25 ++++++++---- vke/src/FrameBuffers.cs | 3 ++ vke/src/VkWindow.cs | 18 ++++---- vke/src/base/Buffer.cs | 2 +- vke/src/ktx.cs | 2 +- vke/vke.csproj | 2 +- 20 files changed, 127 insertions(+), 135 deletions(-) delete mode 100644 samples/pbr/PbrModel.cs diff --git a/.travis.yml b/.travis.yml index 9f6e04b..4996a99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ before_install: - wget -qO - http://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo apt-key add - - sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-bionic.list https://packages.lunarg.com/vulkan/lunarg-vulkan-bionic.list - sudo apt -qq update - - sudo apt install vulkan-sdk + - sudo apt -y install vulkan-sdk script: - dotnet build /p:Configuration=ReleaseSpirVTasks diff --git a/Directory.Build.props b/Directory.Build.props index de2db9f..b09b8f8 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,8 +4,8 @@ $(SolutionDir)build\$(Configuration)\ 0.1.44 $(SpirVTasksReleaseVersion) - 0.1.21 - $(VkeReleaseVersion) + 0.2.0 + $(VkeReleaseVersion)-beta true false 7.2 diff --git a/addons/Directory.Build.props b/addons/Directory.Build.props index 30a5264..f8470f0 100644 --- a/addons/Directory.Build.props +++ b/addons/Directory.Build.props @@ -21,13 +21,6 @@ $(SolutionDir)build\$(Configuration)\ - - TRACE;DEBUG;NETSTANDARD;NETSTANDARD2_0;_WITH_SHADOWS;WITH_VKVG - - - NETSTANDARD;NETSTANDARD2_0;WITH_SHADOWS;_WITH_VKVG - - diff --git a/samples/ClearScreen/README.md b/samples/ClearScreen/README.md index 8a342fd..3851d61 100644 --- a/samples/ClearScreen/README.md +++ b/samples/ClearScreen/README.md @@ -4,8 +4,10 @@ To build a minimal vulkan application, add the [vke](https://www.nuget.org/packa ```xml - net472 - Exe + + net472 + Exe + @@ -33,7 +35,7 @@ class Program : VkWindow { ### Vulkan Initialization -`initVulkan` is the first method called by the 'Run' method. Default initialization will provide a vulkan window, a default swap chain bound to it, and a draw and present semaphore to sync the rendering. +**`initVulkan`** is the first method called by the **'Run'** method. Default initialization will provide a vulkan window, a default swap chain bound to it, and a draw and present semaphore to sync the rendering. ```csharp protected override void initVulkan () { base.initVulkan (); @@ -52,7 +54,7 @@ Note that because we only reset the command buffers when rebuilding these, we ne ### Frame buffer creation -The resize method is called at least once before any rendering, so it's a safe place to initialize output size related vulkan objects like the frame buffers. vke provide a FrameBuffer collection object to ease handling of multiple related buffers like those used for a swap chain for example.. +The **`OnResize`** method is called at least once before any rendering, so it's a safe place to initialize output size related vulkan objects like the frame buffers. vke provide a FrameBuffer collection object to ease handling of multiple related buffers like those used for a swap chain for example.. ```csharp FrameBuffers frameBuffers; diff --git a/samples/ClearScreen/main.cs b/samples/ClearScreen/main.cs index 3e11384..c343e99 100644 --- a/samples/ClearScreen/main.cs +++ b/samples/ClearScreen/main.cs @@ -15,7 +15,7 @@ namespace ClearScreen { } } - //frame buffer collection to handle on fb per swapchain image. + //frame buffer collection to handle one frame buffer per swapchain image. FrameBuffers frameBuffers; RenderPass renderPass; diff --git a/samples/DistanceFieldFontTest/Program.cs b/samples/DistanceFieldFontTest/Program.cs index 52b55e0..feea78f 100644 --- a/samples/DistanceFieldFontTest/Program.cs +++ b/samples/DistanceFieldFontTest/Program.cs @@ -249,14 +249,14 @@ namespace DistanceFieldFontTest { protected override void onMouseMove (double xPos, double yPos) { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton[0]) { + if (GetButton (MouseButton.Left) == InputAction.Press) { rotY -= rotSpeed * (float)diffX; rotX += rotSpeed * (float)diffY; - } else if (MouseButton[1]) { + updateViewRequested = true; + } else if (GetButton (MouseButton.Right) == InputAction.Press) { zoom += zoomSpeed * (float)diffY; + updateViewRequested = true; } - - updateViewRequested = true; } protected override void onKeyDown (Key key, int scanCode, Modifier modifiers) { diff --git a/samples/Textured/README.md b/samples/Textured/README.md index 331e752..ece9973 100644 --- a/samples/Textured/README.md +++ b/samples/Textured/README.md @@ -1,25 +1,34 @@ ### Enabling extensions -The `VkWindow` class provides two properties that you may override to enable additional extensions. +The **`VkWindow`** class provides two properties that you may override to enable additional extensions. +```csharp +public override string[] EnabledInstanceExtensions => new string[] { + Ext.I.VK_EXT_debug_utils +}; +public override string[] EnabledDeviceExtensions => new string[] { + Ext.D.VK_KHR_swapchain, +}; +``` +Extension's names are organized in two subclasses of the `Ext` static class, one for the instance extensions (**`Ext.I`**) and one for the device ones (**`Ext.D`**). ### Enabling features -Override the `configureEnabledFeatures` method of `VkWindow` to enable features. +Override the **`configureEnabledFeatures`** method of **`VkWindow`** to enable features. This method is called just after +the physical device selection, available features list is automatically queried from it and provided as the first argument. ```csharp protected override void configureEnabledFeatures ( - VkPhysicalDeviceFeatures available_features, - ref VkPhysicalDeviceFeatures enabled_features) -{ - enabled_features.samplerAnisotropy = available_features.samplerAnisotropy; + VkPhysicalDeviceFeatures available_features, + ref VkPhysicalDeviceFeatures enabled_features) { + + enabled_features.samplerAnisotropy = available_features.samplerAnisotropy; } ``` ### Creating queues -To create queues, override the `createQueues` method of `VkWindow`. This function is called before the logical device creation and will take care of physically available queues, creating duplicates if count exceed availability. The `base` method will create a default presentable queue. +To create queues, override the **`createQueues`** method of **`VkWindow`**. This function is called before the logical device creation and will take care of physically available queues, creating duplicates if count exceed availability. The `base` method will create a default presentable queue. ```csharp protected override void createQueues () { base.createQueues (); transferQ = new Queue (dev, VkQueueFlags.Transfer); -} -``` \ No newline at end of file +} \ No newline at end of file diff --git a/samples/Textured/main.cs b/samples/Textured/main.cs index f2702d6..a123759 100644 --- a/samples/Textured/main.cs +++ b/samples/Textured/main.cs @@ -19,10 +19,10 @@ namespace Textured { vke.Run (); } } - protected override void configureEnabledFeatures (VkPhysicalDeviceFeatures available_features, ref VkPhysicalDeviceFeatures features) { - base.configureEnabledFeatures (available_features, ref features); - features.textureCompressionBC = available_features.textureCompressionBC; - features.textureCompressionASTC_LDR = available_features.textureCompressionASTC_LDR; + protected override void configureEnabledFeatures (VkPhysicalDeviceFeatures available_features, ref VkPhysicalDeviceFeatures enabled_features) { + base.configureEnabledFeatures (available_features, ref enabled_features); + enabled_features.textureCompressionBC = available_features.textureCompressionBC; + enabled_features.textureCompressionASTC_LDR = available_features.textureCompressionASTC_LDR; } float rotSpeed = 0.01f, zoomSpeed = 0.01f; @@ -198,10 +198,10 @@ namespace Textured { protected override void onMouseMove (double xPos, double yPos) { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton[0]) { + if (GetButton (MouseButton.Left) == InputAction.Press) { rotY -= rotSpeed * (float)diffX; rotX += rotSpeed * (float)diffY; - } else if (MouseButton[1]) { + } else if (GetButton (MouseButton.Right) == InputAction.Press) { zoom += zoomSpeed * (float)diffY; } diff --git a/samples/TexturedCube/main.cs b/samples/TexturedCube/main.cs index 7be99ee..b962e7e 100644 --- a/samples/TexturedCube/main.cs +++ b/samples/TexturedCube/main.cs @@ -229,14 +229,14 @@ namespace TextureCube { protected override void onMouseMove (double xPos, double yPos) { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton[0]) { + if (GetButton (MouseButton.Left) == InputAction.Press) { rotY -= rotSpeed * (float)diffX; rotX += rotSpeed * (float)diffY; - } else if (MouseButton[1]) { + updateViewRequested = true; + } else if (GetButton (MouseButton.Right) == InputAction.Press) { zoom += zoomSpeed * (float)diffY; + updateViewRequested = true; } - - updateViewRequested = true; } protected override void onKeyDown (Key key, int scanCode, Modifier modifiers) { diff --git a/samples/Triangle/README.md b/samples/Triangle/README.md index fc76714..f65858d 100644 --- a/samples/Triangle/README.md +++ b/samples/Triangle/README.md @@ -1,6 +1,6 @@ ### Creating buffers -Vke has two classes to handle buffers. Mappable [`HostBuffer`](../../wiki/api/HostBuffer) and device only [`GPUBuffer`](../../wiki/api/GPUBuffer). +Vke has two classes to handle buffers. Mappable [`HostBuffer`](../../../../wiki/vke.HostBuffer) and device only [`GPUBuffer`](../../../../wiki/vke.GPUBuffer). For this first simple example, we will only use host mappable buffers. Those classes can handle a Generic argument of a blittable type to handle arrays. Resources like buffers or images are activated in constructor, and they need to be explicitly disposed on cleanup. Create them in the `initVulkan` override. ```csharp @@ -16,7 +16,7 @@ To be able to access the mvp matrix in a shader, we need a descriptor. This impl ```csharp descriptorPool = new DescriptorPool (dev, 1, new VkDescriptorPoolSize (VkDescriptorType.UniformBuffer)); ``` -Graphic pipeline configuration are predefined by the [`GraphicPipelineConfig`](../../wiki/api/GraphicPipelineConfig) class, which ease sharing configs for several pipelines having lots in common. The pipeline layout will be automatically activated on pipeline creation, so that sharing layout among different pipelines will benefit from the reference counting to automatically dispose unused layout on pipeline clean up. It's the same for [`DescriptorSetLayout`](../../wiki/api/DescriptorSetLayout). +Graphic pipeline configuration are predefined by the [`GraphicPipelineConfig`](../../../../wiki/vke.GraphicPipelineConfig) class, which ease sharing configs for several pipelines having lots in common. The pipeline layout will be automatically activated on pipeline creation, so that sharing layout among different pipelines will benefit from the reference counting to automatically dispose unused layout on pipeline clean up. It's the same for [`DescriptorSetLayout`](../../wiki/api/DescriptorSetLayout). ```csharp GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault ( VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1, false); @@ -26,7 +26,7 @@ cfg.Layout = new PipelineLayout (dev, new VkDescriptorSetLayoutBinding ( 0, VkShaderStageFlags.Vertex, VkDescriptorType.UniformBuffer))); ``` -Next we configure a default [`RenderPass`](../../wiki/api/RenderPass) with just a color attachment for the swap chain image, a default sub-pass is automatically created and the render pass activation will follow the pipeline life cycle and will be automatically disposed when no longer in use. +Next we configure a default [`RenderPass`](../../../../wiki/vke.RenderPass) with just a color attachment for the swap chain image, a default sub-pass is automatically created and the render pass activation will follow the pipeline life cycle and will be automatically disposed when no longer in use. ```csharp cfg.RenderPass = new RenderPass (dev, swapChain.ColorFormat, cfg.Samples); ``` @@ -36,7 +36,7 @@ cfg.AddVertexBinding (0); cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, //position VkFormat.R32g32b32Sfloat);//color ``` -shader are automatically compiled by [`SpirVTacks`](../../SpirVTasks/README.md) if added to the project. The resulting shaders are automatically embedded in the assembly. To specifiy that the shader path is a resource name, put the **'#'** prefix. Else the path will be search on disk. +shader are automatically compiled by [`SpirVTasks`](../../SpirVTasks/README.md) if added to the project. The resulting shaders are automatically embedded in the assembly. To specifiy that the shader path is a resource name, put the **'#'** prefix. Else the path will be search on disk. ```csharp cfg.AddShader (VkShaderStageFlags.Vertex, "#shaders.main.vert.spv"); cfg.AddShader (VkShaderStageFlags.Fragment, "#shaders.main.frag.spv"); @@ -49,7 +49,7 @@ Because descriptor layouts used for a pipeline are only activated on pipeline ac ```csharp descriptorSet = descriptorPool.Allocate (pipeline.Layout.DescriptorSetLayouts[0]); ``` -The descriptor update is a two step operation. First we create a [`DescriptorSetWrites`](../../wiki/api/DescriptorSetWrites) object defining the layout(s), than we write the descriptor(s). +The descriptor update is a two step operation. First we create a [`DescriptorSetWrites`](../../../../wiki/vke.DescriptorSetWrites) object defining the layout(s), than we write the descriptor(s). The `Descriptor` property of the mvp HostBuffer will return a default descriptor with no offset of the full size of the buffer. ```csharp diff --git a/samples/Triangle/main.cs b/samples/Triangle/main.cs index 12007df..f962cb6 100644 --- a/samples/Triangle/main.cs +++ b/samples/Triangle/main.cs @@ -4,9 +4,9 @@ using System; using System.Numerics; using System.Runtime.InteropServices; -//using System.Text; using vke; using Vulkan; +using Glfw; //the traditional triangle sample namespace Triangle { @@ -119,16 +119,14 @@ namespace Triangle { protected override void onMouseMove (double xPos, double yPos) { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton [0]) { + if (GetButton (MouseButton.Left) == InputAction.Press) { rotY -= rotSpeed * (float)diffX; rotX += rotSpeed * (float)diffY; - } else if (MouseButton [1]) { + updateViewRequested = true; + } else if (GetButton (MouseButton.Right) == InputAction.Press) { zoom += zoomSpeed * (float)diffY; - } else - return; - //VkWindow has a boolean for requesting a call to 'UpdateView', it will be - //reset by the 'UpdateView' base method or the custom override. - updateViewRequested = true; + updateViewRequested = true; + } } void buildCommandBuffers() { diff --git a/samples/deferred/main.cs b/samples/deferred/main.cs index 4d4d044..ff5e440 100644 --- a/samples/deferred/main.cs +++ b/samples/deferred/main.cs @@ -22,7 +22,7 @@ namespace deferred { #endif SwapChain.PREFERED_FORMAT = VkFormat.B8g8r8a8Srgb; DeferredPbrRenderer.TEXTURE_ARRAY = true; - DeferredPbrRenderer.NUM_SAMPLES = VkSampleCountFlags.SampleCount1; + DeferredPbrRenderer.NUM_SAMPLES = VkSampleCountFlags.SampleCount4; DeferredPbrRenderer.HDR_FORMAT = VkFormat.R32g32b32a32Sfloat; DeferredPbrRenderer.MRT_FORMAT = VkFormat.R32g32b32a32Sfloat; @@ -222,14 +222,13 @@ namespace deferred { protected override void onMouseMove (double xPos, double yPos) { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton[0]) { - camera.Rotate ((float)-diffY, (float)-diffX, 0); - } else if (MouseButton[1]) { + if (GetButton (MouseButton.Left) == InputAction.Press) { + camera.Rotate ((float)-diffY, (float)-diffX); + updateViewRequested = true; + } else if (GetButton (MouseButton.Right) == InputAction.Press) { camera.SetZoom ((float)diffY); - } else - return; - - updateViewRequested = true; + updateViewRequested = true; + } } protected override void onKeyDown (Key key, int scanCode, Modifier modifiers) { switch (key) { diff --git a/samples/pbr/PbrModel.cs b/samples/pbr/PbrModel.cs deleted file mode 100644 index a598f36..0000000 --- a/samples/pbr/PbrModel.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2019 Jean-Philippe Bruyère -// -// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -using System.Numerics; -using System.Runtime.InteropServices; - -using Vulkan; - -namespace vke { - using vke.glTF; - - - //TODO:stride in buffer views? - public class PbrModel2 : PbrModelSeparatedTextures { - public PbrModel2 (Queue transferQ, string path, DescriptorSetLayout layout, params AttachmentType[] attachments) - : base (transferQ, path, layout, attachments) {} - - //TODO:destset for binding must be variable - //TODO: ADD REFAULT MAT IF NO MAT DEFINED - public override void RenderNode (CommandBuffer cmd, PipelineLayout pipelineLayout, Node node, Matrix4x4 currentTransform, bool shadowPass = false) { - Matrix4x4 localMat = node.localMatrix * currentTransform; - - cmd.PushConstant (pipelineLayout, VkShaderStageFlags.Vertex, localMat); - - if (node.Mesh != null) { - foreach (Primitive p in node.Mesh.Primitives) { - cmd.PushConstant (pipelineLayout, VkShaderStageFlags.Fragment, (int)p.material, (uint)Marshal.SizeOf ()); - if (descriptorSets[p.material] != null) - cmd.BindDescriptorSet (pipelineLayout, descriptorSets[p.material], 1); - cmd.DrawIndexed (p.indexCount, 1, p.indexBase, p.vertexBase, 0); - } - } - if (node.Children == null) - return; - foreach (Node child in node.Children) - RenderNode (cmd, pipelineLayout, child, localMat); - } - } -} diff --git a/samples/pbr/PbrPipeline.cs b/samples/pbr/PbrPipeline.cs index 040fd62..352c305 100644 --- a/samples/pbr/PbrPipeline.cs +++ b/samples/pbr/PbrPipeline.cs @@ -5,11 +5,40 @@ using System; using System.Numerics; using System.Runtime.InteropServices; +using vke; +using vke.glTF; +using vke.Environment; using Vulkan; -namespace vke { +namespace pbrSample +{ class PBRPipeline : GraphicPipeline { - + public class PbrModel : PbrModelSeparatedTextures + { + public PbrModel (Queue transferQ, string path, DescriptorSetLayout layout, params AttachmentType[] attachments) + : base (transferQ, path, layout, attachments) { } + + //TODO:destset for binding must be variable + //TODO: ADD REFAULT MAT IF NO MAT DEFINED + public override void RenderNode (CommandBuffer cmd, PipelineLayout pipelineLayout, Node node, Matrix4x4 currentTransform, bool shadowPass = false) { + Matrix4x4 localMat = node.localMatrix * currentTransform; + + cmd.PushConstant (pipelineLayout, VkShaderStageFlags.Vertex, localMat); + + if (node.Mesh != null) { + foreach (Primitive p in node.Mesh.Primitives) { + cmd.PushConstant (pipelineLayout, VkShaderStageFlags.Fragment, (int)p.material, (uint)Marshal.SizeOf ()); + if (descriptorSets[p.material] != null) + cmd.BindDescriptorSet (pipelineLayout, descriptorSets[p.material], 1); + cmd.DrawIndexed (p.indexCount, 1, p.indexBase, p.vertexBase, 0); + } + } + if (node.Children == null) + return; + foreach (Node child in node.Children) + RenderNode (cmd, pipelineLayout, child, localMat); + } + } public struct Matrices { public Matrix4x4 projection; public Matrix4x4 model; @@ -41,16 +70,9 @@ namespace vke { DescriptorSetLayout descLayoutTextures; public DescriptorSet dsMain; - public PbrModel2 model; - public vke.Environment.EnvironmentCube envCube; - string[] cubemapPathes = { - Utils.DataDirectory + "textures/papermill.ktx", - Utils.DataDirectory + "textures/cubemap_yokohama_bc3_unorm.ktx", - Utils.DataDirectory + "textures/gcanyon_cube.ktx", - Utils.DataDirectory + "textures/pisa_cube.ktx", - Utils.DataDirectory + "textures/uffizi_cube.ktx", - }; - public PBRPipeline (Queue staggingQ, RenderPass renderPass, PipelineCache pipelineCache = null) : + public PbrModel model; + public EnvironmentCube envCube; + public PBRPipeline (Queue staggingQ, RenderPass renderPass, string cubeMapPath, PipelineCache pipelineCache = null) : base (renderPass, pipelineCache, "pbr pipeline") { descriptorPool = new DescriptorPool (Dev, 2, @@ -80,7 +102,7 @@ namespace vke { new VkPushConstantRange (VkShaderStageFlags.Fragment, sizeof(int), 64) ); cfg.RenderPass = renderPass; - cfg.AddVertexBinding (0); + cfg.AddVertexBinding (0); cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat, VkFormat.R32g32Sfloat); cfg.AddShader (Dev, VkShaderStageFlags.Vertex, "#shaders.pbr.vert.spv"); @@ -94,7 +116,7 @@ namespace vke { dsMain = descriptorPool.Allocate (descLayoutMain); - envCube = new Environment.EnvironmentCube (cubemapPathes[0], layout, staggingQ, RenderPass); + envCube = new EnvironmentCube (cubeMapPath, layout, staggingQ, RenderPass); matrices.prefilteredCubeMipLevels = envCube.prefilterCube.CreateInfo.mipLevels; uboMats = new HostBuffer (Dev, VkBufferUsageFlags.UniformBuffer, matrices, true); @@ -110,7 +132,7 @@ namespace vke { public void LoadModel (Queue staggingQ, string path) { model?.Dispose (); - model = new PbrModel2 (staggingQ, path, descLayoutTextures, + model = new PbrModel (staggingQ, path, descLayoutTextures, AttachmentType.Color, AttachmentType.PhysicalProps, AttachmentType.Normal, diff --git a/samples/pbr/main.cs b/samples/pbr/main.cs index 6b979ca..81eec97 100644 --- a/samples/pbr/main.cs +++ b/samples/pbr/main.cs @@ -26,7 +26,7 @@ namespace pbrSample { vke.Run (); } } - VkSampleCountFlags samples = VkSampleCountFlags.SampleCount1; + VkSampleCountFlags samples = VkSampleCountFlags.SampleCount4; FrameBuffers frameBuffers; PBRPipeline pbrPipeline; @@ -48,6 +48,14 @@ namespace pbrSample { Utils.DataDirectory + "models/MER_static.glb", Utils.DataDirectory + "models/Box.gltf", }; + string[] cubemapPathes = { + Utils.DataDirectory + "textures/papermill.ktx", + Utils.DataDirectory + "textures/cubemap_yokohama_bc3_unorm.ktx", + Utils.DataDirectory + "textures/gcanyon_cube.ktx", + Utils.DataDirectory + "textures/pisa_cube.ktx", + Utils.DataDirectory + "textures/uffizi_cube.ktx", + }; + DebugView currentDebugView = DebugView.none; @@ -64,7 +72,7 @@ namespace pbrSample { camera.SetPosition (0, 0, -2); pbrPipeline = new PBRPipeline (presentQueue, - new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), samples)); + new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), samples), cubemapPathes[0]); loadCurrentModel (); } @@ -147,14 +155,13 @@ namespace pbrSample { protected override void onMouseMove (double xPos, double yPos) { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton[0]) { - camera.Rotate ((float)-diffY, (float)-diffX,0); - } else if (MouseButton[1]) { + if (GetButton (MouseButton.Left) == InputAction.Press) { + camera.Rotate ((float)-diffY, (float)-diffX); + updateViewRequested = true; + } else if (GetButton (MouseButton.Right) == InputAction.Press) { camera.SetZoom ((float)diffY); - } else - return; - - updateViewRequested = true; + updateViewRequested = true; + } } protected override void onKeyDown (Key key, int scanCode, Modifier modifiers) { diff --git a/vke/src/FrameBuffers.cs b/vke/src/FrameBuffers.cs index 7b5a567..030962a 100644 --- a/vke/src/FrameBuffers.cs +++ b/vke/src/FrameBuffers.cs @@ -6,6 +6,9 @@ using System.Collections.ObjectModel; namespace vke { + /// + /// Collection of FrameBuffers, useful to handle multiple framebuffers for a swapchain. + /// public class FrameBuffers : Collection, IDisposable { //public Framebuffer this[int index] => Items[index]; diff --git a/vke/src/VkWindow.cs b/vke/src/VkWindow.cs index 54424d8..fbfbedb 100644 --- a/vke/src/VkWindow.cs +++ b/vke/src/VkWindow.cs @@ -41,15 +41,13 @@ namespace vke { protected bool updateViewRequested = true; protected double lastMouseX { get; private set; } protected double lastMouseY { get; private set; } - protected bool[] MouseButton => buttons; /// readonly GLFW window handle public IntPtr WindowHandle => hWin; /**Default camera initialized with a Field of view of 40° and and aspect ratio of 1. */ protected Camera camera = new Camera (Utils.DegreesToRadians (45f), 1f); - - bool[] buttons = new bool[10]; + public Modifier KeyModifiers = 0; IntPtr currentCursor; uint frameCount; @@ -233,10 +231,10 @@ namespace vke { protected virtual void onMouseMove (double xPos, double yPos) { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton[(int)Glfw.MouseButton.Left]) { + if (GetButton(MouseButton.Left) == InputAction.Press) { camera.Rotate ((float)-diffX, (float)-diffY); updateViewRequested = true; - } else if (MouseButton[(int)Glfw.MouseButton.Right]) { + } else if (GetButton(MouseButton.Right) == InputAction.Press) { camera.Move ((float)diffX,0,0); camera.Move (0, 0, (float)-diffY); updateViewRequested = true; @@ -283,6 +281,9 @@ namespace vke { protected virtual void onKeyUp (Key key, int scanCode, Modifier modifiers) { } protected virtual void onChar (CodePoint cp) { } + protected InputAction GetButton (MouseButton button) => + Glfw3.GetMouseButton (hWin, button); + #region events delegates static CursorPosDelegate HandleCursorPosDelegate = (window, xPosition, yPosition) => { @@ -291,13 +292,10 @@ namespace vke { windows[window].lastMouseY = yPosition; }; static MouseButtonDelegate HandleMouseButtonDelegate = (IntPtr window, Glfw.MouseButton button, InputAction action, Modifier mods) => { - if (action == InputAction.Press) { - windows[window].buttons[(int)button] = true; + if (action == InputAction.Press) windows[window].onMouseButtonDown (button); - } else { - windows[window].buttons[(int)button] = false; + else windows[window].onMouseButtonUp (button); - } }; static ScrollDelegate HandleScrollDelegate = (IntPtr window, double xOffset, double yOffset) => { windows[window].onScroll (xOffset, yOffset); diff --git a/vke/src/base/Buffer.cs b/vke/src/base/Buffer.cs index aa25004..263ed52 100644 --- a/vke/src/base/Buffer.cs +++ b/vke/src/base/Buffer.cs @@ -115,7 +115,7 @@ namespace vke { /// an offset in the destination buffer for the copy operation. public void CopyTo (CommandBuffer cmd, Buffer buff, ulong size = 0, ulong srcOffset = 0, ulong dstOffset = 0) { VkBufferCopy bufferCopy = new VkBufferCopy { - size = (size == 0) ? AllocatedDeviceMemorySize : size, + size = (size == 0) ? createInfo.size : size, srcOffset = srcOffset, dstOffset = dstOffset }; diff --git a/vke/src/ktx.cs b/vke/src/ktx.cs index c9a8ccf..2c38068 100644 --- a/vke/src/ktx.cs +++ b/vke/src/ktx.cs @@ -97,7 +97,7 @@ namespace KTX { uint blockSize = blockW * blockH; if (memoryProperty.HasFlag (VkMemoryPropertyFlags.DeviceLocal)) { - ulong staggingSize = (ulong)ktxStream.Length + 256;//img.AllocatedDeviceMemorySize; + ulong staggingSize = img.AllocatedDeviceMemorySize; Console.WriteLine ($"KtxStream size = {ktxStream.Length}, img Allocation = {img.AllocatedDeviceMemorySize}"); using (HostBuffer stagging = new HostBuffer (staggingQ.Dev, VkBufferUsageFlags.TransferSrc, staggingSize)) { diff --git a/vke/vke.csproj b/vke/vke.csproj index ac1dc33..734c8c5 100644 --- a/vke/vke.csproj +++ b/vke/vke.csproj @@ -51,7 +51,7 @@ - + -- 2.47.3