인스턴스 생성 구조 완료
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
#include <glm/glm.hpp>
|
||||
#include <gsl/gsl>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "utilities.h"
|
||||
|
||||
5
include/utilities.h
Normal file
5
include/utilities.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
namespace veng {
|
||||
bool streq(gsl::czstring left, gsl::czstring right);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#include "glfw/glfw_window.h"
|
||||
|
||||
namespace veng {
|
||||
@@ -12,7 +13,9 @@ class Graphics final {
|
||||
void InitializeVulkan();
|
||||
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;
|
||||
gsl::not_null<Window *> window_;
|
||||
|
||||
9
src/utilities.cpp
Normal file
9
src/utilities.cpp
Normal 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
|
||||
@@ -18,6 +18,7 @@ void Graphics::InitializeVulkan() { CreateInstance(); }
|
||||
|
||||
void Graphics::CreateInstance() {
|
||||
gsl::span<gsl::czstring> suggested_extentions = GetSuggestedExtentions();
|
||||
if (!AreAllExtensionsSupported(suggested_extentions)) std::exit(EXIT_FAILURE);
|
||||
|
||||
VkApplicationInfo app_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};
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user