diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2016-04-28 19:34:37 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2016-04-30 03:07:25 +0000 |
commit | 51e953a3579fb91f30f7f0d6159b737684976959 (patch) | |
tree | 4ff44265adeb671ec8e1060a63eaa8be15dbc29d /vcl/opengl/gdiimpl.cxx | |
parent | ba0a5708803d899de4c40cfe2c1697ae83b4827a (diff) |
opengl: track the state of scissor test and the dimensions
For performance reasons we shouldn't set glScissors if it is not
necessary so we remember to what dimensions we set the glScissor
and don't set it again if this is not necessary. The same goes for
enabling/disabling the GL_SCISSOR_TEST.
Change-Id: I5e1383081b4e76bdded04525c780d3a724f9db5c
Reviewed-on: https://gerrit.libreoffice.org/24504
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/opengl/gdiimpl.cxx')
-rw-r--r-- | vcl/opengl/gdiimpl.cxx | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx index 8bb2c1dbe978..ca5f4395594f 100644 --- a/vcl/opengl/gdiimpl.cxx +++ b/vcl/opengl/gdiimpl.cxx @@ -34,6 +34,7 @@ #include "svdata.hxx" #include "opengl/zone.hxx" #include "opengl/salbmp.hxx" +#include "opengl/RenderState.hxx" #include <vector> @@ -233,11 +234,6 @@ void OpenGLSalGraphicsImpl::PostDraw() CHECK_GL_ERROR(); } - if( mbUseScissor ) - { - glDisable( GL_SCISSOR_TEST ); - CHECK_GL_ERROR(); - } if( mbUseStencil ) { glDisable( GL_STENCIL_TEST ); @@ -274,6 +270,7 @@ void OpenGLSalGraphicsImpl::freeResources() VCL_GL_INFO( "freeResources" ); mpContext->makeCurrent(); FlushDeferredDrawing(); + mpContext->state()->scissor().disable(); mpContext->ReleaseFramebuffer( maOffscreenTex ); } ReleaseContext(); @@ -327,27 +324,27 @@ void OpenGLSalGraphicsImpl::ImplSetClipBit( const vcl::Region& rClip, GLuint nMa void OpenGLSalGraphicsImpl::ImplInitClipRegion() { // make sure the context has the right clipping set - if( maClipRegion != mpContext->maClipRegion ) + if (maClipRegion != mpContext->maClipRegion) { mpContext->maClipRegion = maClipRegion; - if( mbUseScissor ) - { - Rectangle aRect( maClipRegion.GetBoundRect() ); - glScissor( aRect.Left(), GetHeight() - aRect.Bottom() - 1, aRect.GetWidth(), aRect.GetHeight() ); - CHECK_GL_ERROR(); - } - else if( !maClipRegion.IsEmpty() ) + if (mbUseStencil) { - ImplSetClipBit( maClipRegion, 0x01 ); + ImplSetClipBit(maClipRegion, 0x01); } } - if( mbUseScissor ) + if (mbUseScissor) { - glEnable( GL_SCISSOR_TEST ); - CHECK_GL_ERROR(); + Rectangle aRect(maClipRegion.GetBoundRect()); + mpContext->state()->scissor().set(aRect.Left(), GetHeight() - aRect.Bottom() - 1, aRect.GetWidth(), aRect.GetHeight()); + mpContext->state()->scissor().enable(); } - if( mbUseStencil ) + else + { + mpContext->state()->scissor().disable(); + } + + if (mbUseStencil) { glStencilFunc( GL_EQUAL, 1, 0x1 ); CHECK_GL_ERROR(); @@ -377,9 +374,9 @@ bool OpenGLSalGraphicsImpl::setClipRegion( const vcl::Region& rClip ) mbUseStencil = false; mbUseScissor = false; - if( maClipRegion.IsRectangle() ) + if (maClipRegion.IsRectangle()) mbUseScissor = true; - else if ( !maClipRegion.IsEmpty() ) + else if (!maClipRegion.IsEmpty()) mbUseStencil = true; return true; @@ -1503,7 +1500,7 @@ void OpenGLSalGraphicsImpl::DrawTransformedTexture( // The scissor area is set to the current window size in PreDraw, // so if we do not disable the scissor test, the texture produced // by the first downscaling is clipped to the current window size. - glDisable(GL_SCISSOR_TEST); + mpContext->state()->scissor().disable(); CHECK_GL_ERROR(); // Maybe it can give problems too. @@ -1529,10 +1526,8 @@ void OpenGLSalGraphicsImpl::DrawTransformedTexture( // Re-enable scissor and stencil tests if needed. if (mbUseScissor) - { - glEnable(GL_SCISSOR_TEST); - CHECK_GL_ERROR(); - } + mpContext->state()->scissor().enable(); + if (mbUseStencil) { glEnable(GL_STENCIL_TEST); @@ -2511,6 +2506,8 @@ void OpenGLSalGraphicsImpl::flush() { FlushDeferredDrawing(); + mpContext->state()->scissor().disable(); + if( IsOffscreen() ) return; @@ -2527,6 +2524,8 @@ void OpenGLSalGraphicsImpl::doFlush() { FlushDeferredDrawing(); + mpContext->state()->scissor().disable(); + if( IsOffscreen() ) return; @@ -2570,6 +2569,8 @@ void OpenGLSalGraphicsImpl::doFlush() glViewport( 0, 0, GetWidth(), GetHeight() ); CHECK_GL_ERROR(); + mpWindowContext->state()->scissor().disable(); + #if OSL_DEBUG_LEVEL > 0 // random background glClear glClearColor((float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, 1.0); |