2015-12-08 07:31:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-04-25 14:38:41 +00:00
|
|
|
* Copyright (C) 2015-2020 Mario Luzeiro <mrluzeiro@ua.pt>
|
2021-05-22 18:23:43 +00:00
|
|
|
* Copyright (C) 2015-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-12-08 07:31:57 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2020-11-10 23:24:01 +00:00
|
|
|
#include <gal/opengl/kiglew.h> // Must be included first
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
#include "render_3d_opengl.h"
|
|
|
|
#include "opengl_utils.h"
|
2015-12-08 07:31:57 +00:00
|
|
|
#include "common_ogl/ogl_utils.h"
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2016-07-19 17:35:25 +00:00
|
|
|
#include <3d_math.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
#include <base_units.h>
|
|
|
|
|
|
|
|
/**
|
2020-12-13 23:02:57 +00:00
|
|
|
* Scale conversion from 3d model units to pcb units
|
|
|
|
*/
|
2016-07-19 17:35:25 +00:00
|
|
|
#define UNITS3D_TO_UNITSPCB (IU_PER_MM)
|
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
RENDER_3D_OPENGL::RENDER_3D_OPENGL( EDA_3D_CANVAS* aCanvas, BOARD_ADAPTER& aAdapter,
|
|
|
|
CAMERA& aCamera ) :
|
2021-08-16 14:28:46 +00:00
|
|
|
RENDER_3D_BASE( aCanvas, aAdapter, aCamera )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2021-10-21 13:29:19 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "RENDER_3D_OPENGL::RENDER_3D_OPENGL" ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
m_layers.clear();
|
2021-01-05 22:19:00 +00:00
|
|
|
m_outerLayerHoles.clear();
|
|
|
|
m_innerLayerHoles.clear();
|
2015-12-08 07:31:57 +00:00
|
|
|
m_triangles.clear();
|
2021-01-02 21:05:29 +00:00
|
|
|
m_board = nullptr;
|
2021-01-05 22:19:00 +00:00
|
|
|
m_antiBoard = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_platedPadsFront = nullptr;
|
|
|
|
m_platedPadsBack = nullptr;
|
2020-09-06 19:09:43 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_outerThroughHoles = nullptr;
|
|
|
|
m_outerThroughHoleRings = nullptr;
|
|
|
|
m_outerViaThroughHoles = nullptr;
|
2021-01-02 21:05:29 +00:00
|
|
|
m_vias = nullptr;
|
2021-01-05 22:19:00 +00:00
|
|
|
m_padHoles = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_circleTexture = 0;
|
2020-11-30 01:07:49 +00:00
|
|
|
m_grid = 0;
|
2021-01-05 22:19:00 +00:00
|
|
|
m_lastGridType = GRID3D_TYPE::NONE;
|
2021-05-11 19:52:28 +00:00
|
|
|
m_currentRollOverItem = nullptr;
|
2021-01-05 22:19:00 +00:00
|
|
|
m_boardWithHoles = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_3dModelMap.clear();
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
RENDER_3D_OPENGL::~RENDER_3D_OPENGL()
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2021-10-21 13:29:19 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "RENDER_3D_OPENGL::RENDER_3D_OPENGL" ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
freeAllLists();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
glDeleteTextures( 1, &m_circleTexture );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
int RENDER_3D_OPENGL::GetWaitForEditingTimeOut()
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
return 50; // ms
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::SetCurWindowSize( const wxSize& aSize )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
if( m_windowSize != aSize )
|
|
|
|
{
|
|
|
|
m_windowSize = aSize;
|
|
|
|
glViewport( 0, 0, m_windowSize.x, m_windowSize.y );
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Initialize here any screen dependent data here
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::setLightFront( bool enabled )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( enabled )
|
|
|
|
glEnable( GL_LIGHT0 );
|
|
|
|
else
|
|
|
|
glDisable( GL_LIGHT0 );
|
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::setLightTop( bool enabled )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( enabled )
|
|
|
|
glEnable( GL_LIGHT1 );
|
|
|
|
else
|
|
|
|
glDisable( GL_LIGHT1 );
|
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::setLightBottom( bool enabled )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( enabled )
|
|
|
|
glEnable( GL_LIGHT2 );
|
|
|
|
else
|
|
|
|
glDisable( GL_LIGHT2 );
|
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::render3dArrows()
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
const float arrow_size = RANGE_SCALE_3D * 0.30f;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
glDisable( GL_CULL_FACE );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// YxY squared view port, this is on propose
|
|
|
|
glViewport( 4, 4, m_windowSize.y / 8 , m_windowSize.y / 8 );
|
|
|
|
glClear( GL_DEPTH_BUFFER_BIT );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
glMatrixMode( GL_PROJECTION );
|
|
|
|
glLoadIdentity();
|
|
|
|
gluPerspective( 45.0f, 1.0f, 0.001f, RANGE_SCALE_3D );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
glMatrixMode( GL_MODELVIEW );
|
|
|
|
glLoadIdentity();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
const glm::mat4 TranslationMatrix =
|
|
|
|
glm::translate( glm::mat4( 1.0f ), SFVEC3F( 0.0f, 0.0f, -( arrow_size * 2.75f ) ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-03-26 14:05:20 +00:00
|
|
|
const glm::mat4 ViewMatrix = TranslationMatrix * m_camera.GetRotationMatrix();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
glLoadMatrixf( glm::value_ptr( ViewMatrix ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
setArrowMaterial();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
glColor3f( 0.9f, 0.0f, 0.0f );
|
2021-01-02 21:05:29 +00:00
|
|
|
DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( arrow_size, 0.0f, 0.0f ), 0.275f );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
glColor3f( 0.0f, 0.9f, 0.0f );
|
2021-01-02 21:05:29 +00:00
|
|
|
DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.0f, arrow_size, 0.0f ), 0.275f );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
glColor3f( 0.0f, 0.0f, 0.9f );
|
2021-01-02 21:05:29 +00:00
|
|
|
DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.0f, 0.0f, arrow_size ), 0.275f );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
glEnable( GL_CULL_FACE );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::setupMaterials()
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2018-11-09 11:58:38 +00:00
|
|
|
m_materials = {};
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.realistic )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// http://devernay.free.fr/cours/opengl/materials.html
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-09-06 19:09:43 +00:00
|
|
|
// Plated copper
|
2016-07-19 17:35:25 +00:00
|
|
|
// Copper material mixed with the copper color
|
2020-03-26 14:05:20 +00:00
|
|
|
m_materials.m_Copper.m_Ambient = SFVEC3F( m_boardAdapter.m_CopperColor.r * 0.1f,
|
|
|
|
m_boardAdapter.m_CopperColor.g * 0.1f,
|
|
|
|
m_boardAdapter.m_CopperColor.b * 0.1f);
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-03-26 14:05:20 +00:00
|
|
|
m_materials.m_Copper.m_Specular = SFVEC3F( m_boardAdapter.m_CopperColor.r * 0.75f + 0.25f,
|
|
|
|
m_boardAdapter.m_CopperColor.g * 0.75f + 0.25f,
|
|
|
|
m_boardAdapter.m_CopperColor.b * 0.75f + 0.25f );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// This guess the material type(ex: copper vs gold) to determine the
|
|
|
|
// shininess factor between 0.1 and 0.4
|
2020-03-26 14:05:20 +00:00
|
|
|
float shininessfactor = 0.40f - mapf( fabs( m_boardAdapter.m_CopperColor.r -
|
|
|
|
m_boardAdapter.m_CopperColor.g ),
|
2016-07-19 17:35:25 +00:00
|
|
|
0.15f, 1.00f,
|
|
|
|
0.00f, 0.30f );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
m_materials.m_Copper.m_Shininess = shininessfactor * 128.0f;
|
2019-09-10 15:34:48 +00:00
|
|
|
m_materials.m_Copper.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
2020-09-06 19:09:43 +00:00
|
|
|
// Non plated copper (raw copper)
|
|
|
|
m_materials.m_NonPlatedCopper.m_Ambient = SFVEC3F( 0.191f, 0.073f, 0.022f );
|
2020-12-13 23:02:57 +00:00
|
|
|
m_materials.m_NonPlatedCopper.m_Diffuse = SFVEC3F( 184.0f / 255.0f, 115.0f / 255.0f,
|
|
|
|
50.0f / 255.0f );
|
2020-09-06 19:09:43 +00:00
|
|
|
m_materials.m_NonPlatedCopper.m_Specular = SFVEC3F( 0.256f, 0.137f, 0.086f );
|
|
|
|
m_materials.m_NonPlatedCopper.m_Shininess = 0.1f * 128.0f;
|
|
|
|
m_materials.m_NonPlatedCopper.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Paste material mixed with paste color
|
2020-03-26 14:05:20 +00:00
|
|
|
m_materials.m_Paste.m_Ambient = SFVEC3F( m_boardAdapter.m_SolderPasteColor.r,
|
|
|
|
m_boardAdapter.m_SolderPasteColor.g,
|
|
|
|
m_boardAdapter.m_SolderPasteColor.b );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-03-26 14:05:20 +00:00
|
|
|
m_materials.m_Paste.m_Specular = SFVEC3F( m_boardAdapter.m_SolderPasteColor.r *
|
|
|
|
m_boardAdapter.m_SolderPasteColor.r,
|
|
|
|
m_boardAdapter.m_SolderPasteColor.g *
|
|
|
|
m_boardAdapter.m_SolderPasteColor.g,
|
|
|
|
m_boardAdapter.m_SolderPasteColor.b *
|
|
|
|
m_boardAdapter.m_SolderPasteColor.b );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
m_materials.m_Paste.m_Shininess = 0.1f * 128.0f;
|
2019-09-10 15:34:48 +00:00
|
|
|
m_materials.m_Paste.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Silk screen material mixed with silk screen color
|
2020-03-26 14:05:20 +00:00
|
|
|
m_materials.m_SilkSTop.m_Ambient = SFVEC3F( m_boardAdapter.m_SilkScreenColorTop.r,
|
|
|
|
m_boardAdapter.m_SilkScreenColorTop.g,
|
|
|
|
m_boardAdapter.m_SilkScreenColorTop.b );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-01-22 22:38:30 +00:00
|
|
|
m_materials.m_SilkSTop.m_Specular = SFVEC3F(
|
2021-01-02 21:05:29 +00:00
|
|
|
m_boardAdapter.m_SilkScreenColorTop.r * m_boardAdapter.m_SilkScreenColorTop.r +
|
|
|
|
0.10f,
|
|
|
|
m_boardAdapter.m_SilkScreenColorTop.g * m_boardAdapter.m_SilkScreenColorTop.g +
|
|
|
|
0.10f,
|
|
|
|
m_boardAdapter.m_SilkScreenColorTop.b * m_boardAdapter.m_SilkScreenColorTop.b +
|
|
|
|
0.10f );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-01-22 22:38:30 +00:00
|
|
|
m_materials.m_SilkSTop.m_Shininess = 0.078125f * 128.0f;
|
|
|
|
m_materials.m_SilkSTop.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
|
|
|
|
|
|
|
// Silk screen material mixed with silk screen color
|
2020-03-26 14:05:20 +00:00
|
|
|
m_materials.m_SilkSBot.m_Ambient = SFVEC3F( m_boardAdapter.m_SilkScreenColorBot.r,
|
|
|
|
m_boardAdapter.m_SilkScreenColorBot.g,
|
|
|
|
m_boardAdapter.m_SilkScreenColorBot.b );
|
2020-01-22 22:38:30 +00:00
|
|
|
|
|
|
|
m_materials.m_SilkSBot.m_Specular = SFVEC3F(
|
2021-01-02 21:05:29 +00:00
|
|
|
m_boardAdapter.m_SilkScreenColorBot.r * m_boardAdapter.m_SilkScreenColorBot.r +
|
|
|
|
0.10f,
|
|
|
|
m_boardAdapter.m_SilkScreenColorBot.g * m_boardAdapter.m_SilkScreenColorBot.g +
|
|
|
|
0.10f,
|
|
|
|
m_boardAdapter.m_SilkScreenColorBot.b * m_boardAdapter.m_SilkScreenColorBot.b +
|
|
|
|
0.10f );
|
2020-01-22 22:38:30 +00:00
|
|
|
|
|
|
|
m_materials.m_SilkSBot.m_Shininess = 0.078125f * 128.0f;
|
|
|
|
m_materials.m_SilkSBot.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-08-21 08:56:15 +00:00
|
|
|
m_materials.m_SolderMask.m_Shininess = 0.8f * 128.0f;
|
|
|
|
m_materials.m_SolderMask.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Epoxy material
|
2021-01-02 21:05:29 +00:00
|
|
|
m_materials.m_EpoxyBoard.m_Ambient = SFVEC3F( 117.0f / 255.0f, 97.0f / 255.0f,
|
2016-07-19 17:35:25 +00:00
|
|
|
47.0f / 255.0f );
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
m_materials.m_EpoxyBoard.m_Specular = SFVEC3F( 18.0f / 255.0f, 3.0f / 255.0f,
|
2016-07-19 17:35:25 +00:00
|
|
|
20.0f / 255.0f );
|
|
|
|
|
|
|
|
m_materials.m_EpoxyBoard.m_Shininess = 0.1f * 128.0f;
|
2019-09-10 15:34:48 +00:00
|
|
|
m_materials.m_EpoxyBoard.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
else // Technical Mode
|
|
|
|
{
|
|
|
|
const SFVEC3F matAmbientColor = SFVEC3F( 0.10f );
|
|
|
|
const SFVEC3F matSpecularColor = SFVEC3F( 0.10f );
|
|
|
|
const float matShininess = 0.1f * 128.0f;
|
|
|
|
|
|
|
|
// Copper material
|
|
|
|
m_materials.m_Copper.m_Ambient = matAmbientColor;
|
|
|
|
m_materials.m_Copper.m_Specular = matSpecularColor;
|
|
|
|
m_materials.m_Copper.m_Shininess = matShininess;
|
2019-09-10 15:34:48 +00:00
|
|
|
m_materials.m_Copper.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Paste material
|
|
|
|
m_materials.m_Paste.m_Ambient = matAmbientColor;
|
|
|
|
m_materials.m_Paste.m_Specular = matSpecularColor;
|
|
|
|
m_materials.m_Paste.m_Shininess = matShininess;
|
2019-09-10 15:34:48 +00:00
|
|
|
m_materials.m_Paste.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Silk screen material
|
2020-01-22 22:38:30 +00:00
|
|
|
m_materials.m_SilkSTop.m_Ambient = matAmbientColor;
|
|
|
|
m_materials.m_SilkSTop.m_Specular = matSpecularColor;
|
|
|
|
m_materials.m_SilkSTop.m_Shininess = matShininess;
|
|
|
|
m_materials.m_SilkSTop.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
|
|
|
|
|
|
|
// Silk screen material
|
|
|
|
m_materials.m_SilkSBot.m_Ambient = matAmbientColor;
|
|
|
|
m_materials.m_SilkSBot.m_Specular = matSpecularColor;
|
|
|
|
m_materials.m_SilkSBot.m_Shininess = matShininess;
|
|
|
|
m_materials.m_SilkSBot.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Solder mask material
|
2020-08-21 08:56:15 +00:00
|
|
|
m_materials.m_SolderMask.m_Ambient = matAmbientColor;
|
|
|
|
m_materials.m_SolderMask.m_Specular = matSpecularColor;
|
|
|
|
m_materials.m_SolderMask.m_Shininess = matShininess;
|
|
|
|
m_materials.m_SolderMask.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Epoxy material
|
|
|
|
m_materials.m_EpoxyBoard.m_Ambient = matAmbientColor;
|
|
|
|
m_materials.m_EpoxyBoard.m_Specular = matSpecularColor;
|
|
|
|
m_materials.m_EpoxyBoard.m_Shininess = matShininess;
|
2019-09-10 15:34:48 +00:00
|
|
|
m_materials.m_EpoxyBoard.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Gray material (used for example in technical vias and pad holes)
|
|
|
|
m_materials.m_GrayMaterial.m_Ambient = SFVEC3F( 0.8f, 0.8f, 0.8f );
|
|
|
|
m_materials.m_GrayMaterial.m_Diffuse = SFVEC3F( 0.3f, 0.3f, 0.3f );
|
|
|
|
m_materials.m_GrayMaterial.m_Specular = SFVEC3F( 0.4f, 0.4f, 0.4f );
|
|
|
|
m_materials.m_GrayMaterial.m_Shininess = 0.01f * 128.0f;
|
2019-09-10 15:34:48 +00:00
|
|
|
m_materials.m_GrayMaterial.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::setLayerMaterial( PCB_LAYER_ID aLayerID )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
switch( aLayerID )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2020-12-13 23:02:57 +00:00
|
|
|
case F_Mask:
|
|
|
|
case B_Mask:
|
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
const SFVEC4F layerColor = getLayerColor( aLayerID );
|
2020-12-13 23:02:57 +00:00
|
|
|
|
|
|
|
m_materials.m_SolderMask.m_Diffuse = layerColor;
|
|
|
|
|
|
|
|
// Convert Opacity to Transparency
|
|
|
|
m_materials.m_SolderMask.m_Transparency = 1.0f - layerColor.a;
|
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.realistic )
|
2020-08-21 08:56:15 +00:00
|
|
|
{
|
2020-12-13 23:02:57 +00:00
|
|
|
m_materials.m_SolderMask.m_Ambient = m_materials.m_SolderMask.m_Diffuse * 0.3f;
|
2020-08-21 08:56:15 +00:00
|
|
|
|
2020-12-13 23:02:57 +00:00
|
|
|
m_materials.m_SolderMask.m_Specular =
|
|
|
|
m_materials.m_SolderMask.m_Diffuse * m_materials.m_SolderMask.m_Diffuse;
|
|
|
|
}
|
2020-08-21 08:56:15 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
OglSetMaterial( m_materials.m_SolderMask, 1.0f );
|
2020-12-13 23:02:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-08-21 08:56:15 +00:00
|
|
|
|
2020-12-13 23:02:57 +00:00
|
|
|
case B_Paste:
|
|
|
|
case F_Paste:
|
2021-01-05 22:19:00 +00:00
|
|
|
m_materials.m_Paste.m_Diffuse = getLayerColor( aLayerID );
|
2021-01-07 19:33:43 +00:00
|
|
|
OglSetMaterial( m_materials.m_Paste, 1.0f );
|
2020-12-13 23:02:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case B_SilkS:
|
2021-01-05 22:19:00 +00:00
|
|
|
m_materials.m_SilkSBot.m_Diffuse = getLayerColor( aLayerID );
|
2021-01-07 19:33:43 +00:00
|
|
|
OglSetMaterial( m_materials.m_SilkSBot, 1.0f );
|
2020-12-13 23:02:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case F_SilkS:
|
2021-01-05 22:19:00 +00:00
|
|
|
m_materials.m_SilkSTop.m_Diffuse = getLayerColor( aLayerID );
|
2021-01-07 19:33:43 +00:00
|
|
|
OglSetMaterial( m_materials.m_SilkSTop, 1.0f );
|
2020-12-13 23:02:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case B_Adhes:
|
|
|
|
case F_Adhes:
|
|
|
|
case Dwgs_User:
|
|
|
|
case Cmts_User:
|
|
|
|
case Eco1_User:
|
|
|
|
case Eco2_User:
|
|
|
|
case Edge_Cuts:
|
|
|
|
case Margin:
|
|
|
|
case B_CrtYd:
|
|
|
|
case F_CrtYd:
|
|
|
|
case B_Fab:
|
|
|
|
case F_Fab:
|
2021-01-05 22:19:00 +00:00
|
|
|
m_materials.m_Plastic.m_Diffuse = getLayerColor( aLayerID );
|
2020-12-13 23:02:57 +00:00
|
|
|
|
|
|
|
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_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_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
2021-01-07 19:33:43 +00:00
|
|
|
OglSetMaterial( m_materials.m_Plastic, 1.0f );
|
2020-12-13 23:02:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-01-05 22:19:00 +00:00
|
|
|
m_materials.m_Copper.m_Diffuse = getLayerColor( aLayerID );
|
2021-01-07 19:33:43 +00:00
|
|
|
OglSetMaterial( m_materials.m_Copper, 1.0f );
|
2020-12-13 23:02:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-08-21 08:56:15 +00:00
|
|
|
|
2020-12-13 23:02:57 +00:00
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
SFVEC4F RENDER_3D_OPENGL::getLayerColor( PCB_LAYER_ID aLayerID )
|
2020-12-13 23:02:57 +00:00
|
|
|
{
|
|
|
|
SFVEC4F layerColor = m_boardAdapter.GetLayerColor( aLayerID );
|
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.realistic )
|
2020-12-13 23:02:57 +00:00
|
|
|
{
|
|
|
|
switch( aLayerID )
|
|
|
|
{
|
|
|
|
case B_Adhes:
|
|
|
|
case F_Adhes:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case B_Mask:
|
|
|
|
layerColor = m_boardAdapter.m_SolderMaskColorBot;
|
|
|
|
break;
|
|
|
|
case F_Mask:
|
|
|
|
layerColor = m_boardAdapter.m_SolderMaskColorTop;
|
2020-01-22 22:38:30 +00:00
|
|
|
break;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
case B_Paste:
|
|
|
|
case F_Paste:
|
2020-12-13 23:02:57 +00:00
|
|
|
layerColor = m_boardAdapter.m_SolderPasteColor;
|
2020-03-23 15:17:22 +00:00
|
|
|
break;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
case B_SilkS:
|
2020-12-13 23:02:57 +00:00
|
|
|
layerColor = m_boardAdapter.m_SilkScreenColorBot;
|
2020-03-23 15:17:22 +00:00
|
|
|
break;
|
2016-07-19 17:35:25 +00:00
|
|
|
case F_SilkS:
|
2020-12-13 23:02:57 +00:00
|
|
|
layerColor = m_boardAdapter.m_SilkScreenColorTop;
|
2020-01-22 22:38:30 +00:00
|
|
|
break;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
case Dwgs_User:
|
|
|
|
case Cmts_User:
|
|
|
|
case Eco1_User:
|
|
|
|
case Eco2_User:
|
|
|
|
case Edge_Cuts:
|
|
|
|
case Margin:
|
2020-12-13 23:02:57 +00:00
|
|
|
break;
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
case B_CrtYd:
|
|
|
|
case F_CrtYd:
|
2020-12-13 23:02:57 +00:00
|
|
|
break;
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
case B_Fab:
|
|
|
|
case F_Fab:
|
2020-12-13 23:02:57 +00:00
|
|
|
break;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
default:
|
2020-12-13 23:02:57 +00:00
|
|
|
layerColor = m_boardAdapter.m_CopperColor;
|
|
|
|
break;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
return layerColor;
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 13:50:16 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void init_lights( void )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// Setup light
|
|
|
|
// https://www.opengl.org/sdk/docs/man2/xhtml/glLight.xml
|
|
|
|
const GLfloat ambient[] = { 0.084f, 0.084f, 0.084f, 1.0f };
|
|
|
|
const GLfloat diffuse0[] = { 0.3f, 0.3f, 0.3f, 1.0f };
|
|
|
|
const GLfloat specular0[] = { 0.5f, 0.5f, 0.5f, 1.0f };
|
|
|
|
|
|
|
|
glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
|
|
|
|
glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse0 );
|
|
|
|
glLightfv( GL_LIGHT0, GL_SPECULAR, specular0 );
|
|
|
|
|
|
|
|
const GLfloat diffuse12[] = { 0.7f, 0.7f, 0.7f, 1.0f };
|
|
|
|
const GLfloat specular12[] = { 0.7f, 0.7f, 0.7f, 1.0f };
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// defines a directional light that points along the negative z-axis
|
|
|
|
GLfloat position[4] = { 0.0f, 0.0f, 1.0f, 0.0f };
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// This makes a vector slight not perpendicular with XZ plane
|
|
|
|
const SFVEC3F vectorLight = SphericalToCartesian( glm::pi<float>() * 0.03f,
|
|
|
|
glm::pi<float>() * 0.25f );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
position[0] = vectorLight.x;
|
|
|
|
position[1] = vectorLight.y;
|
|
|
|
position[2] = vectorLight.z;
|
|
|
|
|
|
|
|
glLightfv( GL_LIGHT1, GL_AMBIENT, ambient );
|
|
|
|
glLightfv( GL_LIGHT1, GL_DIFFUSE, diffuse12 );
|
|
|
|
glLightfv( GL_LIGHT1, GL_SPECULAR, specular12 );
|
|
|
|
glLightfv( GL_LIGHT1, GL_POSITION, position );
|
|
|
|
|
|
|
|
// defines a directional light that points along the positive z-axis
|
|
|
|
position[2] = -position[2];
|
2016-05-11 03:25:53 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
glLightfv( GL_LIGHT2, GL_AMBIENT, ambient );
|
|
|
|
glLightfv( GL_LIGHT2, GL_DIFFUSE, diffuse12 );
|
|
|
|
glLightfv( GL_LIGHT2, GL_SPECULAR, specular12 );
|
|
|
|
glLightfv( GL_LIGHT2, GL_POSITION, position );
|
|
|
|
|
|
|
|
const GLfloat lmodel_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
|
|
|
|
|
|
|
glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmodel_ambient );
|
|
|
|
|
|
|
|
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
|
|
|
|
}
|
|
|
|
|
2020-11-10 13:50:16 +00:00
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::setCopperMaterial()
|
2020-09-06 19:09:43 +00:00
|
|
|
{
|
2021-01-07 19:33:43 +00:00
|
|
|
OglSetMaterial( m_materials.m_NonPlatedCopper, 1.0f );
|
2020-09-06 19:09:43 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 13:50:16 +00:00
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::setPlatedCopperAndDepthOffset( PCB_LAYER_ID aLayer_id )
|
2020-09-06 19:09:43 +00:00
|
|
|
{
|
|
|
|
glEnable( GL_POLYGON_OFFSET_FILL );
|
2022-03-06 13:35:46 +00:00
|
|
|
glPolygonOffset( -0.1f, -2.0f );
|
2021-01-05 22:19:00 +00:00
|
|
|
setLayerMaterial( aLayer_id );
|
2020-09-06 19:09:43 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 13:50:16 +00:00
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::unsetDepthOffset()
|
2020-09-06 19:09:43 +00:00
|
|
|
{
|
|
|
|
glDisable( GL_POLYGON_OFFSET_FILL );
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-10 13:50:16 +00:00
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::renderBoardBody( bool aSkipRenderHoles )
|
2020-08-25 20:33:51 +00:00
|
|
|
{
|
2020-11-03 09:38:07 +00:00
|
|
|
m_materials.m_EpoxyBoard.m_Diffuse = m_boardAdapter.m_BoardBodyColor;
|
2020-12-13 23:02:57 +00:00
|
|
|
|
|
|
|
// opacity to transparency
|
|
|
|
m_materials.m_EpoxyBoard.m_Transparency = 1.0f - m_boardAdapter.m_BoardBodyColor.a;
|
2020-08-25 20:33:51 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
OglSetMaterial( m_materials.m_EpoxyBoard, 1.0f );
|
2020-08-25 20:33:51 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
OPENGL_RENDER_LIST* ogl_disp_list = nullptr;
|
2020-08-25 20:33:51 +00:00
|
|
|
|
2020-11-03 09:38:07 +00:00
|
|
|
if( aSkipRenderHoles )
|
2020-11-30 01:07:49 +00:00
|
|
|
ogl_disp_list = m_board;
|
2020-11-03 09:38:07 +00:00
|
|
|
else
|
2021-01-05 22:19:00 +00:00
|
|
|
ogl_disp_list = m_boardWithHoles;
|
2020-08-25 20:33:51 +00:00
|
|
|
|
2020-11-03 09:38:07 +00:00
|
|
|
if( ogl_disp_list )
|
|
|
|
{
|
2021-12-03 14:14:50 +00:00
|
|
|
ogl_disp_list->ApplyScalePosition( -m_boardAdapter.GetBoardBodyThickness() / 2.0f,
|
|
|
|
m_boardAdapter.GetBoardBodyThickness() );
|
2020-08-25 20:33:51 +00:00
|
|
|
|
2020-11-03 09:38:07 +00:00
|
|
|
ogl_disp_list->SetItIsTransparent( true );
|
2020-08-25 20:33:51 +00:00
|
|
|
|
2020-11-03 09:38:07 +00:00
|
|
|
ogl_disp_list->DrawAll();
|
2020-08-25 20:33:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-10 13:50:16 +00:00
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
|
2021-01-02 21:05:29 +00:00
|
|
|
REPORTER* aWarningReporter )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-11-10 13:50:16 +00:00
|
|
|
// Initialize OpenGL
|
2015-12-08 07:31:57 +00:00
|
|
|
if( !m_is_opengl_initialized )
|
|
|
|
{
|
|
|
|
if( !initializeOpenGL() )
|
2016-07-19 17:35:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( m_reloadRequested )
|
|
|
|
{
|
2019-05-12 13:08:30 +00:00
|
|
|
std::unique_ptr<BUSY_INDICATOR> busy = CreateBusyIndicator();
|
2017-12-28 10:01:10 +00:00
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
if( aStatusReporter )
|
|
|
|
aStatusReporter->Report( _( "Loading..." ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
reload( aStatusReporter, aWarningReporter );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// generate a new 3D grid as the size of the board may had changed
|
2021-08-30 20:30:18 +00:00
|
|
|
m_lastGridType = static_cast<GRID3D_TYPE>( m_boardAdapter.m_Cfg->m_Render.grid_type );
|
2021-01-05 22:19:00 +00:00
|
|
|
generate3dGrid( m_lastGridType );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Check if grid was changed
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.grid_type != m_lastGridType )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// and generate a new one
|
2021-08-30 20:30:18 +00:00
|
|
|
m_lastGridType = static_cast<GRID3D_TYPE>( m_boardAdapter.m_Cfg->m_Render.grid_type );
|
2021-01-05 22:19:00 +00:00
|
|
|
generate3dGrid( m_lastGridType );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 08:37:00 +00:00
|
|
|
setupMaterials();
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Initial setup
|
|
|
|
glDepthFunc( GL_LESS );
|
|
|
|
glEnable( GL_CULL_FACE );
|
2020-11-10 13:50:16 +00:00
|
|
|
glFrontFace( GL_CCW ); // This is the OpenGL default
|
|
|
|
glEnable( GL_NORMALIZE ); // This allow OpenGL to normalize the normals after transformations
|
2016-07-19 17:35:25 +00:00
|
|
|
glViewport( 0, 0, m_windowSize.x, m_windowSize.y );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( aIsMoving && m_boardAdapter.m_Cfg->m_Render.opengl_AA_disableOnMove )
|
2020-11-04 10:11:29 +00:00
|
|
|
glDisable( GL_MULTISAMPLE );
|
|
|
|
else
|
|
|
|
glEnable( GL_MULTISAMPLE );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
// clear color and depth buffers
|
|
|
|
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
|
|
|
|
glClearDepth( 1.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
glClearStencil( 0x00 );
|
2015-12-08 07:31:57 +00:00
|
|
|
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
OglResetTextureState();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Draw the background ( rectangle with color gradient)
|
2021-01-07 19:33:43 +00:00
|
|
|
OglDrawBackground( SFVEC3F( m_boardAdapter.m_BgColorTop ),
|
|
|
|
SFVEC3F( m_boardAdapter.m_BgColorBot ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
glEnable( GL_DEPTH_TEST );
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
// Set projection and modelview matrixes
|
|
|
|
glMatrixMode( GL_PROJECTION );
|
2020-03-26 14:05:20 +00:00
|
|
|
glLoadMatrixf( glm::value_ptr( m_camera.GetProjectionMatrix() ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
glMatrixMode( GL_MODELVIEW );
|
|
|
|
glLoadIdentity();
|
2020-03-26 14:05:20 +00:00
|
|
|
glLoadMatrixf( glm::value_ptr( m_camera.GetViewMatrix() ) );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Position the headlight
|
2021-01-05 22:19:00 +00:00
|
|
|
setLightFront( true );
|
|
|
|
setLightTop( true );
|
|
|
|
setLightBottom( true );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
glEnable( GL_LIGHTING );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
const SFVEC3F& cameraPos = m_camera.GetPos();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-10 13:50:16 +00:00
|
|
|
// Place the light at a minimum Z so the diffuse factor will not drop
|
2016-07-19 17:35:25 +00:00
|
|
|
// and the board will still look with good light.
|
|
|
|
float zpos;
|
|
|
|
|
|
|
|
if( cameraPos.z > 0.0f )
|
|
|
|
zpos = glm::max( cameraPos.z, 0.5f ) + cameraPos.z * cameraPos.z;
|
|
|
|
else
|
|
|
|
zpos = glm::min( cameraPos.z,-0.5f ) - cameraPos.z * cameraPos.z;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
// This is a point light.
|
|
|
|
const GLfloat headlight_pos[] = { cameraPos.x, cameraPos.y, zpos, 1.0f };
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
glLightfv( GL_LIGHT0, GL_POSITION, headlight_pos );
|
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
bool skipThickness = aIsMoving && m_boardAdapter.m_Cfg->m_Render.opengl_thickness_disableOnMove;
|
|
|
|
bool skipRenderHoles = aIsMoving && m_boardAdapter.m_Cfg->m_Render.opengl_holes_disableOnMove;
|
|
|
|
bool skipRenderVias = aIsMoving && m_boardAdapter.m_Cfg->m_Render.opengl_vias_disableOnMove;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
bool drawMiddleSegments = !skipThickness;
|
2020-04-23 16:28:56 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.realistic )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// Draw vias and pad holes with copper material
|
2021-01-05 22:19:00 +00:00
|
|
|
setLayerMaterial( B_Cu );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-07 19:33:43 +00:00
|
|
|
OglSetMaterial( m_materials.m_GrayMaterial, 1.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
if( !( skipRenderVias || skipRenderHoles ) && m_vias )
|
|
|
|
m_vias->DrawAll();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
if( !skipRenderHoles && m_padHoles )
|
|
|
|
m_padHoles->DrawAll();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Display copper and tech layers
|
2020-12-04 15:35:57 +00:00
|
|
|
for( MAP_OGL_DISP_LISTS::const_iterator ii = m_layers.begin(); ii != m_layers.end(); ++ii )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2020-12-13 23:02:57 +00:00
|
|
|
const PCB_LAYER_ID layer_id = ( PCB_LAYER_ID )( ii->first );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-08-25 20:33:51 +00:00
|
|
|
// Mask layers are not processed here because they are a special case
|
2021-01-07 19:33:43 +00:00
|
|
|
if( ( layer_id == B_Mask ) || ( layer_id == F_Mask ) )
|
2015-12-08 07:31:57 +00:00
|
|
|
continue;
|
|
|
|
|
2021-08-25 16:33:49 +00:00
|
|
|
// Do not show inner layers when it is displaying the board and board body is opaque
|
|
|
|
// enough: the time to create inner layers can be *really significant*.
|
|
|
|
// So avoid creating them is they are not very visible
|
|
|
|
const double opacity_min = 0.8;
|
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.show_board_body
|
|
|
|
&& m_boardAdapter.m_BoardBodyColor.a > opacity_min )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-12-13 23:02:57 +00:00
|
|
|
if( ( layer_id > F_Cu ) && ( layer_id < B_Cu ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
OPENGL_RENDER_LIST* pLayerDispList = static_cast<OPENGL_RENDER_LIST*>( ii->second );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( ( layer_id >= F_Cu ) && ( layer_id <= B_Cu ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.renderPlatedPadsAsPlated
|
|
|
|
&& m_boardAdapter.m_Cfg->m_Render.realistic )
|
|
|
|
{
|
2020-09-27 09:28:05 +00:00
|
|
|
setCopperMaterial();
|
2021-08-30 20:30:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setLayerMaterial( layer_id );
|
|
|
|
}
|
2020-09-06 19:09:43 +00:00
|
|
|
|
2020-04-17 21:33:23 +00:00
|
|
|
if( skipRenderHoles )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-04-17 21:33:23 +00:00
|
|
|
pLayerDispList->DrawAllCameraCulled( m_camera.GetPos().z, drawMiddleSegments );
|
2020-09-06 19:09:43 +00:00
|
|
|
|
2022-03-06 13:35:46 +00:00
|
|
|
// Draw plated pads
|
2021-01-05 22:19:00 +00:00
|
|
|
if( layer_id == F_Cu && m_platedPadsFront )
|
2020-11-30 01:07:49 +00:00
|
|
|
{
|
2022-03-06 13:35:46 +00:00
|
|
|
setPlatedCopperAndDepthOffset( layer_id );
|
2021-01-05 22:19:00 +00:00
|
|
|
m_platedPadsFront->DrawAllCameraCulled( m_camera.GetPos().z,
|
2020-11-30 01:07:49 +00:00
|
|
|
drawMiddleSegments );
|
|
|
|
}
|
2021-01-05 22:19:00 +00:00
|
|
|
else if( layer_id == B_Cu && m_platedPadsBack )
|
2020-11-30 01:07:49 +00:00
|
|
|
{
|
2022-03-06 13:35:46 +00:00
|
|
|
setPlatedCopperAndDepthOffset( layer_id );
|
2021-01-05 22:19:00 +00:00
|
|
|
m_platedPadsBack->DrawAllCameraCulled( m_camera.GetPos().z,
|
|
|
|
drawMiddleSegments );
|
2020-11-30 01:07:49 +00:00
|
|
|
}
|
2020-09-06 19:09:43 +00:00
|
|
|
|
|
|
|
unsetDepthOffset();
|
2020-04-17 21:33:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
if( m_outerThroughHoles )
|
2020-11-30 01:07:49 +00:00
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
m_outerThroughHoles->ApplyScalePosition( pLayerDispList->GetZBot(),
|
|
|
|
pLayerDispList->GetZTop()
|
|
|
|
- pLayerDispList->GetZBot() );
|
2020-11-30 01:07:49 +00:00
|
|
|
}
|
2020-07-11 16:32:45 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
if( m_antiBoard )
|
2020-11-03 09:38:07 +00:00
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
m_antiBoard->ApplyScalePosition( pLayerDispList->GetZBot(),
|
|
|
|
pLayerDispList->GetZTop()
|
|
|
|
- pLayerDispList->GetZBot() );
|
2020-11-03 09:38:07 +00:00
|
|
|
}
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
if( m_outerLayerHoles.find( layer_id ) != m_outerLayerHoles.end() )
|
2020-04-17 21:33:23 +00:00
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
const OPENGL_RENDER_LIST* viasHolesLayer = m_outerLayerHoles.at( layer_id );
|
2020-04-17 21:33:23 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
wxASSERT( viasHolesLayer != nullptr );
|
2020-04-17 21:33:23 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( viasHolesLayer != nullptr )
|
2020-04-17 21:33:23 +00:00
|
|
|
{
|
2020-11-30 01:07:49 +00:00
|
|
|
pLayerDispList->DrawAllCameraCulledSubtractLayer( drawMiddleSegments,
|
2021-01-05 22:19:00 +00:00
|
|
|
m_outerThroughHoles,
|
2020-11-30 01:07:49 +00:00
|
|
|
viasHolesLayer,
|
2021-01-05 22:19:00 +00:00
|
|
|
m_antiBoard );
|
2020-09-06 19:09:43 +00:00
|
|
|
|
2022-03-06 13:35:46 +00:00
|
|
|
// Draw plated pads
|
2021-01-05 22:19:00 +00:00
|
|
|
if( layer_id == F_Cu && m_platedPadsFront )
|
2020-10-01 15:49:36 +00:00
|
|
|
{
|
2022-03-06 13:35:46 +00:00
|
|
|
setPlatedCopperAndDepthOffset( layer_id );
|
2021-01-05 22:19:00 +00:00
|
|
|
m_platedPadsFront->DrawAllCameraCulledSubtractLayer(
|
2020-12-13 23:02:57 +00:00
|
|
|
drawMiddleSegments,
|
2021-01-05 22:19:00 +00:00
|
|
|
m_outerThroughHoles,
|
2020-12-13 23:02:57 +00:00
|
|
|
viasHolesLayer,
|
2021-01-05 22:19:00 +00:00
|
|
|
m_antiBoard );
|
2020-10-01 15:49:36 +00:00
|
|
|
}
|
2021-01-05 22:19:00 +00:00
|
|
|
else if( layer_id == B_Cu && m_platedPadsBack )
|
2020-10-01 15:49:36 +00:00
|
|
|
{
|
2022-03-06 13:35:46 +00:00
|
|
|
setPlatedCopperAndDepthOffset( layer_id );
|
2021-01-05 22:19:00 +00:00
|
|
|
m_platedPadsBack->DrawAllCameraCulledSubtractLayer(
|
2020-12-13 23:02:57 +00:00
|
|
|
drawMiddleSegments,
|
2021-01-05 22:19:00 +00:00
|
|
|
m_outerThroughHoles,
|
2020-12-13 23:02:57 +00:00
|
|
|
viasHolesLayer,
|
2021-01-05 22:19:00 +00:00
|
|
|
m_antiBoard );
|
2020-10-01 15:49:36 +00:00
|
|
|
}
|
2020-09-06 19:09:43 +00:00
|
|
|
|
|
|
|
unsetDepthOffset();
|
2020-04-17 21:33:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-12-04 15:35:57 +00:00
|
|
|
pLayerDispList->DrawAllCameraCulledSubtractLayer( drawMiddleSegments,
|
2021-01-05 22:19:00 +00:00
|
|
|
m_outerThroughHoles,
|
|
|
|
m_antiBoard );
|
2020-09-06 19:09:43 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
if( layer_id == F_Cu && m_platedPadsFront )
|
2020-10-01 15:49:36 +00:00
|
|
|
{
|
2022-03-06 13:35:46 +00:00
|
|
|
setPlatedCopperAndDepthOffset( layer_id );
|
2021-01-05 22:19:00 +00:00
|
|
|
m_platedPadsFront->DrawAllCameraCulledSubtractLayer( drawMiddleSegments,
|
|
|
|
m_outerThroughHoles,
|
|
|
|
m_antiBoard );
|
2020-10-01 15:49:36 +00:00
|
|
|
}
|
2021-01-05 22:19:00 +00:00
|
|
|
else if( layer_id == B_Cu && m_platedPadsBack )
|
2020-10-01 15:49:36 +00:00
|
|
|
{
|
2022-03-06 13:35:46 +00:00
|
|
|
setPlatedCopperAndDepthOffset( layer_id );
|
2021-01-05 22:19:00 +00:00
|
|
|
m_platedPadsBack->DrawAllCameraCulledSubtractLayer( drawMiddleSegments,
|
2021-01-07 19:33:43 +00:00
|
|
|
m_outerThroughHoles,
|
|
|
|
m_antiBoard );
|
2020-10-01 15:49:36 +00:00
|
|
|
}
|
2020-09-06 19:09:43 +00:00
|
|
|
|
|
|
|
unsetDepthOffset();
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
setLayerMaterial( layer_id );
|
2020-09-06 19:09:43 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
OPENGL_RENDER_LIST* throughHolesOuter =
|
2021-08-30 20:30:18 +00:00
|
|
|
m_boardAdapter.m_Cfg->m_Render.clip_silk_on_via_annulus
|
|
|
|
&& m_boardAdapter.m_Cfg->m_Render.realistic
|
|
|
|
&& ( layer_id == B_SilkS || layer_id == F_SilkS ) ? m_outerThroughHoleRings
|
|
|
|
: m_outerThroughHoles;
|
2020-07-16 22:36:06 +00:00
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
if( throughHolesOuter )
|
2020-10-01 15:49:36 +00:00
|
|
|
{
|
2021-08-30 20:30:18 +00:00
|
|
|
throughHolesOuter->ApplyScalePosition( pLayerDispList->GetZBot(),
|
|
|
|
pLayerDispList->GetZTop()
|
|
|
|
- pLayerDispList->GetZBot() );
|
2020-10-01 15:49:36 +00:00
|
|
|
}
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
OPENGL_RENDER_LIST* anti_board = m_antiBoard;
|
2020-11-04 09:36:41 +00:00
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
if( anti_board )
|
2020-10-06 11:49:10 +00:00
|
|
|
{
|
2021-08-30 20:30:18 +00:00
|
|
|
anti_board->ApplyScalePosition( pLayerDispList->GetZBot(),
|
|
|
|
pLayerDispList->GetZTop()
|
|
|
|
- pLayerDispList->GetZBot() );
|
2020-10-06 11:49:10 +00:00
|
|
|
}
|
2020-07-11 16:32:45 +00:00
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
if( !skipRenderHoles
|
2021-08-30 20:30:18 +00:00
|
|
|
&& m_boardAdapter.m_Cfg->m_Render.subtract_mask_from_silk
|
|
|
|
&& m_boardAdapter.m_Cfg->m_Render.realistic
|
|
|
|
&& ( ( layer_id == B_SilkS && m_layers.find( B_Mask ) != m_layers.end() )
|
|
|
|
|| ( layer_id == F_SilkS && m_layers.find( F_Mask ) != m_layers.end() ) ) )
|
2020-01-29 16:00:05 +00:00
|
|
|
{
|
2020-10-01 15:49:36 +00:00
|
|
|
const PCB_LAYER_ID layerMask_id = (layer_id == B_SilkS) ? B_Mask : F_Mask;
|
2020-01-29 16:00:05 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const OPENGL_RENDER_LIST* pLayerDispListMask = m_layers.at( layerMask_id );
|
2020-01-29 16:00:05 +00:00
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
pLayerDispList->DrawAllCameraCulledSubtractLayer( drawMiddleSegments,
|
|
|
|
pLayerDispListMask,
|
|
|
|
throughHolesOuter, anti_board );
|
2020-01-29 16:00:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-07 19:33:43 +00:00
|
|
|
if( !skipRenderHoles && throughHolesOuter
|
|
|
|
&& ( layer_id == B_SilkS || layer_id == F_SilkS ) )
|
2020-01-29 16:00:05 +00:00
|
|
|
{
|
2020-11-30 01:07:49 +00:00
|
|
|
pLayerDispList->DrawAllCameraCulledSubtractLayer( drawMiddleSegments, nullptr,
|
2020-12-13 23:02:57 +00:00
|
|
|
throughHolesOuter,
|
|
|
|
anti_board );
|
2020-01-29 16:00:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-17 21:33:23 +00:00
|
|
|
// Do not render Paste layers when skipRenderHoles is enabled
|
|
|
|
// otherwise it will cause z-fight issues
|
2020-10-01 15:49:36 +00:00
|
|
|
if( !( skipRenderHoles && ( layer_id == B_Paste || layer_id == F_Paste ) ) )
|
2020-04-17 21:33:23 +00:00
|
|
|
{
|
2020-11-30 01:07:49 +00:00
|
|
|
pLayerDispList->DrawAllCameraCulledSubtractLayer( drawMiddleSegments,
|
|
|
|
anti_board );
|
2020-04-17 21:33:23 +00:00
|
|
|
}
|
2020-01-29 16:00:05 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glPopMatrix();
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Render 3D Models (Non-transparent)
|
2021-01-05 22:19:00 +00:00
|
|
|
render3dModels( false, false );
|
|
|
|
render3dModels( true, false );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-08-25 20:33:51 +00:00
|
|
|
// Display board body
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.show_board_body )
|
2021-01-05 22:19:00 +00:00
|
|
|
renderBoardBody( skipRenderHoles );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Display transparent mask layers
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.show_soldermask )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-01-29 16:00:05 +00:00
|
|
|
// add a depth buffer offset, it will help to hide some artifacts
|
|
|
|
// on silkscreen where the SolderMask is removed
|
|
|
|
glEnable( GL_POLYGON_OFFSET_FILL );
|
2020-09-07 15:00:48 +00:00
|
|
|
glPolygonOffset( 0.0f, -2.0f );
|
2020-01-29 16:00:05 +00:00
|
|
|
|
2020-03-26 14:05:20 +00:00
|
|
|
if( m_camera.GetPos().z > 0 )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
renderSolderMaskLayer( B_Mask, m_boardAdapter.GetLayerTopZPos( B_Mask ),
|
|
|
|
drawMiddleSegments, skipRenderHoles );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
renderSolderMaskLayer( F_Mask, m_boardAdapter.GetLayerBottomZPos( F_Mask ),
|
|
|
|
drawMiddleSegments, skipRenderHoles );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
renderSolderMaskLayer( F_Mask, m_boardAdapter.GetLayerBottomZPos( F_Mask ),
|
|
|
|
drawMiddleSegments, skipRenderHoles );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
renderSolderMaskLayer( B_Mask, m_boardAdapter.GetLayerTopZPos( B_Mask ),
|
|
|
|
drawMiddleSegments, skipRenderHoles );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2020-01-29 16:00:05 +00:00
|
|
|
|
|
|
|
glDisable( GL_POLYGON_OFFSET_FILL );
|
|
|
|
glPolygonOffset( 0.0f, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Render 3D Models (Transparent)
|
2020-04-25 00:08:55 +00:00
|
|
|
// !TODO: this can be optimized. If there are no transparent models (or no opacity),
|
|
|
|
// then there is no need to make this function call.
|
2020-04-25 14:38:41 +00:00
|
|
|
glDepthMask( GL_FALSE );
|
|
|
|
glEnable( GL_BLEND );
|
|
|
|
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
// Enables Texture Env so it can combine model transparency with each footprint opacity
|
2020-04-25 14:38:41 +00:00
|
|
|
glEnable( GL_TEXTURE_2D );
|
|
|
|
glActiveTexture( GL_TEXTURE0 );
|
|
|
|
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
|
|
|
|
glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE );
|
|
|
|
glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE );
|
|
|
|
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PRIMARY_COLOR );
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR );
|
|
|
|
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS );
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR );
|
|
|
|
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PRIMARY_COLOR );
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA );
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_CONSTANT );
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_CONSTANT );
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
render3dModels( false, true );
|
|
|
|
render3dModels( true, true );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-04-25 14:38:41 +00:00
|
|
|
glDisable( GL_BLEND );
|
2021-01-07 19:33:43 +00:00
|
|
|
OglResetTextureState();
|
2020-04-25 14:38:41 +00:00
|
|
|
|
|
|
|
glDepthMask( GL_TRUE );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Render Grid
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.grid_type != GRID3D_TYPE::NONE )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2016-07-19 17:35:25 +00:00
|
|
|
glDisable( GL_LIGHTING );
|
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
if( glIsList( m_grid ) )
|
|
|
|
glCallList( m_grid );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
glEnable( GL_LIGHTING );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Render 3D arrows
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.show_axis )
|
2021-01-05 22:19:00 +00:00
|
|
|
render3dArrows();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Return back to the original viewport (this is important if we want
|
|
|
|
// to take a screenshot after the render)
|
|
|
|
glViewport( 0, 0, m_windowSize.x, m_windowSize.y );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
bool RENDER_3D_OPENGL::initializeOpenGL()
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
glEnable( GL_LINE_SMOOTH );
|
|
|
|
glShadeModel( GL_SMOOTH );
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
// 4-byte pixel alignment
|
|
|
|
glPixelStorei( GL_UNPACK_ALIGNMENT, 4 );
|
|
|
|
|
|
|
|
// Initialize the open GL texture to draw the filled semi-circle of the segments
|
2021-01-02 21:05:29 +00:00
|
|
|
IMAGE* circleImage = new IMAGE( SIZE_OF_CIRCLE_TEXTURE, SIZE_OF_CIRCLE_TEXTURE );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
if( !circleImage )
|
|
|
|
return false;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-04-21 22:56:11 +00:00
|
|
|
unsigned int circleRadius = ( SIZE_OF_CIRCLE_TEXTURE / 2 ) - 4;
|
2021-04-20 21:19:11 +00:00
|
|
|
|
2020-12-13 23:02:57 +00:00
|
|
|
circleImage->CircleFilled( ( SIZE_OF_CIRCLE_TEXTURE / 2 ) - 0,
|
|
|
|
( SIZE_OF_CIRCLE_TEXTURE / 2 ) - 0,
|
2021-04-20 21:19:11 +00:00
|
|
|
circleRadius,
|
2016-07-19 17:35:25 +00:00
|
|
|
0xFF );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-04-20 21:19:11 +00:00
|
|
|
IMAGE* circleImageBlured = new IMAGE( circleImage->GetWidth(), circleImage->GetHeight() );
|
|
|
|
|
|
|
|
circleImageBlured->EfxFilter_SkipCenter( circleImage, IMAGE_FILTER::GAUSSIAN_BLUR, circleRadius - 8 );
|
|
|
|
|
|
|
|
m_circleTexture = OglLoadTexture( *circleImageBlured );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-04-20 21:19:11 +00:00
|
|
|
delete circleImageBlured;
|
2021-04-22 21:20:34 +00:00
|
|
|
circleImageBlured = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
delete circleImage;
|
2021-04-22 21:20:34 +00:00
|
|
|
circleImage = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
init_lights();
|
|
|
|
|
|
|
|
// Use this mode if you want see the triangle lines (debug proposes)
|
|
|
|
//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
|
2015-12-08 07:31:57 +00:00
|
|
|
m_is_opengl_initialized = true;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::setArrowMaterial()
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
glEnable( GL_COLOR_MATERIAL );
|
|
|
|
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
const SFVEC4F ambient = SFVEC4F( 0.0f, 0.0f, 0.0f, 1.0f );
|
|
|
|
const SFVEC4F diffuse = SFVEC4F( 0.0f, 0.0f, 0.0f, 1.0f );
|
|
|
|
const SFVEC4F emissive = SFVEC4F( 0.0f, 0.0f, 0.0f, 1.0f );
|
2015-12-08 07:31:57 +00:00
|
|
|
const SFVEC4F specular = SFVEC4F( 0.1f, 0.1f, 0.1f, 1.0f );
|
|
|
|
|
|
|
|
glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r );
|
2016-07-19 17:35:25 +00:00
|
|
|
glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 96.0f );
|
|
|
|
|
|
|
|
glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r );
|
|
|
|
glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r );
|
|
|
|
glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, &emissive.r );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::freeAllLists()
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2020-11-30 01:07:49 +00:00
|
|
|
if( glIsList( m_grid ) )
|
|
|
|
glDeleteLists( m_grid, 1 );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
m_grid = 0;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
for( MAP_OGL_DISP_LISTS::const_iterator ii = m_layers.begin(); ii != m_layers.end(); ++ii )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
OPENGL_RENDER_LIST* pLayerDispList = static_cast<OPENGL_RENDER_LIST*>( ii->second );
|
2015-12-08 07:31:57 +00:00
|
|
|
delete pLayerDispList;
|
|
|
|
}
|
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
m_layers.clear();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
delete m_platedPadsFront;
|
|
|
|
m_platedPadsFront = nullptr;
|
2020-09-27 09:28:05 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
delete m_platedPadsBack;
|
|
|
|
m_platedPadsBack = nullptr;
|
2020-09-27 09:28:05 +00:00
|
|
|
|
2021-12-03 14:14:50 +00:00
|
|
|
|
|
|
|
for( const std::pair<const PCB_LAYER_ID, OPENGL_RENDER_LIST*> entry : m_outerLayerHoles )
|
|
|
|
delete entry.second;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_outerLayerHoles.clear();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-12-03 14:14:50 +00:00
|
|
|
for( const std::pair<const PCB_LAYER_ID, OPENGL_RENDER_LIST*> entry : m_innerLayerHoles )
|
|
|
|
delete entry.second;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_innerLayerHoles.clear();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
for( LIST_TRIANGLES::const_iterator ii = m_triangles.begin(); ii != m_triangles.end(); ++ii )
|
2020-09-06 19:09:43 +00:00
|
|
|
delete *ii;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
m_triangles.clear();
|
|
|
|
|
2021-12-03 14:14:50 +00:00
|
|
|
for( const std::pair<const wxString&, MODEL_3D*>& entry : m_3dModelMap )
|
|
|
|
delete entry.second;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
m_3dModelMap.clear();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-12-03 14:14:50 +00:00
|
|
|
m_3dModelMatrixMap.clear();
|
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
delete m_board;
|
|
|
|
m_board = nullptr;
|
2020-10-01 15:49:36 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
delete m_boardWithHoles;
|
|
|
|
m_boardWithHoles = nullptr;
|
2020-12-24 13:27:56 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
delete m_antiBoard;
|
|
|
|
m_antiBoard = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
delete m_outerThroughHoles;
|
|
|
|
m_outerThroughHoles = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
delete m_outerViaThroughHoles;
|
|
|
|
m_outerViaThroughHoles = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
delete m_outerThroughHoleRings;
|
|
|
|
m_outerThroughHoleRings = nullptr;
|
2020-07-16 22:36:06 +00:00
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
delete m_vias;
|
|
|
|
m_vias = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
delete m_padHoles;
|
|
|
|
m_padHoles = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::renderSolderMaskLayer( PCB_LAYER_ID aLayerID, float aZPosition,
|
2021-01-05 22:19:00 +00:00
|
|
|
bool aDrawMiddleSegments, bool aSkipRenderHoles )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
wxASSERT( (aLayerID == B_Mask) || (aLayerID == F_Mask) );
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
float nonCopperThickness = m_boardAdapter.GetNonCopperLayerThickness();
|
2020-11-30 01:07:49 +00:00
|
|
|
|
|
|
|
if( m_board )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-11-30 01:07:49 +00:00
|
|
|
if( m_layers.find( aLayerID ) != m_layers.end() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
OPENGL_RENDER_LIST* pLayerDispListMask = m_layers.at( aLayerID );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
if( m_outerViaThroughHoles )
|
|
|
|
m_outerViaThroughHoles->ApplyScalePosition( aZPosition, nonCopperThickness );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
m_board->ApplyScalePosition( aZPosition, nonCopperThickness );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
setLayerMaterial( aLayerID );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
m_board->SetItIsTransparent( true );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-04-17 21:33:23 +00:00
|
|
|
if( aSkipRenderHoles )
|
|
|
|
{
|
2020-11-30 01:07:49 +00:00
|
|
|
m_board->DrawAllCameraCulled( m_camera.GetPos().z, aDrawMiddleSegments );
|
2020-04-17 21:33:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-30 01:07:49 +00:00
|
|
|
m_board->DrawAllCameraCulledSubtractLayer( aDrawMiddleSegments, pLayerDispListMask,
|
2021-01-05 22:19:00 +00:00
|
|
|
m_outerViaThroughHoles );
|
2020-04-17 21:33:23 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// This case there is no layer with mask, so we will render the full board as mask
|
2021-01-05 22:19:00 +00:00
|
|
|
if( m_outerViaThroughHoles )
|
|
|
|
m_outerViaThroughHoles->ApplyScalePosition( aZPosition, nonCopperThickness );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
m_board->ApplyScalePosition( aZPosition, nonCopperThickness );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
setLayerMaterial( aLayerID );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
m_board->SetItIsTransparent( true );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-04-17 21:33:23 +00:00
|
|
|
if( aSkipRenderHoles )
|
|
|
|
{
|
2020-11-30 01:07:49 +00:00
|
|
|
m_board->DrawAllCameraCulled( m_camera.GetPos().z, aDrawMiddleSegments );
|
2020-04-17 21:33:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-30 01:07:49 +00:00
|
|
|
m_board->DrawAllCameraCulledSubtractLayer( aDrawMiddleSegments,
|
2021-01-05 22:19:00 +00:00
|
|
|
m_outerViaThroughHoles );
|
2020-04-17 21:33:23 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-10 13:50:16 +00:00
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::render3dModelsSelected( bool aRenderTopOrBot, bool aRenderTransparentOnly,
|
2021-01-05 22:19:00 +00:00
|
|
|
bool aRenderSelectedOnly )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-07-18 15:44:54 +00:00
|
|
|
if( !m_boardAdapter.GetBoard() )
|
|
|
|
return;
|
2020-09-02 16:22:12 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
MODEL_3D::BeginDrawMulti( !aRenderSelectedOnly );
|
2020-04-17 16:10:04 +00:00
|
|
|
|
2020-10-21 03:48:06 +00:00
|
|
|
// Go for all footprints
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* fp : m_boardAdapter.GetBoard()->Footprints() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-05-11 19:52:28 +00:00
|
|
|
bool highlight = false;
|
2020-09-04 00:00:56 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_IsBoardView )
|
2020-11-12 23:50:33 +00:00
|
|
|
{
|
2021-10-13 23:31:09 +00:00
|
|
|
if( fp->IsSelected() )
|
|
|
|
highlight = true;
|
2020-09-02 16:22:12 +00:00
|
|
|
|
2021-12-27 23:48:37 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.opengl_highlight_on_rollover
|
|
|
|
&& fp == m_currentRollOverItem )
|
|
|
|
{
|
2021-10-13 23:31:09 +00:00
|
|
|
highlight = true;
|
2021-12-27 23:48:37 +00:00
|
|
|
}
|
2021-10-13 23:31:09 +00:00
|
|
|
|
|
|
|
if( aRenderSelectedOnly != highlight )
|
|
|
|
continue;
|
2020-09-04 00:00:56 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
if( !fp->Models().empty() )
|
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
if( m_boardAdapter.IsFootprintShown( (FOOTPRINT_ATTR_T) fp->GetAttributes() ) )
|
2020-11-12 23:50:33 +00:00
|
|
|
{
|
2021-10-13 23:31:09 +00:00
|
|
|
if( aRenderTopOrBot == !fp->IsFlipped() )
|
|
|
|
renderFootprint( fp, aRenderTransparentOnly, highlight );
|
2020-11-12 23:50:33 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2020-04-17 16:10:04 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
MODEL_3D::EndDrawMulti();
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 13:50:16 +00:00
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::render3dModels( bool aRenderTopOrBot, bool aRenderTransparentOnly )
|
2020-09-02 16:22:12 +00:00
|
|
|
{
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_IsBoardView )
|
2021-01-05 22:19:00 +00:00
|
|
|
render3dModelsSelected( aRenderTopOrBot, aRenderTransparentOnly, true );
|
2020-09-27 17:18:44 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
render3dModelsSelected( aRenderTopOrBot, aRenderTransparentOnly, false );
|
2020-09-02 16:22:12 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::renderFootprint( const FOOTPRINT* aFootprint, bool aRenderTransparentOnly,
|
2021-01-05 22:19:00 +00:00
|
|
|
bool aIsSelected )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-11-13 11:17:15 +00:00
|
|
|
if( !aFootprint->Models().empty() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
const double zpos = m_boardAdapter.GetFootprintZPos( aFootprint->IsFlipped() );
|
2021-08-30 20:30:18 +00:00
|
|
|
SFVEC3F selColor = m_boardAdapter.GetColor( m_boardAdapter.m_Cfg->m_Render.opengl_selection_color );
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
2021-12-29 19:19:08 +00:00
|
|
|
VECTOR2I pos = aFootprint->GetPosition();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
glTranslatef( pos.x * m_boardAdapter.BiuTo3dUnits(), -pos.y * m_boardAdapter.BiuTo3dUnits(),
|
2020-12-13 23:02:57 +00:00
|
|
|
zpos );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-01-13 17:27:36 +00:00
|
|
|
if( !aFootprint->GetOrientation().IsZero() )
|
|
|
|
glRotated( aFootprint->GetOrientation().AsDegrees(), 0.0, 0.0, 1.0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
if( aFootprint->IsFlipped() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
glRotatef( 180.0f, 0.0f, 1.0f, 0.0f );
|
|
|
|
glRotatef( 180.0f, 0.0f, 0.0f, 1.0f );
|
|
|
|
}
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
double modelunit_to_3d_units_factor = m_boardAdapter.BiuTo3dUnits() * UNITS3D_TO_UNITSPCB;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
glScaled( modelunit_to_3d_units_factor, modelunit_to_3d_units_factor,
|
2016-07-19 17:35:25 +00:00
|
|
|
modelunit_to_3d_units_factor );
|
|
|
|
|
|
|
|
// Get the list of model files for this model
|
2020-11-13 11:17:15 +00:00
|
|
|
for( const FP_3DMODEL& sM : aFootprint->Models() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-09-08 19:41:43 +00:00
|
|
|
if( !sM.m_Show || sM.m_Filename.empty() )
|
2020-05-08 21:32:06 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Check if the model is present in our cache map
|
2021-01-05 22:19:00 +00:00
|
|
|
auto cache_i = m_3dModelMap.find( sM.m_Filename );
|
2020-05-08 21:32:06 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
if( cache_i == m_3dModelMap.end() )
|
2020-05-08 21:32:06 +00:00
|
|
|
continue;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( const MODEL_3D* modelPtr = cache_i->second )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-05-08 21:32:06 +00:00
|
|
|
bool opaque = sM.m_Opacity >= 1.0;
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
if( ( !aRenderTransparentOnly && modelPtr->HasOpaqueMeshes() && opaque ) ||
|
|
|
|
( aRenderTransparentOnly && ( modelPtr->HasTransparentMeshes() || !opaque ) ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-05-08 21:32:06 +00:00
|
|
|
glPushMatrix();
|
|
|
|
|
2021-12-03 14:14:50 +00:00
|
|
|
std::vector<double> key = { sM.m_Offset.x, sM.m_Offset.y, sM.m_Offset.z,
|
|
|
|
sM.m_Rotation.x, sM.m_Rotation.y, sM.m_Rotation.z,
|
|
|
|
sM.m_Scale.x, sM.m_Scale.y, sM.m_Scale.z };
|
|
|
|
|
|
|
|
auto it = m_3dModelMatrixMap.find( key );
|
|
|
|
|
|
|
|
if( it != m_3dModelMatrixMap.end() )
|
|
|
|
{
|
|
|
|
glMultMatrixf( glm::value_ptr( it->second ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glm::mat4 mtx( 1 );
|
|
|
|
mtx = glm::translate( mtx, { sM.m_Offset.x, sM.m_Offset.y, sM.m_Offset.z } );
|
|
|
|
mtx = glm::rotate( mtx, glm::radians( (float) -sM.m_Rotation.z ), { 0.0f, 0.0f, 1.0f } );
|
|
|
|
mtx = glm::rotate( mtx, glm::radians( (float) -sM.m_Rotation.y ), { 0.0f, 1.0f, 0.0f } );
|
|
|
|
mtx = glm::rotate( mtx, glm::radians( (float) -sM.m_Rotation.x ), { 1.0f, 0.0f, 0.0f } );
|
|
|
|
mtx = glm::scale( mtx, { sM.m_Scale.x, sM.m_Scale.y, sM.m_Scale.z } );
|
|
|
|
m_3dModelMatrixMap[ key ] = mtx;
|
|
|
|
|
|
|
|
glMultMatrixf( glm::value_ptr( mtx ) );
|
|
|
|
}
|
|
|
|
|
2020-05-08 21:32:06 +00:00
|
|
|
|
|
|
|
if( aRenderTransparentOnly )
|
2020-11-30 01:07:49 +00:00
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
modelPtr->DrawTransparent( sM.m_Opacity,
|
|
|
|
aFootprint->IsSelected() || aIsSelected,
|
2021-08-30 20:30:18 +00:00
|
|
|
selColor );
|
2020-11-30 01:07:49 +00:00
|
|
|
}
|
2020-05-08 21:32:06 +00:00
|
|
|
else
|
2020-11-30 01:07:49 +00:00
|
|
|
{
|
2021-08-30 20:30:18 +00:00
|
|
|
modelPtr->DrawOpaque( aFootprint->IsSelected() || aIsSelected, selColor );
|
2020-11-30 01:07:49 +00:00
|
|
|
}
|
2020-05-08 21:32:06 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.opengl_show_model_bbox )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-05-08 21:32:06 +00:00
|
|
|
glEnable( GL_BLEND );
|
|
|
|
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
|
|
|
|
|
|
|
glDisable( GL_LIGHTING );
|
|
|
|
|
|
|
|
glLineWidth( 1 );
|
2021-01-05 22:19:00 +00:00
|
|
|
modelPtr->DrawBboxes();
|
2020-05-08 21:32:06 +00:00
|
|
|
|
|
|
|
glLineWidth( 4 );
|
2021-01-05 22:19:00 +00:00
|
|
|
modelPtr->DrawBbox();
|
2020-05-08 21:32:06 +00:00
|
|
|
|
|
|
|
glEnable( GL_LIGHTING );
|
|
|
|
glDisable( GL_BLEND );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2020-05-08 21:32:06 +00:00
|
|
|
|
|
|
|
glPopMatrix();
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
void RENDER_3D_OPENGL::generate3dGrid( GRID3D_TYPE aGridType )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-11-30 01:07:49 +00:00
|
|
|
if( glIsList( m_grid ) )
|
|
|
|
glDeleteLists( m_grid, 1 );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
m_grid = 0;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2019-12-30 13:01:06 +00:00
|
|
|
if( aGridType == GRID3D_TYPE::NONE )
|
2016-07-19 17:35:25 +00:00
|
|
|
return;
|
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
m_grid = glGenLists( 1 );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
if( !glIsList( m_grid ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
return;
|
|
|
|
|
2020-11-30 01:07:49 +00:00
|
|
|
glNewList( m_grid, GL_COMPILE );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
glEnable( GL_BLEND );
|
|
|
|
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
|
|
|
|
|
|
|
const double zpos = 0.0;
|
|
|
|
|
|
|
|
// Color of grid lines
|
2020-03-26 14:05:20 +00:00
|
|
|
const SFVEC3F gridColor = m_boardAdapter.GetColor( DARKGRAY );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Color of grid lines every 5 lines
|
2021-09-02 16:19:18 +00:00
|
|
|
const SFVEC3F gridColor_marker = m_boardAdapter.GetColor( LIGHTBLUE );
|
2021-01-05 22:19:00 +00:00
|
|
|
const double scale = m_boardAdapter.BiuTo3dUnits();
|
2020-10-05 10:41:14 +00:00
|
|
|
const GLfloat transparency = 0.35f;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
double griSizeMM = 0.0;
|
|
|
|
|
|
|
|
switch( aGridType )
|
|
|
|
{
|
|
|
|
default:
|
2019-12-30 13:01:06 +00:00
|
|
|
case GRID3D_TYPE::NONE:
|
2016-07-19 17:35:25 +00:00
|
|
|
return;
|
2019-12-30 13:01:06 +00:00
|
|
|
case GRID3D_TYPE::GRID_1MM:
|
2016-07-19 17:35:25 +00:00
|
|
|
griSizeMM = 1.0;
|
|
|
|
break;
|
2019-12-30 13:01:06 +00:00
|
|
|
case GRID3D_TYPE::GRID_2P5MM:
|
2016-07-19 17:35:25 +00:00
|
|
|
griSizeMM = 2.5;
|
|
|
|
break;
|
2019-12-30 13:01:06 +00:00
|
|
|
case GRID3D_TYPE::GRID_5MM:
|
2016-07-19 17:35:25 +00:00
|
|
|
griSizeMM = 5.0;
|
|
|
|
break;
|
2019-12-30 13:01:06 +00:00
|
|
|
case GRID3D_TYPE::GRID_10MM:
|
2016-07-19 17:35:25 +00:00
|
|
|
griSizeMM = 10.0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
glNormal3f( 0.0, 0.0, 1.0 );
|
|
|
|
|
2021-12-29 19:19:08 +00:00
|
|
|
const VECTOR2I brd_size = m_boardAdapter.GetBoardSize();
|
|
|
|
VECTOR2I brd_center_pos = m_boardAdapter.GetBoardPos();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
brd_center_pos.y = -brd_center_pos.y;
|
|
|
|
|
|
|
|
const int xsize = std::max( brd_size.x, Millimeter2iu( 100 ) ) * 1.2;
|
|
|
|
const int ysize = std::max( brd_size.y, Millimeter2iu( 100 ) ) * 1.2;
|
|
|
|
|
|
|
|
// Grid limits, in 3D units
|
2021-01-02 21:05:29 +00:00
|
|
|
double xmin = ( brd_center_pos.x - xsize / 2 ) * scale;
|
|
|
|
double xmax = ( brd_center_pos.x + xsize / 2 ) * scale;
|
|
|
|
double ymin = ( brd_center_pos.y - ysize / 2 ) * scale;
|
|
|
|
double ymax = ( brd_center_pos.y + ysize / 2 ) * scale;
|
|
|
|
double zmin = Millimeter2iu( -50 ) * scale;
|
|
|
|
double zmax = Millimeter2iu( 100 ) * scale;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-09-02 16:19:18 +00:00
|
|
|
// Set rasterised line width (min value = 1)
|
|
|
|
glLineWidth( 1 );
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Draw horizontal grid centered on 3D origin (center of the board)
|
|
|
|
for( int ii = 0; ; ii++ )
|
|
|
|
{
|
|
|
|
if( (ii % 5) )
|
|
|
|
glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency );
|
|
|
|
else
|
2021-01-02 21:05:29 +00:00
|
|
|
glColor4f( gridColor_marker.r, gridColor_marker.g, gridColor_marker.b,
|
2016-07-19 17:35:25 +00:00
|
|
|
transparency );
|
|
|
|
|
|
|
|
const int delta = KiROUND( ii * griSizeMM * IU_PER_MM );
|
|
|
|
|
|
|
|
if( delta <= xsize / 2 ) // Draw grid lines parallel to X axis
|
|
|
|
{
|
|
|
|
glBegin( GL_LINES );
|
|
|
|
glVertex3f( (brd_center_pos.x + delta) * scale, -ymin, zpos );
|
|
|
|
glVertex3f( (brd_center_pos.x + delta) * scale, -ymax, zpos );
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
if( ii != 0 )
|
|
|
|
{
|
|
|
|
glBegin( GL_LINES );
|
|
|
|
glVertex3f( (brd_center_pos.x - delta) * scale, -ymin, zpos );
|
|
|
|
glVertex3f( (brd_center_pos.x - delta) * scale, -ymax, zpos );
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( delta <= ysize / 2 ) // Draw grid lines parallel to Y axis
|
|
|
|
{
|
|
|
|
glBegin( GL_LINES );
|
2021-01-02 21:05:29 +00:00
|
|
|
glVertex3f( xmin, -( brd_center_pos.y + delta ) * scale, zpos );
|
|
|
|
glVertex3f( xmax, -( brd_center_pos.y + delta ) * scale, zpos );
|
2016-07-19 17:35:25 +00:00
|
|
|
glEnd();
|
|
|
|
|
|
|
|
if( ii != 0 )
|
|
|
|
{
|
|
|
|
glBegin( GL_LINES );
|
2021-01-02 21:05:29 +00:00
|
|
|
glVertex3f( xmin, -( brd_center_pos.y - delta ) * scale, zpos );
|
|
|
|
glVertex3f( xmax, -( brd_center_pos.y - delta ) * scale, zpos );
|
2016-07-19 17:35:25 +00:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( delta > ysize / 2 ) && ( delta > xsize / 2 ) )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw vertical grid on Z axis
|
|
|
|
glNormal3f( 0.0, -1.0, 0.0 );
|
|
|
|
|
|
|
|
// Draw vertical grid lines (parallel to Z axis)
|
|
|
|
double posy = -brd_center_pos.y * scale;
|
|
|
|
|
|
|
|
for( int ii = 0; ; ii++ )
|
|
|
|
{
|
|
|
|
if( (ii % 5) )
|
|
|
|
glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency );
|
|
|
|
else
|
2021-01-02 21:05:29 +00:00
|
|
|
glColor4f( gridColor_marker.r, gridColor_marker.g, gridColor_marker.b,
|
2016-07-19 17:35:25 +00:00
|
|
|
transparency );
|
|
|
|
|
|
|
|
const double delta = ii * griSizeMM * IU_PER_MM;
|
|
|
|
|
|
|
|
glBegin( GL_LINES );
|
2021-01-02 21:05:29 +00:00
|
|
|
xmax = ( brd_center_pos.x + delta ) * scale;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
glVertex3f( xmax, posy, zmin );
|
|
|
|
glVertex3f( xmax, posy, zmax );
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
if( ii != 0 )
|
|
|
|
{
|
|
|
|
glBegin( GL_LINES );
|
2021-01-02 21:05:29 +00:00
|
|
|
xmin = ( brd_center_pos.x - delta ) * scale;
|
2016-07-19 17:35:25 +00:00
|
|
|
glVertex3f( xmin, posy, zmin );
|
|
|
|
glVertex3f( xmin, posy, zmax );
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( delta > xsize / 2.0f )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw horizontal grid lines on Z axis (parallel to X axis)
|
|
|
|
for( int ii = 0; ; ii++ )
|
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
if( ii % 5 )
|
2016-07-19 17:35:25 +00:00
|
|
|
glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency );
|
|
|
|
else
|
2021-01-07 19:33:43 +00:00
|
|
|
glColor4f( gridColor_marker.r, gridColor_marker.g, gridColor_marker.b, transparency );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
const double delta = ii * griSizeMM * IU_PER_MM * scale;
|
|
|
|
|
|
|
|
if( delta <= zmax )
|
|
|
|
{
|
|
|
|
// Draw grid lines on Z axis (positive Z axis coordinates)
|
|
|
|
glBegin( GL_LINES );
|
|
|
|
glVertex3f( xmin, posy, delta );
|
|
|
|
glVertex3f( xmax, posy, delta );
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( delta <= -zmin && ( ii != 0 ) )
|
|
|
|
{
|
|
|
|
// Draw grid lines on Z axis (negative Z axis coordinates)
|
|
|
|
glBegin( GL_LINES );
|
|
|
|
glVertex3f( xmin, posy, -delta );
|
|
|
|
glVertex3f( xmax, posy, -delta );
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( delta > zmax ) && ( delta > -zmin ) )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
glDisable( GL_BLEND );
|
|
|
|
|
|
|
|
glEndList();
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|