• 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_MESH_SHADER_H
17 #define SCENE_SRC_MESH_SHADER_H
18 
19 #include <scene/ext/intf_ecs_object.h>
20 #include <scene/ext/intf_internal_scene.h>
21 #include <scene/ext/intf_render_resource.h>
22 #include <scene/interface/intf_shader.h>
23 #include <shared_mutex>
24 
25 #include <meta/ext/implementation_macros.h>
26 #include <meta/ext/object.h>
27 #include <meta/interface/resource/intf_dynamic_resource.h>
28 
SCENE_BEGIN_NAMESPACE()29 SCENE_BEGIN_NAMESPACE()
30 
31 class Shader : public META_NS::IntroduceInterfaces<META_NS::MetaObject, IShader, IRenderResource, IEcsResource,
32                    IGraphicsState, META_NS::IDynamicResource, META_NS::INamed, IShaderState> {
33     META_OBJECT(Shader, ClassId::Shader, IntroduceInterfaces)
34 public:
35     META_BEGIN_STATIC_DATA()
36     META_STATIC_PROPERTY_DATA(META_NS::INamed, BASE_NS::string, Name)
37     META_STATIC_PROPERTY_DATA(IShader, BASE_NS::string, Uri)
38     META_STATIC_EVENT_DATA(META_NS::IDynamicResource, META_NS::IOnChanged, OnResourceChanged)
39     META_END_STATIC_DATA()
40 
41     META_IMPLEMENT_PROPERTY(BASE_NS::string, Name)
42     META_IMPLEMENT_READONLY_PROPERTY(BASE_NS::string, Uri)
43     META_IMPLEMENT_EVENT(META_NS::IOnChanged, OnResourceChanged)
44 
45     BASE_NS::string GetName() const override;
46 
47     bool SetRenderHandle(const IInternalScene::Ptr& scene, RENDER_NS::RenderHandleReference handle,
48         CORE_NS::EntityReference ent) override;
49     bool SetShaderState(const IInternalScene::Ptr& scene, RENDER_NS::RenderHandleReference handle,
50         CORE_NS::EntityReference ent, RENDER_NS::RenderHandleReference ghandle,
51         CORE_NS::EntityReference gstate) override;
52     RENDER_NS::RenderHandleReference GetRenderHandle() const override;
53     CORE_NS::Entity GetEntity() const override;
54 
55     bool SetGraphicsState(CORE_NS::EntityReference) override;
56     CORE_NS::EntityReference GetGraphicsState() const override;
57 
58     Future<bool> LoadShader(const IScene::Ptr&, BASE_NS::string_view uri) override;
59 
60     void Refresh() override {}
61 
62     Future<CullModeFlags> GetCullMode() const override;
63     Future<bool> SetCullMode(CullModeFlags) override;
64     Future<bool> IsBlendEnabled() const override;
65     Future<bool> EnableBlend(bool) override;
66 
67 private:
68     bool SetRenderHandleImpl(const IInternalScene::Ptr& scene, RENDER_NS::RenderHandleReference);
69     IInternalScene::Ptr GetScene() const;
70 
71     RENDER_NS::RenderHandleReference GetGraphicsStateHandle() const;
72     RENDER_NS::RenderHandleReference UpdateGraphicsState(
73         const IInternalScene::Ptr& scene, const RENDER_NS::GraphicsState& gs);
74 
75 private:
76     mutable std::shared_mutex mutex_;
77     RENDER_NS::RenderHandleReference handle_;
78     CORE_NS::EntityReference entity_;
79     CORE_NS::EntityReference graphicsState_;
80     RENDER_NS::RenderHandleReference graphicsStateHandle_;
81     IInternalScene::WeakPtr scene_;
82 };
83 
84 SCENE_END_NAMESPACE()
85 
86 #endif