diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2016-05-29 08:39:07 +0100 |
---|---|---|
committer | Jani Heikkinen <jani.heikkinen@qt.io> | 2016-06-01 11:02:41 +0000 |
commit | d561d938d036af49188c06c84a8b007964e60c5f (patch) | |
tree | 6065262b7ef32de7adb87dac197cff738b43c04f /src/render/graphicshelpers/graphicscontext_p.h | |
parent | da456565c11be06092aed1f68bd33330057b2143 (diff) |
Fix shader caching
Introduces a specialized ShaderCache class. This is populated with
shaders on demand from render command processing. Likewise for adding
references to shared QOpenGLShaderPrograms from other Shader backend
nodes.
When a Shader backend node is destroyed, it will remove its reference
from the ShaderCache. When a shared QOpenGLShaderProgram has no
remaining references the cache marks it as pending deletion. If it
still has no references the next time the OpenGL submission thread
calls the purge() function on the cache, it will be removed.
With this approach the actual QOpenGLShaderProgram objects are
managed purely by the OpenGL submission thread and are owned by the
cache once added to it.
Task-number: QTBUG-53669
Change-Id: Ia8459b0fdb775148c83202a801ac41cbdd447bcc
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/render/graphicshelpers/graphicscontext_p.h')
-rw-r--r-- | src/render/graphicshelpers/graphicscontext_p.h | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/render/graphicshelpers/graphicscontext_p.h b/src/render/graphicshelpers/graphicscontext_p.h index 4c41c0e4b..f5598386d 100644 --- a/src/render/graphicshelpers/graphicscontext_p.h +++ b/src/render/graphicshelpers/graphicscontext_p.h @@ -66,6 +66,7 @@ #include <Qt3DRender/qattribute.h> #include <Qt3DRender/private/handle_types_p.h> #include <Qt3DRender/private/qgraphicsapifilter_p.h> +#include <Qt3DRender/private/shadercache_p.h> QT_BEGIN_NAMESPACE @@ -124,9 +125,9 @@ public: void activateGLHelper(); bool hasValidGLHelper() const; + QOpenGLShaderProgram *createShaderProgram(Shader *shaderNode); void activateShader(Shader* shader); - QOpenGLShaderProgram *containsProgram(const ProgramDNA &dna); - void removeProgram(const ProgramDNA &dna, Qt3DCore::QNodeId id); + void removeShaderProgramReference(Shader *shaderNode); GLuint activeFBO() const { return m_activeFBO; } GLuint defaultFBO() const { return m_defaultFBO; } @@ -245,8 +246,8 @@ private: GraphicsHelperInterface *m_glHelper; bool m_ownCurrent; + ShaderCache m_shaderCache; Shader *m_activeShader; - QHash<ProgramDNA, Shader *> m_renderShaderHash; QHash<Qt3DCore::QNodeId, HGLBuffer> m_renderBufferHash; QHash<Qt3DCore::QNodeId, GLuint> m_renderTargets; QHash<GLuint, QSize> m_renderTargetsSize; |