diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2019-08-02 20:57:22 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2019-08-02 20:57:22 +0200 |
| commit | 1956ca6301c5a28fd4d943085205d6a699d008ee (patch) | |
| tree | e3fc2f8fb91330051afa6e9d3de951244bda7aaa | |
| parent | 8cb89e9ad7babc587f57445f29b61d06aeb60513 (diff) | |
debug marker, divers
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | samples/Triangle/main.cs | 2 | ||||
| -rw-r--r-- | samples/common/CrowWin.cs | 6 | ||||
| -rw-r--r-- | samples/deferred/deferred.csproj | 2 | ||||
| -rw-r--r-- | samples/deferred/deferredPbrRenderer.cs | 2 | ||||
| -rw-r--r-- | samples/deferred/main-crow.cs | 14 | ||||
| -rw-r--r-- | samples/deferred/main.cs | 3 | ||||
| -rw-r--r-- | samples/pbr/PbrModel.cs | 2 | ||||
| -rw-r--r-- | samples/pbr/main.cs | 2 | ||||
| -rw-r--r-- | samples/vkvg_tests/main.cs | 2 | ||||
| -rw-r--r-- | vke/src/Activable.cs | 27 | ||||
| -rw-r--r-- | vke/src/CommandBuffer.cs | 10 | ||||
| -rw-r--r-- | vke/src/Device.cs | 25 | ||||
| -rw-r--r-- | vke/src/ExtensionMethods.cs | 14 | ||||
| -rw-r--r-- | vke/src/Instance.cs | 2 | ||||
| -rw-r--r-- | vke/src/MarshaledObject.cs | 3 | ||||
| -rw-r--r-- | vke/src/MemoryPool.cs | 2 | ||||
| -rw-r--r-- | vke/src/SwapChain.cs | 11 | ||||
| -rw-r--r-- | vke/src/VkWindow.cs | 31 | ||||
| -rw-r--r-- | vke/src/glfw/Glfw3.cs | 28 | ||||
| -rw-r--r-- | vke/src/model/glTFLoader.cs | 7 |
21 files changed, 132 insertions, 65 deletions
@@ -15,7 +15,7 @@ Autogenerated low level Vulkan c# binding. This project starts as a fork of the The nuget package is available under the name **Vulkan**. <p align="center"> <a href="https://github.com/jpbruyere/vk.net/blob/master/samples/pbr/screenshot.png"> - <kbd><img src="https://github.com/jpbruyere/vk.net/blob/master/samples/pbr/screenshot.png" height="300"></kbd> + <kbd><img src="https://raw.githubusercontent.com/jpbruyere/vk.net/master/samples/pbr/screenshot.png" height="300"></kbd> </a> <br>Port of the gltfPBR from Sacha Willems</br> </p> diff --git a/samples/Triangle/main.cs b/samples/Triangle/main.cs index 6a3fe5b..27f9838 100644 --- a/samples/Triangle/main.cs +++ b/samples/Triangle/main.cs @@ -52,7 +52,7 @@ namespace Triangle { }; ushort[] indices = new ushort[] { 0, 1, 2 }; - Program () : base (false) { + Program () : base () { vbo = new HostBuffer<Vertex> (dev, VkBufferUsageFlags.VertexBuffer, vertices); ibo = new HostBuffer<ushort> (dev, VkBufferUsageFlags.IndexBuffer, indices); uboMats = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, matrices); diff --git a/samples/common/CrowWin.cs b/samples/common/CrowWin.cs index ae3ca71..42cf2cd 100644 --- a/samples/common/CrowWin.cs +++ b/samples/common/CrowWin.cs @@ -25,8 +25,8 @@ namespace Crow { protected CVKL.Image uiImage; protected bool isRunning; - protected CrowWin (bool debugMarkers = false, string name = "CrowWin", uint _width = 1024, uint _height = 768, bool vSync = false) : - base (debugMarkers, name, _width, _height, vSync) { + protected CrowWin (string name = "CrowWin", uint _width = 1024, uint _height = 768, bool vSync = false) : + base (name, _width, _height, vSync) { Thread crowThread = new Thread (crow_thread_func); crowThread.IsBackground = true; @@ -87,7 +87,7 @@ namespace Crow { } void crow_thread_func () { - vkvgDev = new vkvg.Device (instance.Handle, phy.Handle, dev.VkDev.Handle, presentQueue.qFamIndex, + vkvgDev = new vkvg.Device (instance.Handle, phy.Handle, dev.Handle, presentQueue.qFamIndex, vkvg.SampleCount.Sample_4, presentQueue.index); crow = new Interface (vkvgDev, (int)swapChain.Width, (int)swapChain.Height); diff --git a/samples/deferred/deferred.csproj b/samples/deferred/deferred.csproj index 8ee850e..ae60085 100644 --- a/samples/deferred/deferred.csproj +++ b/samples/deferred/deferred.csproj @@ -30,7 +30,7 @@ </Datas> <Compile Include="EnvironmentPipeline.cs;deferredPbrRenderer.cs;shadowMapRenderer.cs" /> </ItemGroup> - + <ItemGroup Condition="'$(Configuration)' == 'DebugCrow' "> <Compile Include="../common/CrowWin.cs" /> <Compile Include="main-crow.cs" /> diff --git a/samples/deferred/deferredPbrRenderer.cs b/samples/deferred/deferredPbrRenderer.cs index d954c0f..d4c1ccb 100644 --- a/samples/deferred/deferredPbrRenderer.cs +++ b/samples/deferred/deferredPbrRenderer.cs @@ -14,7 +14,7 @@ namespace deferred { public static VkSampleCountFlags NUM_SAMPLES = VkSampleCountFlags.SampleCount1; public static VkFormat HDR_FORMAT = VkFormat.R32g32b32a32Sfloat; public static VkFormat MRT_FORMAT = VkFormat.R32g32b32a32Sfloat; - public static bool TEXTURE_ARRAY = false; + public static bool TEXTURE_ARRAY; public enum DebugView { none, diff --git a/samples/deferred/main-crow.cs b/samples/deferred/main-crow.cs index 6fa200e..8f9e3e4 100644 --- a/samples/deferred/main-crow.cs +++ b/samples/deferred/main-crow.cs @@ -11,9 +11,9 @@ namespace deferred { static void Main (string[] args) { Instance.DEBUG_UTILS = true; Instance.VALIDATION = true; - //Instance.RenderDocCapture = true; + Instance.RENDER_DOC_CAPTURE = true; DeferredPbrRenderer.TEXTURE_ARRAY = true; - PbrModelTexArray.TEXTURE_DIM = 512; + PbrModelTexArray.TEXTURE_DIM = 1024; using (Program vke = new Program ()) { vke.Run (); @@ -75,6 +75,11 @@ namespace deferred { public List<Model.Scene> Scenes => renderer.model.Scenes; #endregion + public override string[] EnabledDeviceExtensions => new string[] { + Ext.D.VK_KHR_swapchain, + Ext.D.VK_EXT_debug_marker + }; + protected override void configureEnabledFeatures (VkPhysicalDeviceFeatures available_features, ref VkPhysicalDeviceFeatures features) { base.configureEnabledFeatures (available_features, ref features); @@ -108,6 +113,7 @@ namespace deferred { }; string[] modelPathes = { //"/mnt/devel/gts/vkChess.net/data/models/chess.glb", + //"/home/jp/gltf/jaguar/scene.gltf", "data/models/DamagedHelmet/glTF/DamagedHelmet.gltf", "data/models/shadow.glb", "data/models/Hubble.glb", @@ -126,7 +132,7 @@ namespace deferred { DebugReport dbgRepport; - Program () : base(true) { + Program () : base() { if (Instance.DEBUG_UTILS) dbgRepport = new DebugReport (instance, @@ -155,6 +161,8 @@ namespace deferred { init_crow_commands (); crow.Load ("#deferred.menu.crow").DataSource = this; + + } protected override void recordDraw (CommandBuffer cmd, int imageIndex) { diff --git a/samples/deferred/main.cs b/samples/deferred/main.cs index 6a6eb1b..dacd9e5 100644 --- a/samples/deferred/main.cs +++ b/samples/deferred/main.cs @@ -11,6 +11,7 @@ namespace deferred { Instance.VALIDATION = true; Instance.DEBUG_UTILS = true; //Instance.RENDER_DOC_CAPTURE = true; + DeferredPbrRenderer.TEXTURE_ARRAY = true; DeferredPbrRenderer.NUM_SAMPLES = VkSampleCountFlags.SampleCount4; @@ -59,7 +60,7 @@ namespace deferred { DebugReport dbgRepport; - Deferred () : base(true) { + Deferred () : base() { if (Instance.DEBUG_UTILS) dbgRepport = new DebugReport (instance, diff --git a/samples/pbr/PbrModel.cs b/samples/pbr/PbrModel.cs index b7e117a..575f283 100644 --- a/samples/pbr/PbrModel.cs +++ b/samples/pbr/PbrModel.cs @@ -37,7 +37,7 @@ namespace CVKL { //TODO:stride in buffer views? public class PbrModel2 : Model { - public struct Vertex { + public new struct Vertex { [VertexAttribute (VertexAttributeType.Position, VkFormat.R32g32b32Sfloat)] public Vector3 pos; [VertexAttribute (VertexAttributeType.Normal, VkFormat.R32g32b32Sfloat)] diff --git a/samples/pbr/main.cs b/samples/pbr/main.cs index d8e0590..53c6342 100644 --- a/samples/pbr/main.cs +++ b/samples/pbr/main.cs @@ -196,7 +196,7 @@ namespace pbrSample { camera.SetPosition (0, 0, 5); - vkvgDev = new vkvg.Device (instance.Handle, phy.Handle, dev.VkDev.Handle, presentQueue.qFamIndex, + vkvgDev = new vkvg.Device (instance.Handle, phy.Handle, dev.Handle, presentQueue.qFamIndex, vkvg.SampleCount.Sample_4, presentQueue.index); initUISurface (); diff --git a/samples/vkvg_tests/main.cs b/samples/vkvg_tests/main.cs index 9bae346..42c018b 100644 --- a/samples/vkvg_tests/main.cs +++ b/samples/vkvg_tests/main.cs @@ -142,7 +142,7 @@ namespace vkvg_test { } void uiThreadFunc () { - vkvgDev = new vkvg.Device (instance.Handle, phy.Handle, dev.VkDev.Handle, presentQueue.qFamIndex, + vkvgDev = new vkvg.Device (instance.Handle, phy.Handle, dev.Handle, presentQueue.qFamIndex, vkvg.SampleCount.Sample_8, presentQueue.index); while (true) { diff --git a/vke/src/Activable.cs b/vke/src/Activable.cs index a98f780..b77443c 100644 --- a/vke/src/Activable.cs +++ b/vke/src/Activable.cs @@ -28,7 +28,23 @@ using VK; using static VK.Vk; namespace CVKL { - public enum ActivableState { Init, Activated, Disposed }; + /// <summary> + /// Tristate status of activables, reflecting vulkan openrations + /// </summary> + public enum ActivableState { + /// <summary> + /// Class has been instanced, but no vulkan handle was created. + /// </summary> + Init, + /// <summary> + /// On the first activation, vulkan handle is created and ref count is one. Further activations will increment the reference count by one. + /// </summary> + Activated, + /// <summary> + /// Reference count is zero, handles have been destroyed. Such object may be reactivated. + /// </summary> + Disposed + }; /// <summary> /// Base class for most of the vulkan device's objects following the IDispose pattern. Each time an activable is used, it's reference count is incremented, and /// each time it is disposed, the count is decremented. When the count reach zero, the handle is destroyed and the finalizizer is unregistered. Once disposed, the @@ -51,7 +67,7 @@ namespace CVKL { /// <value>The debug marker info.</value> protected abstract VkDebugMarkerObjectNameInfoEXT DebugMarkerInfo { get; } /// <summary> - /// Vulkan logical device this activable is bound to + /// Vulkan logical device this activable is bound to. /// </summary> public Device Dev { get; private set; } @@ -65,13 +81,14 @@ namespace CVKL { this.name = name; } #endregion + /// <summary> /// if debug marker extension is activated, this will set the name for debuggers /// </summary> public void SetName (string name) { this.name = name; - if (!Dev.DebugMarkersEnabled) + if (!Dev.debugMarkersEnabled) return; VkDebugMarkerObjectNameInfoEXT dmo = DebugMarkerInfo; @@ -83,10 +100,12 @@ namespace CVKL { /// Activation of the object, the reference count is incremented. /// </summary> public virtual void Activate () { + references++; + if (state == ActivableState.Activated) + return; if (state == ActivableState.Disposed) GC.ReRegisterForFinalize (this); state = ActivableState.Activated; - references++; SetName (name); } diff --git a/vke/src/CommandBuffer.cs b/vke/src/CommandBuffer.cs index ac55e48..825ff4d 100644 --- a/vke/src/CommandBuffer.cs +++ b/vke/src/CommandBuffer.cs @@ -38,11 +38,11 @@ namespace CVKL { CommandPool pool; VkCommandBuffer handle; - States state; + //States state; public VkCommandBuffer Handle => handle; public Device Device => pool?.Dev;//this help - public States State => state; + //public States State => state; internal CommandBuffer (VkDevice _dev, CommandPool _pool, VkCommandBuffer _buff) { @@ -139,7 +139,7 @@ namespace CVKL { } public void BeginRegion (string name, float r = 1f, float g = 0.1f, float b=0.1f, float a = 1f) { - if (!Device.DebugMarkersEnabled) + if (!Device.debugMarkersEnabled) return; VkDebugMarkerMarkerInfoEXT info = VkDebugMarkerMarkerInfoEXT.New(); info.pMarkerName = name.Pin (); @@ -153,7 +153,7 @@ namespace CVKL { name.Unpin (); } public void InsertDebugMarker (string name, float r = 1f, float g = 0.1f, float b=0.1f, float a = 1f) { - if (!Device.DebugMarkersEnabled) + if (!Device.debugMarkersEnabled) return; VkDebugMarkerMarkerInfoEXT info = VkDebugMarkerMarkerInfoEXT.New(); info.pMarkerName = name.Pin (); @@ -167,7 +167,7 @@ namespace CVKL { name.Unpin (); } public void EndRegion () { - if (Device.DebugMarkersEnabled) + if (Device.debugMarkersEnabled) vkCmdDebugMarkerEndEXT (Handle); } diff --git a/vke/src/Device.cs b/vke/src/Device.cs index 3c29f2c..811f446 100644 --- a/vke/src/Device.cs +++ b/vke/src/Device.cs @@ -34,20 +34,25 @@ using static VK.Vk; namespace CVKL { + /// <summary> + /// Logical device encapsulating vulkan logical device handle. Implements only IDisposable an do not derive from + /// Activable, so it may be activated only once and no reference counting on it is handled, and no reactivation is posible + /// after being disposed. + /// </summary> public class Device : IDisposable { public readonly PhysicalDevice phy; - public readonly bool DebugMarkersEnabled; VkDevice dev; public VkDevice VkDev => dev; + public IntPtr Handle => dev.Handle; internal List<Queue> queues = new List<Queue> (); + internal bool debugMarkersEnabled; public ResourceManager resourceManager; - public Device (PhysicalDevice _phy, bool enableDebugMarkers = false) { + public Device (PhysicalDevice _phy) { phy = _phy; - DebugMarkersEnabled = enableDebugMarkers; } public void Activate (VkPhysicalDeviceFeatures enabledFeatures, params string[] extensions) { @@ -79,12 +84,16 @@ namespace CVKL { prioritiesLists.Add (priorities);//add for unpined } + //enable only supported exceptions List<IntPtr> deviceExtensions = new List<IntPtr> (); - if (DebugMarkersEnabled && !extensions.Contains (Ext.D.VK_EXT_debug_marker)) - deviceExtensions.Add (new FixedUtf8String (Ext.D.VK_EXT_debug_marker)); - - for (int i = 0; i < extensions.Length; i++) - deviceExtensions.Add (new FixedUtf8String (extensions[i])); + for (int i = 0; i < extensions.Length; i++) { + if (phy.GetDeviceExtensionSupported (extensions[i])) { + deviceExtensions.Add (new FixedUtf8String (extensions[i])); + //store in a bool to prevent frequent string test for debug marker ext presence + if (extensions[i] == Ext.D.VK_EXT_debug_marker) + debugMarkersEnabled = true; + } + } VkDeviceCreateInfo deviceCreateInfo = VkDeviceCreateInfo.New (); deviceCreateInfo.queueCreateInfoCount = (uint)qInfos.Count; diff --git a/vke/src/ExtensionMethods.cs b/vke/src/ExtensionMethods.cs index c731f33..d63fc8b 100644 --- a/vke/src/ExtensionMethods.cs +++ b/vke/src/ExtensionMethods.cs @@ -99,7 +99,7 @@ namespace CVKL { } public static void SetDebugMarkerName (this VkCommandBuffer obj, Device dev, string name) { - if (!dev.DebugMarkersEnabled) + if (!dev.debugMarkersEnabled) return; VkDebugMarkerObjectNameInfoEXT dmo = new VkDebugMarkerObjectNameInfoEXT (VkDebugReportObjectTypeEXT.CommandBufferEXT, (ulong)obj.Handle.ToInt64 ()) { pObjectName = name.Pin () }; @@ -107,7 +107,7 @@ namespace CVKL { name.Unpin (); } public static void SetDebugMarkerName (this VkImageView obj, Device dev, string name) { - if (!dev.DebugMarkersEnabled) + if (!dev.debugMarkersEnabled) return; VkDebugMarkerObjectNameInfoEXT dmo = new VkDebugMarkerObjectNameInfoEXT (VkDebugReportObjectTypeEXT.ImageViewEXT, obj.Handle) { pObjectName = name.Pin () }; @@ -115,7 +115,7 @@ namespace CVKL { name.Unpin (); } public static void SetDebugMarkerName (this VkSampler obj, Device dev, string name) { - if (!dev.DebugMarkersEnabled) + if (!dev.debugMarkersEnabled) return; VkDebugMarkerObjectNameInfoEXT dmo = new VkDebugMarkerObjectNameInfoEXT (VkDebugReportObjectTypeEXT.SamplerEXT, obj.Handle) { pObjectName = name.Pin () }; @@ -123,7 +123,7 @@ namespace CVKL { name.Unpin (); } public static void SetDebugMarkerName (this VkPipeline obj, Device dev, string name) { - if (!dev.DebugMarkersEnabled) + if (!dev.debugMarkersEnabled) return; VkDebugMarkerObjectNameInfoEXT dmo = new VkDebugMarkerObjectNameInfoEXT (VkDebugReportObjectTypeEXT.PipelineEXT, obj.Handle) { pObjectName = name.Pin () }; @@ -131,7 +131,7 @@ namespace CVKL { name.Unpin (); } public static void SetDebugMarkerName (this VkDescriptorSet obj, Device dev, string name) { - if (!dev.DebugMarkersEnabled) + if (!dev.debugMarkersEnabled) return; VkDebugMarkerObjectNameInfoEXT dmo = new VkDebugMarkerObjectNameInfoEXT (VkDebugReportObjectTypeEXT.DescriptorSetEXT, obj.Handle) { pObjectName = name.Pin () }; @@ -139,7 +139,7 @@ namespace CVKL { name.Unpin (); } public static void SetDebugMarkerName (this VkSemaphore obj, Device dev, string name) { - if (!dev.DebugMarkersEnabled) + if (!dev.debugMarkersEnabled) return; VkDebugMarkerObjectNameInfoEXT dmo = new VkDebugMarkerObjectNameInfoEXT (VkDebugReportObjectTypeEXT.SemaphoreEXT, obj.Handle) { pObjectName = name.Pin () }; @@ -147,7 +147,7 @@ namespace CVKL { name.Unpin (); } public static void SetDebugMarkerName (this VkFence obj, Device dev, string name) { - if (!dev.DebugMarkersEnabled) + if (!dev.debugMarkersEnabled) return; VkDebugMarkerObjectNameInfoEXT dmo = new VkDebugMarkerObjectNameInfoEXT (VkDebugReportObjectTypeEXT.FenceEXT, obj.Handle) { pObjectName = name.Pin () }; diff --git a/vke/src/Instance.cs b/vke/src/Instance.cs index b4bcca0..199bbdb 100644 --- a/vke/src/Instance.cs +++ b/vke/src/Instance.cs @@ -36,7 +36,7 @@ namespace CVKL { public class Instance : IDisposable { /// <summary>If true, the VK_LAYER_KHRONOS_validation layer is loaded at startup; </summary> public static bool VALIDATION; - /// <summary>If true, the VK_EXT_debug_utils and VK_EXT_debug_report device extensions are enabled</summary> + /// <summary>If true, the VK_EXT_debug_utils and VK_EXT_debug_report instance extensions are enabled</summary> public static bool DEBUG_UTILS; /// <summary>If true, the VK_LAYER_RENDERDOC_Capture layer is loaded at startup; </summary> public static bool RENDER_DOC_CAPTURE; diff --git a/vke/src/MarshaledObject.cs b/vke/src/MarshaledObject.cs index 6d3beb7..6116071 100644 --- a/vke/src/MarshaledObject.cs +++ b/vke/src/MarshaledObject.cs @@ -46,7 +46,8 @@ namespace CVKL { void freeHandle () { if (!disposed) handle.Free (); - } + disposed = true; + } #region IDisposable Support private bool disposed; diff --git a/vke/src/MemoryPool.cs b/vke/src/MemoryPool.cs index 71b2d38..b9532ab 100644 --- a/vke/src/MemoryPool.cs +++ b/vke/src/MemoryPool.cs @@ -21,7 +21,7 @@ namespace CVKL { //Resource mappedFrom; //Resource mappedTo; - ulong freeMemPointer; + //ulong freeMemPointer; IntPtr mappedPointer; public ulong Size => memInfo.allocationSize; diff --git a/vke/src/SwapChain.cs b/vke/src/SwapChain.cs index 5473c93..d691ea8 100644 --- a/vke/src/SwapChain.cs +++ b/vke/src/SwapChain.cs @@ -28,8 +28,10 @@ using VK; using static VK.Vk; namespace CVKL { - public class SwapChain : Activable { - internal VkSwapchainKHR handle; + public class SwapChain : Activable { + public static VkImageUsageFlags IMAGES_USAGE = VkImageUsageFlags.ColorAttachment; + + internal VkSwapchainKHR handle; internal uint currentImageIndex; VkSwapchainCreateInfoKHR createInfos; @@ -48,7 +50,8 @@ namespace CVKL { public VkFormat ColorFormat => createInfos.imageFormat; public VkImageUsageFlags ImageUsage => createInfos.imageUsage; - public SwapChain (PresentQueue _presentableQueue, uint width = 800, uint height = 600, VkFormat format = VkFormat.B8g8r8a8Unorm, VkPresentModeKHR presentMode = VkPresentModeKHR.FifoKHR) + public SwapChain (PresentQueue _presentableQueue, uint width = 800, uint height = 600, VkFormat format = VkFormat.B8g8r8a8Unorm, + VkPresentModeKHR presentMode = VkPresentModeKHR.FifoKHR) : base (_presentableQueue.dev){ presentQueue = _presentableQueue; @@ -78,7 +81,7 @@ namespace CVKL { createInfos.surface = presentQueue.Surface; createInfos.imageExtent = new VkExtent2D (width, height); createInfos.imageArrayLayers = 1; - createInfos.imageUsage = VkImageUsageFlags.ColorAttachment; + createInfos.imageUsage = IMAGES_USAGE; createInfos.imageSharingMode = VkSharingMode.Exclusive; createInfos.compositeAlpha = VkCompositeAlphaFlagsKHR.OpaqueKHR; createInfos.presentMode = presentMode; diff --git a/vke/src/VkWindow.cs b/vke/src/VkWindow.cs index 15d4697..96abc1b 100644 --- a/vke/src/VkWindow.cs +++ b/vke/src/VkWindow.cs @@ -29,6 +29,7 @@ using System.Diagnostics; using Glfw; using VK; using static VK.Vk; +using System.Collections.Generic; namespace CVKL { /// <summary> @@ -51,7 +52,7 @@ namespace CVKL { protected VkSemaphore[] drawComplete; protected uint fps; - protected bool updateViewRequested = true, rebuildBuffers = false; + protected bool updateViewRequested = true, rebuildBuffers; protected double lastMouseX, lastMouseY; protected bool[] MouseButton => buttons; @@ -70,11 +71,8 @@ namespace CVKL { /// <summary> /// Override this property to change the list of enabled extensions /// </summary> - public virtual string[] EnabledExtensions { - get { - return new string[] { Ext.D.VK_KHR_swapchain }; - } - } + public virtual string[] EnabledDeviceExtensions => new string[] { Ext.D.VK_KHR_swapchain }; + /// <summary> /// Frequency in millisecond of the call to the Update method /// </summary> @@ -83,7 +81,9 @@ namespace CVKL { public uint Width => width; public uint Height => height; - public VkWindow (bool debugMarkers = false, string name = "VkWindow", uint _width = 1024, uint _height = 768, bool vSync = false) { + IntPtr handCursor; + + public VkWindow (string name = "VkWindow", uint _width = 1024, uint _height = 768, bool vSync = false) { currentWindow = this; width = _width; @@ -96,6 +96,9 @@ namespace CVKL { hWin = Glfw3.CreateWindow ((int)width, (int)height, name, MonitorHandle.Zero, IntPtr.Zero); + if (hWin == IntPtr.Zero) + throw new Exception ("[GLFW3] Unable to create vulkan Window"); + Glfw3.SetKeyCallback (hWin, HandleKeyDelegate); Glfw3.SetMouseButtonPosCallback (hWin, HandleMouseButtonDelegate); Glfw3.SetCursorPosCallback (hWin, HandleCursorPosDelegate); @@ -103,10 +106,14 @@ namespace CVKL { Glfw3.SetScrollCallback (hWin, HandleScrollDelegate); Glfw3.SetCharCallback (hWin, HandleCharDelegate); - initVulkan (vSync, debugMarkers); + initVulkan (vSync); + + handCursor = Glfw3.CreateStandardCursor (CursorShape.Hand); + + Glfw3.SetCursor (hWin, handCursor); } - void initVulkan (bool vSync, bool debugMarkers) { + void initVulkan (bool vSync) { instance = new Instance (); hSurf = instance.CreateSurface (hWin); @@ -116,15 +123,13 @@ namespace CVKL { VkPhysicalDeviceFeatures enabledFeatures = default (VkPhysicalDeviceFeatures); configureEnabledFeatures (phy.Features, ref enabledFeatures); - if (debugMarkers) - debugMarkers = phy.GetDeviceExtensionSupported (Ext.D.VK_EXT_debug_marker); //First create the c# device class - dev = new Device (phy, debugMarkers); + dev = new Device (phy); //create queue class createQueues (); //activate the device to have effective queues created accordingly to what's available - dev.Activate (enabledFeatures, EnabledExtensions); + dev.Activate (enabledFeatures, EnabledDeviceExtensions); swapChain = new SwapChain (presentQueue as PresentQueue, width, height, VkFormat.B8g8r8a8Srgb, vSync ? VkPresentModeKHR.FifoKHR : VkPresentModeKHR.MailboxKHR); diff --git a/vke/src/glfw/Glfw3.cs b/vke/src/glfw/Glfw3.cs index 432dbbd..27e7497 100644 --- a/vke/src/glfw/Glfw3.cs +++ b/vke/src/glfw/Glfw3.cs @@ -4,10 +4,19 @@ using System.Runtime.InteropServices; namespace Glfw { - /// <summary> - /// Interop functions for the GLFW3 API. - /// </summary> - public unsafe static class Glfw3 + public enum CursorShape + { + Arrow = 0x00036001, + IBeam = 0x00036002, + Crosshair = 0x00036003, + Hand = 0x00036004, + HResize = 0x00036005, + VResize = 0x00036006 + } + /// <summary> + /// Interop functions for the GLFW3 API. + /// </summary> + public unsafe static class Glfw3 { /// <summary> /// The base name for the GLFW3 library. @@ -512,5 +521,14 @@ namespace Glfw return new Version(major, minor, revision); } - } + + [DllImport (GlfwDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "glfwCreateStandardCursor")] + public static extern IntPtr CreateStandardCursor (CursorShape shape); + + [DllImport (GlfwDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "glfwDestroyCursor")] + public static extern void DestroyCursor (IntPtr cursor); + + [DllImport (GlfwDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "glfwSetCursor")] + public static extern void SetCursor (IntPtr window, IntPtr cursor); + } } diff --git a/vke/src/model/glTFLoader.cs b/vke/src/model/glTFLoader.cs index d21ff61..88d29f5 100644 --- a/vke/src/model/glTFLoader.cs +++ b/vke/src/model/glTFLoader.cs @@ -383,7 +383,7 @@ namespace CVKL { ///// build texture array ///// </summary> ///// <returns>The images.</returns> - ///// <param name="textureSize">Texture size.</param> + ///// <param name="textureSize">Uniformized Texture size for all images</param> public void BuildTexArray (ref Image texArray, uint firstImg = 0) { int texDim = (int)texArray.CreateInfo.extent.width; @@ -468,7 +468,10 @@ namespace CVKL { transferQ.WaitIdle (); cmd.Free (); } - + /// <summary> + /// Load model images as separate texture in a c# array + /// </summary> + /// <returns>The images.</returns> public Image[] LoadImages () { if (gltf.Images == null) return new Image[] {}; |