-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathView_old.hpp
213 lines (170 loc) · 4.87 KB
/
View_old.hpp
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*#pragma once
#include <set>
#include <vulkan/vulkan.hpp>
#include <SDL2/SDL_vulkan.h>
#include <SDL2/SDL.h>
#include "VkBootsrap.h"
#include "Game.hpp"
//#include "Controller.hpp"
#include "PipelineBuilder.hpp"
#include "Structs.hpp"
#define CLAMP(x, lo, hi) ((x) < (lo) ? (lo) : (x) > (hi) ? (hi) : (x))
constexpr int WIDTH = 800;
constexpr int HEIGHT = 600;
constexpr bool enableValidationLayers = true;
constexpr std::array<const char *, 1> VALIDATION_LAYERS{
//"VK_LAYER_LUNARG_standard_validation"
"VK_LAYER_KHRONOS_validation"
};
class View {
public:
//View(Game &_game, Controller &_controller);
View(Game &_game);
~View();
// render loop
void repaint();
void initialize();
// render pipeline
void createPipeline(VkPipeline &_pipeline, int _mode);
// render pass
void acquireNextImage();
void resetCommandBuffer();
void beginCommandBuffer();
void endCommandBuffer();
void freeCommandBuffer();
void beginRenderpass(VkClearColorValue _clearColor, VkClearDepthStencilValue _clearDepthStencil);
void endRenderpass();
void queueSubmit();
void queuePresent();
void setViewport(int _width, int _height);
void setScissor(int _width, int _height);
//
// setup and initialization
//////////////////////////////////////
// core
void initSDL();
void createWindow();
void createInstance();
void createDebug();
void createSurface();
void selectPhysicalDevice();
void selectQueueFamily();
void createDevice();
// screen
bool createSwapchain();
VkImageView createImageView(VkImage _img, VkFormat _fmt, VkImageAspectFlags _flags);
void createImageViews();
void setupDepthStencil();
void createRenderpass();
void createFramebuffer();
// command
void createCommandPool();
void createCommandBuffers();
void createSemaphores();
void createSemaphore(VkSemaphore *_semaphore);
void createFences();
// cleanup
void cleanup();
DeletionQueue m_deletionQueue;
// utility
void createImage(uint32_t _width, uint32_t _height, VkFormat _format,
VkImageTiling _tiling, VkImageUsageFlags _usage,
VkMemoryPropertyFlags _properties, VkImage &_image,
VkDeviceMemory &_imageMemory);
uint32_t findMemoryByType(uint32_t _typeFilter, VkMemoryPropertyFlags _props);
/////////////////////////////////////////
SDL_Window *getWindow() { return m_window; }
VkInstance *getInstance(){ return &m_instance; }
// project
int m_shaderMode;
private:
// project
Game *m_game;
//Controller *m_controller;
VkShaderModule m_vShader;
VkShaderModule m_vShader2;
VkShaderModule m_fShader;
// vulkan
VkDebugReportCallbackEXT m_debugCallback;
VkInstance m_instance;
VkSurfaceKHR m_surface;
VkPhysicalDevice m_physicalDevice;
uint32_t m_graphics_queueFamilyIndex;
uint32_t m_present_queueFamilyIndex;
VkDevice m_logicalDevice;
VkQueue m_graphicsQueue;
VkQueue m_presentQueue;
//
// WINDOW
//////////////////////
SDL_Window *m_window;
VkSwapchainKHR m_swapchain;
VkSurfaceCapabilitiesKHR m_surfaceCapabilities;//
VkSurfaceFormatKHR m_surfaceFormat;//
VkExtent2D m_swapchainSize;//
std::vector<VkImage> m_swapchainImages;//
uint32_t m_swapchainImageCount;//
std::vector<VkImageView> m_swapchainImageViews;
VkFormat m_depthFormat;//
VkImage m_depthImage;//
VkDeviceMemory m_depthImageMemory;//
VkImageView m_depthImageView;//
VkRenderPass m_renderpass;//
std::vector<VkFramebuffer> m_swapchainFramebuffers;
//
// command
/////////////
VkCommandPool m_commandPool;
VkCommandBuffer m_commandBuffer;
std::vector<VkCommandBuffer> m_commandBuffers;
VkSemaphore m_imageAvailableSemaphore;
VkSemaphore m_renderingFinishedSemaphore;
std::vector<VkFence> m_fences;
//
// pipeline
///////////////
PipelineBuilder m_pipelineBuilder;
VkPipeline m_pipeline;
VkPipeline m_pipeline2;
//
// other
//////////
uint32_t m_frameIndex;
VkPipelineStageFlags m_waitDestStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
VkImage m_image;
/// <summary>
/// Debug/Callback utility functions
/// </summary>
public:
PFN_vkCreateDebugReportCallbackEXT SDL2_vkCreateDebugReportCallbackEXT = nullptr;
static VKAPI_ATTR VkBool32 VKAPI_CALL VulkanReportFunc(
VkDebugReportFlagsEXT flags,
VkDebugReportObjectTypeEXT objType,
uint64_t obj,
size_t location,
int32_t code,
const char *layerPrefix,
const char *msg,
void *userData) {
printf("VULKAN VALIDATION: %s\n", msg);
return VK_FALSE;
}
VkBool32 getSupportedDepthFormat(VkPhysicalDevice physicalDevice, VkFormat *depthFormat) {
std::vector<VkFormat> depthFormats = {
VK_FORMAT_D32_SFLOAT_S8_UINT,
VK_FORMAT_D32_SFLOAT,
VK_FORMAT_D24_UNORM_S8_UINT,
VK_FORMAT_D16_UNORM_S8_UINT,
VK_FORMAT_D16_UNORM
};
for (auto &format : depthFormats) {
VkFormatProperties formatProps;
vkGetPhysicalDeviceFormatProperties(physicalDevice, format, &formatProps);
if (formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
*depthFormat = format;
return true;
}
}
return false;
}
};