From f7c54e0b9d3f54365adfb552df74d8f6cebe8ab9 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 8 Sep 2017 17:56:04 +1000 Subject: [PATCH] traits: define as many traits as possible through native types --- object.cpp | 4 ++-- object.hpp | 12 +++++----- traits.hpp | 68 +++++++++++++++++++++++++++--------------------------- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/object.cpp b/object.cpp index e60713e..0811ba8 100644 --- a/object.cpp +++ b/object.cpp @@ -42,12 +42,12 @@ std::vector cruft::vk::enumerated::find (const instance &parent) { // find the total number of objects uint32_t expected = 0; - error::try_code (enum_traits::enumerate (parent.native (), &expected, nullptr)); + error::try_code (enum_traits>::enumerate (parent.native (), &expected, nullptr)); // allocate an array of handles and fetch them uint32_t found = expected; native_t handles[expected]; - error::try_code (enum_traits::enumerate (parent.native (), &found, handles)); + error::try_code (enum_traits>::enumerate (parent.native (), &found, handles)); // return an collection of objects from the handles return std::vector (handles, handles + found); diff --git a/object.hpp b/object.hpp index 7d8d385..4251cee 100644 --- a/object.hpp +++ b/object.hpp @@ -55,7 +55,7 @@ namespace cruft::vk { root (Args &&...args): object ( cruft::vk::error::try_query ( - life_traits::create, + life_traits>::create, std::forward (args)... ) ) @@ -63,7 +63,7 @@ namespace cruft::vk { ~root () { - life_traits::destroy (this->native (), nullptr); + life_traits>::destroy (this->native (), nullptr); } }; @@ -77,7 +77,7 @@ namespace cruft::vk { descendant (ParentT &parent, Args &&...args): object ( cruft::vk::error::try_query( - life_traits::create, + life_traits>::create, parent.native (), std::forward (args)... ) @@ -87,7 +87,7 @@ namespace cruft::vk { ~descendant () { - life_traits::destroy (this->native (), nullptr); + life_traits>::destroy (this->native (), nullptr); } }; @@ -117,7 +117,7 @@ namespace cruft::vk { owned (OwnerT &owner, Args &&...args): object ( error::try_query ( - life_traits::create, + life_traits>::create, owner.native (), std::forward (args)... ) @@ -142,7 +142,7 @@ namespace cruft::vk { void destroy (OwnerT &owner) { - life_traits::destroy (owner.native (), this->native (), nullptr); + life_traits>::destroy (owner.native (), this->native (), nullptr); this->m_native = VK_NULL_HANDLE; } }; diff --git a/traits.hpp b/traits.hpp index c055dac..30d13fd 100644 --- a/traits.hpp +++ b/traits.hpp @@ -93,24 +93,24 @@ namespace cruft::vk { //------------------------------------------------------------------------- - template <> struct native_traits { using type = VkInstance; }; - template <> struct native_traits { using type = VkPhysicalDevice; }; - template <> struct native_traits { using type = VkDevice; }; - template <> struct native_traits { using type = VkQueue; }; - template <> struct native_traits { using type = VkCommandPool; }; - template <> struct native_traits { using type = VkCommandBuffer; }; - template <> struct native_traits { using type = VkFence; }; - template <> struct native_traits { using type = VkSemaphore; }; - template <> struct native_traits { using type = VkEvent; }; - template <> struct native_traits { using type = VkRenderPass; }; - template <> struct native_traits { using type = VkFramebuffer; }; - template <> struct native_traits { using type = VkShaderModule; }; - template <> struct native_traits { using type = VkPipeline; }; - template <> struct native_traits { using type = VkPipelineCache; }; - template <> struct native_traits { using type = VkDeviceMemory; }; - template <> struct native_traits { using type = VkBuffer; }; - template <> struct native_traits { using type = VkBufferView; }; - template <> struct native_traits { using type = VkSurfaceKHR; }; + template <> struct native_traits { using type = VkInstance; }; + template <> struct native_traits { using type = VkPhysicalDevice; }; + template <> struct native_traits { using type = VkDevice; }; + template <> struct native_traits { using type = VkQueue; }; + template <> struct native_traits { using type = VkCommandPool; }; + template <> struct native_traits { using type = VkCommandBuffer; }; + template <> struct native_traits { using type = VkFence; }; + template <> struct native_traits { using type = VkSemaphore; }; + template <> struct native_traits { using type = VkEvent; }; + template <> struct native_traits { using type = VkRenderPass; }; + template <> struct native_traits { using type = VkFramebuffer; }; + template <> struct native_traits { using type = VkShaderModule; }; + template <> struct native_traits { using type = VkPipeline; }; + template <> struct native_traits { using type = VkPipelineCache; }; + template <> struct native_traits { using type = VkDeviceMemory; }; + template <> struct native_traits { using type = VkBuffer; }; + template <> struct native_traits { using type = VkBufferView; }; + template <> struct native_traits { using type = VkSurfaceKHR; }; //------------------------------------------------------------------------- @@ -149,57 +149,57 @@ namespace cruft::vk { //------------------------------------------------------------------------- - template <> struct life_traits { + template <> struct life_traits { static constexpr auto& create = vkCreateInstance; static constexpr auto& destroy = vkDestroyInstance; }; - template <> struct life_traits { + template <> struct life_traits { static constexpr auto& create = vkCreateDevice; static constexpr auto& destroy = vkDestroyDevice; }; - template <> struct life_traits { + template <> struct life_traits { static constexpr auto& create = vkCreateCommandPool; static constexpr auto& destroy = vkDestroyCommandPool; }; - template <> struct life_traits { + template <> struct life_traits { static constexpr auto& create = vkCreateFence; static constexpr auto& destroy = vkDestroyFence; }; - template <> struct life_traits { + template <> struct life_traits { static constexpr auto& create = vkCreateSemaphore; static constexpr auto& destroy = vkDestroySemaphore; }; - template <> struct life_traits { + template <> struct life_traits { static constexpr auto& create = vkCreateEvent; static constexpr auto& destroy = vkDestroyEvent; }; - template <> struct life_traits { + template <> struct life_traits { static constexpr auto& create = vkCreateRenderPass; static constexpr auto& destroy = vkDestroyRenderPass; }; - template <> struct life_traits { + template <> struct life_traits { static constexpr auto& create = vkCreateFramebuffer; static constexpr auto& destroy = vkDestroyFramebuffer; }; - template <> struct life_traits { + template <> struct life_traits { static constexpr auto& create = vkCreateShaderModule; static constexpr auto& destroy = vkDestroyShaderModule; }; - template <> struct life_traits { + template <> struct life_traits { static constexpr auto& destroy = vkDestroySurfaceKHR; }; template <> - struct life_traits { + struct life_traits { static constexpr auto& create = vkGetDeviceQueue; static constexpr auto destroy = ::util::tuple::ignore< @@ -226,22 +226,22 @@ namespace cruft::vk { // static constexpr auto destroy = vkDestroyPipeline; //}; - template <> struct life_traits { + template <> struct life_traits { static constexpr auto& create = vkCreatePipelineCache; static constexpr auto& destroy = vkDestroyPipelineCache; }; - template <> struct life_traits { + template <> struct life_traits { static constexpr auto& create = vkAllocateMemory; static constexpr auto& destroy = vkFreeMemory; }; - template <> struct life_traits { + template <> struct life_traits { static constexpr auto& create = vkCreateBuffer; static constexpr auto& destroy = vkDestroyBuffer; }; - template <> struct life_traits { + template <> struct life_traits { static constexpr auto& create = vkCreateBufferView; }; @@ -250,7 +250,7 @@ namespace cruft::vk { /// describes the functions required to enumerate native types template struct enum_traits { }; - template <> struct enum_traits { + template <> struct enum_traits { static constexpr auto enumerate = vkEnumeratePhysicalDevices; }; }