From 5235d7e5ebbaa40d55533b4d4573dd3bf77214c6 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 11 Nov 2013 10:48:49 +0100 Subject: [PATCH 1/2] Modified error handling for OpenGL backend, now error messages should be visible. --- common/drawpanel_gal.cpp | 30 ++++++++++++++------- common/gal/opengl/cached_container.cpp | 7 ++--- common/gal/opengl/gpu_manager.cpp | 9 ++++--- common/gal/opengl/opengl_compositor.cpp | 29 ++++++++++---------- common/gal/opengl/opengl_gal.cpp | 35 +++++++++++++++++-------- common/gal/opengl/shader.cpp | 8 +++--- common/gal/opengl/vertex_manager.cpp | 5 ++-- common/tool/tool_manager.cpp | 8 +++--- include/class_drawpanel_gal.h | 35 ++++++++++++++++++------- pcbnew/tools/move_tool.cpp | 3 ++- 10 files changed, 109 insertions(+), 60 deletions(-) diff --git a/common/drawpanel_gal.cpp b/common/drawpanel_gal.cpp index e7471286d6..3ec9568fde 100644 --- a/common/drawpanel_gal.cpp +++ b/common/drawpanel_gal.cpp @@ -93,7 +93,10 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin Connect( KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); + // Set up timer that prevents too frequent redraw commands m_refreshTimer.SetOwner( this ); + m_pendingRefresh = false; + m_drawing = false; Connect( wxEVT_TIMER, wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this ); this->SetFocus(); @@ -121,18 +124,25 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) ) m_pendingRefresh = false; m_lastRefresh = wxGetLocalTimeMillis(); - m_gal->BeginDrawing(); - m_gal->SetBackgroundColor( KIGFX::COLOR4D( 0.0, 0.0, 0.0, 1.0 ) ); - m_gal->ClearScreen(); + if( !m_drawing ) + { + m_drawing = true; - m_view->ClearTargets(); - // Grid has to be redrawn only when the NONCACHED target is redrawn - if( m_view->IsTargetDirty( KIGFX::TARGET_NONCACHED ) ) - m_gal->DrawGrid(); - m_view->Redraw(); - m_gal->DrawCursor( m_viewControls->GetCursorPosition() ); + m_gal->BeginDrawing(); + m_gal->SetBackgroundColor( KIGFX::COLOR4D( 0.0, 0.0, 0.0, 1.0 ) ); + m_gal->ClearScreen(); - m_gal->EndDrawing(); + m_view->ClearTargets(); + // Grid has to be redrawn only when the NONCACHED target is redrawn + if( m_view->IsTargetDirty( KIGFX::TARGET_NONCACHED ) ) + m_gal->DrawGrid(); + m_view->Redraw(); + m_gal->DrawCursor( m_viewControls->GetCursorPosition() ); + + m_gal->EndDrawing(); + + m_drawing = false; + } } diff --git a/common/gal/opengl/cached_container.cpp b/common/gal/opengl/cached_container.cpp index dda078fd7f..ffdf55aab6 100644 --- a/common/gal/opengl/cached_container.cpp +++ b/common/gal/opengl/cached_container.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #ifdef __WXDEBUG__ @@ -315,7 +316,7 @@ bool CACHED_CONTAINER::defragment( VERTEX* aTarget ) if( aTarget == NULL ) { - wxLogError( wxT( "Run out of memory" ) ); + DisplayError( NULL, wxT( "Run out of memory" ) ); return false; } } @@ -439,7 +440,7 @@ bool CACHED_CONTAINER::resizeContainer( unsigned int aNewSize ) if( newContainer == NULL ) { - wxLogError( wxT( "Run out of memory" ) ); + DisplayError( NULL, wxT( "Run out of memory" ) ); return false; } @@ -458,7 +459,7 @@ bool CACHED_CONTAINER::resizeContainer( unsigned int aNewSize ) if( newContainer == NULL ) { - wxLogError( wxT( "Run out of memory" ) ); + DisplayError( NULL, wxT( "Run out of memory" ) ); return false; } diff --git a/common/gal/opengl/gpu_manager.cpp b/common/gal/opengl/gpu_manager.cpp index 31dcf547ff..c3f15829ce 100644 --- a/common/gal/opengl/gpu_manager.cpp +++ b/common/gal/opengl/gpu_manager.cpp @@ -32,9 +32,12 @@ #include #include #include -#include +#include +#include #ifdef __WXDEBUG__ #include +#include +#include #endif using namespace KIGFX; @@ -70,7 +73,7 @@ void GPU_MANAGER::SetShader( SHADER& aShader ) if( m_shaderAttrib == -1 ) { - wxLogFatalError( wxT( "Could not get the shader attribute location" ) ); + DisplayError( NULL, wxT( "Could not get the shader attribute location" ) ); } } @@ -205,7 +208,7 @@ void GPU_CACHED_MANAGER::uploadToGpu() if( glGetError() != GL_NO_ERROR ) { - wxLogError( wxT( "Error during data upload to the GPU memory" ) ); + DisplayError( NULL, wxT( "Error during data upload to the GPU memory" ) ); } #ifdef __WXDEBUG__ diff --git a/common/gal/opengl/opengl_compositor.cpp b/common/gal/opengl/opengl_compositor.cpp index 48559e8aa3..af7b52ba5b 100644 --- a/common/gal/opengl/opengl_compositor.cpp +++ b/common/gal/opengl/opengl_compositor.cpp @@ -29,7 +29,8 @@ */ #include -#include +#include +#include using namespace KIGFX; @@ -97,9 +98,9 @@ unsigned int OPENGL_COMPOSITOR::CreateBuffer() if( usedBuffers() >= m_maxBuffers ) { - wxLogError( wxT( "Cannot create more framebuffers. OpenGL rendering backend requires at" - "least 3 framebuffers. You may try to update/change " - "your graphic drivers." ) ); + DisplayError( NULL, wxT( "Cannot create more framebuffers. OpenGL rendering " + "backend requires at least 3 framebuffers. You may try to update/change " + "your graphic drivers." ) ); return 0; // Unfortunately we have no more free buffers left } @@ -131,38 +132,38 @@ unsigned int OPENGL_COMPOSITOR::CreateBuffer() switch( status ) { case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: - wxLogFatalError( wxT( "Cannot create the framebuffer." ) ); + DisplayError( NULL, wxT( "Cannot create the framebuffer." ) ); break; case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: - wxLogFatalError( wxT( "The framebuffer attachment points are incomplete." ) ); + DisplayError( NULL, wxT( "The framebuffer attachment points are incomplete." ) ); break; case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: - wxLogFatalError( wxT( "The framebuffer does not have at least " - "one image attached to it." ) ); + DisplayError( NULL, wxT( "The framebuffer does not have at least " + "one image attached to it." ) ); break; case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: - wxLogFatalError( wxT( "The framebuffer read buffer is incomplete." ) ); + DisplayError( NULL, wxT( "The framebuffer read buffer is incomplete." ) ); break; case GL_FRAMEBUFFER_UNSUPPORTED_EXT: - wxLogFatalError( wxT( "The combination of internal formats of the attached images " + DisplayError( NULL, wxT( "The combination of internal formats of the attached images " "violates an implementation-dependent set of restrictions." ) ); break; case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT: - wxLogFatalError( wxT( "GL_RENDERBUFFER_SAMPLES is not the same " + DisplayError( NULL, wxT( "GL_RENDERBUFFER_SAMPLES is not the same " "for all attached renderbuffers" ) ); break; case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT: - wxLogFatalError( wxT( "Framebuffer incomplete layer targets errors." ) ); + DisplayError( NULL, wxT( "Framebuffer incomplete layer targets errors." ) ); break; default: - wxLogFatalError( wxT( "Cannot create the framebuffer." ) ); + DisplayError( NULL, wxT( "Cannot create the framebuffer." ) ); break; } @@ -223,7 +224,7 @@ void OPENGL_COMPOSITOR::DrawBuffer( unsigned int aBufferHandle ) if( aBufferHandle == 0 || aBufferHandle > usedBuffers() ) { - wxLogError( wxT( "Wrong framebuffer handle" ) ); + DisplayError( NULL, wxT( "Wrong framebuffer handle" ) ); return; } diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 7f63b79bea..d01a90a426 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -31,6 +31,7 @@ #include #include +#include #ifdef __WXDEBUG__ #include #endif /* __WXDEBUG__ */ @@ -93,7 +94,8 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, if( tesselator == NULL ) { - wxLogFatalError( wxT( "Could not create the tesselator" ) ); + DisplayError( parentWindow, wxT( "Could not create the tesselator" ) ); + exit( 1 ); } gluTessProperty( tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE ); @@ -144,13 +146,22 @@ void OPENGL_GAL::BeginDrawing() if( !isShaderInitialized ) { if( !shader.LoadBuiltinShader( 0, SHADER_TYPE_VERTEX ) ) - wxLogFatalError( wxT( "Cannot compile vertex shader!" ) ); + { + DisplayError( parentWindow, wxT( "Cannot compile vertex shader!" ) ); + exit( 1 ); + } if( !shader.LoadBuiltinShader( 1, SHADER_TYPE_FRAGMENT ) ) - wxLogFatalError( wxT( "Cannot compile fragment shader!" ) ); + { + DisplayError( parentWindow, wxT( "Cannot compile fragment shader!" ) ); + exit( 1 ); + } if( !shader.Link() ) - wxLogFatalError( wxT( "Cannot link the shaders!" ) ); + { + DisplayError( parentWindow, wxT( "Cannot link the shaders!" ) ); + exit( 1 ); + } // Make VBOs use shaders cachedManager.SetShader( shader ); @@ -915,7 +926,7 @@ void OPENGL_GAL::initGlew() if( GLEW_OK != err ) { - wxLogError( wxString::FromUTF8( (char*) glewGetErrorString( err ) ) ); + DisplayError( parentWindow, wxString::FromUTF8( (char*) glewGetErrorString( err ) ) ); exit( 1 ); } else @@ -931,21 +942,21 @@ void OPENGL_GAL::initGlew() } else { - wxLogError( wxT( "OpenGL Version 2.1 is not supported!" ) ); + DisplayError( parentWindow, wxT( "OpenGL Version 2.1 is not supported!" ) ); exit( 1 ); } // Framebuffers have to be supported if( !GLEW_EXT_framebuffer_object ) { - wxLogError( wxT( "Framebuffer objects are not supported!" ) ); + DisplayError( parentWindow, wxT( "Framebuffer objects are not supported!" ) ); exit( 1 ); } // Vertex buffer have to be supported if( !GLEW_ARB_vertex_buffer_object ) { - wxLogError( wxT( "Vertex buffer objects are not supported!" ) ); + DisplayError( parentWindow, wxT( "Vertex buffer objects are not supported!" ) ); exit( 1 ); } @@ -1040,10 +1051,12 @@ void CALLBACK EdgeCallback( GLboolean aEdgeFlag ) void CALLBACK ErrorCallback( GLenum aErrorCode ) { - const GLubyte* estring; + const GLubyte* eString = gluErrorString( aErrorCode ); - estring = gluErrorString( aErrorCode ); - wxLogError( wxT( "Tessellation Error: %s" ), (char*) estring ); + DisplayError( NULL, wxString( std::string( "Tessellation error: " ) + + std::string( (const char*)( eString ) ) ) ); + + exit( 1 ); } diff --git a/common/gal/opengl/shader.cpp b/common/gal/opengl/shader.cpp index bddd40ca4c..6210776300 100644 --- a/common/gal/opengl/shader.cpp +++ b/common/gal/opengl/shader.cpp @@ -30,6 +30,8 @@ #include #include +#include +#include #include #include "shader_src.h" @@ -201,7 +203,7 @@ std::string SHADER::readSource( std::string aShaderSourceName ) if( !inputFile ) { - wxLogError( wxString::FromUTF8( "Can't read the shader source: " ) + + DisplayError( NULL, wxString::FromUTF8( "Can't read the shader source: " ) + wxString( aShaderSourceName.c_str(), wxConvUTF8 ) ); exit( 1 ); } @@ -223,7 +225,7 @@ bool SHADER::addSource( const std::string& aShaderSource, SHADER_TYPE aShaderTyp { if( isShaderLinked ) { - wxLogError( wxString::FromUTF8( "Shader is already linked!" ) ); + wxLogDebug( wxT( "Shader is already linked!" ) ); } // Create the program @@ -259,7 +261,7 @@ bool SHADER::addSource( const std::string& aShaderSource, SHADER_TYPE aShaderTyp if( status != GL_TRUE ) { - wxLogError( wxT( "Shader compilation error" ) ); + DisplayError( NULL, wxT( "Shader compilation error" ) ); shaderInfo( shaderNumber ); diff --git a/common/gal/opengl/vertex_manager.cpp b/common/gal/opengl/vertex_manager.cpp index 78179c8200..e98df99fe8 100644 --- a/common/gal/opengl/vertex_manager.cpp +++ b/common/gal/opengl/vertex_manager.cpp @@ -33,6 +33,7 @@ #include #include #include +#include using namespace KIGFX; @@ -55,7 +56,7 @@ void VERTEX_MANAGER::Vertex( GLfloat aX, GLfloat aY, GLfloat aZ ) const if( newVertex == NULL ) { - wxLogError( wxT( "Vertex allocation error" ) ); + DisplayError( NULL, wxT( "Vertex allocation error" ) ); return; } @@ -70,7 +71,7 @@ void VERTEX_MANAGER::Vertices( const VERTEX aVertices[], unsigned int aSize ) co if( newVertex == NULL ) { - wxLogError( wxT( "Vertex allocation error" ) ); + DisplayError( NULL, wxT( "Vertex allocation error" ) ); return; } diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 02019f25ef..a2534c0623 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -43,6 +43,7 @@ #include #include +#include #include using boost::optional; @@ -136,11 +137,10 @@ void TOOL_MANAGER::RegisterTool( TOOL_BASE* aTool ) if( aTool->GetType() == INTERACTIVE ) { - bool initState = static_cast( aTool )->Init(); - - if( !initState ) + if( !static_cast( aTool )->Init() ) { - wxLogError( wxT( "Initialization of the %s tool failed" ), aTool->GetName().c_str() ); + DisplayError( NULL, wxString( std::string( "Initialization of the %s tool failed" ) + + aTool->GetName() ) ); // Unregister the tool m_toolState.erase( aTool ); diff --git a/include/class_drawpanel_gal.h b/include/class_drawpanel_gal.h index cba546afd4..dd52d406b8 100644 --- a/include/class_drawpanel_gal.h +++ b/include/class_drawpanel_gal.h @@ -121,18 +121,35 @@ protected: static const int MinRefreshPeriod = 17; ///< 60 FPS. - wxLongLong m_lastRefresh; ///< Last time the panel was refreshed + ///< Last timestamp when the panel was refreshed + wxLongLong m_lastRefresh; + + ///< Is there a redraw event requested? bool m_pendingRefresh; + + ///< True if GAL is currently redrawing the view + bool m_drawing; + + ///< Timer responsible for preventing too frequent refresh wxTimer m_refreshTimer; - KIGFX::GAL* m_gal; ///< Interface for drawing objects on a 2D-surface - KIGFX::VIEW* m_view; ///< Stores view settings (scale, center, etc.) - ///< and items to be drawn - KIGFX::PAINTER* m_painter; ///< Contains information about how to draw items - ///< using GAL - KIGFX::WX_VIEW_CONTROLS* m_viewControls; ///< Control for VIEW (moving, zooming, etc.) - GalType m_currentGal; ///< Currently used GAL - TOOL_DISPATCHER* m_eventDispatcher; ///< Processes and forwards events to tools + ///< Interface for drawing objects on a 2D-surface + KIGFX::GAL* m_gal; + + ///< Stores view settings (scale, center, etc.) and items to be drawn + KIGFX::VIEW* m_view; + + ///< Contains information about how to draw items using GAL + KIGFX::PAINTER* m_painter; + + ///< Control for VIEW (moving, zooming, etc.) + KIGFX::WX_VIEW_CONTROLS* m_viewControls; + + ///< Currently used GAL + GalType m_currentGal; + + ///< Processes and forwards events to tools + TOOL_DISPATCHER* m_eventDispatcher; }; #endif diff --git a/pcbnew/tools/move_tool.cpp b/pcbnew/tools/move_tool.cpp index 6eaea40418..6750d3e8fd 100644 --- a/pcbnew/tools/move_tool.cpp +++ b/pcbnew/tools/move_tool.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "common_actions.h" #include "selection_tool.h" @@ -68,7 +69,7 @@ bool MOVE_TOOL::Init() } else { - wxLogError( wxT( "pcbnew.InteractiveSelection tool is not available" ) ); + DisplayError( NULL, wxT( "pcbnew.InteractiveSelection tool is not available" ) ); return false; } From d250ae5d81ab8735a601e9a9160eda213f746e43 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 11 Nov 2013 13:47:08 +0100 Subject: [PATCH 2/2] Corrected Doxygen comments notation. --- include/class_drawpanel_gal.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/class_drawpanel_gal.h b/include/class_drawpanel_gal.h index dd52d406b8..4d9acac711 100644 --- a/include/class_drawpanel_gal.h +++ b/include/class_drawpanel_gal.h @@ -99,7 +99,7 @@ public: } /// @copydoc wxWindow::Refresh() - virtual void Refresh( bool eraseBackground = true, const wxRect* rect = NULL ); + void Refresh( bool eraseBackground = true, const wxRect* rect = NULL ); /** * Function SetEventDispatcher() @@ -121,34 +121,34 @@ protected: static const int MinRefreshPeriod = 17; ///< 60 FPS. - ///< Last timestamp when the panel was refreshed + /// Last timestamp when the panel was refreshed wxLongLong m_lastRefresh; - ///< Is there a redraw event requested? + /// Is there a redraw event requested? bool m_pendingRefresh; - ///< True if GAL is currently redrawing the view + /// True if GAL is currently redrawing the view bool m_drawing; - ///< Timer responsible for preventing too frequent refresh + /// Timer responsible for preventing too frequent refresh wxTimer m_refreshTimer; - ///< Interface for drawing objects on a 2D-surface + /// Interface for drawing objects on a 2D-surface KIGFX::GAL* m_gal; - ///< Stores view settings (scale, center, etc.) and items to be drawn + /// Stores view settings (scale, center, etc.) and items to be drawn KIGFX::VIEW* m_view; - ///< Contains information about how to draw items using GAL + /// Contains information about how to draw items using GAL KIGFX::PAINTER* m_painter; - ///< Control for VIEW (moving, zooming, etc.) + /// Control for VIEW (moving, zooming, etc.) KIGFX::WX_VIEW_CONTROLS* m_viewControls; - ///< Currently used GAL + /// Currently used GAL GalType m_currentGal; - ///< Processes and forwards events to tools + /// Processes and forwards events to tools TOOL_DISPATCHER* m_eventDispatcher; };