Lock uniform buffer only 1 times per each render + minor fixup of uniforms
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / uniform-buffer-view.h
1 #ifndef DALI_INTERNAL_UNIFORM_BUFFER_VIEW_H
2 #define DALI_INTERNAL_UNIFORM_BUFFER_VIEW_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <stdint.h>
23 #include <stdlib.h>
24
25 namespace Dali
26 {
27 namespace Graphics
28 {
29 class Buffer;
30 }
31 namespace Internal::Render
32 {
33 class UniformBuffer;
34
35 /**
36  * Class UniformBufferView
37  *
38  * The class is responsible for providing view into the UniformBuffer object
39  * giving access to part or all of its memory. UniformBufferView doesn't own
40  * memory.
41  *
42  * The memory accessed through the UniformBufferView should be addressed at
43  * the offset of 0 and up to specified size. The memory beyond the view may be
44  * invalid.
45  *
46  */
47 class UniformBufferView
48 {
49 public:
50   UniformBufferView(UniformBuffer& ubo, uint32_t offset, size_t size);
51
52   ~UniformBufferView();
53
54   /**
55    * @brief Writes data into the current uniform buffer view.
56    * @note We prefer to call UniformBuffer::ReadyToLockUniformBuffer before call Write API.
57    * And also, prefer to call UniformBuffer::UnlockUniformBuffer if current frame's all Write API action done.
58    *
59    * @param[in] data pointer to the source data
60    * @param[in] size size of source data
61    * @param[in] offset destination offset
62    */
63   void Write(const void* data, uint32_t size, uint32_t offset);
64
65   /**
66    * @brief Returns the size of the view
67    *
68    * @return size of view
69    */
70   [[nodiscard]] uint32_t GetSize() const
71   {
72     return mSize;
73   }
74
75   /**
76    * @brief Returns the offset within the UBO
77    * @return Offset
78    */
79   [[nodiscard]] uint32_t GetOffset() const
80   {
81     return mOffset;
82   }
83
84   /**
85    * @brief Returns Graphics buffer associated with this View
86    *
87    * If 'relativeOffset' isn't nullptr then the offset into the individual
88    * Graphics::Buffer is written.
89    *
90    * @param[out] relativeOffset the offset into individual Graphics::Buffer
91    *
92    * @return Pointer to a valid Graphics::Buffer object
93    */
94   [[nodiscard]] Graphics::Buffer* GetBuffer(uint32_t* relativeOffset = nullptr);
95
96 private:
97   UniformBuffer* mUniformBuffer{nullptr}; ///< UniformBuffer that the view views
98   uint32_t       mOffset{0u};             ///< Offset within the buffer
99   size_t         mSize{0u};               ///< Size of view
100 };
101 } // Namespace Internal::Render
102 } // Namespace Dali
103 #endif //DALI_INTERNAL_UNIFORM_BUFFER_VIEW_H