Browse Source

Split the OpenGL layer out, pt 14: Platform::{Context => GLContext}.

Compatibility header and alias in the next commit so Git is able to
recognize the file move.
pull/233/head
Vladimír Vondruš 8 years ago
parent
commit
53e2043c6b
  1. 14
      doc/platform.dox
  2. 2
      modules/FindMagnum.cmake
  3. 12
      src/Magnum/GL/Context.h
  4. 2
      src/Magnum/Platform/CMakeLists.txt
  5. 55
      src/Magnum/Platform/GLContext.h
  6. 5
      src/Magnum/Platform/Platform.h

14
doc/platform.dox

@ -164,10 +164,10 @@ back to no-AA rendering:
In case you want to use some not-yet-supported toolkit or you don't want to use
the application wrappers in @ref Platform namespace, you can initialize Magnum
manually. First create OpenGL context and then create instance of
@ref Platform::Context class, which will take care of proper initialization and
feature detection. The instance must be alive for whole application lifetime.
Example @cpp main() @ce function with manual initialization is in the following
code listing.
@ref Platform::GLContext class, which will take care of proper initialization
and feature detection. The instance must be alive for whole application
lifetime. Example @cpp main() @ce function with manual initialization is in the
following code listing.
@note Fully contained application using with manual Magnum initialization on
top of Qt toolkit is available in `base-qt` branch of
@ -178,11 +178,11 @@ code listing.
@snippet MagnumPlatform-custom.cpp custom
@attention The @ref Platform::Context instance is bound to a single OpenGL
@attention The @ref Platform::GLContext instance is bound to a single OpenGL
context, which must be always set as current when calling any Magnum APIs
touching OpenGL state.
On majority of platforms the @ref Platform::Context class does GL function
On majority of platforms the @ref Platform::GLContext class does GL function
pointer loading using platform-specific APIs. In that case you also need to
find particular `*Context` library, add its include dir and then link to it.
These platform-specific libraries are available:
@ -220,7 +220,7 @@ is accompanied by a @ref Platform::WindowlessEglContext "Platform::Windowless*Co
class that manages just GL context creation, making it current and destruction.
Similarly to using custom platform toolkits above, the workflow is to first
create a GL context instance, then making it current and finally instantiating
the @ref Platform::Context instance to initialize Magnum.
the @ref Platform::GLContext instance to initialize Magnum.
Similarly as with the applications, to simplify the porting, the library
provides @cpp Platform::WindowlessGLContext @ce typedef, but only if just one

2
modules/FindMagnum.cmake

@ -625,7 +625,7 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# Context libraries
elseif(_component MATCHES ".+Context")
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/Platform)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Context.h)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES GLContext.h)
# GLX context dependencies
if(_component STREQUAL GlxContext)

12
src/Magnum/GL/Context.h

@ -45,7 +45,7 @@
namespace Magnum {
namespace Platform { class Context; }
namespace Platform { class GLContext; }
namespace GL {
@ -109,14 +109,14 @@ through @ref Context::current() is automatically created during construction of
`*Application` classes in @ref Platform namespace. You can safely assume that
the instance is available during whole lifetime of `*Application` object. It's
also possible to create the context without using any `*Application` class
using @ref Platform::Context subclass, see @ref platform documentation for more
information.
using @ref Platform::GLContext subclass, see @ref platform documentation for
more information.
@section GL-Context-command-line Command-line options
The context is configurable through command-line options, that are passed
either from the `Platform::*Application` classes or from the @ref Platform::Context
class. Usage:
either from the `Platform::*Application` classes or from the
@ref Platform::GLContext class. Usage:
@code{.sh}
<application> [--magnum-help] [--magnum-disable-workarounds LIST]
@ -634,7 +634,7 @@ class MAGNUM_GL_EXPORT Context {
private:
#ifndef DOXYGEN_GENERATING_OUTPUT /* https://bugzilla.gnome.org/show_bug.cgi?id=776986 */
friend Implementation::ContextState;
friend Platform::Context;
friend Platform::GLContext;
#endif
explicit Context(NoCreateT, Int argc, const char** argv, void functionLoader());

2
src/Magnum/Platform/CMakeLists.txt

@ -25,7 +25,7 @@
# Headers
set(MagnumPlatform_HEADERS
Context.h
GLContext.h
Platform.h
Screen.h
ScreenedApplication.h

55
src/Magnum/Platform/Context.h → src/Magnum/Platform/GLContext.h

@ -1,5 +1,5 @@
#ifndef Magnum_Platform_Context_h
#define Magnum_Platform_Context_h
#ifndef Magnum_Platform_GLContext_h
#define Magnum_Platform_GLContext_h
/*
This file is part of Magnum.
@ -25,21 +25,34 @@
DEALINGS IN THE SOFTWARE.
*/
#ifdef MAGNUM_TARGET_GL
/** @file
* @brief Class @ref Magnum::Platform::GLContext
*/
#endif
#include <Corrade/Utility/Debug.h>
#include "Magnum/Context.h"
#include "Magnum/OpenGL.h"
#include "Magnum/configure.h"
#ifdef MAGNUM_TARGET_GL
#include "Magnum/GL/Context.h"
#include "Magnum/GL/OpenGL.h"
namespace Magnum { namespace Platform {
/**
@brief Platform-specific context
@brief Platform-specific OpenGL context
In most cases not needed to be used directly as the initialization is done
automatically in `*Application` classes. See @ref platform for more
information.
@note This class is available only if Magnum is compiled with
@ref MAGNUM_TARGET_GL enabled (done by default). See @ref building-features
for more information.
*/
class Context: public Magnum::Context {
class GLContext: public GL::Context {
public:
/**
* @brief Constructor
@ -54,24 +67,24 @@ class Context: public Magnum::Context {
* @def_gl{MINOR_VERSION}, @def_gl{CONTEXT_FLAGS},
* @def_gl{NUM_EXTENSIONS}, @fn_gl{GetString} with @def_gl{EXTENSIONS}
*/
explicit Context(Int argc, const char** argv): Context{NoCreate, argc, argv} { create(); }
explicit GLContext(Int argc, const char** argv): GLContext{NoCreate, argc, argv} { create(); }
/** @overload */
explicit Context(Int argc, char** argv): Context{argc, const_cast<const char**>(argv)} {}
explicit GLContext(Int argc, char** argv): GLContext{argc, const_cast<const char**>(argv)} {}
/** @overload */
explicit Context(Int argc, std::nullptr_t argv): Context{argc, static_cast<const char**>(argv)} {}
explicit GLContext(Int argc, std::nullptr_t argv): GLContext{argc, static_cast<const char**>(argv)} {}
/**
* @brief Default constructor
*
* Equivalent to passing @cpp {0, nullptr} @ce to
* @ref Context(Int, const char**). Even if the command-line options
* @ref GLContext(Int, const char**). Even if the command-line options
* are not propagated, it's still possible to affect the renderer
* behavior from the environment. See @ref Context-command-line for
* more information.
*/
explicit Context(): Context{0, nullptr} {}
explicit GLContext(): GLContext{0, nullptr} {}
/**
* @brief Construct the class without doing complete setup
@ -81,18 +94,18 @@ class Context: public Magnum::Context {
* left in empty state. Use @ref create() or @ref tryCreate() to
* complete the setup.
*/
explicit Context(NoCreateT, Int argc, const char** argv):
explicit GLContext(NoCreateT, Int argc, const char** argv):
#ifndef CORRADE_TARGET_EMSCRIPTEN
Magnum::Context{NoCreate, argc, argv, flextGLInit} {}
GL::Context{NoCreate, argc, argv, flextGLInit} {}
#else
Magnum::Context{NoCreate, argc, argv, nullptr} {}
GL::Context{NoCreate, argc, argv, nullptr} {}
#endif
/** @overload */
explicit Context(NoCreateT, Int argc, char** argv): Context{NoCreate, argc, const_cast<const char**>(argv)} {}
explicit GLContext(NoCreateT, Int argc, char** argv): GLContext{NoCreate, argc, const_cast<const char**>(argv)} {}
/** @overload */
explicit Context(NoCreateT, Int argc, std::nullptr_t argv): Context{NoCreate, argc, static_cast<const char**>(argv)} {}
explicit GLContext(NoCreateT, Int argc, std::nullptr_t argv): GLContext{NoCreate, argc, static_cast<const char**>(argv)} {}
/**
* @brief Construct the class without doing complete setup
@ -103,7 +116,7 @@ class Context: public Magnum::Context {
* renderer behavior from the environment. See @ref Context-command-line
* for more information.
*/
explicit Context(NoCreateT): Context{NoCreate, 0, nullptr} {}
explicit GLContext(NoCreateT): GLContext{NoCreate, 0, nullptr} {}
/**
* @brief Complete the context setup and exit on failure
@ -114,7 +127,7 @@ class Context: public Magnum::Context {
* output and the application exits. See @ref Context(Int, char**) for
* more information and @ref tryCreate() for an alternative.
*/
void create() { return Magnum::Context::create(); }
void create() { return GL::Context::create(); }
/**
* @brief Complete the context setup
@ -122,10 +135,12 @@ class Context: public Magnum::Context {
* Unlike @ref create() just prints a message to error output and
* returns `false` on error.
*/
bool tryCreate() { return Magnum::Context::tryCreate(); }
bool tryCreate() { return GL::Context::tryCreate(); }
};
}}
#else
#error this header is available only in the OpenGL build
#endif
#endif

5
src/Magnum/Platform/Platform.h

@ -34,7 +34,10 @@ namespace Magnum { namespace Platform {
#ifndef DOXYGEN_GENERATING_OUTPUT
template<class> class BasicScreen;
template<class> class BasicScreenedApplication;
class Context;
#ifdef MAGNUM_TARGET_GL
class GLContext;
#endif
#endif
}}

Loading…
Cancel
Save