• 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_INTERFACE_ISHADER_H
17 #define SCENE_INTERFACE_ISHADER_H
18 
19 #include <scene/base/namespace.h>
20 #include <scene/base/types.h>
21 #include <scene/ext/intf_internal_scene.h>
22 #include <scene/interface/intf_scene.h>
23 
24 #include <render/device/intf_shader_manager.h>
25 #include <render/resource_handle.h>
26 
27 #include <meta/base/interface_macros.h>
28 #include <meta/interface/interface_macros.h>
29 
30 SCENE_BEGIN_NAMESPACE()
31 
32 /** Cull mode flag bits */
33 enum class CullModeFlags : uint32_t {
34     /** None */
35     NONE = 0,
36     /** Front bit */
37     FRONT_BIT = 0x00000001,
38     /** Back bit */
39     BACK_BIT = 0x00000002,
40     /** Front and back bit */
41     FRONT_AND_BACK = 0x00000003,
42 };
43 
44 inline CullModeFlags operator|(CullModeFlags l, CullModeFlags r)
45 {
46     return CullModeFlags(static_cast<uint32_t>(l) | static_cast<uint32_t>(r));
47 }
48 
49 class IShader : public CORE_NS::IInterface {
50     META_INTERFACE(CORE_NS::IInterface, IShader, "8a241b86-14c6-48ec-b450-6f9818f9f31a")
51 public:
52     /**
53      * @brief Uri of the shader definition
54      */
55     META_READONLY_PROPERTY(BASE_NS::string, Uri)
56 
57     /// Load shader from uri
58     virtual Future<bool> LoadShader(const IScene::Ptr&, BASE_NS::string_view uri) = 0;
59     /// Get cull mode for the shader
60     virtual Future<CullModeFlags> GetCullMode() const = 0;
61     /// Set cull mode for the shader
62     virtual Future<bool> SetCullMode(CullModeFlags mode) = 0;
63     /// Is blend enabled for the shader
64     virtual Future<bool> IsBlendEnabled() const = 0;
65     /// Enable blend mode for shader
66     virtual Future<bool> EnableBlend(bool enabled) = 0;
67 };
68 
69 class IGraphicsState : public CORE_NS::IInterface {
70     META_INTERFACE(CORE_NS::IInterface, IGraphicsState, "6788f05b-4a55-4396-8cdd-115dc2958656")
71 public:
72     virtual bool SetGraphicsState(CORE_NS::EntityReference) = 0;
73     virtual CORE_NS::EntityReference GetGraphicsState() const = 0;
74 };
75 
76 class IShaderState : public CORE_NS::IInterface {
77     META_INTERFACE(CORE_NS::IInterface, IShaderState, "44b20afb-4e96-41de-a765-df9dd07799de")
78 public:
79     virtual bool SetShaderState(const IInternalScene::Ptr& scene, RENDER_NS::RenderHandleReference handle,
80         CORE_NS::EntityReference ent, RENDER_NS::RenderHandleReference ghandle, CORE_NS::EntityReference gstate) = 0;
81 };
82 META_REGISTER_CLASS(Shader, "56d686b8-7a33-4608-b12a-1a170381bcfd", META_NS::ObjectCategoryBits::NO_CATEGORY)
83 
84 SCENE_END_NAMESPACE()
85 
86 META_TYPE(SCENE_NS::CullModeFlags)
87 META_INTERFACE_TYPE(SCENE_NS::IShader)
88 META_INTERFACE_TYPE(SCENE_NS::IGraphicsState)
89 
90 #endif
91