Split vulkan_base into smaller units

Closes #30. This is a basic refactoring of the graphics module, so
everything won't be in single file.
This commit is contained in:
Piotr Krygier committed 2023-03-29 09:41:04 +02:00
1 parent 649e7f76fe
commit 6a09350902
32 files changed
+2354 -2002

No files matched your search

+121
View File
@@ -0,0 +1,121 @@
/**
* @file window.cxx
* @author Piotr Krygier (everyonencancode@gmail.com)
* @brief
* @version 0.1
* @date 2022-02-15
*
* @copyright Copyright (c) 2022
*
*/
#include "window.hpp"
#include "locale_window.hpp"
#include "utilities/logger.hpp"
#include "vulkan_base.hpp"
namespace rse::graphics::window
{
using namespace locale::window;
/* Error codes */
typedef enum {
WINDOW_ERROR_NO_ERROR = 0U,
WINDOW_ERROR_GLFW_INIT_FAILED,
WINDOW_ERROR_VULKAN_NOT_LOADED,
WINDOW_ERROR_WINDOW_NOT_CREATED
} WINDOW_ERROR;
GLFWwindow *gpWindowHandle = NULL;
/**
* @brief GLFW erro callback
*
* @param error Error code
* @param description Error description
*/
static void errrorCallback(int error, const char* description)
{
(void)error;
LOGE << "Error: " << description;
}
/**
* @brief Pressed key callback
*
* @param window Window in which contex the key has been pressed
* @param key The keyboard key that was pressed or released
* @param scancode The system-specific scancode of the key.
* @param action GLFW_PRESS, GLFW_RELEASE or GLFW_REPEAT
* @param mods Bit field describing which modifier keys were held down
*/
static void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
(void)scancode;
(void)action;
(void)mods;
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
glfwSetWindowShouldClose(window, GLFW_TRUE);
}
}
uint16_t windowInit()
{
/* Initiliaze GLFW AP */
if (GLFW_TRUE != glfwInit())
{
LOGF << windowErrorMesssages[WINDOW_GLFW_INIT_FAILED];
return WINDOW_ERROR_GLFW_INIT_FAILED;
}
/* Check for Vulkan support */
if (GLFW_FALSE == glfwVulkanSupported()) {
LOGF << windowErrorMesssages[WINDOW_VULKAN_NOT_SUPPORTED];
return WINDOW_ERROR_VULKAN_NOT_LOADED;
}
/* Set error callback */
glfwSetErrorCallback(errrorCallback);
/* Create window */
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
gpWindowHandle = glfwCreateWindow(640, 480, "RedScarfEngine", NULL, NULL);
if (NULL == gpWindowHandle) {
LOGF << windowErrorMesssages[WINDOW_NOT_CREATED];
return WINDOW_ERROR_WINDOW_NOT_CREATED;
}
glfwSetKeyCallback(gpWindowHandle, keyCallback);
return WINDOW_ERROR_NO_ERROR;
}
uint16_t windowLoop(rse::graphics::vulkanbase::VulkanState& vulkan_state)
{
while (!glfwWindowShouldClose(gpWindowHandle)) {
glfwPollEvents();
rse::graphics::vulkanbase::drawFrame(vulkan_state);
}
return WINDOW_ERROR_NO_ERROR;
}
void windowTerminate()
{
glfwDestroyWindow(gpWindowHandle);
glfwTerminate();
}
GLFWwindow* getWindowHandle()
{
return gpWindowHandle;
}
} /* namespace rse::graphics::window */