*
*/
+// INTERNAL INCLUDES
#include <dali/graphics-api/graphics-controller.h>
-#include <memory>
-
-namespace Dali
-{
-namespace Internal
-{
-namespace Render
-{
-class UniformBuffer
+namespace Dali::Internal::Render
{
- friend class UniformBufferManager;
-
-private:
- /**
- * Constructor of UniformBuffer
- *
- * @param[in] mController Pointer of the graphics controller
- * @param[in] sizeInBytes initial size of allocated buffer
- * @param[in] alignment memory alignment in bytes
- * @param[in] persistentMappingEnabled if true, buffer is mapped persistently
- * @param[in] usageFlags type of usage ( Graphics::BufferUsage )
- */
- UniformBuffer(Dali::Graphics::Controller* mController,
- uint32_t sizeInBytes,
- uint32_t alignment,
- bool persistentMappingEnabled,
- Graphics::BufferUsageFlags usageFlags);
+class UniformBuffer;
+class UniformBufferView;
+class UniformBufferViewPool;
+/**
+ * Class UniformBufferManager
+ *
+ * Manages the uniform buffers.
+ *
+ */
+class UniformBufferManager
+{
public:
- /**
- * Destructor of UniformBuffer
- */
- ~UniformBuffer();
-
- /**
- * Writes data into the buffer
- *
- * @param[in] data pointer to the source data
- * @param[in] size size of source data
- * @param[in] offset destination offset
- */
- void Write(const void* data, uint32_t size, uint32_t offset);
-
- /**
- * Flushes whole buffer range
- */
- void Flush();
- /**
- * Returns allocated ( requested ) size
- * @return size of buffer
- */
- uint32_t GetSize() const
- {
- return mSize;
- }
+ explicit UniformBufferManager(Dali::Graphics::Controller* controller);
- /**
- * Return Graphics API buffer
- * @return pointer to the buffer object
- */
- Dali::Graphics::Buffer* GetBuffer() const
- {
- return mBuffer.get();
- }
+ ~UniformBufferManager();
/**
- * Returns memory alignment
- * @return memory alignment
+ * Allocates uniform buffer with given size and alignment
+ * @param size Size of uniform buffer
+ * @param alignment Alignment
+ * @return new UniformBuffer
*/
- uint32_t GetAlignment() const
- {
- return mAlignment;
- }
+ Graphics::UniquePtr<UniformBuffer> AllocateUniformBuffer(uint32_t size, uint32_t alignment = 256);
/**
- * Reserves buffer memory
+ * Creates a view on UniformBuffer
*
- * @param size requested size
+ * @param uniformBuffer
+ * @param size
+ * @return Uniform buffer view
*/
- void Reserve(uint32_t size);
+ Graphics::UniquePtr<UniformBufferView> CreateUniformBufferView( UniformBuffer* uniformBuffer, uint32_t offset, uint32_t size);
/**
- * Maps buffer memory
+ * Creates uniform buffer pool view
+ * @param size
+ * @return
*/
- void Map();
+ Graphics::UniquePtr<UniformBufferViewPool> CreateUniformBufferViewPool();
/**
- * Unmaps buffer memory
+ * Returns Controller object
+ * @return controller object
*/
- void Unmap();
+ [[nodiscard]] Graphics::Controller& GetController() const
+ {
+ return *mController;
+ }
/**
- * Fills the buffer from the given offset with given data ( single 8bit value )
- * @param data char type data
- * @param offset start offset
- * @param size size to write, 0 if whole size
+ * Returns embedded uniform buffer pool view for specified DAli buffer index
+ * @return Pointer to valid uniform buffer pool view
*/
- void Fill(char data, uint32_t offset, uint32_t size);
+ [[nodiscard]] UniformBufferViewPool* GetUniformBufferViewPool( uint32_t bufferIndex );
private:
- Graphics::UniquePtr<Graphics::Buffer> mBuffer;
- Dali::Graphics::Controller* mController;
- Graphics::UniquePtr<Graphics::Memory> mMemory{nullptr};
-
- Graphics::MapBufferInfo mMapBufferInfo{};
-
- uint32_t mCapacity{0}; ///< buffer capacity
- uint32_t mSize; ///< buffer size
- uint32_t mAlignment{0};
- bool mPersistentMappedEnabled;
-
- Graphics::BufferUsageFlags mUsageFlags;
-};
-
-class UniformBufferManager
-{
-public:
- UniformBufferManager(Dali::Graphics::Controller* controller);
-
- ~UniformBufferManager();
- /**
- * Allocates uniform buffer with given size
- * @param size
- * @return
- */
- Graphics::UniquePtr<UniformBuffer> AllocateUniformBuffer(uint32_t size);
-
-private:
Dali::Graphics::Controller* mController;
+
+ Graphics::UniquePtr<UniformBufferViewPool> mUniformBufferPoolStorage[2u]; ///< The pool view into UniformBuffer (double buffered)
};
-} // namespace Render
-} // namespace Internal
} // namespace Dali
#endif // DALI_INTERNAL_UNIFORM_BUFFER_MANAGER_H