Add create window surface
This commit is contained in:
@@ -57,6 +57,9 @@ CoreInstance::CoreInstance()
|
||||
|
||||
if (glfwInit() == GLFW_FALSE)
|
||||
throw std::runtime_error("Fail init glfw");
|
||||
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
window_ = glfwCreateWindow(800, 600, main_config_.game_name.c_str(), nullptr, nullptr);
|
||||
if (window_ == nullptr)
|
||||
{
|
||||
|
||||
+17
-10
@@ -6,10 +6,9 @@
|
||||
#include "CoreInstance.h"
|
||||
#include "Log/Log.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include <assert.h>
|
||||
#define VK_CHECK(res) assert(res == VK_SUCCESS)
|
||||
#include "GLFW/glfw3.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
|
||||
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
||||
@@ -23,18 +22,11 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
|
||||
return VK_FALSE;
|
||||
}
|
||||
|
||||
bool RenderEngine::QueueFamilyIndices::is_complete()
|
||||
{
|
||||
return graphycs_family.has_value();
|
||||
}
|
||||
|
||||
VkResult RenderEngine::enable_layer_validation(VkDebugUtilsMessengerCreateInfoEXT* create_info)
|
||||
{
|
||||
PFN_vkCreateDebugUtilsMessengerEXT debug_creator = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(vkGetInstanceProcAddr(instance_, "vkCreateDebugUtilsMessengerEXT"));
|
||||
return debug_creator(instance_, create_info, nullptr, &debug_messenger_);
|
||||
}
|
||||
#else
|
||||
#define VK_CHECK(res) if ((res) != VK_SUCCESS) throw std::runtime_error("Vulkan error: " + std::to_string(res))
|
||||
#endif
|
||||
|
||||
std::vector<const char*> RenderEngine::get_required_extensions()
|
||||
@@ -49,6 +41,12 @@ std::vector<const char*> RenderEngine::get_required_extensions()
|
||||
return extensions;
|
||||
}
|
||||
|
||||
|
||||
bool RenderEngine::QueueFamilyIndices::is_complete()
|
||||
{
|
||||
return graphycs_family.has_value();
|
||||
}
|
||||
|
||||
bool RenderEngine::is_device_suitable(VkPhysicalDevice device)
|
||||
{
|
||||
VkPhysicalDeviceProperties device_properties;
|
||||
@@ -180,6 +178,11 @@ void RenderEngine::create_logical_device()
|
||||
vkGetDeviceQueue(device_, indices.graphycs_family.value(), 0, &graphics_queue_);
|
||||
}
|
||||
|
||||
void RenderEngine::create_surface()
|
||||
{
|
||||
VK_CHECK(glfwCreateWindowSurface(instance_, window_, nullptr, &surface_));
|
||||
}
|
||||
|
||||
RenderEngine::RenderEngine(CoreInstance& core, GLFWwindow* window):
|
||||
core_(core),
|
||||
window_(window)
|
||||
@@ -188,6 +191,7 @@ window_(window)
|
||||
#endif
|
||||
{
|
||||
create_instance();
|
||||
create_surface();
|
||||
pick_physical_device();
|
||||
create_logical_device();
|
||||
}
|
||||
@@ -197,6 +201,9 @@ RenderEngine::~RenderEngine()
|
||||
if (device_ != VK_NULL_HANDLE)
|
||||
vkDestroyDevice(device_, nullptr);
|
||||
|
||||
if (surface_ != VK_NULL_HANDLE)
|
||||
vkDestroySurfaceKHR(instance_, surface_, nullptr);
|
||||
|
||||
#ifdef _DEBUG
|
||||
if (debug_messenger_ != nullptr && instance_ != nullptr) {
|
||||
PFN_vkDestroyDebugUtilsMessengerEXT destroyer_messenger = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(vkGetInstanceProcAddr(instance_, "vkDestroyDebugUtilsMessengerEXT"));
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#define GLFW_INCLUDE_VULKAN
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "GLFW/glfw3.h"
|
||||
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
|
||||
#define GLFW_INCLUDE_VULKAN
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include <assert.h>
|
||||
#define VK_CHECK(res) assert(res == VK_SUCCESS)
|
||||
#else
|
||||
#define VK_CHECK(res) if ((res) != VK_SUCCESS) throw std::runtime_error("Vulkan error: " + std::to_string(res))
|
||||
#endif
|
||||
|
||||
class CoreInstance;
|
||||
|
||||
class RenderEngine
|
||||
@@ -20,6 +28,7 @@ class RenderEngine
|
||||
CoreInstance& core_;
|
||||
GLFWwindow* window_;
|
||||
VkInstance instance_ = VK_NULL_HANDLE;
|
||||
VkSurfaceKHR surface_ = VK_NULL_HANDLE;
|
||||
VkPhysicalDevice physical_device_ = VK_NULL_HANDLE;
|
||||
VkDevice device_ = VK_NULL_HANDLE;
|
||||
VkQueue graphics_queue_ = VK_NULL_HANDLE;
|
||||
@@ -34,6 +43,7 @@ class RenderEngine
|
||||
static QueueFamilyIndices find_queue_family_indices(VkPhysicalDevice device);
|
||||
|
||||
void create_instance();
|
||||
void create_surface();
|
||||
void pick_physical_device();
|
||||
void create_logical_device();
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user