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 | |
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')
-rw-r--r-- | vcl/inc/opengl/RenderState.hxx | 58 | ||||
-rw-r--r-- | vcl/opengl/gdiimpl.cxx | 51 | ||||
-rw-r--r-- | vcl/opengl/salbmp.cxx | 10 | ||||
-rw-r--r-- | vcl/opengl/scale.cxx | 2 |
4 files changed, 94 insertions, 27 deletions
diff --git a/vcl/inc/opengl/RenderState.hxx b/vcl/inc/opengl/RenderState.hxx index a184f2ebe41b..7b3db7bec548 100644 --- a/vcl/inc/opengl/RenderState.hxx +++ b/vcl/inc/opengl/RenderState.hxx @@ -13,15 +13,73 @@ #include "opengl/TextureState.hxx" +class ScissorState +{ + bool mbTest; + int mX; + int mY; + int mWidth; + int mHeight; + +public: + + ScissorState() + : mbTest(false) + , mX(0) + , mY(0) + , mWidth(0) + , mHeight(0) + { + glDisable(GL_SCISSOR_TEST); + CHECK_GL_ERROR(); + } + + void set(int x, int y, int width, int height) + { + if (x != mX || y != mY || width != mWidth || height != mHeight) + { + glScissor(x, y, width, height); + CHECK_GL_ERROR(); + + mX = x; + mY = y; + mWidth = width; + mHeight = height; + } + } + + void enable() + { + if (!mbTest) + { + glEnable(GL_SCISSOR_TEST); + CHECK_GL_ERROR(); + mbTest = true; + } + } + + void disable() + { + if (mbTest) + { + glDisable(GL_SCISSOR_TEST); + CHECK_GL_ERROR(); + mbTest = false; + } + } +}; + class RenderState { TextureState maTexture; + ScissorState maScissor; public: RenderState() {} TextureState& texture() { return maTexture; } + ScissorState& scissor() { return maScissor; } }; #endif // INCLUDED_VCL_INC_OPENGL_RENDER_STATE_H 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); diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx index 13444e6fa254..1cc17d1f8321 100644 --- a/vcl/opengl/salbmp.cxx +++ b/vcl/opengl/salbmp.cxx @@ -35,7 +35,7 @@ #include "opengl/zone.hxx" #include "opengl/program.hxx" #include "opengl/salbmp.hxx" - +#include "opengl/RenderState.hxx" #include "opengl/FixedTextureAtlas.hxx" #if OSL_DEBUG_LEVEL > 0 @@ -539,6 +539,9 @@ bool OpenGLSalBitmap::ReadTexture() OpenGLVCLContextZone aContextZone; + rtl::Reference<OpenGLContext> xContext = OpenGLContext::getVCLContext(); + xContext->state()->scissor().disable(); + if (mnBits == 8 || mnBits == 16 || mnBits == 24 || mnBits == 32) { determineTextureFormat(mnBits, nFormat, nType); @@ -620,6 +623,7 @@ bool OpenGLSalBitmap::calcChecksumGL(OpenGLTexture& rInputTexture, ChecksumType& OUString FragShader("areaHashCRC64TFragmentShader"); rtl::Reference< OpenGLContext > xContext = OpenGLContext::getVCLContext(); + xContext->state()->scissor().disable(); static vcl::DeleteOnDeinit<OpenGLTexture> gCRCTableTexture( new OpenGLTexture(512, 1, GL_RGBA, GL_UNSIGNED_BYTE, @@ -887,7 +891,8 @@ bool OpenGLSalBitmap::Replace( const Color& rSearchColor, const Color& rReplaceC VCL_GL_INFO("::Replace"); OpenGLZone aZone; - rtl::Reference< OpenGLContext > xContext = OpenGLContext::getVCLContext(); + rtl::Reference<OpenGLContext> xContext = OpenGLContext::getVCLContext(); + xContext->state()->scissor().disable(); OpenGLFramebuffer* pFramebuffer; OpenGLProgram* pProgram; @@ -926,6 +931,7 @@ bool OpenGLSalBitmap::ConvertToGreyscale() OpenGLZone aZone; rtl::Reference<OpenGLContext> xContext = OpenGLContext::getVCLContext(); + xContext->state()->scissor().disable(); OpenGLFramebuffer* pFramebuffer; OpenGLProgram* pProgram; diff --git a/vcl/opengl/scale.cxx b/vcl/opengl/scale.cxx index 795090a9a24b..61ecf31a6221 100644 --- a/vcl/opengl/scale.cxx +++ b/vcl/opengl/scale.cxx @@ -27,6 +27,7 @@ #include "opengl/salbmp.hxx" #include "opengl/program.hxx" #include "opengl/texture.hxx" +#include "opengl/RenderState.hxx" #include <ResampleKernel.hxx> @@ -327,6 +328,7 @@ bool OpenGLSalBitmap::ImplScale( const double& rScaleX, const double& rScaleY, B mpUserBuffer.reset(); OpenGLVCLContextZone aContextZone; rtl::Reference<OpenGLContext> xContext = OpenGLContext::getVCLContext(); + xContext->state()->scissor().disable(); if (rScaleX <= 1 && rScaleY <= 1) { |