Reached shader lessons. Stopping to refactor code.
This commit is contained in:
@@ -1,39 +1,40 @@
|
||||
#include "GlfwWindowManager.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "Logger.h"
|
||||
|
||||
// bool WindowManager::bGlfwInitialized = false;
|
||||
VkSurfaceKHR GlfwWindowManager::Surface = VK_NULL_HANDLE;
|
||||
GLFWwindow* GlfwWindowManager::Window = nullptr;
|
||||
|
||||
GlfwWindowManager::GlfwWindowManager() = default;
|
||||
|
||||
GlfwWindowManager::~GlfwWindowManager()
|
||||
{
|
||||
Cleanup();
|
||||
// Cleanup();
|
||||
}
|
||||
|
||||
GlfwWindowManager::GlfwWindowManager(GlfwWindowManager&& Other) noexcept
|
||||
: Window(Other.Window), Title(std::move(Other.Title)), Width(Other.Width), Height(Other.Height)
|
||||
{
|
||||
Other.Window = nullptr;
|
||||
}
|
||||
|
||||
GlfwWindowManager& GlfwWindowManager::operator=(GlfwWindowManager&& Other) noexcept
|
||||
{
|
||||
if (this != &Other)
|
||||
{
|
||||
Cleanup();
|
||||
|
||||
Window = Other.Window;
|
||||
Title = std::move(Other.Title);
|
||||
Width = Other.Width;
|
||||
Height = Other.Height;
|
||||
|
||||
Other.Window = nullptr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
// GlfwWindowManager::GlfwWindowManager(GlfwWindowManager&& Other) noexcept
|
||||
// : Window(Other.Window), Config(Other.Config), Surface(Other.Surface)
|
||||
//{
|
||||
// Other.Window = nullptr;
|
||||
// }
|
||||
//
|
||||
// GlfwWindowManager& GlfwWindowManager::operator=(GlfwWindowManager&& Other) noexcept
|
||||
//{
|
||||
// if (this != &Other)
|
||||
// {
|
||||
// Cleanup();
|
||||
//
|
||||
// Window = Other.Window;
|
||||
// Config = Other.Config;
|
||||
// Surface = Other.Surface;
|
||||
//
|
||||
// Other.Window = nullptr;
|
||||
// }
|
||||
//
|
||||
// return *this;
|
||||
// }
|
||||
|
||||
void GlfwWindowManager::Initialize(const FWindowConfig& Config)
|
||||
{
|
||||
@@ -42,29 +43,12 @@ void GlfwWindowManager::Initialize(const FWindowConfig& Config)
|
||||
return;
|
||||
}
|
||||
|
||||
this->Config = Config;
|
||||
|
||||
InitializeGlfw();
|
||||
|
||||
Title = Config.Title;
|
||||
Width = Config.Width;
|
||||
Height = Config.Height;
|
||||
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
glfwWindowHint(GLFW_RESIZABLE, Config.bResizable ? GLFW_TRUE : GLFW_FALSE);
|
||||
|
||||
Window = glfwCreateWindow(
|
||||
Width,
|
||||
Height,
|
||||
Title.c_str(),
|
||||
Config.bFullscreen ? glfwGetPrimaryMonitor() : nullptr,
|
||||
nullptr);
|
||||
|
||||
if (!Window)
|
||||
{
|
||||
Log::Error("Failed to create GLFW window");
|
||||
}
|
||||
}
|
||||
|
||||
void GlfwWindowManager::Cleanup()
|
||||
void GlfwWindowManager::Cleanup(VkInstance Instance)
|
||||
{
|
||||
if (!IsInitialized())
|
||||
{
|
||||
@@ -100,7 +84,7 @@ void GlfwWindowManager::WaitEvents() const
|
||||
|
||||
void GlfwWindowManager::SetTitle(const std::string& Title)
|
||||
{
|
||||
this->Title = Title;
|
||||
// this->Title = Title;
|
||||
|
||||
if (Window)
|
||||
{
|
||||
@@ -108,20 +92,44 @@ void GlfwWindowManager::SetTitle(const std::string& Title)
|
||||
}
|
||||
}
|
||||
|
||||
VkSurfaceKHR GlfwWindowManager::CreateSurface(VkInstance Instance) const
|
||||
void GlfwWindowManager::CreateSurface(VkInstance Instance)
|
||||
{
|
||||
if (!Window || !Instance)
|
||||
if (!Window)
|
||||
{
|
||||
return VK_NULL_HANDLE;
|
||||
Log::Error("Window not initialized.");
|
||||
}
|
||||
|
||||
VkSurfaceKHR Surface = VK_NULL_HANDLE;
|
||||
if (glfwCreateWindowSurface(Instance, Window, nullptr, &Surface) != VK_SUCCESS)
|
||||
if (!Instance)
|
||||
{
|
||||
Log::Error("Failed to create window surface");
|
||||
Log::Error("Instance is null.");
|
||||
}
|
||||
|
||||
return Surface;
|
||||
VkResult result = glfwCreateWindowSurface(Instance, Window, nullptr, &Surface);
|
||||
if (result != VK_SUCCESS)
|
||||
{
|
||||
std::string errorMsg;
|
||||
switch (result)
|
||||
{
|
||||
case VK_ERROR_EXTENSION_NOT_PRESENT:
|
||||
errorMsg = "VK_ERROR_EXTENSION_NOT_PRESENT - Required extension not present";
|
||||
break;
|
||||
case VK_ERROR_INITIALIZATION_FAILED:
|
||||
errorMsg = "VK_ERROR_INITIALIZATION_FAILED - Initialization failed";
|
||||
break;
|
||||
case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR:
|
||||
errorMsg = "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR - Native window already in use";
|
||||
break;
|
||||
default:
|
||||
errorMsg = "Unknown error code: " + std::to_string(result);
|
||||
break;
|
||||
}
|
||||
|
||||
Log::Error("Failed to create window surface: " + errorMsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log::Info("Window surface created successfully.");
|
||||
}
|
||||
}
|
||||
|
||||
void GlfwWindowManager::SetResizeCallback(GLFWwindowsizefun Callback)
|
||||
@@ -182,4 +190,23 @@ void GlfwWindowManager::InitializeGlfw()
|
||||
Log::Error("Failed to initialize GLFW");
|
||||
}
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
glfwWindowHint(GLFW_RESIZABLE, Config.bResizable ? GLFW_TRUE : GLFW_FALSE);
|
||||
|
||||
Window = glfwCreateWindow(
|
||||
Config.Width,
|
||||
Config.Height,
|
||||
Config.Title.c_str(),
|
||||
Config.bFullscreen ? glfwGetPrimaryMonitor() : nullptr,
|
||||
nullptr);
|
||||
|
||||
if (!Window)
|
||||
{
|
||||
Log::Error("Failed to create GLFW window");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log::Info("Created GLFW window successfully.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user