Added macros for library initialization check.

This commit is contained in:
Camilla Berglund 2013-02-20 00:28:08 +01:00
parent ca0617be2c
commit 719b60dd2b
16 changed files with 88 additions and 434 deletions

View File

@ -40,26 +40,14 @@
GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string) GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_glfwPlatformSetClipboardString(window, string); _glfwPlatformSetClipboardString(window, string);
} }
GLFWAPI const char* glfwGetClipboardString(GLFWwindow* handle) GLFWAPI const char* glfwGetClipboardString(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
return _glfwPlatformGetClipboardString(window); return _glfwPlatformGetClipboardString(window);
} }

View File

@ -930,13 +930,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
GLFWAPI id glfwGetCocoaWindow(GLFWwindow* handle) GLFWAPI id glfwGetCocoaWindow(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(nil);
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
return window->ns.object; return window->ns.object;
} }

View File

@ -364,11 +364,7 @@ GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (_glfwPlatformGetCurrentContext() == window) if (_glfwPlatformGetCurrentContext() == window)
return; return;
@ -378,35 +374,20 @@ GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle)
GLFWAPI GLFWwindow* glfwGetCurrentContext(void) GLFWAPI GLFWwindow* glfwGetCurrentContext(void)
{ {
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
return (GLFWwindow*) _glfwPlatformGetCurrentContext(); return (GLFWwindow*) _glfwPlatformGetCurrentContext();
} }
GLFWAPI void glfwSwapBuffers(GLFWwindow* handle) GLFWAPI void glfwSwapBuffers(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_glfwPlatformSwapBuffers(window); _glfwPlatformSwapBuffers(window);
} }
GLFWAPI void glfwSwapInterval(int interval) GLFWAPI void glfwSwapInterval(int interval)
{ {
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (!_glfwPlatformGetCurrentContext()) if (!_glfwPlatformGetCurrentContext())
{ {
@ -422,11 +403,7 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
const GLubyte* extensions; const GLubyte* extensions;
_GLFWwindow* window; _GLFWwindow* window;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(GL_FALSE);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return GL_FALSE;
}
window = _glfwPlatformGetCurrentContext(); window = _glfwPlatformGetCurrentContext();
if (!window) if (!window)
@ -479,11 +456,7 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname) GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname)
{ {
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
if (!_glfwPlatformGetCurrentContext()) if (!_glfwPlatformGetCurrentContext())
{ {

View File

@ -461,38 +461,21 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname)
GLFWAPI EGLDisplay glfwGetEGLDisplay(void) GLFWAPI EGLDisplay glfwGetEGLDisplay(void)
{ {
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
return _glfw.egl.display; return _glfw.egl.display;
} }
GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* handle) GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
return window->egl.context; return window->egl.context;
} }
GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* handle) GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(0);
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
return window->egl.surface; return window->egl.surface;
} }

View File

@ -42,11 +42,7 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma)
int i, size = GLFW_GAMMA_RAMP_SIZE; int i, size = GLFW_GAMMA_RAMP_SIZE;
GLFWgammaramp ramp; GLFWgammaramp ramp;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (gamma <= 0.f) if (gamma <= 0.f)
{ {
@ -81,13 +77,7 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma)
GLFWAPI void glfwGetGammaRamp(GLFWmonitor* handle, GLFWgammaramp* ramp) GLFWAPI void glfwGetGammaRamp(GLFWmonitor* handle, GLFWgammaramp* ramp)
{ {
_GLFWmonitor* monitor = (_GLFWmonitor*) handle; _GLFWmonitor* monitor = (_GLFWmonitor*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_glfwPlatformGetGammaRamp(monitor, ramp); _glfwPlatformGetGammaRamp(monitor, ramp);
} }
@ -95,11 +85,7 @@ GLFWAPI void glfwSetGammaRamp(GLFWmonitor* handle, const GLFWgammaramp* ramp)
{ {
_GLFWmonitor* monitor = (_GLFWmonitor*) handle; _GLFWmonitor* monitor = (_GLFWmonitor*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (!monitor->rampChanged) if (!monitor->rampChanged)
{ {

View File

@ -594,13 +594,7 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname)
GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* handle) GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
return window->glx.context; return window->glx.context;
} }

View File

@ -208,11 +208,7 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* handle, int mode)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(0);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
switch (mode) switch (mode)
{ {
@ -232,11 +228,7 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
switch (mode) switch (mode)
{ {
@ -259,11 +251,7 @@ GLFWAPI int glfwGetKey(GLFWwindow* handle, int key)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_RELEASE);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return GLFW_RELEASE;
}
if (key < 0 || key > GLFW_KEY_LAST) if (key < 0 || key > GLFW_KEY_LAST)
{ {
@ -285,11 +273,7 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow* handle, int button)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_RELEASE);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return GLFW_RELEASE;
}
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST) 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; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (xpos != NULL) if (xpos)
*xpos = window->cursorPosX; *xpos = window->cursorPosX;
if (ypos != NULL) if (ypos)
*ypos = window->cursorPosY; *ypos = window->cursorPosY;
} }
@ -329,11 +309,7 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, int xpos, int ypos)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (_glfw.focusedWindow != window) if (_glfw.focusedWindow != window)
return; return;
@ -357,78 +333,42 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, int xpos, int ypos)
GLFWAPI void glfwSetKeyCallback(GLFWwindow* handle, GLFWkeyfun cbfun) GLFWAPI void glfwSetKeyCallback(GLFWwindow* handle, GLFWkeyfun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
window->callbacks.key = cbfun; window->callbacks.key = cbfun;
} }
GLFWAPI void glfwSetCharCallback(GLFWwindow* handle, GLFWcharfun cbfun) GLFWAPI void glfwSetCharCallback(GLFWwindow* handle, GLFWcharfun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
window->callbacks.character = cbfun; window->callbacks.character = cbfun;
} }
GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow* handle, GLFWmousebuttonfun cbfun) GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow* handle, GLFWmousebuttonfun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
window->callbacks.mouseButton = cbfun; window->callbacks.mouseButton = cbfun;
} }
GLFWAPI void glfwSetCursorPosCallback(GLFWwindow* handle, GLFWcursorposfun cbfun) GLFWAPI void glfwSetCursorPosCallback(GLFWwindow* handle, GLFWcursorposfun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
window->callbacks.cursorPos = cbfun; window->callbacks.cursorPos = cbfun;
} }
GLFWAPI void glfwSetCursorEnterCallback(GLFWwindow* handle, GLFWcursorenterfun cbfun) GLFWAPI void glfwSetCursorEnterCallback(GLFWwindow* handle, GLFWcursorenterfun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
window->callbacks.cursorEnter = cbfun; window->callbacks.cursorEnter = cbfun;
} }
GLFWAPI void glfwSetScrollCallback(GLFWwindow* handle, GLFWscrollfun cbfun) GLFWAPI void glfwSetScrollCallback(GLFWwindow* handle, GLFWscrollfun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
window->callbacks.scroll = cbfun; window->callbacks.scroll = cbfun;
} }

View File

@ -109,6 +109,20 @@ typedef struct _GLFWmonitor _GLFWmonitor;
// Internal key state used for sticky keys // Internal key state used for sticky keys
#define _GLFW_STICK 3 #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 // Internal types

View File

@ -37,11 +37,7 @@
GLFWAPI int glfwGetJoystickParam(int joy, int param) GLFWAPI int glfwGetJoystickParam(int joy, int param)
{ {
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(0);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
if (joy < 0 || joy > GLFW_JOYSTICK_LAST) if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
{ {
@ -56,11 +52,7 @@ GLFWAPI int glfwGetJoystickAxes(int joy, float* axes, int numaxes)
{ {
int i; int i;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(0);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
if (joy < 0 || joy > GLFW_JOYSTICK_LAST) if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
{ {
@ -87,11 +79,7 @@ GLFWAPI int glfwGetJoystickButtons(int joy,
{ {
int i; int i;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(0);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
if (joy < 0 || joy > GLFW_JOYSTICK_LAST) if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
{ {
@ -114,11 +102,7 @@ GLFWAPI int glfwGetJoystickButtons(int joy,
GLFWAPI const char* glfwGetJoystickName(int joy) GLFWAPI const char* glfwGetJoystickName(int joy)
{ {
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
if (joy < 0 || joy > GLFW_JOYSTICK_LAST) if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
{ {

View File

@ -266,24 +266,14 @@ void _glfwSplitBPP(int bpp, int* red, int* green, int* blue)
GLFWAPI GLFWmonitor** glfwGetMonitors(int* count) GLFWAPI GLFWmonitor** glfwGetMonitors(int* count)
{ {
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
*count = _glfw.monitorCount; *count = _glfw.monitorCount;
return (GLFWmonitor**) _glfw.monitors; return (GLFWmonitor**) _glfw.monitors;
} }
GLFWAPI GLFWmonitor* glfwGetPrimaryMonitor(void) GLFWAPI GLFWmonitor* glfwGetPrimaryMonitor(void)
{ {
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
return (GLFWmonitor*) _glfw.monitors[0]; return (GLFWmonitor*) _glfw.monitors[0];
} }
@ -291,11 +281,7 @@ GLFWAPI void glfwGetMonitorPos(GLFWmonitor* handle, int* xpos, int* ypos)
{ {
_GLFWmonitor* monitor = (_GLFWmonitor*) handle; _GLFWmonitor* monitor = (_GLFWmonitor*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (xpos) if (xpos)
*xpos = monitor->positionX; *xpos = monitor->positionX;
@ -307,11 +293,7 @@ GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* handle, int* width, int* he
{ {
_GLFWmonitor* monitor = (_GLFWmonitor*) handle; _GLFWmonitor* monitor = (_GLFWmonitor*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (width) if (width)
*width = monitor->widthMM; *width = monitor->widthMM;
@ -322,24 +304,13 @@ GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* handle, int* width, int* he
GLFWAPI const char* glfwGetMonitorName(GLFWmonitor* handle) GLFWAPI const char* glfwGetMonitorName(GLFWmonitor* handle)
{ {
_GLFWmonitor* monitor = (_GLFWmonitor*) handle; _GLFWmonitor* monitor = (_GLFWmonitor*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
return monitor->name; return monitor->name;
} }
GLFWAPI void glfwSetMonitorCallback(GLFWmonitorfun cbfun) GLFWAPI void glfwSetMonitorCallback(GLFWmonitorfun cbfun)
{ {
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_glfw.monitorCallback = cbfun; _glfw.monitorCallback = cbfun;
} }
@ -347,11 +318,7 @@ GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* handle, int* count)
{ {
_GLFWmonitor* monitor = (_GLFWmonitor*) handle; _GLFWmonitor* monitor = (_GLFWmonitor*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
if (!refreshVideoModes(monitor)) if (!refreshVideoModes(monitor))
return GL_FALSE; return GL_FALSE;
@ -365,11 +332,7 @@ GLFWAPI GLFWvidmode glfwGetVideoMode(GLFWmonitor* handle)
_GLFWmonitor* monitor = (_GLFWmonitor*) handle; _GLFWmonitor* monitor = (_GLFWmonitor*) handle;
GLFWvidmode mode = { 0, 0, 0, 0, 0 }; GLFWvidmode mode = { 0, 0, 0, 0, 0 };
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(mode);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return mode;
}
_glfwPlatformGetVideoMode(monitor, &mode); _glfwPlatformGetVideoMode(monitor, &mode);
return mode; return mode;

View File

@ -292,13 +292,7 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname)
GLFWAPI id glfwGetNSGLContext(GLFWwindow* handle) GLFWAPI id glfwGetNSGLContext(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(nil);
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
return window->nsgl.context; return window->nsgl.context;
} }

View File

@ -37,23 +37,13 @@
GLFWAPI double glfwGetTime(void) GLFWAPI double glfwGetTime(void)
{ {
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(0.0);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0.0;
}
return _glfwPlatformGetTime(); return _glfwPlatformGetTime();
} }
GLFWAPI void glfwSetTime(double time) GLFWAPI void glfwSetTime(double time)
{ {
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_glfwPlatformSetTime(time); _glfwPlatformSetTime(time);
} }

View File

@ -579,13 +579,7 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname)
GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* handle) GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
return window->wgl.context; return window->wgl.context;
} }

View File

@ -1090,13 +1090,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle) GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
return window->win32.handle; return window->win32.handle;
} }

View File

@ -147,11 +147,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
_GLFWwindow* window; _GLFWwindow* window;
_GLFWwindow* previous; _GLFWwindow* previous;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
if (width <= 0 || height <= 0) if (width <= 0 || height <= 0)
{ {
@ -271,11 +267,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
void glfwDefaultWindowHints(void) void glfwDefaultWindowHints(void)
{ {
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
memset(&_glfw.hints, 0, sizeof(_glfw.hints)); memset(&_glfw.hints, 0, sizeof(_glfw.hints));
@ -298,11 +290,7 @@ void glfwDefaultWindowHints(void)
GLFWAPI void glfwWindowHint(int target, int hint) GLFWAPI void glfwWindowHint(int target, int hint)
{ {
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
switch (target) switch (target)
{ {
@ -385,11 +373,7 @@ GLFWAPI void glfwDestroyWindow(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
// Allow closing of NULL (to match the behavior of free) // Allow closing of NULL (to match the behavior of free)
if (window == NULL) if (window == NULL)
@ -425,26 +409,14 @@ GLFWAPI void glfwDestroyWindow(GLFWwindow* handle)
GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title) GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_glfwPlatformSetWindowTitle(window, title); _glfwPlatformSetWindowTitle(window, title);
} }
GLFWAPI void glfwGetWindowPos(GLFWwindow* handle, int* xpos, int* ypos) GLFWAPI void glfwGetWindowPos(GLFWwindow* handle, int* xpos, int* ypos)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_glfwPlatformGetWindowPos(window, xpos, ypos); _glfwPlatformGetWindowPos(window, xpos, ypos);
} }
@ -452,11 +424,7 @@ GLFWAPI void glfwSetWindowPos(GLFWwindow* handle, int xpos, int ypos)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (window->monitor) if (window->monitor)
{ {
@ -471,13 +439,7 @@ GLFWAPI void glfwSetWindowPos(GLFWwindow* handle, int xpos, int ypos)
GLFWAPI void glfwGetWindowSize(GLFWwindow* handle, int* width, int* height) GLFWAPI void glfwGetWindowSize(GLFWwindow* handle, int* width, int* height)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_glfwPlatformGetWindowSize(window, width, height); _glfwPlatformGetWindowSize(window, width, height);
} }
@ -485,11 +447,7 @@ GLFWAPI void glfwSetWindowSize(GLFWwindow* handle, int width, int height)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (window->iconified) if (window->iconified)
{ {
@ -510,11 +468,7 @@ GLFWAPI void glfwIconifyWindow(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (window->iconified) if (window->iconified)
return; return;
@ -526,11 +480,7 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (!window->iconified) if (!window->iconified)
return; return;
@ -542,11 +492,7 @@ GLFWAPI void glfwShowWindow(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (window->monitor) if (window->monitor)
return; return;
@ -558,11 +504,7 @@ GLFWAPI void glfwHideWindow(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
if (window->monitor) if (window->monitor)
return; return;
@ -574,11 +516,7 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow* handle, int param)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(0);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
switch (param) switch (param)
{ {
@ -617,139 +555,75 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow* handle, int param)
GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* handle) GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
return (GLFWmonitor*) window->monitor; return (GLFWmonitor*) window->monitor;
} }
GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* handle, void* pointer) GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* handle, void* pointer)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
window->userPointer = pointer; window->userPointer = pointer;
} }
GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* handle) GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
return window->userPointer; return window->userPointer;
} }
GLFWAPI void glfwSetWindowPosCallback(GLFWwindow* handle, GLFWwindowposfun cbfun) GLFWAPI void glfwSetWindowPosCallback(GLFWwindow* handle, GLFWwindowposfun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
window->callbacks.pos = cbfun; window->callbacks.pos = cbfun;
} }
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow* handle, GLFWwindowsizefun cbfun) GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow* handle, GLFWwindowsizefun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
window->callbacks.size = cbfun; window->callbacks.size = cbfun;
} }
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow* handle, GLFWwindowclosefun cbfun) GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow* handle, GLFWwindowclosefun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
window->callbacks.close = cbfun; window->callbacks.close = cbfun;
} }
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow* handle, GLFWwindowrefreshfun cbfun) GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow* handle, GLFWwindowrefreshfun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
window->callbacks.refresh = cbfun; window->callbacks.refresh = cbfun;
} }
GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow* handle, GLFWwindowfocusfun cbfun) GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow* handle, GLFWwindowfocusfun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
window->callbacks.focus = cbfun; window->callbacks.focus = cbfun;
} }
GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindow* handle, GLFWwindowiconifyfun cbfun) GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindow* handle, GLFWwindowiconifyfun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
window->callbacks.iconify = cbfun; window->callbacks.iconify = cbfun;
} }
GLFWAPI void glfwPollEvents(void) GLFWAPI void glfwPollEvents(void)
{ {
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_glfwPlatformPollEvents(); _glfwPlatformPollEvents();
} }
GLFWAPI void glfwWaitEvents(void) GLFWAPI void glfwWaitEvents(void)
{ {
if (!_glfwInitialized) _GLFW_REQUIRE_INIT();
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_glfwPlatformWaitEvents(); _glfwPlatformWaitEvents();
} }

View File

@ -1037,25 +1037,14 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
GLFWAPI Display* glfwGetX11Display(void) GLFWAPI Display* glfwGetX11Display(void)
{ {
if (!_glfwInitialized) _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
return _glfw.x11.display; return _glfw.x11.display;
} }
GLFWAPI Window glfwGetX11Window(GLFWwindow* handle) GLFWAPI Window glfwGetX11Window(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(None);
if (!_glfwInitialized)
{
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
return window->x11.handle; return window->x11.handle;
} }