// Copyright (C) 2020 Jérôme Leclercq // 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_BUFFER_HPP #define NAZARA_BUFFER_HPP #include #include #include #include #include #include #include #include namespace Nz { class Buffer; using BufferConstRef = ObjectRef; using BufferRef = ObjectRef; class NAZARA_UTILITY_API Buffer : public RefCounted { friend class Utility; public: using BufferFactory = AbstractBuffer* (*)(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(); bool CopyContent(const BufferRef& 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); template static BufferRef New(Args&&... args); static void SetBufferFactory(DataStorage storage, BufferFactory func); // Signals: NazaraSignal(OnBufferDestroy, const Buffer* /*buffer*/); NazaraSignal(OnBufferRelease, const Buffer* /*buffer*/); 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_BUFFER_HPP