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 "PropertyTools/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 BEGIN_ENUM(SceneShadowTypeMetaData, RenderConfigurationComponent::SceneShadowType)
35 DECL_ENUM(RenderConfigurationComponent::SceneShadowType, PCF, "PCF (Percentage Closer Filtering)")
36 DECL_ENUM(RenderConfigurationComponent::SceneShadowType, VSM, "VSM (Variance Shadow Maps)")
37 END_ENUM(SceneShadowTypeMetaData, RenderConfigurationComponent::SceneShadowType)
38
39 BEGIN_ENUM(SceneShadowQualityMetaData, RenderConfigurationComponent::SceneShadowQuality)
40 DECL_ENUM(RenderConfigurationComponent::SceneShadowQuality, LOW, "Low")
41 DECL_ENUM(RenderConfigurationComponent::SceneShadowQuality, NORMAL, "Normal")
42 DECL_ENUM(RenderConfigurationComponent::SceneShadowQuality, HIGH, "High")
43 DECL_ENUM(RenderConfigurationComponent::SceneShadowQuality, ULTRA, "Ultra")
44 END_ENUM(SceneShadowQualityMetaData, RenderConfigurationComponent::SceneShadowQuality)
45
46 BEGIN_ENUM(SceneShadowSmoothnessMetaData, RenderConfigurationComponent::SceneShadowSmoothness)
47 DECL_ENUM(RenderConfigurationComponent::SceneShadowSmoothness, HARD, "Hard")
48 DECL_ENUM(RenderConfigurationComponent::SceneShadowSmoothness, NORMAL, "Normal")
49 DECL_ENUM(RenderConfigurationComponent::SceneShadowSmoothness, SOFT, "Soft")
50 END_ENUM(SceneShadowSmoothnessMetaData, RenderConfigurationComponent::SceneShadowSmoothness)
51
52 BEGIN_ENUM(SceneRenderingFlagBitsMetaData, RenderConfigurationComponent::SceneRenderingFlagBits)
53 DECL_ENUM(RenderConfigurationComponent::SceneRenderingFlagBits, CREATE_RNGS_BIT, "Create RNGs")
54 END_ENUM(SceneRenderingFlagBitsMetaData, RenderConfigurationComponent::SceneRenderingFlagBits)
55 CORE_END_NAMESPACE()
56
57 CORE3D_BEGIN_NAMESPACE()
58 using BASE_NS::array_view;
59 using BASE_NS::countof;
60
61 using CORE_NS::BaseManager;
62 using CORE_NS::IComponentManager;
63 using CORE_NS::IEcs;
64 using CORE_NS::Property;
65 using CORE_NS::PropertyFlags;
66
67 class RenderConfigurationComponentManager final
68 : public BaseManager<RenderConfigurationComponent, IRenderConfigurationComponentManager> {
69 BEGIN_PROPERTY(RenderConfigurationComponent, ComponentMetadata)
70 #include <3d/ecs/components/render_configuration_component.h>
71 END_PROPERTY();
72 const array_view<const Property> componentMetaData_ { ComponentMetadata, countof(ComponentMetadata) };
73
74 public:
RenderConfigurationComponentManager(IEcs & ecs)75 explicit RenderConfigurationComponentManager(IEcs& ecs)
76 : BaseManager<RenderConfigurationComponent, IRenderConfigurationComponentManager>(
77 ecs, CORE_NS::GetName<RenderConfigurationComponent>())
78 {}
79
80 ~RenderConfigurationComponentManager() = default;
81
PropertyCount() const82 size_t PropertyCount() const override
83 {
84 return componentMetaData_.size();
85 }
86
MetaData(size_t index) const87 const Property* MetaData(size_t index) const override
88 {
89 if (index < componentMetaData_.size()) {
90 return &componentMetaData_[index];
91 }
92 return nullptr;
93 }
94
MetaData() const95 array_view<const Property> MetaData() const override
96 {
97 return componentMetaData_;
98 }
99 };
100
IRenderConfigurationComponentManagerInstance(IEcs & ecs)101 IComponentManager* IRenderConfigurationComponentManagerInstance(IEcs& ecs)
102 {
103 return new RenderConfigurationComponentManager(ecs);
104 }
105
IRenderConfigurationComponentManagerDestroy(IComponentManager * instance)106 void IRenderConfigurationComponentManagerDestroy(IComponentManager* instance)
107 {
108 delete static_cast<RenderConfigurationComponentManager*>(instance);
109 }
110 CORE3D_END_NAMESPACE()
111