Simplify code.

DrawAllCameraCulled() can handle up to 4 knockout lists, and any
of them can be null, so don't dance around how we call it.
This commit is contained in:
Jeff Young 2023-09-21 13:07:10 +01:00
parent e152f97f35
commit 8d06a794f4
15 changed files with 294 additions and 494 deletions

View File

@ -726,8 +726,8 @@ void BOARD_ADAPTER::SetVisibleLayers( const std::bitset<LAYER_3D_END>& aLayers )
m_Cfg->m_Render.show_fp_values = aLayers.test( LAYER_FP_VALUES ); m_Cfg->m_Render.show_fp_values = aLayers.test( LAYER_FP_VALUES );
m_Cfg->m_Render.show_fp_text = aLayers.test( LAYER_FP_TEXT ); m_Cfg->m_Render.show_fp_text = aLayers.test( LAYER_FP_TEXT );
m_Cfg->m_Render.opengl_show_model_bbox = aLayers.test( LAYER_3D_BOUNDING_BOXES ); m_Cfg->m_Render.show_model_bbox = aLayers.test( LAYER_3D_BOUNDING_BOXES );
m_Cfg->m_Render.opengl_show_off_board_silk = aLayers.test( LAYER_3D_OFF_BOARD_SILK ); m_Cfg->m_Render.show_off_board_silk = aLayers.test( LAYER_3D_OFF_BOARD_SILK );
m_Cfg->m_Render.show_axis = aLayers.test( LAYER_3D_AXES ); m_Cfg->m_Render.show_axis = aLayers.test( LAYER_3D_AXES );
} }
@ -760,8 +760,8 @@ std::bitset<LAYER_3D_END> BOARD_ADAPTER::GetVisibleLayers() const
ret.set( LAYER_3D_MODELS_NOT_IN_POS, m_Cfg->m_Render.show_footprints_not_in_posfile ); ret.set( LAYER_3D_MODELS_NOT_IN_POS, m_Cfg->m_Render.show_footprints_not_in_posfile );
ret.set( LAYER_3D_MODELS_MARKED_DNP, m_Cfg->m_Render.show_footprints_dnp ); ret.set( LAYER_3D_MODELS_MARKED_DNP, m_Cfg->m_Render.show_footprints_dnp );
ret.set( LAYER_3D_BOUNDING_BOXES, m_Cfg->m_Render.opengl_show_model_bbox ); ret.set( LAYER_3D_BOUNDING_BOXES, m_Cfg->m_Render.show_model_bbox );
ret.set( LAYER_3D_OFF_BOARD_SILK, m_Cfg->m_Render.opengl_show_off_board_silk ); ret.set( LAYER_3D_OFF_BOARD_SILK, m_Cfg->m_Render.show_off_board_silk );
ret.set( LAYER_3D_AXES, m_Cfg->m_Render.show_axis ); ret.set( LAYER_3D_AXES, m_Cfg->m_Render.show_axis );
if( m_Cfg->m_CurrentPreset == FOLLOW_PCB ) if( m_Cfg->m_CurrentPreset == FOLLOW_PCB )

View File

@ -379,12 +379,6 @@ private:
void buildPadOutlineAsSegments( const PAD* aPad, CONTAINER_2D_BASE* aDstContainer, int aWidth ); void buildPadOutlineAsSegments( const PAD* aPad, CONTAINER_2D_BASE* aDstContainer, int aWidth );
// Helper functions to create poly contours
void buildPadOutlineAsPolygon( const PAD* aPad, SHAPE_POLY_SET& aBuffer, int aWidth) const;
void transformFPShapesToPolySet( const FOOTPRINT* aFootprint, PCB_LAYER_ID aLayer,
SHAPE_POLY_SET& aBuffer ) const;
public: public:
static CUSTOM_COLORS_LIST g_SilkColors; static CUSTOM_COLORS_LIST g_SilkColors;
static CUSTOM_COLORS_LIST g_MaskColors; static CUSTOM_COLORS_LIST g_MaskColors;
@ -407,8 +401,8 @@ public:
bool m_IsBoardView; bool m_IsBoardView;
bool m_MousewheelPanning; bool m_MousewheelPanning;
bool m_IsPreviewer; ///< true if the board adaptater is living in a 3D bool m_IsPreviewer; ///< true if we're in a 3D preview panel, false
///< preview panel, false for the standard 3D viewer ///< for the standard 3D viewer
SFVEC4F m_BgColorBot; ///< background bottom color SFVEC4F m_BgColorBot; ///< background bottom color
SFVEC4F m_BgColorTop; ///< background top color SFVEC4F m_BgColorTop; ///< background top color
@ -435,8 +429,8 @@ private:
SFVEC3F m_boardCenter; ///< 3D center position of the board in 3D units. SFVEC3F m_boardCenter; ///< 3D center position of the board in 3D units.
BBOX_3D m_boardBoundingBox; ///< 3D bounding box of the board in 3D units. BBOX_3D m_boardBoundingBox; ///< 3D bounding box of the board in 3D units.
MAP_POLY m_layers_poly; ///< Amalgamated polygon contours for various types of MAP_POLY m_layers_poly; ///< Amalgamated polygon contours for various types
///< items ///< of items
SHAPE_POLY_SET* m_frontPlatedPadPolys; SHAPE_POLY_SET* m_frontPlatedPadPolys;
SHAPE_POLY_SET* m_backPlatedPadPolys; SHAPE_POLY_SET* m_backPlatedPadPolys;
@ -461,12 +455,11 @@ private:
BVH_CONTAINER_2D m_TH_IDs; ///< List of PTH inner diameters BVH_CONTAINER_2D m_TH_IDs; ///< List of PTH inner diameters
BVH_CONTAINER_2D m_THAnnularRings; ///< List of via annular rings BVH_CONTAINER_2D m_THAnnularRings; ///< List of via annular rings
BVH_CONTAINER_2D m_viaTH_ODs; ///< List of via hole outer diameters BVH_CONTAINER_2D m_viaTH_ODs; ///< List of via hole outer diameters
BVH_CONTAINER_2D m_throughHoleViaIds; ///< List of via hole inner diameters
unsigned int m_copperLayersCount; unsigned int m_copperLayersCount;
double m_biuTo3Dunits; ///< Scale factor to convert board internal units to double m_biuTo3Dunits; ///< Scale factor to convert board internal units
///< 3D units normalized between -1.0 and 1.0. ///< to 3D units normalized between -1.0 and 1.0.
std::array<float, PCB_LAYER_ID_COUNT> m_layerZcoordTop; ///< Top (End) Z position of each std::array<float, PCB_LAYER_ID_COUNT> m_layerZcoordTop; ///< Top (End) Z position of each
///< layer in 3D units. ///< layer in 3D units.

View File

@ -27,8 +27,6 @@
* @file create_3Dgraphic_brd_items.cpp * @file create_3Dgraphic_brd_items.cpp
* @brief This file implements the creation of 2D graphic primitives of pcb items: * @brief This file implements the creation of 2D graphic primitives of pcb items:
* pads, tracks, drawsegments, texts.... * pads, tracks, drawsegments, texts....
* It is based on the function found in the files:
* board_items_to_polygon_shape_transform.cpp
*/ */
#include "../3d_rendering/raytracing/shapes2D/ring_2d.h" #include "../3d_rendering/raytracing/shapes2D/ring_2d.h"
@ -62,8 +60,6 @@
#define TO_SFVEC2F( vec ) SFVEC2F( TO_3DU( vec.x ), TO_3DU( -vec.y ) ) #define TO_SFVEC2F( vec ) SFVEC2F( TO_3DU( vec.x ), TO_3DU( -vec.y ) )
void addFILLED_CIRCLE_2D( CONTAINER_2D_BASE* aContainer, const SFVEC2F& aCenter, float aRadius, void addFILLED_CIRCLE_2D( CONTAINER_2D_BASE* aContainer, const SFVEC2F& aCenter, float aRadius,
const BOARD_ITEM& aBoardItem ) const BOARD_ITEM& aBoardItem )
{ {
@ -275,8 +271,7 @@ void BOARD_ADAPTER::createViaWithMargin( const PCB_TRACK* aTrack, CONTAINER_2D_B
{ {
SFVEC2F start3DU = TO_SFVEC2F( aTrack->GetStart() ); SFVEC2F start3DU = TO_SFVEC2F( aTrack->GetStart() );
SFVEC2F end3DU = TO_SFVEC2F( aTrack->GetEnd() ); SFVEC2F end3DU = TO_SFVEC2F( aTrack->GetEnd() );
const float radius3DU = TO_3DU( ( aTrack->GetWidth() / 2.0 ) + aMargin );
const float radius3DU = TO_3DU( ( aTrack->GetWidth() / 2 ) + aMargin );
addFILLED_CIRCLE_2D( aDstContainer, start3DU, radius3DU, *aTrack ); addFILLED_CIRCLE_2D( aDstContainer, start3DU, radius3DU, *aTrack );
} }
@ -290,7 +285,7 @@ void BOARD_ADAPTER::createTrack( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDs
switch( aTrack->Type() ) switch( aTrack->Type() )
{ {
case PCB_VIA_T: case PCB_VIA_T:
addFILLED_CIRCLE_2D( aDstContainer, start3DU, TO_3DU( aTrack->GetWidth() / 2 ), *aTrack ); addFILLED_CIRCLE_2D( aDstContainer, start3DU, TO_3DU( aTrack->GetWidth() / 2.0 ), *aTrack );
break; break;
case PCB_ARC_T: case PCB_ARC_T:
@ -310,10 +305,10 @@ void BOARD_ADAPTER::createTrack( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDs
return; return;
} }
VECTOR2D center( arc->GetCenter() ); VECTOR2I center( arc->GetCenter() );
EDA_ANGLE arc_angle = arc->GetAngle(); EDA_ANGLE arc_angle = arc->GetAngle();
double radius = arc->GetRadius(); double radius = arc->GetRadius();
int arcsegcount = GetArcToSegmentCount( radius, ARC_HIGH_DEF, arc_angle ); int arcsegcount = GetArcToSegmentCount( KiROUND( radius ), ARC_HIGH_DEF, arc_angle );
int circlesegcount; int circlesegcount;
// Avoid arcs that cannot be drawn // Avoid arcs that cannot be drawn
@ -332,8 +327,8 @@ void BOARD_ADAPTER::createTrack( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDs
circlesegcount = alg::clamp( 1, circlesegcount, 128 ); circlesegcount = alg::clamp( 1, circlesegcount, 128 );
} }
createArcSegments( VECTOR2I( center.x, center.y ), arc->GetStart(), arc_angle, createArcSegments( center, arc->GetStart(), arc_angle, circlesegcount, arc->GetWidth(),
circlesegcount, arc->GetWidth(), aDstContainer, *arc ); aDstContainer, *arc );
break; break;
} }
@ -734,14 +729,13 @@ void BOARD_ADAPTER::buildPadOutlineAsSegments( const PAD* aPad, CONTAINER_2D_BAS
{ {
const SFVEC2F center3DU = TO_SFVEC2F( aPad->ShapePos() ); const SFVEC2F center3DU = TO_SFVEC2F( aPad->ShapePos() );
const int radius = aPad->GetSize().x / 2; const int radius = aPad->GetSize().x / 2;
const float inner_radius3DU = TO_3DU( radius - aWidth / 2 ); const float inner_radius3DU = TO_3DU( radius - aWidth / 2.0 );
const float outer_radius3DU = TO_3DU( radius + aWidth / 2 ); const float outer_radius3DU = TO_3DU( radius + aWidth / 2.0 );
addRING_2D( aContainer, center3DU, inner_radius3DU, outer_radius3DU, *aPad ); addRING_2D( aContainer, center3DU, inner_radius3DU, outer_radius3DU, *aPad );
return;
} }
else
{
// For other shapes, add outlines as thick segments in polygon buffer // For other shapes, add outlines as thick segments in polygon buffer
const std::shared_ptr<SHAPE_POLY_SET>& corners = aPad->GetEffectivePolygon(); const std::shared_ptr<SHAPE_POLY_SET>& corners = aPad->GetEffectivePolygon();
const SHAPE_LINE_CHAIN& path = corners->COutline( 0 ); const SHAPE_LINE_CHAIN& path = corners->COutline( 0 );
@ -754,3 +748,4 @@ void BOARD_ADAPTER::buildPadOutlineAsSegments( const PAD* aPad, CONTAINER_2D_BAS
addROUND_SEGMENT_2D( aContainer, start3DU, end3DU, TO_3DU( aWidth ), *aPad ); addROUND_SEGMENT_2D( aContainer, start3DU, end3DU, TO_3DU( aWidth ), *aPad );
} }
} }
}

View File

@ -55,70 +55,88 @@
#endif #endif
/*
* This is used to draw pad outlines on silk layers.
*/
void buildPadOutlineAsPolygon( const PAD* aPad, SHAPE_POLY_SET& aBuffer, int aWidth, int aMaxError,
ERROR_LOC aErrorLoc )
{
if( aPad->GetShape() == PAD_SHAPE::CIRCLE ) // Draw a ring
{
TransformRingToPolygon( aBuffer, aPad->ShapePos(), aPad->GetSize().x / 2, aWidth,
aMaxError, aErrorLoc );
}
else
{
// For other shapes, add outlines as thick segments in polygon buffer
const SHAPE_LINE_CHAIN& path = aPad->GetEffectivePolygon()->COutline( 0 );
for( int ii = 0; ii < path.PointCount(); ++ii )
{
const VECTOR2I& a = path.CPoint( ii );
const VECTOR2I& b = path.CPoint( ii + 1 );
TransformOvalToPolygon( aBuffer, a, b, aWidth, aMaxError, aErrorLoc );
}
}
}
void transformFPShapesToPolySet( const FOOTPRINT* aFootprint, PCB_LAYER_ID aLayer,
SHAPE_POLY_SET& aBuffer, int aMaxError, ERROR_LOC aErrorLoc )
{
for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
{
if( item->Type() == PCB_SHAPE_T || BaseType( item->Type() ) == PCB_DIMENSION_T )
{
if( item->GetLayer() == aLayer )
item->TransformShapeToPolygon( aBuffer, aLayer, 0, aMaxError, aErrorLoc );
}
}
}
void BOARD_ADAPTER::destroyLayers() void BOARD_ADAPTER::destroyLayers()
{ {
if( !m_layers_poly.empty() ) #define DELETE_AND_FREE( ptr ) \
{ { \
for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET*>& poly : m_layers_poly ) delete ptr; \
delete poly.second; ptr = nullptr; \
} \
m_layers_poly.clear(); #define DELETE_AND_FREE_MAP( map ) \
{ \
for( auto& [ layer, poly ] : map ) \
delete poly; \
\
map.clear(); \
} }
delete m_frontPlatedPadPolys; DELETE_AND_FREE_MAP( m_layers_poly );
m_frontPlatedPadPolys = nullptr;
delete m_backPlatedPadPolys; DELETE_AND_FREE( m_frontPlatedPadPolys )
m_backPlatedPadPolys = nullptr; DELETE_AND_FREE( m_backPlatedPadPolys )
if( !m_layerHoleIdPolys.empty() ) DELETE_AND_FREE_MAP( m_layerHoleOdPolys )
{ DELETE_AND_FREE_MAP( m_layerHoleIdPolys )
for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET*>& poly : m_layerHoleIdPolys )
delete poly.second;
m_layerHoleIdPolys.clear();
}
if( !m_layerHoleOdPolys.empty() )
{
for( std::pair<const PCB_LAYER_ID, SHAPE_POLY_SET*>& poly : m_layerHoleOdPolys )
delete poly.second;
m_layerHoleOdPolys.clear();
}
if( !m_layerMap.empty() )
{
for( std::pair<const PCB_LAYER_ID, BVH_CONTAINER_2D*>& poly : m_layerMap )
delete poly.second;
m_layerMap.clear();
}
delete m_platedPadsFront;
m_platedPadsFront = nullptr;
delete m_platedPadsBack;
m_platedPadsBack = nullptr;
if( !m_layerHoleMap.empty() )
{
for( std::pair<const PCB_LAYER_ID, BVH_CONTAINER_2D*>& poly : m_layerHoleMap )
delete poly.second;
m_layerHoleMap.clear();
}
m_TH_IDs.Clear();
m_TH_ODs.Clear();
m_THAnnularRings.Clear();
m_viaTH_ODs.Clear();
m_throughHoleViaIds.Clear();
m_NPTH_ODPolys.RemoveAllContours(); m_NPTH_ODPolys.RemoveAllContours();
m_TH_ODPolys.RemoveAllContours(); m_TH_ODPolys.RemoveAllContours();
m_viaTH_ODPolys.RemoveAllContours(); m_viaTH_ODPolys.RemoveAllContours();
m_THAnnularRingPolys.RemoveAllContours(); m_THAnnularRingPolys.RemoveAllContours();
DELETE_AND_FREE_MAP( m_layerMap )
DELETE_AND_FREE_MAP( m_layerHoleMap )
DELETE_AND_FREE( m_platedPadsFront )
DELETE_AND_FREE( m_platedPadsBack )
m_TH_ODs.Clear();
m_TH_IDs.Clear();
m_THAnnularRings.Clear();
m_viaTH_ODs.Clear();
} }
@ -551,7 +569,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
true, m_Cfg->m_Render.renderPlatedPadsAsPlated, true, m_Cfg->m_Render.renderPlatedPadsAsPlated,
false ); false );
transformFPShapesToPolySet( footprint, layer, *layerPoly ); transformFPShapesToPolySet( footprint, layer, *layerPoly, maxError, ERROR_INSIDE );
} }
} }
@ -1027,10 +1045,11 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
for( PAD* pad : footprint->Pads() ) for( PAD* pad : footprint->Pads() )
{ {
if( !pad->IsOnLayer( layer ) ) if( pad->IsOnLayer( layer ) )
continue; {
buildPadOutlineAsPolygon( pad, *layerPoly, linewidth, maxError,
buildPadOutlineAsPolygon( pad, *layerPoly, linewidth ); ERROR_INSIDE );
}
} }
} }
else else
@ -1042,7 +1061,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
footprint->TransformFPTextToPolySet( *layerPoly, layer, 0, maxError, ERROR_INSIDE ); footprint->TransformFPTextToPolySet( *layerPoly, layer, 0, maxError, ERROR_INSIDE );
// Add the remaining things with dynamic seg count for circles // Add the remaining things with dynamic seg count for circles
transformFPShapesToPolySet( footprint, layer, *layerPoly ); transformFPShapesToPolySet( footprint, layer, *layerPoly, maxError, ERROR_INSIDE );
} }
} }
@ -1059,7 +1078,6 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
{ {
for( ZONE* zone : m_board->Zones() ) for( ZONE* zone : m_board->Zones() )
{ {
if( zone->IsOnLayer( layer ) ) if( zone->IsOnLayer( layer ) )
zone->TransformSolidAreasShapesToPolygon( layer, *layerPoly ); zone->TransformSolidAreasShapesToPolygon( layer, *layerPoly );
} }
@ -1075,7 +1093,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
// A somewhat experimental feature: if we're rendering off-board silk, turn any pads of // A somewhat experimental feature: if we're rendering off-board silk, turn any pads of
// footprints which are entirely outside the board outline into silk. This makes off-board // footprints which are entirely outside the board outline into silk. This makes off-board
// footprints more visually recognizable. // footprints more visually recognizable.
if( m_Cfg->m_Render.opengl_show_off_board_silk ) if( m_Cfg->m_Render.show_off_board_silk )
{ {
BOX2I boardBBox = m_board_poly.BBox(); BOX2I boardBBox = m_board_poly.BBox();

View File

@ -1,80 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file create_layer_poly.cpp
* @brief This file implements the creation of the pcb board items in the poly
* contours format.
*/
#include "board_adapter.h"
#include <board_design_settings.h>
#include <convert_basic_shapes_to_polygon.h>
#include <pcb_shape.h>
#include <footprint.h>
/*
* This is used to draw pad outlines on silk layers.
*/
void BOARD_ADAPTER::buildPadOutlineAsPolygon( const PAD* aPad, SHAPE_POLY_SET& aBuffer,
int aWidth ) const
{
int maxError = m_board->GetDesignSettings().m_MaxError;
if( aPad->GetShape() == PAD_SHAPE::CIRCLE ) // Draw a ring
{
TransformRingToPolygon( aBuffer, aPad->ShapePos(), aPad->GetSize().x / 2, aWidth, maxError,
ERROR_INSIDE );
return;
}
// For other shapes, add outlines as thick segments in polygon buffer
const std::shared_ptr<SHAPE_POLY_SET>& corners = aPad->GetEffectivePolygon();
const SHAPE_LINE_CHAIN& path = corners->COutline( 0 );
for( int ii = 0; ii < path.PointCount(); ++ii )
{
const VECTOR2I& a = path.CPoint( ii );
const VECTOR2I& b = path.CPoint( ii + 1 );
TransformOvalToPolygon( aBuffer, a, b, aWidth, maxError, ERROR_INSIDE );
}
}
void BOARD_ADAPTER::transformFPShapesToPolySet( const FOOTPRINT* aFootprint, PCB_LAYER_ID aLayer,
SHAPE_POLY_SET& aBuffer ) const
{
int maxError = m_board->GetDesignSettings().m_MaxError;
for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
{
if( item->Type() == PCB_SHAPE_T || BaseType( item->Type() ) == PCB_DIMENSION_T )
{
if( item->GetLayer() == aLayer )
item->TransformShapeToPolygon( aBuffer, aLayer, 0, maxError, ERROR_INSIDE );
}
}
}

View File

@ -35,12 +35,12 @@
#include <eda_3d_viewer_frame.h> #include <eda_3d_viewer_frame.h>
void RENDER_3D_OPENGL::addObjectTriangles( const FILLED_CIRCLE_2D* aFilledCircle, void RENDER_3D_OPENGL::addObjectTriangles( const FILLED_CIRCLE_2D* aCircle,
TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop, TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop,
float aZbot ) float aZbot )
{ {
const SFVEC2F& center = aFilledCircle->GetCenter(); const SFVEC2F& center = aCircle->GetCenter();
const float radius = aFilledCircle->GetRadius() * 2.0f; // Double because the render triangle const float radius = aCircle->GetRadius() * 2.0f; // Double because the render triangle
// This is a small adjustment to the circle texture // This is a small adjustment to the circle texture
const float texture_factor = ( 8.0f / (float) SIZE_OF_CIRCLE_TEXTURE ) + 1.0f; const float texture_factor = ( 8.0f / (float) SIZE_OF_CIRCLE_TEXTURE ) + 1.0f;

View File

@ -499,10 +499,10 @@ void OPENGL_RENDER_LIST::DrawAllCameraCulled( float zCameraPos, bool aDrawMiddle
void OPENGL_RENDER_LIST::DrawAllCameraCulled( bool aDrawMiddle, void OPENGL_RENDER_LIST::DrawAllCameraCulled( bool aDrawMiddle,
const OPENGL_RENDER_LIST* aLayerToSubtractA, const OPENGL_RENDER_LIST* aSubtractList,
const OPENGL_RENDER_LIST* aLayerToSubtractB, const OPENGL_RENDER_LIST* bSubtractList,
const OPENGL_RENDER_LIST* aLayerToSubtractC, const OPENGL_RENDER_LIST* cSubtractList,
const OPENGL_RENDER_LIST* aLayerToSubtractD ) const const OPENGL_RENDER_LIST* dSubtractList ) const
{ {
glClearStencil( 0x00 ); glClearStencil( 0x00 );
glClear( GL_STENCIL_BUFFER_BIT ); glClear( GL_STENCIL_BUFFER_BIT );
@ -517,17 +517,17 @@ void OPENGL_RENDER_LIST::DrawAllCameraCulled( bool aDrawMiddle,
glStencilFunc( GL_ALWAYS, 1, 0 ); glStencilFunc( GL_ALWAYS, 1, 0 );
glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE ); glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
if( aLayerToSubtractA ) if( aSubtractList )
aLayerToSubtractA->DrawBot(); aSubtractList->DrawBot();
if( aLayerToSubtractB ) if( bSubtractList )
aLayerToSubtractB->DrawBot(); bSubtractList->DrawBot();
if( aLayerToSubtractC ) if( cSubtractList )
aLayerToSubtractC->DrawBot(); cSubtractList->DrawBot();
if( aLayerToSubtractD ) if( dSubtractList )
aLayerToSubtractD->DrawBot(); dSubtractList->DrawBot();
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
@ -544,17 +544,17 @@ void OPENGL_RENDER_LIST::DrawAllCameraCulled( bool aDrawMiddle,
glStencilFunc( GL_ALWAYS, 2, 0 ); glStencilFunc( GL_ALWAYS, 2, 0 );
glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE ); glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
if( aLayerToSubtractA ) if( aSubtractList )
aLayerToSubtractA->DrawTop(); aSubtractList->DrawTop();
if( aLayerToSubtractB ) if( bSubtractList )
aLayerToSubtractB->DrawTop(); bSubtractList->DrawTop();
if( aLayerToSubtractC ) if( cSubtractList )
aLayerToSubtractC->DrawTop(); cSubtractList->DrawTop();
if( aLayerToSubtractD ) if( dSubtractList )
aLayerToSubtractD->DrawTop(); dSubtractList->DrawTop();
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
@ -575,8 +575,8 @@ void OPENGL_RENDER_LIST::DrawAllCameraCulled( bool aDrawMiddle,
if( aDrawMiddle ) if( aDrawMiddle )
{ {
if( aLayerToSubtractA ) if( aSubtractList )
aLayerToSubtractA->DrawMiddle(); aSubtractList->DrawMiddle();
} }
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE ); glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
@ -596,6 +596,12 @@ void OPENGL_RENDER_LIST::ApplyScalePosition( float aZposition, float aZscale )
} }
void OPENGL_RENDER_LIST::ApplyScalePosition( OPENGL_RENDER_LIST* aOtherList )
{
ApplyScalePosition( aOtherList->GetZBot(), aOtherList->GetZTop() - aOtherList->GetZBot() );
}
void OPENGL_RENDER_LIST::SetItIsTransparent( bool aSetTransparent ) void OPENGL_RENDER_LIST::SetItIsTransparent( bool aSetTransparent )
{ {
m_draw_it_transparent = aSetTransparent; m_draw_it_transparent = aSetTransparent;

View File

@ -197,12 +197,13 @@ public:
void DrawAllCameraCulled( float zCameraPos, bool aDrawMiddle = true ) const; void DrawAllCameraCulled( float zCameraPos, bool aDrawMiddle = true ) const;
void DrawAllCameraCulled( bool aDrawMiddle, void DrawAllCameraCulled( bool aDrawMiddle,
const OPENGL_RENDER_LIST* aLayerToSubtractA = nullptr, const OPENGL_RENDER_LIST* aSubtractList = nullptr,
const OPENGL_RENDER_LIST* aLayerToSubtractB = nullptr, const OPENGL_RENDER_LIST* bSubtractList = nullptr,
const OPENGL_RENDER_LIST* aLayerToSubtractC = nullptr, const OPENGL_RENDER_LIST* cSubtractList = nullptr,
const OPENGL_RENDER_LIST* aLayerToSubtractD = nullptr ) const; const OPENGL_RENDER_LIST* dSubtractList = nullptr ) const;
void ApplyScalePosition( float aZposition, float aZscale ); void ApplyScalePosition( float aZposition, float aZscale );
void ApplyScalePosition( OPENGL_RENDER_LIST* aOtherList );
void ClearScalePosition() { m_haveTransformation = false; } void ClearScalePosition() { m_haveTransformation = false; }

View File

@ -437,7 +437,6 @@ void RENDER_3D_OPENGL::renderBoardBody( bool aSkipRenderHoles )
m_boardAdapter.GetBoardBodyThickness() ); m_boardAdapter.GetBoardBodyThickness() );
ogl_disp_list->SetItIsTransparent( true ); ogl_disp_list->SetItIsTransparent( true );
ogl_disp_list->DrawAll(); ogl_disp_list->DrawAll();
} }
} }
@ -557,9 +556,13 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
for( MAP_OGL_DISP_LISTS::const_iterator ii = m_layers.begin(); ii != m_layers.end(); ++ii ) for( MAP_OGL_DISP_LISTS::const_iterator ii = m_layers.begin(); ii != m_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 );
bool isSilkLayer = layer_id == F_SilkS || layer_id == B_SilkS;
bool isMaskLayer = layer_id == F_Mask || layer_id == B_Mask;
bool isPasteLayer = layer_id == F_Paste || layer_id == B_Paste;
bool isCopperLayer = layer_id >= F_Cu && layer_id <= B_Cu;
// Mask layers are not processed here because they are a special case // Mask layers are not processed here because they are a special case
if( ( layer_id == B_Mask ) || ( layer_id == F_Mask ) ) if( isMaskLayer )
continue; continue;
// Do not show inner layers when it is displaying the board and board body is opaque // Do not show inner layers when it is displaying the board and board body is opaque
@ -577,7 +580,7 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
OPENGL_RENDER_LIST* pLayerDispList = static_cast<OPENGL_RENDER_LIST*>( ii->second ); OPENGL_RENDER_LIST* pLayerDispList = static_cast<OPENGL_RENDER_LIST*>( ii->second );
if( ( layer_id >= F_Cu ) && ( layer_id <= B_Cu ) ) if( isCopperLayer )
{ {
if( m_boardAdapter.m_Cfg->m_Render.renderPlatedPadsAsPlated ) if( m_boardAdapter.m_Cfg->m_Render.renderPlatedPadsAsPlated )
setCopperMaterial(); setCopperMaterial();
@ -592,14 +595,12 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
if( layer_id == F_Cu && m_platedPadsFront ) if( layer_id == F_Cu && m_platedPadsFront )
{ {
setPlatedCopperAndDepthOffset( layer_id ); setPlatedCopperAndDepthOffset( layer_id );
m_platedPadsFront->DrawAllCameraCulled( m_camera.GetPos().z, m_platedPadsFront->DrawAllCameraCulled( m_camera.GetPos().z, drawMiddleSegments );
drawMiddleSegments );
} }
else if( layer_id == B_Cu && m_platedPadsBack ) else if( layer_id == B_Cu && m_platedPadsBack )
{ {
setPlatedCopperAndDepthOffset( layer_id ); setPlatedCopperAndDepthOffset( layer_id );
m_platedPadsBack->DrawAllCameraCulled( m_camera.GetPos().z, m_platedPadsBack->DrawAllCameraCulled( m_camera.GetPos().z, drawMiddleSegments );
drawMiddleSegments );
} }
unsetDepthOffset(); unsetDepthOffset();
@ -607,139 +608,73 @@ bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
else else
{ {
if( m_outerThroughHoles ) if( m_outerThroughHoles )
{ m_outerThroughHoles->ApplyScalePosition( pLayerDispList );
m_outerThroughHoles->ApplyScalePosition( pLayerDispList->GetZBot(),
pLayerDispList->GetZTop()
- pLayerDispList->GetZBot() );
}
if( m_antiBoard ) if( m_antiBoard )
{ m_antiBoard->ApplyScalePosition( pLayerDispList );
m_antiBoard->ApplyScalePosition( pLayerDispList->GetZBot(),
pLayerDispList->GetZTop()
- pLayerDispList->GetZBot() );
}
if( m_outerLayerHoles.find( layer_id ) != m_outerLayerHoles.end() ) const OPENGL_RENDER_LIST* viasHolesLayer = m_outerLayerHoles[ layer_id ];
{
const OPENGL_RENDER_LIST* viasHolesLayer = m_outerLayerHoles.at( layer_id );
wxASSERT( viasHolesLayer != nullptr ); pLayerDispList->DrawAllCameraCulled( drawMiddleSegments, m_outerThroughHoles,
viasHolesLayer, m_antiBoard );
if( viasHolesLayer != nullptr )
{
pLayerDispList->DrawAllCameraCulled( drawMiddleSegments,
m_outerThroughHoles, viasHolesLayer,
m_antiBoard );
// Draw plated pads // Draw plated pads
if( layer_id == F_Cu && m_platedPadsFront ) if( layer_id == F_Cu && m_platedPadsFront )
{ {
setPlatedCopperAndDepthOffset( layer_id ); setPlatedCopperAndDepthOffset( layer_id );
m_platedPadsFront->DrawAllCameraCulled( drawMiddleSegments, m_platedPadsFront->DrawAllCameraCulled( drawMiddleSegments, m_outerThroughHoles,
m_outerThroughHoles,
viasHolesLayer, m_antiBoard ); viasHolesLayer, m_antiBoard );
} }
else if( layer_id == B_Cu && m_platedPadsBack ) else if( layer_id == B_Cu && m_platedPadsBack )
{ {
setPlatedCopperAndDepthOffset( layer_id ); setPlatedCopperAndDepthOffset( layer_id );
m_platedPadsBack->DrawAllCameraCulled( drawMiddleSegments, m_platedPadsBack->DrawAllCameraCulled( drawMiddleSegments, m_outerThroughHoles,
m_outerThroughHoles,
viasHolesLayer, m_antiBoard ); viasHolesLayer, m_antiBoard );
} }
unsetDepthOffset(); unsetDepthOffset();
} }
} }
else else if( isPasteLayer && skipRenderHoles )
{ {
pLayerDispList->DrawAllCameraCulled( drawMiddleSegments, m_outerThroughHoles, // Do not render paste layers when skipRenderHoles is enabled or we get z-fight issues
m_antiBoard );
if( layer_id == F_Cu && m_platedPadsFront )
{
setPlatedCopperAndDepthOffset( layer_id );
m_platedPadsFront->DrawAllCameraCulled( drawMiddleSegments,
m_outerThroughHoles, m_antiBoard );
}
else if( layer_id == B_Cu && m_platedPadsBack )
{
setPlatedCopperAndDepthOffset( layer_id );
m_platedPadsBack->DrawAllCameraCulled( drawMiddleSegments,
m_outerThroughHoles, m_antiBoard );
}
unsetDepthOffset();
}
}
} }
else else
{ {
setLayerMaterial( layer_id ); setLayerMaterial( layer_id );
OPENGL_RENDER_LIST* throughHolesOuter = m_outerThroughHoles; OPENGL_RENDER_LIST* throughHolesOuter = nullptr;
OPENGL_RENDER_LIST* anti_board = nullptr;
OPENGL_RENDER_LIST* solder_mask = nullptr;
if( m_boardAdapter.m_Cfg->m_Render.clip_silk_on_via_annulus if( isSilkLayer && m_boardAdapter.m_Cfg->m_Render.clip_silk_on_via_annulus )
&& ( layer_id == B_SilkS || layer_id == F_SilkS ) )
{
throughHolesOuter = m_outerThroughHoleRings; throughHolesOuter = m_outerThroughHoleRings;
else
throughHolesOuter = m_outerThroughHoles;
if( isSilkLayer && m_boardAdapter.m_Cfg->m_Render.show_off_board_silk )
anti_board = nullptr;
else if( LSET::PhysicalLayersMask().test( layer_id ) )
anti_board = m_antiBoard;
if( isSilkLayer && m_boardAdapter.m_Cfg->m_Render.subtract_mask_from_silk
&& !m_boardAdapter.m_Cfg->m_Render.show_off_board_silk )
{
solder_mask = m_layers[ (layer_id == B_SilkS) ? B_Mask : F_Mask ];
} }
if( throughHolesOuter ) if( throughHolesOuter )
{ throughHolesOuter->ApplyScalePosition( pLayerDispList );
throughHolesOuter->ApplyScalePosition( pLayerDispList->GetZBot(),
pLayerDispList->GetZTop()
- pLayerDispList->GetZBot() );
}
OPENGL_RENDER_LIST* anti_board = nullptr;
if( ( layer_id == F_SilkS || layer_id == B_SilkS )
&& m_boardAdapter.m_Cfg->m_Render.opengl_show_off_board_silk )
{
anti_board = nullptr;
}
else if( LSET::PhysicalLayersMask().test( layer_id ) )
{
anti_board = m_antiBoard;
}
if( anti_board ) if( anti_board )
{ anti_board->ApplyScalePosition( pLayerDispList );
anti_board->ApplyScalePosition( pLayerDispList->GetZBot(),
pLayerDispList->GetZTop()
- pLayerDispList->GetZBot() );
}
if( skipRenderHoles ) if( solder_mask )
{ solder_mask->ApplyScalePosition( pLayerDispList );
// Do not render Paste layers when skipRenderHoles is enabled
// otherwise it will cause z-fight issues
if( layer_id != B_Paste && layer_id != F_Paste )
pLayerDispList->DrawAllCameraCulled( drawMiddleSegments, anti_board );
}
else if( m_boardAdapter.m_Cfg->m_Render.subtract_mask_from_silk
&& !m_boardAdapter.m_Cfg->m_Render.opengl_show_off_board_silk
&& ( ( layer_id == B_SilkS && m_layers.find( B_Mask ) != m_layers.end() )
|| ( layer_id == F_SilkS && m_layers.find( F_Mask ) != m_layers.end() ) ) )
{
const PCB_LAYER_ID layerMask_id = (layer_id == B_SilkS) ? B_Mask : F_Mask;
const OPENGL_RENDER_LIST* pLayerDispListMask = m_layers.at( layerMask_id ); pLayerDispList->DrawAllCameraCulled( drawMiddleSegments, solder_mask, throughHolesOuter,
pLayerDispList->DrawAllCameraCulled( drawMiddleSegments, pLayerDispListMask,
throughHolesOuter, anti_board );
}
else if( throughHolesOuter )
{
pLayerDispList->DrawAllCameraCulled( drawMiddleSegments, throughHolesOuter,
anti_board ); anti_board );
} }
else
{
pLayerDispList->DrawAllCameraCulled( drawMiddleSegments, anti_board );
}
}
glPopMatrix(); glPopMatrix();
} }
@ -922,11 +857,8 @@ void RENDER_3D_OPENGL::freeAllLists()
m_grid = 0; m_grid = 0;
for( MAP_OGL_DISP_LISTS::const_iterator ii = m_layers.begin(); ii != m_layers.end(); ++ii ) for( const auto& [ layerId, renderList ] : m_layers )
{ delete renderList;
OPENGL_RENDER_LIST* pLayerDispList = static_cast<OPENGL_RENDER_LIST*>( ii->second );
delete pLayerDispList;
}
m_layers.clear(); m_layers.clear();
@ -936,24 +868,23 @@ void RENDER_3D_OPENGL::freeAllLists()
delete m_platedPadsBack; delete m_platedPadsBack;
m_platedPadsBack = nullptr; m_platedPadsBack = nullptr;
for( const auto& [ layerId, renderList ] : m_outerLayerHoles )
for( const std::pair<const PCB_LAYER_ID, OPENGL_RENDER_LIST*> entry : m_outerLayerHoles ) delete renderList;
delete entry.second;
m_outerLayerHoles.clear(); m_outerLayerHoles.clear();
for( const std::pair<const PCB_LAYER_ID, OPENGL_RENDER_LIST*> entry : m_innerLayerHoles ) for( const auto& [ layerId, renderList ] : m_innerLayerHoles )
delete entry.second; delete renderList;
m_innerLayerHoles.clear(); m_innerLayerHoles.clear();
for( LIST_TRIANGLES::const_iterator ii = m_triangles.begin(); ii != m_triangles.end(); ++ii ) for( TRIANGLE_DISPLAY_LIST* list : m_triangles )
delete *ii; delete list;
m_triangles.clear(); m_triangles.clear();
for( const std::pair<const wxString, MODEL_3D*>& entry : m_3dModelMap ) for( const auto& [ name, model ] : m_3dModelMap )
delete entry.second; delete model;
m_3dModelMap.clear(); m_3dModelMap.clear();
@ -985,65 +916,30 @@ void RENDER_3D_OPENGL::freeAllLists()
} }
void RENDER_3D_OPENGL::renderSolderMaskLayer( PCB_LAYER_ID aLayerID, float aZPosition, void RENDER_3D_OPENGL::renderSolderMaskLayer( PCB_LAYER_ID aLayerID, float aZPos,
bool aDrawMiddleSegments, bool aSkipRenderHoles ) bool aDrawMiddleSegments, bool aSkipRenderHoles )
{ {
wxASSERT( (aLayerID == B_Mask) || (aLayerID == F_Mask) ); wxASSERT( (aLayerID == B_Mask) || (aLayerID == F_Mask) );
float nonCopperThickness = m_boardAdapter.GetNonCopperLayerThickness();
if( m_board ) if( m_board )
{ {
if( m_layers.find( aLayerID ) != m_layers.end() ) OPENGL_RENDER_LIST* solder_mask = m_layers[ aLayerID ];
{ OPENGL_RENDER_LIST* via_holes = aSkipRenderHoles ? nullptr : m_outerThroughHoles;
OPENGL_RENDER_LIST* pLayerDispListMask = m_layers.at( aLayerID );
if( m_outerViaThroughHoles ) if( via_holes )
m_outerViaThroughHoles->ApplyScalePosition( aZPosition, nonCopperThickness ); via_holes->ApplyScalePosition( aZPos, m_boardAdapter.GetNonCopperLayerThickness() );
m_board->ApplyScalePosition( aZPosition, nonCopperThickness ); m_board->ApplyScalePosition( aZPos, m_boardAdapter.GetNonCopperLayerThickness() );
setLayerMaterial( aLayerID ); setLayerMaterial( aLayerID );
m_board->SetItIsTransparent( true ); m_board->SetItIsTransparent( true );
m_board->DrawAllCameraCulled( aDrawMiddleSegments, solder_mask, via_holes );
if( aSkipRenderHoles )
{
m_board->DrawAllCameraCulled( m_camera.GetPos().z, aDrawMiddleSegments );
}
else
{
m_board->DrawAllCameraCulled( aDrawMiddleSegments, pLayerDispListMask,
m_outerViaThroughHoles );
}
}
else
{
// This case there is no layer with mask, so we will render the full board as mask
if( m_outerViaThroughHoles )
m_outerViaThroughHoles->ApplyScalePosition( aZPosition, nonCopperThickness );
m_board->ApplyScalePosition( aZPosition, nonCopperThickness );
setLayerMaterial( aLayerID );
m_board->SetItIsTransparent( true );
if( aSkipRenderHoles )
{
m_board->DrawAllCameraCulled( m_camera.GetPos().z, aDrawMiddleSegments );
}
else
{
m_board->DrawAllCameraCulled( aDrawMiddleSegments, m_outerViaThroughHoles );
}
}
} }
} }
void RENDER_3D_OPENGL::get3dModelsSelected( std::list<MODELTORENDER> &aDstRenderList, void RENDER_3D_OPENGL::get3dModelsSelected( std::list<MODELTORENDER> &aDstRenderList, bool aGetTop,
bool aGetTop, bool aGetBot, bool aRenderTransparentOnly, bool aGetBot, bool aRenderTransparentOnly,
bool aRenderSelectedOnly ) bool aRenderSelectedOnly )
{ {
wxASSERT( ( aGetTop == true ) || ( aGetBot == true ) ); wxASSERT( ( aGetTop == true ) || ( aGetBot == true ) );
@ -1061,11 +957,8 @@ void RENDER_3D_OPENGL::get3dModelsSelected( std::list<MODELTORENDER> &aDstRender
if( fp->IsSelected() ) if( fp->IsSelected() )
highlight = true; highlight = true;
if( m_boardAdapter.m_Cfg->m_Render.opengl_highlight_on_rollover if( m_boardAdapter.m_Cfg->m_Render.highlight_on_rollover && fp == m_currentRollOverItem )
&& fp == m_currentRollOverItem )
{
highlight = true; highlight = true;
}
if( aRenderSelectedOnly != highlight ) if( aRenderSelectedOnly != highlight )
continue; continue;
@ -1077,8 +970,7 @@ void RENDER_3D_OPENGL::get3dModelsSelected( std::list<MODELTORENDER> &aDstRender
{ {
const bool isFlipped = fp->IsFlipped(); const bool isFlipped = fp->IsFlipped();
if( ( aGetTop == !isFlipped ) || if( aGetTop == !isFlipped || aGetBot == isFlipped )
( aGetBot == isFlipped ) )
get3dModelsFromFootprint( aDstRenderList, fp, aRenderTransparentOnly, highlight ); get3dModelsFromFootprint( aDstRenderList, fp, aRenderTransparentOnly, highlight );
} }
} }
@ -1087,8 +979,8 @@ void RENDER_3D_OPENGL::get3dModelsSelected( std::list<MODELTORENDER> &aDstRender
void RENDER_3D_OPENGL::get3dModelsFromFootprint( std::list<MODELTORENDER> &aDstRenderList, void RENDER_3D_OPENGL::get3dModelsFromFootprint( std::list<MODELTORENDER> &aDstRenderList,
const FOOTPRINT* aFootprint, bool aRenderTransparentOnly, const FOOTPRINT* aFootprint,
bool aIsSelected ) bool aRenderTransparentOnly, bool aIsSelected )
{ {
if( !aFootprint->Models().empty() ) if( !aFootprint->Models().empty() )
{ {
@ -1098,15 +990,13 @@ void RENDER_3D_OPENGL::get3dModelsFromFootprint( std::list<MODELTORENDER> &aDstR
glm::mat4 fpMatrix( 1.0f ); glm::mat4 fpMatrix( 1.0f );
fpMatrix = glm::translate( fpMatrix, fpMatrix = glm::translate( fpMatrix, SFVEC3F( pos.x * m_boardAdapter.BiuTo3dUnits(),
SFVEC3F( pos.x * m_boardAdapter.BiuTo3dUnits(),
-pos.y * m_boardAdapter.BiuTo3dUnits(), -pos.y * m_boardAdapter.BiuTo3dUnits(),
zpos ) ); zpos ) );
if( !aFootprint->GetOrientation().IsZero() ) if( !aFootprint->GetOrientation().IsZero() )
{ {
fpMatrix = glm::rotate( fpMatrix, fpMatrix = glm::rotate( fpMatrix, (float) aFootprint->GetOrientation().AsRadians(),
(float) aFootprint->GetOrientation().AsRadians(),
SFVEC3F( 0.0f, 0.0f, 1.0f ) ); SFVEC3F( 0.0f, 0.0f, 1.0f ) );
} }
@ -1116,11 +1006,9 @@ void RENDER_3D_OPENGL::get3dModelsFromFootprint( std::list<MODELTORENDER> &aDstR
fpMatrix = glm::rotate( fpMatrix, glm::pi<float>(), SFVEC3F( 0.0f, 0.0f, 1.0f ) ); fpMatrix = glm::rotate( fpMatrix, glm::pi<float>(), SFVEC3F( 0.0f, 0.0f, 1.0f ) );
} }
const double modelunit_to_3d_units_factor = m_boardAdapter.BiuTo3dUnits() * double modelunit_to_3d_units_factor = m_boardAdapter.BiuTo3dUnits() * UNITS3D_TO_UNITSPCB;
UNITS3D_TO_UNITSPCB;
fpMatrix = glm::scale( fpMatrix, fpMatrix = glm::scale( fpMatrix, SFVEC3F( modelunit_to_3d_units_factor ) );
SFVEC3F( modelunit_to_3d_units_factor ) );
// Get the list of model files for this model // Get the list of model files for this model
for( const FP_3DMODEL& sM : aFootprint->Models() ) for( const FP_3DMODEL& sM : aFootprint->Models() )
@ -1170,23 +1058,11 @@ void RENDER_3D_OPENGL::get3dModelsFromFootprint( std::list<MODELTORENDER> &aDstR
modelworldMatrix *= mtx; modelworldMatrix *= mtx;
} }
if( aRenderTransparentOnly ) aDstRenderList.emplace_back( modelworldMatrix, modelPtr,
{ aRenderTransparentOnly ? sM.m_Opacity : 1.0f,
aDstRenderList.emplace_back( modelworldMatrix, aRenderTransparentOnly,
modelPtr,
sM.m_Opacity,
true,
aFootprint->IsSelected() || aIsSelected ); aFootprint->IsSelected() || aIsSelected );
} }
else
{
aDstRenderList.emplace_back( modelworldMatrix,
modelPtr,
1.0f,
false,
aFootprint->IsSelected() || aIsSelected );
}
}
} }
} }
} }
@ -1300,9 +1176,7 @@ void RENDER_3D_OPENGL::renderTransparentModels( const glm::mat4 &aCameraViewMatr
glEnableClientState( GL_TEXTURE_COORD_ARRAY ); glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glEnable( GL_COLOR_MATERIAL ); glEnable( GL_COLOR_MATERIAL );
} }
else else if( isUsingColorInformation && mtr.first->m_isSelected )
{
if( isUsingColorInformation && mtr.first->m_isSelected )
{ {
isUsingColorInformation = false; isUsingColorInformation = false;
@ -1311,7 +1185,6 @@ void RENDER_3D_OPENGL::renderTransparentModels( const glm::mat4 &aCameraViewMatr
glDisable( GL_COLOR_MATERIAL ); glDisable( GL_COLOR_MATERIAL );
} }
} }
}
// Render model, sort each individuall material group // Render model, sort each individuall material group
// by passing cameraPos // by passing cameraPos
@ -1326,8 +1199,7 @@ void RENDER_3D_OPENGL::renderTransparentModels( const glm::mat4 &aCameraViewMatr
void RENDER_3D_OPENGL::renderModel( const glm::mat4 &aCameraViewMatrix, void RENDER_3D_OPENGL::renderModel( const glm::mat4 &aCameraViewMatrix,
const MODELTORENDER &aModelToRender, const MODELTORENDER &aModelToRender,
const SFVEC3F &aSelColor, const SFVEC3F &aSelColor, const SFVEC3F *aCameraWorldPos )
const SFVEC3F *aCameraWorldPos )
{ {
const glm::mat4 modelviewMatrix = aCameraViewMatrix * aModelToRender.m_modelWorldMat; const glm::mat4 modelviewMatrix = aCameraViewMatrix * aModelToRender.m_modelWorldMat;
@ -1337,7 +1209,7 @@ void RENDER_3D_OPENGL::renderModel( const glm::mat4 &aCameraViewMatrix,
aModelToRender.m_isSelected, aSelColor, aModelToRender.m_isSelected, aSelColor,
&aModelToRender.m_modelWorldMat, aCameraWorldPos ); &aModelToRender.m_modelWorldMat, aCameraWorldPos );
if( m_boardAdapter.m_Cfg->m_Render.opengl_show_model_bbox ) if( m_boardAdapter.m_Cfg->m_Render.show_model_bbox )
{ {
const bool wasBlendEnabled = glIsEnabled( GL_BLEND ); const bool wasBlendEnabled = glIsEnabled( GL_BLEND );

View File

@ -73,13 +73,12 @@ public:
private: private:
OPENGL_RENDER_LIST* generateHoles( const LIST_OBJECT2D& aListHolesObject2d, OPENGL_RENDER_LIST* generateHoles( const LIST_OBJECT2D& aListHolesObject2d,
const SHAPE_POLY_SET& aPoly, float aZtop, const SHAPE_POLY_SET& aPoly, float aZtop, float aZbot,
float aZbot, bool aInvertFaces, bool aInvertFaces,
const BVH_CONTAINER_2D* aThroughHoles = nullptr ); const BVH_CONTAINER_2D* aThroughHoles = nullptr );
OPENGL_RENDER_LIST* generateLayerList( const BVH_CONTAINER_2D* aContainer, OPENGL_RENDER_LIST* generateLayerList( const BVH_CONTAINER_2D* aContainer,
const SHAPE_POLY_SET* aPolyList, const SHAPE_POLY_SET* aPolyList, PCB_LAYER_ID aLayerId,
PCB_LAYER_ID aLayerId,
const BVH_CONTAINER_2D* aThroughHoles = nullptr ); const BVH_CONTAINER_2D* aThroughHoles = nullptr );
OPENGL_RENDER_LIST* generateEmptyLayerList( PCB_LAYER_ID aLayerId ); OPENGL_RENDER_LIST* generateEmptyLayerList( PCB_LAYER_ID aLayerId );
@ -93,17 +92,17 @@ private:
void addObjectTriangles( const POLYGON_4PT_2D* aPoly, TRIANGLE_DISPLAY_LIST* aDstLayer, void addObjectTriangles( const POLYGON_4PT_2D* aPoly, TRIANGLE_DISPLAY_LIST* aDstLayer,
float aZtop, float aZbot ); float aZtop, float aZbot );
void addObjectTriangles( const FILLED_CIRCLE_2D* aFilledCircle, void addObjectTriangles( const FILLED_CIRCLE_2D* aCircle, TRIANGLE_DISPLAY_LIST* aDstLayer,
TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop, float aZbot ); float aZtop, float aZbot );
void addObjectTriangles( const TRIANGLE_2D* aTri, TRIANGLE_DISPLAY_LIST* aDstLayer, void addObjectTriangles( const TRIANGLE_2D* aTri, TRIANGLE_DISPLAY_LIST* aDstLayer,
float aZtop, float aZbot ); float aZtop, float aZbot );
void addObjectTriangles( const ROUND_SEGMENT_2D* aSeg, void addObjectTriangles( const ROUND_SEGMENT_2D* aSeg, TRIANGLE_DISPLAY_LIST* aDstLayer,
TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop, float aZbot ); float aZtop, float aZbot );
void renderSolderMaskLayer( PCB_LAYER_ID aLayerID, float aZPosition, void renderSolderMaskLayer( PCB_LAYER_ID aLayerID, float aZPos, bool aDrawMiddleSegments,
bool aDrawMiddleSegments, bool aSkipRenderHoles ); bool aSkipRenderHoles );
void renderBoardBody( bool aSkipRenderHoles ); void renderBoardBody( bool aSkipRenderHoles );
@ -154,15 +153,12 @@ private:
void renderOpaqueModels( const glm::mat4 &aCameraViewMatrix ); void renderOpaqueModels( const glm::mat4 &aCameraViewMatrix );
void renderTransparentModels( const glm::mat4 &aCameraViewMatrix ); void renderTransparentModels( const glm::mat4 &aCameraViewMatrix );
void renderModel( const glm::mat4 &aCameraViewMatrix, void renderModel( const glm::mat4 &aCameraViewMatrix, const MODELTORENDER &aModelToRender,
const MODELTORENDER &aModelToRender, const SFVEC3F &aSelColor, const SFVEC3F *aCameraWorldPos );
const SFVEC3F &aSelColor,
const SFVEC3F *aCameraWorldPos );
void get3dModelsSelected( std::list<MODELTORENDER> &aDstRenderList, void get3dModelsSelected( std::list<MODELTORENDER> &aDstRenderList, bool aGetTop, bool aGetBot,
bool aGetTop, bool aGetBot, bool aRenderTransparentOnly, bool aRenderTransparentOnly, bool aRenderSelectedOnly );
bool aRenderSelectedOnly );
void get3dModelsFromFootprint( std::list<MODELTORENDER> &aDstRenderList, void get3dModelsFromFootprint( std::list<MODELTORENDER> &aDstRenderList,
const FOOTPRINT* aFootprint, bool aRenderTransparentOnly, const FOOTPRINT* aFootprint, bool aRenderTransparentOnly,

View File

@ -253,7 +253,7 @@ void EDA_3D_VIEWER_FRAME::setupUIConditions()
auto showBBoxes = auto showBBoxes =
[this]( const SELECTION& aSel ) [this]( const SELECTION& aSel )
{ {
return m_boardAdapter.m_Cfg->m_Render.opengl_show_model_bbox; return m_boardAdapter.m_Cfg->m_Render.show_model_bbox;
}; };
auto showAxes = auto showAxes =
[this]( const SELECTION& aSel ) [this]( const SELECTION& aSel )

View File

@ -219,11 +219,11 @@ EDA_3D_VIEWER_SETTINGS::EDA_3D_VIEWER_SETTINGS() :
m_params.emplace_back( new PARAM<bool>( "render.opengl_copper_thickness", m_params.emplace_back( new PARAM<bool>( "render.opengl_copper_thickness",
&m_Render.opengl_copper_thickness, false ) ); &m_Render.opengl_copper_thickness, false ) );
m_params.emplace_back( new PARAM<bool>( "render.opengl_show_model_bbox", m_params.emplace_back( new PARAM<bool>( "render.opengl_show_model_bbox",
&m_Render.opengl_show_model_bbox, false ) ); &m_Render.show_model_bbox, false ) );
m_params.emplace_back( new PARAM<bool>( "render.opengl_show_off_board_silk", m_params.emplace_back( new PARAM<bool>( "render.opengl_show_off_board_silk",
&m_Render.opengl_show_off_board_silk, false ) ); &m_Render.show_off_board_silk, false ) );
m_params.emplace_back( new PARAM<bool>( "render.opengl_highlight_on_rollover", m_params.emplace_back( new PARAM<bool>( "render.opengl_highlight_on_rollover",
&m_Render.opengl_highlight_on_rollover, true ) ); &m_Render.highlight_on_rollover, true ) );
m_params.emplace_back( new PARAM<bool>( "render.opengl_AA_disableOnMove", m_params.emplace_back( new PARAM<bool>( "render.opengl_AA_disableOnMove",
&m_Render.opengl_AA_disableOnMove, false ) ); &m_Render.opengl_AA_disableOnMove, false ) );
m_params.emplace_back( new PARAM<bool>( "render.opengl_thickness_disableOnMove", m_params.emplace_back( new PARAM<bool>( "render.opengl_thickness_disableOnMove",

View File

@ -89,9 +89,9 @@ public:
bool opengl_holes_disableOnMove; bool opengl_holes_disableOnMove;
bool opengl_render_bbox_only_OnMove; bool opengl_render_bbox_only_OnMove;
bool opengl_copper_thickness; bool opengl_copper_thickness;
bool opengl_show_model_bbox; bool show_model_bbox;
bool opengl_show_off_board_silk; bool show_off_board_silk;
bool opengl_highlight_on_rollover; bool highlight_on_rollover;
KIGFX::COLOR4D opengl_selection_color; KIGFX::COLOR4D opengl_selection_color;
bool raytrace_anti_aliasing; bool raytrace_anti_aliasing;

View File

@ -30,7 +30,6 @@ set(3D-VIEWER_SRCS
3d_canvas/board_adapter.cpp 3d_canvas/board_adapter.cpp
3d_canvas/create_layer_items.cpp 3d_canvas/create_layer_items.cpp
3d_canvas/create_3Dgraphic_brd_items.cpp 3d_canvas/create_3Dgraphic_brd_items.cpp
3d_canvas/create_layer_poly.cpp
3d_canvas/eda_3d_canvas.cpp 3d_canvas/eda_3d_canvas.cpp
3d_canvas/eda_3d_canvas_pivot.cpp 3d_canvas/eda_3d_canvas_pivot.cpp
3d_model_viewer/eda_3d_model_viewer.cpp 3d_model_viewer/eda_3d_model_viewer.cpp

View File

@ -41,8 +41,8 @@ PANEL_3D_OPENGL_OPTIONS::PANEL_3D_OPENGL_OPTIONS( wxWindow* aParent ) :
void PANEL_3D_OPENGL_OPTIONS::loadSettings( EDA_3D_VIEWER_SETTINGS* aCfg ) void PANEL_3D_OPENGL_OPTIONS::loadSettings( EDA_3D_VIEWER_SETTINGS* aCfg )
{ {
m_checkBoxCuThickness->SetValue( aCfg->m_Render.opengl_copper_thickness ); m_checkBoxCuThickness->SetValue( aCfg->m_Render.opengl_copper_thickness );
m_checkBoxBoundingBoxes->SetValue( aCfg->m_Render.opengl_show_model_bbox ); m_checkBoxBoundingBoxes->SetValue( aCfg->m_Render.show_model_bbox );
m_checkBoxHighlightOnRollOver->SetValue( aCfg->m_Render.opengl_highlight_on_rollover ); m_checkBoxHighlightOnRollOver->SetValue( aCfg->m_Render.highlight_on_rollover );
m_choiceAntiAliasing->SetSelection( static_cast<int>( aCfg->m_Render.opengl_AA_mode ) ); m_choiceAntiAliasing->SetSelection( static_cast<int>( aCfg->m_Render.opengl_AA_mode ) );
m_selectionColorSwatch->SetSwatchColor( aCfg->m_Render.opengl_selection_color, false ); m_selectionColorSwatch->SetSwatchColor( aCfg->m_Render.opengl_selection_color, false );
@ -69,8 +69,8 @@ bool PANEL_3D_OPENGL_OPTIONS::TransferDataFromWindow()
EDA_3D_VIEWER_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EDA_3D_VIEWER_SETTINGS>(); EDA_3D_VIEWER_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EDA_3D_VIEWER_SETTINGS>();
cfg->m_Render.opengl_copper_thickness = m_checkBoxCuThickness->GetValue(); cfg->m_Render.opengl_copper_thickness = m_checkBoxCuThickness->GetValue();
cfg->m_Render.opengl_show_model_bbox = m_checkBoxBoundingBoxes->GetValue(); cfg->m_Render.show_model_bbox = m_checkBoxBoundingBoxes->GetValue();
cfg->m_Render.opengl_highlight_on_rollover = m_checkBoxHighlightOnRollOver->GetValue(); cfg->m_Render.highlight_on_rollover = m_checkBoxHighlightOnRollOver->GetValue();
cfg->m_Render.opengl_AA_mode = static_cast<ANTIALIASING_MODE>( m_choiceAntiAliasing->GetSelection() ); cfg->m_Render.opengl_AA_mode = static_cast<ANTIALIASING_MODE>( m_choiceAntiAliasing->GetSelection() );
cfg->m_Render.opengl_selection_color = m_selectionColorSwatch->GetSwatchColor(); cfg->m_Render.opengl_selection_color = m_selectionColorSwatch->GetSwatchColor();