OpenGL GAL: support fallback without overlay buffer

On platforms with limited framebuffer attachments, like GC7000L
driven by the open source etnaviv driver, we can still use
GPU acceleration by drawing directly to the main buffer.

EDA_DRAW_PANEL_GAL::onPaint checks if an overlay target is
available in the GAL, and if not, redraws the whole view if the
overlay target should be dirty.

Clearing of the overlay target is a no-op if there is no overlay
buffer.

Signed-off-by: Lukas F. Hartmann <lukas@mntre.com>
This commit is contained in:
mntmn 2020-06-21 18:14:37 +02:00 committed by Ian McInerney
parent 8005de27c0
commit bf60482b5c
4 changed files with 52 additions and 6 deletions

View File

@ -198,6 +198,12 @@ void EDA_DRAW_PANEL_GAL::DoRePaint()
KIGFX::GAL_DRAWING_CONTEXT ctx( m_gal );
if( m_view->IsTargetDirty( KIGFX::TARGET_OVERLAY )
&& !m_gal->HasTarget( KIGFX::TARGET_OVERLAY ) )
{
m_view->MarkDirty();
}
m_gal->SetClearColor( settings->GetBackgroundColor() );
m_gal->SetGridColor( settings->GetGridColor() );
m_gal->SetCursorColor( settings->GetCursorColor() );

View File

@ -431,8 +431,15 @@ void OPENGL_GAL::beginDrawing()
// Prepare rendering target buffers
compositor->Initialize();
mainBuffer = compositor->CreateBuffer();
overlayBuffer = compositor->CreateBuffer();
try
{
overlayBuffer = compositor->CreateBuffer();
}
catch( const std::runtime_error& error )
{
wxLogVerbose( "Could not create a framebuffer for overlays.\n" );
overlayBuffer = 0;
}
isFramebufferInitialized = true;
}
@ -558,7 +565,8 @@ void OPENGL_GAL::endDrawing()
cachedManager->EndDrawing();
// Overlay container is rendered to a different buffer
compositor->SetBuffer( overlayBuffer );
if( overlayBuffer )
compositor->SetBuffer( overlayBuffer );
overlayManager->EndDrawing();
// Be sure that the framebuffer is not colorized (happens on specific GPU&drivers combinations)
@ -566,7 +574,10 @@ void OPENGL_GAL::endDrawing()
// Draw the remaining contents, blit the rendering targets to the screen, swap the buffers
compositor->DrawBuffer( mainBuffer );
compositor->DrawBuffer( overlayBuffer );
if( overlayBuffer )
compositor->DrawBuffer( overlayBuffer );
compositor->Present();
blitCursor();
@ -1610,14 +1621,15 @@ void OPENGL_GAL::ClearTarget( RENDER_TARGET aTarget )
break;
case TARGET_OVERLAY:
compositor->SetBuffer( overlayBuffer );
if( overlayBuffer )
compositor->SetBuffer( overlayBuffer );
break;
}
if( aTarget != TARGET_OVERLAY )
compositor->ClearBuffer( m_clearColor );
else
else if( overlayBuffer )
compositor->ClearBuffer( COLOR4D::BLACK );
// Restore the previous state
@ -1625,6 +1637,21 @@ void OPENGL_GAL::ClearTarget( RENDER_TARGET aTarget )
}
bool OPENGL_GAL::HasTarget( RENDER_TARGET aTarget )
{
switch( aTarget )
{
default:
case TARGET_CACHED:
case TARGET_NONCACHED:
return true;
case TARGET_OVERLAY:
return ( overlayBuffer != 0 );
}
}
void OPENGL_GAL::DrawCursor( const VECTOR2D& aCursorPosition )
{
// Now we should only store the position of the mouse cursor

View File

@ -825,6 +825,16 @@ public:
*/
virtual void ClearTarget( RENDER_TARGET aTarget ) {};
/**
* @brief Returns true if the target exists.
*
* @param aTarget is the target to be checked.
*/
virtual bool HasTarget( RENDER_TARGET aTarget )
{
return true;
};
/**
* @brief Sets negative draw mode in the renderer
*

View File

@ -235,6 +235,9 @@ public:
/// @copydoc GAL::ClearTarget()
void ClearTarget( RENDER_TARGET aTarget ) override;
/// @copydoc GAL::HasTarget()
virtual bool HasTarget( RENDER_TARGET aTarget ) override;
/// @copydoc GAL::SetNegativeDrawMode()
void SetNegativeDrawMode( bool aSetting ) override {}