diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2016-04-29 17:07:11 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2016-04-30 03:08:08 +0000 |
commit | a57d048f88ba6cac3ce1550e2a8a143a8887eb05 (patch) | |
tree | 9539c3447fc838c098cd78cb86d9c9473aacf9b1 /vcl/inc | |
parent | b8f0e6452cc019744c44997c92831d94086b35b7 (diff) |
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
Reviewed-on: https://gerrit.libreoffice.org/24506
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/inc')
-rw-r--r-- | vcl/inc/opengl/RenderState.hxx | 122 |
1 files changed, 72 insertions, 50 deletions
diff --git a/vcl/inc/opengl/RenderState.hxx b/vcl/inc/opengl/RenderState.hxx index b1b0b1805f4a..eeac1a508d3e 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 |