From 6a5152f30134ce9b1d686d2d1b4e2a630f74defb Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 Mar 2011 18:53:52 +0100 Subject: [PATCH 01/14] Added initial ARB_robustness support. --- include/GL/glfw3.h | 6 ++++++ readme.html | 1 + src/internal.h | 3 +++ src/opengl.c | 11 +++++++++++ src/win32/win32_window.c | 33 +++++++++++++++++++++++++++++++-- src/window.c | 6 ++++++ src/x11/platform.h | 1 + src/x11/x11_window.c | 29 ++++++++++++++++++++++++++++- tests/version.c | 21 ++++++++++++++++++--- 9 files changed, 105 insertions(+), 6 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index ee622b20..e902964c 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -412,6 +412,12 @@ extern "C" { #define GLFW_OPENGL_FORWARD_COMPAT 0x00020015 #define GLFW_OPENGL_DEBUG_CONTEXT 0x00020016 #define GLFW_OPENGL_PROFILE 0x00020017 +#define GLFW_OPENGL_ROBUSTNESS 0x00020018 + +/* GLFW_OPENGL_ROBUSTNESS mode tokens */ +#define GLFW_OPENGL_NO_ROBUSTNESS 0x00000000 +#define GLFW_OPENGL_NO_RESET_NOTIFICATION 0x00000001 +#define GLFW_OPENGL_LOSE_CONTEXT_ON_RESET 0x00000002 /* GLFW_OPENGL_PROFILE bit tokens */ #define GLFW_OPENGL_CORE_PROFILE 0x00000001 diff --git a/readme.html b/readme.html index 6d54174f..314b1cdd 100644 --- a/readme.html +++ b/readme.html @@ -274,6 +274,7 @@ version of GLFW.

  • Added glfwGetCurrentWindow function for retrieving the window whose OpenGL context is current
  • Added glfwInitWithModels function and GLFWallocator and GLFWthreadmodel types for pluggable memory allocation and threading models
  • Added GLFW_OPENGL_ES2_PROFILE profile for creating OpenGL ES 2.0 contexts using the GLX_EXT_create_context_es2_profile and WGL_EXT_create_context_es2_profile extensions
  • +
  • Added GLFW_OPENGL_ROBUSTNESS window hint and associated strategy tokens for GL_ARB_robustness support
  • Added windows simple multi-window test program
  • Added sharing simple OpenGL object sharing test program
  • Added a parameter to glfwOpenWindow for specifying a context the new window's context will share objects with
  • diff --git a/src/internal.h b/src/internal.h index 2d24b004..c942707b 100644 --- a/src/internal.h +++ b/src/internal.h @@ -99,6 +99,7 @@ struct _GLFWhints GLboolean glForward; GLboolean glDebug; int glProfile; + int glRobustness; }; @@ -119,6 +120,7 @@ struct _GLFWwndconfig GLboolean glForward; GLboolean glDebug; int glProfile; + int glRobustness; _GLFWwindow* share; }; @@ -196,6 +198,7 @@ struct _GLFWwindow int glMajor, glMinor, glRevision; GLboolean glForward, glDebug; int glProfile; + int glRobustness; PFNGLGETSTRINGIPROC GetStringi; // These are defined in the current port's platform.h diff --git a/src/opengl.c b/src/opengl.c index 31e3bbea..a08f97f9 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -320,6 +320,16 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig) return GL_FALSE; } + if (wndconfig->glRobustness) + { + if (wndconfig->glRobustness != GLFW_OPENGL_NO_RESET_NOTIFICATION && + wndconfig->glRobustness != GLFW_OPENGL_LOSE_CONTEXT_ON_RESET) + { + _glfwSetError(GLFW_INVALID_VALUE, "glfwOpenWindow: Invalid OpenGL robustness mode requested"); + return GL_FALSE; + } + } + return GL_TRUE; } @@ -335,6 +345,7 @@ GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig) // As these are hard constraints when non-zero, we can simply copy them window->glProfile = wndconfig->glProfile; window->glForward = wndconfig->glForward; + window->glRobustness = wndconfig->glRobustness; if (window->glMajor < wndconfig->glMajor || (window->glMajor == wndconfig->glMajor && diff --git a/src/win32/win32_window.c b/src/win32/win32_window.c index 2def3a82..317371eb 100644 --- a/src/win32/win32_window.c +++ b/src/win32/win32_window.c @@ -323,7 +323,7 @@ static GLboolean createContext(_GLFWwindow* window, int pixelFormat) { PIXELFORMATDESCRIPTOR pfd; - int i = 0, attribs[9]; + int i = 0, attribs[40]; HGLRC share = NULL; if (wndconfig->share) @@ -355,7 +355,7 @@ static GLboolean createContext(_GLFWwindow* window, attribs[i++] = wndconfig->glMinor; } - if (wndconfig->glForward || wndconfig->glDebug) + if (wndconfig->glForward || wndconfig->glDebug || wndconfig->glRobustness) { int flags = 0; @@ -365,6 +365,9 @@ static GLboolean createContext(_GLFWwindow* window, if (wndconfig->glDebug) flags |= WGL_CONTEXT_DEBUG_BIT_ARB; + if (wndconfig->glRobustness) + flags |= WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB; + attribs[i++] = WGL_CONTEXT_FLAGS_ARB; attribs[i++] = flags; } @@ -397,6 +400,25 @@ static GLboolean createContext(_GLFWwindow* window, attribs[i++] = flags; } + if (wndconfig->glRobustness) + { + int strategy; + + if (!window->WGL.has_WGL_ARB_create_context_robustness) + { + _glfwSetError(GLFW_VERSION_UNAVAILABLE, "Win32/WGL: An OpenGL robustness strategy was requested but WGL_ARB_create_context_robustness is unavailable"); + return GL_FALSE; + } + + if (wndconfig->glRobustness == GLFW_OPENGL_NO_RESET_NOTIFICATION) + strategy = WGL_NO_RESET_NOTIFICATION_ARB; + else if (wndconfig->glRobustness == GLFW_OPENGL_LOSE_CONTEXT_ON_RESET) + strategy = WGL_LOSE_CONTEXT_ON_RESET_ARB; + + attribs[i++] = WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB; + attribs[i++] = strategy; + } + attribs[i++] = 0; window->WGL.context = window->WGL.CreateContextAttribsARB(window->WGL.DC, @@ -1067,6 +1089,7 @@ static void initWGLExtensions(_GLFWwindow* window) window->WGL.has_WGL_ARB_create_context = GL_FALSE; window->WGL.has_WGL_ARB_create_context_profile = GL_FALSE; window->WGL.has_WGL_EXT_create_context_es2_profile = GL_FALSE; + window->WGL.has_WGL_EXT_create_context_robustness = GL_FALSE; window->WGL.has_WGL_EXT_swap_control = GL_FALSE; window->WGL.has_WGL_ARB_pixel_format = GL_FALSE; @@ -1105,6 +1128,12 @@ static void initWGLExtensions(_GLFWwindow* window) window->WGL.has_WGL_EXT_create_context_es2_profile = GL_TRUE; } + if (window->WGL.has_WGL_ARB_create_context) + { + if (_glfwPlatformExtensionSupported("WGL_ARB_create_context_robustness")) + window->WGL.has_WGL_EXT_create_context_robustness = GL_TRUE; + } + if (_glfwPlatformExtensionSupported("WGL_EXT_swap_control")) { window->WGL.SwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) diff --git a/src/window.c b/src/window.c index 20d436ed..f0f504c5 100644 --- a/src/window.c +++ b/src/window.c @@ -277,6 +277,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE; wndconfig.glDebug = _glfwLibrary.hints.glDebug ? GL_TRUE : GL_FALSE; wndconfig.glProfile = _glfwLibrary.hints.glProfile; + wndconfig.glRobustness = _glfwLibrary.hints.glRobustness ? GL_TRUE : GL_FALSE; wndconfig.share = share; // Reset to default values for the next call @@ -499,6 +500,9 @@ GLFWAPI void glfwOpenWindowHint(int target, int hint) case GLFW_OPENGL_PROFILE: _glfwLibrary.hints.glProfile = hint; break; + case GLFW_OPENGL_ROBUSTNESS: + _glfwLibrary.hints.glRobustness = hint; + break; default: break; } @@ -776,6 +780,8 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param) return window->glDebug; case GLFW_OPENGL_PROFILE: return window->glProfile; + case GLFW_OPENGL_ROBUSTNESS: + return window->glRobustness; default: _glfwSetError(GLFW_INVALID_ENUM, "glfwGetWindowParam: Invalid enum value for 'param' parameter"); return 0; diff --git a/src/x11/platform.h b/src/x11/platform.h index bdaa6d8f..204e9cc3 100644 --- a/src/x11/platform.h +++ b/src/x11/platform.h @@ -107,6 +107,7 @@ typedef struct _GLFWcontextGLX GLboolean has_GLX_ARB_multisample; GLboolean has_GLX_ARB_create_context; GLboolean has_GLX_ARB_create_context_profile; + GLboolean has_GLX_ARB_create_context_robustness; GLboolean has_GLX_EXT_create_context_es2_profile; } _GLFWcontextGLX; diff --git a/src/x11/x11_window.c b/src/x11/x11_window.c index 051be402..47af01f6 100644 --- a/src/x11/x11_window.c +++ b/src/x11/x11_window.c @@ -445,7 +445,7 @@ static int createContext(_GLFWwindow* window, setGLXattrib(attribs, index, GLX_CONTEXT_MINOR_VERSION_ARB, wndconfig->glMinor); } - if (wndconfig->glForward || wndconfig->glDebug) + if (wndconfig->glForward || wndconfig->glDebug || wndconfig->glRobustness) { int flags = 0; @@ -455,6 +455,9 @@ static int createContext(_GLFWwindow* window, if (wndconfig->glDebug) flags |= GLX_CONTEXT_DEBUG_BIT_ARB; + if (wndconfig->glRobustness) + flags |= GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB; + setGLXattrib(attribs, index, GLX_CONTEXT_FLAGS_ARB, flags); } @@ -485,6 +488,24 @@ static int createContext(_GLFWwindow* window, setGLXattrib(attribs, index, GLX_CONTEXT_PROFILE_MASK_ARB, flags); } + if (wndconfig->glRobustness) + { + int strategy; + + if (!window->GLX.has_GLX_ARB_create_context_robustness) + { + _glfwSetError(GLFW_VERSION_UNAVAILABLE, "X11/GLX: An OpenGL robustness strategy was requested but GLX_ARB_create_context_robustness is unavailable"); + return GL_FALSE; + } + + if (wndconfig->glRobustness == GLFW_OPENGL_NO_RESET_NOTIFICATION) + strategy = GLX_NO_RESET_NOTIFICATION_ARB; + else if (wndconfig->glRobustness == GLFW_OPENGL_LOSE_CONTEXT_ON_RESET) + strategy = GLX_LOSE_CONTEXT_ON_RESET_ARB; + + setGLXattrib(attribs, index, GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, strategy); + } + setGLXattrib(attribs, index, None, None); // This is the only place we set an Xlib error handler, and we only do @@ -613,6 +634,12 @@ static void initGLXExtensions(_GLFWwindow* window) if (_glfwPlatformExtensionSupported("GLX_EXT_create_context_es2_profile")) window->GLX.has_GLX_EXT_create_context_es2_profile = GL_TRUE; } + + if (window->GLX.has_GLX_ARB_create_context) + { + if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_robustness")) + window->GLX.has_GLX_ARB_create_context_robustness = GL_TRUE; + } } diff --git a/tests/version.c b/tests/version.c index af0c33a6..e473ef55 100644 --- a/tests/version.c +++ b/tests/version.c @@ -44,8 +44,9 @@ static void usage(void) { - printf("Usage: version [-h] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE]\n"); + printf("Usage: version [-h] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n"); printf("available profiles: core compat es2\n"); + printf("available strategies: none lose\n"); } static void error_callback(int error, const char* description) @@ -113,12 +114,12 @@ static void list_extensions(int major, int minor) int main(int argc, char** argv) { - int ch, profile = 0, major = 1, minor = 0, revision; + int ch, profile = 0, strategy = 0, major = 1, minor = 0, revision; GLboolean debug = GL_FALSE, forward = GL_FALSE, list = GL_FALSE; GLint flags, mask; GLFWwindow window; - while ((ch = getopt(argc, argv, "dfhlm:n:p:")) != -1) + while ((ch = getopt(argc, argv, "dfhlm:n:p:r:")) != -1) { switch (ch) { @@ -153,6 +154,17 @@ int main(int argc, char** argv) exit(EXIT_FAILURE); } break; + case 'r': + if (strcasecmp(optarg, "none") == 0) + strategy = GLFW_OPENGL_NO_RESET_NOTIFICATION; + else if (strcasecmp(optarg, "lose") == 0) + strategy = GLFW_OPENGL_LOSE_CONTEXT_ON_RESET; + else + { + usage(); + exit(EXIT_FAILURE); + } + break; default: usage(); exit(EXIT_FAILURE); @@ -185,6 +197,9 @@ int main(int argc, char** argv) if (profile != 0) glfwOpenWindowHint(GLFW_OPENGL_PROFILE, profile); + if (strategy) + glfwOpenWindowHint(GLFW_OPENGL_ROBUSTNESS, strategy); + // We assume here that we stand a better chance of success by leaving all // possible details of pixel format selection to GLFW From 222f1d560053e11d85a5ee7bca6d271bcac3fd93 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 Mar 2011 18:55:20 +0100 Subject: [PATCH 02/14] Added the usual punt on Mac OS X. --- src/cocoa/cocoa_window.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cocoa/cocoa_window.m b/src/cocoa/cocoa_window.m index 974dbdbc..b6c97fbd 100644 --- a/src/cocoa/cocoa_window.m +++ b/src/cocoa/cocoa_window.m @@ -479,6 +479,13 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, return GL_FALSE; } + // Fail if a robustness strategy was requested + if (wndconfig->glRobustness) + { + _glfwSetError(GLFW_VERSION_UNAVAILABLE, "Cocoa/NSOpenGL: Mac OS X does not support OpenGL robustness strategies"); + 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 if (_glfwLibrary.NS.delegate == nil) From c40f0e2c367d6a27c4a51bef68f9d1c370a6d33a Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 Mar 2011 20:43:10 +0100 Subject: [PATCH 03/14] Added missing member. --- src/win32/platform.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/win32/platform.h b/src/win32/platform.h index 08a15183..4ae50979 100644 --- a/src/win32/platform.h +++ b/src/win32/platform.h @@ -232,6 +232,7 @@ typedef struct _GLFWcontextWGL GLboolean has_WGL_ARB_create_context; GLboolean has_WGL_ARB_create_context_profile; GLboolean has_WGL_EXT_create_context_es2_profile; + GLboolean has_WGL_EXT_create_context_robustness; } _GLFWcontextWGL; From c541457617559b5421aa45a39432e80638e69870 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 Mar 2011 20:46:05 +0100 Subject: [PATCH 04/14] ARB, not EXT. --- src/win32/platform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win32/platform.h b/src/win32/platform.h index 4ae50979..d6a5787d 100644 --- a/src/win32/platform.h +++ b/src/win32/platform.h @@ -232,7 +232,7 @@ typedef struct _GLFWcontextWGL GLboolean has_WGL_ARB_create_context; GLboolean has_WGL_ARB_create_context_profile; GLboolean has_WGL_EXT_create_context_es2_profile; - GLboolean has_WGL_EXT_create_context_robustness; + GLboolean has_WGL_ARB_create_context_robustness; } _GLFWcontextWGL; From f31038599706be9dc2597b9a3a267ca5c8217fa5 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 Mar 2011 20:49:27 +0100 Subject: [PATCH 05/14] ARB, not EXT. --- src/win32/win32_window.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/win32/win32_window.c b/src/win32/win32_window.c index 317371eb..91f437b0 100644 --- a/src/win32/win32_window.c +++ b/src/win32/win32_window.c @@ -1089,7 +1089,7 @@ static void initWGLExtensions(_GLFWwindow* window) window->WGL.has_WGL_ARB_create_context = GL_FALSE; window->WGL.has_WGL_ARB_create_context_profile = GL_FALSE; window->WGL.has_WGL_EXT_create_context_es2_profile = GL_FALSE; - window->WGL.has_WGL_EXT_create_context_robustness = GL_FALSE; + window->WGL.has_WGL_ARB_create_context_robustness = GL_FALSE; window->WGL.has_WGL_EXT_swap_control = GL_FALSE; window->WGL.has_WGL_ARB_pixel_format = GL_FALSE; @@ -1131,7 +1131,7 @@ static void initWGLExtensions(_GLFWwindow* window) if (window->WGL.has_WGL_ARB_create_context) { if (_glfwPlatformExtensionSupported("WGL_ARB_create_context_robustness")) - window->WGL.has_WGL_EXT_create_context_robustness = GL_TRUE; + window->WGL.has_WGL_ARB_create_context_robustness = GL_TRUE; } if (_glfwPlatformExtensionSupported("WGL_EXT_swap_control")) From 53f4f54c46070d090665cae2e2c6cb5393bf68d7 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 26 Jul 2011 15:16:34 +0200 Subject: [PATCH 06/14] Flattened source tree. --- CMakeLists.txt | 25 +----- src/CMakeLists.txt | 90 ++++++++++++++++++++++ src/cocoa/CMakeLists.txt | 40 ---------- src/cocoa/libglfw.pc.cmake | 11 --- src/{cocoa => }/cocoa_enable.m | 0 src/{cocoa => }/cocoa_fullscreen.m | 0 src/{cocoa => }/cocoa_gamma.m | 0 src/{cocoa => }/cocoa_init.m | 0 src/{cocoa => }/cocoa_joystick.m | 0 src/{cocoa => }/cocoa_opengl.m | 0 src/{cocoa/platform.h => cocoa_platform.h} | 0 src/{cocoa => }/cocoa_time.m | 0 src/{cocoa => }/cocoa_window.m | 0 src/internal.h | 15 +++- src/libglfw.pc.cmake | 0 src/win32/CMakeLists.txt | 59 -------------- src/win32/libglfw.pc.cmake | 11 --- src/{win32 => }/win32_dllmain.c | 0 src/{win32 => }/win32_enable.c | 0 src/{win32 => }/win32_fullscreen.c | 0 src/{win32 => }/win32_gamma.c | 0 src/{win32 => }/win32_init.c | 0 src/{win32 => }/win32_joystick.c | 0 src/{win32 => }/win32_opengl.c | 0 src/{win32/platform.h => win32_platform.h} | 0 src/{win32 => }/win32_time.c | 0 src/{win32 => }/win32_window.c | 0 src/x11/CMakeLists.txt | 30 -------- src/x11/libglfw.pc.cmake | 11 --- src/{x11 => }/x11_enable.c | 0 src/{x11 => }/x11_fullscreen.c | 0 src/{x11 => }/x11_gamma.c | 0 src/{x11 => }/x11_init.c | 0 src/{x11 => }/x11_joystick.c | 0 src/{x11 => }/x11_keysym2unicode.c | 0 src/{x11 => }/x11_opengl.c | 0 src/{x11/platform.h => x11_platform.h} | 0 src/{x11 => }/x11_time.c | 0 src/{x11 => }/x11_window.c | 0 39 files changed, 103 insertions(+), 189 deletions(-) create mode 100644 src/CMakeLists.txt delete mode 100644 src/cocoa/CMakeLists.txt delete mode 100644 src/cocoa/libglfw.pc.cmake rename src/{cocoa => }/cocoa_enable.m (100%) rename src/{cocoa => }/cocoa_fullscreen.m (100%) rename src/{cocoa => }/cocoa_gamma.m (100%) rename src/{cocoa => }/cocoa_init.m (100%) rename src/{cocoa => }/cocoa_joystick.m (100%) rename src/{cocoa => }/cocoa_opengl.m (100%) rename src/{cocoa/platform.h => cocoa_platform.h} (100%) rename src/{cocoa => }/cocoa_time.m (100%) rename src/{cocoa => }/cocoa_window.m (100%) create mode 100644 src/libglfw.pc.cmake delete mode 100644 src/win32/CMakeLists.txt delete mode 100644 src/win32/libglfw.pc.cmake rename src/{win32 => }/win32_dllmain.c (100%) rename src/{win32 => }/win32_enable.c (100%) rename src/{win32 => }/win32_fullscreen.c (100%) rename src/{win32 => }/win32_gamma.c (100%) rename src/{win32 => }/win32_init.c (100%) rename src/{win32 => }/win32_joystick.c (100%) rename src/{win32 => }/win32_opengl.c (100%) rename src/{win32/platform.h => win32_platform.h} (100%) rename src/{win32 => }/win32_time.c (100%) rename src/{win32 => }/win32_window.c (100%) delete mode 100644 src/x11/CMakeLists.txt delete mode 100644 src/x11/libglfw.pc.cmake rename src/{x11 => }/x11_enable.c (100%) rename src/{x11 => }/x11_fullscreen.c (100%) rename src/{x11 => }/x11_gamma.c (100%) rename src/{x11 => }/x11_init.c (100%) rename src/{x11 => }/x11_joystick.c (100%) rename src/{x11 => }/x11_keysym2unicode.c (100%) rename src/{x11 => }/x11_opengl.c (100%) rename src/{x11/platform.h => x11_platform.h} (100%) rename src/{x11 => }/x11_time.c (100%) rename src/{x11 => }/x11_window.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa2f01f0..f0c2eeef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,19 +15,6 @@ include(CheckSymbolExists) find_package(OpenGL REQUIRED) -set(common_SOURCES - ${GLFW_SOURCE_DIR}/src/enable.c - ${GLFW_SOURCE_DIR}/src/error.c - ${GLFW_SOURCE_DIR}/src/fullscreen.c - ${GLFW_SOURCE_DIR}/src/gamma.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 -) - #-------------------------------------------------------------------- # Set up GLFW for Win32 and WGL on Windows #-------------------------------------------------------------------- @@ -41,9 +28,6 @@ if (WIN32) set(CMAKE_REQUIRED_LIBRARIES ${OPENGL_gl_LIBRARY}) list(APPEND GLFW_INCLUDE_DIR ${OPENGL_INCLUDE_DIR}) list(APPEND GLFW_LIBRARIES ${OPENGL_gl_LIBRARY}) - - # Select platform specific code - add_subdirectory(src/win32) endif (WIN32) #-------------------------------------------------------------------- @@ -105,9 +89,6 @@ if (UNIX AND NOT APPLE AND NOT CYGWIN) if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") set(_GLFW_USE_LINUX_JOYSTICKS 1) endif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - - # Select platform specific code - add_subdirectory(src/x11) endif(UNIX AND NOT APPLE AND NOT CYGWIN) #-------------------------------------------------------------------- @@ -135,14 +116,12 @@ if (UNIX AND APPLE) find_library(COCOA_FRAMEWORK Cocoa) list(APPEND GLFW_LIBRARIES ${COCOA_FRAMEWORK}) list(APPEND GLFW_LIBRARIES ${OPENGL_gl_LIBRARY}) - - # Select platform specific code - add_subdirectory(src/cocoa) endif(UNIX AND APPLE) #-------------------------------------------------------------------- -# Add example and test programs +# Add subdirectories #-------------------------------------------------------------------- +add_subdirectory(src) add_subdirectory(examples) add_subdirectory(tests) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..86be028b --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,90 @@ + +if(CYGWIN) + + # These lines are intended to remove the --export-all-symbols + # flag added in the Modules/Platform/CYGWIN.cmake file of the + # CMake distribution. + # This is a HACK. If you have trouble _linking_ the GLFW + # _shared_ library on Cygwin, try disabling this. + set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") + set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}) + +endif(CYGWIN) + +if(UNIX) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake + ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc DESTINATION lib/pkgconfig) +endif(UNIX) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR} + ${GLFW_SOURCE_DIR}/src + ${GLFW_BINARY_DIR}/src + ${GLFW_INCLUDE_DIR}) + +set(common_SOURCES enable.c + error.c + fullscreen.c + gamma.c + init.c + input.c + joystick.c + opengl.c + time.c + window.c) + +if(_GLFW_COCOA_NSGL) + set(libglfw_SOURCES ${common_SOURCES} cocoa_enable.m cocoa_fullscreen.m + cocoa_gamma.m cocoa_init.m cocoa_joystick.m + cocoa_opengl.m cocoa_time.m cocoa_window.m) + + # For some reason, CMake doesn't know about .m + set_source_files_properties(${libglfw_SOURCES} PROPERTIES LANGUAGE C) +elseif(_GLFW_WIN32_WGL) + set(libglfw_SOURCES ${common_SOURCES} win32_enable.c win32_fullscreen.c + win32_gamma.c win32_init.c win32_joystick.c + win32_opengl.c win32_time.c win32_window.c + win32_dllmain.c) +elseif(_GLFW_X11_GLX) + set(libglfw_SOURCES ${common_SOURCES} x11_enable.c x11_fullscreen.c + x11_gamma.c x11_init.c x11_joystick.c + x11_keysym2unicode.c x11_opengl.c x11_time.c + x11_window.c) +else() + message(FATAL_ERROR "No supported platform was selected") +endif(_GLFW_COCOA_NSGL) + +add_library(libglfwStatic STATIC ${libglfw_SOURCES}) +add_library(libglfwShared SHARED ${libglfw_SOURCES}) +target_link_libraries(libglfwShared ${GLFW_LIBRARIES}) +set_target_properties(libglfwStatic libglfwShared PROPERTIES + CLEAN_DIRECT_OUTPUT 1 + OUTPUT_NAME glfw) + +if(WIN32) + # The GLFW DLL needs a special compile-time macro and import library name + set_target_properties(libglfwShared PROPERTIES + DEFINE_SYMBOL GLFW_BUILD_DLL + PREFIX "" + IMPORT_PREFIX "" + IMPORT_SUFFIX "dll.lib") +endif(WIN32) + +if(CYGWIN) + # Build for the regular Win32 environment (not Cygwin) + set_target_properties(libglfwStatic libglfwShared PROPERTIES + COMPILE_FLAGS "-mwin32 -mno-cygwin" + LINK_FLAGS "-mwin32 -mno-cygwin") +endif(CYGWIN) + +if(APPLE) + # Append -fno-common to the compile flags to work around a bug in the Apple GCC + get_target_property(CFLAGS libglfwShared COMPILE_FLAGS) + if(NOT CFLAGS) + set(CFLAGS "") + endif(NOT CFLAGS) + set_target_properties(libglfwShared PROPERTIES COMPILE_FLAGS "${CFLAGS} -fno-common") +endif(APPLE) + +install(TARGETS libglfwStatic libglfwShared DESTINATION lib) + diff --git a/src/cocoa/CMakeLists.txt b/src/cocoa/CMakeLists.txt deleted file mode 100644 index f0bc3c4c..00000000 --- a/src/cocoa/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ - -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake - ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR} - ${GLFW_SOURCE_DIR}/src - ${GLFW_BINARY_DIR}/src - ${GLFW_INCLUDE_DIR}) - -set(cocoa_SOURCES cocoa_enable.m - cocoa_fullscreen.m - cocoa_gamma.m - cocoa_init.m - cocoa_joystick.m - cocoa_opengl.m - cocoa_time.m - cocoa_window.m) - -# For some reason, CMake doesn't know about .m -set_source_files_properties(${cocoa_SOURCES} PROPERTIES LANGUAGE C) - -set(libglfw_SOURCES ${common_SOURCES} ${cocoa_SOURCES}) - -add_library(libglfwStatic STATIC ${libglfw_SOURCES}) -add_library(libglfwShared SHARED ${libglfw_SOURCES}) -target_link_libraries(libglfwShared ${GLFW_LIBRARIES}) -set_target_properties(libglfwStatic libglfwShared PROPERTIES - CLEAN_DIRECT_OUTPUT 1 - OUTPUT_NAME glfw) - -# Append -fno-common to the compile flags to work around a bug in the Apple GCC -get_target_property(CFLAGS libglfwShared COMPILE_FLAGS) -if(NOT CFLAGS) - set(CFLAGS "") -endif(NOT CFLAGS) -set_target_properties(libglfwShared PROPERTIES COMPILE_FLAGS "${CFLAGS} -fno-common") - -install(TARGETS libglfwStatic libglfwShared DESTINATION lib) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc DESTINATION lib/pkgconfig) - diff --git a/src/cocoa/libglfw.pc.cmake b/src/cocoa/libglfw.pc.cmake deleted file mode 100644 index 37de53a3..00000000 --- a/src/cocoa/libglfw.pc.cmake +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=@PREFIX@ -libdir=@PREFIX@/lib -includedir=@PREFIX@/include - -Name: GLFW -Description: A portable library for OpenGL development -Version: 3.0 -URL: http://www.glfw.org/ -Libs: -L${libdir} -lglfw -framework AGL -framework OpenGL -framework Carbon -Cflags: -I${includedir} diff --git a/src/cocoa/cocoa_enable.m b/src/cocoa_enable.m similarity index 100% rename from src/cocoa/cocoa_enable.m rename to src/cocoa_enable.m diff --git a/src/cocoa/cocoa_fullscreen.m b/src/cocoa_fullscreen.m similarity index 100% rename from src/cocoa/cocoa_fullscreen.m rename to src/cocoa_fullscreen.m diff --git a/src/cocoa/cocoa_gamma.m b/src/cocoa_gamma.m similarity index 100% rename from src/cocoa/cocoa_gamma.m rename to src/cocoa_gamma.m diff --git a/src/cocoa/cocoa_init.m b/src/cocoa_init.m similarity index 100% rename from src/cocoa/cocoa_init.m rename to src/cocoa_init.m diff --git a/src/cocoa/cocoa_joystick.m b/src/cocoa_joystick.m similarity index 100% rename from src/cocoa/cocoa_joystick.m rename to src/cocoa_joystick.m diff --git a/src/cocoa/cocoa_opengl.m b/src/cocoa_opengl.m similarity index 100% rename from src/cocoa/cocoa_opengl.m rename to src/cocoa_opengl.m diff --git a/src/cocoa/platform.h b/src/cocoa_platform.h similarity index 100% rename from src/cocoa/platform.h rename to src/cocoa_platform.h diff --git a/src/cocoa/cocoa_time.m b/src/cocoa_time.m similarity index 100% rename from src/cocoa/cocoa_time.m rename to src/cocoa_time.m diff --git a/src/cocoa/cocoa_window.m b/src/cocoa_window.m similarity index 100% rename from src/cocoa/cocoa_window.m rename to src/cocoa_window.m diff --git a/src/internal.h b/src/internal.h index 4a39b9c9..2c49aa2b 100644 --- a/src/internal.h +++ b/src/internal.h @@ -58,11 +58,18 @@ #include "config.h" -#include "../../include/GL/glfw3.h" -#include "../../include/GL/glext.h" - -#include "platform.h" +#include "../include/GL/glfw3.h" +#include "../include/GL/glext.h" +#if defined(_GLFW_COCOA_NSGL) +#include "cocoa_platform.h" +#elif defined(_GLFW_WIN32_WGL) +#include "win32_platform.h" +#elif defined(_GLFW_X11_GLX) +#include "x11_platform.h" +#else +#error "No supported platform selected" +#endif typedef struct _GLFWhints _GLFWhints; typedef struct _GLFWwndconfig _GLFWwndconfig; diff --git a/src/libglfw.pc.cmake b/src/libglfw.pc.cmake new file mode 100644 index 00000000..e69de29b diff --git a/src/win32/CMakeLists.txt b/src/win32/CMakeLists.txt deleted file mode 100644 index 1220313d..00000000 --- a/src/win32/CMakeLists.txt +++ /dev/null @@ -1,59 +0,0 @@ - -if(CYGWIN) - - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake - ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY) - -# These lines are intended to remove the --export-all-symbols -# flag added in the Modules/Platform/CYGWIN.cmake file of the -# CMake distribution. -# This is a HACK. If you have trouble _linking_ the GLFW -# _shared_ library on Cygwin, try disabling this. - set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") - set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}) - -endif(CYGWIN) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR} - ${GLFW_SOURCE_DIR}/src - ${GLFW_BINARY_DIR}/src - ${GLFW_INCLUDE_DIR}) - -set(libglfw_SOURCES ${common_SOURCES} - win32_enable.c - win32_fullscreen.c - win32_gamma.c - win32_init.c - win32_joystick.c - win32_opengl.c - win32_time.c - win32_window.c - win32_dllmain.c) - -add_library(libglfwStatic STATIC ${libglfw_SOURCES}) -add_library(libglfwShared SHARED ${libglfw_SOURCES}) - -target_link_libraries(libglfwShared ${OPENGL_gl_LIBRARY}) -set_target_properties(libglfwShared PROPERTIES - DEFINE_SYMBOL GLFW_BUILD_DLL - PREFIX "" - IMPORT_PREFIX "" - IMPORT_SUFFIX "dll.lib") - -set_target_properties(libglfwStatic libglfwShared PROPERTIES - CLEAN_DIRECT_OUTPUT 1 - OUTPUT_NAME glfw) - -if(CYGWIN) - # Build for the regular Win32 environment (not Cygwin) - set_target_properties(libglfwStatic libglfwShared PROPERTIES - COMPILE_FLAGS "-mwin32 -mno-cygwin" - LINK_FLAGS "-mwin32 -mno-cygwin") -endif(CYGWIN) - -install(TARGETS libglfwStatic libglfwShared DESTINATION lib) - -if(CYGWIN) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc DESTINATION lib/pkgconfig) -endif(CYGWIN) - diff --git a/src/win32/libglfw.pc.cmake b/src/win32/libglfw.pc.cmake deleted file mode 100644 index 9449ce2e..00000000 --- a/src/win32/libglfw.pc.cmake +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@CMAKE_INSTALL_PREFIX@ -exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${prefix}/include - -Name: GLFW -Description: A portable library for OpenGL development -Version: 3.0 -URL: http://www.glfw.org/ -Libs: -L${libdir} -lglfw @GLFW_LIBRARIES@ -Cflags: -I${includedir} -mwin32 diff --git a/src/win32/win32_dllmain.c b/src/win32_dllmain.c similarity index 100% rename from src/win32/win32_dllmain.c rename to src/win32_dllmain.c diff --git a/src/win32/win32_enable.c b/src/win32_enable.c similarity index 100% rename from src/win32/win32_enable.c rename to src/win32_enable.c diff --git a/src/win32/win32_fullscreen.c b/src/win32_fullscreen.c similarity index 100% rename from src/win32/win32_fullscreen.c rename to src/win32_fullscreen.c diff --git a/src/win32/win32_gamma.c b/src/win32_gamma.c similarity index 100% rename from src/win32/win32_gamma.c rename to src/win32_gamma.c diff --git a/src/win32/win32_init.c b/src/win32_init.c similarity index 100% rename from src/win32/win32_init.c rename to src/win32_init.c diff --git a/src/win32/win32_joystick.c b/src/win32_joystick.c similarity index 100% rename from src/win32/win32_joystick.c rename to src/win32_joystick.c diff --git a/src/win32/win32_opengl.c b/src/win32_opengl.c similarity index 100% rename from src/win32/win32_opengl.c rename to src/win32_opengl.c diff --git a/src/win32/platform.h b/src/win32_platform.h similarity index 100% rename from src/win32/platform.h rename to src/win32_platform.h diff --git a/src/win32/win32_time.c b/src/win32_time.c similarity index 100% rename from src/win32/win32_time.c rename to src/win32_time.c diff --git a/src/win32/win32_window.c b/src/win32_window.c similarity index 100% rename from src/win32/win32_window.c rename to src/win32_window.c diff --git a/src/x11/CMakeLists.txt b/src/x11/CMakeLists.txt deleted file mode 100644 index 6369a334..00000000 --- a/src/x11/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ - -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake - ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR} - ${GLFW_SOURCE_DIR}/src - ${GLFW_BINARY_DIR}/src - ${GLFW_INCLUDE_DIR}) - -set(libglfw_SOURCES ${common_SOURCES} - x11_enable.c - x11_fullscreen.c - x11_gamma.c - x11_init.c - x11_joystick.c - x11_keysym2unicode.c - x11_opengl.c - x11_time.c - x11_window.c) - -add_library(libglfwStatic STATIC ${libglfw_SOURCES}) -add_library(libglfwShared SHARED ${libglfw_SOURCES}) -target_link_libraries(libglfwShared ${GLFW_LIBRARIES}) -set_target_properties(libglfwStatic libglfwShared PROPERTIES - CLEAN_DIRECT_OUTPUT 1 - OUTPUT_NAME glfw) - -install(TARGETS libglfwStatic libglfwShared DESTINATION lib) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc DESTINATION lib/pkgconfig) - diff --git a/src/x11/libglfw.pc.cmake b/src/x11/libglfw.pc.cmake deleted file mode 100644 index c9b8a690..00000000 --- a/src/x11/libglfw.pc.cmake +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@CMAKE_INSTALL_PREFIX@ -exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${prefix}/include - -Name: GLFW -Description: A portable library for OpenGL development -Version: 3.0 -URL: http://www.glfw.org/ -Libs: -L${libdir} -lglfw @GLFW_LIBRARIES@ -Cflags: -I${includedir} diff --git a/src/x11/x11_enable.c b/src/x11_enable.c similarity index 100% rename from src/x11/x11_enable.c rename to src/x11_enable.c diff --git a/src/x11/x11_fullscreen.c b/src/x11_fullscreen.c similarity index 100% rename from src/x11/x11_fullscreen.c rename to src/x11_fullscreen.c diff --git a/src/x11/x11_gamma.c b/src/x11_gamma.c similarity index 100% rename from src/x11/x11_gamma.c rename to src/x11_gamma.c diff --git a/src/x11/x11_init.c b/src/x11_init.c similarity index 100% rename from src/x11/x11_init.c rename to src/x11_init.c diff --git a/src/x11/x11_joystick.c b/src/x11_joystick.c similarity index 100% rename from src/x11/x11_joystick.c rename to src/x11_joystick.c diff --git a/src/x11/x11_keysym2unicode.c b/src/x11_keysym2unicode.c similarity index 100% rename from src/x11/x11_keysym2unicode.c rename to src/x11_keysym2unicode.c diff --git a/src/x11/x11_opengl.c b/src/x11_opengl.c similarity index 100% rename from src/x11/x11_opengl.c rename to src/x11_opengl.c diff --git a/src/x11/platform.h b/src/x11_platform.h similarity index 100% rename from src/x11/platform.h rename to src/x11_platform.h diff --git a/src/x11/x11_time.c b/src/x11_time.c similarity index 100% rename from src/x11/x11_time.c rename to src/x11_time.c diff --git a/src/x11/x11_window.c b/src/x11_window.c similarity index 100% rename from src/x11/x11_window.c rename to src/x11_window.c From 4c6e24c911964b8c814f3992f1a9a36e4003d388 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 26 Jul 2011 16:52:57 +0200 Subject: [PATCH 07/14] Added declaration of size_t. --- include/GL/glfw3.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 63e5f17f..cba9e9b7 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -147,6 +147,10 @@ extern "C" { /* -------------------- END SYSTEM/COMPILER SPECIFIC --------------------- */ +/* Include the declaration of the size_t type used below. + */ +#include + /* Include standard OpenGL headers: GLFW uses GL_FALSE/GL_TRUE, and it is * convenient for the user to only have to include . This also * solves the problem with Windows and needing some From 673b42d8daf2de23757d032553c51c9215a37352 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 26 Jul 2011 16:59:37 +0200 Subject: [PATCH 08/14] Formatting. --- src/CMakeLists.txt | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 86be028b..dd844fc1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,16 +22,8 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${GLFW_BINARY_DIR}/src ${GLFW_INCLUDE_DIR}) -set(common_SOURCES enable.c - error.c - fullscreen.c - gamma.c - init.c - input.c - joystick.c - opengl.c - time.c - window.c) +set(common_SOURCES enable.c error.c fullscreen.c gamma.c init.c input.c + joystick.c opengl.c time.c window.c) if(_GLFW_COCOA_NSGL) set(libglfw_SOURCES ${common_SOURCES} cocoa_enable.m cocoa_fullscreen.m From 7268fc18b4b63f8f65fe294dfeaef0b931514233 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 27 Jul 2011 15:46:19 +0200 Subject: [PATCH 09/14] Don't clobber higher-level uninstall targets. --- CMakeLists.txt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0c2eeef..06acbef0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,11 +155,14 @@ install(FILES COPYING.txt readme.html #-------------------------------------------------------------------- # Uninstall operation +# Don't generate this target if a higher-level project already has #-------------------------------------------------------------------- -configure_file(${GLFW_SOURCE_DIR}/cmake_uninstall.cmake.in - ${GLFW_BINARY_DIR}/cmake_uninstall.cmake IMMEDIATE @ONLY) +if(NOT TARGET uninstall) + configure_file(${GLFW_SOURCE_DIR}/cmake_uninstall.cmake.in + ${GLFW_BINARY_DIR}/cmake_uninstall.cmake IMMEDIATE @ONLY) -add_custom_target(uninstall - ${CMAKE_COMMAND} -P - ${GLFW_BINARY_DIR}/cmake_uninstall.cmake) + add_custom_target(uninstall + ${CMAKE_COMMAND} -P + ${GLFW_BINARY_DIR}/cmake_uninstall.cmake) +endif() From c1ab73b97970a237222d5c6af684a8e10775e1e5 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 27 Jul 2011 16:01:27 +0200 Subject: [PATCH 10/14] Renamed context-related functions to more closely match underlying APIs. --- include/GL/glfw3.h | 6 +++--- readme.html | 6 +++--- src/cocoa_opengl.m | 15 ++++++++++++++- src/cocoa_window.m | 14 +------------- src/internal.h | 4 ++-- src/opengl.c | 42 ++++++++++++++++++++++++++++++++++++++++-- src/win32_opengl.c | 15 ++++++++++++++- src/win32_window.c | 17 ++--------------- src/window.c | 42 ++---------------------------------------- src/x11_opengl.c | 19 ++++++++++++++++++- src/x11_window.c | 17 ----------------- tests/sharing.c | 6 +++--- tests/windows.c | 2 +- 13 files changed, 103 insertions(+), 102 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index cba9e9b7..1836d134 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -537,9 +537,7 @@ GLFWAPI void glfwSetGammaRamp(const GLFWgammaramp* ramp); /* Window handling */ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode, const char* title, GLFWwindow share); GLFWAPI void glfwOpenWindowHint(int target, int hint); -GLFWAPI void glfwMakeWindowCurrent(GLFWwindow window); GLFWAPI int glfwIsWindow(GLFWwindow window); -GLFWAPI GLFWwindow glfwGetCurrentWindow(void); GLFWAPI void glfwCloseWindow(GLFWwindow window); GLFWAPI void glfwSetWindowTitle(GLFWwindow, const char* title); GLFWAPI void glfwGetWindowSize(GLFWwindow, int* width, int* height); @@ -583,11 +581,13 @@ GLFWAPI double glfwGetTime(void); GLFWAPI void glfwSetTime(double time); /* OpenGL support */ +GLFWAPI void glfwMakeContextCurrent(GLFWwindow window); +GLFWAPI GLFWwindow glfwGetCurrentContext(void); GLFWAPI void glfwSwapBuffers(void); GLFWAPI void glfwSwapInterval(int interval); GLFWAPI int glfwExtensionSupported(const char* extension); GLFWAPI void* glfwGetProcAddress(const char* procname); -GLFWAPI void glfwCopyGLState(GLFWwindow src, GLFWwindow dst, unsigned long mask); +GLFWAPI void glfwCopyContext(GLFWwindow src, GLFWwindow dst, unsigned long mask); /* Enable/disable functions */ GLFWAPI void glfwEnable(GLFWwindow window, int token); diff --git a/readme.html b/readme.html index d1d4b031..481444d0 100644 --- a/readme.html +++ b/readme.html @@ -263,7 +263,7 @@ version of GLFW.

    • Added GLFWwindow window handle type and updated window-related functions and callbacks to take a window handle
    • Added glfwIsWindow function for verifying that a given window handle is (still) valid
    • -
    • Added glfwMakeWindowCurrent function for making the context of the specified window current
    • +
    • Added glfwMakeContextCurrent function for making the context of the specified window current
    • Added glfwGetError and glfwErrorString error reporting functions and a number of error tokens
    • Added glfwSetErrorCallback function and GLFWerrorfun type for receiving more specific and/or nested errors
    • Added glfwSetWindowUserPointer and glfwGetWindowUserPointer functions for per-window user pointers
    • @@ -271,9 +271,9 @@ version of GLFW.

    • Added glfwGetWindowPos function for querying the position of the specified window
    • Added glfwSetWindowFocusCallback function and GLFWwindowfocusfun type for receiving window focus events
    • Added glfwSetWindowIconifyCallback function and GLFWwindowiconifyfun type for receiving window iconification events
    • -
    • Added glfwGetCurrentWindow function for retrieving the window whose OpenGL context is current
    • +
    • Added glfwGetCurrentContext function for retrieving the window whose OpenGL context is current
    • Added glfwInitWithModels function and GLFWallocator and GLFWthreadmodel types for pluggable memory allocation and threading models
    • -
    • Added glfwCopyGLState function for copying OpenGL state categories between contexts
    • +
    • Added glfwCopyContext function for copying OpenGL state categories between contexts
    • Added GLFW_OPENGL_ES2_PROFILE profile for creating OpenGL ES 2.0 contexts using the GLX_EXT_create_context_es2_profile and WGL_EXT_create_context_es2_profile extensions
    • Added GLFW_OPENGL_ROBUSTNESS window hint and associated strategy tokens for GL_ARB_robustness support
    • Added GLFW_OPENGL_REVISION window parameter to make up for removal of glfwGetGLVersion
    • diff --git a/src/cocoa_opengl.m b/src/cocoa_opengl.m index 6d93ed9f..bd3827fc 100644 --- a/src/cocoa_opengl.m +++ b/src/cocoa_opengl.m @@ -34,6 +34,19 @@ ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// +//======================================================================== +// Make the OpenGL context associated with the specified window current +//======================================================================== + +void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) +{ + if (window) + [window->NSGL.context makeCurrentContext]; + else + [NSOpenGLContext clearCurrentContext]; +} + + //======================================================================== // Swap buffers //======================================================================== @@ -90,7 +103,7 @@ void* _glfwPlatformGetProcAddress(const char* procname) // Copies the specified OpenGL state categories from src to dst //======================================================================== -void _glfwPlatformCopyGLState(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask) +void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask) { [dst->NSGL.context copyAttributesFromContext:src->NSGL.context withMask:mask]; } diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 283eae32..df2f708f 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -675,7 +675,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, withOptions:nil]; } - glfwMakeWindowCurrent(window); + glfwMakeContextCurrent(window); NSPoint point = [[NSCursor currentCursor] hotSpot]; window->mousePosX = point.x; @@ -686,18 +686,6 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, return GL_TRUE; } -//======================================================================== -// Make the OpenGL context associated with the specified window current -//======================================================================== - -void _glfwPlatformMakeWindowCurrent(_GLFWwindow* window) -{ - if (window) - [window->NSGL.context makeCurrentContext]; - else - [NSOpenGLContext clearCurrentContext]; -} - //======================================================================== // Properly kill the window / video display diff --git a/src/internal.h b/src/internal.h index 2c49aa2b..19bf299a 100644 --- a/src/internal.h +++ b/src/internal.h @@ -296,7 +296,6 @@ void _glfwPlatformSetTime(double time); // Window management int _glfwPlatformOpenWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWfbconfig* fbconfig); -void _glfwPlatformMakeWindowCurrent(_GLFWwindow* window); void _glfwPlatformCloseWindow(_GLFWwindow* window); void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title); void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height); @@ -312,12 +311,13 @@ void _glfwPlatformPollEvents(void); void _glfwPlatformWaitEvents(void); // OpenGL context management +void _glfwPlatformMakeContextCurrent(_GLFWwindow* window); void _glfwPlatformSwapBuffers(void); void _glfwPlatformSwapInterval(int interval); void _glfwPlatformRefreshWindowParams(void); int _glfwPlatformExtensionSupported(const char* extension); void* _glfwPlatformGetProcAddress(const char* procname); -void _glfwPlatformCopyGLState(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask); +void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask); //======================================================================== diff --git a/src/opengl.c b/src/opengl.c index 5e465f4a..9b39d0e7 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -423,6 +423,44 @@ int _glfwStringInExtensionString(const char* string, ////// GLFW public API ////// ////////////////////////////////////////////////////////////////////////// +//======================================================================== +// Make the OpenGL context associated with the specified window current +//======================================================================== + +GLFWAPI void glfwMakeContextCurrent(GLFWwindow handle) +{ + _GLFWwindow* window = (_GLFWwindow*) handle; + + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + + if (_glfwLibrary.currentWindow == window) + return; + + _glfwPlatformMakeContextCurrent(window); + _glfwLibrary.currentWindow = window; +} + + +//======================================================================== +// Returns the window whose OpenGL context is current +//======================================================================== + +GLFWAPI GLFWwindow glfwGetCurrentContext(void) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return GL_FALSE; + } + + return _glfwLibrary.currentWindow; +} + + //======================================================================== // Swap buffers (double-buffering) //======================================================================== @@ -560,7 +598,7 @@ GLFWAPI void* glfwGetProcAddress(const char* procname) // Copies the specified OpenGL state categories from src to dst //======================================================================== -GLFWAPI void glfwCopyGLState(GLFWwindow hsrc, GLFWwindow hdst, unsigned long mask) +GLFWAPI void glfwCopyContext(GLFWwindow hsrc, GLFWwindow hdst, unsigned long mask) { _GLFWwindow* src; _GLFWwindow* dst; @@ -580,6 +618,6 @@ GLFWAPI void glfwCopyGLState(GLFWwindow hsrc, GLFWwindow hdst, unsigned long mas return; } - _glfwPlatformCopyGLState(src, dst, mask); + _glfwPlatformCopyContext(src, dst, mask); } diff --git a/src/win32_opengl.c b/src/win32_opengl.c index d729fb51..e60d1e70 100644 --- a/src/win32_opengl.c +++ b/src/win32_opengl.c @@ -35,6 +35,19 @@ ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// +//======================================================================== +// Make the OpenGL context associated with the specified window current +//======================================================================== + +void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) +{ + if (window) + wglMakeCurrent(window->WGL.DC, window->WGL.context); + else + wglMakeCurrent(NULL, NULL); +} + + //======================================================================== // Swap buffers (double-buffering) //======================================================================== @@ -108,7 +121,7 @@ void* _glfwPlatformGetProcAddress(const char* procname) // Copies the specified OpenGL state categories from src to dst //======================================================================== -void _glfwPlatformCopyGLState(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask) +void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask) { if (!wglCopyContext(src->WGL.context, dst->WGL.context, mask)) _glfwSetError(GLFW_PLATFORM_ERROR, "Win32/WGL: Failed to copy OpenGL context attributes"); diff --git a/src/win32_window.c b/src/win32_window.c index 23633105..56b5908e 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1342,7 +1342,7 @@ static int createWindow(_GLFWwindow* window, if (!createContext(window, wndconfig, pixelFormat)) return GL_FALSE; - glfwMakeWindowCurrent(window); + glfwMakeContextCurrent(window); initWGLExtensions(window); @@ -1365,7 +1365,7 @@ static void destroyWindow(_GLFWwindow* window) // This is duplicated from glfwCloseWindow // TODO: Stop duplicating code if (window == _glfwLibrary.currentWindow) - glfwMakeWindowCurrent(NULL); + glfwMakeContextCurrent(NULL); // This is duplicated from glfwCloseWindow // TODO: Stop duplicating code @@ -1521,19 +1521,6 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, } -//======================================================================== -// Make the OpenGL context associated with the specified window current -//======================================================================== - -void _glfwPlatformMakeWindowCurrent(_GLFWwindow* window) -{ - if (window) - wglMakeCurrent(window->WGL.DC, window->WGL.context); - else - wglMakeCurrent(NULL, NULL); -} - - //======================================================================== // Properly kill the window / video display //======================================================================== diff --git a/src/window.c b/src/window.c index 156460d0..9c985b13 100644 --- a/src/window.c +++ b/src/window.c @@ -336,7 +336,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, } // Cache the actual (as opposed to desired) window parameters - glfwMakeWindowCurrent(window); + glfwMakeContextCurrent(window); _glfwPlatformRefreshWindowParams(); if (!_glfwIsValidContext(window, &wndconfig)) @@ -359,28 +359,6 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, } -//======================================================================== -// Make the OpenGL context associated with the specified window current -//======================================================================== - -GLFWAPI void glfwMakeWindowCurrent(GLFWwindow handle) -{ - _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwSetError(GLFW_NOT_INITIALIZED, NULL); - return; - } - - if (_glfwLibrary.currentWindow == window) - return; - - _glfwPlatformMakeWindowCurrent(window); - _glfwLibrary.currentWindow = window; -} - - //======================================================================== // Returns GL_TRUE if the specified window handle is an actual window //======================================================================== @@ -409,22 +387,6 @@ GLFWAPI int glfwIsWindow(GLFWwindow handle) } -//======================================================================== -// Returns GL_TRUE if the specified window handle is an actual window -//======================================================================== - -GLFWAPI GLFWwindow glfwGetCurrentWindow(void) -{ - if (!_glfwInitialized) - { - _glfwSetError(GLFW_NOT_INITIALIZED, NULL); - return GL_FALSE; - } - - return _glfwLibrary.currentWindow; -} - - //======================================================================== // Set hints for opening the window //======================================================================== @@ -532,7 +494,7 @@ GLFWAPI void glfwCloseWindow(GLFWwindow handle) // Clear the current context if this window's context is current if (window == _glfwLibrary.currentWindow) - glfwMakeWindowCurrent(NULL); + glfwMakeContextCurrent(NULL); // Clear the active window pointer if this is the active window if (window == _glfwLibrary.activeWindow) diff --git a/src/x11_opengl.c b/src/x11_opengl.c index 0442209b..a261d616 100644 --- a/src/x11_opengl.c +++ b/src/x11_opengl.c @@ -56,6 +56,23 @@ void (*glXGetProcAddressEXT(const GLubyte* procName))(); ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// +//======================================================================== +// Make the OpenGL context associated with the specified window current +//======================================================================== + +void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) +{ + if (window) + { + glXMakeCurrent(_glfwLibrary.X11.display, + window->X11.handle, + window->GLX.context); + } + else + glXMakeCurrent(_glfwLibrary.X11.display, None, NULL); +} + + //======================================================================== // Swap OpenGL buffers //======================================================================== @@ -121,7 +138,7 @@ void* _glfwPlatformGetProcAddress(const char* procname) // Copies the specified OpenGL state categories from src to dst //======================================================================== -void _glfwPlatformCopyGLState(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask) +void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask) { glXCopyContext(_glfwLibrary.X11.display, src->GLX.context, diff --git a/src/x11_window.c b/src/x11_window.c index e3e291ff..5a54f389 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1448,23 +1448,6 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, } -//======================================================================== -// Make the OpenGL context associated with the specified window current -//======================================================================== - -void _glfwPlatformMakeWindowCurrent(_GLFWwindow* window) -{ - if (window) - { - glXMakeCurrent(_glfwLibrary.X11.display, - window->X11.handle, - window->GLX.context); - } - else - glXMakeCurrent(_glfwLibrary.X11.display, None, NULL); -} - - //======================================================================== // Properly kill the window/video display //======================================================================== diff --git a/tests/sharing.c b/tests/sharing.c index 16e6eaf4..942ec2c6 100644 --- a/tests/sharing.c +++ b/tests/sharing.c @@ -80,7 +80,7 @@ static GLuint create_texture(void) static void draw_quad(GLuint texture) { int width, height; - glfwGetWindowSize(glfwGetCurrentWindow(), &width, &height); + glfwGetWindowSize(glfwGetCurrentContext(), &width, &height); glViewport(0, 0, width, height); @@ -148,11 +148,11 @@ int main(int argc, char** argv) while (glfwIsWindow(windows[0]) && glfwIsWindow(windows[1])) { - glfwMakeWindowCurrent(windows[0]); + glfwMakeContextCurrent(windows[0]); draw_quad(texture); glfwSwapBuffers(); - glfwMakeWindowCurrent(windows[1]); + glfwMakeContextCurrent(windows[1]); draw_quad(texture); glfwSwapBuffers(); diff --git a/tests/windows.c b/tests/windows.c index 13c76cbe..b84c9262 100644 --- a/tests/windows.c +++ b/tests/windows.c @@ -73,7 +73,7 @@ int main(void) { for (i = 0; i < 4; i++) { - glfwMakeWindowCurrent(windows[i]); + glfwMakeContextCurrent(windows[i]); glClear(GL_COLOR_BUFFER_BIT); glfwSwapBuffers(); } From 4afc67c1df77161825a4a050bcec787b057fd9c6 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 27 Jul 2011 17:09:17 +0200 Subject: [PATCH 11/14] Various Windows and VC++ 2010 fixes. --- examples/getopt.c | 6 ++++++ examples/heightmap.c | 4 +++- include/GL/glfw3.h | 30 +++++++++++++++++++++++++++--- src/gamma.c | 2 +- src/win32_platform.h | 7 +++++-- src/win32_window.c | 5 +++-- tests/events.c | 2 ++ tests/getopt.c | 7 ++++++- tests/windows.c | 2 +- 9 files changed, 54 insertions(+), 11 deletions(-) mode change 100644 => 100755 include/GL/glfw3.h diff --git a/examples/getopt.c b/examples/getopt.c index b891b0a5..9d79b9a7 100644 --- a/examples/getopt.c +++ b/examples/getopt.c @@ -34,12 +34,18 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */ +#define _CRT_SECURE_NO_WARNINGS + #include #include #include #include "getopt.h" +/* 2011-07-27 Camilla Berglund + * + * Added _CRT_SECURE_NO_WARNINGS macro. + */ /* 2009-10-12 Camilla Berglund * * Removed unused global static variable 'ID'. diff --git a/examples/heightmap.c b/examples/heightmap.c index f37c732f..1d3dd72e 100644 --- a/examples/heightmap.c +++ b/examples/heightmap.c @@ -23,6 +23,8 @@ // //======================================================================== +#define _CRT_SECURE_NO_WARNINGS + #include #include #include @@ -422,7 +424,7 @@ static void update_map(int num_iter) if (fabs(pd) <= 1.0f) { /* tx,tz is within the circle */ - GLfloat new_height = disp + (cos(pd*3.14f)*disp); + GLfloat new_height = disp + (float) (cos(pd*3.14f)*disp); map_vertices[1][ii] += new_height; } } diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h old mode 100644 new mode 100755 index 1836d134..ab9629f1 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -75,7 +75,7 @@ extern "C" { #else #define APIENTRY #endif - #define GL_APIENTRY_DEFINED + #define GLFW_APIENTRY_DEFINED #endif /* APIENTRY */ @@ -96,7 +96,7 @@ extern "C" { /* Others (e.g. MinGW, Cygwin) */ #define WINGDIAPI extern #endif - #define GL_WINGDIAPI_DEFINED + #define GLFW_WINGDIAPI_DEFINED #endif /* WINGDIAPI */ /* Some files also need CALLBACK defined */ @@ -112,7 +112,7 @@ extern "C" { /* Other Windows compilers */ #define CALLBACK __stdcall #endif - #define GLU_CALLBACK_DEFINED + #define GLFW_CALLBACK_DEFINED #endif /* CALLBACK */ /* Microsoft Visual C++, Borland C++ and Pelles C needs wchar_t */ @@ -594,6 +594,30 @@ GLFWAPI void glfwEnable(GLFWwindow window, int token); GLFWAPI void glfwDisable(GLFWwindow window, int token); +/************************************************************************* + * Global definition cleanup + *************************************************************************/ + +/* ------------------- BEGIN SYSTEM/COMPILER SPECIFIC -------------------- */ + +#ifdef GLFW_APIENTRY_DEFINED + #undef APIENTRY + #undef GLFW_APIENTRY_DEFINED +#endif + +#ifdef GLFW_WINGDIAPI_DEFINED + #undef WINGDIAPI + #undef GLFW_WINGDIAPI_DEFINED +#endif + +#ifdef GLFW_CALLBACK_DEFINED + #undef CALLBACK + #undef GLFW_CALLBACK_DEFINED +#endif + +/* -------------------- END SYSTEM/COMPILER SPECIFIC --------------------- */ + + #ifdef __cplusplus } #endif diff --git a/src/gamma.c b/src/gamma.c index 83847e10..d0c45d01 100644 --- a/src/gamma.c +++ b/src/gamma.c @@ -57,7 +57,7 @@ GLFWAPI void glfwSetGammaFormula(float gamma, float blacklevel, float gain) float value = (float) i / ((float) (size - 1)); // Apply gamma - value = pow(value, 1.f / gamma) * 65535.f + 0.5f; + value = (float) pow(value, 1.f / gamma) * 65535.f + 0.5f; // Apply gain value = gain * (value - 32767.5f) + 32767.5f; diff --git a/src/win32_platform.h b/src/win32_platform.h index d6a5787d..2ff73116 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -34,13 +34,16 @@ // We don't need all the fancy stuff #define NOMINMAX -#define WIN32_LEAN_AND_MEAN #define VC_EXTRALEAN +#ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN +#endif + #include #include -#include "../../include/GL/wglext.h" +#include "../include/GL/wglext.h" //======================================================================== diff --git a/src/win32_window.c b/src/win32_window.c index 56b5908e..8e72c417 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1556,7 +1556,8 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) { - int bpp, newMode = 0, refresh; + //int bpp, refresh; + int newMode = 0; GLboolean sizeChanged = GL_FALSE; if (window->mode == GLFW_FULLSCREEN) @@ -1647,7 +1648,7 @@ void _glfwPlatformRefreshWindowParams(void) { PIXELFORMATDESCRIPTOR pfd; DEVMODE dm; - int pixelFormat, mode; + int pixelFormat; _GLFWwindow* window = _glfwLibrary.currentWindow; diff --git a/tests/events.c b/tests/events.c index ca114e33..6ae6718a 100644 --- a/tests/events.c +++ b/tests/events.c @@ -31,6 +31,8 @@ // //======================================================================== +#define _CRT_SECURE_NO_WARNINGS + #include #include diff --git a/tests/getopt.c b/tests/getopt.c index b891b0a5..712cf28a 100644 --- a/tests/getopt.c +++ b/tests/getopt.c @@ -34,18 +34,23 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */ +#define _CRT_SECURE_NO_WARNINGS + #include #include #include #include "getopt.h" +/* 2011-07-27 Camilla Berglund + * + * Added _CRT_SECURE_NO_WARNINGS macro. + */ /* 2009-10-12 Camilla Berglund * * Removed unused global static variable 'ID'. */ - char* optarg = NULL; int optind = 0; int opterr = 1; diff --git a/tests/windows.c b/tests/windows.c index b84c9262..ddb8a224 100644 --- a/tests/windows.c +++ b/tests/windows.c @@ -66,7 +66,7 @@ int main(void) glfwSetWindowPos(windows[i], 100 + (i & 1) * 300, 100 + (i >> 1) * 300); - glClearColor(i & 1, i >> 1, 0.0, 0.0); + glClearColor((GLclampf) (i & 1), (GLclampf) (i >> 1), 0.0, 0.0); } while (running) From e4027f14d0d00c34bf36a0775d12b69f94cc3fc6 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 27 Jul 2011 17:48:56 +0200 Subject: [PATCH 12/14] Rough line-wrapping pass. --- src/fullscreen.c | 3 ++- src/input.c | 6 ++++-- src/opengl.c | 42 +++++++++++++++++++++++++++++------------- src/win32_fullscreen.c | 5 ++++- src/win32_opengl.c | 5 ++++- src/window.c | 10 +++++++--- src/x11_init.c | 16 +++++++++++----- 7 files changed, 61 insertions(+), 26 deletions(-) diff --git a/src/fullscreen.c b/src/fullscreen.c index 7a5c97da..7cc96bb7 100644 --- a/src/fullscreen.c +++ b/src/fullscreen.c @@ -138,7 +138,8 @@ GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode) if (mode == NULL) { - _glfwSetError(GLFW_INVALID_VALUE, "glfwGetDesktopMode: Parameter 'mode' cannot be NULL"); + _glfwSetError(GLFW_INVALID_VALUE, + "glfwGetDesktopMode: Parameter 'mode' cannot be NULL"); return; } diff --git a/src/input.c b/src/input.c index 3e0c1c5c..0f5cfaa3 100644 --- a/src/input.c +++ b/src/input.c @@ -53,7 +53,8 @@ GLFWAPI int glfwGetKey(GLFWwindow handle, int key) if (key < 0 || key > GLFW_KEY_LAST) { // TODO: Decide whether key is a value or enum - _glfwSetError(GLFW_INVALID_VALUE, "glfwGetKey: The specified key is invalid"); + _glfwSetError(GLFW_INVALID_VALUE, + "glfwGetKey: The specified key is invalid"); return GLFW_RELEASE; } @@ -85,7 +86,8 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow handle, int button) // Is it a valid mouse button? if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST) { - _glfwSetError(GLFW_INVALID_ENUM, "glfwGetMouseButton: The specified mouse button is invalid"); + _glfwSetError(GLFW_INVALID_ENUM, + "glfwGetMouseButton: The specified mouse button is invalid"); return GLFW_RELEASE; } diff --git a/src/opengl.c b/src/opengl.c index 9b39d0e7..7b97d6e3 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -255,25 +255,29 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig) if (wndconfig->glMajor < 1 || wndconfig->glMinor < 0) { // OpenGL 1.0 is the smallest valid version - _glfwSetError(GLFW_INVALID_VALUE, "glfwOpenWindow: Invalid OpenGL version requested"); + _glfwSetError(GLFW_INVALID_VALUE, + "glfwOpenWindow: Invalid OpenGL version requested"); return GL_FALSE; } if (wndconfig->glMajor == 1 && wndconfig->glMinor > 5) { // OpenGL 1.x series ended with version 1.5 - _glfwSetError(GLFW_INVALID_VALUE, "glfwOpenWindow: Invalid OpenGL version requested"); + _glfwSetError(GLFW_INVALID_VALUE, + "glfwOpenWindow: Invalid OpenGL version requested"); return GL_FALSE; } else if (wndconfig->glMajor == 2 && wndconfig->glMinor > 1) { // OpenGL 2.x series ended with version 2.1 - _glfwSetError(GLFW_INVALID_VALUE, "glfwOpenWindow: Invalid OpenGL version requested"); + _glfwSetError(GLFW_INVALID_VALUE, + "glfwOpenWindow: Invalid OpenGL version requested"); return GL_FALSE; } else if (wndconfig->glMajor == 3 && wndconfig->glMinor > 3) { // OpenGL 3.x series ended with version 3.3 - _glfwSetError(GLFW_INVALID_VALUE, "glfwOpenWindow: Invalid OpenGL version requested"); + _glfwSetError(GLFW_INVALID_VALUE, + "glfwOpenWindow: Invalid OpenGL version requested"); return GL_FALSE; } else @@ -290,7 +294,8 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig) // compatibility with future updates to OpenGL ES, we allow // everything 2.x and let the driver report invalid 2.x versions - _glfwSetError(GLFW_INVALID_VALUE, "glfwOpenWindow: Invalid OpenGL ES 2.x version requested"); + _glfwSetError(GLFW_INVALID_VALUE, + "glfwOpenWindow: Invalid OpenGL ES 2.x version requested"); return GL_FALSE; } } @@ -299,16 +304,20 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig) if (wndconfig->glProfile != GLFW_OPENGL_CORE_PROFILE && wndconfig->glProfile != GLFW_OPENGL_COMPAT_PROFILE) { - _glfwSetError(GLFW_INVALID_ENUM, "glfwOpenWindow: Invalid OpenGL profile requested"); + _glfwSetError(GLFW_INVALID_ENUM, + "glfwOpenWindow: Invalid OpenGL profile requested"); return GL_FALSE; } - if (wndconfig->glMajor < 3 || (wndconfig->glMajor == 3 && wndconfig->glMinor < 2)) + if (wndconfig->glMajor < 3 || + (wndconfig->glMajor == 3 && wndconfig->glMinor < 2)) { // Desktop OpenGL context profiles are only defined for version 3.2 // and above - _glfwSetError(GLFW_INVALID_VALUE, "glfwOpenWindow: Context profiles only exist for OpenGL version 3.2 and above"); + _glfwSetError(GLFW_INVALID_VALUE, + "glfwOpenWindow: Context profiles only exist for " + "OpenGL version 3.2 and above"); return GL_FALSE; } } @@ -316,7 +325,9 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig) if (wndconfig->glForward && wndconfig->glMajor < 3) { // Forward-compatible contexts are only defined for OpenGL version 3.0 and above - _glfwSetError(GLFW_INVALID_VALUE, "glfwOpenWindow: Forward compatibility only exist for OpenGL version 3.0 and above"); + _glfwSetError(GLFW_INVALID_VALUE, + "glfwOpenWindow: Forward compatibility only exist for " + "OpenGL version 3.0 and above"); return GL_FALSE; } @@ -325,7 +336,8 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig) if (wndconfig->glRobustness != GLFW_OPENGL_NO_RESET_NOTIFICATION && wndconfig->glRobustness != GLFW_OPENGL_LOSE_CONTEXT_ON_RESET) { - _glfwSetError(GLFW_INVALID_VALUE, "glfwOpenWindow: Invalid OpenGL robustness mode requested"); + _glfwSetError(GLFW_INVALID_VALUE, + "glfwOpenWindow: Invalid OpenGL robustness mode requested"); return GL_FALSE; } } @@ -358,7 +370,8 @@ GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig) // For API consistency, we emulate the behavior of the // {GLX|WGL}_ARB_create_context extension and fail here - _glfwSetError(GLFW_VERSION_UNAVAILABLE, "glfwOpenWindow: The requested OpenGL version is not available"); + _glfwSetError(GLFW_VERSION_UNAVAILABLE, + "glfwOpenWindow: The requested OpenGL version is not available"); return GL_FALSE; } @@ -375,7 +388,9 @@ GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig) // on X11/GLX using custom build systems, as it needs explicit // configuration in order to work - _glfwSetError(GLFW_PLATFORM_ERROR, "glfwOpenWindow: Entry point retrieval is broken; see the build documentation for your platform"); + _glfwSetError(GLFW_PLATFORM_ERROR, + "glfwOpenWindow: Entry point retrieval is broken; see " + "the build documentation for your platform"); return GL_FALSE; } } @@ -614,7 +629,8 @@ GLFWAPI void glfwCopyContext(GLFWwindow hsrc, GLFWwindow hdst, unsigned long mas if (_glfwLibrary.currentWindow == dst) { - _glfwSetError(GLFW_INVALID_VALUE, "Cannot copy OpenGL state to a current context"); + _glfwSetError(GLFW_INVALID_VALUE, + "Cannot copy OpenGL state to a current context"); return; } diff --git a/src/win32_fullscreen.c b/src/win32_fullscreen.c index 24db644f..de3d898b 100644 --- a/src/win32_fullscreen.c +++ b/src/win32_fullscreen.c @@ -265,6 +265,9 @@ void _glfwPlatformGetDesktopMode(GLFWvidmode* mode) // Return desktop mode parameters mode->width = dm.dmPelsWidth; mode->height = dm.dmPelsHeight; - _glfwSplitBPP(dm.dmBitsPerPel, &mode->redBits, &mode->greenBits, &mode->blueBits); + _glfwSplitBPP(dm.dmBitsPerPel, + &mode->redBits, + &mode->greenBits, + &mode->blueBits); } diff --git a/src/win32_opengl.c b/src/win32_opengl.c index e60d1e70..1a7faa05 100644 --- a/src/win32_opengl.c +++ b/src/win32_opengl.c @@ -124,6 +124,9 @@ void* _glfwPlatformGetProcAddress(const char* procname) void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask) { if (!wglCopyContext(src->WGL.context, dst->WGL.context, mask)) - _glfwSetError(GLFW_PLATFORM_ERROR, "Win32/WGL: Failed to copy OpenGL context attributes"); + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "Win32/WGL: Failed to copy OpenGL context attributes"); + } } diff --git a/src/window.c b/src/window.c index 9c985b13..82d84b87 100644 --- a/src/window.c +++ b/src/window.c @@ -289,7 +289,8 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, if (mode != GLFW_WINDOWED && mode != GLFW_FULLSCREEN) { - _glfwSetError(GLFW_INVALID_ENUM, "glfwOpenWindow: Invalid enum for 'mode' parameter"); + _glfwSetError(GLFW_INVALID_ENUM, + "glfwOpenWindow: Invalid enum for 'mode' parameter"); return GL_FALSE; } @@ -314,7 +315,8 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, window = (_GLFWwindow*) _glfwMalloc(sizeof(_GLFWwindow)); if (!window) { - _glfwSetError(GLFW_OUT_OF_MEMORY, "glfwOpenWindow: Failed to allocate window structure"); + _glfwSetError(GLFW_OUT_OF_MEMORY, + "glfwOpenWindow: Failed to allocate window structure"); return NULL; } @@ -750,7 +752,9 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param) case GLFW_OPENGL_ROBUSTNESS: return window->glRobustness; default: - _glfwSetError(GLFW_INVALID_ENUM, "glfwGetWindowParam: Invalid enum value for 'param' parameter"); + _glfwSetError(GLFW_INVALID_ENUM, + "glfwGetWindowParam: Invalid enum value for 'param' " + "parameter"); return 0; } } diff --git a/src/x11_init.c b/src/x11_init.c index c2480ada..03cc617f 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -401,7 +401,8 @@ static GLboolean initDisplay(void) &_glfwLibrary.X11.RandR.majorVersion, &_glfwLibrary.X11.RandR.minorVersion)) { - _glfwSetError(GLFW_PLATFORM_ERROR, "X11/GLX: Failed to query RandR version"); + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/GLX: Failed to query RandR version"); return GL_FALSE; } } @@ -420,7 +421,8 @@ static GLboolean initDisplay(void) &_glfwLibrary.X11.glxMajor, &_glfwLibrary.X11.glxMinor)) { - _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: Failed to query GLX version"); + _glfwSetError(GLFW_OPENGL_UNAVAILABLE, + "X11/GLX: Failed to query GLX version"); return GL_FALSE; } @@ -475,7 +477,8 @@ static void initGammaRamp(void) // This is probably Nvidia RandR with broken gamma support // Flag it as useless and try Xf86VidMode below, if available _glfwLibrary.X11.RandR.gammaBroken = GL_TRUE; - fprintf(stderr, "Ignoring broken nVidia implementation of RandR 1.2+ gamma\n"); + fprintf(stderr, + "Ignoring broken nVidia implementation of RandR 1.2+ gamma\n"); } XRRFreeScreenResources(rr); @@ -515,14 +518,17 @@ static Cursor createNULLCursor(void) // TODO: Add error checks - cursormask = XCreatePixmap(_glfwLibrary.X11.display, _glfwLibrary.X11.root, 1, 1, 1); + cursormask = XCreatePixmap(_glfwLibrary.X11.display, + _glfwLibrary.X11.root, + 1, 1, 1); xgc.function = GXclear; gc = XCreateGC(_glfwLibrary.X11.display, cursormask, GCFunction, &xgc); XFillRectangle(_glfwLibrary.X11.display, cursormask, gc, 0, 0, 1, 1); col.pixel = 0; col.red = 0; col.flags = 4; - cursor = XCreatePixmapCursor(_glfwLibrary.X11.display, cursormask, cursormask, + cursor = XCreatePixmapCursor(_glfwLibrary.X11.display, + cursormask, cursormask, &col, &col, 0, 0); XFreePixmap(_glfwLibrary.X11.display, cursormask); XFreeGC(_glfwLibrary.X11.display, gc); From c233e005a82e78e4e746c47f143847f77e20dd96 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 27 Jul 2011 18:20:15 +0200 Subject: [PATCH 13/14] Copied context property readback from 2.7.1. --- src/opengl.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/opengl.c b/src/opengl.c index 7b97d6e3..6d6f24fb 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -354,9 +354,36 @@ GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig) { parseGLVersion(&window->glMajor, &window->glMinor, &window->glRevision); - // As these are hard constraints when non-zero, we can simply copy them - window->glProfile = wndconfig->glProfile; - window->glForward = wndconfig->glForward; + // Read back forward-compatibility flag + { + window->glForward = GL_FALSE; + + if (window->glMajor >= 3) + { + GLint flags; + glGetIntegerv(GL_CONTEXT_FLAGS, &flags); + + if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) + window->glForward = GL_TRUE; + } + } + + // Read back OpenGL context profile + { + window->glProfile = 0; + + if (window->glMajor > 3 || (window->glMajor == 3 && window->glMinor >= 2)) + { + GLint mask; + glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); + + if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) + window->glProfile = GLFW_OPENGL_COMPAT_PROFILE; + else if (mask & GL_CONTEXT_CORE_PROFILE_BIT) + window->glProfile = GLFW_OPENGL_CORE_PROFILE; + } + } + window->glRobustness = wndconfig->glRobustness; if (window->glMajor < wndconfig->glMajor || From cfb9394c735cea3082f31b7ac8a421405b6843ba Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 27 Jul 2011 18:24:27 +0200 Subject: [PATCH 14/14] Copied OS X Lion GL3 support from 2.7.2. --- readme.html | 1 + src/cocoa_window.m | 43 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/readme.html b/readme.html index 481444d0..96a892a2 100644 --- a/readme.html +++ b/readme.html @@ -303,6 +303,7 @@ version of GLFW.

    • Bugfix: The default OpenGL version in the version test was set to 1.1
    • Bugfix: The OpenGL profile and forward-compatibility window parameters were not saved after context creation
    • Bugfix: The FSAA test did not check for the availability of GL_ARB_multisample
    • +
    • [Cocoa] Added support for OpenGL 3.2 core profile in 10.7 Lion and above
    • [Cocoa] Bugfix: The loop condition for saving video modes used the wrong index variable
    • [X11] Added support for the GLX_EXT_swap_control extension as an alternative to GLX_SGI_swap_control
    • [X11] Bugfix: Calling glXCreateContextAttribsARB with an unavailable OpenGL version caused the application to terminate with a BadMatch Xlib error
    • diff --git a/src/cocoa_window.m b/src/cocoa_window.m index df2f708f..c0832805 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -476,15 +476,38 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, const _GLFWwndconfig *wndconfig, const _GLFWfbconfig *fbconfig) { - // Fail if OpenGL 3.0 or above was requested - if (wndconfig->glMajor > 2) +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 + // Fail if OpenGL 3.3 or above was requested + if( wndconfig->glMajor > 3 || wndconfig->glMajor == 3 && wndconfig->glMinor > 2 ) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "Cocoa/NSOpenGL: Mac OS X does not support OpenGL " - "version 3.0 or above"); + "Cocoa/NSOpenGL: The targeted version of Mac OS X does " + "not support OpenGL version 3.3 or above"); return GL_FALSE; } + if( wndconfig->glProfile ) + { + // Fail if a profile other than core was explicitly selected + if( wndconfig->glProfile != GLFW_OPENGL_CORE_PROFILE ) + { + _glfwSetError(GLFW_VERSION_UNAVAILABLE, + "Cocoa/NSOpenGL: The targeted version of Mac OS X " + "only supports the OpenGL core profile"); + return GL_FALSE; + } + } +#else + // Fail if OpenGL 3.0 or above was requested + 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"); + return GL_FALSE; + } +#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/ + // Fail if a robustness strategy was requested if (wndconfig->glRobustness) { @@ -591,7 +614,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, unsigned int attribute_count = 0; -#define ADD_ATTR(x) attributes[attribute_count++] = x +#define ADD_ATTR(x) { attributes[attribute_count++] = x; } #define ADD_ATTR2(x, y) { ADD_ATTR(x); ADD_ATTR(y); } // Arbitrary array size here @@ -607,6 +630,11 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID())); } +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 + if( wndconfig->glMajor > 2 ) + ADD_ATTR2( NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core ); +#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/ + ADD_ATTR2(NSOpenGLPFAColorSize, colorBits); if (fbconfig->alphaBits > 0) @@ -847,10 +875,9 @@ void _glfwPlatformRefreshWindowParams(void) forVirtualScreen:0]; window->samples = value; - // These are forced to false as long as Mac OS X lacks support for OpenGL 3.0+ - window->glForward = GL_FALSE; + // These this is forced to false as long as Mac OS X lacks support for + // requesting debug contexts window->glDebug = GL_FALSE; - window->glProfile = 0; } //========================================================================