Add Asset system

- Add Abstract Asset class which defines Assets
- Add AssetManager class to keep track of all the Asset
- Add AssetFile class to cache the asset without loading it
- Add UUID class to uniquely identify assets
- Add MetaFile class to load meta asset files
This commit is contained in:
Thraix
2023-04-13 21:00:36 +02:00
parent 431ad9c573
commit d9e7fd7019
29 changed files with 1002 additions and 37 deletions
+8 -5
View File
@@ -3,6 +3,7 @@
#include "copium/core/Vulkan.h"
#include "copium/mesh/Vertex.h"
#include "copium/mesh/VertexPassthrough.h"
#include "copium/asset/AssetManager.h"
#include <glm/gtc/matrix_transform.hpp>
@@ -49,6 +50,8 @@ namespace Copium
Application::~Application()
{
vkDeviceWaitIdle(Vulkan::GetDevice());
AssetManager::UnloadAsset(texture2D);
AssetManager::UnloadAsset(texture2D2);
}
bool Application::Update()
@@ -81,8 +84,8 @@ namespace Copium
void Application::InitializeTextureSampler()
{
texture2D = std::make_unique<Texture2D>("res/textures/texture.png");
texture2D2 = std::make_unique<Texture2D>("res/textures/texture2.png");
texture2D = AssetManager::LoadAsset("fox.meta");
texture2D2 = AssetManager::LoadAsset("fox2.meta");
}
void Application::InitializeDescriptorSets()
@@ -90,7 +93,7 @@ namespace Copium
descriptorPool = std::make_unique<DescriptorPool>();
descriptorSet = graphicsPipeline->CreateDescriptorSet(*descriptorPool, 0);
descriptorSet->SetSampler(*texture2D, 1);
descriptorSet->SetSampler(AssetManager::GetAsset<Texture2D>(texture2D), 1);
descriptorSetPassthrough = graphicsPipelinePassthrough->CreateDescriptorSet(*descriptorPool, 0);
descriptorSetPassthrough->SetSampler(framebuffer->GetColorAttachment(), 0);
@@ -144,8 +147,8 @@ namespace Copium
renderer->Quad(glm::vec2{-1 + x * 0.2 + 0.05, -1 + y * 0.2 + 0.05}, glm::vec2{0.1, 0.1}, glm::vec3{x * 0.1, y * 0.1, 1.0});
}
}
renderer->Quad(glm::vec2{-0.9, -0.4}, glm::vec2{0.8, 0.8}, *texture2D);
renderer->Quad(glm::vec2{ 0.1, -0.4}, glm::vec2{0.8, 0.8}, *texture2D2);
renderer->Quad(glm::vec2{-0.9, -0.4}, glm::vec2{0.8, 0.8}, AssetManager::GetAsset<Texture2D>(texture2D));
renderer->Quad(glm::vec2{ 0.1, -0.4}, glm::vec2{0.8, 0.8}, AssetManager::GetAsset<Texture2D>(texture2D2));
renderer->End();
framebuffer->Unbind(*commandBuffer);
+3 -3
View File
@@ -1,12 +1,12 @@
#pragma once
#include "copium/asset/AssetMeta.h"
#include "copium/buffer/Framebuffer.h"
#include "copium/mesh/Mesh.h"
#include "copium/pipeline/DescriptorPool.h"
#include "copium/pipeline/DescriptorSet.h"
#include "copium/pipeline/Pipeline.h"
#include "copium/renderer/Renderer.h"
#include "copium/sampler/Texture2D.h"
namespace Copium
{
@@ -16,8 +16,8 @@ namespace Copium
private:
std::unique_ptr<Renderer> renderer;
std::unique_ptr<Framebuffer> framebuffer;
std::unique_ptr<Texture2D> texture2D;
std::unique_ptr<Texture2D> texture2D2;
AssetHandle texture2D;
AssetHandle texture2D2;
std::unique_ptr<DescriptorPool> descriptorPool;
std::unique_ptr<DescriptorSet> descriptorSet;
std::unique_ptr<DescriptorSet> descriptorSetPassthrough;
+9 -1
View File
@@ -1,5 +1,7 @@
#include "copium/core/Vulkan.h"
#include "copium/asset/AssetManager.h"
namespace Copium
{
std::unique_ptr<Instance> Vulkan::instance;
@@ -10,13 +12,19 @@ namespace Copium
void Vulkan::Initialize()
{
instance = std::make_unique<Instance>("Copium Engine");
window = std::make_unique<Window>( "Copium Engine", 1920, 1080, Window::Mode::Windowed);
window = std::make_unique<Window>("Copium Engine", 1920, 1080, Window::Mode::Windowed);
device = std::make_unique<Device>();
swapChain = std::make_unique<SwapChain>();
// 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/");
}
void Vulkan::Destroy()
{
AssetManager::UnregisterAssetDir("assets/");
AssetManager::Cleanup();
swapChain.reset();
device.reset();
window.reset();