window resize handled, instance improved a bit

This commit is contained in:
Blue 2023-10-14 19:57:47 -03:00
parent e114c36690
commit 2b33897b4a
Signed by: blue
GPG key ID: 9B203B252A63EE38
16 changed files with 182 additions and 115 deletions

View file

@ -1,18 +1,11 @@
#include "window.h"
#include <iostream>
Engine::Window::Window(uint32_t width, uint32_t height) :
sdl(createWindow(width, height)),
extent({width, height})
{
//glfwSetWindowUserPointer(window, this);
//glfwSetFramebufferSizeCallback(window, framebufferResizeCallback);
}
// static void framebufferResizeCallback(SDL_Window* window, int width, int height) {
// auto app = reinterpret_cast<HelloTriangleApplication*>(glfwGetWindowUserPointer(window));
// app->framebufferResized = true;
// }
{}
Engine::Window::~Window() {
SDL_DestroyWindow(sdl);
@ -27,7 +20,7 @@ SDL_Window* Engine::Window::createWindow(uint32_t width, uint32_t height) {
SDL_WINDOWPOS_UNDEFINED,
width,
height,
SDL_WINDOW_VULKAN
SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE
);
return wnd;
@ -59,6 +52,18 @@ VkExtent2D Engine::Window::getDrawableSize() const {
return actualExtent;
}
VkExtent2D Engine::Window::getSize() const {
int width, height;
SDL_GetWindowSize(sdl, &width, &height);
VkExtent2D actualExtent = {
static_cast<uint32_t>(width),
static_cast<uint32_t>(height)
};
return actualExtent;
}
void Engine::Window::createSurface(VkInstance instance, VkSurfaceKHR* out) const {
if (SDL_Vulkan_CreateSurface(sdl, instance, out) != SDL_TRUE) {
throw std::runtime_error("failed to create window surface!");
@ -74,6 +79,7 @@ VkExtent2D Engine::Window::chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capa
actualExtent.width = std::clamp(actualExtent.width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width);
actualExtent.height = std::clamp(actualExtent.height, capabilities.minImageExtent.height, capabilities.maxImageExtent.height);
std::cout << actualExtent.width << ":" << actualExtent.height << std::endl;
return actualExtent;
}
}