traits: define as many traits as possible through native types
This commit is contained in:
parent
a24d0a7ab2
commit
f7c54e0b9d
@ -42,12 +42,12 @@ std::vector<T>
|
|||||||
cruft::vk::enumerated<T>::find (const instance &parent) {
|
cruft::vk::enumerated<T>::find (const instance &parent) {
|
||||||
// find the total number of objects
|
// find the total number of objects
|
||||||
uint32_t expected = 0;
|
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
|
// allocate an array of handles and fetch them
|
||||||
uint32_t found = expected;
|
uint32_t found = expected;
|
||||||
native_t<T> handles[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 an collection of objects from the handles
|
||||||
return std::vector<T> (handles, handles + found);
|
return std::vector<T> (handles, handles + found);
|
||||||
|
12
object.hpp
12
object.hpp
@ -55,7 +55,7 @@ namespace cruft::vk {
|
|||||||
root (Args &&...args):
|
root (Args &&...args):
|
||||||
object<SelfT> (
|
object<SelfT> (
|
||||||
cruft::vk::error::try_query (
|
cruft::vk::error::try_query (
|
||||||
life_traits<SelfT>::create,
|
life_traits<native_t<SelfT>>::create,
|
||||||
std::forward<Args> (args)...
|
std::forward<Args> (args)...
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -63,7 +63,7 @@ namespace cruft::vk {
|
|||||||
|
|
||||||
~root ()
|
~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):
|
descendant (ParentT &parent, Args &&...args):
|
||||||
object<T> (
|
object<T> (
|
||||||
cruft::vk::error::try_query(
|
cruft::vk::error::try_query(
|
||||||
life_traits<T>::create,
|
life_traits<native_t<T>>::create,
|
||||||
parent.native (),
|
parent.native (),
|
||||||
std::forward<Args> (args)...
|
std::forward<Args> (args)...
|
||||||
)
|
)
|
||||||
@ -87,7 +87,7 @@ namespace cruft::vk {
|
|||||||
|
|
||||||
~descendant ()
|
~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):
|
owned (OwnerT &owner, Args &&...args):
|
||||||
object<SelfT> (
|
object<SelfT> (
|
||||||
error::try_query (
|
error::try_query (
|
||||||
life_traits<SelfT>::create,
|
life_traits<native_t<SelfT>>::create,
|
||||||
owner.native (),
|
owner.native (),
|
||||||
std::forward<Args> (args)...
|
std::forward<Args> (args)...
|
||||||
)
|
)
|
||||||
@ -142,7 +142,7 @@ namespace cruft::vk {
|
|||||||
void
|
void
|
||||||
destroy (OwnerT &owner)
|
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;
|
this->m_native = VK_NULL_HANDLE;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
32
traits.hpp
32
traits.hpp
@ -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& create = vkCreateInstance;
|
||||||
static constexpr auto& destroy = vkDestroyInstance;
|
static constexpr auto& destroy = vkDestroyInstance;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct life_traits<device> {
|
template <> struct life_traits<VkDevice> {
|
||||||
static constexpr auto& create = vkCreateDevice;
|
static constexpr auto& create = vkCreateDevice;
|
||||||
static constexpr auto& destroy = vkDestroyDevice;
|
static constexpr auto& destroy = vkDestroyDevice;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct life_traits<command_pool> {
|
template <> struct life_traits<VkCommandPool> {
|
||||||
static constexpr auto& create = vkCreateCommandPool;
|
static constexpr auto& create = vkCreateCommandPool;
|
||||||
static constexpr auto& destroy = vkDestroyCommandPool;
|
static constexpr auto& destroy = vkDestroyCommandPool;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct life_traits<fence> {
|
template <> struct life_traits<VkFence> {
|
||||||
static constexpr auto& create = vkCreateFence;
|
static constexpr auto& create = vkCreateFence;
|
||||||
static constexpr auto& destroy = vkDestroyFence;
|
static constexpr auto& destroy = vkDestroyFence;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct life_traits<semaphore> {
|
template <> struct life_traits<VkSemaphore> {
|
||||||
static constexpr auto& create = vkCreateSemaphore;
|
static constexpr auto& create = vkCreateSemaphore;
|
||||||
static constexpr auto& destroy = vkDestroySemaphore;
|
static constexpr auto& destroy = vkDestroySemaphore;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct life_traits<event> {
|
template <> struct life_traits<VkEvent> {
|
||||||
static constexpr auto& create = vkCreateEvent;
|
static constexpr auto& create = vkCreateEvent;
|
||||||
static constexpr auto& destroy = vkDestroyEvent;
|
static constexpr auto& destroy = vkDestroyEvent;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct life_traits<render_pass> {
|
template <> struct life_traits<VkRenderPass> {
|
||||||
static constexpr auto& create = vkCreateRenderPass;
|
static constexpr auto& create = vkCreateRenderPass;
|
||||||
static constexpr auto& destroy = vkDestroyRenderPass;
|
static constexpr auto& destroy = vkDestroyRenderPass;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct life_traits<framebuffer> {
|
template <> struct life_traits<VkFramebuffer> {
|
||||||
static constexpr auto& create = vkCreateFramebuffer;
|
static constexpr auto& create = vkCreateFramebuffer;
|
||||||
static constexpr auto& destroy = vkDestroyFramebuffer;
|
static constexpr auto& destroy = vkDestroyFramebuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct life_traits<shader_module> {
|
template <> struct life_traits<VkShaderModule> {
|
||||||
static constexpr auto& create = vkCreateShaderModule;
|
static constexpr auto& create = vkCreateShaderModule;
|
||||||
static constexpr auto& destroy = vkDestroyShaderModule;
|
static constexpr auto& destroy = vkDestroyShaderModule;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct life_traits<surface> {
|
template <> struct life_traits<VkSurfaceKHR> {
|
||||||
static constexpr auto& destroy = vkDestroySurfaceKHR;
|
static constexpr auto& destroy = vkDestroySurfaceKHR;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct life_traits<queue> {
|
struct life_traits<VkQueue> {
|
||||||
static constexpr auto& create = vkGetDeviceQueue;
|
static constexpr auto& create = vkGetDeviceQueue;
|
||||||
|
|
||||||
static constexpr auto destroy = ::util::tuple::ignore<
|
static constexpr auto destroy = ::util::tuple::ignore<
|
||||||
@ -226,22 +226,22 @@ namespace cruft::vk {
|
|||||||
// static constexpr auto destroy = vkDestroyPipeline;
|
// static constexpr auto destroy = vkDestroyPipeline;
|
||||||
//};
|
//};
|
||||||
|
|
||||||
template <> struct life_traits<pipeline_cache> {
|
template <> struct life_traits<VkPipelineCache> {
|
||||||
static constexpr auto& create = vkCreatePipelineCache;
|
static constexpr auto& create = vkCreatePipelineCache;
|
||||||
static constexpr auto& destroy = vkDestroyPipelineCache;
|
static constexpr auto& destroy = vkDestroyPipelineCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct life_traits<device_memory> {
|
template <> struct life_traits<VkDeviceMemory> {
|
||||||
static constexpr auto& create = vkAllocateMemory;
|
static constexpr auto& create = vkAllocateMemory;
|
||||||
static constexpr auto& destroy = vkFreeMemory;
|
static constexpr auto& destroy = vkFreeMemory;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct life_traits<buffer> {
|
template <> struct life_traits<VkBuffer> {
|
||||||
static constexpr auto& create = vkCreateBuffer;
|
static constexpr auto& create = vkCreateBuffer;
|
||||||
static constexpr auto& destroy = vkDestroyBuffer;
|
static constexpr auto& destroy = vkDestroyBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct life_traits<buffer_view> {
|
template <> struct life_traits<VkBufferView> {
|
||||||
static constexpr auto& create = vkCreateBufferView;
|
static constexpr auto& create = vkCreateBufferView;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ namespace cruft::vk {
|
|||||||
/// describes the functions required to enumerate native types
|
/// describes the functions required to enumerate native types
|
||||||
template <typename> struct enum_traits { };
|
template <typename> struct enum_traits { };
|
||||||
|
|
||||||
template <> struct enum_traits<physical_device> {
|
template <> struct enum_traits<VkPhysicalDevice> {
|
||||||
static constexpr auto enumerate = vkEnumeratePhysicalDevices;
|
static constexpr auto enumerate = vkEnumeratePhysicalDevices;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user