]> O.S.I.I.S - jp/vke.net.git/commitdiff
debug
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 1 Dec 2020 17:35:19 +0000 (18:35 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 1 Dec 2020 17:35:19 +0000 (18:35 +0100)
20 files changed:
.travis.yml
Directory.Build.props
addons/Directory.Build.props
samples/ClearScreen/README.md
samples/ClearScreen/main.cs
samples/DistanceFieldFontTest/Program.cs
samples/Textured/README.md
samples/Textured/main.cs
samples/TexturedCube/main.cs
samples/Triangle/README.md
samples/Triangle/main.cs
samples/deferred/main.cs
samples/pbr/PbrModel.cs [deleted file]
samples/pbr/PbrPipeline.cs
samples/pbr/main.cs
vke/src/FrameBuffers.cs
vke/src/VkWindow.cs
vke/src/base/Buffer.cs
vke/src/ktx.cs
vke/vke.csproj

index 9f6e04b5cd6e4f3d9d836afca91ca15e4e1d0d19..4996a9973bb8093298a187e2408141cd02fad31d 100644 (file)
@@ -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
index de2db9fe61b8ffe42ffb49d8b1b5637dd6f8998b..b09b8f84c6da0f521d2e9a4c737ae5f001de2fb2 100644 (file)
@@ -4,8 +4,8 @@
                <RestoreAdditionalProjectSources Condition="Exists('$(SolutionDir)build\$(Configuration)\')">$(SolutionDir)build\$(Configuration)\</RestoreAdditionalProjectSources>
                <SpirVTasksReleaseVersion>0.1.44</SpirVTasksReleaseVersion>
                <SpirVTasksPackageVersion>$(SpirVTasksReleaseVersion)</SpirVTasksPackageVersion>
-               <VkeReleaseVersion>0.1.21</VkeReleaseVersion>
-               <VkePackageVersion>$(VkeReleaseVersion)</VkePackageVersion>
+               <VkeReleaseVersion>0.2.0</VkeReleaseVersion>
+               <VkePackageVersion>$(VkeReleaseVersion)-beta</VkePackageVersion>
                <UseStbSharp>true</UseStbSharp>
                <UseMemoryPools>false</UseMemoryPools>
                <LangVersion>7.2</LangVersion>
index 30a526402c4d480efdd81c6d21ba8ef0bb1476fe..f8470f037c039e9e0854bc8e6c1848f7abba98bd 100644 (file)
                <RestoreAdditionalProjectSources Condition="Exists('$(SolutionDir)build\$(Configuration)\')">$(SolutionDir)build\$(Configuration)\</RestoreAdditionalProjectSources>
        </PropertyGroup>
     
-       <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">    
-               <DefineConstants>TRACE;DEBUG;NETSTANDARD;NETSTANDARD2_0;_WITH_SHADOWS;WITH_VKVG</DefineConstants>    
-       </PropertyGroup>
-       <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
-               <DefineConstants>NETSTANDARD;NETSTANDARD2_0;WITH_SHADOWS;_WITH_VKVG</DefineConstants>    
-       </PropertyGroup>        
-
        <ItemGroup Condition=" '$(Configuration)|$(Platform)' != 'BuildPackages|AnyCPU' ">
                <ProjectReference Include="..\..\vke\vke.csproj" />
        </ItemGroup>
index 8a342fd1fa8e50b5a67d0ebceba1621faace2111..3851d6106102b57d6b721f955900141db666dd6c 100644 (file)
@@ -4,8 +4,10 @@ To build a minimal vulkan application, add the [vke](https://www.nuget.org/packa
 
 ```xml
 <Project Sdk="Microsoft.NET.Sdk">
-    <TargetFrameworks>net472</TargetFrameworks>
-    <OutputType>Exe</OutputType>
+    <PropertyGroup>
+        <TargetFrameworks>net472</TargetFrameworks>
+        <OutputType>Exe</OutputType>
+    </PropertyGroup>
     <ItemGroup>    
         <GLSLShader Include="shaders\*.*" />           
     </ItemGroup>
@@ -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;
 
index 3e11384431d2732ab852a139e09b9a47ecf3efb9..c343e993d943491fec92872222acd3fa1350a645 100644 (file)
@@ -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;
 
index 52b55e02ae73a13780a699ff2dca47d106a100d9..feea78fb79a7975bb37c7d77ff8a604457b55859 100644 (file)
@@ -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) {
index 331e752e2f23e2a29144e99be273c215a036f7a6..ece9973c0ab128c010858a8170cba3b7af500d35 100644 (file)
@@ -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
index f2702d6e36e18ab43fb0eb58fe8eedb16d3c4c0d..a1237599cfe3f107abc98a79d304d749b7100f08 100644 (file)
@@ -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;
                        }
 
index 7be99eec726f8beeba1edea907d02d561d767cf3..b962e7ed08d4707fc2a102eef2ed999b457bf849 100644 (file)
@@ -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) {
index fc767145b62c04ccf1980cf970d91af6bd6b9ba1..f65858d94a1c1c2b01045bfc7911d6d8630b0b46 100644 (file)
@@ -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<Vertex> (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
index 12007df7707bc2ea214826c4fbf9519529d057b7..f962cb638c49438695561d851906cf0ae7de87a0 100644 (file)
@@ -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() {
index 4d4d044a515897664d30bbd9441925bb3ed5e72c..ff5e440cd2664709613bac9b499c2c36b3b2387b 100644 (file)
@@ -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 (file)
index a598f36..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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<Matrix4x4> ());
-                                       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);
-               }
-       }
-}
index 040fd62f5aff4ae23c5342f638cb7ba4ceb18da2..352c3058a4dec03625138d9048a144c27b6fe372 100644 (file)
@@ -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<Matrix4x4> ());
+                                               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<PbrModel2.Vertex> (0);
+                       cfg.AddVertexBinding<PbrModel.Vertex> (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,
index 6b979ca778b323c10a4737945b14bd32b6594f01..81eec97264c2028d088f079446a52f76b82f060a 100644 (file)
@@ -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) {
index 7b5a5674df21ecb2291659dbc246eb44b7ab933d..030962a1a39ec4506e227d502de25dba72779b14 100644 (file)
@@ -6,6 +6,9 @@ using System.Collections.ObjectModel;
 
 namespace vke
 {
+       /// <summary>
+       /// Collection of FrameBuffers, useful to handle multiple framebuffers for a swapchain.
+       /// </summary>
        public class FrameBuffers : Collection<FrameBuffer>, IDisposable
        {
                //public Framebuffer this[int index] => Items[index];
index 54424d8944e3a16fb74ead48759f4184db6d6643..fbfbedb51aa8b6d974e10067e5bc8aa5df72c80f 100644 (file)
@@ -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;
 
                /// <summary>readonly GLFW window handle</summary>
                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);
index aa250041a7b71b01d58ce08b3776fd38390e1071..263ed523c25a2018065ff962b892d0ad8ddd25b6 100644 (file)
@@ -115,7 +115,7 @@ namespace vke {
                /// <param name="dstOffset">an offset in the destination buffer for the copy operation.</param>
                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
                        };
index c9a8ccf7c30734b87f78856b6bedc69aa4de2b5f..2c38068c42dbe62f010aecc5e93bf238c811232a 100644 (file)
@@ -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)) {
index ac1dc33eb8bc90c8a1cb3c54877b36d66292ca87..734c8c58999af7baf8cd5d77dba0c89b2de11bbe 100644 (file)
@@ -51,7 +51,7 @@
                <PackageReference Include="SpirVTasks" Version="$(SpirVTasksPackageVersion)" />
                <PackageReference Include="Vulkan" Version="0.2.3-beta" />
                <PackageReference Include="shaderc.net" Version="0.1.0" />
-               <PackageReference Include="glfw-sharp" Version="0.2.6-beta" />
+               <PackageReference Include="glfw-sharp" Version="0.2.10-beta" />
        </ItemGroup>
        
        <ItemGroup>