backup - missing some
[demo] / src / vulkan / uniforms-vk.cc
1 #include <stdio.h>
2 #include <string.h>
3
4 #include "uniforms-vk.h"
5
6 UniformBufferVK::UniformBufferVK()
7 {
8         ubo = 0;
9 }
10
11 UniformBufferVK::~UniformBufferVK()
12 {
13         destroy();
14 }
15
16 bool UniformBufferVK::create(int size)
17 {
18         if(!(ubo = vku_create_buffer(size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT))) {
19                 fprintf(stderr, "Failed to create vulkan uniform buffer object.\n");
20                 return false;
21         }
22
23         if(!UniformBuffer::create(size)) {
24                 fprintf(stderr, "Failed to create uniform buffer object.\n");
25                 return false;
26         }
27         return true;
28 }
29
30 void UniformBufferVK::destroy()
31 {
32         vku_destroy_buffer(ubo);
33 }
34
35 void UniformBufferVK::bind(int binding) const
36 {
37         if(vkBindBufferMemory(vk_device, ubo->buf, ubo->mem_pool, 0) !=
38                 VK_SUCCESS) {
39                 fprintf(stderr, "Failed to bind ubo.\n");
40         }
41 }
42
43 bool UniformBufferVK::update(void *data)
44 {
45         if(!vku_update_buffer(ubo, size, data)) {
46                 fprintf(stderr, "Failed to update ubo.\n");
47                 return false;
48         }
49         return true;
50 }