-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriangle_mesh.cpp
31 lines (29 loc) · 1.05 KB
/
triangle_mesh.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
//
// Created by daily on 02-01-24.
//
#include "triangle_mesh.hpp"
TriangleMesh::TriangleMesh(vk::Device logical_device, vk::PhysicalDevice physical_device)
{
this->logical_device_ = logical_device;
std::vector<float> vertices = {
{
0.0f, -0.05f, 0.0f, 1.0f, 0.0f,
0.05f, 0.05f, 0.0f, 1.0f, 0.0f,
-0.05f, 0.05f, 0.0f, 1.0f, 0.0f
}
};
BufferInput inputChunk;
inputChunk.logical_device = logical_device;
inputChunk.physical_device = physical_device;
inputChunk.size = sizeof(float) * vertices.size();
inputChunk.usage = vk::BufferUsageFlagBits::eVertexBuffer;
vertex_buffer = vkutil::createBuffer(inputChunk);
void* memoryLocation = logical_device.mapMemory(vertex_buffer.buffer_memory, 0, inputChunk.size);
memcpy(memoryLocation, vertices.data(), inputChunk.size);
logical_device.unmapMemory(vertex_buffer.buffer_memory);
}
TriangleMesh::~TriangleMesh()
{
logical_device_.destroyBuffer(vertex_buffer.buffer);
logical_device_.freeMemory(vertex_buffer.buffer_memory);
}