Changed batching system to use SHRenderable* instead of handles

This commit is contained in:
Kah Wei 2022-09-18 17:02:02 +08:00
parent ec40754eb9
commit 96ec1afcdd
5 changed files with 15 additions and 13 deletions

View File

@ -35,7 +35,7 @@ namespace SHADE
throw std::invalid_argument("Attempted to create a SHBatch with an invalid SHPipeline!");
}
void SHBatch::Add(Handle<SHRenderable> renderable)
void SHBatch::Add(const SHRenderable* renderable)
{
// Check if we have a SubBatch with the same mesh yet
auto subBatch = std::find_if(subBatches.begin(), subBatches.end(), [&](const SHSubBatch& batch)
@ -54,7 +54,7 @@ namespace SHADE
subBatch->Renderables.insert(renderable);
}
void SHBatch::Remove(Handle<SHRenderable> renderable)
void SHBatch::Remove(const SHRenderable* renderable)
{
// Check if we have a SubBatch with the same mesh yet
auto subBatch = std::find_if(subBatches.begin(), subBatches.end(), [&](const SHSubBatch& batch)
@ -136,7 +136,7 @@ namespace SHADE
});
// Fill in buffers (CPU)
for (Handle<SHRenderable> renderable : subBatch.Renderables)
for (const SHRenderable* renderable : subBatch.Renderables)
{
// Transform
transformData.emplace_back(renderable->TransformMatrix);

View File

@ -49,7 +49,7 @@ namespace SHADE
/* Data Members */
/*-----------------------------------------------------------------------------*/
Handle<SHMesh> Mesh;
std::unordered_set<Handle<SHRenderable>> Renderables;
std::unordered_set<const SHRenderable*> Renderables;
};
/***********************************************************************************/
/*!
@ -68,8 +68,8 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/
/* Usage Functions */
/*-----------------------------------------------------------------------------*/
void Add(Handle<SHRenderable> renderable);
void Remove(Handle<SHRenderable> renderable);
void Add(const SHRenderable* renderable);
void Remove(const SHRenderable* renderable);
void Clear();
void Build(Handle<SHVkLogicalDevice> device, Handle<SHVkCommandBuffer> cmdBuffer);
void Draw(Handle<SHVkCommandBuffer> cmdBuffer);

View File

@ -21,6 +21,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Graphics/Commands/SHVkCommandBuffer.h"
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
#include "Graphics/Pipeline/SHVkPipeline.h"
#include "ECS_Base/Managers/SHComponentManager.h"
namespace SHADE
{
@ -39,7 +40,8 @@ namespace SHADE
void SHBatcher::PrepareBatches()
{
// Iterate through all renderables and send it into the batching
for (auto iter = renderables->cbegin(); iter != renderables->cend(); ++iter)
auto& renderables = SHComponentManager::GetDense<SHRenderable>();
for (auto iter = renderables.cbegin(); iter != renderables.cend(); ++iter)
{
AddToBatch(iter->GetHandle());
}

View File

@ -30,7 +30,7 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
/* Usage Functions */
/*---------------------------------------------------------------------------------*/
void SHSuperBatch::Add(Handle<SHRenderable> renderable) noexcept
void SHSuperBatch::Add(const SHRenderable* renderable) noexcept
{
const Handle<SHVkPipeline> PIPELINE = renderable->GetMaterial()->GetBaseMaterial()->GetPipeline();
@ -52,7 +52,7 @@ namespace SHADE
batch->Add(renderable);
}
void SHSuperBatch::Remove(Handle<SHRenderable> renderable) noexcept
void SHSuperBatch::Remove(const SHRenderable* renderable) noexcept
{
const Handle<SHVkPipeline> PIPELINE = renderable->GetMaterial()->GetBaseMaterial()->GetPipeline();

View File

@ -52,8 +52,8 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/
/* Usage Functions */
/*-----------------------------------------------------------------------------*/
void Add(Handle<SHRenderable> renderable) noexcept;
void Remove(Handle<SHRenderable> renderable) noexcept;
void Add(const SHRenderable* renderable) noexcept;
void Remove(const SHRenderable* renderable) noexcept;
void Clear() noexcept;
void Build(Handle<SHVkLogicalDevice> device, Handle<SHVkCommandBuffer> cmdBuffer) noexcept;
void Draw(Handle<SHVkCommandBuffer> cmdBuffer) noexcept;