Browse Source

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.
pull/23/head
Vladimír Vondruš 13 years ago
parent
commit
100990cb0e
  1. 11
      src/Context.cpp
  2. 4
      src/Platform/AbstractXApplication.cpp
  3. 32
      src/Platform/CMakeLists.txt
  4. 48
      src/Platform/ExtensionWrangler.cpp
  5. 44
      src/Platform/ExtensionWrangler.h
  6. 3
      src/Platform/GlutApplication.cpp
  7. 3
      src/Platform/Sdl2Application.cpp
  8. 4
      src/Platform/WindowlessGlxApplication.cpp

11
src/Context.cpp

@ -298,6 +298,17 @@ const std::vector<Extension>& Extension::extensions(Version version) {
Context* Context::_current = nullptr; Context* Context::_current = nullptr;
Context::Context() { 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 */ /* Version */
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
glGetIntegerv(GL_MAJOR_VERSION, &_majorVersion); glGetIntegerv(GL_MAJOR_VERSION, &_majorVersion);

4
src/Platform/AbstractXApplication.cpp

@ -27,7 +27,6 @@
#include <Utility/utilities.h> #include <Utility/utilities.h>
#include "Context.h" #include "Context.h"
#include "ExtensionWrangler.h"
#define None 0L // redef Xlib nonsense #define None 0L // redef Xlib nonsense
@ -96,9 +95,6 @@ void AbstractXApplication::createContext(const Configuration& configuration) {
/* Set OpenGL context as current */ /* Set OpenGL context as current */
contextHandler->makeCurrent(); contextHandler->makeCurrent();
/* Initialize extension wrangler */
ExtensionWrangler::initialize();
c = new Context; c = new Context;
} }

32
src/Platform/CMakeLists.txt

@ -22,22 +22,14 @@
# DEALINGS IN THE SOFTWARE. # DEALINGS IN THE SOFTWARE.
# #
set(MagnumPlatform_HEADERS set(MagnumPlatform_HEADERS AbstractContextHandler.h)
AbstractContextHandler.h
ExtensionWrangler.h)
# Extension wrangler
add_library(MagnumPlatformExtensionWrangler OBJECT ExtensionWrangler.cpp)
install(FILES ${MagnumPlatform_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(FILES ${MagnumPlatform_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform)
# GLUT application # GLUT application
if(WITH_GLUTAPPLICATION) if(WITH_GLUTAPPLICATION)
find_package(GLUT) find_package(GLUT)
if(GLUT_FOUND) if(GLUT_FOUND)
add_library(MagnumGlutApplication STATIC add_library(MagnumGlutApplication STATIC GlutApplication.cpp)
GlutApplication.cpp
$<TARGET_OBJECTS:MagnumPlatformExtensionWrangler>)
install(FILES GlutApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(FILES GlutApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform)
install(TARGETS MagnumGlutApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(TARGETS MagnumGlutApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
else() else()
@ -50,9 +42,7 @@ if(WITH_SDL2APPLICATION)
find_package(SDL2) find_package(SDL2)
if(SDL2_FOUND) if(SDL2_FOUND)
include_directories(${SDL2_INCLUDE_DIR}) include_directories(${SDL2_INCLUDE_DIR})
add_library(MagnumSdl2Application STATIC add_library(MagnumSdl2Application STATIC Sdl2Application.cpp)
Sdl2Application.cpp
$<TARGET_OBJECTS:MagnumPlatformExtensionWrangler>)
install(FILES Sdl2Application.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(FILES Sdl2Application.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform)
install(TARGETS MagnumSdl2Application DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(TARGETS MagnumSdl2Application DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
else() 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.") message(FATAL_ERROR "NaClApplication is available only when targeting Google Chrome Native Client. Set WITH_NACLAPPLICATION to OFF to skip building it.")
endif() endif()
add_library(MagnumNaClApplication STATIC add_library(MagnumNaClApplication STATIC NaClApplication.cpp)
NaClApplication.cpp)
install(FILES NaClApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(FILES NaClApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform)
install(TARGETS MagnumNaClApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(TARGETS MagnumNaClApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
endif() 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.") message(FATAL_ERROR "WindowlessNaClApplication is available only when targeting Google Chrome Native Client. Set WITH_WINDOWLESSNACLAPPLICATION to OFF to skip building it.")
endif() endif()
add_library(MagnumWindowlessNaClApplication STATIC add_library(MagnumWindowlessNaClApplication STATIC WindowlessNaClApplication.cpp)
WindowlessNaClApplication.cpp)
install(FILES WindowlessNaClApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(FILES WindowlessNaClApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform)
install(TARGETS MagnumWindowlessNaClApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(TARGETS MagnumWindowlessNaClApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
endif() endif()
@ -95,8 +83,7 @@ if(WITH_GLXAPPLICATION)
set(NEED_GLXCONTEXT 1) set(NEED_GLXCONTEXT 1)
add_library(MagnumGlxApplication STATIC add_library(MagnumGlxApplication STATIC
$<TARGET_OBJECTS:MagnumAbstractXApplication> $<TARGET_OBJECTS:MagnumAbstractXApplication>
$<TARGET_OBJECTS:MagnumGlxContextHandler> $<TARGET_OBJECTS:MagnumGlxContextHandler>)
$<TARGET_OBJECTS:MagnumPlatformExtensionWrangler>)
install(FILES GlxApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(FILES GlxApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform)
install(TARGETS MagnumGlxApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(TARGETS MagnumGlxApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
endif() endif()
@ -107,8 +94,7 @@ if(WITH_XEGLAPPLICATION)
set(NEED_EGLCONTEXT 1) set(NEED_EGLCONTEXT 1)
add_library(MagnumXEglApplication STATIC add_library(MagnumXEglApplication STATIC
$<TARGET_OBJECTS:MagnumAbstractXApplication> $<TARGET_OBJECTS:MagnumAbstractXApplication>
$<TARGET_OBJECTS:MagnumEglContextHandler> $<TARGET_OBJECTS:MagnumEglContextHandler>)
$<TARGET_OBJECTS:MagnumPlatformExtensionWrangler>)
install(FILES XEglApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(FILES XEglApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform)
install(TARGETS MagnumXEglApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(TARGETS MagnumXEglApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
endif() endif()
@ -122,9 +108,7 @@ endif()
# Windowless GLX application # Windowless GLX application
if(WITH_WINDOWLESSGLXAPPLICATION) if(WITH_WINDOWLESSGLXAPPLICATION)
add_library(MagnumWindowlessGlxApplication STATIC add_library(MagnumWindowlessGlxApplication STATIC WindowlessGlxApplication.cpp)
WindowlessGlxApplication.cpp
$<TARGET_OBJECTS:MagnumPlatformExtensionWrangler>)
# X11 macros are a mess, disable warnings for C-style casts # X11 macros are a mess, disable warnings for C-style casts
set_target_properties(MagnumWindowlessGlxApplication PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") set_target_properties(MagnumWindowlessGlxApplication PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast")
install(FILES WindowlessGlxApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(FILES WindowlessGlxApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform)

48
src/Platform/ExtensionWrangler.cpp

@ -1,48 +0,0 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
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 <cstdlib>
#include <Utility/Debug.h>
#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
}
}}

44
src/Platform/ExtensionWrangler.h

@ -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š <mosra@centrum.cz>
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

3
src/Platform/GlutApplication.cpp

@ -25,7 +25,6 @@
#include "GlutApplication.h" #include "GlutApplication.h"
#include "Context.h" #include "Context.h"
#include "ExtensionWrangler.h"
namespace Magnum { namespace Platform { namespace Magnum { namespace Platform {
@ -83,8 +82,6 @@ bool GlutApplication::tryCreateContext(const Configuration& configuration) {
glutMotionFunc(staticMouseMoveEvent); glutMotionFunc(staticMouseMoveEvent);
glutDisplayFunc(staticDrawEvent); glutDisplayFunc(staticDrawEvent);
ExtensionWrangler::initialize();
c = new Context; c = new Context;
return true; return true;
} }

3
src/Platform/Sdl2Application.cpp

@ -25,7 +25,6 @@
#include "Sdl2Application.h" #include "Sdl2Application.h"
#include "Context.h" #include "Context.h"
#include "ExtensionWrangler.h"
namespace Magnum { namespace Platform { namespace Magnum { namespace Platform {
@ -106,8 +105,6 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) {
return false; return false;
} }
ExtensionWrangler::initialize();
/* Push resize event, so viewportEvent() is called at startup */ /* Push resize event, so viewportEvent() is called at startup */
SDL_Event* sizeEvent = new SDL_Event; SDL_Event* sizeEvent = new SDL_Event;
sizeEvent->type = SDL_WINDOWEVENT; sizeEvent->type = SDL_WINDOWEVENT;

4
src/Platform/WindowlessGlxApplication.cpp

@ -28,7 +28,6 @@
#include <Utility/Debug.h> #include <Utility/Debug.h>
#include "Context.h" #include "Context.h"
#include "Platform/ExtensionWrangler.h"
#define None 0L // redef Xlib nonsense #define None 0L // redef Xlib nonsense
@ -103,9 +102,6 @@ void WindowlessGlxApplication::createContext(const Configuration&) {
std::exit(1); std::exit(1);
} }
/* Initialize extension wrangler */
ExtensionWrangler::initialize();
c = new Context; c = new Context;
} }

Loading…
Cancel
Save