diff options
author | Trond Kjernåsen <trond.kjernasen@nokia.com> | 2010-06-17 12:46:27 (GMT) |
---|---|---|
committer | Trond Kjernåsen <trond.kjernasen@nokia.com> | 2010-07-02 10:25:24 (GMT) |
commit | b2de72a51124333b639fdfbda829f54088dff838 (patch) | |
tree | b28b3b601351ae05d413315fe88781cefb7d98c8 /src/opengl/gl2paintengineex/qglengineshadermanager.cpp | |
parent | 76a14c8254f4f8beb16de897f31bab13dc7609a4 (diff) | |
download | Qt-b2de72a51124333b639fdfbda829f54088dff838.zip Qt-b2de72a51124333b639fdfbda829f54088dff838.tar.gz Qt-b2de72a51124333b639fdfbda829f54088dff838.tar.bz2 |
Rework the internal GL resource system yet again.
Instead of having to sub-class QGLContextResource, we now have two
template classes:
1. 'QGLContextResource' to handle context specific resources that are
*not* shared in a group, even though the context itself is in a sharing
group
2. 'QGLContextGroupResource' to handle resources shared in a context
group.
Classes used as the template class type must have a constructor with
the following signature:
T(const QGLContext *);
The resources that the templates wrap are freed up when the context
or context group it is tied to is destroyed. The resource is also
freed when the QGLContext<Group>Resource object is destroyed, which
might lead to context switches, depending on where and in how many
non-sharing contexts the resource is used.
The templates wrap some boiler plate code that were common for all the
use cases.
Diffstat (limited to 'src/opengl/gl2paintengineex/qglengineshadermanager.cpp')
-rw-r--r-- | src/opengl/gl2paintengineex/qglengineshadermanager.cpp | 49 |
1 files changed, 6 insertions, 43 deletions
diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp index 888bac9..c06bb3c 100644 --- a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp +++ b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp @@ -48,65 +48,27 @@ QT_BEGIN_NAMESPACE -class QGLSharedShaderResource : public QGLContextResource -{ -public: - ~QGLSharedShaderResource() { - qDebug() << "~QGLSharedShaderResource cleaned up" << hex << this; - } - - void freeResource(void *value) - { - qDebug() << "Context destroyed:"; - qDebug() << " -> deleting shader cache" << hex << value; - delete reinterpret_cast<QGLEngineSharedShaders *>(value); - } -}; - -class QGLThreadLocalShaders -{ -public: - QGLEngineSharedShaders *shadersForContext(const QGLContext *context) { - QGLEngineSharedShaders *shaders = reinterpret_cast<QGLEngineSharedShaders *>(m_resource.value(context)); - if (!shaders) { - QGLShareContextScope scope(context); - shaders = new QGLEngineSharedShaders(context); - qDebug() << " -> new shader cache for context:" << hex << context << "cache:" << shaders; - m_resource.insert(context, shaders); - } - return shaders; - } - - ~QGLThreadLocalShaders() { - qDebug() << "Thread exit:"; - qDebug() << "~QGLThreadLocalShaders() for thread:" << hex << QThread::currentThread(); - } - -private: - QGLSharedShaderResource m_resource; -}; - class QGLShaderStorage { public: QGLEngineSharedShaders *shadersForThread(const QGLContext *context) { - QGLThreadLocalShaders *&shaders = m_storage.localData(); + QGLContextGroupResource<QGLEngineSharedShaders> *&shaders = m_storage.localData(); if (!shaders) { qDebug() << "New thread storage for:" << hex << QThread::currentThread(); - shaders = new QGLThreadLocalShaders; + shaders = new QGLContextGroupResource<QGLEngineSharedShaders>(); } - return shaders->shadersForContext(context); + return shaders->value(context); } private: - QThreadStorage<QGLThreadLocalShaders *> m_storage; + QThreadStorage<QGLContextGroupResource<QGLEngineSharedShaders> *> m_storage; }; Q_GLOBAL_STATIC(QGLShaderStorage, qt_shader_storage); QGLEngineSharedShaders *QGLEngineSharedShaders::shadersForContext(const QGLContext *context) { - return reinterpret_cast<QGLEngineSharedShaders *>(qt_shader_storage()->shadersForThread(context)); + return qt_shader_storage()->shadersForThread(context); } const char* QGLEngineSharedShaders::qShaderSnippets[] = { @@ -271,6 +233,7 @@ QGLEngineSharedShaders::QGLEngineSharedShaders(const QGLContext* context) QGLEngineSharedShaders::~QGLEngineSharedShaders() { + qDebug() << "####### ~QGLEngineSharedShaders() ##########"; qDeleteAll(shaders); shaders.clear(); |