buffer allocation
[demo] / src / vulkan / mesh-vk.cc
index 2f0c5fb..c190199 100644 (file)
@@ -1,12 +1,16 @@
 #include <vulkan/vulkan.h>
 #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)
@@ -18,25 +22,40 @@ 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;
+               return false;
+       }
+
+       /* create vertex buffer */
+
+       if(!(vk_vertices = vku_create_buffer(vertices.size() * sizeof(Vec3),
+                                       VK_BUFFER_USAGE_VERTEX_BUFFER_BIT))) {
+               fprintf(stderr, "Failed to create vertex buffer.\n");
+               return false;
        }
 
-//     if(num_vertices != vertices.size()) {
-//     }
+       return true;
 }
 
 void MeshVK::draw() const