diff options
Diffstat (limited to 'src/SFML/Window/GlResource.cpp')
-rw-r--r-- | src/SFML/Window/GlResource.cpp | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/src/SFML/Window/GlResource.cpp b/src/SFML/Window/GlResource.cpp index dfcbe7a..a3cdddf 100644 --- a/src/SFML/Window/GlResource.cpp +++ b/src/SFML/Window/GlResource.cpp @@ -27,6 +27,7 @@ //////////////////////////////////////////////////////////// #include <SFML/Window/GlResource.hpp> #include <SFML/Window/GlContext.hpp> +#include <SFML/Window/Context.hpp> #include <SFML/System/Mutex.hpp> #include <SFML/System/Lock.hpp> @@ -44,20 +45,15 @@ namespace sf //////////////////////////////////////////////////////////// GlResource::GlResource() { - { - // Protect from concurrent access - Lock lock(mutex); - - // If this is the very first resource, trigger the global context initialization - if (count == 0) - priv::GlContext::globalInit(); + // Protect from concurrent access + Lock lock(mutex); - // Increment the resources counter - count++; - } + // If this is the very first resource, trigger the global context initialization + if (count == 0) + priv::GlContext::globalInit(); - // Now make sure that there is an active OpenGL context in the current thread - priv::GlContext::ensureContext(); + // Increment the resources counter + count++; } @@ -77,9 +73,31 @@ GlResource::~GlResource() //////////////////////////////////////////////////////////// -void GlResource::ensureGlContext() +GlResource::TransientContextLock::TransientContextLock() : +m_context(0) +{ + Lock lock(mutex); + + if (count == 0) + { + m_context = new Context; + return; + } + + priv::GlContext::acquireTransientContext(); +} + + +//////////////////////////////////////////////////////////// +GlResource::TransientContextLock::~TransientContextLock() { - priv::GlContext::ensureContext(); + if (m_context) + { + delete m_context; + return; + } + + priv::GlContext::releaseTransientContext(); } } // namespace sf |