• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 GRAPHICS_CONTEXT_H
17 #define GRAPHICS_CONTEXT_H
18 
19 #include <3d/intf_graphics_context.h>
20 #include <base/containers/unique_ptr.h>
21 #include <base/containers/vector.h>
22 #include <core/namespace.h>
23 #include <render/resource_handle.h>
24 
25 CORE_BEGIN_NAMESPACE()
26 class IEcs;
27 CORE_END_NAMESPACE()
28 
29 RENDER_BEGIN_NAMESPACE()
30 class IRenderContext;
31 class IRenderDataStore;
32 RENDER_END_NAMESPACE()
33 
34 CORE3D_BEGIN_NAMESPACE()
35 class IMeshUtil;
36 class MeshUtil;
37 class IGltf2;
38 class Gltf2;
39 class ISceneUtil;
40 class SceneUtil;
41 class IRenderUtil;
42 class RenderUtil;
43 
44 class GraphicsContext final : public IGraphicsContext {
45 public:
46     explicit GraphicsContext(struct Agp3DPluginState&, RENDER_NS::IRenderContext& engine);
47     ~GraphicsContext() override;
48 
49     GraphicsContext(const GraphicsContext&) = delete;
50     GraphicsContext& operator=(const GraphicsContext&) = delete;
51 
52     void Init() override;
53 
54     RENDER_NS::IRenderContext& GetRenderContext() const override;
55 
56     BASE_NS::array_view<const RENDER_NS::RenderHandleReference> GetRenderNodeGraphs(
57         const CORE_NS::IEcs& ecs) const override;
58 
59     ISceneUtil& GetSceneUtil() const override;
60 
61     IMeshUtil& GetMeshUtil() const override;
62 
63     IGltf2& GetGltf() const override;
64 
65     IRenderUtil& GetRenderUtil() const override;
66 
67     // IInterface
68     const CORE_NS::IInterface* GetInterface(const BASE_NS::Uid& uid) const override;
69     CORE_NS::IInterface* GetInterface(const BASE_NS::Uid& uid) override;
70     void Ref() override;
71     void Unref() override;
72 
73 private:
74     struct Agp3DPluginState& factory_;
75     RENDER_NS::IRenderContext& context_;
76 
77     BASE_NS::unique_ptr<SceneUtil> sceneUtil_;
78     BASE_NS::unique_ptr<MeshUtil> meshUtil_;
79     BASE_NS::unique_ptr<Gltf2> gltf2_;
80     BASE_NS::unique_ptr<RenderUtil> renderUtil_;
81     BASE_NS::vector<RENDER_NS::RenderHandleReference> defaultGpuResources_;
82     bool initialized_ { false };
83     uint32_t refcnt_ { 0 };
84 };
85 CORE3D_END_NAMESPACE()
86 
87 #endif // GRAPHICS_CONTEXT_H
88