mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Add structure chain constructor which accepts a list of its elements (#217)
Add structure chain constructor which accepts a list of its elements
This commit is contained in:
parent
b075d67fbc
commit
437f800444
@ -182,6 +182,15 @@ vk::MemoryAllocateInfo &allocInfo = c.get<vk::MemoryAllocateInfo>();
|
||||
vk::ImportMemoryFdInfoKHR &fdInfo = c.get<vk::ImportMemoryFdInfoKHR>();
|
||||
```
|
||||
|
||||
Vulkan-Hpp provides a constructor for these chains similar to the CreateInfo objects which accepts a list of all structures part of the chain. The `pNext` field is automatically set to the correct value:
|
||||
|
||||
```c++
|
||||
vk::StructureChain<vk::MemoryAllocateInfo, vk::MemoryDedicatedAllocateInfo> c = {
|
||||
vk::MemoryAllocateInfo(size, type),
|
||||
vk::MemoryDedicatedAllocateInfo(image)
|
||||
};
|
||||
```
|
||||
|
||||
Sometimes the user has to pass a preallocated structure chain to query information. In those cases the corresponding query functions are variadic templates and do accept a structure chain to construct the return value:
|
||||
|
||||
```
|
||||
|
@ -398,6 +398,11 @@ const std::string structureChainHeader = R"(
|
||||
linkAndCopy<StructureElements...>(rhs);
|
||||
}
|
||||
|
||||
StructureChain(StructureElements const &... elems)
|
||||
{
|
||||
linkAndCopyElements<StructureElements...>(elems...);
|
||||
}
|
||||
|
||||
StructureChain& operator=(StructureChain const &rhs)
|
||||
{
|
||||
linkAndCopy<StructureElements...>(rhs);
|
||||
@ -439,7 +444,24 @@ const std::string structureChainHeader = R"(
|
||||
linkAndCopy<Y, Z...>(rhs);
|
||||
}
|
||||
|
||||
};
|
||||
template<typename X>
|
||||
void linkAndCopyElements(X const &xelem)
|
||||
{
|
||||
static_cast<X&>(*this) = xelem;
|
||||
}
|
||||
|
||||
template<typename X, typename Y, typename ...Z>
|
||||
void linkAndCopyElements(X const &xelem, Y const &yelem, Z const &... zelem)
|
||||
{
|
||||
static_assert(isStructureChainValid<X,Y>::value, "The structure chain is not valid!");
|
||||
X& x = static_cast<X&>(*this);
|
||||
Y& y = static_cast<Y&>(*this);
|
||||
x = xelem;
|
||||
x.pNext = &y;
|
||||
linkAndCopyElements<Y, Z...>(yelem, zelem...);
|
||||
}
|
||||
};
|
||||
|
||||
)";
|
||||
|
||||
const std::string versionCheckHeader = R"(
|
||||
|
@ -471,6 +471,11 @@ namespace VULKAN_HPP_NAMESPACE
|
||||
linkAndCopy<StructureElements...>(rhs);
|
||||
}
|
||||
|
||||
StructureChain(StructureElements const &... elems)
|
||||
{
|
||||
linkAndCopyElements<StructureElements...>(elems...);
|
||||
}
|
||||
|
||||
StructureChain& operator=(StructureChain const &rhs)
|
||||
{
|
||||
linkAndCopy<StructureElements...>(rhs);
|
||||
@ -512,7 +517,24 @@ namespace VULKAN_HPP_NAMESPACE
|
||||
linkAndCopy<Y, Z...>(rhs);
|
||||
}
|
||||
|
||||
};
|
||||
template<typename X>
|
||||
void linkAndCopyElements(X const &xelem)
|
||||
{
|
||||
static_cast<X&>(*this) = xelem;
|
||||
}
|
||||
|
||||
template<typename X, typename Y, typename ...Z>
|
||||
void linkAndCopyElements(X const &xelem, Y const &yelem, Z const &... zelem)
|
||||
{
|
||||
static_assert(isStructureChainValid<X,Y>::value, "The structure chain is not valid!");
|
||||
X& x = static_cast<X&>(*this);
|
||||
Y& y = static_cast<Y&>(*this);
|
||||
x = xelem;
|
||||
x.pNext = &y;
|
||||
linkAndCopyElements<Y, Z...>(yelem, zelem...);
|
||||
}
|
||||
};
|
||||
|
||||
enum class Result
|
||||
{
|
||||
eSuccess = VK_SUCCESS,
|
||||
|
Loading…
Reference in New Issue
Block a user