Add additional Asset types
- Add Framebuffer Asset - Add Pipeline Asset - Add RenderTexture Asset
This commit is contained in:
@@ -261,16 +261,6 @@
|
|||||||
<ClInclude Include="src\copium\util\VulkanException.h" />
|
<ClInclude Include="src\copium\util\VulkanException.h" />
|
||||||
<ClInclude Include="src\copium\mesh\VertexPassthrough.h" />
|
<ClInclude Include="src\copium\mesh\VertexPassthrough.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<None Include="assets\fox.meta" />
|
|
||||||
<None Include="assets\fox2.meta" />
|
|
||||||
<None Include="res\shaders\passthrough.frag" />
|
|
||||||
<None Include="res\shaders\passthrough.vert" />
|
|
||||||
<None Include="res\shaders\renderer.frag" />
|
|
||||||
<None Include="res\shaders\renderer.vert" />
|
|
||||||
<None Include="res\shaders\shader.frag" />
|
|
||||||
<None Include="res\shaders\shader.vert" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
|||||||
@@ -294,14 +294,4 @@
|
|||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<None Include="res\shaders\shader.frag" />
|
|
||||||
<None Include="res\shaders\shader.vert" />
|
|
||||||
<None Include="res\shaders\passthrough.frag" />
|
|
||||||
<None Include="res\shaders\passthrough.vert" />
|
|
||||||
<None Include="res\shaders\renderer.frag" />
|
|
||||||
<None Include="res\shaders\renderer.vert" />
|
|
||||||
<None Include="assets\fox.meta" />
|
|
||||||
<None Include="assets\fox2.meta" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[Framebuffer]
|
||||||
|
rendertexture-uuid=e59a549e-bb14-991c-0d95-a8e9351fa074
|
||||||
|
uuid=91455834-b62b-354e-ee3b-50f7dbe74d28
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
[RenderTexture]
|
||||||
|
uuid=e59a549e-bb14-991c-0d95-a8e9351fa074
|
||||||
@@ -6,6 +6,6 @@ layout(location = 0) out vec2 outTexCoord;
|
|||||||
|
|
||||||
void main()
|
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;
|
outTexCoord = inPosition * 0.5 + 0.5;
|
||||||
}
|
}
|
||||||
@@ -2,11 +2,7 @@
|
|||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
Asset::Asset(AssetType type)
|
Asset::Asset() = default;
|
||||||
{
|
|
||||||
metaData.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
Asset::~Asset() = default;
|
Asset::~Asset() = default;
|
||||||
|
|
||||||
AssetHandle Asset::GetHandle() const
|
AssetHandle Asset::GetHandle() const
|
||||||
@@ -14,11 +10,6 @@ namespace Copium
|
|||||||
return metaData.handle;
|
return metaData.handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetType Asset::GetType() const
|
|
||||||
{
|
|
||||||
return metaData.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& Asset::GetName() const
|
const std::string& Asset::GetName() const
|
||||||
{
|
{
|
||||||
return metaData.name;
|
return metaData.name;
|
||||||
|
|||||||
@@ -13,11 +13,10 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
friend class AssetManager;
|
friend class AssetManager;
|
||||||
public:
|
public:
|
||||||
Asset(AssetType type);
|
Asset();
|
||||||
virtual ~Asset();
|
virtual ~Asset();
|
||||||
|
|
||||||
AssetHandle GetHandle() const;
|
AssetHandle GetHandle() const;
|
||||||
AssetType GetType() const;
|
|
||||||
const std::string& GetName() const;
|
const std::string& GetName() const;
|
||||||
UUID GetUUID() const;
|
UUID GetUUID() const;
|
||||||
bool isRuntime() const;
|
bool isRuntime() const;
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
|
std::vector<std::string> AssetFile::assetTypes;
|
||||||
|
|
||||||
AssetFile::AssetFile(const std::string& path)
|
AssetFile::AssetFile(const std::string& path)
|
||||||
: path{path}
|
: path{path}
|
||||||
{
|
{
|
||||||
@@ -17,17 +19,16 @@ namespace Copium
|
|||||||
|
|
||||||
void AssetFile::Load()
|
void AssetFile::Load()
|
||||||
{
|
{
|
||||||
const std::vector<std::pair<std::string, AssetType>> strToType{{"Texture2D", AssetType::Texture2D}};
|
|
||||||
MetaFile metaFile{path};
|
MetaFile metaFile{path};
|
||||||
for (auto&& [str, type] : strToType)
|
for (auto&& assetType : assetTypes)
|
||||||
{
|
{
|
||||||
if (!metaFile.HasMetaClass(str))
|
if (!metaFile.HasMetaClass(assetType))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Load(metaFile, str, type);
|
Load(metaFile, assetType);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CP_ABORT("Unknown Asset type");
|
CP_WARN("Unknown Asset type in file: %s", metaFile.GetFilePath().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& AssetFile::GetPath() const
|
const std::string& AssetFile::GetPath() const
|
||||||
@@ -40,11 +41,15 @@ namespace Copium
|
|||||||
return uuid;
|
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);
|
const MetaFileClass& metaClass = metaFile.GetMetaClass(className);
|
||||||
uuid = UUID{metaClass.GetValue("uuid")};
|
uuid = UUID{metaClass.GetValue("uuid")};
|
||||||
type = assetType;
|
|
||||||
dateModified = FileSystem::DateModified(path);
|
dateModified = FileSystem::DateModified(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AssetFile::RegisterAssetType(const std::string& assetType)
|
||||||
|
{
|
||||||
|
assetTypes.emplace_back(assetType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,9 +8,10 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
class AssetFile
|
class AssetFile
|
||||||
{
|
{
|
||||||
|
friend class AssetManager;
|
||||||
private:
|
private:
|
||||||
|
static std::vector<std::string> assetTypes;
|
||||||
std::string path;
|
std::string path;
|
||||||
AssetType type;
|
|
||||||
UUID uuid;
|
UUID uuid;
|
||||||
int64_t dateModified;
|
int64_t dateModified;
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ namespace Copium
|
|||||||
const std::string& GetPath() const;
|
const std::string& GetPath() const;
|
||||||
UUID GetUUID() const;
|
UUID GetUUID() const;
|
||||||
private:
|
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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "copium/asset/AssetManager.h"
|
#include "copium/asset/AssetManager.h"
|
||||||
|
|
||||||
|
#include "copium/buffer/Framebuffer.h"
|
||||||
|
#include "copium/sampler/ColorAttachment.h"
|
||||||
#include "copium/sampler/Texture2D.h"
|
#include "copium/sampler/Texture2D.h"
|
||||||
#include "copium/util/Common.h"
|
#include "copium/util/Common.h"
|
||||||
#include "copium/util/MetaFile.h"
|
#include "copium/util/MetaFile.h"
|
||||||
@@ -10,6 +12,7 @@
|
|||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
std::vector<std::string> AssetManager::assetDirs;
|
std::vector<std::string> AssetManager::assetDirs;
|
||||||
|
std::map<std::string, AssetManager::CreateAssetFunc> AssetManager::assetTypes;
|
||||||
std::map<AssetHandle, std::unique_ptr<Asset>> AssetManager::assets;
|
std::map<AssetHandle, std::unique_ptr<Asset>> AssetManager::assets;
|
||||||
std::map<std::string, AssetHandle> AssetManager::pathToAssetCache;
|
std::map<std::string, AssetHandle> AssetManager::pathToAssetCache;
|
||||||
std::map<std::string, AssetHandle> AssetManager::nameToAssetCache;
|
std::map<std::string, AssetHandle> AssetManager::nameToAssetCache;
|
||||||
@@ -27,10 +30,17 @@ 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};
|
||||||
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)
|
void AssetManager::UnregisterAssetDir(std::string assetDir)
|
||||||
@@ -62,20 +72,12 @@ namespace Copium
|
|||||||
for (auto& dir : assetDirs)
|
for (auto& dir : assetDirs)
|
||||||
{
|
{
|
||||||
std::string path = dir + "/" + assetPath;
|
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};
|
std::ifstream file{path};
|
||||||
if (!file.good())
|
if (!file.good())
|
||||||
continue;
|
continue;
|
||||||
|
file.close();
|
||||||
|
|
||||||
MetaFile metaFile{path};
|
return LoadAssetFromPath(path);
|
||||||
if (metaFile.HasMetaClass("Texture2D"))
|
|
||||||
{
|
|
||||||
return CreateAsset<Texture2D>(metaFile, "Texture2D");
|
|
||||||
}
|
|
||||||
CP_ABORT("Unknown Asset type: %s/%s", dir.c_str(), assetPath.c_str());
|
|
||||||
}
|
}
|
||||||
CP_ABORT("Unknown Asset: %s", assetPath.c_str());
|
CP_ABORT("Unknown Asset: %s", assetPath.c_str());
|
||||||
}
|
}
|
||||||
@@ -86,26 +88,13 @@ namespace Copium
|
|||||||
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)
|
||||||
{
|
{
|
||||||
if (assetFile.GetUUID() != uuid)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (assetFile.NeedReload())
|
if (assetFile.NeedReload())
|
||||||
assetFile.Load();
|
assetFile.Load();
|
||||||
|
|
||||||
if (assetFile.GetUUID() != uuid)
|
if (assetFile.GetUUID() != uuid)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CP_DEBUG("Loading Asset: %s", assetFile.GetPath().c_str());
|
return LoadAssetFromPath(assetFile.GetPath());
|
||||||
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<Texture2D>(metaFile, "Texture2D");
|
|
||||||
}
|
|
||||||
CP_ABORT("Unknown Asset type: %s", assetFile.GetPath().c_str());
|
|
||||||
}
|
}
|
||||||
CP_ABORT("Asset not found with uuid=%s", uuid.ToString().c_str());
|
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
|
// 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)
|
void AssetManager::UnloadAsset(AssetHandle handle)
|
||||||
{
|
{
|
||||||
auto it = assets.find(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())
|
if (it->second->isRuntime())
|
||||||
nameToAssetCache.erase(it->second->GetName());
|
nameToAssetCache.erase(it->second->GetName());
|
||||||
@@ -127,14 +125,19 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
if (assets.empty())
|
if (assets.empty())
|
||||||
return;
|
return;
|
||||||
CP_WARN("Cleaning up %d loaded assets", assets.size());
|
CP_WARN("Performing auto clean up of %d non unloaded assets", assets.size());
|
||||||
assets.clear();
|
while (!assets.empty())
|
||||||
nameToAssetCache.clear();
|
{
|
||||||
pathToAssetCache.clear();
|
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>&& asset)
|
Asset& AssetManager::RegisterRuntimeAsset(const std::string& name, std::unique_ptr<Asset>&& asset)
|
||||||
{
|
{
|
||||||
|
CP_DEBUG("Registering Runtime Asset: %s", name.c_str());
|
||||||
|
|
||||||
auto it = nameToAssetCache.find(name);
|
auto it = nameToAssetCache.find(name);
|
||||||
CP_ASSERT(it == nameToAssetCache.end(), "Asset already exists: %s", name);
|
CP_ASSERT(it == nameToAssetCache.end(), "Asset already exists: %s", name);
|
||||||
|
|
||||||
@@ -148,16 +151,23 @@ namespace Copium
|
|||||||
return *asset2;
|
return *asset2;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
Asset& AssetManager::LoadAssetFromPath(const std::string& filepath)
|
||||||
Asset& AssetManager::CreateAsset(const MetaFile& metaFile, const std::string& metaFileClass)
|
|
||||||
{
|
{
|
||||||
AssetHandle handle = assetHandle++;
|
CP_DEBUG("Loading Asset: %s", filepath.c_str());
|
||||||
pathToAssetCache.emplace(metaFile.GetFilePath(), handle);
|
auto it = pathToAssetCache.find(filepath);
|
||||||
Asset& asset = *assets.emplace(handle, std::make_unique<T>(metaFile)).first->second.get();
|
if (it != pathToAssetCache.end())
|
||||||
asset.metaData.handle = handle;
|
{
|
||||||
asset.metaData.name = metaFile.GetFilePath();
|
auto itAsset = assets.find(it->second);
|
||||||
asset.metaData.uuid = UUID{metaFile.GetMetaClass(metaFileClass).GetValue("uuid")};
|
itAsset->second->metaData.loadCount++;
|
||||||
asset.metaData.isRuntime = false;
|
return *itAsset->second.get();
|
||||||
return asset;
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "copium/asset/AssetFile.h"
|
#include "copium/asset/AssetFile.h"
|
||||||
#include "copium/util/Common.h"
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -13,6 +14,8 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
CP_STATIC_CLASS(AssetManager);
|
CP_STATIC_CLASS(AssetManager);
|
||||||
private:
|
private:
|
||||||
|
using CreateAssetFunc = std::function<Asset&(const MetaFile& metaFile, const std::string& str)>;
|
||||||
|
static std::map<std::string, CreateAssetFunc> assetTypes;
|
||||||
static std::vector<std::string> assetDirs;
|
static std::vector<std::string> assetDirs;
|
||||||
static std::map<AssetHandle, std::unique_ptr<Asset>> assets;
|
static std::map<AssetHandle, std::unique_ptr<Asset>> assets;
|
||||||
|
|
||||||
@@ -32,6 +35,13 @@ namespace Copium
|
|||||||
static Asset& RegisterRuntimeAsset(const std::string& name, std::unique_ptr<Asset>&& asset);
|
static Asset& RegisterRuntimeAsset(const std::string& name, std::unique_ptr<Asset>&& asset);
|
||||||
static void Cleanup();
|
static void Cleanup();
|
||||||
|
|
||||||
|
template <typename AssetType>
|
||||||
|
static void RegisterAssetType(const std::string& assetType)
|
||||||
|
{
|
||||||
|
CP_ASSERT(assetTypes.emplace(assetType, &AssetManager::CreateAsset<AssetType>).second, "Asset type already exists: %s", assetType.c_str());
|
||||||
|
AssetFile::RegisterAssetType(assetType);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename AssetT>
|
template <typename AssetT>
|
||||||
static AssetT& LoadAsset(const std::string& assetPath)
|
static AssetT& LoadAsset(const std::string& assetPath)
|
||||||
{
|
{
|
||||||
@@ -66,7 +76,19 @@ namespace Copium
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static Asset& LoadAssetFromPath(const std::string& filepath);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static Asset& CreateAsset(const MetaFile& metaFile, const std::string& metaFileClass);
|
static Asset& CreateAsset(const MetaFile& metaFile, const std::string& metaFileClass)
|
||||||
|
{
|
||||||
|
AssetHandle handle = assetHandle++;
|
||||||
|
pathToAssetCache.emplace(metaFile.GetFilePath(), handle);
|
||||||
|
Asset& asset = *assets.emplace(handle, std::make_unique<T>(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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,20 +7,15 @@
|
|||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
enum class AssetType
|
|
||||||
{
|
|
||||||
Pipeline,
|
|
||||||
Texture2D,
|
|
||||||
Sound,
|
|
||||||
};
|
|
||||||
using AssetHandle = uint64_t;
|
using AssetHandle = uint64_t;
|
||||||
|
static constexpr int NULL_ASSET_HANDLE = 0;
|
||||||
|
|
||||||
struct AssetMeta
|
struct AssetMeta
|
||||||
{
|
{
|
||||||
AssetHandle handle;
|
AssetHandle handle;
|
||||||
AssetType type;
|
|
||||||
std::string name;
|
std::string name;
|
||||||
UUID uuid;
|
UUID uuid;
|
||||||
bool isRuntime;
|
bool isRuntime = false;
|
||||||
|
int loadCount = 1;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,24 @@
|
|||||||
#include "copium/buffer/Framebuffer.h"
|
#include "copium/buffer/Framebuffer.h"
|
||||||
|
|
||||||
|
#include "copium/asset/AssetManager.h"
|
||||||
#include "copium/buffer/CommandBuffer.h"
|
#include "copium/buffer/CommandBuffer.h"
|
||||||
#include "copium/core/Vulkan.h"
|
#include "copium/core/Vulkan.h"
|
||||||
#include "copium/sampler/Image.h"
|
#include "copium/sampler/Image.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
|
Framebuffer::Framebuffer(const MetaFile& metaFile)
|
||||||
|
{
|
||||||
|
const MetaFileClass& metaClass = metaFile.GetMetaClass("Framebuffer");
|
||||||
|
ColorAttachment& attachment = AssetManager::LoadAsset<ColorAttachment>(UUID{metaClass.GetValue("rendertexture-uuid")});
|
||||||
|
colorAttachment = attachment;
|
||||||
|
width = attachment.GetWidth();
|
||||||
|
height = attachment.GetHeight();
|
||||||
|
InitializeDepthBuffer();
|
||||||
|
InitializeRenderPass();
|
||||||
|
InitializeFramebuffers();
|
||||||
|
}
|
||||||
|
|
||||||
Framebuffer::Framebuffer(uint32_t width, uint32_t height)
|
Framebuffer::Framebuffer(uint32_t width, uint32_t height)
|
||||||
: width{width}, height{height}
|
: width{width}, height{height}
|
||||||
{
|
{
|
||||||
@@ -20,6 +33,7 @@ namespace Copium
|
|||||||
for (auto& framebuffer : framebuffers)
|
for (auto& framebuffer : framebuffers)
|
||||||
vkDestroyFramebuffer(Vulkan::GetDevice(), framebuffer, nullptr);
|
vkDestroyFramebuffer(Vulkan::GetDevice(), framebuffer, nullptr);
|
||||||
vkDestroyRenderPass(Vulkan::GetDevice(), renderPass, nullptr);
|
vkDestroyRenderPass(Vulkan::GetDevice(), renderPass, nullptr);
|
||||||
|
AssetManager::UnloadAsset(colorAttachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framebuffer::Resize(uint32_t width, uint32_t height)
|
void Framebuffer::Resize(uint32_t width, uint32_t height)
|
||||||
@@ -27,12 +41,10 @@ namespace Copium
|
|||||||
vkDeviceWaitIdle(Vulkan::GetDevice());
|
vkDeviceWaitIdle(Vulkan::GetDevice());
|
||||||
this->width = width;
|
this->width = width;
|
||||||
this->height = height;
|
this->height = height;
|
||||||
colorAttachment.reset();
|
|
||||||
depthAttachment.reset();
|
|
||||||
for (auto&& framebuffer : framebuffers)
|
for (auto&& framebuffer : framebuffers)
|
||||||
vkDestroyFramebuffer(Vulkan::GetDevice(), framebuffer, nullptr);
|
vkDestroyFramebuffer(Vulkan::GetDevice(), framebuffer, nullptr);
|
||||||
InitializeImage();
|
AssetManager::GetAsset<ColorAttachment>(colorAttachment).Resize(width, height);
|
||||||
InitializeDepthBuffer();
|
depthAttachment->Resize(width, height);
|
||||||
InitializeFramebuffers();
|
InitializeFramebuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +96,7 @@ namespace Copium
|
|||||||
|
|
||||||
const ColorAttachment& Framebuffer::GetColorAttachment() const
|
const ColorAttachment& Framebuffer::GetColorAttachment() const
|
||||||
{
|
{
|
||||||
return *colorAttachment;
|
return AssetManager::GetAsset<ColorAttachment>(colorAttachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Framebuffer::GetWidth() const
|
uint32_t Framebuffer::GetWidth() const
|
||||||
@@ -99,7 +111,7 @@ namespace Copium
|
|||||||
|
|
||||||
void Framebuffer::InitializeImage()
|
void Framebuffer::InitializeImage()
|
||||||
{
|
{
|
||||||
colorAttachment = std::make_unique<ColorAttachment>(width, height);
|
colorAttachment = AssetManager::RegisterRuntimeAsset("Framebuffer::ColorAttachment", std::make_unique<ColorAttachment>(width, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framebuffer::InitializeDepthBuffer()
|
void Framebuffer::InitializeDepthBuffer()
|
||||||
@@ -174,9 +186,10 @@ namespace Copium
|
|||||||
void Framebuffer::InitializeFramebuffers()
|
void Framebuffer::InitializeFramebuffers()
|
||||||
{
|
{
|
||||||
framebuffers.resize(SwapChain::MAX_FRAMES_IN_FLIGHT);
|
framebuffers.resize(SwapChain::MAX_FRAMES_IN_FLIGHT);
|
||||||
|
const ColorAttachment& attachment = AssetManager::GetAsset<ColorAttachment>(colorAttachment);
|
||||||
for (size_t i = 0; i < framebuffers.size(); ++i)
|
for (size_t i = 0; i < framebuffers.size(); ++i)
|
||||||
{
|
{
|
||||||
std::vector<VkImageView> attachments{colorAttachment->GetImageView(i), depthAttachment->GetImageView()};
|
std::vector<VkImageView> attachments{attachment.GetImageView(i), depthAttachment->GetImageView()};
|
||||||
|
|
||||||
VkFramebufferCreateInfo createInfo{};
|
VkFramebufferCreateInfo createInfo{};
|
||||||
createInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
createInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "copium/asset/Asset.h"
|
||||||
|
#include "copium/asset/AssetMeta.h"
|
||||||
#include "copium/buffer/CommandBuffer.h"
|
#include "copium/buffer/CommandBuffer.h"
|
||||||
#include "copium/sampler/ColorAttachment.h"
|
#include "copium/sampler/ColorAttachment.h"
|
||||||
#include "copium/sampler/DepthAttachment.h"
|
#include "copium/sampler/DepthAttachment.h"
|
||||||
@@ -9,11 +11,11 @@
|
|||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class Framebuffer final
|
class Framebuffer final : public Asset
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(Framebuffer);
|
CP_DELETE_COPY_AND_MOVE_CTOR(Framebuffer);
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ColorAttachment> colorAttachment;
|
AssetHandle colorAttachment;
|
||||||
std::unique_ptr<DepthAttachment> depthAttachment;
|
std::unique_ptr<DepthAttachment> depthAttachment;
|
||||||
std::vector<VkFramebuffer> framebuffers;
|
std::vector<VkFramebuffer> framebuffers;
|
||||||
VkRenderPass renderPass;
|
VkRenderPass renderPass;
|
||||||
@@ -21,6 +23,7 @@ namespace Copium
|
|||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
public:
|
public:
|
||||||
|
Framebuffer(const MetaFile& metaFile);
|
||||||
Framebuffer(uint32_t width, uint32_t height);
|
Framebuffer(uint32_t width, uint32_t height);
|
||||||
~Framebuffer();
|
~Framebuffer();
|
||||||
|
|
||||||
|
|||||||
@@ -52,16 +52,13 @@ namespace Copium
|
|||||||
vkDeviceWaitIdle(Vulkan::GetDevice());
|
vkDeviceWaitIdle(Vulkan::GetDevice());
|
||||||
AssetManager::UnloadAsset(texture2D);
|
AssetManager::UnloadAsset(texture2D);
|
||||||
AssetManager::UnloadAsset(texture2D2);
|
AssetManager::UnloadAsset(texture2D2);
|
||||||
|
AssetManager::UnloadAsset(graphicsPipeline);
|
||||||
|
AssetManager::UnloadAsset(graphicsPipelinePassthrough);
|
||||||
|
AssetManager::UnloadAsset(framebuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::Update()
|
bool Application::Update()
|
||||||
{
|
{
|
||||||
if (framebuffer->GetWidth() != Vulkan::GetSwapChain().GetExtent().width || framebuffer->GetHeight() != Vulkan::GetSwapChain().GetExtent().height)
|
|
||||||
{
|
|
||||||
framebuffer->Resize(Vulkan::GetSwapChain().GetExtent().width / 8, Vulkan::GetSwapChain().GetExtent().height / 8);
|
|
||||||
descriptorSetPassthrough->SetSampler(framebuffer->GetColorAttachment(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Vulkan::GetSwapChain().BeginPresent())
|
if (!Vulkan::GetSwapChain().BeginPresent())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -74,42 +71,37 @@ namespace Copium
|
|||||||
|
|
||||||
void Application::InitializeFrameBuffer()
|
void Application::InitializeFrameBuffer()
|
||||||
{
|
{
|
||||||
framebuffer = std::make_unique<Framebuffer>(Vulkan::GetSwapChain().GetExtent().width, Vulkan::GetSwapChain().GetExtent().height);
|
framebuffer = AssetManager::LoadAsset<Framebuffer>("framebuffer.meta");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::InitializeRenderer()
|
void Application::InitializeRenderer()
|
||||||
{
|
{
|
||||||
renderer = std::make_unique<Renderer>(framebuffer->GetRenderPass());
|
renderer = std::make_unique<Renderer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::InitializeTextureSampler()
|
void Application::InitializeTextureSampler()
|
||||||
{
|
{
|
||||||
texture2D = AssetManager::LoadAsset("fox.meta");
|
texture2D = AssetManager::LoadAsset<Texture2D>("fox.meta");
|
||||||
texture2D2 = AssetManager::LoadAsset("fox2.meta");
|
texture2D2 = AssetManager::LoadAsset<Texture2D>("fox2.meta");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::InitializeDescriptorSets()
|
void Application::InitializeDescriptorSets()
|
||||||
{
|
{
|
||||||
descriptorPool = std::make_unique<DescriptorPool>();
|
descriptorPool = std::make_unique<DescriptorPool>();
|
||||||
|
|
||||||
descriptorSet = graphicsPipeline->CreateDescriptorSet(*descriptorPool, 0);
|
descriptorSet = AssetManager::GetAsset<Pipeline>(graphicsPipeline).CreateDescriptorSet(*descriptorPool, 0);
|
||||||
descriptorSet->SetSampler(AssetManager::GetAsset<Texture2D>(texture2D), 1);
|
descriptorSet->SetSampler(AssetManager::GetAsset<Texture2D>(texture2D), 1);
|
||||||
|
|
||||||
descriptorSetPassthrough = graphicsPipelinePassthrough->CreateDescriptorSet(*descriptorPool, 0);
|
descriptorSetPassthrough = AssetManager::GetAsset<Pipeline>(graphicsPipelinePassthrough).CreateDescriptorSet(*descriptorPool, 0);
|
||||||
descriptorSetPassthrough->SetSampler(framebuffer->GetColorAttachment(), 0);
|
descriptorSetPassthrough->SetSampler(AssetManager::GetAsset<Framebuffer>(framebuffer).GetColorAttachment(), 0);
|
||||||
|
|
||||||
descriptorSetRenderer = renderer->GetGraphicsPipeline().CreateDescriptorSet(*descriptorPool, 1);
|
descriptorSetRenderer = renderer->GetGraphicsPipeline().CreateDescriptorSet(*descriptorPool, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::InitializeGraphicsPipeline()
|
void Application::InitializeGraphicsPipeline()
|
||||||
{
|
{
|
||||||
PipelineCreator creator{framebuffer->GetRenderPass(), "res/shaders/shader.vert", "res/shaders/shader.frag"};
|
graphicsPipeline = AssetManager::LoadAsset<Pipeline>("pipeline.meta");
|
||||||
creator.SetVertexDescriptor(Vertex::GetDescriptor());
|
graphicsPipelinePassthrough = AssetManager::LoadAsset<Pipeline>("passthrough.meta");
|
||||||
graphicsPipeline = std::make_unique<Pipeline>(creator);
|
|
||||||
|
|
||||||
PipelineCreator creatorPassthrough{Vulkan::GetSwapChain().GetRenderPass(), "res/shaders/passthrough.vert", "res/shaders/passthrough.frag"};
|
|
||||||
creatorPassthrough.SetVertexDescriptor(VertexPassthrough::GetDescriptor());
|
|
||||||
graphicsPipelinePassthrough = std::make_unique<Pipeline>(creatorPassthrough);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::InitializeMesh()
|
void Application::InitializeMesh()
|
||||||
@@ -127,13 +119,15 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
commandBuffer->Begin();
|
commandBuffer->Begin();
|
||||||
|
|
||||||
framebuffer->Bind(*commandBuffer);
|
Framebuffer& fb = AssetManager::GetAsset<Framebuffer>(framebuffer);
|
||||||
graphicsPipeline->Bind(*commandBuffer);
|
Pipeline& pl = AssetManager::GetAsset<Pipeline>(graphicsPipeline);
|
||||||
|
fb.Bind(*commandBuffer);
|
||||||
|
pl.Bind(*commandBuffer);
|
||||||
|
|
||||||
UpdateUniformBuffer();
|
UpdateUniformBuffer();
|
||||||
|
|
||||||
graphicsPipeline->SetDescriptorSet(*descriptorSet);
|
pl.SetDescriptorSet(*descriptorSet);
|
||||||
graphicsPipeline->BindDescriptorSets(*commandBuffer);
|
pl.BindDescriptorSets(*commandBuffer);
|
||||||
|
|
||||||
mesh->Bind(*commandBuffer);
|
mesh->Bind(*commandBuffer);
|
||||||
mesh->Render(*commandBuffer);
|
mesh->Render(*commandBuffer);
|
||||||
@@ -151,13 +145,14 @@ namespace Copium
|
|||||||
renderer->Quad(glm::vec2{ 0.1, -0.4}, glm::vec2{0.8, 0.8}, AssetManager::GetAsset<Texture2D>(texture2D2));
|
renderer->Quad(glm::vec2{ 0.1, -0.4}, glm::vec2{0.8, 0.8}, AssetManager::GetAsset<Texture2D>(texture2D2));
|
||||||
renderer->End();
|
renderer->End();
|
||||||
|
|
||||||
framebuffer->Unbind(*commandBuffer);
|
fb.Unbind(*commandBuffer);
|
||||||
|
|
||||||
Vulkan::GetSwapChain().BeginFrameBuffer(*commandBuffer);
|
Vulkan::GetSwapChain().BeginFrameBuffer(*commandBuffer);
|
||||||
|
|
||||||
graphicsPipelinePassthrough->Bind(*commandBuffer);
|
Pipeline& plPassthrough = AssetManager::GetAsset<Pipeline>(graphicsPipelinePassthrough);
|
||||||
graphicsPipelinePassthrough->SetDescriptorSet(*descriptorSetPassthrough);
|
plPassthrough.Bind(*commandBuffer);
|
||||||
graphicsPipelinePassthrough->BindDescriptorSets(*commandBuffer);
|
plPassthrough.SetDescriptorSet(*descriptorSetPassthrough);
|
||||||
|
plPassthrough.BindDescriptorSets(*commandBuffer);
|
||||||
|
|
||||||
meshPassthrough->Bind(*commandBuffer);
|
meshPassthrough->Bind(*commandBuffer);
|
||||||
meshPassthrough->Render(*commandBuffer);
|
meshPassthrough->Render(*commandBuffer);
|
||||||
@@ -171,7 +166,8 @@ namespace Copium
|
|||||||
static Timer startTimer;
|
static Timer startTimer;
|
||||||
|
|
||||||
float time = startTimer.Elapsed();
|
float time = startTimer.Elapsed();
|
||||||
float aspect = framebuffer->GetWidth() / (float)framebuffer->GetHeight();
|
Framebuffer& fb = AssetManager::GetAsset<Framebuffer>(framebuffer);
|
||||||
|
float aspect = fb.GetWidth() / (float)fb.GetHeight();
|
||||||
|
|
||||||
{
|
{
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(45.0f), aspect, 0.1f, 10.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(45.0f), aspect, 0.1f, 10.0f);
|
||||||
|
|||||||
@@ -15,15 +15,15 @@ namespace Copium
|
|||||||
CP_DELETE_COPY_AND_MOVE_CTOR(Application);
|
CP_DELETE_COPY_AND_MOVE_CTOR(Application);
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Renderer> renderer;
|
std::unique_ptr<Renderer> renderer;
|
||||||
std::unique_ptr<Framebuffer> framebuffer;
|
AssetHandle framebuffer;
|
||||||
AssetHandle texture2D;
|
AssetHandle texture2D;
|
||||||
AssetHandle texture2D2;
|
AssetHandle texture2D2;
|
||||||
|
AssetHandle graphicsPipeline;
|
||||||
|
AssetHandle graphicsPipelinePassthrough;
|
||||||
std::unique_ptr<DescriptorPool> descriptorPool;
|
std::unique_ptr<DescriptorPool> descriptorPool;
|
||||||
std::unique_ptr<DescriptorSet> descriptorSet;
|
std::unique_ptr<DescriptorSet> descriptorSet;
|
||||||
std::unique_ptr<DescriptorSet> descriptorSetPassthrough;
|
std::unique_ptr<DescriptorSet> descriptorSetPassthrough;
|
||||||
std::unique_ptr<DescriptorSet> descriptorSetRenderer;
|
std::unique_ptr<DescriptorSet> descriptorSetRenderer;
|
||||||
std::unique_ptr<Pipeline> graphicsPipeline;
|
|
||||||
std::unique_ptr<Pipeline> graphicsPipelinePassthrough;
|
|
||||||
std::unique_ptr<Mesh> mesh;
|
std::unique_ptr<Mesh> mesh;
|
||||||
std::unique_ptr<Mesh> meshPassthrough;
|
std::unique_ptr<Mesh> meshPassthrough;
|
||||||
std::unique_ptr<CommandBuffer> commandBuffer;
|
std::unique_ptr<CommandBuffer> commandBuffer;
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
#include "copium/core/Vulkan.h"
|
#include "copium/core/Vulkan.h"
|
||||||
|
|
||||||
#include "copium/asset/AssetManager.h"
|
#include "copium/asset/AssetManager.h"
|
||||||
|
#include "copium/sampler/Texture2D.h"
|
||||||
|
#include "copium/sampler/ColorAttachment.h"
|
||||||
|
#include "copium/pipeline/Pipeline.h"
|
||||||
|
#include "copium/buffer/Framebuffer.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
@@ -16,6 +20,11 @@ namespace Copium
|
|||||||
device = std::make_unique<Device>();
|
device = std::make_unique<Device>();
|
||||||
swapChain = std::make_unique<SwapChain>();
|
swapChain = std::make_unique<SwapChain>();
|
||||||
|
|
||||||
|
AssetManager::RegisterAssetType<Texture2D>("Texture2D");
|
||||||
|
AssetManager::RegisterAssetType<ColorAttachment>("RenderTexture");
|
||||||
|
AssetManager::RegisterAssetType<Pipeline>("Pipeline");
|
||||||
|
AssetManager::RegisterAssetType<Framebuffer>("Framebuffer");
|
||||||
|
|
||||||
// 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/");
|
||||||
|
|||||||
@@ -8,10 +8,6 @@
|
|||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
CP_ASSERT(glfwInit() == GLFW_TRUE, "Failed to initialize the glfw context");
|
CP_ASSERT(glfwInit() == GLFW_TRUE, "Failed to initialize the glfw context");
|
||||||
for (int i = 0; i < argc; i++)
|
|
||||||
{
|
|
||||||
CP_INFO(argv[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
Copium::Vulkan::Initialize();
|
Copium::Vulkan::Initialize();
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,11 +1,51 @@
|
|||||||
#include "copium/pipeline/Pipeline.h"
|
#include "copium/pipeline/Pipeline.h"
|
||||||
|
|
||||||
|
#include "copium/asset/AssetManager.h"
|
||||||
|
#include "copium/buffer/Framebuffer.h"
|
||||||
#include "copium/core/Vulkan.h"
|
#include "copium/core/Vulkan.h"
|
||||||
#include "copium/pipeline/Shader.h"
|
#include "copium/pipeline/Shader.h"
|
||||||
|
#include "copium/renderer/RendererVertex.h"
|
||||||
|
#include "copium/mesh/VertexPassthrough.h"
|
||||||
|
#include "copium/mesh/Vertex.h"
|
||||||
#include "copium/util/FileSystem.h"
|
#include "copium/util/FileSystem.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
|
Pipeline::Pipeline(const MetaFile& metaFile)
|
||||||
|
: shaderReflector{ShaderReflector{metaFile.GetMetaClass("Pipeline").GetValue("vert-filepath"), metaFile.GetMetaClass("Pipeline").GetValue("frag-filepath")}}
|
||||||
|
{
|
||||||
|
const MetaFileClass& metaFileClass = metaFile.GetMetaClass("Pipeline");
|
||||||
|
VkRenderPass renderPass;
|
||||||
|
if (metaFileClass.HasValue("framebuffer-uuid"))
|
||||||
|
{
|
||||||
|
Framebuffer& fb = AssetManager::LoadAsset<Framebuffer>(UUID{metaFileClass.GetValue("framebuffer-uuid")});
|
||||||
|
renderPass = fb.GetRenderPass();
|
||||||
|
framebuffer = fb;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
renderPass = Vulkan::GetSwapChain().GetRenderPass();
|
||||||
|
}
|
||||||
|
PipelineCreator creator{renderPass, metaFileClass.GetValue("vert-filepath"), metaFileClass.GetValue("frag-filepath")};
|
||||||
|
std::string type = metaFileClass.GetValue("type");
|
||||||
|
if (type == "Renderer")
|
||||||
|
{
|
||||||
|
creator.SetVertexDescriptor(RendererVertex::GetDescriptor());
|
||||||
|
creator.SetDepthTest(false);
|
||||||
|
}
|
||||||
|
else if (type == "Passthrough")
|
||||||
|
{
|
||||||
|
creator.SetVertexDescriptor(VertexPassthrough::GetDescriptor());
|
||||||
|
creator.SetDepthTest(false);
|
||||||
|
}
|
||||||
|
else if (type == "Mesh")
|
||||||
|
{
|
||||||
|
creator.SetVertexDescriptor(Vertex::GetDescriptor());
|
||||||
|
}
|
||||||
|
InitializeDescriptorSetLayout(creator);
|
||||||
|
InitializePipeline(creator);
|
||||||
|
}
|
||||||
|
|
||||||
Pipeline::Pipeline(PipelineCreator creator)
|
Pipeline::Pipeline(PipelineCreator creator)
|
||||||
: shaderReflector{creator.shaderReflector}
|
: shaderReflector{creator.shaderReflector}
|
||||||
{
|
{
|
||||||
@@ -21,6 +61,10 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
vkDestroyDescriptorSetLayout(Vulkan::GetDevice(), descriptorSetLayout, nullptr);
|
vkDestroyDescriptorSetLayout(Vulkan::GetDevice(), descriptorSetLayout, nullptr);
|
||||||
}
|
}
|
||||||
|
if (framebuffer != NULL_ASSET_HANDLE)
|
||||||
|
{
|
||||||
|
AssetManager::UnloadAsset(framebuffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pipeline::Bind(const CommandBuffer& commandBuffer)
|
void Pipeline::Bind(const CommandBuffer& commandBuffer)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "copium/asset/Asset.h"
|
||||||
#include "copium/buffer/CommandBuffer.h"
|
#include "copium/buffer/CommandBuffer.h"
|
||||||
#include "copium/pipeline/DescriptorSet.h"
|
#include "copium/pipeline/DescriptorSet.h"
|
||||||
#include "copium/pipeline/PipelineCreator.h"
|
#include "copium/pipeline/PipelineCreator.h"
|
||||||
@@ -10,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class Pipeline final
|
class Pipeline final : public Asset
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(Pipeline);
|
CP_DELETE_COPY_AND_MOVE_CTOR(Pipeline);
|
||||||
private:
|
private:
|
||||||
@@ -19,8 +20,11 @@ namespace Copium
|
|||||||
std::vector<VkDescriptorSet> boundDescriptorSets;
|
std::vector<VkDescriptorSet> boundDescriptorSets;
|
||||||
VkPipelineLayout pipelineLayout;
|
VkPipelineLayout pipelineLayout;
|
||||||
VkPipeline graphicsPipeline;
|
VkPipeline graphicsPipeline;
|
||||||
|
AssetHandle framebuffer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
Pipeline(const MetaFile& metaFile);
|
||||||
Pipeline(PipelineCreator creator);
|
Pipeline(PipelineCreator creator);
|
||||||
~Pipeline();
|
~Pipeline();
|
||||||
void Bind(const CommandBuffer& commandBuffer);
|
void Bind(const CommandBuffer& commandBuffer);
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
#include "copium/renderer/Batch.h"
|
#include "copium/renderer/Batch.h"
|
||||||
|
|
||||||
|
#include "copium/asset/AssetManager.h"
|
||||||
#include "copium/renderer/RendererVertex.h"
|
#include "copium/renderer/RendererVertex.h"
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
Batch::Batch(Pipeline& pipeline, DescriptorPool& descriptorPool, int vertexCount, const std::vector<const Sampler*> samplers)
|
Batch::Batch(AssetHandle pipeline, DescriptorPool& descriptorPool, int vertexCount, const std::vector<const Sampler*> samplers)
|
||||||
: pipeline{pipeline},
|
: vertexBuffer{RendererVertex::GetDescriptor(), vertexCount},
|
||||||
vertexBuffer{RendererVertex::GetDescriptor(), vertexCount},
|
descriptorSet{AssetManager::GetAsset<Pipeline>(pipeline).CreateDescriptorSet(descriptorPool, 0)}
|
||||||
descriptorSet{pipeline.CreateDescriptorSet(descriptorPool, 0)}
|
|
||||||
{
|
{
|
||||||
descriptorSet->SetSamplers(samplers, 0);
|
descriptorSet->SetSamplers(samplers, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "copium/asset/AssetMeta.h"
|
||||||
#include "copium/buffer/RendererVertexBuffer.h"
|
#include "copium/buffer/RendererVertexBuffer.h"
|
||||||
#include "copium/pipeline/DescriptorSet.h"
|
#include "copium/pipeline/DescriptorSet.h"
|
||||||
#include "copium/pipeline/Pipeline.h"
|
#include "copium/pipeline/Pipeline.h"
|
||||||
@@ -11,12 +12,10 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(Batch);
|
CP_DELETE_COPY_AND_MOVE_CTOR(Batch);
|
||||||
private:
|
private:
|
||||||
Pipeline& pipeline;
|
|
||||||
|
|
||||||
RendererVertexBuffer vertexBuffer;
|
RendererVertexBuffer vertexBuffer;
|
||||||
std::unique_ptr<DescriptorSet> descriptorSet;
|
std::unique_ptr<DescriptorSet> descriptorSet;
|
||||||
public:
|
public:
|
||||||
Batch(Pipeline& pipeline, DescriptorPool& descriptorPool, int vertexCount, const std::vector<const Sampler*> samplers);
|
Batch(AssetHandle pipeline, DescriptorPool& descriptorPool, int vertexCount, const std::vector<const Sampler*> samplers);
|
||||||
RendererVertexBuffer& GetVertexBuffer();
|
RendererVertexBuffer& GetVertexBuffer();
|
||||||
DescriptorSet& GetDescriptorSet();
|
DescriptorSet& GetDescriptorSet();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,19 +12,20 @@ namespace Copium
|
|||||||
static constexpr int MAX_NUM_INDICES = 6 * MAX_NUM_QUADS;
|
static constexpr int MAX_NUM_INDICES = 6 * MAX_NUM_QUADS;
|
||||||
static constexpr int MAX_NUM_TEXTURES = 32;
|
static constexpr int MAX_NUM_TEXTURES = 32;
|
||||||
|
|
||||||
Renderer::Renderer(VkRenderPass renderPass)
|
Renderer::Renderer()
|
||||||
: descriptorPool{},
|
: descriptorPool{},
|
||||||
ibo{MAX_NUM_INDICES},
|
ibo{MAX_NUM_INDICES},
|
||||||
emptyTexture{AssetManager::RegisterRuntimeAsset("empty", std::make_unique<Texture2D>(std::vector<uint8_t>{0, 0, 0, 255}, 1, 1))},
|
emptyTexture{AssetManager::RegisterRuntimeAsset("empty", std::make_unique<Texture2D>(std::vector<uint8_t>{0, 0, 0, 255}, 1, 1))},
|
||||||
samplers{MAX_NUM_TEXTURES, &AssetManager::GetAsset<Texture2D>(emptyTexture)}
|
samplers{MAX_NUM_TEXTURES, &AssetManager::GetAsset<Texture2D>(emptyTexture)}
|
||||||
{
|
{
|
||||||
InitializeIndexBuffer();
|
InitializeIndexBuffer();
|
||||||
InitializeGraphicsPipeline(renderPass);
|
InitializeGraphicsPipeline();
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::~Renderer()
|
Renderer::~Renderer()
|
||||||
{
|
{
|
||||||
AssetManager::UnloadAsset(emptyTexture);
|
AssetManager::UnloadAsset(emptyTexture);
|
||||||
|
AssetManager::UnloadAsset(pipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::Quad(const glm::vec2& pos, const glm::vec2& size, const glm::vec3& color)
|
void Renderer::Quad(const glm::vec2& pos, const glm::vec2& size, const glm::vec3& color)
|
||||||
@@ -59,7 +60,7 @@ namespace Copium
|
|||||||
|
|
||||||
void Renderer::Begin(CommandBuffer& commandBuffer)
|
void Renderer::Begin(CommandBuffer& commandBuffer)
|
||||||
{
|
{
|
||||||
graphicsPipeline->Bind(commandBuffer);
|
AssetManager::GetAsset<Pipeline>(pipeline).Bind(commandBuffer);
|
||||||
ibo.Bind(commandBuffer);
|
ibo.Bind(commandBuffer);
|
||||||
batchIndex = -1;
|
batchIndex = -1;
|
||||||
NextBatch();
|
NextBatch();
|
||||||
@@ -73,12 +74,12 @@ namespace Copium
|
|||||||
|
|
||||||
Pipeline& Renderer::GetGraphicsPipeline()
|
Pipeline& Renderer::GetGraphicsPipeline()
|
||||||
{
|
{
|
||||||
return *graphicsPipeline;
|
return AssetManager::GetAsset<Pipeline>(pipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetDescriptorSet(const DescriptorSet& descriptorSet)
|
void Renderer::SetDescriptorSet(const DescriptorSet& descriptorSet)
|
||||||
{
|
{
|
||||||
graphicsPipeline->SetDescriptorSet(descriptorSet);
|
AssetManager::GetAsset<Pipeline>(pipeline).SetDescriptorSet(descriptorSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::InitializeIndexBuffer()
|
void Renderer::InitializeIndexBuffer()
|
||||||
@@ -99,19 +100,16 @@ namespace Copium
|
|||||||
ibo.UpdateStaging(indices.data());
|
ibo.UpdateStaging(indices.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::InitializeGraphicsPipeline(VkRenderPass renderPass)
|
void Renderer::InitializeGraphicsPipeline()
|
||||||
{
|
{
|
||||||
PipelineCreator creator{renderPass, "res/shaders/renderer.vert", "res/shaders/renderer.frag"};
|
pipeline = AssetManager::LoadAsset<Pipeline>("renderer.meta");
|
||||||
creator.SetVertexDescriptor(RendererVertex::GetDescriptor());
|
|
||||||
creator.SetDepthTest(false);
|
|
||||||
graphicsPipeline = std::make_unique<Pipeline>(creator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Renderer::AllocateSampler(const Sampler& sampler)
|
int Renderer::AllocateSampler(const Sampler& sampler)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < textureCount; i++)
|
for (size_t i = 0; i < textureCount; i++)
|
||||||
{
|
{
|
||||||
if (*samplers[i] == sampler)
|
if (*samplers[i] == (VkSampler)sampler)
|
||||||
{
|
{
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -142,8 +140,8 @@ namespace Copium
|
|||||||
{
|
{
|
||||||
batches[batchIndex]->GetVertexBuffer().Unmap();
|
batches[batchIndex]->GetVertexBuffer().Unmap();
|
||||||
batches[batchIndex]->GetVertexBuffer().Bind(*currentCommandBuffer);
|
batches[batchIndex]->GetVertexBuffer().Bind(*currentCommandBuffer);
|
||||||
graphicsPipeline->SetDescriptorSet(batches[batchIndex]->GetDescriptorSet());
|
AssetManager::GetAsset<Pipeline>(pipeline).SetDescriptorSet(batches[batchIndex]->GetDescriptorSet());
|
||||||
graphicsPipeline->BindDescriptorSets(*currentCommandBuffer);
|
AssetManager::GetAsset<Pipeline>(pipeline).BindDescriptorSets(*currentCommandBuffer);
|
||||||
ibo.Draw(*currentCommandBuffer, quadCount * 6);
|
ibo.Draw(*currentCommandBuffer, quadCount * 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +151,7 @@ namespace Copium
|
|||||||
std::fill(samplers.begin(), samplers.end(), &AssetManager::GetAsset<Texture2D>(emptyTexture));
|
std::fill(samplers.begin(), samplers.end(), &AssetManager::GetAsset<Texture2D>(emptyTexture));
|
||||||
if (batchIndex >= batches.size())
|
if (batchIndex >= batches.size())
|
||||||
{
|
{
|
||||||
batches.emplace_back(std::make_unique<Batch>(*graphicsPipeline, descriptorPool, MAX_NUM_VERTICES, samplers));
|
batches.emplace_back(std::make_unique<Batch>(pipeline, descriptorPool, MAX_NUM_VERTICES, samplers));
|
||||||
}
|
}
|
||||||
mappedVertexBuffer = (char*)batches[batchIndex]->GetVertexBuffer().Map() + batches[batchIndex]->GetVertexBuffer().GetPosition(Vulkan::GetSwapChain().GetFlightIndex());
|
mappedVertexBuffer = (char*)batches[batchIndex]->GetVertexBuffer().Map() + batches[batchIndex]->GetVertexBuffer().GetPosition(Vulkan::GetSwapChain().GetFlightIndex());
|
||||||
quadCount = 0;
|
quadCount = 0;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "copium/asset/AssetMeta.h"
|
||||||
#include "copium/buffer/CommandBuffer.h"
|
#include "copium/buffer/CommandBuffer.h"
|
||||||
#include "copium/buffer/IndexBuffer.h"
|
#include "copium/buffer/IndexBuffer.h"
|
||||||
#include "copium/buffer/RendererVertexBuffer.h"
|
#include "copium/buffer/RendererVertexBuffer.h"
|
||||||
@@ -20,7 +21,7 @@ namespace Copium
|
|||||||
DescriptorPool descriptorPool;
|
DescriptorPool descriptorPool;
|
||||||
IndexBuffer ibo;
|
IndexBuffer ibo;
|
||||||
AssetHandle emptyTexture;
|
AssetHandle emptyTexture;
|
||||||
std::unique_ptr<Pipeline> graphicsPipeline;
|
AssetHandle pipeline;
|
||||||
std::vector<std::unique_ptr<Batch>> batches;
|
std::vector<std::unique_ptr<Batch>> batches;
|
||||||
|
|
||||||
// Temporary data during a render
|
// Temporary data during a render
|
||||||
@@ -31,7 +32,7 @@ namespace Copium
|
|||||||
int textureCount;
|
int textureCount;
|
||||||
void* mappedVertexBuffer;
|
void* mappedVertexBuffer;
|
||||||
public:
|
public:
|
||||||
Renderer(VkRenderPass renderPass);
|
Renderer();
|
||||||
~Renderer();
|
~Renderer();
|
||||||
|
|
||||||
void Quad(const glm::vec2& from, const glm::vec2& to, const glm::vec3& color = glm::vec3{1, 1, 1});
|
void Quad(const glm::vec2& from, const glm::vec2& to, const glm::vec3& color = glm::vec3{1, 1, 1});
|
||||||
@@ -44,7 +45,7 @@ namespace Copium
|
|||||||
void SetDescriptorSet(const DescriptorSet& descriptorSet);
|
void SetDescriptorSet(const DescriptorSet& descriptorSet);
|
||||||
private:
|
private:
|
||||||
void InitializeIndexBuffer();
|
void InitializeIndexBuffer();
|
||||||
void InitializeGraphicsPipeline(VkRenderPass renderPass);
|
void InitializeGraphicsPipeline();
|
||||||
|
|
||||||
int AllocateSampler(const Sampler& sampler);
|
int AllocateSampler(const Sampler& sampler);
|
||||||
void AllocateQuad();
|
void AllocateQuad();
|
||||||
|
|||||||
@@ -5,8 +5,32 @@
|
|||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ColorAttachment::ColorAttachment(const MetaFile& metaFile)
|
||||||
|
{
|
||||||
|
const MetaFileClass& metaClass = metaFile.GetMetaClass("RenderTexture");
|
||||||
|
if (metaClass.HasValue("width"))
|
||||||
|
{
|
||||||
|
char* endPtr;
|
||||||
|
width = std::strtol(metaClass.GetValue("width").c_str(), &endPtr, 10);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
width = Vulkan::GetSwapChain().GetExtent().width;
|
||||||
|
}
|
||||||
|
if (metaClass.HasValue("height"))
|
||||||
|
{
|
||||||
|
char* endPtr;
|
||||||
|
height = std::strtol(metaClass.GetValue("height").c_str(), &endPtr, 10);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
height = Vulkan::GetSwapChain().GetExtent().height;
|
||||||
|
}
|
||||||
|
InitializeColorAttachment(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
ColorAttachment::ColorAttachment(int width, int height)
|
ColorAttachment::ColorAttachment(int width, int height)
|
||||||
: Sampler{}
|
|
||||||
{
|
{
|
||||||
InitializeColorAttachment(width, height);
|
InitializeColorAttachment(width, height);
|
||||||
}
|
}
|
||||||
@@ -21,6 +45,28 @@ namespace Copium
|
|||||||
vkDestroyImageView(Vulkan::GetDevice(), imageView, nullptr);
|
vkDestroyImageView(Vulkan::GetDevice(), imageView, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ColorAttachment::Resize(int width, int height)
|
||||||
|
{
|
||||||
|
for (auto&& image : images)
|
||||||
|
vkDestroyImage(Vulkan::GetDevice(), image, nullptr);
|
||||||
|
for (auto&& imageMemory : imageMemories)
|
||||||
|
vkFreeMemory(Vulkan::GetDevice(), imageMemory, nullptr);
|
||||||
|
for (auto&& imageView : imageViews)
|
||||||
|
vkDestroyImageView(Vulkan::GetDevice(), imageView, nullptr);
|
||||||
|
|
||||||
|
InitializeColorAttachment(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ColorAttachment::GetWidth() const
|
||||||
|
{
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ColorAttachment::GetHeight() const
|
||||||
|
{
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
VkDescriptorImageInfo ColorAttachment::GetDescriptorImageInfo(int index) const
|
VkDescriptorImageInfo ColorAttachment::GetDescriptorImageInfo(int index) const
|
||||||
{
|
{
|
||||||
CP_ASSERT(index >= 0 && index < imageViews.size(), "index out of bound for color attachment");
|
CP_ASSERT(index >= 0 && index < imageViews.size(), "index out of bound for color attachment");
|
||||||
@@ -32,7 +78,7 @@ namespace Copium
|
|||||||
return imageInfo;
|
return imageInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkImageView ColorAttachment::GetImageView(int index)
|
VkImageView ColorAttachment::GetImageView(int index) const
|
||||||
{
|
{
|
||||||
CP_ASSERT(index >= 0 && index < imageViews.size(), "Index out of bound");
|
CP_ASSERT(index >= 0 && index < imageViews.size(), "Index out of bound");
|
||||||
|
|
||||||
|
|||||||
@@ -14,12 +14,19 @@ namespace Copium
|
|||||||
std::vector<VkImage> images;
|
std::vector<VkImage> images;
|
||||||
std::vector<VkDeviceMemory> imageMemories;
|
std::vector<VkDeviceMemory> imageMemories;
|
||||||
std::vector<VkImageView> imageViews;
|
std::vector<VkImageView> imageViews;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
public:
|
public:
|
||||||
|
ColorAttachment(const MetaFile& metaFile);
|
||||||
ColorAttachment(int width, int height);
|
ColorAttachment(int width, int height);
|
||||||
~ColorAttachment() override;
|
~ColorAttachment() override;
|
||||||
|
|
||||||
|
void Resize(int width, int height);
|
||||||
|
|
||||||
|
int GetWidth() const;
|
||||||
|
int GetHeight() const;
|
||||||
VkDescriptorImageInfo GetDescriptorImageInfo(int index) const override;
|
VkDescriptorImageInfo GetDescriptorImageInfo(int index) const override;
|
||||||
VkImageView GetImageView(int index);
|
VkImageView GetImageView(int index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitializeColorAttachment(int width, int height);
|
void InitializeColorAttachment(int width, int height);
|
||||||
|
|||||||
@@ -18,6 +18,15 @@ namespace Copium
|
|||||||
vkDestroyImageView(Vulkan::GetDevice(), imageView, nullptr);
|
vkDestroyImageView(Vulkan::GetDevice(), imageView, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DepthAttachment::Resize(int width, int height)
|
||||||
|
{
|
||||||
|
vkDestroyImage(Vulkan::GetDevice(), image, nullptr);
|
||||||
|
vkFreeMemory(Vulkan::GetDevice(), imageMemory, nullptr);
|
||||||
|
vkDestroyImageView(Vulkan::GetDevice(), imageView, nullptr);
|
||||||
|
InitializeDepthAttachment(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
VkDescriptorImageInfo DepthAttachment::GetDescriptorImageInfo(int index) const
|
VkDescriptorImageInfo DepthAttachment::GetDescriptorImageInfo(int index) const
|
||||||
{
|
{
|
||||||
VkDescriptorImageInfo imageInfo{};
|
VkDescriptorImageInfo imageInfo{};
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ namespace Copium
|
|||||||
DepthAttachment(int width, int height);
|
DepthAttachment(int width, int height);
|
||||||
~DepthAttachment() override;
|
~DepthAttachment() override;
|
||||||
|
|
||||||
|
void Resize(int width, int height);
|
||||||
|
|
||||||
VkDescriptorImageInfo GetDescriptorImageInfo(int index) const override;
|
VkDescriptorImageInfo GetDescriptorImageInfo(int index) const override;
|
||||||
VkImageView GetImageView() const;
|
VkImageView GetImageView() const;
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "copium/asset/Asset.h"
|
||||||
#include "copium/util/Common.h"
|
#include "copium/util/Common.h"
|
||||||
|
|
||||||
#include <vulkan/vulkan.hpp>
|
#include <vulkan/vulkan.hpp>
|
||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class Sampler
|
class Sampler : public Asset
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(Sampler);
|
CP_DELETE_COPY_AND_MOVE_CTOR(Sampler);
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
Texture2D::Texture2D(const MetaFile& metaFile)
|
Texture2D::Texture2D(const MetaFile& metaFile)
|
||||||
: Sampler{}, Asset{AssetType::Texture2D}
|
|
||||||
{
|
{
|
||||||
const std::string& filepath = metaFile.GetMetaClass("Texture2D").GetValue("filepath");
|
const std::string& filepath = metaFile.GetMetaClass("Texture2D").GetValue("filepath");
|
||||||
CP_DEBUG("Loading texture file: %s", filepath.c_str());
|
CP_DEBUG("Loading texture file: %s", filepath.c_str());
|
||||||
@@ -18,7 +17,6 @@ namespace Copium
|
|||||||
}
|
}
|
||||||
|
|
||||||
Texture2D::Texture2D(const std::vector<uint8_t>& rgbaData, int width, int height)
|
Texture2D::Texture2D(const std::vector<uint8_t>& rgbaData, int width, int height)
|
||||||
: Sampler{}, Asset{AssetType::Texture2D}
|
|
||||||
{
|
{
|
||||||
CP_ASSERT(rgbaData.size() == width * height * 4, "rgbaData has invalid size, should be equal to width * height * 4 (%d) actually is %d", width * height * 4, rgbaData.size());
|
CP_ASSERT(rgbaData.size() == width * height * 4, "rgbaData has invalid size, should be equal to width * height * 4 (%d) actually is %d", width * height * 4, rgbaData.size());
|
||||||
InitializeTextureImageFromData((void*)rgbaData.data(), width, height);
|
InitializeTextureImageFromData((void*)rgbaData.data(), width, height);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "copium/asset/Asset.h"
|
|
||||||
#include "copium/buffer/CommandBufferScoped.h"
|
#include "copium/buffer/CommandBufferScoped.h"
|
||||||
#include "copium/sampler/Image.h"
|
#include "copium/sampler/Image.h"
|
||||||
#include "copium/sampler/Sampler.h"
|
#include "copium/sampler/Sampler.h"
|
||||||
@@ -10,7 +9,7 @@
|
|||||||
|
|
||||||
namespace Copium
|
namespace Copium
|
||||||
{
|
{
|
||||||
class Texture2D final : public Sampler, public Asset
|
class Texture2D final : public Sampler
|
||||||
{
|
{
|
||||||
CP_DELETE_COPY_AND_MOVE_CTOR(Texture2D);
|
CP_DELETE_COPY_AND_MOVE_CTOR(Texture2D);
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user