Commit 719b60dd authored by Camilla Berglund's avatar Camilla Berglund
Browse files

Added macros for library initialization check.

parent ca0617be
......@@ -40,26 +40,14 @@
GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
_glfwPlatformSetClipboardString(window, string);
}
GLFWAPI const char* glfwGetClipboardString(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return _glfwPlatformGetClipboardString(window);
}
......@@ -930,13 +930,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
GLFWAPI id glfwGetCocoaWindow(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
_GLFW_REQUIRE_INIT_OR_RETURN(nil);
return window->ns.object;
}
......@@ -364,11 +364,7 @@ GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
if (_glfwPlatformGetCurrentContext() == window)
return;
......@@ -378,35 +374,20 @@ GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle)
GLFWAPI GLFWwindow* glfwGetCurrentContext(void)
{
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return (GLFWwindow*) _glfwPlatformGetCurrentContext();
}
GLFWAPI void glfwSwapBuffers(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
_glfwPlatformSwapBuffers(window);
}
GLFWAPI void glfwSwapInterval(int interval)
{
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
if (!_glfwPlatformGetCurrentContext())
{
......@@ -422,11 +403,7 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
const GLubyte* extensions;
_GLFWwindow* window;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return GL_FALSE;
}
_GLFW_REQUIRE_INIT_OR_RETURN(GL_FALSE);
window = _glfwPlatformGetCurrentContext();
if (!window)
......@@ -479,11 +456,7 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname)
{
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (!_glfwPlatformGetCurrentContext())
{
......
......@@ -461,38 +461,21 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname)
GLFWAPI EGLDisplay glfwGetEGLDisplay(void)
{
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return _glfw.egl.display;
}
GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return window->egl.context;
}
GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
_GLFW_REQUIRE_INIT_OR_RETURN(0);
return window->egl.surface;
}
......@@ -42,11 +42,7 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma)
int i, size = GLFW_GAMMA_RAMP_SIZE;
GLFWgammaramp ramp;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
if (gamma <= 0.f)
{
......@@ -81,13 +77,7 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma)
GLFWAPI void glfwGetGammaRamp(GLFWmonitor* handle, GLFWgammaramp* ramp)
{
_GLFWmonitor* monitor = (_GLFWmonitor*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
_glfwPlatformGetGammaRamp(monitor, ramp);
}
......@@ -95,11 +85,7 @@ GLFWAPI void glfwSetGammaRamp(GLFWmonitor* handle, const GLFWgammaramp* ramp)
{
_GLFWmonitor* monitor = (_GLFWmonitor*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
if (!monitor->rampChanged)
{
......
......@@ -594,13 +594,7 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname)
GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return window->glx.context;
}
......@@ -208,11 +208,7 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* handle, int mode)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
_GLFW_REQUIRE_INIT_OR_RETURN(0);
switch (mode)
{
......@@ -232,11 +228,7 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
switch (mode)
{
......@@ -259,11 +251,7 @@ GLFWAPI int glfwGetKey(GLFWwindow* handle, int key)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return GLFW_RELEASE;
}
_GLFW_REQUIRE_INIT_OR_RETURN(GLFW_RELEASE);
if (key < 0 || key > GLFW_KEY_LAST)
{
......@@ -285,11 +273,7 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow* handle, int button)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return GLFW_RELEASE;
}
_GLFW_REQUIRE_INIT_OR_RETURN(GLFW_RELEASE);
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
{
......@@ -312,16 +296,12 @@ GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, int* xpos, int* ypos)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
if (xpos != NULL)
if (xpos)
*xpos = window->cursorPosX;
if (ypos != NULL)
if (ypos)
*ypos = window->cursorPosY;
}
......@@ -329,11 +309,7 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, int xpos, int ypos)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
if (_glfw.focusedWindow != window)
return;
......@@ -357,78 +333,42 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, int xpos, int ypos)
GLFWAPI void glfwSetKeyCallback(GLFWwindow* handle, GLFWkeyfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
window->callbacks.key = cbfun;
}
GLFWAPI void glfwSetCharCallback(GLFWwindow* handle, GLFWcharfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
window->callbacks.character = cbfun;
}
GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow* handle, GLFWmousebuttonfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
window->callbacks.mouseButton = cbfun;
}
GLFWAPI void glfwSetCursorPosCallback(GLFWwindow* handle, GLFWcursorposfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
window->callbacks.cursorPos = cbfun;
}
GLFWAPI void glfwSetCursorEnterCallback(GLFWwindow* handle, GLFWcursorenterfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
window->callbacks.cursorEnter = cbfun;
}
GLFWAPI void glfwSetScrollCallback(GLFWwindow* handle, GLFWscrollfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
window->callbacks.scroll = cbfun;
}
......@@ -109,6 +109,20 @@ typedef struct _GLFWmonitor _GLFWmonitor;
// Internal key state used for sticky keys
#define _GLFW_STICK 3
// Checks for whether the library has been intitalized
#define _GLFW_REQUIRE_INIT() \
if (!_glfwInitialized) \
{ \
_glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
return; \
}
#define _GLFW_REQUIRE_INIT_OR_RETURN(x) \
if (!_glfwInitialized) \
{ \
_glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
return x; \
}
//========================================================================
// Internal types
......
......@@ -37,11 +37,7 @@
GLFWAPI int glfwGetJoystickParam(int joy, int param)
{
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
_GLFW_REQUIRE_INIT_OR_RETURN(0);
if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
{
......@@ -56,11 +52,7 @@ GLFWAPI int glfwGetJoystickAxes(int joy, float* axes, int numaxes)
{
int i;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
_GLFW_REQUIRE_INIT_OR_RETURN(0);
if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
{
......@@ -87,11 +79,7 @@ GLFWAPI int glfwGetJoystickButtons(int joy,
{
int i;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
_GLFW_REQUIRE_INIT_OR_RETURN(0);
if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
{
......@@ -114,11 +102,7 @@ GLFWAPI int glfwGetJoystickButtons(int joy,
GLFWAPI const char* glfwGetJoystickName(int joy)
{
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
{
......
......@@ -266,24 +266,14 @@ void _glfwSplitBPP(int bpp, int* red, int* green, int* blue)
GLFWAPI GLFWmonitor** glfwGetMonitors(int* count)
{
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
*count = _glfw.monitorCount;
return (GLFWmonitor**) _glfw.monitors;
}
GLFWAPI GLFWmonitor* glfwGetPrimaryMonitor(void)
{
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return (GLFWmonitor*) _glfw.monitors[0];
}
......@@ -291,11 +281,7 @@ GLFWAPI void glfwGetMonitorPos(GLFWmonitor* handle, int* xpos, int* ypos)
{
_GLFWmonitor* monitor = (_GLFWmonitor*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
if (xpos)
*xpos = monitor->positionX;
......@@ -307,11 +293,7 @@ GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* handle, int* width, int* he
{
_GLFWmonitor* monitor = (_GLFWmonitor*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
if (width)
*width = monitor->widthMM;
......@@ -322,24 +304,13 @@ GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* handle, int* width, int* he
GLFWAPI const char* glfwGetMonitorName(GLFWmonitor* handle)
{
_GLFWmonitor* monitor = (_GLFWmonitor*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return monitor->name;
}
GLFWAPI void glfwSetMonitorCallback(GLFWmonitorfun cbfun)
{
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
_glfw.monitorCallback = cbfun;
}
......@@ -347,11 +318,7 @@ GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* handle, int* count)
{
_GLFWmonitor* monitor = (_GLFWmonitor*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (!refreshVideoModes(monitor))
return GL_FALSE;
......@@ -365,11 +332,7 @@ GLFWAPI GLFWvidmode glfwGetVideoMode(GLFWmonitor* handle)
_GLFWmonitor* monitor = (_GLFWmonitor*) handle;
GLFWvidmode mode = { 0, 0, 0, 0, 0 };
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return mode;
}
_GLFW_REQUIRE_INIT_OR_RETURN(mode);
_glfwPlatformGetVideoMode(monitor, &mode);
return mode;
......
......@@ -292,13 +292,7 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname)
GLFWAPI id glfwGetNSGLContext(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
_GLFW_REQUIRE_INIT_OR_RETURN(nil);
return window->nsgl.context;
}
......@@ -37,23 +37,13 @@
GLFWAPI double glfwGetTime(void)
{
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0.0;
}
_GLFW_REQUIRE_INIT_OR_RETURN(0.0);
return _glfwPlatformGetTime();
}
GLFWAPI void glfwSetTime(double time)
{
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_GLFW_REQUIRE_INIT();
_glfwPlatformSetTime(time);
}
......@@ -579,13 +579,7 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname)
GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return window->wgl.context;
}
......@@ -1090,13 +1090,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return window->win32.handle;
}
......@@ -147,11 +147,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
_GLFWwindow* window;
_GLFWwindow* previous;
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);