[Libreoffice-commits] core.git: vcl/inc vcl/opengl
Tomaž Vajngerl
tomaz.vajngerl at collabora.co.uk
Sat Apr 30 03:08:16 UTC 2016
vcl/inc/opengl/RenderState.hxx | 35 +++++++++++++++++++++++++++++++++++
vcl/opengl/gdiimpl.cxx | 33 ++++++++++++++-------------------
vcl/opengl/salbmp.cxx | 4 ++++
vcl/opengl/scale.cxx | 1 +
4 files changed, 54 insertions(+), 19 deletions(-)
New commits:
commit b8f0e6452cc019744c44997c92831d94086b35b7
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Thu Apr 28 20:01:28 2016 +0900
opengl: track the state of stencil test
Change-Id: Id3e15e91316df740f04a42ed8c95b77d83240b5a
Reviewed-on: https://gerrit.libreoffice.org/24505
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
Tested-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/vcl/inc/opengl/RenderState.hxx b/vcl/inc/opengl/RenderState.hxx
index 7b3db7be..b1b0b18 100644
--- a/vcl/inc/opengl/RenderState.hxx
+++ b/vcl/inc/opengl/RenderState.hxx
@@ -69,10 +69,44 @@ public:
}
};
+class StencilState
+{
+ bool mbTest;
+public:
+
+ StencilState()
+ : mbTest(false)
+ {
+ glDisable(GL_STENCIL_TEST);
+ CHECK_GL_ERROR();
+ }
+
+ void enable()
+ {
+ if (!mbTest)
+ {
+ glEnable(GL_STENCIL_TEST);
+ CHECK_GL_ERROR();
+ mbTest = true;
+ }
+ }
+
+ void disable()
+ {
+ if (mbTest)
+ {
+ glDisable(GL_STENCIL_TEST);
+ CHECK_GL_ERROR();
+ mbTest = false;
+ }
+ }
+};
+
class RenderState
{
TextureState maTexture;
ScissorState maScissor;
+ StencilState maStencil;
public:
RenderState()
@@ -80,6 +114,7 @@ public:
TextureState& texture() { return maTexture; }
ScissorState& scissor() { return maScissor; }
+ StencilState& stencil() { return maStencil; }
};
#endif // INCLUDED_VCL_INC_OPENGL_RENDER_STATE_H
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index ca5f439..70b2d65 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -234,11 +234,6 @@ void OpenGLSalGraphicsImpl::PostDraw()
CHECK_GL_ERROR();
}
- if( mbUseStencil )
- {
- glDisable( GL_STENCIL_TEST );
- CHECK_GL_ERROR();
- }
if( mpProgram )
{
mpProgram->Clean();
@@ -271,6 +266,7 @@ void OpenGLSalGraphicsImpl::freeResources()
mpContext->makeCurrent();
FlushDeferredDrawing();
mpContext->state()->scissor().disable();
+ mpContext->state()->stencil().disable();
mpContext->ReleaseFramebuffer( maOffscreenTex );
}
ReleaseContext();
@@ -278,7 +274,7 @@ void OpenGLSalGraphicsImpl::freeResources()
void OpenGLSalGraphicsImpl::ImplSetClipBit( const vcl::Region& rClip, GLuint nMask )
{
- glEnable( GL_STENCIL_TEST );
+ mpContext->state()->stencil().enable();
VCL_GL_INFO( "Adding complex clip / stencil" );
GLuint nStencil = maOffscreenTex.StencilId();
@@ -317,8 +313,8 @@ void OpenGLSalGraphicsImpl::ImplSetClipBit( const vcl::Region& rClip, GLuint nMa
CHECK_GL_ERROR();
glStencilMask( 0x00 );
CHECK_GL_ERROR();
- glDisable( GL_STENCIL_TEST );
- CHECK_GL_ERROR();
+
+ mpContext->state()->stencil().disable();
}
void OpenGLSalGraphicsImpl::ImplInitClipRegion()
@@ -348,8 +344,11 @@ void OpenGLSalGraphicsImpl::ImplInitClipRegion()
{
glStencilFunc( GL_EQUAL, 1, 0x1 );
CHECK_GL_ERROR();
- glEnable( GL_STENCIL_TEST );
- CHECK_GL_ERROR();
+ mpContext->state()->stencil().enable();
+ }
+ else
+ {
+ mpContext->state()->stencil().disable();
}
}
@@ -1501,11 +1500,7 @@ void OpenGLSalGraphicsImpl::DrawTransformedTexture(
// so if we do not disable the scissor test, the texture produced
// by the first downscaling is clipped to the current window size.
mpContext->state()->scissor().disable();
- CHECK_GL_ERROR();
-
- // Maybe it can give problems too.
- glDisable(GL_STENCIL_TEST);
- CHECK_GL_ERROR();
+ mpContext->state()->stencil().disable();
// the square root of the whole inverted scale ratio
double ixscalesqrt = std::floor(std::sqrt(ixscale));
@@ -1529,10 +1524,7 @@ void OpenGLSalGraphicsImpl::DrawTransformedTexture(
mpContext->state()->scissor().enable();
if (mbUseStencil)
- {
- glEnable(GL_STENCIL_TEST);
- CHECK_GL_ERROR();
- }
+ mpContext->state()->stencil().enable();
}
}
@@ -2507,6 +2499,7 @@ void OpenGLSalGraphicsImpl::flush()
FlushDeferredDrawing();
mpContext->state()->scissor().disable();
+ mpContext->state()->stencil().disable();
if( IsOffscreen() )
return;
@@ -2525,6 +2518,7 @@ void OpenGLSalGraphicsImpl::doFlush()
FlushDeferredDrawing();
mpContext->state()->scissor().disable();
+ mpContext->state()->stencil().disable();
if( IsOffscreen() )
return;
@@ -2570,6 +2564,7 @@ void OpenGLSalGraphicsImpl::doFlush()
CHECK_GL_ERROR();
mpWindowContext->state()->scissor().disable();
+ mpWindowContext->state()->stencil().disable();
#if OSL_DEBUG_LEVEL > 0 // random background glClear
glClearColor((float)rand()/RAND_MAX, (float)rand()/RAND_MAX,
diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index 1cc17d1..b9b7a5f 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -541,6 +541,7 @@ bool OpenGLSalBitmap::ReadTexture()
rtl::Reference<OpenGLContext> xContext = OpenGLContext::getVCLContext();
xContext->state()->scissor().disable();
+ xContext->state()->stencil().disable();
if (mnBits == 8 || mnBits == 16 || mnBits == 24 || mnBits == 32)
{
@@ -624,6 +625,7 @@ bool OpenGLSalBitmap::calcChecksumGL(OpenGLTexture& rInputTexture, ChecksumType&
rtl::Reference< OpenGLContext > xContext = OpenGLContext::getVCLContext();
xContext->state()->scissor().disable();
+ xContext->state()->stencil().disable();
static vcl::DeleteOnDeinit<OpenGLTexture> gCRCTableTexture(
new OpenGLTexture(512, 1, GL_RGBA, GL_UNSIGNED_BYTE,
@@ -893,6 +895,7 @@ bool OpenGLSalBitmap::Replace( const Color& rSearchColor, const Color& rReplaceC
OpenGLZone aZone;
rtl::Reference<OpenGLContext> xContext = OpenGLContext::getVCLContext();
xContext->state()->scissor().disable();
+ xContext->state()->stencil().disable();
OpenGLFramebuffer* pFramebuffer;
OpenGLProgram* pProgram;
@@ -932,6 +935,7 @@ bool OpenGLSalBitmap::ConvertToGreyscale()
OpenGLZone aZone;
rtl::Reference<OpenGLContext> xContext = OpenGLContext::getVCLContext();
xContext->state()->scissor().disable();
+ xContext->state()->stencil().disable();
OpenGLFramebuffer* pFramebuffer;
OpenGLProgram* pProgram;
diff --git a/vcl/opengl/scale.cxx b/vcl/opengl/scale.cxx
index 61ecf31..9feb933 100644
--- a/vcl/opengl/scale.cxx
+++ b/vcl/opengl/scale.cxx
@@ -329,6 +329,7 @@ bool OpenGLSalBitmap::ImplScale( const double& rScaleX, const double& rScaleY, B
OpenGLVCLContextZone aContextZone;
rtl::Reference<OpenGLContext> xContext = OpenGLContext::getVCLContext();
xContext->state()->scissor().disable();
+ xContext->state()->stencil().disable();
if (rScaleX <= 1 && rScaleY <= 1)
{
More information about the Libreoffice-commits
mailing list