-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVulkanBuffers.cpp
43 lines (37 loc) · 1.19 KB
/
VulkanBuffers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/******************************************************************************
This file is part of the Newcastle Vulkan Tutorial Series
Author:Rich Davison
Contact:richgdavison@gmail.com
License: MIT (see LICENSE file at the top of the source tree)
*//////////////////////////////////////////////////////////////////////////////
#include "VulkanBuffers.h"
using namespace NCL;
using namespace Rendering;
using namespace Vulkan;
void VulkanBuffer::CopyData(void* data, size_t size) {
if (allocationInfo.pMappedData) {
//we're already mapped, can just copy
memcpy(allocationInfo.pMappedData, data, size);
}
else {
//We should be able to safely map this?
void* mappedData = nullptr;
vmaMapMemory(allocator, allocationHandle, &mappedData);
memcpy(mappedData, data, size);
vmaUnmapMemory(allocator, allocationHandle);
}
}
void* VulkanBuffer::Map() const {
if (allocationInfo.pMappedData) {
return allocationInfo.pMappedData;
}
void* mappedData = nullptr;
vmaMapMemory(allocator, allocationHandle, &mappedData);
return mappedData;
}
void VulkanBuffer::Unmap() const {
vmaUnmapMemory(allocator, allocationHandle);
}
void* VulkanBuffer::Data() const{
return allocationInfo.pMappedData;
}