From 694f3c91b99a264cd2b87bc431bb45331154b837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 16 Apr 2017 16:07:31 -0300 Subject: [PATCH] Refactored 2d clip planes stack. --HG-- branch : dev --- include/eepp/graphics/drawable.hpp | 4 +-- include/eepp/graphics/primitivedrawable.hpp | 4 +-- .../eepp/graphics/renderer/clippingmask.hpp | 2 ++ include/eepp/graphics/renderer/renderer.hpp | 2 -- src/eepp/graphics/renderer/clippingmask.cpp | 28 +++++++++++++++++-- src/eepp/graphics/renderer/renderer.cpp | 1 - src/eepp/graphics/renderer/renderergl.cpp | 28 +++---------------- src/eepp/graphics/renderer/renderergl3.cpp | 28 +++---------------- src/eepp/graphics/renderer/renderergl3cp.cpp | 28 +++---------------- src/eepp/graphics/renderer/renderergles2.cpp | 28 +++---------------- 10 files changed, 48 insertions(+), 105 deletions(-) diff --git a/include/eepp/graphics/drawable.hpp b/include/eepp/graphics/drawable.hpp index b8f89fa05..8ab0ba728 100644 --- a/include/eepp/graphics/drawable.hpp +++ b/include/eepp/graphics/drawable.hpp @@ -11,8 +11,6 @@ namespace EE { namespace Graphics { class EE_API Drawable { public: - Drawable( EE_DRAWABLE_TYPE drawableType ); - virtual Sizef getSize() = 0; virtual void draw() = 0; @@ -49,6 +47,8 @@ class EE_API Drawable { Color mColor; Vector2f mPosition; + Drawable( EE_DRAWABLE_TYPE drawableType ); + virtual void onAlphaChange(); virtual void onColorFilterChange(); diff --git a/include/eepp/graphics/primitivedrawable.hpp b/include/eepp/graphics/primitivedrawable.hpp index f6f48881e..dce4bcd60 100644 --- a/include/eepp/graphics/primitivedrawable.hpp +++ b/include/eepp/graphics/primitivedrawable.hpp @@ -9,8 +9,6 @@ class VertexBuffer; class EE_API PrimitiveDrawable : public Drawable { public: - PrimitiveDrawable( EE_DRAWABLE_TYPE drawableType ); - virtual ~PrimitiveDrawable(); virtual void draw( const Vector2f& position, const Sizef& size ); @@ -33,6 +31,8 @@ class EE_API PrimitiveDrawable : public Drawable { /** @return The line with to draw primitives */ const Float& getLineWidth() const; protected: + PrimitiveDrawable( EE_DRAWABLE_TYPE drawableType ); + EE_FILL_MODE mFillMode; EE_BLEND_MODE mBlendMode; Float mLineWidth; diff --git a/include/eepp/graphics/renderer/clippingmask.hpp b/include/eepp/graphics/renderer/clippingmask.hpp index 313f17e0a..388a34d84 100644 --- a/include/eepp/graphics/renderer/clippingmask.hpp +++ b/include/eepp/graphics/renderer/clippingmask.hpp @@ -48,7 +48,9 @@ class EE_API ClippingMask { void stencilMaskDisable( bool clearMasks = false ); protected: std::list mScissorsClipped; + std::list mPlanesClipped; bool mPushScissorClip; + bool mPushClip; std::vector mDrawables; Mode mMode; diff --git a/include/eepp/graphics/renderer/renderer.hpp b/include/eepp/graphics/renderer/renderer.hpp index 6382c350e..6ec337597 100644 --- a/include/eepp/graphics/renderer/renderer.hpp +++ b/include/eepp/graphics/renderer/renderer.hpp @@ -223,14 +223,12 @@ class EE_API Renderer { Uint32 mExtensions; Uint32 mStateFlags; - bool mPushClip; bool mQuadsSupported; bool mBlendEnabled; int mQuadVertexs; float mLineWidth; unsigned int mCurVAO; - std::list mPlanesClipped; ClippingMask * mClippingMask; private: void writeExtension( Uint8 Pos, Uint32 BitWrite ); diff --git a/src/eepp/graphics/renderer/clippingmask.cpp b/src/eepp/graphics/renderer/clippingmask.cpp index cc881ba25..ccd64c5dc 100644 --- a/src/eepp/graphics/renderer/clippingmask.cpp +++ b/src/eepp/graphics/renderer/clippingmask.cpp @@ -48,12 +48,36 @@ void ClippingMask::clipDisable() { void ClippingMask::clipPlaneEnable( const Int32& x, const Int32& y, const Int32& Width, const Int32& Height ) { GlobalBatchRenderer::instance()->draw(); - GLi->clip2DPlaneEnable( x, y, Width, Height ); + + Rectf r( x, y, x + Width, y + Height ); + + if ( !mPlanesClipped.empty() ) { + Rectf r2 = mPlanesClipped.back(); + r.shrink( r2 ); + } + + GLi->clip2DPlaneEnable( r.Left, r.Top, r.getWidth(), r.getHeight() ); + + if ( mPushClip ) { + mPlanesClipped.push_back( r ); + } } void ClippingMask::clipPlaneDisable() { GlobalBatchRenderer::instance()->draw(); - GLi->clip2DPlaneDisable(); + + if ( ! mPlanesClipped.empty() ) { // This should always be true + mPlanesClipped.pop_back(); + } + + if ( mPlanesClipped.empty() ) { + GLi->clip2DPlaneDisable(); + } else { + Rectf R( mPlanesClipped.back() ); + mPushClip = false; + clipPlaneEnable( R.Left, R.Top, R.getWidth(), R.getHeight() ); + mPushClip = true; + } } ClippingMask::ClippingMask() : diff --git a/src/eepp/graphics/renderer/renderer.cpp b/src/eepp/graphics/renderer/renderer.cpp index beb14a245..d14bb7141 100644 --- a/src/eepp/graphics/renderer/renderer.cpp +++ b/src/eepp/graphics/renderer/renderer.cpp @@ -110,7 +110,6 @@ void Renderer::destroySingleton() { Renderer::Renderer() : mExtensions(0), mStateFlags( 1 << RSF_LINE_SMOOTH ), - mPushClip( true ), mQuadsSupported( true ), mBlendEnabled( false ), mQuadVertexs( 4 ), diff --git a/src/eepp/graphics/renderer/renderergl.cpp b/src/eepp/graphics/renderer/renderergl.cpp index bee71f5c6..78dc7e872 100644 --- a/src/eepp/graphics/renderer/renderergl.cpp +++ b/src/eepp/graphics/renderer/renderergl.cpp @@ -231,11 +231,6 @@ void RendererGL::pointSize( float size ) { void RendererGL::clip2DPlaneEnable( const Int32& x, const Int32& y, const Int32& Width, const Int32& Height ) { Rectf r( x, y, x + Width, y + Height ); - if ( !mPlanesClipped.empty() ) { - Rectf r2 = mPlanesClipped.back(); - r.shrink( r2 ); - } - double clip_left[] = { 1.0 , 0.0 , 0.0, -r.Left }; double clip_right[] = { -1.0, 0.0 , 0.0, r.Right }; double clip_top[] = { 0.0 , 1.0 , 0.0, -r.Top }; @@ -250,28 +245,13 @@ void RendererGL::clip2DPlaneEnable( const Int32& x, const Int32& y, const Int32& clipPlane(GL_CLIP_PLANE1, clip_right); clipPlane(GL_CLIP_PLANE2, clip_top); clipPlane(GL_CLIP_PLANE3, clip_bottom); - - if ( mPushClip ) { - mPlanesClipped.push_back( r ); - } } void RendererGL::clip2DPlaneDisable() { - if ( ! mPlanesClipped.empty() ) { // This should always be true - mPlanesClipped.pop_back(); - } - - if ( mPlanesClipped.empty() ) { - GLi->disable(GL_CLIP_PLANE0); - GLi->disable(GL_CLIP_PLANE1); - GLi->disable(GL_CLIP_PLANE2); - GLi->disable(GL_CLIP_PLANE3); - } else { - Rectf R( mPlanesClipped.back() ); - mPushClip = false; - clip2DPlaneEnable( R.Left, R.Top, R.getWidth(), R.getHeight() ); - mPushClip = true; - } + GLi->disable(GL_CLIP_PLANE0); + GLi->disable(GL_CLIP_PLANE1); + GLi->disable(GL_CLIP_PLANE2); + GLi->disable(GL_CLIP_PLANE3); } void RendererGL::clipPlane( unsigned int plane, const double *equation ) { diff --git a/src/eepp/graphics/renderer/renderergl3.cpp b/src/eepp/graphics/renderer/renderergl3.cpp index 13f3b799f..63996c124 100644 --- a/src/eepp/graphics/renderer/renderergl3.cpp +++ b/src/eepp/graphics/renderer/renderergl3.cpp @@ -543,11 +543,6 @@ void RendererGL3::matrixMode(unsigned int mode) { void RendererGL3::clip2DPlaneEnable( const Int32& x, const Int32& y, const Int32& Width, const Int32& Height ) { Rectf r( x, y, x + Width, y + Height ); - if ( !mPlanesClipped.empty() ) { - Rectf r2 = mPlanesClipped.back(); - r.shrink( r2 ); - } - glm::vec4 vclip_left ( 1.0 , 0.0 , 0.0 , -r.Left ); glm::vec4 vclip_right ( -1.0 , 0.0 , 0.0 , r.Right ); glm::vec4 vclip_top ( 0.0 , 1.0 , 0.0 , -r.Top ); @@ -569,28 +564,13 @@ void RendererGL3::clip2DPlaneEnable( const Int32& x, const Int32& y, const Int32 glUniform4fv( mPlanes[1], 1, static_cast( &vclip_right[0] ) ); glUniform4fv( mPlanes[2], 1, static_cast( &vclip_top[0] ) ); glUniform4fv( mPlanes[3], 1, static_cast( &vclip_bottom[0] ) ); - - if ( mPushClip ) { - mPlanesClipped.push_back( r ); - } } void RendererGL3::clip2DPlaneDisable() { - if ( ! mPlanesClipped.empty() ) { // This should always be true - mPlanesClipped.pop_back(); - } - - if ( mPlanesClipped.empty() ) { - GLi->disable(GL_CLIP_PLANE0); - GLi->disable(GL_CLIP_PLANE1); - GLi->disable(GL_CLIP_PLANE2); - GLi->disable(GL_CLIP_PLANE3); - } else { - Rectf R( mPlanesClipped.back() ); - mPushClip = false; - clip2DPlaneEnable( R.Left, R.Top, R.getWidth(), R.getHeight() ); - mPushClip = true; - } + GLi->disable(GL_CLIP_PLANE0); + GLi->disable(GL_CLIP_PLANE1); + GLi->disable(GL_CLIP_PLANE2); + GLi->disable(GL_CLIP_PLANE3); } void RendererGL3::pointSize( float size ) { diff --git a/src/eepp/graphics/renderer/renderergl3cp.cpp b/src/eepp/graphics/renderer/renderergl3cp.cpp index 0bfd648d2..d5123159d 100644 --- a/src/eepp/graphics/renderer/renderergl3cp.cpp +++ b/src/eepp/graphics/renderer/renderergl3cp.cpp @@ -616,11 +616,6 @@ void RendererGL3CP::matrixMode(unsigned int mode) { void RendererGL3CP::clip2DPlaneEnable( const Int32& x, const Int32& y, const Int32& Width, const Int32& Height ) { Rectf r( x, y, x + Width, y + Height ); - if ( !mPlanesClipped.empty() ) { - Rectf r2 = mPlanesClipped.back(); - r.shrink( r2 ); - } - glm::vec4 vclip_left ( 1.0 , 0.0 , 0.0 , -r.Left ); glm::vec4 vclip_right ( -1.0 , 0.0 , 0.0 , r.Right ); glm::vec4 vclip_top ( 0.0 , 1.0 , 0.0 , -r.Top ); @@ -642,28 +637,13 @@ void RendererGL3CP::clip2DPlaneEnable( const Int32& x, const Int32& y, const Int glUniform4fv( mPlanes[1], 1, static_cast( &vclip_right[0] ) ); glUniform4fv( mPlanes[2], 1, static_cast( &vclip_top[0] ) ); glUniform4fv( mPlanes[3], 1, static_cast( &vclip_bottom[0] ) ); - - if ( mPushClip ) { - mPlanesClipped.push_back( r ); - } } void RendererGL3CP::clip2DPlaneDisable() { - if ( ! mPlanesClipped.empty() ) { // This should always be true - mPlanesClipped.pop_back(); - } - - if ( mPlanesClipped.empty() ) { - GLi->disable(GL_CLIP_PLANE0); - GLi->disable(GL_CLIP_PLANE1); - GLi->disable(GL_CLIP_PLANE2); - GLi->disable(GL_CLIP_PLANE3); - } else { - Rectf R( mPlanesClipped.back() ); - mPushClip = false; - clip2DPlaneEnable( R.Left, R.Top, R.getWidth(), R.getHeight() ); - mPushClip = true; - } + GLi->disable(GL_CLIP_PLANE0); + GLi->disable(GL_CLIP_PLANE1); + GLi->disable(GL_CLIP_PLANE2); + GLi->disable(GL_CLIP_PLANE3); } void RendererGL3CP::pointSize( float size ) { diff --git a/src/eepp/graphics/renderer/renderergles2.cpp b/src/eepp/graphics/renderer/renderergles2.cpp index 6556054af..f292a9868 100644 --- a/src/eepp/graphics/renderer/renderergles2.cpp +++ b/src/eepp/graphics/renderer/renderergles2.cpp @@ -619,11 +619,6 @@ void RendererGLES2::matrixMode(unsigned int mode) { void RendererGLES2::clip2DPlaneEnable( const Int32& x, const Int32& y, const Int32& Width, const Int32& Height ) { Rectf r( x, y, x + Width, y + Height ); - if ( !mPlanesClipped.empty() ) { - Rectf r2 = mPlanesClipped.back(); - r.shrink( r2 ); - } - glm::vec4 vclip_left ( 1.0 , 0.0 , 0.0 , -r.Left ); glm::vec4 vclip_right ( -1.0 , 0.0 , 0.0 , r.Right ); glm::vec4 vclip_top ( 0.0 , 1.0 , 0.0 , -r.Top ); @@ -645,28 +640,13 @@ void RendererGLES2::clip2DPlaneEnable( const Int32& x, const Int32& y, const Int glUniform4fv( mPlanes[1], 1, static_cast( &vclip_right[0] ) ); glUniform4fv( mPlanes[2], 1, static_cast( &vclip_top[0] ) ); glUniform4fv( mPlanes[3], 1, static_cast( &vclip_bottom[0] ) ); - - if ( mPushClip ) { - mPlanesClipped.push_back( r ); - } } void RendererGLES2::clip2DPlaneDisable() { - if ( ! mPlanesClipped.empty() ) { // This should always be true - mPlanesClipped.pop_back(); - } - - if ( mPlanesClipped.empty() ) { - GLi->disable(GL_CLIP_PLANE0); - GLi->disable(GL_CLIP_PLANE1); - GLi->disable(GL_CLIP_PLANE2); - GLi->disable(GL_CLIP_PLANE3); - } else { - Rectf R( mPlanesClipped.back() ); - mPushClip = false; - clip2DPlaneEnable( R.Left, R.Top, R.getWidth(), R.getHeight() ); - mPushClip = true; - } + GLi->disable(GL_CLIP_PLANE0); + GLi->disable(GL_CLIP_PLANE1); + GLi->disable(GL_CLIP_PLANE2); + GLi->disable(GL_CLIP_PLANE3); } void RendererGLES2::pointSize( float size ) {