diff --git a/traits.hpp b/traits.hpp index 8bbd7b5..0ebbb3e 100644 --- a/traits.hpp +++ b/traits.hpp @@ -112,11 +112,69 @@ namespace cruft::vk { #undef IS_WRAPPER + //------------------------------------------------------------------------- + template + struct is_wrapper> : + public is_wrapper + { }; + + //------------------------------------------------------------------------- template static constexpr auto is_wrapper_v = is_wrapper::value; + /////////////////////////////////////////////////////////////////////////// + /// return the native value for the wrapper object + template + constexpr auto + native (const object &obj) + { + return obj.native (); + } + + + ///------------------------------------------------------------------------ + /// return the native handle as is; supplied for implementation convenience + /// in other higher order methods. + template < + typename NativeT, + typename = std::enable_if_t, void> + > + constexpr auto + native (NativeT val) + { + return val; + } + + + ///------------------------------------------------------------------------ + /// return the underlying native value by querying the data object (not the + /// owner object). + template + constexpr auto + native (const owned_ptr &ptr) + { + return native (ptr.get ()); + } + + + ///------------------------------------------------------------------------ + /// try to return the vulkan native type if there is one, else return the + /// value we were given. + template > + constexpr auto + maybe_native (T &&t) + { + if constexpr (is_wrapper_v) + return native (t); + else if constexpr (is_native_v) + return native (t); + else + return t; + } + + /////////////////////////////////////////////////////////////////////////// /// describes the corresponding value for sType in native structures template