// Copyright (C) 2021 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_UTILITY_BUFFER_HPP #define NAZARA_UTILITY_BUFFER_HPP #include #include #include #include #include #include #include namespace Nz { class NAZARA_UTILITY_API Buffer { friend class Utility; public: using BufferFactory = std::function(Buffer* parent, BufferType type)>; Buffer(BufferType type); Buffer(BufferType type, UInt32 size, DataStorage storage = DataStorage::Software, BufferUsageFlags usage = 0); Buffer(const Buffer&) = delete; Buffer(Buffer&&) = delete; ~Buffer() = default; bool CopyContent(const Buffer& buffer); bool Create(UInt32 size, DataStorage storage = DataStorage::Software, BufferUsageFlags usage = 0); void Destroy(); bool Fill(const void* data, UInt32 offset, UInt32 size); inline AbstractBuffer* GetImpl() const; inline UInt32 GetSize() const; inline DataStorage GetStorage() const; inline BufferType GetType() const; inline BufferUsageFlags GetUsage() const; inline bool HasStorage(DataStorage storage) const; inline bool IsValid() const; void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0); void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) const; bool SetStorage(DataStorage storage); void Unmap() const; Buffer& operator=(const Buffer&) = delete; Buffer& operator=(Buffer&&) = delete; static bool IsStorageSupported(DataStorage storage); static void SetBufferFactory(DataStorage storage, BufferFactory func); private: static bool Initialize(); static void Uninitialize(); std::unique_ptr m_impl; BufferType m_type; BufferUsageFlags m_usage; UInt32 m_size; static std::array s_bufferFactories; }; } #include #endif // NAZARA_UTILITY_BUFFER_HPP