vcl/inc/opengl/RenderState.hxx | 134 ++++++++++++++++++++++-------------- vcl/opengl/gdiimpl.cxx | 19 ++--- vcl/source/opengl/OpenGLContext.cxx | 5 - 3 files changed, 96 insertions(+), 62 deletions(-)
New commits: commit 2712237ffc1f56be3f1de8dbc80d05766c780729 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Fri Apr 29 17:17:09 2016 +0900 opengl: track the state of glViewport We don't want to set the viewport over and over again. Change-Id: I60b84a009d4058743e30587616604f9b6fc0f601 diff --git a/vcl/inc/opengl/RenderState.hxx b/vcl/inc/opengl/RenderState.hxx index eeac1a50..ac215a8 100644 --- a/vcl/inc/opengl/RenderState.hxx +++ b/vcl/inc/opengl/RenderState.hxx @@ -123,10 +123,22 @@ class RenderState ScissorState maScissor; StencilState maStencil; + Rectangle maCurrentViewport; + public: RenderState() {} + void viewport(Rectangle aViewPort) + { + if (aViewPort != maCurrentViewport) + { + glViewport(aViewPort.Left(), aViewPort.Top(), aViewPort.GetWidth(), aViewPort.GetHeight()); + CHECK_GL_ERROR(); + maCurrentViewport = aViewPort; + } + } + TextureState& texture() { return maTexture; } ScissorState& scissor() { return maScissor; } StencilState& stencil() { return maStencil; } diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx index 4636e13..d9640b9 100644 --- a/vcl/opengl/gdiimpl.cxx +++ b/vcl/opengl/gdiimpl.cxx @@ -209,8 +209,7 @@ void OpenGLSalGraphicsImpl::InitializePreDrawState(XOROption eOpt) CheckOffscreenTexture(); CHECK_GL_ERROR(); - glViewport( 0, 0, GetWidth(), GetHeight() ); - CHECK_GL_ERROR(); + mpContext->state()->viewport(Rectangle(Point(0, 0), Size(GetWidth(), GetHeight()))); ImplInitClipRegion(); CHECK_GL_ERROR(); @@ -2543,9 +2542,7 @@ void OpenGLSalGraphicsImpl::doFlush() mpWindowContext->AcquireDefaultFramebuffer(); CHECK_GL_ERROR(); - glViewport( 0, 0, GetWidth(), GetHeight() ); - CHECK_GL_ERROR(); - + mpWindowContext->state()->viewport(Rectangle(Point(0, 0), Size(GetWidth(), GetHeight()))); mpWindowContext->state()->scissor().disable(); mpWindowContext->state()->stencil().disable(); diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx index 38a49e5..1ac5f4d 100644 --- a/vcl/source/opengl/OpenGLContext.cxx +++ b/vcl/source/opengl/OpenGLContext.cxx @@ -1683,8 +1683,8 @@ OpenGLFramebuffer* OpenGLContext::AcquireFramebuffer( const OpenGLTexture& rText assert( pFramebuffer ); BindFramebuffer( pFramebuffer ); pFramebuffer->AttachTexture( rTexture ); - glViewport( 0, 0, rTexture.GetWidth(), rTexture.GetHeight() ); - CHECK_GL_ERROR(); + + state()->viewport(Rectangle(Point(), Size(rTexture.GetWidth(), rTexture.GetHeight()))); return pFramebuffer; } commit 65c6f5e3a5ccf81f90b3bb7d5c46d967ee5ef4e3 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Fri Apr 29 17:07:11 2016 +0900 opengl: sync scissor and stencil state, generic capability state Scissor and stencil test needed to be disabled in flush() (which means every postDraw call) because sometimes the state became out of sync with the current state. This commit adds sync() function which synchronises the actual OpenGL state and adds debugging mechanisms to warn when the state becomes out of sync (so we can inspect the exact moment in apitrace). Added a GenericCapabilityState for GL capabilities like GL_SCISSORS_TEST, GL_STENCIL_TEST, GL_BLEND,... and refactored existing ScissorState and StencilState to inherit from it. Change-Id: Ifc159108a5ce850c78a89b1f5b8d12ecdd84f459 diff --git a/vcl/inc/opengl/RenderState.hxx b/vcl/inc/opengl/RenderState.hxx index b1b0b18..eeac1a50 100644 --- a/vcl/inc/opengl/RenderState.hxx +++ b/vcl/inc/opengl/RenderState.hxx @@ -13,95 +13,110 @@ #include "opengl/TextureState.hxx" -class ScissorState +template<GLenum ENUM_TYPE, typename TYPE> +class GenericCapabilityState { +protected: bool mbTest; - int mX; - int mY; - int mWidth; - int mHeight; -public: - - ScissorState() - : mbTest(false) - , mX(0) - , mY(0) - , mWidth(0) - , mHeight(0) + bool readState() { - glDisable(GL_SCISSOR_TEST); - CHECK_GL_ERROR(); - } + return (glIsEnabled(ENUM_TYPE) == GL_TRUE); + }; - void set(int x, int y, int width, int height) +public: + void sync() { - 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; - } + mbTest = readState(); } void enable() { if (!mbTest) { - glEnable(GL_SCISSOR_TEST); + glEnable(ENUM_TYPE); CHECK_GL_ERROR(); mbTest = true; } + else + { + VCL_GL_INFO(TYPE::className() << ": enable called but already set"); + } +#ifdef DBG_UTIL + checkState(); +#endif } void disable() { if (mbTest) { - glDisable(GL_SCISSOR_TEST); + glDisable(ENUM_TYPE); CHECK_GL_ERROR(); mbTest = false; } + else + { + VCL_GL_INFO(TYPE::className() << ": disable called but already set"); + } +#ifdef DBG_UTIL + checkState(); +#endif } + +#ifdef DBG_UTIL + void checkState() + { + bool bRealState = readState(); + if (mbTest != bRealState) + { + VCL_GL_INFO(TYPE::className() << " mismatch! " + << "Expected: " << (mbTest ? "enabled" : "disabled") + << " but is: " << (bRealState ? "enabled" : "disabled")); + } + } +#endif }; -class StencilState +class ScissorState : public GenericCapabilityState<GL_SCISSOR_TEST, ScissorState> { - bool mbTest; +private: + int mX; + int mY; + int mWidth; + int mHeight; + public: + static std::string className() { return std::string("ScissorState"); } - StencilState() - : mbTest(false) - { - glDisable(GL_STENCIL_TEST); - CHECK_GL_ERROR(); - } + ScissorState() + : mX(0) + , mY(0) + , mWidth(0) + , mHeight(0) + {} - void enable() + void set(int x, int y, int width, int height) { - if (!mbTest) + if (x != mX || y != mY || width != mWidth || height != mHeight) { - glEnable(GL_STENCIL_TEST); + glScissor(x, y, width, height); CHECK_GL_ERROR(); - mbTest = true; - } - } - void disable() - { - if (mbTest) - { - glDisable(GL_STENCIL_TEST); - CHECK_GL_ERROR(); - mbTest = false; + mX = x; + mY = y; + mWidth = width; + mHeight = height; } } }; +class StencilState : public GenericCapabilityState<GL_STENCIL_TEST, StencilState> +{ +public: + static std::string className() { return std::string("StencilState"); } +}; + class RenderState { TextureState maTexture; @@ -115,6 +130,13 @@ public: TextureState& texture() { return maTexture; } ScissorState& scissor() { return maScissor; } StencilState& stencil() { return maStencil; } + + void sync() + { + VCL_GL_INFO("RenderState::sync"); + maScissor.sync(); + maStencil.sync(); + } }; #endif // INCLUDED_VCL_INC_OPENGL_RENDER_STATE_H diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx index 3eb72d4..4636e13 100644 --- a/vcl/opengl/gdiimpl.cxx +++ b/vcl/opengl/gdiimpl.cxx @@ -263,8 +263,6 @@ void OpenGLSalGraphicsImpl::freeResources() VCL_GL_INFO( "freeResources" ); mpContext->makeCurrent(); FlushDeferredDrawing(); - mpContext->state()->scissor().disable(); - mpContext->state()->stencil().disable(); mpContext->ReleaseFramebuffer( maOffscreenTex ); } ReleaseContext(); @@ -272,6 +270,7 @@ void OpenGLSalGraphicsImpl::freeResources() void OpenGLSalGraphicsImpl::ImplSetClipBit( const vcl::Region& rClip, GLuint nMask ) { + mpContext->state()->scissor().disable(); mpContext->state()->stencil().enable(); VCL_GL_INFO( "Adding complex clip / stencil" ); @@ -497,6 +496,10 @@ bool OpenGLSalGraphicsImpl::CheckOffscreenTexture() // TODO: lfrb: User GL_ARB_copy_image? OpenGLTexture aNewTex = OpenGLTexture( GetWidth(), GetHeight() ); + + mpContext->state()->scissor().disable(); + mpContext->state()->stencil().disable(); + mpFramebuffer = mpContext->AcquireFramebuffer( aNewTex ); DrawTexture( maOffscreenTex, aPosAry ); maOffscreenTex = aNewTex; @@ -2479,9 +2482,6 @@ void OpenGLSalGraphicsImpl::flush() { FlushDeferredDrawing(); - mpContext->state()->scissor().disable(); - mpContext->state()->stencil().disable(); - if( IsOffscreen() ) return; @@ -2538,6 +2538,8 @@ void OpenGLSalGraphicsImpl::doFlush() VCL_GL_INFO( "flushAndSwap - acquire default framebuffer" ); + mpWindowContext->state()->sync(); + mpWindowContext->AcquireDefaultFramebuffer(); CHECK_GL_ERROR(); diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx index 69e185e..38a49e5 100644 --- a/vcl/source/opengl/OpenGLContext.cxx +++ b/vcl/source/opengl/OpenGLContext.cxx @@ -1228,6 +1228,7 @@ void OpenGLContext::reset() // reset the clip region maClipRegion.SetEmpty(); + mpRenderState.reset(new RenderState); // destroy all framebuffers if( mpLastFramebuffer )
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits