Browse Source

Separate class for extension wrangler initialization.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
a3bc29a000
  1. 11
      src/Contexts/AbstractGlInterface.h
  2. 12
      src/Contexts/AbstractXContext.cpp
  3. 19
      src/Contexts/CMakeLists.txt
  4. 37
      src/Contexts/ExtensionWrangler.cpp
  5. 39
      src/Contexts/ExtensionWrangler.h
  6. 9
      src/Contexts/GlutContext.cpp
  7. 12
      src/Contexts/Sdl2Context.cpp

11
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 Display, class VisualId, class Window> 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;

12
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(AbstractGlInterface<Display*, VisualID, Windo
/* Set OpenGL context as current */
glInterface->makeCurrent();
#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() {

19
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
$<TARGET_OBJECTS:MagnumContextsExtensionWrangler>)
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
$<TARGET_OBJECTS:MagnumContextsExtensionWrangler>)
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 $<TARGET_OBJECTS:MagnumAbstractXContext> $<TARGET_OBJECTS:MagnumEglInterface>)
add_library(MagnumXEglContext STATIC
$<TARGET_OBJECTS:MagnumAbstractXContext>
$<TARGET_OBJECTS:MagnumEglInterface>
$<TARGET_OBJECTS:MagnumContextsExtensionWrangler>)
install(FILES XEglContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumXEglContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
endif()

37
src/Contexts/ExtensionWrangler.cpp

@ -0,0 +1,37 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
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
}
}}

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

9
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();
}
}}

12
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;

Loading…
Cancel
Save