Viewport #94
|
@ -36,11 +36,9 @@ of DigiPen Institute of Technology is prohibited.
|
|||
|
||||
namespace SHADE
|
||||
{
|
||||
#pragma region INIT_EXIT
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructor/Destructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
void SHGraphicsSystem::Init(void)
|
||||
void SHGraphicsSystem::InitBoilerplate(void) noexcept
|
||||
{
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* BACKEND BOILERPLATE */
|
||||
|
@ -106,9 +104,10 @@ namespace SHADE
|
|||
graphicsCmdPool = device->CreateCommandPool(SH_QUEUE_FAMILY_ARRAY_INDEX::GRAPHICS, SH_CMD_POOL_RESET::POOL_BASED, true);
|
||||
transferCmdBuffer = graphicsCmdPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
|
||||
graphicsTexCmdBuffer = graphicsCmdPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SHGraphicsSystem::InitSceneRenderGraph(void) noexcept
|
||||
{
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* MIDDLE END SETUP
|
||||
- Viewports
|
||||
|
@ -118,6 +117,7 @@ namespace SHADE
|
|||
- Default vertex input state
|
||||
- Global data
|
||||
/*-----------------------------------------------------------------------*/
|
||||
auto windowDims = window->GetWindowSize();
|
||||
|
||||
SHGraphicsGlobalData::Init(device);
|
||||
|
||||
|
@ -134,61 +134,47 @@ namespace SHADE
|
|||
defaultViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast<float>(window->GetWindowSize().first), static_cast<float>(window->GetWindowSize().second), 0.0f, 1.0f));
|
||||
|
||||
// Get render graph from default viewport world renderer
|
||||
worldRenderGraph = resourceManager.Create<SHRenderGraph>();
|
||||
sceneRenderGraph = resourceManager.Create<SHRenderGraph>();
|
||||
|
||||
std::vector<Handle<SHVkCommandPool>> renderContextCmdPools{swapchain->GetNumImages()};
|
||||
std::vector<Handle<SHVkCommandPool>> renderContextCmdPools{ swapchain->GetNumImages() };
|
||||
for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i)
|
||||
{
|
||||
renderContextCmdPools[i] = renderContext.GetFrameData(i).cmdPoolHdls[0];
|
||||
}
|
||||
|
||||
// Initialize world render graph
|
||||
worldRenderGraph->Init(device, swapchain);
|
||||
worldRenderGraph->AddResource("Present", {SH_ATT_DESC_TYPE_FLAGS::COLOR_PRESENT}, windowDims.first, windowDims.second);
|
||||
worldRenderGraph->AddResource("Scene", {SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT}, windowDims.first, windowDims.second);
|
||||
worldRenderGraph->AddResource("Depth Buffer", {SH_ATT_DESC_TYPE_FLAGS::DEPTH_STENCIL}, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint);
|
||||
worldRenderGraph->AddResource("Entity ID", {SH_ATT_DESC_TYPE_FLAGS::COLOR}, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc);
|
||||
sceneRenderGraph->Init(device, swapchain);
|
||||
sceneRenderGraph->AddResource("Present", { SH_ATT_DESC_TYPE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second);
|
||||
sceneRenderGraph->AddResource("Scene", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT }, windowDims.first, windowDims.second);
|
||||
sceneRenderGraph->AddResource("Depth Buffer", { SH_ATT_DESC_TYPE_FLAGS::DEPTH_STENCIL }, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint);
|
||||
sceneRenderGraph->AddResource("Entity ID", { SH_ATT_DESC_TYPE_FLAGS::COLOR }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc);
|
||||
|
||||
//worldRenderGraph->AddResource("Position", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat);
|
||||
//worldRenderGraph->AddResource("Normals", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat);
|
||||
//worldRenderGraph->AddResource("Composite", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat);
|
||||
//worldRenderGraph->AddResource("Scene", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eB8G8R8A8Unorm);
|
||||
auto node = worldRenderGraph->AddNode("G-Buffer", { "Entity ID", "Depth Buffer", "Scene"}, {}); // no predecessors
|
||||
auto node = sceneRenderGraph->AddNode("G-Buffer", { "Entity ID", "Depth Buffer", "Scene" }, {}); // no predecessors
|
||||
|
||||
//First subpass to write to G-Buffer
|
||||
auto gBufferWriteSubpass = node->AddSubpass("G-Buffer Write");
|
||||
gBufferWriteSubpass->AddColorOutput("Scene");
|
||||
gBufferWriteSubpass->AddColorOutput("Entity ID");
|
||||
gBufferWriteSubpass->AddDepthOutput ("Depth Buffer", SH_ATT_DESC_TYPE_FLAGS::DEPTH_STENCIL);
|
||||
gBufferWriteSubpass->AddDepthOutput("Depth Buffer", SH_ATT_DESC_TYPE_FLAGS::DEPTH_STENCIL);
|
||||
|
||||
// We do this to just transition our scene layout to shader read
|
||||
auto sceneLayoutTransitionSubpass = node->AddSubpass("Scene Layout Transition");
|
||||
sceneLayoutTransitionSubpass->AddInput("Scene");
|
||||
|
||||
#ifdef SHEDITOR
|
||||
auto imguiNode = worldRenderGraph->AddNode("ImGui Node", { "Present" }, {"G-Buffer"});
|
||||
auto imguiNode = sceneRenderGraph->AddNode("ImGui Node", { "Present" }, { "G-Buffer" });
|
||||
auto imguiSubpass = imguiNode->AddSubpass("ImGui Draw");
|
||||
imguiSubpass->AddColorOutput("Present");
|
||||
#endif
|
||||
|
||||
worldRenderGraph->Generate();
|
||||
|
||||
// Create Semaphore
|
||||
for (auto& semaHandle : graphSemaphores)
|
||||
{
|
||||
semaHandle = device->CreateSemaphore();
|
||||
}
|
||||
|
||||
// Create Debug Renderers
|
||||
/*debugScreenRenderer = defaultViewport->AddRenderer(resourceManager, worldRenderGraph);
|
||||
debugScreenRenderer->SetCamera(screenCamera);
|
||||
debugWorldRenderer = defaultViewport->AddRenderer(resourceManager, worldRenderGraph);
|
||||
debugWorldRenderer->SetCamera(worldCamera);*/
|
||||
// Generate world render graph
|
||||
sceneRenderGraph->Generate();
|
||||
|
||||
// Add world renderer to default viewport
|
||||
worldRenderer = defaultViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], worldRenderGraph);
|
||||
worldRenderer = defaultViewport->AddRenderer(resourceManager, swapchain->GetNumImages(), renderContextCmdPools, descPool, SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS], sceneRenderGraph);
|
||||
worldRenderer->SetCamera(worldCamera);
|
||||
|
||||
|
||||
// TODO: This is VERY temporarily here until a more solid resource management system is implemented
|
||||
shaderSourceLibrary.Init("../../TempShaderFolder/");
|
||||
|
||||
|
@ -202,6 +188,21 @@ namespace SHADE
|
|||
cubeFS->Reflect();
|
||||
|
||||
defaultMaterial = AddMaterial(cubeVS, cubeFS, gBufferWriteSubpass);
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::InitMiddleEnd(void) noexcept
|
||||
{
|
||||
InitSceneRenderGraph();
|
||||
|
||||
// Create Semaphore
|
||||
for (auto& semaHandle : graphSemaphores)
|
||||
{
|
||||
semaHandle = device->CreateSemaphore();
|
||||
}
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::InitSubsystems(void) noexcept
|
||||
{
|
||||
|
||||
mousePickSystem = resourceManager.Create<SHMousePickSystem>();
|
||||
|
||||
|
@ -210,13 +211,36 @@ namespace SHADE
|
|||
for (uint32_t i = 0; i < swapchain->GetNumImages(); ++i)
|
||||
cmdPools.push_back(renderContext.GetFrameData(i).cmdPoolHdls[0]);
|
||||
|
||||
mousePickSystem->Init(device, cmdPools, worldRenderGraph->GetRenderGraphResource("Entity ID"));
|
||||
mousePickSystem->Init(device, cmdPools, sceneRenderGraph->GetRenderGraphResource("Entity ID"));
|
||||
|
||||
// Register the post offscreen render to the system
|
||||
postOffscreenRender = resourceManager.Create<SHPostOffscreenRenderSystem>();
|
||||
postOffscreenRender->Init(device, worldRenderGraph->GetRenderGraphResource("Scene"), descPool);
|
||||
postOffscreenRender->Init(device, sceneRenderGraph->GetRenderGraphResource("Scene"), descPool);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructor/Destructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
void SHGraphicsSystem::Init(void)
|
||||
{
|
||||
InitBoilerplate();
|
||||
InitMiddleEnd();
|
||||
InitSubsystems();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::Exit(void)
|
||||
{
|
||||
}
|
||||
|
||||
#pragma endregion INIT_EXIT
|
||||
|
||||
#pragma region LIFECYCLE
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Lifecycle Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
|
||||
|
@ -337,13 +361,6 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::Exit(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Lifecycle Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
|
||||
|
@ -435,6 +452,10 @@ namespace SHADE
|
|||
renderContext.AdvanceFrame();
|
||||
}
|
||||
|
||||
#pragma endregion LIFECYCLE
|
||||
|
||||
#pragma region ADD_REMOVE_BUILD
|
||||
|
||||
Handle<SHViewport> SHGraphicsSystem::AddViewport(const vk::Viewport& viewport)
|
||||
{
|
||||
// Create the viewport
|
||||
|
@ -545,47 +566,9 @@ namespace SHADE
|
|||
);
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::PrepareResize(uint32_t newWidth, uint32_t newHeight) noexcept
|
||||
{
|
||||
resizeWidth = newWidth;
|
||||
resizeHeight = newHeight;
|
||||
|
||||
renderContext.SetIsResized(true);
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::HandleResize(void) noexcept
|
||||
{
|
||||
if (window->IsMinimized() || renderContext.GetWindowIsDead())
|
||||
return;
|
||||
|
||||
auto windowDims = window->GetWindowSize();
|
||||
|
||||
// Resize the swapchain
|
||||
swapchain->Resize(surface, windowDims.first, windowDims.second);
|
||||
|
||||
renderContext.HandleResize();
|
||||
|
||||
worldRenderGraph->HandleResize(resizeWidth, resizeHeight);
|
||||
|
||||
mousePickSystem->HandleResize();
|
||||
postOffscreenRender->HandleResize();
|
||||
|
||||
defaultViewport->SetWidth(static_cast<float>(resizeWidth));
|
||||
defaultViewport->SetHeight(static_cast<float>(resizeHeight));
|
||||
|
||||
worldCamera->SetPerspective(90.0f, static_cast<float>(resizeWidth), static_cast<float>(resizeHeight), 0.0f, 100.0f);
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::AwaitGraphicsExecution()
|
||||
{
|
||||
device->WaitIdle();
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::SetWindow(SHWindow* wind) noexcept
|
||||
{
|
||||
window = wind;
|
||||
}
|
||||
#pragma endregion ADD_REMOVE
|
||||
|
||||
#pragma region ROUTINES
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* System Routine Functions - BeginRoutine */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
@ -657,5 +640,51 @@ namespace SHADE
|
|||
renderable.ResetChangedFlag();
|
||||
}
|
||||
}
|
||||
#pragma endregion ROUTINES
|
||||
|
||||
#pragma region MISC
|
||||
|
||||
void SHGraphicsSystem::PrepareResize(uint32_t newWidth, uint32_t newHeight) noexcept
|
||||
{
|
||||
resizeWidth = newWidth;
|
||||
resizeHeight = newHeight;
|
||||
|
||||
renderContext.SetIsResized(true);
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::HandleResize(void) noexcept
|
||||
{
|
||||
if (window->IsMinimized() || renderContext.GetWindowIsDead())
|
||||
return;
|
||||
|
||||
auto windowDims = window->GetWindowSize();
|
||||
|
||||
// Resize the swapchain
|
||||
swapchain->Resize(surface, windowDims.first, windowDims.second);
|
||||
|
||||
renderContext.HandleResize();
|
||||
|
||||
sceneRenderGraph->HandleResize(resizeWidth, resizeHeight);
|
||||
|
||||
mousePickSystem->HandleResize();
|
||||
postOffscreenRender->HandleResize();
|
||||
|
||||
defaultViewport->SetWidth(static_cast<float>(resizeWidth));
|
||||
defaultViewport->SetHeight(static_cast<float>(resizeHeight));
|
||||
|
||||
worldCamera->SetPerspective(90.0f, static_cast<float>(resizeWidth), static_cast<float>(resizeHeight), 0.0f, 100.0f);
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::AwaitGraphicsExecution()
|
||||
{
|
||||
device->WaitIdle();
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::SetWindow(SHWindow* wind) noexcept
|
||||
{
|
||||
window = wind;
|
||||
}
|
||||
|
||||
|
||||
#pragma endregion MISC
|
||||
}
|
||||
|
|
|
@ -67,6 +67,12 @@ namespace SHADE
|
|||
/***********************************************************************************/
|
||||
class SH_API SHGraphicsSystem : public SHSystem
|
||||
{
|
||||
private:
|
||||
void InitBoilerplate (void) noexcept;
|
||||
void InitSceneRenderGraph(void) noexcept;
|
||||
void InitMiddleEnd (void) noexcept;
|
||||
void InitSubsystems (void) noexcept;
|
||||
|
||||
public:
|
||||
class SH_API BeginRoutine final : public SHSystemRoutine
|
||||
{
|
||||
|
@ -279,6 +285,7 @@ namespace SHADE
|
|||
|
||||
|
||||
private:
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
@ -305,6 +312,12 @@ namespace SHADE
|
|||
SHSamplerCache samplerCache;
|
||||
SHMaterialInstanceCache materialInstanceCache;
|
||||
// Viewports
|
||||
#ifdef SHEDITOR
|
||||
Handle<SHViewport> editorViewport;
|
||||
Handle<SHRenderer> editorRenderer;
|
||||
Handle<SHRenderGraph> editorRenderGraph;
|
||||
#endif
|
||||
|
||||
Handle<SHViewport> defaultViewport; // Whole screen
|
||||
std::vector<Handle<SHViewport>> viewports; // Additional viewports
|
||||
|
||||
|
@ -326,7 +339,7 @@ namespace SHADE
|
|||
// Temp Materials
|
||||
Handle<SHMaterial> defaultMaterial;
|
||||
|
||||
Handle<SHRenderGraph> worldRenderGraph;
|
||||
Handle<SHRenderGraph> sceneRenderGraph;
|
||||
|
||||
// Sub systems
|
||||
Handle<SHMousePickSystem> mousePickSystem;
|
||||
|
|
Loading…
Reference in New Issue