From 1731bb1dd5575e3d50a799bceb4c38022094c8c6 Mon Sep 17 00:00:00 2001 From: Thraix Date: Sat, 22 Apr 2023 21:00:34 +0200 Subject: [PATCH] Add additional Asset types - Add Framebuffer Asset - Add Pipeline Asset - Add RenderTexture Asset --- CopiumEngine/CopiumEngine.vcxproj | 10 -- CopiumEngine/CopiumEngine.vcxproj.filters | 10 -- CopiumEngine/assets/framebuffer.meta | 3 + CopiumEngine/assets/passthrough.meta | 5 + CopiumEngine/assets/pipeline.meta | 6 ++ CopiumEngine/assets/renderer.meta | 6 ++ CopiumEngine/assets/rendertexture.meta | 2 + CopiumEngine/res/shaders/passthrough.vert | 2 +- CopiumEngine/src/copium/asset/Asset.cpp | 11 +-- CopiumEngine/src/copium/asset/Asset.h | 3 +- CopiumEngine/src/copium/asset/AssetFile.cpp | 19 ++-- CopiumEngine/src/copium/asset/AssetFile.h | 6 +- .../src/copium/asset/AssetManager.cpp | 94 ++++++++++--------- CopiumEngine/src/copium/asset/AssetManager.h | 24 ++++- CopiumEngine/src/copium/asset/AssetMeta.h | 11 +-- .../src/copium/buffer/Framebuffer.cpp | 27 ++++-- CopiumEngine/src/copium/buffer/Framebuffer.h | 7 +- CopiumEngine/src/copium/core/Application.cpp | 54 +++++------ CopiumEngine/src/copium/core/Application.h | 6 +- CopiumEngine/src/copium/core/Vulkan.cpp | 9 ++ CopiumEngine/src/copium/main.cpp | 4 - CopiumEngine/src/copium/pipeline/Pipeline.cpp | 44 +++++++++ CopiumEngine/src/copium/pipeline/Pipeline.h | 6 +- CopiumEngine/src/copium/renderer/Batch.cpp | 8 +- CopiumEngine/src/copium/renderer/Batch.h | 5 +- CopiumEngine/src/copium/renderer/Renderer.cpp | 26 +++-- CopiumEngine/src/copium/renderer/Renderer.h | 7 +- .../src/copium/sampler/ColorAttachment.cpp | 50 +++++++++- .../src/copium/sampler/ColorAttachment.h | 9 +- .../src/copium/sampler/DepthAttachment.cpp | 9 ++ .../src/copium/sampler/DepthAttachment.h | 2 + CopiumEngine/src/copium/sampler/Sampler.h | 3 +- CopiumEngine/src/copium/sampler/Texture2D.cpp | 2 - CopiumEngine/src/copium/sampler/Texture2D.h | 3 +- 34 files changed, 322 insertions(+), 171 deletions(-) create mode 100644 CopiumEngine/assets/framebuffer.meta create mode 100644 CopiumEngine/assets/passthrough.meta create mode 100644 CopiumEngine/assets/pipeline.meta create mode 100644 CopiumEngine/assets/renderer.meta create mode 100644 CopiumEngine/assets/rendertexture.meta 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 #include @@ -13,6 +14,8 @@ namespace Copium { CP_STATIC_CLASS(AssetManager); private: + using CreateAssetFunc = std::function; + static std::map assetTypes; static std::vector assetDirs; static std::map> assets; @@ -32,6 +35,13 @@ namespace Copium static Asset& RegisterRuntimeAsset(const std::string& name, std::unique_ptr&& asset); static void Cleanup(); + template + static void RegisterAssetType(const std::string& assetType) + { + CP_ASSERT(assetTypes.emplace(assetType, &AssetManager::CreateAsset).second, "Asset type already exists: %s", assetType.c_str()); + AssetFile::RegisterAssetType(assetType); + } + template static AssetT& LoadAsset(const std::string& assetPath) { @@ -66,7 +76,19 @@ namespace Copium } private: + static Asset& LoadAssetFromPath(const std::string& filepath); + template - 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(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; + } }; } diff --git a/CopiumEngine/src/copium/asset/AssetMeta.h b/CopiumEngine/src/copium/asset/AssetMeta.h index 3715893..226a978 100644 --- a/CopiumEngine/src/copium/asset/AssetMeta.h +++ b/CopiumEngine/src/copium/asset/AssetMeta.h @@ -7,20 +7,15 @@ namespace Copium { - enum class AssetType - { - Pipeline, - Texture2D, - Sound, - }; using AssetHandle = uint64_t; + static constexpr int NULL_ASSET_HANDLE = 0; struct AssetMeta { AssetHandle handle; - AssetType type; std::string name; UUID uuid; - bool isRuntime; + bool isRuntime = false; + int loadCount = 1; }; } \ No newline at end of file diff --git a/CopiumEngine/src/copium/buffer/Framebuffer.cpp b/CopiumEngine/src/copium/buffer/Framebuffer.cpp index a18a2d7..95bd86f 100644 --- a/CopiumEngine/src/copium/buffer/Framebuffer.cpp +++ b/CopiumEngine/src/copium/buffer/Framebuffer.cpp @@ -1,11 +1,24 @@ #include "copium/buffer/Framebuffer.h" +#include "copium/asset/AssetManager.h" #include "copium/buffer/CommandBuffer.h" #include "copium/core/Vulkan.h" #include "copium/sampler/Image.h" namespace Copium { + Framebuffer::Framebuffer(const MetaFile& metaFile) + { + const MetaFileClass& metaClass = metaFile.GetMetaClass("Framebuffer"); + ColorAttachment& attachment = AssetManager::LoadAsset(UUID{metaClass.GetValue("rendertexture-uuid")}); + colorAttachment = attachment; + width = attachment.GetWidth(); + height = attachment.GetHeight(); + InitializeDepthBuffer(); + InitializeRenderPass(); + InitializeFramebuffers(); + } + Framebuffer::Framebuffer(uint32_t width, uint32_t height) : width{width}, height{height} { @@ -20,6 +33,7 @@ namespace Copium for (auto& framebuffer : framebuffers) vkDestroyFramebuffer(Vulkan::GetDevice(), framebuffer, nullptr); vkDestroyRenderPass(Vulkan::GetDevice(), renderPass, nullptr); + AssetManager::UnloadAsset(colorAttachment); } void Framebuffer::Resize(uint32_t width, uint32_t height) @@ -27,12 +41,10 @@ namespace Copium vkDeviceWaitIdle(Vulkan::GetDevice()); this->width = width; this->height = height; - colorAttachment.reset(); - depthAttachment.reset(); for (auto&& framebuffer : framebuffers) vkDestroyFramebuffer(Vulkan::GetDevice(), framebuffer, nullptr); - InitializeImage(); - InitializeDepthBuffer(); + AssetManager::GetAsset(colorAttachment).Resize(width, height); + depthAttachment->Resize(width, height); InitializeFramebuffers(); } @@ -84,7 +96,7 @@ namespace Copium const ColorAttachment& Framebuffer::GetColorAttachment() const { - return *colorAttachment; + return AssetManager::GetAsset(colorAttachment); } uint32_t Framebuffer::GetWidth() const @@ -99,7 +111,7 @@ namespace Copium void Framebuffer::InitializeImage() { - colorAttachment = std::make_unique(width, height); + colorAttachment = AssetManager::RegisterRuntimeAsset("Framebuffer::ColorAttachment", std::make_unique(width, height)); } void Framebuffer::InitializeDepthBuffer() @@ -174,9 +186,10 @@ namespace Copium void Framebuffer::InitializeFramebuffers() { framebuffers.resize(SwapChain::MAX_FRAMES_IN_FLIGHT); + const ColorAttachment& attachment = AssetManager::GetAsset(colorAttachment); for (size_t i = 0; i < framebuffers.size(); ++i) { - std::vector attachments{colorAttachment->GetImageView(i), depthAttachment->GetImageView()}; + std::vector attachments{attachment.GetImageView(i), depthAttachment->GetImageView()}; VkFramebufferCreateInfo createInfo{}; createInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; diff --git a/CopiumEngine/src/copium/buffer/Framebuffer.h b/CopiumEngine/src/copium/buffer/Framebuffer.h index f0a57e1..1a5f36f 100644 --- a/CopiumEngine/src/copium/buffer/Framebuffer.h +++ b/CopiumEngine/src/copium/buffer/Framebuffer.h @@ -1,5 +1,7 @@ #pragma once +#include "copium/asset/Asset.h" +#include "copium/asset/AssetMeta.h" #include "copium/buffer/CommandBuffer.h" #include "copium/sampler/ColorAttachment.h" #include "copium/sampler/DepthAttachment.h" @@ -9,11 +11,11 @@ namespace Copium { - class Framebuffer final + class Framebuffer final : public Asset { CP_DELETE_COPY_AND_MOVE_CTOR(Framebuffer); private: - std::unique_ptr colorAttachment; + AssetHandle colorAttachment; std::unique_ptr depthAttachment; std::vector framebuffers; VkRenderPass renderPass; @@ -21,6 +23,7 @@ namespace Copium uint32_t width; uint32_t height; public: + Framebuffer(const MetaFile& metaFile); Framebuffer(uint32_t width, uint32_t height); ~Framebuffer(); diff --git a/CopiumEngine/src/copium/core/Application.cpp b/CopiumEngine/src/copium/core/Application.cpp index 43255d8..8d67ec4 100644 --- a/CopiumEngine/src/copium/core/Application.cpp +++ b/CopiumEngine/src/copium/core/Application.cpp @@ -52,16 +52,13 @@ namespace Copium vkDeviceWaitIdle(Vulkan::GetDevice()); AssetManager::UnloadAsset(texture2D); AssetManager::UnloadAsset(texture2D2); + AssetManager::UnloadAsset(graphicsPipeline); + AssetManager::UnloadAsset(graphicsPipelinePassthrough); + AssetManager::UnloadAsset(framebuffer); } 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()) return true; @@ -74,42 +71,37 @@ namespace Copium void Application::InitializeFrameBuffer() { - framebuffer = std::make_unique(Vulkan::GetSwapChain().GetExtent().width, Vulkan::GetSwapChain().GetExtent().height); + framebuffer = AssetManager::LoadAsset("framebuffer.meta"); } void Application::InitializeRenderer() { - renderer = std::make_unique(framebuffer->GetRenderPass()); + renderer = std::make_unique(); } void Application::InitializeTextureSampler() { - texture2D = AssetManager::LoadAsset("fox.meta"); - texture2D2 = AssetManager::LoadAsset("fox2.meta"); + texture2D = AssetManager::LoadAsset("fox.meta"); + texture2D2 = AssetManager::LoadAsset("fox2.meta"); } void Application::InitializeDescriptorSets() { descriptorPool = std::make_unique(); - descriptorSet = graphicsPipeline->CreateDescriptorSet(*descriptorPool, 0); + descriptorSet = AssetManager::GetAsset(graphicsPipeline).CreateDescriptorSet(*descriptorPool, 0); descriptorSet->SetSampler(AssetManager::GetAsset(texture2D), 1); - descriptorSetPassthrough = graphicsPipelinePassthrough->CreateDescriptorSet(*descriptorPool, 0); - descriptorSetPassthrough->SetSampler(framebuffer->GetColorAttachment(), 0); + descriptorSetPassthrough = AssetManager::GetAsset(graphicsPipelinePassthrough).CreateDescriptorSet(*descriptorPool, 0); + descriptorSetPassthrough->SetSampler(AssetManager::GetAsset(framebuffer).GetColorAttachment(), 0); descriptorSetRenderer = renderer->GetGraphicsPipeline().CreateDescriptorSet(*descriptorPool, 1); } void Application::InitializeGraphicsPipeline() { - PipelineCreator creator{framebuffer->GetRenderPass(), "res/shaders/shader.vert", "res/shaders/shader.frag"}; - creator.SetVertexDescriptor(Vertex::GetDescriptor()); - graphicsPipeline = std::make_unique(creator); - - PipelineCreator creatorPassthrough{Vulkan::GetSwapChain().GetRenderPass(), "res/shaders/passthrough.vert", "res/shaders/passthrough.frag"}; - creatorPassthrough.SetVertexDescriptor(VertexPassthrough::GetDescriptor()); - graphicsPipelinePassthrough = std::make_unique(creatorPassthrough); + graphicsPipeline = AssetManager::LoadAsset("pipeline.meta"); + graphicsPipelinePassthrough = AssetManager::LoadAsset("passthrough.meta"); } void Application::InitializeMesh() @@ -127,13 +119,15 @@ namespace Copium { commandBuffer->Begin(); - framebuffer->Bind(*commandBuffer); - graphicsPipeline->Bind(*commandBuffer); + Framebuffer& fb = AssetManager::GetAsset(framebuffer); + Pipeline& pl = AssetManager::GetAsset(graphicsPipeline); + fb.Bind(*commandBuffer); + pl.Bind(*commandBuffer); UpdateUniformBuffer(); - graphicsPipeline->SetDescriptorSet(*descriptorSet); - graphicsPipeline->BindDescriptorSets(*commandBuffer); + pl.SetDescriptorSet(*descriptorSet); + pl.BindDescriptorSets(*commandBuffer); mesh->Bind(*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(texture2D2)); renderer->End(); - framebuffer->Unbind(*commandBuffer); + fb.Unbind(*commandBuffer); Vulkan::GetSwapChain().BeginFrameBuffer(*commandBuffer); - graphicsPipelinePassthrough->Bind(*commandBuffer); - graphicsPipelinePassthrough->SetDescriptorSet(*descriptorSetPassthrough); - graphicsPipelinePassthrough->BindDescriptorSets(*commandBuffer); + Pipeline& plPassthrough = AssetManager::GetAsset(graphicsPipelinePassthrough); + plPassthrough.Bind(*commandBuffer); + plPassthrough.SetDescriptorSet(*descriptorSetPassthrough); + plPassthrough.BindDescriptorSets(*commandBuffer); meshPassthrough->Bind(*commandBuffer); meshPassthrough->Render(*commandBuffer); @@ -171,7 +166,8 @@ namespace Copium static Timer startTimer; float time = startTimer.Elapsed(); - float aspect = framebuffer->GetWidth() / (float)framebuffer->GetHeight(); + Framebuffer& fb = AssetManager::GetAsset(framebuffer); + float aspect = fb.GetWidth() / (float)fb.GetHeight(); { glm::mat4 projection = glm::perspective(glm::radians(45.0f), aspect, 0.1f, 10.0f); diff --git a/CopiumEngine/src/copium/core/Application.h b/CopiumEngine/src/copium/core/Application.h index c39c606..ef38697 100644 --- a/CopiumEngine/src/copium/core/Application.h +++ b/CopiumEngine/src/copium/core/Application.h @@ -15,15 +15,15 @@ namespace Copium CP_DELETE_COPY_AND_MOVE_CTOR(Application); private: std::unique_ptr renderer; - std::unique_ptr framebuffer; + AssetHandle framebuffer; AssetHandle texture2D; AssetHandle texture2D2; + AssetHandle graphicsPipeline; + AssetHandle graphicsPipelinePassthrough; std::unique_ptr descriptorPool; std::unique_ptr descriptorSet; std::unique_ptr descriptorSetPassthrough; std::unique_ptr descriptorSetRenderer; - std::unique_ptr graphicsPipeline; - std::unique_ptr graphicsPipelinePassthrough; std::unique_ptr mesh; std::unique_ptr meshPassthrough; std::unique_ptr commandBuffer; diff --git a/CopiumEngine/src/copium/core/Vulkan.cpp b/CopiumEngine/src/copium/core/Vulkan.cpp index 0717147..33a00e4 100644 --- a/CopiumEngine/src/copium/core/Vulkan.cpp +++ b/CopiumEngine/src/copium/core/Vulkan.cpp @@ -1,6 +1,10 @@ #include "copium/core/Vulkan.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 { @@ -16,6 +20,11 @@ namespace Copium device = std::make_unique(); swapChain = std::make_unique(); + AssetManager::RegisterAssetType("Texture2D"); + AssetManager::RegisterAssetType("RenderTexture"); + AssetManager::RegisterAssetType("Pipeline"); + AssetManager::RegisterAssetType("Framebuffer"); + // 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) AssetManager::RegisterAssetDir("assets/"); diff --git a/CopiumEngine/src/copium/main.cpp b/CopiumEngine/src/copium/main.cpp index 4c4616e..ced70fc 100644 --- a/CopiumEngine/src/copium/main.cpp +++ b/CopiumEngine/src/copium/main.cpp @@ -8,10 +8,6 @@ int main(int argc, char** argv) { 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(); { diff --git a/CopiumEngine/src/copium/pipeline/Pipeline.cpp b/CopiumEngine/src/copium/pipeline/Pipeline.cpp index 19b5058..a4fefd9 100644 --- a/CopiumEngine/src/copium/pipeline/Pipeline.cpp +++ b/CopiumEngine/src/copium/pipeline/Pipeline.cpp @@ -1,11 +1,51 @@ #include "copium/pipeline/Pipeline.h" +#include "copium/asset/AssetManager.h" +#include "copium/buffer/Framebuffer.h" #include "copium/core/Vulkan.h" #include "copium/pipeline/Shader.h" +#include "copium/renderer/RendererVertex.h" +#include "copium/mesh/VertexPassthrough.h" +#include "copium/mesh/Vertex.h" #include "copium/util/FileSystem.h" 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(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) : shaderReflector{creator.shaderReflector} { @@ -21,6 +61,10 @@ namespace Copium { vkDestroyDescriptorSetLayout(Vulkan::GetDevice(), descriptorSetLayout, nullptr); } + if (framebuffer != NULL_ASSET_HANDLE) + { + AssetManager::UnloadAsset(framebuffer); + } } void Pipeline::Bind(const CommandBuffer& commandBuffer) diff --git a/CopiumEngine/src/copium/pipeline/Pipeline.h b/CopiumEngine/src/copium/pipeline/Pipeline.h index d0be52a..de3e848 100644 --- a/CopiumEngine/src/copium/pipeline/Pipeline.h +++ b/CopiumEngine/src/copium/pipeline/Pipeline.h @@ -1,5 +1,6 @@ #pragma once +#include "copium/asset/Asset.h" #include "copium/buffer/CommandBuffer.h" #include "copium/pipeline/DescriptorSet.h" #include "copium/pipeline/PipelineCreator.h" @@ -10,7 +11,7 @@ namespace Copium { - class Pipeline final + class Pipeline final : public Asset { CP_DELETE_COPY_AND_MOVE_CTOR(Pipeline); private: @@ -19,8 +20,11 @@ namespace Copium std::vector boundDescriptorSets; VkPipelineLayout pipelineLayout; VkPipeline graphicsPipeline; + AssetHandle framebuffer; public: + + Pipeline(const MetaFile& metaFile); Pipeline(PipelineCreator creator); ~Pipeline(); void Bind(const CommandBuffer& commandBuffer); diff --git a/CopiumEngine/src/copium/renderer/Batch.cpp b/CopiumEngine/src/copium/renderer/Batch.cpp index f70bc01..ced4a96 100644 --- a/CopiumEngine/src/copium/renderer/Batch.cpp +++ b/CopiumEngine/src/copium/renderer/Batch.cpp @@ -1,13 +1,13 @@ #include "copium/renderer/Batch.h" +#include "copium/asset/AssetManager.h" #include "copium/renderer/RendererVertex.h" namespace Copium { - Batch::Batch(Pipeline& pipeline, DescriptorPool& descriptorPool, int vertexCount, const std::vector samplers) - : pipeline{pipeline}, - vertexBuffer{RendererVertex::GetDescriptor(), vertexCount}, - descriptorSet{pipeline.CreateDescriptorSet(descriptorPool, 0)} + Batch::Batch(AssetHandle pipeline, DescriptorPool& descriptorPool, int vertexCount, const std::vector samplers) + : vertexBuffer{RendererVertex::GetDescriptor(), vertexCount}, + descriptorSet{AssetManager::GetAsset(pipeline).CreateDescriptorSet(descriptorPool, 0)} { descriptorSet->SetSamplers(samplers, 0); } diff --git a/CopiumEngine/src/copium/renderer/Batch.h b/CopiumEngine/src/copium/renderer/Batch.h index 45975de..7104d9c 100644 --- a/CopiumEngine/src/copium/renderer/Batch.h +++ b/CopiumEngine/src/copium/renderer/Batch.h @@ -1,5 +1,6 @@ #pragma once +#include "copium/asset/AssetMeta.h" #include "copium/buffer/RendererVertexBuffer.h" #include "copium/pipeline/DescriptorSet.h" #include "copium/pipeline/Pipeline.h" @@ -11,12 +12,10 @@ namespace Copium { CP_DELETE_COPY_AND_MOVE_CTOR(Batch); private: - Pipeline& pipeline; - RendererVertexBuffer vertexBuffer; std::unique_ptr descriptorSet; public: - Batch(Pipeline& pipeline, DescriptorPool& descriptorPool, int vertexCount, const std::vector samplers); + Batch(AssetHandle pipeline, DescriptorPool& descriptorPool, int vertexCount, const std::vector samplers); RendererVertexBuffer& GetVertexBuffer(); DescriptorSet& GetDescriptorSet(); }; diff --git a/CopiumEngine/src/copium/renderer/Renderer.cpp b/CopiumEngine/src/copium/renderer/Renderer.cpp index c38c37a..aee5d45 100644 --- a/CopiumEngine/src/copium/renderer/Renderer.cpp +++ b/CopiumEngine/src/copium/renderer/Renderer.cpp @@ -12,19 +12,20 @@ namespace Copium static constexpr int MAX_NUM_INDICES = 6 * MAX_NUM_QUADS; static constexpr int MAX_NUM_TEXTURES = 32; - Renderer::Renderer(VkRenderPass renderPass) + Renderer::Renderer() : descriptorPool{}, ibo{MAX_NUM_INDICES}, emptyTexture{AssetManager::RegisterRuntimeAsset("empty", std::make_unique(std::vector{0, 0, 0, 255}, 1, 1))}, samplers{MAX_NUM_TEXTURES, &AssetManager::GetAsset(emptyTexture)} { InitializeIndexBuffer(); - InitializeGraphicsPipeline(renderPass); + InitializeGraphicsPipeline(); } Renderer::~Renderer() { AssetManager::UnloadAsset(emptyTexture); + AssetManager::UnloadAsset(pipeline); } 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) { - graphicsPipeline->Bind(commandBuffer); + AssetManager::GetAsset(pipeline).Bind(commandBuffer); ibo.Bind(commandBuffer); batchIndex = -1; NextBatch(); @@ -73,12 +74,12 @@ namespace Copium Pipeline& Renderer::GetGraphicsPipeline() { - return *graphicsPipeline; + return AssetManager::GetAsset(pipeline); } void Renderer::SetDescriptorSet(const DescriptorSet& descriptorSet) { - graphicsPipeline->SetDescriptorSet(descriptorSet); + AssetManager::GetAsset(pipeline).SetDescriptorSet(descriptorSet); } void Renderer::InitializeIndexBuffer() @@ -99,19 +100,16 @@ namespace Copium ibo.UpdateStaging(indices.data()); } - void Renderer::InitializeGraphicsPipeline(VkRenderPass renderPass) + void Renderer::InitializeGraphicsPipeline() { - PipelineCreator creator{renderPass, "res/shaders/renderer.vert", "res/shaders/renderer.frag"}; - creator.SetVertexDescriptor(RendererVertex::GetDescriptor()); - creator.SetDepthTest(false); - graphicsPipeline = std::make_unique(creator); + pipeline = AssetManager::LoadAsset("renderer.meta"); } int Renderer::AllocateSampler(const Sampler& sampler) { for (size_t i = 0; i < textureCount; i++) { - if (*samplers[i] == sampler) + if (*samplers[i] == (VkSampler)sampler) { return i; } @@ -142,8 +140,8 @@ namespace Copium { batches[batchIndex]->GetVertexBuffer().Unmap(); batches[batchIndex]->GetVertexBuffer().Bind(*currentCommandBuffer); - graphicsPipeline->SetDescriptorSet(batches[batchIndex]->GetDescriptorSet()); - graphicsPipeline->BindDescriptorSets(*currentCommandBuffer); + AssetManager::GetAsset(pipeline).SetDescriptorSet(batches[batchIndex]->GetDescriptorSet()); + AssetManager::GetAsset(pipeline).BindDescriptorSets(*currentCommandBuffer); ibo.Draw(*currentCommandBuffer, quadCount * 6); } @@ -153,7 +151,7 @@ namespace Copium std::fill(samplers.begin(), samplers.end(), &AssetManager::GetAsset(emptyTexture)); if (batchIndex >= batches.size()) { - batches.emplace_back(std::make_unique(*graphicsPipeline, descriptorPool, MAX_NUM_VERTICES, samplers)); + batches.emplace_back(std::make_unique(pipeline, descriptorPool, MAX_NUM_VERTICES, samplers)); } mappedVertexBuffer = (char*)batches[batchIndex]->GetVertexBuffer().Map() + batches[batchIndex]->GetVertexBuffer().GetPosition(Vulkan::GetSwapChain().GetFlightIndex()); quadCount = 0; diff --git a/CopiumEngine/src/copium/renderer/Renderer.h b/CopiumEngine/src/copium/renderer/Renderer.h index 5209fea..52c4477 100644 --- a/CopiumEngine/src/copium/renderer/Renderer.h +++ b/CopiumEngine/src/copium/renderer/Renderer.h @@ -1,5 +1,6 @@ #pragma once +#include "copium/asset/AssetMeta.h" #include "copium/buffer/CommandBuffer.h" #include "copium/buffer/IndexBuffer.h" #include "copium/buffer/RendererVertexBuffer.h" @@ -20,7 +21,7 @@ namespace Copium DescriptorPool descriptorPool; IndexBuffer ibo; AssetHandle emptyTexture; - std::unique_ptr graphicsPipeline; + AssetHandle pipeline; std::vector> batches; // Temporary data during a render @@ -31,7 +32,7 @@ namespace Copium int textureCount; void* mappedVertexBuffer; public: - Renderer(VkRenderPass renderPass); + Renderer(); ~Renderer(); 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); private: void InitializeIndexBuffer(); - void InitializeGraphicsPipeline(VkRenderPass renderPass); + void InitializeGraphicsPipeline(); int AllocateSampler(const Sampler& sampler); void AllocateQuad(); diff --git a/CopiumEngine/src/copium/sampler/ColorAttachment.cpp b/CopiumEngine/src/copium/sampler/ColorAttachment.cpp index 2771e15..e5e6545 100644 --- a/CopiumEngine/src/copium/sampler/ColorAttachment.cpp +++ b/CopiumEngine/src/copium/sampler/ColorAttachment.cpp @@ -5,8 +5,32 @@ 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) - : Sampler{} { InitializeColorAttachment(width, height); } @@ -21,6 +45,28 @@ namespace Copium 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 { CP_ASSERT(index >= 0 && index < imageViews.size(), "index out of bound for color attachment"); @@ -32,7 +78,7 @@ namespace Copium return imageInfo; } - VkImageView ColorAttachment::GetImageView(int index) + VkImageView ColorAttachment::GetImageView(int index) const { CP_ASSERT(index >= 0 && index < imageViews.size(), "Index out of bound"); diff --git a/CopiumEngine/src/copium/sampler/ColorAttachment.h b/CopiumEngine/src/copium/sampler/ColorAttachment.h index 33035e8..abefd61 100644 --- a/CopiumEngine/src/copium/sampler/ColorAttachment.h +++ b/CopiumEngine/src/copium/sampler/ColorAttachment.h @@ -14,12 +14,19 @@ namespace Copium std::vector images; std::vector imageMemories; std::vector imageViews; + int width; + int height; public: + ColorAttachment(const MetaFile& metaFile); ColorAttachment(int width, int height); ~ColorAttachment() override; + void Resize(int width, int height); + + int GetWidth() const; + int GetHeight() const; VkDescriptorImageInfo GetDescriptorImageInfo(int index) const override; - VkImageView GetImageView(int index); + VkImageView GetImageView(int index) const; private: void InitializeColorAttachment(int width, int height); diff --git a/CopiumEngine/src/copium/sampler/DepthAttachment.cpp b/CopiumEngine/src/copium/sampler/DepthAttachment.cpp index 225882f..b40a4a6 100644 --- a/CopiumEngine/src/copium/sampler/DepthAttachment.cpp +++ b/CopiumEngine/src/copium/sampler/DepthAttachment.cpp @@ -18,6 +18,15 @@ namespace Copium 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 imageInfo{}; diff --git a/CopiumEngine/src/copium/sampler/DepthAttachment.h b/CopiumEngine/src/copium/sampler/DepthAttachment.h index a1bf302..f69d766 100644 --- a/CopiumEngine/src/copium/sampler/DepthAttachment.h +++ b/CopiumEngine/src/copium/sampler/DepthAttachment.h @@ -18,6 +18,8 @@ namespace Copium DepthAttachment(int width, int height); ~DepthAttachment() override; + void Resize(int width, int height); + VkDescriptorImageInfo GetDescriptorImageInfo(int index) const override; VkImageView GetImageView() const; diff --git a/CopiumEngine/src/copium/sampler/Sampler.h b/CopiumEngine/src/copium/sampler/Sampler.h index fcda33f..a6a1466 100644 --- a/CopiumEngine/src/copium/sampler/Sampler.h +++ b/CopiumEngine/src/copium/sampler/Sampler.h @@ -1,12 +1,13 @@ #pragma once +#include "copium/asset/Asset.h" #include "copium/util/Common.h" #include namespace Copium { - class Sampler + class Sampler : public Asset { CP_DELETE_COPY_AND_MOVE_CTOR(Sampler); protected: diff --git a/CopiumEngine/src/copium/sampler/Texture2D.cpp b/CopiumEngine/src/copium/sampler/Texture2D.cpp index 1ca4231..5c7df62 100644 --- a/CopiumEngine/src/copium/sampler/Texture2D.cpp +++ b/CopiumEngine/src/copium/sampler/Texture2D.cpp @@ -10,7 +10,6 @@ namespace Copium { Texture2D::Texture2D(const MetaFile& metaFile) - : Sampler{}, Asset{AssetType::Texture2D} { const std::string& filepath = metaFile.GetMetaClass("Texture2D").GetValue("filepath"); CP_DEBUG("Loading texture file: %s", filepath.c_str()); @@ -18,7 +17,6 @@ namespace Copium } Texture2D::Texture2D(const std::vector& 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()); InitializeTextureImageFromData((void*)rgbaData.data(), width, height); diff --git a/CopiumEngine/src/copium/sampler/Texture2D.h b/CopiumEngine/src/copium/sampler/Texture2D.h index 5f3dcf4..12ab48a 100644 --- a/CopiumEngine/src/copium/sampler/Texture2D.h +++ b/CopiumEngine/src/copium/sampler/Texture2D.h @@ -1,6 +1,5 @@ #pragma once -#include "copium/asset/Asset.h" #include "copium/buffer/CommandBufferScoped.h" #include "copium/sampler/Image.h" #include "copium/sampler/Sampler.h" @@ -10,7 +9,7 @@ namespace Copium { - class Texture2D final : public Sampler, public Asset + class Texture2D final : public Sampler { CP_DELETE_COPY_AND_MOVE_CTOR(Texture2D); private: