1 | #include "game-gui-glfw.hpp"
|
---|
2 |
|
---|
3 | #include "consts.hpp"
|
---|
4 |
|
---|
5 | string GameGui_GLFW::s_errorMessage;
|
---|
6 |
|
---|
7 | void glfw_error_callback(int error, const char* description) {
|
---|
8 | GameGui_GLFW::s_errorMessage = description;
|
---|
9 | }
|
---|
10 |
|
---|
11 | string& GameGui_GLFW::GetError() {
|
---|
12 | return GameGui_GLFW::s_errorMessage;
|
---|
13 | }
|
---|
14 |
|
---|
15 | bool GameGui_GLFW::Init() {
|
---|
16 | GameGui_GLFW::s_errorMessage = "No error";
|
---|
17 | glfwSetErrorCallback(glfw_error_callback);
|
---|
18 |
|
---|
19 | return glfwInit() == GLFW_TRUE ? RTWO_SUCCESS : RTWO_ERROR;
|
---|
20 | }
|
---|
21 |
|
---|
22 | void GameGui_GLFW::Shutdown() {
|
---|
23 | glfwTerminate();
|
---|
24 | }
|
---|
25 |
|
---|
26 | void* GameGui_GLFW::CreateWindow(const string& title, unsigned int width, unsigned int height) {
|
---|
27 | glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
---|
28 |
|
---|
29 | window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr);
|
---|
30 |
|
---|
31 | return window;
|
---|
32 | }
|
---|
33 |
|
---|
34 | void GameGui_GLFW::DestroyWindow() {
|
---|
35 | // TODO: This function can throw some errors. They should be handled
|
---|
36 | glfwDestroyWindow(window);
|
---|
37 | }
|
---|
38 |
|
---|
39 | #ifdef GAMEGUI_INCLUDE_VULKAN
|
---|
40 |
|
---|
41 | bool GameGui_GLFW::CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) {
|
---|
42 | return glfwCreateWindowSurface(instance, window, nullptr, surface) == VK_SUCCESS ?
|
---|
43 | RTWO_SUCCESS : RTWO_ERROR;
|
---|
44 | }
|
---|
45 |
|
---|
46 | #endif
|
---|
47 |
|
---|
48 | vector<const char*> GameGui_GLFW::GetRequiredExtensions() {
|
---|
49 | uint32_t glfwExtensionCount = 0;
|
---|
50 | const char** glfwExtensions;
|
---|
51 |
|
---|
52 | glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
|
---|
53 |
|
---|
54 | vector<const char*> extensions(glfwExtensions, glfwExtensions + glfwExtensionCount);
|
---|
55 |
|
---|
56 | return extensions;
|
---|
57 | }
|
---|
58 |
|
---|
59 | void GameGui_GLFW::GetWindowSize(int* width, int* height) {
|
---|
60 | glfwGetFramebufferSize(window, width, height);
|
---|
61 | }
|
---|