-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquad_mesh.cpp
41 lines (37 loc) · 1.41 KB
/
quad_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
32
33
34
35
36
37
38
39
40
41
//
// Created by daily on 19-01-24.
//
#include "quad_mesh.hpp"
QuadMesh::QuadMesh(vk::Device logical_device, vk::PhysicalDevice physical_device)
{
this->logical_device_ = logical_device;
std::vector<float> vertices = {
//eTriangleStrip
-0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f,
0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f,
0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f
//eTriangleList
// -0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f,
// 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f,
// -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f,
//
// 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f,
// 0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f,
// -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.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);
}
QuadMesh::~QuadMesh()
{
logical_device_.destroyBuffer(vertex_buffer.buffer);
logical_device_.freeMemory(vertex_buffer.buffer_memory);
}