~sircmpwn/xrgears

ref: fb9d492b99b8bb61f3c60bd3c976bccb800df57d xrgears/vkc/vkcRenderer.hpp -rw-r--r-- 1.6 KiB
fb9d492b — Lubosz Sarnecki move surface and format to swapchain. 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once

#include "vkcSwapChainVK.hpp"
#include "vkcSwapChainDRM.hpp"
#include "vikRenderer.hpp"

namespace vkc {

class Renderer : public vik::Renderer {
public:
  vik::SwapChain *swap_chain;

  VkPipelineLayout pipeline_layout;
  VkPipeline pipeline;
  VkDeviceMemory mem;
  VkBuffer buffer;
  VkDescriptorSet descriptor_set;
  VkSemaphore semaphore;
  VkFence fence;
  VkCommandPool cmd_pool;

  timeval start_tv;

  VkCommandBuffer cmd_buffer;

  uint32_t vertex_offset, colors_offset, normals_offset;

  Renderer(uint32_t w, uint32_t h) ;
  ~Renderer() ;

  void init_vk(const char *extension);
  void init_render_pass();
  void init_vk_objects();
  void submit_queue();

  void wait_and_reset_fences();

  uint64_t get_animation_time();

  void build_command_buffer(VkFramebuffer frame_buffer);

  void render(uint32_t index);

  void render_swapchain_vk();

  void create_frame_buffer(VkImageView *view, VkFramebuffer *frame_buffer) {
    VkFramebufferCreateInfo framebufferinfo = {};
    framebufferinfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
    framebufferinfo.renderPass = render_pass;
    framebufferinfo.attachmentCount = 1;
    framebufferinfo.pAttachments = view;
    framebufferinfo.width = width;
    framebufferinfo.height = height;
    framebufferinfo.layers = 1;
    vkCreateFramebuffer(device,
                        &framebufferinfo,
                        NULL,
                        frame_buffer);
  }

  void create_frame_buffers() {
    frame_buffers.resize(swap_chain->image_count);
    for (uint32_t i = 0; i < swap_chain->image_count; i++) {
      create_frame_buffer(&swap_chain->buffers[i].view, &frame_buffers[i]);
    }
  }

};
}