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 #include <3d/ecs/components/render_configuration_component.h>
17 #include <core/property/property_types.h>
18
19 #include "ComponentTools/base_manager.h"
20 #include "ComponentTools/base_manager.inl"
21
22 #define IMPLEMENT_MANAGER
23 #include <core/property_tools/property_macros.h>
24
25 CORE_BEGIN_NAMESPACE()
26 using CORE3D_NS::RenderConfigurationComponent;
27
28 // Extend propertysystem with the enums
29 DECLARE_PROPERTY_TYPE(RenderConfigurationComponent::SceneShadowType);
30 DECLARE_PROPERTY_TYPE(RenderConfigurationComponent::SceneShadowQuality);
31 DECLARE_PROPERTY_TYPE(RenderConfigurationComponent::SceneShadowSmoothness);
32
33 // Declare their metadata
34 ENUM_TYPE_METADATA(RenderConfigurationComponent::SceneShadowType, ENUM_VALUE(PCF, "PCF (Percentage Closer Filtering)"),
35 ENUM_VALUE(VSM, "VSM (Variance Shadow Maps)"))
36
37 ENUM_TYPE_METADATA(RenderConfigurationComponent::SceneShadowQuality, ENUM_VALUE(LOW, "Low"),
38 ENUM_VALUE(NORMAL, "Normal"), ENUM_VALUE(HIGH, "High"), ENUM_VALUE(ULTRA, "Ultra"))
39
40 ENUM_TYPE_METADATA(RenderConfigurationComponent::SceneShadowSmoothness, ENUM_VALUE(HARD, "Hard"),
41 ENUM_VALUE(NORMAL, "Normal"), ENUM_VALUE(SOFT, "Soft"))
42
43 ENUM_TYPE_METADATA(RenderConfigurationComponent::SceneRenderingFlagBits, ENUM_VALUE(CREATE_RNGS_BIT, "Create RNGs"))
44 CORE_END_NAMESPACE()
45
46 CORE3D_BEGIN_NAMESPACE()
47 using BASE_NS::array_view;
48 using BASE_NS::countof;
49
50 using CORE_NS::BaseManager;
51 using CORE_NS::IComponentManager;
52 using CORE_NS::IEcs;
53 using CORE_NS::Property;
54 using CORE_NS::PropertyFlags;
55
56 class RenderConfigurationComponentManager final
57 : public BaseManager<RenderConfigurationComponent, IRenderConfigurationComponentManager> {
58 BEGIN_PROPERTY(RenderConfigurationComponent, componentMetaData_)
59 #include <3d/ecs/components/render_configuration_component.h>
60 END_PROPERTY();
61
62 public:
RenderConfigurationComponentManager(IEcs & ecs)63 explicit RenderConfigurationComponentManager(IEcs& ecs)
64 : BaseManager<RenderConfigurationComponent, IRenderConfigurationComponentManager>(
65 ecs, CORE_NS::GetName<RenderConfigurationComponent>(), 1U)
66 {}
67
68 ~RenderConfigurationComponentManager() = default;
69
PropertyCount() const70 size_t PropertyCount() const override
71 {
72 return BASE_NS::countof(componentMetaData_);
73 }
74
MetaData(size_t index) const75 const Property* MetaData(size_t index) const override
76 {
77 if (index < BASE_NS::countof(componentMetaData_)) {
78 return &componentMetaData_[index];
79 }
80 return nullptr;
81 }
82
MetaData() const83 array_view<const Property> MetaData() const override
84 {
85 return componentMetaData_;
86 }
87 };
88
IRenderConfigurationComponentManagerInstance(IEcs & ecs)89 IComponentManager* IRenderConfigurationComponentManagerInstance(IEcs& ecs)
90 {
91 return new RenderConfigurationComponentManager(ecs);
92 }
93
IRenderConfigurationComponentManagerDestroy(IComponentManager * instance)94 void IRenderConfigurationComponentManagerDestroy(IComponentManager* instance)
95 {
96 delete static_cast<RenderConfigurationComponentManager*>(instance);
97 }
98 CORE3D_END_NAMESPACE()
99