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 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 /** Container for create info flag bits */ 58 using CreateInfoFlags = uint32_t; 59 60 /** Creation flags */ 61 CreateInfoFlags createFlags { 0 }; 62 /** Color space flags (defaults to linear) */ 63 BASE_NS::ColorSpaceFlags colorSpaceFlags { 0U }; 64 }; 65 66 /** Initialize the context. 67 */ 68 virtual void Init() = 0; 69 70 /** Initialize the context. 71 */ 72 virtual void Init(const CreateInfo& createInfo) = 0; 73 74 /** Get rendering context. 75 * @return Reference to context. 76 */ 77 virtual RENDER_NS::IRenderContext& GetRenderContext() const = 0; 78 79 /** Get render node graphs from ECS instance. 80 * @return Array view of ECS instance render node graphs. 81 */ 82 virtual BASE_NS::array_view<const RENDER_NS::RenderHandleReference> GetRenderNodeGraphs( 83 const CORE_NS::IEcs& ecs) const = 0; 84 85 /** Get SceneUtil interface. Uses graphics context resource creator and engine internally. 86 * @return Reference to scene util interface. 87 */ 88 virtual ISceneUtil& GetSceneUtil() const = 0; 89 90 /** Get MeshUtil interface. Uses graphics context resource creator and engine internally. 91 * @return Reference to mesh util interface. 92 */ 93 virtual IMeshUtil& GetMeshUtil() const = 0; 94 95 /** Get Gltf2 interface. Uses graphics context resource creator and engine internally. 96 * @return Reference to gltf2 interface. 97 */ 98 virtual IGltf2& GetGltf() const = 0; 99 100 /** Get render util. 101 * @return Reference to render util. 102 */ 103 virtual IRenderUtil& GetRenderUtil() const = 0; 104 105 /** Get color space flags 106 * @return Color space flags given in Init. 107 */ 108 virtual BASE_NS::ColorSpaceFlags GetColorSpaceFlags() const = 0; 109 110 protected: 111 IGraphicsContext() = default; 112 virtual ~IGraphicsContext() = default; 113 }; 114 CORE3D_END_NAMESPACE() 115 116 #endif // API_3D_IGRAPHICS_CONTEXT_H 117