vulkan instance 까지 생성 완료
This commit is contained in:
14
src/glfw/glfw_initialization.cpp
Normal file
14
src/glfw/glfw_initialization.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "glfw/glfw_initialization.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include "precomp.h"
|
||||
|
||||
namespace veng {
|
||||
GlfwInitialization::GlfwInitialization() {
|
||||
if (glfwInit() != GLFW_TRUE) std::exit(EXIT_FAILURE);
|
||||
}
|
||||
GlfwInitialization::~GlfwInitialization() { glfwTerminate(); }
|
||||
} // namespace veng
|
||||
34
src/glfw/glfw_moniotr.cpp
Normal file
34
src/glfw/glfw_moniotr.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "glfw/glfw_monitor.h"
|
||||
#include "precomp.h"
|
||||
|
||||
namespace veng {
|
||||
gsl::span<GLFWmonitor *> GetMonitors() {
|
||||
std::int32_t monitor_count = 0;
|
||||
GLFWmonitor **monitor_pointers = glfwGetMonitors(&monitor_count);
|
||||
return gsl::span<GLFWmonitor *>(monitor_pointers, monitor_count);
|
||||
}
|
||||
|
||||
glm::ivec2 GetMonitorPosition(gsl::not_null<GLFWmonitor *> monitor) {
|
||||
glm::ivec2 monitor_position;
|
||||
glfwGetMonitorPos(monitor, &monitor_position.x, &monitor_position.y);
|
||||
return monitor_position;
|
||||
}
|
||||
glm::ivec2 GetMonitorWorkAreaSize(gsl::not_null<GLFWmonitor *> monitor) {
|
||||
glm::ivec2 monitor_size;
|
||||
glfwGetMonitorWorkarea(monitor, nullptr, nullptr, &monitor_size.x,
|
||||
&monitor_size.y);
|
||||
return monitor_size;
|
||||
}
|
||||
|
||||
void MoveWindowToMonitor(gsl::not_null<GLFWwindow *> window,
|
||||
gsl::not_null<GLFWmonitor *> monitor) {
|
||||
glm::ivec2 window_size;
|
||||
glfwGetWindowSize(window, &window_size.x, &window_size.y);
|
||||
const glm::ivec2 window_new_position = GetMonitorPosition(monitor) +
|
||||
(GetMonitorWorkAreaSize(monitor) / 2) -
|
||||
(window_size / 2);
|
||||
glfwSetWindowPos(window, window_new_position.x, window_new_position.y);
|
||||
}
|
||||
} // namespace veng
|
||||
39
src/glfw/glfw_window.cpp
Normal file
39
src/glfw/glfw_window.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "glfw/glfw_monitor.h"
|
||||
#include "glfw/glfw_window.h"
|
||||
#include "precomp.h"
|
||||
|
||||
namespace veng {
|
||||
|
||||
Window::Window(gsl::czstring name, glm::ivec2 size) {
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
|
||||
window_ = glfwCreateWindow(size.x, size.y, name, nullptr, nullptr);
|
||||
if (window_ == nullptr) std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
Window::~Window() { glfwDestroyWindow(window_); }
|
||||
|
||||
glm::ivec2 Window::GetWindowSize() const {
|
||||
glm::ivec2 window_size;
|
||||
glfwGetWindowSize(window_, &window_size.x, &window_size.y);
|
||||
return window_size;
|
||||
}
|
||||
|
||||
bool Window::ShouldClose() const { return glfwWindowShouldClose(window_); }
|
||||
|
||||
GLFWwindow* Window::GetHandle() const { return window_; }
|
||||
|
||||
bool Window::TryMoveToMonitor(std::uint16_t monitor_number) {
|
||||
gsl::span<GLFWmonitor*> monitors = veng::GetMonitors();
|
||||
|
||||
if (monitor_number < monitors.size()) {
|
||||
veng::MoveWindowToMonitor(window_, monitors[monitor_number]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace veng
|
||||
30
src/main.cpp
30
src/main.cpp
@@ -1,19 +1,21 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <glm/glm.hpp>
|
||||
#include <gsl/gsl>
|
||||
#include <iostream>
|
||||
#include "glfw/glfw_initialization.h"
|
||||
#include "glfw/glfw_monitor.h"
|
||||
#include "glfw/glfw_window.h"
|
||||
#include "vulkan/graphics.h"
|
||||
|
||||
int main(std::int32_t argc, gsl::zstring* argv) {
|
||||
gsl::span<gsl::zstring> arguments(argv, argc);
|
||||
std::sort(arguments.begin(), arguments.end());
|
||||
std::int32_t main(std::int32_t argc, gsl::zstring* argv) {
|
||||
const veng::GlfwInitialization _glfw;
|
||||
|
||||
gsl::not_null<gsl::zstring*> arguments_pointer_validated = argv;
|
||||
veng::Window window("Vulkan Engine", {800, 600});
|
||||
window.TryMoveToMonitor(0);
|
||||
|
||||
std::cout << "Hello, World!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
veng::Graphics graphics(&window);
|
||||
|
||||
while (!window.ShouldClose()) {
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
51
src/vulkan/graphics.cpp
Normal file
51
src/vulkan/graphics.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "vulkan/graphics.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "precomp.h"
|
||||
|
||||
namespace veng {
|
||||
|
||||
Graphics::Graphics(gsl::not_null<Window*> window) : window_(window) {
|
||||
InitializeVulkan();
|
||||
}
|
||||
|
||||
Graphics::~Graphics() {
|
||||
if (instance_ != nullptr) vkDestroyInstance(instance_, nullptr);
|
||||
}
|
||||
|
||||
void Graphics::InitializeVulkan() { CreateInstance(); }
|
||||
|
||||
void Graphics::CreateInstance() {
|
||||
gsl::span<gsl::czstring> suggested_extentions = GetSuggestedExtentions();
|
||||
|
||||
VkApplicationInfo app_info = {};
|
||||
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||
app_info.pNext = nullptr;
|
||||
app_info.pApplicationName = "Udemy Course";
|
||||
app_info.applicationVersion = VK_MAKE_API_VERSION(0, 0, 0, 0);
|
||||
app_info.pEngineName = "VEng";
|
||||
app_info.engineVersion = VK_MAKE_API_VERSION(0, 1, 0, 0);
|
||||
app_info.apiVersion = VK_API_VERSION_1_0;
|
||||
|
||||
VkInstanceCreateInfo instance_creation_info = {};
|
||||
instance_creation_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
instance_creation_info.pNext = nullptr;
|
||||
instance_creation_info.pApplicationInfo = &app_info;
|
||||
instance_creation_info.enabledExtensionCount = suggested_extentions.size();
|
||||
instance_creation_info.ppEnabledExtensionNames = suggested_extentions.data();
|
||||
instance_creation_info.enabledLayerCount = 0;
|
||||
|
||||
VkResult result =
|
||||
vkCreateInstance(&instance_creation_info, nullptr, &instance_);
|
||||
if (result != VK_SUCCESS) std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
gsl::span<gsl::czstring> Graphics::GetSuggestedExtentions() {
|
||||
std::uint32_t glfw_extention_count = 0;
|
||||
gsl::czstring* glfw_extentions =
|
||||
glfwGetRequiredInstanceExtensions(&glfw_extention_count);
|
||||
return {glfw_extentions, glfw_extention_count};
|
||||
}
|
||||
|
||||
} // namespace veng
|
||||
Reference in New Issue
Block a user