summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2016-04-15 13:55:03 +0100
committerSean Harmer <sean.harmer@kdab.com>2016-04-17 12:26:08 +0000
commitbef819368d861f386be44714f7c8d053c1bb2734 (patch)
treec290321da683c6d7b439183fb3491c837b6946a9 /src
parent042c380b5885d15925bf66400ebeaa1dc0e7dda0 (diff)
Remove shader from cache in graphics context cache when deleted
Stops assert firing when trying to use a recycled Shader Change-Id: Ifa18143a145654fd3f9e381627406e907a9e2d48 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/render/graphicshelpers/graphicscontext.cpp7
-rw-r--r--src/render/graphicshelpers/graphicscontext_p.h1
-rw-r--r--src/render/materialsystem/shader.cpp9
-rw-r--r--src/render/materialsystem/shader_p.h1
4 files changed, 17 insertions, 1 deletions
diff --git a/src/render/graphicshelpers/graphicscontext.cpp b/src/render/graphicshelpers/graphicscontext.cpp
index 8bc7d6d6f..c1913362d 100644
--- a/src/render/graphicshelpers/graphicscontext.cpp
+++ b/src/render/graphicshelpers/graphicscontext.cpp
@@ -429,6 +429,13 @@ QOpenGLShaderProgram *GraphicsContext::containsProgram(const ProgramDNA &dna)
return Q_NULLPTR;
}
+void GraphicsContext::removeProgram(const ProgramDNA &dna, Qt3DCore::QNodeId id)
+{
+ Shader *renderShader = m_renderShaderHash.value(dna, nullptr);
+ if (renderShader && renderShader->peerId() == id)
+ m_renderShaderHash.remove(dna);
+}
+
void GraphicsContext::activateRenderTarget(RenderTarget *renderTarget, const AttachmentPack &attachments, GLuint defaultFboId)
{
GLuint fboId = defaultFboId; // Default FBO
diff --git a/src/render/graphicshelpers/graphicscontext_p.h b/src/render/graphicshelpers/graphicscontext_p.h
index 7c744ba12..d73858cdd 100644
--- a/src/render/graphicshelpers/graphicscontext_p.h
+++ b/src/render/graphicshelpers/graphicscontext_p.h
@@ -127,6 +127,7 @@ public:
void activateShader(Shader* shader);
QOpenGLShaderProgram *containsProgram(const ProgramDNA &dna);
+ void removeProgram(const ProgramDNA &dna, Qt3DCore::QNodeId id);
GLuint activeFBO() const { return m_activeFBO; }
GLuint defaultFBO() const { return m_defaultFBO; }
diff --git a/src/render/materialsystem/shader.cpp b/src/render/materialsystem/shader.cpp
index ae655ac6a..17ed8b569 100644
--- a/src/render/materialsystem/shader.cpp
+++ b/src/render/materialsystem/shader.cpp
@@ -60,9 +60,10 @@ namespace Render {
Shader::Shader()
: BackendNode()
- , m_program(Q_NULLPTR)
+ , m_program(nullptr)
, m_isLoaded(false)
, m_dna(0)
+ , m_graphicsContext(nullptr)
{
m_shaderCode.resize(static_cast<int>(QShaderProgram::Compute) + 1);
}
@@ -75,6 +76,11 @@ Shader::~Shader()
void Shader::cleanup()
{
+ // Remove this shader from the hash in the graphics context so
+ // nothing tries to use it after it has been recycled
+ if (m_graphicsContext)
+ m_graphicsContext->removeProgram(dna(), peerId());
+
QBackendNode::setEnabled(false);
m_isLoaded = false;
m_dna = 0;
@@ -251,6 +257,7 @@ QOpenGLShaderProgram *Shader::getOrCreateProgram(GraphicsContext *ctx)
{
if (!m_isLoaded) {
delete m_program;
+ m_graphicsContext = ctx;
m_program = createProgram(ctx);
if (!m_program)
m_program = createDefaultProgram();
diff --git a/src/render/materialsystem/shader_p.h b/src/render/materialsystem/shader_p.h
index 823c089af..77d6fb75e 100644
--- a/src/render/materialsystem/shader_p.h
+++ b/src/render/materialsystem/shader_p.h
@@ -146,6 +146,7 @@ private:
bool m_isLoaded;
ProgramDNA m_dna;
QMutex m_mutex;
+ GraphicsContext *m_graphicsContext;
void updateDNA();