Skip to content
Snippets Groups Projects
Commit be623d75 authored by n0F4x's avatar n0F4x
Browse files

Refactor GLFW initialization

parent 142073bd
No related branches found
No related tags found
No related merge requests found
......@@ -174,7 +174,7 @@ static auto create_render_pass(const vk::Format color_format, const vk::Device d
.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite,
};
const vk::RenderPassCreateInfo render_pass_create_info{
const vk::RenderPassCreateInfo create_info{
.attachmentCount = static_cast<uint32_t>(attachment_descriptions.size()),
.pAttachments = attachment_descriptions.data(),
.subpassCount = 1,
......@@ -183,7 +183,7 @@ static auto create_render_pass(const vk::Format color_format, const vk::Device d
.pDependencies = &subpass_dependency,
};
return device.createRenderPassUnique(render_pass_create_info);
return device.createRenderPassUnique(create_info);
}
Renderer::Renderer(const Window& window)
......
......@@ -3,21 +3,35 @@
#include <format>
#include <stdexcept>
[[nodiscard]]
static auto
create_window(const uint16_t width, const uint16_t height, const std::string& title)
-> GLFWwindow*
static void init_glfw()
{
if (const auto error_code{ glfwInit() }; error_code != GLFW_TRUE) {
if (const int success{ glfwInit() }; success != GLFW_TRUE) {
const char* description{};
const int error_code{ glfwGetError(&description) };
if (description == nullptr) {
throw std::runtime_error{
std::format("glfwInit failed with error code {}", error_code)
};
}
if (const auto result{ std::atexit(glfwTerminate) }; result != 0) {
throw std::runtime_error{ std::format(
"glfwInit failed with error code {} - '{}'", error_code, description
) };
}
if (const int result{ std::atexit(glfwTerminate) }; result != 0) {
throw std::runtime_error{
std::format("std::atexit(glfwTerminate) failed with error code {}", result)
std::format("std::atexit failed with error code {}", result)
};
}
}
[[nodiscard]]
static auto
create_window(const uint16_t width, const uint16_t height, const std::string& title)
-> GLFWwindow*
{
init_glfw();
glfwDefaultWindowHints();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
......@@ -34,9 +48,7 @@ static auto
auto Window::vulkan_instance_extensions() -> std::span<const char* const>
{
static const std::vector s_extension_names{ []() -> std::vector<const char*> {
if (glfwInit() != GLFW_TRUE) {
return {};
}
init_glfw();
uint32_t count{};
const char** glfw_extension_names{ glfwGetRequiredInstanceExtensions(&count) };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment