diff --git a/src/Contexts/AbstractGlInterface.h b/src/Contexts/AbstractGlInterface.h index 629eb1dc3..3f6d14ef6 100644 --- a/src/Contexts/AbstractGlInterface.h +++ b/src/Contexts/AbstractGlInterface.h @@ -19,6 +19,8 @@ * @brief Class Magnum::Contexts::AbstractGlInterface */ +#include "ExtensionWrangler.h" + namespace Magnum { namespace Contexts { /** @brief Base for OpenGL interfaces */ @@ -41,6 +43,15 @@ template class AbstractGlInterface /** @brief Create context */ virtual void createContext(Window nativeWindow) = 0; + /** + * @brief Whether to enable experimental extension wrangler features + * + * Default is to disable. + */ + virtual inline ExtensionWrangler::ExperimentalFeatures experimentalExtensionWranglerFeatures() const { + return ExtensionWrangler::ExperimentalFeatures::Disable; + } + /** @brief Make the context current */ virtual void makeCurrent() = 0; diff --git a/src/Contexts/AbstractXContext.cpp b/src/Contexts/AbstractXContext.cpp index 5195b5387..103dcabbc 100644 --- a/src/Contexts/AbstractXContext.cpp +++ b/src/Contexts/AbstractXContext.cpp @@ -15,6 +15,8 @@ #include "AbstractXContext.h" +#include "ExtensionWrangler.h" + #define None 0L // redef Xlib nonsense /* Mask for X events */ @@ -66,14 +68,8 @@ AbstractXContext::AbstractXContext(AbstractGlInterfacemakeCurrent(); - #ifndef MAGNUM_TARGET_GLES - /* Init GLEW */ - GLenum err = glewInit(); - if(err != GLEW_OK) { - Error() << "AbstractXContext: cannot initialize GLEW:" << glewGetErrorString(err); - exit(1); - } - #endif + /* Initialize extension wrangler */ + ExtensionWrangler::initialize(glInterface->experimentalExtensionWranglerFeatures()); } AbstractXContext::~AbstractXContext() { diff --git a/src/Contexts/CMakeLists.txt b/src/Contexts/CMakeLists.txt index dee2f25e6..bc1aa130c 100644 --- a/src/Contexts/CMakeLists.txt +++ b/src/Contexts/CMakeLists.txt @@ -1,13 +1,19 @@ +# Extension wrangler +add_library(MagnumContextsExtensionWrangler OBJECT ExtensionWrangler.cpp) + set(MagnumContexts_HEADERS AbstractContext.h - AbstractGlInterface.h) + AbstractGlInterface.h + ExtensionWrangler.h) install(FILES ${MagnumContexts_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) # GLUT context if(WITH_GLUTCONTEXT) find_package(GLUT) if(GLUT_FOUND) - add_library(MagnumGlutContext STATIC GlutContext.cpp) + add_library(MagnumGlutContext STATIC + GlutContext.cpp + $) install(FILES GlutContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) install(TARGETS MagnumGlutContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) else() @@ -20,7 +26,9 @@ if(WITH_SDL2CONTEXT) find_package(SDL2) if(SDL2_FOUND) include_directories(${SDL2_INCLUDE_DIR}) - add_library(MagnumSdl2Context STATIC Sdl2Context.cpp) + add_library(MagnumSdl2Context STATIC + Sdl2Context.cpp + $) install(FILES Sdl2Context.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) install(TARGETS MagnumSdl2Context DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) else() @@ -32,7 +40,10 @@ endif() if(WITH_XEGLCONTEXT) set(NEED_ABSTRACTXCONTEXT 1) set(NEED_EGLINTERFACE 1) - add_library(MagnumXEglContext STATIC $ $) + add_library(MagnumXEglContext STATIC + $ + $ + $) install(FILES XEglContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) install(TARGETS MagnumXEglContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) endif() diff --git a/src/Contexts/ExtensionWrangler.cpp b/src/Contexts/ExtensionWrangler.cpp new file mode 100644 index 000000000..4515624bd --- /dev/null +++ b/src/Contexts/ExtensionWrangler.cpp @@ -0,0 +1,37 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "ExtensionWrangler.h" + +#include "Magnum.h" + +namespace Magnum { namespace Contexts { + +void ExtensionWrangler::initialize(ExperimentalFeatures experimentalFeatures) { + #ifndef MAGNUM_TARGET_GLES + /* Enable experimental features */ + if(experimentalFeatures == ExperimentalFeatures::Enable) + glewExperimental = true; + + /* Init GLEW */ + GLenum err = glewInit(); + if(err != GLEW_OK) { + Error() << "ExtensionWrangler: cannot initialize GLEW:" << glewGetErrorString(err); + exit(1); + } + #endif +} + +}} diff --git a/src/Contexts/ExtensionWrangler.h b/src/Contexts/ExtensionWrangler.h new file mode 100644 index 000000000..04dba65d3 --- /dev/null +++ b/src/Contexts/ExtensionWrangler.h @@ -0,0 +1,39 @@ +#ifndef Magnum_Contexts_ExtensionWrangler_h +#define Magnum_Contexts_ExtensionWrangler_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Contexts::ExtensionWrangler + */ + +namespace Magnum { namespace Contexts { + +/** @brief Extension wrangler interface */ +class ExtensionWrangler { + public: + /** @brief Whether to enable or disable experimental features */ + enum class ExperimentalFeatures { + Disable, + Enable + }; + + /** @brief Initialize extension wrangler */ + static void initialize(ExperimentalFeatures experimentalFeatures = ExperimentalFeatures::Disable); +}; + +}} + +#endif diff --git a/src/Contexts/GlutContext.cpp b/src/Contexts/GlutContext.cpp index a3d210e31..01307482d 100644 --- a/src/Contexts/GlutContext.cpp +++ b/src/Contexts/GlutContext.cpp @@ -15,6 +15,8 @@ #include "GlutContext.h" +#include "ExtensionWrangler.h" + namespace Magnum { namespace Contexts { GlutContext* GlutContext::instance = nullptr; @@ -35,12 +37,7 @@ GlutContext::GlutContext(int& argc, char** argv, const std::string& title, const glutMotionFunc(staticMouseMotionEvent); glutDisplayFunc(staticDrawEvent); - /* Init GLEW */ - GLenum err = glewInit(); - if(err != GLEW_OK) { - Error() << "GlutContext: cannot initialize GLEW:" << glewGetErrorString(err); - exit(1); - } + ExtensionWrangler::initialize(); } }} diff --git a/src/Contexts/Sdl2Context.cpp b/src/Contexts/Sdl2Context.cpp index 472b9fc95..074fe3edd 100644 --- a/src/Contexts/Sdl2Context.cpp +++ b/src/Contexts/Sdl2Context.cpp @@ -14,6 +14,7 @@ */ #include "Sdl2Context.h" +#include "ExtensionWrangler.h" namespace Magnum { namespace Contexts { @@ -40,18 +41,9 @@ Sdl2Context::Sdl2Context(int, char**, const std::string& name, const Math::Vecto context = SDL_GL_CreateContext(window); - #ifndef MAGNUM_TARGET_GLES /* This must be enabled, otherwise (on my NVidia) it crashes when creating VAO. WTF. */ - glewExperimental = true; - - /* Init GLEW */ - GLenum err = glewInit(); - if(err != GLEW_OK) { - Error() << "Sdl2Context: cannot initialize GLEW:" << glewGetErrorString(err); - exit(1); - } - #endif + ExtensionWrangler::initialize(ExtensionWrangler::ExperimentalFeatures::Enable); /* Push resize event, so viewportEvent() is called at startup */ SDL_Event* sizeEvent = new SDL_Event;