From 193246e5339d83499657120d924a280f90171e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 23:55:00 +0200 Subject: [PATCH] Private (implementation-only) OpenGL state tracker. --- src/CMakeLists.txt | 2 ++ src/Context.cpp | 5 +++++ src/Context.h | 12 ++++++++++++ src/Implementation/State.cpp | 25 +++++++++++++++++++++++++ src/Implementation/State.h | 31 +++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 src/Implementation/State.cpp create mode 100644 src/Implementation/State.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e2e867e56..6f1d45eaa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,6 +37,8 @@ set(Magnum_SRCS Timeline.cpp TypeTraits.cpp + Implementation/State.cpp + Trade/AbstractImporter.cpp Trade/MeshData2D.cpp Trade/MeshData3D.cpp) diff --git a/src/Context.cpp b/src/Context.cpp index 3a46b7638..92247c051 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -21,6 +21,7 @@ #include "Buffer.h" #include "Extensions.h" +#include "Implementation/State.h" using namespace std; @@ -193,12 +194,16 @@ Context::Context() { CORRADE_ASSERT(!_current, "Context: Another context currently active", ); _current = this; + /* Initialize state tracker */ + _state = new Implementation::State; + /* Initialize functionality based on current OpenGL version and extensions */ Buffer::initializeContextBasedFunctionality(this); } Context::~Context() { CORRADE_ASSERT(_current == this, "Context: Cannot destroy context which is not currently active", ); + delete _state; _current = nullptr; } diff --git a/src/Context.h b/src/Context.h index 820b998e5..3ac3de27e 100644 --- a/src/Context.h +++ b/src/Context.h @@ -28,6 +28,12 @@ namespace Magnum { +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + class State; +} +#endif + /** @brief OpenGL version */ enum class Version: GLint { None = 0, /**< @brief Unspecified */ @@ -202,6 +208,10 @@ class MAGNUM_EXPORT Context { return _version >= extension._coreVersion || (_version >= extension._requiredVersion && extensionStatus[extension._index]); } + #ifndef DOXYGEN_GENERATING_OUTPUT + inline Implementation::State* state() { return _state; } + #endif + private: static Context* _current; @@ -211,6 +221,8 @@ class MAGNUM_EXPORT Context { std::bitset<128> extensionStatus; std::vector _supportedExtensions; + + Implementation::State* _state; }; } diff --git a/src/Implementation/State.cpp b/src/Implementation/State.cpp new file mode 100644 index 000000000..2fb89de2d --- /dev/null +++ b/src/Implementation/State.cpp @@ -0,0 +1,25 @@ +/* + 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 "State.h" + +namespace Magnum { namespace Implementation { + +State::State() {} + +State::~State() { +} + +}} diff --git a/src/Implementation/State.h b/src/Implementation/State.h new file mode 100644 index 000000000..8a070d47d --- /dev/null +++ b/src/Implementation/State.h @@ -0,0 +1,31 @@ +#ifndef Magnum_Implementation_State_h +#define Magnum_Implementation_State_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. +*/ + +#include "Magnum.h" + +namespace Magnum { namespace Implementation { + +class BufferState; + +struct State { + State(); + ~State(); +}; + +}} + +#endif