인스턴스 생성 구조 완료

This commit is contained in:
2025-04-02 01:45:40 +09:00
parent fa5f31e034
commit ca1a93945e
5 changed files with 54 additions and 1 deletions

View File

@@ -2,7 +2,10 @@
#include <cmath> #include <cmath>
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
#include <functional>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <gsl/gsl> #include <gsl/gsl>
#include <string> #include <string>
#include <string_view> #include <string_view>
#include "utilities.h"

5
include/utilities.h Normal file
View File

@@ -0,0 +1,5 @@
#pragma once
namespace veng {
bool streq(gsl::czstring left, gsl::czstring right);
}

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "glfw/glfw_window.h" #include "glfw/glfw_window.h"
namespace veng { namespace veng {
@@ -12,7 +13,9 @@ class Graphics final {
void InitializeVulkan(); void InitializeVulkan();
void CreateInstance(); void CreateInstance();
gsl::span<gsl::czstring> GetSuggestedExtentions(); static gsl::span<gsl::czstring> GetSuggestedExtentions();
static std::vector<VkExtensionProperties> GetSupprotedInstanceExtensions();
static bool AreAllExtensionsSupported(gsl::span<gsl::czstring> extensions);
VkInstance instance_ = nullptr; VkInstance instance_ = nullptr;
gsl::not_null<Window *> window_; gsl::not_null<Window *> window_;

9
src/utilities.cpp Normal file
View File

@@ -0,0 +1,9 @@
#include "utilities.h"
#include "precomp.h"
namespace veng {
bool streq(gsl::czstring left, gsl::czstring right) {
return std::strcmp(left, right) == 0;
}
} // namespace veng

View File

@@ -18,6 +18,7 @@ void Graphics::InitializeVulkan() { CreateInstance(); }
void Graphics::CreateInstance() { void Graphics::CreateInstance() {
gsl::span<gsl::czstring> suggested_extentions = GetSuggestedExtentions(); gsl::span<gsl::czstring> suggested_extentions = GetSuggestedExtentions();
if (!AreAllExtensionsSupported(suggested_extentions)) std::exit(EXIT_FAILURE);
VkApplicationInfo app_info = {}; VkApplicationInfo app_info = {};
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
@@ -48,4 +49,36 @@ gsl::span<gsl::czstring> Graphics::GetSuggestedExtentions() {
return {glfw_extentions, glfw_extention_count}; return {glfw_extentions, glfw_extention_count};
} }
std::vector<VkExtensionProperties> Graphics::GetSupprotedInstanceExtensions() {
VkExtensionProperties buffer[32];
std::uint32_t count;
vkEnumerateInstanceExtensionProperties(nullptr, &count, nullptr);
if (count == 0) return {};
std::vector<VkExtensionProperties> properties(count);
vkEnumerateInstanceExtensionProperties(nullptr, &count, properties.data());
return properties;
}
bool ExtentionMatchesName(gsl::czstring name,
const VkExtensionProperties& properties) {
return streq(properties.extensionName, name);
}
bool IsExtensionSupported(gsl::span<VkExtensionProperties> extensions,
gsl::czstring name) {
return std::any_of(extensions.begin(), extensions.end(),
std::bind_front(ExtentionMatchesName, name));
}
bool Graphics::AreAllExtensionsSupported(gsl::span<gsl::czstring> extensions) {
std::vector<VkExtensionProperties> supported_extensions =
GetSupprotedInstanceExtensions();
return std::all_of(
extensions.begin(), extensions.end(),
std::bind_front(IsExtensionSupported, supported_extensions));
}
} // namespace veng } // namespace veng