traits: rename id_t/id_traits to native_t/native_traits
renaming for consistency both in this project and with cruft-gl. it's easier to perform this change if we push some more code into the object.hpp header so we don't need to talk about native_t too often.
This commit is contained in:
parent
c5591d654a
commit
a24d0a7ab2
39
object.cpp
39
object.cpp
@ -27,43 +27,6 @@ using cruft::vk::object;
|
||||
using cruft::vk::enumerated;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
object<T>::object (native_t _native):
|
||||
m_native (_native)
|
||||
{
|
||||
CHECK_NEQ (m_native, VK_NULL_HANDLE);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
object<T>::object (object &&rhs):
|
||||
m_native (VK_NULL_HANDLE)
|
||||
{
|
||||
std::swap (m_native, rhs.m_native);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
const typename object<T>::native_t&
|
||||
object<T>::native (void) const&
|
||||
{
|
||||
return m_native;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
typename object<T>::native_t&
|
||||
object<T>::native (void) &
|
||||
{
|
||||
return m_native;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
#define OBJECT(T) template struct cruft::vk::object<cruft::vk::T>;
|
||||
VK_TYPE_MAP (OBJECT)
|
||||
|
||||
@ -83,7 +46,7 @@ cruft::vk::enumerated<T>::find (const instance &parent) {
|
||||
|
||||
// allocate an array of handles and fetch them
|
||||
uint32_t found = expected;
|
||||
typename T::native_t handles[expected];
|
||||
native_t<T> handles[expected];
|
||||
error::try_code (enum_traits<T>::enumerate (parent.native (), &found, handles));
|
||||
|
||||
// return an collection of objects from the handles
|
||||
|
64
object.hpp
64
object.hpp
@ -29,45 +29,42 @@ namespace cruft::vk {
|
||||
/// management.
|
||||
template <typename T>
|
||||
struct object {
|
||||
using native_t = id_t<T>;
|
||||
object (native_t<T> _native):
|
||||
m_native (_native)
|
||||
{
|
||||
CHECK_NEQ (m_native, VK_NULL_HANDLE);
|
||||
}
|
||||
|
||||
object (native_t);
|
||||
object (object&&);
|
||||
object (object &&rhs):
|
||||
m_native (VK_NULL_HANDLE)
|
||||
{ std::swap (m_native, rhs.m_native); }
|
||||
|
||||
object (const object&) = delete;
|
||||
|
||||
const native_t& native (void) const&;
|
||||
native_t& native (void) &;
|
||||
const auto& native (void) const& { return m_native; }
|
||||
auto& native (void)& { return m_native; }
|
||||
|
||||
protected:
|
||||
native_t m_native;
|
||||
native_t<T> m_native;
|
||||
};
|
||||
|
||||
|
||||
template <typename SelfT>
|
||||
struct root : public object<SelfT> {
|
||||
using native_t = typename object<SelfT>::native_t;
|
||||
|
||||
template <typename ...Args>
|
||||
root (Args &&...args):
|
||||
object<SelfT> (make (std::forward<Args> (args)...))
|
||||
object<SelfT> (
|
||||
cruft::vk::error::try_query (
|
||||
life_traits<SelfT>::create,
|
||||
std::forward<Args> (args)...
|
||||
)
|
||||
)
|
||||
{ ; }
|
||||
|
||||
~root ()
|
||||
{
|
||||
life_traits<SelfT>::destroy (this->native (), nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename ...Args>
|
||||
static native_t
|
||||
make (Args &&...args)
|
||||
{
|
||||
native_t id;
|
||||
auto res = life_traits<SelfT>::create (std::forward<Args> (args)..., &id);
|
||||
error::try_code (res);
|
||||
return id;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -76,28 +73,22 @@ namespace cruft::vk {
|
||||
/// another object.
|
||||
template <typename T>
|
||||
struct descendant : public object<T> {
|
||||
using native_t = typename object<T>::native_t;
|
||||
|
||||
template <typename ...Args>
|
||||
descendant (Args &&...args):
|
||||
object<T> (make (std::forward<Args> (args)...))
|
||||
template <typename ParentT, typename ...Args>
|
||||
descendant (ParentT &parent, Args &&...args):
|
||||
object<T> (
|
||||
cruft::vk::error::try_query(
|
||||
life_traits<T>::create,
|
||||
parent.native (),
|
||||
std::forward<Args> (args)...
|
||||
)
|
||||
)
|
||||
{ ; }
|
||||
|
||||
|
||||
~descendant ()
|
||||
{
|
||||
life_traits<T>::destroy (this->native (), nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename Base, typename ...Args>
|
||||
static
|
||||
native_t make (Base &&base, Args &&...args)
|
||||
{
|
||||
native_t id;
|
||||
auto res = life_traits<T>::create (base.native (), std::forward<Args> (args)..., &id);
|
||||
error::try_code (res);
|
||||
return id;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -117,7 +108,6 @@ namespace cruft::vk {
|
||||
/// the parent object.
|
||||
template <typename SelfT, typename OwnerT>
|
||||
struct owned : public object<SelfT> {
|
||||
using native_t = typename object<SelfT>::native_t;
|
||||
using owner_t = OwnerT;
|
||||
|
||||
using object<SelfT>::object;
|
||||
|
44
traits.hpp
44
traits.hpp
@ -89,33 +89,33 @@ namespace cruft::vk {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// describes the native type that corresponds to a given vk-cruft type.
|
||||
template <typename> struct id_traits { };
|
||||
template <typename> struct native_traits { };
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <> struct id_traits<instance> { using type = VkInstance; };
|
||||
template <> struct id_traits<physical_device> { using type = VkPhysicalDevice; };
|
||||
template <> struct id_traits<device> { using type = VkDevice; };
|
||||
template <> struct id_traits<queue> { using type = VkQueue; };
|
||||
template <> struct id_traits<command_pool> { using type = VkCommandPool; };
|
||||
template <> struct id_traits<command_buffer> { using type = VkCommandBuffer; };
|
||||
template <> struct id_traits<fence> { using type = VkFence; };
|
||||
template <> struct id_traits<semaphore> { using type = VkSemaphore; };
|
||||
template <> struct id_traits<event> { using type = VkEvent; };
|
||||
template <> struct id_traits<render_pass> { using type = VkRenderPass; };
|
||||
template <> struct id_traits<framebuffer> { using type = VkFramebuffer; };
|
||||
template <> struct id_traits<shader_module> { using type = VkShaderModule; };
|
||||
template <> struct id_traits<pipeline> { using type = VkPipeline; };
|
||||
template <> struct id_traits<pipeline_cache> { using type = VkPipelineCache; };
|
||||
template <> struct id_traits<device_memory> { using type = VkDeviceMemory; };
|
||||
template <> struct id_traits<buffer> { using type = VkBuffer; };
|
||||
template <> struct id_traits<buffer_view> { using type = VkBufferView; };
|
||||
template <> struct id_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; };
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
using id_t = typename id_traits<T>::type;
|
||||
using native_t = typename native_traits<T>::type;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -203,8 +203,8 @@ namespace cruft::vk {
|
||||
static constexpr auto& create = vkGetDeviceQueue;
|
||||
|
||||
static constexpr auto destroy = ::util::tuple::ignore<
|
||||
id_t<owner_t<queue>>,
|
||||
id_t<queue>,
|
||||
native_t<owner_t<queue>>,
|
||||
native_t<queue>,
|
||||
const VkAllocationCallbacks*
|
||||
>;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user