From 9a20dc2a70bead52a158e1a27508b22c292b5521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Apr 2016 11:05:42 +0200 Subject: [PATCH] Platform: backport GlfwApplication to GLFW 3.1. So one can use it without compiling latest master. --- src/Magnum/Platform/GlfwApplication.cpp | 13 ++++++++++--- src/Magnum/Platform/GlfwApplication.h | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index 48dcc7890..5ad36466d 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -35,6 +35,11 @@ namespace Magnum { namespace Platform { GlfwApplication* GlfwApplication::_instance = nullptr; +#ifdef GLFW_TRUE +/* The docs say that it's the same, verify that just in case */ +static_assert(GLFW_TRUE == true && GLFW_FALSE == false, "GLFW does not have sane bool values"); +#endif + #ifndef DOXYGEN_GENERATING_OUTPUT GlfwApplication::GlfwApplication(const Arguments& arguments): GlfwApplication{arguments, Configuration{}} {} #endif @@ -68,8 +73,6 @@ void GlfwApplication::createContext(const Configuration& configuration) { bool GlfwApplication::tryCreateContext(const Configuration& configuration) { CORRADE_ASSERT(_context->version() == Version::None, "Platform::GlfwApplication::tryCreateContext(): context already created", false); - static_assert(GLFW_TRUE == true && GLFW_FALSE == false, "GLFW does not have sane bool values."); - /* Window flags */ GLFWmonitor* monitor = nullptr; /* Needed for setting fullscreen */ if (configuration.windowFlags() >= Configuration::WindowFlag::Fullscreen) { @@ -79,7 +82,9 @@ bool GlfwApplication::tryCreateContext(const Configuration& configuration) { const Configuration::WindowFlags& flags = configuration.windowFlags(); glfwWindowHint(GLFW_RESIZABLE, flags >= Configuration::WindowFlag::Resizeable); glfwWindowHint(GLFW_VISIBLE, !(flags >= Configuration::WindowFlag::Hidden)); + #ifdef GLFW_MAXIMIZED glfwWindowHint(GLFW_MAXIMIZED, flags >= Configuration::WindowFlag::Maximized); + #endif glfwWindowHint(GLFW_ICONIFIED, flags >= Configuration::WindowFlag::Minimized); glfwWindowHint(GLFW_FLOATING, flags >= Configuration::WindowFlag::Floating); } @@ -90,7 +95,9 @@ bool GlfwApplication::tryCreateContext(const Configuration& configuration) { glfwWindowHint(GLFW_SRGB_CAPABLE, configuration.isSRGBCapable()); const Configuration::Flags& flags = configuration.flags(); + #ifdef GLFW_CONTEXT_NO_ERROR glfwWindowHint(GLFW_CONTEXT_NO_ERROR, flags >= Configuration::Flag::NoError); + #endif glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, flags >= Configuration::Flag::Debug); glfwWindowHint(GLFW_STEREO, flags >= Configuration::Flag::Stereo); @@ -105,7 +112,7 @@ bool GlfwApplication::tryCreateContext(const Configuration& configuration) { glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor); #ifndef MAGNUM_TARGET_GLES if(configuration.version() >= Version::GL310) { - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); } #else diff --git a/src/Magnum/Platform/GlfwApplication.h b/src/Magnum/Platform/GlfwApplication.h index 17e882e8d..6974b3038 100644 --- a/src/Magnum/Platform/GlfwApplication.h +++ b/src/Magnum/Platform/GlfwApplication.h @@ -144,7 +144,7 @@ class GlfwApplication { /** @brief Exit application main loop */ void exit() { - glfwSetWindowShouldClose(_window, GLFW_TRUE); + glfwSetWindowShouldClose(_window, true); } protected: @@ -286,12 +286,17 @@ class GlfwApplication::Configuration { * @see @ref Flags, @ref setFlags() */ enum class Flag: Int { + #ifdef GLFW_CONTEXT_NO_ERROR /** * Specifies whether errors should be generated by the context. * If enabled, situations that would have generated errors instead * cause undefined behavior. + * + * @note Supported since GLFW 3.2. */ NoError = GLFW_CONTEXT_NO_ERROR, + #endif + Debug = GLFW_OPENGL_DEBUG_CONTEXT, /**< Debug context */ Stereo = GLFW_STEREO, /**< Stereo rendering */ }; @@ -312,7 +317,16 @@ class GlfwApplication::Configuration { Fullscreen = 1 << 0, /**< Fullscreen window */ Resizeable = 1 << 1, /**< Resizeable window */ Hidden = 1 << 2, /**< Hidden window */ - Maximized = 1 << 3, /**< Maximized window */ + + #ifdef GLFW_MAXIMIZED + /** + * Maximized window + * + * @note Supported since GLFW 3.2. + */ + Maximized = 1 << 3, + #endif + Minimized = 1 << 4, /**< Minimized window */ Floating = 1 << 5, /**< Window floating above others, top-most */ AutoIconify = 1 << 6, /**< Automatically iconify (minimize) if fullscreen window loses input focus */