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/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 5c7690c5..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()); @@ -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_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/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 f1161bab..18ba49d6 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -282,10 +282,12 @@ 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"); { // Dummy Node to transition scene render graph resource @@ -360,8 +362,8 @@ 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); SHFreetypeInstance::Init(); } @@ -855,7 +857,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 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 dbd0fa74..69d951e9 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,9 +43,9 @@ namespace SHADE .depth = 1, .levels = 1, .arrayLayers = 1, - //.imageFormat = vk::Format::eR8G8B8Snorm, + .imageFormat = vk::Format::eR8G8B8A8Snorm, //.imageFormat = vk::Format::eR32Sfloat, - .imageFormat = vk::Format::eR32G32B32Sfloat, + //.imageFormat = vk::Format::eR32G32B32Sfloat, .usageFlags = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst, .createFlags = {} }; @@ -53,7 +54,7 @@ namespace SHADE 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); @@ -65,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{}); } @@ -97,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 */ @@ -106,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, @@ -118,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..e9588d8e 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 diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontLibrary.h index cfb1cd63..ecd17fde 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontLibrary.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontLibrary.h @@ -11,6 +11,7 @@ namespace SHADE class SHVkCommandPool; class SHVkCommandBuffer; class SHVkQueue; + class SHVkDescriptorSetLayout; class SHFontLibrary { @@ -29,6 +30,6 @@ 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; }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp index c7b8e0c9..d9f0ffc7 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp @@ -8,6 +8,8 @@ #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" namespace SHADE { @@ -114,8 +116,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(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 @@ -164,4 +211,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..b0273a1a 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.h @@ -32,6 +32,9 @@ namespace SHADE //! Pipeline layout for the pipeline Handle pipelineLayout; + //! Descriptor set for font data access in shaders + Handle fontDataDescSetLayout; + private: void RecomputePositions(SHTextRendererComponent& textComp) noexcept; @@ -41,6 +44,8 @@ namespace SHADE void Render (Handle cmdBuffer) noexcept; void Exit(void) noexcept; + Handle GetFontDataDescSetLayout (void) const noexcept; + }; } diff --git a/SHADE_Engine/src/Resource/SHResourceManager.hpp b/SHADE_Engine/src/Resource/SHResourceManager.hpp index 2a78c7aa..83848958 100644 --- a/SHADE_Engine/src/Resource/SHResourceManager.hpp +++ b/SHADE_Engine/src/Resource/SHResourceManager.hpp @@ -319,7 +319,7 @@ namespace SHADE else if constexpr (std::is_same_v) { loadedAssetData.emplace_back(assetId); - textureChanged = true; + fontChanged = true; return gfxSystem->AddFont(assetData); }