-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.cpp
More file actions
52 lines (44 loc) · 1.61 KB
/
Window.cpp
File metadata and controls
52 lines (44 loc) · 1.61 KB
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
#include "Window.hpp"
#include <iostream>
#include <stdexcept>
namespace engine {
Window::Window(int w, int h, std::string name) : width{ w }, height{ h }, windowName{ name } {
initWindow();
}
Window::~Window() {
SDL_DestroyWindow(window);
SDL_Quit();
}
void Window::initWindow() {
// Create an SDL window that supports Vulkan rendering.
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
std::cout << "Could not initialize SDL." << std::endl;
}
window = SDL_CreateWindow(windowName.c_str(), SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, width, height,
SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE);
if (window == NULL) {
std::cout << "Could not create SDL window." << std::endl;
}
}
void Window::createWindowSurface(VkInstance instance, VkSurfaceKHR* surface) {
if (!SDL_Vulkan_CreateSurface(window, static_cast<VkInstance>(instance), surface)) {
throw std::runtime_error("failed to create window surface");
return;
}
}
void Window::recreateWindowSurface(VkInstance instance, VkSurfaceKHR* surface) {
vkDestroySurfaceKHR(instance, *surface, nullptr);
if (!SDL_Vulkan_CreateSurface(window, static_cast<VkInstance>(instance), surface)) {
throw std::runtime_error("failed to create window surface");
return;
}
}
void Window::framebufferResizeCallback() {
int w, h;
SDL_GetWindowSize(window, &w, &h);
framebufferResized = true;
width = w;
height = h;
}
} // namespace engine