From bf3486f07710bbe37d2485979e3c99a50d38ef6e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 26 Aug 2012 15:38:18 +0200 Subject: [PATCH 01/12] Comment updates and formatting. --- src/cocoa_gamma.c | 2 +- src/cocoa_input.m | 7 +++-- src/cocoa_joystick.m | 16 ++++------ src/cocoa_window.m | 12 ++------ src/fullscreen.c | 2 +- src/x11_platform.h | 9 +++--- src/x11_window.c | 72 +++++++++++++++++++++----------------------- 7 files changed, 54 insertions(+), 66 deletions(-) diff --git a/src/cocoa_gamma.c b/src/cocoa_gamma.c index 53c47a89..06904516 100644 --- a/src/cocoa_gamma.c +++ b/src/cocoa_gamma.c @@ -40,7 +40,7 @@ //************************************************************************ //======================================================================== -// Save the original gamma ramp so that we can restore it later +// Save the original gamma ramp so that it can be restored later //======================================================================== void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp) diff --git a/src/cocoa_input.m b/src/cocoa_input.m index 869c9cd3..c2bb503c 100644 --- a/src/cocoa_input.m +++ b/src/cocoa_input.m @@ -40,13 +40,14 @@ void _glfwPlatformEnableSystemKeys(_GLFWwindow* window) { - // This is checked in macosx_window.m; we take no action here + // This is checked in cocoa_window.m; no action needed here } void _glfwPlatformDisableSystemKeys(_GLFWwindow* window) { - // This is checked in macosx_window.m; we take no action here - // I don't think it's really possible to disable stuff like Exposé + // This is checked in cocoa_window.m; no action needed here + + // Note that it may not be possible to disable things like Exposé // except in full-screen mode. } diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index bf567f86..7a691f8b 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -46,7 +46,6 @@ //------------------------------------------------------------------------ // Joystick element information //------------------------------------------------------------------------ - typedef struct { IOHIDElementCookie cookie; @@ -65,7 +64,6 @@ typedef struct //------------------------------------------------------------------------ // Joystick information & state //------------------------------------------------------------------------ - typedef struct { int present; @@ -213,7 +211,7 @@ static long getElementValue(_glfwJoystick* joystick, _glfwJoystickElement* eleme &hidEvent); if (kIOReturnSuccess == result) { - /* record min and max for auto calibration */ + // Record min and max for auto calibration if (hidEvent.value < element->minReport) element->minReport = hidEvent.value; if (hidEvent.value > element->maxReport) @@ -221,7 +219,7 @@ static long getElementValue(_glfwJoystick* joystick, _glfwJoystickElement* eleme } } - /* auto user scale */ + // Auto user scale return (long) hidEvent.value; } @@ -384,14 +382,14 @@ void _glfwInitJoysticks(void) if (result != kIOReturnSuccess) continue; - /* Check device type */ + // Check device type refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey)); if (refCF) { CFNumberGetValue(refCF, kCFNumberLongType, &usagePage); if (usagePage != kHIDPage_GenericDesktop) { - /* We are not interested in this device */ + // This device is not relevant to GLFW continue; } } @@ -405,7 +403,7 @@ void _glfwInitJoysticks(void) usage != kHIDUsage_GD_GamePad && usage != kHIDUsage_GD_MultiAxisController)) { - /* We are not interested in this device */ + // This device is not relevant to GLFW continue; } } @@ -439,7 +437,7 @@ void _glfwInitJoysticks(void) joystick, joystick); - /* Get product string */ + // Get product string refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey)); if (refCF) { @@ -561,8 +559,6 @@ int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes) else pos[i] = (2.0f * (axes->value - axes->minReport) / readScale) - 1.0f; - //printf("%ld, %ld, %ld\n", axes->value, axes->minReport, axes->maxReport); - if (i & 1) pos[i] = -pos[i]; } diff --git a/src/cocoa_window.m b/src/cocoa_window.m index d7764f92..aaaff289 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -277,9 +277,6 @@ static int convertMacKeyCode(unsigned int macKeyCode) if (macKeyCode >= 128) return -1; - // This treats keycodes as *positional*; that is, we'll return 'a' - // for the key left of 's', even on an AZERTY keyboard. The charInput - // function should still get 'q' though. return table[macKeyCode]; } @@ -541,7 +538,7 @@ static NSString* findAppName(void) } } - // If we get here, we're unbundled + // If we get here, the application is unbundled ProcessSerialNumber psn = { 0, kCurrentProcess }; TransformProcessType(&psn, kProcessTransformToForegroundApplication); @@ -551,10 +548,7 @@ static NSString* findAppName(void) char** progname = _NSGetProgname(); if (progname && *progname) - { - // TODO: UTF-8? return [NSString stringWithUTF8String:*progname]; - } // Really shouldn't get here return @"GLFW Application"; @@ -866,8 +860,8 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (!initializeAppKit()) return GL_FALSE; - // We can only have one application delegate, but we only allocate it the - // first time we create a window to keep all window code in this file + // There can only be one application delegate, but we allocate it the + // first time a window is created to keep all window code in this file if (_glfwLibrary.NS.delegate == nil) { _glfwLibrary.NS.delegate = [[GLFWApplicationDelegate alloc] init]; diff --git a/src/fullscreen.c b/src/fullscreen.c index 9dab1a59..3ec608ca 100644 --- a/src/fullscreen.c +++ b/src/fullscreen.c @@ -87,7 +87,7 @@ void _glfwSplitBPP(int bpp, int* red, int* green, int* blue) { int delta; - // We assume that by 32 they really meant 24 + // We assume that by 32 the user really meant 24 if (bpp == 32) bpp = 24; diff --git a/src/x11_platform.h b/src/x11_platform.h index 39593655..2d1ffe20 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -42,20 +42,21 @@ #include // This path may need to be changed if you build GLFW using your own setup -// We ship and use our own copy of glxext.h since GLFW uses fairly new +// GLFW comes with its own copy of glxext.h since it uses some fairly new // extensions and not all operating systems come with an up-to-date version #include "../support/GL/glxext.h" -// With XFree86, we can use the XF86VidMode extension +// The XF86VidMode extension provides mode setting and gamma control #if defined(_GLFW_HAS_XF86VIDMODE) #include #endif +// The XRandR extension provides mode setting and gamma control #if defined(_GLFW_HAS_XRANDR) #include #endif -// Do we have support for dlopen/dlsym? +// dlopen is used as a fallback function retrieval mechanism #if defined(_GLFW_HAS_DLOPEN) #include #endif @@ -65,7 +66,7 @@ #include #endif -// We support four different ways for getting addresses for GL/GLX +// GLFW supports four different ways for getting addresses for GL/GLX // extension functions: glXGetProcAddress, glXGetProcAddressARB, // glXGetProcAddressEXT, and dlsym #if defined(_GLFW_HAS_GLXGETPROCADDRESSARB) diff --git a/src/x11_window.c b/src/x11_window.c index 442e76c0..6d7021a0 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -43,21 +43,18 @@ #define Button6 6 #define Button7 7 + //======================================================================== // Translates an X Window key to internal coding //======================================================================== static int translateKey(int keycode) { - // Use the pre-filled LUT (see updateKeyCodeLUT() ). + // Use the pre-filled LUT (see updateKeyCodeLUT() in x11_init.c) if ((keycode >= 0) && (keycode < 256)) - { return _glfwLibrary.X11.keyCodeLUT[keycode]; - } else - { return -1; - } } @@ -90,6 +87,7 @@ static GLboolean createWindow(_GLFWwindow* window, // Every window needs a colormap // Create one based on the visual used by the current context + // TODO: Decouple this from context creation window->X11.colormap = XCreateColormap(_glfwLibrary.X11.display, _glfwLibrary.X11.root, @@ -109,30 +107,29 @@ static GLboolean createWindow(_GLFWwindow* window, if (wndconfig->mode == GLFW_WINDOWED) { - // The /only/ reason we are setting the background pixel here is - // that otherwise our window wont get any decorations on systems - // using Compiz on Intel hardware + // The /only/ reason for setting the background pixel here is that + // otherwise our window won't get any decorations on systems using + // certain versions of Compiz on Intel hardware wa.background_pixel = BlackPixel(_glfwLibrary.X11.display, _glfwLibrary.X11.screen); wamask |= CWBackPixel; } - window->X11.handle = XCreateWindow( - _glfwLibrary.X11.display, - _glfwLibrary.X11.root, - 0, 0, // Upper left corner of this window on root - window->width, window->height, - 0, // Border width - visual->depth, // Color depth - InputOutput, - visual->visual, - wamask, - &wa - ); + window->X11.handle = XCreateWindow(_glfwLibrary.X11.display, + _glfwLibrary.X11.root, + 0, 0, // Position + window->width, window->height, + 0, // Border width + visual->depth, // Color depth + InputOutput, + visual->visual, + wamask, + &wa); if (!window->X11.handle) { - // TODO: Handle all the various error codes here + // TODO: Handle all the various error codes here and translate them + // to GLFW errors _glfwSetError(GLFW_PLATFORM_ERROR, "X11/GLX: Failed to create window"); @@ -147,8 +144,8 @@ static GLboolean createWindow(_GLFWwindow* window, // manager ignore the window completely (ICCCM, section 4) // The good thing is that this makes undecorated fullscreen windows // easy to do; the bad thing is that we have to do everything manually - // and some things (like iconify/restore) won't work at all, as they're - // usually performed by the window manager + // and some things (like iconify/restore) won't work at all, as those + // are tasks usually performed by the window manager XSetWindowAttributes attributes; attributes.override_redirect = True; @@ -165,7 +162,7 @@ static GLboolean createWindow(_GLFWwindow* window, "WM_DELETE_WINDOW", False); - // Declare the WM protocols we support + // Declare the WM protocols supported by GLFW { int count = 0; Atom protocols[2]; @@ -176,8 +173,8 @@ static GLboolean createWindow(_GLFWwindow* window, protocols[count++] = _glfwLibrary.X11.wmDeleteWindow; // The _NET_WM_PING EWMH protocol - // Tells the WM to ping our window and flag us as unresponsive if we - // don't reply within a few seconds + // Tells the WM to ping the GLFW window and flag the application as + // unresponsive if the WM doesn't get a reply within a few seconds if (_glfwLibrary.X11.wmPing != None) protocols[count++] = _glfwLibrary.X11.wmPing; @@ -283,7 +280,7 @@ static void captureCursor(_GLFWwindow* window) static void showCursor(_GLFWwindow* window) { - // Un-grab cursor (only in windowed mode: in fullscreen mode we still + // Un-grab cursor (in windowed mode only; in fullscreen mode we still // want the cursor grabbed in order to confine the cursor to the window // area) if (window->X11.cursorGrabbed) @@ -377,7 +374,7 @@ static void enterFullscreenMode(_GLFWwindow* window) } else if (window->X11.overrideRedirect) { - // In override-redirect mode, we have divorced ourselves from the + // In override-redirect mode we have divorced ourselves from the // window manager, so we need to do everything manually XRaiseWindow(_glfwLibrary.X11.display, window->X11.handle); @@ -405,7 +402,6 @@ static void leaveFullscreenMode(_GLFWwindow* window) { _glfwRestoreVideoMode(); - // Did we change the screen saver setting? if (_glfwLibrary.X11.saver.changed) { // Restore old screen saver settings @@ -648,7 +644,8 @@ static void processSingleEvent(void) if (event.xmotion.x != window->X11.cursorPosX || event.xmotion.y != window->X11.cursorPosY) { - // The cursor was moved and we didn't do it + // The cursor was moved by something other than GLFW + int x, y; if (window->cursorMode == GLFW_CURSOR_CAPTURED) @@ -716,8 +713,8 @@ static void processSingleEvent(void) else if (_glfwLibrary.X11.wmPing != None && (Atom) event.xclient.data.l[0] == _glfwLibrary.X11.wmPing) { - // The window manager is pinging us to make sure we are still - // responding to events + // The window manager is pinging the application to ensure it's + // still responding to events event.xclient.window = _glfwLibrary.X11.root; XSendEvent(_glfwLibrary.X11.display, @@ -864,7 +861,6 @@ static void processSingleEvent(void) { case RRScreenChangeNotify: { - // Show XRandR that we really care XRRUpdateConfiguration(&event); break; } @@ -1071,8 +1067,8 @@ void _glfwPlatformIconifyWindow(_GLFWwindow* window) { if (window->X11.overrideRedirect) { - // We can't iconify/restore override-redirect windows, as that's - // performed by the window manager + // Override-redirect windows cannot be iconified or restored, as those + // tasks are performed by the window manager return; } @@ -1090,8 +1086,8 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window) { if (window->X11.overrideRedirect) { - // We can't iconify/restore override-redirect windows, as that's - // performed by the window manager + // Override-redirect windows cannot be iconified or restored, as those + // tasks are performed by the window manager return; } @@ -1195,7 +1191,7 @@ void _glfwPlatformWaitEvents(void) void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y) { - // Store the new position so we can recognise it later + // Store the new position so it can be recognized later window->X11.cursorPosX = x; window->X11.cursorPosY = y; From c28fb4ca0c7ea922ed864cc71dcdb1b65d1fd472 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 26 Aug 2012 18:11:31 +0200 Subject: [PATCH 02/12] Cleaned up Linux joystick code. --- src/x11_joystick.c | 361 +++++++++++++++++++-------------------------- src/x11_platform.h | 22 ++- 2 files changed, 159 insertions(+), 224 deletions(-) diff --git a/src/x11_joystick.c b/src/x11_joystick.c index 9fc921fd..e54a7c02 100644 --- a/src/x11_joystick.c +++ b/src/x11_joystick.c @@ -30,47 +30,128 @@ #include "internal.h" - -//======================================================================== -// Note: Only Linux joystick input is supported at the moment. Other -// systems will behave as if there are no joysticks connected. -//======================================================================== - - #ifdef _GLFW_USE_LINUX_JOYSTICKS +#include -//------------------------------------------------------------------------ -// Here are the Linux joystick driver v1.x interface definitions that we -// use (we do not want to rely on ): -//------------------------------------------------------------------------ - -#include +#include +#include #include -#include + #include #include - -// Joystick event types -#define JS_EVENT_BUTTON 0x01 /* button pressed/released */ -#define JS_EVENT_AXIS 0x02 /* joystick moved */ -#define JS_EVENT_INIT 0x80 /* initial state of device */ - -// Joystick event structure -struct js_event { - unsigned int time; /* (u32) event timestamp in milliseconds */ - signed short value; /* (s16) value */ - unsigned char type; /* (u8) event type */ - unsigned char number; /* (u8) axis/button number */ -}; - -// Joystick IOCTL commands -#define JSIOCGVERSION _IOR('j', 0x01, int) /* get driver version (u32) */ -#define JSIOCGAXES _IOR('j', 0x11, char) /* get number of axes (u8) */ -#define JSIOCGBUTTONS _IOR('j', 0x12, char) /* get number of buttons (u8) */ - #endif // _GLFW_USE_LINUX_JOYSTICKS +//======================================================================== +// Attempt to open the specified joystick device +//======================================================================== + +static int openJoystickDevice(int joy, const char* path) +{ +#ifdef _GLFW_USE_LINUX_JOYSTICKS + char numAxes, numButtons; + int fd, version; + + fd = open(path, O_NONBLOCK); + if (fd == -1) + return GL_FALSE; + + _glfwLibrary.X11.joystick[joy].fd = fd; + + // Verify that the joystick driver version is at least 1.0 + ioctl(fd, JSIOCGVERSION, &version); + if (version < 0x010000) + { + // It's an old 0.x interface (we don't support it) + close(fd); + return GL_FALSE; + } + + ioctl(fd, JSIOCGAXES, &numAxes); + _glfwLibrary.X11.joystick[joy].numAxes = (int) numAxes; + + ioctl(fd, JSIOCGBUTTONS, &numButtons); + _glfwLibrary.X11.joystick[joy].numButtons = (int) numButtons; + + _glfwLibrary.X11.joystick[joy].axis = + (float*) malloc(sizeof(float) * numAxes); + if (_glfwLibrary.X11.joystick[joy].axis == NULL) + { + close(fd); + + _glfwSetError(GLFW_OUT_OF_MEMORY, NULL); + return GL_FALSE; + } + + _glfwLibrary.X11.joystick[joy].button = + (unsigned char*) malloc(sizeof(char) * numButtons); + if (_glfwLibrary.X11.joystick[joy].button == NULL) + { + free(_glfwLibrary.X11.joystick[joy].axis); + close(fd); + + _glfwSetError(GLFW_OUT_OF_MEMORY, NULL); + return GL_FALSE; + } + + _glfwLibrary.X11.joystick[joy].present = GL_TRUE; +#endif // _GLFW_USE_LINUX_JOYSTICKS + + return GL_TRUE; +} + + +//======================================================================== +// Polls for and processes events for all present joysticks +//======================================================================== + +static void pollJoystickEvents(void) +{ +#ifdef _GLFW_USE_LINUX_JOYSTICKS + int i; + struct js_event e; + + for (i = 0; i <= GLFW_JOYSTICK_LAST; i++) + { + if (!_glfwLibrary.X11.joystick[i].present) + continue; + + // Read all queued events (non-blocking) + while (read(_glfwLibrary.X11.joystick[i].fd, &e, sizeof(e)) > 0) + { + // We don't care if it's an init event or not + e.type &= ~JS_EVENT_INIT; + + switch (e.type) + { + case JS_EVENT_AXIS: + _glfwLibrary.X11.joystick[i].axis[e.number] = + (float) e.value / 32767.0f; + + // We need to change the sign for the Y axes, so that + // positive = up/forward, according to the GLFW spec. + if (e.number & 1) + { + _glfwLibrary.X11.joystick[i].axis[e.number] = + -_glfwLibrary.X11.joystick[i].axis[e.number]; + } + + break; + + case JS_EVENT_BUTTON: + _glfwLibrary.X11.joystick[i].button[e.number] = + e.value ? GLFW_PRESS : GLFW_RELEASE; + break; + + default: + break; + } + } + } +#endif // _GLFW_USE_LINUX_JOYSTICKS +} + + ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// @@ -82,97 +163,24 @@ struct js_event { void _glfwInitJoysticks(void) { #ifdef _GLFW_USE_LINUX_JOYSTICKS - int k, n, fd, joy_count; - const char* joy_base_name; - char joy_dev_name[20]; - int driver_version = 0x000800; - char ret_data; -#endif // _GLFW_USE_LINUX_JOYSTICKS - int i; - - // Start by saying that there are no sticks - for (i = 0; i <= GLFW_JOYSTICK_LAST; i++) - _glfwJoy[i].Present = GL_FALSE; - -#ifdef _GLFW_USE_LINUX_JOYSTICKS - - // Try to open joysticks (nonblocking) - joy_count = 0; - for (k = 0; k <= 1 && joy_count <= GLFW_JOYSTICK_LAST; k++) + int i, j, joy = 0; + char path[20]; + const char* bases[] = { - // Pick joystick base name - switch (k) + "/dev/input/js", + "/dev/js" + }; + + for (i = 0; i < sizeof(bases) / sizeof(bases[0]); i++) + { + for (j = 0; j < 50; j++) { - case 0: - // USB joysticks - joy_base_name = "/dev/input/js"; + if (joy > GLFW_JOYSTICK_LAST) break; - case 1: - // "Legacy" joysticks - joy_base_name = "/dev/js"; - break; - default: - // This should never happen - continue; - } - // Try to open a few of these sticks - for (i = 0; i <= 50 && joy_count <= GLFW_JOYSTICK_LAST; i++) - { - sprintf(joy_dev_name, "%s%d", joy_base_name, i); - fd = open(joy_dev_name, O_NONBLOCK); - if (fd != -1) - { - // Remember fd - _glfwJoy[joy_count].fd = fd; - - // Check that the joystick driver version is 1.0+ - ioctl(fd, JSIOCGVERSION, &driver_version); - if (driver_version < 0x010000) - { - // It's an old 0.x interface (we don't support it) - close(fd); - continue; - } - - // Get number of joystick axes - ioctl(fd, JSIOCGAXES, &ret_data); - _glfwJoy[joy_count].NumAxes = (int) ret_data; - - // Get number of joystick buttons - ioctl(fd, JSIOCGBUTTONS, &ret_data); - _glfwJoy[joy_count].NumButtons = (int) ret_data; - - // Allocate memory for joystick state - _glfwJoy[joy_count].Axis = - (float*) malloc(sizeof(float) * - _glfwJoy[joy_count].NumAxes); - if (_glfwJoy[joy_count].Axis == NULL) - { - close(fd); - continue; - } - _glfwJoy[joy_count].Button = - (unsigned char*) malloc(sizeof(char) * - _glfwJoy[joy_count].NumButtons); - if (_glfwJoy[joy_count].Button == NULL) - { - free(_glfwJoy[joy_count].Axis); - close(fd); - continue; - } - - // Clear joystick state - for (n = 0; n < _glfwJoy[joy_count].NumAxes; n++) - _glfwJoy[joy_count].Axis[n] = 0.0f; - - for (n = 0; n < _glfwJoy[joy_count].NumButtons; n++) - _glfwJoy[joy_count].Button[n] = GLFW_RELEASE; - - // The joystick is supported and connected - _glfwJoy[joy_count].Present = GL_TRUE; - joy_count++; - } + sprintf(path, "%s%i", bases[i], j); + if (openJoystickDevice(joy, path)) + joy++; } } #endif // _GLFW_USE_LINUX_JOYSTICKS @@ -185,72 +193,18 @@ void _glfwInitJoysticks(void) void _glfwTerminateJoysticks(void) { - #ifdef _GLFW_USE_LINUX_JOYSTICKS - int i; - // Close any opened joysticks for (i = 0; i <= GLFW_JOYSTICK_LAST; i++) { - if (_glfwJoy[i].Present) + if (_glfwLibrary.X11.joystick[i].present) { - close(_glfwJoy[i].fd); - free(_glfwJoy[i].Axis); - free(_glfwJoy[i].Button); + close(_glfwLibrary.X11.joystick[i].fd); + free(_glfwLibrary.X11.joystick[i].axis); + free(_glfwLibrary.X11.joystick[i].button); - _glfwJoy[i].Present = GL_FALSE; - } - } - -#endif // _GLFW_USE_LINUX_JOYSTICKS - -} - - -//======================================================================== -// Empty joystick event queue -//======================================================================== - -static void pollJoystickEvents(void) -{ -#ifdef _GLFW_USE_LINUX_JOYSTICKS - - struct js_event e; - int i; - - // Get joystick events for all GLFW joysticks - for (i = 0; i <= GLFW_JOYSTICK_LAST; i++) - { - // Is the stick present? - if (_glfwJoy[i].Present) - { - // Read all queued events (non-blocking) - while (read(_glfwJoy[i].fd, &e, sizeof(struct js_event)) > 0) - { - // We don't care if it's an init event or not - e.type &= ~JS_EVENT_INIT; - - // Check event type - switch (e.type) - { - case JS_EVENT_AXIS: - _glfwJoy[i].Axis[e.number] = (float) e.value / 32767.0f; - // We need to change the sign for the Y axes, so that - // positive = up/forward, according to the GLFW spec. - if (e.number & 1) - _glfwJoy[i].Axis[e.number] = -_glfwJoy[i].Axis[e.number]; - break; - - case JS_EVENT_BUTTON: - _glfwJoy[i].Button[e.number] = - e.value ? GLFW_PRESS : GLFW_RELEASE; - break; - - default: - break; - } - } + _glfwLibrary.X11.joystick[i].present = GL_FALSE; } } #endif // _GLFW_USE_LINUX_JOYSTICKS @@ -267,11 +221,8 @@ static void pollJoystickEvents(void) int _glfwPlatformGetJoystickParam(int joy, int param) { - if (!_glfwJoy[joy].Present) - { - // TODO: Figure out if this is an error + if (!_glfwLibrary.X11.joystick[joy].present) return 0; - } switch (param) { @@ -279,10 +230,10 @@ int _glfwPlatformGetJoystickParam(int joy, int param) return GL_TRUE; case GLFW_AXES: - return _glfwJoy[joy].NumAxes; + return _glfwLibrary.X11.joystick[joy].numAxes; case GLFW_BUTTONS: - return _glfwJoy[joy].NumButtons; + return _glfwLibrary.X11.joystick[joy].numButtons; default: break; @@ -296,28 +247,22 @@ int _glfwPlatformGetJoystickParam(int joy, int param) // Get joystick axis positions //======================================================================== -int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes) +int _glfwPlatformGetJoystickPos(int joy, float* pos, int numAxes) { int i; - if (!_glfwJoy[joy].Present) - { - // TODO: Figure out if this is an error + if (!_glfwLibrary.X11.joystick[joy].present) return 0; - } - // Update joystick state pollJoystickEvents(); - // Does the joystick support less axes than requested? - if (_glfwJoy[joy].NumAxes < numaxes) - numaxes = _glfwJoy[joy].NumAxes; + if (_glfwLibrary.X11.joystick[joy].numAxes < numAxes) + numAxes = _glfwLibrary.X11.joystick[joy].numAxes; - // Copy axis positions from internal state - for (i = 0; i < numaxes; i++) - pos[i] = _glfwJoy[joy].Axis[i]; + for (i = 0; i < numAxes; i++) + pos[i] = _glfwLibrary.X11.joystick[joy].axis[i]; - return numaxes; + return numAxes; } @@ -326,27 +271,21 @@ int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes) //======================================================================== int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, - int numbuttons) + int numButtons) { int i; - if (!_glfwJoy[joy].Present) - { - // TODO: Figure out if this is an error + if (!_glfwLibrary.X11.joystick[joy].present) return 0; - } - // Update joystick state pollJoystickEvents(); - // Does the joystick support less buttons than requested? - if (_glfwJoy[joy].NumButtons < numbuttons) - numbuttons = _glfwJoy[joy].NumButtons; + if (_glfwLibrary.X11.joystick[joy].numButtons < numButtons) + numButtons = _glfwLibrary.X11.joystick[joy].numButtons; - // Copy button states from internal state - for (i = 0; i < numbuttons; i++) - buttons[i] = _glfwJoy[joy].Button[i]; + for (i = 0; i < numButtons; i++) + buttons[i] = _glfwLibrary.X11.joystick[joy].button[i]; - return numbuttons; + return numButtons; } diff --git a/src/x11_platform.h b/src/x11_platform.h index 2d1ffe20..75beb745 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -233,6 +233,15 @@ typedef struct _GLFWlibraryX11 int status; } selection; + struct { + int present; + int fd; + int numAxes; + int numButtons; + float* axis; + unsigned char* button; + } joystick[GLFW_JOYSTICK_LAST + 1]; + } _GLFWlibraryX11; @@ -269,19 +278,6 @@ typedef struct _GLFWlibraryGLX } _GLFWlibraryGLX; -//------------------------------------------------------------------------ -// Joystick information & state -//------------------------------------------------------------------------ -GLFWGLOBAL struct { - int Present; - int fd; - int NumAxes; - int NumButtons; - float* Axis; - unsigned char* Button; -} _glfwJoy[GLFW_JOYSTICK_LAST + 1]; - - //======================================================================== // Prototypes for platform specific internal functions //======================================================================== From 1839c1c73d65ee81551db366a8561adcd609ee88 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 26 Aug 2012 18:28:30 +0200 Subject: [PATCH 03/12] Added joystick API error checks for shared and Linux code. --- src/joystick.c | 30 ++++++++++++++++++++++++++++++ src/x11_joystick.c | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/joystick.c b/src/joystick.c index 682ba4b0..d7f98758 100644 --- a/src/joystick.c +++ b/src/joystick.c @@ -47,6 +47,12 @@ GLFWAPI int glfwGetJoystickParam(int joy, int param) return 0; } + if (joy < 0 || joy > GLFW_JOYSTICK_LAST) + { + _glfwSetError(GLFW_INVALID_ENUM, NULL); + return 0; + } + return _glfwPlatformGetJoystickParam(joy, param); } @@ -65,6 +71,18 @@ GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes) return 0; } + if (joy < 0 || joy > GLFW_JOYSTICK_LAST) + { + _glfwSetError(GLFW_INVALID_ENUM, NULL); + return 0; + } + + if (pos == NULL || numaxes < 0) + { + _glfwSetError(GLFW_INVALID_VALUE, NULL); + return 0; + } + // Clear positions for (i = 0; i < numaxes; i++) pos[i] = 0.0f; @@ -89,6 +107,18 @@ GLFWAPI int glfwGetJoystickButtons(int joy, return 0; } + if (joy < 0 || joy > GLFW_JOYSTICK_LAST) + { + _glfwSetError(GLFW_INVALID_ENUM, NULL); + return 0; + } + + if (buttons == NULL || numbuttons < 0) + { + _glfwSetError(GLFW_INVALID_VALUE, NULL); + return 0; + } + // Clear button states for (i = 0; i < numbuttons; i++) buttons[i] = GLFW_RELEASE; diff --git a/src/x11_joystick.c b/src/x11_joystick.c index e54a7c02..523a4b3d 100644 --- a/src/x11_joystick.c +++ b/src/x11_joystick.c @@ -236,7 +236,7 @@ int _glfwPlatformGetJoystickParam(int joy, int param) return _glfwLibrary.X11.joystick[joy].numButtons; default: - break; + _glfwSetError(GLFW_INVALID_ENUM, NULL); } return 0; From 5d52ad15485207684410487476f5d965a8d23674 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 26 Aug 2012 18:42:15 +0200 Subject: [PATCH 04/12] Replaced GLFWGLOBAL and _init_c_ with extern. --- src/init.c | 18 +++++++++++++++++- src/internal.h | 23 +++++------------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/init.c b/src/init.c index e1d5dfc9..9303c255 100644 --- a/src/init.c +++ b/src/init.c @@ -28,13 +28,29 @@ // //======================================================================== -#define _init_c_ #include "internal.h" #include #include +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +//======================================================================== +// Platform independent global state shared between compilation units +//======================================================================== + +// Flag indicating whether GLFW has been initialized +GLboolean _glfwInitialized = GL_FALSE; + +// All global data protected by _glfwInitialized +// This data should only be touched after a call to glfwInit that has +// not been followed by a call to glfwTerminate +_GLFWlibrary _glfwLibrary; + + ////////////////////////////////////////////////////////////////////////// ////// GLFW public API ////// ////////////////////////////////////////////////////////////////////////// diff --git a/src/internal.h b/src/internal.h index 89ac48b2..d286c5cb 100644 --- a/src/internal.h +++ b/src/internal.h @@ -31,17 +31,6 @@ #ifndef _internal_h_ #define _internal_h_ -//======================================================================== -// GLFWGLOBAL is a macro that places all global variables in the init.c -// module (all other modules reference global variables as 'extern') -//======================================================================== - -#if defined(_init_c_) - #define GLFWGLOBAL -#else - #define GLFWGLOBAL extern -#endif - //======================================================================== // Input handling definitions @@ -245,17 +234,15 @@ struct _GLFWlibrary //======================================================================== -// System independent global variables (GLFW internals) +// Platform independent global state shared between compilation units +// These are exported from init.c //======================================================================== // Flag indicating if GLFW has been initialized -#if defined(_init_c_) -GLboolean _glfwInitialized = GL_FALSE; -#else -GLFWGLOBAL GLboolean _glfwInitialized; -#endif +extern GLboolean _glfwInitialized; -GLFWGLOBAL _GLFWlibrary _glfwLibrary; +// All global data protected by _glfwInitialized +extern _GLFWlibrary _glfwLibrary; //======================================================================== From 85ca7ee1844e2ca6648cee45245ae1e8b57772f1 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 26 Aug 2012 18:42:59 +0200 Subject: [PATCH 05/12] Shortened comment. --- src/init.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/init.c b/src/init.c index 9303c255..12dcd862 100644 --- a/src/init.c +++ b/src/init.c @@ -66,8 +66,7 @@ GLFWAPI int glfwInit(void) memset(&_glfwLibrary, 0, sizeof(_glfwLibrary)); - // Not all window hints have zero as their default value, so this - // needs to be here despite the memset above + // Not all window hints have zero as their default value _glfwSetDefaultWindowHints(); if (!_glfwPlatformInit()) From bd5ff15769d3602929c3d584410597a7b547e6f2 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 26 Aug 2012 18:49:39 +0200 Subject: [PATCH 06/12] Moved error handling to init module. --- src/CMakeLists.txt | 2 +- src/error.c | 149 --------------------------------------------- src/init.c | 113 ++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 150 deletions(-) delete mode 100644 src/error.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5e735991..eaf37325 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,7 @@ include_directories(${GLFW_SOURCE_DIR}/src ${glfw_INCLUDE_DIRS}) set(common_HEADERS ${GLFW_SOURCE_DIR}/include/GL/glfw3.h internal.h) -set(common_SOURCES clipboard.c error.c fullscreen.c gamma.c init.c input.c +set(common_SOURCES clipboard.c fullscreen.c gamma.c init.c input.c joystick.c opengl.c time.c window.c) if (_GLFW_COCOA_NSGL) diff --git a/src/error.c b/src/error.c deleted file mode 100644 index d64cb7cc..00000000 --- a/src/error.c +++ /dev/null @@ -1,149 +0,0 @@ -//======================================================================== -// GLFW - An OpenGL library -// Platform: All -// API version: 3.0 -// WWW: http://www.glfw.org/ -//------------------------------------------------------------------------ -// Copyright (c) 2008-2010 Camilla Berglund -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would -// be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not -// be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source -// distribution. -// -//======================================================================== - -#include "internal.h" - -#include -#include - - -////////////////////////////////////////////////////////////////////////// -////// GLFW internal API ////// -////////////////////////////////////////////////////////////////////////// - -//======================================================================== -// The current error value and callback -// These are not in _glfwLibrary since they need to be initialized and -// accessible before glfwInit so it can report errors -//======================================================================== - -static int _glfwError = GLFW_NO_ERROR; -static GLFWerrorfun _glfwErrorCallback = NULL; - - -//======================================================================== -// Sets the current error value -// This function may be called without GLFW having been initialized -//======================================================================== - -void _glfwSetError(int error, const char* format, ...) -{ - if (_glfwErrorCallback) - { - char buffer[16384]; - const char* description; - - if (format) - { - int count; - va_list vl; - - va_start(vl, format); - count = vsnprintf(buffer, sizeof(buffer), format, vl); - va_end(vl); - - if (count < 0) - buffer[sizeof(buffer) - 1] = '\0'; - - description = buffer; - } - else - description = glfwErrorString(error); - - _glfwErrorCallback(error, description); - } - else - _glfwError = error; -} - - -////////////////////////////////////////////////////////////////////////// -////// GLFW public API ////// -////////////////////////////////////////////////////////////////////////// - -//======================================================================== -// Returns the current error value -// This function may be called without GLFW having been initialized -//======================================================================== - -GLFWAPI int glfwGetError(void) -{ - int error = _glfwError; - _glfwError = GLFW_NO_ERROR; - return error; -} - - -//======================================================================== -// Returns a string representation of the specified error value -// This function may be called without GLFW having been initialized -//======================================================================== - -GLFWAPI const char* glfwErrorString(int error) -{ - switch (error) - { - case GLFW_NO_ERROR: - return "No error"; - case GLFW_NOT_INITIALIZED: - return "The GLFW library is not initialized"; - case GLFW_NO_CURRENT_CONTEXT: - return "There is no current OpenGL context"; - case GLFW_INVALID_ENUM: - return "Invalid argument for enum parameter"; - case GLFW_INVALID_VALUE: - return "Invalid value for parameter"; - case GLFW_OUT_OF_MEMORY: - return "Out of memory"; - case GLFW_OPENGL_UNAVAILABLE: - return "OpenGL is not available on this machine"; - case GLFW_VERSION_UNAVAILABLE: - return "The requested OpenGL version is unavailable"; - case GLFW_PLATFORM_ERROR: - return "A platform-specific error occurred"; - case GLFW_WINDOW_NOT_ACTIVE: - return "The specified window is not active"; - case GLFW_FORMAT_UNAVAILABLE: - return "The requested format is unavailable"; - } - - return "ERROR: UNKNOWN ERROR TOKEN PASSED TO glfwErrorString"; -} - - -//======================================================================== -// Sets the callback function for GLFW errors -// This function may be called without GLFW having been initialized -//======================================================================== - -GLFWAPI void glfwSetErrorCallback(GLFWerrorfun cbfun) -{ - _glfwErrorCallback = cbfun; -} - diff --git a/src/init.c b/src/init.c index 12dcd862..28f3a52f 100644 --- a/src/init.c +++ b/src/init.c @@ -32,6 +32,8 @@ #include #include +#include +#include ////////////////////////////////////////////////////////////////////////// @@ -51,6 +53,56 @@ GLboolean _glfwInitialized = GL_FALSE; _GLFWlibrary _glfwLibrary; +//======================================================================== +// Platform independent global error state +// These are not in _glfwLibrary because they need to be initialized and +// usable before glfwInit so it can report errors to the user +//======================================================================== + +// The current error code +// TODO: Make thread-local +static int _glfwError = GLFW_NO_ERROR; + +// The current error callback +static GLFWerrorfun _glfwErrorCallback = NULL; + + +//======================================================================== +// Sets the current error value +// This function may be called without GLFW having been initialized +//======================================================================== + +void _glfwSetError(int error, const char* format, ...) +{ + if (_glfwErrorCallback) + { + char buffer[16384]; + const char* description; + + if (format) + { + int count; + va_list vl; + + va_start(vl, format); + count = vsnprintf(buffer, sizeof(buffer), format, vl); + va_end(vl); + + if (count < 0) + buffer[sizeof(buffer) - 1] = '\0'; + + description = buffer; + } + else + description = glfwErrorString(error); + + _glfwErrorCallback(error, description); + } + else + _glfwError = error; +} + + ////////////////////////////////////////////////////////////////////////// ////// GLFW public API ////// ////////////////////////////////////////////////////////////////////////// @@ -132,3 +184,64 @@ GLFWAPI const char* glfwGetVersionString(void) return _glfwPlatformGetVersionString(); } + +//======================================================================== +// Returns the current error value +// This function may be called without GLFW having been initialized +//======================================================================== + +GLFWAPI int glfwGetError(void) +{ + int error = _glfwError; + _glfwError = GLFW_NO_ERROR; + return error; +} + + +//======================================================================== +// Returns a string representation of the specified error value +// This function may be called without GLFW having been initialized +//======================================================================== + +GLFWAPI const char* glfwErrorString(int error) +{ + switch (error) + { + case GLFW_NO_ERROR: + return "No error"; + case GLFW_NOT_INITIALIZED: + return "The GLFW library is not initialized"; + case GLFW_NO_CURRENT_CONTEXT: + return "There is no current OpenGL context"; + case GLFW_INVALID_ENUM: + return "Invalid argument for enum parameter"; + case GLFW_INVALID_VALUE: + return "Invalid value for parameter"; + case GLFW_OUT_OF_MEMORY: + return "Out of memory"; + case GLFW_OPENGL_UNAVAILABLE: + return "OpenGL is not available on this machine"; + case GLFW_VERSION_UNAVAILABLE: + return "The requested OpenGL version is unavailable"; + case GLFW_PLATFORM_ERROR: + return "A platform-specific error occurred"; + case GLFW_WINDOW_NOT_ACTIVE: + return "The specified window is not active"; + case GLFW_FORMAT_UNAVAILABLE: + return "The requested format is unavailable"; + } + + return "ERROR: UNKNOWN ERROR TOKEN PASSED TO glfwErrorString"; +} + + +//======================================================================== +// Sets the callback function for GLFW errors +// This function may be called without GLFW having been initialized +//======================================================================== + +GLFWAPI void glfwSetErrorCallback(GLFWerrorfun cbfun) +{ + _glfwErrorCallback = cbfun; +} + From aaaac00aa511f1b7449b2c52fbbed5ddc66a5d7c Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 26 Aug 2012 20:11:32 +0200 Subject: [PATCH 07/12] Comment fixes. --- src/init.c | 61 +++++++++++++++++++++++++++----------------------- src/internal.h | 14 +++++------- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/init.c b/src/init.c index 28f3a52f..7e9fe4e7 100644 --- a/src/init.c +++ b/src/init.c @@ -36,40 +36,43 @@ #include +//------------------------------------------------------------------------ +// Flag indicating whether GLFW has been successfully initialized +//------------------------------------------------------------------------ +GLboolean _glfwInitialized = GL_FALSE; + + +//------------------------------------------------------------------------ +// All shared and API-specific global data protected by _glfwInitialized +// This should only be touched after a call to glfwInit that has not been +// followed by a call to glfwTerminate +//------------------------------------------------------------------------ +_GLFWlibrary _glfwLibrary; + + +//------------------------------------------------------------------------ +// The current GLFW error code +// This is outside of _glfwLibrary so it can be initialized and usable +// before glfwInit is called, which lets that function report errors +// TODO: Make this thread-local +//------------------------------------------------------------------------ +static int _glfwError = GLFW_NO_ERROR; + + +//------------------------------------------------------------------------ +// The current error callback +// This is outside of _glfwLibrary so it can be initialized and usable +// before glfwInit is called, which lets that function report errors +//------------------------------------------------------------------------ +static GLFWerrorfun _glfwErrorCallback = NULL; + + ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// -//======================================================================== -// Platform independent global state shared between compilation units -//======================================================================== - -// Flag indicating whether GLFW has been initialized -GLboolean _glfwInitialized = GL_FALSE; - -// All global data protected by _glfwInitialized -// This data should only be touched after a call to glfwInit that has -// not been followed by a call to glfwTerminate -_GLFWlibrary _glfwLibrary; - - -//======================================================================== -// Platform independent global error state -// These are not in _glfwLibrary because they need to be initialized and -// usable before glfwInit so it can report errors to the user -//======================================================================== - -// The current error code -// TODO: Make thread-local -static int _glfwError = GLFW_NO_ERROR; - -// The current error callback -static GLFWerrorfun _glfwErrorCallback = NULL; - - //======================================================================== // Sets the current error value -// This function may be called without GLFW having been initialized //======================================================================== void _glfwSetError(int error, const char* format, ...) @@ -160,6 +163,7 @@ GLFWAPI void glfwTerminate(void) //======================================================================== // Get GLFW version +// This function may be called without GLFW having been initialized //======================================================================== GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev) @@ -177,6 +181,7 @@ GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev) //======================================================================== // Get the GLFW version string +// This function may be called without GLFW having been initialized //======================================================================== GLFWAPI const char* glfwGetVersionString(void) diff --git a/src/internal.h b/src/internal.h index d286c5cb..9129b50c 100644 --- a/src/internal.h +++ b/src/internal.h @@ -233,15 +233,11 @@ struct _GLFWlibrary }; -//======================================================================== -// Platform independent global state shared between compilation units -// These are exported from init.c -//======================================================================== - -// Flag indicating if GLFW has been initialized +//------------------------------------------------------------------------ +// Global state shared between compilation units of GLFW +// These are exported from and documented in init.c +//------------------------------------------------------------------------ extern GLboolean _glfwInitialized; - -// All global data protected by _glfwInitialized extern _GLFWlibrary _glfwLibrary; @@ -312,7 +308,7 @@ void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long int _glfwCompareVideoModes(const GLFWvidmode* first, const GLFWvidmode* second); void _glfwSplitBPP(int bpp, int* red, int* green, int* blue); -// Error handling (error.c) +// Error handling (init.c) void _glfwSetError(int error, const char* format, ...); // Window management (window.c) From bb635729ec16a9882b5743d897a15654d274c13d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 26 Aug 2012 21:29:39 +0200 Subject: [PATCH 08/12] Fixed spelling of GLFW. --- src/cocoa_joystick.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index d5298e41..f3e113b4 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -283,7 +283,7 @@ static void removalCallback(void* target, IOReturn result, void* refcon, void* s //======================================================================== -// Polls for joystick events and updates GFLW state +// Polls for joystick events and updates GLFW state //======================================================================== static void pollJoystickEvents(void) From f637722fa1c12759b981a4c8bc6b8c3493cde9fa Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 27 Aug 2012 02:40:26 +0200 Subject: [PATCH 09/12] Removed MinGW-w64 hack. --- include/GL/glfw3.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 050f0c30..5172da21 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -67,12 +67,6 @@ extern "C" { #endif #endif /* APIENTRY */ -/* TEMPORARY MinGW-w64 hacks. - */ -#if __MINGW64__ - #define WINAPI -#endif - /* The following three defines are here solely to make some Windows-based * files happy. Theoretically we could include , but * it has the major drawback of severely polluting our namespace. From 2a8b2ccef4b8f15600a8a36c344c6078a84f31ae Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 27 Aug 2012 03:25:58 +0200 Subject: [PATCH 10/12] Split internal prototypes into APIs. --- src/internal.h | 54 +++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/internal.h b/src/internal.h index 9129b50c..8fe3b241 100644 --- a/src/internal.h +++ b/src/internal.h @@ -242,38 +242,41 @@ extern _GLFWlibrary _glfwLibrary; //======================================================================== -// Prototypes for platform specific implementation functions +// Prototypes for the platform API +// This is the interface exposed by the platform-specific code for each +// platform and is called by the shared code of the public API +// It mirrors the public API except it uses objects instead of handles //======================================================================== -// Init/terminate +// Platform init and version int _glfwPlatformInit(void); int _glfwPlatformTerminate(void); const char* _glfwPlatformGetVersionString(void); -// Input +// Input mode support void _glfwPlatformEnableSystemKeys(_GLFWwindow* window); void _glfwPlatformDisableSystemKeys(_GLFWwindow* window); void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y); void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode); -// Fullscreen +// Video mode support GLFWvidmode* _glfwPlatformGetVideoModes(int* count); void _glfwPlatformGetDesktopMode(GLFWvidmode* mode); -// Gamma ramp +// Gamma ramp support void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp); void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp); -// Clipboard +// Clipboard support void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string); const char* _glfwPlatformGetClipboardString(_GLFWwindow* window); -// Joystick +// Joystick input int _glfwPlatformGetJoystickParam(int joy, int param); int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes); int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons); -// Time +// Time input double _glfwPlatformGetTime(void); void _glfwPlatformSetTime(double time); @@ -286,7 +289,7 @@ void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y); void _glfwPlatformIconifyWindow(_GLFWwindow* window); void _glfwPlatformRestoreWindow(_GLFWwindow* window); -// Event management +// Event processing void _glfwPlatformPollEvents(void); void _glfwPlatformWaitEvents(void); @@ -301,19 +304,12 @@ void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long //======================================================================== -// Prototypes for platform independent internal functions +// Prototypes for the event API +// This is used by the platform-specific code to notify the shared code of +// events that can be translated into state changes and/or callback calls, +// instead of directly calling callbacks or modifying shared state //======================================================================== -// Fullscren management (fullscreen.c) -int _glfwCompareVideoModes(const GLFWvidmode* first, const GLFWvidmode* second); -void _glfwSplitBPP(int bpp, int* red, int* green, int* blue); - -// Error handling (init.c) -void _glfwSetError(int error, const char* format, ...); - -// Window management (window.c) -void _glfwSetDefaultWindowHints(void); - // Window event notification (window.c) void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated); void _glfwInputWindowPos(_GLFWwindow* window, int x, int y); @@ -330,6 +326,24 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action); void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y); void _glfwInputCursorEnter(_GLFWwindow* window, int entered); + +//======================================================================== +// Prototypes for internal utility functions +// These functions are shared code and may be used by any part of GLFW +// Each platform may add its own utility functions, but those may only be +// called by the platform-specific code +//======================================================================== + +// Fullscren management (fullscreen.c) +int _glfwCompareVideoModes(const GLFWvidmode* first, const GLFWvidmode* second); +void _glfwSplitBPP(int bpp, int* red, int* green, int* blue); + +// Error handling (init.c) +void _glfwSetError(int error, const char* format, ...); + +// Window management (window.c) +void _glfwSetDefaultWindowHints(void); + // OpenGL context helpers (opengl.c) int _glfwStringInExtensionString(const char* string, const GLubyte* extensions); const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired, From 96963213343971959c94dc94d03b8b93e22730ac Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 27 Aug 2012 13:52:10 +0200 Subject: [PATCH 11/12] Fixed return value of glfwGetCurrentContext. --- src/opengl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opengl.c b/src/opengl.c index 67c6f414..a23a5f34 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -509,7 +509,7 @@ GLFWAPI GLFWwindow glfwGetCurrentContext(void) if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); - return GL_FALSE; + return NULL; } return _glfwLibrary.currentWindow; From e10d935efe8f3da472c1db98f977378020a74a8b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 28 Aug 2012 15:03:57 +0200 Subject: [PATCH 12/12] API tag and error message cleanup. --- src/cocoa_clipboard.m | 4 ++-- src/cocoa_fullscreen.m | 2 +- src/cocoa_gamma.c | 2 +- src/cocoa_input.m | 2 +- src/cocoa_joystick.m | 2 +- src/cocoa_time.c | 2 +- src/cocoa_window.m | 32 +++++++++++++++----------------- src/win32_clipboard.c | 14 +++++++------- src/win32_dllmain.c | 2 +- src/win32_fullscreen.c | 2 +- src/win32_gamma.c | 2 +- src/win32_input.c | 2 +- src/win32_joystick.c | 2 +- src/win32_opengl.c | 40 +++++++++++++++++++--------------------- src/win32_time.c | 2 +- src/win32_window.c | 14 +++++++------- src/window.c | 5 ++--- src/x11_clipboard.c | 4 ++-- src/x11_fullscreen.c | 4 ++-- src/x11_gamma.c | 6 +++--- src/x11_init.c | 4 ++-- src/x11_input.c | 2 +- src/x11_joystick.c | 2 +- src/x11_keysym2unicode.c | 2 +- src/x11_opengl.c | 33 ++++++++++++++------------------- src/x11_time.c | 2 +- src/x11_window.c | 7 +++---- 27 files changed, 93 insertions(+), 104 deletions(-) diff --git a/src/cocoa_clipboard.m b/src/cocoa_clipboard.m index 56b98437..99918f77 100644 --- a/src/cocoa_clipboard.m +++ b/src/cocoa_clipboard.m @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: Cocoa/NSOpenGL +// Platform: Cocoa // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ @@ -70,7 +70,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) if (!object) { _glfwSetError(GLFW_PLATFORM_ERROR, - "Cocoa/NSGL: Failed to retrieve object from pasteboard"); + "Cocoa: Failed to retrieve object from pasteboard"); return NULL; } diff --git a/src/cocoa_fullscreen.m b/src/cocoa_fullscreen.m index 9382993b..47f86739 100644 --- a/src/cocoa_fullscreen.m +++ b/src/cocoa_fullscreen.m @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: Cocoa/NSOpenGL +// Platform: Cocoa // API Version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/cocoa_gamma.c b/src/cocoa_gamma.c index 06904516..85d1e489 100644 --- a/src/cocoa_gamma.c +++ b/src/cocoa_gamma.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: Cocoa/NSOpenGL +// Platform: Cocoa // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/cocoa_input.m b/src/cocoa_input.m index c2bb503c..11e1083b 100644 --- a/src/cocoa_input.m +++ b/src/cocoa_input.m @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: Cocoa/NSOpenGL +// Platform: Cocoa // API Version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index f3e113b4..ff4ba958 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: Cocoa/NSOpenGL +// Platform: Cocoa // API Version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/cocoa_time.c b/src/cocoa_time.c index 745b4239..d80dd147 100644 --- a/src/cocoa_time.c +++ b/src/cocoa_time.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: Cocoa/NSOpenGL +// Platform: Cocoa // API Version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/cocoa_window.m b/src/cocoa_window.m index aaaff289..5129a21f 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -674,8 +674,7 @@ static GLboolean createWindow(_GLFWwindow* window, if (window->NS.object == nil) { - _glfwSetError(GLFW_PLATFORM_ERROR, - "Cocoa/NSOpenGL: Failed to create window"); + _glfwSetError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to create window"); return GL_FALSE; } @@ -717,8 +716,8 @@ static GLboolean createContext(_GLFWwindow* window, (wndconfig->glMajor == 3 && wndconfig->glMinor != 2)) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "Cocoa/NSOpenGL: The targeted version of Mac OS X does " - "not support any OpenGL version above 2.1 except 3.2"); + "NSOpenGL: The targeted version of Mac OS X does not " + "support any OpenGL version above 2.1 except 3.2"); return GL_FALSE; } @@ -727,8 +726,8 @@ static GLboolean createContext(_GLFWwindow* window, if (!wndconfig->glForward) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "Cocoa/NSOpenGL: The targeted version of Mac OS X " - "only supports OpenGL 3.2 contexts if they are " + "NSOpenGL: The targeted version of Mac OS X only " + "supports OpenGL 3.2 contexts if they are " "forward-compatible"); return GL_FALSE; } @@ -736,8 +735,8 @@ static GLboolean createContext(_GLFWwindow* window, if (wndconfig->glProfile != GLFW_OPENGL_CORE_PROFILE) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "Cocoa/NSOpenGL: The targeted version of Mac OS X " - "only supports OpenGL 3.2 contexts if they use the " + "NSOpenGL: The targeted version of Mac OS X only " + "supports OpenGL 3.2 contexts if they use the " "core profile"); return GL_FALSE; } @@ -747,8 +746,8 @@ static GLboolean createContext(_GLFWwindow* window, if (wndconfig->glMajor > 2) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "Cocoa/NSOpenGL: The targeted version of Mac OS X does " - "not support OpenGL version 3.0 or above"); + "NSOpenGL: The targeted version of Mac OS X does not " + "support OpenGL version 3.0 or above"); return GL_FALSE; } #endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/ @@ -757,8 +756,8 @@ static GLboolean createContext(_GLFWwindow* window, if (wndconfig->glRobustness) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "Cocoa/NSOpenGL: Mac OS X does not support OpenGL " - "robustness strategies"); + "NSOpenGL: Mac OS X does not support OpenGL robustness " + "strategies"); return GL_FALSE; } @@ -821,7 +820,7 @@ static GLboolean createContext(_GLFWwindow* window, if (window->NSGL.pixelFormat == nil) { _glfwSetError(GLFW_PLATFORM_ERROR, - "Cocoa/NSOpenGL: Failed to create OpenGL pixel format"); + "NSOpenGL: Failed to create OpenGL pixel format"); return GL_FALSE; } @@ -836,7 +835,7 @@ static GLboolean createContext(_GLFWwindow* window, if (window->NSGL.context == nil) { _glfwSetError(GLFW_PLATFORM_ERROR, - "Cocoa/NSOpenGL: Failed to create OpenGL context"); + "NSOpenGL: Failed to create OpenGL context"); return GL_FALSE; } @@ -868,8 +867,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (_glfwLibrary.NS.delegate == nil) { _glfwSetError(GLFW_PLATFORM_ERROR, - "Cocoa/NSOpenGL: Failed to create application " - "delegate"); + "Cocoa: Failed to create application delegate"); return GL_FALSE; } @@ -880,7 +878,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (window->NS.delegate == nil) { _glfwSetError(GLFW_PLATFORM_ERROR, - "Cocoa/NSOpenGL: Failed to create window delegate"); + "Cocoa: Failed to create window delegate"); return GL_FALSE; } diff --git a/src/win32_clipboard.c b/src/win32_clipboard.c index ca31964d..22cdb8f6 100644 --- a/src/win32_clipboard.c +++ b/src/win32_clipboard.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: Win32/WGL +// Platform: Win32 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ @@ -53,7 +53,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) if (!wideString) { _glfwSetError(GLFW_PLATFORM_ERROR, - "Win32/WGL: Failed to convert clipboard string to " + "Win32: Failed to convert clipboard string to " "wide string"); return; } @@ -66,7 +66,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) free(wideString); _glfwSetError(GLFW_PLATFORM_ERROR, - "Win32/WGL: Failed to allocate global handle for clipboard"); + "Win32: Failed to allocate global handle for clipboard"); return; } @@ -79,7 +79,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) free(wideString); _glfwSetError(GLFW_PLATFORM_ERROR, - "Win32/WGL: Failed to open clipboard"); + "Win32: Failed to open clipboard"); return; } @@ -108,7 +108,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) if (!OpenClipboard(window->Win32.handle)) { _glfwSetError(GLFW_PLATFORM_ERROR, - "Win32/WGL: Failed to open clipboard"); + "Win32: Failed to open clipboard"); return NULL; } @@ -118,7 +118,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) CloseClipboard(); _glfwSetError(GLFW_PLATFORM_ERROR, - "Win32/WGL: Failed to retrieve clipboard data"); + "Win32: Failed to retrieve clipboard data"); return NULL; } @@ -132,7 +132,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) if (!_glfwLibrary.Win32.clipboardString) { _glfwSetError(GLFW_PLATFORM_ERROR, - "Win32/WGL: Failed to convert wide string to UTF-8"); + "Win32: Failed to convert wide string to UTF-8"); return NULL; } diff --git a/src/win32_dllmain.c b/src/win32_dllmain.c index 95258ccc..98f9ab2a 100644 --- a/src/win32_dllmain.c +++ b/src/win32_dllmain.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: Win32/WGL +// Platform: Win32 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/win32_fullscreen.c b/src/win32_fullscreen.c index 3e28e30e..35d75054 100644 --- a/src/win32_fullscreen.c +++ b/src/win32_fullscreen.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: Win32/WGL +// Platform: Win32 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/win32_gamma.c b/src/win32_gamma.c index 36fbd3a4..74958191 100644 --- a/src/win32_gamma.c +++ b/src/win32_gamma.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: Win32/WGL +// Platform: Win32 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/win32_input.c b/src/win32_input.c index d3785aa3..a9195838 100644 --- a/src/win32_input.c +++ b/src/win32_input.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: Win32/WGL +// Platform: Win32 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/win32_joystick.c b/src/win32_joystick.c index c27218db..fcc6b599 100644 --- a/src/win32_joystick.c +++ b/src/win32_joystick.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: Win32/WGL +// Platform: Win32 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/win32_opengl.c b/src/win32_opengl.c index 2c676c91..bf684094 100644 --- a/src/win32_opengl.c +++ b/src/win32_opengl.c @@ -171,15 +171,14 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) if (!available) { - _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "Win32/WGL: No pixel formats found"); + _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "WGL: No pixel formats found"); return NULL; } fbconfigs = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * available); if (!fbconfigs) { - _glfwSetError(GLFW_OUT_OF_MEMORY, - "Win32/WGL: Failed to allocate _GLFWfbconfig array"); + _glfwSetError(GLFW_OUT_OF_MEMORY, NULL); return NULL; } @@ -285,6 +284,9 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) if (*found == 0) { + _glfwSetError(GLFW_PLATFORM_ERROR, + "Win32/WGL: No usable pixel formats found"); + free(fbconfigs); return NULL; } @@ -310,15 +312,15 @@ static GLboolean createContext(_GLFWwindow* window, if (!DescribePixelFormat(window->WGL.DC, pixelFormat, sizeof(pfd), &pfd)) { - _glfwSetError(GLFW_OPENGL_UNAVAILABLE, - "Win32/WGL: Failed to retrieve PFD for selected pixel format"); + _glfwSetError(GLFW_PLATFORM_ERROR, + "Win32: Failed to retrieve PFD for selected pixel format"); return GL_FALSE; } if (!SetPixelFormat(window->WGL.DC, pixelFormat, &pfd)) { - _glfwSetError(GLFW_OPENGL_UNAVAILABLE, - "Win32/WGL: Failed to set selected pixel format"); + _glfwSetError(GLFW_PLATFORM_ERROR, + "Win32: Failed to set selected pixel format"); return GL_FALSE; } @@ -360,7 +362,7 @@ static GLboolean createContext(_GLFWwindow* window, if (!window->WGL.ARB_create_context_profile) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "Win32/WGL: OpenGL profile requested but " + "WGL: OpenGL profile requested but " "WGL_ARB_create_context_profile is unavailable"); return GL_FALSE; } @@ -369,7 +371,7 @@ static GLboolean createContext(_GLFWwindow* window, !window->WGL.EXT_create_context_es2_profile) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "Win32/WGL: OpenGL ES 2.x profile requested but " + "WGL: OpenGL ES 2.x profile requested but " "WGL_EXT_create_context_es2_profile is unavailable"); return GL_FALSE; } @@ -392,7 +394,7 @@ static GLboolean createContext(_GLFWwindow* window, if (!window->WGL.ARB_create_context_robustness) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "Win32/WGL: An OpenGL robustness strategy was " + "WGL: An OpenGL robustness strategy was " "requested but WGL_ARB_create_context_robustness " "is unavailable"); return GL_FALSE; @@ -415,7 +417,7 @@ static GLboolean createContext(_GLFWwindow* window, if (!window->WGL.context) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "Win32/WGL: Failed to create OpenGL context"); + "WGL: Failed to create OpenGL context"); return GL_FALSE; } } @@ -425,7 +427,7 @@ static GLboolean createContext(_GLFWwindow* window, if (!window->WGL.context) { _glfwSetError(GLFW_PLATFORM_ERROR, - "Win32/WGL: Failed to create OpenGL context"); + "WGL: Failed to create OpenGL context"); return GL_FALSE; } @@ -434,8 +436,8 @@ static GLboolean createContext(_GLFWwindow* window, if (!wglShareLists(share, window->WGL.context)) { _glfwSetError(GLFW_PLATFORM_ERROR, - "Win32/WGL: Failed to enable sharing with " - "specified OpenGL context"); + "WGL: Failed to enable sharing with specified " + "OpenGL context"); return GL_FALSE; } } @@ -466,7 +468,7 @@ int _glfwCreateContext(_GLFWwindow* window, if (!window->WGL.DC) { _glfwSetError(GLFW_PLATFORM_ERROR, - "Win32/WGL: Failed to retrieve DC for window"); + "Win32: Failed to retrieve DC for window"); return GL_FALSE; } @@ -478,16 +480,12 @@ int _glfwCreateContext(_GLFWwindow* window, fbconfigs = getFBConfigs(window, &fbcount); if (!fbconfigs) - { - _glfwSetError(GLFW_PLATFORM_ERROR, - "Win32/WGL: No usable pixel formats found"); return GL_FALSE; - } result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount); if (!result) { - _glfwSetError(GLFW_PLATFORM_ERROR, + _glfwSetError(GLFW_FORMAT_UNAVAILABLE, "Win32/WGL: No pixel format matched the criteria"); free(fbconfigs); @@ -620,7 +618,7 @@ void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long if (!wglCopyContext(src->WGL.context, dst->WGL.context, mask)) { _glfwSetError(GLFW_PLATFORM_ERROR, - "Win32/WGL: Failed to copy OpenGL context attributes"); + "WGL: Failed to copy OpenGL context attributes"); } } diff --git a/src/win32_time.c b/src/win32_time.c index f3bd173a..1e1d57f4 100644 --- a/src/win32_time.c +++ b/src/win32_time.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: Win32/WGL +// Platform: Win32 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/win32_window.c b/src/win32_window.c index 77b99026..feccb833 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -813,7 +813,7 @@ static ATOM registerWindowClass(void) if (!classAtom) { _glfwSetError(GLFW_PLATFORM_ERROR, - "Win32/WGL: Failed to register window class"); + "Win32: Failed to register window class"); return 0; } @@ -886,7 +886,7 @@ static int createWindow(_GLFWwindow* window, if (!wideTitle) { _glfwSetError(GLFW_PLATFORM_ERROR, - "glfwCreateWindow: Failed to convert title to wide string"); + "Win32: Failed to convert title to wide string"); return GL_FALSE; } @@ -904,7 +904,7 @@ static int createWindow(_GLFWwindow* window, if (!window->Win32.handle) { - _glfwSetError(GLFW_PLATFORM_ERROR, "Win32/WGL: Failed to create window"); + _glfwSetError(GLFW_PLATFORM_ERROR, "Win32: Failed to create window"); return GL_FALSE; } @@ -1008,8 +1008,8 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (!window->WGL.ARB_create_context) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "Win32/WGL: A forward compatible OpenGL context " - "requested but WGL_ARB_create_context is unavailable"); + "WGL: A forward compatible OpenGL context requested " + "but WGL_ARB_create_context is unavailable"); return GL_FALSE; } @@ -1021,7 +1021,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (!window->WGL.ARB_create_context_profile) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "Win32/WGL: OpenGL profile requested but " + "WGL: OpenGL profile requested but " "WGL_ARB_create_context_profile is unavailable"); return GL_FALSE; } @@ -1107,7 +1107,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) if (!wideTitle) { _glfwSetError(GLFW_PLATFORM_ERROR, - "glfwSetWindowTitle: Failed to convert title to wide string"); + "Win32: Failed to convert title to wide string"); return; } diff --git a/src/window.c b/src/window.c index 4e95129a..acd48195 100644 --- a/src/window.c +++ b/src/window.c @@ -267,7 +267,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, if (mode != GLFW_WINDOWED && mode != GLFW_FULLSCREEN) { _glfwSetError(GLFW_INVALID_ENUM, - "glfwCreateWindow: Invalid enum for 'mode' parameter"); + "glfwCreateWindow: Invalid window mode"); return GL_FALSE; } @@ -292,8 +292,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, window = (_GLFWwindow*) malloc(sizeof(_GLFWwindow)); if (!window) { - _glfwSetError(GLFW_OUT_OF_MEMORY, - "glfwCreateWindow: Failed to allocate window structure"); + _glfwSetError(GLFW_OUT_OF_MEMORY, NULL); return NULL; } diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index a833ed1f..5bc92d44 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/GLX +// Platform: X11 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ @@ -182,7 +182,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) if (_glfwLibrary.X11.selection.status == _GLFW_CONVERSION_FAILED) { _glfwSetError(GLFW_FORMAT_UNAVAILABLE, - "X11/GLX: Failed to convert selection to string"); + "X11: Failed to convert selection to string"); return NULL; } diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c index 8c4138d3..346aefb7 100644 --- a/src/x11_fullscreen.c +++ b/src/x11_fullscreen.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/GLX +// Platform: X11 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ @@ -442,7 +442,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(int* found) if (visuals == NULL) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to retrieve the available visuals"); + "X11: Failed to retrieve the available visuals"); return 0; } diff --git a/src/x11_gamma.c b/src/x11_gamma.c index 44cd1139..148ae740 100644 --- a/src/x11_gamma.c +++ b/src/x11_gamma.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/GLX +// Platform: X11 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ @@ -115,7 +115,7 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp) if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to get gamma ramp due to size " + "X11: Failed to get gamma ramp due to size " "incompatibility"); return; } @@ -166,7 +166,7 @@ void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp) if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to set gamma ramp due to size " + "X11: Failed to set gamma ramp due to size " "incompatibility"); return; } diff --git a/src/x11_init.c b/src/x11_init.c index 372fc2dd..35f66c0f 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -491,7 +491,7 @@ static GLboolean initDisplay(void) _glfwLibrary.X11.display = XOpenDisplay(NULL); if (!_glfwLibrary.X11.display) { - _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: Failed to open X display"); + _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11: Failed to open X display"); return GL_FALSE; } @@ -525,7 +525,7 @@ static GLboolean initDisplay(void) &_glfwLibrary.X11.RandR.minorVersion)) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to query RandR version"); + "X11: Failed to query RandR version"); return GL_FALSE; } } diff --git a/src/x11_input.c b/src/x11_input.c index 49961395..2ea8b8c4 100644 --- a/src/x11_input.c +++ b/src/x11_input.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11 (Unix) +// Platform: X11 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/x11_joystick.c b/src/x11_joystick.c index 523a4b3d..8492850b 100644 --- a/src/x11_joystick.c +++ b/src/x11_joystick.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/GLX +// Platform: X11 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/x11_keysym2unicode.c b/src/x11_keysym2unicode.c index 1f610fdd..c0d10c6e 100644 --- a/src/x11_keysym2unicode.c +++ b/src/x11_keysym2unicode.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/GLX +// Platform: X11 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/x11_opengl.c b/src/x11_opengl.c index 2a5cc451..a7c3f61b 100644 --- a/src/x11_opengl.c +++ b/src/x11_opengl.c @@ -78,7 +78,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) if (!_glfwLibrary.GLX.SGIX_fbconfig) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, - "X11/GLX: GLXFBConfig support not found"); + "GLX: GLXFBConfig support not found"); return NULL; } } @@ -101,7 +101,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) if (!count) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, - "X11/GLX: No GLXFBConfigs returned"); + "GLX: No GLXFBConfigs returned"); return NULL; } } @@ -113,7 +113,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) if (!count) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, - "X11/GLX: No GLXFBConfigs returned"); + "GLX: No GLXFBConfigs returned"); return NULL; } } @@ -121,8 +121,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count); if (!result) { - _glfwSetError(GLFW_OUT_OF_MEMORY, - "X11/GLX: Failed to allocate _GLFWfbconfig array"); + _glfwSetError(GLFW_OUT_OF_MEMORY, NULL); return NULL; } @@ -242,7 +241,7 @@ static int createContext(_GLFWwindow* window, if (fbconfig == NULL) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to retrieve the selected GLXFBConfig"); + "GLX: Failed to retrieve the selected GLXFBConfig"); return GL_FALSE; } } @@ -264,7 +263,7 @@ static int createContext(_GLFWwindow* window, XFree(fbconfig); _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to retrieve visual for GLXFBConfig"); + "GLX: Failed to retrieve visual for GLXFBConfig"); return GL_FALSE; } @@ -303,7 +302,7 @@ static int createContext(_GLFWwindow* window, if (!_glfwLibrary.GLX.ARB_create_context_profile) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "X11/GLX: An OpenGL profile requested but " + "GLX: An OpenGL profile requested but " "GLX_ARB_create_context_profile is unavailable"); return GL_FALSE; } @@ -312,7 +311,7 @@ static int createContext(_GLFWwindow* window, !_glfwLibrary.GLX.EXT_create_context_es2_profile) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "X11/GLX: OpenGL ES 2.x profile requested but " + "GLX: OpenGL ES 2.x profile requested but " "GLX_EXT_create_context_es2_profile is unavailable"); return GL_FALSE; } @@ -334,7 +333,7 @@ static int createContext(_GLFWwindow* window, if (!_glfwLibrary.GLX.ARB_create_context_robustness) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "X11/GLX: An OpenGL robustness strategy was " + "GLX: An OpenGL robustness strategy was " "requested but GLX_ARB_create_context_robustness " "is unavailable"); return GL_FALSE; @@ -397,7 +396,7 @@ static int createContext(_GLFWwindow* window, // TODO: Handle all the various error codes here _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to create OpenGL context"); + "GLX: Failed to create OpenGL context"); return GL_FALSE; } @@ -437,7 +436,7 @@ int _glfwInitOpenGL(void) if (!_glfwLibrary.GLX.libGL) { - _glfwSetError(GLFW_PLATFORM_ERROR, "X11/GLX: Failed to find libGL"); + _glfwSetError(GLFW_PLATFORM_ERROR, "GLX: Failed to find libGL"); return GL_FALSE; } #endif @@ -445,7 +444,7 @@ int _glfwInitOpenGL(void) // Check if GLX is supported on this display if (!glXQueryExtension(_glfwLibrary.X11.display, NULL, NULL)) { - _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: GLX support not found"); + _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "GLX: GLX support not found"); return GL_FALSE; } @@ -454,7 +453,7 @@ int _glfwInitOpenGL(void) &_glfwLibrary.GLX.minorVersion)) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, - "X11/GLX: Failed to query GLX version"); + "GLX: Failed to query GLX version"); return GL_FALSE; } @@ -565,17 +564,13 @@ int _glfwCreateContext(_GLFWwindow* window, fbconfigs = getFBConfigs(window, &fbcount); if (!fbconfigs) - { - _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: No usable GLXFBConfigs found"); return GL_FALSE; - } result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount); if (!result) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: No GLXFBConfig matched the criteria"); + "GLX: No GLXFBConfig matched the criteria"); free(fbconfigs); return GL_FALSE; diff --git a/src/x11_time.c b/src/x11_time.c index f1445233..bf3335d3 100644 --- a/src/x11_time.c +++ b/src/x11_time.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/GLX +// Platform: X11 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/x11_window.c b/src/x11_window.c index 6d7021a0..a34449d8 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -131,8 +131,7 @@ static GLboolean createWindow(_GLFWwindow* window, // TODO: Handle all the various error codes here and translate them // to GLFW errors - _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to create window"); + _glfwSetError(GLFW_PLATFORM_ERROR, "X11: Failed to create window"); return GL_FALSE; } } @@ -191,7 +190,7 @@ static GLboolean createWindow(_GLFWwindow* window, if (!hints) { _glfwSetError(GLFW_OUT_OF_MEMORY, - "X11/GLX: Failed to allocate WM hints"); + "X11: Failed to allocate WM hints"); return GL_FALSE; } @@ -208,7 +207,7 @@ static GLboolean createWindow(_GLFWwindow* window, if (!hints) { _glfwSetError(GLFW_OUT_OF_MEMORY, - "X11/GLX: Failed to allocate size hints"); + "X11: Failed to allocate size hints"); return GL_FALSE; }