Some renaming in 3D code for better SNR. Also formatting fixes.

This commit is contained in:
Jeff Young 2020-11-30 01:07:49 +00:00
parent 1f8b7b6149
commit 7f360a7188
3 changed files with 312 additions and 390 deletions

View File

@ -22,17 +22,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
/**
* @file c3d_render_createscene_ogl_legacy.cpp
* @brief
*/
#include "c3d_render_ogl_legacy.h" #include "c3d_render_ogl_legacy.h"
#include "ogl_legacy_utils.h" #include "ogl_legacy_utils.h"
#include <board.h> #include <board.h>
#include <footprint.h> #include <footprint.h>
#include "../../3d_math.h" #include "../../3d_math.h"
#include "../../3d_fastmath.h"
#include <trigo.h> #include <trigo.h>
#include <project.h> #include <project.h>
#include <profile.h> // To use GetRunningMicroSecs or another profiling utility #include <profile.h> // To use GetRunningMicroSecs or another profiling utility
@ -40,8 +34,7 @@
void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CFILLEDCIRCLE2D * aFilledCircle, void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CFILLEDCIRCLE2D * aFilledCircle,
CLAYER_TRIANGLES *aDstLayer, CLAYER_TRIANGLES *aDstLayer,
float aZtop, float aZtop, float aZbot )
float aZbot )
{ {
const SFVEC2F &center = aFilledCircle->GetCenter(); const SFVEC2F &center = aFilledCircle->GetCenter();
const float radius = aFilledCircle->GetRadius() * const float radius = aFilledCircle->GetRadius() *
@ -55,30 +48,25 @@ void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CFILLEDCIRCLE2D
// it in duplicated // it in duplicated
aDstLayer->m_layer_top_segment_ends->AddTriangle( SFVEC3F( center.x + f, center.y, aZtop ), aDstLayer->m_layer_top_segment_ends->AddTriangle( SFVEC3F( center.x + f, center.y, aZtop ),
SFVEC3F( center.x - f, center.y, aZtop ), SFVEC3F( center.x - f, center.y, aZtop ),
SFVEC3F( center.x, SFVEC3F( center.x, center.y - f, aZtop ) );
center.y - f, aZtop ) );
aDstLayer->m_layer_top_segment_ends->AddTriangle( SFVEC3F( center.x - f, center.y, aZtop ), aDstLayer->m_layer_top_segment_ends->AddTriangle( SFVEC3F( center.x - f, center.y, aZtop ),
SFVEC3F( center.x + f, center.y, aZtop ), SFVEC3F( center.x + f, center.y, aZtop ),
SFVEC3F( center.x, SFVEC3F( center.x, center.y + f, aZtop ) );
center.y + f, aZtop ) );
aDstLayer->m_layer_bot_segment_ends->AddTriangle( SFVEC3F( center.x - f, center.y, aZbot ), aDstLayer->m_layer_bot_segment_ends->AddTriangle( SFVEC3F( center.x - f, center.y, aZbot ),
SFVEC3F( center.x + f, center.y, aZbot ), SFVEC3F( center.x + f, center.y, aZbot ),
SFVEC3F( center.x, SFVEC3F( center.x, center.y - f, aZbot ) );
center.y - f, aZbot ) );
aDstLayer->m_layer_bot_segment_ends->AddTriangle( SFVEC3F( center.x + f, center.y, aZbot ), aDstLayer->m_layer_bot_segment_ends->AddTriangle( SFVEC3F( center.x + f, center.y, aZbot ),
SFVEC3F( center.x - f, center.y, aZbot ), SFVEC3F( center.x - f, center.y, aZbot ),
SFVEC3F( center.x, SFVEC3F( center.x, center.y + f, aZbot ) );
center.y + f, aZbot ) );
} }
void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CPOLYGON4PTS2D * aPoly, void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CPOLYGON4PTS2D * aPoly,
CLAYER_TRIANGLES *aDstLayer, CLAYER_TRIANGLES *aDstLayer,
float aZtop, float aZtop, float aZbot )
float aZbot )
{ {
const SFVEC2F &v0 = aPoly->GetV0(); const SFVEC2F &v0 = aPoly->GetV0();
const SFVEC2F &v1 = aPoly->GetV1(); const SFVEC2F &v1 = aPoly->GetV1();
@ -91,8 +79,7 @@ void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CPOLYGON4PTS2D *
void C3D_RENDER_OGL_LEGACY::generate_ring_contour( const SFVEC2F &aCenter, void C3D_RENDER_OGL_LEGACY::generate_ring_contour( const SFVEC2F &aCenter,
float aInnerRadius, float aInnerRadius, float aOuterRadius,
float aOuterRadius,
unsigned int aNr_sides_per_circle, unsigned int aNr_sides_per_circle,
std::vector< SFVEC2F > &aInnerContourResult, std::vector< SFVEC2F > &aInnerContourResult,
std::vector< SFVEC2F > &aOuterContourResult, std::vector< SFVEC2F > &aOuterContourResult,
@ -113,10 +100,10 @@ void C3D_RENDER_OGL_LEGACY::generate_ring_contour( const SFVEC2F &aCenter,
const SFVEC2F rotatedDir = SFVEC2F( cos( angle ), sin( angle ) ); const SFVEC2F rotatedDir = SFVEC2F( cos( angle ), sin( angle ) );
aInnerContourResult.emplace_back( aCenter.x + rotatedDir.x * aInnerRadius, aInnerContourResult.emplace_back( aCenter.x + rotatedDir.x * aInnerRadius,
aCenter.y + rotatedDir.y * aInnerRadius ); aCenter.y + rotatedDir.y * aInnerRadius );
aOuterContourResult.emplace_back( aCenter.x + rotatedDir.x * aOuterRadius, aOuterContourResult.emplace_back( aCenter.x + rotatedDir.x * aOuterRadius,
aCenter.y + rotatedDir.y * aOuterRadius ); aCenter.y + rotatedDir.y * aOuterRadius );
} }
aInnerContourResult.push_back( aInnerContourResult[0] ); aInnerContourResult.push_back( aInnerContourResult[0] );
@ -128,8 +115,7 @@ void C3D_RENDER_OGL_LEGACY::generate_ring_contour( const SFVEC2F &aCenter,
void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CRING2D * aRing, void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CRING2D * aRing,
CLAYER_TRIANGLES *aDstLayer, CLAYER_TRIANGLES *aDstLayer,
float aZtop, float aZtop, float aZbot )
float aZbot )
{ {
const SFVEC2F &center = aRing->GetCenter(); const SFVEC2F &center = aRing->GetCenter();
const float inner = aRing->GetInnerRadius(); const float inner = aRing->GetInnerRadius();
@ -170,8 +156,7 @@ void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CRING2D * aRing,
void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CTRIANGLE2D * aTri, void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CTRIANGLE2D * aTri,
CLAYER_TRIANGLES *aDstLayer, CLAYER_TRIANGLES *aDstLayer,
float aZtop, float aZtop, float aZbot )
float aZbot )
{ {
const SFVEC2F &v1 = aTri->GetP1(); const SFVEC2F &v1 = aTri->GetP1();
const SFVEC2F &v2 = aTri->GetP2(); const SFVEC2F &v2 = aTri->GetP2();
@ -183,8 +168,7 @@ void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CTRIANGLE2D * aT
void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CROUNDSEGMENT2D * aSeg, void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CROUNDSEGMENT2D * aSeg,
CLAYER_TRIANGLES *aDstLayer, CLAYER_TRIANGLES *aDstLayer,
float aZtop, float aZtop, float aZbot )
float aZbot )
{ {
const SFVEC2F& leftStart = aSeg->GetLeftStar(); const SFVEC2F& leftStart = aSeg->GetLeftStar();
const SFVEC2F& leftEnd = aSeg->GetLeftEnd(); const SFVEC2F& leftEnd = aSeg->GetLeftEnd();
@ -295,17 +279,17 @@ CLAYERS_OGL_DISP_LISTS *C3D_RENDER_OGL_LEGACY::generate_holes_display_list(
{ {
case OBJECT2D_TYPE::FILLED_CIRCLE: case OBJECT2D_TYPE::FILLED_CIRCLE:
add_object_to_triangle_layer( static_cast<const CFILLEDCIRCLE2D*>( object2d_A ), add_object_to_triangle_layer( static_cast<const CFILLEDCIRCLE2D*>( object2d_A ),
layerTriangles, aZtop, aZbot ); layerTriangles, aZtop, aZbot );
break; break;
case OBJECT2D_TYPE::ROUNDSEG: case OBJECT2D_TYPE::ROUNDSEG:
add_object_to_triangle_layer( static_cast<const CROUNDSEGMENT2D*>( object2d_A ), add_object_to_triangle_layer( static_cast<const CROUNDSEGMENT2D*>( object2d_A ),
layerTriangles, aZtop, aZbot ); layerTriangles, aZtop, aZbot );
break; break;
default: default:
wxFAIL_MSG( wxFAIL_MSG( "C3D_RENDER_OGL_LEGACY::generate_holes_display_list: "
"C3D_RENDER_OGL_LEGACY::generate_holes_display_list: Object type is not implemented" ); "Object type is not implemented" );
break; break;
} }
} }
@ -316,18 +300,12 @@ CLAYERS_OGL_DISP_LISTS *C3D_RENDER_OGL_LEGACY::generate_holes_display_list(
if( aPoly.OutlineCount() > 0 ) if( aPoly.OutlineCount() > 0 )
{ {
layerTriangles->AddToMiddleContourns( aPoly, layerTriangles->AddToMiddleContourns( aPoly, aZbot, aZtop,
aZbot,
aZtop,
m_boardAdapter.BiuTo3Dunits(), m_boardAdapter.BiuTo3Dunits(),
aInvertFaces, aInvertFaces, aThroughHoles );
aThroughHoles );
} }
ret = new CLAYERS_OGL_DISP_LISTS( *layerTriangles, ret = new CLAYERS_OGL_DISP_LISTS( *layerTriangles, m_ogl_circle_texture, aZbot, aZtop );
m_ogl_circle_texture,
aZbot,
aZtop );
delete layerTriangles; delete layerTriangles;
} }
@ -336,10 +314,11 @@ CLAYERS_OGL_DISP_LISTS *C3D_RENDER_OGL_LEGACY::generate_holes_display_list(
} }
CLAYERS_OGL_DISP_LISTS* C3D_RENDER_OGL_LEGACY::generateLayerListFromContainer( const CBVHCONTAINER2D *aContainer, CLAYERS_OGL_DISP_LISTS*
const SHAPE_POLY_SET *aPolyList, C3D_RENDER_OGL_LEGACY::generateLayerListFromContainer( const CBVHCONTAINER2D *aContainer,
PCB_LAYER_ID aLayerId, const SHAPE_POLY_SET *aPolyList,
const CBVHCONTAINER2D *aThroughHoles ) PCB_LAYER_ID aLayerId,
const CBVHCONTAINER2D *aThroughHoles )
{ {
if( aContainer == nullptr ) if( aContainer == nullptr )
return nullptr; return nullptr;
@ -402,19 +381,20 @@ CLAYERS_OGL_DISP_LISTS* C3D_RENDER_OGL_LEGACY::generateLayerListFromContainer( c
} }
} }
if( aPolyList ) if( aPolyList &&aPolyList->OutlineCount() > 0 )
if( aPolyList->OutlineCount() > 0 ) {
layerTriangles->AddToMiddleContourns( *aPolyList, layer_z_bot, layer_z_top, layerTriangles->AddToMiddleContourns( *aPolyList, layer_z_bot, layer_z_top,
m_boardAdapter.BiuTo3Dunits(), false, m_boardAdapter.BiuTo3Dunits(), false, aThroughHoles );
aThroughHoles ); }
// Create display list // Create display list
// ///////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////
return new CLAYERS_OGL_DISP_LISTS( *layerTriangles, m_ogl_circle_texture, return new CLAYERS_OGL_DISP_LISTS( *layerTriangles, m_ogl_circle_texture, layer_z_bot,
layer_z_bot, layer_z_top ); layer_z_top );
} }
CLAYERS_OGL_DISP_LISTS* C3D_RENDER_OGL_LEGACY::createBoard( const SHAPE_POLY_SET& aBoardPoly, const CBVHCONTAINER2D *aThroughHoles ) CLAYERS_OGL_DISP_LISTS* C3D_RENDER_OGL_LEGACY::createBoard( const SHAPE_POLY_SET& aBoardPoly,
const CBVHCONTAINER2D *aThroughHoles )
{ {
CLAYERS_OGL_DISP_LISTS* dispLists = nullptr; CLAYERS_OGL_DISP_LISTS* dispLists = nullptr;
CCONTAINER2D boardContainer; CCONTAINER2D boardContainer;
@ -451,27 +431,17 @@ CLAYERS_OGL_DISP_LISTS* C3D_RENDER_OGL_LEGACY::createBoard( const SHAPE_POLY_SET
const SFVEC2F &v2 = tri->GetP2(); const SFVEC2F &v2 = tri->GetP2();
const SFVEC2F &v3 = tri->GetP3(); const SFVEC2F &v3 = tri->GetP3();
add_triangle_top_bot( layerTriangles, add_triangle_top_bot( layerTriangles, v1, v2, v3, layer_z_top, layer_z_bot );
v1,
v2,
v3,
layer_z_top,
layer_z_bot );
} }
if( aBoardPoly.OutlineCount() > 0 ) if( aBoardPoly.OutlineCount() > 0 )
{ {
layerTriangles->AddToMiddleContourns( aBoardPoly, layerTriangles->AddToMiddleContourns( aBoardPoly, layer_z_bot, layer_z_top,
layer_z_bot, m_boardAdapter.BiuTo3Dunits(), false,
layer_z_top,
m_boardAdapter.BiuTo3Dunits(),
false,
aThroughHoles ); aThroughHoles );
dispLists = 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;
@ -502,7 +472,7 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
// Create Board // Create Board
// ///////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////
m_ogl_disp_list_board = createBoard( m_boardAdapter.GetBoardPoly(), &m_boardAdapter.GetThroughHole_Inner() ); m_board = createBoard( m_boardAdapter.GetBoardPoly(), &m_boardAdapter.GetThroughHole_Inner() );
if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) )
{ {
@ -514,19 +484,22 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
m_anti_board_poly.Append( VECTOR2I( -INT_MAX/2, INT_MAX/2 ) ); m_anti_board_poly.Append( VECTOR2I( -INT_MAX/2, INT_MAX/2 ) );
m_anti_board_poly.Outline( 0 ).SetClosed( true ); m_anti_board_poly.Outline( 0 ).SetClosed( true );
m_anti_board_poly.BooleanSubtract( m_boardAdapter.GetBoardPoly(), SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); m_anti_board_poly.BooleanSubtract( m_boardAdapter.GetBoardPoly(),
m_ogl_disp_list_anti_board = createBoard( m_anti_board_poly ); SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
m_anti_board = createBoard( m_anti_board_poly );
} }
SHAPE_POLY_SET board_poly_with_holes = m_boardAdapter.GetBoardPoly(); SHAPE_POLY_SET board_poly_with_holes = m_boardAdapter.GetBoardPoly();
board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly(), SHAPE_POLY_SET::PM_FAST ); board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly(),
board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly_NPTH(), SHAPE_POLY_SET::PM_FAST ); SHAPE_POLY_SET::PM_FAST );
board_poly_with_holes.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly_NPTH(),
SHAPE_POLY_SET::PM_FAST );
m_ogl_disp_list_board_with_holes = createBoard( board_poly_with_holes ); m_board_with_holes = createBoard( board_poly_with_holes );
if( m_ogl_disp_list_anti_board ) if( m_anti_board )
m_ogl_disp_list_anti_board->SetItIsTransparent( true ); m_anti_board->SetItIsTransparent( true );
// Create Through Holes and vias // Create Through Holes and vias
// ///////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////
@ -539,7 +512,7 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) )
outerPolyTHT.BooleanIntersection( m_boardAdapter.GetBoardPoly(), SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); outerPolyTHT.BooleanIntersection( m_boardAdapter.GetBoardPoly(), SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
m_ogl_disp_list_through_holes_outer = generate_holes_display_list( m_through_holes_outer = generate_holes_display_list(
m_boardAdapter.GetThroughHole_Outer().GetList(), m_boardAdapter.GetThroughHole_Outer().GetList(),
outerPolyTHT, outerPolyTHT,
1.0f, 1.0f,
@ -547,7 +520,7 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
false, false,
&m_boardAdapter.GetThroughHole_Inner() ); &m_boardAdapter.GetThroughHole_Inner() );
m_ogl_disp_list_through_holes_vias_outer = generate_holes_display_list( m_through_holes_vias_outer = generate_holes_display_list(
m_boardAdapter.GetThroughHole_Vias_Outer().GetList(), m_boardAdapter.GetThroughHole_Vias_Outer().GetList(),
m_boardAdapter.GetThroughHole_Vias_Outer_poly(), m_boardAdapter.GetThroughHole_Vias_Outer_poly(),
1.0f, 1.0f,
@ -557,7 +530,7 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
if( m_boardAdapter.GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && if( m_boardAdapter.GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) &&
m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) )
{ {
m_ogl_disp_list_through_holes_outer_ring = generate_holes_display_list( m_through_holes_outer_ring = generate_holes_display_list(
m_boardAdapter.GetThroughHole_Outer_Ring().GetList(), m_boardAdapter.GetThroughHole_Outer_Ring().GetList(),
m_boardAdapter.GetThroughHole_Outer_Ring_poly(), m_boardAdapter.GetThroughHole_Outer_Ring_poly(),
1.0f, 1.0f,
@ -594,8 +567,9 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
get_layer_z_pos( layer_id, layer_z_top, layer_z_bot ); get_layer_z_pos( layer_id, layer_z_top, layer_z_bot );
m_ogl_disp_lists_layers_holes_outer[layer_id] = generate_holes_display_list( m_layers_holes_outer[layer_id] = generate_holes_display_list( container->GetList(),
container->GetList(), *poly, layer_z_top, layer_z_bot, false ); *poly, layer_z_top,
layer_z_bot, false );
} }
for( MAP_POLY::const_iterator ii = innerMapHoles.begin(); for( MAP_POLY::const_iterator ii = innerMapHoles.begin();
@ -608,8 +582,9 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
get_layer_z_pos( layer_id, layer_z_top, layer_z_bot ); get_layer_z_pos( layer_id, layer_z_top, layer_z_bot );
m_ogl_disp_lists_layers_holes_inner[layer_id] = generate_holes_display_list( m_layers_holes_inner[layer_id] = generate_holes_display_list( container->GetList(),
container->GetList(), *poly, layer_z_top, layer_z_bot, false ); *poly, layer_z_top,
layer_z_bot, false );
} }
} }
@ -650,17 +625,24 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
if( ( layer_id != B_Mask ) && ( layer_id != F_Mask ) ) if( ( layer_id != B_Mask ) && ( layer_id != F_Mask ) )
{ {
polyListSubtracted.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly(), SHAPE_POLY_SET::PM_FAST ); polyListSubtracted.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly(),
polyListSubtracted.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly_NPTH(), SHAPE_POLY_SET::PM_FAST ); SHAPE_POLY_SET::PM_FAST );
polyListSubtracted.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly_NPTH(),
SHAPE_POLY_SET::PM_FAST );
} }
if( m_boardAdapter.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ) ) if( m_boardAdapter.GetFlag( FL_SUBTRACT_MASK_FROM_SILK ) )
{ {
if( ( ( layer_id == B_SilkS ) && ( map_poly.find( B_Mask ) != map_poly.end() ) ) ) if( layer_id == B_SilkS && map_poly.find( B_Mask ) != map_poly.end() )
polyListSubtracted.BooleanSubtract( *map_poly.at( B_Mask ), SHAPE_POLY_SET::PM_FAST ); {
else polyListSubtracted.BooleanSubtract( *map_poly.at( B_Mask ),
if( ( ( layer_id == F_SilkS ) && ( map_poly.find( F_Mask ) != map_poly.end() ) ) ) SHAPE_POLY_SET::PM_FAST );
polyListSubtracted.BooleanSubtract( *map_poly.at( F_Mask ), SHAPE_POLY_SET::PM_FAST ); }
else if( layer_id == F_SilkS && map_poly.find( F_Mask ) != map_poly.end() )
{
polyListSubtracted.BooleanSubtract( *map_poly.at( F_Mask ),
SHAPE_POLY_SET::PM_FAST );
}
} }
} }
@ -668,13 +650,12 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
aPolyList = &polyListSubtracted; aPolyList = &polyListSubtracted;
} }
CLAYERS_OGL_DISP_LISTS* oglList = generateLayerListFromContainer( container2d, CLAYERS_OGL_DISP_LISTS* oglList = generateLayerListFromContainer( container2d, aPolyList,
aPolyList,
layer_id, layer_id,
&m_boardAdapter.GetThroughHole_Inner() ); &m_boardAdapter.GetThroughHole_Inner() );
if( oglList != nullptr ) if( oglList != nullptr )
m_ogl_disp_lists_layers[layer_id] = oglList; m_layers[layer_id] = oglList;
}// for each layer on }// for each layer on
@ -684,23 +665,29 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
if( m_boardAdapter.GetPolyPlatedPads_Front() ) if( m_boardAdapter.GetPolyPlatedPads_Front() )
{ {
SHAPE_POLY_SET polySubtracted = *m_boardAdapter.GetPolyPlatedPads_Front(); SHAPE_POLY_SET polySubtracted = *m_boardAdapter.GetPolyPlatedPads_Front();
polySubtracted.BooleanIntersection( m_boardAdapter.GetBoardPoly(), SHAPE_POLY_SET::PM_FAST ); polySubtracted.BooleanIntersection( m_boardAdapter.GetBoardPoly(),
polySubtracted.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly(), SHAPE_POLY_SET::PM_FAST ); SHAPE_POLY_SET::PM_FAST );
polySubtracted.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly_NPTH(), SHAPE_POLY_SET::PM_FAST ); polySubtracted.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly(),
SHAPE_POLY_SET::PM_FAST );
polySubtracted.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly_NPTH(),
SHAPE_POLY_SET::PM_FAST );
m_ogl_disp_lists_platedPads_F_Cu = generateLayerListFromContainer( m_boardAdapter.GetPlatedPads_Front(), m_platedPads_F_Cu = generateLayerListFromContainer( m_boardAdapter.GetPlatedPads_Front(),
&polySubtracted, F_Cu ); &polySubtracted, F_Cu );
} }
if( m_boardAdapter.GetPolyPlatedPads_Back() ) if( m_boardAdapter.GetPolyPlatedPads_Back() )
{ {
SHAPE_POLY_SET polySubtracted = *m_boardAdapter.GetPolyPlatedPads_Back(); SHAPE_POLY_SET polySubtracted = *m_boardAdapter.GetPolyPlatedPads_Back();
polySubtracted.BooleanIntersection( m_boardAdapter.GetBoardPoly(), SHAPE_POLY_SET::PM_FAST ); polySubtracted.BooleanIntersection( m_boardAdapter.GetBoardPoly(),
polySubtracted.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly(), SHAPE_POLY_SET::PM_FAST ); SHAPE_POLY_SET::PM_FAST );
polySubtracted.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly_NPTH(), SHAPE_POLY_SET::PM_FAST ); polySubtracted.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly(),
SHAPE_POLY_SET::PM_FAST );
polySubtracted.BooleanSubtract( m_boardAdapter.GetThroughHole_Outer_poly_NPTH(),
SHAPE_POLY_SET::PM_FAST );
m_ogl_disp_lists_platedPads_B_Cu = generateLayerListFromContainer( m_boardAdapter.GetPlatedPads_Back(), m_platedPads_B_Cu = generateLayerListFromContainer( m_boardAdapter.GetPlatedPads_Back(),
&polySubtracted, B_Cu ); &polySubtracted, B_Cu );
} }
} }
@ -766,13 +753,8 @@ void C3D_RENDER_OGL_LEGACY::generate_cylinder( const SFVEC2F &aCenter,
std::vector< SFVEC2F > innerContour; std::vector< SFVEC2F > innerContour;
std::vector< SFVEC2F > outerContour; std::vector< SFVEC2F > outerContour;
generate_ring_contour( aCenter, generate_ring_contour( aCenter, aInnerRadius, aOuterRadius, aNr_sides_per_circle,
aInnerRadius, innerContour, outerContour, false );
aOuterRadius,
aNr_sides_per_circle,
innerContour,
outerContour,
false );
for( unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i ) for( unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
{ {
@ -836,20 +818,12 @@ void C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads()
wxASSERT( zbot < ztop ); wxASSERT( zbot < ztop );
generate_cylinder( via_center, generate_cylinder( via_center, hole_inner_radius, hole_inner_radius + thickness,
hole_inner_radius, ztop, zbot, nrSegments, layerTriangleVIA );
hole_inner_radius + thickness,
ztop,
zbot,
nrSegments,
layerTriangleVIA );
} }
} }
m_ogl_disp_list_via = new CLAYERS_OGL_DISP_LISTS( *layerTriangleVIA, m_vias = new CLAYERS_OGL_DISP_LISTS( *layerTriangleVIA, 0, 0.0f, 0.0f );
0,
0.0f,
0.0f );
delete layerTriangleVIA; delete layerTriangleVIA;
} }
@ -895,8 +869,7 @@ void C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads()
CCONTAINER2D holesContainer; CCONTAINER2D holesContainer;
Convert_shape_line_polygon_to_triangles( tht_outer_holes_poly, Convert_shape_line_polygon_to_triangles( tht_outer_holes_poly, holesContainer,
holesContainer,
m_boardAdapter.BiuTo3Dunits(), m_boardAdapter.BiuTo3Dunits(),
(const BOARD_ITEM &)*m_boardAdapter.GetBoard() ); (const BOARD_ITEM &)*m_boardAdapter.GetBoard() );
@ -926,8 +899,7 @@ void C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads()
const SFVEC2F &v2 = tri->GetP2(); const SFVEC2F &v2 = tri->GetP2();
const SFVEC2F &v3 = tri->GetP3(); const SFVEC2F &v3 = tri->GetP3();
add_triangle_top_bot( layerTriangles, v1, v2, v3, add_triangle_top_bot( layerTriangles, v1, v2, v3, layer_z_top, layer_z_bot );
layer_z_top, layer_z_bot );
} }
wxASSERT( tht_outer_holes_poly.OutlineCount() > 0 ); wxASSERT( tht_outer_holes_poly.OutlineCount() > 0 );
@ -936,13 +908,11 @@ void C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads()
{ {
layerTriangles->AddToMiddleContourns( tht_outer_holes_poly, layerTriangles->AddToMiddleContourns( tht_outer_holes_poly,
layer_z_bot, layer_z_top, layer_z_bot, layer_z_top,
m_boardAdapter.BiuTo3Dunits(), m_boardAdapter.BiuTo3Dunits(), false );
false );
m_ogl_disp_list_pads_holes = new CLAYERS_OGL_DISP_LISTS( m_pad_holes = new CLAYERS_OGL_DISP_LISTS( *layerTriangles,
*layerTriangles, m_ogl_circle_texture, // not need
m_ogl_circle_texture, // not need layer_z_top, layer_z_top );
layer_z_top, layer_z_top );
} }
delete layerTriangles; delete layerTriangles;

View File

@ -22,18 +22,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
/**
* @file c3d_render_ogl_legacy.cpp
* @brief
*/
#include <gal/opengl/kiglew.h> // Must be included first #include <gal/opengl/kiglew.h> // Must be included first
#include "c3d_render_ogl_legacy.h" #include "c3d_render_ogl_legacy.h"
#include "ogl_legacy_utils.h" #include "ogl_legacy_utils.h"
#include "common_ogl/ogl_utils.h" #include "common_ogl/ogl_utils.h"
#include "../cimage.h"
#include <board.h>
#include <footprint.h> #include <footprint.h>
#include <3d_math.h> #include <3d_math.h>
#include <math/util.h> // for KiROUND #include <math/util.h> // for KiROUND
@ -50,30 +43,29 @@ C3D_RENDER_OGL_LEGACY::C3D_RENDER_OGL_LEGACY( BOARD_ADAPTER& aAdapter, CCAMERA&
{ {
wxLogTrace( m_logTrace, wxT( "C3D_RENDER_OGL_LEGACY::C3D_RENDER_OGL_LEGACY" ) ); wxLogTrace( m_logTrace, wxT( "C3D_RENDER_OGL_LEGACY::C3D_RENDER_OGL_LEGACY" ) );
m_ogl_disp_lists_layers.clear(); m_layers.clear();
m_ogl_disp_lists_layers_holes_outer.clear(); m_layers_holes_outer.clear();
m_ogl_disp_lists_layers_holes_inner.clear(); m_layers_holes_inner.clear();
m_triangles.clear(); m_triangles.clear();
m_ogl_disp_list_board = NULL; m_board = NULL;
m_ogl_disp_list_anti_board = NULL; m_anti_board = NULL;
m_ogl_disp_lists_platedPads_F_Cu = nullptr; m_platedPads_F_Cu = nullptr;
m_ogl_disp_lists_platedPads_B_Cu = nullptr; m_platedPads_B_Cu = nullptr;
m_ogl_disp_list_through_holes_outer = NULL; m_through_holes_outer = NULL;
m_ogl_disp_list_through_holes_outer_ring = NULL; m_through_holes_outer_ring = NULL;
m_ogl_disp_list_through_holes_vias_outer = NULL; m_through_holes_vias_outer = NULL;
//m_ogl_disp_list_through_holes_vias_inner = NULL; //m_ogl_disp_list_through_holes_vias_inner = NULL;
m_ogl_disp_list_via = NULL; m_vias = NULL;
m_ogl_disp_list_pads_holes = NULL; m_pad_holes = NULL;
m_ogl_disp_list_vias_and_pad_holes_outer_contourn_and_caps = NULL; m_vias_and_pad_holes_outer_contourn_and_caps = NULL;
m_ogl_circle_texture = 0; m_ogl_circle_texture = 0;
m_ogl_disp_list_grid = 0; m_grid = 0;
m_last_grid_type = GRID3D_TYPE::NONE; m_last_grid_type = GRID3D_TYPE::NONE;
m_currentIntersectedBoardItem = nullptr; m_currentIntersectedBoardItem = nullptr;
m_ogl_disp_list_board_with_holes = nullptr; m_board_with_holes = nullptr;
m_ogl_disp_list_through_holes_outer_with_npth = nullptr;
m_3dmodel_map.clear(); m_3dmodel_map.clear();
} }
@ -151,9 +143,8 @@ void C3D_RENDER_OGL_LEGACY::render_3D_arrows()
glMatrixMode( GL_MODELVIEW ); glMatrixMode( GL_MODELVIEW );
glLoadIdentity(); glLoadIdentity();
const glm::mat4 TranslationMatrix = glm::translate( const glm::mat4 TranslationMatrix = glm::translate( glm::mat4(1.0f),
glm::mat4(1.0f), SFVEC3F( 0.0f, 0.0f, -(arrow_size * 2.75f) ) );
SFVEC3F( 0.0f, 0.0f, -(arrow_size * 2.75f) ) );
const glm::mat4 ViewMatrix = TranslationMatrix * m_camera.GetRotationMatrix(); const glm::mat4 ViewMatrix = TranslationMatrix * m_camera.GetRotationMatrix();
@ -378,15 +369,14 @@ void C3D_RENDER_OGL_LEGACY::set_layer_material( PCB_LAYER_ID aLayerID )
case B_Fab: case B_Fab:
case F_Fab: case F_Fab:
m_materials.m_Plastic.m_Diffuse = get_layer_color( aLayerID ); m_materials.m_Plastic.m_Diffuse = get_layer_color( aLayerID );
m_materials.m_Plastic.m_Ambient = SFVEC3F(
m_materials.m_Plastic.m_Diffuse.r * 0.05f,
m_materials.m_Plastic.m_Diffuse.g * 0.05f,
m_materials.m_Plastic.m_Diffuse.b * 0.05f );
m_materials.m_Plastic.m_Specular = SFVEC3F( m_materials.m_Plastic.m_Ambient = SFVEC3F( m_materials.m_Plastic.m_Diffuse.r * 0.05f,
m_materials.m_Plastic.m_Diffuse.r * 0.7f, m_materials.m_Plastic.m_Diffuse.g * 0.05f,
m_materials.m_Plastic.m_Diffuse.g * 0.7f, m_materials.m_Plastic.m_Diffuse.b * 0.05f );
m_materials.m_Plastic.m_Diffuse.b * 0.7f );
m_materials.m_Plastic.m_Specular = SFVEC3F( m_materials.m_Plastic.m_Diffuse.r * 0.7f,
m_materials.m_Plastic.m_Diffuse.g * 0.7f,
m_materials.m_Plastic.m_Diffuse.b * 0.7f );
m_materials.m_Plastic.m_Shininess = 0.078125f * 128.0f; m_materials.m_Plastic.m_Shininess = 0.078125f * 128.0f;
m_materials.m_Plastic.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f ); m_materials.m_Plastic.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
@ -538,9 +528,9 @@ void C3D_RENDER_OGL_LEGACY::render_board_body( bool aSkipRenderHoles )
CLAYERS_OGL_DISP_LISTS* ogl_disp_list = nullptr; CLAYERS_OGL_DISP_LISTS* ogl_disp_list = nullptr;
if( aSkipRenderHoles ) if( aSkipRenderHoles )
ogl_disp_list = m_ogl_disp_list_board; ogl_disp_list = m_board;
else else
ogl_disp_list = m_ogl_disp_list_board_with_holes; ogl_disp_list = m_board_with_holes;
if( ogl_disp_list ) if( ogl_disp_list )
{ {
@ -683,21 +673,15 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
OGL_SetMaterial( m_materials.m_GrayMaterial, 1.0f ); OGL_SetMaterial( m_materials.m_GrayMaterial, 1.0f );
} }
if( (!( skipRenderVias || skipRenderHoles ) ) && m_ogl_disp_list_via ) if( !( skipRenderVias || skipRenderHoles ) && m_vias )
{ m_vias->DrawAll();
m_ogl_disp_list_via->DrawAll();
}
if( ( !skipRenderHoles ) && m_ogl_disp_list_pads_holes ) if( !skipRenderHoles && m_pad_holes )
{ m_pad_holes->DrawAll();
m_ogl_disp_list_pads_holes->DrawAll();
}
// Display copper and tech layers // Display copper and tech layers
// ///////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////
for( MAP_OGL_DISP_LISTS::const_iterator ii = m_ogl_disp_lists_layers.begin(); for( MAP_OGL_DISP_LISTS::const_iterator ii = m_layers.begin(); ii != m_layers.end(); ++ii )
ii != m_ogl_disp_lists_layers.end();
++ii )
{ {
const PCB_LAYER_ID layer_id = (PCB_LAYER_ID)(ii->first); const PCB_LAYER_ID layer_id = (PCB_LAYER_ID)(ii->first);
@ -738,69 +722,73 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
// 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_platedPads_F_Cu || m_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_platedPads_F_Cu )
m_ogl_disp_lists_platedPads_F_Cu->DrawAllCameraCulled( m_camera.GetPos().z, {
drawMiddleSegments );
else m_platedPads_F_Cu->DrawAllCameraCulled( m_camera.GetPos().z,
if( ( layer_id == B_Cu ) && m_ogl_disp_lists_platedPads_B_Cu ) drawMiddleSegments );
m_ogl_disp_lists_platedPads_B_Cu->DrawAllCameraCulled( m_camera.GetPos().z, }
drawMiddleSegments ); else if( layer_id == B_Cu && m_platedPads_B_Cu )
{
m_platedPads_B_Cu->DrawAllCameraCulled( m_camera.GetPos().z,
drawMiddleSegments );
}
unsetDepthOffset(); unsetDepthOffset();
} }
else else
{ {
if( m_ogl_disp_list_through_holes_outer ) if( m_through_holes_outer )
m_ogl_disp_list_through_holes_outer->ApplyScalePosition(
pLayerDispList->GetZBot(),
pLayerDispList->GetZTop() - pLayerDispList->GetZBot() );
if( m_ogl_disp_list_anti_board )
{ {
m_ogl_disp_list_anti_board->ApplyScalePosition( pLayerDispList->GetZBot(), m_through_holes_outer->ApplyScalePosition( pLayerDispList->GetZBot(),
pLayerDispList->GetZTop() - pLayerDispList->GetZBot() ); pLayerDispList->GetZTop()
- pLayerDispList->GetZBot() );
} }
if( m_ogl_disp_lists_layers_holes_outer.find( layer_id ) != if( m_anti_board )
m_ogl_disp_lists_layers_holes_outer.end() )
{ {
const CLAYERS_OGL_DISP_LISTS* viasHolesLayer = m_anti_board->ApplyScalePosition( pLayerDispList->GetZBot(),
m_ogl_disp_lists_layers_holes_outer.at( layer_id ); pLayerDispList->GetZTop()
- pLayerDispList->GetZBot() );
}
if( m_layers_holes_outer.find( layer_id ) != m_layers_holes_outer.end() )
{
const CLAYERS_OGL_DISP_LISTS* viasHolesLayer = m_layers_holes_outer.at( layer_id );
wxASSERT( viasHolesLayer != NULL ); wxASSERT( viasHolesLayer != NULL );
if( viasHolesLayer != NULL ) if( viasHolesLayer != NULL )
{ {
pLayerDispList->DrawAllCameraCulledSubtractLayer( pLayerDispList->DrawAllCameraCulledSubtractLayer( drawMiddleSegments,
drawMiddleSegments, m_through_holes_outer,
m_ogl_disp_list_through_holes_outer, viasHolesLayer,
viasHolesLayer, m_anti_board );
m_ogl_disp_list_anti_board );
// 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_platedPads_F_Cu || m_platedPads_B_Cu ) )
{
setPlatedCopperAndDepthOffset( layer_id ); 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,
m_ogl_disp_list_anti_board );
} }
else if( ( layer_id == B_Cu ) && m_ogl_disp_lists_platedPads_B_Cu )
if( layer_id == F_Cu && m_platedPads_F_Cu )
{ {
m_ogl_disp_lists_platedPads_B_Cu->DrawAllCameraCulledSubtractLayer( m_platedPads_F_Cu->DrawAllCameraCulledSubtractLayer( drawMiddleSegments,
drawMiddleSegments, m_through_holes_outer,
m_ogl_disp_list_through_holes_outer, viasHolesLayer,
viasHolesLayer, m_anti_board );
m_ogl_disp_list_anti_board ); }
else if( layer_id == B_Cu && m_platedPads_B_Cu )
{
m_platedPads_B_Cu->DrawAllCameraCulledSubtractLayer( drawMiddleSegments,
m_through_holes_outer,
viasHolesLayer,
m_anti_board );
} }
unsetDepthOffset(); unsetDepthOffset();
@ -808,32 +796,28 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
} }
else else
{ {
pLayerDispList->DrawAllCameraCulledSubtractLayer( pLayerDispList->DrawAllCameraCulledSubtractLayer( m_through_holes_outer,
drawMiddleSegments, m_anti_board );
m_ogl_disp_list_through_holes_outer,
m_ogl_disp_list_anti_board );
// 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_platedPads_F_Cu || m_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_platedPads_F_Cu )
{ {
m_ogl_disp_lists_platedPads_F_Cu->DrawAllCameraCulledSubtractLayer( m_platedPads_F_Cu->DrawAllCameraCulledSubtractLayer( drawMiddleSegments,
drawMiddleSegments, m_through_holes_outer,
m_ogl_disp_list_through_holes_outer, m_anti_board );
m_ogl_disp_list_anti_board );
} }
else if( ( layer_id == B_Cu ) && m_ogl_disp_lists_platedPads_B_Cu ) else if( layer_id == B_Cu && m_platedPads_B_Cu )
{ {
m_ogl_disp_lists_platedPads_B_Cu->DrawAllCameraCulledSubtractLayer( m_platedPads_B_Cu->DrawAllCameraCulledSubtractLayer( drawMiddleSegments,
drawMiddleSegments, m_through_holes_outer,
m_ogl_disp_list_through_holes_outer, m_anti_board );
m_ogl_disp_list_anti_board );
} }
unsetDepthOffset(); unsetDepthOffset();
@ -844,58 +828,51 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
{ {
set_layer_material( layer_id ); set_layer_material( layer_id );
CLAYERS_OGL_DISP_LISTS* dispListThroughHolesOuter = CLAYERS_OGL_DISP_LISTS* throughHolesOuter =
( m_boardAdapter.GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && m_boardAdapter.GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS )
m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) && m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE )
&& ( ( layer_id == B_SilkS ) || ( layer_id == F_SilkS ) ) ) ? && ( layer_id == B_SilkS || layer_id == F_SilkS ) ? m_through_holes_outer_ring
m_ogl_disp_list_through_holes_outer_ring : : m_through_holes_outer;
m_ogl_disp_list_through_holes_outer;
if( dispListThroughHolesOuter ) if( throughHolesOuter )
{ {
dispListThroughHolesOuter->ApplyScalePosition( pLayerDispList->GetZBot(), throughHolesOuter->ApplyScalePosition( pLayerDispList->GetZBot(),
pLayerDispList->GetZTop() - pLayerDispList->GetZBot() ); pLayerDispList->GetZTop() - pLayerDispList->GetZBot() );
} }
CLAYERS_OGL_DISP_LISTS* ogl_disp_list_anti_board = m_ogl_disp_list_anti_board; CLAYERS_OGL_DISP_LISTS* anti_board = m_anti_board;
if( ( layer_id == B_Paste ) || ( layer_id == F_Paste ) ) if( ( layer_id == B_Paste ) || ( layer_id == F_Paste ) )
ogl_disp_list_anti_board = nullptr; anti_board = nullptr;
if( ogl_disp_list_anti_board ) if( anti_board )
{ {
ogl_disp_list_anti_board->ApplyScalePosition( pLayerDispList->GetZBot(), anti_board->ApplyScalePosition( pLayerDispList->GetZBot(),
pLayerDispList->GetZTop() - 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 )
m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) && && m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE )
( ( ( layer_id == B_SilkS ) && && ( ( layer_id == B_SilkS && m_layers.find( B_Mask ) != m_layers.end() )
( m_ogl_disp_lists_layers.find( B_Mask ) != m_ogl_disp_lists_layers.end() ) ) || || ( layer_id == F_SilkS && m_layers.find( F_Mask ) != m_layers.end() ) ) )
( ( layer_id == F_SilkS ) &&
( 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_layers.at( layerMask_id );
pLayerDispList->DrawAllCameraCulledSubtractLayer( pLayerDispList->DrawAllCameraCulledSubtractLayer( drawMiddleSegments,
drawMiddleSegments, pLayerDispListMask,
pLayerDispListMask, throughHolesOuter, anti_board );
dispListThroughHolesOuter,
ogl_disp_list_anti_board );
} }
else else
{ {
if( !skipRenderHoles && if( !skipRenderHoles
dispListThroughHolesOuter && ( layer_id == B_SilkS || layer_id == F_SilkS ) ) && throughHolesOuter
&& ( layer_id == B_SilkS || layer_id == F_SilkS ) )
{ {
pLayerDispList->DrawAllCameraCulledSubtractLayer( pLayerDispList->DrawAllCameraCulledSubtractLayer( drawMiddleSegments, nullptr,
drawMiddleSegments, throughHolesOuter, anti_board );
nullptr,
dispListThroughHolesOuter,
ogl_disp_list_anti_board );
} }
else else
{ {
@ -903,9 +880,8 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
// otherwise it will cause z-fight issues // 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->DrawAllCameraCulledSubtractLayer( pLayerDispList->DrawAllCameraCulledSubtractLayer( drawMiddleSegments,
drawMiddleSegments, anti_board );
ogl_disp_list_anti_board );
} }
} }
} }
@ -1004,8 +980,8 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
{ {
glDisable( GL_LIGHTING ); glDisable( GL_LIGHTING );
if( glIsList( m_ogl_disp_list_grid ) ) if( glIsList( m_grid ) )
glCallList( m_ogl_disp_list_grid ); glCallList( m_grid );
glEnable( GL_LIGHTING ); glEnable( GL_LIGHTING );
} }
@ -1094,52 +1070,48 @@ void C3D_RENDER_OGL_LEGACY::ogl_set_arrow_material()
void C3D_RENDER_OGL_LEGACY::ogl_free_all_display_lists() void C3D_RENDER_OGL_LEGACY::ogl_free_all_display_lists()
{ {
if( glIsList( m_ogl_disp_list_grid ) ) if( glIsList( m_grid ) )
glDeleteLists( m_ogl_disp_list_grid, 1 ); glDeleteLists( m_grid, 1 );
m_ogl_disp_list_grid = 0; m_grid = 0;
for( MAP_OGL_DISP_LISTS::const_iterator ii = m_ogl_disp_lists_layers.begin(); for( MAP_OGL_DISP_LISTS::const_iterator ii = m_layers.begin(); ii != m_layers.end(); ++ii )
ii != m_ogl_disp_lists_layers.end(); {
CLAYERS_OGL_DISP_LISTS *pLayerDispList = static_cast<CLAYERS_OGL_DISP_LISTS*>(ii->second);
delete pLayerDispList;
}
m_layers.clear();
delete m_platedPads_F_Cu;
m_platedPads_F_Cu = nullptr;
delete m_platedPads_B_Cu;
m_platedPads_B_Cu = nullptr;
for( MAP_OGL_DISP_LISTS::const_iterator ii = m_layers_holes_outer.begin();
ii != m_layers_holes_outer.end();
++ii ) ++ii )
{ {
CLAYERS_OGL_DISP_LISTS *pLayerDispList = static_cast<CLAYERS_OGL_DISP_LISTS*>(ii->second); CLAYERS_OGL_DISP_LISTS *pLayerDispList = static_cast<CLAYERS_OGL_DISP_LISTS*>(ii->second);
delete pLayerDispList; delete pLayerDispList;
} }
m_ogl_disp_lists_layers.clear(); m_layers_holes_outer.clear();
delete m_ogl_disp_lists_platedPads_F_Cu;
m_ogl_disp_lists_platedPads_F_Cu = nullptr;
delete m_ogl_disp_lists_platedPads_B_Cu;
m_ogl_disp_lists_platedPads_B_Cu = nullptr;
for( MAP_OGL_DISP_LISTS::const_iterator ii = m_ogl_disp_lists_layers_holes_outer.begin(); for( MAP_OGL_DISP_LISTS::const_iterator ii = m_layers_holes_inner.begin();
ii != m_ogl_disp_lists_layers_holes_outer.end(); ii != m_layers_holes_inner.end();
++ii ) ++ii )
{ {
CLAYERS_OGL_DISP_LISTS *pLayerDispList = static_cast<CLAYERS_OGL_DISP_LISTS*>(ii->second); CLAYERS_OGL_DISP_LISTS *pLayerDispList = static_cast<CLAYERS_OGL_DISP_LISTS*>(ii->second);
delete pLayerDispList; delete pLayerDispList;
} }
m_ogl_disp_lists_layers_holes_outer.clear(); m_layers_holes_inner.clear();
for( LIST_TRIANGLES::const_iterator ii = m_triangles.begin(); ii != m_triangles.end(); ++ii )
for( MAP_OGL_DISP_LISTS::const_iterator ii = m_ogl_disp_lists_layers_holes_inner.begin();
ii != m_ogl_disp_lists_layers_holes_inner.end();
++ii )
{
CLAYERS_OGL_DISP_LISTS *pLayerDispList = static_cast<CLAYERS_OGL_DISP_LISTS*>(ii->second);
delete pLayerDispList;
}
m_ogl_disp_lists_layers_holes_inner.clear();
for( LIST_TRIANGLES::const_iterator ii = m_triangles.begin();
ii != m_triangles.end();
++ii )
{ {
delete *ii; delete *ii;
} }
@ -1147,9 +1119,7 @@ void C3D_RENDER_OGL_LEGACY::ogl_free_all_display_lists()
m_triangles.clear(); m_triangles.clear();
for( MAP_3DMODEL::const_iterator ii = m_3dmodel_map.begin(); for( MAP_3DMODEL::const_iterator ii = m_3dmodel_map.begin(); ii != m_3dmodel_map.end(); ++ii )
ii != m_3dmodel_map.end();
++ii )
{ {
C_OGL_3DMODEL *pointer = static_cast<C_OGL_3DMODEL*>(ii->second); C_OGL_3DMODEL *pointer = static_cast<C_OGL_3DMODEL*>(ii->second);
delete pointer; delete pointer;
@ -1158,99 +1128,86 @@ void C3D_RENDER_OGL_LEGACY::ogl_free_all_display_lists()
m_3dmodel_map.clear(); m_3dmodel_map.clear();
delete m_ogl_disp_list_board; delete m_board;
m_ogl_disp_list_board = nullptr; m_board = nullptr;
delete m_ogl_disp_list_anti_board; delete m_anti_board;
m_ogl_disp_list_anti_board = nullptr; m_anti_board = nullptr;
delete m_ogl_disp_list_through_holes_outer; delete m_through_holes_outer;
m_ogl_disp_list_through_holes_outer = nullptr; m_through_holes_outer = nullptr;
delete m_ogl_disp_list_through_holes_vias_outer; delete m_through_holes_vias_outer;
m_ogl_disp_list_through_holes_vias_outer = nullptr; m_through_holes_vias_outer = nullptr;
delete m_ogl_disp_list_through_holes_outer_ring; delete m_through_holes_outer_ring;
m_ogl_disp_list_through_holes_outer_ring = nullptr; m_through_holes_outer_ring = nullptr;
delete m_ogl_disp_list_via; delete m_vias;
m_ogl_disp_list_via = nullptr; m_vias = nullptr;
delete m_ogl_disp_list_pads_holes; delete m_pad_holes;
m_ogl_disp_list_pads_holes = nullptr; m_pad_holes = nullptr;
delete m_ogl_disp_list_vias_and_pad_holes_outer_contourn_and_caps; delete m_vias_and_pad_holes_outer_contourn_and_caps;
m_ogl_disp_list_vias_and_pad_holes_outer_contourn_and_caps = nullptr; m_vias_and_pad_holes_outer_contourn_and_caps = nullptr;
} }
void C3D_RENDER_OGL_LEGACY::render_solder_mask_layer(PCB_LAYER_ID aLayerID, void C3D_RENDER_OGL_LEGACY::render_solder_mask_layer(PCB_LAYER_ID aLayerID, float aZPosition,
float aZPosition,
bool aDrawMiddleSegments, bool aDrawMiddleSegments,
bool aSkipRenderHoles ) bool aSkipRenderHoles )
{ {
wxASSERT( (aLayerID == B_Mask) || (aLayerID == F_Mask) ); wxASSERT( (aLayerID == B_Mask) || (aLayerID == F_Mask) );
if( m_ogl_disp_list_board ) float nonCopperThickness = m_boardAdapter.GetNonCopperLayerThickness3DU();
if( m_board )
{ {
if( m_ogl_disp_lists_layers.find( aLayerID ) != if( m_layers.find( aLayerID ) != m_layers.end() )
m_ogl_disp_lists_layers.end() )
{ {
CLAYERS_OGL_DISP_LISTS *pLayerDispListMask = m_ogl_disp_lists_layers.at( aLayerID ); CLAYERS_OGL_DISP_LISTS *pLayerDispListMask = m_layers.at( aLayerID );
if( m_ogl_disp_list_through_holes_vias_outer ) if( m_through_holes_vias_outer )
m_ogl_disp_list_through_holes_vias_outer->ApplyScalePosition( m_through_holes_vias_outer->ApplyScalePosition( aZPosition, nonCopperThickness );
aZPosition,
m_boardAdapter.GetNonCopperLayerThickness3DU() );
m_ogl_disp_list_board->ApplyScalePosition( m_board->ApplyScalePosition( aZPosition, nonCopperThickness );
aZPosition,
m_boardAdapter.GetNonCopperLayerThickness3DU() );
set_layer_material( aLayerID ); set_layer_material( aLayerID );
m_ogl_disp_list_board->SetItIsTransparent( true ); m_board->SetItIsTransparent( true );
if( aSkipRenderHoles ) if( aSkipRenderHoles )
{ {
m_ogl_disp_list_board->DrawAllCameraCulled( m_camera.GetPos().z, m_board->DrawAllCameraCulled( m_camera.GetPos().z, aDrawMiddleSegments );
aDrawMiddleSegments );
} }
else else
{ {
m_ogl_disp_list_board->DrawAllCameraCulledSubtractLayer( m_board->DrawAllCameraCulledSubtractLayer( aDrawMiddleSegments, pLayerDispListMask,
aDrawMiddleSegments, m_through_holes_vias_outer );
pLayerDispListMask,
m_ogl_disp_list_through_holes_vias_outer );
} }
} }
else else
{ {
// This case there is no layer with mask, so we will render the full board as mask // This case there is no layer with mask, so we will render the full board as mask
if( m_ogl_disp_list_through_holes_vias_outer ) if( m_through_holes_vias_outer )
m_ogl_disp_list_through_holes_vias_outer->ApplyScalePosition( m_through_holes_vias_outer->ApplyScalePosition( aZPosition, nonCopperThickness );
aZPosition,
m_boardAdapter.GetNonCopperLayerThickness3DU() );
m_ogl_disp_list_board->ApplyScalePosition( m_board->ApplyScalePosition( aZPosition, nonCopperThickness );
aZPosition,
m_boardAdapter.GetNonCopperLayerThickness3DU() );
set_layer_material( aLayerID ); set_layer_material( aLayerID );
m_ogl_disp_list_board->SetItIsTransparent( true ); m_board->SetItIsTransparent( true );
if( aSkipRenderHoles ) if( aSkipRenderHoles )
{ {
m_ogl_disp_list_board->DrawAllCameraCulled( m_camera.GetPos().z, m_board->DrawAllCameraCulled( m_camera.GetPos().z, aDrawMiddleSegments );
aDrawMiddleSegments );
} }
else else
{ {
m_ogl_disp_list_board->DrawAllCameraCulledSubtractLayer( m_board->DrawAllCameraCulledSubtractLayer( aDrawMiddleSegments,
aDrawMiddleSegments, m_through_holes_vias_outer );
m_ogl_disp_list_through_holes_vias_outer );
} }
} }
} }
@ -1289,8 +1246,8 @@ void C3D_RENDER_OGL_LEGACY::render_3D_models_selected( bool aRenderTopOrBot,
{ {
if( m_boardAdapter.ShouldFPBeDisplayed( (FOOTPRINT_ATTR_T) fp->GetAttributes() ) ) if( m_boardAdapter.ShouldFPBeDisplayed( (FOOTPRINT_ATTR_T) fp->GetAttributes() ) )
{ {
if( ( aRenderTopOrBot && !fp->IsFlipped() ) if( ( aRenderTopOrBot && !fp->IsFlipped() )
|| ( !aRenderTopOrBot && fp->IsFlipped() ) ) || ( !aRenderTopOrBot && fp->IsFlipped() ) )
{ {
render_3D_footprint( fp, aRenderTransparentOnly, isIntersected ); render_3D_footprint( fp, aRenderTransparentOnly, isIntersected );
} }
@ -1333,7 +1290,7 @@ void C3D_RENDER_OGL_LEGACY::render_3D_footprint( const FOOTPRINT* aFootprint,
glTranslatef( pos.x * m_boardAdapter.BiuTo3Dunits(), glTranslatef( pos.x * m_boardAdapter.BiuTo3Dunits(),
-pos.y * m_boardAdapter.BiuTo3Dunits(), -pos.y * m_boardAdapter.BiuTo3Dunits(),
zpos ); zpos );
if( aFootprint->GetOrientation() ) if( aFootprint->GetOrientation() )
glRotated((double) aFootprint->GetOrientation() / 10.0, 0.0, 0.0, 1.0 ); glRotated((double) aFootprint->GetOrientation() / 10.0, 0.0, 0.0, 1.0 );
@ -1385,12 +1342,16 @@ void C3D_RENDER_OGL_LEGACY::render_3D_footprint( const FOOTPRINT* aFootprint,
glMultMatrixf( glm::value_ptr( mtx ) ); glMultMatrixf( glm::value_ptr( mtx ) );
if( aRenderTransparentOnly ) if( aRenderTransparentOnly )
{
modelPtr->Draw_transparent( sM.m_Opacity, modelPtr->Draw_transparent( sM.m_Opacity,
aFootprint->IsSelected() || aIsSelected, aFootprint->IsSelected() || aIsSelected,
m_boardAdapter.m_opengl_selectionColor ); m_boardAdapter.m_opengl_selectionColor );
}
else else
{
modelPtr->Draw_opaque( aFootprint->IsSelected() || aIsSelected, modelPtr->Draw_opaque( aFootprint->IsSelected() || aIsSelected,
m_boardAdapter.m_opengl_selectionColor ); m_boardAdapter.m_opengl_selectionColor );
}
if( m_boardAdapter.GetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX ) ) if( m_boardAdapter.GetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX ) )
{ {
@ -1423,20 +1384,20 @@ void C3D_RENDER_OGL_LEGACY::render_3D_footprint( const FOOTPRINT* aFootprint,
// and a vertical grid (XZ plane and Y = 0) // and a vertical grid (XZ plane and Y = 0)
void C3D_RENDER_OGL_LEGACY::generate_new_3DGrid( GRID3D_TYPE aGridType ) void C3D_RENDER_OGL_LEGACY::generate_new_3DGrid( GRID3D_TYPE aGridType )
{ {
if( glIsList( m_ogl_disp_list_grid ) ) if( glIsList( m_grid ) )
glDeleteLists( m_ogl_disp_list_grid, 1 ); glDeleteLists( m_grid, 1 );
m_ogl_disp_list_grid = 0; m_grid = 0;
if( aGridType == GRID3D_TYPE::NONE ) if( aGridType == GRID3D_TYPE::NONE )
return; return;
m_ogl_disp_list_grid = glGenLists( 1 ); m_grid = glGenLists( 1 );
if( !glIsList( m_ogl_disp_list_grid ) ) if( !glIsList( m_grid ) )
return; return;
glNewList( m_ogl_disp_list_grid, GL_COMPILE ); glNewList( m_grid, GL_COMPILE );
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

View File

@ -76,43 +76,34 @@ public:
private: private:
bool initializeOpenGL(); bool initializeOpenGL();
CLAYERS_OGL_DISP_LISTS* createBoard( const SHAPE_POLY_SET& aBoardPoly, const CBVHCONTAINER2D *aThroughHoles = nullptr ); CLAYERS_OGL_DISP_LISTS* createBoard( const SHAPE_POLY_SET& aBoardPoly,
const CBVHCONTAINER2D *aThroughHoles = nullptr );
void reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter ); void reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter );
void ogl_set_arrow_material(); void ogl_set_arrow_material();
void ogl_free_all_display_lists(); void ogl_free_all_display_lists();
MAP_OGL_DISP_LISTS m_ogl_disp_lists_layers; MAP_OGL_DISP_LISTS m_layers;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_lists_platedPads_F_Cu; CLAYERS_OGL_DISP_LISTS* m_platedPads_F_Cu;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_lists_platedPads_B_Cu; CLAYERS_OGL_DISP_LISTS* m_platedPads_B_Cu;
MAP_OGL_DISP_LISTS m_ogl_disp_lists_layers_holes_outer; MAP_OGL_DISP_LISTS m_layers_holes_outer;
MAP_OGL_DISP_LISTS m_ogl_disp_lists_layers_holes_inner; MAP_OGL_DISP_LISTS m_layers_holes_inner;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_board; CLAYERS_OGL_DISP_LISTS* m_board;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_board_with_holes; CLAYERS_OGL_DISP_LISTS* m_board_with_holes;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_anti_board; CLAYERS_OGL_DISP_LISTS* m_anti_board;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_through_holes_outer; CLAYERS_OGL_DISP_LISTS* m_through_holes_outer;
CLAYERS_OGL_DISP_LISTS* m_through_holes_vias_outer;
// User for body render CLAYERS_OGL_DISP_LISTS* m_through_holes_outer_ring;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_through_holes_outer_with_npth; CLAYERS_OGL_DISP_LISTS* m_vias_and_pad_holes_outer_contourn_and_caps;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_through_holes_vias_outer;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_through_holes_outer_ring;
//CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_through_holes_vias_inner; // Not in use
// This is for pads holes of the footprints
//CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_vias_and_pad_holes_inner_contourn_and_caps;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_vias_and_pad_holes_outer_contourn_and_caps;
LIST_TRIANGLES m_triangles; // store pointers so can be deleted latter
LIST_TRIANGLES m_triangles; ///< store pointers so can be deleted latter
GLuint m_ogl_circle_texture; GLuint m_ogl_circle_texture;
GLuint m_ogl_disp_list_grid; ///< oGL list that stores current grid GLuint m_grid; ///< oGL list that stores current grid
GRID3D_TYPE m_last_grid_type; ///< Stores the last grid computed GRID3D_TYPE m_last_grid_type; ///< Stores the last grid computed
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_via; CLAYERS_OGL_DISP_LISTS* m_vias;
CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_pads_holes; CLAYERS_OGL_DISP_LISTS* m_pad_holes;
MAP_3DMODEL m_3dmodel_map; MAP_3DMODEL m_3dmodel_map;