X-Git-Url: https://eleni.mutantstargoat.com/git/?a=blobdiff_plain;f=src%2Fvulkan%2Fmesh-vk.cc;h=494389b00daa4f2c6ea9ab29529aca6f8cac30d4;hb=c3d7c1b7f8a7f4bcfc7661b6baf166ce0648083a;hp=2c55013f7f515569173af9e31c1d801cf2779ce1;hpb=8d1aef17df1bf15491ce4fd35242adcd58a9c411;p=demo diff --git a/src/vulkan/mesh-vk.cc b/src/vulkan/mesh-vk.cc index 2c55013..494389b 100644 --- a/src/vulkan/mesh-vk.cc +++ b/src/vulkan/mesh-vk.cc @@ -1,4 +1,5 @@ #include +#include "allocator.h" #include "mesh-vk.h" MeshVK::MeshVK() @@ -49,33 +50,63 @@ bool MeshVK::update_vertex_data() /* create the buffers */ - if(!(vk_vertices = vku_create_buffer(vertices.size() * sizeof(Vec3), + int vsz = vertices.size() * sizeof(Vec3); + if(!(vk_vertices = vku_create_buffer(vsz, 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), + int nsz = normals.size() * sizeof(Vec3); + if(!(vk_normals = vku_create_buffer(nsz, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT))) { + vku_destroy_buffer(vk_vertices); + 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), + int tsz = tex_coords.size() * sizeof(Vec2); + if(!(vk_tex_coords = vku_create_buffer(tsz, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT))) { + vku_destroy_buffer(vk_vertices); + vku_destroy_buffer(vk_normals); + fprintf(stderr, "Failed to create the buffer for the texture coordinates.\n"); return false; } - if(!(vk_indices = vku_create_buffer(indices.size() * 2, + int isz = indices.size() * 2; + if(!(vk_indices = vku_create_buffer(isz, VK_BUFFER_USAGE_INDEX_BUFFER_BIT))) { + vku_destroy_buffer(vk_vertices); + vku_destroy_buffer(vk_normals); + vku_destroy_buffer(vk_tex_coords); + fprintf(stderr, "Failed to create the indices buffer.\n"); return false; } - //TODO XXX - /* map the buffers */ + /* write the buffers */ + + if(!vku_write_memory(vk_vertices->mem_pool, vsz, (void*)vertices.data())) { + fprintf(stderr, "Failed to write the vertices on GPU.\n"); + return false; + } + if(!vku_write_memory(vk_normals->mem_pool, nsz, (void*)normals.data())) { + fprintf(stderr, "Failed to write the normalson GPU.\n"); + return false; + } + if(!vku_write_memory(vk_tex_coords->mem_pool, tsz, + (void*)tex_coords.data())) { + fprintf(stderr, "Failed to write the texture coordinates on GPU.\n"); + return false; + } + if(!vku_write_memory(vk_indices->mem_pool, isz, (void*)indices.data())) { + fprintf(stderr, "Failed to write the indices on GPU.\n"); + return false; + } return true; }