X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fvulkan%2Fmesh-vk.cc;h=52ad3a83ce16933dd86dd2e1d8aa3dbd62dd4a4b;hb=86c912d603be75ac8b2fdb2229f1696e9c0c01d9;hp=b495ea2844eedcfd20d965668cea0374a56eceda;hpb=fb89e67e6550d207d2a28599a420455d3c8f0f29;p=demo diff --git a/src/vulkan/mesh-vk.cc b/src/vulkan/mesh-vk.cc index b495ea2..52ad3a8 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() @@ -42,6 +43,7 @@ MeshVK::~MeshVK() bool MeshVK::update_vertex_data() { + return true; if(vertices.empty()) { printf("empty vertices!\n"); return false; @@ -49,32 +51,36 @@ bool MeshVK::update_vertex_data() /* create the buffers */ - if(!(vk_vertices = vku_create_buffer(vertices.size() * sizeof(Vec3), - VK_BUFFER_USAGE_VERTEX_BUFFER_BIT))) { + 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), - VK_BUFFER_USAGE_VERTEX_BUFFER_BIT))) { + 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), - VK_BUFFER_USAGE_VERTEX_BUFFER_BIT))) { + 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"); + "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))) { + 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); @@ -83,11 +89,48 @@ bool MeshVK::update_vertex_data() return false; } - /* 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 to GPU.\n"); + return false; + } + if(vkBindBufferMemory(vk_device, vk_vertices->buf, vk_vertices->mem_pool, + 0) != VK_SUCCESS) { + fprintf(stderr, "Failed to bind the vertex buffer memory\n"); + return false; + } - //TODO this is going to change when we allocate one mem block for all data, - //for the moment we map each buffer memory block and we set the data + if(!vku_write_memory(vk_normals->mem_pool, nsz, (void *)normals.data())) { + fprintf(stderr, "Failed to write the normals to GPU.\n"); + return false; + } + if(vkBindBufferMemory(vk_device, vk_normals->buf, vk_normals->mem_pool, 0) + != VK_SUCCESS) { + fprintf(stderr, "Failed to bind the normal buffer memory\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 to GPU.\n"); + return false; + } + if(vkBindBufferMemory(vk_device, vk_tex_coords->buf, + vk_tex_coords->mem_pool, 0) != VK_SUCCESS) { + fprintf(stderr, "Failed to bind the tex coordinates buffer memory.\n"); + return false; + } + + if(!vku_write_memory(vk_indices->mem_pool, isz, (void *)indices.data())) { + fprintf(stderr, "Failed to write the indices to GPU.\n"); + return false; + } + if(vkBindBufferMemory(vk_device, vk_indices->buf, vk_indices->mem_pool, 0) + != VK_SUCCESS) { + fprintf(stderr, "Failed to bind the index buffer memory.\n"); + return false; + } return true; }