Clip tech layers to board in 3D renderer.

Fixes https://gitlab.com/kicad/code/kicad/issues/4873
This commit is contained in:
Jeff Young 2020-10-01 16:49:36 +01:00
parent f702da95c7
commit 5b7c6e100d
5 changed files with 126 additions and 85 deletions

View File

@ -412,30 +412,11 @@ CLAYERS_OGL_DISP_LISTS* C3D_RENDER_OGL_LEGACY::generateLayerListFromContainer( c
} }
void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter ) CLAYERS_OGL_DISP_LISTS* C3D_RENDER_OGL_LEGACY::createBoard( SHAPE_POLY_SET aBoardPoly )
{ {
m_reloadRequested = false; CLAYERS_OGL_DISP_LISTS* dispLists = nullptr;
ogl_free_all_display_lists();
COBJECT2D_STATS::Instance().ResetStats();
unsigned stats_startReloadTime = GetRunningMicroSecs();
m_boardAdapter.InitSettings( aStatusReporter, aWarningReporter );
SFVEC3F camera_pos = m_boardAdapter.GetBoardCenter3DU();
m_camera.SetBoardLookAtPos( camera_pos );
if( aStatusReporter )
aStatusReporter->Report( _( "Load OpenGL: board" ) );
// Create Board
// /////////////////////////////////////////////////////////////////////////
CCONTAINER2D boardContainer; CCONTAINER2D boardContainer;
SHAPE_POLY_SET tmpBoard = m_boardAdapter.GetBoardPoly(); Convert_shape_line_polygon_to_triangles( aBoardPoly,
Convert_shape_line_polygon_to_triangles( tmpBoard,
boardContainer, boardContainer,
m_boardAdapter.BiuTo3Dunits(), m_boardAdapter.BiuTo3Dunits(),
(const BOARD_ITEM &)*m_boardAdapter.GetBoard() ); (const BOARD_ITEM &)*m_boardAdapter.GetBoard() );
@ -487,15 +468,54 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
m_boardAdapter.BiuTo3Dunits(), m_boardAdapter.BiuTo3Dunits(),
false ); false );
m_ogl_disp_list_board = new CLAYERS_OGL_DISP_LISTS( *layerTriangles, dispLists = new CLAYERS_OGL_DISP_LISTS( *layerTriangles,
m_ogl_circle_texture, m_ogl_circle_texture,
layer_z_top, layer_z_top,
layer_z_top ); layer_z_top );
} }
delete layerTriangles; delete layerTriangles;
} }
return dispLists;
}
void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter )
{
m_reloadRequested = false;
ogl_free_all_display_lists();
COBJECT2D_STATS::Instance().ResetStats();
unsigned stats_startReloadTime = GetRunningMicroSecs();
m_boardAdapter.InitSettings( aStatusReporter, aWarningReporter );
SFVEC3F camera_pos = m_boardAdapter.GetBoardCenter3DU();
m_camera.SetBoardLookAtPos( camera_pos );
if( aStatusReporter )
aStatusReporter->Report( _( "Load OpenGL: board" ) );
// Create Board
// /////////////////////////////////////////////////////////////////////////
m_ogl_disp_list_board = createBoard( m_boardAdapter.GetBoardPoly() );
SHAPE_POLY_SET anti_board;
anti_board.NewOutline();
anti_board.Append( VECTOR2I( -INT_MAX/2, -INT_MAX/2 ) );
anti_board.Append( VECTOR2I( INT_MAX/2, -INT_MAX/2 ) );
anti_board.Append( VECTOR2I( INT_MAX/2, INT_MAX/2 ) );
anti_board.Append( VECTOR2I( -INT_MAX/2, INT_MAX/2 ) );
anti_board.Outline( 0 ).SetClosed( true );
anti_board.BooleanSubtract( m_boardAdapter.GetBoardPoly(), SHAPE_POLY_SET::PM_FAST );
m_ogl_disp_list_anti_board = createBoard( anti_board );
m_ogl_disp_list_anti_board->SetItIsTransparent( true );
// Create Through Holes and vias // Create Through Holes and vias
// ///////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////

View File

@ -59,6 +59,7 @@ C3D_RENDER_OGL_LEGACY::C3D_RENDER_OGL_LEGACY( BOARD_ADAPTER& aAdapter, CCAMERA&
m_ogl_disp_lists_layers_holes_inner.clear(); m_ogl_disp_lists_layers_holes_inner.clear();
m_triangles.clear(); m_triangles.clear();
m_ogl_disp_list_board = NULL; m_ogl_disp_list_board = NULL;
m_ogl_disp_list_anti_board = NULL;
m_ogl_disp_lists_platedPads_F_Cu = nullptr; m_ogl_disp_lists_platedPads_F_Cu = nullptr;
m_ogl_disp_lists_platedPads_B_Cu = nullptr; m_ogl_disp_lists_platedPads_B_Cu = nullptr;
@ -543,12 +544,12 @@ void C3D_RENDER_OGL_LEGACY::render_board_body( bool aSkipRenderHoles )
if( (m_ogl_disp_list_through_holes_outer_with_npth) && (!aSkipRenderHoles) ) if( (m_ogl_disp_list_through_holes_outer_with_npth) && (!aSkipRenderHoles) )
{ {
m_ogl_disp_list_through_holes_outer_with_npth->ApplyScalePosition( m_ogl_disp_list_through_holes_outer_with_npth->ApplyScalePosition(
-m_boardAdapter.GetEpoxyThickness3DU() / 2.0f, -m_boardAdapter.GetEpoxyThickness3DU() / 2.0f,
m_boardAdapter.GetEpoxyThickness3DU() ); m_boardAdapter.GetEpoxyThickness3DU() );
m_ogl_disp_list_board->DrawAllCameraCulledSubtractLayer( m_ogl_disp_list_board->DrawAllCameraCulledSubtractLayer(
m_ogl_disp_list_through_holes_outer_with_npth, true,
NULL ); m_ogl_disp_list_through_holes_outer_with_npth );
} }
else else
{ {
@ -776,9 +777,9 @@ bool C3D_RENDER_OGL_LEGACY::Redraw(
if( viasHolesLayer != NULL ) if( viasHolesLayer != NULL )
{ {
pLayerDispList->DrawAllCameraCulledSubtractLayer( pLayerDispList->DrawAllCameraCulledSubtractLayer(
drawMiddleSegments,
m_ogl_disp_list_through_holes_outer, m_ogl_disp_list_through_holes_outer,
viasHolesLayer, viasHolesLayer );
drawMiddleSegments );
// Draw copper plated pads // Draw copper plated pads
@ -787,16 +788,19 @@ bool C3D_RENDER_OGL_LEGACY::Redraw(
setPlatedCopperAndDepthOffset( layer_id ); setPlatedCopperAndDepthOffset( layer_id );
if( ( layer_id == F_Cu ) && m_ogl_disp_lists_platedPads_F_Cu ) if( ( layer_id == F_Cu ) && m_ogl_disp_lists_platedPads_F_Cu )
{
m_ogl_disp_lists_platedPads_F_Cu->DrawAllCameraCulledSubtractLayer( m_ogl_disp_lists_platedPads_F_Cu->DrawAllCameraCulledSubtractLayer(
drawMiddleSegments,
m_ogl_disp_list_through_holes_outer, m_ogl_disp_list_through_holes_outer,
viasHolesLayer, viasHolesLayer );
drawMiddleSegments ); }
else else if( ( layer_id == B_Cu ) && m_ogl_disp_lists_platedPads_B_Cu )
if( ( layer_id == B_Cu ) && m_ogl_disp_lists_platedPads_B_Cu ) {
m_ogl_disp_lists_platedPads_B_Cu->DrawAllCameraCulledSubtractLayer( m_ogl_disp_lists_platedPads_B_Cu->DrawAllCameraCulledSubtractLayer(
m_ogl_disp_list_through_holes_outer, drawMiddleSegments,
viasHolesLayer, m_ogl_disp_list_through_holes_outer,
drawMiddleSegments ); viasHolesLayer );
}
unsetDepthOffset(); unsetDepthOffset();
} }
@ -804,27 +808,29 @@ bool C3D_RENDER_OGL_LEGACY::Redraw(
else else
{ {
pLayerDispList->DrawAllCameraCulledSubtractLayer( pLayerDispList->DrawAllCameraCulledSubtractLayer(
m_ogl_disp_list_through_holes_outer, drawMiddleSegments,
NULL, m_ogl_disp_list_through_holes_outer );
drawMiddleSegments );
// Draw copper plated pads // Draw copper plated pads
if( ( ( layer_id == F_Cu ) || ( layer_id == B_Cu ) ) && if( ( ( layer_id == F_Cu ) || ( layer_id == B_Cu ) ) &&
( m_ogl_disp_lists_platedPads_F_Cu || m_ogl_disp_lists_platedPads_B_Cu ) ) ( m_ogl_disp_lists_platedPads_F_Cu || m_ogl_disp_lists_platedPads_B_Cu ) )
{
setPlatedCopperAndDepthOffset( layer_id ); setPlatedCopperAndDepthOffset( layer_id );
}
if( ( layer_id == F_Cu ) && m_ogl_disp_lists_platedPads_F_Cu ) if( ( layer_id == F_Cu ) && m_ogl_disp_lists_platedPads_F_Cu )
{
m_ogl_disp_lists_platedPads_F_Cu->DrawAllCameraCulledSubtractLayer( m_ogl_disp_lists_platedPads_F_Cu->DrawAllCameraCulledSubtractLayer(
m_ogl_disp_list_through_holes_outer, drawMiddleSegments,
NULL, m_ogl_disp_list_through_holes_outer );
drawMiddleSegments ); }
else else if( ( layer_id == B_Cu ) && m_ogl_disp_lists_platedPads_B_Cu )
if( ( layer_id == B_Cu ) && m_ogl_disp_lists_platedPads_B_Cu ) {
m_ogl_disp_lists_platedPads_B_Cu->DrawAllCameraCulledSubtractLayer( m_ogl_disp_lists_platedPads_B_Cu->DrawAllCameraCulledSubtractLayer(
m_ogl_disp_list_through_holes_outer, drawMiddleSegments,
NULL, m_ogl_disp_list_through_holes_outer );
drawMiddleSegments ); }
unsetDepthOffset(); unsetDepthOffset();
} }
@ -841,8 +847,13 @@ bool C3D_RENDER_OGL_LEGACY::Redraw(
m_ogl_disp_list_through_holes_outer; m_ogl_disp_list_through_holes_outer;
if( dispListThroughHolesOuter ) if( dispListThroughHolesOuter )
{
dispListThroughHolesOuter->ApplyScalePosition( pLayerDispList->GetZBot(), dispListThroughHolesOuter->ApplyScalePosition( pLayerDispList->GetZBot(),
pLayerDispList->GetZTop() - pLayerDispList->GetZBot() ); pLayerDispList->GetZTop() - pLayerDispList->GetZBot() );
}
m_ogl_disp_list_anti_board->ApplyScalePosition( pLayerDispList->GetZBot(),
pLayerDispList->GetZTop() - pLayerDispList->GetZBot() );
if( (!skipRenderHoles) && if( (!skipRenderHoles) &&
m_boardAdapter.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ) && m_boardAdapter.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ) &&
@ -851,37 +862,36 @@ bool C3D_RENDER_OGL_LEGACY::Redraw(
( ( layer_id == F_SilkS ) && ( ( layer_id == F_SilkS ) &&
( m_ogl_disp_lists_layers.find( F_Mask ) != m_ogl_disp_lists_layers.end() ) ) ) ) ( m_ogl_disp_lists_layers.find( F_Mask ) != m_ogl_disp_lists_layers.end() ) ) ) )
{ {
const PCB_LAYER_ID layerMask_id = (layer_id == B_SilkS)?B_Mask:F_Mask; const PCB_LAYER_ID layerMask_id = (layer_id == B_SilkS) ? B_Mask : F_Mask;
const CLAYERS_OGL_DISP_LISTS *pLayerDispListMask = m_ogl_disp_lists_layers.at( layerMask_id ); const CLAYERS_OGL_DISP_LISTS *pLayerDispListMask = m_ogl_disp_lists_layers.at( layerMask_id );
pLayerDispList->DrawAllCameraCulledSubtractLayer( pLayerDispList->DrawAllCameraCulledSubtractLayer(
drawMiddleSegments,
pLayerDispListMask, pLayerDispListMask,
dispListThroughHolesOuter, dispListThroughHolesOuter,
drawMiddleSegments ); m_ogl_disp_list_anti_board );
} }
else else
{ {
if((!skipRenderHoles) && if( !skipRenderHoles &&
dispListThroughHolesOuter && dispListThroughHolesOuter && ( layer_id == B_SilkS || layer_id == F_SilkS ) )
( ( layer_id == B_SilkS ) || ( layer_id == F_SilkS )
// Remove vias on SolderPaste can be added as an option in future
// ( layer_id == B_Paste ) || ( layer_id == F_Paste ) )
) )
{ {
pLayerDispList->DrawAllCameraCulledSubtractLayer( pLayerDispList->DrawAllCameraCulledSubtractLayer(
NULL, drawMiddleSegments,
nullptr,
dispListThroughHolesOuter, dispListThroughHolesOuter,
drawMiddleSegments ); m_ogl_disp_list_anti_board );
} }
else else
{ {
// Do not render Paste layers when skipRenderHoles is enabled // Do not render Paste layers when skipRenderHoles is enabled
// otherwise it will cause z-fight issues // otherwise it will cause z-fight issues
if( !( skipRenderHoles && if( !( skipRenderHoles && ( layer_id == B_Paste || layer_id == F_Paste ) ) )
( ( layer_id == B_Paste ) || ( layer_id == F_Paste ) ) ) )
{ {
pLayerDispList->DrawAllCameraCulled( m_camera.GetPos().z, drawMiddleSegments ); pLayerDispList->DrawAllCameraCulledSubtractLayer(
drawMiddleSegments,
m_ogl_disp_list_anti_board );
} }
} }
} }
@ -1136,28 +1146,31 @@ void C3D_RENDER_OGL_LEGACY::ogl_free_all_display_lists()
delete m_ogl_disp_list_board; delete m_ogl_disp_list_board;
m_ogl_disp_list_board = 0; m_ogl_disp_list_board = nullptr;
delete m_ogl_disp_list_anti_board;
m_ogl_disp_list_anti_board = nullptr;
delete m_ogl_disp_list_through_holes_outer_with_npth; delete m_ogl_disp_list_through_holes_outer_with_npth;
m_ogl_disp_list_through_holes_outer_with_npth = 0; m_ogl_disp_list_through_holes_outer_with_npth = nullptr;
delete m_ogl_disp_list_through_holes_outer; delete m_ogl_disp_list_through_holes_outer;
m_ogl_disp_list_through_holes_outer = 0; m_ogl_disp_list_through_holes_outer = nullptr;
delete m_ogl_disp_list_through_holes_vias_outer; delete m_ogl_disp_list_through_holes_vias_outer;
m_ogl_disp_list_through_holes_vias_outer = 0; m_ogl_disp_list_through_holes_vias_outer = nullptr;
delete m_ogl_disp_list_through_holes_outer_ring; delete m_ogl_disp_list_through_holes_outer_ring;
m_ogl_disp_list_through_holes_outer_ring = 0; m_ogl_disp_list_through_holes_outer_ring = nullptr;
delete m_ogl_disp_list_via; delete m_ogl_disp_list_via;
m_ogl_disp_list_via = 0; m_ogl_disp_list_via = nullptr;
delete m_ogl_disp_list_pads_holes; delete m_ogl_disp_list_pads_holes;
m_ogl_disp_list_pads_holes = 0; m_ogl_disp_list_pads_holes = nullptr;
delete m_ogl_disp_list_vias_and_pad_holes_outer_contourn_and_caps; delete m_ogl_disp_list_vias_and_pad_holes_outer_contourn_and_caps;
m_ogl_disp_list_vias_and_pad_holes_outer_contourn_and_caps = 0; m_ogl_disp_list_vias_and_pad_holes_outer_contourn_and_caps = nullptr;
} }
@ -1196,9 +1209,9 @@ void C3D_RENDER_OGL_LEGACY::render_solder_mask_layer(PCB_LAYER_ID aLayerID,
else else
{ {
m_ogl_disp_list_board->DrawAllCameraCulledSubtractLayer( m_ogl_disp_list_board->DrawAllCameraCulledSubtractLayer(
aDrawMiddleSegments,
pLayerDispListMask, pLayerDispListMask,
m_ogl_disp_list_through_holes_vias_outer, m_ogl_disp_list_through_holes_vias_outer );
aDrawMiddleSegments );
} }
} }
else else
@ -1226,9 +1239,8 @@ void C3D_RENDER_OGL_LEGACY::render_solder_mask_layer(PCB_LAYER_ID aLayerID,
else else
{ {
m_ogl_disp_list_board->DrawAllCameraCulledSubtractLayer( m_ogl_disp_list_board->DrawAllCameraCulledSubtractLayer(
NULL, aDrawMiddleSegments,
m_ogl_disp_list_through_holes_vias_outer, m_ogl_disp_list_through_holes_vias_outer );
aDrawMiddleSegments );
} }
} }
} }

View File

@ -73,6 +73,7 @@ public:
private: private:
bool initializeOpenGL(); bool initializeOpenGL();
CLAYERS_OGL_DISP_LISTS* createBoard( SHAPE_POLY_SET aBoardPoly );
void reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter ); void reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter );
void ogl_set_arrow_material(); void ogl_set_arrow_material();
@ -84,6 +85,7 @@ private:
MAP_OGL_DISP_LISTS m_ogl_disp_lists_layers_holes_outer; MAP_OGL_DISP_LISTS m_ogl_disp_lists_layers_holes_outer;
MAP_OGL_DISP_LISTS m_ogl_disp_lists_layers_holes_inner; MAP_OGL_DISP_LISTS m_ogl_disp_lists_layers_holes_inner;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_board; CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_board;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_anti_board;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_through_holes_outer; CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_through_holes_outer;
// User for body render // User for body render

View File

@ -521,10 +521,10 @@ void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulled(float zCameraPos, bool aDrawMid
} }
void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulledSubtractLayer( void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulledSubtractLayer( bool aDrawMiddle,
const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractA, const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractA,
const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractB, const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractB,
bool aDrawMiddle ) const const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractC ) const
{ {
glClearStencil( 0x00 ); glClearStencil( 0x00 );
glClear( GL_STENCIL_BUFFER_BIT ); glClear( GL_STENCIL_BUFFER_BIT );
@ -545,6 +545,9 @@ void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulledSubtractLayer(
if( aLayerToSubtractB ) if( aLayerToSubtractB )
aLayerToSubtractB->DrawBot(); aLayerToSubtractB->DrawBot();
if( aLayerToSubtractC )
aLayerToSubtractC->DrawBot();
//if( !m_draw_it_transparent ) //if( !m_draw_it_transparent )
{ {
@ -570,6 +573,9 @@ void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulledSubtractLayer(
if( aLayerToSubtractB ) if( aLayerToSubtractB )
aLayerToSubtractB->DrawTop(); aLayerToSubtractB->DrawTop();
if( aLayerToSubtractC )
aLayerToSubtractC->DrawTop();
//if( !m_draw_it_transparent ) //if( !m_draw_it_transparent )
{ {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);

View File

@ -253,9 +253,10 @@ public:
*/ */
void DrawAllCameraCulled( float zCameraPos, bool aDrawMiddle = true ) const; void DrawAllCameraCulled( float zCameraPos, bool aDrawMiddle = true ) const;
void DrawAllCameraCulledSubtractLayer( const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractA, void DrawAllCameraCulledSubtractLayer( bool aDrawMiddle,
const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractB, const CLAYERS_OGL_DISP_LISTS* aLayerToSubtractA = nullptr,
bool aDrawMiddle = true ) const; const CLAYERS_OGL_DISP_LISTS* aLayerToSubtractB = nullptr,
const CLAYERS_OGL_DISP_LISTS* aLayerToSubtractC = nullptr ) const;
void ApplyScalePosition( float aZposition, float aZscale ); void ApplyScalePosition( float aZposition, float aZscale );