Add and make use of Vulkan Memory Allocator
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_HARDWAREBUFFER_HPP
|
||||
#define NAZARA_HARDWAREBUFFER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Buffer;
|
||||
|
||||
class HardwareBuffer : public AbstractBuffer
|
||||
{
|
||||
public:
|
||||
HardwareBuffer(Buffer* parent, BufferType type);
|
||||
~HardwareBuffer();
|
||||
|
||||
bool Fill(const void* data, UInt32 offset, UInt32 size) override;
|
||||
|
||||
bool Initialize(unsigned int size, BufferUsageFlags usage) override;
|
||||
|
||||
DataStorage GetStorage() const override;
|
||||
|
||||
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) override;
|
||||
bool Unmap() override;
|
||||
|
||||
// Fonctions OpenGL
|
||||
void Bind() const;
|
||||
GLuint GetOpenGLID() const;
|
||||
|
||||
private:
|
||||
GLuint m_buffer;
|
||||
BufferType m_type;
|
||||
Buffer* m_parent;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_HARDWAREBUFFER_HPP
|
||||
@@ -31,11 +31,10 @@ namespace Nz
|
||||
|
||||
AbstractBuffer* RenderBuffer::GetHardwareBuffer(RenderDevice* device)
|
||||
{
|
||||
auto it = m_hardwareBuffers.find(device);
|
||||
if (it == m_hardwareBuffers.end())
|
||||
return nullptr;
|
||||
if (HardwareBuffer* hwBuffer = GetHardwareBufferData(device))
|
||||
return hwBuffer->buffer.get();
|
||||
|
||||
return it->second.buffer.get();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DataStorage RenderBuffer::GetStorage() const
|
||||
@@ -65,6 +64,18 @@ namespace Nz
|
||||
}
|
||||
|
||||
bool RenderBuffer::Synchronize(RenderDevice* device)
|
||||
{
|
||||
HardwareBuffer* hwBuffer = GetHardwareBufferData(device);
|
||||
if (!hwBuffer)
|
||||
return false;
|
||||
|
||||
if (hwBuffer->synchronized)
|
||||
return true;
|
||||
|
||||
return hwBuffer->buffer->Fill(m_softwareBuffer.GetData(), 0, m_size);
|
||||
}
|
||||
|
||||
auto RenderBuffer::GetHardwareBufferData(RenderDevice* device) -> HardwareBuffer*
|
||||
{
|
||||
auto it = m_hardwareBuffers.find(device);
|
||||
if (it == m_hardwareBuffers.end())
|
||||
@@ -74,16 +85,13 @@ namespace Nz
|
||||
if (!hwBuffer.buffer->Initialize(m_size, m_usage))
|
||||
{
|
||||
NazaraError("Failed to initialize hardware buffer");
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
it = m_hardwareBuffers.emplace(device, std::move(hwBuffer)).first;
|
||||
}
|
||||
|
||||
HardwareBuffer& hwBuffer = it->second;
|
||||
if (hwBuffer.synchronized)
|
||||
return true;
|
||||
|
||||
return hwBuffer.buffer->Fill(m_softwareBuffer.GetData(), 0, m_size);
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user