Browse Source

Private (implementation-only) OpenGL state tracker.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
193246e533
  1. 2
      src/CMakeLists.txt
  2. 5
      src/Context.cpp
  3. 12
      src/Context.h
  4. 25
      src/Implementation/State.cpp
  5. 31
      src/Implementation/State.h

2
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)

5
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;
}

12
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<Extension> _supportedExtensions;
Implementation::State* _state;
};
}

25
src/Implementation/State.cpp

@ -0,0 +1,25 @@
/*
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 "State.h"
namespace Magnum { namespace Implementation {
State::State() {}
State::~State() {
}
}}

31
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š <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 "Magnum.h"
namespace Magnum { namespace Implementation {
class BufferState;
struct State {
State();
~State();
};
}}
#endif
Loading…
Cancel
Save