Make Vulkan-Hpp namespace configurable. (#129)

This commit is contained in:
Markus Tavenrath 2017-09-19 07:55:48 -05:00 committed by Andreas Süßenbach
parent daae0b6194
commit b4694d931c
3 changed files with 177 additions and 162 deletions

View File

@ -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```. * ```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. * 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 # 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 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, ...)```. function which accepts the corresponding handle as first parameter. Instead of ```vkBindBufferMemory(device, ...)``` one can write ```device.bindBufferMemory(...)``` or ```vk::bindBufferMemory(device, ...)```.

View File

@ -30,6 +30,15 @@
#include <tinyxml2.h> #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"( const std::string exceptionHeader = R"(
#if defined(_MSC_VER) && (_MSC_VER == 1800) #if defined(_MSC_VER) && (_MSC_VER == 1800)
# define noexcept _NOEXCEPT # define noexcept _NOEXCEPT
@ -38,7 +47,7 @@ const std::string exceptionHeader = R"(
class ErrorCategoryImpl : public std::error_category class ErrorCategoryImpl : public std::error_category
{ {
public: 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)); } 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...>(); link<Y, Z...>();
} }
template<typename X> template<typename X>
void linkAndCopy(StructureChain const &rhs) void linkAndCopy(StructureChain const &rhs)
{ {
static_cast<X&>(*this) = static_cast<X const &>(rhs); static_cast<X&>(*this) = static_cast<X const &>(rhs);
} }
template<typename X, typename Y, typename ...Z> template<typename X, typename Y, typename ...Z>
void linkAndCopy(StructureChain const &rhs) void linkAndCopy(StructureChain const &rhs)
{ {
static_assert(isStructureChainValid<X,Y>(), "The structure chain is not valid!"); static_assert(isStructureChainValid<X,Y>(), "The structure chain is not valid!");
X& x = static_cast<X&>(*this); X& x = static_cast<X&>(*this);
Y& y = static_cast<Y&>(*this); Y& y = static_cast<Y&>(*this);
x = static_cast<X const &>(rhs); x = static_cast<X const &>(rhs);
x.pNext = &y; x.pNext = &y;
linkAndCopy<Y, Z...>(rhs); linkAndCopy<Y, Z...>(rhs);
} }
}; };
@ -2717,7 +2726,7 @@ ${i} assert( ${firstVectorName}.size() == ${secondVectorName}.size() );
#else #else
${i} if ( ${firstVectorName}.size() != ${secondVectorName}.size() ) ${i} if ( ${firstVectorName}.size() != ${secondVectorName}.size() )
${i} { ${i} {
${i} throw LogicError( "vk::${className}::${reducedName}: ${firstVectorName}.size() != ${secondVectorName}.size()" ); ${i} throw LogicError( "VULKAN_HPP_NAMESPACE::${className}::${reducedName}: ${firstVectorName}.size() != ${secondVectorName}.size()" );
${i} } ${i} }
#endif // VULKAN_HPP_NO_EXCEPTIONS #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 // 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())) if (!commandData.twoStep && (1 < commandData.successCodes.size()))
{ {
@ -4330,8 +4339,7 @@ int main( int argc, char **argv )
<< inlineHeader << inlineHeader
<< explicitHeader << explicitHeader
<< std::endl << std::endl
<< "namespace vk" << std::endl << vkNamespace
<< "{" << std::endl
<< flagsHeader << flagsHeader
<< optionalClassHeader << optionalClassHeader
<< arrayProxyHeader << arrayProxyHeader
@ -4351,16 +4359,16 @@ int main( int argc, char **argv )
ofs << "#endif" << std::endl; ofs << "#endif" << std::endl;
vkData.dependencies.erase(it); vkData.dependencies.erase(it);
ofs << "} // namespace vk" << std::endl ofs << "} // namespace VULKAN_HPP_NAMESPACE" << std::endl
<< std::endl << std::endl
<< "namespace std" << std::endl << "namespace std" << std::endl
<< "{" << std::endl << "{" << std::endl
<< " template <>" << 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 << "}" << std::endl
<< std::endl << std::endl
<< "namespace vk" << std::endl << "namespace VULKAN_HPP_NAMESPACE" << std::endl
<< "{" << std::endl << "{" << std::endl
<< resultValueHeader << resultValueHeader
<< createResultValueHeader; << 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 << std::endl
<< "#endif" << std::endl; << "#endif" << std::endl;
} }

File diff suppressed because it is too large Load Diff