Fix multiple creation of runtime framebuffers
- Framebuffer names are now generated based on Uuids, as such we can create multiple runtime Framebuffers - Framebuffers now uses ints instead of uint32_t, to avoid issues where we do "-framebuffer.GetWidth()", which will return an odd uint32_t value - Add some additional AssetRef constructors
This commit is contained in:
@@ -146,18 +146,18 @@ namespace Copium
|
|||||||
CP_ASSERT(pathToAssetCache.empty(), "Path 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, const Uuid& uuid, std::unique_ptr<Asset>&& asset)
|
||||||
{
|
{
|
||||||
CP_DEBUG("Registering Runtime Asset: %s", name.c_str());
|
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.c_str());
|
||||||
|
|
||||||
AssetId id = runtimeAssetId++;
|
AssetId id = runtimeAssetId++;
|
||||||
Asset* asset2 = assets.emplace(id, std::move(asset)).first->second.get();
|
Asset* asset2 = assets.emplace(id, std::move(asset)).first->second.get();
|
||||||
asset2->metaData.id = id;
|
asset2->metaData.id = id;
|
||||||
asset2->metaData.name = name;
|
asset2->metaData.name = name;
|
||||||
asset2->metaData.uuid = Uuid();
|
asset2->metaData.uuid = uuid;
|
||||||
asset2->metaData.isRuntime = true;
|
asset2->metaData.isRuntime = true;
|
||||||
nameToAssetCache.emplace(name, id);
|
nameToAssetCache.emplace(name, id);
|
||||||
return *asset2;
|
return *asset2;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace Copium
|
|||||||
static Asset& LoadAsset(const Uuid& uuid);
|
static Asset& LoadAsset(const Uuid& uuid);
|
||||||
static AssetId DuplicateAsset(AssetId id);
|
static AssetId DuplicateAsset(AssetId id);
|
||||||
static void UnloadAsset(AssetId id);
|
static void UnloadAsset(AssetId id);
|
||||||
static Asset& RegisterRuntimeAsset(const std::string& name, std::unique_ptr<Asset>&& asset);
|
static Asset& RegisterRuntimeAsset(const std::string& name, const Uuid& uuid, std::unique_ptr<Asset>&& asset);
|
||||||
static const std::vector<AssetFile>& GetAssetFiles();
|
static const std::vector<AssetFile>& GetAssetFiles();
|
||||||
static void Cleanup();
|
static void Cleanup();
|
||||||
|
|
||||||
@@ -70,13 +70,25 @@ namespace Copium
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename AssetT>
|
template <typename AssetT>
|
||||||
static AssetT& RegisterRuntimeAsset(const std::string& name, std::unique_ptr<AssetT>&& assetT)
|
static AssetT& RegisterRuntimeAsset(const std::string& name, const Uuid& uuid, std::unique_ptr<AssetT>&& assetT)
|
||||||
{
|
{
|
||||||
AssetT* ptr = assetT.release();
|
AssetT* ptr = assetT.release();
|
||||||
Asset& asset = RegisterRuntimeAsset(name, std::unique_ptr<Asset>((Asset*)ptr));
|
Asset& asset = RegisterRuntimeAsset(name, uuid, std::unique_ptr<Asset>((Asset*)ptr));
|
||||||
return *(AssetT*)&asset;
|
return *(AssetT*)&asset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename AssetT>
|
||||||
|
static AssetT& RegisterRuntimeAsset(const std::string& name, std::unique_ptr<AssetT>&& assetT)
|
||||||
|
{
|
||||||
|
return RegisterRuntimeAsset(name, Uuid{}, std::move(assetT));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename AssetT>
|
||||||
|
static AssetT& RegisterRuntimeAsset(const Uuid& uuid, std::unique_ptr<AssetT>&& assetT)
|
||||||
|
{
|
||||||
|
return RegisterRuntimeAsset(uuid.ToString(), uuid, std::move(assetT));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Asset& LoadAssetFromPath(const std::string& filepath);
|
static Asset& LoadAssetFromPath(const std::string& filepath);
|
||||||
|
|
||||||
|
|||||||
@@ -12,22 +12,34 @@ namespace Copium
|
|||||||
: id{std::shared_ptr<AssetId>(new AssetId(NULL_ASSET_ID), AssetIdUnloader{})}
|
: id{std::shared_ptr<AssetId>(new AssetId(NULL_ASSET_ID), AssetIdUnloader{})}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
AssetRef(const std::string& assetName)
|
explicit AssetRef(const std::string& assetName)
|
||||||
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::LoadAsset(assetName).GetId()), AssetIdUnloader{})}
|
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::LoadAsset(assetName).GetId()), AssetIdUnloader{})}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
AssetRef(const Uuid& uuid)
|
explicit AssetRef(const Uuid& uuid)
|
||||||
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::LoadAsset(uuid).GetId()), AssetIdUnloader{})}
|
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::LoadAsset(uuid).GetId()), AssetIdUnloader{})}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
AssetRef(AssetType& asset)
|
explicit AssetRef(AssetType& asset)
|
||||||
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::DuplicateAsset(asset.GetId())), AssetIdUnloader{})}
|
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::DuplicateAsset(asset.GetId())), AssetIdUnloader{})}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
explicit AssetRef(std::unique_ptr<AssetType>&& runtimeAsset)
|
||||||
|
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::RegisterRuntimeAsset(Uuid{}, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})}
|
||||||
|
{}
|
||||||
|
|
||||||
|
AssetRef(const Uuid& uuid, std::unique_ptr<AssetType>&& runtimeAsset)
|
||||||
|
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::RegisterRuntimeAsset(uuid, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})}
|
||||||
|
{}
|
||||||
|
|
||||||
AssetRef(const std::string& name, std::unique_ptr<AssetType>&& runtimeAsset)
|
AssetRef(const std::string& name, std::unique_ptr<AssetType>&& runtimeAsset)
|
||||||
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::RegisterRuntimeAsset(name, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})}
|
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::RegisterRuntimeAsset(name, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
AssetRef(const std::string& name, const Uuid& uuid, std::unique_ptr<AssetType>&& runtimeAsset)
|
||||||
|
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::RegisterRuntimeAsset(name, uuid, std::move(runtimeAsset)).GetId()), AssetIdUnloader{})}
|
||||||
|
{}
|
||||||
|
|
||||||
AssetRef(AssetId id)
|
AssetRef(AssetId id)
|
||||||
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::DuplicateAsset(id)), AssetIdUnloader{})}
|
: id{std::shared_ptr<AssetId>(new AssetId(AssetManager::DuplicateAsset(id)), AssetIdUnloader{})}
|
||||||
{}
|
{}
|
||||||
|
|||||||
@@ -12,17 +12,24 @@ namespace Copium
|
|||||||
const MetaFileClass& metaClass = metaFile.GetMetaClass("Framebuffer");
|
const MetaFileClass& metaClass = metaFile.GetMetaClass("Framebuffer");
|
||||||
colorAttachment = AssetRef<ColorAttachment>(Uuid{metaClass.GetValue("rendertexture-uuid")});
|
colorAttachment = AssetRef<ColorAttachment>(Uuid{metaClass.GetValue("rendertexture-uuid")});
|
||||||
ColorAttachment& attachment = colorAttachment.GetAsset();
|
ColorAttachment& attachment = colorAttachment.GetAsset();
|
||||||
|
|
||||||
width = attachment.GetWidth();
|
width = attachment.GetWidth();
|
||||||
height = attachment.GetHeight();
|
height = attachment.GetHeight();
|
||||||
|
CP_ASSERT(width > 0, "Width of framebuffer is less than 1: %d", width);
|
||||||
|
CP_ASSERT(height > 0, "Height of framebuffer is less than 1: %d", height);
|
||||||
|
|
||||||
InitializeDepthBuffer();
|
InitializeDepthBuffer();
|
||||||
InitializeRenderPass();
|
InitializeRenderPass();
|
||||||
InitializeFramebuffers();
|
InitializeFramebuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
Framebuffer::Framebuffer(uint32_t width, uint32_t height)
|
Framebuffer::Framebuffer(int width, int height, const SamplerCreator& samplerCreator)
|
||||||
: width{width}, height{height}
|
: width{width}, height{height}
|
||||||
{
|
{
|
||||||
InitializeImage();
|
CP_ASSERT(width > 0, "Width of framebuffer is less than 1: %d", width);
|
||||||
|
CP_ASSERT(height > 0, "Height of framebuffer is less than 1: %d", height);
|
||||||
|
|
||||||
|
InitializeImage(samplerCreator);
|
||||||
InitializeDepthBuffer();
|
InitializeDepthBuffer();
|
||||||
InitializeRenderPass();
|
InitializeRenderPass();
|
||||||
InitializeFramebuffers();
|
InitializeFramebuffers();
|
||||||
@@ -39,8 +46,11 @@ namespace Copium
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framebuffer::Resize(uint32_t width, uint32_t height)
|
void Framebuffer::Resize(int width, int height)
|
||||||
{
|
{
|
||||||
|
CP_ASSERT(width > 0, "Width of framebuffer is less than 1: %d", width);
|
||||||
|
CP_ASSERT(height > 0, "Height of framebuffer is less than 1: %d", height);
|
||||||
|
|
||||||
Vulkan::GetDevice().WaitIdle();
|
Vulkan::GetDevice().WaitIdle();
|
||||||
this->width = width;
|
this->width = width;
|
||||||
this->height = height;
|
this->height = height;
|
||||||
@@ -61,9 +71,9 @@ namespace Copium
|
|||||||
renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||||
renderPassBeginInfo.renderPass = renderPass;
|
renderPassBeginInfo.renderPass = renderPass;
|
||||||
renderPassBeginInfo.framebuffer = framebuffers[Vulkan::GetSwapChain().GetFlightIndex()];
|
renderPassBeginInfo.framebuffer = framebuffers[Vulkan::GetSwapChain().GetFlightIndex()];
|
||||||
;
|
|
||||||
renderPassBeginInfo.renderArea.offset = {0, 0};
|
renderPassBeginInfo.renderArea.offset = {0, 0};
|
||||||
renderPassBeginInfo.renderArea.extent = {width, height};
|
renderPassBeginInfo.renderArea.extent = {static_cast<uint32_t>(width), static_cast<uint32_t>(height)};
|
||||||
renderPassBeginInfo.clearValueCount = clearValues.size();
|
renderPassBeginInfo.clearValueCount = clearValues.size();
|
||||||
renderPassBeginInfo.pClearValues = clearValues.data();
|
renderPassBeginInfo.pClearValues = clearValues.data();
|
||||||
vkCmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
vkCmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||||
@@ -78,7 +88,7 @@ namespace Copium
|
|||||||
vkCmdSetViewport(commandBuffer, 0, 1, &viewport);
|
vkCmdSetViewport(commandBuffer, 0, 1, &viewport);
|
||||||
VkRect2D scissor{};
|
VkRect2D scissor{};
|
||||||
scissor.offset = {0, 0};
|
scissor.offset = {0, 0};
|
||||||
scissor.extent = {width, height};
|
scissor.extent = {static_cast<uint32_t>(width), static_cast<uint32_t>(height)};
|
||||||
vkCmdSetScissor(commandBuffer, 0, 1, &scissor);
|
vkCmdSetScissor(commandBuffer, 0, 1, &scissor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,19 +112,19 @@ namespace Copium
|
|||||||
return colorAttachment.GetAsset();
|
return colorAttachment.GetAsset();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Framebuffer::GetWidth() const
|
int Framebuffer::GetWidth() const
|
||||||
{
|
{
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Framebuffer::GetHeight() const
|
int Framebuffer::GetHeight() const
|
||||||
{
|
{
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framebuffer::InitializeImage()
|
void Framebuffer::InitializeImage(const SamplerCreator& samplerCreator)
|
||||||
{
|
{
|
||||||
colorAttachment = AssetManager::RegisterRuntimeAsset("Framebuffer::ColorAttachment", std::make_unique<ColorAttachment>(width, height, SamplerCreator{}));
|
colorAttachment = AssetRef(std::make_unique<ColorAttachment>(width, height, samplerCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framebuffer::InitializeDepthBuffer()
|
void Framebuffer::InitializeDepthBuffer()
|
||||||
|
|||||||
@@ -20,25 +20,25 @@ namespace Copium
|
|||||||
std::vector<VkFramebuffer> framebuffers;
|
std::vector<VkFramebuffer> framebuffers;
|
||||||
VkRenderPass renderPass;
|
VkRenderPass renderPass;
|
||||||
|
|
||||||
uint32_t width;
|
int width;
|
||||||
uint32_t height;
|
int height;
|
||||||
public:
|
public:
|
||||||
Framebuffer(const MetaFile& metaFile);
|
Framebuffer(const MetaFile& metaFile);
|
||||||
Framebuffer(uint32_t width, uint32_t height);
|
Framebuffer(int width, int height, const SamplerCreator& samplerCreator);
|
||||||
~Framebuffer();
|
~Framebuffer();
|
||||||
|
|
||||||
void Resize(uint32_t width, uint32_t height);
|
void Resize(int width, int height);
|
||||||
void Bind(const CommandBuffer& commandBuffer);
|
void Bind(const CommandBuffer& commandBuffer);
|
||||||
void Unbind(const CommandBuffer& commandBuffer);
|
void Unbind(const CommandBuffer& commandBuffer);
|
||||||
|
|
||||||
VkRenderPass GetRenderPass() const;
|
VkRenderPass GetRenderPass() const;
|
||||||
VkFramebuffer GetFramebuffer() const;
|
VkFramebuffer GetFramebuffer() const;
|
||||||
const ColorAttachment& GetColorAttachment() const;
|
const ColorAttachment& GetColorAttachment() const;
|
||||||
uint32_t GetWidth() const;
|
int GetWidth() const;
|
||||||
uint32_t GetHeight() const;
|
int GetHeight() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitializeImage();
|
void InitializeImage(const SamplerCreator& samplerCreator);
|
||||||
void InitializeDepthBuffer();
|
void InitializeDepthBuffer();
|
||||||
void InitializeRenderPass();
|
void InitializeRenderPass();
|
||||||
void InitializeFramebuffers();
|
void InitializeFramebuffers();
|
||||||
|
|||||||
Reference in New Issue
Block a user