Improved ResourceListeners

Former-commit-id: 8016c23cb75aab94762a1e2838dbbcac2093119b
This commit is contained in:
Lynix
2013-08-09 16:28:07 +02:00
parent 4b1a6cc09e
commit d4cff9946e
11 changed files with 74 additions and 71 deletions

View File

@@ -324,11 +324,12 @@ void NzRenderTexture::Destroy()
{
if (m_impl)
{
bool canFreeFBO = true;
#if NAZARA_RENDERER_SAFE
if (NzContext::GetCurrent() != m_impl->context)
{
NazaraError("RenderTexture can only be used with it's creation context");
return;
NazaraWarning("RenderTexture should be destroyed by it's creation context, this will cause leaks");
canFreeFBO = false;
}
#endif
@@ -339,7 +340,7 @@ void NzRenderTexture::Destroy()
if (attachment.isUsed)
{
if (attachment.isBuffer)
glDeleteRenderbuffers(1, &attachment.buffer);
glDeleteRenderbuffers(1, &attachment.buffer); // Les Renderbuffers sont partagés entre les contextes: Ne posera pas de problème
else
{
attachment.texture->SetRenderTexture(nullptr);
@@ -348,7 +349,8 @@ void NzRenderTexture::Destroy()
}
}
glDeleteFramebuffers(1, &m_impl->fbo);
if (canFreeFBO)
glDeleteFramebuffers(1, &m_impl->fbo);
delete m_impl;
m_impl = nullptr;
@@ -636,11 +638,15 @@ void NzRenderTexture::Desactivate() const
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
}
void NzRenderTexture::OnResourceDestroy(const NzResource* resource, int index)
bool NzRenderTexture::OnResourceDestroy(const NzResource* resource, int index)
{
if (resource == m_impl->context)
// Notre context a été détruit, libérons la RenderTexture pour éviter un leak
{
// Notre contexte va être détruit, libérons la RenderTexture pour éviter un leak
Destroy();
return false;
}
else
{
// Sinon, c'est une texture
@@ -652,5 +658,7 @@ void NzRenderTexture::OnResourceDestroy(const NzResource* resource, int index)
m_impl->checked = false;
m_impl->drawBuffersUpdated = false;
return true;
}
}