diff --git a/config/Sources.cmake b/config/Sources.cmake index f25104e9df248d07dd0cd864d56645db8ed422d7..c69abf89b7d701175cd5620de09ec7f212b0c367 100644 --- a/config/Sources.cmake +++ b/config/Sources.cmake @@ -2,4 +2,6 @@ set(vkcv_sources ${vkcv_source}/vkcv/Context.hpp ${vkcv_source}/vkcv/Context.cpp + ${vkcv_source}/vkcv/CoreManager.hpp + ${vkcv_source}/vkcv/CoreManager.cpp ) diff --git a/src/vkcv/CoreManager.cpp b/src/vkcv/CoreManager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7205e81ec05c5ee4d50ed6e3cf16a049fce9d921 --- /dev/null +++ b/src/vkcv/CoreManager.cpp @@ -0,0 +1,27 @@ +#define GLFW_INCLUDE_VULKAN + +#include "CoreManager.hpp" + +namespace vkcv { + + int glfwCounter = 0; + + void initGLFW() { + + if (glfwCounter == 0) { + int glfwSuccess = glfwInit(); + + if (glfwSuccess == GLFW_FALSE) { + throw std::runtime_error("Could not initialize GLFW"); + } + } + glfwCounter++; + } + + void terminateGLFW() { + if (glfwCounter == 1) { + glfwTerminate(); + } + glfwCounter--; + } +} \ No newline at end of file diff --git a/src/vkcv/CoreManager.hpp b/src/vkcv/CoreManager.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9e874310792ec6ba27510f1a9d57fcdc8cc57a9a --- /dev/null +++ b/src/vkcv/CoreManager.hpp @@ -0,0 +1,19 @@ +#ifndef VKCV_COREMANAGER_HPP +#define VKCV_COREMANAGER_HPP + +#include <GLFW/glfw3.h> +#include <stdexcept> + +namespace vkcv { + + /** + * initialize GLFW if not initialized + */ + void initGLFW(); + /** + * terminate GLFW + */ + void terminateGLFW(); +} + +#endif //VKCV_COREMANAGER_HPP