75 lines
2.3 KiB
C++
75 lines
2.3 KiB
C++
#include "RenderEngine.h"
|
|
|
|
#include <stdexcept>
|
|
|
|
#ifdef _DEBUG
|
|
#include <assert.h>
|
|
#define VK_CHECK(res) assert(res == VK_SUCCESS)
|
|
#else
|
|
#define VK_CHECK(res) res
|
|
#endif
|
|
|
|
void RenderEngine::render_thread_func()
|
|
{
|
|
window = glfwCreateWindow(640, 480, "UwU Engine", NULL, NULL);
|
|
if (!window)
|
|
{
|
|
glfwTerminate();
|
|
throw std::runtime_error("Fail create window");
|
|
}
|
|
while (!glfwWindowShouldClose(window))
|
|
{
|
|
glfwSwapBuffers(window);
|
|
glfwPollEvents();
|
|
}
|
|
onCloseWindow.Call();
|
|
}
|
|
|
|
RenderEngine::RenderEngine(const std::string& app_name,
|
|
int major_app_version, int minor_app_version, int patch_app_version,
|
|
int major_engine_version, int minor_engine_version, int patch_engine_version)
|
|
{
|
|
if (!glfwInit())
|
|
throw std::runtime_error("Fail initialize GLFW");
|
|
|
|
{
|
|
uint32_t extensions_count = 0;
|
|
const char** extensions = glfwGetRequiredInstanceExtensions(&extensions_count);
|
|
|
|
VkApplicationInfo app_info{};
|
|
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
|
app_info.apiVersion = VK_API_VERSION_1_0;
|
|
app_info.applicationVersion = VK_MAKE_VERSION(major_app_version, minor_app_version, patch_app_version);
|
|
app_info.pApplicationName = app_name.c_str();
|
|
app_info.pEngineName = "UwU Engine";
|
|
app_info.engineVersion = VK_MAKE_VERSION(major_engine_version, minor_engine_version, patch_engine_version);
|
|
|
|
VkInstanceCreateInfo instance_create_info{};
|
|
instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
|
instance_create_info.ppEnabledExtensionNames = extensions;
|
|
instance_create_info.enabledExtensionCount = extensions_count;
|
|
instance_create_info.pApplicationInfo = &app_info;
|
|
VK_CHECK(vkCreateInstance(&instance_create_info, nullptr, &instance_));
|
|
}
|
|
}
|
|
|
|
RenderEngine::~RenderEngine()
|
|
{
|
|
if (window != nullptr && !glfwWindowShouldClose(window))
|
|
glfwSetWindowShouldClose(window, true);
|
|
|
|
if (render_thread != nullptr)
|
|
{
|
|
render_thread->join();
|
|
delete render_thread;
|
|
}
|
|
if (window != nullptr)
|
|
glfwDestroyWindow(window);
|
|
glfwTerminate();
|
|
}
|
|
|
|
void RenderEngine::start()
|
|
{
|
|
render_thread = new std::thread(&RenderEngine::render_thread_func, this);
|
|
}
|