X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fvulkan%2Fmesh-vk.cc;h=2c55013f7f515569173af9e31c1d801cf2779ce1;hb=8d1aef17df1bf15491ce4fd35242adcd58a9c411;hp=89594f2e9c79cdfd01e8bbb09ba0f69c202284d0;hpb=243eb502c5dc70e586a9e81815234069bf623480;p=demo diff --git a/src/vulkan/mesh-vk.cc b/src/vulkan/mesh-vk.cc index 89594f2..2c55013 100644 --- a/src/vulkan/mesh-vk.cc +++ b/src/vulkan/mesh-vk.cc @@ -1,11 +1,16 @@ +#include #include "mesh-vk.h" -MeshVK::MeshVK() {} +MeshVK::MeshVK() +{ +} + MeshVK::MeshVK(const MeshVK &mesh) { indices = mesh.indices; vertices = mesh.vertices; normals = mesh.normals; + tex_coords = mesh.tex_coords; } MeshVK &MeshVK::operator=(const MeshVK &mesh) @@ -17,18 +22,62 @@ MeshVK &MeshVK::operator=(const MeshVK &mesh) indices = mesh.indices; vertices = mesh.vertices; normals = mesh.normals; + tex_coords = mesh.tex_coords; return *this; } MeshVK::~MeshVK() { + vku_destroy_buffer(vk_vertices); + vku_destroy_buffer(vk_normals); + vku_destroy_buffer(vk_tex_coords); + vku_destroy_buffer(vk_indices); + vertices.clear(); normals.clear(); + tex_coords.clear(); + indices.clear(); } -void MeshVK::update_vertex_data() +bool MeshVK::update_vertex_data() { + if(vertices.empty()) { + printf("empty vertices!\n"); + return false; + } + + /* create the buffers */ + + if(!(vk_vertices = vku_create_buffer(vertices.size() * sizeof(Vec3), + VK_BUFFER_USAGE_VERTEX_BUFFER_BIT))) { + fprintf(stderr, "Failed to create the buffer for the vertices.\n"); + return false; + } + + if(!(vk_normals = vku_create_buffer(normals.size() * sizeof(Vec3), + VK_BUFFER_USAGE_VERTEX_BUFFER_BIT))) { + fprintf(stderr, "Failed to create the buffer for the normals.\n"); + return false; + } + + if(!(vk_tex_coords = vku_create_buffer(tex_coords.size() * sizeof(Vec2), + VK_BUFFER_USAGE_VERTEX_BUFFER_BIT))) { + fprintf(stderr, + "Failed to create the buffer for the texture coordinates.\n"); + return false; + } + + if(!(vk_indices = vku_create_buffer(indices.size() * 2, + VK_BUFFER_USAGE_INDEX_BUFFER_BIT))) { + fprintf(stderr, "Failed to create the indices buffer.\n"); + return false; + } + + //TODO XXX + /* map the buffers */ + + return true; } void MeshVK::draw() const @@ -37,4 +86,4 @@ void MeshVK::draw() const void MeshVK::draw_normals(float scale) const { -} \ No newline at end of file +}