// Copyright (C) 2023 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 #include #include #include #include #include namespace Nz { SoftwareBuffer::SoftwareBuffer(BufferType type, UInt64 size, BufferUsageFlags usage, const void* initialData) : Buffer(DataStorage::Software, type, size, usage | BufferUsage::DirectMapping | BufferUsage::Dynamic | BufferUsage::PersistentMapping | BufferUsage::Read | BufferUsage::Write), m_mapped(false) { m_buffer = std::make_unique(size); if (initialData) std::memcpy(&m_buffer[0], initialData, size); } bool SoftwareBuffer::Fill(const void* data, UInt64 offset, UInt64 size) { NazaraAssert(!m_mapped, "Buffer is already mapped"); std::memcpy(&m_buffer[offset], data, size); return true; } const UInt8* SoftwareBuffer::GetData() const { return &m_buffer[0]; } void* SoftwareBuffer::Map(UInt64 offset, UInt64 /*size*/) { NazaraAssert(!m_mapped, "Buffer is already mapped"); m_mapped = true; return &m_buffer[offset]; } bool SoftwareBuffer::Unmap() { NazaraAssert(m_mapped, "Buffer is not mapped"); m_mapped = false; return true; } std::shared_ptr SoftwareBufferFactory(BufferType type, UInt64 size, BufferUsageFlags usage, const void* initialData) { return std::make_shared(type, size, usage, initialData); } }