From 100990cb0e2743df698e59b1b51a45812be5e2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 16 Sep 2013 19:30:17 +0200 Subject: [PATCH] Move extension loading into Magnum::Context. Resolves some linker errors in Windows, removes code bloat from Platform namespace (previously it was copied in _every_ *Application). Originally this was in Platform namespace because I thought that it would be possible to have one version of Magnum library for both desktop and ES and the actual Application would determine which GL edition will be used. Fun idea, but it would remove the static checks (e.g. accidentaly using geometry shaders on ES), which isn't worth it. --- src/Context.cpp | 11 ++++++ src/Platform/AbstractXApplication.cpp | 4 -- src/Platform/CMakeLists.txt | 32 ++++----------- src/Platform/ExtensionWrangler.cpp | 48 ----------------------- src/Platform/ExtensionWrangler.h | 44 --------------------- src/Platform/GlutApplication.cpp | 3 -- src/Platform/Sdl2Application.cpp | 3 -- src/Platform/WindowlessGlxApplication.cpp | 4 -- 8 files changed, 19 insertions(+), 130 deletions(-) delete mode 100644 src/Platform/ExtensionWrangler.cpp delete mode 100644 src/Platform/ExtensionWrangler.h diff --git a/src/Context.cpp b/src/Context.cpp index ec0273f9a..727d057fa 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -298,6 +298,17 @@ const std::vector& Extension::extensions(Version version) { Context* Context::_current = nullptr; Context::Context() { + #ifndef MAGNUM_TARGET_GLES + /* Init glLoadGen. Ignore functions that failed to load (described by + `ogl_LOAD_SUCCEEDED + n` return code), as we requested the latest OpenGL + with many vendor extensions and there won't ever be a driver supporting + everything possible. */ + if(ogl_LoadFunctions() == ogl_LOAD_FAILED) { + Error() << "ExtensionWrangler: cannot initialize glLoadGen"; + std::exit(1); + } + #endif + /* Version */ #ifndef MAGNUM_TARGET_GLES2 glGetIntegerv(GL_MAJOR_VERSION, &_majorVersion); diff --git a/src/Platform/AbstractXApplication.cpp b/src/Platform/AbstractXApplication.cpp index 6b4824c5a..5b7b8bc35 100644 --- a/src/Platform/AbstractXApplication.cpp +++ b/src/Platform/AbstractXApplication.cpp @@ -27,7 +27,6 @@ #include #include "Context.h" -#include "ExtensionWrangler.h" #define None 0L // redef Xlib nonsense @@ -96,9 +95,6 @@ void AbstractXApplication::createContext(const Configuration& configuration) { /* Set OpenGL context as current */ contextHandler->makeCurrent(); - /* Initialize extension wrangler */ - ExtensionWrangler::initialize(); - c = new Context; } diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index 9cd8640a2..127e8f9fe 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -22,22 +22,14 @@ # DEALINGS IN THE SOFTWARE. # -set(MagnumPlatform_HEADERS - AbstractContextHandler.h - ExtensionWrangler.h) - -# Extension wrangler -add_library(MagnumPlatformExtensionWrangler OBJECT ExtensionWrangler.cpp) - +set(MagnumPlatform_HEADERS AbstractContextHandler.h) install(FILES ${MagnumPlatform_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) # GLUT application if(WITH_GLUTAPPLICATION) find_package(GLUT) if(GLUT_FOUND) - add_library(MagnumGlutApplication STATIC - GlutApplication.cpp - $) + add_library(MagnumGlutApplication STATIC GlutApplication.cpp) install(FILES GlutApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumGlutApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) else() @@ -50,9 +42,7 @@ if(WITH_SDL2APPLICATION) find_package(SDL2) if(SDL2_FOUND) include_directories(${SDL2_INCLUDE_DIR}) - add_library(MagnumSdl2Application STATIC - Sdl2Application.cpp - $) + add_library(MagnumSdl2Application STATIC Sdl2Application.cpp) install(FILES Sdl2Application.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumSdl2Application DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) else() @@ -66,8 +56,7 @@ if(WITH_NACLAPPLICATION) message(FATAL_ERROR "NaClApplication is available only when targeting Google Chrome Native Client. Set WITH_NACLAPPLICATION to OFF to skip building it.") endif() - add_library(MagnumNaClApplication STATIC - NaClApplication.cpp) + add_library(MagnumNaClApplication STATIC NaClApplication.cpp) install(FILES NaClApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumNaClApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) endif() @@ -78,8 +67,7 @@ if(WITH_WINDOWLESSNACLAPPLICATION) message(FATAL_ERROR "WindowlessNaClApplication is available only when targeting Google Chrome Native Client. Set WITH_WINDOWLESSNACLAPPLICATION to OFF to skip building it.") endif() - add_library(MagnumWindowlessNaClApplication STATIC - WindowlessNaClApplication.cpp) + add_library(MagnumWindowlessNaClApplication STATIC WindowlessNaClApplication.cpp) install(FILES WindowlessNaClApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumWindowlessNaClApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) endif() @@ -95,8 +83,7 @@ if(WITH_GLXAPPLICATION) set(NEED_GLXCONTEXT 1) add_library(MagnumGlxApplication STATIC $ - $ - $) + $) install(FILES GlxApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumGlxApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) endif() @@ -107,8 +94,7 @@ if(WITH_XEGLAPPLICATION) set(NEED_EGLCONTEXT 1) add_library(MagnumXEglApplication STATIC $ - $ - $) + $) install(FILES XEglApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumXEglApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) endif() @@ -122,9 +108,7 @@ endif() # Windowless GLX application if(WITH_WINDOWLESSGLXAPPLICATION) - add_library(MagnumWindowlessGlxApplication STATIC - WindowlessGlxApplication.cpp - $) + add_library(MagnumWindowlessGlxApplication STATIC WindowlessGlxApplication.cpp) # X11 macros are a mess, disable warnings for C-style casts set_target_properties(MagnumWindowlessGlxApplication PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") install(FILES WindowlessGlxApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) diff --git a/src/Platform/ExtensionWrangler.cpp b/src/Platform/ExtensionWrangler.cpp deleted file mode 100644 index c5f781264..000000000 --- a/src/Platform/ExtensionWrangler.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - This file is part of Magnum. - - Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -#include "ExtensionWrangler.h" - -#include -#include - -#include "Magnum.h" -#include "OpenGL.h" - -namespace Magnum { namespace Platform { - -void ExtensionWrangler::initialize() { - #ifndef MAGNUM_TARGET_GLES - /* Init glLoadGen. Ignore functions that failed to load (described by - `ogl_LOAD_SUCCEEDED + n` return code), as we requested the latest OpenGL - with many vendor extensions and there won't ever be a driver supporting - everything possible. */ - if(ogl_LoadFunctions() == ogl_LOAD_FAILED) { - Error() << "ExtensionWrangler: cannot initialize glLoadGen"; - std::exit(1); - } - #endif -} - -}} diff --git a/src/Platform/ExtensionWrangler.h b/src/Platform/ExtensionWrangler.h deleted file mode 100644 index 7944f131c..000000000 --- a/src/Platform/ExtensionWrangler.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef Magnum_Platform_ExtensionWrangler_h -#define Magnum_Platform_ExtensionWrangler_h -/* - This file is part of Magnum. - - Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -/** @file - * @brief Class Magnum::Platform::ExtensionWrangler - */ - -namespace Magnum { namespace Platform { - -/** @brief %Extension wrangler interface */ -class ExtensionWrangler { - public: - ExtensionWrangler() = delete; - - /** @brief Initialize extension wrangler */ - static void initialize(); -}; - -}} - -#endif diff --git a/src/Platform/GlutApplication.cpp b/src/Platform/GlutApplication.cpp index 422a2390b..aa8d8e388 100644 --- a/src/Platform/GlutApplication.cpp +++ b/src/Platform/GlutApplication.cpp @@ -25,7 +25,6 @@ #include "GlutApplication.h" #include "Context.h" -#include "ExtensionWrangler.h" namespace Magnum { namespace Platform { @@ -83,8 +82,6 @@ bool GlutApplication::tryCreateContext(const Configuration& configuration) { glutMotionFunc(staticMouseMoveEvent); glutDisplayFunc(staticDrawEvent); - ExtensionWrangler::initialize(); - c = new Context; return true; } diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index efa55a1ff..65e63a31d 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -25,7 +25,6 @@ #include "Sdl2Application.h" #include "Context.h" -#include "ExtensionWrangler.h" namespace Magnum { namespace Platform { @@ -106,8 +105,6 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) { return false; } - ExtensionWrangler::initialize(); - /* Push resize event, so viewportEvent() is called at startup */ SDL_Event* sizeEvent = new SDL_Event; sizeEvent->type = SDL_WINDOWEVENT; diff --git a/src/Platform/WindowlessGlxApplication.cpp b/src/Platform/WindowlessGlxApplication.cpp index 99e1e5cd7..5feedb01f 100644 --- a/src/Platform/WindowlessGlxApplication.cpp +++ b/src/Platform/WindowlessGlxApplication.cpp @@ -28,7 +28,6 @@ #include #include "Context.h" -#include "Platform/ExtensionWrangler.h" #define None 0L // redef Xlib nonsense @@ -103,9 +102,6 @@ void WindowlessGlxApplication::createContext(const Configuration&) { std::exit(1); } - /* Initialize extension wrangler */ - ExtensionWrangler::initialize(); - c = new Context; }