traits: define as many traits as possible through native types

This commit is contained in:
Danny Robson 2017-09-08 17:56:04 +10:00
parent a24d0a7ab2
commit f7c54e0b9d
3 changed files with 42 additions and 42 deletions

View File

@ -42,12 +42,12 @@ std::vector<T>
cruft::vk::enumerated<T>::find (const instance &parent) {
// find the total number of objects
uint32_t expected = 0;
error::try_code (enum_traits<T>::enumerate (parent.native (), &expected, nullptr));
error::try_code (enum_traits<native_t<T>>::enumerate (parent.native (), &expected, nullptr));
// allocate an array of handles and fetch them
uint32_t found = expected;
native_t<T> handles[expected];
error::try_code (enum_traits<T>::enumerate (parent.native (), &found, handles));
error::try_code (enum_traits<native_t<T>>::enumerate (parent.native (), &found, handles));
// return an collection of objects from the handles
return std::vector<T> (handles, handles + found);

View File

@ -55,7 +55,7 @@ namespace cruft::vk {
root (Args &&...args):
object<SelfT> (
cruft::vk::error::try_query (
life_traits<SelfT>::create,
life_traits<native_t<SelfT>>::create,
std::forward<Args> (args)...
)
)
@ -63,7 +63,7 @@ namespace cruft::vk {
~root ()
{
life_traits<SelfT>::destroy (this->native (), nullptr);
life_traits<native_t<SelfT>>::destroy (this->native (), nullptr);
}
};
@ -77,7 +77,7 @@ namespace cruft::vk {
descendant (ParentT &parent, Args &&...args):
object<T> (
cruft::vk::error::try_query(
life_traits<T>::create,
life_traits<native_t<T>>::create,
parent.native (),
std::forward<Args> (args)...
)
@ -87,7 +87,7 @@ namespace cruft::vk {
~descendant ()
{
life_traits<T>::destroy (this->native (), nullptr);
life_traits<native_t<T>>::destroy (this->native (), nullptr);
}
};
@ -117,7 +117,7 @@ namespace cruft::vk {
owned (OwnerT &owner, Args &&...args):
object<SelfT> (
error::try_query (
life_traits<SelfT>::create,
life_traits<native_t<SelfT>>::create,
owner.native (),
std::forward<Args> (args)...
)
@ -142,7 +142,7 @@ namespace cruft::vk {
void
destroy (OwnerT &owner)
{
life_traits<SelfT>::destroy (owner.native (), this->native (), nullptr);
life_traits<native_t<SelfT>>::destroy (owner.native (), this->native (), nullptr);
this->m_native = VK_NULL_HANDLE;
}
};

View File

@ -93,24 +93,24 @@ namespace cruft::vk {
//-------------------------------------------------------------------------
template <> struct native_traits<instance> { using type = VkInstance; };
template <> struct native_traits<physical_device> { using type = VkPhysicalDevice; };
template <> struct native_traits<device> { using type = VkDevice; };
template <> struct native_traits<queue> { using type = VkQueue; };
template <> struct native_traits<command_pool> { using type = VkCommandPool; };
template <> struct native_traits<command_buffer> { using type = VkCommandBuffer; };
template <> struct native_traits<fence> { using type = VkFence; };
template <> struct native_traits<semaphore> { using type = VkSemaphore; };
template <> struct native_traits<event> { using type = VkEvent; };
template <> struct native_traits<render_pass> { using type = VkRenderPass; };
template <> struct native_traits<framebuffer> { using type = VkFramebuffer; };
template <> struct native_traits<shader_module> { using type = VkShaderModule; };
template <> struct native_traits<pipeline> { using type = VkPipeline; };
template <> struct native_traits<pipeline_cache> { using type = VkPipelineCache; };
template <> struct native_traits<device_memory> { using type = VkDeviceMemory; };
template <> struct native_traits<buffer> { using type = VkBuffer; };
template <> struct native_traits<buffer_view> { using type = VkBufferView; };
template <> struct native_traits<surface> { using type = VkSurfaceKHR; };
template <> struct native_traits<instance> { using type = VkInstance; };
template <> struct native_traits<physical_device> { using type = VkPhysicalDevice; };
template <> struct native_traits<device> { using type = VkDevice; };
template <> struct native_traits<queue> { using type = VkQueue; };
template <> struct native_traits<command_pool> { using type = VkCommandPool; };
template <> struct native_traits<command_buffer> { using type = VkCommandBuffer; };
template <> struct native_traits<fence> { using type = VkFence; };
template <> struct native_traits<semaphore> { using type = VkSemaphore; };
template <> struct native_traits<event> { using type = VkEvent; };
template <> struct native_traits<render_pass> { using type = VkRenderPass; };
template <> struct native_traits<framebuffer> { using type = VkFramebuffer; };
template <> struct native_traits<shader_module> { using type = VkShaderModule; };
template <> struct native_traits<pipeline> { using type = VkPipeline; };
template <> struct native_traits<pipeline_cache> { using type = VkPipelineCache; };
template <> struct native_traits<device_memory> { using type = VkDeviceMemory; };
template <> struct native_traits<buffer> { using type = VkBuffer; };
template <> struct native_traits<buffer_view> { using type = VkBufferView; };
template <> struct native_traits<surface> { using type = VkSurfaceKHR; };
//-------------------------------------------------------------------------
@ -149,57 +149,57 @@ namespace cruft::vk {
//-------------------------------------------------------------------------
template <> struct life_traits<instance> {
template <> struct life_traits<VkInstance> {
static constexpr auto& create = vkCreateInstance;
static constexpr auto& destroy = vkDestroyInstance;
};
template <> struct life_traits<device> {
template <> struct life_traits<VkDevice> {
static constexpr auto& create = vkCreateDevice;
static constexpr auto& destroy = vkDestroyDevice;
};
template <> struct life_traits<command_pool> {
template <> struct life_traits<VkCommandPool> {
static constexpr auto& create = vkCreateCommandPool;
static constexpr auto& destroy = vkDestroyCommandPool;
};
template <> struct life_traits<fence> {
template <> struct life_traits<VkFence> {
static constexpr auto& create = vkCreateFence;
static constexpr auto& destroy = vkDestroyFence;
};
template <> struct life_traits<semaphore> {
template <> struct life_traits<VkSemaphore> {
static constexpr auto& create = vkCreateSemaphore;
static constexpr auto& destroy = vkDestroySemaphore;
};
template <> struct life_traits<event> {
template <> struct life_traits<VkEvent> {
static constexpr auto& create = vkCreateEvent;
static constexpr auto& destroy = vkDestroyEvent;
};
template <> struct life_traits<render_pass> {
template <> struct life_traits<VkRenderPass> {
static constexpr auto& create = vkCreateRenderPass;
static constexpr auto& destroy = vkDestroyRenderPass;
};
template <> struct life_traits<framebuffer> {
template <> struct life_traits<VkFramebuffer> {
static constexpr auto& create = vkCreateFramebuffer;
static constexpr auto& destroy = vkDestroyFramebuffer;
};
template <> struct life_traits<shader_module> {
template <> struct life_traits<VkShaderModule> {
static constexpr auto& create = vkCreateShaderModule;
static constexpr auto& destroy = vkDestroyShaderModule;
};
template <> struct life_traits<surface> {
template <> struct life_traits<VkSurfaceKHR> {
static constexpr auto& destroy = vkDestroySurfaceKHR;
};
template <>
struct life_traits<queue> {
struct life_traits<VkQueue> {
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<pipeline_cache> {
template <> struct life_traits<VkPipelineCache> {
static constexpr auto& create = vkCreatePipelineCache;
static constexpr auto& destroy = vkDestroyPipelineCache;
};
template <> struct life_traits<device_memory> {
template <> struct life_traits<VkDeviceMemory> {
static constexpr auto& create = vkAllocateMemory;
static constexpr auto& destroy = vkFreeMemory;
};
template <> struct life_traits<buffer> {
template <> struct life_traits<VkBuffer> {
static constexpr auto& create = vkCreateBuffer;
static constexpr auto& destroy = vkDestroyBuffer;
};
template <> struct life_traits<buffer_view> {
template <> struct life_traits<VkBufferView> {
static constexpr auto& create = vkCreateBufferView;
};
@ -250,7 +250,7 @@ namespace cruft::vk {
/// describes the functions required to enumerate native types
template <typename> struct enum_traits { };
template <> struct enum_traits<physical_device> {
template <> struct enum_traits<VkPhysicalDevice> {
static constexpr auto enumerate = vkEnumeratePhysicalDevices;
};
}