1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 02:38:52 -05:00

Move initialized flag into library struct

This commit is contained in:
Camilla Löwy 2017-02-06 15:58:15 +01:00
parent 98bdd36231
commit 926d2beddb
2 changed files with 10 additions and 18 deletions

View File

@ -33,14 +33,12 @@
#include <stdarg.h>
// The three global variables below comprise all global data in GLFW.
// The global variables below comprise all global data in GLFW.
// Any other global variable is a bug.
// Global state shared between compilation units of GLFW
// These are documented in internal.h
//
GLFWbool _glfwInitialized = GLFW_FALSE;
_GLFWlibrary _glfw;
_GLFWlibrary _glfw = { GLFW_FALSE };
// This is outside of _glfw so it can be initialized and usable before
// glfwInit is called, which lets that function report errors
@ -119,7 +117,7 @@ void _glfwInputError(int error, const char* format, ...)
GLFWAPI int glfwInit(void)
{
if (_glfwInitialized)
if (_glfw.initialized)
return GLFW_TRUE;
memset(&_glfw, 0, sizeof(_glfw));
@ -130,8 +128,7 @@ GLFWAPI int glfwInit(void)
return GLFW_FALSE;
}
_glfwInitialized = GLFW_TRUE;
_glfw.initialized = GLFW_TRUE;
_glfw.timerOffset = _glfwPlatformGetTimerValue();
// Not all window hints have zero as their default value
@ -144,7 +141,7 @@ GLFWAPI void glfwTerminate(void)
{
int i;
if (!_glfwInitialized)
if (!_glfw.initialized)
return;
memset(&_glfw.callbacks, 0, sizeof(_glfw.callbacks));
@ -171,7 +168,6 @@ GLFWAPI void glfwTerminate(void)
_glfwPlatformTerminate();
memset(&_glfw, 0, sizeof(_glfw));
_glfwInitialized = GLFW_FALSE;
}
GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev)

View File

@ -230,13 +230,13 @@ typedef void (APIENTRY * PFN_vkVoidFunction)(void);
// Checks for whether the library has been initialized
#define _GLFW_REQUIRE_INIT() \
if (!_glfwInitialized) \
if (!_glfw.initialized) \
{ \
_glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
return; \
}
#define _GLFW_REQUIRE_INIT_OR_RETURN(x) \
if (!_glfwInitialized) \
if (!_glfw.initialized) \
{ \
_glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
return x; \
@ -468,6 +468,8 @@ struct _GLFWjoystick
*/
struct _GLFWlibrary
{
GLFWbool initialized;
struct {
_GLFWfbconfig framebuffer;
_GLFWwndconfig window;
@ -533,13 +535,7 @@ struct _GLFWlibrary
// Global state shared between compilation units of GLFW
//========================================================================
/*! @brief Flag indicating whether GLFW has been successfully initialized.
*/
extern GLFWbool _glfwInitialized;
/*! @brief All global data protected by @ref _glfwInitialized.
* This should only be touched after a call to @ref glfwInit that has not been
* followed by a call to @ref glfwTerminate.
/*! @brief All global data shared between compilation units.
*/
extern _GLFWlibrary _glfw;