mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Make Vulkan-Hpp namespace configurable. (#129)
This commit is contained in:
parent
daae0b6194
commit
b4694d931c
@ -24,6 +24,8 @@ To avoid name collisions with the Vulkan C API the C++ bindings reside in the vk
|
||||
* ```VK_STRUCTURE_TYPE_PRESENT_INFO_KHR``` is now ```vk::StructureType::ePresentInfoKHR```.
|
||||
* Flag bits are handled like scoped enums with the addition that the _BIT suffix has also been removed.
|
||||
|
||||
In some cases it might be necessary to move Vulkan-Hpp to a custom namespace. This can be achieved by defining VULKAN_HPP_NAMESPACE before including Vulkan-Hpp.
|
||||
|
||||
# Handles
|
||||
Vulkan-Hpp declares a class for all handles to ensure full type safety and to add support for member functions on handles. A member function has been added to a handle class for each
|
||||
function which accepts the corresponding handle as first parameter. Instead of ```vkBindBufferMemory(device, ...)``` one can write ```device.bindBufferMemory(...)``` or ```vk::bindBufferMemory(device, ...)```.
|
||||
|
@ -30,6 +30,15 @@
|
||||
|
||||
#include <tinyxml2.h>
|
||||
|
||||
const std::string vkNamespace = R"(
|
||||
#if !defined(VULKAN_HPP_NAMESPACE)
|
||||
#define VULKAN_HPP_NAMESPACE vk
|
||||
#endif
|
||||
|
||||
namespace VULKAN_HPP_NAMESPACE
|
||||
{
|
||||
)";
|
||||
|
||||
const std::string exceptionHeader = R"(
|
||||
#if defined(_MSC_VER) && (_MSC_VER == 1800)
|
||||
# define noexcept _NOEXCEPT
|
||||
@ -38,7 +47,7 @@ const std::string exceptionHeader = R"(
|
||||
class ErrorCategoryImpl : public std::error_category
|
||||
{
|
||||
public:
|
||||
virtual const char* name() const noexcept override { return "vk::Result"; }
|
||||
virtual const char* name() const noexcept override { return "VULKAN_HPP_NAMESPACE::Result"; }
|
||||
virtual std::string message(int ev) const override { return to_string(static_cast<Result>(ev)); }
|
||||
};
|
||||
|
||||
@ -403,21 +412,21 @@ const std::string structureChainHeader = R"(
|
||||
link<Y, Z...>();
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
void linkAndCopy(StructureChain const &rhs)
|
||||
{
|
||||
static_cast<X&>(*this) = static_cast<X const &>(rhs);
|
||||
}
|
||||
|
||||
template<typename X, typename Y, typename ...Z>
|
||||
void linkAndCopy(StructureChain const &rhs)
|
||||
{
|
||||
static_assert(isStructureChainValid<X,Y>(), "The structure chain is not valid!");
|
||||
X& x = static_cast<X&>(*this);
|
||||
Y& y = static_cast<Y&>(*this);
|
||||
x = static_cast<X const &>(rhs);
|
||||
x.pNext = &y;
|
||||
linkAndCopy<Y, Z...>(rhs);
|
||||
template<typename X>
|
||||
void linkAndCopy(StructureChain const &rhs)
|
||||
{
|
||||
static_cast<X&>(*this) = static_cast<X const &>(rhs);
|
||||
}
|
||||
|
||||
template<typename X, typename Y, typename ...Z>
|
||||
void linkAndCopy(StructureChain const &rhs)
|
||||
{
|
||||
static_assert(isStructureChainValid<X,Y>(), "The structure chain is not valid!");
|
||||
X& x = static_cast<X&>(*this);
|
||||
Y& y = static_cast<Y&>(*this);
|
||||
x = static_cast<X const &>(rhs);
|
||||
x.pNext = &y;
|
||||
linkAndCopy<Y, Z...>(rhs);
|
||||
}
|
||||
|
||||
};
|
||||
@ -2717,7 +2726,7 @@ ${i} assert( ${firstVectorName}.size() == ${secondVectorName}.size() );
|
||||
#else
|
||||
${i} if ( ${firstVectorName}.size() != ${secondVectorName}.size() )
|
||||
${i} {
|
||||
${i} throw LogicError( "vk::${className}::${reducedName}: ${firstVectorName}.size() != ${secondVectorName}.size()" );
|
||||
${i} throw LogicError( "VULKAN_HPP_NAMESPACE::${className}::${reducedName}: ${firstVectorName}.size() != ${secondVectorName}.size()" );
|
||||
${i} }
|
||||
#endif // VULKAN_HPP_NO_EXCEPTIONS
|
||||
)#";
|
||||
@ -2756,7 +2765,7 @@ void writeFunctionBodyEnhancedReturnResultValue(std::ostream & os, std::string c
|
||||
}
|
||||
|
||||
// now the function name (with full namespace) as a string
|
||||
os << "\"vk::" << (commandData.className.empty() ? "" : commandData.className + "::") << (singular ? stripPluralS(commandData.reducedName) : commandData.reducedName) << "\"";
|
||||
os << "\"VULKAN_HPP_NAMESPACE::" << (commandData.className.empty() ? "" : commandData.className + "::") << (singular ? stripPluralS(commandData.reducedName) : commandData.reducedName) << "\"";
|
||||
|
||||
if (!commandData.twoStep && (1 < commandData.successCodes.size()))
|
||||
{
|
||||
@ -4330,8 +4339,7 @@ int main( int argc, char **argv )
|
||||
<< inlineHeader
|
||||
<< explicitHeader
|
||||
<< std::endl
|
||||
<< "namespace vk" << std::endl
|
||||
<< "{" << std::endl
|
||||
<< vkNamespace
|
||||
<< flagsHeader
|
||||
<< optionalClassHeader
|
||||
<< arrayProxyHeader
|
||||
@ -4351,16 +4359,16 @@ int main( int argc, char **argv )
|
||||
ofs << "#endif" << std::endl;
|
||||
vkData.dependencies.erase(it);
|
||||
|
||||
ofs << "} // namespace vk" << std::endl
|
||||
ofs << "} // namespace VULKAN_HPP_NAMESPACE" << std::endl
|
||||
<< std::endl
|
||||
<< "namespace std" << std::endl
|
||||
<< "{" << std::endl
|
||||
<< " template <>" << std::endl
|
||||
<< " struct is_error_code_enum<vk::Result> : public true_type" << std::endl
|
||||
<< " struct is_error_code_enum<VULKAN_HPP_NAMESPACE::Result> : public true_type" << std::endl
|
||||
<< " {};" << std::endl
|
||||
<< "}" << std::endl
|
||||
<< std::endl
|
||||
<< "namespace vk" << std::endl
|
||||
<< "namespace VULKAN_HPP_NAMESPACE" << std::endl
|
||||
<< "{" << std::endl
|
||||
<< resultValueHeader
|
||||
<< createResultValueHeader;
|
||||
@ -4394,7 +4402,7 @@ int main( int argc, char **argv )
|
||||
}
|
||||
}
|
||||
|
||||
ofs << "} // namespace vk" << std::endl
|
||||
ofs << "} // namespace VULKAN_HPP_NAMESPACE" << std::endl
|
||||
<< std::endl
|
||||
<< "#endif" << std::endl;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user