From 9909f60f6d0270d9999dec331f7c905d48f534e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 9 Jun 2013 16:52:06 -0300 Subject: [PATCH] 2D Clipping planes stacks. cFrameBuffer restores the previous matrix projection. Added Set2DProjection to cWindow. --- include/eepp/graphics/cframebuffer.hpp | 1 + include/eepp/graphics/renderer/cgl.hpp | 2 ++ include/eepp/window/cwindow.hpp | 5 +++- projects/linux/ee.creator.user | 6 ++--- src/eepp/graphics/cframebuffer.cpp | 10 ++++++++ src/eepp/graphics/renderer/cgl.cpp | 3 ++- src/eepp/graphics/renderer/crenderergl.cpp | 23 +++++++++++++++---- src/eepp/graphics/renderer/crenderergl3.cpp | 23 +++++++++++++++---- src/eepp/graphics/renderer/crenderergles2.cpp | 23 +++++++++++++++---- src/eepp/window/cwindow.cpp | 18 +++++++++------ src/test/eetest.cpp | 2 +- 11 files changed, 91 insertions(+), 25 deletions(-) diff --git a/include/eepp/graphics/cframebuffer.hpp b/include/eepp/graphics/cframebuffer.hpp index eb4e6a446..beec369e4 100644 --- a/include/eepp/graphics/cframebuffer.hpp +++ b/include/eepp/graphics/cframebuffer.hpp @@ -69,6 +69,7 @@ class EE_API cFrameBuffer { cTexture * mTexture; eeColorAf mClearColor; cView mPrevView; + GLfloat mProjMat[16]; cFrameBuffer( Window::cWindow * window ); diff --git a/include/eepp/graphics/renderer/cgl.hpp b/include/eepp/graphics/renderer/cgl.hpp index c7391c36e..d48d820b8 100644 --- a/include/eepp/graphics/renderer/cgl.hpp +++ b/include/eepp/graphics/renderer/cgl.hpp @@ -194,6 +194,8 @@ class EE_API cGL { Uint32 mExtensions; Uint32 mStateFlags; + bool mPushClip; + std::list mPlanesClipped; private: void WriteExtension( Uint8 Pos, Uint32 BitWrite ); }; diff --git a/include/eepp/window/cwindow.hpp b/include/eepp/window/cwindow.hpp index 3f63f0144..a801091e7 100644 --- a/include/eepp/window/cwindow.hpp +++ b/include/eepp/window/cwindow.hpp @@ -270,7 +270,10 @@ class EE_API cWindow { /** This will set the default rendering states and view to render in 2D mode */ void Setup2D( const bool& KeepView = false ); - /** Set the current Viewport ( and creates a new ortho proyection if needed ) */ + /** Set a new 2D projection matrix */ + void Set2DProjection( const Uint32& Width, const Uint32& Height ); + + /** Set the current Viewport ( and creates a new ortho proyection if needed ) */ void SetViewport( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height, const bool& UpdateProjectionMatrix = true ); /** Set the window background color */ diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 23914de88..565fb9c26 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget @@ -48,9 +48,9 @@ Desktop Desktop {388e5431-b31b-42b3-b9ad-9002d279d75d} - 17 + 0 0 - 9 + 0 /home/programming/eepp/make/linux diff --git a/src/eepp/graphics/cframebuffer.cpp b/src/eepp/graphics/cframebuffer.cpp index b5d6a4514..7435cfb4a 100644 --- a/src/eepp/graphics/cframebuffer.cpp +++ b/src/eepp/graphics/cframebuffer.cpp @@ -67,6 +67,9 @@ void cFrameBuffer::SetBufferView() { mPrevView = mWindow->GetView(); + // Get the user projection matrix + GLi->GetCurrentMatrix( GL_PROJECTION_MATRIX, mProjMat ); + GLi->Viewport( 0, 0, mWidth, mHeight ); GLi->MatrixMode( GL_PROJECTION ); GLi->LoadIdentity(); @@ -79,6 +82,13 @@ void cFrameBuffer::RecoverView() { cGlobalBatchRenderer::instance()->Draw(); mWindow->SetView( mPrevView ); + + // Recover the user projection matrix + GLi->LoadIdentity(); + GLi->MatrixMode( GL_PROJECTION ); + GLi->LoadMatrixf( mProjMat ); + GLi->MatrixMode( GL_MODELVIEW ); + GLi->LoadIdentity(); } const Int32& cFrameBuffer::GetWidth() const { diff --git a/src/eepp/graphics/renderer/cgl.cpp b/src/eepp/graphics/renderer/cgl.cpp index 671222e4b..fe758bef5 100644 --- a/src/eepp/graphics/renderer/cgl.cpp +++ b/src/eepp/graphics/renderer/cgl.cpp @@ -84,7 +84,8 @@ void cGL::DestroySingleton() { cGL::cGL() : mExtensions(0), - mStateFlags( 1 << GLSF_LINE_SMOOTH ) + mStateFlags( 1 << GLSF_LINE_SMOOTH ), + mPushClip( true ) { GLi = this; } diff --git a/src/eepp/graphics/renderer/crenderergl.cpp b/src/eepp/graphics/renderer/crenderergl.cpp index 7562b3806..89fbc5b36 100644 --- a/src/eepp/graphics/renderer/crenderergl.cpp +++ b/src/eepp/graphics/renderer/crenderergl.cpp @@ -241,13 +241,28 @@ void cRendererGL::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( eeRectf( x, y, Width, Height ) ); + } } void cRendererGL::Clip2DPlaneDisable() { - GLi->Disable(GL_CLIP_PLANE0); - GLi->Disable(GL_CLIP_PLANE1); - GLi->Disable(GL_CLIP_PLANE2); - GLi->Disable(GL_CLIP_PLANE3); + 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 { + eeRectf R( mPlanesClipped.back() ); + mPushClip = false; + Clip2DPlaneEnable( R.Left, R.Top, R.Right, R.Bottom ); + mPushClip = true; + } } void cRendererGL::ClipPlane( GLenum plane, const GLdouble *equation ) { diff --git a/src/eepp/graphics/renderer/crenderergl3.cpp b/src/eepp/graphics/renderer/crenderergl3.cpp index b28c1965c..be4da7ed0 100644 --- a/src/eepp/graphics/renderer/crenderergl3.cpp +++ b/src/eepp/graphics/renderer/crenderergl3.cpp @@ -561,13 +561,28 @@ void cRendererGL3::Clip2DPlaneEnable( const Int32& x, const Int32& y, const Int3 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( eeRectf( x, y, Width, Height ) ); + } } void cRendererGL3::Clip2DPlaneDisable() { - GLi->Disable(GL_CLIP_PLANE0); - GLi->Disable(GL_CLIP_PLANE1); - GLi->Disable(GL_CLIP_PLANE2); - GLi->Disable(GL_CLIP_PLANE3); + 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 { + eeRectf R( mPlanesClipped.back() ); + mPushClip = false; + Clip2DPlaneEnable( R.Left, R.Top, R.Right, R.Bottom ); + mPushClip = true; + } } void cRendererGL3::PointSize( GLfloat size ) { diff --git a/src/eepp/graphics/renderer/crenderergles2.cpp b/src/eepp/graphics/renderer/crenderergles2.cpp index 8b0d26afd..eb33ebdc6 100644 --- a/src/eepp/graphics/renderer/crenderergles2.cpp +++ b/src/eepp/graphics/renderer/crenderergles2.cpp @@ -639,13 +639,28 @@ void cRendererGLES2::Clip2DPlaneEnable( const Int32& x, const Int32& y, const In 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( eeRectf( x, y, Width, Height ) ); + } } void cRendererGLES2::Clip2DPlaneDisable() { - GLi->Disable(GL_CLIP_PLANE0); - GLi->Disable(GL_CLIP_PLANE1); - GLi->Disable(GL_CLIP_PLANE2); - GLi->Disable(GL_CLIP_PLANE3); + 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 { + eeRectf R( mPlanesClipped.back() ); + mPushClip = false; + Clip2DPlaneEnable( R.Left, R.Top, R.Right, R.Bottom ); + mPushClip = true; + } } void cRendererGLES2::PointSize( GLfloat size ) { diff --git a/src/eepp/window/cwindow.cpp b/src/eepp/window/cwindow.cpp index 0837080a0..807a36ab0 100644 --- a/src/eepp/window/cwindow.cpp +++ b/src/eepp/window/cwindow.cpp @@ -98,17 +98,21 @@ bool cWindow::Resizeable() const { return 0 != ( mWindow.WindowConfig.Style & WindowStyle::Resize ); } +void cWindow::Set2DProjection( const Uint32& Width, const Uint32& Height ) { + GLi->MatrixMode( GL_PROJECTION ); + GLi->LoadIdentity(); + + GLi->Ortho( 0.0f, Width, Height, 0.0f, -1000.0f, 1000.0f ); + + GLi->MatrixMode( GL_MODELVIEW ); + GLi->LoadIdentity(); +} + void cWindow::SetViewport( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height, const bool& UpdateProjectionMatrix ) { GLi->Viewport( x, GetHeight() - ( y + Height ), Width, Height ); if ( UpdateProjectionMatrix ) { - GLi->MatrixMode( GL_PROJECTION ); - GLi->LoadIdentity(); - - GLi->Ortho( 0.0f, Width, Height, 0.0f, -1000.0f, 1000.0f ); - - GLi->MatrixMode( GL_MODELVIEW ); - GLi->LoadIdentity(); + Set2DProjection( Width, Height ); } } diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index d474747be..adf8cd871 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -837,7 +837,7 @@ void cEETest::LoadTextures() { Tiles.resize(10); - cTextureAtlasLoader tgl( MyPath + "atlases/tiles.etg" ); + cTextureAtlasLoader tgl( MyPath + "atlases/tiles.eta" ); cTextureAtlas * SG = cTextureAtlasManager::instance()->GetByName( "tiles" ); if ( NULL != SG ) {