-
-
Save ThePhD/cbdb54ad51678ba8cef75db33dd2e5c5 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_arg_t<Func, 2>::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, int index, bool Builtin = boost::function_types::is_callable_builtin<Func>::value> | |
struct function_arg_t; | |
template <typename Func, int index> | |
struct function_arg_t<Func, index, true> : boost::mpl::at<typename boost::function_types::parameter_types<Func>::type, boost::mpl::int_<index>> | |
{}; | |
template <typename Func, int index> | |
struct function_arg_t<Func, index, false> : function_arg_t<decltype(&Func::operator())> | |
{}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment