diff --git a/CopiumEngine/CopiumEngine.vcxproj b/CopiumEngine/CopiumEngine.vcxproj
index 0c0deab..d92d3b9 100644
--- a/CopiumEngine/CopiumEngine.vcxproj
+++ b/CopiumEngine/CopiumEngine.vcxproj
@@ -261,16 +261,6 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/CopiumEngine/CopiumEngine.vcxproj.filters b/CopiumEngine/CopiumEngine.vcxproj.filters
index dce9c0c..46a531e 100644
--- a/CopiumEngine/CopiumEngine.vcxproj.filters
+++ b/CopiumEngine/CopiumEngine.vcxproj.filters
@@ -294,14 +294,4 @@
Header Files
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/CopiumEngine/assets/framebuffer.meta b/CopiumEngine/assets/framebuffer.meta
new file mode 100644
index 0000000..4cb713f
--- /dev/null
+++ b/CopiumEngine/assets/framebuffer.meta
@@ -0,0 +1,3 @@
+[Framebuffer]
+rendertexture-uuid=e59a549e-bb14-991c-0d95-a8e9351fa074
+uuid=91455834-b62b-354e-ee3b-50f7dbe74d28
\ No newline at end of file
diff --git a/CopiumEngine/assets/passthrough.meta b/CopiumEngine/assets/passthrough.meta
new file mode 100644
index 0000000..d1c57a7
--- /dev/null
+++ b/CopiumEngine/assets/passthrough.meta
@@ -0,0 +1,5 @@
+[Pipeline]
+vert-filepath=res/shaders/passthrough.vert
+frag-filepath=res/shaders/passthrough.frag
+type=Passthrough
+uuid=8fdcfe12-5c69-cf29-2f31-e177d6267e4e
\ No newline at end of file
diff --git a/CopiumEngine/assets/pipeline.meta b/CopiumEngine/assets/pipeline.meta
new file mode 100644
index 0000000..29400f5
--- /dev/null
+++ b/CopiumEngine/assets/pipeline.meta
@@ -0,0 +1,6 @@
+[Pipeline]
+vert-filepath=res/shaders/shader.vert
+frag-filepath=res/shaders/shader.frag
+framebuffer-uuid=91455834-b62b-354e-ee3b-50f7dbe74d28
+type=Mesh
+uuid=37082163-6f99-bded-1617-6220c84e3c2a
\ No newline at end of file
diff --git a/CopiumEngine/assets/renderer.meta b/CopiumEngine/assets/renderer.meta
new file mode 100644
index 0000000..21e6382
--- /dev/null
+++ b/CopiumEngine/assets/renderer.meta
@@ -0,0 +1,6 @@
+[Pipeline]
+vert-filepath=res/shaders/renderer.vert
+frag-filepath=res/shaders/renderer.frag
+framebuffer-uuid=91455834-b62b-354e-ee3b-50f7dbe74d28
+type=Renderer
+uuid=59c56410-000b-70ca-1ae1-4568fb7856f7
\ No newline at end of file
diff --git a/CopiumEngine/assets/rendertexture.meta b/CopiumEngine/assets/rendertexture.meta
new file mode 100644
index 0000000..1c7e6b1
--- /dev/null
+++ b/CopiumEngine/assets/rendertexture.meta
@@ -0,0 +1,2 @@
+[RenderTexture]
+uuid=e59a549e-bb14-991c-0d95-a8e9351fa074
\ No newline at end of file
diff --git a/CopiumEngine/res/shaders/passthrough.vert b/CopiumEngine/res/shaders/passthrough.vert
index 17f81cc..86866a7 100644
--- a/CopiumEngine/res/shaders/passthrough.vert
+++ b/CopiumEngine/res/shaders/passthrough.vert
@@ -6,6 +6,6 @@ layout(location = 0) out vec2 outTexCoord;
void main()
{
- gl_Position = vec4(inPosition * 0.5, 0.999, 1.0);
+ gl_Position = vec4(inPosition, 0.0, 1.0);
outTexCoord = inPosition * 0.5 + 0.5;
}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/asset/Asset.cpp b/CopiumEngine/src/copium/asset/Asset.cpp
index 67b0d01..4f04c17 100644
--- a/CopiumEngine/src/copium/asset/Asset.cpp
+++ b/CopiumEngine/src/copium/asset/Asset.cpp
@@ -2,11 +2,7 @@
namespace Copium
{
- Asset::Asset(AssetType type)
- {
- metaData.type = type;
- }
-
+ Asset::Asset() = default;
Asset::~Asset() = default;
AssetHandle Asset::GetHandle() const
@@ -14,11 +10,6 @@ namespace Copium
return metaData.handle;
}
- AssetType Asset::GetType() const
- {
- return metaData.type;
- }
-
const std::string& Asset::GetName() const
{
return metaData.name;
diff --git a/CopiumEngine/src/copium/asset/Asset.h b/CopiumEngine/src/copium/asset/Asset.h
index 1c0ac7e..a66e6be 100644
--- a/CopiumEngine/src/copium/asset/Asset.h
+++ b/CopiumEngine/src/copium/asset/Asset.h
@@ -13,11 +13,10 @@ namespace Copium
{
friend class AssetManager;
public:
- Asset(AssetType type);
+ Asset();
virtual ~Asset();
AssetHandle GetHandle() const;
- AssetType GetType() const;
const std::string& GetName() const;
UUID GetUUID() const;
bool isRuntime() const;
diff --git a/CopiumEngine/src/copium/asset/AssetFile.cpp b/CopiumEngine/src/copium/asset/AssetFile.cpp
index 1e6f10f..a302af5 100644
--- a/CopiumEngine/src/copium/asset/AssetFile.cpp
+++ b/CopiumEngine/src/copium/asset/AssetFile.cpp
@@ -4,6 +4,8 @@
namespace Copium
{
+ std::vector AssetFile::assetTypes;
+
AssetFile::AssetFile(const std::string& path)
: path{path}
{
@@ -17,17 +19,16 @@ namespace Copium
void AssetFile::Load()
{
- const std::vector> strToType{{"Texture2D", AssetType::Texture2D}};
MetaFile metaFile{path};
- for (auto&& [str, type] : strToType)
+ for (auto&& assetType : assetTypes)
{
- if (!metaFile.HasMetaClass(str))
+ if (!metaFile.HasMetaClass(assetType))
continue;
- Load(metaFile, str, type);
+ Load(metaFile, assetType);
return;
}
- CP_ABORT("Unknown Asset type");
+ CP_WARN("Unknown Asset type in file: %s", metaFile.GetFilePath().c_str());
}
const std::string& AssetFile::GetPath() const
@@ -40,11 +41,15 @@ namespace Copium
return uuid;
}
- void AssetFile::Load(const MetaFile& metaFile, const std::string& className, AssetType assetType)
+ void AssetFile::Load(const MetaFile& metaFile, const std::string& className)
{
const MetaFileClass& metaClass = metaFile.GetMetaClass(className);
uuid = UUID{metaClass.GetValue("uuid")};
- type = assetType;
dateModified = FileSystem::DateModified(path);
}
+
+ void AssetFile::RegisterAssetType(const std::string& assetType)
+ {
+ assetTypes.emplace_back(assetType);
+ }
}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/asset/AssetFile.h b/CopiumEngine/src/copium/asset/AssetFile.h
index 804115a..629d375 100644
--- a/CopiumEngine/src/copium/asset/AssetFile.h
+++ b/CopiumEngine/src/copium/asset/AssetFile.h
@@ -8,9 +8,10 @@ namespace Copium
{
class AssetFile
{
+ friend class AssetManager;
private:
+ static std::vector assetTypes;
std::string path;
- AssetType type;
UUID uuid;
int64_t dateModified;
@@ -23,6 +24,7 @@ namespace Copium
const std::string& GetPath() const;
UUID GetUUID() const;
private:
- void Load(const MetaFile& metaFile, const std::string& className, AssetType assetType);
+ void Load(const MetaFile& metaFile, const std::string& className);
+ static void RegisterAssetType(const std::string& assetType);
};
}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/asset/AssetManager.cpp b/CopiumEngine/src/copium/asset/AssetManager.cpp
index 78ec3b1..a5fefd5 100644
--- a/CopiumEngine/src/copium/asset/AssetManager.cpp
+++ b/CopiumEngine/src/copium/asset/AssetManager.cpp
@@ -1,5 +1,7 @@
#include "copium/asset/AssetManager.h"
+#include "copium/buffer/Framebuffer.h"
+#include "copium/sampler/ColorAttachment.h"
#include "copium/sampler/Texture2D.h"
#include "copium/util/Common.h"
#include "copium/util/MetaFile.h"
@@ -10,6 +12,7 @@
namespace Copium
{
std::vector AssetManager::assetDirs;
+ std::map AssetManager::assetTypes;
std::map> AssetManager::assets;
std::map AssetManager::pathToAssetCache;
std::map AssetManager::nameToAssetCache;
@@ -27,10 +30,17 @@ namespace Copium
if (std::filesystem::is_directory(it->path()))
continue;
std::filesystem::path assetDirPath{assetDir};
- cachedAssetFiles.emplace_back(assetDir + "/" + std::filesystem::absolute(it->path()).string().substr(std::filesystem::absolute(assetDirPath).string().size()).c_str());
+ std::string assetPath = assetDir + "/" + std::filesystem::absolute(it->path()).string().substr(std::filesystem::absolute(assetDirPath).string().size() + 1).c_str();
+ try
+ {
+ CP_DEBUG("Registering Asset: %s", assetPath.c_str());
+ cachedAssetFiles.emplace_back(assetPath);
+ }
+ catch (RuntimeException& exception)
+ {
+ CP_ERR("Failed to register Asset: %s", assetPath.c_str());
+ }
}
- UUID uuid{};
- CP_INFO(uuid.ToString().c_str());
}
void AssetManager::UnregisterAssetDir(std::string assetDir)
@@ -62,20 +72,12 @@ namespace Copium
for (auto& dir : assetDirs)
{
std::string path = dir + "/" + assetPath;
- auto it = pathToAssetCache.find(path);
- if (it != pathToAssetCache.end())
- return *assets.find(it->second)->second.get();
-
std::ifstream file{path};
if (!file.good())
continue;
+ file.close();
- MetaFile metaFile{path};
- if (metaFile.HasMetaClass("Texture2D"))
- {
- return CreateAsset(metaFile, "Texture2D");
- }
- CP_ABORT("Unknown Asset type: %s/%s", dir.c_str(), assetPath.c_str());
+ return LoadAssetFromPath(path);
}
CP_ABORT("Unknown Asset: %s", assetPath.c_str());
}
@@ -86,26 +88,13 @@ namespace Copium
CP_DEBUG("Loading uuid Asset: %s", uuid.ToString().c_str());
for (auto&& assetFile : cachedAssetFiles)
{
- if (assetFile.GetUUID() != uuid)
- continue;
-
if (assetFile.NeedReload())
assetFile.Load();
if (assetFile.GetUUID() != uuid)
continue;
- CP_DEBUG("Loading Asset: %s", assetFile.GetPath().c_str());
- auto it = pathToAssetCache.find(assetFile.GetPath());
- if (it != pathToAssetCache.end())
- return *assets.find(it->second)->second.get();
-
- MetaFile metaFile{assetFile.GetPath()};
- if (metaFile.HasMetaClass("Texture2D"))
- {
- return CreateAsset(metaFile, "Texture2D");
- }
- CP_ABORT("Unknown Asset type: %s", assetFile.GetPath().c_str());
+ return LoadAssetFromPath(assetFile.GetPath());
}
CP_ABORT("Asset not found with uuid=%s", uuid.ToString().c_str());
// TODO: Reload the assetCache to see if a new file has appeared with that uuid
@@ -114,7 +103,16 @@ namespace Copium
void AssetManager::UnloadAsset(AssetHandle handle)
{
auto it = assets.find(handle);
- CP_ASSERT(it != assets.end(), "Asset not loaded");
+ if (it == assets.end())
+ {
+ CP_WARN("Asset not loaded");
+ return;
+ }
+ CP_DEBUG("Unloading Asset: %s", it->second->GetName().c_str());
+
+ it->second->metaData.loadCount--;
+ if (it->second->metaData.loadCount > 0)
+ return;
if (it->second->isRuntime())
nameToAssetCache.erase(it->second->GetName());
@@ -127,14 +125,19 @@ namespace Copium
{
if (assets.empty())
return;
- CP_WARN("Cleaning up %d loaded assets", assets.size());
- assets.clear();
- nameToAssetCache.clear();
- pathToAssetCache.clear();
+ CP_WARN("Performing auto clean up of %d non unloaded assets", assets.size());
+ while (!assets.empty())
+ {
+ UnloadAsset(assets.begin()->second->GetHandle());
+ }
+ CP_ASSERT(nameToAssetCache.empty(), "Name To Asset Cache not empty after full unload");
+ CP_ASSERT(pathToAssetCache.empty(), "Path To Asset Cache not empty after full unload");
}
Asset& AssetManager::RegisterRuntimeAsset(const std::string& name, std::unique_ptr&& asset)
{
+ CP_DEBUG("Registering Runtime Asset: %s", name.c_str());
+
auto it = nameToAssetCache.find(name);
CP_ASSERT(it == nameToAssetCache.end(), "Asset already exists: %s", name);
@@ -148,16 +151,23 @@ namespace Copium
return *asset2;
}
- template
- Asset& AssetManager::CreateAsset(const MetaFile& metaFile, const std::string& metaFileClass)
+ Asset& AssetManager::LoadAssetFromPath(const std::string& filepath)
{
- AssetHandle handle = assetHandle++;
- pathToAssetCache.emplace(metaFile.GetFilePath(), handle);
- Asset& asset = *assets.emplace(handle, std::make_unique(metaFile)).first->second.get();
- asset.metaData.handle = handle;
- asset.metaData.name = metaFile.GetFilePath();
- asset.metaData.uuid = UUID{metaFile.GetMetaClass(metaFileClass).GetValue("uuid")};
- asset.metaData.isRuntime = false;
- return asset;
+ CP_DEBUG("Loading Asset: %s", filepath.c_str());
+ auto it = pathToAssetCache.find(filepath);
+ if (it != pathToAssetCache.end())
+ {
+ auto itAsset = assets.find(it->second);
+ itAsset->second->metaData.loadCount++;
+ return *itAsset->second.get();
+ }
+
+ MetaFile metaFile{filepath};
+ for (auto& assetType : assetTypes)
+ {
+ if(metaFile.HasMetaClass(assetType.first))
+ return assetType.second(metaFile, assetType.first);
+ }
+ CP_ABORT("Unknown Asset type: %s", filepath.c_str());
}
}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/asset/AssetManager.h b/CopiumEngine/src/copium/asset/AssetManager.h
index 527c98a..feeb3e5 100644
--- a/CopiumEngine/src/copium/asset/AssetManager.h
+++ b/CopiumEngine/src/copium/asset/AssetManager.h
@@ -4,6 +4,7 @@
#include "copium/asset/AssetFile.h"
#include "copium/util/Common.h"
+#include
#include