Renamed SHTextRenderer and to SHTextRenderable and added C# interface #239

Merged
Pycorax merged 4 commits from SP3-6-c-scripting into main 2022-11-22 01:19:52 +08:00
9 changed files with 36 additions and 36 deletions
Showing only changes of commit 4172362790 - Show all commits

View File

@ -13,7 +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 "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h"
#include "Assets/SHAssetManager.h" #include "Assets/SHAssetManager.h"
#include "Camera/SHCameraComponent.h" #include "Camera/SHCameraComponent.h"

View File

@ -497,11 +497,11 @@ namespace SHADE
} }
template<> template<>
static void DrawComponent(SHTextRendererComponent* component) static void DrawComponent(SHTextRenderableComponent* component)
{ {
if (!component) if (!component)
return; return;
ImGui::PushID(SHFamilyID<SHComponent>::GetID<SHTextRendererComponent>()); ImGui::PushID(SHFamilyID<SHComponent>::GetID<SHTextRenderableComponent>());
const auto componentType = rttr::type::get(*component); const auto componentType = rttr::type::get(*component);
SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }, "Is Component Active"); SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }, "Is Component Active");
ImGui::SameLine(); ImGui::SameLine();

View File

@ -22,7 +22,7 @@
#include "UI/SHCanvasComponent.h" #include "UI/SHCanvasComponent.h"
#include "SHEditorComponentView.h" #include "SHEditorComponentView.h"
#include "AudioSystem/SHAudioListenerComponent.h" #include "AudioSystem/SHAudioListenerComponent.h"
#include "Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h" #include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h"
namespace SHADE namespace SHADE
{ {
@ -145,7 +145,7 @@ namespace SHADE
{ {
DrawComponent(uiComponent); DrawComponent(uiComponent);
} }
if (auto textRendererComponent = SHComponentManager::GetComponent_s<SHTextRendererComponent>(eid)) if (auto textRendererComponent = SHComponentManager::GetComponent_s<SHTextRenderableComponent>(eid))
{ {
DrawComponent(textRendererComponent); DrawComponent(textRendererComponent);
} }
@ -167,7 +167,7 @@ namespace SHADE
DrawAddComponentWithEnforcedComponentButton<SHRenderable, SHTransformComponent>(eid); DrawAddComponentWithEnforcedComponentButton<SHRenderable, SHTransformComponent>(eid);
DrawAddComponentWithEnforcedComponentButton<SHRigidBodyComponent, SHTransformComponent>(eid); DrawAddComponentWithEnforcedComponentButton<SHRigidBodyComponent, SHTransformComponent>(eid);
DrawAddComponentWithEnforcedComponentButton<SHColliderComponent, SHTransformComponent>(eid); DrawAddComponentWithEnforcedComponentButton<SHColliderComponent, SHTransformComponent>(eid);
DrawAddComponentWithEnforcedComponentButton<SHTextRendererComponent, SHTransformComponent>(eid); DrawAddComponentWithEnforcedComponentButton<SHTextRenderableComponent, SHTransformComponent>(eid);
ImGui::EndMenu(); ImGui::EndMenu();

View File

@ -1,15 +1,15 @@
#include "SHpch.h" #include "SHpch.h"
#include "SHTextRendererComponent.h" #include "SHTextRenderableComponent.h"
namespace SHADE namespace SHADE
{ {
void SHTextRendererComponent::MakeDirty(void) noexcept void SHTextRenderableComponent::MakeDirty(void) noexcept
{ {
requiresRecompute = true; requiresRecompute = true;
} }
void SHTextRendererComponent::Clean(void) noexcept void SHTextRenderableComponent::Clean(void) noexcept
{ {
requiresRecompute = false; requiresRecompute = false;
} }
@ -22,7 +22,7 @@ namespace SHADE
*/ */
/***************************************************************************/ /***************************************************************************/
void SHTextRendererComponent::OnCreate(void) void SHTextRenderableComponent::OnCreate(void)
{ {
text = "My name is Brandon."; text = "My name is Brandon.";
requiresRecompute = true; requiresRecompute = true;
@ -31,7 +31,7 @@ namespace SHADE
color = SHColour::WHITE; color = SHColour::WHITE;
} }
void SHTextRendererComponent::OnDestroy(void) void SHTextRenderableComponent::OnDestroy(void)
{ {
} }
@ -49,13 +49,13 @@ namespace SHADE
*/ */
/***************************************************************************/ /***************************************************************************/
void SHTextRendererComponent::SetText(std::string_view newText) noexcept void SHTextRenderableComponent::SetText(std::string_view newText) noexcept
{ {
text = newText; text = newText;
MakeDirty(); MakeDirty();
} }
void SHTextRendererComponent::SetFont(Handle<SHFont> font) noexcept void SHTextRenderableComponent::SetFont(Handle<SHFont> font) noexcept
{ {
fontHandle = font; fontHandle = font;
MakeDirty(); MakeDirty();
@ -72,12 +72,12 @@ namespace SHADE
*/ */
/***************************************************************************/ /***************************************************************************/
std::string const& SHTextRendererComponent::GetText(void) const noexcept std::string const& SHTextRenderableComponent::GetText(void) const noexcept
{ {
return text; return text;
} }
Handle<SHFont> SHTextRendererComponent::GetFont(void) const noexcept Handle<SHFont> SHTextRenderableComponent::GetFont(void) const noexcept
{ {
return fontHandle; return fontHandle;
} }
@ -90,6 +90,6 @@ namespace rttr
{ {
using namespace SHADE; using namespace SHADE;
registration::class_<SHTextRendererComponent>("Text Renderer Component"); registration::class_<SHTextRenderableComponent>("Text Renderer Component");
}; };
} }

View File

@ -13,7 +13,7 @@ namespace SHADE
class SHVkDescriptorSetGroup; class SHVkDescriptorSetGroup;
class SHVkBuffer; class SHVkBuffer;
class SH_API SHTextRendererComponent final : public SHComponent class SH_API SHTextRenderableComponent final : public SHComponent
{ {
public: public:
static constexpr uint32_t MAX_CHARACTERS = 500; static constexpr uint32_t MAX_CHARACTERS = 500;

View File

@ -1,6 +1,6 @@
#include "SHpch.h" #include "SHpch.h"
#include "SHTextRenderingSubSystem.h" #include "SHTextRenderingSubSystem.h"
#include "Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h" #include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h"
#include "ECS_Base/Managers/SHComponentManager.h" #include "ECS_Base/Managers/SHComponentManager.h"
#include "Math/Vector/SHVec4.h" #include "Math/Vector/SHVec4.h"
#include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Devices/SHVkLogicalDevice.h"
@ -14,20 +14,20 @@
namespace SHADE namespace SHADE
{ {
void SHTextRenderingSubSystem::RecomputePositions(SHTextRendererComponent& textComp) noexcept void SHTextRenderingSubSystem::RecomputePositions(SHTextRenderableComponent& textComp) noexcept
{ {
if (textComp.text.empty() || !textComp.fontHandle) if (textComp.text.empty() || !textComp.fontHandle)
return; return;
// Create the buffer // Create the buffer
if (!textComp.indexingDataBuffer) if (!textComp.indexingDataBuffer)
textComp.indexingDataBuffer = logicalDevice->CreateBuffer(SHTextRendererComponent::MAX_CHARACTERS * sizeof(uint32_t), nullptr, SHTextRendererComponent::MAX_CHARACTERS * sizeof(uint32_t), vk::BufferUsageFlagBits::eVertexBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT); textComp.indexingDataBuffer = logicalDevice->CreateBuffer(SHTextRenderableComponent::MAX_CHARACTERS * sizeof(uint32_t), nullptr, SHTextRenderableComponent::MAX_CHARACTERS * sizeof(uint32_t), vk::BufferUsageFlagBits::eVertexBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT);
if (!textComp.charPositionDataBuffer) if (!textComp.charPositionDataBuffer)
textComp.charPositionDataBuffer = logicalDevice->CreateBuffer(SHTextRendererComponent::MAX_CHARACTERS * sizeof(SHVec4), nullptr, SHTextRendererComponent::MAX_CHARACTERS * sizeof(SHVec4), vk::BufferUsageFlagBits::eVertexBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT); textComp.charPositionDataBuffer = logicalDevice->CreateBuffer(SHTextRenderableComponent::MAX_CHARACTERS * sizeof(SHVec4), nullptr, SHTextRenderableComponent::MAX_CHARACTERS * sizeof(SHVec4), vk::BufferUsageFlagBits::eVertexBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT);
// For indexing font transformation in the shader // For indexing font transformation in the shader
std::vector <SHTextRendererComponent::TextIndexingType> indexingData; std::vector <SHTextRenderableComponent::TextIndexingType> indexingData;
// For placing glyphs correctly // For placing glyphs correctly
std::vector <SHVec4> charPositionData; std::vector <SHVec4> charPositionData;
@ -49,7 +49,7 @@ namespace SHADE
// for every character // for every character
for (uint32_t i = 0; i < numChars; ++i) for (uint32_t i = 0; i < numChars; ++i)
{ {
SHTextRendererComponent::TextIndexingType index = glyphTransformIndices.at(textComp.text[i]); SHTextRenderableComponent::TextIndexingType index = glyphTransformIndices.at(textComp.text[i]);
// Copy baseline // Copy baseline
SHVec4 characterPos = baselineOrigin; SHVec4 characterPos = baselineOrigin;
@ -83,7 +83,7 @@ namespace SHADE
//} //}
} }
textComp.indexingDataBuffer->WriteToMemory(indexingData.data(), static_cast<uint32_t>(indexingData.size()) * sizeof (SHTextRendererComponent::TextIndexingType),0, 0); textComp.indexingDataBuffer->WriteToMemory(indexingData.data(), static_cast<uint32_t>(indexingData.size()) * sizeof (SHTextRenderableComponent::TextIndexingType),0, 0);
textComp.charPositionDataBuffer->WriteToMemory(charPositionData.data(), static_cast<uint32_t>(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();
@ -93,7 +93,7 @@ namespace SHADE
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 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>(); SHComponentManager::CreateComponentSparseSet<SHTextRenderableComponent>();
cameraDescSetBind = bindFunction; cameraDescSetBind = bindFunction;
@ -179,7 +179,7 @@ namespace SHADE
void SHTextRenderingSubSystem::Run(uint32_t frameIndex) noexcept void SHTextRenderingSubSystem::Run(uint32_t frameIndex) noexcept
{ {
auto& textRendererComps = SHComponentManager::GetDense<SHTextRendererComponent>(); auto& textRendererComps = SHComponentManager::GetDense<SHTextRenderableComponent>();
for (auto& comp : textRendererComps) for (auto& comp : textRendererComps)
{ {
@ -194,7 +194,7 @@ namespace SHADE
void SHTextRenderingSubSystem::Render(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept void SHTextRenderingSubSystem::Render(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept
{ {
auto& textRendererComps = SHComponentManager::GetDense<SHTextRendererComponent>(); auto& textRendererComps = SHComponentManager::GetDense<SHTextRenderableComponent>();
for (auto& comp : textRendererComps) for (auto& comp : textRendererComps)
{ {
auto* transform = SHComponentManager::GetComponent<SHTransformComponent>(comp.GetEID()); auto* transform = SHComponentManager::GetComponent<SHTransformComponent>(comp.GetEID());

View File

@ -14,7 +14,7 @@ namespace SHADE
class SHVkBuffer; class SHVkBuffer;
class SHLightComponent; class SHLightComponent;
class SHVkCommandBuffer; class SHVkCommandBuffer;
class SHTextRendererComponent; class SHTextRenderableComponent;
class SHVkPipeline; class SHVkPipeline;
class SHVkPipelineLayout; class SHVkPipelineLayout;
class SHVkRenderpass; class SHVkRenderpass;
@ -48,7 +48,7 @@ namespace SHADE
std::function<void(Handle<SHVkCommandBuffer>, uint32_t)> cameraDescSetBind; std::function<void(Handle<SHVkCommandBuffer>, uint32_t)> cameraDescSetBind;
private: private:
void RecomputePositions(SHTextRendererComponent& textComp) noexcept; void RecomputePositions(SHTextRenderableComponent& textComp) noexcept;
public: public:
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 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;

View File

@ -211,7 +211,7 @@ namespace SHADE
AddComponentToComponentNode<SHLightComponent>(components, eid); AddComponentToComponentNode<SHLightComponent>(components, eid);
AddComponentToComponentNode<SHRigidBodyComponent>(components, eid); AddComponentToComponentNode<SHRigidBodyComponent>(components, eid);
AddConvComponentToComponentNode<SHColliderComponent>(components, eid); AddConvComponentToComponentNode<SHColliderComponent>(components, eid);
AddConvComponentToComponentNode<SHTextRendererComponent>(components, eid); AddConvComponentToComponentNode<SHTextRenderableComponent>(components, eid);
node[ComponentsNode] = components; node[ComponentsNode] = components;
@ -263,7 +263,7 @@ namespace SHADE
AddComponentID<SHRigidBodyComponent>(componentIDList, componentsNode); AddComponentID<SHRigidBodyComponent>(componentIDList, componentsNode);
AddComponentID<SHLightComponent>(componentIDList, componentsNode); AddComponentID<SHLightComponent>(componentIDList, componentsNode);
AddComponentID<SHColliderComponent>(componentIDList, componentsNode); AddComponentID<SHColliderComponent>(componentIDList, componentsNode);
AddComponentID<SHTextRendererComponent>(componentIDList, componentsNode); AddComponentID<SHTextRenderableComponent>(componentIDList, componentsNode);
return componentIDList; return componentIDList;
} }
@ -340,7 +340,7 @@ namespace SHADE
SHSerializationHelper::InitializeComponentFromNode<SHRigidBodyComponent>(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode<SHRigidBodyComponent>(componentsNode, eid);
SHSerializationHelper::ConvertNodeToComponent<SHRenderable>(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent<SHRenderable>(componentsNode, eid);
SHSerializationHelper::ConvertNodeToComponent<SHColliderComponent>(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent<SHColliderComponent>(componentsNode, eid);
SHSerializationHelper::ConvertNodeToComponent<SHTextRendererComponent>(componentsNode, eid); SHSerializationHelper::ConvertNodeToComponent<SHTextRenderableComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHLightComponent>(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode<SHLightComponent>(componentsNode, eid);
} }
} }

View File

@ -12,7 +12,7 @@
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h" #include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
#include "SHSerializationTools.h" #include "SHSerializationTools.h"
#include "Physics/Interface/SHColliderComponent.h" #include "Physics/Interface/SHColliderComponent.h"
#include "Graphics/MiddleEnd/TextRendering/SHTextRendererComponent.h" #include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h"
#include "Graphics/MiddleEnd/TextRendering/SHFont.h" #include "Graphics/MiddleEnd/TextRendering/SHFont.h"
namespace YAML namespace YAML
@ -327,12 +327,12 @@ namespace YAML
}; };
template<> template<>
struct convert<SHTextRendererComponent> struct convert<SHTextRenderableComponent>
{ {
static constexpr std::string_view TEXT_YAML_TAG = "Text"; static constexpr std::string_view TEXT_YAML_TAG = "Text";
static constexpr std::string_view FONT_YAML_TAG = "Font"; static constexpr std::string_view FONT_YAML_TAG = "Font";
static YAML::Node encode(SHTextRendererComponent const& rhs) static YAML::Node encode(SHTextRenderableComponent const& rhs)
{ {
YAML::Node node; YAML::Node node;
node[TEXT_YAML_TAG.data()] = rhs.GetText(); node[TEXT_YAML_TAG.data()] = rhs.GetText();
@ -347,7 +347,7 @@ namespace YAML
} }
return node; return node;
} }
static bool decode(YAML::Node const& node, SHTextRendererComponent& rhs) static bool decode(YAML::Node const& node, SHTextRenderableComponent& rhs)
{ {
if (node[TEXT_YAML_TAG.data()].IsDefined()) if (node[TEXT_YAML_TAG.data()].IsDefined())
{ {