36#include <glm/geometric.hpp>
53 wxLogTrace(
m_logTrace, wxT(
"RENDER_3D_OPENGL::RENDER_3D_OPENGL" ) );
90 wxLogTrace(
m_logTrace, wxT(
"RENDER_3D_OPENGL::~RENDER_3D_OPENGL" ) );
116 int fbWidth, fbHeight;
117 glGetIntegerv( GL_VIEWPORT, viewport );
130 glEnable( GL_LIGHT0 );
132 glDisable( GL_LIGHT0 );
139 glEnable( GL_LIGHT1 );
141 glDisable( GL_LIGHT1 );
148 glEnable( GL_LIGHT2 );
150 glDisable( GL_LIGHT2 );
213 m_materials.m_Copper.m_Shininess = shininessfactor * 128.0f;
222 m_materials.m_NonPlatedCopper.m_Shininess = 0.1f * 128.0f;
251 m_materials.m_Adhesive.m_Shininess = 0.1f * 128.0f;
265 m_materials.m_SilkSTop.m_Shininess = 0.078125f * 128.0f;
278 m_materials.m_SilkSBot.m_Shininess = 0.078125f * 128.0f;
281 m_materials.m_SolderMask.m_Shininess = 0.8f * 128.0f;
291 m_materials.m_EpoxyBoard.m_Shininess = 0.1f * 128.0f;
321 m_materials.m_SolderMask.m_Transparency = 1.0f - layerColor.a;
389 m_materials.m_Plastic.m_Shininess = 0.078125f * 128.0f;
412 m_materials.m_Plastic.m_Shininess = 0.078125f * 128.0f;
430 const GLfloat ambient[] = { 0.084f, 0.084f, 0.084f, 1.0f };
431 const GLfloat diffuse0[] = { 0.3f, 0.3f, 0.3f, 1.0f };
432 const GLfloat specular0[] = { 0.5f, 0.5f, 0.5f, 1.0f };
434 glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
435 glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse0 );
436 glLightfv( GL_LIGHT0, GL_SPECULAR, specular0 );
438 const GLfloat diffuse12[] = { 0.7f, 0.7f, 0.7f, 1.0f };
439 const GLfloat specular12[] = { 0.7f, 0.7f, 0.7f, 1.0f };
442 GLfloat position[4] = { 0.0f, 0.0f, 1.0f, 0.0f };
446 glm::pi<float>() * 0.25f );
448 position[0] = vectorLight.x;
449 position[1] = vectorLight.y;
450 position[2] = vectorLight.z;
452 glLightfv( GL_LIGHT1, GL_AMBIENT, ambient );
453 glLightfv( GL_LIGHT1, GL_DIFFUSE, diffuse12 );
454 glLightfv( GL_LIGHT1, GL_SPECULAR, specular12 );
455 glLightfv( GL_LIGHT1, GL_POSITION, position );
458 position[2] = -position[2];
460 glLightfv( GL_LIGHT2, GL_AMBIENT, ambient );
461 glLightfv( GL_LIGHT2, GL_DIFFUSE, diffuse12 );
462 glLightfv( GL_LIGHT2, GL_SPECULAR, specular12 );
463 glLightfv( GL_LIGHT2, GL_POSITION, position );
465 const GLfloat lmodel_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
467 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmodel_ambient );
469 glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
481 glEnable( GL_POLYGON_OFFSET_FILL );
482 glPolygonOffset( -0.1f, -2.0f );
489 glDisable( GL_POLYGON_OFFSET_FILL );
502 std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> board_disp_list_def =
nullptr;
509 if( board_disp_list_def )
512 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_disp_list = board_disp_list_def->MakeOrGet() )
514 ogl_disp_list->ApplyScalePosition( -
m_boardAdapter.GetBoardBodyThickness() / 2.0f,
517 ogl_disp_list->SetItIsTransparent(
true );
518 ogl_disp_list->DrawAll();
525 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_disp_list =
m_postMachinePlugs->MakeOrGet() )
527 ogl_disp_list->ApplyScalePosition( -
m_boardAdapter.GetBoardBodyThickness() / 2.0f,
530 ogl_disp_list->SetItIsTransparent(
true );
531 ogl_disp_list->DrawAll();
539 return SFVEC4F( aInput.r * aInput.a, aInput.g * aInput.a, aInput.b * aInput.a, aInput.a );
556 if( reloadRequested )
592 glDepthFunc( GL_LESS );
593 glEnable( GL_CULL_FACE );
594 glFrontFace( GL_CCW );
595 glEnable( GL_NORMALIZE );
599 glDisable( GL_MULTISAMPLE );
601 glEnable( GL_MULTISAMPLE );
604 glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
605 glClearDepth( 1.0f );
606 glClearStencil( 0x00 );
607 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
615 glEnable( GL_DEPTH_TEST );
618 glMatrixMode( GL_PROJECTION );
619 glLoadMatrixf( glm::value_ptr(
m_camera.GetProjectionMatrix() ) );
620 glMatrixMode( GL_MODELVIEW );
622 glLoadMatrixf( glm::value_ptr(
m_camera.GetViewMatrix() ) );
629 glEnable( GL_LIGHTING );
638 if( cameraPos.z > 0.0f )
639 zpos = glm::max( cameraPos.z, 0.5f ) + cameraPos.z * cameraPos.z;
641 zpos = glm::min( cameraPos.z,-0.5f ) - cameraPos.z * cameraPos.z;
644 const GLfloat headlight_pos[] = { cameraPos.x, cameraPos.y, zpos, 1.0f };
646 glLightfv( GL_LIGHT0, GL_POSITION, headlight_pos );
652 bool showThickness = !skipThickness;
654 std::bitset<LAYER_3D_END> layerFlags =
m_boardAdapter.GetVisibleLayers();
661 ogl_disp_list->DrawAll();
666 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_disp_list =
m_padHoles->MakeOrGet() )
667 ogl_disp_list->DrawAll();
671 for( MAP_OGL_DISP_LISTS::const_iterator ii =
m_layers.begin(); ii !=
m_layers.end(); ++ii )
685 const double opacity_min = 0.8;
698 std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> pLayerDispListDef = ii->second;
699 std::shared_ptr<OPENGL_RENDER_LIST> pLayerDispList = pLayerDispListDef->MakeOrGet();
710 std::shared_ptr<OPENGL_RENDER_LIST> outerTH =
nullptr;
711 std::shared_ptr<OPENGL_RENDER_LIST> viaHoles =
nullptr;
713 if( !skipRenderHoles )
724 anti_board->ApplyScalePosition( pLayerDispList );
727 outerTH->ApplyScalePosition( pLayerDispList );
729 pLayerDispList->DrawCulled( showThickness, outerTH, viaHoles, anti_board );
738 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_disp_list =
m_platedPadsFront->MakeOrGet() )
739 ogl_disp_list->DrawCulled( showThickness, outerTH, viaHoles, anti_board );
745 ogl_disp_list->DrawCulled( showThickness, outerTH, viaHoles );
754 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_disp_list =
m_platedPadsBack->MakeOrGet() )
755 ogl_disp_list->DrawCulled( showThickness, outerTH, viaHoles, anti_board );
760 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_disp_list =
m_offboardPadsBack->MakeOrGet() )
761 ogl_disp_list->DrawCulled( showThickness, outerTH, viaHoles );
771 std::shared_ptr<OPENGL_RENDER_LIST> throughHolesOuter =
nullptr;
772 std::shared_ptr<OPENGL_RENDER_LIST> anti_board =
nullptr;
773 std::shared_ptr<OPENGL_RENDER_LIST> solder_mask =
nullptr;
775 if( !skipRenderHoles )
786 anti_board =
nullptr;
793 solder_mask =
m_layers[maskLayer] ?
m_layers[maskLayer]->MakeOrGet() :
nullptr;
796 if( throughHolesOuter )
797 throughHolesOuter->ApplyScalePosition( pLayerDispList );
800 anti_board->ApplyScalePosition( pLayerDispList );
803 solder_mask->ApplyScalePosition( pLayerDispList );
806 glEnable( GL_POLYGON_OFFSET_FILL );
807 glPolygonOffset( 0.0f, -4.0f );
809 pLayerDispList->DrawCulled( showThickness, solder_mask, throughHolesOuter, anti_board );
811 glDisable( GL_POLYGON_OFFSET_FILL );
812 glPolygonOffset( 0.0f, 0.0f );
818 glm::mat4 cameraViewMatrix;
820 glGetFloatv( GL_MODELVIEW_MATRIX, glm::value_ptr( cameraViewMatrix ) );
836 std::shared_ptr<OPENGL_RENDER_LIST> renderList = renderListDef->MakeOrGet();
841 bool highlight =
false;
845 if( fp->IsSelected() )
859 renderList->DrawAll();
870 glEnable( GL_POLYGON_OFFSET_FILL );
871 glPolygonOffset( 0.0f, 2.0f );
875 glDisable( GL_POLYGON_OFFSET_FILL );
876 glPolygonOffset( 0.0f, 0.0f );
885 glEnable( GL_POLYGON_OFFSET_FILL );
886 glPolygonOffset( 0.0f, -2.0f );
893 showThickness, skipRenderHoles );
899 showThickness, skipRenderHoles );
907 showThickness, skipRenderHoles );
913 showThickness, skipRenderHoles );
917 glDisable( GL_POLYGON_OFFSET_FILL );
918 glPolygonOffset( 0.0f, 0.0f );
924 glDepthMask( GL_FALSE );
925 glEnable( GL_BLEND );
926 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
929 glEnable( GL_TEXTURE_2D );
930 glActiveTexture( GL_TEXTURE0 );
935 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
936 glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE );
937 glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE );
939 glTexEnvi( GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PRIMARY_COLOR );
940 glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR );
942 glTexEnvi( GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS );
943 glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR );
945 glTexEnvi( GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PRIMARY_COLOR );
946 glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA );
947 glTexEnvi( GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_CONSTANT );
948 glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA );
952 glDisable( GL_BLEND );
955 glEnable( GL_BLEND );
956 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
960 glDisable( GL_BLEND );
962 glDepthMask( GL_TRUE );
967 glDisable( GL_LIGHTING );
972 glEnable( GL_LIGHTING );
989 glEnable( GL_LINE_SMOOTH );
990 glShadeModel( GL_SMOOTH );
993 glPixelStorei( GL_UNPACK_ALIGNMENT, 4 );
1014 delete circleImageBlured;
1015 circleImageBlured =
nullptr;
1018 circleImage =
nullptr;
1032 glEnable( GL_COLOR_MATERIAL );
1033 glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
1040 glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r );
1041 glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 96.0f );
1043 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r );
1044 glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r );
1045 glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, &emissive.r );
1051#define DELETE_AND_FREE( ptr ) \
1056#define DELETE_AND_FREE_MAP( map ) \
1058 for( auto& [ layer, ptr ] : map ) \
1065 glDeleteLists(
m_grid, 1 );
1079 for( std::shared_ptr<TRIANGLE_DISPLAY_LIST>& list :
m_triangles )
1111 std::vector<std::shared_ptr<void>> retired;
1114 std::lock_guard<std::recursive_mutex> lock(
m_renderMutex );
1121 bool aShowThickness,
bool aSkipRenderHoles )
1123 wxASSERT( (aLayerID ==
B_Mask) || (aLayerID ==
F_Mask) );
1127 std::shared_ptr<OPENGL_RENDER_LIST> board_list =
m_board->MakeOrGet();
1128 std::shared_ptr<OPENGL_RENDER_LIST> solder_mask =
m_layers[aLayerID] ?
m_layers[aLayerID]->MakeOrGet()
1130 std::shared_ptr<OPENGL_RENDER_LIST> via_holes;
1132 if( !aSkipRenderHoles )
1141 via_holes->ApplyScalePosition( aZPos,
m_boardAdapter.GetNonCopperLayerThickness() );
1143 board_list->ApplyScalePosition( aZPos,
m_boardAdapter.GetNonCopperLayerThickness() );
1146 board_list->SetItIsTransparent(
true );
1147 board_list->DrawCulled( aShowThickness, solder_mask, via_holes );
1151 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_draw_list =
m_viaFrontCover->MakeOrGet() )
1153 ogl_draw_list->ApplyScalePosition( aZPos, 4 *
m_boardAdapter.GetNonCopperLayerThickness() );
1154 ogl_draw_list->DrawTop();
1159 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_draw_list =
m_viaBackCover->MakeOrGet() )
1161 ogl_draw_list->ApplyScalePosition( aZPos, 4 *
m_boardAdapter.GetNonCopperLayerThickness() );
1162 ogl_draw_list->DrawBot();
1170 bool aGetBot,
bool aRenderTransparentOnly,
1171 bool aRenderSelectedOnly )
1173 wxASSERT( ( aGetTop ==
true ) || ( aGetBot ==
true ) );
1183 bool highlight =
false;
1187 if( fp->IsSelected() )
1193 if( aRenderSelectedOnly != highlight )
1197 if( !fp->Models().empty() ||
m_boardAdapter.ShowMissingModels() )
1201 const bool isFlipped = fp->IsFlipped();
1203 if( aGetTop == !isFlipped || aGetBot == isFlipped )
1213 bool aRenderTransparentOnly,
bool aIsSelected )
1215 if( !aFootprint->
Models().empty() )
1217 const glm::mat4 fpMatrix =
m_boardAdapter.GetFootprintMatrix( *aFootprint );
1220 bool placeholderAdded =
false;
1225 if( !sM.m_Show || sM.m_Filename.empty() )
1233 if( !placeholderAdded )
1236 aIsSelected, aRenderTransparentOnly ? sM.m_Opacity : 1.0f );
1237 placeholderAdded =
true;
1243 if(
const std::shared_ptr<MODEL_3D_DEFERRED>& modelPtrDef = cache_i->second )
1245 std::shared_ptr<MODEL_3D> modelPtr = modelPtrDef->MakeOrGet();
1250 bool opaque = sM.m_Opacity >= 1.0;
1252 if( ( !aRenderTransparentOnly && modelPtr->HasOpaqueMeshes() && opaque ) ||
1253 ( aRenderTransparentOnly && ( modelPtr->HasTransparentMeshes() || !opaque ) ) )
1255 glm::mat4 modelworldMatrix = fpMatrix;
1257 const SFVEC3F offset =
SFVEC3F( sM.m_Offset.x, sM.m_Offset.y, sM.m_Offset.z );
1258 const SFVEC3F rotation =
SFVEC3F( sM.m_Rotation.x, sM.m_Rotation.y,
1262 std::vector<float> key = { offset.x, offset.y, offset.z,
1263 rotation.x, rotation.y, rotation.z,
1270 modelworldMatrix *= it->second;
1277 modelworldMatrix *= mtx;
1280 aDstRenderList.emplace_back( modelworldMatrix, modelPtr,
1281 aRenderTransparentOnly ? sM.m_Opacity : 1.0f,
1282 aRenderTransparentOnly,
1290 const glm::mat4 fpMatrix =
m_boardAdapter.GetFootprintMatrix( *aFootprint );
1299 const glm::mat4& aFpMatrix,
const FOOTPRINT* aFootprint,
1300 bool aRenderTransparentOnly,
bool aIsSelected,
float aOpacity )
1314 float scaleX = bboxW;
1315 float scaleY = bboxH;
1316 float scaleZ = std::min( bboxW, bboxH ) * 0.5f;
1319 float offsetX = localCenter.
x /
pcbIUScale.IU_PER_MM;
1320 float offsetY = -localCenter.
y /
pcbIUScale.IU_PER_MM;
1321 float offsetZ = scaleZ * 0.5f;
1326 glm::mat4 mtx = aFpMatrix;
1327 mtx = glm::translate( mtx,
SFVEC3F( offsetX, offsetY, offsetZ ) );
1328 mtx = glm::scale( mtx,
SFVEC3F( scaleX, scaleY, scaleZ ) );
1330 bool placeholderOpaque = aOpacity >= 1.0;
1332 if( ( !aRenderTransparentOnly &&
m_placeholderModel->HasOpaqueMeshes() && placeholderOpaque )
1333 || ( aRenderTransparentOnly && (
m_placeholderModel->HasTransparentMeshes() || !placeholderOpaque ) ) )
1335 aDstRenderList.emplace_back( mtx,
m_placeholderModel, aOpacity, aRenderTransparentOnly,
1349 std::list<MODELTORENDER> renderList;
1357 if( !renderList.empty() )
1362 renderModel( aCameraViewMatrix, mtr, selColor,
nullptr );
1371 if( !renderList.empty() )
1376 renderModel( aCameraViewMatrix, mtr, selColor,
nullptr );
1392 const EXTRUDED_3D_BODY* body = fp->GetBody() ? fp->GetBody()->GetExtruded() :
nullptr;
1397 if( !renderListDef )
1400 std::shared_ptr<OPENGL_RENDER_LIST> renderList = renderListDef->MakeOrGet();
1405 bool highlight =
false;
1409 if( fp->IsSelected() )
1421 if( ( c.
a < 1.0 ) != aTransparentPass )
1437 renderList->DrawAll();
1443 if( std::shared_ptr<OPENGL_RENDER_LIST> pegList = pegIt->second->MakeOrGet() )
1456 std::list<MODELTORENDER> renderListModels;
1467 if( renderListModels.empty() )
1470 std::vector<std::pair<const MODELTORENDER *, float>> transparentModelList;
1472 transparentModelList.reserve( renderListModels.size() );
1479 const BBOX_3D& bBox = mtr.m_model->GetBBox();
1481 const SFVEC3F bBoxWorld = mtr.m_modelWorldMat * glm::vec4( bBoxCenter, 1.0f );
1483 const float distanceToCamera = glm::length( cameraPos - bBoxWorld );
1485 transparentModelList.emplace_back( &mtr, distanceToCamera );
1489 std::sort( transparentModelList.begin(), transparentModelList.end(),
1490 [&]( std::pair<const MODELTORENDER *, float>& a,
1491 std::pair<const MODELTORENDER *, float>& b )
1493 if( a.second != b.second )
1494 return a.second > b.second;
1496 return a.first > b.first;
1502 bool isUsingColorInformation = !( transparentModelList.begin()->first->m_isSelected &&
1507 for(
const std::pair<const MODELTORENDER *, float>& mtr : transparentModelList )
1512 if( !isUsingColorInformation && !mtr.first->m_isSelected )
1514 isUsingColorInformation =
true;
1516 glEnableClientState( GL_COLOR_ARRAY );
1517 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1518 glEnable( GL_COLOR_MATERIAL );
1520 else if( isUsingColorInformation && mtr.first->m_isSelected )
1522 isUsingColorInformation =
false;
1524 glDisableClientState( GL_COLOR_ARRAY );
1525 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1526 glDisable( GL_COLOR_MATERIAL );
1532 renderModel( aCameraViewMatrix, *mtr.first, selColor, &cameraPos );
1547 const glm::mat4 modelviewMatrix = aCameraViewMatrix * aModelToRender.
m_modelWorldMat;
1549 glLoadMatrixf( glm::value_ptr( modelviewMatrix ) );
1557 const bool wasBlendEnabled = glIsEnabled( GL_BLEND );
1559 if( !wasBlendEnabled )
1561 glEnable( GL_BLEND );
1562 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1565 glDisable( GL_LIGHTING );
1573 glEnable( GL_LIGHTING );
1575 if( !wasBlendEnabled )
1576 glDisable( GL_BLEND );
1584 glDeleteLists(
m_grid, 1 );
1591 m_grid = glGenLists( 1 );
1593 if( !glIsList(
m_grid ) )
1596 glNewList(
m_grid, GL_COMPILE );
1598 glEnable( GL_BLEND );
1599 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1601 const double zpos = 0.0;
1609 const GLfloat transparency = 0.35f;
1611 double griSizeMM = 0.0;
1624 glNormal3f( 0.0, 0.0, 1.0 );
1629 brd_center_pos.
y = -brd_center_pos.
y;
1631 const int xsize = std::max( brd_size.
x,
pcbIUScale.mmToIU( 100 ) ) * 1.2;
1632 const int ysize = std::max( brd_size.
y,
pcbIUScale.mmToIU( 100 ) ) * 1.2;
1635 double xmin = ( brd_center_pos.
x - xsize / 2 ) *
scale;
1636 double xmax = ( brd_center_pos.
x + xsize / 2 ) *
scale;
1637 double ymin = ( brd_center_pos.
y - ysize / 2 ) *
scale;
1638 double ymax = ( brd_center_pos.
y + ysize / 2 ) *
scale;
1646 for(
int ii = 0; ; ii++ )
1649 glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency );
1651 glColor4f( gridColor_marker.r, gridColor_marker.g, gridColor_marker.b,
1656 if(
delta <= xsize / 2 )
1658 glBegin( GL_LINES );
1659 glVertex3f( (brd_center_pos.
x +
delta) *
scale, -ymin, zpos );
1660 glVertex3f( (brd_center_pos.
x +
delta) *
scale, -ymax, zpos );
1665 glBegin( GL_LINES );
1666 glVertex3f( (brd_center_pos.
x -
delta) *
scale, -ymin, zpos );
1667 glVertex3f( (brd_center_pos.
x -
delta) *
scale, -ymax, zpos );
1672 if(
delta <= ysize / 2 )
1674 glBegin( GL_LINES );
1675 glVertex3f( xmin, -( brd_center_pos.
y +
delta ) *
scale, zpos );
1676 glVertex3f( xmax, -( brd_center_pos.
y +
delta ) *
scale, zpos );
1681 glBegin( GL_LINES );
1682 glVertex3f( xmin, -( brd_center_pos.
y -
delta ) *
scale, zpos );
1683 glVertex3f( xmax, -( brd_center_pos.
y -
delta ) *
scale, zpos );
1688 if( (
delta > ysize / 2 ) && (
delta > xsize / 2 ) )
1693 glNormal3f( 0.0, -1.0, 0.0 );
1696 double posy = -brd_center_pos.
y *
scale;
1698 for(
int ii = 0; ; ii++ )
1701 glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency );
1703 glColor4f( gridColor_marker.r, gridColor_marker.g, gridColor_marker.b,
1708 glBegin( GL_LINES );
1711 glVertex3f( xmax, posy, zmin );
1712 glVertex3f( xmax, posy, zmax );
1717 glBegin( GL_LINES );
1719 glVertex3f( xmin, posy, zmin );
1720 glVertex3f( xmin, posy, zmax );
1724 if(
delta > xsize / 2.0f )
1729 for(
int ii = 0; ; ii++ )
1732 glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency );
1734 glColor4f( gridColor_marker.r, gridColor_marker.g, gridColor_marker.b, transparency );
1741 glBegin( GL_LINES );
1742 glVertex3f( xmin, posy,
delta );
1743 glVertex3f( xmax, posy,
delta );
1747 if(
delta <= -zmin && ( ii != 0 ) )
1750 glBegin( GL_LINES );
1751 glVertex3f( xmin, posy, -
delta );
1752 glVertex3f( xmax, posy, -
delta );
1760 glDisable( GL_BLEND );
1769 static SFVEC3F positions[24] = {
1770 { -0.5f, -0.5f, 0.5f },
1771 { 0.5f, -0.5f, 0.5f },
1772 { 0.5f, 0.5f, 0.5f },
1773 { -0.5f, 0.5f, 0.5f },
1776 { -0.5f, 0.5f, -0.5f },
1777 { 0.5f, 0.5f, -0.5f },
1778 { 0.5f, -0.5f, -0.5f },
1779 { -0.5f, -0.5f, -0.5f },
1782 { 0.5f, -0.5f, -0.5f },
1783 { 0.5f, 0.5f, -0.5f },
1784 { 0.5f, 0.5f, 0.5f },
1785 { 0.5f, -0.5f, 0.5f },
1788 { -0.5f, -0.5f, 0.5f },
1789 { -0.5f, 0.5f, 0.5f },
1790 { -0.5f, 0.5f, -0.5f },
1791 { -0.5f, -0.5f, -0.5f },
1794 { -0.5f, 0.5f, 0.5f },
1795 { 0.5f, 0.5f, 0.5f },
1796 { 0.5f, 0.5f, -0.5f },
1797 { -0.5f, 0.5f, -0.5f },
1800 { -0.5f, -0.5f, -0.5f },
1801 { 0.5f, -0.5f, -0.5f },
1802 { 0.5f, -0.5f, 0.5f },
1803 { -0.5f, -0.5f, 0.5f }
1806 static SFVEC3F normals[24] = {
1838 static unsigned int indices[36] = {
1841 8, 9, 10, 8, 10, 11,
1842 12, 13, 14, 12, 14, 15,
1843 16, 17, 18, 16, 18, 19,
1844 20, 21, 22, 20, 22, 23
1856 static SMESH mesh = { 24, positions, normals,
nullptr,
nullptr, 36, indices, 0 };
@ NORMAL
Use all material properties from model file.
glm::mat4 CalcModelMatrix(const SFVEC3F &aOffset, const SFVEC3F &aRotation, const SFVEC3F &aScale)
Build the model-to-footprint transform used by rendering and picking.
Defines math related functions.
float mapf(float x, float in_min, float in_max, float out_min, float out_max)
SFVEC3F SphericalToCartesian(float aInclination, float aAzimuth)
https://en.wikipedia.org/wiki/Spherical_coordinate_system
EXTRUSION_MATERIAL_PROPS GetMaterialProps(EXTRUSION_MATERIAL aMaterial, const SFVEC3F &aDiffuse)
BOX2I CalcPlaceholderLocalBox(const FOOTPRINT *aFootprint)
Calculate a local space bounding box for a placeholder 3D model.
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Helper class to handle information needed to display 3D board.
constexpr size_type GetWidth() const
constexpr const Vec GetCenter() const
constexpr size_type GetHeight() const
A class used to derive camera objects from.
Implement a canvas based on a wxGLCanvas.
static KIGFX::COLOR4D GetDefaultColor(EXTRUSION_MATERIAL aMaterial)
EXTRUSION_MATERIAL m_material
auto RunWithoutCtxLock(Func &&aFunction, Args &&... args)
Run the given function first releasing the GL context lock, then restoring it.
Manage an 8-bit channel image.
void CircleFilled(int aCx, int aCy, int aRadius, unsigned char aValue)
void EfxFilter_SkipCenter(IMAGE *aInImg, IMAGE_FILTER aFilterType, unsigned int aRadius)
Apply a filter to the input image and store it in the image class.
unsigned int GetHeight() const
unsigned int GetWidth() const
A color representation with 4 components: red, green, blue, alpha.
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
static const LSET & PhysicalLayersMask()
Return a mask holding all layers which are physically realized.
void DrawBbox() const
Draw main bounding box of the model.
static void EndDrawMulti()
Cleanup render states after drawing multiple models.
void Draw(bool aTransparent, float aOpacity, bool aUseSelectedMaterial, const SFVEC3F &aSelectionColor, const glm::mat4 *aModelWorldMatrix, const SFVEC3F *aCameraWorldPos) const
Render the model into the current context.
static void BeginDrawMulti(bool aUseColorInformation)
Set some basic render states before drawing multiple models.
void DrawBboxes() const
Draw individual bounding boxes of each mesh.
GL_CONTEXT_MANAGER * GetGLContextManager()
std::unique_ptr< BUSY_INDICATOR > CreateBusyIndicator() const
Return a created busy indicator, if a factory has been set, else a null pointer.
RENDER_3D_BASE(BOARD_ADAPTER &aBoardAdapter, CAMERA &aCamera)
bool m_canvasInitialized
Flag if the canvas specific for this render was already initialized.
std::shared_ptr< REPORTER > m_activityReporter
wxSize m_windowSize
The window size that this camera is working.
BOARD_ADAPTER & m_boardAdapter
Settings reference in use for this render.
void renderExtrudedBodies()
SPHERES_GIZMO::GizmoSphereSelection getSelectedGizmoSphere() const
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_offboardPadsBack
std::map< const FOOTPRINT *, std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > > m_extrudedBodyLists
GRID3D_TYPE m_lastGridType
Stores the last grid type.
std::tuple< int, int, int, int > getGizmoViewport() const
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_viaFrontCover
void renderOpaqueModels(const glm::mat4 &aCameraViewMatrix)
void StopBgWorker() override
Request stop and join any in-progress background loading.
void generate3dGrid(GRID3D_TYPE aGridType)
Create a 3D grid to an OpenGL display list.
void setLightFront(bool enabled)
std::shared_ptr< MODEL_3D > m_placeholderModel
bool Redraw(bool aIsMoving) override
Redraw the view.
MAP_OGL_DISP_LISTS m_layers
MAP_OGL_DISP_LISTS m_innerLayerHoles
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_postMachinePlugs
Board material plugs for backdrill/counterbore/countersink.
RENDER_3D_OPENGL(EDA_3D_CANVAS *aCanvas, BOARD_ADAPTER &aAdapter, CAMERA &aCamera)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_offboardPadsFront
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_complexPlatedHoles
MAP_OGL_DISP_LISTS m_outerLayerHoles
BOARD_ITEM * m_currentRollOverItem
void renderBoardBody(bool aSkipRenderHoles)
std::map< std::vector< float >, glm::mat4 > m_3dModelMatrixMap
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_backOuterThroughHoles
std::recursive_mutex m_renderMutex
LIST_TRIANGLES m_triangles
store pointers so can be deleted latter
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_platedPadsFront
void setLayerMaterial(PCB_LAYER_ID aLayerID)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_platedPadsBack
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_board
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_boardWithHoles
void resetSelectedGizmoSphere()
struct RENDER_3D_OPENGL::@136145154067207014164113243162246125147361200233 m_materials
void createPlaceholderModel()
void renderModel(const glm::mat4 &aCameraViewMatrix, const MODELTORENDER &aModelToRender, const SFVEC3F &aSelColor, const SFVEC3F *aCameraWorldPos)
int GetWaitForEditingTimeOut() override
Give the interface the time (in ms) that it should wait for editing or movements before (this works f...
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_antiBoard
std::map< wxString, std::shared_ptr< MODEL_3D_DEFERRED > > m_3dModelMap
void renderSolderMaskLayer(PCB_LAYER_ID aLayerID, float aZPos, bool aShowThickness, bool aSkipRenderHoles)
void renderTransparentModels(const glm::mat4 &aCameraViewMatrix)
void get3dModelsSelected(std::list< MODELTORENDER > &aDstRenderList, bool aGetTop, bool aGetBot, bool aRenderTransparentOnly, bool aRenderSelectedOnly)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_frontOuterThroughHoles
void releaseRetiredRenderPtrs()
void setPlatedCopperAndDepthOffset(PCB_LAYER_ID aLayer_id)
void updateGizmoSelection(glm::mat4 aCameraRotationMatrix)
std::map< const FOOTPRINT *, std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > > m_extrudedPadLists
void SetCurWindowSize(const wxSize &aSize) override
Before each render, the canvas will tell the render what is the size of its windows,...
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_padHoles
void renderPlaceholderForFootprint(std::list< MODELTORENDER > &aDstRenderList, const glm::mat4 &aFpMatrix, const FOOTPRINT *aFootprint, bool aRenderTransparentOnly, bool aIsSelected, float aOpacity)
std::vector< std::shared_ptr< void > > m_retiredRenderPtrs
SPHERES_GIZMO * m_spheres_gizmo
GLuint m_grid
oGL list that stores current grid
std::map< const FOOTPRINT *, std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > > m_extrudedPegLists
void get3dModelsFromFootprint(std::list< MODELTORENDER > &aDstRenderList, const FOOTPRINT *aFootprint, bool aRenderTransparentOnly, bool aIsSelected)
void handleGizmoMouseInput(int mouseX, int mouseY)
void setLightBottom(bool enabled)
void setGizmoViewport(int x, int y, int width, int height)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_outerThroughHoleRings
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_viaBackCover
void setLightTop(bool enabled)
Renders a set of colored spheres in 3D space that act as a directional orientation gizmo.
GizmoSphereSelection
Enum to indicate which sphere (direction) is selected.
#define DELETE_AND_FREE_MAP(map)
#define DELETE_AND_FREE(ptr)
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
int MapPCBLayerTo3DLayer(PCB_LAYER_ID aLayer)
@ LAYER_3D_SOLDERMASK_TOP
@ LAYER_3D_SOLDERMASK_BOTTOM
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
PCB_LAYER_ID
A quick note on layer IDs:
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
void OglResetTextureState()
Reset to default state the texture settings.
void OglSetMaterial(const SMATERIAL &aMaterial, float aOpacity, bool aUseSelectedMaterial, SFVEC3F aSelectionColor)
Set OpenGL materials.
GLuint OglLoadTexture(const IMAGE &aImage)
Generate a new OpenGL texture.
void OglDrawBackground(const SFVEC4F &aTopColor, const SFVEC4F &aBotColor)
Define generic OpenGL functions that are common to any OpenGL target.
PGM_BASE & Pgm()
The global program "get" accessor.
static SFVEC4F premultiplyAlpha(const SFVEC4F &aInput)
#define SIZE_OF_CIRCLE_TEXTURE
Manage a bounding box defined by two SFVEC3F min max points.
SFVEC3F GetCenter() const
Return the center point of the bounding box.
bool opengl_thickness_disableOnMove
KIGFX::COLOR4D opengl_selection_color
bool clip_silk_on_via_annuli
bool subtract_mask_from_silk
bool opengl_microvias_disableOnMove
bool highlight_on_rollover
bool DifferentiatePlatedCopper()
return true if platted copper aeras and non platted copper areas must be drawn using a different colo...
bool opengl_holes_disableOnMove
bool opengl_AA_disableOnMove
glm::mat4 m_modelWorldMat
std::shared_ptr< MODEL_3D > m_model
Store the a model based on meshes and materials.
float m_Transparency
1.0 is completely transparent, 0.0 completely opaque
SFVEC3F m_Diffuse
Default diffuse color if m_Color is NULL.
Per-vertex normal/color/texcoors structure.
VECTOR2< int32_t > VECTOR2I