traits: use wrapper_traits for wrapper create/destroy indirection

This commit is contained in:
Danny Robson 2017-09-13 16:50:23 +10:00
parent 4ecac0648b
commit 0ccbfc1cbe
2 changed files with 16 additions and 8 deletions

View File

@ -58,7 +58,7 @@ namespace cruft::vk {
root (Args &&...args):
object<SelfT> (
cruft::vk::error::try_query (
life_traits<native_t<SelfT>>::create,
wrapper_traits<SelfT>::create,
std::forward<Args> (args)...
)
)
@ -66,7 +66,7 @@ namespace cruft::vk {
~root ()
{
life_traits<native_t<SelfT>>::destroy (this->native (), nullptr);
wrapper_traits<SelfT>::destroy (this->native (), nullptr);
}
};
@ -81,7 +81,7 @@ namespace cruft::vk {
descendant (ParentT &parent, Args &&...args):
object<SelfT> (
cruft::vk::error::try_query(
life_traits<native_t<SelfT>>::create,
wrapper_traits<SelfT>::create,
parent.native (),
std::forward<Args> (args)...
)
@ -92,7 +92,7 @@ namespace cruft::vk {
//---------------------------------------------------------------------
~descendant ()
{
life_traits<native_t<SelfT>>::destroy (this->native (), nullptr);
wrapper_traits<SelfT>::destroy (this->native (), nullptr);
}
};
@ -129,7 +129,7 @@ namespace cruft::vk {
owned (OwnerT &owner, Args &&...args):
object<SelfT> (
error::try_query (
life_traits<native_t<SelfT>>::create,
wrapper_traits<SelfT>::create,
owner.native (),
std::forward<Args> (args)...
)
@ -154,7 +154,7 @@ namespace cruft::vk {
void
destroy (OwnerT &owner)
{
life_traits<native_t<SelfT>>::destroy (owner.native (), this->native (), nullptr);
wrapper_traits<SelfT>::destroy (owner.native (), this->native (), nullptr);
this->m_native = VK_NULL_HANDLE;
}
};

View File

@ -170,6 +170,8 @@ namespace cruft::vk {
template <> struct owner_traits<shader_module> { using type = device; };
template <> struct owner_traits<surface> { using type = instance; };
template <> struct owner_traits<swapchain> { using type = device; };
template <> struct owner_traits<pipeline<bindpoint::GRAPHICS>> { using type = device; };
template <> struct owner_traits<pipeline<bindpoint::COMPUTE>> { using type = device; };
template <typename T>
using owner_t = typename owner_traits<T>::type;
@ -314,16 +316,22 @@ namespace cruft::vk {
};
///////////////////////////////////////////////////////////////////////////
template <typename T>
struct wrapper_traits : public life_traits<native_t<T>> { };
//-------------------------------------------------------------------------
template <>
struct life_traits<pipeline<bindpoint::GRAPHICS>> {
struct wrapper_traits<pipeline<bindpoint::GRAPHICS>> {
static constexpr auto &create = vkCreateGraphicsPipelines;
static constexpr auto &destroy = vkDestroyPipeline;
};
//-------------------------------------------------------------------------
template <>
struct life_traits<pipeline<bindpoint::COMPUTE>> {
struct wrapper_traits<pipeline<bindpoint::COMPUTE>> {
static constexpr auto &create = vkCreateComputePipelines;
static constexpr auto &destroy = vkDestroyPipeline;
};