buffer allocation
[demo] / src / vulkan / mesh-vk.cc
index d9d6665..c190199 100644 (file)
@@ -1,11 +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)
@@ -17,16 +22,46 @@ 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();
+}
+
+bool MeshVK::update_vertex_data()
+{
+       if(vertices.empty()) {
+               printf("empty vertices!\n");
+               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;
+       }
+
+       return true;
 }
 
-void MeshVK::update_vertex_data()
+void MeshVK::draw() const
 {
-}
\ No newline at end of file
+}
+
+void MeshVK::draw_normals(float scale) const
+{
+}