diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 727e1b3..48b4491 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -222,6 +222,7 @@ std::string const optionalClassHeader = ( ); std::string const arrayProxyHeader = ( + "#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE\n" " template \n" " class ArrayProxy\n" " {\n" @@ -311,6 +312,7 @@ std::string const arrayProxyHeader = ( " uint32_t m_count;\n" " T * m_ptr;\n" " };\n" + "#endif\n" "\n" ); @@ -524,7 +526,7 @@ struct StructData {} bool returnedOnly; - bool isUnion; + bool isUnion; std::vector members; std::string protect; }; @@ -1457,7 +1459,7 @@ void readTypeStruct( tinyxml2::XMLElement * element, VkData & vkData ) assert( vkData.structs.find( name ) == vkData.structs.end() ); std::map::iterator it = vkData.structs.insert( std::make_pair( name, StructData() ) ).first; it->second.returnedOnly = !!element->Attribute( "returnedonly" ); - it->second.isUnion = false; + it->second.isUnion = false; tinyxml2::XMLElement * child = element->FirstChildElement(); do @@ -1559,7 +1561,7 @@ void readTypeUnion( tinyxml2::XMLElement * element, VkData & vkData ) assert( vkData.structs.find( name ) == vkData.structs.end() ); std::map::iterator it = vkData.structs.insert( std::make_pair( name, StructData() ) ).first; - it->second.isUnion = true; + it->second.isUnion = true; tinyxml2::XMLElement * child = element->FirstChildElement(); do @@ -2337,14 +2339,14 @@ void writeStructConstructor( std::ofstream & ofs, std::string const& name, Struc } else { - ofs << "std::array<" + structData.members[i].type + "," + structData.members[i].arraySize + "> const& " + structData.members[i].name << "_ = { " << defaultIt->second; + ofs << "std::array<" + structData.members[i].type + "," + structData.members[i].arraySize + "> const& " + structData.members[i].name << "_ = { { " << defaultIt->second; size_t n = atoi(structData.members[i].arraySize.c_str()); assert(0 < n); for (size_t j = 1; j < n; j++) { ofs << ", " << defaultIt->second; } - ofs << " }"; + ofs << " } }"; } listedArgument = true; } @@ -2736,21 +2738,21 @@ void writeTypeScalar( std::ofstream & ofs, DependencyData const& dependencyData << std::endl; } -bool containsUnion(std::string const& type, std::map const& structs) -{ - std::map::const_iterator sit = structs.find(type); - bool found = (sit != structs.end()); - if (found) - { - found = sit->second.isUnion; - for (std::vector::const_iterator mit = sit->second.members.begin(); mit != sit->second.members.end() && !found; ++mit) - { - found = (mit->type == mit->pureType) && containsUnion(mit->type, structs); - } - } - return found; -} - +bool containsUnion(std::string const& type, std::map const& structs) +{ + std::map::const_iterator sit = structs.find(type); + bool found = (sit != structs.end()); + if (found) + { + found = sit->second.isUnion; + for (std::vector::const_iterator mit = sit->second.members.begin(); mit != sit->second.members.end() && !found; ++mit) + { + found = (mit->type == mit->pureType) && containsUnion(mit->type, structs); + } + } + return found; +} + void writeTypeStruct( std::ofstream & ofs, VkData const& vkData, DependencyData const& dependencyData, std::map const& defaultValues ) { std::map::const_iterator it = vkData.structs.find( dependencyData.name ); @@ -2782,42 +2784,38 @@ void writeTypeStruct( std::ofstream & ofs, VkData const& vkData, DependencyData << " }" << std::endl << std::endl; - // operator==() and operator!=() - // only structs without a union as a member can have a meaningfull == and != operation; we filter them out - if (!containsUnion(dependencyData.name, vkData.structs)) - { - ofs << " bool operator==( " << dependencyData.name << " const& rhs ) const" << std::endl - << " {" << std::endl - << " return "; - for (size_t i = 0; i < it->second.members.size(); i++) - { - if (i != 0) - { - ofs << std::endl << " && "; - } - if (!it->second.members[i].arraySize.empty()) - { - ofs << "( memcmp( " << it->second.members[i].name << ", rhs." << it->second.members[i].name << ", " << it->second.members[i].arraySize << " * sizeof( " << it->second.members[i].type << " ) ) == 0 )"; - } - else - { - ofs << "( " << it->second.members[i].name << " == rhs." << it->second.members[i].name << " )"; - } - } - ofs << ";" << std::endl - << " }" << std::endl - << std::endl - << " bool operator!=( " << dependencyData.name << " const& rhs ) const" << std::endl - << " {" << std::endl - << " return !operator==( rhs );" << std::endl - << " }" << std::endl - << std::endl; - } - else - { - int a = 0; - } - + // operator==() and operator!=() + // only structs without a union as a member can have a meaningfull == and != operation; we filter them out + if (!containsUnion(dependencyData.name, vkData.structs)) + { + ofs << " bool operator==( " << dependencyData.name << " const& rhs ) const" << std::endl + << " {" << std::endl + << " return "; + for (size_t i = 0; i < it->second.members.size(); i++) + { + if (i != 0) + { + ofs << std::endl << " && "; + } + if (!it->second.members[i].arraySize.empty()) + { + ofs << "( memcmp( " << it->second.members[i].name << ", rhs." << it->second.members[i].name << ", " << it->second.members[i].arraySize << " * sizeof( " << it->second.members[i].type << " ) ) == 0 )"; + } + else + { + ofs << "( " << it->second.members[i].name << " == rhs." << it->second.members[i].name << " )"; + } + } + ofs << ";" << std::endl + << " }" << std::endl + << std::endl + << " bool operator!=( " << dependencyData.name << " const& rhs ) const" << std::endl + << " {" << std::endl + << " return !operator==( rhs );" << std::endl + << " }" << std::endl + << std::endl; + } + // the member variables for (size_t i = 0; i < it->second.members.size(); i++) { @@ -2839,9 +2837,9 @@ void writeTypeStruct( std::ofstream & ofs, VkData const& vkData, DependencyData ofs << ";" << std::endl; } } - ofs << " };" << std::endl - << " static_assert( sizeof( " << dependencyData.name << " ) == sizeof( Vk" << dependencyData.name << " ), \"struct and wrapper have different size!\" );" << std::endl; - + ofs << " };" << std::endl + << " static_assert( sizeof( " << dependencyData.name << " ) == sizeof( Vk" << dependencyData.name << " ), \"struct and wrapper have different size!\" );" << std::endl; + leaveProtect(ofs, it->second.protect); ofs << std::endl; } @@ -2877,7 +2875,7 @@ void writeTypeUnion( std::ofstream & ofs, VkData const& vkData, DependencyData c } else { - ofs << " = { " << it->second << " }"; + ofs << " = { {" << it->second << "} }"; } } ofs << " )" << std::endl @@ -3081,14 +3079,18 @@ int main( int argc, char **argv ) << "#ifndef VULKAN_HPP" << std::endl << "#define VULKAN_HPP" << std::endl << std::endl + << "#include " << std::endl << "#include " << std::endl << "#include " << std::endl << "#include " << std::endl << "#include " << std::endl + << "#include " << std::endl << "#include " << std::endl << "#include " << std::endl + << "#include " << std::endl << "#include " << std::endl << "#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE" << std::endl + << "# include " << std::endl << "# include " << std::endl << "#endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/" << std::endl << std::endl; @@ -3131,12 +3133,14 @@ int main( int argc, char **argv ) << std::endl << "#endif" << std::endl; } - catch (std::exception e) + catch (std::exception const& e) { std::cout << "caught exception: " << e.what() << std::endl; + return -1; } catch (...) { std::cout << "caught unknown exception" << std::endl; + return -1; } } diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index 950b44e..89815ed 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -52,14 +52,18 @@ #ifndef VULKAN_HPP #define VULKAN_HPP +#include #include #include #include #include +#include #include #include +#include #include #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE +# include # include #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -216,6 +220,7 @@ namespace vk RefType *m_ptr; }; +#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template class ArrayProxy { @@ -305,6 +310,7 @@ namespace vk uint32_t m_count; T * m_ptr; }; +#endif enum class Result { @@ -2855,7 +2861,7 @@ namespace vk union ClearColorValue { - ClearColorValue( const std::array& float32_ = { 0 } ) + ClearColorValue( const std::array& float32_ = { {0} } ) { memcpy( &float32, float32_.data(), 4 * sizeof( float ) ); } @@ -8156,7 +8162,7 @@ namespace vk struct DebugMarkerMarkerInfoEXT { - DebugMarkerMarkerInfoEXT( const char* pMarkerName_ = nullptr, std::array const& color_ = { 0, 0, 0, 0 } ) + DebugMarkerMarkerInfoEXT( const char* pMarkerName_ = nullptr, std::array const& color_ = { { 0, 0, 0, 0 } } ) : sType( StructureType::eDebugMarkerMarkerInfoEXT ) , pNext( nullptr ) , pMarkerName( pMarkerName_ ) @@ -9655,7 +9661,7 @@ namespace vk struct PipelineColorBlendStateCreateInfo { - PipelineColorBlendStateCreateInfo( PipelineColorBlendStateCreateFlags flags_ = PipelineColorBlendStateCreateFlags(), Bool32 logicOpEnable_ = 0, LogicOp logicOp_ = LogicOp::eClear, uint32_t attachmentCount_ = 0, const PipelineColorBlendAttachmentState* pAttachments_ = nullptr, std::array const& blendConstants_ = { 0, 0, 0, 0 } ) + PipelineColorBlendStateCreateInfo( PipelineColorBlendStateCreateFlags flags_ = PipelineColorBlendStateCreateFlags(), Bool32 logicOpEnable_ = 0, LogicOp logicOp_ = LogicOp::eClear, uint32_t attachmentCount_ = 0, const PipelineColorBlendAttachmentState* pAttachments_ = nullptr, std::array const& blendConstants_ = { { 0, 0, 0, 0 } } ) : sType( StructureType::ePipelineColorBlendStateCreateInfo ) , pNext( nullptr ) , flags( flags_ ) @@ -10766,7 +10772,7 @@ namespace vk struct ImageBlit { - ImageBlit( ImageSubresourceLayers srcSubresource_ = ImageSubresourceLayers(), std::array const& srcOffsets_ = { Offset3D(), Offset3D() }, ImageSubresourceLayers dstSubresource_ = ImageSubresourceLayers(), std::array const& dstOffsets_ = { Offset3D(), Offset3D() } ) + ImageBlit( ImageSubresourceLayers srcSubresource_ = ImageSubresourceLayers(), std::array const& srcOffsets_ = { { Offset3D(), Offset3D() } }, ImageSubresourceLayers dstSubresource_ = ImageSubresourceLayers(), std::array const& dstOffsets_ = { { Offset3D(), Offset3D() } } ) : srcSubresource( srcSubresource_ ) , dstSubresource( dstSubresource_ ) {