diff --git a/examples/boing.c b/examples/boing.c
index bd6d4d29..9b7e2022 100644
--- a/examples/boing.c
+++ b/examples/boing.c
@@ -617,7 +617,7 @@ int main( void )
display();
/* Swap buffers */
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
glfwPollEvents();
/* Check if we are still running */
diff --git a/examples/gears.c b/examples/gears.c
index 6fecb646..535a574d 100644
--- a/examples/gears.c
+++ b/examples/gears.c
@@ -368,7 +368,7 @@ int main(int argc, char *argv[])
animate();
// Swap buffers
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
glfwPollEvents();
}
diff --git a/examples/heightmap.c b/examples/heightmap.c
index 7b03a1b3..ce894f99 100644
--- a/examples/heightmap.c
+++ b/examples/heightmap.c
@@ -663,7 +663,7 @@ int main(int argc, char** argv)
glDrawElements(GL_LINES, 2* MAP_NUM_LINES , GL_UNSIGNED_INT, 0);
/* display and process events through callbacks */
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
glfwPollEvents();
/* Check the frame rate and update the heightmap if needed */
dt = glfwGetTime();
diff --git a/examples/splitview.c b/examples/splitview.c
index 2ab3a82c..0b767b7f 100644
--- a/examples/splitview.c
+++ b/examples/splitview.c
@@ -500,7 +500,7 @@ int main(void)
drawAllViews();
// Swap buffers
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
do_redraw = 0;
}
diff --git a/examples/triangle.c b/examples/triangle.c
index 212f5df3..8a352ca9 100644
--- a/examples/triangle.c
+++ b/examples/triangle.c
@@ -89,7 +89,7 @@ int main(void)
glEnd();
// Swap buffers
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
glfwPollEvents();
if (glfwGetKey(window, GLFW_KEY_ESCAPE))
diff --git a/examples/wave.c b/examples/wave.c
index d58f1711..ae5447f8 100644
--- a/examples/wave.c
+++ b/examples/wave.c
@@ -145,7 +145,7 @@ void init_grid(void)
// Draw scene
//========================================================================
-void draw_scene(void)
+void draw_scene(GLFWwindow window)
{
// Clear the color and depth buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -162,7 +162,7 @@ void draw_scene(void)
glDrawElements(GL_QUADS, 4 * QUADNUM, GL_UNSIGNED_INT, quad);
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
}
@@ -450,7 +450,7 @@ int main(int argc, char* argv[])
adjust_grid();
// Draw wave grid to OpenGL display
- draw_scene();
+ draw_scene(window);
glfwPollEvents();
}
diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h
index 49e2bdf3..718391cb 100644
--- a/include/GL/glfw3.h
+++ b/include/GL/glfw3.h
@@ -581,7 +581,7 @@ GLFWAPI void glfwSetTime(double time);
/* OpenGL support */
GLFWAPI void glfwMakeContextCurrent(GLFWwindow window);
GLFWAPI GLFWwindow glfwGetCurrentContext(void);
-GLFWAPI void glfwSwapBuffers(void);
+GLFWAPI void glfwSwapBuffers(GLFWwindow window);
GLFWAPI void glfwSwapInterval(int interval);
GLFWAPI int glfwExtensionSupported(const char* extension);
GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname);
diff --git a/readme.html b/readme.html
index c5447a20..8bf5d046 100644
--- a/readme.html
+++ b/readme.html
@@ -288,6 +288,7 @@ version of GLFW.
Added modes
video mode enumeration and setting test program
Added glfw3native.h
header and platform-specific functions for explicit access to native display, window and context handles
Added glfwSetGamma
, glfwSetGammaRamp
and glfwGetGammaRamp
functions and GLFWgammaramp
type for monitor gamma ramp control
+ Added window parameter to glfwSwapBuffers
Changed buffer bit depth parameters of glfwOpenWindow
to window hints
Changed glfwOpenWindow
and glfwSetWindowTitle
to use UTF-8 encoded strings
Changed glfwGetProcAddress
to return a (generic) function pointer
diff --git a/src/cocoa_opengl.m b/src/cocoa_opengl.m
index b04efaee..2ffd774c 100644
--- a/src/cocoa_opengl.m
+++ b/src/cocoa_opengl.m
@@ -51,10 +51,8 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
// Swap buffers
//========================================================================
-void _glfwPlatformSwapBuffers(void)
+void _glfwPlatformSwapBuffers(_GLFWwindow* window)
{
- _GLFWwindow* window = _glfwLibrary.currentWindow;
-
// ARP appears to be unnecessary, but this is future-proof
[window->NSGL.context flushBuffer];
}
diff --git a/src/internal.h b/src/internal.h
index 5d22e15e..1e4825c0 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -324,7 +324,7 @@ void _glfwPlatformWaitEvents(void);
// OpenGL context management
void _glfwPlatformMakeContextCurrent(_GLFWwindow* window);
-void _glfwPlatformSwapBuffers(void);
+void _glfwPlatformSwapBuffers(_GLFWwindow* window);
void _glfwPlatformSwapInterval(int interval);
void _glfwPlatformRefreshWindowParams(_GLFWwindow* window);
int _glfwPlatformExtensionSupported(const char* extension);
diff --git a/src/opengl.c b/src/opengl.c
index 24889e07..19c07253 100644
--- a/src/opengl.c
+++ b/src/opengl.c
@@ -541,21 +541,17 @@ GLFWAPI GLFWwindow glfwGetCurrentContext(void)
// Swap buffers (double-buffering)
//========================================================================
-GLFWAPI void glfwSwapBuffers(void)
+GLFWAPI void glfwSwapBuffers(GLFWwindow handle)
{
+ _GLFWwindow* window = (_GLFWwindow*) handle;
+
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
- if (!_glfwLibrary.currentWindow)
- {
- _glfwSetError(GLFW_NO_CURRENT_CONTEXT, NULL);
- return;
- }
-
- _glfwPlatformSwapBuffers();
+ _glfwPlatformSwapBuffers(window);
}
diff --git a/src/win32_opengl.c b/src/win32_opengl.c
index 2d85369f..fe1898e7 100644
--- a/src/win32_opengl.c
+++ b/src/win32_opengl.c
@@ -545,10 +545,8 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
// Swap buffers (double-buffering)
//========================================================================
-void _glfwPlatformSwapBuffers(void)
+void _glfwPlatformSwapBuffers(_GLFWwindow* window)
{
- _GLFWwindow* window = _glfwLibrary.currentWindow;
-
SwapBuffers(window->WGL.DC);
}
diff --git a/src/window.c b/src/window.c
index 8bc5fbeb..3b0e7a55 100644
--- a/src/window.c
+++ b/src/window.c
@@ -344,7 +344,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
// Clearing the front buffer to black to avoid garbage pixels left over
// from previous uses of our bit of VRAM
glClear(GL_COLOR_BUFFER_BIT);
- _glfwPlatformSwapBuffers();
+ _glfwPlatformSwapBuffers(window);
return window;
}
diff --git a/src/x11_opengl.c b/src/x11_opengl.c
index 3549e573..2a5cc451 100644
--- a/src/x11_opengl.c
+++ b/src/x11_opengl.c
@@ -642,10 +642,9 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
// Swap OpenGL buffers
//========================================================================
-void _glfwPlatformSwapBuffers(void)
+void _glfwPlatformSwapBuffers(_GLFWwindow* window)
{
- glXSwapBuffers(_glfwLibrary.X11.display,
- _glfwLibrary.currentWindow->X11.handle);
+ glXSwapBuffers(_glfwLibrary.X11.display, window->X11.handle);
}
diff --git a/tests/accuracy.c b/tests/accuracy.c
index 836bb18b..40894742 100644
--- a/tests/accuracy.c
+++ b/tests/accuracy.c
@@ -113,7 +113,7 @@ int main(void)
glVertex2f((GLfloat) cursor_x, (GLfloat) window_height);
glEnd();
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
glfwPollEvents();
}
diff --git a/tests/clipboard.c b/tests/clipboard.c
index 58e9bdd7..8ab90dbb 100644
--- a/tests/clipboard.c
+++ b/tests/clipboard.c
@@ -143,7 +143,7 @@ int main(int argc, char** argv)
glColor3f(0.8f, 0.2f, 0.4f);
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
glfwWaitEvents();
}
diff --git a/tests/events.c b/tests/events.c
index 85c6913f..0d345765 100644
--- a/tests/events.c
+++ b/tests/events.c
@@ -239,7 +239,7 @@ static void window_refresh_callback(GLFWwindow window)
printf("%08x at %0.3f: Window refresh\n", counter++, glfwGetTime());
glClear(GL_COLOR_BUFFER_BIT);
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
}
static void window_focus_callback(GLFWwindow window, int activated)
diff --git a/tests/fsaa.c b/tests/fsaa.c
index 0b11ac75..e2e0623c 100644
--- a/tests/fsaa.c
+++ b/tests/fsaa.c
@@ -147,7 +147,7 @@ int main(int argc, char** argv)
glEnable(GL_MULTISAMPLE_ARB);
glRectf(-0.15f, -0.15f, 0.15f, 0.15f);
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
glfwPollEvents();
}
diff --git a/tests/fsfocus.c b/tests/fsfocus.c
index 51075594..e718a319 100644
--- a/tests/fsfocus.c
+++ b/tests/fsfocus.c
@@ -101,7 +101,7 @@ int main(void)
while (running)
{
glClear(GL_COLOR_BUFFER_BIT);
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
glfwWaitEvents();
}
diff --git a/tests/gamma.c b/tests/gamma.c
index e9d487cd..1f3ca5e1 100644
--- a/tests/gamma.c
+++ b/tests/gamma.c
@@ -158,7 +158,7 @@ int main(int argc, char** argv)
glColor3f(0.8f, 0.2f, 0.4f);
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
glfwPollEvents();
}
diff --git a/tests/iconify.c b/tests/iconify.c
index 4deb45e7..4f1c7d22 100644
--- a/tests/iconify.c
+++ b/tests/iconify.c
@@ -152,7 +152,7 @@ int main(int argc, char** argv)
glClearColor(1, 1, 1, 0);
glClear(GL_COLOR_BUFFER_BIT);
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
glfwPollEvents();
}
diff --git a/tests/joysticks.c b/tests/joysticks.c
index b2375b83..36952038 100644
--- a/tests/joysticks.c
+++ b/tests/joysticks.c
@@ -205,7 +205,7 @@ int main(void)
refresh_joysticks();
draw_joysticks();
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
glfwPollEvents();
}
diff --git a/tests/modes.c b/tests/modes.c
index 9e72562a..eeb83abf 100644
--- a/tests/modes.c
+++ b/tests/modes.c
@@ -148,7 +148,7 @@ static void test_modes(void)
while (glfwGetTime() < 5.0)
{
glClear(GL_COLOR_BUFFER_BIT);
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
glfwPollEvents();
if (!window)
diff --git a/tests/peter.c b/tests/peter.c
index e79e5805..7e0be921 100644
--- a/tests/peter.c
+++ b/tests/peter.c
@@ -131,7 +131,7 @@ int main(void)
{
glClear(GL_COLOR_BUFFER_BIT);
- glfwSwapBuffers();
+ glfwSwapBuffers(window_handle);
glfwWaitEvents();
}
diff --git a/tests/reopen.c b/tests/reopen.c
index 1d692b80..545ba280 100644
--- a/tests/reopen.c
+++ b/tests/reopen.c
@@ -147,7 +147,7 @@ int main(int argc, char** argv)
glRectf(-0.5f, -0.5f, 1.f, 1.f);
glPopMatrix();
- glfwSwapBuffers();
+ glfwSwapBuffers(window_handle);
glfwPollEvents();
if (closed)
diff --git a/tests/sharing.c b/tests/sharing.c
index 5a2e028f..8031a9bb 100644
--- a/tests/sharing.c
+++ b/tests/sharing.c
@@ -172,11 +172,12 @@ int main(int argc, char** argv)
{
glfwMakeContextCurrent(windows[0]);
draw_quad(texture);
- glfwSwapBuffers();
glfwMakeContextCurrent(windows[1]);
draw_quad(texture);
- glfwSwapBuffers();
+
+ glfwSwapBuffers(windows[0]);
+ glfwSwapBuffers(windows[1]);
glfwWaitEvents();
}
diff --git a/tests/tearing.c b/tests/tearing.c
index 3ab131cd..19ffe531 100644
--- a/tests/tearing.c
+++ b/tests/tearing.c
@@ -97,7 +97,7 @@ int main(void)
position = cosf(glfwGetTime() * 4.f) * 0.75f;
glRectf(position - 0.25f, -1.f, position + 0.25f, 1.f);
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
glfwPollEvents();
}
diff --git a/tests/title.c b/tests/title.c
index a66160b8..918d7eed 100644
--- a/tests/title.c
+++ b/tests/title.c
@@ -61,7 +61,7 @@ int main(void)
while (glfwGetCurrentContext())
{
glClear(GL_COLOR_BUFFER_BIT);
- glfwSwapBuffers();
+ glfwSwapBuffers(window);
glfwWaitEvents();
}
diff --git a/tests/windows.c b/tests/windows.c
index ac7500ad..27c1bd30 100644
--- a/tests/windows.c
+++ b/tests/windows.c
@@ -87,7 +87,7 @@ int main(void)
{
glfwMakeContextCurrent(windows[i]);
glClear(GL_COLOR_BUFFER_BIT);
- glfwSwapBuffers();
+ glfwSwapBuffers(windows[i]);
}
glfwPollEvents();