project-aster/aster/glfw_context.h

43 lines
752 B
C

// =============================================
// 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 count = 0;
GlfwContext()
{
if (count++ > 0)
return;
if (glfwInit() == GLFW_FALSE)
{
CRASH(PostError());
}
}
~GlfwContext()
{
if (--count == 0)
{
glfwTerminate();
}
count = 0;
}
};