• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SCENE_SRC_COMPONENT_MATERIAL_COMPONENT_H
17 #define SCENE_SRC_COMPONENT_MATERIAL_COMPONENT_H
18 
19 #include <scene/ext/component.h>
20 #include <scene/interface/intf_material.h>
21 
22 #include <3d/ecs/components/material_component.h>
23 
24 #include <meta/ext/object.h>
25 
26 META_TYPE(CORE3D_NS::MaterialComponent::Type)
27 META_TYPE(CORE3D_NS::MaterialComponent::Shader)
28 META_TYPE(CORE3D_NS::MaterialComponent::TextureInfo)
29 META_TYPE(CORE3D_NS::MaterialComponent::RenderSort)
30 
31 META_BEGIN_NAMESPACE()
32 template<bool B>
33 struct DefaultCompare<CORE3D_NS::MaterialComponent::Shader, B> {
34     using T = CORE3D_NS::MaterialComponent::Shader;
35     static constexpr bool Equal(const T& v1, const T& v2)
36     {
37         return v1.shader == v2.shader && v1.graphicsState == v2.graphicsState;
38     }
39 
40     template<typename NewType>
41     using Rebind = DefaultCompare<NewType>;
42 };
43 META_END_NAMESPACE()
44 
45 SCENE_BEGIN_NAMESPACE()
46 
47 class IInternalMaterial : public CORE_NS::IInterface {
48     META_INTERFACE(CORE_NS::IInterface, IInternalMaterial, "63a98b32-f062-42d0-81f7-490f3290df8a")
49 public:
50     META_PROPERTY(MaterialType, Type)
51     META_PROPERTY(float, AlphaCutoff)
52     META_PROPERTY(uint32_t, LightingFlags)
53 
54     META_PROPERTY(CORE3D_NS::MaterialComponent::RenderSort, RenderSort)
55 
56     META_PROPERTY(CORE3D_NS::MaterialComponent::Shader, MaterialShader)
57     META_PROPERTY(CORE3D_NS::MaterialComponent::Shader, DepthShader)
58 
59     META_ARRAY_PROPERTY(CORE3D_NS::MaterialComponent::TextureInfo, Textures)
60 
61     META_PROPERTY(uint32_t, UseTexcoordSetBit)
62     META_PROPERTY(uint32_t, CustomRenderSlotId)
63 
64     META_ARRAY_PROPERTY(CORE_NS::EntityReference, CustomResources)
65     META_PROPERTY(CORE_NS::IPropertyHandle*, CustomProperties)
66 
67     struct ActiveTextureSlotInfo {
68         size_t count {};
69         struct TextureSlot {
70             BASE_NS::string name;
71         };
72         BASE_NS::vector<TextureSlot> slots;
73     };
74 
75     virtual ActiveTextureSlotInfo GetActiveTextureSlotInfo() = 0;
76 };
77 
78 META_REGISTER_CLASS(MaterialComponent, "bc819033-2a5b-4182-bc7a-365ff8e33822", META_NS::ObjectCategoryBits::NO_CATEGORY)
79 
80 class MaterialComponent : public META_NS::IntroduceInterfaces<Component, IInternalMaterial> {
81     META_OBJECT(MaterialComponent, ClassId::MaterialComponent, IntroduceInterfaces)
82 
83 public:
84     META_BEGIN_STATIC_DATA()
85     SCENE_STATIC_PROPERTY_DATA(IInternalMaterial, MaterialType, Type, "MaterialComponent.type")
86     SCENE_STATIC_PROPERTY_DATA(IInternalMaterial, float, AlphaCutoff, "MaterialComponent.alphaCutoff")
87     SCENE_STATIC_PROPERTY_DATA(IInternalMaterial, uint32_t, LightingFlags, "MaterialComponent.materialLightingFlags")
88     SCENE_STATIC_PROPERTY_DATA(
89         IInternalMaterial, CORE3D_NS::MaterialComponent::RenderSort, RenderSort, "MaterialComponent.renderSort")
90 
91     SCENE_STATIC_PROPERTY_DATA(
92         IInternalMaterial, CORE3D_NS::MaterialComponent::Shader, MaterialShader, "MaterialComponent.materialShader")
93     SCENE_STATIC_PROPERTY_DATA(
94         IInternalMaterial, CORE3D_NS::MaterialComponent::Shader, DepthShader, "MaterialComponent.depthShader")
95 
96     SCENE_STATIC_ARRAY_PROPERTY_DATA(
97         IInternalMaterial, CORE3D_NS::MaterialComponent::TextureInfo, Textures, "MaterialComponent.textures")
98 
99     SCENE_STATIC_PROPERTY_DATA(IInternalMaterial, uint32_t, UseTexcoordSetBit, "MaterialComponent.useTexcoordSetBit")
100     SCENE_STATIC_PROPERTY_DATA(IInternalMaterial, uint32_t, CustomRenderSlotId, "MaterialComponent.customRenderSlotId")
101 
102     SCENE_STATIC_ARRAY_PROPERTY_DATA(
103         IInternalMaterial, CORE_NS::EntityReference, CustomResources, "MaterialComponent.customResources")
104     SCENE_STATIC_PROPERTY_DATA(
105         IInternalMaterial, CORE_NS::IPropertyHandle*, CustomProperties, "MaterialComponent.customProperties")
106     META_END_STATIC_DATA()
107 
108     META_IMPLEMENT_PROPERTY(MaterialType, Type)
109     META_IMPLEMENT_PROPERTY(float, AlphaCutoff)
110     META_IMPLEMENT_PROPERTY(uint32_t, LightingFlags)
111     META_IMPLEMENT_PROPERTY(CORE3D_NS::MaterialComponent::RenderSort, RenderSort)
112 
113     META_IMPLEMENT_PROPERTY(CORE3D_NS::MaterialComponent::Shader, MaterialShader)
114     META_IMPLEMENT_PROPERTY(CORE3D_NS::MaterialComponent::Shader, DepthShader)
115 
116     META_IMPLEMENT_ARRAY_PROPERTY(CORE3D_NS::MaterialComponent::TextureInfo, Textures)
117 
118     META_IMPLEMENT_PROPERTY(uint32_t, UseTexcoordSetBit)
119     META_IMPLEMENT_PROPERTY(uint32_t, CustomRenderSlotId)
120 
121     META_IMPLEMENT_ARRAY_PROPERTY(CORE_NS::EntityReference, CustomResources)
122     META_IMPLEMENT_PROPERTY(CORE_NS::IPropertyHandle*, CustomProperties)
123 
124 public:
125     BASE_NS::string GetName() const override;
126     ActiveTextureSlotInfo GetActiveTextureSlotInfo() override;
127 };
128 
129 SCENE_END_NAMESPACE()
130 
131 #endif
132