Refactor GenericFeaturesPNextNode

This commit is contained in:
Charles Giessen 2021-04-18 14:39:20 -06:00 committed by Charles Giessen
parent c607a65755
commit 75db58ae8b
2 changed files with 17 additions and 15 deletions

View File

@ -37,6 +37,18 @@ namespace vkb {
namespace detail { namespace detail {
GenericFeaturesPNextNode::GenericFeaturesPNextNode()
: fields() {} // zero initializes the array of fields
bool GenericFeaturesPNextNode::match(
GenericFeaturesPNextNode const& requested, GenericFeaturesPNextNode const& supported) {
assert(requested.sType == supported.sType && "Non-matching sTypes in features nodes!");
for (uint32_t i = 0; i < field_capacity; i++) {
if (requested.fields[i] && !supported.fields[i]) return false;
}
return true;
}
class VulkanFunctions { class VulkanFunctions {
private: private:
std::mutex init_mutex; std::mutex init_mutex;

View File

@ -117,26 +117,16 @@ template <typename T> class Result {
struct GenericFeaturesPNextNode { struct GenericFeaturesPNextNode {
GenericFeaturesPNextNode() : sType(static_cast<VkStructureType>(0)), pNext(nullptr) { GenericFeaturesPNextNode();
for (auto& field : fields) {
field = 0; template <typename T> void set(T const& features) { *reinterpret_cast<T*>(this) = features; }
}
} static bool match(GenericFeaturesPNextNode const& requested, GenericFeaturesPNextNode const& supported);
VkStructureType sType = static_cast<VkStructureType>(0); VkStructureType sType = static_cast<VkStructureType>(0);
void* pNext = nullptr; void* pNext = nullptr;
static const uint32_t field_capacity = 256; static const uint32_t field_capacity = 256;
VkBool32 fields[field_capacity]; VkBool32 fields[field_capacity];
template <typename T> void set(T const& features) { *reinterpret_cast<T*>(this) = features; }
static bool match(GenericFeaturesPNextNode const& requested, GenericFeaturesPNextNode const& supported) {
assert(requested.sType == supported.sType && "Non-matching sTypes in features nodes!");
for (uint32_t i = 0; i < field_capacity; i++) {
if (requested.fields[i] && !supported.fields[i]) return false;
}
return true;
}
}; };
} // namespace detail } // namespace detail