• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 API_3D_IGRAPHICS_CONTEXT_H
17 #define API_3D_IGRAPHICS_CONTEXT_H
18 
19 #include <3d/namespace.h>
20 #include <base/containers/array_view.h>
21 #include <base/util/color.h>
22 #include <core/namespace.h>
23 #include <core/plugin/intf_interface.h>
24 #include <render/namespace.h>
25 
26 CORE_BEGIN_NAMESPACE()
27 class IEngine;
28 class IEcs;
29 CORE_END_NAMESPACE()
30 
31 RENDER_BEGIN_NAMESPACE()
32 class IRenderContext;
33 class RenderHandleReference;
34 RENDER_END_NAMESPACE()
35 
36 CORE3D_BEGIN_NAMESPACE()
37 class ISceneUtil;
38 class IRenderUtil;
39 class IMeshUtil;
40 class IGltf2;
41 
42 /**
43  * IGraphicsContext.
44  * Graphics context interface for 3D rendering use cases.
45  */
46 class IGraphicsContext : public CORE_NS::IInterface {
47 public:
48     static constexpr auto UID = BASE_NS::Uid { "c6eb95b1-8b32-40f7-8acd-7969792e574b" };
49 
50     using Ptr = BASE_NS::refcnt_ptr<IGraphicsContext>;
51 
52     /** Create info for 3D graphics context.
53      */
54     struct CreateInfo {
55         /** Create info flag bits to setup configuration flags */
56         enum CreateInfoFlagBits : uint32_t {
57             /** Explicitly enable acceleration structures
58              * Enables meshes to build BLAS
59              * Enables render side to handle TLAS
60              */
61             ENABLE_ACCELERATION_STRUCTURES_BIT = (1U << 0U),
62         };
63         /** Container for create info flag bits */
64         using CreateInfoFlags = uint32_t;
65 
66         /** Creation flags */
67         CreateInfoFlags createFlags { 0 };
68         /** Color space flags (defaults to linear) */
69         BASE_NS::ColorSpaceFlags colorSpaceFlags { 0U };
70     };
71 
72     /** Initialize the context.
73      */
74     virtual void Init() = 0;
75 
76     /** Initialize the context.
77      */
78     virtual void Init(const CreateInfo& createInfo) = 0;
79 
80     /** Get rendering context.
81      * @return Reference to context.
82      */
83     virtual RENDER_NS::IRenderContext& GetRenderContext() const = 0;
84 
85     /** Get render node graphs from ECS instance.
86      * @return Array view of ECS instance render node graphs.
87      */
88     virtual BASE_NS::array_view<const RENDER_NS::RenderHandleReference> GetRenderNodeGraphs(
89         const CORE_NS::IEcs& ecs) const = 0;
90 
91     /** Get SceneUtil interface. Uses graphics context resource creator and engine internally.
92      * @return Reference to scene util interface.
93      */
94     virtual ISceneUtil& GetSceneUtil() const = 0;
95 
96     /** Get MeshUtil interface. Uses graphics context resource creator and engine internally.
97      * @return Reference to mesh util interface.
98      */
99     virtual IMeshUtil& GetMeshUtil() const = 0;
100 
101     /** Get Gltf2 interface. Uses graphics context resource creator and engine internally.
102      * @return Reference to gltf2 interface.
103      */
104     virtual IGltf2& GetGltf() const = 0;
105 
106     /** Get render util.
107      * @return Reference to render util.
108      */
109     virtual IRenderUtil& GetRenderUtil() const = 0;
110 
111     /** Get create info
112      * @return Create info.
113      */
114     virtual CreateInfo GetCreateInfo() const = 0;
115 
116 protected:
117     IGraphicsContext() = default;
118     virtual ~IGraphicsContext() = default;
119 };
120 CORE3D_END_NAMESPACE()
121 
122 #endif // API_3D_IGRAPHICS_CONTEXT_H
123