From aae8999ecff188668997a944c02b6737bcc98420 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 4 Mar 2011 14:25:12 +0100 Subject: [PATCH] Moved OpenGL-related functions into *opengl files. --- CMakeLists.txt | 2 +- src/cocoa/CMakeLists.txt | 2 +- src/cocoa/{cocoa_glext.m => cocoa_opengl.m} | 24 +++++++++++ src/cocoa/cocoa_window.m | 24 ----------- src/{glext.c => opengl.c} | 45 +++++++++++++++++++++ src/win32/CMakeLists.txt | 2 +- src/win32/{win32_glext.c => win32_opengl.c} | 25 ++++++++++++ src/win32/win32_window.c | 25 ------------ src/window.c | 45 --------------------- src/x11/CMakeLists.txt | 2 +- src/x11/{x11_glext.c => x11_opengl.c} | 30 ++++++++++++++ src/x11/x11_window.c | 30 -------------- 12 files changed, 128 insertions(+), 128 deletions(-) rename src/cocoa/{cocoa_glext.m => cocoa_opengl.m} (77%) rename src/{glext.c => opengl.c} (87%) rename src/win32/{win32_glext.c => win32_opengl.c} (80%) rename src/x11/{x11_glext.c => x11_opengl.c} (78%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c3cbf74..aa2f01f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,10 +20,10 @@ set(common_SOURCES ${GLFW_SOURCE_DIR}/src/error.c ${GLFW_SOURCE_DIR}/src/fullscreen.c ${GLFW_SOURCE_DIR}/src/gamma.c - ${GLFW_SOURCE_DIR}/src/glext.c ${GLFW_SOURCE_DIR}/src/init.c ${GLFW_SOURCE_DIR}/src/input.c ${GLFW_SOURCE_DIR}/src/joystick.c + ${GLFW_SOURCE_DIR}/src/opengl.c ${GLFW_SOURCE_DIR}/src/time.c ${GLFW_SOURCE_DIR}/src/window.c ) diff --git a/src/cocoa/CMakeLists.txt b/src/cocoa/CMakeLists.txt index 8124c00b..f0bc3c4c 100644 --- a/src/cocoa/CMakeLists.txt +++ b/src/cocoa/CMakeLists.txt @@ -10,9 +10,9 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} set(cocoa_SOURCES cocoa_enable.m cocoa_fullscreen.m cocoa_gamma.m - cocoa_glext.m cocoa_init.m cocoa_joystick.m + cocoa_opengl.m cocoa_time.m cocoa_window.m) diff --git a/src/cocoa/cocoa_glext.m b/src/cocoa/cocoa_opengl.m similarity index 77% rename from src/cocoa/cocoa_glext.m rename to src/cocoa/cocoa_opengl.m index f96f3e66..d56afba3 100644 --- a/src/cocoa/cocoa_glext.m +++ b/src/cocoa/cocoa_opengl.m @@ -34,6 +34,30 @@ ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// +//======================================================================== +// Swap buffers +//======================================================================== + +void _glfwPlatformSwapBuffers(void) +{ + _GLFWwindow* window = _glfwLibrary.currentWindow; + + // ARP appears to be unnecessary, but this is future-proof + [window->NSGL.context flushBuffer]; +} + +//======================================================================== +// Set double buffering swap interval +//======================================================================== + +void _glfwPlatformSwapInterval(int interval) +{ + _GLFWwindow* window = _glfwLibrary.currentWindow; + + GLint sync = interval; + [window->NSGL.context setValues:&sync forParameter:NSOpenGLCPSwapInterval]; +} + //======================================================================== // Check if an OpenGL extension is available at runtime //======================================================================== diff --git a/src/cocoa/cocoa_window.m b/src/cocoa/cocoa_window.m index 3fe7c475..84cdf037 100644 --- a/src/cocoa/cocoa_window.m +++ b/src/cocoa/cocoa_window.m @@ -770,30 +770,6 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window) [window->NS.window deminiaturize:nil]; } -//======================================================================== -// Swap buffers -//======================================================================== - -void _glfwPlatformSwapBuffers(void) -{ - _GLFWwindow* window = _glfwLibrary.currentWindow; - - // ARP appears to be unnecessary, but this is future-proof - [window->NSGL.context flushBuffer]; -} - -//======================================================================== -// Set double buffering swap interval -//======================================================================== - -void _glfwPlatformSwapInterval(int interval) -{ - _GLFWwindow* window = _glfwLibrary.currentWindow; - - GLint sync = interval; - [window->NSGL.context setValues:&sync forParameter:NSOpenGLCPSwapInterval]; -} - //======================================================================== // Write back window parameters into GLFW window structure //======================================================================== diff --git a/src/glext.c b/src/opengl.c similarity index 87% rename from src/glext.c rename to src/opengl.c index 9ae29249..7c25c75d 100644 --- a/src/glext.c +++ b/src/opengl.c @@ -125,6 +125,51 @@ int _glfwStringInExtensionString(const char* string, ////// GLFW public API ////// ////////////////////////////////////////////////////////////////////////// +//======================================================================== +// Swap buffers (double-buffering) +//======================================================================== + +GLFWAPI void glfwSwapBuffers(void) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + + if (!_glfwLibrary.currentWindow) + { + _glfwSetError(GLFW_NO_CURRENT_WINDOW, NULL); + return; + } + + if (_glfwLibrary.currentWindow) + _glfwPlatformSwapBuffers(); +} + + +//======================================================================== +// Set double buffering swap interval (0 = vsync off) +//======================================================================== + +GLFWAPI void glfwSwapInterval(int interval) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + + if (!_glfwLibrary.currentWindow) + { + _glfwSetError(GLFW_NO_CURRENT_WINDOW, NULL); + return; + } + + _glfwPlatformSwapInterval(interval); +} + + //======================================================================== // Check if an OpenGL extension is available at runtime //======================================================================== diff --git a/src/win32/CMakeLists.txt b/src/win32/CMakeLists.txt index 4886d7ba..1220313d 100644 --- a/src/win32/CMakeLists.txt +++ b/src/win32/CMakeLists.txt @@ -23,9 +23,9 @@ set(libglfw_SOURCES ${common_SOURCES} win32_enable.c win32_fullscreen.c win32_gamma.c - win32_glext.c win32_init.c win32_joystick.c + win32_opengl.c win32_time.c win32_window.c win32_dllmain.c) diff --git a/src/win32/win32_glext.c b/src/win32/win32_opengl.c similarity index 80% rename from src/win32/win32_glext.c rename to src/win32/win32_opengl.c index 4245ae8d..0e9320fc 100644 --- a/src/win32/win32_glext.c +++ b/src/win32/win32_opengl.c @@ -35,6 +35,31 @@ ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// +//======================================================================== +// Swap buffers (double-buffering) +//======================================================================== + +void _glfwPlatformSwapBuffers(void) +{ + _GLFWwindow* window = _glfwLibrary.currentWindow; + + _glfw_SwapBuffers(window->WGL.DC); +} + + +//======================================================================== +// Set double buffering swap interval +//======================================================================== + +void _glfwPlatformSwapInterval(int interval) +{ + _GLFWwindow* window = _glfwLibrary.currentWindow; + + if (window->WGL.has_WGL_EXT_swap_control) + window->WGL.SwapIntervalEXT(interval); +} + + //======================================================================== // Check if the current context supports the specified WGL extension //======================================================================== diff --git a/src/win32/win32_window.c b/src/win32/win32_window.c index 3d3058c0..b0862036 100644 --- a/src/win32/win32_window.c +++ b/src/win32/win32_window.c @@ -1593,31 +1593,6 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window) } -//======================================================================== -// Swap buffers (double-buffering) -//======================================================================== - -void _glfwPlatformSwapBuffers(void) -{ - _GLFWwindow* window = _glfwLibrary.currentWindow; - - _glfw_SwapBuffers(window->WGL.DC); -} - - -//======================================================================== -// Set double buffering swap interval -//======================================================================== - -void _glfwPlatformSwapInterval(int interval) -{ - _GLFWwindow* window = _glfwLibrary.currentWindow; - - if (window->WGL.has_WGL_EXT_swap_control) - window->WGL.SwapIntervalEXT(interval); -} - - //======================================================================== // Write back window parameters into GLFW window structure //======================================================================== diff --git a/src/window.c b/src/window.c index dba41e40..0893d6a1 100644 --- a/src/window.c +++ b/src/window.c @@ -984,51 +984,6 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow handle) } -//======================================================================== -// Swap buffers (double-buffering) -//======================================================================== - -GLFWAPI void glfwSwapBuffers(void) -{ - if (!_glfwInitialized) - { - _glfwSetError(GLFW_NOT_INITIALIZED, NULL); - return; - } - - if (!_glfwLibrary.currentWindow) - { - _glfwSetError(GLFW_NO_CURRENT_WINDOW, NULL); - return; - } - - if (_glfwLibrary.currentWindow) - _glfwPlatformSwapBuffers(); -} - - -//======================================================================== -// Set double buffering swap interval (0 = vsync off) -//======================================================================== - -GLFWAPI void glfwSwapInterval(int interval) -{ - if (!_glfwInitialized) - { - _glfwSetError(GLFW_NOT_INITIALIZED, NULL); - return; - } - - if (!_glfwLibrary.currentWindow) - { - _glfwSetError(GLFW_NO_CURRENT_WINDOW, NULL); - return; - } - - _glfwPlatformSwapInterval(interval); -} - - //======================================================================== // Get window parameter //======================================================================== diff --git a/src/x11/CMakeLists.txt b/src/x11/CMakeLists.txt index 4fe09c49..6369a334 100644 --- a/src/x11/CMakeLists.txt +++ b/src/x11/CMakeLists.txt @@ -11,10 +11,10 @@ set(libglfw_SOURCES ${common_SOURCES} x11_enable.c x11_fullscreen.c x11_gamma.c - x11_glext.c x11_init.c x11_joystick.c x11_keysym2unicode.c + x11_opengl.c x11_time.c x11_window.c) diff --git a/src/x11/x11_glext.c b/src/x11/x11_opengl.c similarity index 78% rename from src/x11/x11_glext.c rename to src/x11/x11_opengl.c index d3bac333..cbb669ba 100644 --- a/src/x11/x11_glext.c +++ b/src/x11/x11_opengl.c @@ -56,6 +56,36 @@ void (*glXGetProcAddressEXT(const GLubyte* procName))(); ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// +//======================================================================== +// Swap OpenGL buffers +//======================================================================== + +void _glfwPlatformSwapBuffers(void) +{ + glXSwapBuffers(_glfwLibrary.X11.display, + _glfwLibrary.currentWindow->X11.handle); +} + + +//======================================================================== +// Set double buffering swap interval +//======================================================================== + +void _glfwPlatformSwapInterval(int interval) +{ + _GLFWwindow* window = _glfwLibrary.currentWindow; + + if (window->GLX.has_GLX_EXT_swap_control) + { + window->GLX.SwapIntervalEXT(_glfwLibrary.X11.display, + window->X11.handle, + interval); + } + else if (window->GLX.has_GLX_SGI_swap_control) + window->GLX.SwapIntervalSGI(interval); +} + + //======================================================================== // Check if an OpenGL extension is available at runtime //======================================================================== diff --git a/src/x11/x11_window.c b/src/x11/x11_window.c index 0364084b..afa5b7aa 100644 --- a/src/x11/x11_window.c +++ b/src/x11/x11_window.c @@ -1566,36 +1566,6 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window) } -//======================================================================== -// Swap OpenGL buffers -//======================================================================== - -void _glfwPlatformSwapBuffers(void) -{ - glXSwapBuffers(_glfwLibrary.X11.display, - _glfwLibrary.currentWindow->X11.handle); -} - - -//======================================================================== -// Set double buffering swap interval -//======================================================================== - -void _glfwPlatformSwapInterval(int interval) -{ - _GLFWwindow* window = _glfwLibrary.currentWindow; - - if (window->GLX.has_GLX_EXT_swap_control) - { - window->GLX.SwapIntervalEXT(_glfwLibrary.X11.display, - window->X11.handle, - interval); - } - else if (window->GLX.has_GLX_SGI_swap_control) - window->GLX.SwapIntervalSGI(interval); -} - - //======================================================================== // Read back framebuffer parameters from the context //========================================================================