-
Notifications
You must be signed in to change notification settings - Fork 1
/
scene.h
95 lines (74 loc) · 2.81 KB
/
scene.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
// Copyright(c) Leonardo Romor <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://gnu.org/licenses/gpl-2.0.txt>
#ifndef __SIMPLE_SCENE_H_
#define __SIMPLE_SCENE_H_
#include <iostream>
#include <vulkan/vulkan.hpp>
#include "vulkan-core.h"
#include "entity.h"
#include "input/gamepad.h"
#include "camera.h"
// Given an initialized vulkan context
// perform rendering of the entities.
class Scene {
public:
typedef std::function<vk::Extent2D()> QueryExtentCallback;
Scene(space::core::VkAppContext *context, Camera *camera, const QueryExtentCallback &fn);
void Init();
void AddEntity(space::Entity *entity);
void SubmitRendering();
void Present();
private:
space::core::VkAppContext *const vk_ctx_;
const QueryExtentCallback QueryExtent;
vk::UniqueCommandPool command_pool_;
vk::Queue graphics_queue_;
vk::Queue present_queue_;
vk::UniqueDescriptorSetLayout descriptor_set_layout_;
// The pipeline layout used to describe
// how descriptors should be used.
vk::UniquePipelineLayout pipeline_layout_;
vk::UniquePipelineCache pipeline_cache_;
// Define the set of objects to be recreated
// in case of an out-of-date swapchain.
struct SwapChainContext {
vk::UniqueCommandBuffer command_buffer;
space::core::SwapChainData swap_chain_data;
vk::SampleCountFlagBits max_sampling;
// For multisampling
space::core::ImageData color_buffer_data;
// Depth buffer data. Contains the resulting
// depth pseudoimage.
space::core::DepthBufferData depth_buffer_data;
// Uniform buffer containing projection matrix
// and other shared buffers.
space::core::BufferData uniform_buffer_data;
// We are using a single render pass
vk::UniqueRenderPass render_pass;
std::vector<vk::UniqueFramebuffer> framebuffers;
vk::UniqueDescriptorPool descriptor_pool;
vk::UniqueDescriptorSet descriptor_set;
};
std::unique_ptr<SwapChainContext> swap_chain_context_;
// Creates a new swapchain and returns the old one.
void CreateSwapChainContext();
uint32_t current_buffer_;
// Fence for when the rendering is done
// and we are ready to present :)
vk::UniqueFence draw_fence_;
std::vector<space::Entity *> entities_;
Camera *camera_;
};
#endif // __SIMPLE_SCENE_H_