From: Jean-Philippe Bruyère Date: Fri, 31 Jan 2020 09:07:29 +0000 (+0100) Subject: update triangle readme X-Git-Tag: v0.1.21~12 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=411e9c33c63d191efb202881e9d8705c58b00b7d;p=jp%2Fvke.net.git update triangle readme --- diff --git a/samples/Triangle/README.md b/samples/Triangle/README.md index 35e3a72..07c2895 100644 --- a/samples/Triangle/README.md +++ b/samples/Triangle/README.md @@ -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 + + net472 + Exe + + + + + + + + + +``` + ### 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 (dev, VkBufferUsageFlags.VertexBuffer, vertices); + ibo = new HostBuffer (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 (); } ```