-
-
Save Borgleader/c568d248c117845743e4f54c96bf21c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace vku | |
{ | |
namespace detail | |
{ | |
template <typename Func, typename T = std::remove_pointer<typename meta::function_arg2_t<Func>::type>::type> | |
inline std::vector<T> get_api_values(Func func) | |
{ | |
uint32_t count = 0; | |
if (func(&count, nullptr) == VK_SUCCESS && count > 0) | |
{ | |
std::vector<T> available_values(count); | |
if (func(&count, available_values.data()) == VK_SUCCESS) | |
return available_values; | |
} | |
return{}; | |
} | |
inline std::vector<VkExtensionProperties> get_instance_extensions() | |
{ | |
auto f = [](uint32_t* count, VkExtensionProperties* values) { return vk::vkEnumerateInstanceExtensionProperties(nullptr, count, values); }; | |
return get_api_values(f); | |
} | |
inline std::vector<VkLayerProperties> get_instance_layers() | |
{ | |
auto f = [](uint32_t* count, VkLayerProperties* values) { return vk::vkEnumerateInstanceLayerProperties(count, values); }; | |
return get_api_values(f); | |
} | |
inline std::vector<VkPhysicalDevice> get_physical_devices(const VkInstance& instance) | |
{ | |
auto f = [=](uint32_t* count, VkPhysicalDevice* values) { return vk::vkEnumeratePhysicalDevices(instance, count, values); }; | |
return get_api_values(f); | |
} | |
inline std::vector<VkExtensionProperties> get_physical_device_extensions(const VkPhysicalDevice& physical_device) | |
{ | |
auto f = [=](uint32_t* count, VkExtensionProperties* values) { return vk::vkEnumerateDeviceExtensionProperties(physical_device, nullptr, count, values); }; | |
return get_api_values(f); | |
} | |
inline std::vector<VkLayerProperties> get_physical_device_layers(const VkPhysicalDevice& physical_device) | |
{ | |
auto f = [=](uint32_t* count, VkLayerProperties* values) { return vk::vkEnumerateDeviceLayerProperties(physical_device, count, values); }; | |
return get_api_values(f); | |
} | |
inline std::vector<VkSurfaceFormatKHR> get_surface_formats(const VkPhysicalDevice& physical_device, const VkSurfaceKHR& surface) | |
{ | |
auto f = [=](uint32_t* count, VkSurfaceFormatKHR* values) { return vk::vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, count, values); }; | |
return get_api_values(f); | |
} | |
inline std::vector<VkPresentModeKHR> get_present_modes(const VkPhysicalDevice& physical_device, const VkSurfaceKHR& surface) | |
{ | |
auto f = [=](uint32_t* count, VkPresentModeKHR* values) { return vk::vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, count, values); }; | |
return get_api_values(f); | |
} | |
} | |
} | |
namespace meta | |
{ | |
template <typename Func, bool Builtin = boost::function_types::is_callable_builtin<Func>::value> | |
struct function_arity; | |
template <typename Func> | |
struct function_arity<Func, true> : boost::function_types::function_arity<Func> | |
{}; | |
template <typename Func> | |
struct function_arity<Func, false> : function_arity<decltype(&Func::operator())> | |
{}; | |
template <typename Func, bool Builtin = boost::function_types::is_callable_builtin<Func>::value> | |
struct function_arg1_t; | |
template <typename Func> | |
struct function_arg1_t<Func, true> : boost::mpl::at<typename boost::function_types::parameter_types<Func>::type, boost::mpl::int_<1>> | |
{}; | |
template <typename Func> | |
struct function_arg1_t<Func, false> : function_arg1_t<decltype(&Func::operator())> | |
{}; | |
template <typename Func, bool Builtin = boost::function_types::is_callable_builtin<Func>::value> | |
struct function_arg2_t; | |
template <typename Func> | |
struct function_arg2_t<Func, true> : boost::mpl::at<typename boost::function_types::parameter_types<Func>::type, boost::mpl::int_<2>> | |
{}; | |
template <typename Func> | |
struct function_arg2_t<Func, false> : function_arg2_t<decltype(&Func::operator())> | |
{}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment