1 #ifndef DALI_INTERNAL_RENDERERS_GPU_BUFFER_H
2 #define DALI_INTERNAL_RENDERERS_GPU_BUFFER_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/graphics-api/graphics-controller.h>
26 class VertexBufferUpdateCallback;
31 * Used to create and update a GPU memory buffer.
33 * The buffer can be used for storing vertex data, index arrays (indices)
34 * or pixel data (PBO).
36 * The buffer allows data to be stored in high-performance
37 * graphics memory on the server side and
38 * promotes efficient data transfer.
44 * When writing into the buffer, the WritePolicy
45 * determines whether the current content would be preserved
48 * RETAIN - buffer content is retained
50 * DISCARD - buffer content is discarded. In this case, writing into
51 * a part of buffer will result with undefined content outside
52 * the specified area. The client should rewrite whole area
53 * in order to have coherent and valid data.
55 enum class WritePolicy
57 RETAIN, ///< Buffer content is preserved
58 DISCARD ///< Buffer content is invalidated and discarded
63 * @param[in] graphicsController the graphics controller
64 * @param[in] usage The type of buffer
65 * @param[in] writePolicy The buffer data write policy to be used, default is WritePolicy::RETAIN
67 GpuBuffer(Graphics::Controller& graphicsController, Graphics::BufferUsageFlags usage, GpuBuffer::WritePolicy writePolicy);
70 * Destructor, non virtual as no virtual methods or inheritance
72 ~GpuBuffer() = default;
75 * Creates or updates a buffer object and binds it to the target.
76 * @param graphicsController The graphics controller
77 * @param size Specifies the size in bytes of the buffer object's new data store.
78 * @param data pointer to the data to load
80 void UpdateDataBuffer(Graphics::Controller& graphicsController, uint32_t size, const void* data);
83 * Updates existing buffer by calling associated VertexBufferUpdateCallback
85 * bytesUpdatedCount limits next draw call to that amount of data.
87 * @param[in] graphicsController Valid controller
88 * @param[in] callback Valid pointer to the VertexBufferUpdateCallback
89 * @param[out] bytesUpdatedCount Number of bytes updated
91 void UpdateDataBufferWithCallback(Graphics::Controller& graphicsController, Dali::VertexBufferUpdateCallback* callback, uint32_t& bytesUpdatedCount);
94 * Get the size of the buffer
95 * @return size Size of the buffer in bytes
97 [[nodiscard]] uint32_t GetBufferSize() const
102 [[nodiscard]] inline const Graphics::Buffer* GetGraphicsObject() const
104 return mGraphicsObject.get();
108 * Destroy the graphics buffer and reset.
113 Graphics::UniquePtr<Graphics::Buffer> mGraphicsObject;
114 uint32_t mCapacity{0}; ///< buffer capacity
115 uint32_t mSize{0}; ///< buffer size
116 Graphics::BufferUsageFlags mUsage;
117 WritePolicy mWritePolicy{WritePolicy::RETAIN}; ///< data write policy for the buffer
120 } // namespace Internal
123 #endif // DALI_INTERNAL_RENDERERS_GPU_BUFFER_H