Integrated into SBApplication and accounted for case where number of points to draw is 0.
This commit is contained in:
parent
550b8d85f0
commit
57027da80b
|
@ -31,6 +31,7 @@
|
|||
#include "FRC/SHFramerateController.h"
|
||||
#include "AudioSystem/SHAudioSystem.h"
|
||||
#include "Camera/SHCameraSystem.h"
|
||||
#include "Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h"
|
||||
|
||||
// Components
|
||||
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
||||
|
@ -69,6 +70,7 @@ namespace Sandbox
|
|||
SHGraphicsSystem* graphicsSystem = static_cast<SHGraphicsSystem*>(SHSystemManager::GetSystem<SHGraphicsSystem>());
|
||||
SHSystemManager::CreateSystem<SHAudioSystem>();
|
||||
SHSystemManager::CreateSystem<SHCameraSystem>();
|
||||
SHSystemManager::CreateSystem<SHDebugDrawSystem>();
|
||||
|
||||
#ifdef SHEDITOR
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
@ -90,6 +92,7 @@ namespace Sandbox
|
|||
SHSystemManager::RegisterRoutine<SHPhysicsSystem, SHPhysicsSystem::PhysicsPostUpdate>();
|
||||
|
||||
SHSystemManager::RegisterRoutine<SHTransformSystem, SHTransformSystem::TransformPostPhysicsUpdate>();
|
||||
SHSystemManager::RegisterRoutine<SHDebugDrawSystem, SHDebugDrawSystem::ProcessPointsRoutine>();
|
||||
|
||||
SHSystemManager::RegisterRoutine<SHGraphicsSystem, SHGraphicsSystem::BatcherDispatcherRoutine>();
|
||||
SHSystemManager::RegisterRoutine<SHGraphicsSystem, SHGraphicsSystem::BeginRoutine>();
|
||||
|
|
|
@ -25,11 +25,11 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
/* DrawRoutine */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
SHDebugDrawSystem::DrawRoutine::DrawRoutine()
|
||||
SHDebugDrawSystem::ProcessPointsRoutine::ProcessPointsRoutine()
|
||||
: SHSystemRoutine("Debug Draw")
|
||||
{}
|
||||
|
||||
void SHDebugDrawSystem::DrawRoutine::Execute(double dt) noexcept
|
||||
void SHDebugDrawSystem::ProcessPointsRoutine::Execute(double dt) noexcept
|
||||
{
|
||||
auto gfxSys = SHSystemManager::GetSystem<SHGraphicsSystem>();
|
||||
if (gfxSys)
|
||||
|
@ -40,8 +40,12 @@ namespace SHADE
|
|||
|
||||
// Create the buffer if it doesn't exist or just update it
|
||||
SHDebugDrawSystem* system = static_cast<SHDebugDrawSystem*>(GetSystem());
|
||||
system->numPoints = system->points.size();
|
||||
const uint32_t DATA_SIZE = sizeof(PointVertex) * system->points.size();
|
||||
SHVkUtil::EnsureBufferAndCopyHostVisibleData(gfxSys->GetDevice(), system->vertexBuffer, system->points.data(), DATA_SIZE, vk::BufferUsageFlagBits::eVertexBuffer);
|
||||
if (DATA_SIZE > 0)
|
||||
{
|
||||
SHVkUtil::EnsureBufferAndCopyHostVisibleData(gfxSys->GetDevice(), system->vertexBuffer, system->points.data(), DATA_SIZE, vk::BufferUsageFlagBits::eVertexBuffer);
|
||||
}
|
||||
|
||||
// Reset for next frame
|
||||
system->points.clear();
|
||||
|
@ -59,6 +63,10 @@ namespace SHADE
|
|||
auto subPass = renderGraph->GetNode("Debug Draw")->GetSubpass("Debug Draw");
|
||||
subPass->AddExteriorDrawCalls([&](Handle<SHVkCommandBuffer>& cmdBuffer)
|
||||
{
|
||||
// Don't draw if no points
|
||||
if (numPoints <= 0)
|
||||
return;
|
||||
|
||||
cmdBuffer->BindPipeline(GFX_SYSTEM->GetDebugDrawPipeline());
|
||||
cmdBuffer->BindVertexBuffer(0, vertexBuffer, 0);
|
||||
cmdBuffer->DrawArrays(static_cast<uint32_t>(points.size()), 1, 0, 0);
|
||||
|
@ -67,7 +75,10 @@ namespace SHADE
|
|||
|
||||
void SHDebugDrawSystem::Exit()
|
||||
{
|
||||
|
||||
if (vertexBuffer)
|
||||
{
|
||||
vertexBuffer.Free();
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -21,14 +21,10 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "ECS_Base/System/SHSystem.h"
|
||||
#include "ECS_Base/System/SHSystemRoutine.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "Graphics/Buffers/SHVkBuffer.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Forward Declarations */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
class SHVkBuffer;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -44,10 +40,10 @@ namespace SHADE
|
|||
/*-------------------------------------------------------------------------------*/
|
||||
/* System Routines */
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
class SH_API DrawRoutine final : public SHSystemRoutine
|
||||
class SH_API ProcessPointsRoutine final : public SHSystemRoutine
|
||||
{
|
||||
public:
|
||||
DrawRoutine();
|
||||
ProcessPointsRoutine();
|
||||
virtual void Execute(double dt) noexcept override final;
|
||||
};
|
||||
|
||||
|
@ -73,7 +69,7 @@ namespace SHADE
|
|||
/*-------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
struct PointVertex
|
||||
struct SH_API PointVertex
|
||||
{
|
||||
SHVec3 Position;
|
||||
SHVec4 Color;
|
||||
|
@ -85,6 +81,7 @@ namespace SHADE
|
|||
std::vector<PointVertex> points;
|
||||
// GPU Buffers
|
||||
Handle<SHVkBuffer> vertexBuffer;
|
||||
uint32_t numPoints = 0;
|
||||
// Cached Points for polygon drawing
|
||||
std::vector<SHVec3> spherePoints;
|
||||
};
|
||||
|
|
|
@ -204,12 +204,15 @@ namespace SHADE
|
|||
auto pureCopyShader = shaderModuleLibrary.GetShaderModule("PureCopyCs.glsl");
|
||||
gBufferNode->AddNodeCompute(pureCopyShader, { "Scene Pre-Process", "Scene" });
|
||||
|
||||
// Set up Debug Draw Pass
|
||||
auto debugDrawNode = worldRenderGraph->AddNode("Debug Draw", { "Scene" }, { "G-Buffer" });
|
||||
auto debugDrawSubpass = debugDrawNode->AddSubpass("Debug Draw");
|
||||
debugDrawSubpass->AddColorOutput("Scene");
|
||||
|
||||
auto dummyNode = worldRenderGraph->AddNode("Dummy Pass", { "Scene" }, {"G-Buffer"}); // no predecessors
|
||||
auto dummyNode = worldRenderGraph->AddNode("Dummy Pass", { "Scene" }, {"Debug Draw"}); // no predecessors
|
||||
auto dummySubpass = dummyNode->AddSubpass("Dummy Subpass");
|
||||
dummySubpass->AddInput("Scene");
|
||||
|
||||
|
||||
// Generate world render graph
|
||||
worldRenderGraph->Generate();
|
||||
|
||||
|
@ -224,6 +227,24 @@ namespace SHADE
|
|||
|
||||
defaultMaterial = AddMaterial(cubeVS, cubeFS, gBufferSubpass);
|
||||
|
||||
// Create debug draw pipeline
|
||||
auto debugDrawVS = shaderModuleLibrary.GetShaderModule("DebugDrawVs.glsl");
|
||||
auto debugDrawFS = shaderModuleLibrary.GetShaderModule("DebugDrawFs.glsl");
|
||||
|
||||
auto debugDrawPipelineLayout = resourceManager.Create<SHVkPipelineLayout>
|
||||
(
|
||||
device, SHPipelineLayoutParams
|
||||
{
|
||||
.shaderModules = { debugDrawVS, debugDrawFS },
|
||||
.globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts()
|
||||
}
|
||||
);
|
||||
debugDrawPipeline = resourceManager.Create<SHVkPipeline>(device, debugDrawPipelineLayout);
|
||||
debugDrawPipeline->GetPipelineState().SetRasterizationState(SHRasterizationState
|
||||
{
|
||||
.polygonMode = vk::PolygonMode::eLine,
|
||||
.cull_mode = vk::CullModeFlagBits::eNone
|
||||
});
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::InitMiddleEnd(void) noexcept
|
||||
|
|
Loading…
Reference in New Issue