diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..de03ecf --- /dev/null +++ b/.clang-format @@ -0,0 +1,334 @@ +--- +Language: Cpp +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: true + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseArrows: false + AlignCaseColons: false +AlignConsecutiveTableGenBreakingDAGArgColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveTableGenCondOperatorColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveTableGenDefinitionColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortBlocksOnASingleLine: Never +AllowShortCaseExpressionOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AllowShortNamespacesOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AttributeMacros: + - __capability + - absl_nonnull + - absl_nullable + - absl_nullability_unknown +BinPackArguments: false +BinPackLongBracedList: true +BinPackParameters: false +BitFieldColonSpacing: Both +BracedInitializerIndentWidth: -1 +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterExternBlock: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakAfterReturnType: None +BreakArrays: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: Allman +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTemplateCloser: false +BreakBeforeTernaryOperators: true +BreakBinaryOperations: Never +BreakConstructorInitializers: BeforeColon +BreakFunctionDefinitionParameters: false +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +BreakTemplateDeclarations: Yes +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 2 +ContinuationIndentWidth: 2 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +EnumTrailingComma: Leave +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^<.*\.h>' + Priority: 1 + SortPriority: 0 + CaseSensitive: false + - Regex: '^<.*' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 3 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '([-_](test|unittest))?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: true +IndentExportBlock: true +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLines: + AtEndOfFile: false + AtStartOfBlock: false + AtStartOfFile: true +KeepFormFeed: false +LambdaBodyIndentation: Signature +LineEnding: DeriveLF +MacroBlockBegin: '' +MacroBlockEnd: '' +MainIncludeChar: Quote +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: All +ObjCBinPackProtocolList: Never +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +OneLineFormatOffRegex: '' +PackConstructorInitializers: Never +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakBeforeMemberAccess: 150 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Left +PPIndentWidth: -1 +QualifierAlignment: Leave +RawStringFormats: + - Language: Cpp + Delimiters: + - cc + - CC + - cpp + - Cpp + - CPP + - 'c++' + - 'C++' + CanonicalDelimiter: '' + BasedOnStyle: google + - Language: TextProto + Delimiters: + - pb + - PB + - proto + - PROTO + EnclosingFunctions: + - EqualsProto + - EquivToProto + - PARSE_PARTIAL_TEXT_PROTO + - PARSE_TEST_PROTO + - PARSE_TEXT_PROTO + - ParseTextOrDie + - ParseTextProtoOrDie + - ParseTestProto + - ParsePartialTestProto + CanonicalDelimiter: pb + BasedOnStyle: google +ReferenceAlignment: Pointer +ReflowComments: Always +RemoveBracesLLVM: false +RemoveEmptyLinesInUnwrappedLines: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Always +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: + Enabled: true + IgnoreCase: false +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterOperatorKeyword: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterNot: false + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + ExceptDoubleParentheses: false + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: Auto +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TableGenBreakInsideDAGArg: DontBreak +TabWidth: 2 +UseTab: Never +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE +WrapNamespaceBodyWithEmptyLines: Leave +... + diff --git a/CopiumEngine/src/copium/asset/Asset.h b/CopiumEngine/src/copium/asset/Asset.h index bd42544..95c6a70 100644 --- a/CopiumEngine/src/copium/asset/Asset.h +++ b/CopiumEngine/src/copium/asset/Asset.h @@ -1,16 +1,17 @@ #pragma once +#include + #include "copium/asset/AssetMeta.h" #include "copium/util/Uuid.h" -#include - namespace Copium { class Asset { friend class AssetManager; + public: Asset(); virtual ~Asset(); diff --git a/CopiumEngine/src/copium/asset/AssetFile.cpp b/CopiumEngine/src/copium/asset/AssetFile.cpp index e0fddfd..ff78289 100644 --- a/CopiumEngine/src/copium/asset/AssetFile.cpp +++ b/CopiumEngine/src/copium/asset/AssetFile.cpp @@ -1,9 +1,9 @@ #include "copium/asset/AssetFile.h" -#include "copium/util/FileSystem.h" - #include +#include "copium/util/FileSystem.h" + namespace Copium { std::vector AssetFile::assetTypes; diff --git a/CopiumEngine/src/copium/asset/AssetFile.h b/CopiumEngine/src/copium/asset/AssetFile.h index e31963b..7f42089 100644 --- a/CopiumEngine/src/copium/asset/AssetFile.h +++ b/CopiumEngine/src/copium/asset/AssetFile.h @@ -8,6 +8,7 @@ namespace Copium class AssetFile { friend class AssetManager; + private: static std::vector assetTypes; std::string path; @@ -22,6 +23,7 @@ namespace Copium const std::string& GetPath() const; Uuid GetUuid() const; + private: void Load(MetaFile& metaFile, const std::string& className); static void RegisterAssetType(const std::string& assetType); diff --git a/CopiumEngine/src/copium/asset/AssetHandle.h b/CopiumEngine/src/copium/asset/AssetHandle.h index 851423f..b21caa3 100644 --- a/CopiumEngine/src/copium/asset/AssetHandle.h +++ b/CopiumEngine/src/copium/asset/AssetHandle.h @@ -1,7 +1,7 @@ #pragma once -#include "copium/asset/AssetMeta.h" #include "copium/asset/AssetManager.h" +#include "copium/asset/AssetMeta.h" namespace Copium { @@ -11,27 +11,33 @@ namespace Copium public: AssetHandle() : id{NULL_ASSET_ID} - {} + { + } AssetHandle(const std::string& assetName) : id{AssetManager::LoadAsset(assetName).GetId()} - {} + { + } AssetHandle(const Uuid& uuid) : id{AssetManager::LoadAsset(uuid).GetId()} - {} + { + } AssetHandle(AssetType& asset) : id{AssetManager::DuplicateAsset(asset.GetId())} - {} + { + } AssetHandle(const std::string& name, std::unique_ptr&& runtimeAsset) : id{AssetManager::RegisterRuntimeAsset(name, std::move(runtimeAsset)).GetId()} - {} + { + } AssetHandle(AssetId id) : id{AssetManager::DuplicateAsset(id)} - {} + { + } AssetId GetId() const { @@ -53,6 +59,7 @@ namespace Copium { return id != NULL_ASSET_ID; } + private: AssetId id; }; diff --git a/CopiumEngine/src/copium/asset/AssetManager.cpp b/CopiumEngine/src/copium/asset/AssetManager.cpp index 46ce986..a2916c9 100644 --- a/CopiumEngine/src/copium/asset/AssetManager.cpp +++ b/CopiumEngine/src/copium/asset/AssetManager.cpp @@ -1,11 +1,11 @@ #include "copium/asset/AssetManager.h" +#include +#include + #include "copium/util/Common.h" #include "copium/util/MetaFile.h" -#include -#include - namespace Copium { std::vector AssetManager::assetDirs; @@ -27,7 +27,11 @@ namespace Copium if (std::filesystem::is_directory(it->path())) continue; std::filesystem::path assetDirPath{assetDir}; - std::string assetPath = assetDir + "/" + std::filesystem::absolute(it->path()).string().substr(std::filesystem::absolute(assetDirPath).string().size() + 1).c_str(); + std::string assetPath = assetDir + "/" + + std::filesystem::absolute(it->path()) + .string() + .substr(std::filesystem::absolute(assetDirPath).string().size() + 1) + .c_str(); try { CP_DEBUG("Registering Asset: %s", assetPath.c_str()); @@ -45,7 +49,7 @@ namespace Copium if (assetDir.back() == '/') assetDir.pop_back(); - for (auto it = assetDirs.begin(); it != assetDirs.end(); ++it) + for (auto it = assetDirs.begin(); it != assetDirs.end(); ++it) { if (*it == assetDir) { @@ -79,8 +83,7 @@ namespace Copium CP_ABORT("Unknown Asset: %s", assetPath.c_str()); } - - Asset& AssetManager::LoadAsset(const Uuid& uuid) + Asset& AssetManager::LoadAsset(const Uuid& uuid) { CP_DEBUG("Loading uuid Asset: %s", uuid.ToString().c_str()); for (auto&& assetFile : cachedAssetFiles) @@ -115,7 +118,8 @@ namespace Copium CP_WARN("Asset not loaded"); return; } - CP_DEBUG("Unloading Asset: %s (%d instances left)", it->second->GetName().c_str(), it->second->metaData.loadCount - 1); + CP_DEBUG( + "Unloading Asset: %s (%d instances left)", it->second->GetName().c_str(), it->second->metaData.loadCount - 1); it->second->metaData.loadCount--; if (it->second->metaData.loadCount > 0) @@ -133,7 +137,7 @@ namespace Copium return cachedAssetFiles; } - void AssetManager::Cleanup() + void AssetManager::Cleanup() { if (assets.empty()) return; @@ -177,7 +181,7 @@ namespace Copium MetaFile metaFile{filepath}; for (auto& assetType : assetTypes) { - if(metaFile.HasMetaClass(assetType.first)) + if (metaFile.HasMetaClass(assetType.first)) return assetType.second(metaFile, assetType.first); } CP_ABORT("Unknown Asset type: %s", filepath.c_str()); diff --git a/CopiumEngine/src/copium/asset/AssetManager.h b/CopiumEngine/src/copium/asset/AssetManager.h index e9bad4b..ee18485 100644 --- a/CopiumEngine/src/copium/asset/AssetManager.h +++ b/CopiumEngine/src/copium/asset/AssetManager.h @@ -1,18 +1,19 @@ #pragma once -#include "copium/asset/Asset.h" -#include "copium/asset/AssetFile.h" -#include "copium/util/Common.h" - #include #include #include +#include "copium/asset/Asset.h" +#include "copium/asset/AssetFile.h" +#include "copium/util/Common.h" + namespace Copium { class AssetManager { CP_STATIC_CLASS(AssetManager); + private: using CreateAssetFunc = std::function; static std::map assetTypes; @@ -24,7 +25,7 @@ namespace Copium static AssetId assetId; static AssetId runtimeAssetId; - static std::vector cachedAssetFiles; // TODO: Make a set? + static std::vector cachedAssetFiles; // TODO: Make a set? public: static void RegisterAssetDir(std::string assetDir); static void UnregisterAssetDir(std::string assetDir); @@ -40,7 +41,9 @@ namespace Copium template static void RegisterAssetType(const std::string& assetType) { - CP_ASSERT(assetTypes.emplace(assetType, &AssetManager::CreateAsset).second, "Asset type already exists: %s", assetType.c_str()); + CP_ASSERT(assetTypes.emplace(assetType, &AssetManager::CreateAsset).second, + "Asset type already exists: %s", + assetType.c_str()); AssetFile::RegisterAssetType(assetType); } @@ -61,7 +64,7 @@ namespace Copium } template - static AssetT& GetAsset(AssetId id) + static AssetT& GetAsset(AssetId id) { Asset& asset = GetAsset(id); AssetT* assetT = dynamic_cast(&asset); diff --git a/CopiumEngine/src/copium/asset/AssetMeta.h b/CopiumEngine/src/copium/asset/AssetMeta.h index 1f3f735..2b2ebe9 100644 --- a/CopiumEngine/src/copium/asset/AssetMeta.h +++ b/CopiumEngine/src/copium/asset/AssetMeta.h @@ -1,10 +1,11 @@ #pragma once -#include "copium/util/Uuid.h" - #include + #include +#include "copium/util/Uuid.h" + namespace Copium { static constexpr int NULL_ASSET_ID = 0; diff --git a/CopiumEngine/src/copium/asset/AssetRef.h b/CopiumEngine/src/copium/asset/AssetRef.h index 22a7598..106ace2 100644 --- a/CopiumEngine/src/copium/asset/AssetRef.h +++ b/CopiumEngine/src/copium/asset/AssetRef.h @@ -10,39 +10,53 @@ namespace Copium public: AssetRef() : id{std::shared_ptr(new AssetId(NULL_ASSET_ID), AssetIdUnloader{})} - {} + { + } explicit AssetRef(const std::string& assetName) : id{std::shared_ptr(new AssetId(AssetManager::LoadAsset(assetName).GetId()), AssetIdUnloader{})} - {} + { + } explicit AssetRef(const Uuid& uuid) : id{std::shared_ptr(new AssetId(AssetManager::LoadAsset(uuid).GetId()), AssetIdUnloader{})} - {} + { + } explicit AssetRef(AssetType& asset) : id{std::shared_ptr(new AssetId(AssetManager::DuplicateAsset(asset.GetId())), AssetIdUnloader{})} - {} + { + } explicit AssetRef(std::unique_ptr&& runtimeAsset) - : id{std::shared_ptr(new AssetId(AssetManager::RegisterRuntimeAsset(Uuid{}, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})} - {} + : id{std::shared_ptr( + new AssetId(AssetManager::RegisterRuntimeAsset(Uuid{}, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})} + { + } AssetRef(const Uuid& uuid, std::unique_ptr&& runtimeAsset) - : id{std::shared_ptr(new AssetId(AssetManager::RegisterRuntimeAsset(uuid, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})} - {} + : id{std::shared_ptr( + new AssetId(AssetManager::RegisterRuntimeAsset(uuid, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})} + { + } AssetRef(const std::string& name, std::unique_ptr&& runtimeAsset) - : id{std::shared_ptr(new AssetId(AssetManager::RegisterRuntimeAsset(name, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})} - {} + : id{std::shared_ptr( + new AssetId(AssetManager::RegisterRuntimeAsset(name, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})} + { + } AssetRef(const std::string& name, const Uuid& uuid, std::unique_ptr&& runtimeAsset) - : id{std::shared_ptr(new AssetId(AssetManager::RegisterRuntimeAsset(name, uuid, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})} - {} + : id{std::shared_ptr( + new AssetId(AssetManager::RegisterRuntimeAsset(name, uuid, std::move(runtimeAsset)).GetId()), + AssetIdUnloader{})} + { + } AssetRef(AssetId id) : id{std::shared_ptr(new AssetId(AssetManager::DuplicateAsset(id)), AssetIdUnloader{})} - {} + { + } AssetId GetId() const { @@ -60,7 +74,8 @@ namespace Copium } private: - struct AssetIdUnloader { + struct AssetIdUnloader + { void operator()(AssetId* id) { if (*id != NULL_ASSET_ID) @@ -69,6 +84,7 @@ namespace Copium } } }; + private: std::shared_ptr id; }; diff --git a/CopiumEngine/src/copium/buffer/Buffer.cpp b/CopiumEngine/src/copium/buffer/Buffer.cpp index 7c118f8..e70aefc 100644 --- a/CopiumEngine/src/copium/buffer/Buffer.cpp +++ b/CopiumEngine/src/copium/buffer/Buffer.cpp @@ -5,7 +5,8 @@ namespace Copium { Buffer::Buffer(VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkDeviceSize size, int count) - : size{size}, count{count} + : size{size}, + count{count} { VkBufferCreateInfo createInfo{}; createInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; @@ -23,7 +24,8 @@ namespace Copium allocateInfo.allocationSize = memoryRequirements.size; allocateInfo.memoryTypeIndex = Vulkan::GetDevice().FindMemoryType(memoryRequirements.memoryTypeBits, properties); - CP_VK_ASSERT(vkAllocateMemory(Vulkan::GetDevice(), &allocateInfo, nullptr, &memory), "Failed to allocate buffer memory"); + CP_VK_ASSERT(vkAllocateMemory(Vulkan::GetDevice(), &allocateInfo, nullptr, &memory), + "Failed to allocate buffer memory"); vkBindBufferMemory(Vulkan::GetDevice(), handle, memory, 0); } @@ -32,10 +34,12 @@ namespace Copium { VkDeviceMemory memoryCpy = memory; VkBuffer handleCpy = handle; - Vulkan::GetDevice().QueueIdleCommand([memoryCpy, handleCpy]() { - vkFreeMemory(Vulkan::GetDevice(), memoryCpy, nullptr); - vkDestroyBuffer(Vulkan::GetDevice(), handleCpy, nullptr); - }); + Vulkan::GetDevice().QueueIdleCommand( + [memoryCpy, handleCpy]() + { + vkFreeMemory(Vulkan::GetDevice(), memoryCpy, nullptr); + vkDestroyBuffer(Vulkan::GetDevice(), handleCpy, nullptr); + }); } void Buffer::Update(void* indexData, int index) @@ -58,7 +62,10 @@ namespace Copium void Buffer::UpdateStaging(void* data) { VkDeviceSize bufferSize = size * count; - Buffer stagingBuffer{VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, bufferSize, 1}; + Buffer stagingBuffer{VK_BUFFER_USAGE_TRANSFER_SRC_BIT, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, + bufferSize, + 1}; stagingBuffer.Update(data, 0); @@ -67,7 +74,10 @@ namespace Copium void Buffer::UpdateStaging(void* data, VkDeviceSize offset, VkDeviceSize size) { - Buffer stagingBuffer{VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, size, 1}; + Buffer stagingBuffer{VK_BUFFER_USAGE_TRANSFER_SRC_BIT, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, + size, + 1}; stagingBuffer.Update(data, 0); @@ -89,7 +99,7 @@ namespace Copium mappedData = nullptr; } - Buffer::operator VkBuffer() const + Buffer::operator VkBuffer() const { return handle; } @@ -115,7 +125,8 @@ namespace Copium allocateInfo.commandBufferCount = 1; VkCommandBuffer commandBuffer; - CP_VK_ASSERT(vkAllocateCommandBuffers(Vulkan::GetDevice(), &allocateInfo, &commandBuffer), "Failed to initialize command buffer"); + CP_VK_ASSERT(vkAllocateCommandBuffers(Vulkan::GetDevice(), &allocateInfo, &commandBuffer), + "Failed to initialize command buffer"); VkCommandBufferBeginInfo beginInfo{}; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; diff --git a/CopiumEngine/src/copium/buffer/Buffer.h b/CopiumEngine/src/copium/buffer/Buffer.h index 0722cfe..a1d150d 100644 --- a/CopiumEngine/src/copium/buffer/Buffer.h +++ b/CopiumEngine/src/copium/buffer/Buffer.h @@ -1,14 +1,15 @@ #pragma once -#include "copium/util/Common.h" - #include +#include "copium/util/Common.h" + namespace Copium { class Buffer { CP_DELETE_COPY_AND_MOVE_CTOR(Buffer); + protected: VkDeviceMemory memory; VkBuffer handle; diff --git a/CopiumEngine/src/copium/buffer/CommandBuffer.cpp b/CopiumEngine/src/copium/buffer/CommandBuffer.cpp index 2f7b7e1..e1ad7c4 100644 --- a/CopiumEngine/src/copium/buffer/CommandBuffer.cpp +++ b/CopiumEngine/src/copium/buffer/CommandBuffer.cpp @@ -9,14 +9,14 @@ namespace Copium { switch (type) { - case CommandBufferType::SingleUse: - commandBuffers.resize(1); - break; - case CommandBufferType::Dynamic: - commandBuffers.resize(SwapChain::MAX_FRAMES_IN_FLIGHT); - break; - default: - CP_ABORT("Unreachable switch case: %s", ToString(type).c_str()); + case CommandBufferType::SingleUse: + commandBuffers.resize(1); + break; + case CommandBufferType::Dynamic: + commandBuffers.resize(SwapChain::MAX_FRAMES_IN_FLIGHT); + break; + default: + CP_ABORT("Unreachable switch case: %s", ToString(type).c_str()); } VkCommandBufferAllocateInfo allocateInfo{}; @@ -24,15 +24,21 @@ namespace Copium allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; allocateInfo.commandPool = Vulkan::GetDevice().GetCommandPool(); allocateInfo.commandBufferCount = commandBuffers.size(); - CP_VK_ASSERT(vkAllocateCommandBuffers(Vulkan::GetDevice(), &allocateInfo, commandBuffers.data()), "Failed to allocate CommandBuffer"); + CP_VK_ASSERT(vkAllocateCommandBuffers(Vulkan::GetDevice(), &allocateInfo, commandBuffers.data()), + "Failed to allocate CommandBuffer"); } CommandBuffer::~CommandBuffer() { std::vector commandBuffersCpy = commandBuffers; - Vulkan::GetDevice().QueueIdleCommand([commandBuffersCpy]() { - vkFreeCommandBuffers(Vulkan::GetDevice(), Vulkan::GetDevice().GetCommandPool(), commandBuffersCpy.size(), commandBuffersCpy.data()); - }); + Vulkan::GetDevice().QueueIdleCommand( + [commandBuffersCpy]() + { + vkFreeCommandBuffers(Vulkan::GetDevice(), + Vulkan::GetDevice().GetCommandPool(), + commandBuffersCpy.size(), + commandBuffersCpy.data()); + }); } // TODO: Test as constexpr function to see if it avoids the switch case @@ -45,17 +51,18 @@ namespace Copium switch (type) { - case CommandBufferType::SingleUse: - beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; - break; - case CommandBufferType::Dynamic: - break; - default: - CP_ABORT("Unreachable switch case: %s", ToString(type).c_str()); + case CommandBufferType::SingleUse: + beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + break; + case CommandBufferType::Dynamic: + break; + default: + CP_ABORT("Unreachable switch case: %s", ToString(type).c_str()); } vkResetCommandBuffer(commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()], 0); - CP_VK_ASSERT(vkBeginCommandBuffer(commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()], &beginInfo), "Failed to begin command buffer"); + CP_VK_ASSERT(vkBeginCommandBuffer(commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()], &beginInfo), + "Failed to begin command buffer"); } void CommandBuffer::End() diff --git a/CopiumEngine/src/copium/buffer/CommandBuffer.h b/CopiumEngine/src/copium/buffer/CommandBuffer.h index 56aa724..108bcbf 100644 --- a/CopiumEngine/src/copium/buffer/CommandBuffer.h +++ b/CopiumEngine/src/copium/buffer/CommandBuffer.h @@ -1,10 +1,10 @@ #pragma once +#include + #include "copium/util/Common.h" #include "copium/util/Enum.h" -#include - #define CP_COMMAND_BUFFER_TYPE_ENUMS SingleUse, Dynamic CP_ENUM_CREATOR(Copium, CommandBufferType, CP_COMMAND_BUFFER_TYPE_ENUMS); @@ -13,6 +13,7 @@ namespace Copium class CommandBuffer { CP_DELETE_COPY_AND_MOVE_CTOR(CommandBuffer); + private: std::vector commandBuffers; const CommandBufferType type; diff --git a/CopiumEngine/src/copium/buffer/CommandBufferScoped.h b/CopiumEngine/src/copium/buffer/CommandBufferScoped.h index 442ba16..c9a2565 100644 --- a/CopiumEngine/src/copium/buffer/CommandBufferScoped.h +++ b/CopiumEngine/src/copium/buffer/CommandBufferScoped.h @@ -8,6 +8,7 @@ namespace Copium class CommandBufferScoped final : public CommandBuffer { CP_DELETE_COPY_AND_MOVE_CTOR(CommandBufferScoped); + public: CommandBufferScoped(); diff --git a/CopiumEngine/src/copium/buffer/Framebuffer.cpp b/CopiumEngine/src/copium/buffer/Framebuffer.cpp index bdd7e37..55a5b69 100644 --- a/CopiumEngine/src/copium/buffer/Framebuffer.cpp +++ b/CopiumEngine/src/copium/buffer/Framebuffer.cpp @@ -24,7 +24,8 @@ namespace Copium } Framebuffer::Framebuffer(int width, int height, const SamplerCreator& samplerCreator) - : width{width}, height{height} + : width{width}, + height{height} { CP_ASSERT(width > 0, "Width of framebuffer is less than 1: %d", width); CP_ASSERT(height > 0, "Height of framebuffer is less than 1: %d", height); @@ -39,11 +40,13 @@ namespace Copium { std::vector framebuffersCpy = framebuffers; VkRenderPass renderPassCpy = renderPass; - Vulkan::GetDevice().QueueIdleCommand([framebuffersCpy, renderPassCpy]() { - for (auto& framebuffer : framebuffersCpy) - vkDestroyFramebuffer(Vulkan::GetDevice(), framebuffer, nullptr); - vkDestroyRenderPass(Vulkan::GetDevice(), renderPassCpy, nullptr); - }); + Vulkan::GetDevice().QueueIdleCommand( + [framebuffersCpy, renderPassCpy]() + { + for (auto& framebuffer : framebuffersCpy) + vkDestroyFramebuffer(Vulkan::GetDevice(), framebuffer, nullptr); + vkDestroyRenderPass(Vulkan::GetDevice(), renderPassCpy, nullptr); + }); } void Framebuffer::Resize(int width, int height) @@ -193,7 +196,8 @@ namespace Copium renderPassCreateInfo.dependencyCount = dependencies.size(); renderPassCreateInfo.pDependencies = dependencies.data(); - CP_VK_ASSERT(vkCreateRenderPass(Vulkan::GetDevice(), &renderPassCreateInfo, nullptr, &renderPass), "Failed to initialze render pass"); + CP_VK_ASSERT(vkCreateRenderPass(Vulkan::GetDevice(), &renderPassCreateInfo, nullptr, &renderPass), + "Failed to initialze render pass"); } void Framebuffer::InitializeFramebuffers() @@ -213,7 +217,8 @@ namespace Copium createInfo.height = height; createInfo.layers = 1; - CP_VK_ASSERT(vkCreateFramebuffer(Vulkan::GetDevice(), &createInfo, nullptr, &framebuffers[i]), "Failed to initialize framebuffer"); + CP_VK_ASSERT(vkCreateFramebuffer(Vulkan::GetDevice(), &createInfo, nullptr, &framebuffers[i]), + "Failed to initialize framebuffer"); } } } diff --git a/CopiumEngine/src/copium/buffer/Framebuffer.h b/CopiumEngine/src/copium/buffer/Framebuffer.h index 9718b2d..83a54d6 100644 --- a/CopiumEngine/src/copium/buffer/Framebuffer.h +++ b/CopiumEngine/src/copium/buffer/Framebuffer.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "copium/asset/Asset.h" #include "copium/asset/AssetRef.h" #include "copium/buffer/CommandBuffer.h" @@ -7,13 +9,12 @@ #include "copium/sampler/DepthAttachment.h" #include "copium/util/Common.h" -#include - namespace Copium { class Framebuffer final : public Asset { CP_DELETE_COPY_AND_MOVE_CTOR(Framebuffer); + private: AssetRef colorAttachment; std::unique_ptr depthAttachment; @@ -22,6 +23,7 @@ namespace Copium int width; int height; + public: Framebuffer(const MetaFile& metaFile); Framebuffer(int width, int height, const SamplerCreator& samplerCreator); diff --git a/CopiumEngine/src/copium/buffer/IndexBuffer.cpp b/CopiumEngine/src/copium/buffer/IndexBuffer.cpp index 8212837..176c22e 100644 --- a/CopiumEngine/src/copium/buffer/IndexBuffer.cpp +++ b/CopiumEngine/src/copium/buffer/IndexBuffer.cpp @@ -7,9 +7,11 @@ namespace Copium IndexBuffer::IndexBuffer(int indexCount) : Buffer{VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, - indexCount * sizeof(uint16_t), 1}, + indexCount * sizeof(uint16_t), + 1}, indexCount{indexCount} - {} + { + } void IndexBuffer::Bind(const CommandBuffer& commandBuffer) { diff --git a/CopiumEngine/src/copium/buffer/IndexBuffer.h b/CopiumEngine/src/copium/buffer/IndexBuffer.h index 3c45871..98a3a4f 100644 --- a/CopiumEngine/src/copium/buffer/IndexBuffer.h +++ b/CopiumEngine/src/copium/buffer/IndexBuffer.h @@ -9,8 +9,10 @@ namespace Copium class IndexBuffer final : public Buffer { CP_DELETE_COPY_AND_MOVE_CTOR(IndexBuffer); + private: int indexCount; + public: IndexBuffer(int indexCount); diff --git a/CopiumEngine/src/copium/buffer/RendererVertexBuffer.cpp b/CopiumEngine/src/copium/buffer/RendererVertexBuffer.cpp index 628720b..ad235bd 100644 --- a/CopiumEngine/src/copium/buffer/RendererVertexBuffer.cpp +++ b/CopiumEngine/src/copium/buffer/RendererVertexBuffer.cpp @@ -6,8 +6,12 @@ namespace Copium { RendererVertexBuffer::RendererVertexBuffer(const VertexDescriptor& descriptor, int vertexCount) - : Buffer{VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, descriptor.GetVertexSize() * vertexCount, SwapChain::MAX_FRAMES_IN_FLIGHT} - {} + : Buffer{VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, + descriptor.GetVertexSize() * vertexCount, + SwapChain::MAX_FRAMES_IN_FLIGHT} + { + } void RendererVertexBuffer::Bind(const CommandBuffer& commandBuffer) { diff --git a/CopiumEngine/src/copium/buffer/RendererVertexBuffer.h b/CopiumEngine/src/copium/buffer/RendererVertexBuffer.h index 6f29244..0e923b5 100644 --- a/CopiumEngine/src/copium/buffer/RendererVertexBuffer.h +++ b/CopiumEngine/src/copium/buffer/RendererVertexBuffer.h @@ -9,6 +9,7 @@ namespace Copium class RendererVertexBuffer : public Buffer { CP_DELETE_COPY_AND_MOVE_CTOR(RendererVertexBuffer); + public: RendererVertexBuffer(const VertexDescriptor& descriptor, int vertexCount); diff --git a/CopiumEngine/src/copium/buffer/UniformBuffer.cpp b/CopiumEngine/src/copium/buffer/UniformBuffer.cpp index f8b869a..2a95a68 100644 --- a/CopiumEngine/src/copium/buffer/UniformBuffer.cpp +++ b/CopiumEngine/src/copium/buffer/UniformBuffer.cpp @@ -5,7 +5,11 @@ namespace Copium { UniformBuffer::UniformBuffer(ShaderBinding binding) - : Buffer{VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, binding.GetUniformBufferSize(), SwapChain::MAX_FRAMES_IN_FLIGHT}, binding{binding} + : Buffer{VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, + binding.GetUniformBufferSize(), + SwapChain::MAX_FRAMES_IN_FLIGHT}, + binding{binding} { buffer.resize(Buffer::GetSize()); } diff --git a/CopiumEngine/src/copium/buffer/UniformBuffer.h b/CopiumEngine/src/copium/buffer/UniformBuffer.h index 887b3c0..22b4da5 100644 --- a/CopiumEngine/src/copium/buffer/UniformBuffer.h +++ b/CopiumEngine/src/copium/buffer/UniformBuffer.h @@ -1,17 +1,18 @@ #pragma once +#include +#include + #include "copium/buffer/Buffer.h" #include "copium/pipeline/ShaderBinding.h" #include "copium/util/Common.h" -#include -#include - namespace Copium { class UniformBuffer final : public Buffer { CP_DELETE_COPY_AND_MOVE_CTOR(UniformBuffer); + private: ShaderBinding binding; std::vector buffer; diff --git a/CopiumEngine/src/copium/buffer/VertexBuffer.cpp b/CopiumEngine/src/copium/buffer/VertexBuffer.cpp index 4734c37..508af7d 100644 --- a/CopiumEngine/src/copium/buffer/VertexBuffer.cpp +++ b/CopiumEngine/src/copium/buffer/VertexBuffer.cpp @@ -3,7 +3,10 @@ namespace Copium { VertexBuffer::VertexBuffer(const VertexDescriptor& descriptor, int vertexCount) - : Buffer{VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, descriptor.GetVertexSize() * vertexCount, 1} + : Buffer{VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, + descriptor.GetVertexSize() * vertexCount, + 1} { VkDeviceSize offset = 0; for (auto&& binding : descriptor.GetBindings()) diff --git a/CopiumEngine/src/copium/buffer/VertexBuffer.h b/CopiumEngine/src/copium/buffer/VertexBuffer.h index 05547f5..58217e2 100644 --- a/CopiumEngine/src/copium/buffer/VertexBuffer.h +++ b/CopiumEngine/src/copium/buffer/VertexBuffer.h @@ -1,21 +1,23 @@ #pragma once +#include +#include + #include "copium/buffer/Buffer.h" #include "copium/buffer/CommandBuffer.h" #include "copium/pipeline/VertexDescriptor.h" #include "copium/util/Common.h" -#include -#include - namespace Copium { class VertexBuffer final : public Buffer { CP_DELETE_COPY_AND_MOVE_CTOR(VertexBuffer); + private: std::vector bindingOffsets; std::vector bindingSizes; + public: VertexBuffer(const VertexDescriptor& descriptor, int vertexCount); diff --git a/CopiumEngine/src/copium/core/DebugMessenger.cpp b/CopiumEngine/src/copium/core/DebugMessenger.cpp index d4c9621..4bb7539 100644 --- a/CopiumEngine/src/copium/core/DebugMessenger.cpp +++ b/CopiumEngine/src/copium/core/DebugMessenger.cpp @@ -18,7 +18,8 @@ namespace Copium VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT; createInfo.pfnUserCallback = DebugCallback; createInfo.pUserData = nullptr; - CP_VK_ASSERT(vkCreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &debugMessenger), "Failed to initialze debug messenger"); + CP_VK_ASSERT(vkCreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &debugMessenger), + "Failed to initialze debug messenger"); } DebugMessenger::~DebugMessenger() @@ -38,22 +39,27 @@ namespace Copium #else DebugMessenger::DebugMessenger(Instance& instance) : instance{instance} - {} + { + } DebugMessenger::~DebugMessenger() - {} + { + } void DebugMessenger::AddRequiredExtensions(std::vector* extensions) - {} + { + } void DebugMessenger::AddRequiredLayers(std::vector* layers) - {} + { + } #endif - VKAPI_ATTR VkBool32 VKAPI_CALL DebugMessenger::DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, - VkDebugUtilsMessageTypeFlagsEXT messageType, - const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, - void* pUserData) + VKAPI_ATTR VkBool32 VKAPI_CALL + DebugMessenger::DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, + VkDebugUtilsMessageTypeFlagsEXT messageType, + const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, + void* pUserData) { if (messageSeverity >= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) { @@ -78,10 +84,12 @@ namespace Copium void DebugMessenger::vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, - const VkAllocationCallbacks* pAllocator) { - auto func = (PFN_vkDestroyDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT"); - if (func != nullptr) { - func(instance, debugMessenger, pAllocator); + const VkAllocationCallbacks* pAllocator) + { + auto func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT"); + if (func != nullptr) + { + func(instance, debugMessenger, pAllocator); } } diff --git a/CopiumEngine/src/copium/core/DebugMessenger.h b/CopiumEngine/src/copium/core/DebugMessenger.h index 1c9623d..a27381d 100644 --- a/CopiumEngine/src/copium/core/DebugMessenger.h +++ b/CopiumEngine/src/copium/core/DebugMessenger.h @@ -1,9 +1,9 @@ #pragma once -#include "copium/util/Common.h" - #include +#include "copium/util/Common.h" + namespace Copium { class Instance; @@ -11,10 +11,12 @@ namespace Copium class DebugMessenger final { CP_DELETE_COPY_AND_MOVE_CTOR(DebugMessenger); + private: Instance& instance; VkDebugUtilsMessengerEXT debugMessenger; + public: DebugMessenger(Instance& instance); ~DebugMessenger(); diff --git a/CopiumEngine/src/copium/core/Device.cpp b/CopiumEngine/src/copium/core/Device.cpp index 522921d..0b8eb67 100644 --- a/CopiumEngine/src/copium/core/Device.cpp +++ b/CopiumEngine/src/copium/core/Device.cpp @@ -115,7 +115,10 @@ namespace Copium devicePriorities.emplace_back(device, GetPhysicalDevicePriority(device)); } - std::sort(devicePriorities.begin(), devicePriorities.end(), [](const std::pair& lhs, const std::pair& rhs) { return lhs.second > rhs.second; }); + std::sort(devicePriorities.begin(), + devicePriorities.end(), + [](const std::pair& lhs, const std::pair& rhs) + { return lhs.second > rhs.second; }); auto&& it = devicePriorities.begin(); CP_ASSERT(it->second != 0, "Failed to find suitable gpu"); diff --git a/CopiumEngine/src/copium/core/Device.h b/CopiumEngine/src/copium/core/Device.h index f48118a..97ab45e 100644 --- a/CopiumEngine/src/copium/core/Device.h +++ b/CopiumEngine/src/copium/core/Device.h @@ -1,17 +1,19 @@ #pragma once -#include "copium/util/Common.h" - -#include -#include #include +#include +#include + +#include "copium/util/Common.h" namespace Copium { class Vulkan; + class Device { CP_DELETE_COPY_AND_MOVE_CTOR(Device); + public: Device(); ~Device(); diff --git a/CopiumEngine/src/copium/core/ImGuiInstance.cpp b/CopiumEngine/src/copium/core/ImGuiInstance.cpp index 6fa84b6..e5fcce4 100644 --- a/CopiumEngine/src/copium/core/ImGuiInstance.cpp +++ b/CopiumEngine/src/copium/core/ImGuiInstance.cpp @@ -1,11 +1,11 @@ #include "ImGuiInstance.h" -#include "copium/core/Vulkan.h" -#include "copium/buffer/CommandBufferScoped.h" - -#include #include #include +#include + +#include "copium/buffer/CommandBufferScoped.h" +#include "copium/core/Vulkan.h" namespace Copium { @@ -92,7 +92,8 @@ namespace Copium createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; createInfo.bindingCount = 1; createInfo.pBindings = layoutBindings.data(); - CP_VK_ASSERT(vkCreateDescriptorSetLayout(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorSetLayout), "Failed to create ImGui DescriptorSetLayout"); + CP_VK_ASSERT(vkCreateDescriptorSetLayout(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorSetLayout), + "Failed to create ImGui DescriptorSetLayout"); ShaderBinding binding; binding.name = "texture"; diff --git a/CopiumEngine/src/copium/core/Instance.cpp b/CopiumEngine/src/copium/core/Instance.cpp index 392cc59..0f065e5 100644 --- a/CopiumEngine/src/copium/core/Instance.cpp +++ b/CopiumEngine/src/copium/core/Instance.cpp @@ -1,9 +1,9 @@ #include "Instance.h" -#include "copium/util/Common.h" - #include +#include "copium/util/Common.h" + namespace Copium { Instance::Instance(const std::string& applicationName) diff --git a/CopiumEngine/src/copium/core/Instance.h b/CopiumEngine/src/copium/core/Instance.h index a177d2d..c33afe2 100644 --- a/CopiumEngine/src/copium/core/Instance.h +++ b/CopiumEngine/src/copium/core/Instance.h @@ -7,6 +7,7 @@ namespace Copium class Instance final { CP_DELETE_COPY_AND_MOVE_CTOR(Instance); + private: VkInstance instance; std::unique_ptr debugMessenger; diff --git a/CopiumEngine/src/copium/core/QueueFamilies.h b/CopiumEngine/src/copium/core/QueueFamilies.h index 2d546ec..1bb2c07 100644 --- a/CopiumEngine/src/copium/core/QueueFamilies.h +++ b/CopiumEngine/src/copium/core/QueueFamilies.h @@ -1,8 +1,9 @@ #pragma once -#include #include +#include + namespace Copium { struct QueueFamiliesQuery diff --git a/CopiumEngine/src/copium/core/SwapChain.cpp b/CopiumEngine/src/copium/core/SwapChain.cpp index c68f3bc..cc0c943 100644 --- a/CopiumEngine/src/copium/core/SwapChain.cpp +++ b/CopiumEngine/src/copium/core/SwapChain.cpp @@ -35,7 +35,8 @@ namespace Copium } SwapChain::SwapChain() - : flightIndex{0}, resizeFramebuffer{false} + : flightIndex{0}, + resizeFramebuffer{false} { Initialize(); InitializeImageViews(); @@ -120,7 +121,8 @@ namespace Copium { vkWaitForFences(Vulkan::GetDevice(), 1, &inFlightFences[flightIndex], VK_TRUE, UINT64_MAX); - VkResult result = vkAcquireNextImageKHR(Vulkan::GetDevice(), handle, UINT64_MAX, imageAvailableSemaphores[flightIndex], VK_NULL_HANDLE, &imageIndex); + VkResult result = vkAcquireNextImageKHR( + Vulkan::GetDevice(), handle, UINT64_MAX, imageAvailableSemaphores[flightIndex], VK_NULL_HANDLE, &imageIndex); if (result == VK_ERROR_OUT_OF_DATE_KHR) { Recreate(); @@ -144,7 +146,8 @@ namespace Copium submitInfo.signalSemaphoreCount = 1; submitInfo.pSignalSemaphores = &renderFinishedSemaphores[imageIndex]; - CP_VK_ASSERT(vkQueueSubmit(Vulkan::GetDevice().GetGraphicsQueue(), 1, &submitInfo, inFlightFences[flightIndex]), "Failed to submit command buffer"); + CP_VK_ASSERT(vkQueueSubmit(Vulkan::GetDevice().GetGraphicsQueue(), 1, &submitInfo, inFlightFences[flightIndex]), + "Failed to submit command buffer"); } void SwapChain::EndPresent() @@ -248,7 +251,8 @@ namespace Copium createInfo.pQueueFamilyIndices = nullptr; } - CP_VK_ASSERT(vkCreateSwapchainKHR(Vulkan::GetDevice(), &createInfo, nullptr, &handle), "Failed to initialize the swapchain"); + CP_VK_ASSERT(vkCreateSwapchainKHR(Vulkan::GetDevice(), &createInfo, nullptr, &handle), + "Failed to initialize the swapchain"); vkGetSwapchainImagesKHR(Vulkan::GetDevice(), handle, &imageCount, nullptr); images.resize(imageCount); @@ -308,8 +312,10 @@ namespace Copium VkSubpassDependency dependency{}; dependency.srcSubpass = VK_SUBPASS_EXTERNAL; dependency.dstSubpass = 0; - dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT; - dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT; + dependency.srcStageMask = + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT; + dependency.dstStageMask = + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT; dependency.srcAccessMask = 0; dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; @@ -323,7 +329,8 @@ namespace Copium renderPassCreateInfo.dependencyCount = 1; renderPassCreateInfo.pDependencies = &dependency; - CP_VK_ASSERT(vkCreateRenderPass(Vulkan::GetDevice(), &renderPassCreateInfo, nullptr, &renderPass), "Failed to initialze render pass"); + CP_VK_ASSERT(vkCreateRenderPass(Vulkan::GetDevice(), &renderPassCreateInfo, nullptr, &renderPass), + "Failed to initialze render pass"); } void SwapChain::InitializeFramebuffers() @@ -343,7 +350,8 @@ namespace Copium createInfo.height = extent.height; createInfo.layers = 1; - CP_VK_ASSERT(vkCreateFramebuffer(Vulkan::GetDevice(), &createInfo, nullptr, &framebuffers[i]), "Failed to initialize swap chain framebuffer"); + CP_VK_ASSERT(vkCreateFramebuffer(Vulkan::GetDevice(), &createInfo, nullptr, &framebuffers[i]), + "Failed to initialize swap chain framebuffer"); } } @@ -355,18 +363,21 @@ namespace Copium semaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) { - CP_VK_ASSERT(vkCreateSemaphore(Vulkan::GetDevice(), &semaphoreCreateInfo, nullptr, &imageAvailableSemaphores[i]), "Failed to initialize available image semaphore"); + CP_VK_ASSERT(vkCreateSemaphore(Vulkan::GetDevice(), &semaphoreCreateInfo, nullptr, &imageAvailableSemaphores[i]), + "Failed to initialize available image semaphore"); VkFenceCreateInfo fenceCreateInfo{}; fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; fenceCreateInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; - CP_VK_ASSERT(vkCreateFence(Vulkan::GetDevice(), &fenceCreateInfo, nullptr, &inFlightFences[i]), "Failed to initialize in flight fence"); + CP_VK_ASSERT(vkCreateFence(Vulkan::GetDevice(), &fenceCreateInfo, nullptr, &inFlightFences[i]), + "Failed to initialize in flight fence"); } renderFinishedSemaphores.resize(images.size()); - for(size_t i = 0; i < renderFinishedSemaphores.size(); i++) + for (size_t i = 0; i < renderFinishedSemaphores.size(); i++) { - CP_VK_ASSERT(vkCreateSemaphore(Vulkan::GetDevice(), &semaphoreCreateInfo, nullptr, &renderFinishedSemaphores[i]), "Failed to initialize render finished semaphore"); + CP_VK_ASSERT(vkCreateSemaphore(Vulkan::GetDevice(), &semaphoreCreateInfo, nullptr, &renderFinishedSemaphores[i]), + "Failed to initialize render finished semaphore"); } } @@ -387,7 +398,8 @@ namespace Copium { for (auto&& availableFormat : availableFormats) { - if (availableFormat.format == VK_FORMAT_R8G8B8A8_UNORM && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) + if (availableFormat.format == VK_FORMAT_R8G8B8A8_UNORM && + availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) { return availableFormat; } diff --git a/CopiumEngine/src/copium/core/SwapChain.h b/CopiumEngine/src/copium/core/SwapChain.h index f8e7df1..470bdff 100644 --- a/CopiumEngine/src/copium/core/SwapChain.h +++ b/CopiumEngine/src/copium/core/SwapChain.h @@ -1,13 +1,14 @@ #pragma once +#include +#include + +#include + #include "copium/buffer/CommandBuffer.h" #include "copium/sampler/DepthAttachment.h" #include "copium/util/Common.h" -#include -#include -#include - namespace Copium { struct SwapChainSupportDetails @@ -23,8 +24,10 @@ namespace Copium class SwapChain final { CP_DELETE_COPY_AND_MOVE_CTOR(SwapChain); + public: static const int MAX_FRAMES_IN_FLIGHT; + private: VkSwapchainKHR handle; VkRenderPass renderPass; diff --git a/CopiumEngine/src/copium/core/Vulkan.cpp b/CopiumEngine/src/copium/core/Vulkan.cpp index 5b53f8e..fc747e0 100644 --- a/CopiumEngine/src/copium/core/Vulkan.cpp +++ b/CopiumEngine/src/copium/core/Vulkan.cpp @@ -41,10 +41,13 @@ namespace Copium AssetManager::RegisterAssetType("Font"); // TODO: Make the working directory always be relative to the assets folder - // By looking at where the executable is, since that should always be in the bin folder (it currently isn't though) + // By looking at where the executable is, since that should always be in the bin folder (it currently isn't + // though) AssetManager::RegisterAssetDir("assets/"); - emptyTexture2D = AssetHandle{"empty_texture2d", std::make_unique(std::vector{255, 0, 255, 255}, 1, 1, SamplerCreator{})}; - whiteTexture2D = AssetHandle{"white_texture2d", std::make_unique(std::vector{255, 255, 255, 255}, 1, 1, SamplerCreator{})}; + emptyTexture2D = AssetHandle{ + "empty_texture2d", std::make_unique(std::vector{255, 0, 255, 255}, 1, 1, SamplerCreator{})}; + whiteTexture2D = AssetHandle{ + "white_texture2d", std::make_unique(std::vector{255, 255, 255, 255}, 1, 1, SamplerCreator{})}; CP_INFO("Initialized AssetManager in %f seconds", timer.Elapsed()); } diff --git a/CopiumEngine/src/copium/core/Vulkan.h b/CopiumEngine/src/copium/core/Vulkan.h index de9fde5..d50e4fe 100644 --- a/CopiumEngine/src/copium/core/Vulkan.h +++ b/CopiumEngine/src/copium/core/Vulkan.h @@ -1,21 +1,22 @@ #pragma once +#include + #include "copium/asset/AssetHandle.h" #include "copium/core/Device.h" +#include "copium/core/ImGuiInstance.h" #include "copium/core/Instance.h" #include "copium/core/SwapChain.h" #include "copium/core/Window.h" -#include "copium/core/ImGuiInstance.h" -#include "copium/util/Common.h" #include "copium/sampler/Texture2D.h" - -#include +#include "copium/util/Common.h" namespace Copium { class Vulkan { CP_STATIC_CLASS(Vulkan); + private: static std::unique_ptr instance; static std::unique_ptr window; @@ -25,6 +26,7 @@ namespace Copium static AssetHandle emptyTexture2D; static AssetHandle whiteTexture2D; + public: static void Initialize(); static void Destroy(); diff --git a/CopiumEngine/src/copium/core/Window.cpp b/CopiumEngine/src/copium/core/Window.cpp index 64b2d30..b37f61f 100644 --- a/CopiumEngine/src/copium/core/Window.cpp +++ b/CopiumEngine/src/copium/core/Window.cpp @@ -1,5 +1,7 @@ #include "copium/core/Window.h" +#include + #include "copium/core/Vulkan.h" #include "copium/event/EventDispatcher.h" #include "copium/event/Input.h" @@ -12,12 +14,11 @@ #include "copium/event/WindowFocusEvent.h" #include "copium/event/WindowResizeEvent.h" -#include - namespace Copium { Window::Window(const std::string& windowName, int width, int height, WindowMode mode) - : width{width}, height{height} + : width{width}, + height{height} { InitializeWindow(windowName, width, height, mode); InitializeSurface(); @@ -75,32 +76,32 @@ namespace Copium switch (mode) { - case WindowMode::Fullscreen: - { - GLFWmonitor* monitor = glfwGetPrimaryMonitor(); - const GLFWvidmode* mode = glfwGetVideoMode(monitor); - window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), monitor, nullptr); - width = mode->width; - height = mode->height; - break; - } - case WindowMode::BorderlessWindowed: - { - const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); + case WindowMode::Fullscreen: + { + GLFWmonitor* monitor = glfwGetPrimaryMonitor(); + const GLFWvidmode* mode = glfwGetVideoMode(monitor); + window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), monitor, nullptr); + width = mode->width; + height = mode->height; + break; + } + case WindowMode::BorderlessWindowed: + { + const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); - glfwWindowHint(GLFW_DECORATED, false); - window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), nullptr, nullptr); - width = mode->width; - height = mode->height; - break; - } - case WindowMode::Windowed: - { - window = glfwCreateWindow(width, height, windowName.c_str(), nullptr, nullptr); - break; - } - default: - CP_ABORT("Unreachable switch case: %s", ToString(mode).c_str()); + glfwWindowHint(GLFW_DECORATED, false); + window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), nullptr, nullptr); + width = mode->width; + height = mode->height; + break; + } + case WindowMode::Windowed: + { + window = glfwCreateWindow(width, height, windowName.c_str(), nullptr, nullptr); + break; + } + default: + CP_ABORT("Unreachable switch case: %s", ToString(mode).c_str()); } CP_ASSERT(window, "Failed to initialize glfw window"); @@ -116,7 +117,8 @@ namespace Copium void Window::InitializeSurface() { - CP_VK_ASSERT(glfwCreateWindowSurface(Vulkan::GetInstance(), window, nullptr, &surface), "Failed to create Vulkan surface"); + CP_VK_ASSERT(glfwCreateWindowSurface(Vulkan::GetInstance(), window, nullptr, &surface), + "Failed to create Vulkan surface"); } void Window::FramebufferResizeCallback(GLFWwindow* glfwWindow, int width, int height) @@ -132,7 +134,7 @@ namespace Copium void Window::KeyCallback(GLFWwindow* glfwWindow, int key, int scancode, int action, int mods) { - if (key == -1) // For some reason media keys count as keys with value -1 + if (key == -1) // For some reason media keys count as keys with value -1 return; try { @@ -148,7 +150,8 @@ namespace Copium } } catch (RuntimeException& exception) - {} + { + } } void Window::MouseButtonCallback(GLFWwindow* glfwWindow, int button, int action, int mods) @@ -167,7 +170,8 @@ namespace Copium } } catch (RuntimeException& exception) - {} + { + } } void Window::MouseMoveCallback(GLFWwindow* glfwWindow, double xpos, double ypos) diff --git a/CopiumEngine/src/copium/core/Window.h b/CopiumEngine/src/copium/core/Window.h index 51cc9da..66bb722 100644 --- a/CopiumEngine/src/copium/core/Window.h +++ b/CopiumEngine/src/copium/core/Window.h @@ -1,14 +1,11 @@ #pragma once +#include + #include "copium/util/Common.h" #include "copium/util/Enum.h" -#include - -#define CP_WINDOW_MODE_ENUMS \ - Fullscreen, \ - BorderlessWindowed, \ - Windowed +#define CP_WINDOW_MODE_ENUMS Fullscreen, BorderlessWindowed, Windowed CP_ENUM_CREATOR(Copium, WindowMode, CP_WINDOW_MODE_ENUMS); @@ -19,6 +16,7 @@ namespace Copium class Window final { CP_DELETE_COPY_AND_MOVE_CTOR(Window); + private: GLFWwindow* window; VkSurfaceKHR surface; diff --git a/CopiumEngine/src/copium/ecs/ComponentListener.h b/CopiumEngine/src/copium/ecs/ComponentListener.h index c3e5ab7..de65b5c 100644 --- a/CopiumEngine/src/copium/ecs/ComponentListener.h +++ b/CopiumEngine/src/copium/ecs/ComponentListener.h @@ -12,10 +12,17 @@ namespace Copium public: using component_type = Component; friend class ECSManager; + protected: ECSManager* manager; + public: - virtual void Added(EntityId entityId, Component& component) {} - virtual void Removed(EntityId entityId, Component& component) {} + virtual void Added(EntityId entityId, Component& component) + { + } + + virtual void Removed(EntityId entityId, Component& component) + { + } }; } diff --git a/CopiumEngine/src/copium/ecs/ComponentPool.h b/CopiumEngine/src/copium/ecs/ComponentPool.h index ca5b8d9..e92b06c 100644 --- a/CopiumEngine/src/copium/ecs/ComponentPool.h +++ b/CopiumEngine/src/copium/ecs/ComponentPool.h @@ -1,30 +1,32 @@ #pragma once +#include + +#include "copium/ecs/ComponentListener.h" +#include "copium/ecs/ComponentPoolBase.h" #include "copium/ecs/Config.h" #include "copium/ecs/EntitySet.h" -#include "copium/ecs/ComponentPoolBase.h" -#include "copium/ecs/ComponentListener.h" #include "copium/util/Common.h" -#include - namespace Copium { template class ComponentPool : public ComponentPoolBase { using Iterator = typename std::vector::iterator; + private: std::vector components; ComponentListener* listener = nullptr; public: ComponentPool() - {} + { + } ~ComponentPool() override { - if(listener) + if (listener) delete listener; } @@ -37,7 +39,7 @@ namespace Copium { components.push_back(component); entities.Emplace(entity); - if(listener) + if (listener) listener->Added(entity, components.back()); return components.back(); } diff --git a/CopiumEngine/src/copium/ecs/ComponentPoolBase.h b/CopiumEngine/src/copium/ecs/ComponentPoolBase.h index 58ffa70..676e412 100644 --- a/CopiumEngine/src/copium/ecs/ComponentPoolBase.h +++ b/CopiumEngine/src/copium/ecs/ComponentPoolBase.h @@ -1,16 +1,17 @@ #pragma once +#include + #include "copium/ecs/Config.h" #include "copium/ecs/EntitySet.h" -#include - namespace Copium { class ComponentPoolBase { protected: EntitySet entities; + public: virtual ~ComponentPoolBase() = default; diff --git a/CopiumEngine/src/copium/ecs/Config.h b/CopiumEngine/src/copium/ecs/Config.h index f01b752..055b3bf 100644 --- a/CopiumEngine/src/copium/ecs/Config.h +++ b/CopiumEngine/src/copium/ecs/Config.h @@ -1,6 +1,7 @@ #pragma once #include + #include namespace Copium diff --git a/CopiumEngine/src/copium/ecs/ECSManager.cpp b/CopiumEngine/src/copium/ecs/ECSManager.cpp index 2bdb1c3..8a48403 100644 --- a/CopiumEngine/src/copium/ecs/ECSManager.cpp +++ b/CopiumEngine/src/copium/ecs/ECSManager.cpp @@ -6,7 +6,8 @@ namespace Copium { ECSManager::ECSManager() : systemPool{std::make_unique(this)} - {} + { + } ECSManager::~ECSManager() { diff --git a/CopiumEngine/src/copium/ecs/ECSManager.h b/CopiumEngine/src/copium/ecs/ECSManager.h index 3c5dfd1..7de5b6f 100644 --- a/CopiumEngine/src/copium/ecs/ECSManager.h +++ b/CopiumEngine/src/copium/ecs/ECSManager.h @@ -1,5 +1,9 @@ #pragma once +#include +#include +#include +#include #include "copium/ecs/ComponentPool.h" #include "copium/ecs/Config.h" @@ -7,11 +11,6 @@ #include "copium/ecs/SystemPool.h" #include "copium/util/Common.h" -#include -#include -#include -#include - namespace Copium { class ECSManager final @@ -22,6 +21,7 @@ namespace Copium std::unique_ptr systemPool; int currentEntityId = 1; + public: ECSManager(); ~ECSManager(); @@ -85,7 +85,10 @@ namespace Copium if (pool) { - CP_ASSERT(!HasComponent(entity), "Component already exists in entity (entity=%u, Component=%s)", entity, typeid(Component).name()); + CP_ASSERT(!HasComponent(entity), + "Component already exists in entity (entity=%u, Component=%s)", + entity, + typeid(Component).name()); return pool->Emplace(entity, component); } else @@ -100,7 +103,10 @@ namespace Copium void RemoveComponent(EntityId entity) { auto pool = GetComponentPoolAssure(); - CP_ASSERT(pool->Erase(entity), "Entity did not contain component (entity=%u, Component=%s)", entity, typeid(Component).name()); + CP_ASSERT(pool->Erase(entity), + "Entity did not contain component (entity=%u, Component=%s)", + entity, + typeid(Component).name()); } template @@ -114,7 +120,8 @@ namespace Copium { auto pool = GetComponentPoolAssure(); Component* component = pool->FindComponent(entity); - CP_ASSERT(component, "Entity did not contain component (entity=%u, Component=%s)", entity, typeid(Component).name()); + CP_ASSERT( + component, "Entity did not contain component (entity=%u, Component=%s)", entity, typeid(Component).name()); return *component; } @@ -212,7 +219,8 @@ namespace Copium template EntityId Find() { - return Find([] (EntityId, const Component& component, const Components&... components) { return true; }); + return Find([](EntityId, const Component& component, const Components&... components) + { return true; }); } template @@ -233,7 +241,9 @@ namespace Copium ComponentPool* GetComponentPoolAssure() { auto it = componentPool.find(GetComponentId()); - CP_ASSERT(it != componentPool.end(), "Component has not been added to an entity (Component=%s)", typeid(Component).name()); + CP_ASSERT(it != componentPool.end(), + "Component has not been added to an entity (Component=%s)", + typeid(Component).name()); return static_cast*>(it->second); } }; diff --git a/CopiumEngine/src/copium/ecs/Entity.cpp b/CopiumEngine/src/copium/ecs/Entity.cpp index 0fc569f..398827f 100644 --- a/CopiumEngine/src/copium/ecs/Entity.cpp +++ b/CopiumEngine/src/copium/ecs/Entity.cpp @@ -3,16 +3,22 @@ namespace Copium { Entity::Entity() - : manager{nullptr}, id{INVALID_ENTITY} - {} + : manager{nullptr}, + id{INVALID_ENTITY} + { + } Entity::Entity(ECSManager* manager) - : manager{manager}, id{INVALID_ENTITY} - {} + : manager{manager}, + id{INVALID_ENTITY} + { + } Entity::Entity(ECSManager* manager, EntityId id) - : manager{manager}, id{id} - {} + : manager{manager}, + id{id} + { + } Entity::operator EntityId() const { diff --git a/CopiumEngine/src/copium/ecs/EntitySet.cpp b/CopiumEngine/src/copium/ecs/EntitySet.cpp index 06aee9c..5f5cd18 100644 --- a/CopiumEngine/src/copium/ecs/EntitySet.cpp +++ b/CopiumEngine/src/copium/ecs/EntitySet.cpp @@ -55,9 +55,23 @@ namespace Copium return entitiesList.size(); } - std::vector& EntitySet::GetList() { return entitiesList; } - const std::vector& EntitySet::GetList() const { return entitiesList; } + std::vector& EntitySet::GetList() + { + return entitiesList; + } - std::vector::iterator EntitySet::begin() { return entitiesList.begin(); } - std::vector::iterator EntitySet::end() { return entitiesList.end(); } + const std::vector& EntitySet::GetList() const + { + return entitiesList; + } + + std::vector::iterator EntitySet::begin() + { + return entitiesList.begin(); + } + + std::vector::iterator EntitySet::end() + { + return entitiesList.end(); + } } diff --git a/CopiumEngine/src/copium/ecs/EntitySet.h b/CopiumEngine/src/copium/ecs/EntitySet.h index 70ef8da..1ccd16d 100644 --- a/CopiumEngine/src/copium/ecs/EntitySet.h +++ b/CopiumEngine/src/copium/ecs/EntitySet.h @@ -1,17 +1,17 @@ #pragma once -#include "copium/ecs/Config.h" - #include #include +#include "copium/ecs/Config.h" + namespace Copium { class EntitySet { private: std::vector entitiesList; - std::unordered_map entitiesMap; // Maps the entity id to a component index + std::unordered_map entitiesMap; // Maps the entity id to a component index public: bool Emplace(EntityId entity); bool Erase(EntityId entity); diff --git a/CopiumEngine/src/copium/ecs/Signal.h b/CopiumEngine/src/copium/ecs/Signal.h index be13820..24ee92d 100644 --- a/CopiumEngine/src/copium/ecs/Signal.h +++ b/CopiumEngine/src/copium/ecs/Signal.h @@ -1,31 +1,31 @@ #pragma once #define CP_SIGNAL_DECLERATION_DEFINITION() \ - static int GetIdStatic() \ - { \ - static int id = GetAllocatedId(); \ - return id; \ - } \ - \ - int GetId() const \ - { \ - return GetIdStatic(); \ + static int GetIdStatic() \ + { \ + static int id = GetAllocatedId(); \ + return id; \ + } \ + \ + int GetId() const \ + { \ + return GetIdStatic(); \ } #define CP_SIGNAL_DECLERATION(SignalClass) \ - static int GetIdStatic(); \ + static int GetIdStatic(); \ int GetId() const override #define CP_SIGNAL_DEFINITION(SignalClass) \ - int SignalClass::GetIdStatic() \ - { \ - static int id = GetAllocatedId(); \ - return id; \ - } \ - \ - int SignalClass::GetId() const \ - { \ - return GetIdStatic(); \ + int SignalClass::GetIdStatic() \ + { \ + static int id = GetAllocatedId(); \ + return id; \ + } \ + \ + int SignalClass::GetId() const \ + { \ + return GetIdStatic(); \ } namespace Copium diff --git a/CopiumEngine/src/copium/ecs/System.h b/CopiumEngine/src/copium/ecs/System.h index 475315b..4d14c67 100644 --- a/CopiumEngine/src/copium/ecs/System.h +++ b/CopiumEngine/src/copium/ecs/System.h @@ -1,11 +1,11 @@ #pragma once -#include "copium/ecs/ECSManager.h" -#include "copium/ecs/SystemBase.h" -#include "copium/ecs/Entity.h" - #include +#include "copium/ecs/ECSManager.h" +#include "copium/ecs/Entity.h" +#include "copium/ecs/SystemBase.h" + namespace Copium { template @@ -14,20 +14,22 @@ namespace Copium public: void Run() override { - manager->Each([&](EntityId entityId, Components&... components) { RunEntity(Entity{manager, entityId}, components...); }); + manager->Each([&](EntityId entityId, Components&... components) + { RunEntity(Entity{manager, entityId}, components...); }); } void Run(const Signal& signal) override { - manager->Each([&](EntityId entityId, Components&... components) { RunEntity(signal, Entity{manager, entityId}, components...); }); + manager->Each([&](EntityId entityId, Components&... components) + { RunEntity(signal, Entity{manager, entityId}, components...); }); } virtual void RunEntity(Entity entity, Components&... components) {}; virtual void RunEntity(const Signal& signal, Entity entity, Components&... components) {}; - // TODO: Not sure if this is the way entities should be validated std::set loggedEntities; + bool ValidateEntity(Entity entity) { if (entity && entity.HasComponents()) diff --git a/CopiumEngine/src/copium/ecs/SystemBase.h b/CopiumEngine/src/copium/ecs/SystemBase.h index db5a8d7..0be05a5 100644 --- a/CopiumEngine/src/copium/ecs/SystemBase.h +++ b/CopiumEngine/src/copium/ecs/SystemBase.h @@ -9,6 +9,7 @@ namespace Copium class SystemBase { friend class SystemPool; + protected: ECSManager* manager; diff --git a/CopiumEngine/src/copium/ecs/SystemOrderer.cpp b/CopiumEngine/src/copium/ecs/SystemOrderer.cpp index b212c13..33bba23 100644 --- a/CopiumEngine/src/copium/ecs/SystemOrderer.cpp +++ b/CopiumEngine/src/copium/ecs/SystemOrderer.cpp @@ -7,7 +7,8 @@ namespace Copium SystemOrderer::SystemOrderer(std::type_index systemId, SystemPool* systemPool) : systemId{systemId}, systemPool{systemPool} - {} + { + } void SystemOrderer::Before(const std::type_index& otherSystemId) { diff --git a/CopiumEngine/src/copium/ecs/SystemOrderer.h b/CopiumEngine/src/copium/ecs/SystemOrderer.h index d2d3028..ea23e99 100644 --- a/CopiumEngine/src/copium/ecs/SystemOrderer.h +++ b/CopiumEngine/src/copium/ecs/SystemOrderer.h @@ -11,6 +11,7 @@ namespace Copium private: std::type_index systemId; SystemPool* systemPool = nullptr; + public: SystemOrderer(std::type_index systemId, SystemPool* systemPool); diff --git a/CopiumEngine/src/copium/ecs/SystemPool.cpp b/CopiumEngine/src/copium/ecs/SystemPool.cpp index da054f6..1ed53c7 100644 --- a/CopiumEngine/src/copium/ecs/SystemPool.cpp +++ b/CopiumEngine/src/copium/ecs/SystemPool.cpp @@ -6,7 +6,8 @@ namespace Copium { SystemPool::SystemPool(ECSManager* manager) : manager{manager} - {} + { + } SystemPool::~SystemPool() { diff --git a/CopiumEngine/src/copium/ecs/SystemPool.h b/CopiumEngine/src/copium/ecs/SystemPool.h index 622b784..782ebd0 100644 --- a/CopiumEngine/src/copium/ecs/SystemPool.h +++ b/CopiumEngine/src/copium/ecs/SystemPool.h @@ -1,13 +1,13 @@ #pragma once -#include "copium/ecs/SystemBase.h" -#include "copium/ecs/SystemOrderer.h" -#include "copium/ecs/Signal.h" -#include "copium/util/Common.h" - -#include #include #include +#include + +#include "copium/ecs/Signal.h" +#include "copium/ecs/SystemBase.h" +#include "copium/ecs/SystemOrderer.h" +#include "copium/util/Common.h" namespace Copium { @@ -16,6 +16,7 @@ namespace Copium class SystemPool final { CP_DELETE_COPY_AND_MOVE_CTOR(SystemPool); + private: ECSManager* manager; std::map systems; diff --git a/CopiumEngine/src/copium/event/Event.cpp b/CopiumEngine/src/copium/event/Event.cpp index f6a9067..6adbfb8 100644 --- a/CopiumEngine/src/copium/event/Event.cpp +++ b/CopiumEngine/src/copium/event/Event.cpp @@ -5,7 +5,8 @@ namespace Copium Event::Event(EventType type) : type{type} - {} + { + } EventType Event::GetType() const { diff --git a/CopiumEngine/src/copium/event/Event.h b/CopiumEngine/src/copium/event/Event.h index bd2adb9..7994906 100644 --- a/CopiumEngine/src/copium/event/Event.h +++ b/CopiumEngine/src/copium/event/Event.h @@ -8,6 +8,7 @@ namespace Copium { private: EventType type; + public: Event(EventType type); diff --git a/CopiumEngine/src/copium/event/EventDispatcher.cpp b/CopiumEngine/src/copium/event/EventDispatcher.cpp index 77a6cc2..d1b29fe 100644 --- a/CopiumEngine/src/copium/event/EventDispatcher.cpp +++ b/CopiumEngine/src/copium/event/EventDispatcher.cpp @@ -27,15 +27,15 @@ namespace Copium EventResult result = eventHandler->OnEvent(*event); switch (result) { - case EventResult::Continue: - continue; - case EventResult::Handled: - return; - case EventResult::Focus: - focusedEventHandler = eventHandler; - return; - default: - CP_ABORT("Unreachable switch case: %s", ToString(result).c_str()); + case EventResult::Continue: + continue; + case EventResult::Handled: + return; + case EventResult::Focus: + focusedEventHandler = eventHandler; + return; + default: + CP_ABORT("Unreachable switch case: %s", ToString(result).c_str()); } } } diff --git a/CopiumEngine/src/copium/event/EventDispatcher.h b/CopiumEngine/src/copium/event/EventDispatcher.h index 5d03963..2c06d63 100644 --- a/CopiumEngine/src/copium/event/EventDispatcher.h +++ b/CopiumEngine/src/copium/event/EventDispatcher.h @@ -1,12 +1,12 @@ #pragma once +#include +#include +#include + #include "copium/event/Event.h" #include "copium/event/EventHandler.h" -#include -#include -#include - namespace Copium { class EventDispatcher @@ -15,12 +15,14 @@ namespace Copium static EventHandler* focusedEventHandler; static std::vector eventHandlers; static std::queue> events; + public: template static void QueueEvent(const EventType& event) { events.push(std::make_unique(event)); } + static void Dispatch(); static void AddEventHandler(EventHandler* eventHandler); static void RemoveEventHandler(EventHandler* eventHandler); diff --git a/CopiumEngine/src/copium/event/EventResult.h b/CopiumEngine/src/copium/event/EventResult.h index 928e862..a6b6af9 100644 --- a/CopiumEngine/src/copium/event/EventResult.h +++ b/CopiumEngine/src/copium/event/EventResult.h @@ -2,9 +2,6 @@ #include "copium/util/Enum.h" -#define CP_EVENT_RESULT_ENUMS \ - Continue, \ - Handled, \ - Focus +#define CP_EVENT_RESULT_ENUMS Continue, Handled, Focus CP_ENUM_CREATOR(Copium, EventResult, CP_EVENT_RESULT_ENUMS); diff --git a/CopiumEngine/src/copium/event/EventSignal.cpp b/CopiumEngine/src/copium/event/EventSignal.cpp index badffe5..42b6137 100644 --- a/CopiumEngine/src/copium/event/EventSignal.cpp +++ b/CopiumEngine/src/copium/event/EventSignal.cpp @@ -4,7 +4,8 @@ namespace Copium { EventSignal::EventSignal(const Event& event) : event{event} - {} + { + } const Event& EventSignal::GetEvent() const { diff --git a/CopiumEngine/src/copium/event/EventSignal.h b/CopiumEngine/src/copium/event/EventSignal.h index cde8b12..3cdfe9c 100644 --- a/CopiumEngine/src/copium/event/EventSignal.h +++ b/CopiumEngine/src/copium/event/EventSignal.h @@ -1,7 +1,7 @@ #pragma once -#include "copium/event/Event.h" #include "copium/ecs/Signal.h" +#include "copium/event/Event.h" namespace Copium { diff --git a/CopiumEngine/src/copium/event/EventType.h b/CopiumEngine/src/copium/event/EventType.h index f2a699a..9607d4a 100644 --- a/CopiumEngine/src/copium/event/EventType.h +++ b/CopiumEngine/src/copium/event/EventType.h @@ -3,9 +3,6 @@ #include "copium/util/Enum.h" #define CP_EVENT_TYPE_ENUMS \ - MouseMove, MousePress, MouseRelease, MouseScroll, \ - KeyPress, KeyRelease, \ - WindowResize, WindowFocus, \ - ViewportResize + MouseMove, MousePress, MouseRelease, MouseScroll, KeyPress, KeyRelease, WindowResize, WindowFocus, ViewportResize CP_ENUM_CREATOR(Copium, EventType, CP_EVENT_TYPE_ENUMS); diff --git a/CopiumEngine/src/copium/event/Input.cpp b/CopiumEngine/src/copium/event/Input.cpp index 940c4a0..9ba1fab 100644 --- a/CopiumEngine/src/copium/event/Input.cpp +++ b/CopiumEngine/src/copium/event/Input.cpp @@ -1,11 +1,11 @@ #include "copium/event/Input.h" +#include + #include "copium/core/Vulkan.h" #include "copium/event/InputCode.h" #include "copium/util/Common.h" -#include - namespace Copium { bool Input::keyDownList[MAX_NUM_KEYS]; @@ -75,7 +75,8 @@ namespace Copium glm::vec2 Input::GetMouseWindowPos() { - return glm::vec2{(mousePos.x + 1.0f) * 0.5f * Vulkan::GetWindow().GetWidth(), (1.0f - mousePos.y) * 0.5f * Vulkan::GetWindow().GetHeight()}; + return glm::vec2{(mousePos.x + 1.0f) * 0.5f * Vulkan::GetWindow().GetWidth(), + (1.0f - mousePos.y) * 0.5f * Vulkan::GetWindow().GetHeight()}; } void Input::OnKey(int keyCode, bool pressed) @@ -120,128 +121,250 @@ namespace Copium { switch (key) { - case CP_KEY_SPACE: return "Space"; - case CP_KEY_APOSTROPHE: return "\'"; - case CP_KEY_COMMA: return ","; - case CP_KEY_MINUS: return "-"; - case CP_KEY_PERIOD: return "."; - case CP_KEY_SLASH: return "/"; - case CP_KEY_0: return "0"; - case CP_KEY_1: return "1"; - case CP_KEY_2: return "2"; - case CP_KEY_3: return "3"; - case CP_KEY_4: return "4"; - case CP_KEY_5: return "5"; - case CP_KEY_6: return "6"; - case CP_KEY_7: return "7"; - case CP_KEY_8: return "8"; - case CP_KEY_9: return "9"; - case CP_KEY_SEMICOLON: return ";"; - case CP_KEY_EQUAL: return "="; - case CP_KEY_A: return "A"; - case CP_KEY_B: return "B"; - case CP_KEY_C: return "C"; - case CP_KEY_D: return "D"; - case CP_KEY_E: return "E"; - case CP_KEY_F: return "F"; - case CP_KEY_G: return "G"; - case CP_KEY_H: return "H"; - case CP_KEY_I: return "I"; - case CP_KEY_J: return "J"; - case CP_KEY_K: return "K"; - case CP_KEY_L: return "L"; - case CP_KEY_M: return "M"; - case CP_KEY_N: return "N"; - case CP_KEY_O: return "O"; - case CP_KEY_P: return "P"; - case CP_KEY_Q: return "Q"; - case CP_KEY_R: return "R"; - case CP_KEY_S: return "S"; - case CP_KEY_T: return "T"; - case CP_KEY_U: return "U"; - case CP_KEY_V: return "V"; - case CP_KEY_W: return "W"; - case CP_KEY_X: return "X"; - case CP_KEY_Y: return "Y"; - case CP_KEY_Z: return "Z"; - case CP_KEY_LEFT_BRACKET: return "["; - case CP_KEY_BACKSLASH: return "\\"; - case CP_KEY_RIGHT_BRACKET: return "]"; - case CP_KEY_GRAVE_ACCENT: return "Grave Accent ?"; - case CP_KEY_WORLD_1: return "World 1 ?"; - case CP_KEY_WORLD_2: return "World 2 ?"; - case CP_KEY_ESCAPE: return "Escape"; - case CP_KEY_ENTER: return "Enter"; - case CP_KEY_TAB: return "Tab"; - case CP_KEY_BACKSPACE: return "Return"; - case CP_KEY_INSERT: return "Insert"; - case CP_KEY_DELETE: return "Delete"; - case CP_KEY_RIGHT: return "Right Arrow"; - case CP_KEY_LEFT: return "Left Arrow"; - case CP_KEY_DOWN: return "Down Arrow"; - case CP_KEY_UP: return "Up Arrow"; - case CP_KEY_PAGE_UP: return "Page Up"; - case CP_KEY_PAGE_DOWN: return "Page Down"; - case CP_KEY_HOME: return "Home"; - case CP_KEY_END: return "End"; - case CP_KEY_CAPS_LOCK: return "Caps Lock"; - case CP_KEY_SCROLL_LOCK: return "Scroll Lock"; - case CP_KEY_NUM_LOCK: return "Num Lock"; - case CP_KEY_PRINT_SCREEN: return "Print Screen"; - case CP_KEY_PAUSE: return "Pause"; - case CP_KEY_F1: return "F1"; - case CP_KEY_F2: return "F2"; - case CP_KEY_F3: return "F3"; - case CP_KEY_F4: return "F4"; - case CP_KEY_F5: return "F5"; - case CP_KEY_F6: return "F6"; - case CP_KEY_F7: return "F7"; - case CP_KEY_F8: return "F8"; - case CP_KEY_F9: return "F9"; - case CP_KEY_F10: return "F10"; - case CP_KEY_F11: return "F11"; - case CP_KEY_F12: return "F12"; - case CP_KEY_F13: return "F13"; - case CP_KEY_F14: return "F14"; - case CP_KEY_F15: return "F15"; - case CP_KEY_F16: return "F16"; - case CP_KEY_F17: return "F17"; - case CP_KEY_F18: return "F18"; - case CP_KEY_F19: return "F19"; - case CP_KEY_F20: return "F20"; - case CP_KEY_F21: return "F21"; - case CP_KEY_F22: return "F22"; - case CP_KEY_F23: return "F23"; - case CP_KEY_F24: return "F24"; - case CP_KEY_F25: return "F25"; - case CP_KEY_KP_0: return "Keypad 0"; - case CP_KEY_KP_1: return "Keypad 1"; - case CP_KEY_KP_2: return "Keypad 2"; - case CP_KEY_KP_3: return "Keypad 3"; - case CP_KEY_KP_4: return "Keypad 4"; - case CP_KEY_KP_5: return "Keypad 5"; - case CP_KEY_KP_6: return "Keypad 6"; - case CP_KEY_KP_7: return "Keypad 7"; - case CP_KEY_KP_8: return "Keypad 8"; - case CP_KEY_KP_9: return "Keypad 9"; - case CP_KEY_KP_DECIMAL: return "Keypad ,"; - case CP_KEY_KP_DIVIDE: return "Keypad /"; - case CP_KEY_KP_MULTIPLY: return "Keypad *"; - case CP_KEY_KP_SUBTRACT: return "Keypad -"; - case CP_KEY_KP_ADD: return "Keypad +"; - case CP_KEY_KP_ENTER: return "Keypad Enter"; - case CP_KEY_KP_EQUAL: return "Keypad ="; - case CP_KEY_LEFT_SHIFT: return "Left Shift"; - case CP_KEY_LEFT_CONTROL: return "Left Control"; - case CP_KEY_LEFT_ALT: return "Left Alt"; - case CP_KEY_LEFT_SUPER: return "Left Super"; - case CP_KEY_RIGHT_SHIFT: return "Right Shift"; - case CP_KEY_RIGHT_CONTROL: return "Right Control"; - case CP_KEY_RIGHT_ALT: return "Right Alt"; - case CP_KEY_RIGHT_SUPER: return "Right Super"; - case CP_KEY_MENU: return "Menu"; - case CP_KEY_UNBOUND: return "Unbound"; - default: return "Unknown " + std::to_string(key); + case CP_KEY_SPACE: + return "Space"; + case CP_KEY_APOSTROPHE: + return "\'"; + case CP_KEY_COMMA: + return ","; + case CP_KEY_MINUS: + return "-"; + case CP_KEY_PERIOD: + return "."; + case CP_KEY_SLASH: + return "/"; + case CP_KEY_0: + return "0"; + case CP_KEY_1: + return "1"; + case CP_KEY_2: + return "2"; + case CP_KEY_3: + return "3"; + case CP_KEY_4: + return "4"; + case CP_KEY_5: + return "5"; + case CP_KEY_6: + return "6"; + case CP_KEY_7: + return "7"; + case CP_KEY_8: + return "8"; + case CP_KEY_9: + return "9"; + case CP_KEY_SEMICOLON: + return ";"; + case CP_KEY_EQUAL: + return "="; + case CP_KEY_A: + return "A"; + case CP_KEY_B: + return "B"; + case CP_KEY_C: + return "C"; + case CP_KEY_D: + return "D"; + case CP_KEY_E: + return "E"; + case CP_KEY_F: + return "F"; + case CP_KEY_G: + return "G"; + case CP_KEY_H: + return "H"; + case CP_KEY_I: + return "I"; + case CP_KEY_J: + return "J"; + case CP_KEY_K: + return "K"; + case CP_KEY_L: + return "L"; + case CP_KEY_M: + return "M"; + case CP_KEY_N: + return "N"; + case CP_KEY_O: + return "O"; + case CP_KEY_P: + return "P"; + case CP_KEY_Q: + return "Q"; + case CP_KEY_R: + return "R"; + case CP_KEY_S: + return "S"; + case CP_KEY_T: + return "T"; + case CP_KEY_U: + return "U"; + case CP_KEY_V: + return "V"; + case CP_KEY_W: + return "W"; + case CP_KEY_X: + return "X"; + case CP_KEY_Y: + return "Y"; + case CP_KEY_Z: + return "Z"; + case CP_KEY_LEFT_BRACKET: + return "["; + case CP_KEY_BACKSLASH: + return "\\"; + case CP_KEY_RIGHT_BRACKET: + return "]"; + case CP_KEY_GRAVE_ACCENT: + return "Grave Accent ?"; + case CP_KEY_WORLD_1: + return "World 1 ?"; + case CP_KEY_WORLD_2: + return "World 2 ?"; + case CP_KEY_ESCAPE: + return "Escape"; + case CP_KEY_ENTER: + return "Enter"; + case CP_KEY_TAB: + return "Tab"; + case CP_KEY_BACKSPACE: + return "Return"; + case CP_KEY_INSERT: + return "Insert"; + case CP_KEY_DELETE: + return "Delete"; + case CP_KEY_RIGHT: + return "Right Arrow"; + case CP_KEY_LEFT: + return "Left Arrow"; + case CP_KEY_DOWN: + return "Down Arrow"; + case CP_KEY_UP: + return "Up Arrow"; + case CP_KEY_PAGE_UP: + return "Page Up"; + case CP_KEY_PAGE_DOWN: + return "Page Down"; + case CP_KEY_HOME: + return "Home"; + case CP_KEY_END: + return "End"; + case CP_KEY_CAPS_LOCK: + return "Caps Lock"; + case CP_KEY_SCROLL_LOCK: + return "Scroll Lock"; + case CP_KEY_NUM_LOCK: + return "Num Lock"; + case CP_KEY_PRINT_SCREEN: + return "Print Screen"; + case CP_KEY_PAUSE: + return "Pause"; + case CP_KEY_F1: + return "F1"; + case CP_KEY_F2: + return "F2"; + case CP_KEY_F3: + return "F3"; + case CP_KEY_F4: + return "F4"; + case CP_KEY_F5: + return "F5"; + case CP_KEY_F6: + return "F6"; + case CP_KEY_F7: + return "F7"; + case CP_KEY_F8: + return "F8"; + case CP_KEY_F9: + return "F9"; + case CP_KEY_F10: + return "F10"; + case CP_KEY_F11: + return "F11"; + case CP_KEY_F12: + return "F12"; + case CP_KEY_F13: + return "F13"; + case CP_KEY_F14: + return "F14"; + case CP_KEY_F15: + return "F15"; + case CP_KEY_F16: + return "F16"; + case CP_KEY_F17: + return "F17"; + case CP_KEY_F18: + return "F18"; + case CP_KEY_F19: + return "F19"; + case CP_KEY_F20: + return "F20"; + case CP_KEY_F21: + return "F21"; + case CP_KEY_F22: + return "F22"; + case CP_KEY_F23: + return "F23"; + case CP_KEY_F24: + return "F24"; + case CP_KEY_F25: + return "F25"; + case CP_KEY_KP_0: + return "Keypad 0"; + case CP_KEY_KP_1: + return "Keypad 1"; + case CP_KEY_KP_2: + return "Keypad 2"; + case CP_KEY_KP_3: + return "Keypad 3"; + case CP_KEY_KP_4: + return "Keypad 4"; + case CP_KEY_KP_5: + return "Keypad 5"; + case CP_KEY_KP_6: + return "Keypad 6"; + case CP_KEY_KP_7: + return "Keypad 7"; + case CP_KEY_KP_8: + return "Keypad 8"; + case CP_KEY_KP_9: + return "Keypad 9"; + case CP_KEY_KP_DECIMAL: + return "Keypad ,"; + case CP_KEY_KP_DIVIDE: + return "Keypad /"; + case CP_KEY_KP_MULTIPLY: + return "Keypad *"; + case CP_KEY_KP_SUBTRACT: + return "Keypad -"; + case CP_KEY_KP_ADD: + return "Keypad +"; + case CP_KEY_KP_ENTER: + return "Keypad Enter"; + case CP_KEY_KP_EQUAL: + return "Keypad ="; + case CP_KEY_LEFT_SHIFT: + return "Left Shift"; + case CP_KEY_LEFT_CONTROL: + return "Left Control"; + case CP_KEY_LEFT_ALT: + return "Left Alt"; + case CP_KEY_LEFT_SUPER: + return "Left Super"; + case CP_KEY_RIGHT_SHIFT: + return "Right Shift"; + case CP_KEY_RIGHT_CONTROL: + return "Right Control"; + case CP_KEY_RIGHT_ALT: + return "Right Alt"; + case CP_KEY_RIGHT_SUPER: + return "Right Super"; + case CP_KEY_MENU: + return "Menu"; + case CP_KEY_UNBOUND: + return "Unbound"; + default: + return "Unknown " + std::to_string(key); } } } diff --git a/CopiumEngine/src/copium/event/Input.h b/CopiumEngine/src/copium/event/Input.h index f4c5079..3a6be47 100644 --- a/CopiumEngine/src/copium/event/Input.h +++ b/CopiumEngine/src/copium/event/Input.h @@ -1,10 +1,10 @@ #pragma once -#include "copium/util/BoundingBox.h" - #include #include +#include "copium/util/BoundingBox.h" + namespace Copium { class Input diff --git a/CopiumEngine/src/copium/event/InputCode.h b/CopiumEngine/src/copium/event/InputCode.h index 252338c..0508e1d 100644 --- a/CopiumEngine/src/copium/event/InputCode.h +++ b/CopiumEngine/src/copium/event/InputCode.h @@ -1,129 +1,129 @@ #pragma once -#define CP_MOUSE_LEFT 0 -#define CP_MOUSE_RIGHT 1 -#define CP_MOUSE_MIDDLE 2 -#define CP_MOUSE_BACK 3 -#define CP_MOUSE_FORWARD 4 +#define CP_MOUSE_LEFT 0 +#define CP_MOUSE_RIGHT 1 +#define CP_MOUSE_MIDDLE 2 +#define CP_MOUSE_BACK 3 +#define CP_MOUSE_FORWARD 4 -#define CP_KEY_SPACE 32 -#define CP_KEY_APOSTROPHE 39 -#define CP_KEY_COMMA 44 -#define CP_KEY_MINUS 45 -#define CP_KEY_PERIOD 46 -#define CP_KEY_SLASH 47 -#define CP_KEY_0 48 -#define CP_KEY_1 49 -#define CP_KEY_2 50 -#define CP_KEY_3 51 -#define CP_KEY_4 52 -#define CP_KEY_5 53 -#define CP_KEY_6 54 -#define CP_KEY_7 55 -#define CP_KEY_8 56 -#define CP_KEY_9 57 -#define CP_KEY_SEMICOLON 59 -#define CP_KEY_EQUAL 61 -#define CP_KEY_A 65 -#define CP_KEY_B 66 -#define CP_KEY_C 67 -#define CP_KEY_D 68 -#define CP_KEY_E 69 -#define CP_KEY_F 70 -#define CP_KEY_G 71 -#define CP_KEY_H 72 -#define CP_KEY_I 73 -#define CP_KEY_J 74 -#define CP_KEY_K 75 -#define CP_KEY_L 76 -#define CP_KEY_M 77 -#define CP_KEY_N 78 -#define CP_KEY_O 79 -#define CP_KEY_P 80 -#define CP_KEY_Q 81 -#define CP_KEY_R 82 -#define CP_KEY_S 83 -#define CP_KEY_T 84 -#define CP_KEY_U 85 -#define CP_KEY_V 86 -#define CP_KEY_W 87 -#define CP_KEY_X 88 -#define CP_KEY_Y 89 -#define CP_KEY_Z 90 -#define CP_KEY_LEFT_BRACKET 91 -#define CP_KEY_BACKSLASH 92 -#define CP_KEY_RIGHT_BRACKET 93 -#define CP_KEY_GRAVE_ACCENT 96 -#define CP_KEY_WORLD_1 161 -#define CP_KEY_WORLD_2 162 -#define CP_KEY_ESCAPE 256 -#define CP_KEY_ENTER 257 -#define CP_KEY_TAB 258 -#define CP_KEY_BACKSPACE 259 -#define CP_KEY_INSERT 260 -#define CP_KEY_DELETE 261 -#define CP_KEY_RIGHT 262 -#define CP_KEY_LEFT 263 -#define CP_KEY_DOWN 264 -#define CP_KEY_UP 265 -#define CP_KEY_PAGE_UP 266 -#define CP_KEY_PAGE_DOWN 267 -#define CP_KEY_HOME 268 -#define CP_KEY_END 269 -#define CP_KEY_CAPS_LOCK 280 -#define CP_KEY_SCROLL_LOCK 281 -#define CP_KEY_NUM_LOCK 282 -#define CP_KEY_PRINT_SCREEN 283 -#define CP_KEY_PAUSE 284 -#define CP_KEY_F1 290 -#define CP_KEY_F2 291 -#define CP_KEY_F3 292 -#define CP_KEY_F4 293 -#define CP_KEY_F5 294 -#define CP_KEY_F6 295 -#define CP_KEY_F7 296 -#define CP_KEY_F8 297 -#define CP_KEY_F9 298 -#define CP_KEY_F10 299 -#define CP_KEY_F11 300 -#define CP_KEY_F12 301 -#define CP_KEY_F13 302 -#define CP_KEY_F14 303 -#define CP_KEY_F15 304 -#define CP_KEY_F16 305 -#define CP_KEY_F17 306 -#define CP_KEY_F18 307 -#define CP_KEY_F19 308 -#define CP_KEY_F20 309 -#define CP_KEY_F21 310 -#define CP_KEY_F22 311 -#define CP_KEY_F23 312 -#define CP_KEY_F24 313 -#define CP_KEY_F25 314 -#define CP_KEY_KP_0 320 -#define CP_KEY_KP_1 321 -#define CP_KEY_KP_2 322 -#define CP_KEY_KP_3 323 -#define CP_KEY_KP_4 324 -#define CP_KEY_KP_5 325 -#define CP_KEY_KP_6 326 -#define CP_KEY_KP_7 327 -#define CP_KEY_KP_8 328 -#define CP_KEY_KP_9 329 -#define CP_KEY_KP_DECIMAL 330 -#define CP_KEY_KP_DIVIDE 331 -#define CP_KEY_KP_MULTIPLY 332 -#define CP_KEY_KP_SUBTRACT 333 -#define CP_KEY_KP_ADD 334 -#define CP_KEY_KP_ENTER 335 -#define CP_KEY_KP_EQUAL 336 -#define CP_KEY_LEFT_SHIFT 340 -#define CP_KEY_LEFT_CONTROL 341 -#define CP_KEY_LEFT_ALT 342 -#define CP_KEY_LEFT_SUPER 343 -#define CP_KEY_RIGHT_SHIFT 344 -#define CP_KEY_RIGHT_CONTROL 345 -#define CP_KEY_RIGHT_ALT 346 -#define CP_KEY_RIGHT_SUPER 347 -#define CP_KEY_MENU 348 -#define CP_KEY_UNBOUND 0x0fffffff +#define CP_KEY_SPACE 32 +#define CP_KEY_APOSTROPHE 39 +#define CP_KEY_COMMA 44 +#define CP_KEY_MINUS 45 +#define CP_KEY_PERIOD 46 +#define CP_KEY_SLASH 47 +#define CP_KEY_0 48 +#define CP_KEY_1 49 +#define CP_KEY_2 50 +#define CP_KEY_3 51 +#define CP_KEY_4 52 +#define CP_KEY_5 53 +#define CP_KEY_6 54 +#define CP_KEY_7 55 +#define CP_KEY_8 56 +#define CP_KEY_9 57 +#define CP_KEY_SEMICOLON 59 +#define CP_KEY_EQUAL 61 +#define CP_KEY_A 65 +#define CP_KEY_B 66 +#define CP_KEY_C 67 +#define CP_KEY_D 68 +#define CP_KEY_E 69 +#define CP_KEY_F 70 +#define CP_KEY_G 71 +#define CP_KEY_H 72 +#define CP_KEY_I 73 +#define CP_KEY_J 74 +#define CP_KEY_K 75 +#define CP_KEY_L 76 +#define CP_KEY_M 77 +#define CP_KEY_N 78 +#define CP_KEY_O 79 +#define CP_KEY_P 80 +#define CP_KEY_Q 81 +#define CP_KEY_R 82 +#define CP_KEY_S 83 +#define CP_KEY_T 84 +#define CP_KEY_U 85 +#define CP_KEY_V 86 +#define CP_KEY_W 87 +#define CP_KEY_X 88 +#define CP_KEY_Y 89 +#define CP_KEY_Z 90 +#define CP_KEY_LEFT_BRACKET 91 +#define CP_KEY_BACKSLASH 92 +#define CP_KEY_RIGHT_BRACKET 93 +#define CP_KEY_GRAVE_ACCENT 96 +#define CP_KEY_WORLD_1 161 +#define CP_KEY_WORLD_2 162 +#define CP_KEY_ESCAPE 256 +#define CP_KEY_ENTER 257 +#define CP_KEY_TAB 258 +#define CP_KEY_BACKSPACE 259 +#define CP_KEY_INSERT 260 +#define CP_KEY_DELETE 261 +#define CP_KEY_RIGHT 262 +#define CP_KEY_LEFT 263 +#define CP_KEY_DOWN 264 +#define CP_KEY_UP 265 +#define CP_KEY_PAGE_UP 266 +#define CP_KEY_PAGE_DOWN 267 +#define CP_KEY_HOME 268 +#define CP_KEY_END 269 +#define CP_KEY_CAPS_LOCK 280 +#define CP_KEY_SCROLL_LOCK 281 +#define CP_KEY_NUM_LOCK 282 +#define CP_KEY_PRINT_SCREEN 283 +#define CP_KEY_PAUSE 284 +#define CP_KEY_F1 290 +#define CP_KEY_F2 291 +#define CP_KEY_F3 292 +#define CP_KEY_F4 293 +#define CP_KEY_F5 294 +#define CP_KEY_F6 295 +#define CP_KEY_F7 296 +#define CP_KEY_F8 297 +#define CP_KEY_F9 298 +#define CP_KEY_F10 299 +#define CP_KEY_F11 300 +#define CP_KEY_F12 301 +#define CP_KEY_F13 302 +#define CP_KEY_F14 303 +#define CP_KEY_F15 304 +#define CP_KEY_F16 305 +#define CP_KEY_F17 306 +#define CP_KEY_F18 307 +#define CP_KEY_F19 308 +#define CP_KEY_F20 309 +#define CP_KEY_F21 310 +#define CP_KEY_F22 311 +#define CP_KEY_F23 312 +#define CP_KEY_F24 313 +#define CP_KEY_F25 314 +#define CP_KEY_KP_0 320 +#define CP_KEY_KP_1 321 +#define CP_KEY_KP_2 322 +#define CP_KEY_KP_3 323 +#define CP_KEY_KP_4 324 +#define CP_KEY_KP_5 325 +#define CP_KEY_KP_6 326 +#define CP_KEY_KP_7 327 +#define CP_KEY_KP_8 328 +#define CP_KEY_KP_9 329 +#define CP_KEY_KP_DECIMAL 330 +#define CP_KEY_KP_DIVIDE 331 +#define CP_KEY_KP_MULTIPLY 332 +#define CP_KEY_KP_SUBTRACT 333 +#define CP_KEY_KP_ADD 334 +#define CP_KEY_KP_ENTER 335 +#define CP_KEY_KP_EQUAL 336 +#define CP_KEY_LEFT_SHIFT 340 +#define CP_KEY_LEFT_CONTROL 341 +#define CP_KEY_LEFT_ALT 342 +#define CP_KEY_LEFT_SUPER 343 +#define CP_KEY_RIGHT_SHIFT 344 +#define CP_KEY_RIGHT_CONTROL 345 +#define CP_KEY_RIGHT_ALT 346 +#define CP_KEY_RIGHT_SUPER 347 +#define CP_KEY_MENU 348 +#define CP_KEY_UNBOUND 0x0fffffff diff --git a/CopiumEngine/src/copium/event/KeyPressEvent.cpp b/CopiumEngine/src/copium/event/KeyPressEvent.cpp index 384a4c6..e90e6dc 100644 --- a/CopiumEngine/src/copium/event/KeyPressEvent.cpp +++ b/CopiumEngine/src/copium/event/KeyPressEvent.cpp @@ -3,8 +3,10 @@ namespace Copium { KeyPressEvent::KeyPressEvent(int button) - : Event{EventType::KeyPress}, button{button} - {} + : Event{EventType::KeyPress}, + button{button} + { + } int KeyPressEvent::GetButton() const { diff --git a/CopiumEngine/src/copium/event/KeyPressEvent.h b/CopiumEngine/src/copium/event/KeyPressEvent.h index 59ffdd4..f267ad2 100644 --- a/CopiumEngine/src/copium/event/KeyPressEvent.h +++ b/CopiumEngine/src/copium/event/KeyPressEvent.h @@ -8,6 +8,7 @@ namespace Copium { private: int button; + public: KeyPressEvent(int button); diff --git a/CopiumEngine/src/copium/event/KeyReleaseEvent.cpp b/CopiumEngine/src/copium/event/KeyReleaseEvent.cpp index e692ee9..b8b63ba 100644 --- a/CopiumEngine/src/copium/event/KeyReleaseEvent.cpp +++ b/CopiumEngine/src/copium/event/KeyReleaseEvent.cpp @@ -3,8 +3,10 @@ namespace Copium { KeyReleaseEvent::KeyReleaseEvent(int button) - : Event{EventType::KeyRelease}, button{button} - {} + : Event{EventType::KeyRelease}, + button{button} + { + } int KeyReleaseEvent::GetButton() const { diff --git a/CopiumEngine/src/copium/event/KeyReleaseEvent.h b/CopiumEngine/src/copium/event/KeyReleaseEvent.h index 9b98a13..22c81d1 100644 --- a/CopiumEngine/src/copium/event/KeyReleaseEvent.h +++ b/CopiumEngine/src/copium/event/KeyReleaseEvent.h @@ -8,6 +8,7 @@ namespace Copium { private: int button; + public: KeyReleaseEvent(int button); diff --git a/CopiumEngine/src/copium/event/MouseMoveEvent.cpp b/CopiumEngine/src/copium/event/MouseMoveEvent.cpp index 47f69d2..d797c63 100644 --- a/CopiumEngine/src/copium/event/MouseMoveEvent.cpp +++ b/CopiumEngine/src/copium/event/MouseMoveEvent.cpp @@ -3,8 +3,11 @@ namespace Copium { MouseMoveEvent::MouseMoveEvent(glm::vec2 pos, glm::vec2 delta) - : Event{EventType::MouseMove}, pos{pos}, delta{delta} - {} + : Event{EventType::MouseMove}, + pos{pos}, + delta{delta} + { + } glm::vec2 MouseMoveEvent::GetPos() const { diff --git a/CopiumEngine/src/copium/event/MouseMoveEvent.h b/CopiumEngine/src/copium/event/MouseMoveEvent.h index bf75bea..14e0117 100644 --- a/CopiumEngine/src/copium/event/MouseMoveEvent.h +++ b/CopiumEngine/src/copium/event/MouseMoveEvent.h @@ -1,9 +1,9 @@ #pragma once -#include "copium/event/Event.h" - #include +#include "copium/event/Event.h" + namespace Copium { class MouseMoveEvent : public Event @@ -11,6 +11,7 @@ namespace Copium private: glm::vec2 pos; glm::vec2 delta; + public: MouseMoveEvent(glm::vec2 pos, glm::vec2 delta); diff --git a/CopiumEngine/src/copium/event/MousePressEvent.cpp b/CopiumEngine/src/copium/event/MousePressEvent.cpp index de6d5fe..3df8850 100644 --- a/CopiumEngine/src/copium/event/MousePressEvent.cpp +++ b/CopiumEngine/src/copium/event/MousePressEvent.cpp @@ -3,8 +3,10 @@ namespace Copium { MousePressEvent::MousePressEvent(int button) - : Event{EventType::MousePress}, button{button} - {} + : Event{EventType::MousePress}, + button{button} + { + } int MousePressEvent::GetButton() const { diff --git a/CopiumEngine/src/copium/event/MousePressEvent.h b/CopiumEngine/src/copium/event/MousePressEvent.h index a9f573b..47656ad 100644 --- a/CopiumEngine/src/copium/event/MousePressEvent.h +++ b/CopiumEngine/src/copium/event/MousePressEvent.h @@ -1,15 +1,16 @@ #pragma once -#include "copium/event/Event.h" - #include +#include "copium/event/Event.h" + namespace Copium { class MousePressEvent : public Event { private: int button; + public: MousePressEvent(int button); diff --git a/CopiumEngine/src/copium/event/MouseReleaseEvent.cpp b/CopiumEngine/src/copium/event/MouseReleaseEvent.cpp index 43beb89..2ea8c59 100644 --- a/CopiumEngine/src/copium/event/MouseReleaseEvent.cpp +++ b/CopiumEngine/src/copium/event/MouseReleaseEvent.cpp @@ -3,8 +3,10 @@ namespace Copium { MouseReleaseEvent::MouseReleaseEvent(int button) - : Event{EventType::MouseRelease}, button{button} - {} + : Event{EventType::MouseRelease}, + button{button} + { + } int MouseReleaseEvent::GetButton() const { diff --git a/CopiumEngine/src/copium/event/MouseReleaseEvent.h b/CopiumEngine/src/copium/event/MouseReleaseEvent.h index 56e3006..5743e8f 100644 --- a/CopiumEngine/src/copium/event/MouseReleaseEvent.h +++ b/CopiumEngine/src/copium/event/MouseReleaseEvent.h @@ -1,15 +1,16 @@ #pragma once -#include "copium/event/Event.h" - #include +#include "copium/event/Event.h" + namespace Copium { class MouseReleaseEvent : public Event { private: int button; + public: MouseReleaseEvent(int button); diff --git a/CopiumEngine/src/copium/event/MouseScrollEvent.cpp b/CopiumEngine/src/copium/event/MouseScrollEvent.cpp index 37c441f..7aba9be 100644 --- a/CopiumEngine/src/copium/event/MouseScrollEvent.cpp +++ b/CopiumEngine/src/copium/event/MouseScrollEvent.cpp @@ -3,8 +3,11 @@ namespace Copium { MouseScrollEvent::MouseScrollEvent(int scrollX, int scrollY) - : Event{EventType::MouseScroll}, scrollX{scrollX}, scrollY{scrollY} - {} + : Event{EventType::MouseScroll}, + scrollX{scrollX}, + scrollY{scrollY} + { + } int MouseScrollEvent::GetScrollX() const { diff --git a/CopiumEngine/src/copium/event/MouseScrollEvent.h b/CopiumEngine/src/copium/event/MouseScrollEvent.h index a2ef4a4..b9b1ab4 100644 --- a/CopiumEngine/src/copium/event/MouseScrollEvent.h +++ b/CopiumEngine/src/copium/event/MouseScrollEvent.h @@ -9,6 +9,7 @@ namespace Copium private: int scrollX; int scrollY; + public: MouseScrollEvent(int scrollX, int scrollY); diff --git a/CopiumEngine/src/copium/event/ViewportResize.cpp b/CopiumEngine/src/copium/event/ViewportResize.cpp index 441029a..740bb47 100644 --- a/CopiumEngine/src/copium/event/ViewportResize.cpp +++ b/CopiumEngine/src/copium/event/ViewportResize.cpp @@ -3,8 +3,10 @@ namespace Copium { ViewportResize::ViewportResize(const BoundingBox& viewport) - : Event(EventType::ViewportResize), viewport{viewport} - {} + : Event(EventType::ViewportResize), + viewport{viewport} + { + } const BoundingBox& ViewportResize::GetViewport() const { diff --git a/CopiumEngine/src/copium/event/ViewportResize.h b/CopiumEngine/src/copium/event/ViewportResize.h index 31f0d54..43fe365 100644 --- a/CopiumEngine/src/copium/event/ViewportResize.h +++ b/CopiumEngine/src/copium/event/ViewportResize.h @@ -8,6 +8,7 @@ namespace Copium class ViewportResize : public Event { BoundingBox viewport; + public: ViewportResize(const BoundingBox& viewport); diff --git a/CopiumEngine/src/copium/event/WindowFocusEvent.cpp b/CopiumEngine/src/copium/event/WindowFocusEvent.cpp index 53d1c85..22dc555 100644 --- a/CopiumEngine/src/copium/event/WindowFocusEvent.cpp +++ b/CopiumEngine/src/copium/event/WindowFocusEvent.cpp @@ -3,8 +3,10 @@ namespace Copium { WindowFocusEvent::WindowFocusEvent(bool focused) - : Event{EventType::WindowFocus}, focused{focused} - {} + : Event{EventType::WindowFocus}, + focused{focused} + { + } bool WindowFocusEvent::IsFocused() const { diff --git a/CopiumEngine/src/copium/event/WindowFocusEvent.h b/CopiumEngine/src/copium/event/WindowFocusEvent.h index 2469198..fe13df3 100644 --- a/CopiumEngine/src/copium/event/WindowFocusEvent.h +++ b/CopiumEngine/src/copium/event/WindowFocusEvent.h @@ -8,6 +8,7 @@ namespace Copium { private: bool focused; + public: WindowFocusEvent(bool focused); diff --git a/CopiumEngine/src/copium/event/WindowResizeEvent.cpp b/CopiumEngine/src/copium/event/WindowResizeEvent.cpp index 67066c8..a2a8de6 100644 --- a/CopiumEngine/src/copium/event/WindowResizeEvent.cpp +++ b/CopiumEngine/src/copium/event/WindowResizeEvent.cpp @@ -3,8 +3,11 @@ namespace Copium { WindowResizeEvent::WindowResizeEvent(int width, int height) - : Event{EventType::WindowResize}, width{width}, height{height} - {} + : Event{EventType::WindowResize}, + width{width}, + height{height} + { + } int WindowResizeEvent::GetWidth() const { diff --git a/CopiumEngine/src/copium/event/WindowResizeEvent.h b/CopiumEngine/src/copium/event/WindowResizeEvent.h index bd63103..41bb049 100644 --- a/CopiumEngine/src/copium/event/WindowResizeEvent.h +++ b/CopiumEngine/src/copium/event/WindowResizeEvent.h @@ -9,6 +9,7 @@ namespace Copium private: int width; int height; + public: WindowResizeEvent(int width, int height); diff --git a/CopiumEngine/src/copium/mesh/Mesh.h b/CopiumEngine/src/copium/mesh/Mesh.h index d530347..b4b84bb 100644 --- a/CopiumEngine/src/copium/mesh/Mesh.h +++ b/CopiumEngine/src/copium/mesh/Mesh.h @@ -1,21 +1,23 @@ #pragma once +#include +#include + +#include "copium/buffer/CommandBuffer.h" #include "copium/buffer/IndexBuffer.h" #include "copium/buffer/VertexBuffer.h" -#include "copium/buffer/CommandBuffer.h" #include "copium/util/Common.h" -#include -#include - namespace Copium { class Mesh { CP_DELETE_COPY_AND_MOVE_CTOR(Mesh); + private: std::unique_ptr indexBuffer; std::unique_ptr vertexBuffer; + public: template Mesh(const std::vector& vertices, const std::vector& indices); @@ -30,6 +32,6 @@ namespace Copium indexBuffer = std::make_unique(indices.size()); indexBuffer->UpdateStaging((void*)indices.data()); vertexBuffer = std::make_unique(T::GetDescriptor(), vertices.size()); - vertexBuffer ->UpdateStaging(0, (void*)vertices.data()); + vertexBuffer->UpdateStaging(0, (void*)vertices.data()); } } diff --git a/CopiumEngine/src/copium/mesh/Vertex.h b/CopiumEngine/src/copium/mesh/Vertex.h index d3ca4a4..7229b16 100644 --- a/CopiumEngine/src/copium/mesh/Vertex.h +++ b/CopiumEngine/src/copium/mesh/Vertex.h @@ -1,9 +1,9 @@ #pragma once -#include "copium/pipeline/VertexDescriptor.h" - #include +#include "copium/pipeline/VertexDescriptor.h" + namespace Copium { struct Vertex @@ -15,4 +15,3 @@ namespace Copium static VertexDescriptor GetDescriptor(); }; } - diff --git a/CopiumEngine/src/copium/mesh/VertexPassthrough.cpp b/CopiumEngine/src/copium/mesh/VertexPassthrough.cpp index 42a914a..5e21ea8 100644 --- a/CopiumEngine/src/copium/mesh/VertexPassthrough.cpp +++ b/CopiumEngine/src/copium/mesh/VertexPassthrough.cpp @@ -5,7 +5,8 @@ namespace Copium VertexDescriptor VertexPassthrough::GetDescriptor() { VertexDescriptor descriptor{}; - descriptor.AddAttribute(0, 0, VK_FORMAT_R32G32_SFLOAT, offsetof(VertexPassthrough, texCoord), sizeof(VertexPassthrough)); + descriptor.AddAttribute( + 0, 0, VK_FORMAT_R32G32_SFLOAT, offsetof(VertexPassthrough, texCoord), sizeof(VertexPassthrough)); return descriptor; } } \ No newline at end of file diff --git a/CopiumEngine/src/copium/mesh/VertexPassthrough.h b/CopiumEngine/src/copium/mesh/VertexPassthrough.h index 49db4de..cd7c4ee 100644 --- a/CopiumEngine/src/copium/mesh/VertexPassthrough.h +++ b/CopiumEngine/src/copium/mesh/VertexPassthrough.h @@ -1,9 +1,9 @@ #pragma once -#include "copium/pipeline/VertexDescriptor.h" - #include +#include "copium/pipeline/VertexDescriptor.h" + namespace Copium { struct VertexPassthrough diff --git a/CopiumEngine/src/copium/pipeline/DescriptorPool.cpp b/CopiumEngine/src/copium/pipeline/DescriptorPool.cpp index adb20cc..374a25a 100644 --- a/CopiumEngine/src/copium/pipeline/DescriptorPool.cpp +++ b/CopiumEngine/src/copium/pipeline/DescriptorPool.cpp @@ -23,23 +23,22 @@ namespace Copium poolSizes.emplace_back(descriptorSetPoolSize); } - VkDescriptorPoolCreateInfo createInfo{}; createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; createInfo.poolSizeCount = poolSizes.size(); createInfo.pPoolSizes = poolSizes.data(); - createInfo.maxSets = uniformDescriptorSets + imageDescriptorSets; // I have no actual idea if this is fine + createInfo.maxSets = uniformDescriptorSets + imageDescriptorSets; // I have no actual idea if this is fine createInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; - CP_VK_ASSERT(vkCreateDescriptorPool(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorPool), "Failed to initialize descriptor pool"); + CP_VK_ASSERT(vkCreateDescriptorPool(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorPool), + "Failed to initialize descriptor pool"); } DescriptorPool::~DescriptorPool() { VkDescriptorPool descriptorPoolCpy = descriptorPool; - Vulkan::GetDevice().QueueIdleCommand([descriptorPoolCpy]() { - vkDestroyDescriptorPool(Vulkan::GetDevice(), descriptorPoolCpy, nullptr); - }); + Vulkan::GetDevice().QueueIdleCommand([descriptorPoolCpy]() + { vkDestroyDescriptorPool(Vulkan::GetDevice(), descriptorPoolCpy, nullptr); }); } std::vector DescriptorPool::AllocateDescriptorSets(VkDescriptorSetLayout descriptorSetLayout) @@ -52,7 +51,8 @@ namespace Copium allocateInfo.descriptorSetCount = descriptorSets.size(); allocateInfo.pSetLayouts = layouts.data(); - CP_VK_ASSERT(vkAllocateDescriptorSets(Vulkan::GetDevice(), &allocateInfo, descriptorSets.data()), "Failed to allocate descriptor sets"); + CP_VK_ASSERT(vkAllocateDescriptorSets(Vulkan::GetDevice(), &allocateInfo, descriptorSets.data()), + "Failed to allocate descriptor sets"); return descriptorSets; } @@ -61,9 +61,12 @@ namespace Copium { VkDescriptorPool descriptorPoolCpy = descriptorPool; std::vector descriptorSetsCpy = descriptorSets; - Vulkan::GetDevice().QueueIdleCommand([descriptorPoolCpy, descriptorSetsCpy]() { - vkFreeDescriptorSets(Vulkan::GetDevice(), descriptorPoolCpy, descriptorSetsCpy.size(), descriptorSetsCpy.data()); - }); + Vulkan::GetDevice().QueueIdleCommand( + [descriptorPoolCpy, descriptorSetsCpy]() + { + vkFreeDescriptorSets( + Vulkan::GetDevice(), descriptorPoolCpy, descriptorSetsCpy.size(), descriptorSetsCpy.data()); + }); } DescriptorPool::operator VkDescriptorPool() const diff --git a/CopiumEngine/src/copium/pipeline/DescriptorPool.h b/CopiumEngine/src/copium/pipeline/DescriptorPool.h index a92a813..9494d3b 100644 --- a/CopiumEngine/src/copium/pipeline/DescriptorPool.h +++ b/CopiumEngine/src/copium/pipeline/DescriptorPool.h @@ -1,16 +1,18 @@ #pragma once -#include "copium/util/Common.h" - #include +#include "copium/util/Common.h" + namespace Copium { class DescriptorPool final { CP_DELETE_COPY_AND_MOVE_CTOR(DescriptorPool); + private: VkDescriptorPool descriptorPool; + public: DescriptorPool(int uniformDescriptorSets, int imageDescriptorSets); ~DescriptorPool(); diff --git a/CopiumEngine/src/copium/pipeline/DescriptorSet.cpp b/CopiumEngine/src/copium/pipeline/DescriptorSet.cpp index bd552f4..5a685a9 100644 --- a/CopiumEngine/src/copium/pipeline/DescriptorSet.cpp +++ b/CopiumEngine/src/copium/pipeline/DescriptorSet.cpp @@ -4,8 +4,12 @@ namespace Copium { - DescriptorSet::DescriptorSet(DescriptorPool& descriptorPool, VkDescriptorSetLayout descriptorSetLayout, const std::set& bindings) - : descriptorPool{descriptorPool}, descriptorSetLayout{descriptorSetLayout}, bindings{bindings} + DescriptorSet::DescriptorSet(DescriptorPool& descriptorPool, + VkDescriptorSetLayout descriptorSetLayout, + const std::set& bindings) + : descriptorPool{descriptorPool}, + descriptorSetLayout{descriptorSetLayout}, + bindings{bindings} { CP_ASSERT(!bindings.empty(), "Cannot initialize DescriptorSet with empty ShaderBindings"); @@ -64,7 +68,8 @@ namespace Copium void DescriptorSet::SetSamplers(const std::vector& samplers, uint32_t binding) { - for (size_t i = 0; i < descriptorSets.size(); ++i) { + for (size_t i = 0; i < descriptorSets.size(); ++i) + { std::vector descriptorWrites{samplers.size()}; for (size_t j = 0; j < samplers.size(); j++) { @@ -126,7 +131,8 @@ namespace Copium void DescriptorSet::SetUniformBuffer(const UniformBuffer& uniformBuffer, uint32_t binding) { - for (size_t i = 0; i < descriptorSets.size(); ++i) { + for (size_t i = 0; i < descriptorSets.size(); ++i) + { VkDescriptorBufferInfo bufferInfo = uniformBuffer.GetDescriptorBufferInfo(i); VkWriteDescriptorSet descriptorWrite{}; diff --git a/CopiumEngine/src/copium/pipeline/DescriptorSet.h b/CopiumEngine/src/copium/pipeline/DescriptorSet.h index 9d513dd..32a5af7 100644 --- a/CopiumEngine/src/copium/pipeline/DescriptorSet.h +++ b/CopiumEngine/src/copium/pipeline/DescriptorSet.h @@ -1,23 +1,23 @@ #pragma once +#include +#include +#include +#include +#include + #include "copium/buffer/UniformBuffer.h" #include "copium/pipeline/DescriptorPool.h" #include "copium/pipeline/ShaderBinding.h" #include "copium/sampler/Sampler.h" #include "copium/util/Common.h" -#include -#include - -#include -#include -#include - namespace Copium { class DescriptorSet final { CP_DELETE_COPY_AND_MOVE_CTOR(DescriptorSet); + private: DescriptorPool& descriptorPool; VkDescriptorSetLayout descriptorSetLayout; @@ -27,7 +27,9 @@ namespace Copium std::map> uniformBuffers; public: - DescriptorSet(DescriptorPool& descriptorPool, VkDescriptorSetLayout descriptorSetLayout, const std::set& bindings); + DescriptorSet(DescriptorPool& descriptorPool, + VkDescriptorSetLayout descriptorSetLayout, + const std::set& bindings); ~DescriptorSet(); void SetSampler(const Sampler& sampler, uint32_t binding, int arrayIndex = 0); @@ -39,6 +41,7 @@ namespace Copium VkDescriptorSet GetVkDescriptorSet(int flightIndex) const; operator VkDescriptorSet() const; + private: void SetUniformBuffer(const UniformBuffer& uniformBuffer, uint32_t binding); }; diff --git a/CopiumEngine/src/copium/pipeline/Pipeline.cpp b/CopiumEngine/src/copium/pipeline/Pipeline.cpp index ac64845..8527b51 100644 --- a/CopiumEngine/src/copium/pipeline/Pipeline.cpp +++ b/CopiumEngine/src/copium/pipeline/Pipeline.cpp @@ -2,16 +2,17 @@ #include "copium/buffer/Framebuffer.h" #include "copium/core/Vulkan.h" -#include "copium/pipeline/Shader.h" -#include "copium/renderer/RendererVertex.h" -#include "copium/mesh/VertexPassthrough.h" #include "copium/mesh/Vertex.h" +#include "copium/mesh/VertexPassthrough.h" +#include "copium/pipeline/Shader.h" #include "copium/renderer/LineVertex.h" +#include "copium/renderer/RendererVertex.h" namespace Copium { Pipeline::Pipeline(const MetaFile& metaFile) - : shaderReflector{ShaderReflector{metaFile.GetMetaClass("Pipeline").GetValue("vert-filepath"), metaFile.GetMetaClass("Pipeline").GetValue("frag-filepath")}} + : shaderReflector{ShaderReflector{metaFile.GetMetaClass("Pipeline").GetValue("vert-filepath"), + metaFile.GetMetaClass("Pipeline").GetValue("frag-filepath")}} { const MetaFileClass& metaFileClass = metaFile.GetMetaClass("Pipeline"); VkRenderPass renderPass; @@ -25,7 +26,8 @@ namespace Copium { renderPass = Vulkan::GetSwapChain().GetRenderPass(); } - PipelineCreator creator{renderPass, metaFileClass.GetValue("vert-filepath"), metaFileClass.GetValue("frag-filepath")}; + PipelineCreator creator{ + renderPass, metaFileClass.GetValue("vert-filepath"), metaFileClass.GetValue("frag-filepath")}; std::string type = metaFileClass.GetValue("type"); if (type == "Renderer") { @@ -66,14 +68,16 @@ namespace Copium VkPipeline graphicsPipelineCpy = graphicsPipeline; VkPipelineLayout pipelineLayoutCpy = pipelineLayout; std::vector descriptorSetLayoutsCpy = descriptorSetLayouts; - Vulkan::GetDevice().QueueIdleCommand([graphicsPipelineCpy, pipelineLayoutCpy, descriptorSetLayoutsCpy]() { - vkDestroyPipeline(Vulkan::GetDevice(), graphicsPipelineCpy, nullptr); - vkDestroyPipelineLayout(Vulkan::GetDevice(), pipelineLayoutCpy, nullptr); - for (auto&& descriptorSetLayout : descriptorSetLayoutsCpy) + Vulkan::GetDevice().QueueIdleCommand( + [graphicsPipelineCpy, pipelineLayoutCpy, descriptorSetLayoutsCpy]() { - vkDestroyDescriptorSetLayout(Vulkan::GetDevice(), descriptorSetLayout, nullptr); - } - }); + vkDestroyPipeline(Vulkan::GetDevice(), graphicsPipelineCpy, nullptr); + vkDestroyPipelineLayout(Vulkan::GetDevice(), pipelineLayoutCpy, nullptr); + for (auto&& descriptorSetLayout : descriptorSetLayoutsCpy) + { + vkDestroyDescriptorSetLayout(Vulkan::GetDevice(), descriptorSetLayout, nullptr); + } + }); } void Pipeline::Bind(const CommandBuffer& commandBuffer) @@ -92,7 +96,14 @@ namespace Copium void Pipeline::BindDescriptorSets(const CommandBuffer& commandBuffer) { - vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, GetDescriptorSetCount(), boundDescriptorSetsPerFlightIndex[Vulkan::GetSwapChain().GetFlightIndex()].data(), 0, nullptr); + vkCmdBindDescriptorSets(commandBuffer, + VK_PIPELINE_BIND_POINT_GRAPHICS, + pipelineLayout, + 0, + GetDescriptorSetCount(), + boundDescriptorSetsPerFlightIndex[Vulkan::GetSwapChain().GetFlightIndex()].data(), + 0, + nullptr); } std::unique_ptr Pipeline::CreateDescriptorSet(DescriptorPool& descriptorPool, int setIndex) const @@ -155,7 +166,8 @@ namespace Copium createInfo.bindingCount = layoutBindings.size(); createInfo.pBindings = layoutBindings.data(); - CP_VK_ASSERT(vkCreateDescriptorSetLayout(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorSetLayouts[i++]), "Failed to initialize descriptor set layout"); + CP_VK_ASSERT(vkCreateDescriptorSetLayout(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorSetLayouts[i++]), + "Failed to initialize descriptor set layout"); } } @@ -187,10 +199,7 @@ namespace Copium scissor.offset = {0, 0}; scissor.extent = {1, 1}; - std::vector dynamicStates = { - VK_DYNAMIC_STATE_VIEWPORT, - VK_DYNAMIC_STATE_SCISSOR - }; + std::vector dynamicStates = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR}; VkPipelineDynamicStateCreateInfo dynamicStateCreateInfo{}; dynamicStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; @@ -239,12 +248,9 @@ namespace Copium depthStencilCreateInfo.front = {}; depthStencilCreateInfo.back = {}; - - VkPipelineColorBlendAttachmentState colorBlendAttachment{}; // TODO: Add to PipelineCreator - colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | - VK_COLOR_COMPONENT_G_BIT | - VK_COLOR_COMPONENT_B_BIT | - VK_COLOR_COMPONENT_A_BIT; + VkPipelineColorBlendAttachmentState colorBlendAttachment{}; // TODO: Add to PipelineCreator + colorBlendAttachment.colorWriteMask = + VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; colorBlendAttachment.blendEnable = creator.blending ? VK_TRUE : VK_FALSE; colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; @@ -271,7 +277,8 @@ namespace Copium pipelineLayoutCreateInfo.pushConstantRangeCount = 0; pipelineLayoutCreateInfo.pPushConstantRanges = nullptr; - CP_VK_ASSERT(vkCreatePipelineLayout(Vulkan::GetDevice(), &pipelineLayoutCreateInfo, nullptr, &pipelineLayout), "Failed to initialize pipeline layout"); + CP_VK_ASSERT(vkCreatePipelineLayout(Vulkan::GetDevice(), &pipelineLayoutCreateInfo, nullptr, &pipelineLayout), + "Failed to initialize pipeline layout"); const std::vector& shaderStages = shader.GetShaderStages(); VkGraphicsPipelineCreateInfo graphicsPipelineCreateInfo{}; @@ -292,6 +299,8 @@ namespace Copium graphicsPipelineCreateInfo.basePipelineHandle = VK_NULL_HANDLE; graphicsPipelineCreateInfo.basePipelineIndex = -1; - CP_VK_ASSERT(vkCreateGraphicsPipelines(Vulkan::GetDevice(), VK_NULL_HANDLE, 1, &graphicsPipelineCreateInfo, nullptr, &graphicsPipeline), "Failed to initialize graphics pipeline"); + CP_VK_ASSERT(vkCreateGraphicsPipelines( + Vulkan::GetDevice(), VK_NULL_HANDLE, 1, &graphicsPipelineCreateInfo, nullptr, &graphicsPipeline), + "Failed to initialize graphics pipeline"); } } diff --git a/CopiumEngine/src/copium/pipeline/Pipeline.h b/CopiumEngine/src/copium/pipeline/Pipeline.h index 03e544b..a77d8e4 100644 --- a/CopiumEngine/src/copium/pipeline/Pipeline.h +++ b/CopiumEngine/src/copium/pipeline/Pipeline.h @@ -1,5 +1,8 @@ #pragma once +#include +#include + #include "copium/asset/Asset.h" #include "copium/asset/AssetRef.h" #include "copium/buffer/CommandBuffer.h" @@ -8,14 +11,12 @@ #include "copium/pipeline/PipelineCreator.h" #include "copium/util/Common.h" -#include -#include - namespace Copium { class Pipeline final : public Asset { CP_DELETE_COPY_AND_MOVE_CTOR(Pipeline); + private: ShaderReflector shaderReflector; std::vector descriptorSetLayouts{}; @@ -25,7 +26,6 @@ namespace Copium AssetRef framebuffer; public: - Pipeline(const MetaFile& metaFile); Pipeline(PipelineCreator creator); ~Pipeline(); diff --git a/CopiumEngine/src/copium/pipeline/PipelineCreator.cpp b/CopiumEngine/src/copium/pipeline/PipelineCreator.cpp index 62952a2..7173479 100644 --- a/CopiumEngine/src/copium/pipeline/PipelineCreator.cpp +++ b/CopiumEngine/src/copium/pipeline/PipelineCreator.cpp @@ -4,7 +4,9 @@ namespace Copium { - PipelineCreator::PipelineCreator(VkRenderPass renderPass, const std::string& vertexShader, const std::string& fragmentShader) + PipelineCreator::PipelineCreator(VkRenderPass renderPass, + const std::string& vertexShader, + const std::string& fragmentShader) : vertexShader{vertexShader}, fragmentShader{fragmentShader}, shaderReflector{vertexShader, fragmentShader}, @@ -47,7 +49,10 @@ namespace Copium { for (auto& binding : shaderReflector.bindings) { - descriptorSetLayouts[binding.set].emplace_back(DescriptorSetBinding{binding.binding, GetDescriptorType(binding.bindingType), binding.arraySize, GetShaderStageFlags(binding.shaderType)}); + descriptorSetLayouts[binding.set].emplace_back(DescriptorSetBinding{binding.binding, + GetDescriptorType(binding.bindingType), + binding.arraySize, + GetShaderStageFlags(binding.shaderType)}); } } @@ -55,12 +60,12 @@ namespace Copium { switch (type) { - case BindingType::Sampler2D: - return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - case BindingType::UniformBuffer: - return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - default: - CP_ABORT("Unhandled switch case"); + case BindingType::Sampler2D: + return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + case BindingType::UniformBuffer: + return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + default: + CP_ABORT("Unhandled switch case"); } } @@ -68,12 +73,12 @@ namespace Copium { switch (type) { - case ShaderType::Vertex: - return VK_SHADER_STAGE_VERTEX_BIT; - case ShaderType::Fragment: - return VK_SHADER_STAGE_FRAGMENT_BIT; - default: - CP_ABORT("Unhandled switch case"); + case ShaderType::Vertex: + return VK_SHADER_STAGE_VERTEX_BIT; + case ShaderType::Fragment: + return VK_SHADER_STAGE_FRAGMENT_BIT; + default: + CP_ABORT("Unhandled switch case"); } } } diff --git a/CopiumEngine/src/copium/pipeline/PipelineCreator.h b/CopiumEngine/src/copium/pipeline/PipelineCreator.h index 9ee557d..5a275b2 100644 --- a/CopiumEngine/src/copium/pipeline/PipelineCreator.h +++ b/CopiumEngine/src/copium/pipeline/PipelineCreator.h @@ -1,14 +1,13 @@ #pragma once +#include +#include +#include +#include + #include "copium/pipeline/ShaderReflector.h" #include "copium/pipeline/VertexDescriptor.h" -#include - -#include -#include -#include - namespace Copium { class PipelineCreator @@ -21,6 +20,7 @@ namespace Copium VkShaderStageFlags flags; }; friend class Pipeline; + private: std::map> descriptorSetLayouts{}; @@ -45,6 +45,7 @@ namespace Copium void SetCullFrontFace(VkFrontFace cullFrontFace); void SetDepthTest(bool depthTest); void SetBlending(bool blending); + private: void AddShaderDescription(); static VkDescriptorType GetDescriptorType(BindingType type); diff --git a/CopiumEngine/src/copium/pipeline/Shader.cpp b/CopiumEngine/src/copium/pipeline/Shader.cpp index 447947a..b6f7af0 100644 --- a/CopiumEngine/src/copium/pipeline/Shader.cpp +++ b/CopiumEngine/src/copium/pipeline/Shader.cpp @@ -1,7 +1,7 @@ #include "Shader.h" -#include "copium/util/FileSystem.h" #include "copium/core/Vulkan.h" +#include "copium/util/FileSystem.h" #include "copium/util/RuntimeException.h" namespace Copium @@ -10,24 +10,24 @@ namespace Copium { switch (type) { - case ShaderReadType::GlslCode: - vertShaderModule = InitializeShaderModuleFromGlslCode(vertexInput, shaderc_vertex_shader); - fragShaderModule = InitializeShaderModuleFromGlslCode(fragmentInput, shaderc_fragment_shader); - break; - case ShaderReadType::GlslFile: - vertShaderModule = InitializeShaderModuleFromGlslFile(vertexInput, shaderc_vertex_shader); - fragShaderModule = InitializeShaderModuleFromGlslFile(fragmentInput, shaderc_fragment_shader); - break; - case ShaderReadType::SpvCode: - vertShaderModule = InitializeShaderModule(vertexInput); - fragShaderModule = InitializeShaderModule(fragmentInput); - break; - case ShaderReadType::SpvFile: - vertShaderModule = InitializeShaderModule(FileSystem::ReadFile(vertexInput)); - fragShaderModule = InitializeShaderModule(FileSystem::ReadFile(fragmentInput)); - break; - default: - CP_ASSERT(false, "Unreachable switch case: %s", ToString(type).c_str()); + case ShaderReadType::GlslCode: + vertShaderModule = InitializeShaderModuleFromGlslCode(vertexInput, shaderc_vertex_shader); + fragShaderModule = InitializeShaderModuleFromGlslCode(fragmentInput, shaderc_fragment_shader); + break; + case ShaderReadType::GlslFile: + vertShaderModule = InitializeShaderModuleFromGlslFile(vertexInput, shaderc_vertex_shader); + fragShaderModule = InitializeShaderModuleFromGlslFile(fragmentInput, shaderc_fragment_shader); + break; + case ShaderReadType::SpvCode: + vertShaderModule = InitializeShaderModule(vertexInput); + fragShaderModule = InitializeShaderModule(fragmentInput); + break; + case ShaderReadType::SpvFile: + vertShaderModule = InitializeShaderModule(FileSystem::ReadFile(vertexInput)); + fragShaderModule = InitializeShaderModule(FileSystem::ReadFile(fragmentInput)); + break; + default: + CP_ASSERT(false, "Unreachable switch case: %s", ToString(type).c_str()); } shaderStages.resize(2); @@ -48,10 +48,12 @@ namespace Copium { VkShaderModule vertShaderModuleCpy = vertShaderModule; VkShaderModule fragShaderModuleCpy = fragShaderModule; - Vulkan::GetDevice().QueueIdleCommand([vertShaderModuleCpy, fragShaderModuleCpy]() { - vkDestroyShaderModule(Vulkan::GetDevice(), vertShaderModuleCpy, nullptr); - vkDestroyShaderModule(Vulkan::GetDevice(), fragShaderModuleCpy, nullptr); - }); + Vulkan::GetDevice().QueueIdleCommand( + [vertShaderModuleCpy, fragShaderModuleCpy]() + { + vkDestroyShaderModule(Vulkan::GetDevice(), vertShaderModuleCpy, nullptr); + vkDestroyShaderModule(Vulkan::GetDevice(), fragShaderModuleCpy, nullptr); + }); } const std::vector Shader::GetShaderStages() const @@ -100,8 +102,12 @@ namespace Copium options.SetOptimizationLevel(shaderc_optimization_level_size); std::vector glslCode = FileSystem::ReadFile(filename); - shaderc::SpvCompilationResult result = compiler.CompileGlslToSpv(glslCode.data(), glslCode.size(), type, filename.c_str(), options); - CP_ASSERT(result.GetCompilationStatus() == shaderc_compilation_status_success, "Failed to compile shader: %s\n%s", filename.c_str(), result.GetErrorMessage().c_str()); + shaderc::SpvCompilationResult result = + compiler.CompileGlslToSpv(glslCode.data(), glslCode.size(), type, filename.c_str(), options); + CP_ASSERT(result.GetCompilationStatus() == shaderc_compilation_status_success, + "Failed to compile shader: %s\n%s", + filename.c_str(), + result.GetErrorMessage().c_str()); std::vector data{result.cbegin(), result.cend()}; FileSystem::WriteFile(spvFilename, (const char*)data.data(), data.size() * sizeof(uint32_t)); @@ -116,7 +122,9 @@ namespace Copium options.SetOptimizationLevel(shaderc_optimization_level_size); shaderc::SpvCompilationResult result = compiler.CompileGlslToSpv(code.data(), type, "inline_shader_code", options); - CP_ASSERT(result.GetCompilationStatus() == shaderc_compilation_status_success, "Failed to compile inline shader code: %s", result.GetErrorMessage()); + CP_ASSERT(result.GetCompilationStatus() == shaderc_compilation_status_success, + "Failed to compile inline shader code: %s", + result.GetErrorMessage()); std::vector data{result.cbegin(), result.cend()}; return InitializeShaderModule(data.data(), data.size() * sizeof(uint32_t)); @@ -130,7 +138,8 @@ namespace Copium createInfo.pCode = data; VkShaderModule shaderModule; - CP_VK_ASSERT(vkCreateShaderModule(Vulkan::GetDevice(), &createInfo, nullptr, &shaderModule), "Failed to initialize shader module"); + CP_VK_ASSERT(vkCreateShaderModule(Vulkan::GetDevice(), &createInfo, nullptr, &shaderModule), + "Failed to initialize shader module"); return shaderModule; } diff --git a/CopiumEngine/src/copium/pipeline/Shader.h b/CopiumEngine/src/copium/pipeline/Shader.h index 1e4b28e..f1f4ab3 100644 --- a/CopiumEngine/src/copium/pipeline/Shader.h +++ b/CopiumEngine/src/copium/pipeline/Shader.h @@ -1,11 +1,11 @@ #pragma once -#include "copium/util/Common.h" -#include "copium/util/Enum.h" - #include #include +#include "copium/util/Common.h" +#include "copium/util/Enum.h" + #define CP_SHADER_READ_TYPE_ENUMS GlslFile, GlslCode, SpvFile, SpvCode CP_ENUM_CREATOR(Copium, ShaderReadType, CP_SHADER_READ_TYPE_ENUMS); @@ -14,15 +14,18 @@ namespace Copium class Shader final { CP_DELETE_COPY_AND_MOVE_CTOR(Shader); + private: VkShaderModule vertShaderModule; VkShaderModule fragShaderModule; std::vector shaderStages; + public: Shader(ShaderReadType type, const std::string& vertexInput, const std::string& fragmentInput); ~Shader(); const std::vector GetShaderStages() const; + private: VkShaderModule InitializeShaderModule(const std::vector& codeSpv); VkShaderModule InitializeShaderModule(const std::string& codeSpv); diff --git a/CopiumEngine/src/copium/pipeline/ShaderBinding.cpp b/CopiumEngine/src/copium/pipeline/ShaderBinding.cpp index e27da34..dc25077 100644 --- a/CopiumEngine/src/copium/pipeline/ShaderBinding.cpp +++ b/CopiumEngine/src/copium/pipeline/ShaderBinding.cpp @@ -64,22 +64,22 @@ namespace Copium { switch (type) { - case UniformType::Mat3: - return 4 * 9; // glm::mat3 - case UniformType::Mat4: - return 4 * 16; // glm::mat4 - case UniformType::Vec2: - return 4 * 2; // glm::vec2 - case UniformType::Vec3: - return 4 * 3; // glm::vec3 - case UniformType::Vec4: - return 4 * 4; // glm::vec4 - case UniformType::Int: - return 4; // int - case UniformType::Float: - return 4; // float - default: - CP_ABORT("Unhandled switch case: %s", ToString(type).c_str()); + case UniformType::Mat3: + return 4 * 9; // glm::mat3 + case UniformType::Mat4: + return 4 * 16; // glm::mat4 + case UniformType::Vec2: + return 4 * 2; // glm::vec2 + case UniformType::Vec3: + return 4 * 3; // glm::vec3 + case UniformType::Vec4: + return 4 * 4; // glm::vec4 + case UniformType::Int: + return 4; // int + case UniformType::Float: + return 4; // float + default: + CP_ABORT("Unhandled switch case: %s", ToString(type).c_str()); } } @@ -87,22 +87,22 @@ namespace Copium { switch (type) { - case UniformType::Mat3: - return 64; // alignas(16) glm::mat3 - case UniformType::Mat4: - return 64; // alignas(16) glm::mat4 - case UniformType::Vec2: - return 16; // alignas(16) glm::vec2 - case UniformType::Vec3: - return 16; // alignas(16) glm::vec2 - case UniformType::Vec4: - return 16; // alignas(16) glm::vec2 - case UniformType::Int: - return 16; // alignas(16) glm::vec2 - case UniformType::Float: - return 16; // alignas(16) glm::vec2 - default: - CP_ABORT("Unhandled switch case", ToString(type).c_str()); + case UniformType::Mat3: + return 64; // alignas(16) glm::mat3 + case UniformType::Mat4: + return 64; // alignas(16) glm::mat4 + case UniformType::Vec2: + return 16; // alignas(16) glm::vec2 + case UniformType::Vec3: + return 16; // alignas(16) glm::vec2 + case UniformType::Vec4: + return 16; // alignas(16) glm::vec2 + case UniformType::Int: + return 16; // alignas(16) glm::vec2 + case UniformType::Float: + return 16; // alignas(16) glm::vec2 + default: + CP_ABORT("Unhandled switch case", ToString(type).c_str()); } } } diff --git a/CopiumEngine/src/copium/pipeline/ShaderBinding.h b/CopiumEngine/src/copium/pipeline/ShaderBinding.h index d2fe675..1a2ee8b 100644 --- a/CopiumEngine/src/copium/pipeline/ShaderBinding.h +++ b/CopiumEngine/src/copium/pipeline/ShaderBinding.h @@ -1,11 +1,10 @@ #pragma once -#include "copium/util/Enum.h" - +#include #include #include -#include +#include "copium/util/Enum.h" #define CP_BINDING_TYPE_ENUMS Sampler2D, UniformBuffer #define CP_SHADER_TYPE_ENUMS Vertex, Fragment @@ -31,10 +30,11 @@ namespace Copium bool operator<(const ShaderBinding& rhs) const; - uint32_t GetUniformOffset (const std::string& uniform) const; + uint32_t GetUniformOffset(const std::string& uniform) const; uint32_t GetUniformSize(const std::string& uniform) const; UniformType GetUniformType(const std::string& uniform) const; uint32_t GetUniformBufferSize() const; + private: uint32_t GetUniformTypeSize(UniformType type) const; uint32_t GetUniformTypeOffset(UniformType type) const; diff --git a/CopiumEngine/src/copium/pipeline/ShaderReflector.cpp b/CopiumEngine/src/copium/pipeline/ShaderReflector.cpp index 8aba3f2..25698bc 100644 --- a/CopiumEngine/src/copium/pipeline/ShaderReflector.cpp +++ b/CopiumEngine/src/copium/pipeline/ShaderReflector.cpp @@ -1,9 +1,9 @@ #include "copium/pipeline/ShaderReflector.h" -#include "copium/util/FileSystem.h" - #include +#include "copium/util/FileSystem.h" + namespace Copium { @@ -36,12 +36,14 @@ namespace Copium void ShaderReflector::ParseLine(const std::string& str, int& index) { - while(str[index] != '\n' && index < str.size()) index++; + while (str[index] != '\n' && index < str.size()) + index++; } void ShaderReflector::ParseWhitespace(const std::string& str, int& index) { - while ((str[index] == '\n' || str[index] == ' ' || str[index] == '\t' || str[index] == '\r') && index < str.size()) index++; + while ((str[index] == '\n' || str[index] == ' ' || str[index] == '\t' || str[index] == '\r') && index < str.size()) + index++; } void ShaderReflector::ParseLayout(const std::string& str, int& index, ShaderType shaderType) @@ -49,7 +51,7 @@ namespace Copium // TODO: Make more robust, currently we might get a crash on the string if the glsl file is invalid index += sizeof("layout") - 1; ParseWhitespace(str, index); - index++; // "(" + index++; // "(" ParseWhitespace(str, index); if (std::string_view(&str[index], sizeof("set") - 1) != "set") { @@ -60,29 +62,30 @@ namespace Copium shaderBinding.shaderType = shaderType; index += sizeof("set") - 1; ParseWhitespace(str, index); - index++; // "=" + index++; // "=" ParseWhitespace(str, index); char* end; shaderBinding.set = std::strtol(&str[index], &end, 10); index = end - str.c_str(); ParseWhitespace(str, index); - index++; // "," + index++; // "," ParseWhitespace(str, index); index += sizeof("binding") - 1; ParseWhitespace(str, index); - index++; // "=" + index++; // "=" ParseWhitespace(str, index); shaderBinding.binding = std::strtol(&str[index], &end, 10); index = end - str.c_str(); ParseWhitespace(str, index); - index++; // ") + index++; // ") ParseWhitespace(str, index); index += sizeof("uniform") - 1; ParseWhitespace(str, index); std::string_view type = ParseWord(str, index); ParseWhitespace(str, index); - if (str[index] == '{') ParseUniformBuffer(str, index, shaderBinding); + if (str[index] == '{') + ParseUniformBuffer(str, index, shaderBinding); ParseWhitespace(str, index); std::string_view name = ParseWord(str, index); shaderBinding.name = name; @@ -109,11 +112,10 @@ namespace Copium std::string_view ShaderReflector::ParseWord(const std::string& str, int& index) { int start = index; - while (((str[index] >= 'a' && str[index] < 'z') || - (str[index] >= 'A' && str[index] < 'Z') || + while (((str[index] >= 'a' && str[index] < 'z') || (str[index] >= 'A' && str[index] < 'Z') || (str[index] >= '0' && str[index] <= '9')) || - str[index] == '_' && - index < str.size()) index++; + str[index] == '_' && index < str.size()) + index++; return std::string_view(&str[start], index - start); } @@ -125,7 +127,7 @@ namespace Copium { std::string_view type = ParseWord(str, index); ParseWhitespace(str, index); - std::string_view name = ParseWord(str, index); // uniform name + std::string_view name = ParseWord(str, index); // uniform name if (type == "mat3") binding.uniforms.emplace_back(UniformType::Mat3, std::string(name)); else if (type == "mat4") @@ -143,9 +145,10 @@ namespace Copium else CP_ABORT("Unsupported uniform type=%s", std::string(type).c_str()); ParseWhitespace(str, index); - index++; // ";" + index++; // ";" ParseWhitespace(str, index); } - if (index < str.size()) index++; // go past "}" + if (index < str.size()) + index++; // go past "}" } } \ No newline at end of file diff --git a/CopiumEngine/src/copium/pipeline/ShaderReflector.h b/CopiumEngine/src/copium/pipeline/ShaderReflector.h index efa1f2e..18ae31f 100644 --- a/CopiumEngine/src/copium/pipeline/ShaderReflector.h +++ b/CopiumEngine/src/copium/pipeline/ShaderReflector.h @@ -1,16 +1,17 @@ #pragma once -#include "copium/pipeline/ShaderBinding.h" - #include #include +#include "copium/pipeline/ShaderBinding.h" + namespace Copium { class ShaderReflector { public: std::set bindings; + public: ShaderReflector(const std::string& vertexGlslFile, const std::string& fragmentGlslFile); diff --git a/CopiumEngine/src/copium/pipeline/VertexDescriptor.cpp b/CopiumEngine/src/copium/pipeline/VertexDescriptor.cpp index 774842d..e336273 100644 --- a/CopiumEngine/src/copium/pipeline/VertexDescriptor.cpp +++ b/CopiumEngine/src/copium/pipeline/VertexDescriptor.cpp @@ -4,9 +4,11 @@ namespace Copium { - void VertexDescriptor::AddAttribute(uint32_t binding, uint32_t location, VkFormat format, uint32_t offset, uint32_t size) + void VertexDescriptor::AddAttribute( + uint32_t binding, uint32_t location, VkFormat format, uint32_t offset, uint32_t size) { - CP_ASSERT(binding <= bindings.size(), "Attribute binding must less than or be equal to the amount of current bindings"); + CP_ASSERT(binding <= bindings.size(), + "Attribute binding must less than or be equal to the amount of current bindings"); if (binding == bindings.size()) AddLayout(binding, size); diff --git a/CopiumEngine/src/copium/renderer/Batch.cpp b/CopiumEngine/src/copium/renderer/Batch.cpp index 04b2ab9..aa4ca29 100644 --- a/CopiumEngine/src/copium/renderer/Batch.cpp +++ b/CopiumEngine/src/copium/renderer/Batch.cpp @@ -7,9 +7,11 @@ namespace Copium { Batch::Batch(AssetRef& pipeline, int vertexCount, const std::vector samplers) : vertexBuffer{RendererVertex::GetDescriptor(), vertexCount}, - descriptorPool{pipeline.GetAsset().GetDescriptorSetCount() * SwapChain::MAX_FRAMES_IN_FLIGHT, 32 * SwapChain::MAX_FRAMES_IN_FLIGHT}, + descriptorPool{pipeline.GetAsset().GetDescriptorSetCount() * SwapChain::MAX_FRAMES_IN_FLIGHT, + 32 * SwapChain::MAX_FRAMES_IN_FLIGHT}, descriptorSet{pipeline.GetAsset().CreateDescriptorSet(descriptorPool, 0)} - {} + { + } RendererVertexBuffer& Batch::GetVertexBuffer() { diff --git a/CopiumEngine/src/copium/renderer/Batch.h b/CopiumEngine/src/copium/renderer/Batch.h index 3f8ff44..dba4036 100644 --- a/CopiumEngine/src/copium/renderer/Batch.h +++ b/CopiumEngine/src/copium/renderer/Batch.h @@ -11,10 +11,12 @@ namespace Copium class Batch { CP_DELETE_COPY_AND_MOVE_CTOR(Batch); + private: RendererVertexBuffer vertexBuffer; DescriptorPool descriptorPool; std::unique_ptr descriptorSet; + public: Batch(AssetRef& pipeline, int vertexCount, const std::vector samplers); RendererVertexBuffer& GetVertexBuffer(); diff --git a/CopiumEngine/src/copium/renderer/LineRenderer.h b/CopiumEngine/src/copium/renderer/LineRenderer.h index 3a80925..9646b12 100644 --- a/CopiumEngine/src/copium/renderer/LineRenderer.h +++ b/CopiumEngine/src/copium/renderer/LineRenderer.h @@ -1,18 +1,19 @@ #pragma once +#include + #include "copium/buffer/CommandBuffer.h" #include "copium/buffer/IndexBuffer.h" #include "copium/buffer/RendererVertexBuffer.h" #include "copium/pipeline/Pipeline.h" #include "copium/util/Common.h" -#include - namespace Copium { class LineRenderer { CP_DELETE_COPY_AND_MOVE_CTOR(LineRenderer); + public: LineRenderer(const AssetRef& pipeline); ~LineRenderer(); @@ -36,6 +37,7 @@ namespace Copium CommandBuffer* currentCommandBuffer; int lineCount; void* mappedVertexBuffer; + private: void InitializeIndexBuffer(); diff --git a/CopiumEngine/src/copium/renderer/LineVertex.h b/CopiumEngine/src/copium/renderer/LineVertex.h index 7f451bf..8a291ac 100644 --- a/CopiumEngine/src/copium/renderer/LineVertex.h +++ b/CopiumEngine/src/copium/renderer/LineVertex.h @@ -1,9 +1,9 @@ #pragma once -#include "copium/pipeline/VertexDescriptor.h" - #include +#include "copium/pipeline/VertexDescriptor.h" + namespace Copium { struct LineVertex diff --git a/CopiumEngine/src/copium/renderer/Renderer.cpp b/CopiumEngine/src/copium/renderer/Renderer.cpp index 7d5c534..d066756 100644 --- a/CopiumEngine/src/copium/renderer/Renderer.cpp +++ b/CopiumEngine/src/copium/renderer/Renderer.cpp @@ -28,23 +28,35 @@ namespace Copium AddVertex(glm::vec2{pos.x + size.x, pos.y}, color, -1, glm::vec2{0, 0}, RendererVertex::TYPE_QUAD); } - - void Renderer::Quad(const glm::vec2& pos, const glm::vec2& size, const Sampler& sampler, const glm::vec2& texCoord1, const glm::vec2& texCoord2) + void Renderer::Quad(const glm::vec2& pos, + const glm::vec2& size, + const Sampler& sampler, + const glm::vec2& texCoord1, + const glm::vec2& texCoord2) { AllocateQuad(); int texIndex = AllocateSampler(sampler); - AddVertex(pos, glm::vec3{1,1,1}, texIndex, texCoord1, RendererVertex::TYPE_QUAD); - AddVertex(glm::vec2{pos.x, pos.y + size.y}, glm::vec3{1, 1, 1}, texIndex, glm::vec2{texCoord1.x, texCoord2.y}, RendererVertex::TYPE_QUAD); - AddVertex(pos + size, glm::vec3{1,1,1}, texIndex, texCoord2, RendererVertex::TYPE_QUAD); - AddVertex(glm::vec2{pos.x + size.x, pos.y}, glm::vec3{1, 1, 1}, texIndex, glm::vec2{texCoord2.x, texCoord1.y}, RendererVertex::TYPE_QUAD); + AddVertex(pos, glm::vec3{1, 1, 1}, texIndex, texCoord1, RendererVertex::TYPE_QUAD); + AddVertex(glm::vec2{pos.x, pos.y + size.y}, + glm::vec3{1, 1, 1}, + texIndex, + glm::vec2{texCoord1.x, texCoord2.y}, + RendererVertex::TYPE_QUAD); + AddVertex(pos + size, glm::vec3{1, 1, 1}, texIndex, texCoord2, RendererVertex::TYPE_QUAD); + AddVertex(glm::vec2{pos.x + size.x, pos.y}, + glm::vec3{1, 1, 1}, + texIndex, + glm::vec2{texCoord2.x, texCoord1.y}, + RendererVertex::TYPE_QUAD); } - glm::vec2 Renderer::Text(const std::string& str, const glm::vec2& position, const Font& font, float size, const glm::vec3& color) + glm::vec2 Renderer::Text( + const std::string& str, const glm::vec2& position, const Font& font, float size, const glm::vec3& color) { glm::vec2 offset = position; for (char c : str) { - if(c == ' ') + if (c == ' ') { const Glyph& glyph = font.GetGlyph(c); offset.x += glyph.advance * size; @@ -65,23 +77,40 @@ namespace Copium const Glyph& glyph = font.GetGlyph(c); AllocateQuad(); int texIndex = AllocateSampler(font); - AddVertex(offset + glm::vec2{glyph.boundingBox.l * size, glyph.boundingBox.b * size}, color, texIndex, glyph.texCoordBoundingBox.AsLb(), RendererVertex::TYPE_TEXT); - AddVertex(offset + glm::vec2{glyph.boundingBox.l * size, glyph.boundingBox.t * size}, color, texIndex, glm::vec2{glyph.texCoordBoundingBox.l, glyph.texCoordBoundingBox.t}, RendererVertex::TYPE_TEXT); - AddVertex(offset + glm::vec2{glyph.boundingBox.r * size, glyph.boundingBox.t * size}, color, texIndex, glyph.texCoordBoundingBox.AsRt(), RendererVertex::TYPE_TEXT); - AddVertex(offset + glm::vec2{glyph.boundingBox.r * size, glyph.boundingBox.b * size}, color, texIndex, glm::vec2{glyph.texCoordBoundingBox.r, glyph.texCoordBoundingBox.b}, RendererVertex::TYPE_TEXT); + AddVertex(offset + glm::vec2{glyph.boundingBox.l * size, glyph.boundingBox.b * size}, + color, + texIndex, + glyph.texCoordBoundingBox.AsLb(), + RendererVertex::TYPE_TEXT); + AddVertex(offset + glm::vec2{glyph.boundingBox.l * size, glyph.boundingBox.t * size}, + color, + texIndex, + glm::vec2{glyph.texCoordBoundingBox.l, glyph.texCoordBoundingBox.t}, + RendererVertex::TYPE_TEXT); + AddVertex(offset + glm::vec2{glyph.boundingBox.r * size, glyph.boundingBox.t * size}, + color, + texIndex, + glyph.texCoordBoundingBox.AsRt(), + RendererVertex::TYPE_TEXT); + AddVertex(offset + glm::vec2{glyph.boundingBox.r * size, glyph.boundingBox.b * size}, + color, + texIndex, + glm::vec2{glyph.texCoordBoundingBox.r, glyph.texCoordBoundingBox.b}, + RendererVertex::TYPE_TEXT); offset.x += glyph.advance * size; } return offset; } - void Renderer::AddVertex(const glm::vec2& position, const glm::vec3& color, int texindex, const glm::vec2& texCoord, int type) + void Renderer::AddVertex( + const glm::vec2& position, const glm::vec3& color, int texindex, const glm::vec2& texCoord, int type) { RendererVertex* vertex = (RendererVertex*)mappedVertexBuffer; vertex->position = position; vertex->color = color; vertex->texCoord = texCoord; vertex->texIndex = texindex; - vertex->type = type; + vertex->type = type; mappedVertexBuffer = (RendererVertex*)mappedVertexBuffer + 1; } @@ -177,7 +206,8 @@ namespace Copium batches.emplace_back(std::make_unique(pipeline, MAX_NUM_VERTICES, samplers)); } batches[batchIndex]->GetDescriptorSet().SetSamplersDynamic(samplers, 0); - mappedVertexBuffer = (char*)batches[batchIndex]->GetVertexBuffer().Map() + batches[batchIndex]->GetVertexBuffer().GetPosition(Vulkan::GetSwapChain().GetFlightIndex()); + mappedVertexBuffer = (char*)batches[batchIndex]->GetVertexBuffer().Map() + + batches[batchIndex]->GetVertexBuffer().GetPosition(Vulkan::GetSwapChain().GetFlightIndex()); quadCount = 0; textureCount = 0; } diff --git a/CopiumEngine/src/copium/renderer/Renderer.h b/CopiumEngine/src/copium/renderer/Renderer.h index 480dc3a..f347feb 100644 --- a/CopiumEngine/src/copium/renderer/Renderer.h +++ b/CopiumEngine/src/copium/renderer/Renderer.h @@ -1,5 +1,8 @@ #pragma once +#include +#include + #include "copium/asset/AssetRef.h" #include "copium/buffer/CommandBuffer.h" #include "copium/buffer/IndexBuffer.h" @@ -8,14 +11,12 @@ #include "copium/sampler/Font.h" #include "copium/util/Common.h" -#include -#include - namespace Copium { class Renderer final { CP_DELETE_COPY_AND_MOVE_CTOR(Renderer); + private: IndexBuffer ibo; AssetRef pipeline; @@ -29,19 +30,29 @@ namespace Copium int textureCount; void* mappedVertexBuffer; std::map> descriptorSets; + public: Renderer(const AssetRef& pipeline); void Quad(const glm::vec2& pos, const glm::vec2& size, const glm::vec3& color = glm::vec3{1, 1, 1}); - void Quad(const glm::vec2& pos, const glm::vec2& size, const Sampler& sampler, const glm::vec2& texCoord1 = glm::vec2{0, 0}, const glm::vec2& texCoord2 = glm::vec2{1, 1}); + void Quad(const glm::vec2& pos, + const glm::vec2& size, + const Sampler& sampler, + const glm::vec2& texCoord1 = glm::vec2{0, 0}, + const glm::vec2& texCoord2 = glm::vec2{1, 1}); // Returns the position where the text rendering ended - glm::vec2 Text(const std::string& str, const glm::vec2& position, const Font& font, float size, const glm::vec3& color = glm::vec3(1, 1, 1)); + glm::vec2 Text(const std::string& str, + const glm::vec2& position, + const Font& font, + float size, + const glm::vec3& color = glm::vec3(1, 1, 1)); void Begin(CommandBuffer& commandBuffer); void End(); Pipeline& GetGraphicsPipeline(); void SetDescriptorSet(const DescriptorSet& descriptorSet); + private: void InitializeIndexBuffer(); @@ -50,6 +61,7 @@ namespace Copium void Flush(); void NextBatch(); - void AddVertex(const glm::vec2& position, const glm::vec3& color, int texindex, const glm::vec2& texCoord, int type); + void AddVertex( + const glm::vec2& position, const glm::vec3& color, int texindex, const glm::vec2& texCoord, int type); }; } diff --git a/CopiumEngine/src/copium/renderer/RendererVertex.h b/CopiumEngine/src/copium/renderer/RendererVertex.h index 2ed2ff7..36454d9 100644 --- a/CopiumEngine/src/copium/renderer/RendererVertex.h +++ b/CopiumEngine/src/copium/renderer/RendererVertex.h @@ -1,9 +1,9 @@ #pragma once -#include "copium/pipeline/VertexDescriptor.h" - #include +#include "copium/pipeline/VertexDescriptor.h" + namespace Copium { struct RendererVertex @@ -14,7 +14,7 @@ namespace Copium glm::vec3 color; glm::vec2 texCoord; int8_t texIndex; - int8_t type = TYPE_QUAD; // TODO: Should maybe have different Renderers for quad vs text instead of a flag + int8_t type = TYPE_QUAD; // TODO: Should maybe have different Renderers for quad vs text instead of a flag static VertexDescriptor GetDescriptor(); }; diff --git a/CopiumEngine/src/copium/sampler/ColorAttachment.cpp b/CopiumEngine/src/copium/sampler/ColorAttachment.cpp index 00163ed..d539a8b 100644 --- a/CopiumEngine/src/copium/sampler/ColorAttachment.cpp +++ b/CopiumEngine/src/copium/sampler/ColorAttachment.cpp @@ -42,14 +42,16 @@ namespace Copium std::vector imagesCpy = images; std::vector imageMemoriesCpy = imageMemories; std::vector imageViewsCpy = imageViews; - Vulkan::GetDevice().QueueIdleCommand([imagesCpy, imageMemoriesCpy, imageViewsCpy]() { - for (auto&& image : imagesCpy) - vkDestroyImage(Vulkan::GetDevice(), image, nullptr); - for (auto&& imageMemory : imageMemoriesCpy) - vkFreeMemory(Vulkan::GetDevice(), imageMemory, nullptr); - for (auto&& imageView : imageViewsCpy) - vkDestroyImageView(Vulkan::GetDevice(), imageView, nullptr); - }); + Vulkan::GetDevice().QueueIdleCommand( + [imagesCpy, imageMemoriesCpy, imageViewsCpy]() + { + for (auto&& image : imagesCpy) + vkDestroyImage(Vulkan::GetDevice(), image, nullptr); + for (auto&& imageMemory : imageMemoriesCpy) + vkFreeMemory(Vulkan::GetDevice(), imageMemory, nullptr); + for (auto&& imageView : imageViewsCpy) + vkDestroyImageView(Vulkan::GetDevice(), imageView, nullptr); + }); } void ColorAttachment::Resize(int width, int height) @@ -99,7 +101,14 @@ namespace Copium imageMemories.resize(SwapChain::MAX_FRAMES_IN_FLIGHT); for (size_t i = 0; i < images.size(); i++) { - Image::InitializeImage(width, height, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &images[i], &imageMemories[i]); + Image::InitializeImage(width, + height, + VK_FORMAT_R8G8B8A8_UNORM, + VK_IMAGE_TILING_OPTIMAL, + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, + &images[i], + &imageMemories[i]); imageViews[i] = Image::InitializeImageView(images[i], VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT); } } diff --git a/CopiumEngine/src/copium/sampler/ColorAttachment.h b/CopiumEngine/src/copium/sampler/ColorAttachment.h index ebe6bdb..c50e47a 100644 --- a/CopiumEngine/src/copium/sampler/ColorAttachment.h +++ b/CopiumEngine/src/copium/sampler/ColorAttachment.h @@ -1,21 +1,23 @@ #pragma once +#include + #include "copium/sampler/Sampler.h" #include "copium/util/Common.h" -#include - namespace Copium { class ColorAttachment final : public Sampler { CP_DELETE_COPY_AND_MOVE_CTOR(ColorAttachment); + private: std::vector images; std::vector imageMemories; std::vector imageViews; int width; int height; + public: ColorAttachment(const MetaFile& metaFile); ColorAttachment(int width, int height, const SamplerCreator& samplerCreator); diff --git a/CopiumEngine/src/copium/sampler/DepthAttachment.cpp b/CopiumEngine/src/copium/sampler/DepthAttachment.cpp index ff3ad7e..35981ba 100644 --- a/CopiumEngine/src/copium/sampler/DepthAttachment.cpp +++ b/CopiumEngine/src/copium/sampler/DepthAttachment.cpp @@ -16,14 +16,15 @@ namespace Copium VkImage imageCpy = image; VkDeviceMemory imageMemoryCpy = imageMemory; VkImageView imageViewCpy = imageView; - Vulkan::GetDevice().QueueIdleCommand([imageCpy, imageMemoryCpy, imageViewCpy]() { - vkDestroyImage(Vulkan::GetDevice(), imageCpy, nullptr); - vkFreeMemory(Vulkan::GetDevice(), imageMemoryCpy, nullptr); - vkDestroyImageView(Vulkan::GetDevice(), imageViewCpy, nullptr); - }); + Vulkan::GetDevice().QueueIdleCommand( + [imageCpy, imageMemoryCpy, imageViewCpy]() + { + vkDestroyImage(Vulkan::GetDevice(), imageCpy, nullptr); + vkFreeMemory(Vulkan::GetDevice(), imageMemoryCpy, nullptr); + vkDestroyImageView(Vulkan::GetDevice(), imageViewCpy, nullptr); + }); } - void DepthAttachment::Resize(int width, int height) { vkDestroyImage(Vulkan::GetDevice(), image, nullptr); @@ -49,7 +50,14 @@ namespace Copium void DepthAttachment::InitializeDepthAttachment(int width, int height) { VkFormat depthFormat = Image::SelectDepthFormat(); - Image::InitializeImage(width, height, depthFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &image, &imageMemory); + Image::InitializeImage(width, + height, + depthFormat, + VK_IMAGE_TILING_OPTIMAL, + VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, + &image, + &imageMemory); imageView = Image::InitializeImageView(image, depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT); } } \ No newline at end of file diff --git a/CopiumEngine/src/copium/sampler/DepthAttachment.h b/CopiumEngine/src/copium/sampler/DepthAttachment.h index 2595764..c8a2f82 100644 --- a/CopiumEngine/src/copium/sampler/DepthAttachment.h +++ b/CopiumEngine/src/copium/sampler/DepthAttachment.h @@ -1,19 +1,21 @@ #pragma once +#include + #include "copium/sampler/Sampler.h" #include "copium/util/Common.h" -#include - namespace Copium { class DepthAttachment final : public Sampler { CP_DELETE_COPY_AND_MOVE_CTOR(DepthAttachment); + private: VkImage image; VkDeviceMemory imageMemory; VkImageView imageView; + public: DepthAttachment(int width, int height, const SamplerCreator& samplerCreator); ~DepthAttachment() override; diff --git a/CopiumEngine/src/copium/sampler/Font.cpp b/CopiumEngine/src/copium/sampler/Font.cpp index 1ed27fe..c8d3007 100644 --- a/CopiumEngine/src/copium/sampler/Font.cpp +++ b/CopiumEngine/src/copium/sampler/Font.cpp @@ -1,18 +1,18 @@ #include "copium/sampler/Font.h" +#include + #include "copium/buffer/Buffer.h" #include "copium/core/Vulkan.h" #include "copium/sampler/Image.h" -#include - namespace Copium { Font::Font(const MetaFile& metaFile) : Sampler{SamplerCreator{metaFile.GetMetaClass("Font")}} { msdfgen::FreetypeHandle* ft = msdfgen::initializeFreetype(); - CP_ASSERT(ft, "Failed to initialize FreeType"); // TODO: Move to Vulkan singleton class? + CP_ASSERT(ft, "Failed to initialize FreeType"); // TODO: Move to Vulkan singleton class? std::string fontPath = metaFile.GetMetaClass("Font").GetValue("filepath"); msdfgen::FontHandle* font = msdfgen::loadFont(ft, fontPath.c_str()); CP_ASSERT(font, "Failed to initialize font: %s", fontPath.c_str()); @@ -36,7 +36,9 @@ namespace Copium int width = 0, height = 0; packer.getDimensions(width, height); - msdf_atlas::ImmediateAtlasGenerator> generator(width, height); + msdf_atlas:: + ImmediateAtlasGenerator> + generator(width, height); msdf_atlas::GeneratorAttributes attributes; generator.setAttributes(attributes); generator.setThreadCount(4); @@ -78,11 +80,13 @@ namespace Copium VkImage imageCpy = image; VkDeviceMemory imageMemoryCpy = imageMemory; VkImageView imageViewCpy = imageView; - Vulkan::GetDevice().QueueIdleCommand([imageCpy, imageMemoryCpy, imageViewCpy]() { - vkDestroyImage(Vulkan::GetDevice(), imageCpy, nullptr); - vkFreeMemory(Vulkan::GetDevice(), imageMemoryCpy, nullptr); - vkDestroyImageView(Vulkan::GetDevice(), imageViewCpy, nullptr); - }); + Vulkan::GetDevice().QueueIdleCommand( + [imageCpy, imageMemoryCpy, imageViewCpy]() + { + vkDestroyImage(Vulkan::GetDevice(), imageCpy, nullptr); + vkFreeMemory(Vulkan::GetDevice(), imageMemoryCpy, nullptr); + vkDestroyImageView(Vulkan::GetDevice(), imageViewCpy, nullptr); + }); } VkDescriptorImageInfo Font::GetDescriptorImageInfo(int index) const @@ -117,7 +121,7 @@ namespace Copium glm::vec2 offset{0.0f}; for (auto c : str) { - if(c == ' ') + if (c == ' ') { const Glyph& glyph = GetGlyph(c); offset.x += glyph.advance; @@ -153,15 +157,27 @@ namespace Copium void Font::InitializeTextureImageFromData(const uint8_t* rgbaData, int width, int height) { VkDeviceSize bufferSize = width * height * 4; - Buffer stagingBuffer{VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, bufferSize, 1}; + Buffer stagingBuffer{VK_BUFFER_USAGE_TRANSFER_SRC_BIT, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, + bufferSize, + 1}; void* data = stagingBuffer.Map(); memcpy(data, rgbaData, bufferSize); stagingBuffer.Unmap(); - Image::InitializeImage(width, height, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &image, &imageMemory); - Image::TransitionImageLayout(image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + Image::InitializeImage(width, + height, + VK_FORMAT_R8G8B8A8_UNORM, + VK_IMAGE_TILING_OPTIMAL, + VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, + &image, + &imageMemory); + Image::TransitionImageLayout( + image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); Image::CopyBufferToImage(stagingBuffer, image, width, height); - Image::TransitionImageLayout(image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + Image::TransitionImageLayout( + image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); imageView = Image::InitializeImageView(image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT); } } diff --git a/CopiumEngine/src/copium/sampler/Font.h b/CopiumEngine/src/copium/sampler/Font.h index 026648f..a64d688 100644 --- a/CopiumEngine/src/copium/sampler/Font.h +++ b/CopiumEngine/src/copium/sampler/Font.h @@ -1,7 +1,7 @@ #pragma once -#include "copium/sampler/Sampler.h" #include "copium/sampler/Glyph.h" +#include "copium/sampler/Sampler.h" #include "copium/util/BoundingBox.h" namespace Copium @@ -9,6 +9,7 @@ namespace Copium class Font : public Sampler { CP_DELETE_COPY_AND_MOVE_CTOR(Font); + private: VkImage image; VkDeviceMemory imageMemory; @@ -17,6 +18,7 @@ namespace Copium std::map glyphs; float lineHeight; float baseHeight; + public: Font(const MetaFile& metaFile); ~Font() override; diff --git a/CopiumEngine/src/copium/sampler/Image.cpp b/CopiumEngine/src/copium/sampler/Image.cpp index 38717b2..fb366ab 100644 --- a/CopiumEngine/src/copium/sampler/Image.cpp +++ b/CopiumEngine/src/copium/sampler/Image.cpp @@ -5,7 +5,14 @@ namespace Copium { - void Image::InitializeImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage* image, VkDeviceMemory* imageMemory) + void Image::InitializeImage(uint32_t width, + uint32_t height, + VkFormat format, + VkImageTiling tiling, + VkImageUsageFlags usage, + VkMemoryPropertyFlags properties, + VkImage* image, + VkDeviceMemory* imageMemory) { VkImageCreateInfo createInfo{}; createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; @@ -33,7 +40,8 @@ namespace Copium allocateInfo.allocationSize = memoryRequirements.size; allocateInfo.memoryTypeIndex = Vulkan::GetDevice().FindMemoryType(memoryRequirements.memoryTypeBits, properties); - CP_VK_ASSERT(vkAllocateMemory(Vulkan::GetDevice(), &allocateInfo, nullptr, imageMemory), "Failed to initiallizse image memory"); + CP_VK_ASSERT(vkAllocateMemory(Vulkan::GetDevice(), &allocateInfo, nullptr, imageMemory), + "Failed to initiallizse image memory"); vkBindImageMemory(Vulkan::GetDevice(), *image, *imageMemory, 0); } @@ -55,7 +63,8 @@ namespace Copium createInfo.subresourceRange.levelCount = 1; createInfo.subresourceRange.baseArrayLayer = 0; createInfo.subresourceRange.layerCount = 1; - CP_VK_ASSERT(vkCreateImageView(Vulkan::GetDevice(), &createInfo, nullptr, &imageView), "Failed to initialize image view"); + CP_VK_ASSERT(vkCreateImageView(Vulkan::GetDevice(), &createInfo, nullptr, &imageView), + "Failed to initialize image view"); return imageView; } @@ -80,39 +89,47 @@ namespace Copium VkPipelineStageFlags srcStage; VkPipelineStageFlags dstStage; - if (newLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) { + if (newLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) + { barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; - if (HasStencilComponent(format)) { + if (HasStencilComponent(format)) + { barrier.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT; } } - else { + else + { barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; } - if (oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && newLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { + if (oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && newLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) + { barrier.srcAccessMask = 0; barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; srcStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT; } - else if (oldLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL && newLayout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) { + else if (oldLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL && newLayout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) + { barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; srcStage = VK_PIPELINE_STAGE_TRANSFER_BIT; dstStage = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; } - else if (oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && newLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) { + else if (oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && newLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) + { barrier.srcAccessMask = 0; - barrier.dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; + barrier.dstAccessMask = + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; srcStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; dstStage = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT; } - else if (oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && newLayout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) { + else if (oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && newLayout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) + { barrier.srcAccessMask = 0; barrier.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; @@ -147,10 +164,11 @@ namespace Copium vkCmdCopyBufferToImage(commandBuffer, buffer, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); } - VkFormat Image::SelectDepthFormat() { - return SelectSupportedFormat({VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT}, VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT); + return SelectSupportedFormat({VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT}, + VK_IMAGE_TILING_OPTIMAL, + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT); } bool Image::HasStencilComponent(VkFormat format) @@ -158,7 +176,9 @@ namespace Copium return format == VK_FORMAT_D32_SFLOAT_S8_UINT || format == VK_FORMAT_D24_UNORM_S8_UINT; } - VkFormat Image::SelectSupportedFormat(const std::vector& candidates, VkImageTiling tiling, VkFormatFeatureFlags features) + VkFormat Image::SelectSupportedFormat(const std::vector& candidates, + VkImageTiling tiling, + VkFormatFeatureFlags features) { for (VkFormat format : candidates) { diff --git a/CopiumEngine/src/copium/sampler/Image.h b/CopiumEngine/src/copium/sampler/Image.h index 9eda313..00877fc 100644 --- a/CopiumEngine/src/copium/sampler/Image.h +++ b/CopiumEngine/src/copium/sampler/Image.h @@ -1,17 +1,25 @@ #pragma once +#include + #include "copium/buffer/Buffer.h" #include "copium/util/Common.h" -#include - namespace Copium { class Image { - CP_STATIC_CLASS(Image); + CP_STATIC_CLASS(Image); + public: - static void InitializeImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage* image, VkDeviceMemory* imageMemory); + static void InitializeImage(uint32_t width, + uint32_t height, + VkFormat format, + VkImageTiling tiling, + VkImageUsageFlags usage, + VkMemoryPropertyFlags properties, + VkImage* image, + VkDeviceMemory* imageMemory); static VkImageView InitializeImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags); static void TransitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout); static void CopyBufferToImage(const Buffer& buffer, VkImage image, uint32_t width, uint32_t height); @@ -19,6 +27,8 @@ namespace Copium private: static bool HasStencilComponent(VkFormat format); - static VkFormat SelectSupportedFormat(const std::vector& candidates, VkImageTiling tiling, VkFormatFeatureFlags features); + static VkFormat SelectSupportedFormat(const std::vector& candidates, + VkImageTiling tiling, + VkFormatFeatureFlags features); }; } \ No newline at end of file diff --git a/CopiumEngine/src/copium/sampler/Sampler.cpp b/CopiumEngine/src/copium/sampler/Sampler.cpp index 0c01d5a..d26a3e3 100644 --- a/CopiumEngine/src/copium/sampler/Sampler.cpp +++ b/CopiumEngine/src/copium/sampler/Sampler.cpp @@ -12,9 +12,8 @@ namespace Copium Sampler::~Sampler() { VkSampler samplerCpy = sampler; - Vulkan::GetDevice().QueueIdleCommand([samplerCpy]() { - vkDestroySampler(Vulkan::GetDevice(), samplerCpy, nullptr); - }); + Vulkan::GetDevice().QueueIdleCommand([samplerCpy]() + { vkDestroySampler(Vulkan::GetDevice(), samplerCpy, nullptr); }); } void Sampler::InitializeSampler(const SamplerCreator& samplerCreator) @@ -39,7 +38,8 @@ namespace Copium createInfo.minLod = 0.0f; createInfo.maxLod = 0.0f; - CP_VK_ASSERT(vkCreateSampler(Vulkan::GetDevice(), &createInfo, nullptr, &sampler), "Failed to initialize texture sampler"); + CP_VK_ASSERT(vkCreateSampler(Vulkan::GetDevice(), &createInfo, nullptr, &sampler), + "Failed to initialize texture sampler"); } Sampler::operator VkSampler() const diff --git a/CopiumEngine/src/copium/sampler/Sampler.h b/CopiumEngine/src/copium/sampler/Sampler.h index 3dca60c..886b8b3 100644 --- a/CopiumEngine/src/copium/sampler/Sampler.h +++ b/CopiumEngine/src/copium/sampler/Sampler.h @@ -1,18 +1,20 @@ #pragma once +#include + #include "copium/asset/Asset.h" #include "copium/sampler/SamplerCreator.h" #include "copium/util/Common.h" -#include - namespace Copium { class Sampler : public Asset { CP_DELETE_COPY_AND_MOVE_CTOR(Sampler); + protected: VkSampler sampler; + public: // Sampler(); Sampler(const SamplerCreator& samplerCreator); @@ -20,6 +22,7 @@ namespace Copium virtual VkDescriptorImageInfo GetDescriptorImageInfo(int index) const = 0; operator VkSampler() const; + private: void InitializeSampler(const SamplerCreator& samplerCreator); }; diff --git a/CopiumEngine/src/copium/sampler/SamplerCreator.h b/CopiumEngine/src/copium/sampler/SamplerCreator.h index d4fc187..afc0ae0 100644 --- a/CopiumEngine/src/copium/sampler/SamplerCreator.h +++ b/CopiumEngine/src/copium/sampler/SamplerCreator.h @@ -1,14 +1,15 @@ #pragma once -#include "copium/util/MetaFile.h" - #include +#include "copium/util/MetaFile.h" + namespace Copium { class SamplerCreator { friend class Sampler; + private: VkFilter minFilter{VK_FILTER_LINEAR}; VkFilter magFilter{VK_FILTER_LINEAR}; diff --git a/CopiumEngine/src/copium/sampler/Texture2D.cpp b/CopiumEngine/src/copium/sampler/Texture2D.cpp index a200174..1df604b 100644 --- a/CopiumEngine/src/copium/sampler/Texture2D.cpp +++ b/CopiumEngine/src/copium/sampler/Texture2D.cpp @@ -16,10 +16,18 @@ namespace Copium InitializeTextureImageFromFile(filepath); } - Texture2D::Texture2D(const std::vector& rgbaData, int width, int height, const SamplerCreator& samplerCreator) - : Sampler{samplerCreator}, width{width}, height{height} + Texture2D::Texture2D(const std::vector& rgbaData, + int width, + int height, + const SamplerCreator& samplerCreator) + : Sampler{samplerCreator}, + width{width}, + height{height} { - CP_ASSERT(rgbaData.size() == width * height * 4, "rgbaData has invalid size, should be equal to width * height * 4 (%d) actually is %d", width * height * 4, rgbaData.size()); + CP_ASSERT(rgbaData.size() == width * height * 4, + "rgbaData has invalid size, should be equal to width * height * 4 (%d) actually is %d", + width * height * 4, + rgbaData.size()); InitializeTextureImageFromData(rgbaData.data(), width, height); } @@ -28,11 +36,13 @@ namespace Copium VkImage imageCpy = image; VkDeviceMemory imageMemoryCpy = imageMemory; VkImageView imageViewCpy = imageView; - Vulkan::GetDevice().QueueIdleCommand([imageCpy, imageMemoryCpy, imageViewCpy]() { - vkDestroyImage(Vulkan::GetDevice(), imageCpy, nullptr); - vkFreeMemory(Vulkan::GetDevice(), imageMemoryCpy, nullptr); - vkDestroyImageView(Vulkan::GetDevice(), imageViewCpy, nullptr); - }); + Vulkan::GetDevice().QueueIdleCommand( + [imageCpy, imageMemoryCpy, imageViewCpy]() + { + vkDestroyImage(Vulkan::GetDevice(), imageCpy, nullptr); + vkFreeMemory(Vulkan::GetDevice(), imageMemoryCpy, nullptr); + vkDestroyImageView(Vulkan::GetDevice(), imageViewCpy, nullptr); + }); } VkDescriptorImageInfo Texture2D::GetDescriptorImageInfo(int index) const @@ -45,15 +55,15 @@ namespace Copium return imageInfo; } - int Texture2D::GetWidth() const - { - return width; - } + int Texture2D::GetWidth() const + { + return width; + } - int Texture2D::GetHeight() const - { - return height; - } + int Texture2D::GetHeight() const + { + return height; + } void Texture2D::InitializeTextureImageFromFile(const std::string& filename) { @@ -75,15 +85,27 @@ namespace Copium void Texture2D::InitializeTextureImageFromData(const uint8_t* rgbaData, int width, int height) { VkDeviceSize bufferSize = width * height * 4; - Buffer stagingBuffer{VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, bufferSize, 1}; + Buffer stagingBuffer{VK_BUFFER_USAGE_TRANSFER_SRC_BIT, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, + bufferSize, + 1}; void* data = stagingBuffer.Map(); memcpy(data, rgbaData, bufferSize); stagingBuffer.Unmap(); - Image::InitializeImage(width, height, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &image, &imageMemory); - Image::TransitionImageLayout(image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + Image::InitializeImage(width, + height, + VK_FORMAT_R8G8B8A8_UNORM, + VK_IMAGE_TILING_OPTIMAL, + VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, + &image, + &imageMemory); + Image::TransitionImageLayout( + image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); Image::CopyBufferToImage(stagingBuffer, image, width, height); - Image::TransitionImageLayout(image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + Image::TransitionImageLayout( + image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); imageView = Image::InitializeImageView(image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT); } } diff --git a/CopiumEngine/src/copium/sampler/Texture2D.h b/CopiumEngine/src/copium/sampler/Texture2D.h index 7710be0..d635dc8 100644 --- a/CopiumEngine/src/copium/sampler/Texture2D.h +++ b/CopiumEngine/src/copium/sampler/Texture2D.h @@ -8,6 +8,7 @@ namespace Copium class Texture2D final : public Sampler { CP_DELETE_COPY_AND_MOVE_CTOR(Texture2D); + private: VkImage image; VkDeviceMemory imageMemory; @@ -15,6 +16,7 @@ namespace Copium int width; int height; + public: Texture2D(const MetaFile& metaFile); Texture2D(const std::vector& rgbaData, int width, int height, const SamplerCreator& samplerCreator); diff --git a/CopiumEngine/src/copium/util/BoundingBox.cpp b/CopiumEngine/src/copium/util/BoundingBox.cpp index b6b9e16..fe6625d 100644 --- a/CopiumEngine/src/copium/util/BoundingBox.cpp +++ b/CopiumEngine/src/copium/util/BoundingBox.cpp @@ -3,20 +3,36 @@ namespace Copium { BoundingBox::BoundingBox() - : l{0.0f}, b{0.0f}, r{0.0f}, t{0.0f} - {} + : l{0.0f}, + b{0.0f}, + r{0.0f}, + t{0.0f} + { + } BoundingBox::BoundingBox(float all) - : l{all}, b{all}, r{all}, t{all} - {} + : l{all}, + b{all}, + r{all}, + t{all} + { + } BoundingBox::BoundingBox(float l, float b, float r, float t) - : l{l}, b{b}, r{r}, t{t} - {} + : l{l}, + b{b}, + r{r}, + t{t} + { + } BoundingBox::BoundingBox(glm::vec2 lb, glm::vec2 rt) - : l{lb.x}, b{lb.y}, r{rt.x}, t{rt.y} - {} + : l{lb.x}, + b{lb.y}, + r{rt.x}, + t{rt.y} + { + } glm::vec2 BoundingBox::GetSize() const { diff --git a/CopiumEngine/src/copium/util/Common.h b/CopiumEngine/src/copium/util/Common.h index b7c7897..62f7cea 100644 --- a/CopiumEngine/src/copium/util/Common.h +++ b/CopiumEngine/src/copium/util/Common.h @@ -1,66 +1,79 @@ #pragma once +#include +#include +#include + #include "copium/util/RuntimeException.h" #include "copium/util/VulkanException.h" -#include -#include -#include - -#define CP_TERM_RED "\x1B[31m" -#define CP_TERM_GREEN "\x1B[32m" +#define CP_TERM_RED "\x1B[31m" +#define CP_TERM_GREEN "\x1B[32m" #define CP_TERM_YELLOW "\x1B[33m" -#define CP_TERM_GRAY "\x1B[90m" -#define CP_TERM_CLEAR "\033[0m" +#define CP_TERM_GRAY "\x1B[90m" +#define CP_TERM_CLEAR "\033[0m" -#define CP_DEBUG(...) std::cout << CP_TERM_GRAY << "[DBG] " << __func__ << " : " << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR << std::endl -#define CP_INFO(...) std::cout << "[INF] " << __func__ << " : " << Copium::String::Format(__VA_ARGS__) << std::endl -#define CP_WARN(...) std::cout << CP_TERM_YELLOW << "[WRN] " << __func__ << " : " << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR << std::endl -#define CP_ERR(...) std::cout << CP_TERM_RED << "[ERR] " << __func__ << " : " << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR << std::endl +#define CP_DEBUG(...) \ + std::cout << CP_TERM_GRAY << "[DBG] " << __func__ << " : " << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR \ + << std::endl +#define CP_INFO(...) std::cout << "[INF] " << __func__ << " : " << Copium::String::Format(__VA_ARGS__) << std::endl +#define CP_WARN(...) \ + std::cout << CP_TERM_YELLOW << "[WRN] " << __func__ << " : " << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR \ + << std::endl +#define CP_ERR(...) \ + std::cout << CP_TERM_RED << "[ERR] " << __func__ << " : " << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR \ + << std::endl // Continue traces, will not print the [XXX] tag before the log -#define CP_DEBUG_CONT(...) std::cout << CP_TERM_GRAY << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR << std::endl -#define CP_INFO_CONT(...) std::cout << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(__VA_ARGS__) << std::endl -#define CP_WARN_CONT(...) std::cout << CP_TERM_YELLOW << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR << std::endl -#define CP_ERR_CONT(...) std::cout << CP_TERM_RED << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR << std::endl +#define CP_DEBUG_CONT(...) \ + std::cout << CP_TERM_GRAY << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " \ + << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR << std::endl +#define CP_INFO_CONT(...) \ + std::cout << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " \ + << Copium::String::Format(__VA_ARGS__) << std::endl +#define CP_WARN_CONT(...) \ + std::cout << CP_TERM_YELLOW << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " \ + << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR << std::endl +#define CP_ERR_CONT(...) \ + std::cout << CP_TERM_RED << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " \ + << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR << std::endl -#define CP_ABORT(...) \ - do \ - { \ - CP_ERR("Aborted at %s:%d", __FILE__, __LINE__); \ - CP_ERR_CONT(__VA_ARGS__); \ +#define CP_ABORT(...) \ + do \ + { \ + CP_ERR("Aborted at %s:%d", __FILE__, __LINE__); \ + CP_ERR_CONT(__VA_ARGS__); \ throw Copium::RuntimeException(Copium::String::Format(__VA_ARGS__)); \ - } while(false) -#define CP_ASSERT(Function, ...) \ - do \ - { \ - if(!(Function)) \ - { \ - CP_ERR("Assertion failed at %s:%d", __FILE__, __LINE__); \ + } while (false) +#define CP_ASSERT(Function, ...) \ + do \ + { \ + if (!(Function)) \ + { \ + CP_ERR("Assertion failed at %s:%d", __FILE__, __LINE__); \ CP_ERR_CONT("%s : %s", #Function, Copium::String::Format(__VA_ARGS__).c_str()); \ - throw Copium::RuntimeException(Copium::String::Format(__VA_ARGS__)); \ - } \ - } while(false) -#define CP_VK_ASSERT(Function, ...) \ - do \ - { \ - if(Function != VK_SUCCESS) \ - { \ - CP_ERR("Assertion failed at %s:%d", __FILE__, __LINE__); \ + throw Copium::RuntimeException(Copium::String::Format(__VA_ARGS__)); \ + } \ + } while (false) +#define CP_VK_ASSERT(Function, ...) \ + do \ + { \ + if (Function != VK_SUCCESS) \ + { \ + CP_ERR("Assertion failed at %s:%d", __FILE__, __LINE__); \ CP_ERR_CONT("%s : %s", #Function, Copium::String::Format(__VA_ARGS__).c_str()); \ - throw Copium::VulkanException(Copium::String::Format(__VA_ARGS__)); \ - } \ - } while(false) + throw Copium::VulkanException(Copium::String::Format(__VA_ARGS__)); \ + } \ + } while (false) #define CP_UNIMPLEMENTED() CP_WARN("%s is unimplemented", __FUNCTION__) #define CP_ABORT_UNIMPLEMENTED() CP_ABORT("%s is unimplemented", __FUNCTION__) -#define CP_STATIC_CLASS(ClassName)\ - ClassName() = delete +#define CP_STATIC_CLASS(ClassName) ClassName() = delete #define CP_DELETE_COPY_AND_MOVE_CTOR(ClassName) \ - ClassName(ClassName&&) = delete; \ - ClassName(const ClassName&) = delete; \ - ClassName& operator=(ClassName&&) = delete; \ + ClassName(ClassName&&) = delete; \ + ClassName(const ClassName&) = delete; \ + ClassName& operator=(ClassName&&) = delete; \ ClassName& operator=(const ClassName&) = delete namespace Copium @@ -68,13 +81,14 @@ namespace Copium class String { CP_STATIC_CLASS(String); + public: static std::string Format(const std::string& format) { return format; } - template + template static std::string Format(const std::string& format, Args... args) { int size = std::snprintf(nullptr, 0, format.c_str(), args...) + 1; diff --git a/CopiumEngine/src/copium/util/Enum.h b/CopiumEngine/src/copium/util/Enum.h index 1b910bc..1069b71 100644 --- a/CopiumEngine/src/copium/util/Enum.h +++ b/CopiumEngine/src/copium/util/Enum.h @@ -6,25 +6,24 @@ #define CP_STRINGIFY(x) #x #define CP_TO_STRING(x) CP_STRINGIFY(x) -#define CP_ENUM_CREATOR(NameSpace, EnumName, EnumList) \ -namespace NameSpace { \ - enum class EnumName \ - { \ - EnumList \ - }; \ - static const std::string& ToString(EnumName enumName) \ - { \ - static std::vector enumNames = Copium::EnumPrinter::GetEnumNames(CP_TO_STRING(#EnumList)); \ - return enumNames[(int)enumName]; \ - } \ - \ - static std::ostream& operator<<(std::ostream& ostream, EnumName enumName) \ - { \ - return ostream << ToString(enumName); \ - } \ -} - - +#define CP_ENUM_CREATOR(NameSpace, EnumName, EnumList) \ + namespace NameSpace \ + { \ + enum class EnumName \ + { \ + EnumList \ + }; \ + static const std::string& ToString(EnumName enumName) \ + { \ + static std::vector enumNames = Copium::EnumPrinter::GetEnumNames(CP_TO_STRING(#EnumList)); \ + return enumNames[(int)enumName]; \ + } \ + \ + static std::ostream& operator<<(std::ostream& ostream, EnumName enumName) \ + { \ + return ostream << ToString(enumName); \ + } \ + } namespace Copium { @@ -41,7 +40,8 @@ namespace Copium strs.emplace_back(enumNames.substr(lastPos, pos - lastPos)); lastPos = pos + 1; - while (enumNames[lastPos] == ' ') lastPos++; + while (enumNames[lastPos] == ' ') + lastPos++; pos = enumNames.find(',', lastPos); } strs.emplace_back(enumNames.substr(lastPos)); diff --git a/CopiumEngine/src/copium/util/FileSystem.cpp b/CopiumEngine/src/copium/util/FileSystem.cpp index 4a5627d..a96a151 100644 --- a/CopiumEngine/src/copium/util/FileSystem.cpp +++ b/CopiumEngine/src/copium/util/FileSystem.cpp @@ -1,9 +1,10 @@ #include "copium/util/FileSystem.h" +#include +#include + #include #include -#include -#include namespace Copium { diff --git a/CopiumEngine/src/copium/util/FileSystem.h b/CopiumEngine/src/copium/util/FileSystem.h index 8773a7b..f882b81 100644 --- a/CopiumEngine/src/copium/util/FileSystem.h +++ b/CopiumEngine/src/copium/util/FileSystem.h @@ -1,22 +1,23 @@ #pragma once -#include "copium/util/Common.h" - #include #include +#include "copium/util/Common.h" + namespace Copium { - class FileSystem - { - CP_STATIC_CLASS(FileSystem); - public: - static std::vector ReadFile(const std::string& filename); - static std::vector ReadFile32(const std::string& filename); - static std::string ReadFileStr(const std::string& filename); - static void WriteFile(const std::string& filename, const std::string& data); - static void WriteFile(const std::string& filename, const char* data, size_t size); - static bool FileExists(const std::string& filename); - static int64_t DateModified(const std::string& filename); - }; + class FileSystem + { + CP_STATIC_CLASS(FileSystem); + + public: + static std::vector ReadFile(const std::string& filename); + static std::vector ReadFile32(const std::string& filename); + static std::string ReadFileStr(const std::string& filename); + static void WriteFile(const std::string& filename, const std::string& data); + static void WriteFile(const std::string& filename, const char* data, size_t size); + static bool FileExists(const std::string& filename); + static int64_t DateModified(const std::string& filename); + }; } diff --git a/CopiumEngine/src/copium/util/MetaFile.cpp b/CopiumEngine/src/copium/util/MetaFile.cpp index 319e158..0a12046 100644 --- a/CopiumEngine/src/copium/util/MetaFile.cpp +++ b/CopiumEngine/src/copium/util/MetaFile.cpp @@ -1,16 +1,16 @@ #include "copium/util/MetaFile.h" +#include + #include "copium/util/Common.h" #include "copium/util/StringUtil.h" -#include - namespace Copium { std::string MetaFileClass::GetValue(const std::string& key, const std::string& val) const { auto it = values.find(key); - if(it != values.end()) + if (it != values.end()) return it->second; return val; } @@ -39,14 +39,17 @@ namespace Copium std::ostream& operator<<(std::ostream& stream, const MetaFileClass& file) { - for(auto value : file.GetValues()) + for (auto value : file.GetValues()) { stream << value.first << "=" << value.second << std::endl; } return stream; } - MetaFile::MetaFile() {} + MetaFile::MetaFile() + { + } + MetaFile::MetaFile(const std::string& filepath) : filepath{filepath} { @@ -85,7 +88,7 @@ namespace Copium return it->second; } - const std::string& MetaFile::GetFilePath() const + const std::string& MetaFile::GetFilePath() const { return filepath; } @@ -97,7 +100,7 @@ namespace Copium std::ostream& operator<<(std::ostream& stream, const MetaFile& file) { - for(auto metaClass : file.classes) + for (auto metaClass : file.classes) { stream << "[" << metaClass.first << "]" << std::endl; stream << metaClass.second; @@ -117,21 +120,21 @@ namespace Copium std::string currentClass = ""; auto metaClassIt = classes.end(); std::string line; - while(std::getline(stream, line)) + while (std::getline(stream, line)) { std::string_view trimmedLine = StringUtil::Trim(line); - if(trimmedLine.empty()) + if (trimmedLine.empty()) continue; if (trimmedLine[0] == '/' && trimmedLine[1] == '/') continue; - if(trimmedLine == "---") + if (trimmedLine == "---") { return; } - if(trimmedLine.front() == '[' && trimmedLine.back() == ']' ) + if (trimmedLine.front() == '[' && trimmedLine.back() == ']') { currentClass = StringUtil::Trim(line); currentClass = currentClass.substr(1, currentClass.size() - 2); @@ -142,7 +145,7 @@ namespace Copium } size_t pos = line.find("="); - if(pos == std::string::npos) + if (pos == std::string::npos) { CP_WARN("Meta file line does not contain \'=\'"); continue; @@ -150,7 +153,7 @@ namespace Copium std::string_view key = StringUtil::Trim(std::string_view(line.c_str(), pos)); std::string_view value = StringUtil::Trim(std::string_view(line.c_str() + pos + 1)); - if(key.length() == 0) + if (key.length() == 0) { CP_WARN("MetaFile key is empty"); continue; @@ -158,7 +161,7 @@ namespace Copium CP_ASSERT(metaClassIt != classes.end(), "No meta file header specified: ", filepath.c_str()); auto res = metaClassIt->second.values.emplace(key, value); - if(!res.second) + if (!res.second) { CP_WARN("Meta file key is defined twice: %s", std::string(key).c_str()); } @@ -173,11 +176,11 @@ namespace Copium CP_ASSERT(stream, "Failed to read file: %s", file.c_str()); MetaFile meta; - while(!stream.eof()) + while (!stream.eof()) { MetaFile meta{}; stream >> meta; - if(meta.classes.empty()) + if (meta.classes.empty()) continue; metaFiles.emplace_back(meta); } diff --git a/CopiumEngine/src/copium/util/MetaFile.h b/CopiumEngine/src/copium/util/MetaFile.h index 737e5ce..48193cb 100644 --- a/CopiumEngine/src/copium/util/MetaFile.h +++ b/CopiumEngine/src/copium/util/MetaFile.h @@ -10,49 +10,56 @@ namespace Copium class MetaFileClass { friend class MetaFile; - private: - std::map values; - public: - MetaFileClass() {} - MetaFileClass(const std::map& values) - : values{values} - {} - std::string GetValue(const std::string& key, const std::string& val) const; - bool HasValue(const std::string& key) const; - const std::string& GetValue(const std::string& key) const; - const std::map& GetValues() const; + private: + std::map values; - void AddValue(const std::string& key, const std::string& val); + public: + MetaFileClass() + { + } - friend std::ostream& operator<<(std::ostream& stream, const MetaFileClass& file); + MetaFileClass(const std::map& values) + : values{values} + { + } + + std::string GetValue(const std::string& key, const std::string& val) const; + bool HasValue(const std::string& key) const; + const std::string& GetValue(const std::string& key) const; + const std::map& GetValues() const; + + void AddValue(const std::string& key, const std::string& val); + + friend std::ostream& operator<<(std::ostream& stream, const MetaFileClass& file); }; class MetaFile { - private: - std::string filepath; - std::map classes; // map> + private: + std::string filepath; + std::map classes; // map> - public: - MetaFile(); - MetaFile(const std::string& filepath); - MetaFile(std::istream& stream); + public: + MetaFile(); + MetaFile(const std::string& filepath); + MetaFile(std::istream& stream); - bool HasMetaClass(const std::string& className) const; + bool HasMetaClass(const std::string& className) const; - const std::map& GetMetaFileClasses(); - MetaFileClass& GetMetaClass(const std::string& className); - const MetaFileClass& GetMetaClass(const std::string& className) const; - const std::string& GetFilePath() const; + const std::map& GetMetaFileClasses(); + MetaFileClass& GetMetaClass(const std::string& className); + const MetaFileClass& GetMetaClass(const std::string& className) const; + const std::string& GetFilePath() const; - void AddMetaClass(const std::string& name, const MetaFileClass& metaClass); + void AddMetaClass(const std::string& name, const MetaFileClass& metaClass); - friend std::ostream& operator<<(std::ostream& stream, const MetaFile& file); - friend std::istream& operator>>(std::istream& stream, MetaFile& file); + friend std::ostream& operator<<(std::ostream& stream, const MetaFile& file); + friend std::istream& operator>>(std::istream& stream, MetaFile& file); - static std::vector ReadList(const std::string& file); - private: - void LoadMetaFile(std::istream& stream); + static std::vector ReadList(const std::string& file); + + private: + void LoadMetaFile(std::istream& stream); }; } diff --git a/CopiumEngine/src/copium/util/RuntimeException.cpp b/CopiumEngine/src/copium/util/RuntimeException.cpp index 6c7518a..aa10ac5 100644 --- a/CopiumEngine/src/copium/util/RuntimeException.cpp +++ b/CopiumEngine/src/copium/util/RuntimeException.cpp @@ -4,7 +4,8 @@ namespace Copium { RuntimeException::RuntimeException(const std::string& str) : errorMessage{str} - {} + { + } const std::string& RuntimeException::GetErrorMessage() const { diff --git a/CopiumEngine/src/copium/util/RuntimeException.h b/CopiumEngine/src/copium/util/RuntimeException.h index 3390f7a..4c5d887 100644 --- a/CopiumEngine/src/copium/util/RuntimeException.h +++ b/CopiumEngine/src/copium/util/RuntimeException.h @@ -4,13 +4,14 @@ namespace Copium { - class RuntimeException - { + class RuntimeException + { private: std::string errorMessage; - public: + + public: RuntimeException(const std::string& str); const std::string& GetErrorMessage() const; - }; + }; } diff --git a/CopiumEngine/src/copium/util/StringUtil.cpp b/CopiumEngine/src/copium/util/StringUtil.cpp index e863f17..2228a5e 100644 --- a/CopiumEngine/src/copium/util/StringUtil.cpp +++ b/CopiumEngine/src/copium/util/StringUtil.cpp @@ -5,7 +5,7 @@ namespace Copium size_t StringUtil::GetTrimStartPos(const std::string_view& str) { size_t pos = 0; - while(pos < str.size() && (str[pos] == ' ' || str[pos] == '\t')) + while (pos < str.size() && (str[pos] == ' ' || str[pos] == '\t')) pos++; return pos; @@ -13,10 +13,10 @@ namespace Copium size_t StringUtil::GetTrimEndPos(const std::string_view& str) { - if(str.empty()) + if (str.empty()) return 0; size_t pos = str.size() - 1; - while(pos > 0 && (str[pos] == ' ' || str[pos] == '\t')) + while (pos > 0 && (str[pos] == ' ' || str[pos] == '\t')) pos--; return pos; } @@ -25,7 +25,7 @@ namespace Copium { size_t start = GetTrimStartPos(str); size_t end = GetTrimEndPos(str); - if(start == str.size() || start > end) + if (start == str.size() || start > end) return ""; return std::string_view(str.data() + start, end - start + 1); } diff --git a/CopiumEngine/src/copium/util/StringUtil.h b/CopiumEngine/src/copium/util/StringUtil.h index 59612c5..a70e1ed 100644 --- a/CopiumEngine/src/copium/util/StringUtil.h +++ b/CopiumEngine/src/copium/util/StringUtil.h @@ -1,10 +1,10 @@ #pragma once -#include "copium/util/Common.h" - #include #include +#include "copium/util/Common.h" + namespace Copium { class StringUtil @@ -14,6 +14,7 @@ namespace Copium public: static std::string_view Trim(const std::string& str); static std::string_view Trim(const std::string_view& str); + private: static size_t GetTrimStartPos(const std::string_view& str); static size_t GetTrimEndPos(const std::string_view& str); diff --git a/CopiumEngine/src/copium/util/Timer.cpp b/CopiumEngine/src/copium/util/Timer.cpp index 104d44a..b9e3e42 100644 --- a/CopiumEngine/src/copium/util/Timer.cpp +++ b/CopiumEngine/src/copium/util/Timer.cpp @@ -4,7 +4,8 @@ namespace Copium { Timer::Timer() : startTime{std::chrono::steady_clock::now()} - {} + { + } void Timer::Start() { diff --git a/CopiumEngine/src/copium/util/Timer.h b/CopiumEngine/src/copium/util/Timer.h index 181df96..70c517e 100644 --- a/CopiumEngine/src/copium/util/Timer.h +++ b/CopiumEngine/src/copium/util/Timer.h @@ -8,6 +8,7 @@ namespace Copium { private: std::chrono::time_point startTime; + public: Timer(); diff --git a/CopiumEngine/src/copium/util/Uuid.cpp b/CopiumEngine/src/copium/util/Uuid.cpp index 4e7f27f..3cc403e 100644 --- a/CopiumEngine/src/copium/util/Uuid.cpp +++ b/CopiumEngine/src/copium/util/Uuid.cpp @@ -7,49 +7,57 @@ namespace Copium std::random_device Uuid::randomDevice{}; std::mt19937 Uuid::randomGenerator{randomDevice()}; - std::uniform_int_distribution Uuid::randomDistribution{std::numeric_limits::min(), std::numeric_limits::max()}; + std::uniform_int_distribution Uuid::randomDistribution{std::numeric_limits::min(), + std::numeric_limits::max()}; Uuid::Uuid() - : msb{randomDistribution(randomGenerator)}, lsb{randomDistribution(randomGenerator)} - {} + : msb{randomDistribution(randomGenerator)}, + lsb{randomDistribution(randomGenerator)} + { + } Uuid::Uuid(uint64_t msb, uint64_t lsb) - : msb{msb}, lsb{lsb} - {} + : msb{msb}, + lsb{lsb} + { + } Uuid::Uuid(const std::string& uuidString) - : msb{0}, lsb{0} + : msb{0}, + lsb{0} { CP_ASSERT(uuidString.size() == 36, "Invalid Uuid string size: %s", uuidString.c_str()); for (int i = 0; i < 18; i++) { - if (i == 8 || i == 13) // skip "-" + if (i == 8 || i == 13) // skip "-" continue; msb <<= 4; msb |= HexToDec(uuidString[i]); } for (int i = 19; i < 36; i++) { - if (i == 23) // skip "-" + if (i == 23) // skip "-" continue; lsb <<= 4; lsb |= HexToDec(uuidString[i]); } } - std::string Uuid::ToString() const + std::string Uuid::ToString() const { std::string string; string.reserve(36); for (int i = 0; i < 16; i++) { - if (i == 8 || i == 12) string.push_back('-'); + if (i == 8 || i == 12) + string.push_back('-'); string.push_back(DecToHex((msb >> (60 - i * 4)) & 0xf)); } string.push_back('-'); for (int i = 0; i < 16; i++) { - if (i == 4) string.push_back('-'); + if (i == 4) + string.push_back('-'); string.push_back(DecToHex((lsb >> (60 - i * 4)) & 0xf)); } return string; @@ -79,15 +87,19 @@ namespace Copium uint8_t Uuid::HexToDec(char c) const { - if (c >= '0' && c <= '9') return c - '0'; - if (c >= 'a' && c <= 'f') return c - 'a' + 10; + if (c >= '0' && c <= '9') + return c - '0'; + if (c >= 'a' && c <= 'f') + return c - 'a' + 10; CP_ABORT("Invalid char value: %c (%d)", c, (int)c); } char Uuid::DecToHex(uint8_t nibble) const { - if (nibble >= 0 && nibble <= 9) return '0' + nibble; - if (nibble >= 10 && nibble <= 15) return 'a' + nibble - 10; + if (nibble >= 0 && nibble <= 9) + return '0' + nibble; + if (nibble >= 10 && nibble <= 15) + return 'a' + nibble - 10; CP_ABORT("Invalid nibble value: %d", (int)nibble); } } diff --git a/CopiumEngine/src/copium/util/Uuid.h b/CopiumEngine/src/copium/util/Uuid.h index 379eeec..d2a1caf 100644 --- a/CopiumEngine/src/copium/util/Uuid.h +++ b/CopiumEngine/src/copium/util/Uuid.h @@ -1,6 +1,7 @@ #pragma once #include + #include #include @@ -14,6 +15,7 @@ namespace Copium static std::random_device randomDevice; static std::mt19937 randomGenerator; static std::uniform_int_distribution randomDistribution; + public: Uuid(); Uuid(uint64_t msb, uint64_t lsb); diff --git a/CopiumEngine/src/copium/util/VulkanException.h b/CopiumEngine/src/copium/util/VulkanException.h index aad0665..3f29cbf 100644 --- a/CopiumEngine/src/copium/util/VulkanException.h +++ b/CopiumEngine/src/copium/util/VulkanException.h @@ -1,9 +1,9 @@ #pragma once -#include "copium/util/RuntimeException.h" - #include +#include "copium/util/RuntimeException.h" + namespace Copium { class VulkanException : public RuntimeException @@ -11,6 +11,7 @@ namespace Copium public: VulkanException(const std::string& str) : RuntimeException{str} - {} + { + } }; }