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_mesh_batch_component.h>
17
18 #include "ComponentTools/base_manager.h"
19 #include "ComponentTools/base_manager.inl"
20
21 #define IMPLEMENT_MANAGER
22 #include "PropertyTools/property_macros.h"
23
24 CORE_BEGIN_NAMESPACE()
25 // Extend propertysystem with the enums
26 DECLARE_PROPERTY_TYPE(CORE3D_NS::RenderMeshBatchComponent::BatchType);
27
28 // Declare their metadata
29 BEGIN_ENUM(BatchTypeMetaData, CORE3D_NS::RenderMeshBatchComponent::BatchType)
30 DECL_ENUM(CORE3D_NS::RenderMeshBatchComponent::BatchType, GPU_INSTANCING, "GPU Instancing")
31 END_ENUM(BatchTypeMetaData, CORE3D_NS::RenderMeshBatchComponent::BatchType)
32 CORE_END_NAMESPACE()
33
34 CORE3D_BEGIN_NAMESPACE()
35 using BASE_NS::array_view;
36 using BASE_NS::countof;
37
38 using CORE_NS::BaseManager;
39 using CORE_NS::IComponentManager;
40 using CORE_NS::IEcs;
41 using CORE_NS::Property;
42
43 class RenderMeshBatchComponentManager final
44 : public BaseManager<RenderMeshBatchComponent, IRenderMeshBatchComponentManager> {
45 BEGIN_PROPERTY(RenderMeshBatchComponent, ComponentMetadata)
46 #include <3d/ecs/components/render_mesh_batch_component.h>
47 END_PROPERTY();
48 const array_view<const Property> componentMetaData_ { ComponentMetadata, countof(ComponentMetadata) };
49
50 public:
RenderMeshBatchComponentManager(IEcs & ecs)51 explicit RenderMeshBatchComponentManager(IEcs& ecs)
52 : BaseManager<RenderMeshBatchComponent, IRenderMeshBatchComponentManager>(
53 ecs, CORE_NS::GetName<RenderMeshBatchComponent>())
54 {}
55
56 ~RenderMeshBatchComponentManager() = default;
57
PropertyCount() const58 size_t PropertyCount() const override
59 {
60 return componentMetaData_.size();
61 }
62
MetaData(size_t index) const63 const Property* MetaData(size_t index) const override
64 {
65 if (index < componentMetaData_.size()) {
66 return &componentMetaData_[index];
67 }
68 return nullptr;
69 }
70
MetaData() const71 array_view<const Property> MetaData() const override
72 {
73 return componentMetaData_;
74 }
75 };
76
IRenderMeshBatchComponentManagerInstance(IEcs & ecs)77 IComponentManager* IRenderMeshBatchComponentManagerInstance(IEcs& ecs)
78 {
79 return new RenderMeshBatchComponentManager(ecs);
80 }
81
IRenderMeshBatchComponentManagerDestroy(IComponentManager * instance)82 void IRenderMeshBatchComponentManagerDestroy(IComponentManager* instance)
83 {
84 delete static_cast<RenderMeshBatchComponentManager*>(instance);
85 }
86 CORE3D_END_NAMESPACE()
87