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;
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
// /////////////////////////////////////////////////////////////////////////
CLAYERS_OGL_DISP_LISTS* dispLists = nullptr;
CCONTAINER2D boardContainer;
SHAPE_POLY_SET tmpBoard = m_boardAdapter.GetBoardPoly();
Convert_shape_line_polygon_to_triangles( tmpBoard,
Convert_shape_line_polygon_to_triangles( aBoardPoly,
boardContainer,
m_boardAdapter.BiuTo3Dunits(),
(const BOARD_ITEM &)*m_boardAdapter.GetBoard() );
@ -487,7 +468,7 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
m_boardAdapter.BiuTo3Dunits(),
false );
m_ogl_disp_list_board = new CLAYERS_OGL_DISP_LISTS( *layerTriangles,
dispLists = new CLAYERS_OGL_DISP_LISTS( *layerTriangles,
m_ogl_circle_texture,
layer_z_top,
layer_z_top );
@ -496,6 +477,45 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
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
// /////////////////////////////////////////////////////////////////////////

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_triangles.clear();
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_B_Cu = nullptr;
@ -547,8 +548,8 @@ void C3D_RENDER_OGL_LEGACY::render_board_body( bool aSkipRenderHoles )
m_boardAdapter.GetEpoxyThickness3DU() );
m_ogl_disp_list_board->DrawAllCameraCulledSubtractLayer(
m_ogl_disp_list_through_holes_outer_with_npth,
NULL );
true,
m_ogl_disp_list_through_holes_outer_with_npth );
}
else
{
@ -776,9 +777,9 @@ bool C3D_RENDER_OGL_LEGACY::Redraw(
if( viasHolesLayer != NULL )
{
pLayerDispList->DrawAllCameraCulledSubtractLayer(
drawMiddleSegments,
m_ogl_disp_list_through_holes_outer,
viasHolesLayer,
drawMiddleSegments );
viasHolesLayer );
// Draw copper plated pads
@ -787,16 +788,19 @@ bool C3D_RENDER_OGL_LEGACY::Redraw(
setPlatedCopperAndDepthOffset( layer_id );
if( ( layer_id == F_Cu ) && m_ogl_disp_lists_platedPads_F_Cu )
{
m_ogl_disp_lists_platedPads_F_Cu->DrawAllCameraCulledSubtractLayer(
drawMiddleSegments,
m_ogl_disp_list_through_holes_outer,
viasHolesLayer,
drawMiddleSegments );
else
if( ( layer_id == B_Cu ) && m_ogl_disp_lists_platedPads_B_Cu )
viasHolesLayer );
}
else if( ( layer_id == B_Cu ) && m_ogl_disp_lists_platedPads_B_Cu )
{
m_ogl_disp_lists_platedPads_B_Cu->DrawAllCameraCulledSubtractLayer(
drawMiddleSegments,
m_ogl_disp_list_through_holes_outer,
viasHolesLayer,
drawMiddleSegments );
viasHolesLayer );
}
unsetDepthOffset();
}
@ -804,27 +808,29 @@ bool C3D_RENDER_OGL_LEGACY::Redraw(
else
{
pLayerDispList->DrawAllCameraCulledSubtractLayer(
m_ogl_disp_list_through_holes_outer,
NULL,
drawMiddleSegments );
drawMiddleSegments,
m_ogl_disp_list_through_holes_outer );
// Draw copper plated pads
if( ( ( layer_id == F_Cu ) || ( layer_id == B_Cu ) ) &&
( m_ogl_disp_lists_platedPads_F_Cu || m_ogl_disp_lists_platedPads_B_Cu ) )
{
setPlatedCopperAndDepthOffset( layer_id );
}
if( ( layer_id == F_Cu ) && m_ogl_disp_lists_platedPads_F_Cu )
{
m_ogl_disp_lists_platedPads_F_Cu->DrawAllCameraCulledSubtractLayer(
m_ogl_disp_list_through_holes_outer,
NULL,
drawMiddleSegments );
else
if( ( layer_id == B_Cu ) && m_ogl_disp_lists_platedPads_B_Cu )
drawMiddleSegments,
m_ogl_disp_list_through_holes_outer );
}
else if( ( layer_id == B_Cu ) && m_ogl_disp_lists_platedPads_B_Cu )
{
m_ogl_disp_lists_platedPads_B_Cu->DrawAllCameraCulledSubtractLayer(
m_ogl_disp_list_through_holes_outer,
NULL,
drawMiddleSegments );
drawMiddleSegments,
m_ogl_disp_list_through_holes_outer );
}
unsetDepthOffset();
}
@ -841,8 +847,13 @@ bool C3D_RENDER_OGL_LEGACY::Redraw(
m_ogl_disp_list_through_holes_outer;
if( dispListThroughHolesOuter )
{
dispListThroughHolesOuter->ApplyScalePosition( pLayerDispList->GetZBot(),
pLayerDispList->GetZTop() - pLayerDispList->GetZBot() );
}
m_ogl_disp_list_anti_board->ApplyScalePosition( pLayerDispList->GetZBot(),
pLayerDispList->GetZTop() - pLayerDispList->GetZBot() );
if( (!skipRenderHoles) &&
m_boardAdapter.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ) &&
@ -856,32 +867,31 @@ bool C3D_RENDER_OGL_LEGACY::Redraw(
const CLAYERS_OGL_DISP_LISTS *pLayerDispListMask = m_ogl_disp_lists_layers.at( layerMask_id );
pLayerDispList->DrawAllCameraCulledSubtractLayer(
drawMiddleSegments,
pLayerDispListMask,
dispListThroughHolesOuter,
drawMiddleSegments );
m_ogl_disp_list_anti_board );
}
else
{
if((!skipRenderHoles) &&
dispListThroughHolesOuter &&
( ( 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 ) )
) )
if( !skipRenderHoles &&
dispListThroughHolesOuter && ( layer_id == B_SilkS || layer_id == F_SilkS ) )
{
pLayerDispList->DrawAllCameraCulledSubtractLayer(
NULL,
drawMiddleSegments,
nullptr,
dispListThroughHolesOuter,
drawMiddleSegments );
m_ogl_disp_list_anti_board );
}
else
{
// Do not render Paste layers when skipRenderHoles is enabled
// otherwise it will cause z-fight issues
if( !( skipRenderHoles &&
( ( layer_id == B_Paste ) || ( layer_id == F_Paste ) ) ) )
if( !( skipRenderHoles && ( 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;
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;
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;
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;
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;
m_ogl_disp_list_through_holes_outer_ring = 0;
m_ogl_disp_list_through_holes_outer_ring = nullptr;
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;
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;
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
{
m_ogl_disp_list_board->DrawAllCameraCulledSubtractLayer(
aDrawMiddleSegments,
pLayerDispListMask,
m_ogl_disp_list_through_holes_vias_outer,
aDrawMiddleSegments );
m_ogl_disp_list_through_holes_vias_outer );
}
}
else
@ -1226,9 +1239,8 @@ void C3D_RENDER_OGL_LEGACY::render_solder_mask_layer(PCB_LAYER_ID aLayerID,
else
{
m_ogl_disp_list_board->DrawAllCameraCulledSubtractLayer(
NULL,
m_ogl_disp_list_through_holes_vias_outer,
aDrawMiddleSegments );
aDrawMiddleSegments,
m_ogl_disp_list_through_holes_vias_outer );
}
}
}

View File

@ -73,6 +73,7 @@ public:
private:
bool initializeOpenGL();
CLAYERS_OGL_DISP_LISTS* createBoard( SHAPE_POLY_SET aBoardPoly );
void reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter );
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_inner;
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;
// 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 *aLayerToSubtractB,
bool aDrawMiddle ) const
const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractC ) const
{
glClearStencil( 0x00 );
glClear( GL_STENCIL_BUFFER_BIT );
@ -545,6 +545,9 @@ void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulledSubtractLayer(
if( aLayerToSubtractB )
aLayerToSubtractB->DrawBot();
if( aLayerToSubtractC )
aLayerToSubtractC->DrawBot();
//if( !m_draw_it_transparent )
{
@ -570,6 +573,9 @@ void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulledSubtractLayer(
if( aLayerToSubtractB )
aLayerToSubtractB->DrawTop();
if( aLayerToSubtractC )
aLayerToSubtractC->DrawTop();
//if( !m_draw_it_transparent )
{
glEnable(GL_DEPTH_TEST);

View File

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