diff --git a/Assets/Fonts/SegoeUI.shfont b/Assets/Fonts/SegoeUI.shfont index d4532e59..3f709c2a 100644 Binary files a/Assets/Fonts/SegoeUI.shfont and b/Assets/Fonts/SegoeUI.shfont differ diff --git a/Assets/Fonts/SegoeUI.shfont.shmeta b/Assets/Fonts/SegoeUI.shfont.shmeta new file mode 100644 index 00000000..33ee953d --- /dev/null +++ b/Assets/Fonts/SegoeUI.shfont.shmeta @@ -0,0 +1,3 @@ +Name: SegoeUI +ID: 176667660 +Type: 10 diff --git a/Assets/Shaders/Text_FS.glsl b/Assets/Shaders/Text_FS.glsl index f3884973..87e29de8 100644 --- a/Assets/Shaders/Text_FS.glsl +++ b/Assets/Shaders/Text_FS.glsl @@ -23,16 +23,12 @@ layout(location = 0) in struct layout(location = 3) flat in struct { uint eid; + vec3 textColor; } In2; -// push constants -layout(std140, push_constant) uniform TestPushConstant -{ - vec3 textColor; -} testPushConstant; -layout(set = 6, binding = 0) uniform sampler2D fontBitmap; +layout(set = 4, binding = 0) uniform sampler2D fontBitmap; layout(location = 0) out vec4 color; layout(location = 1) out uint outEntityID; @@ -56,7 +52,7 @@ void main() fragColor = vec4(0.0f, 1.0f, 1.0f, 1.0f); } - fragColor = mix(vec4(0.0f), vec4(testPushConstant.textColor, 1.0f), min (opacity, 1.0f)); + fragColor = mix(vec4(0.0f), vec4(In2.textColor, 1.0f), min (opacity, 1.0f)); color = fragColor; diff --git a/Assets/Shaders/Text_FS.shshaderb b/Assets/Shaders/Text_FS.shshaderb index 9121f960..96c8c587 100644 Binary files a/Assets/Shaders/Text_FS.shshaderb and b/Assets/Shaders/Text_FS.shshaderb differ diff --git a/Assets/Shaders/Text_VS.glsl b/Assets/Shaders/Text_VS.glsl index b3224211..62316533 100644 --- a/Assets/Shaders/Text_VS.glsl +++ b/Assets/Shaders/Text_VS.glsl @@ -21,6 +21,7 @@ layout(location = 0) out struct layout(location = 3) out struct { uint eid; + vec3 textColor; } Out2; // Camera data @@ -37,11 +38,12 @@ layout(std140, push_constant) uniform TestPushConstant { mat4 worldTransform; uint eid; + vec3 textColor; } testPushConstant; // Descriptor sets -layout(std430, set = 6, binding = 1) buffer GlyphTransforms +layout(std430, set = 4, binding = 1) buffer GlyphTransforms { mat4 matrices[]; } glyphTransforms; @@ -92,6 +94,8 @@ void main() // Transform the vertices to font space vertexPos = toFontSpace * vertexPos; + Out2.textColor = testPushConstant.textColor; + // transform the vertex position to font space gl_Position = PVMatrix * localModel * vec4(vertexPos, 1.0f); } \ No newline at end of file diff --git a/Assets/Shaders/Text_VS.shshaderb b/Assets/Shaders/Text_VS.shshaderb index 481e0950..b6f0afe7 100644 Binary files a/Assets/Shaders/Text_VS.shshaderb and b/Assets/Shaders/Text_VS.shshaderb differ diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 3811e90e..1bf95c88 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -78,6 +78,7 @@ namespace Sandbox SHSystemManager::CreateSystem(); SHSystemManager::CreateSystem(); + std::system("FontCompiler.exe ../../Assets/Fonts/SegoeUI.ttf"); SHSystemManager::CreateSystem(); SHGraphicsSystem* graphicsSystem = static_cast(SHSystemManager::GetSystem()); @@ -135,7 +136,7 @@ namespace Sandbox //SHComponentManager::CreateComponentSparseSet(); SHAssetManager::Load(); - + auto font = SHAssetManager::GetData(176667660); SHSystemManager::RegisterRoutine(); @@ -148,8 +149,6 @@ namespace Sandbox SHFrameRateController::UpdateFRC(); - //std::system("FontCompiler.exe ../../Assets/Fonts/SegoeUI.ttf"); - // Link up SHDebugDraw SHDebugDraw::Init(SHSystemManager::GetSystem()); } diff --git a/SHADE_Application/src/Scenes/SBMainScene.cpp b/SHADE_Application/src/Scenes/SBMainScene.cpp index b14f2e6f..9da68729 100644 --- a/SHADE_Application/src/Scenes/SBMainScene.cpp +++ b/SHADE_Application/src/Scenes/SBMainScene.cpp @@ -13,6 +13,7 @@ #include "Physics/Interface/SHRigidBodyComponent.h" #include "Physics/Interface/SHColliderComponent.h" #include "Graphics/MiddleEnd/Lights/SHLightComponent.h" +#include "Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h" #include "Assets/SHAssetManager.h" #include "Camera/SHCameraComponent.h" @@ -41,6 +42,19 @@ namespace Sandbox void SBMainScene::Init() { sceneName = SHSerialization::DeserializeSceneFromFile(sceneAssetID); + + /*-----------------------------------------------------------------------*/ + /* TESTING CODE */ + /*-----------------------------------------------------------------------*/ + //testText = SHEntityManager::CreateEntity(MAX_EID, "Test Text"); + //auto gfxSystem =SHSystemManager::GetSystem(); + + //auto textComp = SHComponentManager::GetComponent(testText); + + //textComp->SetFont(gfxSystem->GetFontLibrary().GetFonts()[0]); + /*-----------------------------------------------------------------------*/ + /* TESTING CODE */ + /*-----------------------------------------------------------------------*/ } void SBMainScene::Update(float dt) diff --git a/SHADE_Application/src/Scenes/SBMainScene.h b/SHADE_Application/src/Scenes/SBMainScene.h index 7bd10118..18d43e33 100644 --- a/SHADE_Application/src/Scenes/SBMainScene.h +++ b/SHADE_Application/src/Scenes/SBMainScene.h @@ -12,6 +12,8 @@ namespace Sandbox EntityID testObj; std::vector stressTestObjects; + EntityID testText; + public: virtual void Load(); virtual void Init(); diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHFontLoader.cpp b/SHADE_Engine/src/Assets/Libraries/Loaders/SHFontLoader.cpp index 05242c0a..9bbd3a71 100644 --- a/SHADE_Engine/src/Assets/Libraries/Loaders/SHFontLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHFontLoader.cpp @@ -48,15 +48,17 @@ namespace SHADE // read the height file.read(reinterpret_cast(&newFontAsset->bitmapHeight), sizeof(SHFontAsset::bitmapHeight)); - uint32_t bytesRequired = newFontAsset->bitmapWidth * newFontAsset->bitmapHeight * SHFontAsset::BYTES_PER_CHANNEL * SHFontAsset::NUM_CHANNELS; + uint32_t bytesRequired = 0; + file.read(reinterpret_cast(&bytesRequired), sizeof(uint32_t)); // Read the bitmap newFontAsset->bitmapData.resize(bytesRequired); - file.read (reinterpret_cast(newFontAsset->bitmapData.data()), bytesRequired); + file.read(reinterpret_cast(newFontAsset->bitmapData.data()), bytesRequired); + file.close(); - return nullptr; + return newFontAsset; } void SHFontLoader::Write(SHAssetData const* data, AssetPath path) diff --git a/SHADE_Engine/src/Assets/SHAssetMacros.h b/SHADE_Engine/src/Assets/SHAssetMacros.h index 6b5e03d5..5ab1945d 100644 --- a/SHADE_Engine/src/Assets/SHAssetMacros.h +++ b/SHADE_Engine/src/Assets/SHAssetMacros.h @@ -67,8 +67,9 @@ constexpr std::string_view ASSET_ROOT {"../../Assets"}; constexpr std::string_view BUILT_IN_ASSET_ROOT{ "../../Built_In" }; #endif -// COMPILER PATHS +// COMPILER EXE constexpr std::string_view MODEL_COMPILER_EXE{ "ModelCompiler.exe" }; +constexpr std::string_view FONT_COMPILER_EXE{ "FontCompiler.exe" }; // INTERNAL ASSET PATHS constexpr std::string_view SCENE_FOLDER{ "/Scenes/" }; diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index 895de0f9..e6762822 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -20,6 +20,7 @@ #include "Libraries/Loaders/SHTextureLoader.h" #include "Libraries/Loaders/SHShaderSourceLoader.h" #include "Libraries/Loaders/SHTextBasedLoader.h" +#include "Libraries/Loaders/SHFontLoader.h" //#include "Libraries/Compilers/SHMeshCompiler.h" #include "Libraries/Compilers/SHTextureCompiler.h" @@ -398,6 +399,16 @@ namespace SHADE } newPath = pathGen.value(); } + else if (ext == TTF_EXTENSION.data()) + { + std::string command = FONT_COMPILER_EXE.data(); + command += " " + path.string(); + std::system(command.c_str()); + + std::string fontPath = path.string().substr(0, path.string().find_last_of('.')); + fontPath += FONT_EXTENSION; + newPath = fontPath; + } else { SHLOG_WARNING("File Type compilation not yet Implemented: {}", path.string()); @@ -450,6 +461,8 @@ namespace SHADE loaders[static_cast(AssetType::PREFAB)] = loaders[static_cast(AssetType::SCENE)]; loaders[static_cast(AssetType::MATERIAL)] = loaders[static_cast(AssetType::SCENE)]; loaders[static_cast(AssetType::MESH)] = nullptr; + loaders[static_cast(AssetType::SCRIPT)] = nullptr; + loaders[static_cast(AssetType::FONT)] = dynamic_cast(new SHFontLoader()); } /**************************************************************************** diff --git a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp index 2a24ad0e..cf545223 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp @@ -345,10 +345,18 @@ namespace SHADE void SHHierarchyPanel::ParentSelectedEntities(EntityID parentEID, std::vector const& entities) const noexcept { auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); + + std::vector entitiesToParent{}; + std::ranges::copy_if(entities, std::back_inserter(entitiesToParent), [&sceneGraph](EntityID const& eid) + { + if (sceneGraph.GetParent(eid)->GetEntityID() == MAX_EID) + return true; + return false; + }); //auto const editor = SHSystemManager::GetSystem(); SHEntityParentCommand::EntityParentData entityParentData; std::vector parentedEIDS; - for (auto const& eid : entities) + for (auto const& eid : entitiesToParent) { if(eid == parentEID) continue; diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 6091556e..146e36c3 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -68,10 +68,10 @@ namespace SHADE { if (!component) return; + const auto componentType = rttr::type::get(); ImGui::PushID(SHFamilyID::GetID()); SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }, "Is Component Active"); - ImGui::PopID(); ImGui::SameLine(); if (ImGui::CollapsingHeader(componentType.get_name().data())) { @@ -216,6 +216,8 @@ namespace SHADE } } else DrawContextMenu(component); + ImGui::PopID(); + } template<> @@ -223,7 +225,8 @@ namespace SHADE { if (!component) return; - ImGui::PushID(component); + ImGui::PushID(SHFamilyID::GetID()); + const auto componentType = rttr::type::get(*component); SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }, "Is Component Active"); ImGui::SameLine(); @@ -330,6 +333,7 @@ namespace SHADE { if (!component) return; + ImGui::PushID(SHFamilyID::GetID()); const auto componentType = rttr::type::get(*component); SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }, "Is Component Active"); ImGui::SameLine(); @@ -353,6 +357,7 @@ namespace SHADE { DrawContextMenu(component); } + ImGui::PopID(); } template<> @@ -360,6 +365,7 @@ namespace SHADE { if (!component) return; + ImGui::PushID(SHFamilyID::GetID()); const auto componentType = rttr::type::get(*component); SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }, "Is Component Active"); ImGui::SameLine(); @@ -397,5 +403,6 @@ namespace SHADE { DrawContextMenu(component); } + ImGui::PopID(); } } diff --git a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp index 223f9b83..2912a0bc 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp @@ -35,7 +35,7 @@ namespace SHADE constexpr ImGuiWindowFlags dockspaceFlags = ImGuiDockNodeFlags_PassthruCentralNode; - //#==============================================================# + //#==============================================================# //|| Public Member Functions || //#==============================================================# SHEditorMenuBar::SHEditorMenuBar() @@ -221,13 +221,20 @@ namespace SHADE ImGui::BeginDisabled(editor->editorState == SHEditor::State::PLAY); if(ImGui::SmallButton(ICON_MD_PLAY_ARROW)) { - if(editor->SaveScene()) + if(editor->editorState == SHEditor::State::STOP) + { + if (editor->SaveScene()) + { + editor->Play(); + } + } + else { editor->Play(); } } ImGui::EndDisabled(); - ImGui::BeginDisabled(editor->editorState == SHEditor::State::PAUSE); + ImGui::BeginDisabled(editor->editorState == SHEditor::State::STOP || editor->editorState == SHEditor::State::PAUSE); if(ImGui::SmallButton(ICON_MD_PAUSE)) { editor->Pause(); diff --git a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp index d0b32ff5..564731d6 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp @@ -85,7 +85,7 @@ namespace SHADE shouldUpdateCamArm = ImGui::IsWindowHovered() && ImGui::IsKeyDown(ImGuiKey_LeftAlt) && ImGui::IsMouseDown(ImGuiMouseButton_Left); - if (editor->editorState != SHEditor::State::PLAY && ImGui::IsWindowFocused() && !ImGui::IsMouseDown(ImGuiMouseButton_Right)) + if (editor->editorState != SHEditor::State::PLAY && !ImGui::IsAnyItemActive() && !ImGui::IsMouseDown(ImGuiMouseButton_Right)) { if (ImGui::IsKeyReleased(ImGuiKey_W)) { @@ -151,7 +151,7 @@ namespace SHADE if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) { ImGui::BeginTooltip(); - ImGui::Text("Translate [Q]"); + ImGui::Text("Translate [W]"); ImGui::EndTooltip(); } if (isTranslate) @@ -169,7 +169,7 @@ namespace SHADE if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) { ImGui::BeginTooltip(); - ImGui::Text("Rotate [W]"); + ImGui::Text("Rotate [E]"); ImGui::EndTooltip(); } if (isRotate) @@ -187,7 +187,7 @@ namespace SHADE if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) { ImGui::BeginTooltip(); - ImGui::Text("Scale [E]"); + ImGui::Text("Scale [R]"); ImGui::EndTooltip(); } if (isScale) diff --git a/SHADE_Engine/src/Editor/SHEditor.cpp b/SHADE_Engine/src/Editor/SHEditor.cpp index 7372f227..07caee7a 100644 --- a/SHADE_Engine/src/Editor/SHEditor.cpp +++ b/SHADE_Engine/src/Editor/SHEditor.cpp @@ -516,7 +516,7 @@ namespace SHADE ImGui_ImplVulkan_DestroyFontUploadObjects(); - renderGraph->GetNode("ImGui Node")->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle& cmd) + renderGraph->GetNode("ImGui Node")->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle& cmd, uint32_t frameIndex) { cmd->BeginLabeledSegment("ImGui Draw"); ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->GetVkCommandBuffer()); diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp index 272a838d..95cf2e91 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp +++ b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp @@ -459,7 +459,7 @@ namespace SHADE return SHVkInstance::GetResourceManager().Create(GetHandle(), &vmaAllocator, w, h, levels, format, usage, create); } - Handle SHVkLogicalDevice::CreateImage(SHImageCreateParams const& imageDetails, unsigned char* data, uint32_t dataSize, std::span inMipOffsets, VmaMemoryUsage memUsage, VmaAllocationCreateFlags allocFlags) noexcept + Handle SHVkLogicalDevice::CreateImage(SHImageCreateParams const& imageDetails, unsigned char* data, uint32_t dataSize, std::vector const& inMipOffsets, VmaMemoryUsage memUsage, VmaAllocationCreateFlags allocFlags) noexcept { return SHVkInstance::GetResourceManager().Create(GetHandle(), &vmaAllocator, imageDetails, data, dataSize, inMipOffsets, memUsage, allocFlags); } diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.h b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.h index 158c20b2..ed09b482 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.h +++ b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.h @@ -162,7 +162,7 @@ namespace SHADE SHImageCreateParams const& imageDetails, unsigned char* data, uint32_t dataSize, - std::span inMipOffsets, + std::vector const& inMipOffsets, VmaMemoryUsage memUsage, VmaAllocationCreateFlags allocFlags ) noexcept; diff --git a/SHADE_Engine/src/Graphics/Images/SHVkImage.cpp b/SHADE_Engine/src/Graphics/Images/SHVkImage.cpp index 9f22f4c2..53703924 100644 --- a/SHADE_Engine/src/Graphics/Images/SHVkImage.cpp +++ b/SHADE_Engine/src/Graphics/Images/SHVkImage.cpp @@ -123,7 +123,7 @@ namespace SHADE SHImageCreateParams const& imageDetails, const unsigned char* data, uint32_t dataSize, - std::span inMipOffsets, + std::vector const& inMipOffsets, VmaMemoryUsage memUsage, VmaAllocationCreateFlags allocFlags ) noexcept diff --git a/SHADE_Engine/src/Graphics/Images/SHVkImage.h b/SHADE_Engine/src/Graphics/Images/SHVkImage.h index 07e0d21d..98d8d0af 100644 --- a/SHADE_Engine/src/Graphics/Images/SHVkImage.h +++ b/SHADE_Engine/src/Graphics/Images/SHVkImage.h @@ -102,7 +102,7 @@ namespace SHADE vk::Buffer stagingBuffer; //! Mipmap offsets for initializing the vk::BufferImageCopy during transfer to GPU resource - std::span mipOffsets; + std::vector mipOffsets; //! Handle to the device that creates these images Handle device; @@ -125,7 +125,7 @@ namespace SHADE SHImageCreateParams const& imageDetails, const unsigned char* data, uint32_t dataSize, - std::span inMipOffsets, + std::vector const& inMipOffsets, VmaMemoryUsage memUsage, VmaAllocationCreateFlags allocFlags ) noexcept; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp index 8a12b684..d0fbaf2c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp @@ -97,23 +97,6 @@ namespace SHADE Handle materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, { materialDataBinding }); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, materialDataPerInstanceLayout->GetVkHandle(), "[Descriptor Set Layout] Material Globals"); - SHVkDescriptorSetLayout::Binding fontBitmapBinding - { - .Type = vk::DescriptorType::eCombinedImageSampler, - .Stage = vk::ShaderStageFlagBits::eFragment, - .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA, - .DescriptorCount = 1, - }; - - SHVkDescriptorSetLayout::Binding fontMatrixBinding - { - .Type = vk::DescriptorType::eStorageBuffer, - .Stage = vk::ShaderStageFlagBits::eVertex, - .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA, - .DescriptorCount = 1, - }; - - Handle fontDataLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, { fontBitmapBinding, fontMatrixBinding }); globalDescSetLayouts.push_back(staticGlobalLayout); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp index 60262607..0bfa89a2 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.cpp @@ -90,7 +90,7 @@ namespace SHADE auto const& RENDERERS = GFX_SYSTEM->GetDefaultViewport()->GetRenderers(); auto renderGraph = RENDERERS[SHGraphicsConstants::RenderGraphIndices::WORLD]->GetRenderGraph(); auto subPass = renderGraph->GetNode("Debug Draw")->GetSubpass("Debug Draw"); - subPass->AddExteriorDrawCalls([this, GFX_SYSTEM](Handle& cmdBuffer) + subPass->AddExteriorDrawCalls([this, GFX_SYSTEM](Handle& cmdBuffer, uint32_t frameIndex) { // Get Current frame index 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"); - subPassWithDepth->AddExteriorDrawCalls([this, GFX_SYSTEM](Handle& cmdBuffer) + subPassWithDepth->AddExteriorDrawCalls([this, GFX_SYSTEM](Handle& cmdBuffer, uint32_t frameIndex) { // Get Current frame index const uint32_t FRAME_IDX = GFX_SYSTEM->GetCurrentFrameIndex(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index bd505524..e6051841 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -66,7 +66,9 @@ namespace SHADE /***************************************************************************/ /*! \brief - DescriptorSet Index for render graph resources. + DescriptorSet Index for render graph resources. Unlike the sets from + 1 to 3 and 6, this set index does not have hard coded bindings and is + NOT part of the layouts included in the global data. */ /***************************************************************************/ static constexpr uint32_t RENDERGRAPH_RESOURCE = 4; @@ -75,7 +77,7 @@ namespace SHADE \brief DescriptorSet Index for render graph node compute resources. For data that we wish to pass to compute shaders in the render graph, this is - the set to use. Unlike the sets from 1 to 3, this set index does not have + the set to use. Unlike the sets from 1 to 3 and 6, this set index does not have hard coded bindings and is NOT part of the layouts included in the global data. */ @@ -89,7 +91,7 @@ namespace SHADE */ /***************************************************************************/ - static constexpr uint32_t FONT_DATA = 6; + static constexpr uint32_t FONT_DATA = 4; }; struct DescriptorSetBindings diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index aae06784..0c7dcb05 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -121,15 +121,16 @@ namespace SHADE SHAssetManager::CompileAsset("../../Assets/Shaders/Text_FS.glsl", false); // Load Built In Shaders - static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet(VS_DEFAULT); - static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet(FS_DEFAULT); - static constexpr AssetID VS_DEBUG = 48002439; debugVertShader = SHResourceManager::LoadOrGet(VS_DEBUG); - static constexpr AssetID FS_DEBUG = 36671027; debugFragShader = SHResourceManager::LoadOrGet(FS_DEBUG); - static constexpr AssetID CS_COMPOSITE = 45072428; deferredCompositeShader = SHResourceManager::LoadOrGet(CS_COMPOSITE); - static constexpr AssetID SSAO = 38430899; ssaoShader = SHResourceManager::LoadOrGet(SSAO); - static constexpr AssetID SSAO_BLUR = 39760835; ssaoBlurShader = SHResourceManager::LoadOrGet(SSAO_BLUR); - static constexpr AssetID TEXT_VS = 39816727; textVS = SHResourceManager::LoadOrGet(TEXT_VS); - static constexpr AssetID TEXT_FS = 38024754; textFS = SHResourceManager::LoadOrGet(TEXT_FS); + static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet(VS_DEFAULT); + static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet(FS_DEFAULT); + static constexpr AssetID VS_DEBUG = 48002439; debugVertShader = SHResourceManager::LoadOrGet(VS_DEBUG); + static constexpr AssetID FS_DEBUG = 36671027; debugFragShader = SHResourceManager::LoadOrGet(FS_DEBUG); + static constexpr AssetID CS_COMPOSITE = 45072428; deferredCompositeShader = SHResourceManager::LoadOrGet(CS_COMPOSITE); + static constexpr AssetID SSAO = 38430899; ssaoShader = SHResourceManager::LoadOrGet(SSAO); + static constexpr AssetID SSAO_BLUR = 39760835; ssaoBlurShader = SHResourceManager::LoadOrGet(SSAO_BLUR); + static constexpr AssetID TEXT_VS = 39816727; textVS = SHResourceManager::LoadOrGet(TEXT_VS); + static constexpr AssetID TEXT_FS = 38024754; textFS = SHResourceManager::LoadOrGet(TEXT_FS); + static constexpr AssetID SEGOE_UI_FONT = 176667660; testFont = SHResourceManager::LoadOrGet(SEGOE_UI_FONT); } void SHGraphicsSystem::InitSceneRenderGraph(void) noexcept @@ -281,10 +282,16 @@ namespace SHADE screenRenderGraph = resourceManager.Create(); screenRenderGraph->Init("Scene Render Graph", device, swapchain, &resourceManager); screenRenderGraph->LinkNonOwningResource(worldRenderGraph, "Scene"); + screenRenderGraph->LinkNonOwningResource(worldRenderGraph, "Entity ID"); - auto screenSpaceNode = screenRenderGraph->AddNode("Screen Space Pass", { "Scene" }, {}); + auto screenSpaceNode = screenRenderGraph->AddNode("Screen Space Pass", { "Scene", "Entity ID"}, {}); auto uiSubpass = screenSpaceNode->AddSubpass("UI"); uiSubpass->AddColorOutput("Scene"); + uiSubpass->AddColorOutput("Entity ID"); + uiSubpass->AddExteriorDrawCalls([=](Handle& cmdBuffer, uint32_t frameIndex) + { + textRenderingSubSystem->Render(cmdBuffer, frameIndex); + }); { // Dummy Node to transition scene render graph resource @@ -359,8 +366,11 @@ namespace SHADE textRenderingSubSystem = resourceManager.Create(); // initialize the text renderer - //auto uiNode = screenRenderGraph->GetNode("Screen Space Pass"); - //textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS); + auto uiNode = screenRenderGraph->GetNode("Screen Space Pass"); + textRenderingSubSystem->Init(device, uiNode->GetRenderpass(), uiNode->GetSubpass("UI"), descPool, textVS, textFS, [=](Handle cmdBuffer, uint32_t frameIndex) + { + screenRenderer->BindDescSet(cmdBuffer, frameIndex); + }); SHFreetypeInstance::Init(); } @@ -503,6 +513,8 @@ namespace SHADE #endif } + textRenderingSubSystem->Run(frameIndex); + // For every viewport for (int vpIndex = 0; vpIndex < static_cast(viewports.size()); ++vpIndex) { @@ -807,7 +819,7 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ Handle SHGraphicsSystem::AddTexture(const SHTextureAsset& texAsset) { - const int MIPS = texAsset.mipOffsets.size(); + const int MIPS = static_cast (texAsset.mipOffsets.size()); auto sampler = samplerCache.GetSampler(device, SHVkSamplerParams { .maxLod = static_cast(MIPS) }); SET_VK_OBJ_NAME(device, vk::ObjectType::eSampler, sampler->GetVkSampler(), "[Sampler] Mips " + std::to_string(MIPS)); return texLibrary.Add(texAsset, sampler); @@ -815,7 +827,7 @@ namespace SHADE SHADE::Handle SHGraphicsSystem::AddTexture(uint32_t pixelCount, const SHTexture::PixelChannel* const pixelData, uint32_t width, uint32_t height, SHTexture::TextureFormat format, std::vector mipOffsets) { - const int MIPS = mipOffsets.size(); + const int MIPS = static_cast (mipOffsets.size()); auto sampler = samplerCache.GetSampler(device, SHVkSamplerParams{ .maxLod = static_cast(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); @@ -854,7 +866,7 @@ namespace SHADE void SHGraphicsSystem::BuildFonts(void) noexcept { - fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, resourceManager); + fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, textRenderingSubSystem->GetFontDataDescSetLayout(), resourceManager); } #pragma endregion ADD_REMOVE @@ -1005,6 +1017,11 @@ namespace SHADE return worldRenderGraph->GetNode(G_BUFFER_RENDER_GRAPH_NODE_NAME.data()); } + SHADE::SHFontLibrary const& SHGraphicsSystem::GetFontLibrary(void) const noexcept + { + return fontLibrary; + } + Handle SHGraphicsSystem::createDebugDrawPipeline(Handle renderPass, Handle subpass) { auto pipelineLayout = resourceManager.Create diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index a5c39831..d72cb8c8 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -367,6 +367,7 @@ namespace SHADE Handle GetDebugDrawPipeline(void) const noexcept { return debugDrawPipeline; } Handle GetDebugDrawDepthPipeline(void) const noexcept { return debugDrawDepthPipeline; } uint32_t GetCurrentFrameIndex(void) const noexcept { return renderContext.GetCurrentFrame(); } + SHFontLibrary const& GetFontLibrary (void) const noexcept; /*-----------------------------------------------------------------------------*/ /* Getters */ @@ -437,6 +438,8 @@ namespace SHADE Handle textVS; Handle textFS; + // Fonts + Handle testFont; // Built-In Materials Handle defaultMaterial; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp index 63d374eb..55b52645 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp @@ -101,6 +101,11 @@ namespace SHADE //cpuCameraData.viewProjectionMatrix = camera->GetViewProjectionMatrix(); cameraBuffer->WriteToMemory(&cpuCameraData, sizeof(SHShaderCameraData), 0, cameraDataAlignedSize * frameIndex); + BindDescSet(cmdBuffer, frameIndex); + } + + void SHRenderer::BindDescSet(Handle cmdBuffer, uint32_t frameIndex) noexcept + { std::array dynamicOffsets{ frameIndex * cameraDataAlignedSize }; cmdBuffer->BindDescriptorSet(cameraDescriptorSet, SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, std::span{ dynamicOffsets.data(), 1 }); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h index 140cf53b..c6146a56 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h @@ -63,6 +63,7 @@ namespace SHADE /***********************************************************************************/ class SHRenderer { + public: /*-----------------------------------------------------------------------------*/ /* Constructor/Destructors */ @@ -82,6 +83,7 @@ namespace SHADE void Draw(uint32_t frameIndex, Handle descPool) noexcept; void UpdateDataAndBind(Handle cmdBuffer, uint32_t frameIndex) noexcept; void UpdateDataAndBind(Handle cmdBuffer, uint32_t frameIndex, SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept; + void BindDescSet (Handle cmdBuffer, uint32_t frameIndex) noexcept; void UpdateCameraDataToBuffer (void) noexcept; void SetViewProjectionMatrix (SHMatrix const& viewMatrix, SHMatrix const& projMatrix) noexcept; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 2949ad43..3d5a5773 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -423,9 +423,8 @@ namespace SHADE /*! \brief - Loops through every single light component and checks for dirty light - data. If light data is dirty, rewrite to the CPU container. We also want - to bind the descriptor set for the light data. + Loops through every single light component and writes light data to CPU + then GPU. */ /***************************************************************************/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/PostProcessing/SHSSAO.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/PostProcessing/SHSSAO.cpp index 2bf32fd8..db5b08c3 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/PostProcessing/SHSSAO.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/PostProcessing/SHSSAO.cpp @@ -76,7 +76,7 @@ namespace SHADE }; uint32_t mipOffset = 0; - rotationVectorsImage = logicalDevice->CreateImage(imageDetails, reinterpret_cast( rotationVectors.data()), static_cast(sizeof(rotationVectors)), {&mipOffset, 1}, VMA_MEMORY_USAGE_AUTO, {}); + rotationVectorsImage = logicalDevice->CreateImage(imageDetails, reinterpret_cast(rotationVectors.data()), static_cast(sizeof(rotationVectors)), { mipOffset }, VMA_MEMORY_USAGE_AUTO, {}); vk::ImageMemoryBarrier transferBarrier{}; rotationVectorsImage->PrepareImageTransitionInfo(vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal, transferBarrier); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp index 977a0bad..7d8e2b44 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp @@ -4,6 +4,7 @@ #include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/Descriptors/SHVkDescriptorSetGroup.h" #include "Graphics/Buffers/SHVkBuffer.h" +#include "Graphics/Images/SHVkSampler.h" namespace SHADE { @@ -42,16 +43,18 @@ namespace SHADE .depth = 1, .levels = 1, .arrayLayers = 1, - .imageFormat = vk::Format::eR32G32B32Sfloat, + .imageFormat = vk::Format::eR8G8B8A8Unorm, + //.imageFormat = vk::Format::eR32Sfloat, + //.imageFormat = vk::Format::eR32G32B32Sfloat, .usageFlags = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst, .createFlags = {} }; - uint32_t bytesRequired = fontAsset.bitmapWidth * fontAsset.bitmapHeight * SHFontAsset::BYTES_PER_CHANNEL * SHFontAsset::NUM_CHANNELS; + uint32_t bytesRequired = asset.bitmapData.size(); uint32_t mipOffset = 0; // Create the image - bitmapDataImage = logicalDevice->CreateImage(imageParams, fontAsset.bitmapData.data(), bytesRequired, { &mipOffset, 1 }, VmaMemoryUsage::VMA_MEMORY_USAGE_AUTO, {}); + bitmapDataImage = logicalDevice->CreateImage(imageParams, fontAsset.bitmapData.data(), bytesRequired, { mipOffset }, VmaMemoryUsage::VMA_MEMORY_USAGE_AUTO, {}); // Amount of data required to hold matrices for all glyphs uint32_t glyphDataSize = fontAsset.glyphTransformations.size() * sizeof (SHMatrix); @@ -63,9 +66,7 @@ namespace SHADE // allocate GPU buffer for matrices matrixDataBuffer = logicalDevice->CreateBuffer(glyphDataSize, fontAsset.glyphTransformations.data(), glyphDataSize, vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eStorageBuffer, VMA_MEMORY_USAGE_AUTO, {}); - //// Prepare pre and post transfer barrier - //bitmapDataImage->PrepareImageTransitionInfo(vk::ImageLayout::eUndefined, vk::ImageLayout::eTransferDstOptimal, preTransferBarrier); - //bitmapDataImage->PrepareImageTransitionInfo(vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal, postTransferBarrier); + sampler = logicalDevice->CreateSampler(SHVkSamplerParams{}); } @@ -95,7 +96,7 @@ namespace SHADE matrixDataBuffer->TransferToDeviceResource(commandBuffer); } - void SHFont::DoPostTransfer(Handle descPool) noexcept + void SHFont::DoPostTransfer(Handle descPool, Handle layout) noexcept { /*-----------------------------------------------------------------------*/ /* CREATE IMAGE VIEW */ @@ -104,7 +105,7 @@ namespace SHADE SHImageViewDetails viewDetails { .viewType = vk::ImageViewType::e2D, - .format = vk::Format::eR32G32B32Sfloat, + .format = bitmapDataImage->GetImageFormat(), .imageAspectFlags = vk::ImageAspectFlagBits::eColor, .baseMipLevel = 0, .mipLevelCount = 1, @@ -116,14 +117,11 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* DESCRIPTORS */ /*-----------------------------------------------------------------------*/ - // Font data desc set layout - auto fontDataLayout = SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA]; - // allocate desc set for the bitmap and matrix data - descSet = descPool->Allocate({ fontDataLayout }, { 1, 1 }); + descSet = descPool->Allocate({ layout }, { 1 }); - //auto viewLayoutSampler = std::make_tuple() - descSet->ModifyWriteDescImage(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA, {}); + auto viewLayoutSampler = std::make_tuple(bitmapDataImageView, sampler, vk::ImageLayout::eShaderReadOnlyOptimal); + descSet->ModifyWriteDescImage(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA, {&viewLayoutSampler, 1}); descSet->ModifyWriteDescBuffer(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA, { &matrixDataBuffer, 1 }, 0, fontAsset.glyphTransformations.size() * sizeof(SHMatrix)); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.h index c3aba053..1439281a 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.h @@ -9,12 +9,14 @@ namespace SHADE class SHVkLogicalDevice; class SHVkDescriptorPool; class SHVkDescriptorSetGroup; + class SHVkDescriptorSetLayout; class SHVkCommandBuffer; class SHVkCommandPool; class SHVkImage; class SHVkImageView; class SHVkBuffer; class SHVkQueue; + class SHVkSampler; class SHFont { @@ -37,6 +39,8 @@ namespace SHADE //! Descriptor set required to store the bitmap AND matrix data for the UV and quad transformation Handle descSet; + Handle sampler; + //! Used for getting the correct indices into the matrix data buffer std::unordered_map unicodeIndexing; @@ -52,7 +56,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ SHFont (Handle inLogicalDeviceHdl, SHFontAsset const& asset) noexcept; void TransferToGPU (Handle commandBuffer) noexcept; - void DoPostTransfer (Handle descPool) noexcept; + void DoPostTransfer (Handle descPool, Handle layout) noexcept; /*-----------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontLibrary.cpp index 1316851c..3ae5c2ec 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontLibrary.cpp @@ -50,11 +50,11 @@ namespace SHADE */ /***************************************************************************/ - void SHFontLibrary::BuildFonts(Handle logicalDevice, Handle queue, Handle cmdPool, Handle descPool, SHResourceHub& resourceHub) noexcept + void SHFontLibrary::BuildFonts(Handle logicalDevice, Handle queue, Handle cmdPool, Handle descPool, Handle layout, SHResourceHub& resourceHub) noexcept { // create fence to wait on after transfer Handle finishCopyFence = resourceHub.Create(logicalDevice); - + finishCopyFence->Reset(); // allocate new command buffer Handle transferCommandBuffer = cmdPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); @@ -84,10 +84,10 @@ namespace SHADE // Prepare image views and desc sets for (auto& font : unpreparedFonts) - font->DoPostTransfer(descPool); + font->DoPostTransfer(descPool, layout); // Free the command buffer and fence - resourceHub.Free(transferCommandBuffer); + transferCommandBuffer.Free(); resourceHub.Free(finishCopyFence); // Once unprepared fonts are now ready for use, push them into container @@ -100,4 +100,9 @@ namespace SHADE postTransferBarriers.clear(); } + std::vector> const& SHFontLibrary::GetFonts(void) const noexcept + { + return fonts; + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontLibrary.h index cfb1cd63..a3762e6b 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontLibrary.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontLibrary.h @@ -11,8 +11,9 @@ namespace SHADE class SHVkCommandPool; class SHVkCommandBuffer; class SHVkQueue; + class SHVkDescriptorSetLayout; - class SHFontLibrary + class SH_API SHFontLibrary { private: //! Handles to all the fonts usable in SHTextRendererComponents @@ -29,6 +30,7 @@ namespace SHADE public: Handle AddFont (Handle logicalDevice, SHResourceHub& resourceHub, SHFontAsset const& asset) noexcept; - void BuildFonts (Handle logicalDevice, Handle queue, Handle cmdPool, Handle descPool, SHResourceHub& resourceHub) noexcept; + void BuildFonts (Handle logicalDevice, Handle queue, Handle cmdPool, Handle descPool, Handle layout, SHResourceHub& resourceHub) noexcept; + std::vector> const& GetFonts (void) const noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.cpp index e392e79c..ac1dd73f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.cpp @@ -24,13 +24,18 @@ namespace SHADE /***************************************************************************/ void SHTextRendererComponent::OnCreate(void) { - text = ""; + text = "Text"; requiresRecompute = true; // Default white color. color = SHColour::WHITE; } + void SHTextRendererComponent::OnDestroy(void) + { + + } + /***************************************************************************/ /*! @@ -50,6 +55,11 @@ namespace SHADE MakeDirty(); } + void SHTextRendererComponent::SetFont(Handle font) noexcept + { + fontHandle = font; + } + /***************************************************************************/ /*! diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h index 769665bc..242253ec 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h @@ -12,7 +12,7 @@ namespace SHADE class SHVkDescriptorSetGroup; class SHVkBuffer; - class SHTextRendererComponent final : public SHComponent + class SH_API SHTextRendererComponent final : public SHComponent { public: static constexpr uint32_t MAX_CHARACTERS = 500; @@ -44,11 +44,14 @@ namespace SHADE public: void OnCreate(void) override final; + void OnDestroy(void) override final; /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ void SetText (std::string_view newText) noexcept; + void SetFont (Handle font) noexcept; + std::string const& GetText (void) const noexcept; friend class SHTextRenderingSubSystem; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp index c7b8e0c9..ed7314ba 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp @@ -8,6 +8,9 @@ #include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/Pipeline/SHVkPipeline.h" +#include "Graphics/SHVkUtil.h" +#include "Graphics/RenderGraph/SHSubpass.h" +#include "Math/Transform/SHTransformComponent.h" namespace SHADE { @@ -80,16 +83,20 @@ namespace SHADE //} } - textComp.indexingDataBuffer->WriteToMemory(indexingData.data(), indexingData.size() * sizeof (SHTextRendererComponent::TextIndexingType),0, 0); - textComp.charPositionDataBuffer->WriteToMemory(charPositionData.data(), charPositionData.size() * sizeof (SHVec4), 0, 0); + textComp.indexingDataBuffer->WriteToMemory(indexingData.data(), static_cast(indexingData.size()) * sizeof (SHTextRendererComponent::TextIndexingType),0, 0); + textComp.charPositionDataBuffer->WriteToMemory(charPositionData.data(), static_cast(charPositionData.size()) * sizeof (SHVec4), 0, 0); indexingData.clear(); charPositionData.clear(); } - void SHTextRenderingSubSystem::Init(Handle device, Handle compatibleRenderpass, Handle subpass, Handle descPool, Handle textVS, Handle textFS) noexcept + void SHTextRenderingSubSystem::Init(Handle device, Handle compatibleRenderpass, Handle subpass, Handle descPool, Handle textVS, Handle textFS, std::function, uint32_t)> const& bindFunction) noexcept { + SHComponentManager::CreateComponentSparseSet(); + + cameraDescSetBind = bindFunction; + logicalDevice = device; // prepare pipeline layout params @@ -114,8 +121,53 @@ namespace SHADE // Set vertex state for new pipeline pipeline->GetPipelineState().SetVertexInputState(vertexInputState); + SHColorBlendState colorBlendState{}; + colorBlendState.logic_op_enable = VK_FALSE; + colorBlendState.logic_op = vk::LogicOp::eCopy; + + auto const& subpassColorReferences = subpass->GetColorAttachmentReferences(); + colorBlendState.attachments.reserve(static_cast(subpassColorReferences.size())); + + for (auto& att : subpassColorReferences) + { + colorBlendState.attachments.push_back(vk::PipelineColorBlendAttachmentState + { + .blendEnable = SHVkUtil::IsBlendCompatible(subpass->GetFormatFromAttachmentReference(att.attachment)) ? true : false, + .srcColorBlendFactor = vk::BlendFactor::eSrcAlpha, + .dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha, + .colorBlendOp = vk::BlendOp::eAdd, + .srcAlphaBlendFactor = vk::BlendFactor::eOne, + .dstAlphaBlendFactor = vk::BlendFactor::eZero, + .alphaBlendOp = vk::BlendOp::eAdd, + .colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA, + } + ); + } + + pipeline->GetPipelineState().SetColorBlenState(colorBlendState); + + // Construct pipeline pipeline->ConstructPipeline(); + + SHVkDescriptorSetLayout::Binding fontBitmapBinding + { + .Type = vk::DescriptorType::eCombinedImageSampler, + .Stage = vk::ShaderStageFlagBits::eFragment, + .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA, + .DescriptorCount = 1, + }; + + SHVkDescriptorSetLayout::Binding fontMatrixBinding + { + .Type = vk::DescriptorType::eStorageBuffer, + .Stage = vk::ShaderStageFlagBits::eVertex, + .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA, + .DescriptorCount = 1, + }; + + fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, { fontBitmapBinding, fontMatrixBinding }); + } void SHTextRenderingSubSystem::Run(uint32_t frameIndex) noexcept @@ -130,17 +182,18 @@ namespace SHADE RecomputePositions(comp); comp.Clean(); } - } } - void SHTextRenderingSubSystem::Render(Handle cmdBuffer) noexcept + void SHTextRenderingSubSystem::Render(Handle cmdBuffer, uint32_t frameIndex) noexcept { auto& textRendererComps = SHComponentManager::GetDense(); for (auto& comp : textRendererComps) { + auto* transform = SHComponentManager::GetComponent(comp.GetEID()); + Handle fontHandle = comp.fontHandle; - if (fontHandle) + if (fontHandle && transform) { // bind the pipeline cmdBuffer->BindPipeline(pipeline); @@ -149,10 +202,20 @@ namespace SHADE cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::CALCULATED_GLYPH_POSITION, comp.charPositionDataBuffer, 0); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::GLYPH_INDEX, comp.indexingDataBuffer, 0); + cameraDescSetBind(cmdBuffer, frameIndex); + // bind descriptors for font (matrices) 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 + cmdBuffer->DrawArrays(4, comp.text.size(), 0, 0); + //glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, static_cast(textComp.lastRenderedCharacterIndex) + 1); } @@ -164,4 +227,9 @@ namespace SHADE } + Handle SHTextRenderingSubSystem::GetFontDataDescSetLayout(void) const noexcept + { + return fontDataDescSetLayout; + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h index 52c6a497..d569ca91 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h @@ -2,6 +2,8 @@ #include "Resource/SHHandle.h" #include "Graphics/Pipeline/SHPipelineState.h" +#include "Math/SHMatrix.h" +#include "Math/Vector/SHVec3.h" namespace SHADE { @@ -22,6 +24,12 @@ namespace SHADE class SHTextRenderingSubSystem { private: + struct ShaderPushConstantData + { + SHMatrix worldTransform; + uint32_t eid; + SHVec3 textColor; + }; //! Logical device for creation and destruction Handle logicalDevice; @@ -32,15 +40,26 @@ namespace SHADE //! Pipeline layout for the pipeline Handle pipelineLayout; + //! Descriptor set for font data access in shaders + Handle fontDataDescSetLayout; + + //! Super temporary. Global descriptor set needs to be revamped along with + //! entire graphics system. + std::function, uint32_t)> cameraDescSetBind; + private: void RecomputePositions(SHTextRendererComponent& textComp) noexcept; public: - void Init(Handle device, Handle compatibleRenderpass, Handle subpass, Handle descPool, Handle textVS, Handle textFS) noexcept; + void Init(Handle device, Handle compatibleRenderpass, Handle subpass, Handle descPool, Handle textVS, Handle textFS, std::function, uint32_t)> const& bindFunction) noexcept; void Run(uint32_t frameIndex) noexcept; - void Render (Handle cmdBuffer) noexcept; + + void Render (Handle cmdBuffer, uint32_t frameIndex) noexcept; void Exit(void) noexcept; + Handle GetFontDataDescSetLayout (void) const noexcept; + + }; } diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp index 589e66d2..0333aa09 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp +++ b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp @@ -79,9 +79,9 @@ namespace SHADE 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 diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index 54138d48..121d78dd 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -211,7 +211,7 @@ namespace SHADE // Draw all the exterior draw calls for (auto& drawCall : exteriorDrawCalls) { - drawCall(commandBuffer); + drawCall(commandBuffer, frameIndex); } commandBuffer->EndLabeledSegment(); } @@ -221,7 +221,7 @@ namespace SHADE UpdateWriteDescriptors(); } - void SHSubpass::AddExteriorDrawCalls(std::function&)> const& newDrawCall) noexcept + void SHSubpass::AddExteriorDrawCalls(std::function&, uint32_t)> const& newDrawCall) noexcept { exteriorDrawCalls.push_back(newDrawCall); } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h index 9b4d7bf9..c28ff919 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h @@ -76,7 +76,7 @@ namespace SHADE //! 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 //! COMPLEX. - std::vector&)>> exteriorDrawCalls; + std::vector&, uint32_t)>> exteriorDrawCalls; /// For identifying subpasses std::string name; @@ -99,7 +99,7 @@ namespace SHADE void AddGeneralDepthOutput(std::string resourceToReference) noexcept; void AddInput(std::string resourceToReference) noexcept; void AddGeneralInput (std::string resourceToReference) noexcept; - void AddExteriorDrawCalls(std::function&)> const& newDrawCall) noexcept; + void AddExteriorDrawCalls(std::function&, uint32_t)> const& newDrawCall) noexcept; // Runtime functions void Execute(Handle& commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; diff --git a/SHADE_Engine/src/Resource/SHResourceManager.hpp b/SHADE_Engine/src/Resource/SHResourceManager.hpp index 4472fd46..83848958 100644 --- a/SHADE_Engine/src/Resource/SHResourceManager.hpp +++ b/SHADE_Engine/src/Resource/SHResourceManager.hpp @@ -316,10 +316,10 @@ namespace SHADE return matHandle; } - else if constexpr (std::is_same_v) + else if constexpr (std::is_same_v) { loadedAssetData.emplace_back(assetId); - textureChanged = true; + fontChanged = true; return gfxSystem->AddFont(assetData); } diff --git a/SHADE_Engine/src/Serialization/SHSerialization.cpp b/SHADE_Engine/src/Serialization/SHSerialization.cpp index 8e4e350c..6933fbb5 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.cpp +++ b/SHADE_Engine/src/Serialization/SHSerialization.cpp @@ -179,7 +179,9 @@ namespace SHADE { if (ComponentType* component = SHComponentManager::GetComponent_s(eid)) { - componentsNode[rttr::type::get().get_name().data()] = YAML::convert::encode(*component); + auto componentNode = YAML::convert::encode(*component); + componentNode[IsActive.data()] = component->isActive; + componentsNode[rttr::type::get().get_name().data()] = componentNode; } } diff --git a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp index 84e99345..b560acae 100644 --- a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp +++ b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp @@ -14,6 +14,8 @@ namespace SHADE { + static constexpr std::string_view IsActive = "IsActive"; + using AssetQueue = std::unordered_map; struct SHSerializationHelper { @@ -118,9 +120,9 @@ namespace SHADE YAML::Node node{}; if (!component) return node; - auto componentType = rttr::type::get(); node = RTTRToNode(*component); + node[IsActive.data()] = component->isActive; return node; } @@ -198,6 +200,9 @@ namespace SHADE auto componentNode = componentsNode[rttrType.get_name().data()]; if (!componentNode.IsDefined()) return; + if(componentNode[IsActive.data()].IsDefined()) + component->isActive = componentNode[IsActive.data()].as(); + auto properties = rttrType.get_properties(); for (auto const& prop : properties) { @@ -227,8 +232,10 @@ namespace SHADE auto component = SHComponentManager::GetComponent_s(eid); if (componentsNode.IsNull() && !component) return; - - YAML::convert::decode(GetComponentNode(componentsNode, eid), *component); + auto componentNode = GetComponentNode(componentsNode, eid); + if (componentNode[IsActive.data()].IsDefined()) + component->isActive = componentNode[IsActive.data()].as(); + YAML::convert::decode(componentNode, *component); } template , bool> = true> diff --git a/SHADE_Engine/src/Tools/Logger/SHLog.cpp b/SHADE_Engine/src/Tools/Logger/SHLog.cpp index 30a79338..139a731e 100644 --- a/SHADE_Engine/src/Tools/Logger/SHLog.cpp +++ b/SHADE_Engine/src/Tools/Logger/SHLog.cpp @@ -44,13 +44,6 @@ namespace SHADE SHLOG_FLOOR() } -#ifdef _DEBUG - void SHLog::Trace(const std::string& msg) noexcept - { - SHLOG_TRACE(msg) - } -#endif - void SHLog_Info(const char* msg) noexcept { SHLOG_INFO(msg) diff --git a/SHADE_Engine/src/Tools/Logger/SHLogger.cpp b/SHADE_Engine/src/Tools/Logger/SHLogger.cpp index 9c1e76fc..72791eb1 100644 --- a/SHADE_Engine/src/Tools/Logger/SHLogger.cpp +++ b/SHADE_Engine/src/Tools/Logger/SHLogger.cpp @@ -323,34 +323,6 @@ namespace SHADE SHLOG_FLOOR() } - #ifdef _DEBUG - void SHLogger::LogTrace(const std::string& msg) noexcept - { - SHLOG_TRACE(msg) - } - - void SHLogger::LogVerboseTrace(const std::string& msg, const std::source_location& src) noexcept - { - const bool SHOW_SRC_FILE = configFlags & (1U << 3); - const bool SHOW_SRC_LINE = configFlags & (1U << 4); - - std::stringstream ss; - ss << "["; - if (SHOW_SRC_FILE) - { - ss << std::filesystem::path(src.file_name()).filename().string() << ", "; - if (SHOW_SRC_LINE) - { - ss << src.line() << ", "; - } - } - - ss << src.function_name() << "] " << msg; - - SHLOG_TRACE(ss.str()) - } - #endif - /*-----------------------------------------------------------------------------------*/ /* Private Function Member Definitions */ /*-----------------------------------------------------------------------------------*/