Added UI functionality to the Graphics System #232
|
@ -13,6 +13,7 @@
|
||||||
#include "Physics/Interface/SHRigidBodyComponent.h"
|
#include "Physics/Interface/SHRigidBodyComponent.h"
|
||||||
#include "Physics/Interface/SHColliderComponent.h"
|
#include "Physics/Interface/SHColliderComponent.h"
|
||||||
#include "Graphics/MiddleEnd/Lights/SHLightComponent.h"
|
#include "Graphics/MiddleEnd/Lights/SHLightComponent.h"
|
||||||
|
#include "Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h"
|
||||||
|
|
||||||
#include "Assets/SHAssetManager.h"
|
#include "Assets/SHAssetManager.h"
|
||||||
#include "Camera/SHCameraComponent.h"
|
#include "Camera/SHCameraComponent.h"
|
||||||
|
@ -41,6 +42,19 @@ namespace Sandbox
|
||||||
void SBMainScene::Init()
|
void SBMainScene::Init()
|
||||||
{
|
{
|
||||||
sceneName = SHSerialization::DeserializeSceneFromFile(sceneAssetID);
|
sceneName = SHSerialization::DeserializeSceneFromFile(sceneAssetID);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* TESTING CODE */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
//testText = SHEntityManager::CreateEntity<SHTransformComponent, SHTextRendererComponent>(MAX_EID, "Test Text");
|
||||||
|
//auto gfxSystem =SHSystemManager::GetSystem<SHGraphicsSystem>();
|
||||||
|
|
||||||
|
//auto textComp = SHComponentManager::GetComponent<SHTextRendererComponent>(testText);
|
||||||
|
|
||||||
|
//textComp->SetFont(gfxSystem->GetFontLibrary().GetFonts()[0]);
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* TESTING CODE */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void SBMainScene::Update(float dt)
|
void SBMainScene::Update(float dt)
|
||||||
|
|
|
@ -12,6 +12,8 @@ namespace Sandbox
|
||||||
EntityID testObj;
|
EntityID testObj;
|
||||||
std::vector<EntityID> stressTestObjects;
|
std::vector<EntityID> stressTestObjects;
|
||||||
|
|
||||||
|
EntityID testText;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void Load();
|
virtual void Load();
|
||||||
virtual void Init();
|
virtual void Init();
|
||||||
|
|
|
@ -516,7 +516,7 @@ namespace SHADE
|
||||||
|
|
||||||
ImGui_ImplVulkan_DestroyFontUploadObjects();
|
ImGui_ImplVulkan_DestroyFontUploadObjects();
|
||||||
|
|
||||||
renderGraph->GetNode("ImGui Node")->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle<SHVkCommandBuffer>& cmd)
|
renderGraph->GetNode("ImGui Node")->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle<SHVkCommandBuffer>& cmd, uint32_t frameIndex)
|
||||||
{
|
{
|
||||||
cmd->BeginLabeledSegment("ImGui Draw");
|
cmd->BeginLabeledSegment("ImGui Draw");
|
||||||
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->GetVkCommandBuffer());
|
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->GetVkCommandBuffer());
|
||||||
|
|
|
@ -90,7 +90,7 @@ namespace SHADE
|
||||||
auto const& RENDERERS = GFX_SYSTEM->GetDefaultViewport()->GetRenderers();
|
auto const& RENDERERS = GFX_SYSTEM->GetDefaultViewport()->GetRenderers();
|
||||||
auto renderGraph = RENDERERS[SHGraphicsConstants::RenderGraphIndices::WORLD]->GetRenderGraph();
|
auto renderGraph = RENDERERS[SHGraphicsConstants::RenderGraphIndices::WORLD]->GetRenderGraph();
|
||||||
auto subPass = renderGraph->GetNode("Debug Draw")->GetSubpass("Debug Draw");
|
auto subPass = renderGraph->GetNode("Debug Draw")->GetSubpass("Debug Draw");
|
||||||
subPass->AddExteriorDrawCalls([this, GFX_SYSTEM](Handle<SHVkCommandBuffer>& cmdBuffer)
|
subPass->AddExteriorDrawCalls([this, GFX_SYSTEM](Handle<SHVkCommandBuffer>& cmdBuffer, uint32_t frameIndex)
|
||||||
{
|
{
|
||||||
// Get Current frame index
|
// Get Current frame index
|
||||||
const uint32_t FRAME_IDX = GFX_SYSTEM->GetCurrentFrameIndex();
|
const uint32_t FRAME_IDX = GFX_SYSTEM->GetCurrentFrameIndex();
|
||||||
|
@ -106,7 +106,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
auto subPassWithDepth = renderGraph->GetNode("Debug Draw with Depth")->GetSubpass("Debug Draw with Depth");
|
auto subPassWithDepth = renderGraph->GetNode("Debug Draw with Depth")->GetSubpass("Debug Draw with Depth");
|
||||||
subPassWithDepth->AddExteriorDrawCalls([this, GFX_SYSTEM](Handle<SHVkCommandBuffer>& cmdBuffer)
|
subPassWithDepth->AddExteriorDrawCalls([this, GFX_SYSTEM](Handle<SHVkCommandBuffer>& cmdBuffer, uint32_t frameIndex)
|
||||||
{
|
{
|
||||||
// Get Current frame index
|
// Get Current frame index
|
||||||
const uint32_t FRAME_IDX = GFX_SYSTEM->GetCurrentFrameIndex();
|
const uint32_t FRAME_IDX = GFX_SYSTEM->GetCurrentFrameIndex();
|
||||||
|
|
|
@ -288,6 +288,10 @@ namespace SHADE
|
||||||
auto uiSubpass = screenSpaceNode->AddSubpass("UI");
|
auto uiSubpass = screenSpaceNode->AddSubpass("UI");
|
||||||
uiSubpass->AddColorOutput("Scene");
|
uiSubpass->AddColorOutput("Scene");
|
||||||
uiSubpass->AddColorOutput("Entity ID");
|
uiSubpass->AddColorOutput("Entity ID");
|
||||||
|
uiSubpass->AddExteriorDrawCalls([=](Handle<SHVkCommandBuffer>& cmdBuffer, uint32_t frameIndex)
|
||||||
|
{
|
||||||
|
textRenderingSubSystem->Render(cmdBuffer, frameIndex);
|
||||||
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
// Dummy Node to transition scene render graph resource
|
// Dummy Node to transition scene render graph resource
|
||||||
|
@ -363,7 +367,10 @@ namespace SHADE
|
||||||
|
|
||||||
// initialize the text renderer
|
// initialize the text renderer
|
||||||
auto uiNode = screenRenderGraph->GetNode("Screen Space Pass");
|
auto uiNode = screenRenderGraph->GetNode("Screen Space Pass");
|
||||||
textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS);
|
textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS, [=](Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex)
|
||||||
|
{
|
||||||
|
screenRenderer->BindDescSet(cmdBuffer, frameIndex);
|
||||||
|
});
|
||||||
|
|
||||||
SHFreetypeInstance::Init();
|
SHFreetypeInstance::Init();
|
||||||
}
|
}
|
||||||
|
@ -506,6 +513,8 @@ namespace SHADE
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textRenderingSubSystem->Run(frameIndex);
|
||||||
|
|
||||||
// For every viewport
|
// For every viewport
|
||||||
for (int vpIndex = 0; vpIndex < static_cast<int>(viewports.size()); ++vpIndex)
|
for (int vpIndex = 0; vpIndex < static_cast<int>(viewports.size()); ++vpIndex)
|
||||||
{
|
{
|
||||||
|
@ -810,7 +819,7 @@ namespace SHADE
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
Handle<SHTexture> SHGraphicsSystem::AddTexture(const SHTextureAsset& texAsset)
|
Handle<SHTexture> SHGraphicsSystem::AddTexture(const SHTextureAsset& texAsset)
|
||||||
{
|
{
|
||||||
const int MIPS = texAsset.mipOffsets.size();
|
const int MIPS = static_cast<int> (texAsset.mipOffsets.size());
|
||||||
auto sampler = samplerCache.GetSampler(device, SHVkSamplerParams { .maxLod = static_cast<float>(MIPS) });
|
auto sampler = samplerCache.GetSampler(device, SHVkSamplerParams { .maxLod = static_cast<float>(MIPS) });
|
||||||
SET_VK_OBJ_NAME(device, vk::ObjectType::eSampler, sampler->GetVkSampler(), "[Sampler] Mips " + std::to_string(MIPS));
|
SET_VK_OBJ_NAME(device, vk::ObjectType::eSampler, sampler->GetVkSampler(), "[Sampler] Mips " + std::to_string(MIPS));
|
||||||
return texLibrary.Add(texAsset, sampler);
|
return texLibrary.Add(texAsset, sampler);
|
||||||
|
@ -818,7 +827,7 @@ namespace SHADE
|
||||||
|
|
||||||
SHADE::Handle<SHADE::SHTexture> SHGraphicsSystem::AddTexture(uint32_t pixelCount, const SHTexture::PixelChannel* const pixelData, uint32_t width, uint32_t height, SHTexture::TextureFormat format, std::vector<uint32_t> mipOffsets)
|
SHADE::Handle<SHADE::SHTexture> SHGraphicsSystem::AddTexture(uint32_t pixelCount, const SHTexture::PixelChannel* const pixelData, uint32_t width, uint32_t height, SHTexture::TextureFormat format, std::vector<uint32_t> mipOffsets)
|
||||||
{
|
{
|
||||||
const int MIPS = mipOffsets.size();
|
const int MIPS = static_cast<int> (mipOffsets.size());
|
||||||
auto sampler = samplerCache.GetSampler(device, SHVkSamplerParams{ .maxLod = static_cast<float>(MIPS) });
|
auto sampler = samplerCache.GetSampler(device, SHVkSamplerParams{ .maxLod = static_cast<float>(MIPS) });
|
||||||
SET_VK_OBJ_NAME(device, vk::ObjectType::eSampler, sampler->GetVkSampler(), "[Sampler] Mips " + std::to_string(MIPS));
|
SET_VK_OBJ_NAME(device, vk::ObjectType::eSampler, sampler->GetVkSampler(), "[Sampler] Mips " + std::to_string(MIPS));
|
||||||
return texLibrary.Add(pixelCount, pixelData, width, height, format, mipOffsets, sampler);
|
return texLibrary.Add(pixelCount, pixelData, width, height, format, mipOffsets, sampler);
|
||||||
|
@ -1008,6 +1017,11 @@ namespace SHADE
|
||||||
return worldRenderGraph->GetNode(G_BUFFER_RENDER_GRAPH_NODE_NAME.data());
|
return worldRenderGraph->GetNode(G_BUFFER_RENDER_GRAPH_NODE_NAME.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHADE::SHFontLibrary const& SHGraphicsSystem::GetFontLibrary(void) const noexcept
|
||||||
|
{
|
||||||
|
return fontLibrary;
|
||||||
|
}
|
||||||
|
|
||||||
Handle<SHVkPipeline> SHGraphicsSystem::createDebugDrawPipeline(Handle<SHVkRenderpass> renderPass, Handle<SHSubpass> subpass)
|
Handle<SHVkPipeline> SHGraphicsSystem::createDebugDrawPipeline(Handle<SHVkRenderpass> renderPass, Handle<SHSubpass> subpass)
|
||||||
{
|
{
|
||||||
auto pipelineLayout = resourceManager.Create<SHVkPipelineLayout>
|
auto pipelineLayout = resourceManager.Create<SHVkPipelineLayout>
|
||||||
|
|
|
@ -367,6 +367,7 @@ namespace SHADE
|
||||||
Handle<SHVkPipeline> GetDebugDrawPipeline(void) const noexcept { return debugDrawPipeline; }
|
Handle<SHVkPipeline> GetDebugDrawPipeline(void) const noexcept { return debugDrawPipeline; }
|
||||||
Handle<SHVkPipeline> GetDebugDrawDepthPipeline(void) const noexcept { return debugDrawDepthPipeline; }
|
Handle<SHVkPipeline> GetDebugDrawDepthPipeline(void) const noexcept { return debugDrawDepthPipeline; }
|
||||||
uint32_t GetCurrentFrameIndex(void) const noexcept { return renderContext.GetCurrentFrame(); }
|
uint32_t GetCurrentFrameIndex(void) const noexcept { return renderContext.GetCurrentFrame(); }
|
||||||
|
SHFontLibrary const& GetFontLibrary (void) const noexcept;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Getters */
|
/* Getters */
|
||||||
|
|
|
@ -101,6 +101,11 @@ namespace SHADE
|
||||||
//cpuCameraData.viewProjectionMatrix = camera->GetViewProjectionMatrix();
|
//cpuCameraData.viewProjectionMatrix = camera->GetViewProjectionMatrix();
|
||||||
cameraBuffer->WriteToMemory(&cpuCameraData, sizeof(SHShaderCameraData), 0, cameraDataAlignedSize * frameIndex);
|
cameraBuffer->WriteToMemory(&cpuCameraData, sizeof(SHShaderCameraData), 0, cameraDataAlignedSize * frameIndex);
|
||||||
|
|
||||||
|
BindDescSet(cmdBuffer, frameIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHRenderer::BindDescSet(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept
|
||||||
|
{
|
||||||
std::array<uint32_t, 1> dynamicOffsets{ frameIndex * cameraDataAlignedSize };
|
std::array<uint32_t, 1> dynamicOffsets{ frameIndex * cameraDataAlignedSize };
|
||||||
|
|
||||||
cmdBuffer->BindDescriptorSet(cameraDescriptorSet, SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, std::span{ dynamicOffsets.data(), 1 });
|
cmdBuffer->BindDescriptorSet(cameraDescriptorSet, SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, std::span{ dynamicOffsets.data(), 1 });
|
||||||
|
|
|
@ -63,6 +63,7 @@ namespace SHADE
|
||||||
/***********************************************************************************/
|
/***********************************************************************************/
|
||||||
class SHRenderer
|
class SHRenderer
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Constructor/Destructors */
|
/* Constructor/Destructors */
|
||||||
|
@ -82,6 +83,7 @@ namespace SHADE
|
||||||
void Draw(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool) noexcept;
|
void Draw(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool) noexcept;
|
||||||
void UpdateDataAndBind(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept;
|
void UpdateDataAndBind(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept;
|
||||||
void UpdateDataAndBind(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept;
|
void UpdateDataAndBind(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept;
|
||||||
|
void BindDescSet (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept;
|
||||||
void UpdateCameraDataToBuffer (void) noexcept;
|
void UpdateCameraDataToBuffer (void) noexcept;
|
||||||
void SetViewProjectionMatrix (SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept;
|
void SetViewProjectionMatrix (SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept;
|
||||||
|
|
||||||
|
|
|
@ -423,9 +423,8 @@ namespace SHADE
|
||||||
/*!
|
/*!
|
||||||
|
|
||||||
\brief
|
\brief
|
||||||
Loops through every single light component and checks for dirty light
|
Loops through every single light component and writes light data to CPU
|
||||||
data. If light data is dirty, rewrite to the CPU container. We also want
|
then GPU.
|
||||||
to bind the descriptor set for the light data.
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace SHADE
|
||||||
.depth = 1,
|
.depth = 1,
|
||||||
.levels = 1,
|
.levels = 1,
|
||||||
.arrayLayers = 1,
|
.arrayLayers = 1,
|
||||||
.imageFormat = vk::Format::eR8G8B8A8Snorm,
|
.imageFormat = vk::Format::eR8G8B8A8Unorm,
|
||||||
//.imageFormat = vk::Format::eR32Sfloat,
|
//.imageFormat = vk::Format::eR32Sfloat,
|
||||||
//.imageFormat = vk::Format::eR32G32B32Sfloat,
|
//.imageFormat = vk::Format::eR32G32B32Sfloat,
|
||||||
.usageFlags = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst,
|
.usageFlags = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst,
|
||||||
|
|
|
@ -100,4 +100,9 @@ namespace SHADE
|
||||||
postTransferBarriers.clear();
|
postTransferBarriers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<Handle<SHFont>> const& SHFontLibrary::GetFonts(void) const noexcept
|
||||||
|
{
|
||||||
|
return fonts;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -13,7 +13,7 @@ namespace SHADE
|
||||||
class SHVkQueue;
|
class SHVkQueue;
|
||||||
class SHVkDescriptorSetLayout;
|
class SHVkDescriptorSetLayout;
|
||||||
|
|
||||||
class SHFontLibrary
|
class SH_API SHFontLibrary
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
//! Handles to all the fonts usable in SHTextRendererComponents
|
//! Handles to all the fonts usable in SHTextRendererComponents
|
||||||
|
@ -31,5 +31,6 @@ namespace SHADE
|
||||||
public:
|
public:
|
||||||
Handle<SHFont> AddFont (Handle<SHVkLogicalDevice> logicalDevice, SHResourceHub& resourceHub, SHFontAsset const& asset) noexcept;
|
Handle<SHFont> AddFont (Handle<SHVkLogicalDevice> logicalDevice, SHResourceHub& resourceHub, SHFontAsset const& asset) noexcept;
|
||||||
void BuildFonts (Handle<SHVkLogicalDevice> logicalDevice, Handle<SHVkQueue> queue, Handle<SHVkCommandPool> cmdPool, Handle<SHVkDescriptorPool> descPool, Handle<SHVkDescriptorSetLayout> layout, SHResourceHub& resourceHub) noexcept;
|
void BuildFonts (Handle<SHVkLogicalDevice> logicalDevice, Handle<SHVkQueue> queue, Handle<SHVkCommandPool> cmdPool, Handle<SHVkDescriptorPool> descPool, Handle<SHVkDescriptorSetLayout> layout, SHResourceHub& resourceHub) noexcept;
|
||||||
|
std::vector<Handle<SHFont>> const& GetFonts (void) const noexcept;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,13 +24,18 @@ namespace SHADE
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
void SHTextRendererComponent::OnCreate(void)
|
void SHTextRendererComponent::OnCreate(void)
|
||||||
{
|
{
|
||||||
text = "";
|
text = "Text";
|
||||||
requiresRecompute = true;
|
requiresRecompute = true;
|
||||||
|
|
||||||
// Default white color.
|
// Default white color.
|
||||||
color = SHColour::WHITE;
|
color = SHColour::WHITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHTextRendererComponent::OnDestroy(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
|
|
||||||
|
@ -50,6 +55,11 @@ namespace SHADE
|
||||||
MakeDirty();
|
MakeDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHTextRendererComponent::SetFont(Handle<SHFont> font) noexcept
|
||||||
|
{
|
||||||
|
fontHandle = font;
|
||||||
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace SHADE
|
||||||
class SHVkDescriptorSetGroup;
|
class SHVkDescriptorSetGroup;
|
||||||
class SHVkBuffer;
|
class SHVkBuffer;
|
||||||
|
|
||||||
class SHTextRendererComponent final : public SHComponent
|
class SH_API SHTextRendererComponent final : public SHComponent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static constexpr uint32_t MAX_CHARACTERS = 500;
|
static constexpr uint32_t MAX_CHARACTERS = 500;
|
||||||
|
@ -44,11 +44,14 @@ namespace SHADE
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void OnCreate(void) override final;
|
void OnCreate(void) override final;
|
||||||
|
void OnDestroy(void) override final;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* SETTERS AND GETTERS */
|
/* SETTERS AND GETTERS */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
void SetText (std::string_view newText) noexcept;
|
void SetText (std::string_view newText) noexcept;
|
||||||
|
void SetFont (Handle<SHFont> font) noexcept;
|
||||||
|
|
||||||
std::string const& GetText (void) const noexcept;
|
std::string const& GetText (void) const noexcept;
|
||||||
|
|
||||||
friend class SHTextRenderingSubSystem;
|
friend class SHTextRenderingSubSystem;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "Graphics/Pipeline/SHVkPipeline.h"
|
#include "Graphics/Pipeline/SHVkPipeline.h"
|
||||||
#include "Graphics/SHVkUtil.h"
|
#include "Graphics/SHVkUtil.h"
|
||||||
#include "Graphics/RenderGraph/SHSubpass.h"
|
#include "Graphics/RenderGraph/SHSubpass.h"
|
||||||
|
#include "Math/Transform/SHTransformComponent.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -82,16 +83,20 @@ namespace SHADE
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
textComp.indexingDataBuffer->WriteToMemory(indexingData.data(), indexingData.size() * sizeof (SHTextRendererComponent::TextIndexingType),0, 0);
|
textComp.indexingDataBuffer->WriteToMemory(indexingData.data(), static_cast<uint32_t>(indexingData.size()) * sizeof (SHTextRendererComponent::TextIndexingType),0, 0);
|
||||||
textComp.charPositionDataBuffer->WriteToMemory(charPositionData.data(), charPositionData.size() * sizeof (SHVec4), 0, 0);
|
textComp.charPositionDataBuffer->WriteToMemory(charPositionData.data(), static_cast<uint32_t>(charPositionData.size()) * sizeof (SHVec4), 0, 0);
|
||||||
|
|
||||||
indexingData.clear();
|
indexingData.clear();
|
||||||
charPositionData.clear();
|
charPositionData.clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHTextRenderingSubSystem::Init(Handle<SHVkLogicalDevice> device, Handle<SHVkRenderpass> compatibleRenderpass, Handle<SHSubpass> subpass, Handle<SHVkDescriptorPool> descPool, Handle<SHVkShaderModule> textVS, Handle<SHVkShaderModule> textFS) noexcept
|
void SHTextRenderingSubSystem::Init(Handle<SHVkLogicalDevice> device, Handle<SHVkRenderpass> compatibleRenderpass, Handle<SHSubpass> subpass, Handle<SHVkDescriptorPool> descPool, Handle<SHVkShaderModule> textVS, Handle<SHVkShaderModule> textFS, std::function<void(Handle<SHVkCommandBuffer>, uint32_t)> const& bindFunction) noexcept
|
||||||
{
|
{
|
||||||
|
SHComponentManager::CreateComponentSparseSet<SHTextRendererComponent>();
|
||||||
|
|
||||||
|
cameraDescSetBind = bindFunction;
|
||||||
|
|
||||||
logicalDevice = device;
|
logicalDevice = device;
|
||||||
|
|
||||||
// prepare pipeline layout params
|
// prepare pipeline layout params
|
||||||
|
@ -121,7 +126,7 @@ namespace SHADE
|
||||||
colorBlendState.logic_op = vk::LogicOp::eCopy;
|
colorBlendState.logic_op = vk::LogicOp::eCopy;
|
||||||
|
|
||||||
auto const& subpassColorReferences = subpass->GetColorAttachmentReferences();
|
auto const& subpassColorReferences = subpass->GetColorAttachmentReferences();
|
||||||
colorBlendState.attachments.reserve(subpassColorReferences.size());
|
colorBlendState.attachments.reserve(static_cast<uint32_t>(subpassColorReferences.size()));
|
||||||
|
|
||||||
for (auto& att : subpassColorReferences)
|
for (auto& att : subpassColorReferences)
|
||||||
{
|
{
|
||||||
|
@ -177,17 +182,18 @@ namespace SHADE
|
||||||
RecomputePositions(comp);
|
RecomputePositions(comp);
|
||||||
comp.Clean();
|
comp.Clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHTextRenderingSubSystem::Render(Handle<SHVkCommandBuffer> cmdBuffer) noexcept
|
void SHTextRenderingSubSystem::Render(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept
|
||||||
{
|
{
|
||||||
auto& textRendererComps = SHComponentManager::GetDense<SHTextRendererComponent>();
|
auto& textRendererComps = SHComponentManager::GetDense<SHTextRendererComponent>();
|
||||||
for (auto& comp : textRendererComps)
|
for (auto& comp : textRendererComps)
|
||||||
{
|
{
|
||||||
|
auto* transform = SHComponentManager::GetComponent<SHTransformComponent>(comp.GetEID());
|
||||||
|
|
||||||
Handle<SHFont> fontHandle = comp.fontHandle;
|
Handle<SHFont> fontHandle = comp.fontHandle;
|
||||||
if (fontHandle)
|
if (fontHandle && transform)
|
||||||
{
|
{
|
||||||
// bind the pipeline
|
// bind the pipeline
|
||||||
cmdBuffer->BindPipeline(pipeline);
|
cmdBuffer->BindPipeline(pipeline);
|
||||||
|
@ -196,10 +202,20 @@ namespace SHADE
|
||||||
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::CALCULATED_GLYPH_POSITION, comp.charPositionDataBuffer, 0);
|
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::CALCULATED_GLYPH_POSITION, comp.charPositionDataBuffer, 0);
|
||||||
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::GLYPH_INDEX, comp.indexingDataBuffer, 0);
|
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::GLYPH_INDEX, comp.indexingDataBuffer, 0);
|
||||||
|
|
||||||
|
cameraDescSetBind(cmdBuffer, frameIndex);
|
||||||
|
|
||||||
// bind descriptors for font (matrices)
|
// bind descriptors for font (matrices)
|
||||||
cmdBuffer->BindDescriptorSet(fontHandle->GetDescriptorSet(), SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, {});
|
cmdBuffer->BindDescriptorSet(fontHandle->GetDescriptorSet(), SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, {});
|
||||||
|
|
||||||
|
cmdBuffer->SetPushConstantVariable("TestPushConstant.worldTransform", transform->GetTRS(), SH_PIPELINE_TYPE::GRAPHICS);
|
||||||
|
cmdBuffer->SetPushConstantVariable("TestPushConstant.eid", comp.GetEID(), SH_PIPELINE_TYPE::GRAPHICS);
|
||||||
|
cmdBuffer->SetPushConstantVariable("TestPushConstant.textColor", SHVec3 (1.0f, 1.0f, 1.0f), SH_PIPELINE_TYPE::GRAPHICS);
|
||||||
|
|
||||||
|
cmdBuffer->SubmitPushConstants(SH_PIPELINE_TYPE::GRAPHICS);
|
||||||
|
|
||||||
// call draw call
|
// call draw call
|
||||||
|
cmdBuffer->DrawArrays(4, comp.text.size(), 0, 0);
|
||||||
|
//glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, static_cast<GLsizei>(textComp.lastRenderedCharacterIndex) + 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include "Resource/SHHandle.h"
|
#include "Resource/SHHandle.h"
|
||||||
#include "Graphics/Pipeline/SHPipelineState.h"
|
#include "Graphics/Pipeline/SHPipelineState.h"
|
||||||
|
#include "Math/SHMatrix.h"
|
||||||
|
#include "Math/Vector/SHVec3.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -22,6 +24,12 @@ namespace SHADE
|
||||||
class SHTextRenderingSubSystem
|
class SHTextRenderingSubSystem
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
struct ShaderPushConstantData
|
||||||
|
{
|
||||||
|
SHMatrix worldTransform;
|
||||||
|
uint32_t eid;
|
||||||
|
SHVec3 textColor;
|
||||||
|
};
|
||||||
|
|
||||||
//! Logical device for creation and destruction
|
//! Logical device for creation and destruction
|
||||||
Handle<SHVkLogicalDevice> logicalDevice;
|
Handle<SHVkLogicalDevice> logicalDevice;
|
||||||
|
@ -35,15 +43,21 @@ namespace SHADE
|
||||||
//! Descriptor set for font data access in shaders
|
//! Descriptor set for font data access in shaders
|
||||||
Handle<SHVkDescriptorSetLayout> fontDataDescSetLayout;
|
Handle<SHVkDescriptorSetLayout> fontDataDescSetLayout;
|
||||||
|
|
||||||
|
//! Super temporary. Global descriptor set needs to be revamped along with
|
||||||
|
//! entire graphics system.
|
||||||
|
std::function<void(Handle<SHVkCommandBuffer>, uint32_t)> cameraDescSetBind;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void RecomputePositions(SHTextRendererComponent& textComp) noexcept;
|
void RecomputePositions(SHTextRendererComponent& textComp) noexcept;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Init(Handle<SHVkLogicalDevice> device, Handle<SHVkRenderpass> compatibleRenderpass, Handle<SHSubpass> subpass, Handle<SHVkDescriptorPool> descPool, Handle<SHVkShaderModule> textVS, Handle<SHVkShaderModule> textFS) noexcept;
|
void Init(Handle<SHVkLogicalDevice> device, Handle<SHVkRenderpass> compatibleRenderpass, Handle<SHSubpass> subpass, Handle<SHVkDescriptorPool> descPool, Handle<SHVkShaderModule> textVS, Handle<SHVkShaderModule> textFS, std::function<void(Handle<SHVkCommandBuffer>, uint32_t)> const& bindFunction) noexcept;
|
||||||
void Run(uint32_t frameIndex) noexcept;
|
void Run(uint32_t frameIndex) noexcept;
|
||||||
void Render (Handle<SHVkCommandBuffer> cmdBuffer) noexcept;
|
|
||||||
|
void Render (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept;
|
||||||
void Exit(void) noexcept;
|
void Exit(void) noexcept;
|
||||||
|
|
||||||
|
|
||||||
Handle<SHVkDescriptorSetLayout> GetFontDataDescSetLayout (void) const noexcept;
|
Handle<SHVkDescriptorSetLayout> GetFontDataDescSetLayout (void) const noexcept;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -79,9 +79,9 @@ namespace SHADE
|
||||||
startOffset += pcInfo.size;
|
startOffset += pcInfo.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stageFlags |= shaderModule->GetShaderStageFlagBits();
|
||||||
}
|
}
|
||||||
|
|
||||||
stageFlags |= shaderModule->GetShaderStageFlagBits();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// After all the sizes of the push constant blocks have been added, record the size in the interface
|
// After all the sizes of the push constant blocks have been added, record the size in the interface
|
||||||
|
|
|
@ -211,7 +211,7 @@ namespace SHADE
|
||||||
// Draw all the exterior draw calls
|
// Draw all the exterior draw calls
|
||||||
for (auto& drawCall : exteriorDrawCalls)
|
for (auto& drawCall : exteriorDrawCalls)
|
||||||
{
|
{
|
||||||
drawCall(commandBuffer);
|
drawCall(commandBuffer, frameIndex);
|
||||||
}
|
}
|
||||||
commandBuffer->EndLabeledSegment();
|
commandBuffer->EndLabeledSegment();
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ namespace SHADE
|
||||||
UpdateWriteDescriptors();
|
UpdateWriteDescriptors();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHSubpass::AddExteriorDrawCalls(std::function<void(Handle<SHVkCommandBuffer>&)> const& newDrawCall) noexcept
|
void SHSubpass::AddExteriorDrawCalls(std::function<void(Handle<SHVkCommandBuffer>&, uint32_t)> const& newDrawCall) noexcept
|
||||||
{
|
{
|
||||||
exteriorDrawCalls.push_back(newDrawCall);
|
exteriorDrawCalls.push_back(newDrawCall);
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ namespace SHADE
|
||||||
//! after we draw everything from the batch. Because of this, these draw calls
|
//! after we draw everything from the batch. Because of this, these draw calls
|
||||||
//! are always the last things drawn, so DO NOT USE THIS FUNCTIONALITY FOR ANYTHING
|
//! are always the last things drawn, so DO NOT USE THIS FUNCTIONALITY FOR ANYTHING
|
||||||
//! COMPLEX.
|
//! COMPLEX.
|
||||||
std::vector<std::function<void(Handle<SHVkCommandBuffer>&)>> exteriorDrawCalls;
|
std::vector<std::function<void(Handle<SHVkCommandBuffer>&, uint32_t)>> exteriorDrawCalls;
|
||||||
/// For identifying subpasses
|
/// For identifying subpasses
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ namespace SHADE
|
||||||
void AddGeneralDepthOutput(std::string resourceToReference) noexcept;
|
void AddGeneralDepthOutput(std::string resourceToReference) noexcept;
|
||||||
void AddInput(std::string resourceToReference) noexcept;
|
void AddInput(std::string resourceToReference) noexcept;
|
||||||
void AddGeneralInput (std::string resourceToReference) noexcept;
|
void AddGeneralInput (std::string resourceToReference) noexcept;
|
||||||
void AddExteriorDrawCalls(std::function<void(Handle<SHVkCommandBuffer>&)> const& newDrawCall) noexcept;
|
void AddExteriorDrawCalls(std::function<void(Handle<SHVkCommandBuffer>&, uint32_t)> const& newDrawCall) noexcept;
|
||||||
|
|
||||||
// Runtime functions
|
// Runtime functions
|
||||||
void Execute(Handle<SHVkCommandBuffer>& commandBuffer, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex) noexcept;
|
void Execute(Handle<SHVkCommandBuffer>& commandBuffer, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex) noexcept;
|
||||||
|
|
Loading…
Reference in New Issue