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_RENDER_IRENDER_DATA_STORE_H
17 #define API_RENDER_IRENDER_DATA_STORE_H
18
19 #include <base/containers/string_view.h>
20 #include <render/namespace.h>
21
22 BASE_BEGIN_NAMESPACE()
23 struct Uid;
24 BASE_END_NAMESPACE()
25
RENDER_BEGIN_NAMESPACE()26 RENDER_BEGIN_NAMESPACE()
27 /** @ingroup group_render_irenderdatastore */
28 /** Base class for render data management.
29 * Inherit to create a new data manager.
30 */
31 class IRenderDataStore {
32 public:
33 IRenderDataStore(const IRenderDataStore&) = delete;
34 IRenderDataStore& operator=(const IRenderDataStore&) = delete;
35
36 /** Called automatically by the renderer when render data store manager CommitFrameData is called.
37 * This is called automatically every frame.
38 * Needs to be overwritten by the inherit classes.
39 * Here one could e.g. flip double buffers etc.
40 */
41 virtual void CommitFrameData() = 0;
42
43 /** Called automatically by the engine (renderer) before render node front-end processing.
44 * Needs to be overwritten by the inherit classes.
45 * Here one could e.g. allocate GPU resources for current counts or do some specific management
46 * for all this frame's data.
47 */
48 virtual void PreRender() = 0;
49
50 /** Called automatically by the engine (renderer) after rendering front-end has been completed.
51 * This happens before PreRenderBackend. For example, clear render data store data which has been processed in render
52 * nodes. Needs to be overwritten by the inherit classes. Here one can place resets for buffers and data.
53 */
54 virtual void PostRender() = 0;
55
56 /** Called automatically by the engine (renderer) before back-end processing.
57 * Here (and only here with render data stores) one can access low level / back-end GPU resources.
58 * Needs to be overwritten by the inherit classes.
59 * Process only backend related work here.
60 */
61 virtual void PreRenderBackend() = 0;
62
63 /** Called automatically by the engine (renderer) after all rendering back-end processing (full rendering)
64 * Needs to be overwritten by the inherit classes.
65 * Process only post full render here. (Clear data store content already in PostRender())
66 */
67 virtual void PostRenderBackend() = 0;
68
69 /** Should be called when one starts to fill up the render data store.
70 * Needs to be overwritten by the inherit classes.
71 * This should clear all the buffers which are filled once a frame.
72 */
73 virtual void Clear() = 0;
74
75 /** Should return IRenderDataStoreManager::RenderDataStoreFlags which are implemented by the data store.
76 * Do not print flags which are not supported by the data store.
77 * Needs to be overwritten by the inherit classes.
78 * Used by the renderer for e.g. validation. (Can print warnings when correct flags are not returned.)
79 */
80 virtual uint32_t GetFlags() const = 0;
81
82 /** Get the type name of the render data store.
83 * @return Type name of the render data store.
84 */
85 virtual BASE_NS::string_view GetTypeName() const = 0;
86
87 /** Get the unique instance name of the render data store.
88 * @return Unique name of the render data store.
89 */
90 virtual BASE_NS::string_view GetName() const = 0;
91
92 /** Get the type UID of the render data store.
93 * @return Type UID of the render data store.
94 */
95 virtual const BASE_NS::Uid& GetUid() const = 0;
96
97 protected:
98 IRenderDataStore() = default;
99 virtual ~IRenderDataStore() = default;
100 };
101 RENDER_END_NAMESPACE()
102
103 #endif // API_RENDER_IRENDER_DATA_STORE_H
104