Added UI functionality to the Graphics System #232
|
@ -0,0 +1,19 @@
|
|||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
#extension GL_ARB_shading_language_420pack : enable
|
||||
#extension GL_EXT_nonuniform_qualifier : require
|
||||
|
||||
layout (input_attachment_index = 0, set = 4, binding = 0) uniform subpassInput vec4 sceneTexture;
|
||||
|
||||
layout(location = 0) in struct
|
||||
{
|
||||
vec2 uv; // location = 0
|
||||
|
||||
} In;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragColor = vec4 (texture (sceneTexture, In.uv).rgb, 1.0f);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#version 450
|
||||
#extension GL_KHR_vulkan_glsl : enable
|
||||
|
||||
layout(location = 0) out struct
|
||||
{
|
||||
vec2 uv; // location = 0
|
||||
|
||||
} Out;
|
||||
|
||||
vec2 CreateQuad(in uint vertexID)
|
||||
{
|
||||
uint b = 1 << vertexID;
|
||||
return vec2 ((0x3 & b) != 0, (0x9 & b) != 0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texCoord = CreateQuad (gl_VertexIndex);
|
||||
vec2 vertexPos = texCoord - vec2(0.5f);
|
||||
gl_Position = vec4 (vertexPos, 0.0f, 1.0f);
|
||||
}
|
|
@ -161,19 +161,24 @@ namespace Sandbox
|
|||
void SBApplication::Update(void)
|
||||
{
|
||||
SHGraphicsSystem* graphicsSystem = SHADE::SHSystemManager::GetSystem<SHGraphicsSystem>();
|
||||
|
||||
#ifdef SHEDITOR
|
||||
SHEditor* editor = SHADE::SHSystemManager::GetSystem<SHEditor>();
|
||||
#endif
|
||||
|
||||
//TODO: Change true to window is open
|
||||
while (!window.WindowShouldClose())
|
||||
{
|
||||
SHFrameRateController::UpdateFRC();
|
||||
SHInputManager::UpdateInput(SHFrameRateController::GetRawDeltaTime());
|
||||
SHSceneManager::UpdateSceneManager();
|
||||
|
||||
#ifdef SHEDITOR
|
||||
if(editor->editorState == SHEditor::State::PLAY)
|
||||
SHSceneManager::SceneUpdate(0.016f);
|
||||
#endif
|
||||
SHSystemManager::RunRoutines(editor->editorState != SHEditor::State::PLAY, 0.016f);
|
||||
editor->PollPicking();
|
||||
#endif
|
||||
|
||||
static bool drawColliders = false;
|
||||
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::F10))
|
||||
|
|
|
@ -283,6 +283,7 @@ namespace SHADE
|
|||
screenRenderGraph->Init("Scene Render Graph", device, swapchain, &resourceManager);
|
||||
screenRenderGraph->LinkNonOwningResource(worldRenderGraph, "Scene");
|
||||
screenRenderGraph->LinkNonOwningResource(worldRenderGraph, "Entity ID");
|
||||
screenRenderGraph->AddResource("Present", { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT }, windowDims.first, windowDims.second);
|
||||
|
||||
auto screenSpaceNode = screenRenderGraph->AddNode("Screen Space Pass", { "Scene", "Entity ID"}, {});
|
||||
auto uiSubpass = screenSpaceNode->AddSubpass("UI");
|
||||
|
@ -300,6 +301,7 @@ namespace SHADE
|
|||
dummySubpass->AddInput("Scene");
|
||||
}
|
||||
|
||||
//screenRenderGraph->AddRenderToSwapchainNode ("Scene", "Present", )
|
||||
|
||||
screenRenderGraph->Generate();
|
||||
|
||||
|
@ -1011,7 +1013,11 @@ namespace SHADE
|
|||
renderContext.HandleResize();
|
||||
|
||||
worldRenderGraph->HandleResize(resizeWidth, resizeHeight);
|
||||
|
||||
#ifdef SHEDITOR
|
||||
editorRenderGraph->HandleResize(windowDims.first, windowDims.second);
|
||||
#endif
|
||||
|
||||
screenRenderGraph->HandleResize(resizeWidth, resizeHeight);
|
||||
|
||||
mousePickSystem->HandleResize();
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#include "SHRenderGraphStorage.h"
|
||||
#include "Graphics/RenderGraph/SHRenderGraphNodeCompute.h"
|
||||
#include "Tools/Utilities/SHUtilities.h"
|
||||
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h"
|
||||
#include "Graphics/RenderGraph/SHRenderToSwapchainImageSystem.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -385,6 +387,12 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
void SHRenderGraph::ConfigureSubSystems(void) noexcept
|
||||
{
|
||||
if (renderToSwapchainImageSystem)
|
||||
renderToSwapchainImageSystem->ConstructPipelines(renderGraphStorage->logicalDevice);
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
|
||||
|
@ -536,6 +544,33 @@ namespace SHADE
|
|||
return node;
|
||||
}
|
||||
|
||||
void SHRenderGraph::AddRenderToSwapchainNode(std::string toSwapchainResource, std::string swapchainResource, std::initializer_list<std::string> predecessorNodes, std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> shaderModules) noexcept
|
||||
{
|
||||
for (auto& node : predecessorNodes)
|
||||
{
|
||||
if (!nodeIndexing.contains(node))
|
||||
return;
|
||||
}
|
||||
|
||||
if (renderGraphStorage->graphResources->contains(toSwapchainResource) && renderGraphStorage->graphResources->contains(swapchainResource))
|
||||
{
|
||||
auto newNode = AddNode("Render To Present", { ResourceInstruction (toSwapchainResource.c_str()), ResourceInstruction(swapchainResource.c_str()) }, predecessorNodes);
|
||||
auto newSubpass = newNode->AddSubpass("Render");
|
||||
newSubpass->AddColorOutput(swapchainResource);
|
||||
newSubpass->AddInput(toSwapchainResource);
|
||||
|
||||
renderToSwapchainImageSystem = renderGraphStorage->resourceHub->Create<SHRenderToSwapchainImageSystem> (newNode, newSubpass, shaderModules);
|
||||
|
||||
newSubpass->AddExteriorDrawCalls([=](Handle<SHVkCommandBuffer>& cmdBuffer, uint32_t frameIndex)
|
||||
{
|
||||
cmdBuffer->BindPipeline(renderToSwapchainImageSystem->GetPipeline());
|
||||
|
||||
// draw a quad.
|
||||
cmdBuffer->DrawIndexed(4, 0, 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
|
||||
|
@ -556,6 +591,7 @@ namespace SHADE
|
|||
ConfigureSubpasses();
|
||||
ConfigureRenderpasses();
|
||||
ConfigureFramebuffers();
|
||||
ConfigureSubSystems();
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace SHADE
|
|||
class SHGraphicsGlobalData;
|
||||
class SHVkDescriptorPool;
|
||||
class SHRenderGraphStorage;
|
||||
class SHRenderToSwapchainImageSystem;
|
||||
|
||||
class SH_API SHRenderGraph
|
||||
{
|
||||
|
@ -52,6 +53,7 @@ namespace SHADE
|
|||
void ConfigureAttachmentDescriptions (void) noexcept;
|
||||
void ConfigureSubpasses (void) noexcept;
|
||||
void ConfigureRenderpasses (void) noexcept;
|
||||
void ConfigureSubSystems (void) noexcept;
|
||||
void ConfigureFramebuffers (void) noexcept;
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
@ -69,6 +71,9 @@ namespace SHADE
|
|||
//! Name of the RenderGraph
|
||||
std::string name;
|
||||
|
||||
//! For rendering onto the swapchain
|
||||
Handle<SHRenderToSwapchainImageSystem> renderToSwapchainImageSystem;
|
||||
|
||||
public:
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* CTORS AND DTORS */
|
||||
|
@ -85,6 +90,7 @@ namespace SHADE
|
|||
void AddResource(std::string resourceName, std::initializer_list<SH_RENDER_GRAPH_RESOURCE_FLAGS> typeFlags, uint32_t w = static_cast<uint32_t>(-1), uint32_t h = static_cast<uint32_t>(-1), vk::Format format = vk::Format::eB8G8R8A8Unorm, uint8_t levels = 1, vk::ImageUsageFlagBits usageFlags = {}, vk::ImageCreateFlagBits createFlags = {});
|
||||
void LinkNonOwningResource (Handle<SHRenderGraph> resourceOrigin, std::string resourceName) noexcept;
|
||||
Handle<SHRenderGraphNode> AddNode (std::string nodeName, std::initializer_list<ResourceInstruction> resourceInstruction, std::initializer_list<std::string> predecessorNodes) noexcept;
|
||||
void AddRenderToSwapchainNode (std::string toSwapchainResource, std::string swapchainResource, std::initializer_list<std::string> predecessorNodes, std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> shaderModules) noexcept;
|
||||
|
||||
void Generate (void) noexcept;
|
||||
void CheckForNodeComputes (void) noexcept;
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHRenderToSwapchainImageSystem.h"
|
||||
#include "Graphics/Devices/SHVkLogicalDevice.h"
|
||||
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h"
|
||||
#include "Graphics/RenderGraph/SHRenderGraphNode.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
||||
SHRenderToSwapchainImageSystem::SHRenderToSwapchainImageSystem(Handle<SHRenderGraphNode> node, Handle<SHSubpass> subpass, std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> shaders) noexcept
|
||||
: renderGraphNode {node}
|
||||
, subpass{subpass}
|
||||
, shaderModules{shaders}
|
||||
, pipeline{}
|
||||
, pipelineLayout{}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SHRenderToSwapchainImageSystem::ConstructPipelines(Handle<SHVkLogicalDevice> logicalDevice) noexcept
|
||||
{
|
||||
auto pipelineLayout = logicalDevice->CreatePipelineLayout(SHPipelineLayoutParams
|
||||
{
|
||||
.shaderModules = {shaderModules.first, shaderModules.second},
|
||||
.globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts(),
|
||||
});
|
||||
|
||||
auto newPipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderGraphNode->GetRenderpass(), subpass);
|
||||
|
||||
SHInputAssemblyState inputAssembly{};
|
||||
inputAssembly.topology = vk::PrimitiveTopology::eTriangleFan;
|
||||
|
||||
newPipeline->GetPipelineState().SetInputAssemblyState(inputAssembly);
|
||||
|
||||
newPipeline->ConstructPipeline();
|
||||
|
||||
}
|
||||
|
||||
Handle<SHVkPipeline> SHRenderToSwapchainImageSystem::GetPipeline(void) const noexcept
|
||||
{
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include "Resource/SHHandle.h"
|
||||
#include <utility>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
class SHVkPipeline;
|
||||
class SHVkPipelineLayout;
|
||||
class SHVkShaderModule;
|
||||
class SHRenderGraphNode;
|
||||
class SHSubpass;
|
||||
class SHVkLogicalDevice;
|
||||
class SHSubpass;
|
||||
|
||||
|
||||
class SHRenderToSwapchainImageSystem
|
||||
{
|
||||
private:
|
||||
//! Render Graph node to get the renderpass from to initialize the pipeline
|
||||
Handle<SHRenderGraphNode> renderGraphNode;
|
||||
|
||||
//! Subpass to initialize the pipeline with
|
||||
Handle<SHSubpass> subpass;
|
||||
|
||||
//! Shader module required to render the quad on screen
|
||||
std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> shaderModules;
|
||||
|
||||
//! pipeline required to draw the image
|
||||
Handle<SHVkPipeline> pipeline;
|
||||
|
||||
//! Pipeline layout of the pipeline
|
||||
Handle<SHVkPipelineLayout> pipelineLayout;
|
||||
|
||||
public:
|
||||
SHRenderToSwapchainImageSystem (Handle<SHRenderGraphNode> node, Handle<SHSubpass> subpass, std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> shaders) noexcept;
|
||||
|
||||
void ConstructPipelines (Handle<SHVkLogicalDevice> logicalDevice) noexcept;
|
||||
|
||||
Handle<SHVkPipeline> GetPipeline (void) const noexcept;
|
||||
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue