From 3baef895d9977843720532e454a9a83bff446ade Mon Sep 17 00:00:00 2001
From: Sebastian Gaida <gaida@ca-digit.com>
Date: Mon, 3 May 2021 13:19:59 +0200
Subject: [PATCH] [#8] add CoreManager-Class and basic glfw-Functions

---
 config/Sources.cmake     |  2 ++
 src/vkcv/CoreManager.cpp | 27 +++++++++++++++++++++++++++
 src/vkcv/CoreManager.hpp | 19 +++++++++++++++++++
 3 files changed, 48 insertions(+)
 create mode 100644 src/vkcv/CoreManager.cpp
 create mode 100644 src/vkcv/CoreManager.hpp

diff --git a/config/Sources.cmake b/config/Sources.cmake
index f25104e9..c69abf89 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 00000000..7205e81e
--- /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 00000000..9e874310
--- /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
-- 
GitLab