diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2015-08-31 12:11:50 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2015-08-31 20:18:54 +0100 |
commit | 18dd07ba4fd9ede98ce576e6024831658bbd5401 (patch) | |
tree | 013a6802b3a7089c1b62b68c4169d21ae0982799 | |
parent | 6cf43cf6b98866401702d3275a7a026d8fa01edf (diff) |
tdf#93751 - ensure textures are unbound from framebuffers post destroy.
Change-Id: I81aec0e6f8db57905826c54c3442528be6068700
-rw-r--r-- | include/vcl/opengl/OpenGLContext.hxx | 1 | ||||
-rw-r--r-- | vcl/inc/opengl/framebuffer.hxx | 1 | ||||
-rw-r--r-- | vcl/opengl/framebuffer.cxx | 9 | ||||
-rw-r--r-- | vcl/opengl/texture.cxx | 10 | ||||
-rw-r--r-- | vcl/source/opengl/OpenGLContext.cxx | 20 |
5 files changed, 39 insertions, 2 deletions
diff --git a/include/vcl/opengl/OpenGLContext.hxx b/include/vcl/opengl/OpenGLContext.hxx index 2f147623fe59..96abe498fa80 100644 --- a/include/vcl/opengl/OpenGLContext.hxx +++ b/include/vcl/opengl/OpenGLContext.hxx @@ -191,6 +191,7 @@ public: bool AcquireDefaultFramebuffer(); OpenGLFramebuffer* AcquireFramebuffer( const OpenGLTexture& rTexture ); static void ReleaseFramebuffer( OpenGLFramebuffer* pFramebuffer ); + void UnbindTextureFromFramebuffers( GLuint nTexture ); #ifdef DBG_UTIL void AddRef(SalGraphicsImpl*); void DeRef(SalGraphicsImpl*); diff --git a/vcl/inc/opengl/framebuffer.hxx b/vcl/inc/opengl/framebuffer.hxx index 385b11ac5771..5d5e870bed3d 100644 --- a/vcl/inc/opengl/framebuffer.hxx +++ b/vcl/inc/opengl/framebuffer.hxx @@ -34,6 +34,7 @@ public: static void Unbind(); bool IsFree() const; + bool IsAttached( GLuint nTexture ) const; bool IsAttached( const OpenGLTexture& rTexture ) const; void AttachTexture( const OpenGLTexture& rTexture ); void DetachTexture(); diff --git a/vcl/opengl/framebuffer.cxx b/vcl/opengl/framebuffer.cxx index 87af985f4ba4..7e19981f8078 100644 --- a/vcl/opengl/framebuffer.cxx +++ b/vcl/opengl/framebuffer.cxx @@ -46,12 +46,17 @@ void OpenGLFramebuffer::Unbind() bool OpenGLFramebuffer::IsFree() const { - return (!mnAttachedTexture); + return !mnAttachedTexture; +} + +bool OpenGLFramebuffer::IsAttached( GLuint nTexture ) const +{ + return mnAttachedTexture == nTexture; } bool OpenGLFramebuffer::IsAttached( const OpenGLTexture& rTexture ) const { - return ( mnAttachedTexture == rTexture.Id() ); + return mnAttachedTexture == rTexture.Id(); } void OpenGLFramebuffer::AttachTexture( const OpenGLTexture& rTexture ) diff --git a/vcl/opengl/texture.cxx b/vcl/opengl/texture.cxx index 4e62915151cd..217b8bf7a598 100644 --- a/vcl/opengl/texture.cxx +++ b/vcl/opengl/texture.cxx @@ -108,7 +108,17 @@ ImplOpenGLTexture::~ImplOpenGLTexture() { VCL_GL_INFO( "vcl.opengl", "~OpenGLTexture " << mnTexture ); if( mnTexture != 0 ) + { + // FIXME: this is really not optimal performance-wise. + + // Check we have been correctly un-bound from all framebuffers. + ImplSVData* pSVData = ImplGetSVData(); + OpenGLContext* pContext = pSVData->maGDIData.mpLastContext; + if (pContext) + pContext->UnbindTextureFromFramebuffers( mnTexture ); + glDeleteTextures( 1, &mnTexture ); + } } bool ImplOpenGLTexture::InsertBuffer(int nX, int nY, int nWidth, int nHeight, int nFormat, int nType, sal_uInt8* pData) diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx index 8253241795ea..cb0535623c28 100644 --- a/vcl/source/opengl/OpenGLContext.cxx +++ b/vcl/source/opengl/OpenGLContext.cxx @@ -1537,6 +1537,26 @@ OpenGLFramebuffer* OpenGLContext::AcquireFramebuffer( const OpenGLTexture& rText return pFramebuffer; } +// FIXME: this method is rather grim from a perf. perspective. +// We should instead (eventually) use pointers to associate the +// framebuffer and texture cleanly. +void OpenGLContext::UnbindTextureFromFramebuffers( GLuint nTexture ) +{ + OpenGLFramebuffer* pFramebuffer; + + // see if there is a framebuffer attached to that texture + pFramebuffer = mpLastFramebuffer; + while( pFramebuffer ) + { + if (pFramebuffer->IsAttached(nTexture)) + { + BindFramebuffer(pFramebuffer); + pFramebuffer->DetachTexture(); + } + pFramebuffer = pFramebuffer->mpPrevFramebuffer; + } +} + void OpenGLContext::ReleaseFramebuffer( OpenGLFramebuffer* pFramebuffer ) { if( pFramebuffer ) |