diff --git a/include/eepp/graphics/framebuffer.hpp b/include/eepp/graphics/framebuffer.hpp index b3d887d0d..fa37e95fb 100644 --- a/include/eepp/graphics/framebuffer.hpp +++ b/include/eepp/graphics/framebuffer.hpp @@ -99,6 +99,7 @@ class EE_API FrameBuffer { View mView; View mPrevView; float mProjMat[16]; + float mModelViewMat[16]; FrameBuffer( EE::Window::Window * window ); diff --git a/include/eepp/graphics/renderer/clippingmask.hpp b/include/eepp/graphics/renderer/clippingmask.hpp index 388a34d84..3cbfa81d6 100644 --- a/include/eepp/graphics/renderer/clippingmask.hpp +++ b/include/eepp/graphics/renderer/clippingmask.hpp @@ -46,6 +46,15 @@ class EE_API ClippingMask { void stencilMaskEnable(); void stencilMaskDisable( bool clearMasks = false ); + + std::list getScissorsClipped() const; + + void setScissorsClipped(const std::list & scissorsClipped); + + std::list getPlanesClipped() const; + + void setPlanesClipped(const std::list & planesClipped); + protected: std::list mScissorsClipped; std::list mPlanesClipped; diff --git a/src/eepp/graphics/framebuffer.cpp b/src/eepp/graphics/framebuffer.cpp index 733b44739..c3c448d46 100644 --- a/src/eepp/graphics/framebuffer.cpp +++ b/src/eepp/graphics/framebuffer.cpp @@ -60,8 +60,9 @@ void FrameBuffer::clear() { } void FrameBuffer::setBufferView() { - // Get the user projection matrix + // Get the user projection and modelview matrix GLi->getCurrentMatrix( GL_PROJECTION_MATRIX, mProjMat ); + GLi->getCurrentMatrix( GL_MODELVIEW_MATRIX, mModelViewMat ); mView.setSize( mSize.getWidth(), mSize.getHeight() ); sFBOActiveViews.push_back(&mView); @@ -86,12 +87,13 @@ void FrameBuffer::recoverView() { GLi->viewport( 0, 0, view->getView().getWidth(), view->getView().getHeight() ); } - // Recover the user projection matrix + // Recover the user projection and modelview matrix GLi->loadIdentity(); GLi->matrixMode( GL_PROJECTION ); GLi->loadMatrixf( mProjMat ); GLi->matrixMode( GL_MODELVIEW ); GLi->loadIdentity(); + GLi->loadMatrixf( mModelViewMat ); } const Int32& FrameBuffer::getWidth() const { diff --git a/src/eepp/graphics/renderer/clippingmask.cpp b/src/eepp/graphics/renderer/clippingmask.cpp index 1b393d2f8..acc99e4b2 100644 --- a/src/eepp/graphics/renderer/clippingmask.cpp +++ b/src/eepp/graphics/renderer/clippingmask.cpp @@ -138,6 +138,35 @@ void ClippingMask::stencilMaskDisable( bool clearMasks ) { this->clearMasks(); } +std::list ClippingMask::getScissorsClipped() const { + return mScissorsClipped; +} + +void ClippingMask::setScissorsClipped(const std::list & scissorsClipped) { + mScissorsClipped = scissorsClipped; + + if ( !mScissorsClipped.empty() ) { + Rectf r( mScissorsClipped.back() ); + EE::Window::Window * window = Engine::instance()->getCurrentWindow(); + GLi->scissor( r.Left, window->getHeight() - r.Bottom, r.getWidth(), r.getHeight() ); + GLi->enable( GL_SCISSOR_TEST ); + } +} + +std::list ClippingMask::getPlanesClipped() const { + return mPlanesClipped; +} + +void ClippingMask::setPlanesClipped(const std::list & planesClipped) { + mPlanesClipped = planesClipped; + + if ( !mPlanesClipped.empty() ) { + Rectf r( mPlanesClipped.back() ); + + GLi->clip2DPlaneEnable( r.Left, r.Top, r.getWidth(), r.getHeight() ); + } +} + void ClippingMask::drawMask() { for ( std::size_t i = 0; i < getMaskCount(); i++ ) const_cast(mDrawables[i])->draw(); diff --git a/src/eepp/maps/mapeditor/uimap.cpp b/src/eepp/maps/mapeditor/uimap.cpp index 08ac50329..d870741bf 100644 --- a/src/eepp/maps/mapeditor/uimap.cpp +++ b/src/eepp/maps/mapeditor/uimap.cpp @@ -13,7 +13,7 @@ UIMap * UIMap::New( UITheme * Theme, TileMap * Map ) { } UIMap::UIMap( UITheme * Theme, TileMap * Map ) : - UIWindow( SIMPLE_LAYOUT, UIWindowStyleConfig( UI_WIN_NO_BORDER ) ), + UIWindow( SIMPLE_LAYOUT, UIWindowStyleConfig( UI_WIN_NO_BORDER | UI_WIN_FRAME_BUFFER ) ), mMap( Map ), mCurLayer( NULL ), mEditingMode( 0 ), @@ -105,7 +105,6 @@ void UIMap::update() { if ( NULL != mMap ) { invalidate(); - invalidateDraw(); mMap->update(); diff --git a/src/eepp/ui/uiwindow.cpp b/src/eepp/ui/uiwindow.cpp index 7cdc11f4f..0ab063065 100644 --- a/src/eepp/ui/uiwindow.cpp +++ b/src/eepp/ui/uiwindow.cpp @@ -1115,12 +1115,20 @@ void UIWindow::internalDraw() { drawShadow(); + ClippingMask * clippingMask = GLi->getClippingMask(); + + std::list clips = clippingMask->getPlanesClipped(); + + if ( !clips.empty() ) + clippingMask->clipPlaneDisable(); + matrixSet(); if ( !ownsFrameBuffer() || NULL == mParentCtrl || !UIManager::instance()->usesInvalidation() || ( mControlFlags & UI_CTRL_FLAG_NEEDS_REDRAW ) ) { + clipMe(); draw(); @@ -1132,6 +1140,9 @@ void UIWindow::internalDraw() { matrixUnset(); + if ( !clips.empty() ) + clippingMask->setPlanesClipped( clips ); + postDraw(); drawHighlightInvalidation(); @@ -1156,10 +1167,12 @@ void UIWindow::matrixSet() { if ( NULL == mParentCtrl || !UIManager::instance()->usesInvalidation() || ( mControlFlags & UI_CTRL_FLAG_NEEDS_REDRAW ) ) mFrameBuffer->clear(); - } - if ( 0 != mScreenPos ) - GLi->translatef( -mScreenPos.x , -mScreenPos.y, 0.f ); + if ( 0 != mScreenPos ) { + GLi->pushMatrix(); + GLi->translatef( -mScreenPosf.x , -mScreenPosf.y, 0.f ); + } + } } else { UIWidget::matrixSet(); } @@ -1170,7 +1183,7 @@ void UIWindow::matrixUnset() { GlobalBatchRenderer::instance()->draw(); if ( 0 != mScreenPos ) - GLi->translatef( mScreenPos.x , mScreenPos.y, 0.f ); + GLi->popMatrix(); if ( NULL != mFrameBuffer ) mFrameBuffer->unbind();