diff --git a/Assets/Editor/Fonts/MaterialIcons-Regular.shfont b/Assets/Editor/Fonts/MaterialIcons-Regular.shfont new file mode 100644 index 00000000..496a7032 Binary files /dev/null and b/Assets/Editor/Fonts/MaterialIcons-Regular.shfont differ diff --git a/Assets/Editor/Fonts/Segoe UI.shfont b/Assets/Editor/Fonts/Segoe UI.shfont new file mode 100644 index 00000000..d4532e59 Binary files /dev/null and b/Assets/Editor/Fonts/Segoe UI.shfont differ diff --git a/Assets/Editor/Fonts/fa-solid-900.shfont b/Assets/Editor/Fonts/fa-solid-900.shfont new file mode 100644 index 00000000..71c2c4ac Binary files /dev/null and b/Assets/Editor/Fonts/fa-solid-900.shfont differ diff --git a/Assets/Fonts/SegoeUI.ttf b/Assets/Fonts/SegoeUI.ttf new file mode 100644 index 00000000..46b3b993 Binary files /dev/null and b/Assets/Fonts/SegoeUI.ttf differ diff --git a/Assets/Shaders/Text_VS.glsl b/Assets/Shaders/Text_VS.glsl index 369e185e..90760fe2 100644 --- a/Assets/Shaders/Text_VS.glsl +++ b/Assets/Shaders/Text_VS.glsl @@ -7,7 +7,6 @@ // vertex inputs layout(location = 0) in vec4 positionalOffset; layout(location = 1) in uint glyphIndex; -layout(location = 2) in uvec2 integerData; // between shader stages layout(location = 0) out struct @@ -37,6 +36,7 @@ layout(set = 2, binding = 0) uniform CameraData layout(std140, push_constant) uniform TestPushConstant { mat4 worldTransform; + uint eid; } testPushConstant; @@ -55,7 +55,7 @@ vec2 CreateQuad(in uint vertexID) void main() { // write EID data to FS - Out2.eid = integerData[0]; + Out2.eid = testPushConstats.eid; // local variable for font index uint fontIndex = glyphIndex; diff --git a/Dependencies.bat b/Dependencies.bat index 44185ff8..ba411815 100644 --- a/Dependencies.bat +++ b/Dependencies.bat @@ -6,7 +6,7 @@ echo --------------------------------------------------- echo "SHADE DEPENDENCIES (Default - All in 10 Seconds)" echo "A - All" echo "B - VMA" -echo "C - msdf" +echo "C - FontCompiler" echo "D - ModelCompiler" echo "E - spdlog" echo "F - reactphysics3d" @@ -28,7 +28,7 @@ set _e=%ERRORLEVEL% if %_e%==1 goto VMA if %_e%==2 goto VMA -if %_e%==3 goto MSDF +if %_e%==3 goto FontCompiler if %_e%==4 goto ModelCompiler if %_e%==5 goto spdlog if %_e%==6 goto reactphysics3d @@ -47,12 +47,13 @@ if %_e%==16 goto fmod echo -----------------------VMA---------------------------- rmdir "Dependencies/VMA" /S /Q git clone https://github.com/SHADE-DP/VulkanMemoryAllocator.git "Dependencies/VMA" -if %_e%==2 (goto :done) else (goto :MSDF) +if %_e%==2 (goto :done) else (goto :FontCompiler) -:MSDF -echo -----------------------MSDF---------------------------- -rmdir "Dependencies/msdf" /S /Q -git clone --recurse-submodules https://github.com/SHADE-DP/msdf-atlas-gen.git "Dependencies/msdf" +:FontCompiler +echo -----------------------FontCompiler---------------------------- +rmdir "Dependencies/FontCompiler" /S /Q +git clone https://github.com/SHADE-DP/FontCompiler.git "Dependencies/FontCompiler" +git clone --recurse-submodules https://github.com/SHADE-DP/msdf-atlas-gen "Dependencies/FontCompiler/Dependencies/msdf" if %_e%==3 (goto :done) else (goto :ModelCompiler) :ModelCompiler diff --git a/Dependencies.lua b/Dependencies.lua index 2e24222b..fe75c3f4 100644 --- a/Dependencies.lua +++ b/Dependencies.lua @@ -3,8 +3,9 @@ IncludeDir["ModelCompiler"] = "%{wks.location}\\Dependencies\\ModelCompiler" IncludeDir["imgui"] = "%{wks.location}\\Dependencies\\imgui" IncludeDir["imguizmo"] = "%{wks.location}\\Dependencies\\imguizmo" IncludeDir["imnodes"] = "%{wks.location}\\Dependencies\\imnodes" -IncludeDir["msdf_atlas_gen"] = "%{wks.location}\\Dependencies\\msdf" -IncludeDir["msdfgen"] = "%{wks.location}\\Dependencies\\msdf\\msdfgen" +IncludeDir["FontCompiler"] = "%{wks.location}\\Dependencies\\FontCompiler" +IncludeDir["msdf_atlas_gen"] = "%{wks.location}\\Dependencies\\FontCompiler\\Dependencies\\msdf" +IncludeDir["msdfgen"] = "%{wks.location}\\Dependencies\\FontCompiler\\Dependencies\\msdf\\msdfgen" IncludeDir["spdlog"] = "%{wks.location}\\Dependencies\\spdlog" IncludeDir["tracy"] = "%{wks.location}\\Dependencies\\tracy" IncludeDir["VMA"] = "%{wks.location}\\Dependencies\\VMA" diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index bf5b8d49..4cbffe91 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -146,6 +146,8 @@ namespace Sandbox SHFrameRateController::UpdateFRC(); + //std::system("FontCompiler.exe ../../Assets/Fonts/SegoeUI.ttf"); + // Link up SHDebugDraw SHDebugDraw::Init(SHSystemManager::GetSystem()); } diff --git a/SHADE_Engine/premake5.lua b/SHADE_Engine/premake5.lua index 42f95520..a7899b3c 100644 --- a/SHADE_Engine/premake5.lua +++ b/SHADE_Engine/premake5.lua @@ -118,6 +118,7 @@ project "SHADE_Engine" { "xcopy /r /y /q \"%{IncludeDir.ModelCompiler}\\bin\\Debug\\assimp-vc142-mtd.dll\" \"$(OutDir)\"", "xcopy /r /y /q \"%{IncludeDir.ModelCompiler}\\bin\\Debug\\ModelCompiler.exe\" \"$(OutDir)\"", + "xcopy /r /y /q \"%{IncludeDir.FontCompiler}\\bin\\Debug\\FontCompiler.exe\" \"$(OutDir)\"", "xcopy /r /y /q \"%{IncludeDir.fmod}\\lib\\fmodL.dll\" \"$(OutDir)\"", "xcopy /r /y /q \"%{IncludeDir.fmod}\\lib\\fmodstudioL.dll\" \"$(OutDir)\"" } @@ -127,6 +128,7 @@ project "SHADE_Engine" { "xcopy /r /y /q \"%{IncludeDir.ModelCompiler}\\bin\\Release\\assimp-vc142-mt.dll\" \"$(OutDir)\"", "xcopy /r /y /q \"%{IncludeDir.ModelCompiler}\\bin\\Release\\ModelCompiler.exe\" \"$(OutDir)\"", + "xcopy /r /y /q \"%{IncludeDir.FontCompiler}\\bin\\Release\\FontCompiler.exe\" \"$(OutDir)\"", "xcopy /r /y /q \"%{IncludeDir.fmod}\\lib\\fmod.dll\" \"$(OutDir)\"", "xcopy /r /y /q \"%{IncludeDir.fmod}\\lib\\fmodstudio.dll\" \"$(OutDir)\"" } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index fd8566d7..bd505524 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -203,6 +203,10 @@ namespace SHADE /***************************************************************************/ static constexpr uint32_t INTEGER_DATA = 5; + static constexpr uint32_t CALCULATED_GLYPH_POSITION = 0; + static constexpr uint32_t GLYPH_INDEX = 1; + + }; /*******************************************************************************/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp index 2812aef4..977a0bad 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.cpp @@ -154,4 +154,9 @@ namespace SHADE return matrixDataBuffer; } + Handle SHFont::GetDescriptorSet(void) const noexcept + { + return descSet; + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.h index d529dec2..c3aba053 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFont.h @@ -61,7 +61,8 @@ namespace SHADE std::unordered_map GetUnicodeIndexing (void) const noexcept; SHFontAsset const& GetFontAsset (void) const noexcept; Handle GetImage (void) const noexcept; - Handle GetMatrixBuffer (void) const noexcept; + Handle GetMatrixBuffer (void) const noexcept; + Handle GetDescriptorSet (void) const noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp index a7416544..c7b8e0c9 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp @@ -7,6 +7,7 @@ #include "Graphics/MiddleEnd/TextRendering/SHFont.h" #include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" +#include "Graphics/Pipeline/SHVkPipeline.h" namespace SHADE { @@ -102,6 +103,19 @@ namespace SHADE // Create pipeline pipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, compatibleRenderpass, subpass); + + // vertex input state of the pipeline + SHVertexInputState vertexInputState; + + // Configure vertex attributes + vertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_4D) }); // location = 0 (character position data) + vertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::UINT32_1D) }); // location = 1 (glyph index to index matrices) + + // Set vertex state for new pipeline + pipeline->GetPipelineState().SetVertexInputState(vertexInputState); + + // Construct pipeline + pipeline->ConstructPipeline(); } void SHTextRenderingSubSystem::Run(uint32_t frameIndex) noexcept @@ -120,19 +134,27 @@ namespace SHADE } } - void SHTextRenderingSubSystem::Render(void) noexcept + void SHTextRenderingSubSystem::Render(Handle cmdBuffer) noexcept { auto& textRendererComps = SHComponentManager::GetDense(); for (auto& comp : textRendererComps) { - // draw the component + Handle fontHandle = comp.fontHandle; + if (fontHandle) + { + // bind the pipeline + cmdBuffer->BindPipeline(pipeline); - // bind the pipeline - // bind the pipeline layout - // bind VBO (position and indices) - // bind descriptors for font (matrices) + // bind VBO (position and indices) + cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::CALCULATED_GLYPH_POSITION, comp.charPositionDataBuffer, 0); + cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::GLYPH_INDEX, comp.indexingDataBuffer, 0); - // call draw call + // bind descriptors for font (matrices) + cmdBuffer->BindDescriptorSet(fontHandle->GetDescriptorSet(), SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::FONT_DATA, {}); + + // call draw call + + } } } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h index 26db3046..52c6a497 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h @@ -1,6 +1,7 @@ #pragma once #include "Resource/SHHandle.h" +#include "Graphics/Pipeline/SHPipelineState.h" namespace SHADE { @@ -37,7 +38,7 @@ namespace SHADE public: void Init(Handle device, Handle compatibleRenderpass, Handle subpass, Handle descPool, Handle textVS, Handle textFS) noexcept; void Run(uint32_t frameIndex) noexcept; - void Render (void) noexcept; + void Render (Handle cmdBuffer) noexcept; void Exit(void) noexcept; diff --git a/premake5.lua b/premake5.lua index 2164d649..26f181b5 100644 --- a/premake5.lua +++ b/premake5.lua @@ -25,10 +25,11 @@ workspace "SHADE" include "SHADE_CSharp" group "Dependencies" - include "Dependencies/msdf" + include "Dependencies/FontCompiler/Dependencies/msdf" include "Dependencies/imgui" --include "Dependencies/tracy" include "Dependencies/yamlcpp" include "Dependencies/reactphysics3d" include "Dependencies/ModelCompiler" + include "Dependencies/FontCompiler" group ""