KiCad PCB EDA Suite
Loading...
Searching...
No Matches
render_3d_opengl.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015-2020 Mario Luzeiro <[email protected]>
5 * Copyright (C) 2023 CERN
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <cstdint>
27#include <kicad_gl/kiglad.h> // Must be included first
28
30#include "render_3d_opengl.h"
31#include "opengl_utils.h"
34#include <board.h>
35#include <footprint.h>
37#include <3d_math.h>
38#include <glm/geometric.hpp>
39#include <lset.h>
40#include <pgm_base.h>
41#include <math/util.h> // for KiROUND
42#include <utility>
43#include <vector>
44#include <wx/log.h>
45
46#include <base_units.h>
47
48#include <glm/gtc/type_ptr.hpp>
49
59static float TransparencyControl( float aGrayColorValue, float aTransparency )
60{
61 const float aaa = aTransparency * aTransparency * aTransparency;
62
63 // 1.00-1.05*(1.0-x)^3
64 float ca = 1.0f - aTransparency;
65 ca = 1.00f - 1.05f * ca * ca * ca;
66
67 return glm::clamp( aGrayColorValue * ca + aaa, 0.0f, 1.0f );
68}
69
73#define UNITS3D_TO_UNITSPCB ( pcbIUScale.IU_PER_MM )
74
76 RENDER_3D_BASE( aAdapter, aCamera ),
77 m_canvas( aCanvas )
78{
79 wxLogTrace( m_logTrace, wxT( "RENDER_3D_OPENGL::RENDER_3D_OPENGL" ) );
80
81 m_layers.clear();
82 m_outerLayerHoles.clear();
83 m_innerLayerHoles.clear();
84 m_triangles.clear();
85 m_board = nullptr;
86 m_antiBoard = nullptr;
87
88 m_platedPadsFront = nullptr;
89 m_platedPadsBack = nullptr;
90 m_offboardPadsFront = nullptr;
91 m_offboardPadsBack = nullptr;
92
93 m_outerThroughHoles = nullptr;
95 m_outerViaThroughHoles = nullptr;
96 m_microviaHoles = nullptr;
97 m_padHoles = nullptr;
98 m_viaFrontCover = nullptr;
99 m_viaBackCover = nullptr;
100
101 m_circleTexture = 0;
102 m_grid = 0;
104 m_currentRollOverItem = nullptr;
105 m_boardWithHoles = nullptr;
106 m_postMachinePlugs = nullptr;
107
108 m_3dModelMap.clear();
109
110 m_spheres_gizmo = new SPHERES_GIZMO( 4, 4 );
111}
112
113
115{
116 wxLogTrace( m_logTrace, wxT( "RENDER_3D_OPENGL::RENDER_3D_OPENGL" ) );
117
118 freeAllLists();
119
120 delete m_placeholderModel;
121
122 glDeleteTextures( 1, &m_circleTexture );
123
124 delete m_spheres_gizmo;
125}
126
127
129{
130 return 50; // ms
131}
132
133
134void RENDER_3D_OPENGL::SetCurWindowSize( const wxSize& aSize )
135{
136 if( m_windowSize != aSize )
137 {
138 int viewport[4];
139 int fbWidth, fbHeight;
140 glGetIntegerv( GL_VIEWPORT, viewport );
141
142 m_windowSize = aSize;
143 glViewport( 0, 0, m_windowSize.x, m_windowSize.y );
145 // Initialize here any screen dependent data here
146 }
147}
148
149
151{
152 if( enabled )
153 glEnable( GL_LIGHT0 );
154 else
155 glDisable( GL_LIGHT0 );
156}
157
158
160{
161 if( enabled )
162 glEnable( GL_LIGHT1 );
163 else
164 glDisable( GL_LIGHT1 );
165}
166
167
169{
170 if( enabled )
171 glEnable( GL_LIGHT2 );
172 else
173 glDisable( GL_LIGHT2 );
174}
175
176
178{
179 m_spheres_gizmo->resetSelectedGizmoSphere();
180}
181
182
187
188
189void RENDER_3D_OPENGL::setGizmoViewport( int x, int y, int width, int height )
190{
191 m_spheres_gizmo->setViewport( x, y, width, height );
192}
193
194
195std::tuple<int, int, int, int> RENDER_3D_OPENGL::getGizmoViewport() const
196{
197 return m_spheres_gizmo->getViewport();
198}
199
200
201void RENDER_3D_OPENGL::handleGizmoMouseInput( int mouseX, int mouseY )
202{
203 m_spheres_gizmo->handleMouseInput( mouseX, mouseY );
204}
205
206
208{
209 m_materials = {};
210
211 // http://devernay.free.fr/cours/opengl/materials.html
212
213 // Plated copper
214 // Copper material mixed with the copper color
215 m_materials.m_Copper.m_Ambient = SFVEC3F( m_boardAdapter.m_CopperColor.r * 0.1f,
216 m_boardAdapter.m_CopperColor.g * 0.1f,
217 m_boardAdapter.m_CopperColor.b * 0.1f);
218
219 m_materials.m_Copper.m_Specular = SFVEC3F( m_boardAdapter.m_CopperColor.r * 0.75f + 0.25f,
220 m_boardAdapter.m_CopperColor.g * 0.75f + 0.25f,
221 m_boardAdapter.m_CopperColor.b * 0.75f + 0.25f );
222
223 // This guess the material type(ex: copper vs gold) to determine the
224 // shininess factor between 0.1 and 0.4
225 float shininessfactor = 0.40f - mapf( fabs( m_boardAdapter.m_CopperColor.r -
226 m_boardAdapter.m_CopperColor.g ),
227 0.15f, 1.00f,
228 0.00f, 0.30f );
229
230 m_materials.m_Copper.m_Shininess = shininessfactor * 128.0f;
231 m_materials.m_Copper.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
232
233
234 // Non plated copper (raw copper)
235 m_materials.m_NonPlatedCopper.m_Ambient = SFVEC3F( 0.191f, 0.073f, 0.022f );
236 m_materials.m_NonPlatedCopper.m_Diffuse = SFVEC3F( 184.0f / 255.0f, 115.0f / 255.0f,
237 50.0f / 255.0f );
238 m_materials.m_NonPlatedCopper.m_Specular = SFVEC3F( 0.256f, 0.137f, 0.086f );
239 m_materials.m_NonPlatedCopper.m_Shininess = 0.1f * 128.0f;
240 m_materials.m_NonPlatedCopper.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
241
242 // Paste material mixed with paste color
243 m_materials.m_Paste.m_Ambient = SFVEC3F( m_boardAdapter.m_SolderPasteColor.r,
244 m_boardAdapter.m_SolderPasteColor.g,
245 m_boardAdapter.m_SolderPasteColor.b );
246
247 m_materials.m_Paste.m_Specular = SFVEC3F( m_boardAdapter.m_SolderPasteColor.r *
248 m_boardAdapter.m_SolderPasteColor.r,
249 m_boardAdapter.m_SolderPasteColor.g *
250 m_boardAdapter.m_SolderPasteColor.g,
251 m_boardAdapter.m_SolderPasteColor.b *
252 m_boardAdapter.m_SolderPasteColor.b );
253
254 m_materials.m_Paste.m_Shininess = 0.1f * 128.0f;
255 m_materials.m_Paste.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
256
257 // Silk screen material mixed with silk screen color
258 m_materials.m_SilkSTop.m_Ambient = SFVEC3F( m_boardAdapter.m_SilkScreenColorTop.r,
259 m_boardAdapter.m_SilkScreenColorTop.g,
260 m_boardAdapter.m_SilkScreenColorTop.b );
261
262 m_materials.m_SilkSTop.m_Specular = SFVEC3F(
263 m_boardAdapter.m_SilkScreenColorTop.r * m_boardAdapter.m_SilkScreenColorTop.r + 0.10f,
264 m_boardAdapter.m_SilkScreenColorTop.g * m_boardAdapter.m_SilkScreenColorTop.g + 0.10f,
265 m_boardAdapter.m_SilkScreenColorTop.b * m_boardAdapter.m_SilkScreenColorTop.b + 0.10f );
266
267 m_materials.m_SilkSTop.m_Shininess = 0.078125f * 128.0f;
268 m_materials.m_SilkSTop.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
269
270 // Silk screen material mixed with silk screen color
271 m_materials.m_SilkSBot.m_Ambient = SFVEC3F( m_boardAdapter.m_SilkScreenColorBot.r,
272 m_boardAdapter.m_SilkScreenColorBot.g,
273 m_boardAdapter.m_SilkScreenColorBot.b );
274
275 m_materials.m_SilkSBot.m_Specular = SFVEC3F(
276 m_boardAdapter.m_SilkScreenColorBot.r * m_boardAdapter.m_SilkScreenColorBot.r + 0.10f,
277 m_boardAdapter.m_SilkScreenColorBot.g * m_boardAdapter.m_SilkScreenColorBot.g + 0.10f,
278 m_boardAdapter.m_SilkScreenColorBot.b * m_boardAdapter.m_SilkScreenColorBot.b + 0.10f );
279
280 m_materials.m_SilkSBot.m_Shininess = 0.078125f * 128.0f;
281 m_materials.m_SilkSBot.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
282
283 // Shininess is computed dynamically in setLayerMaterial() based on color darkness
284 m_materials.m_SolderMask.m_Shininess = 0.85f * 128.0f;
285 m_materials.m_SolderMask.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
286
287 // Epoxy material
288 m_materials.m_EpoxyBoard.m_Ambient = SFVEC3F( 117.0f / 255.0f, 97.0f / 255.0f,
289 47.0f / 255.0f );
290
291 m_materials.m_EpoxyBoard.m_Specular = SFVEC3F( 18.0f / 255.0f, 3.0f / 255.0f,
292 20.0f / 255.0f );
293
294 m_materials.m_EpoxyBoard.m_Shininess = 0.1f * 128.0f;
295 m_materials.m_EpoxyBoard.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
296}
297
298
300{
301 if( m_boardAdapter.GetUseBoardEditorCopperLayerColors() && IsCopperLayer( aLayerID ) )
302 {
303 COLOR4D copper_color = m_boardAdapter.m_BoardEditorColors[aLayerID];
304 m_materials.m_Copper.m_Diffuse = SFVEC3F( copper_color.r, copper_color.g,
305 copper_color.b );
306 OglSetMaterial( m_materials.m_Copper, 1.0f );
307 m_materials.m_NonPlatedCopper.m_Diffuse = m_materials.m_Copper.m_Diffuse;
308 OglSetMaterial( m_materials.m_NonPlatedCopper, 1.0f );
309
310 return;
311 }
312
313 switch( aLayerID )
314 {
315 case F_Mask:
316 case B_Mask:
317 {
318 const SFVEC4F layerColor = aLayerID == F_Mask ? m_boardAdapter.m_SolderMaskColorTop
319 : m_boardAdapter.m_SolderMaskColorBot;
320
321 m_materials.m_SolderMask.m_Diffuse = layerColor;
322
323 // Compute gray value for material property adjustments based on color darkness
324 const float solderMask_gray = ( layerColor.r + layerColor.g + layerColor.b ) / 3.0f;
325
326 // Use TransparencyControl to make darker colors more opaque, preventing copper
327 // show-through on dark solder masks
328 const float baseTransparency = 1.0f - layerColor.a;
329 m_materials.m_SolderMask.m_Transparency = TransparencyControl( solderMask_gray,
330 baseTransparency );
331
332 m_materials.m_SolderMask.m_Ambient = m_materials.m_SolderMask.m_Diffuse * 0.3f;
333
334 // Darker solder masks need a higher specular floor to avoid washed-out appearance
335 const SFVEC3F baseSpecular = m_materials.m_SolderMask.m_Diffuse
336 * m_materials.m_SolderMask.m_Diffuse;
337 m_materials.m_SolderMask.m_Specular = glm::max( baseSpecular, SFVEC3F( 0.30f ) );
338
339 // Darker colors get higher shininess for a tighter specular highlight, matching
340 // how dark solder masks appear in real life
341 const float minSolderMaskShininess = 0.85f * 128.0f;
342 const float maxSolderMaskShininess = 512.0f;
343 m_materials.m_SolderMask.m_Shininess = minSolderMaskShininess
344 + ( maxSolderMaskShininess - minSolderMaskShininess ) * ( 1.0f - solderMask_gray );
345
346 OglSetMaterial( m_materials.m_SolderMask, 1.0f );
347 break;
348 }
349
350 case B_Paste:
351 case F_Paste:
352 m_materials.m_Paste.m_Diffuse = m_boardAdapter.m_SolderPasteColor;
353 OglSetMaterial( m_materials.m_Paste, 1.0f );
354 break;
355
356 case B_SilkS:
357 m_materials.m_SilkSBot.m_Diffuse = m_boardAdapter.m_SilkScreenColorBot;
358 OglSetMaterial( m_materials.m_SilkSBot, 1.0f );
359 break;
360
361 case F_SilkS:
362 m_materials.m_SilkSTop.m_Diffuse = m_boardAdapter.m_SilkScreenColorTop;
363 OglSetMaterial( m_materials.m_SilkSTop, 1.0f );
364 break;
365
366 case B_Adhes:
367 case F_Adhes:
368 case Dwgs_User:
369 case Cmts_User:
370 case Eco1_User:
371 case Eco2_User:
372 case Edge_Cuts:
373 case Margin:
374 case B_CrtYd:
375 case F_CrtYd:
376 case B_Fab:
377 case F_Fab:
378 switch( aLayerID )
379 {
380 case Dwgs_User: m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_UserDrawingsColor; break;
381 case Cmts_User: m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_UserCommentsColor; break;
382 case Eco1_User: m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_ECO1Color; break;
383 case Eco2_User: m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_ECO2Color; break;
384 case Edge_Cuts: m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_UserDrawingsColor; break;
385 case Margin: m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_UserDrawingsColor; break;
386 default:
387 m_materials.m_Plastic.m_Diffuse = m_boardAdapter.GetLayerColor( aLayerID );
388 break;
389 }
390
391 m_materials.m_Plastic.m_Ambient = SFVEC3F( m_materials.m_Plastic.m_Diffuse.r * 0.05f,
392 m_materials.m_Plastic.m_Diffuse.g * 0.05f,
393 m_materials.m_Plastic.m_Diffuse.b * 0.05f );
394
395 m_materials.m_Plastic.m_Specular = SFVEC3F( m_materials.m_Plastic.m_Diffuse.r * 0.7f,
396 m_materials.m_Plastic.m_Diffuse.g * 0.7f,
397 m_materials.m_Plastic.m_Diffuse.b * 0.7f );
398
399 m_materials.m_Plastic.m_Shininess = 0.078125f * 128.0f;
400 m_materials.m_Plastic.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
401 OglSetMaterial( m_materials.m_Plastic, 1.0f );
402 break;
403
404 default:
405 {
406 int layer3D = MapPCBLayerTo3DLayer( aLayerID );
407
408 // Note: MUST do this in LAYER_3D space; User_1..User_45 are NOT contiguous
409 if( layer3D >= LAYER_3D_USER_1 && layer3D <= LAYER_3D_USER_45 )
410 {
411 int user_idx = layer3D - LAYER_3D_USER_1;
412
413 m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_UserDefinedLayerColor[ user_idx ];
414 m_materials.m_Plastic.m_Ambient = SFVEC3F( m_materials.m_Plastic.m_Diffuse.r * 0.05f,
415 m_materials.m_Plastic.m_Diffuse.g * 0.05f,
416 m_materials.m_Plastic.m_Diffuse.b * 0.05f );
417
418 m_materials.m_Plastic.m_Specular = SFVEC3F( m_materials.m_Plastic.m_Diffuse.r * 0.7f,
419 m_materials.m_Plastic.m_Diffuse.g * 0.7f,
420 m_materials.m_Plastic.m_Diffuse.b * 0.7f );
421
422 m_materials.m_Plastic.m_Shininess = 0.078125f * 128.0f;
423 m_materials.m_Plastic.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
424 OglSetMaterial( m_materials.m_Plastic, 1.0f );
425 break;
426 }
427
428 m_materials.m_Copper.m_Diffuse = m_boardAdapter.m_CopperColor;
429 OglSetMaterial( m_materials.m_Copper, 1.0f );
430 break;
431 }
432 }
433}
434
435
437{
438 // Setup light
439 // https://www.opengl.org/sdk/docs/man2/xhtml/glLight.xml
440 const GLfloat ambient[] = { 0.084f, 0.084f, 0.084f, 1.0f };
441 const GLfloat diffuse0[] = { 0.3f, 0.3f, 0.3f, 1.0f };
442 const GLfloat specular0[] = { 0.5f, 0.5f, 0.5f, 1.0f };
443
444 glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
445 glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse0 );
446 glLightfv( GL_LIGHT0, GL_SPECULAR, specular0 );
447
448 const GLfloat diffuse12[] = { 0.7f, 0.7f, 0.7f, 1.0f };
449 const GLfloat specular12[] = { 0.7f, 0.7f, 0.7f, 1.0f };
450
451 // defines a directional light that points along the negative z-axis
452 GLfloat position[4] = { 0.0f, 0.0f, 1.0f, 0.0f };
453
454 // This makes a vector slight not perpendicular with XZ plane
455 const SFVEC3F vectorLight = SphericalToCartesian( glm::pi<float>() * 0.03f,
456 glm::pi<float>() * 0.25f );
457
458 position[0] = vectorLight.x;
459 position[1] = vectorLight.y;
460 position[2] = vectorLight.z;
461
462 glLightfv( GL_LIGHT1, GL_AMBIENT, ambient );
463 glLightfv( GL_LIGHT1, GL_DIFFUSE, diffuse12 );
464 glLightfv( GL_LIGHT1, GL_SPECULAR, specular12 );
465 glLightfv( GL_LIGHT1, GL_POSITION, position );
466
467 // defines a directional light that points along the positive z-axis
468 position[2] = -position[2];
469
470 glLightfv( GL_LIGHT2, GL_AMBIENT, ambient );
471 glLightfv( GL_LIGHT2, GL_DIFFUSE, diffuse12 );
472 glLightfv( GL_LIGHT2, GL_SPECULAR, specular12 );
473 glLightfv( GL_LIGHT2, GL_POSITION, position );
474
475 const GLfloat lmodel_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
476
477 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmodel_ambient );
478
479 glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
480}
481
482
484{
485 OglSetMaterial( m_materials.m_NonPlatedCopper, 1.0f );
486}
487
488
490{
491 glEnable( GL_POLYGON_OFFSET_FILL );
492 glPolygonOffset( -0.1f, -2.0f );
493 setLayerMaterial( aLayer_id );
494}
495
496
498{
499 glDisable( GL_POLYGON_OFFSET_FILL );
500}
501
502
503void RENDER_3D_OPENGL::renderBoardBody( bool aSkipRenderHoles )
504{
505 m_materials.m_EpoxyBoard.m_Diffuse = m_boardAdapter.m_BoardBodyColor;
506
507 // opacity to transparency
508 m_materials.m_EpoxyBoard.m_Transparency = 1.0f - m_boardAdapter.m_BoardBodyColor.a;
509
510 OglSetMaterial( m_materials.m_EpoxyBoard, 1.0f );
511
512 OPENGL_RENDER_LIST* ogl_disp_list = nullptr;
513
514 if( aSkipRenderHoles )
515 ogl_disp_list = m_board;
516 else
517 ogl_disp_list = m_boardWithHoles;
518
519 if( ogl_disp_list )
520 {
521 ogl_disp_list->ApplyScalePosition( -m_boardAdapter.GetBoardBodyThickness() / 2.0f,
522 m_boardAdapter.GetBoardBodyThickness() );
523
524 ogl_disp_list->SetItIsTransparent( true );
525 ogl_disp_list->DrawAll();
526 }
527
528 // Also render post-machining plugs (board material that remains after backdrill/counterbore/countersink)
529 if( !aSkipRenderHoles && m_postMachinePlugs )
530 {
531 m_postMachinePlugs->ApplyScalePosition( -m_boardAdapter.GetBoardBodyThickness() / 2.0f,
532 m_boardAdapter.GetBoardBodyThickness() );
533
534 m_postMachinePlugs->SetItIsTransparent( true );
535 m_postMachinePlugs->DrawAll();
536 }
537}
538
539
540static inline SFVEC4F premultiplyAlpha( const SFVEC4F& aInput )
541{
542 return SFVEC4F( aInput.r * aInput.a, aInput.g * aInput.a, aInput.b * aInput.a, aInput.a );
543}
544
545
546bool RENDER_3D_OPENGL::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
547 REPORTER* aWarningReporter )
548{
549 // Initialize OpenGL
551 {
552 if( !initializeOpenGL() )
553 return false;
554 }
555
557
559 {
560 std::unique_ptr<BUSY_INDICATOR> busy = CreateBusyIndicator();
561
562 if( aStatusReporter )
563 aStatusReporter->Report( _( "Loading..." ) );
564
565 // Careful here!
566 // We are in the middle of rendering and the reload method may show
567 // a dialog box that requires the opengl context for a redraw
568 Pgm().GetGLContextManager()->RunWithoutCtxLock( [this, aStatusReporter, aWarningReporter]()
569 {
570 reload( aStatusReporter, aWarningReporter );
571 } );
572
573 // generate a new 3D grid as the size of the board may had changed
574 m_lastGridType = static_cast<GRID3D_TYPE>( cfg.grid_type );
576 }
577 else
578 {
579 // Check if grid was changed
580 if( cfg.grid_type != m_lastGridType )
581 {
582 // and generate a new one
583 m_lastGridType = static_cast<GRID3D_TYPE>( cfg.grid_type );
585 }
586 }
587
589
590 // Initial setup
591 glDepthFunc( GL_LESS );
592 glEnable( GL_CULL_FACE );
593 glFrontFace( GL_CCW ); // This is the OpenGL default
594 glEnable( GL_NORMALIZE ); // This allow OpenGL to normalize the normals after transformations
595 glViewport( 0, 0, m_windowSize.x, m_windowSize.y );
596
597 if( aIsMoving && cfg.opengl_AA_disableOnMove )
598 glDisable( GL_MULTISAMPLE );
599 else
600 glEnable( GL_MULTISAMPLE );
601
602 // clear color and depth buffers
603 glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
604 glClearDepth( 1.0f );
605 glClearStencil( 0x00 );
606 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
607
609
610 // Draw the background ( rectangle with color gradient)
612 premultiplyAlpha( m_boardAdapter.m_BgColorBot ) );
613
614 glEnable( GL_DEPTH_TEST );
615
616 // Set projection and modelview matrixes
617 glMatrixMode( GL_PROJECTION );
618 glLoadMatrixf( glm::value_ptr( m_camera.GetProjectionMatrix() ) );
619 glMatrixMode( GL_MODELVIEW );
620 glLoadIdentity();
621 glLoadMatrixf( glm::value_ptr( m_camera.GetViewMatrix() ) );
622
623 // Position the headlight
624 setLightFront( true );
625 setLightTop( true );
626 setLightBottom( true );
627
628 glEnable( GL_LIGHTING );
629
630 {
631 const SFVEC3F& cameraPos = m_camera.GetPos();
632
633 // Place the light at a minimum Z so the diffuse factor will not drop
634 // and the board will still look with good light.
635 float zpos;
636
637 if( cameraPos.z > 0.0f )
638 zpos = glm::max( cameraPos.z, 0.5f ) + cameraPos.z * cameraPos.z;
639 else
640 zpos = glm::min( cameraPos.z,-0.5f ) - cameraPos.z * cameraPos.z;
641
642 // This is a point light.
643 const GLfloat headlight_pos[] = { cameraPos.x, cameraPos.y, zpos, 1.0f };
644
645 glLightfv( GL_LIGHT0, GL_POSITION, headlight_pos );
646 }
647
648 bool skipThickness = aIsMoving && cfg.opengl_thickness_disableOnMove;
649 bool skipRenderHoles = aIsMoving && cfg.opengl_holes_disableOnMove;
650 bool skipRenderMicroVias = aIsMoving && cfg.opengl_microvias_disableOnMove;
651 bool showThickness = !skipThickness;
652
653 std::bitset<LAYER_3D_END> layerFlags = m_boardAdapter.GetVisibleLayers();
654
656
657 if( !( skipRenderMicroVias || skipRenderHoles ) && m_microviaHoles )
658 m_microviaHoles->DrawAll();
659
660 if( !skipRenderHoles && m_padHoles )
661 m_padHoles->DrawAll();
662
663 // Display copper and tech layers
664 for( MAP_OGL_DISP_LISTS::const_iterator ii = m_layers.begin(); ii != m_layers.end(); ++ii )
665 {
666 const PCB_LAYER_ID layer = ( PCB_LAYER_ID )( ii->first );
667 bool isSilkLayer = layer == F_SilkS || layer == B_SilkS;
668 bool isMaskLayer = layer == F_Mask || layer == B_Mask;
669 bool isPasteLayer = layer == F_Paste || layer == B_Paste;
670
671 // Mask layers are not processed here because they are a special case
672 if( isMaskLayer )
673 continue;
674
675 // Do not show inner layers when it is displaying the board and board body is opaque
676 // enough: the time to create inner layers can be *really significant*.
677 // So avoid creating them is they are not very visible
678 const double opacity_min = 0.8;
679
680 if( layerFlags.test( LAYER_3D_BOARD ) && m_boardAdapter.m_BoardBodyColor.a > opacity_min )
681 {
682 // generating internal copper layers is time consuming. so skip them
683 // if the board body is masking them (i.e. if the opacity is near 1.0)
684 // B_Cu is layer 2 and all inner layers are higher values
685 if( layer > B_Cu && IsCopperLayer( layer ) )
686 continue;
687 }
688
689 glPushMatrix();
690
691 OPENGL_RENDER_LIST* pLayerDispList = static_cast<OPENGL_RENDER_LIST*>( ii->second );
692
693 if( IsCopperLayer( layer ) )
694 {
695 if( cfg.DifferentiatePlatedCopper() )
697 else
698 setLayerMaterial( layer );
699
700 OPENGL_RENDER_LIST* outerTH = nullptr;
701 OPENGL_RENDER_LIST* viaHoles = nullptr;
702
703 if( !skipRenderHoles )
704 {
705 outerTH = m_outerThroughHoles;
706 viaHoles = m_outerLayerHoles[layer];
707 }
708
709 if( m_antiBoard )
710 m_antiBoard->ApplyScalePosition( pLayerDispList );
711
712 if( outerTH )
713 outerTH->ApplyScalePosition( pLayerDispList );
714
715 pLayerDispList->DrawCulled( showThickness, outerTH, viaHoles, m_antiBoard );
716
717 // Draw plated & offboard pads
718 if( layer == F_Cu && ( m_platedPadsFront || m_offboardPadsFront ) )
719 {
721
723 m_platedPadsFront->DrawCulled( showThickness, outerTH, viaHoles, m_antiBoard );
724
726 m_offboardPadsFront->DrawCulled( showThickness, outerTH, viaHoles );
727 }
728 else if( layer == B_Cu && ( m_platedPadsBack || m_offboardPadsBack ) )
729 {
731
732 if( m_platedPadsBack )
733 m_platedPadsBack->DrawCulled( showThickness, outerTH, viaHoles, m_antiBoard );
734
736 m_offboardPadsBack->DrawCulled( showThickness, outerTH, viaHoles );
737 }
738
740 }
741 else
742 {
743 setLayerMaterial( layer );
744
745 OPENGL_RENDER_LIST* throughHolesOuter = nullptr;
746 OPENGL_RENDER_LIST* anti_board = nullptr;
747 OPENGL_RENDER_LIST* solder_mask = nullptr;
748
749 if( !skipRenderHoles )
750 {
751 if( isSilkLayer && cfg.clip_silk_on_via_annuli )
752 throughHolesOuter = m_outerThroughHoleRings;
753 else
754 throughHolesOuter = m_outerThroughHoles;
755 }
756
757 if( isSilkLayer && cfg.show_off_board_silk )
758 anti_board = nullptr;
759 else if( LSET::PhysicalLayersMask().test( layer ) )
760 anti_board = m_antiBoard;
761
762 if( isSilkLayer && cfg.subtract_mask_from_silk && !cfg.show_off_board_silk )
763 solder_mask = m_layers[ ( layer == B_SilkS) ? B_Mask : F_Mask ];
764
765 if( throughHolesOuter )
766 throughHolesOuter->ApplyScalePosition( pLayerDispList );
767
768 if( anti_board )
769 anti_board->ApplyScalePosition( pLayerDispList );
770
771 if( solder_mask )
772 solder_mask->ApplyScalePosition( pLayerDispList );
773
774 pLayerDispList->DrawCulled( showThickness, solder_mask, throughHolesOuter, anti_board );
775 }
776
777 glPopMatrix();
778 }
779
780 glm::mat4 cameraViewMatrix;
781
782 glGetFloatv( GL_MODELVIEW_MATRIX, glm::value_ptr( cameraViewMatrix ) );
783
784 // Render 3D Models (Non-transparent)
785 renderOpaqueModels( cameraViewMatrix );
786
787 // Display board body
788 if( layerFlags.test( LAYER_3D_BOARD ) )
789 renderBoardBody( skipRenderHoles );
790
791 // Display transparent mask layers
792 if( layerFlags.test( LAYER_3D_SOLDERMASK_TOP )
793 || layerFlags.test( LAYER_3D_SOLDERMASK_BOTTOM ) )
794 {
795 // add a depth buffer offset, it will help to hide some artifacts
796 // on silkscreen where the SolderMask is removed
797 glEnable( GL_POLYGON_OFFSET_FILL );
798 glPolygonOffset( 0.0f, -2.0f );
799
800 if( m_camera.GetPos().z > 0 )
801 {
802 if( layerFlags.test( LAYER_3D_SOLDERMASK_BOTTOM ) )
803 {
805 showThickness, skipRenderHoles );
806 }
807
808 if( layerFlags.test( LAYER_3D_SOLDERMASK_TOP ) )
809 {
810 renderSolderMaskLayer( F_Mask, m_boardAdapter.GetLayerBottomZPos( F_Mask ),
811 showThickness, skipRenderHoles );
812 }
813 }
814 else
815 {
816 if( layerFlags.test( LAYER_3D_SOLDERMASK_TOP ) )
817 {
818 renderSolderMaskLayer( F_Mask, m_boardAdapter.GetLayerBottomZPos( F_Mask ),
819 showThickness, skipRenderHoles );
820 }
821
822 if( layerFlags.test( LAYER_3D_SOLDERMASK_BOTTOM ) )
823 {
825 showThickness, skipRenderHoles );
826 }
827 }
828
829 glDisable( GL_POLYGON_OFFSET_FILL );
830 glPolygonOffset( 0.0f, 0.0f );
831 }
832
833 // Render 3D Models (Transparent)
834 // !TODO: this can be optimized. If there are no transparent models (or no opacity),
835 // then there is no need to make this function call.
836 glDepthMask( GL_FALSE );
837 glEnable( GL_BLEND );
838 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
839
840 // Enables Texture Env so it can combine model transparency with each footprint opacity
841 glEnable( GL_TEXTURE_2D );
842 glActiveTexture( GL_TEXTURE0 );
843
844 // Uses an existent texture so the glTexEnv operations will work.
845 glBindTexture( GL_TEXTURE_2D, m_circleTexture );
846
847 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
848 glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE );
849 glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE );
850
851 glTexEnvi( GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PRIMARY_COLOR );
852 glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR );
853
854 glTexEnvi( GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS );
855 glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR );
856
857 glTexEnvi( GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PRIMARY_COLOR );
858 glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA );
859 glTexEnvi( GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_CONSTANT );
860 glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA );
861
862 renderTransparentModels( cameraViewMatrix );
863
864 glDisable( GL_BLEND );
866
867 glDepthMask( GL_TRUE );
868
869 // Render Grid
870 if( cfg.grid_type != GRID3D_TYPE::NONE )
871 {
872 glDisable( GL_LIGHTING );
873
874 if( glIsList( m_grid ) )
875 glCallList( m_grid );
876
877 glEnable( GL_LIGHTING );
878 }
879
880 // Render 3D arrows
881 if( cfg.show_navigator )
882 m_spheres_gizmo->render3dSpheresGizmo( m_camera.GetRotationMatrix() );
883
884 // Return back to the original viewport (this is important if we want
885 // to take a screenshot after the render)
886 glViewport( 0, 0, m_windowSize.x, m_windowSize.y );
887
888 return false;
889}
890
891
893{
894 glEnable( GL_LINE_SMOOTH );
895 glShadeModel( GL_SMOOTH );
896
897 // 4-byte pixel alignment
898 glPixelStorei( GL_UNPACK_ALIGNMENT, 4 );
899
900 // Initialize the open GL texture to draw the filled semi-circle of the segments
902
903 if( !circleImage )
904 return false;
905
906 unsigned int circleRadius = ( SIZE_OF_CIRCLE_TEXTURE / 2 ) - 4;
907
908 circleImage->CircleFilled( ( SIZE_OF_CIRCLE_TEXTURE / 2 ) - 0,
909 ( SIZE_OF_CIRCLE_TEXTURE / 2 ) - 0,
910 circleRadius,
911 0xFF );
912
913 IMAGE* circleImageBlured = new IMAGE( circleImage->GetWidth(), circleImage->GetHeight() );
914
915 circleImageBlured->EfxFilter_SkipCenter( circleImage, IMAGE_FILTER::GAUSSIAN_BLUR, circleRadius - 8 );
916
917 m_circleTexture = OglLoadTexture( *circleImageBlured );
918
919 delete circleImageBlured;
920 circleImageBlured = nullptr;
921
922 delete circleImage;
923 circleImage = nullptr;
924
925 init_lights();
926
927 // Use this mode if you want see the triangle lines (debug proposes)
928 //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
929 m_canvasInitialized = true;
930
931 return true;
932}
933
934
936{
937 glEnable( GL_COLOR_MATERIAL );
938 glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
939
940 const SFVEC4F ambient = SFVEC4F( 0.0f, 0.0f, 0.0f, 1.0f );
941 const SFVEC4F diffuse = SFVEC4F( 0.0f, 0.0f, 0.0f, 1.0f );
942 const SFVEC4F emissive = SFVEC4F( 0.0f, 0.0f, 0.0f, 1.0f );
943 const SFVEC4F specular = SFVEC4F( 0.1f, 0.1f, 0.1f, 1.0f );
944
945 glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r );
946 glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 96.0f );
947
948 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r );
949 glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r );
950 glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, &emissive.r );
951}
952
953
955{
956#define DELETE_AND_FREE( ptr ) \
957 { \
958 delete ptr; \
959 ptr = nullptr; \
960 } \
961
962#define DELETE_AND_FREE_MAP( map ) \
963 { \
964 for( auto& [ layer, ptr ] : map ) \
965 delete ptr; \
966 \
967 map.clear(); \
968 }
969
970 if( glIsList( m_grid ) )
971 glDeleteLists( m_grid, 1 );
972
973 m_grid = 0;
974
976
981
984
986 delete list;
987
988 m_triangles.clear();
989
991
992 m_3dModelMatrixMap.clear();
993
998
1002
1008}
1009
1010
1012 bool aShowThickness, bool aSkipRenderHoles )
1013{
1014 wxASSERT( (aLayerID == B_Mask) || (aLayerID == F_Mask) );
1015
1016 if( m_board )
1017 {
1018 OPENGL_RENDER_LIST* solder_mask = m_layers[ aLayerID ];
1019 OPENGL_RENDER_LIST* via_holes = aSkipRenderHoles ? nullptr : m_outerThroughHoles;
1020
1021 if( via_holes )
1022 via_holes->ApplyScalePosition( aZPos, m_boardAdapter.GetNonCopperLayerThickness() );
1023
1024 m_board->ApplyScalePosition( aZPos, m_boardAdapter.GetNonCopperLayerThickness() );
1025
1026 setLayerMaterial( aLayerID );
1027 m_board->SetItIsTransparent( true );
1028 m_board->DrawCulled( aShowThickness, solder_mask, via_holes );
1029
1030 if( aLayerID == F_Mask && m_viaFrontCover )
1031 {
1032 m_viaFrontCover->ApplyScalePosition( aZPos, 4 * m_boardAdapter.GetNonCopperLayerThickness() );
1033 m_viaFrontCover->DrawTop();
1034 }
1035 else if( aLayerID == B_Mask && m_viaBackCover )
1036 {
1037 m_viaBackCover->ApplyScalePosition( aZPos, 4 * m_boardAdapter.GetNonCopperLayerThickness() );
1038 m_viaBackCover->DrawBot();
1039 }
1040 }
1041}
1042
1043
1044void RENDER_3D_OPENGL::get3dModelsSelected( std::list<MODELTORENDER> &aDstRenderList, bool aGetTop,
1045 bool aGetBot, bool aRenderTransparentOnly,
1046 bool aRenderSelectedOnly )
1047{
1048 wxASSERT( ( aGetTop == true ) || ( aGetBot == true ) );
1049
1050 if( !m_boardAdapter.GetBoard() )
1051 return;
1052
1054
1055 // Go for all footprints
1056 for( FOOTPRINT* fp : m_boardAdapter.GetBoard()->Footprints() )
1057 {
1058 bool highlight = false;
1059
1060 if( m_boardAdapter.m_IsBoardView )
1061 {
1062 if( fp->IsSelected() )
1063 highlight = true;
1064
1066 highlight = true;
1067
1068 if( aRenderSelectedOnly != highlight )
1069 continue;
1070 }
1071
1072 bool hasModels = !fp->Models().empty();
1073 bool showMissing = m_boardAdapter.m_Cfg->m_Render.show_missing_models;
1074
1075 if( hasModels || showMissing )
1076 {
1077 if( m_boardAdapter.IsFootprintShown( fp ) )
1078 {
1079 const bool isFlipped = fp->IsFlipped();
1080
1081 if( aGetTop == !isFlipped || aGetBot == isFlipped )
1082 get3dModelsFromFootprint( aDstRenderList, fp, aRenderTransparentOnly,
1083 highlight );
1084 }
1085 }
1086 }
1087}
1088
1089
1090void RENDER_3D_OPENGL::get3dModelsFromFootprint( std::list<MODELTORENDER> &aDstRenderList,
1091 const FOOTPRINT* aFootprint,
1092 bool aRenderTransparentOnly, bool aIsSelected )
1093{
1094 if( !aFootprint->Models().empty() )
1095 {
1096 const double zpos = m_boardAdapter.GetFootprintZPos( aFootprint->IsFlipped() );
1097
1098 VECTOR2I pos = aFootprint->GetPosition();
1099
1100 glm::mat4 fpMatrix( 1.0f );
1101
1102 fpMatrix = glm::translate( fpMatrix, SFVEC3F( pos.x * m_boardAdapter.BiuTo3dUnits(),
1103 -pos.y * m_boardAdapter.BiuTo3dUnits(), zpos ) );
1104
1105 if( !aFootprint->GetOrientation().IsZero() )
1106 {
1107 fpMatrix = glm::rotate( fpMatrix, (float) aFootprint->GetOrientation().AsRadians(),
1108 SFVEC3F( 0.0f, 0.0f, 1.0f ) );
1109 }
1110
1111 if( aFootprint->IsFlipped() )
1112 {
1113 fpMatrix = glm::rotate( fpMatrix, glm::pi<float>(), SFVEC3F( 0.0f, 1.0f, 0.0f ) );
1114 fpMatrix = glm::rotate( fpMatrix, glm::pi<float>(), SFVEC3F( 0.0f, 0.0f, 1.0f ) );
1115 }
1116
1117 double modelunit_to_3d_units_factor = m_boardAdapter.BiuTo3dUnits() * UNITS3D_TO_UNITSPCB;
1118
1119 fpMatrix = glm::scale( fpMatrix, SFVEC3F( modelunit_to_3d_units_factor ) );
1120
1121 // Get the list of model files for this model
1122 for( const FP_3DMODEL& sM : aFootprint->Models() )
1123 {
1124 if( !sM.m_Show || sM.m_Filename.empty() )
1125 continue;
1126
1127 // Check if the model is present in our cache map
1128 auto cache_i = m_3dModelMap.find( sM.m_Filename );
1129
1130 if( cache_i == m_3dModelMap.end() )
1131 {
1132 renderPlaceholderForFootprint( aDstRenderList, fpMatrix, aFootprint, aRenderTransparentOnly,
1133 aIsSelected, aRenderTransparentOnly ? sM.m_Opacity : 1.0f );
1134 continue;
1135 }
1136
1137 if( const MODEL_3D* modelPtr = cache_i->second )
1138 {
1139 bool opaque = sM.m_Opacity >= 1.0;
1140
1141 if( ( !aRenderTransparentOnly && modelPtr->HasOpaqueMeshes() && opaque ) ||
1142 ( aRenderTransparentOnly && ( modelPtr->HasTransparentMeshes() || !opaque ) ) )
1143 {
1144 glm::mat4 modelworldMatrix = fpMatrix;
1145
1146 const SFVEC3F offset = SFVEC3F( sM.m_Offset.x, sM.m_Offset.y, sM.m_Offset.z );
1147 const SFVEC3F rotation = SFVEC3F( sM.m_Rotation.x, sM.m_Rotation.y,
1148 sM.m_Rotation.z );
1149 const SFVEC3F scale = SFVEC3F( sM.m_Scale.x, sM.m_Scale.y, sM.m_Scale.z );
1150
1151 std::vector<float> key = { offset.x, offset.y, offset.z,
1152 rotation.x, rotation.y, rotation.z,
1153 scale.x, scale.y, scale.z };
1154
1155 auto it = m_3dModelMatrixMap.find( key );
1156
1157 if( it != m_3dModelMatrixMap.end() )
1158 {
1159 modelworldMatrix *= it->second;
1160 }
1161 else
1162 {
1163 glm::mat4 mtx( 1.0f );
1164 mtx = glm::translate( mtx, offset );
1165 mtx = glm::rotate( mtx, glm::radians( -rotation.z ), { 0.0f, 0.0f, 1.0f } );
1166 mtx = glm::rotate( mtx, glm::radians( -rotation.y ), { 0.0f, 1.0f, 0.0f } );
1167 mtx = glm::rotate( mtx, glm::radians( -rotation.x ), { 1.0f, 0.0f, 0.0f } );
1168 mtx = glm::scale( mtx, scale );
1169 m_3dModelMatrixMap[ key ] = mtx;
1170
1171 modelworldMatrix *= mtx;
1172 }
1173
1174 aDstRenderList.emplace_back( modelworldMatrix, modelPtr,
1175 aRenderTransparentOnly ? sM.m_Opacity : 1.0f,
1176 aRenderTransparentOnly,
1177 aFootprint->IsSelected() || aIsSelected );
1178 }
1179 }
1180 }
1181 }
1182 else
1183 {
1184 const double zpos = m_boardAdapter.GetFootprintZPos( aFootprint->IsFlipped() );
1185
1186 VECTOR2I pos = aFootprint->GetPosition();
1187
1188 glm::mat4 fpMatrix( 1.0f );
1189
1190 fpMatrix = glm::translate( fpMatrix, SFVEC3F( pos.x * m_boardAdapter.BiuTo3dUnits(),
1191 -pos.y * m_boardAdapter.BiuTo3dUnits(), zpos ) );
1192
1193 if( !aFootprint->GetOrientation().IsZero() )
1194 {
1195 fpMatrix = glm::rotate( fpMatrix, (float) aFootprint->GetOrientation().AsRadians(),
1196 SFVEC3F( 0.0f, 0.0f, 1.0f ) );
1197 }
1198
1199 if( aFootprint->IsFlipped() )
1200 {
1201 fpMatrix = glm::rotate( fpMatrix, glm::pi<float>(), SFVEC3F( 0.0f, 1.0f, 0.0f ) );
1202 fpMatrix = glm::rotate( fpMatrix, glm::pi<float>(), SFVEC3F( 0.0f, 0.0f, 1.0f ) );
1203 }
1204
1205 double modelunit_to_3d_units_factor = m_boardAdapter.BiuTo3dUnits() * UNITS3D_TO_UNITSPCB;
1206
1207 fpMatrix = glm::scale( fpMatrix, SFVEC3F( modelunit_to_3d_units_factor ) );
1208
1209 renderPlaceholderForFootprint( aDstRenderList, fpMatrix, aFootprint, aRenderTransparentOnly, aIsSelected,
1210 1.0f );
1211 }
1212}
1213
1214
1215void RENDER_3D_OPENGL::renderPlaceholderForFootprint( std::list<MODELTORENDER>& aDstRenderList,
1216 const glm::mat4& aFpMatrix, const FOOTPRINT* aFootprint,
1217 bool aRenderTransparentOnly, bool aIsSelected, float aOpacity )
1218{
1219 if( !m_boardAdapter.m_Cfg->m_Render.show_missing_models || !m_placeholderModel )
1220 return;
1221
1222 BOX2I localBox = CalcPlaceholderLocalBox( aFootprint );
1223
1224 float bboxW = std::abs( localBox.GetWidth() ) / pcbIUScale.IU_PER_MM * 0.9f;
1225 float bboxH = std::abs( localBox.GetHeight() ) / pcbIUScale.IU_PER_MM * 0.9f;
1226
1227 float scaleX = bboxW;
1228 float scaleY = bboxH;
1229 float scaleZ = std::min( bboxW, bboxH ) * 0.5f;
1230
1231 VECTOR2I localCenter = localBox.GetCenter();
1232 float offsetX = localCenter.x / pcbIUScale.IU_PER_MM;
1233 float offsetY = -localCenter.y / pcbIUScale.IU_PER_MM;
1234 float offsetZ = scaleZ * 0.5f;
1235
1236 if( aFootprint->IsFlipped() )
1237 offsetY = -offsetY;
1238
1239 glm::mat4 mtx = aFpMatrix;
1240 mtx = glm::translate( mtx, SFVEC3F( offsetX, offsetY, offsetZ ) );
1241 mtx = glm::scale( mtx, SFVEC3F( scaleX, scaleY, scaleZ ) );
1242
1243 bool placeholderOpaque = aOpacity >= 1.0;
1244
1245 if( ( !aRenderTransparentOnly && m_placeholderModel->HasOpaqueMeshes() && placeholderOpaque )
1246 || ( aRenderTransparentOnly && ( m_placeholderModel->HasTransparentMeshes() || !placeholderOpaque ) ) )
1247 {
1248 aDstRenderList.emplace_back( mtx, m_placeholderModel, aOpacity, aRenderTransparentOnly,
1249 aFootprint->IsSelected() || aIsSelected );
1250 }
1251}
1252
1253
1254void RENDER_3D_OPENGL::renderOpaqueModels( const glm::mat4 &aCameraViewMatrix )
1255{
1257
1258 const SFVEC3F selColor = m_boardAdapter.GetColor( cfg.opengl_selection_color );
1259
1260 glPushMatrix();
1261
1262 std::list<MODELTORENDER> renderList;
1263
1264 if( m_boardAdapter.m_IsBoardView )
1265 {
1266 renderList.clear();
1267
1268 get3dModelsSelected( renderList, true, true, false, true );
1269
1270 if( !renderList.empty() )
1271 {
1272 MODEL_3D::BeginDrawMulti( false );
1273
1274 for( const MODELTORENDER& mtr : renderList )
1275 renderModel( aCameraViewMatrix, mtr, selColor, nullptr );
1276
1278 }
1279 }
1280
1281 renderList.clear();
1282 get3dModelsSelected( renderList, true, true, false, false );
1283
1284 if( !renderList.empty() )
1285 {
1287
1288 for( const MODELTORENDER& mtr : renderList )
1289 renderModel( aCameraViewMatrix, mtr, selColor, nullptr );
1290
1292 }
1293
1294 glPopMatrix();
1295}
1296
1297
1298void RENDER_3D_OPENGL::renderTransparentModels( const glm::mat4 &aCameraViewMatrix )
1299{
1301
1302 const SFVEC3F selColor = m_boardAdapter.GetColor( cfg.opengl_selection_color );
1303
1304 std::list<MODELTORENDER> renderListModels; // do not clear it until this function returns
1305
1306 if( m_boardAdapter.m_IsBoardView )
1307 {
1308 // Get Transparent Selected
1309 get3dModelsSelected( renderListModels, true, true, true, true );
1310 }
1311
1312 // Get Transparent Not Selected
1313 get3dModelsSelected( renderListModels, true, true, true, false );
1314
1315 if( renderListModels.empty() )
1316 return;
1317
1318 std::vector<std::pair<const MODELTORENDER *, float>> transparentModelList;
1319
1320 transparentModelList.reserve( renderListModels.size() );
1321
1322 // Calculate the distance to the camera for each model
1323 const SFVEC3F &cameraPos = m_camera.GetPos();
1324
1325 for( const MODELTORENDER& mtr : renderListModels )
1326 {
1327 const BBOX_3D& bBox = mtr.m_model->GetBBox();
1328 const SFVEC3F& bBoxCenter = bBox.GetCenter();
1329 const SFVEC3F bBoxWorld = mtr.m_modelWorldMat * glm::vec4( bBoxCenter, 1.0f );
1330
1331 const float distanceToCamera = glm::length( cameraPos - bBoxWorld );
1332
1333 transparentModelList.emplace_back( &mtr, distanceToCamera );
1334 }
1335
1336 // Sort from back to front
1337 std::sort( transparentModelList.begin(), transparentModelList.end(),
1338 [&]( std::pair<const MODELTORENDER *, float>& a,
1339 std::pair<const MODELTORENDER *, float>& b )
1340 {
1341 if( a.second != b.second )
1342 return a.second > b.second;
1343
1344 return a.first > b.first; // use pointers as a last resort
1345 } );
1346
1347 // Start rendering calls
1348 glPushMatrix();
1349
1350 bool isUsingColorInformation = !( transparentModelList.begin()->first->m_isSelected &&
1351 m_boardAdapter.m_IsBoardView );
1352
1353 MODEL_3D::BeginDrawMulti( isUsingColorInformation );
1354
1355 for( const std::pair<const MODELTORENDER *, float>& mtr : transparentModelList )
1356 {
1357 if( m_boardAdapter.m_IsBoardView )
1358 {
1359 // Toggle between using model color or the select color
1360 if( !isUsingColorInformation && !mtr.first->m_isSelected )
1361 {
1362 isUsingColorInformation = true;
1363
1364 glEnableClientState( GL_COLOR_ARRAY );
1365 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1366 glEnable( GL_COLOR_MATERIAL );
1367 }
1368 else if( isUsingColorInformation && mtr.first->m_isSelected )
1369 {
1370 isUsingColorInformation = false;
1371
1372 glDisableClientState( GL_COLOR_ARRAY );
1373 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1374 glDisable( GL_COLOR_MATERIAL );
1375 }
1376 }
1377
1378 // Render model, sort each individuall material group
1379 // by passing cameraPos
1380 renderModel( aCameraViewMatrix, *mtr.first, selColor, &cameraPos );
1381 }
1382
1384
1385 glPopMatrix();
1386}
1387
1388
1389void RENDER_3D_OPENGL::renderModel( const glm::mat4 &aCameraViewMatrix,
1390 const MODELTORENDER &aModelToRender,
1391 const SFVEC3F &aSelColor, const SFVEC3F *aCameraWorldPos )
1392{
1394
1395 const glm::mat4 modelviewMatrix = aCameraViewMatrix * aModelToRender.m_modelWorldMat;
1396
1397 glLoadMatrixf( glm::value_ptr( modelviewMatrix ) );
1398
1399 aModelToRender.m_model->Draw( aModelToRender.m_isTransparent, aModelToRender.m_opacity,
1400 aModelToRender.m_isSelected, aSelColor,
1401 &aModelToRender.m_modelWorldMat, aCameraWorldPos );
1402
1403 if( cfg.show_model_bbox )
1404 {
1405 const bool wasBlendEnabled = glIsEnabled( GL_BLEND );
1406
1407 if( !wasBlendEnabled )
1408 {
1409 glEnable( GL_BLEND );
1410 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1411 }
1412
1413 glDisable( GL_LIGHTING );
1414
1415 glLineWidth( 1 );
1416 aModelToRender.m_model->DrawBboxes();
1417
1418 glLineWidth( 4 );
1419 aModelToRender.m_model->DrawBbox();
1420
1421 glEnable( GL_LIGHTING );
1422
1423 if( !wasBlendEnabled )
1424 glDisable( GL_BLEND );
1425 }
1426}
1427
1428
1430{
1431 if( glIsList( m_grid ) )
1432 glDeleteLists( m_grid, 1 );
1433
1434 m_grid = 0;
1435
1436 if( aGridType == GRID3D_TYPE::NONE )
1437 return;
1438
1439 m_grid = glGenLists( 1 );
1440
1441 if( !glIsList( m_grid ) )
1442 return;
1443
1444 glNewList( m_grid, GL_COMPILE );
1445
1446 glEnable( GL_BLEND );
1447 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1448
1449 const double zpos = 0.0;
1450
1451 // Color of grid lines
1452 const SFVEC3F gridColor = m_boardAdapter.GetColor( DARKGRAY );
1453
1454 // Color of grid lines every 5 lines
1455 const SFVEC3F gridColor_marker = m_boardAdapter.GetColor( LIGHTBLUE );
1456 const double scale = m_boardAdapter.BiuTo3dUnits();
1457 const GLfloat transparency = 0.35f;
1458
1459 double griSizeMM = 0.0;
1460
1461 switch( aGridType )
1462 {
1463 case GRID3D_TYPE::GRID_1MM: griSizeMM = 1.0; break;
1464 case GRID3D_TYPE::GRID_2P5MM: griSizeMM = 2.5; break;
1465 case GRID3D_TYPE::GRID_5MM: griSizeMM = 5.0; break;
1466 case GRID3D_TYPE::GRID_10MM: griSizeMM = 10.0; break;
1467
1468 default:
1469 case GRID3D_TYPE::NONE: return;
1470 }
1471
1472 glNormal3f( 0.0, 0.0, 1.0 );
1473
1474 const VECTOR2I brd_size = m_boardAdapter.GetBoardSize();
1475 VECTOR2I brd_center_pos = m_boardAdapter.GetBoardPos();
1476
1477 brd_center_pos.y = -brd_center_pos.y;
1478
1479 const int xsize = std::max( brd_size.x, pcbIUScale.mmToIU( 100 ) ) * 1.2;
1480 const int ysize = std::max( brd_size.y, pcbIUScale.mmToIU( 100 ) ) * 1.2;
1481
1482 // Grid limits, in 3D units
1483 double xmin = ( brd_center_pos.x - xsize / 2 ) * scale;
1484 double xmax = ( brd_center_pos.x + xsize / 2 ) * scale;
1485 double ymin = ( brd_center_pos.y - ysize / 2 ) * scale;
1486 double ymax = ( brd_center_pos.y + ysize / 2 ) * scale;
1487 double zmin = pcbIUScale.mmToIU( -50 ) * scale;
1488 double zmax = pcbIUScale.mmToIU( 100 ) * scale;
1489
1490 // Set rasterised line width (min value = 1)
1491 glLineWidth( 1 );
1492
1493 // Draw horizontal grid centered on 3D origin (center of the board)
1494 for( int ii = 0; ; ii++ )
1495 {
1496 if( (ii % 5) )
1497 glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency );
1498 else
1499 glColor4f( gridColor_marker.r, gridColor_marker.g, gridColor_marker.b,
1500 transparency );
1501
1502 const int delta = KiROUND( ii * griSizeMM * pcbIUScale.IU_PER_MM );
1503
1504 if( delta <= xsize / 2 ) // Draw grid lines parallel to X axis
1505 {
1506 glBegin( GL_LINES );
1507 glVertex3f( (brd_center_pos.x + delta) * scale, -ymin, zpos );
1508 glVertex3f( (brd_center_pos.x + delta) * scale, -ymax, zpos );
1509 glEnd();
1510
1511 if( ii != 0 )
1512 {
1513 glBegin( GL_LINES );
1514 glVertex3f( (brd_center_pos.x - delta) * scale, -ymin, zpos );
1515 glVertex3f( (brd_center_pos.x - delta) * scale, -ymax, zpos );
1516 glEnd();
1517 }
1518 }
1519
1520 if( delta <= ysize / 2 ) // Draw grid lines parallel to Y axis
1521 {
1522 glBegin( GL_LINES );
1523 glVertex3f( xmin, -( brd_center_pos.y + delta ) * scale, zpos );
1524 glVertex3f( xmax, -( brd_center_pos.y + delta ) * scale, zpos );
1525 glEnd();
1526
1527 if( ii != 0 )
1528 {
1529 glBegin( GL_LINES );
1530 glVertex3f( xmin, -( brd_center_pos.y - delta ) * scale, zpos );
1531 glVertex3f( xmax, -( brd_center_pos.y - delta ) * scale, zpos );
1532 glEnd();
1533 }
1534 }
1535
1536 if( ( delta > ysize / 2 ) && ( delta > xsize / 2 ) )
1537 break;
1538 }
1539
1540 // Draw vertical grid on Z axis
1541 glNormal3f( 0.0, -1.0, 0.0 );
1542
1543 // Draw vertical grid lines (parallel to Z axis)
1544 double posy = -brd_center_pos.y * scale;
1545
1546 for( int ii = 0; ; ii++ )
1547 {
1548 if( (ii % 5) )
1549 glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency );
1550 else
1551 glColor4f( gridColor_marker.r, gridColor_marker.g, gridColor_marker.b,
1552 transparency );
1553
1554 const double delta = ii * griSizeMM * pcbIUScale.IU_PER_MM;
1555
1556 glBegin( GL_LINES );
1557 xmax = ( brd_center_pos.x + delta ) * scale;
1558
1559 glVertex3f( xmax, posy, zmin );
1560 glVertex3f( xmax, posy, zmax );
1561 glEnd();
1562
1563 if( ii != 0 )
1564 {
1565 glBegin( GL_LINES );
1566 xmin = ( brd_center_pos.x - delta ) * scale;
1567 glVertex3f( xmin, posy, zmin );
1568 glVertex3f( xmin, posy, zmax );
1569 glEnd();
1570 }
1571
1572 if( delta > xsize / 2.0f )
1573 break;
1574 }
1575
1576 // Draw horizontal grid lines on Z axis (parallel to X axis)
1577 for( int ii = 0; ; ii++ )
1578 {
1579 if( ii % 5 )
1580 glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency );
1581 else
1582 glColor4f( gridColor_marker.r, gridColor_marker.g, gridColor_marker.b, transparency );
1583
1584 const double delta = ii * griSizeMM * pcbIUScale.IU_PER_MM * scale;
1585
1586 if( delta <= zmax )
1587 {
1588 // Draw grid lines on Z axis (positive Z axis coordinates)
1589 glBegin( GL_LINES );
1590 glVertex3f( xmin, posy, delta );
1591 glVertex3f( xmax, posy, delta );
1592 glEnd();
1593 }
1594
1595 if( delta <= -zmin && ( ii != 0 ) )
1596 {
1597 // Draw grid lines on Z axis (negative Z axis coordinates)
1598 glBegin( GL_LINES );
1599 glVertex3f( xmin, posy, -delta );
1600 glVertex3f( xmax, posy, -delta );
1601 glEnd();
1602 }
1603
1604 if( ( delta > zmax ) && ( delta > -zmin ) )
1605 break;
1606 }
1607
1608 glDisable( GL_BLEND );
1609
1610 glEndList();
1611}
1612
1613
1615{
1616 // Unit cube: 1mm × 1mm × 1mm, centered at origin
1617 static SFVEC3F positions[24] = { // +Z (top)
1618 { -0.5f, -0.5f, 0.5f },
1619 { 0.5f, -0.5f, 0.5f },
1620 { 0.5f, 0.5f, 0.5f },
1621 { -0.5f, 0.5f, 0.5f },
1622
1623 // -Z (bottom)
1624 { -0.5f, 0.5f, -0.5f },
1625 { 0.5f, 0.5f, -0.5f },
1626 { 0.5f, -0.5f, -0.5f },
1627 { -0.5f, -0.5f, -0.5f },
1628
1629 // +X
1630 { 0.5f, -0.5f, -0.5f },
1631 { 0.5f, 0.5f, -0.5f },
1632 { 0.5f, 0.5f, 0.5f },
1633 { 0.5f, -0.5f, 0.5f },
1634
1635 // -X
1636 { -0.5f, -0.5f, 0.5f },
1637 { -0.5f, 0.5f, 0.5f },
1638 { -0.5f, 0.5f, -0.5f },
1639 { -0.5f, -0.5f, -0.5f },
1640
1641 // +Y
1642 { -0.5f, 0.5f, 0.5f },
1643 { 0.5f, 0.5f, 0.5f },
1644 { 0.5f, 0.5f, -0.5f },
1645 { -0.5f, 0.5f, -0.5f },
1646
1647 // -Y
1648 { -0.5f, -0.5f, -0.5f },
1649 { 0.5f, -0.5f, -0.5f },
1650 { 0.5f, -0.5f, 0.5f },
1651 { -0.5f, -0.5f, 0.5f }
1652 };
1653
1654 static SFVEC3F normals[24] = { // +Z
1655 { 0, 0, 1 },
1656 { 0, 0, 1 },
1657 { 0, 0, 1 },
1658 { 0, 0, 1 },
1659 // -Z
1660 { 0, 0, -1 },
1661 { 0, 0, -1 },
1662 { 0, 0, -1 },
1663 { 0, 0, -1 },
1664 // +X
1665 { 1, 0, 0 },
1666 { 1, 0, 0 },
1667 { 1, 0, 0 },
1668 { 1, 0, 0 },
1669 // -X
1670 { -1, 0, 0 },
1671 { -1, 0, 0 },
1672 { -1, 0, 0 },
1673 { -1, 0, 0 },
1674 // +Y
1675 { 0, 1, 0 },
1676 { 0, 1, 0 },
1677 { 0, 1, 0 },
1678 { 0, 1, 0 },
1679 // -Y
1680 { 0, -1, 0 },
1681 { 0, -1, 0 },
1682 { 0, -1, 0 },
1683 { 0, -1, 0 }
1684 };
1685
1686 static unsigned int indices[36] = {
1687 0, 1, 2, 0, 2, 3, // +Z
1688 4, 5, 6, 4, 6, 7, // -Z
1689 8, 9, 10, 8, 10, 11, // +X
1690 12, 13, 14, 12, 14, 15, // -X
1691 16, 17, 18, 16, 18, 19, // +Y
1692 20, 21, 22, 20, 22, 23 // -Y
1693 };
1694
1695 static SMATERIAL material = {
1696 SFVEC3F( 0.2f, 0.1f, 0.0f ), // ambient
1697 SFVEC3F( 1.0f, 0.5f, 0.0f ), // diffuse
1698 SFVEC3F( 0.0f, 0.0f, 0.0f ), // emissive
1699 SFVEC3F( 0.1f, 0.1f, 0.1f ), // specular
1700 0.1f, // shininess
1701 0.4f // transparency
1702 };
1703
1704 static SMESH mesh = { 24, positions, normals, nullptr, nullptr, 36, indices, 0 };
1705
1706 static S3DMODEL model = { 1, &mesh, 1, &material };
1707
1709}
GRID3D_TYPE
Grid types.
Definition 3d_enums.h:54
@ NORMAL
Use all material properties from model file.
Definition 3d_enums.h:72
Defines math related functions.
float mapf(float x, float in_min, float in_max, float out_min, float out_max)
Definition 3d_math.h:133
SFVEC3F SphericalToCartesian(float aInclination, float aAzimuth)
https://en.wikipedia.org/wiki/Spherical_coordinate_system
Definition 3d_math.h:43
BOX2I CalcPlaceholderLocalBox(const FOOTPRINT *aFootprint)
Calculate a local space bounding box for a placeholder 3D model.
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
Helper class to handle information needed to display 3D board.
constexpr size_type GetWidth() const
Definition box2.h:214
constexpr const Vec GetCenter() const
Definition box2.h:230
constexpr size_type GetHeight() const
Definition box2.h:215
A class used to derive camera objects from.
Definition camera.h:103
Implement a canvas based on a wxGLCanvas.
bool IsZero() const
Definition eda_angle.h:136
double AsRadians() const
Definition eda_angle.h:120
bool IsSelected() const
Definition eda_item.h:129
EDA_ANGLE GetOrientation() const
Definition footprint.h:350
bool IsFlipped() const
Definition footprint.h:544
std::vector< FP_3DMODEL > & Models()
Definition footprint.h:343
VECTOR2I GetPosition() const override
Definition footprint.h:347
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.
Definition image.h:90
void CircleFilled(int aCx, int aCy, int aRadius, unsigned char aValue)
Definition image.cpp:173
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.
Definition image.cpp:527
unsigned int GetHeight() const
Definition image.h:214
unsigned int GetWidth() const
Definition image.h:213
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
double r
Red component.
Definition color4d.h:393
double g
Green component.
Definition color4d.h:394
double b
Blue component.
Definition color4d.h:395
static const LSET & PhysicalLayersMask()
Return a mask holding all layers which are physically realized.
Definition lset.cpp:697
void DrawBbox() const
Draw main bounding box of the model.
Definition 3d_model.cpp:571
static void EndDrawMulti()
Cleanup render states after drawing multiple models.
Definition 3d_model.cpp:405
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.
Definition 3d_model.cpp:418
static void BeginDrawMulti(bool aUseColorInformation)
Set some basic render states before drawing multiple models.
Definition 3d_model.cpp:389
void DrawBboxes() const
Draw individual bounding boxes of each mesh.
Definition 3d_model.cpp:590
Store the OpenGL display lists to related with a layer.
void ApplyScalePosition(float aZposition, float aZscale)
void SetItIsTransparent(bool aSetTransparent)
void DrawCulled(bool aDrawMiddle, const OPENGL_RENDER_LIST *aSubtractList=nullptr, const OPENGL_RENDER_LIST *bSubtractList=nullptr, const OPENGL_RENDER_LIST *cSubtractList=nullptr, const OPENGL_RENDER_LIST *dSubtractList=nullptr) const
Draw all layers if they are visible by the camera if camera position is above the layer.
void DrawAll(bool aDrawMiddle=true) const
Call to draw all the display lists.
GL_CONTEXT_MANAGER * GetGLContextManager()
Definition pgm_base.h:120
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.
wxSize m_windowSize
The window size that this camera is working.
BOARD_ADAPTER & m_boardAdapter
Settings reference in use for this render.
OPENGL_RENDER_LIST * m_board
OPENGL_RENDER_LIST * m_outerThroughHoleRings
OPENGL_RENDER_LIST * m_offboardPadsFront
SPHERES_GIZMO::GizmoSphereSelection getSelectedGizmoSphere() const
GRID3D_TYPE m_lastGridType
Stores the last grid type.
std::tuple< int, int, int, int > getGizmoViewport() const
OPENGL_RENDER_LIST * m_microviaHoles
void renderOpaqueModels(const glm::mat4 &aCameraViewMatrix)
void generate3dGrid(GRID3D_TYPE aGridType)
Create a 3D grid to an OpenGL display list.
void setLightFront(bool enabled)
bool Redraw(bool aIsMoving, REPORTER *aStatusReporter, REPORTER *aWarningReporter) override
Redraw the view.
MAP_OGL_DISP_LISTS m_layers
MAP_OGL_DISP_LISTS m_innerLayerHoles
OPENGL_RENDER_LIST * m_boardWithHoles
RENDER_3D_OPENGL(EDA_3D_CANVAS *aCanvas, BOARD_ADAPTER &aAdapter, CAMERA &aCamera)
MAP_OGL_DISP_LISTS m_outerLayerHoles
OPENGL_RENDER_LIST * m_offboardPadsBack
BOARD_ITEM * m_currentRollOverItem
void renderBoardBody(bool aSkipRenderHoles)
std::map< std::vector< float >, glm::mat4 > m_3dModelMatrixMap
std::map< wxString, MODEL_3D * > m_3dModelMap
OPENGL_RENDER_LIST * m_viaBackCover
OPENGL_RENDER_LIST * m_viaFrontCover
LIST_TRIANGLES m_triangles
store pointers so can be deleted latter
OPENGL_RENDER_LIST * m_outerViaThroughHoles
MODEL_3D * m_placeholderModel
OPENGL_RENDER_LIST * m_outerThroughHoles
void setLayerMaterial(PCB_LAYER_ID aLayerID)
OPENGL_RENDER_LIST * m_platedPadsFront
struct RENDER_3D_OPENGL::@136145154067207014164113243162246125147361200233 m_materials
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...
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)
OPENGL_RENDER_LIST * m_postMachinePlugs
Board material plugs for backdrill/counterbore/countersink.
void setPlatedCopperAndDepthOffset(PCB_LAYER_ID aLayer_id)
OPENGL_RENDER_LIST * m_antiBoard
void SetCurWindowSize(const wxSize &aSize) override
Before each render, the canvas will tell the render what is the size of its windows,...
EDA_3D_CANVAS * m_canvas
void renderPlaceholderForFootprint(std::list< MODELTORENDER > &aDstRenderList, const glm::mat4 &aFpMatrix, const FOOTPRINT *aFootprint, bool aRenderTransparentOnly, bool aIsSelected, float aOpacity)
OPENGL_RENDER_LIST * m_padHoles
SPHERES_GIZMO * m_spheres_gizmo
GLuint m_grid
oGL list that stores current grid
OPENGL_RENDER_LIST * m_platedPadsBack
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)
void setLightTop(bool enabled)
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
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.
Store arrays of triangles to be used to create display lists.
@ LIGHTBLUE
Definition color4d.h:62
@ DARKGRAY
Definition color4d.h:46
#define DELETE_AND_FREE_MAP(map)
#define DELETE_AND_FREE(ptr)
#define _(s)
#define UNITS3D_TO_UNITSPCB
Implements a model viewer canvas.
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
@ GAUSSIAN_BLUR
Definition image.h:65
int MapPCBLayerTo3DLayer(PCB_LAYER_ID aLayer)
Definition layer_id.cpp:335
@ LAYER_3D_USER_1
Definition layer_ids.h:569
@ LAYER_3D_SOLDERMASK_TOP
Definition layer_ids.h:562
@ LAYER_3D_SOLDERMASK_BOTTOM
Definition layer_ids.h:561
@ LAYER_3D_BOARD
Definition layer_ids.h:556
@ LAYER_3D_USER_45
Definition layer_ids.h:613
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:679
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ F_CrtYd
Definition layer_ids.h:116
@ B_Adhes
Definition layer_ids.h:103
@ Edge_Cuts
Definition layer_ids.h:112
@ Dwgs_User
Definition layer_ids.h:107
@ F_Paste
Definition layer_ids.h:104
@ Cmts_User
Definition layer_ids.h:108
@ F_Adhes
Definition layer_ids.h:102
@ B_Mask
Definition layer_ids.h:98
@ B_Cu
Definition layer_ids.h:65
@ Eco1_User
Definition layer_ids.h:109
@ F_Mask
Definition layer_ids.h:97
@ B_Paste
Definition layer_ids.h:105
@ F_Fab
Definition layer_ids.h:119
@ Margin
Definition layer_ids.h:113
@ F_SilkS
Definition layer_ids.h:100
@ B_CrtYd
Definition layer_ids.h:115
@ Eco2_User
Definition layer_ids.h:110
@ B_SilkS
Definition layer_ids.h:101
@ F_Cu
Definition layer_ids.h:64
@ B_Fab
Definition layer_ids.h:118
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
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.
Definition ogl_utils.cpp:95
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.
see class PGM_BASE
void init_lights()
static SFVEC4F premultiplyAlpha(const SFVEC4F &aInput)
static float TransparencyControl(float aGrayColorValue, float aTransparency)
Attempt to control the transparency based on the gray value of the color.
#define SIZE_OF_CIRCLE_TEXTURE
const int scale
Manage a bounding box defined by two SFVEC3F min max points.
Definition bbox_3d.h:43
SFVEC3F GetCenter() const
Return the center point of the bounding box.
Definition bbox_3d.cpp:132
bool DifferentiatePlatedCopper()
return true if platted copper aeras and non platted copper areas must be drawn using a different colo...
Store the a model based on meshes and materials.
Definition c3dmodel.h:95
Per-vertex normal/color/texcoors structure.
Definition c3dmodel.h:81
KIBIS_MODEL * model
int delta
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687
glm::vec3 SFVEC3F
Definition xv3d_types.h:44
glm::vec4 SFVEC4F
Definition xv3d_types.h:46