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 <scene/interface/intf_camera.h>
17 #include <scene/interface/intf_environment.h>
18 #include <scene/interface/intf_light.h>
19 #include <scene/interface/intf_material.h>
20 #include <scene/interface/intf_mesh.h>
21 #include <scene/interface/intf_text.h>
22 #include <scene/interface/intf_texture.h>
23 #include <scene/interface/postprocess/intf_bloom.h>
24 #include <scene/interface/postprocess/intf_tonemap.h>
25 #include <scene/interface/resource/image_info.h>
26
27 #include <meta/base/meta_types.h>
28 #include <meta/ext/any_builder.h>
29 #include <meta/interface/detail/any.h>
30
31 SCENE_BEGIN_NAMESPACE()
32
33 // clang-format off
34 using BasicTypes = META_NS::TypeList<
35 EnvBackgroundType,
36 SamplerFilter,
37 SamplerAddressMode,
38 MaterialType,
39 LightingFlags,
40 RenderSort,
41 ImageLoadFlags,
42 CameraProjection,
43 CameraCulling,
44 CameraPipeline,
45 CameraPipelineFlag,
46 CameraSceneFlag,
47 ColorFormat,
48 EffectQualityType,
49 FontMethod,
50 LightType,
51 BloomType,
52 TonemapType,
53 CullModeFlags,
54 ImageLoadInfo
55 >;
56 using ObjectTypes = META_NS::TypeList<
57 ISampler::Ptr,
58 IImage::Ptr,
59 ITexture::Ptr,
60 IMaterial::Ptr,
61 IEnvironment::Ptr,
62 IShader::Ptr,
63 ISubMesh::Ptr,
64 IMorpher::Ptr,
65 IPostProcess::Ptr,
66 IBloom::Ptr,
67 ITonemap::Ptr
68 >;
69 // clang-format on
70
71 namespace Internal {
72
73 // Compatibility with old IBitmap any
74 class BitmapAnyBuilder : public META_NS::AnyBuilder {
75 public:
76 using AnyType = META_NS::AnyType<IImage::Ptr>;
77
StaticGetClassId()78 static META_NS::ObjectId StaticGetClassId()
79 {
80 return META_NS::ObjectId("61621edc-f7f4-a195-4275-696c74416e79");
81 }
Construct()82 META_NS::IAny::Ptr Construct() override
83 {
84 return META_NS::IAny::Ptr(new AnyType);
85 }
GetObjectId() const86 META_NS::ObjectId GetObjectId() const override
87 {
88 return StaticGetClassId();
89 }
GetTypeName() const90 BASE_NS::string GetTypeName() const override
91 {
92 return BASE_NS::string(AnyType::StaticGetTypeIdString());
93 }
94 };
95
96 template<typename... List>
RegisterTypes(META_NS::IPropertyRegister & pr,META_NS::TypeList<List...>)97 static void RegisterTypes(META_NS::IPropertyRegister& pr, META_NS::TypeList<List...>)
98 {
99 (META_NS::RegisterTypeForBuiltinAny<List>(), ...);
100 (META_NS::RegisterTypeForBuiltinArrayAny<List>(), ...);
101 }
102
103 template<typename... List>
UnregisterTypes(META_NS::IPropertyRegister & pr,META_NS::TypeList<List...>)104 static void UnregisterTypes(META_NS::IPropertyRegister& pr, META_NS::TypeList<List...>)
105 {
106 (META_NS::UnregisterTypeForBuiltinAny<List>(), ...);
107 (META_NS::UnregisterTypeForBuiltinArrayAny<List>(), ...);
108 }
109
RegisterAnys()110 void RegisterAnys()
111 {
112 auto& pr = META_NS::GetObjectRegistry().GetPropertyRegister();
113 RegisterTypes(pr, BasicTypes {});
114 RegisterTypes(pr, ObjectTypes {});
115
116 // for compatibility
117 pr.RegisterAny(CreateShared<BitmapAnyBuilder>());
118 }
119
UnRegisterAnys()120 void UnRegisterAnys()
121 {
122 auto& pr = META_NS::GetObjectRegistry().GetPropertyRegister();
123 UnregisterTypes(pr, ObjectTypes {});
124 UnregisterTypes(pr, BasicTypes {});
125
126 pr.UnregisterAny(BitmapAnyBuilder::StaticGetClassId());
127 }
128
129 } // namespace Internal
130 SCENE_END_NAMESPACE()
131