Format all files based on clang-format file
This commit is contained in:
+334
@@ -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
|
||||||
|
...
|
||||||
|
|
||||||
@@ -1,16 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "copium/asset/AssetMeta.h"
|
#include "copium/asset/AssetMeta.h"
|
||||||
#include "copium/util/Uuid.h"
|
#include "copium/util/Uuid.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
|
|
||||||
class Asset
|
class Asset
|
||||||
{
|
{
|
||||||
friend class AssetManager;
|
friend class AssetManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Asset();
|
Asset();
|
||||||
virtual ~Asset();
|
virtual ~Asset();
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include "copium/asset/AssetFile.h"
|
#include "copium/asset/AssetFile.h"
|
||||||
|
|
||||||
#include "copium/util/FileSystem.h"
|
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "copium/util/FileSystem.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
std::vector<std::string> AssetFile::assetTypes;
|
std::vector<std::string> AssetFile::assetTypes;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace Copium
|
|||||||
class AssetFile
|
class AssetFile
|
||||||
{
|
{
|
||||||
friend class AssetManager;
|
friend class AssetManager;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::vector<std::string> assetTypes;
|
static std::vector<std::string> assetTypes;
|
||||||
std::string path;
|
std::string path;
|
||||||
@@ -22,6 +23,7 @@ namespace Copium
|
|||||||
|
|
||||||
const std::string& GetPath() const;
|
const std::string& GetPath() const;
|
||||||
Uuid GetUuid() const;
|
Uuid GetUuid() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Load(MetaFile& metaFile, const std::string& className);
|
void Load(MetaFile& metaFile, const std::string& className);
|
||||||
static void RegisterAssetType(const std::string& assetType);
|
static void RegisterAssetType(const std::string& assetType);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/asset/AssetMeta.h"
|
|
||||||
#include "copium/asset/AssetManager.h"
|
#include "copium/asset/AssetManager.h"
|
||||||
|
#include "copium/asset/AssetMeta.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
@@ -11,27 +11,33 @@ namespace Copium
|
|||||||
public:
|
public:
|
||||||
AssetHandle()
|
AssetHandle()
|
||||||
: id{NULL_ASSET_ID}
|
: id{NULL_ASSET_ID}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
AssetHandle(const std::string& assetName)
|
AssetHandle(const std::string& assetName)
|
||||||
: id{AssetManager::LoadAsset(assetName).GetId()}
|
: id{AssetManager::LoadAsset(assetName).GetId()}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
AssetHandle(const Uuid& uuid)
|
AssetHandle(const Uuid& uuid)
|
||||||
: id{AssetManager::LoadAsset(uuid).GetId()}
|
: id{AssetManager::LoadAsset(uuid).GetId()}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
AssetHandle(AssetType& asset)
|
AssetHandle(AssetType& asset)
|
||||||
: id{AssetManager::DuplicateAsset(asset.GetId())}
|
: id{AssetManager::DuplicateAsset(asset.GetId())}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
AssetHandle(const std::string& name, std::unique_ptr<AssetType>&& runtimeAsset)
|
AssetHandle(const std::string& name, std::unique_ptr<AssetType>&& runtimeAsset)
|
||||||
: id{AssetManager::RegisterRuntimeAsset(name, std::move(runtimeAsset)).GetId()}
|
: id{AssetManager::RegisterRuntimeAsset(name, std::move(runtimeAsset)).GetId()}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
AssetHandle(AssetId id)
|
AssetHandle(AssetId id)
|
||||||
: id{AssetManager::DuplicateAsset(id)}
|
: id{AssetManager::DuplicateAsset(id)}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
AssetId GetId() const
|
AssetId GetId() const
|
||||||
{
|
{
|
||||||
@@ -53,6 +59,7 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
return id != NULL_ASSET_ID;
|
return id != NULL_ASSET_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AssetId id;
|
AssetId id;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#include "copium/asset/AssetManager.h"
|
#include "copium/asset/AssetManager.h"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#include "copium/util/Common.h"
|
#include "copium/util/Common.h"
|
||||||
#include "copium/util/MetaFile.h"
|
#include "copium/util/MetaFile.h"
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <filesystem>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
std::vector<std::string> AssetManager::assetDirs;
|
std::vector<std::string> AssetManager::assetDirs;
|
||||||
@@ -27,7 +27,11 @@ namespace Copium
|
|||||||
if (std::filesystem::is_directory(it->path()))
|
if (std::filesystem::is_directory(it->path()))
|
||||||
continue;
|
continue;
|
||||||
std::filesystem::path assetDirPath{assetDir};
|
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
|
try
|
||||||
{
|
{
|
||||||
CP_DEBUG("Registering Asset: %s", assetPath.c_str());
|
CP_DEBUG("Registering Asset: %s", assetPath.c_str());
|
||||||
@@ -45,7 +49,7 @@ namespace Copium
|
|||||||
if (assetDir.back() == '/')
|
if (assetDir.back() == '/')
|
||||||
assetDir.pop_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)
|
if (*it == assetDir)
|
||||||
{
|
{
|
||||||
@@ -79,8 +83,7 @@ namespace Copium
|
|||||||
CP_ABORT("Unknown Asset: %s", assetPath.c_str());
|
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());
|
CP_DEBUG("Loading uuid Asset: %s", uuid.ToString().c_str());
|
||||||
for (auto&& assetFile : cachedAssetFiles)
|
for (auto&& assetFile : cachedAssetFiles)
|
||||||
@@ -115,7 +118,8 @@ namespace Copium
|
|||||||
CP_WARN("Asset not loaded");
|
CP_WARN("Asset not loaded");
|
||||||
return;
|
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--;
|
it->second->metaData.loadCount--;
|
||||||
if (it->second->metaData.loadCount > 0)
|
if (it->second->metaData.loadCount > 0)
|
||||||
@@ -133,7 +137,7 @@ namespace Copium
|
|||||||
return cachedAssetFiles;
|
return cachedAssetFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetManager::Cleanup()
|
void AssetManager::Cleanup()
|
||||||
{
|
{
|
||||||
if (assets.empty())
|
if (assets.empty())
|
||||||
return;
|
return;
|
||||||
@@ -177,7 +181,7 @@ namespace Copium
|
|||||||
MetaFile metaFile{filepath};
|
MetaFile metaFile{filepath};
|
||||||
for (auto& assetType : assetTypes)
|
for (auto& assetType : assetTypes)
|
||||||
{
|
{
|
||||||
if(metaFile.HasMetaClass(assetType.first))
|
if (metaFile.HasMetaClass(assetType.first))
|
||||||
return assetType.second(metaFile, assetType.first);
|
return assetType.second(metaFile, assetType.first);
|
||||||
}
|
}
|
||||||
CP_ABORT("Unknown Asset type: %s", filepath.c_str());
|
CP_ABORT("Unknown Asset type: %s", filepath.c_str());
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/asset/Asset.h"
|
|
||||||
#include "copium/asset/AssetFile.h"
|
|
||||||
#include "copium/util/Common.h"
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "copium/asset/Asset.h"
|
||||||
|
#include "copium/asset/AssetFile.h"
|
||||||
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class AssetManager
|
class AssetManager
|
||||||
{
|
{
|
||||||
CP_STATIC_CLASS(AssetManager);
|
CP_STATIC_CLASS(AssetManager);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using CreateAssetFunc = std::function<Asset&(const MetaFile& metaFile, const std::string& str)>;
|
using CreateAssetFunc = std::function<Asset&(const MetaFile& metaFile, const std::string& str)>;
|
||||||
static std::map<std::string, CreateAssetFunc> assetTypes;
|
static std::map<std::string, CreateAssetFunc> assetTypes;
|
||||||
@@ -24,7 +25,7 @@ namespace Copium
|
|||||||
static AssetId assetId;
|
static AssetId assetId;
|
||||||
static AssetId runtimeAssetId;
|
static AssetId runtimeAssetId;
|
||||||
|
|
||||||
static std::vector<AssetFile> cachedAssetFiles; // TODO: Make a set?
|
static std::vector<AssetFile> cachedAssetFiles; // TODO: Make a set?
|
||||||
public:
|
public:
|
||||||
static void RegisterAssetDir(std::string assetDir);
|
static void RegisterAssetDir(std::string assetDir);
|
||||||
static void UnregisterAssetDir(std::string assetDir);
|
static void UnregisterAssetDir(std::string assetDir);
|
||||||
@@ -40,7 +41,9 @@ namespace Copium
|
|||||||
template <typename AssetType>
|
template <typename AssetType>
|
||||||
static void RegisterAssetType(const std::string& 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);
|
AssetFile::RegisterAssetType(assetType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +64,7 @@ namespace Copium
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename AssetT>
|
template <typename AssetT>
|
||||||
static AssetT& GetAsset(AssetId id)
|
static AssetT& GetAsset(AssetId id)
|
||||||
{
|
{
|
||||||
Asset& asset = GetAsset(id);
|
Asset& asset = GetAsset(id);
|
||||||
AssetT* assetT = dynamic_cast<AssetT*>(&asset);
|
AssetT* assetT = dynamic_cast<AssetT*>(&asset);
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/util/Uuid.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "copium/util/Uuid.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
static constexpr int NULL_ASSET_ID = 0;
|
static constexpr int NULL_ASSET_ID = 0;
|
||||||
|
|||||||
@@ -10,39 +10,53 @@ namespace Copium
|
|||||||
public:
|
public:
|
||||||
AssetRef()
|
AssetRef()
|
||||||
: id{std::shared_ptr<AssetId>(new AssetId(NULL_ASSET_ID), AssetIdUnloader{})}
|
: id{std::shared_ptr<AssetId>(new AssetId(NULL_ASSET_ID), AssetIdUnloader{})}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
explicit AssetRef(const std::string& assetName)
|
explicit AssetRef(const std::string& assetName)
|
||||||
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::LoadAsset(assetName).GetId()), AssetIdUnloader{})}
|
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::LoadAsset(assetName).GetId()), AssetIdUnloader{})}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
explicit AssetRef(const Uuid& uuid)
|
explicit AssetRef(const Uuid& uuid)
|
||||||
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::LoadAsset(uuid).GetId()), AssetIdUnloader{})}
|
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::LoadAsset(uuid).GetId()), AssetIdUnloader{})}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
explicit AssetRef(AssetType& asset)
|
explicit AssetRef(AssetType& asset)
|
||||||
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::DuplicateAsset(asset.GetId())), AssetIdUnloader{})}
|
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::DuplicateAsset(asset.GetId())), AssetIdUnloader{})}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
explicit AssetRef(std::unique_ptr<AssetType>&& runtimeAsset)
|
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)
|
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)
|
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)
|
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)
|
AssetRef(AssetId id)
|
||||||
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::DuplicateAsset(id)), AssetIdUnloader{})}
|
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::DuplicateAsset(id)), AssetIdUnloader{})}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
AssetId GetId() const
|
AssetId GetId() const
|
||||||
{
|
{
|
||||||
@@ -60,7 +74,8 @@ namespace Copium
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct AssetIdUnloader {
|
struct AssetIdUnloader
|
||||||
|
{
|
||||||
void operator()(AssetId* id)
|
void operator()(AssetId* id)
|
||||||
{
|
{
|
||||||
if (*id != NULL_ASSET_ID)
|
if (*id != NULL_ASSET_ID)
|
||||||
@@ -69,6 +84,7 @@ namespace Copium
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<AssetId> id;
|
std::shared_ptr<AssetId> id;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
Buffer::Buffer(VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkDeviceSize size, int count)
|
Buffer::Buffer(VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkDeviceSize size, int count)
|
||||||
: size{size}, count{count}
|
: size{size},
|
||||||
|
count{count}
|
||||||
{
|
{
|
||||||
VkBufferCreateInfo createInfo{};
|
VkBufferCreateInfo createInfo{};
|
||||||
createInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
createInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||||
@@ -23,7 +24,8 @@ namespace Copium
|
|||||||
allocateInfo.allocationSize = memoryRequirements.size;
|
allocateInfo.allocationSize = memoryRequirements.size;
|
||||||
allocateInfo.memoryTypeIndex = Vulkan::GetDevice().FindMemoryType(memoryRequirements.memoryTypeBits, properties);
|
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);
|
vkBindBufferMemory(Vulkan::GetDevice(), handle, memory, 0);
|
||||||
}
|
}
|
||||||
@@ -32,10 +34,12 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
VkDeviceMemory memoryCpy = memory;
|
VkDeviceMemory memoryCpy = memory;
|
||||||
VkBuffer handleCpy = handle;
|
VkBuffer handleCpy = handle;
|
||||||
Vulkan::GetDevice().QueueIdleCommand([memoryCpy, handleCpy]() {
|
Vulkan::GetDevice().QueueIdleCommand(
|
||||||
vkFreeMemory(Vulkan::GetDevice(), memoryCpy, nullptr);
|
[memoryCpy, handleCpy]()
|
||||||
vkDestroyBuffer(Vulkan::GetDevice(), handleCpy, nullptr);
|
{
|
||||||
});
|
vkFreeMemory(Vulkan::GetDevice(), memoryCpy, nullptr);
|
||||||
|
vkDestroyBuffer(Vulkan::GetDevice(), handleCpy, nullptr);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::Update(void* indexData, int index)
|
void Buffer::Update(void* indexData, int index)
|
||||||
@@ -58,7 +62,10 @@ namespace Copium
|
|||||||
void Buffer::UpdateStaging(void* data)
|
void Buffer::UpdateStaging(void* data)
|
||||||
{
|
{
|
||||||
VkDeviceSize bufferSize = size * count;
|
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);
|
stagingBuffer.Update(data, 0);
|
||||||
|
|
||||||
@@ -67,7 +74,10 @@ namespace Copium
|
|||||||
|
|
||||||
void Buffer::UpdateStaging(void* data, VkDeviceSize offset, VkDeviceSize size)
|
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);
|
stagingBuffer.Update(data, 0);
|
||||||
|
|
||||||
@@ -89,7 +99,7 @@ namespace Copium
|
|||||||
mappedData = nullptr;
|
mappedData = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer::operator VkBuffer() const
|
Buffer::operator VkBuffer() const
|
||||||
{
|
{
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
@@ -115,7 +125,8 @@ namespace Copium
|
|||||||
allocateInfo.commandBufferCount = 1;
|
allocateInfo.commandBufferCount = 1;
|
||||||
|
|
||||||
VkCommandBuffer commandBuffer;
|
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{};
|
VkCommandBufferBeginInfo beginInfo{};
|
||||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/util/Common.h"
|
|
||||||
|
|
||||||
#include <vulkan/vulkan.hpp>
|
#include <vulkan/vulkan.hpp>
|
||||||
|
|
||||||
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class Buffer
|
class Buffer
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(Buffer);
|
CP_DELETE_COPY_AND_MOVE_CTOR(Buffer);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
VkDeviceMemory memory;
|
VkDeviceMemory memory;
|
||||||
VkBuffer handle;
|
VkBuffer handle;
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case CommandBufferType::SingleUse:
|
case CommandBufferType::SingleUse:
|
||||||
commandBuffers.resize(1);
|
commandBuffers.resize(1);
|
||||||
break;
|
break;
|
||||||
case CommandBufferType::Dynamic:
|
case CommandBufferType::Dynamic:
|
||||||
commandBuffers.resize(SwapChain::MAX_FRAMES_IN_FLIGHT);
|
commandBuffers.resize(SwapChain::MAX_FRAMES_IN_FLIGHT);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
CP_ABORT("Unreachable switch case: %s", ToString(type).c_str());
|
CP_ABORT("Unreachable switch case: %s", ToString(type).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
VkCommandBufferAllocateInfo allocateInfo{};
|
VkCommandBufferAllocateInfo allocateInfo{};
|
||||||
@@ -24,15 +24,21 @@ namespace Copium
|
|||||||
allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||||
allocateInfo.commandPool = Vulkan::GetDevice().GetCommandPool();
|
allocateInfo.commandPool = Vulkan::GetDevice().GetCommandPool();
|
||||||
allocateInfo.commandBufferCount = commandBuffers.size();
|
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()
|
CommandBuffer::~CommandBuffer()
|
||||||
{
|
{
|
||||||
std::vector<VkCommandBuffer> commandBuffersCpy = commandBuffers;
|
std::vector<VkCommandBuffer> commandBuffersCpy = commandBuffers;
|
||||||
Vulkan::GetDevice().QueueIdleCommand([commandBuffersCpy]() {
|
Vulkan::GetDevice().QueueIdleCommand(
|
||||||
vkFreeCommandBuffers(Vulkan::GetDevice(), Vulkan::GetDevice().GetCommandPool(), commandBuffersCpy.size(), commandBuffersCpy.data());
|
[commandBuffersCpy]()
|
||||||
});
|
{
|
||||||
|
vkFreeCommandBuffers(Vulkan::GetDevice(),
|
||||||
|
Vulkan::GetDevice().GetCommandPool(),
|
||||||
|
commandBuffersCpy.size(),
|
||||||
|
commandBuffersCpy.data());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Test as constexpr function to see if it avoids the switch case
|
// TODO: Test as constexpr function to see if it avoids the switch case
|
||||||
@@ -45,17 +51,18 @@ namespace Copium
|
|||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case CommandBufferType::SingleUse:
|
case CommandBufferType::SingleUse:
|
||||||
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
||||||
break;
|
break;
|
||||||
case CommandBufferType::Dynamic:
|
case CommandBufferType::Dynamic:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
CP_ABORT("Unreachable switch case: %s", ToString(type).c_str());
|
CP_ABORT("Unreachable switch case: %s", ToString(type).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
vkResetCommandBuffer(commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()], 0);
|
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()
|
void CommandBuffer::End()
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <vulkan/vulkan.hpp>
|
||||||
|
|
||||||
#include "copium/util/Common.h"
|
#include "copium/util/Common.h"
|
||||||
#include "copium/util/Enum.h"
|
#include "copium/util/Enum.h"
|
||||||
|
|
||||||
#include <vulkan/vulkan.hpp>
|
|
||||||
|
|
||||||
#define CP_COMMAND_BUFFER_TYPE_ENUMS SingleUse, Dynamic
|
#define CP_COMMAND_BUFFER_TYPE_ENUMS SingleUse, Dynamic
|
||||||
CP_ENUM_CREATOR(Copium, CommandBufferType, CP_COMMAND_BUFFER_TYPE_ENUMS);
|
CP_ENUM_CREATOR(Copium, CommandBufferType, CP_COMMAND_BUFFER_TYPE_ENUMS);
|
||||||
|
|
||||||
@@ -13,6 +13,7 @@ namespace Copium
|
|||||||
class CommandBuffer
|
class CommandBuffer
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(CommandBuffer);
|
CP_DELETE_COPY_AND_MOVE_CTOR(CommandBuffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<VkCommandBuffer> commandBuffers;
|
std::vector<VkCommandBuffer> commandBuffers;
|
||||||
const CommandBufferType type;
|
const CommandBufferType type;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace Copium
|
|||||||
class CommandBufferScoped final : public CommandBuffer
|
class CommandBufferScoped final : public CommandBuffer
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(CommandBufferScoped);
|
CP_DELETE_COPY_AND_MOVE_CTOR(CommandBufferScoped);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CommandBufferScoped();
|
CommandBufferScoped();
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ namespace Copium
|
|||||||
}
|
}
|
||||||
|
|
||||||
Framebuffer::Framebuffer(int width, int height, const SamplerCreator& samplerCreator)
|
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(width > 0, "Width of framebuffer is less than 1: %d", width);
|
||||||
CP_ASSERT(height > 0, "Height of framebuffer is less than 1: %d", height);
|
CP_ASSERT(height > 0, "Height of framebuffer is less than 1: %d", height);
|
||||||
@@ -39,11 +40,13 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
std::vector<VkFramebuffer> framebuffersCpy = framebuffers;
|
std::vector<VkFramebuffer> framebuffersCpy = framebuffers;
|
||||||
VkRenderPass renderPassCpy = renderPass;
|
VkRenderPass renderPassCpy = renderPass;
|
||||||
Vulkan::GetDevice().QueueIdleCommand([framebuffersCpy, renderPassCpy]() {
|
Vulkan::GetDevice().QueueIdleCommand(
|
||||||
for (auto& framebuffer : framebuffersCpy)
|
[framebuffersCpy, renderPassCpy]()
|
||||||
vkDestroyFramebuffer(Vulkan::GetDevice(), framebuffer, nullptr);
|
{
|
||||||
vkDestroyRenderPass(Vulkan::GetDevice(), renderPassCpy, nullptr);
|
for (auto& framebuffer : framebuffersCpy)
|
||||||
});
|
vkDestroyFramebuffer(Vulkan::GetDevice(), framebuffer, nullptr);
|
||||||
|
vkDestroyRenderPass(Vulkan::GetDevice(), renderPassCpy, nullptr);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framebuffer::Resize(int width, int height)
|
void Framebuffer::Resize(int width, int height)
|
||||||
@@ -193,7 +196,8 @@ namespace Copium
|
|||||||
renderPassCreateInfo.dependencyCount = dependencies.size();
|
renderPassCreateInfo.dependencyCount = dependencies.size();
|
||||||
renderPassCreateInfo.pDependencies = dependencies.data();
|
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()
|
void Framebuffer::InitializeFramebuffers()
|
||||||
@@ -213,7 +217,8 @@ namespace Copium
|
|||||||
createInfo.height = height;
|
createInfo.height = height;
|
||||||
createInfo.layers = 1;
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <vulkan/vulkan.hpp>
|
||||||
|
|
||||||
#include "copium/asset/Asset.h"
|
#include "copium/asset/Asset.h"
|
||||||
#include "copium/asset/AssetRef.h"
|
#include "copium/asset/AssetRef.h"
|
||||||
#include "copium/buffer/CommandBuffer.h"
|
#include "copium/buffer/CommandBuffer.h"
|
||||||
@@ -7,13 +9,12 @@
|
|||||||
#include "copium/sampler/DepthAttachment.h"
|
#include "copium/sampler/DepthAttachment.h"
|
||||||
#include "copium/util/Common.h"
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
#include <vulkan/vulkan.hpp>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class Framebuffer final : public Asset
|
class Framebuffer final : public Asset
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(Framebuffer);
|
CP_DELETE_COPY_AND_MOVE_CTOR(Framebuffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AssetRef<ColorAttachment> colorAttachment;
|
AssetRef<ColorAttachment> colorAttachment;
|
||||||
std::unique_ptr<DepthAttachment> depthAttachment;
|
std::unique_ptr<DepthAttachment> depthAttachment;
|
||||||
@@ -22,6 +23,7 @@ namespace Copium
|
|||||||
|
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Framebuffer(const MetaFile& metaFile);
|
Framebuffer(const MetaFile& metaFile);
|
||||||
Framebuffer(int width, int height, const SamplerCreator& samplerCreator);
|
Framebuffer(int width, int height, const SamplerCreator& samplerCreator);
|
||||||
|
|||||||
@@ -7,9 +7,11 @@ namespace Copium
|
|||||||
IndexBuffer::IndexBuffer(int indexCount)
|
IndexBuffer::IndexBuffer(int indexCount)
|
||||||
: Buffer{VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
|
: Buffer{VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
|
||||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
||||||
indexCount * sizeof(uint16_t), 1},
|
indexCount * sizeof(uint16_t),
|
||||||
|
1},
|
||||||
indexCount{indexCount}
|
indexCount{indexCount}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void IndexBuffer::Bind(const CommandBuffer& commandBuffer)
|
void IndexBuffer::Bind(const CommandBuffer& commandBuffer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ namespace Copium
|
|||||||
class IndexBuffer final : public Buffer
|
class IndexBuffer final : public Buffer
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(IndexBuffer);
|
CP_DELETE_COPY_AND_MOVE_CTOR(IndexBuffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int indexCount;
|
int indexCount;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IndexBuffer(int indexCount);
|
IndexBuffer(int indexCount);
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,12 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
|
|
||||||
RendererVertexBuffer::RendererVertexBuffer(const VertexDescriptor& descriptor, int vertexCount)
|
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)
|
void RendererVertexBuffer::Bind(const CommandBuffer& commandBuffer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace Copium
|
|||||||
class RendererVertexBuffer : public Buffer
|
class RendererVertexBuffer : public Buffer
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(RendererVertexBuffer);
|
CP_DELETE_COPY_AND_MOVE_CTOR(RendererVertexBuffer);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RendererVertexBuffer(const VertexDescriptor& descriptor, int vertexCount);
|
RendererVertexBuffer(const VertexDescriptor& descriptor, int vertexCount);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,11 @@
|
|||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
UniformBuffer::UniformBuffer(ShaderBinding binding)
|
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());
|
buffer.resize(Buffer::GetSize());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <vulkan/vulkan.hpp>
|
||||||
|
|
||||||
#include "copium/buffer/Buffer.h"
|
#include "copium/buffer/Buffer.h"
|
||||||
#include "copium/pipeline/ShaderBinding.h"
|
#include "copium/pipeline/ShaderBinding.h"
|
||||||
#include "copium/util/Common.h"
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include <vulkan/vulkan.hpp>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class UniformBuffer final : public Buffer
|
class UniformBuffer final : public Buffer
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(UniformBuffer);
|
CP_DELETE_COPY_AND_MOVE_CTOR(UniformBuffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ShaderBinding binding;
|
ShaderBinding binding;
|
||||||
std::vector<uint8_t> buffer;
|
std::vector<uint8_t> buffer;
|
||||||
|
|||||||
@@ -3,7 +3,10 @@
|
|||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
VertexBuffer::VertexBuffer(const VertexDescriptor& descriptor, int vertexCount)
|
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;
|
VkDeviceSize offset = 0;
|
||||||
for (auto&& binding : descriptor.GetBindings())
|
for (auto&& binding : descriptor.GetBindings())
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <vulkan/vulkan.hpp>
|
||||||
|
|
||||||
#include "copium/buffer/Buffer.h"
|
#include "copium/buffer/Buffer.h"
|
||||||
#include "copium/buffer/CommandBuffer.h"
|
#include "copium/buffer/CommandBuffer.h"
|
||||||
#include "copium/pipeline/VertexDescriptor.h"
|
#include "copium/pipeline/VertexDescriptor.h"
|
||||||
#include "copium/util/Common.h"
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <vulkan/vulkan.hpp>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class VertexBuffer final : public Buffer
|
class VertexBuffer final : public Buffer
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(VertexBuffer);
|
CP_DELETE_COPY_AND_MOVE_CTOR(VertexBuffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<VkDeviceSize> bindingOffsets;
|
std::vector<VkDeviceSize> bindingOffsets;
|
||||||
std::vector<VkDeviceSize> bindingSizes;
|
std::vector<VkDeviceSize> bindingSizes;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VertexBuffer(const VertexDescriptor& descriptor, int vertexCount);
|
VertexBuffer(const VertexDescriptor& descriptor, int vertexCount);
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ namespace Copium
|
|||||||
VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
|
VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
|
||||||
createInfo.pfnUserCallback = DebugCallback;
|
createInfo.pfnUserCallback = DebugCallback;
|
||||||
createInfo.pUserData = nullptr;
|
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()
|
DebugMessenger::~DebugMessenger()
|
||||||
@@ -38,22 +39,27 @@ namespace Copium
|
|||||||
#else
|
#else
|
||||||
DebugMessenger::DebugMessenger(Instance& instance)
|
DebugMessenger::DebugMessenger(Instance& instance)
|
||||||
: instance{instance}
|
: instance{instance}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
DebugMessenger::~DebugMessenger()
|
DebugMessenger::~DebugMessenger()
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void DebugMessenger::AddRequiredExtensions(std::vector<const char*>* extensions)
|
void DebugMessenger::AddRequiredExtensions(std::vector<const char*>* extensions)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void DebugMessenger::AddRequiredLayers(std::vector<const char*>* layers)
|
void DebugMessenger::AddRequiredLayers(std::vector<const char*>* layers)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VKAPI_ATTR VkBool32 VKAPI_CALL DebugMessenger::DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
VKAPI_ATTR VkBool32 VKAPI_CALL
|
||||||
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
DebugMessenger::DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||||
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
||||||
void* pUserData)
|
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
||||||
|
void* pUserData)
|
||||||
{
|
{
|
||||||
if (messageSeverity >= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT)
|
if (messageSeverity >= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT)
|
||||||
{
|
{
|
||||||
@@ -78,10 +84,12 @@ namespace Copium
|
|||||||
|
|
||||||
void DebugMessenger::vkDestroyDebugUtilsMessengerEXT(VkInstance instance,
|
void DebugMessenger::vkDestroyDebugUtilsMessengerEXT(VkInstance instance,
|
||||||
VkDebugUtilsMessengerEXT debugMessenger,
|
VkDebugUtilsMessengerEXT debugMessenger,
|
||||||
const VkAllocationCallbacks* pAllocator) {
|
const VkAllocationCallbacks* pAllocator)
|
||||||
auto func = (PFN_vkDestroyDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT");
|
{
|
||||||
if (func != nullptr) {
|
auto func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT");
|
||||||
func(instance, debugMessenger, pAllocator);
|
if (func != nullptr)
|
||||||
|
{
|
||||||
|
func(instance, debugMessenger, pAllocator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/util/Common.h"
|
|
||||||
|
|
||||||
#include <vulkan/vulkan.hpp>
|
#include <vulkan/vulkan.hpp>
|
||||||
|
|
||||||
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class Instance;
|
class Instance;
|
||||||
@@ -11,10 +11,12 @@ namespace Copium
|
|||||||
class DebugMessenger final
|
class DebugMessenger final
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(DebugMessenger);
|
CP_DELETE_COPY_AND_MOVE_CTOR(DebugMessenger);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Instance& instance;
|
Instance& instance;
|
||||||
|
|
||||||
VkDebugUtilsMessengerEXT debugMessenger;
|
VkDebugUtilsMessengerEXT debugMessenger;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DebugMessenger(Instance& instance);
|
DebugMessenger(Instance& instance);
|
||||||
~DebugMessenger();
|
~DebugMessenger();
|
||||||
|
|||||||
@@ -115,7 +115,10 @@ namespace Copium
|
|||||||
devicePriorities.emplace_back(device, GetPhysicalDevicePriority(device));
|
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();
|
auto&& it = devicePriorities.begin();
|
||||||
CP_ASSERT(it->second != 0, "Failed to find suitable gpu");
|
CP_ASSERT(it->second != 0, "Failed to find suitable gpu");
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/util/Common.h"
|
|
||||||
|
|
||||||
#include <vulkan/vulkan.hpp>
|
|
||||||
#include <queue>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <queue>
|
||||||
|
#include <vulkan/vulkan.hpp>
|
||||||
|
|
||||||
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class Vulkan;
|
class Vulkan;
|
||||||
|
|
||||||
class Device
|
class Device
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(Device);
|
CP_DELETE_COPY_AND_MOVE_CTOR(Device);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Device();
|
Device();
|
||||||
~Device();
|
~Device();
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#include "ImGuiInstance.h"
|
#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_glfw.h>
|
||||||
#include <backends/imgui_impl_vulkan.h>
|
#include <backends/imgui_impl_vulkan.h>
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
|
#include "copium/buffer/CommandBufferScoped.h"
|
||||||
|
#include "copium/core/Vulkan.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
@@ -92,7 +92,8 @@ namespace Copium
|
|||||||
createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
||||||
createInfo.bindingCount = 1;
|
createInfo.bindingCount = 1;
|
||||||
createInfo.pBindings = layoutBindings.data();
|
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;
|
ShaderBinding binding;
|
||||||
binding.name = "texture";
|
binding.name = "texture";
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include "Instance.h"
|
#include "Instance.h"
|
||||||
|
|
||||||
#include "copium/util/Common.h"
|
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
Instance::Instance(const std::string& applicationName)
|
Instance::Instance(const std::string& applicationName)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ namespace Copium
|
|||||||
class Instance final
|
class Instance final
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(Instance);
|
CP_DELETE_COPY_AND_MOVE_CTOR(Instance);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VkInstance instance;
|
VkInstance instance;
|
||||||
std::unique_ptr<DebugMessenger> debugMessenger;
|
std::unique_ptr<DebugMessenger> debugMessenger;
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <optional>
|
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
struct QueueFamiliesQuery
|
struct QueueFamiliesQuery
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ namespace Copium
|
|||||||
}
|
}
|
||||||
|
|
||||||
SwapChain::SwapChain()
|
SwapChain::SwapChain()
|
||||||
: flightIndex{0}, resizeFramebuffer{false}
|
: flightIndex{0},
|
||||||
|
resizeFramebuffer{false}
|
||||||
{
|
{
|
||||||
Initialize();
|
Initialize();
|
||||||
InitializeImageViews();
|
InitializeImageViews();
|
||||||
@@ -120,7 +121,8 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
vkWaitForFences(Vulkan::GetDevice(), 1, &inFlightFences[flightIndex], VK_TRUE, UINT64_MAX);
|
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)
|
if (result == VK_ERROR_OUT_OF_DATE_KHR)
|
||||||
{
|
{
|
||||||
Recreate();
|
Recreate();
|
||||||
@@ -144,7 +146,8 @@ namespace Copium
|
|||||||
submitInfo.signalSemaphoreCount = 1;
|
submitInfo.signalSemaphoreCount = 1;
|
||||||
submitInfo.pSignalSemaphores = &renderFinishedSemaphores[imageIndex];
|
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()
|
void SwapChain::EndPresent()
|
||||||
@@ -248,7 +251,8 @@ namespace Copium
|
|||||||
createInfo.pQueueFamilyIndices = nullptr;
|
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);
|
vkGetSwapchainImagesKHR(Vulkan::GetDevice(), handle, &imageCount, nullptr);
|
||||||
images.resize(imageCount);
|
images.resize(imageCount);
|
||||||
@@ -308,8 +312,10 @@ namespace Copium
|
|||||||
VkSubpassDependency dependency{};
|
VkSubpassDependency dependency{};
|
||||||
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
|
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
|
||||||
dependency.dstSubpass = 0;
|
dependency.dstSubpass = 0;
|
||||||
dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
|
dependency.srcStageMask =
|
||||||
dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
|
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.srcAccessMask = 0;
|
||||||
dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
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.dependencyCount = 1;
|
||||||
renderPassCreateInfo.pDependencies = &dependency;
|
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()
|
void SwapChain::InitializeFramebuffers()
|
||||||
@@ -343,7 +350,8 @@ namespace Copium
|
|||||||
createInfo.height = extent.height;
|
createInfo.height = extent.height;
|
||||||
createInfo.layers = 1;
|
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;
|
semaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
||||||
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i)
|
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{};
|
VkFenceCreateInfo fenceCreateInfo{};
|
||||||
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||||
fenceCreateInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
|
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());
|
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)
|
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;
|
return availableFormat;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "copium/buffer/CommandBuffer.h"
|
#include "copium/buffer/CommandBuffer.h"
|
||||||
#include "copium/sampler/DepthAttachment.h"
|
#include "copium/sampler/DepthAttachment.h"
|
||||||
#include "copium/util/Common.h"
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
#include <vector>
|
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
struct SwapChainSupportDetails
|
struct SwapChainSupportDetails
|
||||||
@@ -23,8 +24,10 @@ namespace Copium
|
|||||||
class SwapChain final
|
class SwapChain final
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(SwapChain);
|
CP_DELETE_COPY_AND_MOVE_CTOR(SwapChain);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const int MAX_FRAMES_IN_FLIGHT;
|
static const int MAX_FRAMES_IN_FLIGHT;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VkSwapchainKHR handle;
|
VkSwapchainKHR handle;
|
||||||
VkRenderPass renderPass;
|
VkRenderPass renderPass;
|
||||||
|
|||||||
@@ -41,10 +41,13 @@ namespace Copium
|
|||||||
AssetManager::RegisterAssetType<Font>("Font");
|
AssetManager::RegisterAssetType<Font>("Font");
|
||||||
|
|
||||||
// TODO: Make the working directory always be relative to the assets folder
|
// 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/");
|
AssetManager::RegisterAssetDir("assets/");
|
||||||
emptyTexture2D = AssetHandle<Texture2D>{"empty_texture2d", std::make_unique<Texture2D>(std::vector<uint8_t>{255, 0, 255, 255}, 1, 1, SamplerCreator{})};
|
emptyTexture2D = AssetHandle<Texture2D>{
|
||||||
whiteTexture2D = AssetHandle<Texture2D>{"white_texture2d", std::make_unique<Texture2D>(std::vector<uint8_t>{255, 255, 255, 255}, 1, 1, SamplerCreator{})};
|
"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());
|
CP_INFO("Initialized AssetManager in %f seconds", timer.Elapsed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,22 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "copium/asset/AssetHandle.h"
|
#include "copium/asset/AssetHandle.h"
|
||||||
#include "copium/core/Device.h"
|
#include "copium/core/Device.h"
|
||||||
|
#include "copium/core/ImGuiInstance.h"
|
||||||
#include "copium/core/Instance.h"
|
#include "copium/core/Instance.h"
|
||||||
#include "copium/core/SwapChain.h"
|
#include "copium/core/SwapChain.h"
|
||||||
#include "copium/core/Window.h"
|
#include "copium/core/Window.h"
|
||||||
#include "copium/core/ImGuiInstance.h"
|
|
||||||
#include "copium/util/Common.h"
|
|
||||||
#include "copium/sampler/Texture2D.h"
|
#include "copium/sampler/Texture2D.h"
|
||||||
|
#include "copium/util/Common.h"
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class Vulkan
|
class Vulkan
|
||||||
{
|
{
|
||||||
CP_STATIC_CLASS(Vulkan);
|
CP_STATIC_CLASS(Vulkan);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::unique_ptr<Instance> instance;
|
static std::unique_ptr<Instance> instance;
|
||||||
static std::unique_ptr<Window> window;
|
static std::unique_ptr<Window> window;
|
||||||
@@ -25,6 +26,7 @@ namespace Copium
|
|||||||
|
|
||||||
static AssetHandle<Texture2D> emptyTexture2D;
|
static AssetHandle<Texture2D> emptyTexture2D;
|
||||||
static AssetHandle<Texture2D> whiteTexture2D;
|
static AssetHandle<Texture2D> whiteTexture2D;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void Initialize();
|
static void Initialize();
|
||||||
static void Destroy();
|
static void Destroy();
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "copium/core/Window.h"
|
#include "copium/core/Window.h"
|
||||||
|
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#include "copium/core/Vulkan.h"
|
#include "copium/core/Vulkan.h"
|
||||||
#include "copium/event/EventDispatcher.h"
|
#include "copium/event/EventDispatcher.h"
|
||||||
#include "copium/event/Input.h"
|
#include "copium/event/Input.h"
|
||||||
@@ -12,12 +14,11 @@
|
|||||||
#include "copium/event/WindowFocusEvent.h"
|
#include "copium/event/WindowFocusEvent.h"
|
||||||
#include "copium/event/WindowResizeEvent.h"
|
#include "copium/event/WindowResizeEvent.h"
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
Window::Window(const std::string& windowName, int width, int height, WindowMode mode)
|
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);
|
InitializeWindow(windowName, width, height, mode);
|
||||||
InitializeSurface();
|
InitializeSurface();
|
||||||
@@ -75,32 +76,32 @@ namespace Copium
|
|||||||
|
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case WindowMode::Fullscreen:
|
case WindowMode::Fullscreen:
|
||||||
{
|
{
|
||||||
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
||||||
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
||||||
window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), monitor, nullptr);
|
window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), monitor, nullptr);
|
||||||
width = mode->width;
|
width = mode->width;
|
||||||
height = mode->height;
|
height = mode->height;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WindowMode::BorderlessWindowed:
|
case WindowMode::BorderlessWindowed:
|
||||||
{
|
{
|
||||||
const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||||
|
|
||||||
glfwWindowHint(GLFW_DECORATED, false);
|
glfwWindowHint(GLFW_DECORATED, false);
|
||||||
window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), nullptr, nullptr);
|
window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), nullptr, nullptr);
|
||||||
width = mode->width;
|
width = mode->width;
|
||||||
height = mode->height;
|
height = mode->height;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WindowMode::Windowed:
|
case WindowMode::Windowed:
|
||||||
{
|
{
|
||||||
window = glfwCreateWindow(width, height, windowName.c_str(), nullptr, nullptr);
|
window = glfwCreateWindow(width, height, windowName.c_str(), nullptr, nullptr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
CP_ABORT("Unreachable switch case: %s", ToString(mode).c_str());
|
CP_ABORT("Unreachable switch case: %s", ToString(mode).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
CP_ASSERT(window, "Failed to initialize glfw window");
|
CP_ASSERT(window, "Failed to initialize glfw window");
|
||||||
@@ -116,7 +117,8 @@ namespace Copium
|
|||||||
|
|
||||||
void Window::InitializeSurface()
|
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)
|
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)
|
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;
|
return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -148,7 +150,8 @@ namespace Copium
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (RuntimeException& exception)
|
catch (RuntimeException& exception)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::MouseButtonCallback(GLFWwindow* glfwWindow, int button, int action, int mods)
|
void Window::MouseButtonCallback(GLFWwindow* glfwWindow, int button, int action, int mods)
|
||||||
@@ -167,7 +170,8 @@ namespace Copium
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (RuntimeException& exception)
|
catch (RuntimeException& exception)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::MouseMoveCallback(GLFWwindow* glfwWindow, double xpos, double ypos)
|
void Window::MouseMoveCallback(GLFWwindow* glfwWindow, double xpos, double ypos)
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <vulkan/vulkan.hpp>
|
||||||
|
|
||||||
#include "copium/util/Common.h"
|
#include "copium/util/Common.h"
|
||||||
#include "copium/util/Enum.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);
|
CP_ENUM_CREATOR(Copium, WindowMode, CP_WINDOW_MODE_ENUMS);
|
||||||
|
|
||||||
@@ -19,6 +16,7 @@ namespace Copium
|
|||||||
class Window final
|
class Window final
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(Window);
|
CP_DELETE_COPY_AND_MOVE_CTOR(Window);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLFWwindow* window;
|
GLFWwindow* window;
|
||||||
VkSurfaceKHR surface;
|
VkSurfaceKHR surface;
|
||||||
|
|||||||
@@ -12,10 +12,17 @@ namespace Copium
|
|||||||
public:
|
public:
|
||||||
using component_type = Component;
|
using component_type = Component;
|
||||||
friend class ECSManager;
|
friend class ECSManager;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ECSManager* manager;
|
ECSManager* manager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void Added(EntityId entityId, Component& component) {}
|
virtual void Added(EntityId entityId, Component& component)
|
||||||
virtual void Removed(EntityId entityId, Component& component) {}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Removed(EntityId entityId, Component& component)
|
||||||
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +1,32 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "copium/ecs/ComponentListener.h"
|
||||||
|
#include "copium/ecs/ComponentPoolBase.h"
|
||||||
#include "copium/ecs/Config.h"
|
#include "copium/ecs/Config.h"
|
||||||
#include "copium/ecs/EntitySet.h"
|
#include "copium/ecs/EntitySet.h"
|
||||||
#include "copium/ecs/ComponentPoolBase.h"
|
|
||||||
#include "copium/ecs/ComponentListener.h"
|
|
||||||
#include "copium/util/Common.h"
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
template <typename Component>
|
template <typename Component>
|
||||||
class ComponentPool : public ComponentPoolBase
|
class ComponentPool : public ComponentPoolBase
|
||||||
{
|
{
|
||||||
using Iterator = typename std::vector<Component>::iterator;
|
using Iterator = typename std::vector<Component>::iterator;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Component> components;
|
std::vector<Component> components;
|
||||||
ComponentListener<Component>* listener = nullptr;
|
ComponentListener<Component>* listener = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ComponentPool()
|
ComponentPool()
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
~ComponentPool() override
|
~ComponentPool() override
|
||||||
{
|
{
|
||||||
if(listener)
|
if (listener)
|
||||||
delete listener;
|
delete listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +39,7 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
components.push_back(component);
|
components.push_back(component);
|
||||||
entities.Emplace(entity);
|
entities.Emplace(entity);
|
||||||
if(listener)
|
if (listener)
|
||||||
listener->Added(entity, components.back());
|
listener->Added(entity, components.back());
|
||||||
return components.back();
|
return components.back();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "copium/ecs/Config.h"
|
#include "copium/ecs/Config.h"
|
||||||
#include "copium/ecs/EntitySet.h"
|
#include "copium/ecs/EntitySet.h"
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class ComponentPoolBase
|
class ComponentPoolBase
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
EntitySet entities;
|
EntitySet entities;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~ComponentPoolBase() = default;
|
virtual ~ComponentPoolBase() = default;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
ECSManager::ECSManager()
|
ECSManager::ECSManager()
|
||||||
: systemPool{std::make_unique<SystemPool>(this)}
|
: systemPool{std::make_unique<SystemPool>(this)}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
ECSManager::~ECSManager()
|
ECSManager::~ECSManager()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
|
#include <typeindex>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "copium/ecs/ComponentPool.h"
|
#include "copium/ecs/ComponentPool.h"
|
||||||
#include "copium/ecs/Config.h"
|
#include "copium/ecs/Config.h"
|
||||||
@@ -7,11 +11,6 @@
|
|||||||
#include "copium/ecs/SystemPool.h"
|
#include "copium/ecs/SystemPool.h"
|
||||||
#include "copium/util/Common.h"
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <map>
|
|
||||||
#include <typeindex>
|
|
||||||
#include <unordered_set>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class ECSManager final
|
class ECSManager final
|
||||||
@@ -22,6 +21,7 @@ namespace Copium
|
|||||||
|
|
||||||
std::unique_ptr<SystemPool> systemPool;
|
std::unique_ptr<SystemPool> systemPool;
|
||||||
int currentEntityId = 1;
|
int currentEntityId = 1;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ECSManager();
|
ECSManager();
|
||||||
~ECSManager();
|
~ECSManager();
|
||||||
@@ -85,7 +85,10 @@ namespace Copium
|
|||||||
|
|
||||||
if (pool)
|
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);
|
return pool->Emplace(entity, component);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -100,7 +103,10 @@ namespace Copium
|
|||||||
void RemoveComponent(EntityId entity)
|
void RemoveComponent(EntityId entity)
|
||||||
{
|
{
|
||||||
auto pool = GetComponentPoolAssure<Component>();
|
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>
|
template <typename... Components>
|
||||||
@@ -114,7 +120,8 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
auto pool = GetComponentPoolAssure<Component>();
|
auto pool = GetComponentPoolAssure<Component>();
|
||||||
Component* component = pool->FindComponent(entity);
|
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;
|
return *component;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +219,8 @@ namespace Copium
|
|||||||
template <typename Component, typename... Components>
|
template <typename Component, typename... Components>
|
||||||
EntityId Find()
|
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>
|
template <typename T>
|
||||||
@@ -233,7 +241,9 @@ namespace Copium
|
|||||||
ComponentPool<Component>* GetComponentPoolAssure()
|
ComponentPool<Component>* GetComponentPoolAssure()
|
||||||
{
|
{
|
||||||
auto it = componentPool.find(GetComponentId<Component>());
|
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);
|
return static_cast<ComponentPool<Component>*>(it->second);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,16 +3,22 @@
|
|||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
Entity::Entity()
|
Entity::Entity()
|
||||||
: manager{nullptr}, id{INVALID_ENTITY}
|
: manager{nullptr},
|
||||||
{}
|
id{INVALID_ENTITY}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Entity::Entity(ECSManager* manager)
|
Entity::Entity(ECSManager* manager)
|
||||||
: manager{manager}, id{INVALID_ENTITY}
|
: manager{manager},
|
||||||
{}
|
id{INVALID_ENTITY}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Entity::Entity(ECSManager* manager, EntityId id)
|
Entity::Entity(ECSManager* manager, EntityId id)
|
||||||
: manager{manager}, id{id}
|
: manager{manager},
|
||||||
{}
|
id{id}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Entity::operator EntityId() const
|
Entity::operator EntityId() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -55,9 +55,23 @@ namespace Copium
|
|||||||
return entitiesList.size();
|
return entitiesList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<EntityId>& EntitySet::GetList() { return entitiesList; }
|
std::vector<EntityId>& EntitySet::GetList()
|
||||||
const std::vector<EntityId>& EntitySet::GetList() const { return entitiesList; }
|
{
|
||||||
|
return entitiesList;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<EntityId>::iterator EntitySet::begin() { return entitiesList.begin(); }
|
const std::vector<EntityId>& EntitySet::GetList() const
|
||||||
std::vector<EntityId>::iterator EntitySet::end() { return entitiesList.end(); }
|
{
|
||||||
|
return entitiesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<EntityId>::iterator EntitySet::begin()
|
||||||
|
{
|
||||||
|
return entitiesList.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<EntityId>::iterator EntitySet::end()
|
||||||
|
{
|
||||||
|
return entitiesList.end();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/ecs/Config.h"
|
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "copium/ecs/Config.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class EntitySet
|
class EntitySet
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::vector<EntityId> entitiesList;
|
std::vector<EntityId> entitiesList;
|
||||||
std::unordered_map<EntityId, size_t> entitiesMap; // Maps the entity id to a component index
|
std::unordered_map<EntityId, size_t> entitiesMap; // Maps the entity id to a component index
|
||||||
public:
|
public:
|
||||||
bool Emplace(EntityId entity);
|
bool Emplace(EntityId entity);
|
||||||
bool Erase(EntityId entity);
|
bool Erase(EntityId entity);
|
||||||
|
|||||||
@@ -1,31 +1,31 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define CP_SIGNAL_DECLERATION_DEFINITION() \
|
#define CP_SIGNAL_DECLERATION_DEFINITION() \
|
||||||
static int GetIdStatic() \
|
static int GetIdStatic() \
|
||||||
{ \
|
{ \
|
||||||
static int id = GetAllocatedId(); \
|
static int id = GetAllocatedId(); \
|
||||||
return id; \
|
return id; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
int GetId() const \
|
int GetId() const \
|
||||||
{ \
|
{ \
|
||||||
return GetIdStatic(); \
|
return GetIdStatic(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CP_SIGNAL_DECLERATION(SignalClass) \
|
#define CP_SIGNAL_DECLERATION(SignalClass) \
|
||||||
static int GetIdStatic(); \
|
static int GetIdStatic(); \
|
||||||
int GetId() const override
|
int GetId() const override
|
||||||
|
|
||||||
#define CP_SIGNAL_DEFINITION(SignalClass) \
|
#define CP_SIGNAL_DEFINITION(SignalClass) \
|
||||||
int SignalClass::GetIdStatic() \
|
int SignalClass::GetIdStatic() \
|
||||||
{ \
|
{ \
|
||||||
static int id = GetAllocatedId(); \
|
static int id = GetAllocatedId(); \
|
||||||
return id; \
|
return id; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
int SignalClass::GetId() const \
|
int SignalClass::GetId() const \
|
||||||
{ \
|
{ \
|
||||||
return GetIdStatic(); \
|
return GetIdStatic(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/ecs/ECSManager.h"
|
|
||||||
#include "copium/ecs/SystemBase.h"
|
|
||||||
#include "copium/ecs/Entity.h"
|
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
#include "copium/ecs/ECSManager.h"
|
||||||
|
#include "copium/ecs/Entity.h"
|
||||||
|
#include "copium/ecs/SystemBase.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
template <typename... Components>
|
template <typename... Components>
|
||||||
@@ -14,20 +14,22 @@ namespace Copium
|
|||||||
public:
|
public:
|
||||||
void Run() override
|
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
|
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(Entity entity, Components&... components) {};
|
||||||
virtual void RunEntity(const Signal& signal, 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
|
// TODO: Not sure if this is the way entities should be validated
|
||||||
std::set<EntityId> loggedEntities;
|
std::set<EntityId> loggedEntities;
|
||||||
|
|
||||||
bool ValidateEntity(Entity entity)
|
bool ValidateEntity(Entity entity)
|
||||||
{
|
{
|
||||||
if (entity && entity.HasComponents<Components...>())
|
if (entity && entity.HasComponents<Components...>())
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace Copium
|
|||||||
class SystemBase
|
class SystemBase
|
||||||
{
|
{
|
||||||
friend class SystemPool;
|
friend class SystemPool;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ECSManager* manager;
|
ECSManager* manager;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ namespace Copium
|
|||||||
SystemOrderer::SystemOrderer(std::type_index systemId, SystemPool* systemPool)
|
SystemOrderer::SystemOrderer(std::type_index systemId, SystemPool* systemPool)
|
||||||
: systemId{systemId},
|
: systemId{systemId},
|
||||||
systemPool{systemPool}
|
systemPool{systemPool}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void SystemOrderer::Before(const std::type_index& otherSystemId)
|
void SystemOrderer::Before(const std::type_index& otherSystemId)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ namespace Copium
|
|||||||
private:
|
private:
|
||||||
std::type_index systemId;
|
std::type_index systemId;
|
||||||
SystemPool* systemPool = nullptr;
|
SystemPool* systemPool = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SystemOrderer(std::type_index systemId, SystemPool* systemPool);
|
SystemOrderer(std::type_index systemId, SystemPool* systemPool);
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
SystemPool::SystemPool(ECSManager* manager)
|
SystemPool::SystemPool(ECSManager* manager)
|
||||||
: manager{manager}
|
: manager{manager}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
SystemPool::~SystemPool()
|
SystemPool::~SystemPool()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
#pragma once
|
#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 <map>
|
||||||
#include <typeindex>
|
#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
|
namespace Copium
|
||||||
{
|
{
|
||||||
@@ -16,6 +16,7 @@ namespace Copium
|
|||||||
class SystemPool final
|
class SystemPool final
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(SystemPool);
|
CP_DELETE_COPY_AND_MOVE_CTOR(SystemPool);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ECSManager* manager;
|
ECSManager* manager;
|
||||||
std::map<std::type_index, SystemBase*> systems;
|
std::map<std::type_index, SystemBase*> systems;
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ namespace Copium
|
|||||||
|
|
||||||
Event::Event(EventType type)
|
Event::Event(EventType type)
|
||||||
: type{type}
|
: type{type}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
EventType Event::GetType() const
|
EventType Event::GetType() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
EventType type;
|
EventType type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Event(EventType type);
|
Event(EventType type);
|
||||||
|
|
||||||
|
|||||||
@@ -27,15 +27,15 @@ namespace Copium
|
|||||||
EventResult result = eventHandler->OnEvent(*event);
|
EventResult result = eventHandler->OnEvent(*event);
|
||||||
switch (result)
|
switch (result)
|
||||||
{
|
{
|
||||||
case EventResult::Continue:
|
case EventResult::Continue:
|
||||||
continue;
|
continue;
|
||||||
case EventResult::Handled:
|
case EventResult::Handled:
|
||||||
return;
|
return;
|
||||||
case EventResult::Focus:
|
case EventResult::Focus:
|
||||||
focusedEventHandler = eventHandler;
|
focusedEventHandler = eventHandler;
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
CP_ABORT("Unreachable switch case: %s", ToString(result).c_str());
|
CP_ABORT("Unreachable switch case: %s", ToString(result).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <queue>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "copium/event/Event.h"
|
#include "copium/event/Event.h"
|
||||||
#include "copium/event/EventHandler.h"
|
#include "copium/event/EventHandler.h"
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
#include <queue>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class EventDispatcher
|
class EventDispatcher
|
||||||
@@ -15,12 +15,14 @@ namespace Copium
|
|||||||
static EventHandler* focusedEventHandler;
|
static EventHandler* focusedEventHandler;
|
||||||
static std::vector<EventHandler*> eventHandlers;
|
static std::vector<EventHandler*> eventHandlers;
|
||||||
static std::queue<std::unique_ptr<Event>> events;
|
static std::queue<std::unique_ptr<Event>> events;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template <typename EventType>
|
template <typename EventType>
|
||||||
static void QueueEvent(const EventType& event)
|
static void QueueEvent(const EventType& event)
|
||||||
{
|
{
|
||||||
events.push(std::make_unique<EventType>(event));
|
events.push(std::make_unique<EventType>(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Dispatch();
|
static void Dispatch();
|
||||||
static void AddEventHandler(EventHandler* eventHandler);
|
static void AddEventHandler(EventHandler* eventHandler);
|
||||||
static void RemoveEventHandler(EventHandler* eventHandler);
|
static void RemoveEventHandler(EventHandler* eventHandler);
|
||||||
|
|||||||
@@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
#include "copium/util/Enum.h"
|
#include "copium/util/Enum.h"
|
||||||
|
|
||||||
#define CP_EVENT_RESULT_ENUMS \
|
#define CP_EVENT_RESULT_ENUMS Continue, Handled, Focus
|
||||||
Continue, \
|
|
||||||
Handled, \
|
|
||||||
Focus
|
|
||||||
|
|
||||||
CP_ENUM_CREATOR(Copium, EventResult, CP_EVENT_RESULT_ENUMS);
|
CP_ENUM_CREATOR(Copium, EventResult, CP_EVENT_RESULT_ENUMS);
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
EventSignal::EventSignal(const Event& event)
|
EventSignal::EventSignal(const Event& event)
|
||||||
: event{event}
|
: event{event}
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
const Event& EventSignal::GetEvent() const
|
const Event& EventSignal::GetEvent() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/event/Event.h"
|
|
||||||
#include "copium/ecs/Signal.h"
|
#include "copium/ecs/Signal.h"
|
||||||
|
#include "copium/event/Event.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,9 +3,6 @@
|
|||||||
#include "copium/util/Enum.h"
|
#include "copium/util/Enum.h"
|
||||||
|
|
||||||
#define CP_EVENT_TYPE_ENUMS \
|
#define CP_EVENT_TYPE_ENUMS \
|
||||||
MouseMove, MousePress, MouseRelease, MouseScroll, \
|
MouseMove, MousePress, MouseRelease, MouseScroll, KeyPress, KeyRelease, WindowResize, WindowFocus, ViewportResize
|
||||||
KeyPress, KeyRelease, \
|
|
||||||
WindowResize, WindowFocus, \
|
|
||||||
ViewportResize
|
|
||||||
|
|
||||||
CP_ENUM_CREATOR(Copium, EventType, CP_EVENT_TYPE_ENUMS);
|
CP_ENUM_CREATOR(Copium, EventType, CP_EVENT_TYPE_ENUMS);
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#include "copium/event/Input.h"
|
#include "copium/event/Input.h"
|
||||||
|
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
#include "copium/core/Vulkan.h"
|
#include "copium/core/Vulkan.h"
|
||||||
#include "copium/event/InputCode.h"
|
#include "copium/event/InputCode.h"
|
||||||
#include "copium/util/Common.h"
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
bool Input::keyDownList[MAX_NUM_KEYS];
|
bool Input::keyDownList[MAX_NUM_KEYS];
|
||||||
@@ -75,7 +75,8 @@ namespace Copium
|
|||||||
|
|
||||||
glm::vec2 Input::GetMouseWindowPos()
|
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)
|
void Input::OnKey(int keyCode, bool pressed)
|
||||||
@@ -120,128 +121,250 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case CP_KEY_SPACE: return "Space";
|
case CP_KEY_SPACE:
|
||||||
case CP_KEY_APOSTROPHE: return "\'";
|
return "Space";
|
||||||
case CP_KEY_COMMA: return ",";
|
case CP_KEY_APOSTROPHE:
|
||||||
case CP_KEY_MINUS: return "-";
|
return "\'";
|
||||||
case CP_KEY_PERIOD: return ".";
|
case CP_KEY_COMMA:
|
||||||
case CP_KEY_SLASH: return "/";
|
return ",";
|
||||||
case CP_KEY_0: return "0";
|
case CP_KEY_MINUS:
|
||||||
case CP_KEY_1: return "1";
|
return "-";
|
||||||
case CP_KEY_2: return "2";
|
case CP_KEY_PERIOD:
|
||||||
case CP_KEY_3: return "3";
|
return ".";
|
||||||
case CP_KEY_4: return "4";
|
case CP_KEY_SLASH:
|
||||||
case CP_KEY_5: return "5";
|
return "/";
|
||||||
case CP_KEY_6: return "6";
|
case CP_KEY_0:
|
||||||
case CP_KEY_7: return "7";
|
return "0";
|
||||||
case CP_KEY_8: return "8";
|
case CP_KEY_1:
|
||||||
case CP_KEY_9: return "9";
|
return "1";
|
||||||
case CP_KEY_SEMICOLON: return ";";
|
case CP_KEY_2:
|
||||||
case CP_KEY_EQUAL: return "=";
|
return "2";
|
||||||
case CP_KEY_A: return "A";
|
case CP_KEY_3:
|
||||||
case CP_KEY_B: return "B";
|
return "3";
|
||||||
case CP_KEY_C: return "C";
|
case CP_KEY_4:
|
||||||
case CP_KEY_D: return "D";
|
return "4";
|
||||||
case CP_KEY_E: return "E";
|
case CP_KEY_5:
|
||||||
case CP_KEY_F: return "F";
|
return "5";
|
||||||
case CP_KEY_G: return "G";
|
case CP_KEY_6:
|
||||||
case CP_KEY_H: return "H";
|
return "6";
|
||||||
case CP_KEY_I: return "I";
|
case CP_KEY_7:
|
||||||
case CP_KEY_J: return "J";
|
return "7";
|
||||||
case CP_KEY_K: return "K";
|
case CP_KEY_8:
|
||||||
case CP_KEY_L: return "L";
|
return "8";
|
||||||
case CP_KEY_M: return "M";
|
case CP_KEY_9:
|
||||||
case CP_KEY_N: return "N";
|
return "9";
|
||||||
case CP_KEY_O: return "O";
|
case CP_KEY_SEMICOLON:
|
||||||
case CP_KEY_P: return "P";
|
return ";";
|
||||||
case CP_KEY_Q: return "Q";
|
case CP_KEY_EQUAL:
|
||||||
case CP_KEY_R: return "R";
|
return "=";
|
||||||
case CP_KEY_S: return "S";
|
case CP_KEY_A:
|
||||||
case CP_KEY_T: return "T";
|
return "A";
|
||||||
case CP_KEY_U: return "U";
|
case CP_KEY_B:
|
||||||
case CP_KEY_V: return "V";
|
return "B";
|
||||||
case CP_KEY_W: return "W";
|
case CP_KEY_C:
|
||||||
case CP_KEY_X: return "X";
|
return "C";
|
||||||
case CP_KEY_Y: return "Y";
|
case CP_KEY_D:
|
||||||
case CP_KEY_Z: return "Z";
|
return "D";
|
||||||
case CP_KEY_LEFT_BRACKET: return "[";
|
case CP_KEY_E:
|
||||||
case CP_KEY_BACKSLASH: return "\\";
|
return "E";
|
||||||
case CP_KEY_RIGHT_BRACKET: return "]";
|
case CP_KEY_F:
|
||||||
case CP_KEY_GRAVE_ACCENT: return "Grave Accent ?";
|
return "F";
|
||||||
case CP_KEY_WORLD_1: return "World 1 ?";
|
case CP_KEY_G:
|
||||||
case CP_KEY_WORLD_2: return "World 2 ?";
|
return "G";
|
||||||
case CP_KEY_ESCAPE: return "Escape";
|
case CP_KEY_H:
|
||||||
case CP_KEY_ENTER: return "Enter";
|
return "H";
|
||||||
case CP_KEY_TAB: return "Tab";
|
case CP_KEY_I:
|
||||||
case CP_KEY_BACKSPACE: return "Return";
|
return "I";
|
||||||
case CP_KEY_INSERT: return "Insert";
|
case CP_KEY_J:
|
||||||
case CP_KEY_DELETE: return "Delete";
|
return "J";
|
||||||
case CP_KEY_RIGHT: return "Right Arrow";
|
case CP_KEY_K:
|
||||||
case CP_KEY_LEFT: return "Left Arrow";
|
return "K";
|
||||||
case CP_KEY_DOWN: return "Down Arrow";
|
case CP_KEY_L:
|
||||||
case CP_KEY_UP: return "Up Arrow";
|
return "L";
|
||||||
case CP_KEY_PAGE_UP: return "Page Up";
|
case CP_KEY_M:
|
||||||
case CP_KEY_PAGE_DOWN: return "Page Down";
|
return "M";
|
||||||
case CP_KEY_HOME: return "Home";
|
case CP_KEY_N:
|
||||||
case CP_KEY_END: return "End";
|
return "N";
|
||||||
case CP_KEY_CAPS_LOCK: return "Caps Lock";
|
case CP_KEY_O:
|
||||||
case CP_KEY_SCROLL_LOCK: return "Scroll Lock";
|
return "O";
|
||||||
case CP_KEY_NUM_LOCK: return "Num Lock";
|
case CP_KEY_P:
|
||||||
case CP_KEY_PRINT_SCREEN: return "Print Screen";
|
return "P";
|
||||||
case CP_KEY_PAUSE: return "Pause";
|
case CP_KEY_Q:
|
||||||
case CP_KEY_F1: return "F1";
|
return "Q";
|
||||||
case CP_KEY_F2: return "F2";
|
case CP_KEY_R:
|
||||||
case CP_KEY_F3: return "F3";
|
return "R";
|
||||||
case CP_KEY_F4: return "F4";
|
case CP_KEY_S:
|
||||||
case CP_KEY_F5: return "F5";
|
return "S";
|
||||||
case CP_KEY_F6: return "F6";
|
case CP_KEY_T:
|
||||||
case CP_KEY_F7: return "F7";
|
return "T";
|
||||||
case CP_KEY_F8: return "F8";
|
case CP_KEY_U:
|
||||||
case CP_KEY_F9: return "F9";
|
return "U";
|
||||||
case CP_KEY_F10: return "F10";
|
case CP_KEY_V:
|
||||||
case CP_KEY_F11: return "F11";
|
return "V";
|
||||||
case CP_KEY_F12: return "F12";
|
case CP_KEY_W:
|
||||||
case CP_KEY_F13: return "F13";
|
return "W";
|
||||||
case CP_KEY_F14: return "F14";
|
case CP_KEY_X:
|
||||||
case CP_KEY_F15: return "F15";
|
return "X";
|
||||||
case CP_KEY_F16: return "F16";
|
case CP_KEY_Y:
|
||||||
case CP_KEY_F17: return "F17";
|
return "Y";
|
||||||
case CP_KEY_F18: return "F18";
|
case CP_KEY_Z:
|
||||||
case CP_KEY_F19: return "F19";
|
return "Z";
|
||||||
case CP_KEY_F20: return "F20";
|
case CP_KEY_LEFT_BRACKET:
|
||||||
case CP_KEY_F21: return "F21";
|
return "[";
|
||||||
case CP_KEY_F22: return "F22";
|
case CP_KEY_BACKSLASH:
|
||||||
case CP_KEY_F23: return "F23";
|
return "\\";
|
||||||
case CP_KEY_F24: return "F24";
|
case CP_KEY_RIGHT_BRACKET:
|
||||||
case CP_KEY_F25: return "F25";
|
return "]";
|
||||||
case CP_KEY_KP_0: return "Keypad 0";
|
case CP_KEY_GRAVE_ACCENT:
|
||||||
case CP_KEY_KP_1: return "Keypad 1";
|
return "Grave Accent ?";
|
||||||
case CP_KEY_KP_2: return "Keypad 2";
|
case CP_KEY_WORLD_1:
|
||||||
case CP_KEY_KP_3: return "Keypad 3";
|
return "World 1 ?";
|
||||||
case CP_KEY_KP_4: return "Keypad 4";
|
case CP_KEY_WORLD_2:
|
||||||
case CP_KEY_KP_5: return "Keypad 5";
|
return "World 2 ?";
|
||||||
case CP_KEY_KP_6: return "Keypad 6";
|
case CP_KEY_ESCAPE:
|
||||||
case CP_KEY_KP_7: return "Keypad 7";
|
return "Escape";
|
||||||
case CP_KEY_KP_8: return "Keypad 8";
|
case CP_KEY_ENTER:
|
||||||
case CP_KEY_KP_9: return "Keypad 9";
|
return "Enter";
|
||||||
case CP_KEY_KP_DECIMAL: return "Keypad ,";
|
case CP_KEY_TAB:
|
||||||
case CP_KEY_KP_DIVIDE: return "Keypad /";
|
return "Tab";
|
||||||
case CP_KEY_KP_MULTIPLY: return "Keypad *";
|
case CP_KEY_BACKSPACE:
|
||||||
case CP_KEY_KP_SUBTRACT: return "Keypad -";
|
return "Return";
|
||||||
case CP_KEY_KP_ADD: return "Keypad +";
|
case CP_KEY_INSERT:
|
||||||
case CP_KEY_KP_ENTER: return "Keypad Enter";
|
return "Insert";
|
||||||
case CP_KEY_KP_EQUAL: return "Keypad =";
|
case CP_KEY_DELETE:
|
||||||
case CP_KEY_LEFT_SHIFT: return "Left Shift";
|
return "Delete";
|
||||||
case CP_KEY_LEFT_CONTROL: return "Left Control";
|
case CP_KEY_RIGHT:
|
||||||
case CP_KEY_LEFT_ALT: return "Left Alt";
|
return "Right Arrow";
|
||||||
case CP_KEY_LEFT_SUPER: return "Left Super";
|
case CP_KEY_LEFT:
|
||||||
case CP_KEY_RIGHT_SHIFT: return "Right Shift";
|
return "Left Arrow";
|
||||||
case CP_KEY_RIGHT_CONTROL: return "Right Control";
|
case CP_KEY_DOWN:
|
||||||
case CP_KEY_RIGHT_ALT: return "Right Alt";
|
return "Down Arrow";
|
||||||
case CP_KEY_RIGHT_SUPER: return "Right Super";
|
case CP_KEY_UP:
|
||||||
case CP_KEY_MENU: return "Menu";
|
return "Up Arrow";
|
||||||
case CP_KEY_UNBOUND: return "Unbound";
|
case CP_KEY_PAGE_UP:
|
||||||
default: return "Unknown " + std::to_string(key);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/util/BoundingBox.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "copium/util/BoundingBox.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class Input
|
class Input
|
||||||
|
|||||||
@@ -1,129 +1,129 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define CP_MOUSE_LEFT 0
|
#define CP_MOUSE_LEFT 0
|
||||||
#define CP_MOUSE_RIGHT 1
|
#define CP_MOUSE_RIGHT 1
|
||||||
#define CP_MOUSE_MIDDLE 2
|
#define CP_MOUSE_MIDDLE 2
|
||||||
#define CP_MOUSE_BACK 3
|
#define CP_MOUSE_BACK 3
|
||||||
#define CP_MOUSE_FORWARD 4
|
#define CP_MOUSE_FORWARD 4
|
||||||
|
|
||||||
#define CP_KEY_SPACE 32
|
#define CP_KEY_SPACE 32
|
||||||
#define CP_KEY_APOSTROPHE 39
|
#define CP_KEY_APOSTROPHE 39
|
||||||
#define CP_KEY_COMMA 44
|
#define CP_KEY_COMMA 44
|
||||||
#define CP_KEY_MINUS 45
|
#define CP_KEY_MINUS 45
|
||||||
#define CP_KEY_PERIOD 46
|
#define CP_KEY_PERIOD 46
|
||||||
#define CP_KEY_SLASH 47
|
#define CP_KEY_SLASH 47
|
||||||
#define CP_KEY_0 48
|
#define CP_KEY_0 48
|
||||||
#define CP_KEY_1 49
|
#define CP_KEY_1 49
|
||||||
#define CP_KEY_2 50
|
#define CP_KEY_2 50
|
||||||
#define CP_KEY_3 51
|
#define CP_KEY_3 51
|
||||||
#define CP_KEY_4 52
|
#define CP_KEY_4 52
|
||||||
#define CP_KEY_5 53
|
#define CP_KEY_5 53
|
||||||
#define CP_KEY_6 54
|
#define CP_KEY_6 54
|
||||||
#define CP_KEY_7 55
|
#define CP_KEY_7 55
|
||||||
#define CP_KEY_8 56
|
#define CP_KEY_8 56
|
||||||
#define CP_KEY_9 57
|
#define CP_KEY_9 57
|
||||||
#define CP_KEY_SEMICOLON 59
|
#define CP_KEY_SEMICOLON 59
|
||||||
#define CP_KEY_EQUAL 61
|
#define CP_KEY_EQUAL 61
|
||||||
#define CP_KEY_A 65
|
#define CP_KEY_A 65
|
||||||
#define CP_KEY_B 66
|
#define CP_KEY_B 66
|
||||||
#define CP_KEY_C 67
|
#define CP_KEY_C 67
|
||||||
#define CP_KEY_D 68
|
#define CP_KEY_D 68
|
||||||
#define CP_KEY_E 69
|
#define CP_KEY_E 69
|
||||||
#define CP_KEY_F 70
|
#define CP_KEY_F 70
|
||||||
#define CP_KEY_G 71
|
#define CP_KEY_G 71
|
||||||
#define CP_KEY_H 72
|
#define CP_KEY_H 72
|
||||||
#define CP_KEY_I 73
|
#define CP_KEY_I 73
|
||||||
#define CP_KEY_J 74
|
#define CP_KEY_J 74
|
||||||
#define CP_KEY_K 75
|
#define CP_KEY_K 75
|
||||||
#define CP_KEY_L 76
|
#define CP_KEY_L 76
|
||||||
#define CP_KEY_M 77
|
#define CP_KEY_M 77
|
||||||
#define CP_KEY_N 78
|
#define CP_KEY_N 78
|
||||||
#define CP_KEY_O 79
|
#define CP_KEY_O 79
|
||||||
#define CP_KEY_P 80
|
#define CP_KEY_P 80
|
||||||
#define CP_KEY_Q 81
|
#define CP_KEY_Q 81
|
||||||
#define CP_KEY_R 82
|
#define CP_KEY_R 82
|
||||||
#define CP_KEY_S 83
|
#define CP_KEY_S 83
|
||||||
#define CP_KEY_T 84
|
#define CP_KEY_T 84
|
||||||
#define CP_KEY_U 85
|
#define CP_KEY_U 85
|
||||||
#define CP_KEY_V 86
|
#define CP_KEY_V 86
|
||||||
#define CP_KEY_W 87
|
#define CP_KEY_W 87
|
||||||
#define CP_KEY_X 88
|
#define CP_KEY_X 88
|
||||||
#define CP_KEY_Y 89
|
#define CP_KEY_Y 89
|
||||||
#define CP_KEY_Z 90
|
#define CP_KEY_Z 90
|
||||||
#define CP_KEY_LEFT_BRACKET 91
|
#define CP_KEY_LEFT_BRACKET 91
|
||||||
#define CP_KEY_BACKSLASH 92
|
#define CP_KEY_BACKSLASH 92
|
||||||
#define CP_KEY_RIGHT_BRACKET 93
|
#define CP_KEY_RIGHT_BRACKET 93
|
||||||
#define CP_KEY_GRAVE_ACCENT 96
|
#define CP_KEY_GRAVE_ACCENT 96
|
||||||
#define CP_KEY_WORLD_1 161
|
#define CP_KEY_WORLD_1 161
|
||||||
#define CP_KEY_WORLD_2 162
|
#define CP_KEY_WORLD_2 162
|
||||||
#define CP_KEY_ESCAPE 256
|
#define CP_KEY_ESCAPE 256
|
||||||
#define CP_KEY_ENTER 257
|
#define CP_KEY_ENTER 257
|
||||||
#define CP_KEY_TAB 258
|
#define CP_KEY_TAB 258
|
||||||
#define CP_KEY_BACKSPACE 259
|
#define CP_KEY_BACKSPACE 259
|
||||||
#define CP_KEY_INSERT 260
|
#define CP_KEY_INSERT 260
|
||||||
#define CP_KEY_DELETE 261
|
#define CP_KEY_DELETE 261
|
||||||
#define CP_KEY_RIGHT 262
|
#define CP_KEY_RIGHT 262
|
||||||
#define CP_KEY_LEFT 263
|
#define CP_KEY_LEFT 263
|
||||||
#define CP_KEY_DOWN 264
|
#define CP_KEY_DOWN 264
|
||||||
#define CP_KEY_UP 265
|
#define CP_KEY_UP 265
|
||||||
#define CP_KEY_PAGE_UP 266
|
#define CP_KEY_PAGE_UP 266
|
||||||
#define CP_KEY_PAGE_DOWN 267
|
#define CP_KEY_PAGE_DOWN 267
|
||||||
#define CP_KEY_HOME 268
|
#define CP_KEY_HOME 268
|
||||||
#define CP_KEY_END 269
|
#define CP_KEY_END 269
|
||||||
#define CP_KEY_CAPS_LOCK 280
|
#define CP_KEY_CAPS_LOCK 280
|
||||||
#define CP_KEY_SCROLL_LOCK 281
|
#define CP_KEY_SCROLL_LOCK 281
|
||||||
#define CP_KEY_NUM_LOCK 282
|
#define CP_KEY_NUM_LOCK 282
|
||||||
#define CP_KEY_PRINT_SCREEN 283
|
#define CP_KEY_PRINT_SCREEN 283
|
||||||
#define CP_KEY_PAUSE 284
|
#define CP_KEY_PAUSE 284
|
||||||
#define CP_KEY_F1 290
|
#define CP_KEY_F1 290
|
||||||
#define CP_KEY_F2 291
|
#define CP_KEY_F2 291
|
||||||
#define CP_KEY_F3 292
|
#define CP_KEY_F3 292
|
||||||
#define CP_KEY_F4 293
|
#define CP_KEY_F4 293
|
||||||
#define CP_KEY_F5 294
|
#define CP_KEY_F5 294
|
||||||
#define CP_KEY_F6 295
|
#define CP_KEY_F6 295
|
||||||
#define CP_KEY_F7 296
|
#define CP_KEY_F7 296
|
||||||
#define CP_KEY_F8 297
|
#define CP_KEY_F8 297
|
||||||
#define CP_KEY_F9 298
|
#define CP_KEY_F9 298
|
||||||
#define CP_KEY_F10 299
|
#define CP_KEY_F10 299
|
||||||
#define CP_KEY_F11 300
|
#define CP_KEY_F11 300
|
||||||
#define CP_KEY_F12 301
|
#define CP_KEY_F12 301
|
||||||
#define CP_KEY_F13 302
|
#define CP_KEY_F13 302
|
||||||
#define CP_KEY_F14 303
|
#define CP_KEY_F14 303
|
||||||
#define CP_KEY_F15 304
|
#define CP_KEY_F15 304
|
||||||
#define CP_KEY_F16 305
|
#define CP_KEY_F16 305
|
||||||
#define CP_KEY_F17 306
|
#define CP_KEY_F17 306
|
||||||
#define CP_KEY_F18 307
|
#define CP_KEY_F18 307
|
||||||
#define CP_KEY_F19 308
|
#define CP_KEY_F19 308
|
||||||
#define CP_KEY_F20 309
|
#define CP_KEY_F20 309
|
||||||
#define CP_KEY_F21 310
|
#define CP_KEY_F21 310
|
||||||
#define CP_KEY_F22 311
|
#define CP_KEY_F22 311
|
||||||
#define CP_KEY_F23 312
|
#define CP_KEY_F23 312
|
||||||
#define CP_KEY_F24 313
|
#define CP_KEY_F24 313
|
||||||
#define CP_KEY_F25 314
|
#define CP_KEY_F25 314
|
||||||
#define CP_KEY_KP_0 320
|
#define CP_KEY_KP_0 320
|
||||||
#define CP_KEY_KP_1 321
|
#define CP_KEY_KP_1 321
|
||||||
#define CP_KEY_KP_2 322
|
#define CP_KEY_KP_2 322
|
||||||
#define CP_KEY_KP_3 323
|
#define CP_KEY_KP_3 323
|
||||||
#define CP_KEY_KP_4 324
|
#define CP_KEY_KP_4 324
|
||||||
#define CP_KEY_KP_5 325
|
#define CP_KEY_KP_5 325
|
||||||
#define CP_KEY_KP_6 326
|
#define CP_KEY_KP_6 326
|
||||||
#define CP_KEY_KP_7 327
|
#define CP_KEY_KP_7 327
|
||||||
#define CP_KEY_KP_8 328
|
#define CP_KEY_KP_8 328
|
||||||
#define CP_KEY_KP_9 329
|
#define CP_KEY_KP_9 329
|
||||||
#define CP_KEY_KP_DECIMAL 330
|
#define CP_KEY_KP_DECIMAL 330
|
||||||
#define CP_KEY_KP_DIVIDE 331
|
#define CP_KEY_KP_DIVIDE 331
|
||||||
#define CP_KEY_KP_MULTIPLY 332
|
#define CP_KEY_KP_MULTIPLY 332
|
||||||
#define CP_KEY_KP_SUBTRACT 333
|
#define CP_KEY_KP_SUBTRACT 333
|
||||||
#define CP_KEY_KP_ADD 334
|
#define CP_KEY_KP_ADD 334
|
||||||
#define CP_KEY_KP_ENTER 335
|
#define CP_KEY_KP_ENTER 335
|
||||||
#define CP_KEY_KP_EQUAL 336
|
#define CP_KEY_KP_EQUAL 336
|
||||||
#define CP_KEY_LEFT_SHIFT 340
|
#define CP_KEY_LEFT_SHIFT 340
|
||||||
#define CP_KEY_LEFT_CONTROL 341
|
#define CP_KEY_LEFT_CONTROL 341
|
||||||
#define CP_KEY_LEFT_ALT 342
|
#define CP_KEY_LEFT_ALT 342
|
||||||
#define CP_KEY_LEFT_SUPER 343
|
#define CP_KEY_LEFT_SUPER 343
|
||||||
#define CP_KEY_RIGHT_SHIFT 344
|
#define CP_KEY_RIGHT_SHIFT 344
|
||||||
#define CP_KEY_RIGHT_CONTROL 345
|
#define CP_KEY_RIGHT_CONTROL 345
|
||||||
#define CP_KEY_RIGHT_ALT 346
|
#define CP_KEY_RIGHT_ALT 346
|
||||||
#define CP_KEY_RIGHT_SUPER 347
|
#define CP_KEY_RIGHT_SUPER 347
|
||||||
#define CP_KEY_MENU 348
|
#define CP_KEY_MENU 348
|
||||||
#define CP_KEY_UNBOUND 0x0fffffff
|
#define CP_KEY_UNBOUND 0x0fffffff
|
||||||
|
|||||||
@@ -3,8 +3,10 @@
|
|||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
KeyPressEvent::KeyPressEvent(int button)
|
KeyPressEvent::KeyPressEvent(int button)
|
||||||
: Event{EventType::KeyPress}, button{button}
|
: Event{EventType::KeyPress},
|
||||||
{}
|
button{button}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
int KeyPressEvent::GetButton() const
|
int KeyPressEvent::GetButton() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int button;
|
int button;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KeyPressEvent(int button);
|
KeyPressEvent(int button);
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,10 @@
|
|||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
KeyReleaseEvent::KeyReleaseEvent(int button)
|
KeyReleaseEvent::KeyReleaseEvent(int button)
|
||||||
: Event{EventType::KeyRelease}, button{button}
|
: Event{EventType::KeyRelease},
|
||||||
{}
|
button{button}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
int KeyReleaseEvent::GetButton() const
|
int KeyReleaseEvent::GetButton() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int button;
|
int button;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KeyReleaseEvent(int button);
|
KeyReleaseEvent(int button);
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,11 @@
|
|||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
MouseMoveEvent::MouseMoveEvent(glm::vec2 pos, glm::vec2 delta)
|
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
|
glm::vec2 MouseMoveEvent::GetPos() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/event/Event.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
#include "copium/event/Event.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class MouseMoveEvent : public Event
|
class MouseMoveEvent : public Event
|
||||||
@@ -11,6 +11,7 @@ namespace Copium
|
|||||||
private:
|
private:
|
||||||
glm::vec2 pos;
|
glm::vec2 pos;
|
||||||
glm::vec2 delta;
|
glm::vec2 delta;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MouseMoveEvent(glm::vec2 pos, glm::vec2 delta);
|
MouseMoveEvent(glm::vec2 pos, glm::vec2 delta);
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,10 @@
|
|||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
MousePressEvent::MousePressEvent(int button)
|
MousePressEvent::MousePressEvent(int button)
|
||||||
: Event{EventType::MousePress}, button{button}
|
: Event{EventType::MousePress},
|
||||||
{}
|
button{button}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
int MousePressEvent::GetButton() const
|
int MousePressEvent::GetButton() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/event/Event.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
#include "copium/event/Event.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class MousePressEvent : public Event
|
class MousePressEvent : public Event
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int button;
|
int button;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MousePressEvent(int button);
|
MousePressEvent(int button);
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,10 @@
|
|||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
MouseReleaseEvent::MouseReleaseEvent(int button)
|
MouseReleaseEvent::MouseReleaseEvent(int button)
|
||||||
: Event{EventType::MouseRelease}, button{button}
|
: Event{EventType::MouseRelease},
|
||||||
{}
|
button{button}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
int MouseReleaseEvent::GetButton() const
|
int MouseReleaseEvent::GetButton() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/event/Event.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
#include "copium/event/Event.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class MouseReleaseEvent : public Event
|
class MouseReleaseEvent : public Event
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int button;
|
int button;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MouseReleaseEvent(int button);
|
MouseReleaseEvent(int button);
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,11 @@
|
|||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
MouseScrollEvent::MouseScrollEvent(int scrollX, int scrollY)
|
MouseScrollEvent::MouseScrollEvent(int scrollX, int scrollY)
|
||||||
: Event{EventType::MouseScroll}, scrollX{scrollX}, scrollY{scrollY}
|
: Event{EventType::MouseScroll},
|
||||||
{}
|
scrollX{scrollX},
|
||||||
|
scrollY{scrollY}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
int MouseScrollEvent::GetScrollX() const
|
int MouseScrollEvent::GetScrollX() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace Copium
|
|||||||
private:
|
private:
|
||||||
int scrollX;
|
int scrollX;
|
||||||
int scrollY;
|
int scrollY;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MouseScrollEvent(int scrollX, int scrollY);
|
MouseScrollEvent(int scrollX, int scrollY);
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,10 @@
|
|||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
ViewportResize::ViewportResize(const BoundingBox& viewport)
|
ViewportResize::ViewportResize(const BoundingBox& viewport)
|
||||||
: Event(EventType::ViewportResize), viewport{viewport}
|
: Event(EventType::ViewportResize),
|
||||||
{}
|
viewport{viewport}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
const BoundingBox& ViewportResize::GetViewport() const
|
const BoundingBox& ViewportResize::GetViewport() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace Copium
|
|||||||
class ViewportResize : public Event
|
class ViewportResize : public Event
|
||||||
{
|
{
|
||||||
BoundingBox viewport;
|
BoundingBox viewport;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ViewportResize(const BoundingBox& viewport);
|
ViewportResize(const BoundingBox& viewport);
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,10 @@
|
|||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
WindowFocusEvent::WindowFocusEvent(bool focused)
|
WindowFocusEvent::WindowFocusEvent(bool focused)
|
||||||
: Event{EventType::WindowFocus}, focused{focused}
|
: Event{EventType::WindowFocus},
|
||||||
{}
|
focused{focused}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool WindowFocusEvent::IsFocused() const
|
bool WindowFocusEvent::IsFocused() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool focused;
|
bool focused;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WindowFocusEvent(bool focused);
|
WindowFocusEvent(bool focused);
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,11 @@
|
|||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
WindowResizeEvent::WindowResizeEvent(int width, int height)
|
WindowResizeEvent::WindowResizeEvent(int width, int height)
|
||||||
: Event{EventType::WindowResize}, width{width}, height{height}
|
: Event{EventType::WindowResize},
|
||||||
{}
|
width{width},
|
||||||
|
height{height}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
int WindowResizeEvent::GetWidth() const
|
int WindowResizeEvent::GetWidth() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace Copium
|
|||||||
private:
|
private:
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WindowResizeEvent(int width, int height);
|
WindowResizeEvent(int width, int height);
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "copium/buffer/CommandBuffer.h"
|
||||||
#include "copium/buffer/IndexBuffer.h"
|
#include "copium/buffer/IndexBuffer.h"
|
||||||
#include "copium/buffer/VertexBuffer.h"
|
#include "copium/buffer/VertexBuffer.h"
|
||||||
#include "copium/buffer/CommandBuffer.h"
|
|
||||||
#include "copium/util/Common.h"
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class Mesh
|
class Mesh
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(Mesh);
|
CP_DELETE_COPY_AND_MOVE_CTOR(Mesh);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<IndexBuffer> indexBuffer;
|
std::unique_ptr<IndexBuffer> indexBuffer;
|
||||||
std::unique_ptr<VertexBuffer> vertexBuffer;
|
std::unique_ptr<VertexBuffer> vertexBuffer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Mesh(const std::vector<T>& vertices, const std::vector<uint16_t>& indices);
|
Mesh(const std::vector<T>& vertices, const std::vector<uint16_t>& indices);
|
||||||
@@ -30,6 +32,6 @@ namespace Copium
|
|||||||
indexBuffer = std::make_unique<IndexBuffer>(indices.size());
|
indexBuffer = std::make_unique<IndexBuffer>(indices.size());
|
||||||
indexBuffer->UpdateStaging((void*)indices.data());
|
indexBuffer->UpdateStaging((void*)indices.data());
|
||||||
vertexBuffer = std::make_unique<VertexBuffer>(T::GetDescriptor(), vertices.size());
|
vertexBuffer = std::make_unique<VertexBuffer>(T::GetDescriptor(), vertices.size());
|
||||||
vertexBuffer ->UpdateStaging(0, (void*)vertices.data());
|
vertexBuffer->UpdateStaging(0, (void*)vertices.data());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/pipeline/VertexDescriptor.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
#include "copium/pipeline/VertexDescriptor.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
struct Vertex
|
struct Vertex
|
||||||
@@ -15,4 +15,3 @@ namespace Copium
|
|||||||
static VertexDescriptor GetDescriptor();
|
static VertexDescriptor GetDescriptor();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ namespace Copium
|
|||||||
VertexDescriptor VertexPassthrough::GetDescriptor()
|
VertexDescriptor VertexPassthrough::GetDescriptor()
|
||||||
{
|
{
|
||||||
VertexDescriptor descriptor{};
|
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;
|
return descriptor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/pipeline/VertexDescriptor.h"
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
#include "copium/pipeline/VertexDescriptor.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
struct VertexPassthrough
|
struct VertexPassthrough
|
||||||
|
|||||||
@@ -23,23 +23,22 @@ namespace Copium
|
|||||||
poolSizes.emplace_back(descriptorSetPoolSize);
|
poolSizes.emplace_back(descriptorSetPoolSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VkDescriptorPoolCreateInfo createInfo{};
|
VkDescriptorPoolCreateInfo createInfo{};
|
||||||
createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||||
createInfo.poolSizeCount = poolSizes.size();
|
createInfo.poolSizeCount = poolSizes.size();
|
||||||
createInfo.pPoolSizes = poolSizes.data();
|
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;
|
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()
|
DescriptorPool::~DescriptorPool()
|
||||||
{
|
{
|
||||||
VkDescriptorPool descriptorPoolCpy = descriptorPool;
|
VkDescriptorPool descriptorPoolCpy = descriptorPool;
|
||||||
Vulkan::GetDevice().QueueIdleCommand([descriptorPoolCpy]() {
|
Vulkan::GetDevice().QueueIdleCommand([descriptorPoolCpy]()
|
||||||
vkDestroyDescriptorPool(Vulkan::GetDevice(), descriptorPoolCpy, nullptr);
|
{ vkDestroyDescriptorPool(Vulkan::GetDevice(), descriptorPoolCpy, nullptr); });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<VkDescriptorSet> DescriptorPool::AllocateDescriptorSets(VkDescriptorSetLayout descriptorSetLayout)
|
std::vector<VkDescriptorSet> DescriptorPool::AllocateDescriptorSets(VkDescriptorSetLayout descriptorSetLayout)
|
||||||
@@ -52,7 +51,8 @@ namespace Copium
|
|||||||
allocateInfo.descriptorSetCount = descriptorSets.size();
|
allocateInfo.descriptorSetCount = descriptorSets.size();
|
||||||
allocateInfo.pSetLayouts = layouts.data();
|
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;
|
return descriptorSets;
|
||||||
}
|
}
|
||||||
@@ -61,9 +61,12 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
VkDescriptorPool descriptorPoolCpy = descriptorPool;
|
VkDescriptorPool descriptorPoolCpy = descriptorPool;
|
||||||
std::vector<VkDescriptorSet> descriptorSetsCpy = descriptorSets;
|
std::vector<VkDescriptorSet> descriptorSetsCpy = descriptorSets;
|
||||||
Vulkan::GetDevice().QueueIdleCommand([descriptorPoolCpy, descriptorSetsCpy]() {
|
Vulkan::GetDevice().QueueIdleCommand(
|
||||||
vkFreeDescriptorSets(Vulkan::GetDevice(), descriptorPoolCpy, descriptorSetsCpy.size(), descriptorSetsCpy.data());
|
[descriptorPoolCpy, descriptorSetsCpy]()
|
||||||
});
|
{
|
||||||
|
vkFreeDescriptorSets(
|
||||||
|
Vulkan::GetDevice(), descriptorPoolCpy, descriptorSetsCpy.size(), descriptorSetsCpy.data());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
DescriptorPool::operator VkDescriptorPool() const
|
DescriptorPool::operator VkDescriptorPool() const
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/util/Common.h"
|
|
||||||
|
|
||||||
#include <vulkan/vulkan.hpp>
|
#include <vulkan/vulkan.hpp>
|
||||||
|
|
||||||
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class DescriptorPool final
|
class DescriptorPool final
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(DescriptorPool);
|
CP_DELETE_COPY_AND_MOVE_CTOR(DescriptorPool);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VkDescriptorPool descriptorPool;
|
VkDescriptorPool descriptorPool;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DescriptorPool(int uniformDescriptorSets, int imageDescriptorSets);
|
DescriptorPool(int uniformDescriptorSets, int imageDescriptorSets);
|
||||||
~DescriptorPool();
|
~DescriptorPool();
|
||||||
|
|||||||
@@ -4,8 +4,12 @@
|
|||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
DescriptorSet::DescriptorSet(DescriptorPool& descriptorPool, VkDescriptorSetLayout descriptorSetLayout, const std::set<ShaderBinding>& bindings)
|
DescriptorSet::DescriptorSet(DescriptorPool& descriptorPool,
|
||||||
: descriptorPool{descriptorPool}, descriptorSetLayout{descriptorSetLayout}, bindings{bindings}
|
VkDescriptorSetLayout descriptorSetLayout,
|
||||||
|
const std::set<ShaderBinding>& bindings)
|
||||||
|
: descriptorPool{descriptorPool},
|
||||||
|
descriptorSetLayout{descriptorSetLayout},
|
||||||
|
bindings{bindings}
|
||||||
{
|
{
|
||||||
CP_ASSERT(!bindings.empty(), "Cannot initialize DescriptorSet with empty ShaderBindings");
|
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)
|
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()};
|
std::vector<VkWriteDescriptorSet> descriptorWrites{samplers.size()};
|
||||||
for (size_t j = 0; j < samplers.size(); j++)
|
for (size_t j = 0; j < samplers.size(); j++)
|
||||||
{
|
{
|
||||||
@@ -126,7 +131,8 @@ namespace Copium
|
|||||||
|
|
||||||
void DescriptorSet::SetUniformBuffer(const UniformBuffer& uniformBuffer, uint32_t binding)
|
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);
|
VkDescriptorBufferInfo bufferInfo = uniformBuffer.GetDescriptorBufferInfo(i);
|
||||||
|
|
||||||
VkWriteDescriptorSet descriptorWrite{};
|
VkWriteDescriptorSet descriptorWrite{};
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
|
#include <vulkan/vulkan.hpp>
|
||||||
|
|
||||||
#include "copium/buffer/UniformBuffer.h"
|
#include "copium/buffer/UniformBuffer.h"
|
||||||
#include "copium/pipeline/DescriptorPool.h"
|
#include "copium/pipeline/DescriptorPool.h"
|
||||||
#include "copium/pipeline/ShaderBinding.h"
|
#include "copium/pipeline/ShaderBinding.h"
|
||||||
#include "copium/sampler/Sampler.h"
|
#include "copium/sampler/Sampler.h"
|
||||||
#include "copium/util/Common.h"
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include <vulkan/vulkan.hpp>
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <set>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class DescriptorSet final
|
class DescriptorSet final
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(DescriptorSet);
|
CP_DELETE_COPY_AND_MOVE_CTOR(DescriptorSet);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DescriptorPool& descriptorPool;
|
DescriptorPool& descriptorPool;
|
||||||
VkDescriptorSetLayout descriptorSetLayout;
|
VkDescriptorSetLayout descriptorSetLayout;
|
||||||
@@ -27,7 +27,9 @@ namespace Copium
|
|||||||
std::map<std::string, std::unique_ptr<UniformBuffer>> uniformBuffers;
|
std::map<std::string, std::unique_ptr<UniformBuffer>> uniformBuffers;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DescriptorSet(DescriptorPool& descriptorPool, VkDescriptorSetLayout descriptorSetLayout, const std::set<ShaderBinding>& bindings);
|
DescriptorSet(DescriptorPool& descriptorPool,
|
||||||
|
VkDescriptorSetLayout descriptorSetLayout,
|
||||||
|
const std::set<ShaderBinding>& bindings);
|
||||||
~DescriptorSet();
|
~DescriptorSet();
|
||||||
|
|
||||||
void SetSampler(const Sampler& sampler, uint32_t binding, int arrayIndex = 0);
|
void SetSampler(const Sampler& sampler, uint32_t binding, int arrayIndex = 0);
|
||||||
@@ -39,6 +41,7 @@ namespace Copium
|
|||||||
VkDescriptorSet GetVkDescriptorSet(int flightIndex) const;
|
VkDescriptorSet GetVkDescriptorSet(int flightIndex) const;
|
||||||
|
|
||||||
operator VkDescriptorSet() const;
|
operator VkDescriptorSet() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetUniformBuffer(const UniformBuffer& uniformBuffer, uint32_t binding);
|
void SetUniformBuffer(const UniformBuffer& uniformBuffer, uint32_t binding);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,16 +2,17 @@
|
|||||||
|
|
||||||
#include "copium/buffer/Framebuffer.h"
|
#include "copium/buffer/Framebuffer.h"
|
||||||
#include "copium/core/Vulkan.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/Vertex.h"
|
||||||
|
#include "copium/mesh/VertexPassthrough.h"
|
||||||
|
#include "copium/pipeline/Shader.h"
|
||||||
#include "copium/renderer/LineVertex.h"
|
#include "copium/renderer/LineVertex.h"
|
||||||
|
#include "copium/renderer/RendererVertex.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
Pipeline::Pipeline(const MetaFile& metaFile)
|
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");
|
const MetaFileClass& metaFileClass = metaFile.GetMetaClass("Pipeline");
|
||||||
VkRenderPass renderPass;
|
VkRenderPass renderPass;
|
||||||
@@ -25,7 +26,8 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
renderPass = Vulkan::GetSwapChain().GetRenderPass();
|
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");
|
std::string type = metaFileClass.GetValue("type");
|
||||||
if (type == "Renderer")
|
if (type == "Renderer")
|
||||||
{
|
{
|
||||||
@@ -66,14 +68,16 @@ namespace Copium
|
|||||||
VkPipeline graphicsPipelineCpy = graphicsPipeline;
|
VkPipeline graphicsPipelineCpy = graphicsPipeline;
|
||||||
VkPipelineLayout pipelineLayoutCpy = pipelineLayout;
|
VkPipelineLayout pipelineLayoutCpy = pipelineLayout;
|
||||||
std::vector<VkDescriptorSetLayout> descriptorSetLayoutsCpy = descriptorSetLayouts;
|
std::vector<VkDescriptorSetLayout> descriptorSetLayoutsCpy = descriptorSetLayouts;
|
||||||
Vulkan::GetDevice().QueueIdleCommand([graphicsPipelineCpy, pipelineLayoutCpy, descriptorSetLayoutsCpy]() {
|
Vulkan::GetDevice().QueueIdleCommand(
|
||||||
vkDestroyPipeline(Vulkan::GetDevice(), graphicsPipelineCpy, nullptr);
|
[graphicsPipelineCpy, pipelineLayoutCpy, descriptorSetLayoutsCpy]()
|
||||||
vkDestroyPipelineLayout(Vulkan::GetDevice(), pipelineLayoutCpy, nullptr);
|
|
||||||
for (auto&& descriptorSetLayout : 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)
|
void Pipeline::Bind(const CommandBuffer& commandBuffer)
|
||||||
@@ -92,7 +96,14 @@ namespace Copium
|
|||||||
|
|
||||||
void Pipeline::BindDescriptorSets(const CommandBuffer& commandBuffer)
|
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
|
std::unique_ptr<DescriptorSet> Pipeline::CreateDescriptorSet(DescriptorPool& descriptorPool, int setIndex) const
|
||||||
@@ -155,7 +166,8 @@ namespace Copium
|
|||||||
createInfo.bindingCount = layoutBindings.size();
|
createInfo.bindingCount = layoutBindings.size();
|
||||||
createInfo.pBindings = layoutBindings.data();
|
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.offset = {0, 0};
|
||||||
scissor.extent = {1, 1};
|
scissor.extent = {1, 1};
|
||||||
|
|
||||||
std::vector<VkDynamicState> dynamicStates = {
|
std::vector<VkDynamicState> dynamicStates = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR};
|
||||||
VK_DYNAMIC_STATE_VIEWPORT,
|
|
||||||
VK_DYNAMIC_STATE_SCISSOR
|
|
||||||
};
|
|
||||||
|
|
||||||
VkPipelineDynamicStateCreateInfo dynamicStateCreateInfo{};
|
VkPipelineDynamicStateCreateInfo dynamicStateCreateInfo{};
|
||||||
dynamicStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
|
dynamicStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
|
||||||
@@ -239,12 +248,9 @@ namespace Copium
|
|||||||
depthStencilCreateInfo.front = {};
|
depthStencilCreateInfo.front = {};
|
||||||
depthStencilCreateInfo.back = {};
|
depthStencilCreateInfo.back = {};
|
||||||
|
|
||||||
|
VkPipelineColorBlendAttachmentState colorBlendAttachment{}; // TODO: Add to PipelineCreator
|
||||||
VkPipelineColorBlendAttachmentState colorBlendAttachment{}; // TODO: Add to PipelineCreator
|
colorBlendAttachment.colorWriteMask =
|
||||||
colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT |
|
VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_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.blendEnable = creator.blending ? VK_TRUE : VK_FALSE;
|
||||||
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
|
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
|
||||||
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||||
@@ -271,7 +277,8 @@ namespace Copium
|
|||||||
pipelineLayoutCreateInfo.pushConstantRangeCount = 0;
|
pipelineLayoutCreateInfo.pushConstantRangeCount = 0;
|
||||||
pipelineLayoutCreateInfo.pPushConstantRanges = nullptr;
|
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();
|
const std::vector<VkPipelineShaderStageCreateInfo>& shaderStages = shader.GetShaderStages();
|
||||||
VkGraphicsPipelineCreateInfo graphicsPipelineCreateInfo{};
|
VkGraphicsPipelineCreateInfo graphicsPipelineCreateInfo{};
|
||||||
@@ -292,6 +299,8 @@ namespace Copium
|
|||||||
graphicsPipelineCreateInfo.basePipelineHandle = VK_NULL_HANDLE;
|
graphicsPipelineCreateInfo.basePipelineHandle = VK_NULL_HANDLE;
|
||||||
graphicsPipelineCreateInfo.basePipelineIndex = -1;
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <vulkan/vulkan.hpp>
|
||||||
|
|
||||||
#include "copium/asset/Asset.h"
|
#include "copium/asset/Asset.h"
|
||||||
#include "copium/asset/AssetRef.h"
|
#include "copium/asset/AssetRef.h"
|
||||||
#include "copium/buffer/CommandBuffer.h"
|
#include "copium/buffer/CommandBuffer.h"
|
||||||
@@ -8,14 +11,12 @@
|
|||||||
#include "copium/pipeline/PipelineCreator.h"
|
#include "copium/pipeline/PipelineCreator.h"
|
||||||
#include "copium/util/Common.h"
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <vulkan/vulkan.hpp>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class Pipeline final : public Asset
|
class Pipeline final : public Asset
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(Pipeline);
|
CP_DELETE_COPY_AND_MOVE_CTOR(Pipeline);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ShaderReflector shaderReflector;
|
ShaderReflector shaderReflector;
|
||||||
std::vector<VkDescriptorSetLayout> descriptorSetLayouts{};
|
std::vector<VkDescriptorSetLayout> descriptorSetLayouts{};
|
||||||
@@ -25,7 +26,6 @@ namespace Copium
|
|||||||
AssetRef<Framebuffer> framebuffer;
|
AssetRef<Framebuffer> framebuffer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Pipeline(const MetaFile& metaFile);
|
Pipeline(const MetaFile& metaFile);
|
||||||
Pipeline(PipelineCreator creator);
|
Pipeline(PipelineCreator creator);
|
||||||
~Pipeline();
|
~Pipeline();
|
||||||
|
|||||||
@@ -4,7 +4,9 @@
|
|||||||
|
|
||||||
namespace Copium
|
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},
|
: vertexShader{vertexShader},
|
||||||
fragmentShader{fragmentShader},
|
fragmentShader{fragmentShader},
|
||||||
shaderReflector{vertexShader, fragmentShader},
|
shaderReflector{vertexShader, fragmentShader},
|
||||||
@@ -47,7 +49,10 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
for (auto& binding : shaderReflector.bindings)
|
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)
|
switch (type)
|
||||||
{
|
{
|
||||||
case BindingType::Sampler2D:
|
case BindingType::Sampler2D:
|
||||||
return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||||
case BindingType::UniformBuffer:
|
case BindingType::UniformBuffer:
|
||||||
return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||||
default:
|
default:
|
||||||
CP_ABORT("Unhandled switch case");
|
CP_ABORT("Unhandled switch case");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,12 +73,12 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case ShaderType::Vertex:
|
case ShaderType::Vertex:
|
||||||
return VK_SHADER_STAGE_VERTEX_BIT;
|
return VK_SHADER_STAGE_VERTEX_BIT;
|
||||||
case ShaderType::Fragment:
|
case ShaderType::Fragment:
|
||||||
return VK_SHADER_STAGE_FRAGMENT_BIT;
|
return VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||||
default:
|
default:
|
||||||
CP_ABORT("Unhandled switch case");
|
CP_ABORT("Unhandled switch case");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <vulkan/vulkan.hpp>
|
||||||
|
|
||||||
#include "copium/pipeline/ShaderReflector.h"
|
#include "copium/pipeline/ShaderReflector.h"
|
||||||
#include "copium/pipeline/VertexDescriptor.h"
|
#include "copium/pipeline/VertexDescriptor.h"
|
||||||
|
|
||||||
#include <vulkan/vulkan.hpp>
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class PipelineCreator
|
class PipelineCreator
|
||||||
@@ -21,6 +20,7 @@ namespace Copium
|
|||||||
VkShaderStageFlags flags;
|
VkShaderStageFlags flags;
|
||||||
};
|
};
|
||||||
friend class Pipeline;
|
friend class Pipeline;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<uint32_t, std::vector<DescriptorSetBinding>> descriptorSetLayouts{};
|
std::map<uint32_t, std::vector<DescriptorSetBinding>> descriptorSetLayouts{};
|
||||||
|
|
||||||
@@ -45,6 +45,7 @@ namespace Copium
|
|||||||
void SetCullFrontFace(VkFrontFace cullFrontFace);
|
void SetCullFrontFace(VkFrontFace cullFrontFace);
|
||||||
void SetDepthTest(bool depthTest);
|
void SetDepthTest(bool depthTest);
|
||||||
void SetBlending(bool blending);
|
void SetBlending(bool blending);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void AddShaderDescription();
|
void AddShaderDescription();
|
||||||
static VkDescriptorType GetDescriptorType(BindingType type);
|
static VkDescriptorType GetDescriptorType(BindingType type);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
|
|
||||||
#include "copium/util/FileSystem.h"
|
|
||||||
#include "copium/core/Vulkan.h"
|
#include "copium/core/Vulkan.h"
|
||||||
|
#include "copium/util/FileSystem.h"
|
||||||
#include "copium/util/RuntimeException.h"
|
#include "copium/util/RuntimeException.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
@@ -10,24 +10,24 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case ShaderReadType::GlslCode:
|
case ShaderReadType::GlslCode:
|
||||||
vertShaderModule = InitializeShaderModuleFromGlslCode(vertexInput, shaderc_vertex_shader);
|
vertShaderModule = InitializeShaderModuleFromGlslCode(vertexInput, shaderc_vertex_shader);
|
||||||
fragShaderModule = InitializeShaderModuleFromGlslCode(fragmentInput, shaderc_fragment_shader);
|
fragShaderModule = InitializeShaderModuleFromGlslCode(fragmentInput, shaderc_fragment_shader);
|
||||||
break;
|
break;
|
||||||
case ShaderReadType::GlslFile:
|
case ShaderReadType::GlslFile:
|
||||||
vertShaderModule = InitializeShaderModuleFromGlslFile(vertexInput, shaderc_vertex_shader);
|
vertShaderModule = InitializeShaderModuleFromGlslFile(vertexInput, shaderc_vertex_shader);
|
||||||
fragShaderModule = InitializeShaderModuleFromGlslFile(fragmentInput, shaderc_fragment_shader);
|
fragShaderModule = InitializeShaderModuleFromGlslFile(fragmentInput, shaderc_fragment_shader);
|
||||||
break;
|
break;
|
||||||
case ShaderReadType::SpvCode:
|
case ShaderReadType::SpvCode:
|
||||||
vertShaderModule = InitializeShaderModule(vertexInput);
|
vertShaderModule = InitializeShaderModule(vertexInput);
|
||||||
fragShaderModule = InitializeShaderModule(fragmentInput);
|
fragShaderModule = InitializeShaderModule(fragmentInput);
|
||||||
break;
|
break;
|
||||||
case ShaderReadType::SpvFile:
|
case ShaderReadType::SpvFile:
|
||||||
vertShaderModule = InitializeShaderModule(FileSystem::ReadFile(vertexInput));
|
vertShaderModule = InitializeShaderModule(FileSystem::ReadFile(vertexInput));
|
||||||
fragShaderModule = InitializeShaderModule(FileSystem::ReadFile(fragmentInput));
|
fragShaderModule = InitializeShaderModule(FileSystem::ReadFile(fragmentInput));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
CP_ASSERT(false, "Unreachable switch case: %s", ToString(type).c_str());
|
CP_ASSERT(false, "Unreachable switch case: %s", ToString(type).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
shaderStages.resize(2);
|
shaderStages.resize(2);
|
||||||
@@ -48,10 +48,12 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
VkShaderModule vertShaderModuleCpy = vertShaderModule;
|
VkShaderModule vertShaderModuleCpy = vertShaderModule;
|
||||||
VkShaderModule fragShaderModuleCpy = fragShaderModule;
|
VkShaderModule fragShaderModuleCpy = fragShaderModule;
|
||||||
Vulkan::GetDevice().QueueIdleCommand([vertShaderModuleCpy, fragShaderModuleCpy]() {
|
Vulkan::GetDevice().QueueIdleCommand(
|
||||||
vkDestroyShaderModule(Vulkan::GetDevice(), vertShaderModuleCpy, nullptr);
|
[vertShaderModuleCpy, fragShaderModuleCpy]()
|
||||||
vkDestroyShaderModule(Vulkan::GetDevice(), fragShaderModuleCpy, nullptr);
|
{
|
||||||
});
|
vkDestroyShaderModule(Vulkan::GetDevice(), vertShaderModuleCpy, nullptr);
|
||||||
|
vkDestroyShaderModule(Vulkan::GetDevice(), fragShaderModuleCpy, nullptr);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<VkPipelineShaderStageCreateInfo> Shader::GetShaderStages() const
|
const std::vector<VkPipelineShaderStageCreateInfo> Shader::GetShaderStages() const
|
||||||
@@ -100,8 +102,12 @@ namespace Copium
|
|||||||
options.SetOptimizationLevel(shaderc_optimization_level_size);
|
options.SetOptimizationLevel(shaderc_optimization_level_size);
|
||||||
|
|
||||||
std::vector<char> glslCode = FileSystem::ReadFile(filename);
|
std::vector<char> glslCode = FileSystem::ReadFile(filename);
|
||||||
shaderc::SpvCompilationResult result = compiler.CompileGlslToSpv(glslCode.data(), glslCode.size(), type, filename.c_str(), options);
|
shaderc::SpvCompilationResult result =
|
||||||
CP_ASSERT(result.GetCompilationStatus() == shaderc_compilation_status_success, "Failed to compile shader: %s\n%s", filename.c_str(), result.GetErrorMessage().c_str());
|
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()};
|
std::vector<uint32_t> data{result.cbegin(), result.cend()};
|
||||||
FileSystem::WriteFile(spvFilename, (const char*)data.data(), data.size() * sizeof(uint32_t));
|
FileSystem::WriteFile(spvFilename, (const char*)data.data(), data.size() * sizeof(uint32_t));
|
||||||
@@ -116,7 +122,9 @@ namespace Copium
|
|||||||
options.SetOptimizationLevel(shaderc_optimization_level_size);
|
options.SetOptimizationLevel(shaderc_optimization_level_size);
|
||||||
|
|
||||||
shaderc::SpvCompilationResult result = compiler.CompileGlslToSpv(code.data(), type, "inline_shader_code", options);
|
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()};
|
std::vector<uint32_t> data{result.cbegin(), result.cend()};
|
||||||
return InitializeShaderModule(data.data(), data.size() * sizeof(uint32_t));
|
return InitializeShaderModule(data.data(), data.size() * sizeof(uint32_t));
|
||||||
@@ -130,7 +138,8 @@ namespace Copium
|
|||||||
createInfo.pCode = data;
|
createInfo.pCode = data;
|
||||||
|
|
||||||
VkShaderModule shaderModule;
|
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;
|
return shaderModule;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/util/Common.h"
|
|
||||||
#include "copium/util/Enum.h"
|
|
||||||
|
|
||||||
#include <shaderc/shaderc.hpp>
|
#include <shaderc/shaderc.hpp>
|
||||||
#include <vulkan/vulkan.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
|
#define CP_SHADER_READ_TYPE_ENUMS GlslFile, GlslCode, SpvFile, SpvCode
|
||||||
CP_ENUM_CREATOR(Copium, ShaderReadType, CP_SHADER_READ_TYPE_ENUMS);
|
CP_ENUM_CREATOR(Copium, ShaderReadType, CP_SHADER_READ_TYPE_ENUMS);
|
||||||
|
|
||||||
@@ -14,15 +14,18 @@ namespace Copium
|
|||||||
class Shader final
|
class Shader final
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(Shader);
|
CP_DELETE_COPY_AND_MOVE_CTOR(Shader);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VkShaderModule vertShaderModule;
|
VkShaderModule vertShaderModule;
|
||||||
VkShaderModule fragShaderModule;
|
VkShaderModule fragShaderModule;
|
||||||
std::vector<VkPipelineShaderStageCreateInfo> shaderStages;
|
std::vector<VkPipelineShaderStageCreateInfo> shaderStages;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Shader(ShaderReadType type, const std::string& vertexInput, const std::string& fragmentInput);
|
Shader(ShaderReadType type, const std::string& vertexInput, const std::string& fragmentInput);
|
||||||
~Shader();
|
~Shader();
|
||||||
|
|
||||||
const std::vector<VkPipelineShaderStageCreateInfo> GetShaderStages() const;
|
const std::vector<VkPipelineShaderStageCreateInfo> GetShaderStages() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VkShaderModule InitializeShaderModule(const std::vector<uint32_t>& codeSpv);
|
VkShaderModule InitializeShaderModule(const std::vector<uint32_t>& codeSpv);
|
||||||
VkShaderModule InitializeShaderModule(const std::string& codeSpv);
|
VkShaderModule InitializeShaderModule(const std::string& codeSpv);
|
||||||
|
|||||||
@@ -64,22 +64,22 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case UniformType::Mat3:
|
case UniformType::Mat3:
|
||||||
return 4 * 9; // glm::mat3
|
return 4 * 9; // glm::mat3
|
||||||
case UniformType::Mat4:
|
case UniformType::Mat4:
|
||||||
return 4 * 16; // glm::mat4
|
return 4 * 16; // glm::mat4
|
||||||
case UniformType::Vec2:
|
case UniformType::Vec2:
|
||||||
return 4 * 2; // glm::vec2
|
return 4 * 2; // glm::vec2
|
||||||
case UniformType::Vec3:
|
case UniformType::Vec3:
|
||||||
return 4 * 3; // glm::vec3
|
return 4 * 3; // glm::vec3
|
||||||
case UniformType::Vec4:
|
case UniformType::Vec4:
|
||||||
return 4 * 4; // glm::vec4
|
return 4 * 4; // glm::vec4
|
||||||
case UniformType::Int:
|
case UniformType::Int:
|
||||||
return 4; // int
|
return 4; // int
|
||||||
case UniformType::Float:
|
case UniformType::Float:
|
||||||
return 4; // float
|
return 4; // float
|
||||||
default:
|
default:
|
||||||
CP_ABORT("Unhandled switch case: %s", ToString(type).c_str());
|
CP_ABORT("Unhandled switch case: %s", ToString(type).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,22 +87,22 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case UniformType::Mat3:
|
case UniformType::Mat3:
|
||||||
return 64; // alignas(16) glm::mat3
|
return 64; // alignas(16) glm::mat3
|
||||||
case UniformType::Mat4:
|
case UniformType::Mat4:
|
||||||
return 64; // alignas(16) glm::mat4
|
return 64; // alignas(16) glm::mat4
|
||||||
case UniformType::Vec2:
|
case UniformType::Vec2:
|
||||||
return 16; // alignas(16) glm::vec2
|
return 16; // alignas(16) glm::vec2
|
||||||
case UniformType::Vec3:
|
case UniformType::Vec3:
|
||||||
return 16; // alignas(16) glm::vec2
|
return 16; // alignas(16) glm::vec2
|
||||||
case UniformType::Vec4:
|
case UniformType::Vec4:
|
||||||
return 16; // alignas(16) glm::vec2
|
return 16; // alignas(16) glm::vec2
|
||||||
case UniformType::Int:
|
case UniformType::Int:
|
||||||
return 16; // alignas(16) glm::vec2
|
return 16; // alignas(16) glm::vec2
|
||||||
case UniformType::Float:
|
case UniformType::Float:
|
||||||
return 16; // alignas(16) glm::vec2
|
return 16; // alignas(16) glm::vec2
|
||||||
default:
|
default:
|
||||||
CP_ABORT("Unhandled switch case", ToString(type).c_str());
|
CP_ABORT("Unhandled switch case", ToString(type).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/util/Enum.h"
|
#include <cstdint>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
|
#include "copium/util/Enum.h"
|
||||||
|
|
||||||
#define CP_BINDING_TYPE_ENUMS Sampler2D, UniformBuffer
|
#define CP_BINDING_TYPE_ENUMS Sampler2D, UniformBuffer
|
||||||
#define CP_SHADER_TYPE_ENUMS Vertex, Fragment
|
#define CP_SHADER_TYPE_ENUMS Vertex, Fragment
|
||||||
@@ -31,10 +30,11 @@ namespace Copium
|
|||||||
|
|
||||||
bool operator<(const ShaderBinding& rhs) const;
|
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;
|
uint32_t GetUniformSize(const std::string& uniform) const;
|
||||||
UniformType GetUniformType(const std::string& uniform) const;
|
UniformType GetUniformType(const std::string& uniform) const;
|
||||||
uint32_t GetUniformBufferSize() const;
|
uint32_t GetUniformBufferSize() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t GetUniformTypeSize(UniformType type) const;
|
uint32_t GetUniformTypeSize(UniformType type) const;
|
||||||
uint32_t GetUniformTypeOffset(UniformType type) const;
|
uint32_t GetUniformTypeOffset(UniformType type) const;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include "copium/pipeline/ShaderReflector.h"
|
#include "copium/pipeline/ShaderReflector.h"
|
||||||
|
|
||||||
#include "copium/util/FileSystem.h"
|
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
|
#include "copium/util/FileSystem.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -36,12 +36,14 @@ namespace Copium
|
|||||||
|
|
||||||
void ShaderReflector::ParseLine(const std::string& str, int& index)
|
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)
|
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)
|
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
|
// TODO: Make more robust, currently we might get a crash on the string if the glsl file is invalid
|
||||||
index += sizeof("layout") - 1;
|
index += sizeof("layout") - 1;
|
||||||
ParseWhitespace(str, index);
|
ParseWhitespace(str, index);
|
||||||
index++; // "("
|
index++; // "("
|
||||||
ParseWhitespace(str, index);
|
ParseWhitespace(str, index);
|
||||||
if (std::string_view(&str[index], sizeof("set") - 1) != "set")
|
if (std::string_view(&str[index], sizeof("set") - 1) != "set")
|
||||||
{
|
{
|
||||||
@@ -60,29 +62,30 @@ namespace Copium
|
|||||||
shaderBinding.shaderType = shaderType;
|
shaderBinding.shaderType = shaderType;
|
||||||
index += sizeof("set") - 1;
|
index += sizeof("set") - 1;
|
||||||
ParseWhitespace(str, index);
|
ParseWhitespace(str, index);
|
||||||
index++; // "="
|
index++; // "="
|
||||||
ParseWhitespace(str, index);
|
ParseWhitespace(str, index);
|
||||||
char* end;
|
char* end;
|
||||||
shaderBinding.set = std::strtol(&str[index], &end, 10);
|
shaderBinding.set = std::strtol(&str[index], &end, 10);
|
||||||
index = end - str.c_str();
|
index = end - str.c_str();
|
||||||
ParseWhitespace(str, index);
|
ParseWhitespace(str, index);
|
||||||
index++; // ","
|
index++; // ","
|
||||||
ParseWhitespace(str, index);
|
ParseWhitespace(str, index);
|
||||||
index += sizeof("binding") - 1;
|
index += sizeof("binding") - 1;
|
||||||
ParseWhitespace(str, index);
|
ParseWhitespace(str, index);
|
||||||
index++; // "="
|
index++; // "="
|
||||||
ParseWhitespace(str, index);
|
ParseWhitespace(str, index);
|
||||||
shaderBinding.binding = std::strtol(&str[index], &end, 10);
|
shaderBinding.binding = std::strtol(&str[index], &end, 10);
|
||||||
index = end - str.c_str();
|
index = end - str.c_str();
|
||||||
ParseWhitespace(str, index);
|
ParseWhitespace(str, index);
|
||||||
index++; // ")
|
index++; // ")
|
||||||
ParseWhitespace(str, index);
|
ParseWhitespace(str, index);
|
||||||
index += sizeof("uniform") - 1;
|
index += sizeof("uniform") - 1;
|
||||||
ParseWhitespace(str, index);
|
ParseWhitespace(str, index);
|
||||||
|
|
||||||
std::string_view type = ParseWord(str, index);
|
std::string_view type = ParseWord(str, index);
|
||||||
ParseWhitespace(str, index);
|
ParseWhitespace(str, index);
|
||||||
if (str[index] == '{') ParseUniformBuffer(str, index, shaderBinding);
|
if (str[index] == '{')
|
||||||
|
ParseUniformBuffer(str, index, shaderBinding);
|
||||||
ParseWhitespace(str, index);
|
ParseWhitespace(str, index);
|
||||||
std::string_view name = ParseWord(str, index);
|
std::string_view name = ParseWord(str, index);
|
||||||
shaderBinding.name = name;
|
shaderBinding.name = name;
|
||||||
@@ -109,11 +112,10 @@ namespace Copium
|
|||||||
std::string_view ShaderReflector::ParseWord(const std::string& str, int& index)
|
std::string_view ShaderReflector::ParseWord(const std::string& str, int& index)
|
||||||
{
|
{
|
||||||
int start = index;
|
int start = index;
|
||||||
while (((str[index] >= 'a' && str[index] < 'z') ||
|
while (((str[index] >= 'a' && str[index] < 'z') || (str[index] >= 'A' && str[index] < 'Z') ||
|
||||||
(str[index] >= 'A' && str[index] < 'Z') ||
|
|
||||||
(str[index] >= '0' && str[index] <= '9')) ||
|
(str[index] >= '0' && str[index] <= '9')) ||
|
||||||
str[index] == '_' &&
|
str[index] == '_' && index < str.size())
|
||||||
index < str.size()) index++;
|
index++;
|
||||||
return std::string_view(&str[start], index - start);
|
return std::string_view(&str[start], index - start);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +127,7 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
std::string_view type = ParseWord(str, index);
|
std::string_view type = ParseWord(str, index);
|
||||||
ParseWhitespace(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")
|
if (type == "mat3")
|
||||||
binding.uniforms.emplace_back(UniformType::Mat3, std::string(name));
|
binding.uniforms.emplace_back(UniformType::Mat3, std::string(name));
|
||||||
else if (type == "mat4")
|
else if (type == "mat4")
|
||||||
@@ -143,9 +145,10 @@ namespace Copium
|
|||||||
else
|
else
|
||||||
CP_ABORT("Unsupported uniform type=%s", std::string(type).c_str());
|
CP_ABORT("Unsupported uniform type=%s", std::string(type).c_str());
|
||||||
ParseWhitespace(str, index);
|
ParseWhitespace(str, index);
|
||||||
index++; // ";"
|
index++; // ";"
|
||||||
ParseWhitespace(str, index);
|
ParseWhitespace(str, index);
|
||||||
}
|
}
|
||||||
if (index < str.size()) index++; // go past "}"
|
if (index < str.size())
|
||||||
|
index++; // go past "}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user