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 CORE__RENDER__NODE_DATA__RENDER_DATA_STORE_DEFAULT_SCENE_H
17 #define CORE__RENDER__NODE_DATA__RENDER_DATA_STORE_DEFAULT_SCENE_H
18 
19 #include <cstdint>
20 
21 #include <3d/render/intf_render_data_store_default_scene.h>
22 #include <base/containers/string.h>
23 #include <base/containers/string_view.h>
24 #include <base/containers/unordered_map.h>
25 #include <base/containers/vector.h>
26 #include <base/util/uid.h>
27 
28 RENDER_BEGIN_NAMESPACE()
29 class IRenderContext;
30 RENDER_END_NAMESPACE()
31 
CORE3D_BEGIN_NAMESPACE()32 CORE3D_BEGIN_NAMESPACE()
33 /**
34 RenderDataStoreDefaultScene implementation.
35 */
36 class RenderDataStoreDefaultScene final : public IRenderDataStoreDefaultScene {
37 public:
38     explicit RenderDataStoreDefaultScene(const BASE_NS::string_view name);
39     ~RenderDataStoreDefaultScene() override = default;
40 
41     void CommitFrameData() override {};
42     void PreRender() override {};
43     // Reset and start indexing from the beginning. i.e. frame boundary reset.
44     void PostRender() override;
45     void PreRenderBackend() override {};
46     void PostRenderBackend() override {};
47     void Clear() override;
48     uint32_t GetFlags() const override
49     {
50         return 0;
51     };
52 
53     void SetScene(const RenderScene& scene) override;
54     RenderScene GetScene(const BASE_NS::string_view sceneName) const override;
55     RenderScene GetScene() const override;
56 
57     // for plugin / factory interface
58     static constexpr char const* const TYPE_NAME = "RenderDataStoreDefaultScene";
59     static IRenderDataStore* Create(RENDER_NS::IRenderContext& renderContext, char const* name);
60     static void Destroy(IRenderDataStore* instance);
61 
62     BASE_NS::string_view GetTypeName() const override
63     {
64         return TYPE_NAME;
65     }
66 
67     BASE_NS::string_view GetName() const override
68     {
69         return name_;
70     }
71 
72     const BASE_NS::Uid& GetUid() const override
73     {
74         return UID;
75     }
76 
77 private:
78     BASE_NS::string name_;
79 
80     BASE_NS::vector<RenderScene> scenes_;
81     BASE_NS::unordered_map<BASE_NS::string, size_t> nameToScene_;
82     uint32_t nextId { 0u };
83 };
84 CORE3D_END_NAMESPACE()
85 
86 #endif // CORE__RENDER__NODE_DATA__RENDER_DATA_STORE_DEFAULT_SCENE_H
87