except: prefer safer try_foo style accessors

This commit is contained in:
Danny Robson 2017-09-09 15:34:27 +10:00
parent 01ec49efe9
commit 7bc8870e06
2 changed files with 16 additions and 27 deletions

View File

@ -83,17 +83,14 @@ instance::instance (const create_info_t &info):
std::set<std::string>
instance::extensions (void) const
{
uint32_t expected = 0;
error::try_code (vkEnumerateInstanceExtensionProperties (nullptr, &expected, nullptr));
auto values = error::try_values (
vkEnumerateInstanceExtensionProperties, nullptr
);
VkExtensionProperties props[expected];
uint32_t found = expected;
error::try_code (vkEnumerateInstanceExtensionProperties (nullptr, &found, props));
std::set<std::string> ext;
for (const auto &i: props)
ext.insert (i.extensionName);
return ext;
std::set<std::string> strings;
for (const auto &i: values)
strings.insert (i.extensionName);
return strings;
}
@ -101,11 +98,5 @@ instance::extensions (void) const
std::vector<VkLayerProperties>
instance::available_layers (void)
{
uint32_t count;
vk::error::try_code (vkEnumerateInstanceLayerProperties (&count, nullptr));
std::vector<VkLayerProperties> layers (count);
vk::error::try_code (vkEnumerateInstanceLayerProperties (&count, layers.data ()));
return layers;
return error::try_values (vkEnumerateInstanceLayerProperties);
}

View File

@ -27,19 +27,17 @@ using cruft::vk::physical_device;
std::set<std::string>
physical_device::extensions (void) const
{
uint32_t expected = 0;
error::try_code (vkEnumerateDeviceExtensionProperties (native (), nullptr, &expected, nullptr));
auto values = error::try_values (
vkEnumerateDeviceExtensionProperties, native (), nullptr
);
VkExtensionProperties props[expected];
uint32_t found = expected;
error::try_code (vkEnumerateDeviceExtensionProperties (native (), nullptr, &found, props));
std::set<std::string> ext;
for (const auto &i: props)
ext.insert (i.extensionName);
return ext;
std::set<std::string> strings;
for (const auto &i: values)
strings.emplace (i.extensionName);
return strings;
}
///////////////////////////////////////////////////////////////////////////////
VkPhysicalDeviceProperties
physical_device::properties (void) const