Merge branch 'master' into EGL

Conflicts:
	include/GL/glfw3.h
	src/opengl.c
	src/win32_opengl.c
	src/window.c
	src/x11_fullscreen.c
	src/x11_glx_opengl.c
	src/x11_platform.h
	src/x11_window.c
	tests/glfwinfo.c
This commit is contained in:
Camilla Berglund
2012-09-06 21:05:03 +02:00
76 changed files with 1473 additions and 3805 deletions
+41 -130
View File
@@ -43,15 +43,6 @@
#define Button6 6
#define Button7 7
//========================================================================
// Checks whether the event is a MapNotify for the specified window
//========================================================================
static Bool isMapNotify(Display* d, XEvent* e, char* arg)
{
return (e->type == MapNotify) && (e->xmap.window == (Window)arg);
}
//========================================================================
// Translates an X Window key to internal coding
@@ -59,15 +50,11 @@ static Bool isMapNotify(Display* d, XEvent* e, char* arg)
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;
}
}
@@ -94,13 +81,13 @@ static int translateChar(XKeyEvent* event)
static GLboolean createWindow(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig)
{
XEvent event;
unsigned long wamask;
XSetWindowAttributes wa;
XVisualInfo* visual = _glfwGetContextVisual(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,
@@ -120,33 +107,31 @@ 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: Failed to create window");
_glfwSetError(GLFW_PLATFORM_ERROR, "X11: Failed to create window");
return GL_FALSE;
}
}
@@ -158,8 +143,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;
@@ -176,7 +161,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];
@@ -187,8 +172,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;
@@ -243,8 +228,7 @@ static GLboolean createWindow(_GLFWwindow* window,
// Make sure the window is mapped before proceeding
XMapWindow(_glfwLibrary.X11.display, window->X11.handle);
XPeekIfEvent(_glfwLibrary.X11.display, &event, isMapNotify,
(char*) window->X11.handle);
XFlush(_glfwLibrary.X11.display);
return GL_TRUE;
}
@@ -295,7 +279,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)
@@ -389,7 +373,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);
@@ -417,7 +401,6 @@ static void leaveFullscreenMode(_GLFWwindow* window)
{
_glfwRestoreVideoMode();
// Did we change the screen saver setting?
if (_glfwLibrary.X11.saver.changed)
{
// Restore old screen saver settings
@@ -494,17 +477,10 @@ static void processSingleEvent(void)
// A keyboard key was pressed
window = findWindow(event.xkey.window);
if (window == NULL)
{
fprintf(stderr, "Cannot find GLFW window structure for KeyPress event\n");
return;
}
// Translate and report key press
_glfwInputKey(window, translateKey(event.xkey.keycode), GLFW_PRESS);
// Translate and report character input
_glfwInputChar(window, translateChar(&event.xkey));
break;
}
@@ -513,10 +489,7 @@ static void processSingleEvent(void)
// A keyboard key was released
window = findWindow(event.xkey.window);
if (window == NULL)
{
fprintf(stderr, "Cannot find GLFW window structure for KeyRelease event\n");
return;
}
// Do not report key releases for key repeats. For key repeats we
// will get KeyRelease/KeyPress pairs with similar or identical
@@ -544,9 +517,7 @@ static void processSingleEvent(void)
}
}
// Translate and report key release
_glfwInputKey(window, translateKey(event.xkey.keycode), GLFW_RELEASE);
break;
}
@@ -555,10 +526,7 @@ static void processSingleEvent(void)
// A mouse button was pressed or a scrolling event occurred
window = findWindow(event.xbutton.window);
if (window == NULL)
{
fprintf(stderr, "Cannot find GLFW window structure for ButtonPress event\n");
return;
}
if (event.xbutton.button == Button1)
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS);
@@ -587,10 +555,7 @@ static void processSingleEvent(void)
// A mouse button was released
window = findWindow(event.xbutton.window);
if (window == NULL)
{
fprintf(stderr, "Cannot find GLFW window structure for ButtonRelease event\n");
return;
}
if (event.xbutton.button == Button1)
{
@@ -618,10 +583,7 @@ static void processSingleEvent(void)
// The cursor entered the window
window = findWindow(event.xcrossing.window);
if (window == NULL)
{
fprintf(stderr, "Cannot find GLFW window structure for EnterNotify event\n");
return;
}
if (window->cursorMode == GLFW_CURSOR_HIDDEN)
hideCursor(window);
@@ -635,10 +597,7 @@ static void processSingleEvent(void)
// The cursor left the window
window = findWindow(event.xcrossing.window);
if (window == NULL)
{
fprintf(stderr, "Cannot find GLFW window structure for LeaveNotify event\n");
return;
}
if (window->cursorMode == GLFW_CURSOR_HIDDEN)
showCursor(window);
@@ -652,15 +611,13 @@ static void processSingleEvent(void)
// The cursor was moved
window = findWindow(event.xmotion.window);
if (window == NULL)
{
fprintf(stderr, "Cannot find GLFW window structure for MotionNotify event\n");
return;
}
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)
@@ -692,10 +649,7 @@ static void processSingleEvent(void)
// The window configuration changed somehow
window = findWindow(event.xconfigure.window);
if (window == NULL)
{
fprintf(stderr, "Cannot find GLFW window structure for ConfigureNotify event\n");
return;
}
_glfwInputWindowSize(window,
event.xconfigure.width,
@@ -713,23 +667,20 @@ static void processSingleEvent(void)
// Custom client message, probably from the window manager
window = findWindow(event.xclient.window);
if (window == NULL)
{
fprintf(stderr, "Cannot find GLFW window structure for ClientMessage event\n");
return;
}
if ((Atom) event.xclient.data.l[0] == _glfwLibrary.X11.wmDeleteWindow)
{
// The window manager was asked to close the window, for example by
// the user pressing a 'close' window decoration button
window->closeRequested = GL_TRUE;
_glfwInputWindowCloseRequest(window);
}
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,
@@ -747,10 +698,7 @@ static void processSingleEvent(void)
// The window was mapped
window = findWindow(event.xmap.window);
if (window == NULL)
{
fprintf(stderr, "Cannot find GLFW window structure for MapNotify event\n");
return;
}
_glfwInputWindowIconify(window, GL_FALSE);
break;
@@ -761,10 +709,7 @@ static void processSingleEvent(void)
// The window was unmapped
window = findWindow(event.xmap.window);
if (window == NULL)
{
fprintf(stderr, "Cannot find GLFW window structure for UnmapNotify event\n");
return;
}
_glfwInputWindowIconify(window, GL_TRUE);
break;
@@ -775,10 +720,7 @@ static void processSingleEvent(void)
// The window gained focus
window = findWindow(event.xfocus.window);
if (window == NULL)
{
fprintf(stderr, "Cannot find GLFW window structure for FocusIn event\n");
return;
}
_glfwInputWindowFocus(window, GL_TRUE);
@@ -793,10 +735,7 @@ static void processSingleEvent(void)
// The window lost focus
window = findWindow(event.xfocus.window);
if (window == NULL)
{
fprintf(stderr, "Cannot find GLFW window structure for FocusOut event\n");
return;
}
_glfwInputWindowFocus(window, GL_FALSE);
@@ -811,10 +750,7 @@ static void processSingleEvent(void)
// The window's contents was damaged
window = findWindow(event.xexpose.window);
if (window == NULL)
{
fprintf(stderr, "Cannot find GLFW window structure for Expose event\n");
return;
}
_glfwInputWindowDamage(window);
break;
@@ -876,7 +812,6 @@ static void processSingleEvent(void)
{
case RRScreenChangeNotify:
{
// Show XRandR that we really care
XRRUpdateConfiguration(&event);
break;
}
@@ -887,24 +822,6 @@ static void processSingleEvent(void)
}
}
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Processes all pending events
//========================================================================
void _glfwProcessPendingEvents(void)
{
int i, count = XPending(_glfwLibrary.X11.display);
for (i = 0; i < count; i++)
processSingleEvent();
}
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
@@ -914,12 +831,11 @@ void _glfwProcessPendingEvents(void)
// the OpenGL rendering context is created
//========================================================================
int _glfwPlatformOpenWindow(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig,
const _GLFWfbconfig* fbconfig)
int _glfwPlatformCreateWindow(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig,
const _GLFWfbconfig* fbconfig)
{
window->refreshRate = wndconfig->refreshRate;
window->resizable = wndconfig->resizable;
if (!_glfwCreateContext(window, wndconfig, fbconfig))
return GL_FALSE;
@@ -942,9 +858,6 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
enterFullscreenMode(window);
}
// Process the window map event and any other that may have arrived
_glfwProcessPendingEvents();
// Retrieve and set initial cursor position
{
Window cursorWindow, cursorRoot;
@@ -973,7 +886,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
// Properly kill the window/video display
//========================================================================
void _glfwPlatformCloseWindow(_GLFWwindow* window)
void _glfwPlatformDestroyWindow(_GLFWwindow* window)
{
if (window->mode == GLFW_FULLSCREEN)
leaveFullscreenMode(window);
@@ -1105,8 +1018,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;
}
@@ -1124,8 +1037,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;
}
@@ -1137,10 +1050,8 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
// Read back framebuffer parameters from the context
//========================================================================
void _glfwPlatformRefreshWindowParams(void)
void _glfwPlatformRefreshWindowParams(_GLFWwindow* window)
{
_GLFWwindow* window = _glfwLibrary.currentWindow;
// Retrieve refresh rate if possible
if (_glfwLibrary.X11.RandR.available)
{
@@ -1231,7 +1142,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;