Files
XCEngine/engine/src/RHI/OpenGL/OpenGLDescriptorPool.cpp

60 lines
1.4 KiB
C++

#include "XCEngine/RHI/OpenGL/OpenGLDescriptorPool.h"
#include "XCEngine/RHI/OpenGL/OpenGLDescriptorSet.h"
#include "XCEngine/RHI/OpenGL/OpenGLTextureUnitAllocator.h"
namespace XCEngine {
namespace RHI {
OpenGLDescriptorPool::OpenGLDescriptorPool()
: m_type(DescriptorHeapType::CBV_SRV_UAV)
, m_maxSets(0)
, m_textureUnitAllocator(nullptr) {
}
OpenGLDescriptorPool::~OpenGLDescriptorPool() {
Shutdown();
}
bool OpenGLDescriptorPool::Initialize(const DescriptorPoolDesc& desc) {
m_type = desc.type;
m_maxSets = desc.descriptorCount;
return true;
}
void OpenGLDescriptorPool::Shutdown() {
m_allocatedSets.clear();
m_textureUnitAllocator = nullptr;
}
RHIDescriptorSet* OpenGLDescriptorPool::AllocateSet(const DescriptorSetLayoutDesc& layout) {
if (m_allocatedSets.size() >= m_maxSets) {
return nullptr;
}
OpenGLDescriptorSet* newSet = new OpenGLDescriptorSet();
if (!newSet->Initialize(m_textureUnitAllocator, layout.bindingCount, layout)) {
delete newSet;
return nullptr;
}
m_allocatedSets.push_back(newSet);
return newSet;
}
void OpenGLDescriptorPool::FreeSet(RHIDescriptorSet* set) {
if (set == nullptr) {
return;
}
for (auto it = m_allocatedSets.begin(); it != m_allocatedSets.end(); ++it) {
if (*it == set) {
m_allocatedSets.erase(it);
delete set;
return;
}
}
}
} // namespace RHI
} // namespace XCEngine