From d66e0d4f7a653a26503c6ed164eeee405433ef74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20W=C5=82ostowski?= Date: Mon, 15 Oct 2018 00:09:59 +0200 Subject: [PATCH] eeschema-gal: implemented EnableDepthTest() in GAL, fixed drawing order in eeschema --- common/gal/opengl/gpu_manager.cpp | 17 ++++++++++++++++- common/gal/opengl/opengl_gal.cpp | 11 +++++------ common/gal/opengl/vertex_manager.cpp | 5 +++++ eeschema/sch_edit_frame.cpp | 3 +++ eeschema/sch_painter.cpp | 4 ++-- eeschema/sch_view.cpp | 3 +++ include/gal/opengl/gpu_manager.h | 9 +++++++++ include/gal/opengl/vertex_manager.h | 6 ++++++ 8 files changed, 49 insertions(+), 9 deletions(-) diff --git a/common/gal/opengl/gpu_manager.cpp b/common/gal/opengl/gpu_manager.cpp index 921c0c3867..93ff22f7e4 100644 --- a/common/gal/opengl/gpu_manager.cpp +++ b/common/gal/opengl/gpu_manager.cpp @@ -49,7 +49,7 @@ GPU_MANAGER* GPU_MANAGER::MakeManager( VERTEX_CONTAINER* aContainer ) GPU_MANAGER::GPU_MANAGER( VERTEX_CONTAINER* aContainer ) : - m_isDrawing( false ), m_container( aContainer ), m_shader( NULL ), m_shaderAttrib( 0 ) + m_isDrawing( false ), m_container( aContainer ), m_shader( NULL ), m_shaderAttrib( 0 ), m_enableDepthTest( true ) { } @@ -154,6 +154,11 @@ void GPU_CACHED_MANAGER::EndDrawing() return; } + if( m_enableDepthTest ) + glEnable( GL_DEPTH_TEST ); + else + glDisable( GL_DEPTH_TEST ); + // Prepare buffers glEnableClientState( GL_VERTEX_ARRAY ); glEnableClientState( GL_COLOR_ARRAY ); @@ -254,6 +259,11 @@ void GPU_NONCACHED_MANAGER::EndDrawing() GLfloat* coordinates = (GLfloat*) ( vertices ); GLubyte* colors = (GLubyte*) ( vertices ) + COLOR_OFFSET; + if( m_enableDepthTest ) + glEnable( GL_DEPTH_TEST ); + else + glDisable( GL_DEPTH_TEST ); + // Prepare buffers glEnableClientState( GL_VERTEX_ARRAY ); glEnableClientState( GL_COLOR_ARRAY ); @@ -295,3 +305,8 @@ void GPU_NONCACHED_MANAGER::EndDrawing() wxT( "GPU_NONCACHED_MANAGER::EndDrawing(): %.1f ms" ), totalRealTime.msecs() ); #endif /* __WXDEBUG__ */ } + +void GPU_MANAGER::EnableDepthTest( bool aEnabled ) +{ + m_enableDepthTest = aEnabled; +} diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 52485bbf07..4cefbee352 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -1159,6 +1159,8 @@ void OPENGL_GAL::DrawGrid() SetTarget( TARGET_NONCACHED ); compositor->SetBuffer( mainBuffer ); + nonCachedManager->EnableDepthTest( false ); + // sub-pixel lines all render the same double minorLineWidth = std::max( 1.0, gridLineWidth ) * getWorldPixelSize(); double majorLineWidth = minorLineWidth * 2.0; @@ -2072,10 +2074,7 @@ static void InitTesselatorCallbacks( GLUtesselator* aTesselator ) void OPENGL_GAL::EnableDepthTest( bool aEnabled ) { - if( aEnabled ) - glEnable( GL_DEPTH_TEST ); - else - { - glDisable( GL_DEPTH_TEST ); - } + cachedManager->EnableDepthTest( aEnabled ); + nonCachedManager->EnableDepthTest( aEnabled ); + overlayManager->EnableDepthTest( aEnabled ); } diff --git a/common/gal/opengl/vertex_manager.cpp b/common/gal/opengl/vertex_manager.cpp index 76d433b9f7..b0e497df70 100644 --- a/common/gal/opengl/vertex_manager.cpp +++ b/common/gal/opengl/vertex_manager.cpp @@ -284,3 +284,8 @@ void VERTEX_MANAGER::putVertex( VERTEX& aTarget, GLfloat aX, GLfloat aY, GLfloat aTarget.shader[j] = m_shader[j]; } } + +void VERTEX_MANAGER::EnableDepthTest( bool aEnabled ) +{ + m_gpu->EnableDepthTest( aEnabled ); +} diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 168662387f..ba1f8076dd 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1427,6 +1427,9 @@ void SCH_EDIT_FRAME::addCurrentItemToScreen( bool aRedraw ) } item->ClearFlags(); + + GetCanvas()->GetView()->Update( item ); + screen->SetModify(); screen->SetCurItem( NULL ); m_canvas->SetMouseCapture( NULL, NULL ); diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 965503ca48..f0db0f0253 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -144,8 +144,6 @@ bool SCH_PAINTER::Draw( const VIEW_ITEM *aItem, int aLayer ) m_schSettings.ImportLegacyColors( nullptr ); - m_gal->EnableDepthTest( false ); - switch( item->Type() ) { HANDLE_ITEM(LIB_ALIAS_T, LIB_ALIAS); @@ -1079,6 +1077,8 @@ void SCH_PAINTER::draw( SCH_COMPONENT *aComp, int aLayer ) std::vector fields; aComp->GetFields( fields, false ); + m_gal->AdvanceDepth(); + for( SCH_FIELD* field : fields ) { if( field->GetId() == REFERENCE || !field->IsMoving() ) diff --git a/eeschema/sch_view.cpp b/eeschema/sch_view.cpp index 5cd8467caf..da4c7004cf 100644 --- a/eeschema/sch_view.cpp +++ b/eeschema/sch_view.cpp @@ -222,6 +222,9 @@ void SCH_VIEW::Redraw() ( *i )->items->Query( rect, visitor ); } + + m_gal->EnableDepthTest( false ); + VIEW::Redraw(); } diff --git a/include/gal/opengl/gpu_manager.h b/include/gal/opengl/gpu_manager.h index 6b7cc20e24..d43e923400 100644 --- a/include/gal/opengl/gpu_manager.h +++ b/include/gal/opengl/gpu_manager.h @@ -79,6 +79,12 @@ public: */ virtual void SetShader( SHADER& aShader ); + /** + * Function EnableDepthTest() + * Enables/disables Z buffer depth test. + */ + void EnableDepthTest( bool aEnabled ); + protected: GPU_MANAGER( VERTEX_CONTAINER* aContainer ); @@ -93,6 +99,9 @@ protected: ///> Location of shader attributes (for glVertexAttribPointer) int m_shaderAttrib; + + ///> true: enable Z test when drawing + bool m_enableDepthTest; }; diff --git a/include/gal/opengl/vertex_manager.h b/include/gal/opengl/vertex_manager.h index d39f4b0feb..6c8e23f400 100644 --- a/include/gal/opengl/vertex_manager.h +++ b/include/gal/opengl/vertex_manager.h @@ -349,6 +349,12 @@ public: */ void EndDrawing() const; + /** + * Function EnableDepthTest() + * Enables/disables Z buffer depth test. + */ + void EnableDepthTest( bool aEnabled ); + protected: /** * Function putVertex()