1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef TEXT_3D_ECS_TEXTSYSTEM_H
17 #define TEXT_3D_ECS_TEXTSYSTEM_H
18
19 #include <base/containers/unordered_map.h>
20 #include <core/ecs/entity.h>
21 #include <core/ecs/intf_system.h>
22 #include <core/namespace.h>
23 #include <font/namespace.h>
24 #include <render/resource_handle.h>
25 #include <text_3d/namespace.h>
26
27 CORE_BEGIN_NAMESPACE()
28 class IEcs;
29 CORE_END_NAMESPACE()
30
31 FONT_BEGIN_NAMESPACE()
32 class IFontManager;
33 FONT_END_NAMESPACE()
34
35 TEXT3D_BEGIN_NAMESPACE()
36 class IMeshComponentManager;
37 class IRenderHandleComponentManager;
38 class IRenderMeshComponentManager;
39 class ITextComponentManager;
40 struct TextComponent;
41
42 class TextSystem final : public CORE_NS::ISystem {
43 public:
44 static constexpr BASE_NS::Uid UID { "ba7602a6-03f6-4934-ac21-e7b8e609af4d" };
45
46 explicit TextSystem(CORE_NS::IEcs& ecs);
47 ~TextSystem() override;
48
49 BASE_NS::string_view GetName() const override;
50 BASE_NS::Uid GetUid() const override;
51
52 CORE_NS::IPropertyHandle* GetProperties() override;
53 const CORE_NS::IPropertyHandle* GetProperties() const override;
54 void SetProperties(const CORE_NS::IPropertyHandle&) override;
55
56 bool IsActive() const override;
57 void SetActive(bool state) override;
58
59 void Initialize() override;
60 bool Update(bool frameRenderingQueued, uint64_t time, uint64_t delta) override;
61 void Uninitialize() override;
62
63 const CORE_NS::IEcs& GetECS() const override;
64
65 private:
66 struct TextData;
67
68 void GenerateMesh(const TextComponent& textComponent, CORE_NS::Entity entity, struct TextData& cached);
69
70 bool active_ { false };
71 CORE_NS::IEcs& ecs_;
72 FONT_NS::IFontManager* fontManager_ { nullptr };
73 IMeshComponentManager* meshManager_ { nullptr };
74 IRenderHandleComponentManager* renderHandleManager_ { nullptr };
75 IRenderMeshComponentManager* renderMeshManager_ { nullptr };
76 ITextComponentManager* textManager_ { nullptr };
77 uint32_t textManagerGeneration_ {};
78 struct ShaderData {
79 RENDER_NS::RenderHandleReference graphicsState;
80 RENDER_NS::RenderHandleReference shader;
81 RENDER_NS::RenderHandleReference depthShader;
82 };
83 ShaderData rasterShader_;
84 ShaderData sdfShader_;
85
86 BASE_NS::unordered_map<CORE_NS::Entity, TextData> textCache_;
87 };
88
GetName(const TextSystem *)89 inline constexpr BASE_NS::string_view GetName(const TextSystem*)
90 {
91 return "TextSystem";
92 }
93 TEXT3D_END_NAMESPACE()
94
95 #endif // TEXT_3D_ECS_TEXTSYSTEM_H
96