// ============================================= // Aster: glfw_context.h // Copyright (c) 2020-2024 Anish Bhobe // ============================================= #pragma once #include "global.h" struct GlfwContext { static i32 PostError() noexcept { static const char *error = nullptr; const auto code = glfwGetError(&error); ERROR("GLFW {}", error); return code; } inline static u32 m_Count = 0; GlfwContext() { if (m_Count++ > 0) return; if (glfwInit() == GLFW_FALSE) { ABORT(PostError()); } } ~GlfwContext() { if (--m_Count == 0) { glfwTerminate(); } m_Count = 0; } };