]> O.S.I.I.S - jp/vke.net.git/commitdiff
update triangle readme
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 31 Jan 2020 09:07:29 +0000 (10:07 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 31 Jan 2020 09:07:29 +0000 (10:07 +0100)
samples/Triangle/README.md

index 35e3a72a1d9c63c45cd942f9381c3da469b1d4d1..07c2895e017200b966b0c99535f97e04063d1a89 100644 (file)
@@ -1,30 +1,67 @@
-
+### The Project File.
+
+To build a minimal vulkan application, add the [vke](https://www.nuget.org/packages/vke/) nuget package, and to enable automatic shader compilation, add the [SpirVTasks](https://www.nuget.org/packages/SpirVTasks/) package and a generic **GLSLShader** item globing a full directory.
+
+```xml
+<Project Sdk="Microsoft.NET.Sdk">
+    <TargetFrameworks>net472</TargetFrameworks>
+    <OutputType>Exe</OutputType>
+    <ItemGroup>    
+        <GLSLShader Include="shaders\*.*" />           
+    </ItemGroup>
+    <ItemGroup>
+        <PackageReference Include="SpirVTasks" />
+        <PackageReference Include="vke" />
+    </ItemGroup>
+</Project>
+
+```
+
 ### VkWindow class
 
-To create a new vulkan application, derrive your application from `VkWindow`. Validation and
-debug reports may be activated with the static Fields of the `Instance` class.
+**vke** use [GLFW](https://www.glfw.org/) to interface with the windowing system of the OS. Derive your application from the `VkWindow` base class to start with a vulkan enabled window. **Validation** and **RenderDoc** layers loading may be control at startup with public static boolean properties from the `Instance`class.
 
 ```csharp
 class Program : VkWindow {
        static void Main (string[] args) {
-               Instance.VALIDATION = true;
-               
+               Instance.VALIDATION = true;             
                using (Program vke = new Program ()) {
                        vke.Run ();
                }
        }
 }
 ```
+### Vulkan Initialization
+
+Default vulkan initialization of the VkWindow class will provide the minimal for running and present simple command buffers. For further initialization steps, override the `init_vulkan`method.
+
+```csharp
+protected override void initVulkan () {
+   base.initVulkan ();
+   vbo = new HostBuffer<Vertex> (dev, VkBufferUsageFlags.VertexBuffer, vertices);
+   ibo = new HostBuffer<ushort> (dev, VkBufferUsageFlags.IndexBuffer, indices);
+   uboMats = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, matrices);   
+   ...
+```
 ### 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. The `Ext` static class of the vulkan package provides up to date lists of existing vulkan extensions for convenience.
+
+```csharp
+public virtual string[] EnabledInstanceExtensions => null;
+public virtual string[] EnabledDeviceExtensions =>
+    new string[] { Ext.D.VK_KHR_swapchain };
+```
 
 ### Enabling features
 
-Override the `configureEnabledFeatures` method of `VkWindow` to enable features.
+Override the `configureEnabledFeatures` method of `VkWindow` to enable features. Available features queried from the selected physical device are provided as argument.
 ```csharp
-protected override void configureEnabledFeatures (VkPhysicalDeviceFeatures available_features, ref VkPhysicalDeviceFeatures enabled_features) {
-       enabled_features.samplerAnisotropy = available_features.samplerAnisotropy;
+protected override void configureEnabledFeatures (
+    VkPhysicalDeviceFeatures available_features,
+    ref VkPhysicalDeviceFeatures enabled_features) {
+    
+       enabled_features.samplerAnisotropy = available_features.samplerAnisotropy;    
 }
 ```
 ### Creating queues
@@ -39,30 +76,17 @@ protected override void createQueues () {
 ```
 ### Rendering
 
-The constructor of the `VkWIndow` will finish the vulkan initialisation, so that you may create pipelines, buffers, and so on in your constructor.
-
-VkWindow will provide the default swapchain, but it's up to you to create the frame buffers. For the triangle example, create them in the `OnResize` override.
+VkWindow will provide the default swapchain, but it's up to you to create the frame buffers. For the triangle example, create them in the `OnResize` override. The `RenderPass` class has the ability to create a framebuffer collection for a given swapchain. The `OnResize` method is guarantied to be called once before entering the rendering loop, so that it is a safe place to call the building of your command buffers.
 ```csharp
-Framebuffer[] frameBuffers;
+FrameBuffers frameBuffers;
 
 protected override void OnResize () {
-       if (frameBuffers != null)
-               for (int i = 0; i < swapChain.ImageCount; ++i)
-                       frameBuffers[i]?.Dispose ();
-       frameBuffers = new Framebuffer[swapChain.ImageCount];
-
-       for (int i = 0; i < swapChain.ImageCount; ++i) 
-               frameBuffers[i] = new Framebuffer (pipeline.RenderPass, swapChain.Width, swapChain.Height,
-                       (pipeline.Samples == VkSampleCountFlags.SampleCount1) ? new Image[] {
-                               swapChain.images[i],
-                               null
-                       } : new Image[] {
-                               null,
-                               null,
-                               swapChain.images[i]
-                       });
-
-       buildCommandBuffers ();
+       base.OnResize ();
+
+       frameBuffers?.Dispose();
+       frameBuffers = pipeline.RenderPass.CreateFrameBuffers(swapChain);
+
+    buildCommandBuffers ();
 }
 ```