diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2015-08-31 12:11:50 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2015-09-01 07:41:29 +0000 |
commit | 0a3cfc66d5c82e5c44ef5220bdbe4344b9d1e2ce (patch) | |
tree | c855a53c9bf963f464262e9629b8785ae6a3853c | |
parent | 3253cc2b4ab547cc42cb9f62254ecccac40b5459 (diff) |
tdf#93751 - ensure textures are unbound from framebuffers post destroy.
Change-Id: I81aec0e6f8db57905826c54c3442528be6068700
Reviewed-on: https://gerrit.libreoffice.org/18184
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
-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 73434a0b9319..8c756b7d303e 100644 --- a/include/vcl/opengl/OpenGLContext.hxx +++ b/include/vcl/opengl/OpenGLContext.hxx @@ -193,6 +193,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 4e8f9cc152da..89bf1a42215b 100644 --- a/vcl/inc/opengl/framebuffer.hxx +++ b/vcl/inc/opengl/framebuffer.hxx @@ -35,6 +35,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 5861f76152fb..b33d990d0c00 100644 --- a/vcl/opengl/texture.cxx +++ b/vcl/opengl/texture.cxx @@ -107,7 +107,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 20b510f18f8a..8f3cce8e8243 100644 --- a/vcl/source/opengl/OpenGLContext.cxx +++ b/vcl/source/opengl/OpenGLContext.cxx @@ -1625,6 +1625,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 ) |