Cleanup code
This commit is contained in:
@@ -172,7 +172,7 @@ namespace openVulkanoCpp::Vulkan
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceManager::PrepareCamera(Scene::Camera* camera)
|
||||
VulkanCamera* ResourceManager::PrepareCamera(Scene::Camera* camera)
|
||||
{
|
||||
const std::unique_lock lock(mutex);
|
||||
if (!camera->renderCamera)
|
||||
@@ -187,6 +187,7 @@ namespace openVulkanoCpp::Vulkan
|
||||
vkCam->Init(camera, uBuffer);
|
||||
camera->renderCamera = vkCam;
|
||||
}
|
||||
return static_cast<VulkanCamera*>(camera->renderCamera);
|
||||
}
|
||||
|
||||
UniformBuffer* ResourceManager::CreateUniformBuffer(const DescriptorSetLayoutBinding& binding, size_t size, void* data, uint32_t setId)
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace openVulkanoCpp
|
||||
class Context;
|
||||
class VulkanGeometry;
|
||||
class VulkanTexture;
|
||||
class VulkanCamera;
|
||||
class UniformBuffer;
|
||||
|
||||
class ResourceManager : public ICloseable, public IShaderOwner
|
||||
@@ -83,7 +84,7 @@ namespace openVulkanoCpp
|
||||
|
||||
VulkanTexture* PrepareTexture(Scene::Texture* texture);
|
||||
|
||||
void PrepareCamera(Scene::Camera* camera);
|
||||
VulkanCamera* PrepareCamera(Scene::Camera* camera);
|
||||
|
||||
void RemoveShader(VulkanShader* shader) override;
|
||||
|
||||
|
||||
46
openVulkanoCpp/Vulkan/Resources/UniformBuffer.cpp
Normal file
46
openVulkanoCpp/Vulkan/Resources/UniformBuffer.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "UniformBuffer.hpp"
|
||||
#include "ManagedResource.hpp"
|
||||
#include "ResourceManager.hpp"
|
||||
#include "Vulkan/VulkanDrawContext.hpp"
|
||||
#include "Vulkan/Scene/VulkanShader.hpp"
|
||||
|
||||
namespace openVulkanoCpp::Vulkan
|
||||
{
|
||||
void UniformBuffer::Init(ManagedBuffer* buffer, uint32_t frameOffset, uint32_t frameSize, vk::DescriptorSetLayout* descriptorSetLayout, const DescriptorSetLayoutBinding& binding, uint32_t setId)
|
||||
{
|
||||
m_buffer = buffer;
|
||||
m_frameOffset = frameOffset;
|
||||
|
||||
const vk::DescriptorSetAllocateInfo descSetAllocInfo = { ResourceManager::INSTANCE->descriptorPool, 1, descriptorSetLayout };
|
||||
m_descriptorSet = buffer->allocation->device.allocateDescriptorSets(descSetAllocInfo)[0];
|
||||
vk::DescriptorBufferInfo bufferInfo = { buffer->buffer, 0, frameSize };
|
||||
vk::WriteDescriptorSet writeDescriptorSet = { m_descriptorSet, binding.bindingId, 0, 1 };
|
||||
writeDescriptorSet.descriptorType = static_cast<vk::DescriptorType>(binding.descriptorType);
|
||||
writeDescriptorSet.pBufferInfo = &bufferInfo;
|
||||
buffer->allocation->device.updateDescriptorSets(1, &writeDescriptorSet, 0, nullptr);
|
||||
m_setOffset = setId;
|
||||
}
|
||||
|
||||
void UniformBuffer::Close()
|
||||
{ //TODO handle this better
|
||||
m_buffer->allocation->device.freeDescriptorSets(ResourceManager::INSTANCE->descriptorPool, 1, &m_descriptorSet);
|
||||
m_buffer = nullptr;
|
||||
}
|
||||
|
||||
void UniformBuffer::Record(VulkanDrawContext* drawContext)
|
||||
{
|
||||
uint32_t frameOffset = m_frameOffset * drawContext->currentImageId;
|
||||
drawContext->commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, drawContext->GetShader()->pipelineLayout, m_setOffset, m_setCount, &m_descriptorSet, (m_frameOffset) ? 1 : 0, &frameOffset);
|
||||
}
|
||||
|
||||
void UniformBuffer::Update(void* data, uint32_t size, uint32_t bufferId) const
|
||||
{
|
||||
m_buffer->Copy(data, size, m_frameOffset * bufferId);
|
||||
}
|
||||
}
|
||||
@@ -7,16 +7,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "Base/ICloseable.hpp"
|
||||
#include "ManagedResource.hpp"
|
||||
#include "Vulkan/Scene/IRecordable.hpp"
|
||||
#include "Vulkan/Scene/VulkanShader.hpp"
|
||||
#include "Vulkan/VulkanDrawContext.hpp"
|
||||
|
||||
namespace openVulkanoCpp::Vulkan
|
||||
{
|
||||
class UniformBuffer final : IRecordable, ICloseable
|
||||
struct ManagedBuffer;
|
||||
|
||||
class UniformBuffer final : public IRecordable, public ICloseable
|
||||
{
|
||||
ManagedBuffer* m_buffer;
|
||||
ManagedBuffer* m_buffer = nullptr;
|
||||
vk::DescriptorSet m_descriptorSet;
|
||||
uint32_t m_frameOffset;
|
||||
uint32_t m_setOffset, m_setCount = 1;
|
||||
@@ -27,36 +26,12 @@ namespace openVulkanoCpp::Vulkan
|
||||
if (m_buffer) Close();
|
||||
}
|
||||
|
||||
void Init(ManagedBuffer* buffer, uint32_t frameOffset, uint32_t frameSize, vk::DescriptorSetLayout* descriptorSetLayout, const DescriptorSetLayoutBinding& binding, uint32_t setId)
|
||||
{
|
||||
m_buffer = buffer;
|
||||
m_frameOffset = frameOffset;
|
||||
void Init(ManagedBuffer* buffer, uint32_t frameOffset, uint32_t frameSize, vk::DescriptorSetLayout* descriptorSetLayout, const DescriptorSetLayoutBinding& binding, uint32_t setId);
|
||||
|
||||
const vk::DescriptorSetAllocateInfo descSetAllocInfo = { ResourceManager::INSTANCE->descriptorPool, 1, descriptorSetLayout };
|
||||
m_descriptorSet = buffer->allocation->device.allocateDescriptorSets(descSetAllocInfo)[0];
|
||||
vk::DescriptorBufferInfo bufferInfo = { buffer->buffer, 0, frameSize };
|
||||
vk::WriteDescriptorSet writeDescriptorSet = { m_descriptorSet, binding.bindingId, 0, 1 };
|
||||
writeDescriptorSet.descriptorType = static_cast<vk::DescriptorType>(binding.descriptorType);
|
||||
writeDescriptorSet.pBufferInfo = &bufferInfo;
|
||||
buffer->allocation->device.updateDescriptorSets(1, &writeDescriptorSet, 0, nullptr);
|
||||
m_setOffset = setId;
|
||||
}
|
||||
void Close() override;
|
||||
|
||||
void Close() override
|
||||
{ //TODO handle this better
|
||||
m_buffer->allocation->device.freeDescriptorSets(ResourceManager::INSTANCE->descriptorPool, 1, &m_descriptorSet);
|
||||
m_buffer = nullptr;
|
||||
}
|
||||
void Record(VulkanDrawContext* drawContext) override;
|
||||
|
||||
void Record(VulkanDrawContext* drawContext) override
|
||||
{
|
||||
uint32_t frameOffset = m_frameOffset * drawContext->currentImageId;
|
||||
drawContext->commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, drawContext->GetShader()->pipelineLayout, m_setOffset, m_setCount, &m_descriptorSet, (m_frameOffset) ? 1 : 0, &frameOffset);
|
||||
}
|
||||
|
||||
void Update(void* data, uint32_t size, uint32_t bufferId) const
|
||||
{
|
||||
m_buffer->Copy(data, size, m_frameOffset * bufferId);
|
||||
}
|
||||
void Update(void* data, uint32_t size, uint32_t bufferId) const;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user