scop
a small 3D object loader
Loading...
Searching...
No Matches
VulkanIndex.cpp
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* VulkanIndex.cpp :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: rbourgea <rbourgea@student.42.fr> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/01/12 07:12:35 by rbourgea #+# #+# */
9/* Updated: 2024/01/12 07:13:31 by rbourgea ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "VulkanApp.hpp"
14
16 VkDeviceSize bufferSize = sizeof(indices[0]) * indices.size();
17
18 VkBuffer stagingBuffer;
19 VkDeviceMemory stagingBufferMemory;
20 createBuffer(bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, stagingBuffer, stagingBufferMemory);
21
22 void* data;
23 vkMapMemory(device, stagingBufferMemory, 0, bufferSize, 0, &data);
24 memcpy(data, indices.data(), (size_t) bufferSize);
25 vkUnmapMemory(device, stagingBufferMemory);
26
27 createBuffer(bufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, indexBuffer, indexBufferMemory);
28
29 copyBuffer(stagingBuffer, indexBuffer, bufferSize);
30
31 vkDestroyBuffer(device, stagingBuffer, nullptr);
32 vkFreeMemory(device, stagingBufferMemory, nullptr);
33}
std::vector< uint32_t > indices
VkDevice device
void copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size)
VkBuffer indexBuffer
void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory)
void createIndexBuffer()
VkDeviceMemory indexBufferMemory