Format all files based on clang-format file

This commit is contained in:
Thraix
2026-01-28 22:27:57 +01:00
parent 6c1c558998
commit e5866b2dcb
138 changed files with 1923 additions and 1011 deletions
+334
View File
@@ -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: '^<ext/.*\.h>'
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
...
+3 -2
View File
@@ -1,16 +1,17 @@
#pragma once
#include <stdint.h>
#include "copium/asset/AssetMeta.h"
#include "copium/util/Uuid.h"
#include <stdint.h>
namespace Copium
{
class Asset
{
friend class AssetManager;
public:
Asset();
virtual ~Asset();
+2 -2
View File
@@ -1,9 +1,9 @@
#include "copium/asset/AssetFile.h"
#include "copium/util/FileSystem.h"
#include <fstream>
#include "copium/util/FileSystem.h"
namespace Copium
{
std::vector<std::string> AssetFile::assetTypes;
@@ -8,6 +8,7 @@ namespace Copium
class AssetFile
{
friend class AssetManager;
private:
static std::vector<std::string> 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);
+14 -7
View File
@@ -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<AssetType>&& 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;
};
+10 -6
View File
@@ -1,11 +1,11 @@
#include "copium/asset/AssetManager.h"
#include <filesystem>
#include <fstream>
#include "copium/util/Common.h"
#include "copium/util/MetaFile.h"
#include <fstream>
#include <filesystem>
namespace Copium
{
std::vector<std::string> 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());
@@ -79,7 +83,6 @@ namespace Copium
CP_ABORT("Unknown Asset: %s", assetPath.c_str());
}
Asset& AssetManager::LoadAsset(const Uuid& uuid)
{
CP_DEBUG("Loading uuid Asset: %s", uuid.ToString().c_str());
@@ -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)
+8 -5
View File
@@ -1,18 +1,19 @@
#pragma once
#include "copium/asset/Asset.h"
#include "copium/asset/AssetFile.h"
#include "copium/util/Common.h"
#include <functional>
#include <map>
#include <vector>
#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<Asset&(const MetaFile& metaFile, const std::string& str)>;
static std::map<std::string, CreateAssetFunc> assetTypes;
@@ -40,7 +41,9 @@ namespace Copium
template <typename AssetType>
static void RegisterAssetType(const std::string& assetType)
{
CP_ASSERT(assetTypes.emplace(assetType, &AssetManager::CreateAsset<AssetType>).second, "Asset type already exists: %s", assetType.c_str());
CP_ASSERT(assetTypes.emplace(assetType, &AssetManager::CreateAsset<AssetType>).second,
"Asset type already exists: %s",
assetType.c_str());
AssetFile::RegisterAssetType(assetType);
}
+3 -2
View File
@@ -1,10 +1,11 @@
#pragma once
#include "copium/util/Uuid.h"
#include <stdint.h>
#include <string>
#include "copium/util/Uuid.h"
namespace Copium
{
static constexpr int NULL_ASSET_ID = 0;
+30 -14
View File
@@ -10,39 +10,53 @@ namespace Copium
public:
AssetRef()
: id{std::shared_ptr<AssetId>(new AssetId(NULL_ASSET_ID), AssetIdUnloader{})}
{}
{
}
explicit AssetRef(const std::string& assetName)
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::LoadAsset(assetName).GetId()), AssetIdUnloader{})}
{}
{
}
explicit AssetRef(const Uuid& uuid)
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::LoadAsset(uuid).GetId()), AssetIdUnloader{})}
{}
{
}
explicit AssetRef(AssetType& asset)
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::DuplicateAsset(asset.GetId())), AssetIdUnloader{})}
{}
{
}
explicit AssetRef(std::unique_ptr<AssetType>&& runtimeAsset)
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::RegisterRuntimeAsset(Uuid{}, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})}
{}
: id{std::shared_ptr<AssetId>(
new AssetId(AssetManager::RegisterRuntimeAsset(Uuid{}, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})}
{
}
AssetRef(const Uuid& uuid, std::unique_ptr<AssetType>&& runtimeAsset)
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::RegisterRuntimeAsset(uuid, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})}
{}
: id{std::shared_ptr<AssetId>(
new AssetId(AssetManager::RegisterRuntimeAsset(uuid, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})}
{
}
AssetRef(const std::string& name, std::unique_ptr<AssetType>&& runtimeAsset)
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::RegisterRuntimeAsset(name, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})}
{}
: id{std::shared_ptr<AssetId>(
new AssetId(AssetManager::RegisterRuntimeAsset(name, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})}
{
}
AssetRef(const std::string& name, const Uuid& uuid, std::unique_ptr<AssetType>&& runtimeAsset)
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::RegisterRuntimeAsset(name, uuid, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})}
{}
: id{std::shared_ptr<AssetId>(
new AssetId(AssetManager::RegisterRuntimeAsset(name, uuid, std::move(runtimeAsset)).GetId()),
AssetIdUnloader{})}
{
}
AssetRef(AssetId id)
: id{std::shared_ptr<AssetId>(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<AssetId> id;
};
+17 -6
View File
@@ -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,7 +34,9 @@ namespace Copium
{
VkDeviceMemory memoryCpy = memory;
VkBuffer handleCpy = handle;
Vulkan::GetDevice().QueueIdleCommand([memoryCpy, handleCpy]() {
Vulkan::GetDevice().QueueIdleCommand(
[memoryCpy, handleCpy]()
{
vkFreeMemory(Vulkan::GetDevice(), memoryCpy, nullptr);
vkDestroyBuffer(Vulkan::GetDevice(), handleCpy, nullptr);
});
@@ -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);
@@ -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;
+3 -2
View File
@@ -1,14 +1,15 @@
#pragma once
#include "copium/util/Common.h"
#include <vulkan/vulkan.hpp>
#include "copium/util/Common.h"
namespace Copium
{
class Buffer
{
CP_DELETE_COPY_AND_MOVE_CTOR(Buffer);
protected:
VkDeviceMemory memory;
VkBuffer handle;
@@ -24,14 +24,20 @@ 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<VkCommandBuffer> 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());
});
}
@@ -55,7 +61,8 @@ namespace Copium
}
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()
@@ -1,10 +1,10 @@
#pragma once
#include <vulkan/vulkan.hpp>
#include "copium/util/Common.h"
#include "copium/util/Enum.h"
#include <vulkan/vulkan.hpp>
#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<VkCommandBuffer> commandBuffers;
const CommandBufferType type;
@@ -8,6 +8,7 @@ namespace Copium
class CommandBufferScoped final : public CommandBuffer
{
CP_DELETE_COPY_AND_MOVE_CTOR(CommandBufferScoped);
public:
CommandBufferScoped();
@@ -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,7 +40,9 @@ namespace Copium
{
std::vector<VkFramebuffer> framebuffersCpy = framebuffers;
VkRenderPass renderPassCpy = renderPass;
Vulkan::GetDevice().QueueIdleCommand([framebuffersCpy, renderPassCpy]() {
Vulkan::GetDevice().QueueIdleCommand(
[framebuffersCpy, renderPassCpy]()
{
for (auto& framebuffer : framebuffersCpy)
vkDestroyFramebuffer(Vulkan::GetDevice(), framebuffer, nullptr);
vkDestroyRenderPass(Vulkan::GetDevice(), renderPassCpy, nullptr);
@@ -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");
}
}
}
+4 -2
View File
@@ -1,5 +1,7 @@
#pragma once
#include <vulkan/vulkan.hpp>
#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 <vulkan/vulkan.hpp>
namespace Copium
{
class Framebuffer final : public Asset
{
CP_DELETE_COPY_AND_MOVE_CTOR(Framebuffer);
private:
AssetRef<ColorAttachment> colorAttachment;
std::unique_ptr<DepthAttachment> depthAttachment;
@@ -22,6 +23,7 @@ namespace Copium
int width;
int height;
public:
Framebuffer(const MetaFile& metaFile);
Framebuffer(int width, int height, const SamplerCreator& samplerCreator);
@@ -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)
{
@@ -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);
@@ -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)
{
@@ -9,6 +9,7 @@ namespace Copium
class RendererVertexBuffer : public Buffer
{
CP_DELETE_COPY_AND_MOVE_CTOR(RendererVertexBuffer);
public:
RendererVertexBuffer(const VertexDescriptor& descriptor, int vertexCount);
@@ -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());
}
@@ -1,17 +1,18 @@
#pragma once
#include <glm/glm.hpp>
#include <vulkan/vulkan.hpp>
#include "copium/buffer/Buffer.h"
#include "copium/pipeline/ShaderBinding.h"
#include "copium/util/Common.h"
#include <glm/glm.hpp>
#include <vulkan/vulkan.hpp>
namespace Copium
{
class UniformBuffer final : public Buffer
{
CP_DELETE_COPY_AND_MOVE_CTOR(UniformBuffer);
private:
ShaderBinding binding;
std::vector<uint8_t> buffer;
@@ -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())
@@ -1,21 +1,23 @@
#pragma once
#include <vector>
#include <vulkan/vulkan.hpp>
#include "copium/buffer/Buffer.h"
#include "copium/buffer/CommandBuffer.h"
#include "copium/pipeline/VertexDescriptor.h"
#include "copium/util/Common.h"
#include <vector>
#include <vulkan/vulkan.hpp>
namespace Copium
{
class VertexBuffer final : public Buffer
{
CP_DELETE_COPY_AND_MOVE_CTOR(VertexBuffer);
private:
std::vector<VkDeviceSize> bindingOffsets;
std::vector<VkDeviceSize> bindingSizes;
public:
VertexBuffer(const VertexDescriptor& descriptor, int vertexCount);
@@ -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,19 +39,24 @@ namespace Copium
#else
DebugMessenger::DebugMessenger(Instance& instance)
: instance{instance}
{}
{
}
DebugMessenger::~DebugMessenger()
{}
{
}
void DebugMessenger::AddRequiredExtensions(std::vector<const char*>* extensions)
{}
{
}
void DebugMessenger::AddRequiredLayers(std::vector<const char*>* layers)
{}
{
}
#endif
VKAPI_ATTR VkBool32 VKAPI_CALL DebugMessenger::DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
VKAPI_ATTR VkBool32 VKAPI_CALL
DebugMessenger::DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
VkDebugUtilsMessageTypeFlagsEXT messageType,
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
void* pUserData)
@@ -78,9 +84,11 @@ namespace Copium
void DebugMessenger::vkDestroyDebugUtilsMessengerEXT(VkInstance instance,
VkDebugUtilsMessengerEXT debugMessenger,
const VkAllocationCallbacks* pAllocator) {
const VkAllocationCallbacks* pAllocator)
{
auto func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT");
if (func != nullptr) {
if (func != nullptr)
{
func(instance, debugMessenger, pAllocator);
}
}
@@ -1,9 +1,9 @@
#pragma once
#include "copium/util/Common.h"
#include <vulkan/vulkan.hpp>
#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();
+4 -1
View File
@@ -115,7 +115,10 @@ namespace Copium
devicePriorities.emplace_back(device, GetPhysicalDevicePriority(device));
}
std::sort(devicePriorities.begin(), devicePriorities.end(), [](const std::pair<VkPhysicalDevice, uint32_t>& lhs, const std::pair<VkPhysicalDevice, uint32_t>& rhs) { return lhs.second > rhs.second; });
std::sort(devicePriorities.begin(),
devicePriorities.end(),
[](const std::pair<VkPhysicalDevice, uint32_t>& lhs, const std::pair<VkPhysicalDevice, uint32_t>& rhs)
{ return lhs.second > rhs.second; });
auto&& it = devicePriorities.begin();
CP_ASSERT(it->second != 0, "Failed to find suitable gpu");
+6 -4
View File
@@ -1,17 +1,19 @@
#pragma once
#include "copium/util/Common.h"
#include <vulkan/vulkan.hpp>
#include <queue>
#include <functional>
#include <queue>
#include <vulkan/vulkan.hpp>
#include "copium/util/Common.h"
namespace Copium
{
class Vulkan;
class Device
{
CP_DELETE_COPY_AND_MOVE_CTOR(Device);
public:
Device();
~Device();
@@ -1,11 +1,11 @@
#include "ImGuiInstance.h"
#include "copium/core/Vulkan.h"
#include "copium/buffer/CommandBufferScoped.h"
#include <imgui.h>
#include <backends/imgui_impl_glfw.h>
#include <backends/imgui_impl_vulkan.h>
#include <imgui.h>
#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";
+2 -2
View File
@@ -1,9 +1,9 @@
#include "Instance.h"
#include "copium/util/Common.h"
#include <GLFW/glfw3.h>
#include "copium/util/Common.h"
namespace Copium
{
Instance::Instance(const std::string& applicationName)
+1
View File
@@ -7,6 +7,7 @@ namespace Copium
class Instance final
{
CP_DELETE_COPY_AND_MOVE_CTOR(Instance);
private:
VkInstance instance;
std::unique_ptr<DebugMessenger> debugMessenger;
+2 -1
View File
@@ -1,8 +1,9 @@
#pragma once
#include <optional>
#include <vulkan/vulkan.h>
#include <optional>
namespace Copium
{
struct QueueFamiliesQuery
+24 -12
View File
@@ -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++)
{
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;
}
+7 -4
View File
@@ -1,13 +1,14 @@
#pragma once
#include <GLFW/glfw3.h>
#include <vulkan/vulkan.h>
#include <vector>
#include "copium/buffer/CommandBuffer.h"
#include "copium/sampler/DepthAttachment.h"
#include "copium/util/Common.h"
#include <GLFW/glfw3.h>
#include <vector>
#include <vulkan/vulkan.h>
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;
+6 -3
View File
@@ -41,10 +41,13 @@ namespace Copium
AssetManager::RegisterAssetType<Font>("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<Texture2D>{"empty_texture2d", std::make_unique<Texture2D>(std::vector<uint8_t>{255, 0, 255, 255}, 1, 1, SamplerCreator{})};
whiteTexture2D = AssetHandle<Texture2D>{"white_texture2d", std::make_unique<Texture2D>(std::vector<uint8_t>{255, 255, 255, 255}, 1, 1, SamplerCreator{})};
emptyTexture2D = AssetHandle<Texture2D>{
"empty_texture2d", std::make_unique<Texture2D>(std::vector<uint8_t>{255, 0, 255, 255}, 1, 1, SamplerCreator{})};
whiteTexture2D = AssetHandle<Texture2D>{
"white_texture2d", std::make_unique<Texture2D>(std::vector<uint8_t>{255, 255, 255, 255}, 1, 1, SamplerCreator{})};
CP_INFO("Initialized AssetManager in %f seconds", timer.Elapsed());
}
+6 -4
View File
@@ -1,21 +1,22 @@
#pragma once
#include <memory>
#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 <memory>
#include "copium/util/Common.h"
namespace Copium
{
class Vulkan
{
CP_STATIC_CLASS(Vulkan);
private:
static std::unique_ptr<Instance> instance;
static std::unique_ptr<Window> window;
@@ -25,6 +26,7 @@ namespace Copium
static AssetHandle<Texture2D> emptyTexture2D;
static AssetHandle<Texture2D> whiteTexture2D;
public:
static void Initialize();
static void Destroy();
+10 -6
View File
@@ -1,5 +1,7 @@
#include "copium/core/Window.h"
#include <GLFW/glfw3.h>
#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 <GLFW/glfw3.h>
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();
@@ -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)
@@ -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)
+4 -6
View File
@@ -1,14 +1,11 @@
#pragma once
#include <vulkan/vulkan.hpp>
#include "copium/util/Common.h"
#include "copium/util/Enum.h"
#include <vulkan/vulkan.hpp>
#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;
@@ -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)
{
}
};
}
+7 -5
View File
@@ -1,26 +1,28 @@
#pragma once
#include <vector>
#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 <vector>
namespace Copium
{
template <typename Component>
class ComponentPool : public ComponentPoolBase
{
using Iterator = typename std::vector<Component>::iterator;
private:
std::vector<Component> components;
ComponentListener<Component>* listener = nullptr;
public:
ComponentPool()
{}
{
}
~ComponentPool() override
{
@@ -1,16 +1,17 @@
#pragma once
#include <vector>
#include "copium/ecs/Config.h"
#include "copium/ecs/EntitySet.h"
#include <vector>
namespace Copium
{
class ComponentPoolBase
{
protected:
EntitySet entities;
public:
virtual ~ComponentPoolBase() = default;
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include <stdint.h>
#include <limits>
namespace Copium
+2 -1
View File
@@ -6,7 +6,8 @@ namespace Copium
{
ECSManager::ECSManager()
: systemPool{std::make_unique<SystemPool>(this)}
{}
{
}
ECSManager::~ECSManager()
{
+20 -10
View File
@@ -1,5 +1,9 @@
#pragma once
#include <functional>
#include <map>
#include <typeindex>
#include <unordered_set>
#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 <functional>
#include <map>
#include <typeindex>
#include <unordered_set>
namespace Copium
{
class ECSManager final
@@ -22,6 +21,7 @@ namespace Copium
std::unique_ptr<SystemPool> systemPool;
int currentEntityId = 1;
public:
ECSManager();
~ECSManager();
@@ -85,7 +85,10 @@ namespace Copium
if (pool)
{
CP_ASSERT(!HasComponent<Component>(entity), "Component already exists in entity (entity=%u, Component=%s)", entity, typeid(Component).name());
CP_ASSERT(!HasComponent<Component>(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<Component>();
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 <typename... Components>
@@ -114,7 +120,8 @@ namespace Copium
{
auto pool = GetComponentPoolAssure<Component>();
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 <typename Component, typename... Components>
EntityId Find()
{
return Find<Component, Components...>([] (EntityId, const Component& component, const Components&... components) { return true; });
return Find<Component, Components...>([](EntityId, const Component& component, const Components&... components)
{ return true; });
}
template <typename T>
@@ -233,7 +241,9 @@ namespace Copium
ComponentPool<Component>* GetComponentPoolAssure()
{
auto it = componentPool.find(GetComponentId<Component>());
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<ComponentPool<Component>*>(it->second);
}
};
+12 -6
View File
@@ -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
{
+19 -5
View File
@@ -55,9 +55,23 @@ namespace Copium
return entitiesList.size();
}
std::vector<EntityId>& EntitySet::GetList() { return entitiesList; }
const std::vector<EntityId>& EntitySet::GetList() const { return entitiesList; }
std::vector<EntityId>::iterator EntitySet::begin() { return entitiesList.begin(); }
std::vector<EntityId>::iterator EntitySet::end() { return entitiesList.end(); }
std::vector<EntityId>& EntitySet::GetList()
{
return entitiesList;
}
const std::vector<EntityId>& EntitySet::GetList() const
{
return entitiesList;
}
std::vector<EntityId>::iterator EntitySet::begin()
{
return entitiesList.begin();
}
std::vector<EntityId>::iterator EntitySet::end()
{
return entitiesList.end();
}
}
+2 -2
View File
@@ -1,10 +1,10 @@
#pragma once
#include "copium/ecs/Config.h"
#include <unordered_map>
#include <vector>
#include "copium/ecs/Config.h"
namespace Copium
{
class EntitySet
+9 -7
View File
@@ -1,11 +1,11 @@
#pragma once
#include "copium/ecs/ECSManager.h"
#include "copium/ecs/SystemBase.h"
#include "copium/ecs/Entity.h"
#include <set>
#include "copium/ecs/ECSManager.h"
#include "copium/ecs/Entity.h"
#include "copium/ecs/SystemBase.h"
namespace Copium
{
template <typename... Components>
@@ -14,20 +14,22 @@ namespace Copium
public:
void Run() override
{
manager->Each<Components...>([&](EntityId entityId, Components&... components) { RunEntity(Entity{manager, entityId}, components...); });
manager->Each<Components...>([&](EntityId entityId, Components&... components)
{ RunEntity(Entity{manager, entityId}, components...); });
}
void Run(const Signal& signal) override
{
manager->Each<Components...>([&](EntityId entityId, Components&... components) { RunEntity(signal, Entity{manager, entityId}, components...); });
manager->Each<Components...>([&](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<EntityId> loggedEntities;
bool ValidateEntity(Entity entity)
{
if (entity && entity.HasComponents<Components...>())
+1
View File
@@ -9,6 +9,7 @@ namespace Copium
class SystemBase
{
friend class SystemPool;
protected:
ECSManager* manager;
@@ -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)
{
@@ -11,6 +11,7 @@ namespace Copium
private:
std::type_index systemId;
SystemPool* systemPool = nullptr;
public:
SystemOrderer(std::type_index systemId, SystemPool* systemPool);
+2 -1
View File
@@ -6,7 +6,8 @@ namespace Copium
{
SystemPool::SystemPool(ECSManager* manager)
: manager{manager}
{}
{
}
SystemPool::~SystemPool()
{
+7 -6
View File
@@ -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 <vector>
#include <map>
#include <typeindex>
#include <vector>
#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<std::type_index, SystemBase*> systems;
+2 -1
View File
@@ -5,7 +5,8 @@ namespace Copium
Event::Event(EventType type)
: type{type}
{}
{
}
EventType Event::GetType() const
{
+1
View File
@@ -8,6 +8,7 @@ namespace Copium
{
private:
EventType type;
public:
Event(EventType type);
@@ -1,12 +1,12 @@
#pragma once
#include <memory>
#include <queue>
#include <vector>
#include "copium/event/Event.h"
#include "copium/event/EventHandler.h"
#include <memory>
#include <vector>
#include <queue>
namespace Copium
{
class EventDispatcher
@@ -15,12 +15,14 @@ namespace Copium
static EventHandler* focusedEventHandler;
static std::vector<EventHandler*> eventHandlers;
static std::queue<std::unique_ptr<Event>> events;
public:
template <typename EventType>
static void QueueEvent(const EventType& event)
{
events.push(std::make_unique<EventType>(event));
}
static void Dispatch();
static void AddEventHandler(EventHandler* eventHandler);
static void RemoveEventHandler(EventHandler* eventHandler);
+1 -4
View File
@@ -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);
@@ -4,7 +4,8 @@ namespace Copium
{
EventSignal::EventSignal(const Event& event)
: event{event}
{}
{
}
const Event& EventSignal::GetEvent() const
{
+1 -1
View File
@@ -1,7 +1,7 @@
#pragma once
#include "copium/event/Event.h"
#include "copium/ecs/Signal.h"
#include "copium/event/Event.h"
namespace Copium
{
+1 -4
View File
@@ -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);
+248 -125
View File
@@ -1,11 +1,11 @@
#include "copium/event/Input.h"
#include <glm/gtc/matrix_transform.hpp>
#include "copium/core/Vulkan.h"
#include "copium/event/InputCode.h"
#include "copium/util/Common.h"
#include <glm/gtc/matrix_transform.hpp>
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);
}
}
}
+2 -2
View File
@@ -1,10 +1,10 @@
#pragma once
#include "copium/util/BoundingBox.h"
#include <glm/glm.hpp>
#include <string>
#include "copium/util/BoundingBox.h"
namespace Copium
{
class Input
@@ -3,8 +3,10 @@
namespace Copium
{
KeyPressEvent::KeyPressEvent(int button)
: Event{EventType::KeyPress}, button{button}
{}
: Event{EventType::KeyPress},
button{button}
{
}
int KeyPressEvent::GetButton() const
{
@@ -8,6 +8,7 @@ namespace Copium
{
private:
int button;
public:
KeyPressEvent(int button);
@@ -3,8 +3,10 @@
namespace Copium
{
KeyReleaseEvent::KeyReleaseEvent(int button)
: Event{EventType::KeyRelease}, button{button}
{}
: Event{EventType::KeyRelease},
button{button}
{
}
int KeyReleaseEvent::GetButton() const
{
@@ -8,6 +8,7 @@ namespace Copium
{
private:
int button;
public:
KeyReleaseEvent(int button);
@@ -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
{
@@ -1,9 +1,9 @@
#pragma once
#include "copium/event/Event.h"
#include <glm/glm.hpp>
#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);
@@ -3,8 +3,10 @@
namespace Copium
{
MousePressEvent::MousePressEvent(int button)
: Event{EventType::MousePress}, button{button}
{}
: Event{EventType::MousePress},
button{button}
{
}
int MousePressEvent::GetButton() const
{
@@ -1,15 +1,16 @@
#pragma once
#include "copium/event/Event.h"
#include <glm/glm.hpp>
#include "copium/event/Event.h"
namespace Copium
{
class MousePressEvent : public Event
{
private:
int button;
public:
MousePressEvent(int button);
@@ -3,8 +3,10 @@
namespace Copium
{
MouseReleaseEvent::MouseReleaseEvent(int button)
: Event{EventType::MouseRelease}, button{button}
{}
: Event{EventType::MouseRelease},
button{button}
{
}
int MouseReleaseEvent::GetButton() const
{
@@ -1,15 +1,16 @@
#pragma once
#include "copium/event/Event.h"
#include <glm/glm.hpp>
#include "copium/event/Event.h"
namespace Copium
{
class MouseReleaseEvent : public Event
{
private:
int button;
public:
MouseReleaseEvent(int button);
@@ -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
{
@@ -9,6 +9,7 @@ namespace Copium
private:
int scrollX;
int scrollY;
public:
MouseScrollEvent(int scrollX, int scrollY);
@@ -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
{
@@ -8,6 +8,7 @@ namespace Copium
class ViewportResize : public Event
{
BoundingBox viewport;
public:
ViewportResize(const BoundingBox& viewport);
@@ -3,8 +3,10 @@
namespace Copium
{
WindowFocusEvent::WindowFocusEvent(bool focused)
: Event{EventType::WindowFocus}, focused{focused}
{}
: Event{EventType::WindowFocus},
focused{focused}
{
}
bool WindowFocusEvent::IsFocused() const
{
@@ -8,6 +8,7 @@ namespace Copium
{
private:
bool focused;
public:
WindowFocusEvent(bool focused);
@@ -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
{
@@ -9,6 +9,7 @@ namespace Copium
private:
int width;
int height;
public:
WindowResizeEvent(int width, int height);
+6 -4
View File
@@ -1,21 +1,23 @@
#pragma once
#include <memory>
#include <vector>
#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 <vector>
#include <memory>
namespace Copium
{
class Mesh
{
CP_DELETE_COPY_AND_MOVE_CTOR(Mesh);
private:
std::unique_ptr<IndexBuffer> indexBuffer;
std::unique_ptr<VertexBuffer> vertexBuffer;
public:
template <typename T>
Mesh(const std::vector<T>& vertices, const std::vector<uint16_t>& indices);
+2 -3
View File
@@ -1,9 +1,9 @@
#pragma once
#include "copium/pipeline/VertexDescriptor.h"
#include <glm/glm.hpp>
#include "copium/pipeline/VertexDescriptor.h"
namespace Copium
{
struct Vertex
@@ -15,4 +15,3 @@ namespace Copium
static VertexDescriptor GetDescriptor();
};
}
@@ -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;
}
}
@@ -1,9 +1,9 @@
#pragma once
#include "copium/pipeline/VertexDescriptor.h"
#include <glm/glm.hpp>
#include "copium/pipeline/VertexDescriptor.h"
namespace Copium
{
struct VertexPassthrough
@@ -23,7 +23,6 @@ namespace Copium
poolSizes.emplace_back(descriptorSetPoolSize);
}
VkDescriptorPoolCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
createInfo.poolSizeCount = poolSizes.size();
@@ -31,15 +30,15 @@ namespace Copium
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<VkDescriptorSet> 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,8 +61,11 @@ namespace Copium
{
VkDescriptorPool descriptorPoolCpy = descriptorPool;
std::vector<VkDescriptorSet> 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());
});
}
@@ -1,16 +1,18 @@
#pragma once
#include "copium/util/Common.h"
#include <vulkan/vulkan.hpp>
#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();
@@ -4,8 +4,12 @@
namespace Copium
{
DescriptorSet::DescriptorSet(DescriptorPool& descriptorPool, VkDescriptorSetLayout descriptorSetLayout, const std::set<ShaderBinding>& bindings)
: descriptorPool{descriptorPool}, descriptorSetLayout{descriptorSetLayout}, bindings{bindings}
DescriptorSet::DescriptorSet(DescriptorPool& descriptorPool,
VkDescriptorSetLayout descriptorSetLayout,
const std::set<ShaderBinding>& 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<const Sampler*>& samplers, uint32_t binding)
{
for (size_t i = 0; i < descriptorSets.size(); ++i) {
for (size_t i = 0; i < descriptorSets.size(); ++i)
{
std::vector<VkWriteDescriptorSet> 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{};
@@ -1,23 +1,23 @@
#pragma once
#include <glm/glm.hpp>
#include <map>
#include <set>
#include <vector>
#include <vulkan/vulkan.hpp>
#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 <glm/glm.hpp>
#include <vulkan/vulkan.hpp>
#include <map>
#include <set>
#include <vector>
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<std::string, std::unique_ptr<UniformBuffer>> uniformBuffers;
public:
DescriptorSet(DescriptorPool& descriptorPool, VkDescriptorSetLayout descriptorSetLayout, const std::set<ShaderBinding>& bindings);
DescriptorSet(DescriptorPool& descriptorPool,
VkDescriptorSetLayout descriptorSetLayout,
const std::set<ShaderBinding>& 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);
};
+28 -19
View File
@@ -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,7 +68,9 @@ namespace Copium
VkPipeline graphicsPipelineCpy = graphicsPipeline;
VkPipelineLayout pipelineLayoutCpy = pipelineLayout;
std::vector<VkDescriptorSetLayout> descriptorSetLayoutsCpy = descriptorSetLayouts;
Vulkan::GetDevice().QueueIdleCommand([graphicsPipelineCpy, pipelineLayoutCpy, descriptorSetLayoutsCpy]() {
Vulkan::GetDevice().QueueIdleCommand(
[graphicsPipelineCpy, pipelineLayoutCpy, descriptorSetLayoutsCpy]()
{
vkDestroyPipeline(Vulkan::GetDevice(), graphicsPipelineCpy, nullptr);
vkDestroyPipelineLayout(Vulkan::GetDevice(), pipelineLayoutCpy, nullptr);
for (auto&& descriptorSetLayout : descriptorSetLayoutsCpy)
@@ -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<DescriptorSet> 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<VkDynamicState> dynamicStates = {
VK_DYNAMIC_STATE_VIEWPORT,
VK_DYNAMIC_STATE_SCISSOR
};
std::vector<VkDynamicState> 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;
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<VkPipelineShaderStageCreateInfo>& 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");
}
}
+4 -4
View File
@@ -1,5 +1,8 @@
#pragma once
#include <vector>
#include <vulkan/vulkan.hpp>
#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 <vector>
#include <vulkan/vulkan.hpp>
namespace Copium
{
class Pipeline final : public Asset
{
CP_DELETE_COPY_AND_MOVE_CTOR(Pipeline);
private:
ShaderReflector shaderReflector;
std::vector<VkDescriptorSetLayout> descriptorSetLayouts{};
@@ -25,7 +26,6 @@ namespace Copium
AssetRef<Framebuffer> framebuffer;
public:
Pipeline(const MetaFile& metaFile);
Pipeline(PipelineCreator creator);
~Pipeline();
@@ -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)});
}
}
@@ -1,14 +1,13 @@
#pragma once
#include <cstdint>
#include <map>
#include <string>
#include <vulkan/vulkan.hpp>
#include "copium/pipeline/ShaderReflector.h"
#include "copium/pipeline/VertexDescriptor.h"
#include <vulkan/vulkan.hpp>
#include <map>
#include <string>
#include <cstdint>
namespace Copium
{
class PipelineCreator
@@ -21,6 +20,7 @@ namespace Copium
VkShaderStageFlags flags;
};
friend class Pipeline;
private:
std::map<uint32_t, std::vector<DescriptorSetBinding>> 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);
+15 -6
View File
@@ -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
@@ -48,7 +48,9 @@ namespace Copium
{
VkShaderModule vertShaderModuleCpy = vertShaderModule;
VkShaderModule fragShaderModuleCpy = fragShaderModule;
Vulkan::GetDevice().QueueIdleCommand([vertShaderModuleCpy, fragShaderModuleCpy]() {
Vulkan::GetDevice().QueueIdleCommand(
[vertShaderModuleCpy, fragShaderModuleCpy]()
{
vkDestroyShaderModule(Vulkan::GetDevice(), vertShaderModuleCpy, nullptr);
vkDestroyShaderModule(Vulkan::GetDevice(), fragShaderModuleCpy, nullptr);
});
@@ -100,8 +102,12 @@ namespace Copium
options.SetOptimizationLevel(shaderc_optimization_level_size);
std::vector<char> 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<uint32_t> 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<uint32_t> 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;
}
+6 -3
View File
@@ -1,11 +1,11 @@
#pragma once
#include "copium/util/Common.h"
#include "copium/util/Enum.h"
#include <shaderc/shaderc.hpp>
#include <vulkan/vulkan.hpp>
#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<VkPipelineShaderStageCreateInfo> shaderStages;
public:
Shader(ShaderReadType type, const std::string& vertexInput, const std::string& fragmentInput);
~Shader();
const std::vector<VkPipelineShaderStageCreateInfo> GetShaderStages() const;
private:
VkShaderModule InitializeShaderModule(const std::vector<uint32_t>& codeSpv);
VkShaderModule InitializeShaderModule(const std::string& codeSpv);
@@ -1,11 +1,10 @@
#pragma once
#include "copium/util/Enum.h"
#include <cstdint>
#include <string>
#include <vector>
#include <cstdint>
#include "copium/util/Enum.h"
#define CP_BINDING_TYPE_ENUMS Sampler2D, UniformBuffer
#define CP_SHADER_TYPE_ENUMS Vertex, Fragment
@@ -35,6 +34,7 @@ namespace Copium
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;
@@ -1,9 +1,9 @@
#include "copium/pipeline/ShaderReflector.h"
#include "copium/util/FileSystem.h"
#include <string_view>
#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)
@@ -82,7 +84,8 @@ namespace Copium
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);
}
@@ -146,6 +148,7 @@ namespace Copium
index++; // ";"
ParseWhitespace(str, index);
}
if (index < str.size()) index++; // go past "}"
if (index < str.size())
index++; // go past "}"
}
}
@@ -1,16 +1,17 @@
#pragma once
#include "copium/pipeline/ShaderBinding.h"
#include <set>
#include <string>
#include "copium/pipeline/ShaderBinding.h"
namespace Copium
{
class ShaderReflector
{
public:
std::set<ShaderBinding> bindings;
public:
ShaderReflector(const std::string& vertexGlslFile, const std::string& fragmentGlslFile);
@@ -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);
+4 -2
View File
@@ -7,9 +7,11 @@ namespace Copium
{
Batch::Batch(AssetRef<Pipeline>& pipeline, int vertexCount, const std::vector<const Sampler*> 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()
{
+2
View File
@@ -11,10 +11,12 @@ namespace Copium
class Batch
{
CP_DELETE_COPY_AND_MOVE_CTOR(Batch);
private:
RendererVertexBuffer vertexBuffer;
DescriptorPool descriptorPool;
std::unique_ptr<DescriptorSet> descriptorSet;
public:
Batch(AssetRef<Pipeline>& pipeline, int vertexCount, const std::vector<const Sampler*> samplers);
RendererVertexBuffer& GetVertexBuffer();

Some files were not shown because too many files have changed in this diff Show More