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, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <cstdint>
23#include <kicad_gl/kiglad.h> // Must be included first
24
26#include "render_3d_opengl.h"
28#include "opengl_utils.h"
31#include <board.h>
32#include <footprint.h>
33#include <pcb_3d_body.h>
35#include <3d_math.h>
36#include <glm/geometric.hpp>
37#include <lset.h>
38#include <pgm_base.h>
39#include <math/util.h> // for KiROUND
40#include <base_units.h>
41
42#include <utility>
43#include <vector>
44
45#include <wx/log.h>
46#include <wx/utils.h>
47
48
50 RENDER_3D_BASE( aAdapter, aCamera ),
51 m_canvas( aCanvas )
52{
53 wxLogTrace( m_logTrace, wxT( "RENDER_3D_OPENGL::RENDER_3D_OPENGL" ) );
54
55 m_layers.clear();
56 m_outerLayerHoles.clear();
57 m_innerLayerHoles.clear();
58 m_triangles.clear();
59 m_board = nullptr;
60 m_antiBoard = nullptr;
61
62 m_platedPadsFront = nullptr;
63 m_platedPadsBack = nullptr;
64 m_offboardPadsFront = nullptr;
65 m_offboardPadsBack = nullptr;
66
70 m_complexPlatedHoles = nullptr;
71 m_padHoles = nullptr;
72 m_viaFrontCover = nullptr;
73 m_viaBackCover = nullptr;
74
76 m_grid = 0;
78 m_currentRollOverItem = nullptr;
79 m_boardWithHoles = nullptr;
80 m_postMachinePlugs = nullptr;
81
82 m_3dModelMap.clear();
83
84 m_spheres_gizmo = new SPHERES_GIZMO( 4, 4 );
85}
86
87
89{
90 wxLogTrace( m_logTrace, wxT( "RENDER_3D_OPENGL::~RENDER_3D_OPENGL" ) );
91
93
95
96 m_placeholderModel.reset();
97
99 glDeleteTextures( 1, &m_circleTexture );
100
101 delete m_spheres_gizmo;
102}
103
104
106{
107 return 50; // ms
108}
109
110
111void RENDER_3D_OPENGL::SetCurWindowSize( const wxSize& aSize )
112{
113 if( m_windowSize != aSize )
114 {
115 int viewport[4];
116 int fbWidth, fbHeight;
117 glGetIntegerv( GL_VIEWPORT, viewport );
118
119 m_windowSize = aSize;
120 glViewport( 0, 0, m_windowSize.x, m_windowSize.y );
122 // Initialize here any screen dependent data here
123 }
124}
125
126
128{
129 if( enabled )
130 glEnable( GL_LIGHT0 );
131 else
132 glDisable( GL_LIGHT0 );
133}
134
135
137{
138 if( enabled )
139 glEnable( GL_LIGHT1 );
140 else
141 glDisable( GL_LIGHT1 );
142}
143
144
146{
147 if( enabled )
148 glEnable( GL_LIGHT2 );
149 else
150 glDisable( GL_LIGHT2 );
151}
152
153
155{
156 m_spheres_gizmo->resetSelectedGizmoSphere();
157}
158
159
164
165
166void RENDER_3D_OPENGL::setGizmoViewport( int x, int y, int width, int height )
167{
168 m_spheres_gizmo->setViewport( x, y, width, height );
169}
170
171
172std::tuple<int, int, int, int> RENDER_3D_OPENGL::getGizmoViewport() const
173{
174 return m_spheres_gizmo->getViewport();
175}
176
177
178void RENDER_3D_OPENGL::handleGizmoMouseInput( int mouseX, int mouseY )
179{
180 m_spheres_gizmo->handleMouseInput( mouseX, mouseY );
181}
182
183
184void RENDER_3D_OPENGL::updateGizmoSelection( glm::mat4 aCameraRotationMatrix )
185{
186 m_spheres_gizmo->updateSelection( aCameraRotationMatrix );
187}
188
189
191{
192 m_materials = {};
193
194 // http://devernay.free.fr/cours/opengl/materials.html
195
196 // Plated copper
197 // Copper material mixed with the copper color
198 m_materials.m_Copper.m_Ambient = SFVEC3F( m_boardAdapter.m_CopperColor.r * 0.1f,
199 m_boardAdapter.m_CopperColor.g * 0.1f,
200 m_boardAdapter.m_CopperColor.b * 0.1f);
201
202 m_materials.m_Copper.m_Specular = SFVEC3F( m_boardAdapter.m_CopperColor.r * 0.75f + 0.25f,
203 m_boardAdapter.m_CopperColor.g * 0.75f + 0.25f,
204 m_boardAdapter.m_CopperColor.b * 0.75f + 0.25f );
205
206 // This guess the material type(ex: copper vs gold) to determine the
207 // shininess factor between 0.1 and 0.4
208 float shininessfactor = 0.40f - mapf( fabs( m_boardAdapter.m_CopperColor.r -
209 m_boardAdapter.m_CopperColor.g ),
210 0.15f, 1.00f,
211 0.00f, 0.30f );
212
213 m_materials.m_Copper.m_Shininess = shininessfactor * 128.0f;
214 m_materials.m_Copper.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
215
216
217 // Non plated copper (raw copper)
218 m_materials.m_NonPlatedCopper.m_Ambient = SFVEC3F( 0.191f, 0.073f, 0.022f );
219 m_materials.m_NonPlatedCopper.m_Diffuse = SFVEC3F( 184.0f / 255.0f, 115.0f / 255.0f,
220 50.0f / 255.0f );
221 m_materials.m_NonPlatedCopper.m_Specular = SFVEC3F( 0.256f, 0.137f, 0.086f );
222 m_materials.m_NonPlatedCopper.m_Shininess = 0.1f * 128.0f;
223 m_materials.m_NonPlatedCopper.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
224
225 // Paste material mixed with paste color
226 m_materials.m_Paste.m_Ambient = SFVEC3F( m_boardAdapter.m_SolderPasteColor.r,
227 m_boardAdapter.m_SolderPasteColor.g,
228 m_boardAdapter.m_SolderPasteColor.b );
229
230 m_materials.m_Paste.m_Specular = SFVEC3F( m_boardAdapter.m_SolderPasteColor.r *
231 m_boardAdapter.m_SolderPasteColor.r,
232 m_boardAdapter.m_SolderPasteColor.g *
233 m_boardAdapter.m_SolderPasteColor.g,
234 m_boardAdapter.m_SolderPasteColor.b *
235 m_boardAdapter.m_SolderPasteColor.b );
236
237 m_materials.m_Paste.m_Shininess = 0.1f * 128.0f;
238 m_materials.m_Paste.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
239
240 m_materials.m_Adhesive.m_Ambient = SFVEC3F( m_boardAdapter.m_AdhesiveColor.r,
241 m_boardAdapter.m_AdhesiveColor.g,
242 m_boardAdapter.m_AdhesiveColor.b );
243
244 m_materials.m_Adhesive.m_Specular = SFVEC3F( m_boardAdapter.m_AdhesiveColor.r *
245 m_boardAdapter.m_AdhesiveColor.r,
246 m_boardAdapter.m_AdhesiveColor.g *
247 m_boardAdapter.m_AdhesiveColor.g,
248 m_boardAdapter.m_AdhesiveColor.b *
249 m_boardAdapter.m_AdhesiveColor.b );
250
251 m_materials.m_Adhesive.m_Shininess = 0.1f * 128.0f;
252 m_materials.m_Adhesive.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
253
254
255 // Silk screen material mixed with silk screen color
256 m_materials.m_SilkSTop.m_Ambient = SFVEC3F( m_boardAdapter.m_SilkScreenColorTop.r,
257 m_boardAdapter.m_SilkScreenColorTop.g,
258 m_boardAdapter.m_SilkScreenColorTop.b );
259
260 m_materials.m_SilkSTop.m_Specular = SFVEC3F(
261 m_boardAdapter.m_SilkScreenColorTop.r * m_boardAdapter.m_SilkScreenColorTop.r + 0.10f,
262 m_boardAdapter.m_SilkScreenColorTop.g * m_boardAdapter.m_SilkScreenColorTop.g + 0.10f,
263 m_boardAdapter.m_SilkScreenColorTop.b * m_boardAdapter.m_SilkScreenColorTop.b + 0.10f );
264
265 m_materials.m_SilkSTop.m_Shininess = 0.078125f * 128.0f;
266 m_materials.m_SilkSTop.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
267
268 // Silk screen material mixed with silk screen color
269 m_materials.m_SilkSBot.m_Ambient = SFVEC3F( m_boardAdapter.m_SilkScreenColorBot.r,
270 m_boardAdapter.m_SilkScreenColorBot.g,
271 m_boardAdapter.m_SilkScreenColorBot.b );
272
273 m_materials.m_SilkSBot.m_Specular = SFVEC3F(
274 m_boardAdapter.m_SilkScreenColorBot.r * m_boardAdapter.m_SilkScreenColorBot.r + 0.10f,
275 m_boardAdapter.m_SilkScreenColorBot.g * m_boardAdapter.m_SilkScreenColorBot.g + 0.10f,
276 m_boardAdapter.m_SilkScreenColorBot.b * m_boardAdapter.m_SilkScreenColorBot.b + 0.10f );
277
278 m_materials.m_SilkSBot.m_Shininess = 0.078125f * 128.0f;
279 m_materials.m_SilkSBot.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
280
281 m_materials.m_SolderMask.m_Shininess = 0.8f * 128.0f;
282 m_materials.m_SolderMask.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
283
284 // Epoxy material
285 m_materials.m_EpoxyBoard.m_Ambient = SFVEC3F( 117.0f / 255.0f, 97.0f / 255.0f,
286 47.0f / 255.0f );
287
288 m_materials.m_EpoxyBoard.m_Specular = SFVEC3F( 18.0f / 255.0f, 3.0f / 255.0f,
289 20.0f / 255.0f );
290
291 m_materials.m_EpoxyBoard.m_Shininess = 0.1f * 128.0f;
292 m_materials.m_EpoxyBoard.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
293}
294
295
297{
298 if( m_boardAdapter.GetUseBoardEditorCopperLayerColors() && IsCopperLayer( aLayerID ) )
299 {
300 COLOR4D copper_color = m_boardAdapter.m_BoardEditorColors[aLayerID];
301 m_materials.m_Copper.m_Diffuse = SFVEC3F( copper_color.r, copper_color.g,
302 copper_color.b );
303 OglSetMaterial( m_materials.m_Copper, 1.0f );
304 m_materials.m_NonPlatedCopper.m_Diffuse = m_materials.m_Copper.m_Diffuse;
305 OglSetMaterial( m_materials.m_NonPlatedCopper, 1.0f );
306
307 return;
308 }
309
310 switch( aLayerID )
311 {
312 case F_Mask:
313 case B_Mask:
314 {
315 const SFVEC4F layerColor = aLayerID == F_Mask ? m_boardAdapter.m_SolderMaskColorTop
316 : m_boardAdapter.m_SolderMaskColorBot;
317
318 m_materials.m_SolderMask.m_Diffuse = layerColor;
319
320 // Convert Opacity to Transparency
321 m_materials.m_SolderMask.m_Transparency = 1.0f - layerColor.a;
322
323 m_materials.m_SolderMask.m_Ambient = m_materials.m_SolderMask.m_Diffuse * 0.3f;
324
325 m_materials.m_SolderMask.m_Specular = m_materials.m_SolderMask.m_Diffuse
326 * m_materials.m_SolderMask.m_Diffuse;
327
328 OglSetMaterial( m_materials.m_SolderMask, 1.0f );
329 break;
330 }
331
332 case B_Paste:
333 case F_Paste:
334 m_materials.m_Paste.m_Diffuse = m_boardAdapter.m_SolderPasteColor;
335 OglSetMaterial( m_materials.m_Paste, 1.0f );
336 break;
337
338 case B_SilkS:
339 m_materials.m_SilkSBot.m_Diffuse = m_boardAdapter.m_SilkScreenColorBot;
340 OglSetMaterial( m_materials.m_SilkSBot, 1.0f );
341 break;
342
343 case F_SilkS:
344 m_materials.m_SilkSTop.m_Diffuse = m_boardAdapter.m_SilkScreenColorTop;
345 OglSetMaterial( m_materials.m_SilkSTop, 1.0f );
346 break;
347
348 case B_Adhes:
349 case F_Adhes:
350 m_materials.m_Adhesive.m_Diffuse = m_boardAdapter.m_AdhesiveColor;
351 OglSetMaterial( m_materials.m_Adhesive, 1.0f );
352 break;
353
354 case Dwgs_User:
355 case Cmts_User:
356 case Eco1_User:
357 case Eco2_User:
358 case Edge_Cuts:
359 case Margin:
360 case B_CrtYd:
361 case F_CrtYd:
362 case B_Fab:
363 case F_Fab:
364 switch( aLayerID )
365 {
366 case Dwgs_User: m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_UserDrawingsColor; break;
367 case Cmts_User: m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_UserCommentsColor; break;
368 case Eco1_User: m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_ECO1Color; break;
369 case Eco2_User: m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_ECO2Color; break;
370 case Edge_Cuts: m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_UserDrawingsColor; break;
371 case Margin: m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_UserDrawingsColor; break;
372 case F_Fab: m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_FFabColor; break;
373 case B_Fab: m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_BFabColor; break;
374 case F_CrtYd: m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_FCourtyardColor; break;
375 case B_CrtYd: m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_BCourtyardColor; break;
376 default:
377 m_materials.m_Plastic.m_Diffuse = m_boardAdapter.GetLayerColor( aLayerID );
378 break;
379 }
380
381 m_materials.m_Plastic.m_Ambient = SFVEC3F( m_materials.m_Plastic.m_Diffuse.r * 0.05f,
382 m_materials.m_Plastic.m_Diffuse.g * 0.05f,
383 m_materials.m_Plastic.m_Diffuse.b * 0.05f );
384
385 m_materials.m_Plastic.m_Specular = SFVEC3F( m_materials.m_Plastic.m_Diffuse.r * 0.7f,
386 m_materials.m_Plastic.m_Diffuse.g * 0.7f,
387 m_materials.m_Plastic.m_Diffuse.b * 0.7f );
388
389 m_materials.m_Plastic.m_Shininess = 0.078125f * 128.0f;
390 m_materials.m_Plastic.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
391 OglSetMaterial( m_materials.m_Plastic, 1.0f );
392 break;
393
394 default:
395 {
396 int layer3D = MapPCBLayerTo3DLayer( aLayerID );
397
398 // Note: MUST do this in LAYER_3D space; User_1..User_45 are NOT contiguous
399 if( layer3D >= LAYER_3D_USER_1 && layer3D <= LAYER_3D_USER_45 )
400 {
401 int user_idx = layer3D - LAYER_3D_USER_1;
402
403 m_materials.m_Plastic.m_Diffuse = m_boardAdapter.m_UserDefinedLayerColor[ user_idx ];
404 m_materials.m_Plastic.m_Ambient = SFVEC3F( m_materials.m_Plastic.m_Diffuse.r * 0.05f,
405 m_materials.m_Plastic.m_Diffuse.g * 0.05f,
406 m_materials.m_Plastic.m_Diffuse.b * 0.05f );
407
408 m_materials.m_Plastic.m_Specular = SFVEC3F( m_materials.m_Plastic.m_Diffuse.r * 0.7f,
409 m_materials.m_Plastic.m_Diffuse.g * 0.7f,
410 m_materials.m_Plastic.m_Diffuse.b * 0.7f );
411
412 m_materials.m_Plastic.m_Shininess = 0.078125f * 128.0f;
413 m_materials.m_Plastic.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
414 OglSetMaterial( m_materials.m_Plastic, 1.0f );
415 break;
416 }
417
418 m_materials.m_Copper.m_Diffuse = m_boardAdapter.m_CopperColor;
419 OglSetMaterial( m_materials.m_Copper, 1.0f );
420 break;
421 }
422 }
423}
424
425
427{
428 // Setup light
429 // https://www.opengl.org/sdk/docs/man2/xhtml/glLight.xml
430 const GLfloat ambient[] = { 0.084f, 0.084f, 0.084f, 1.0f };
431 const GLfloat diffuse0[] = { 0.3f, 0.3f, 0.3f, 1.0f };
432 const GLfloat specular0[] = { 0.5f, 0.5f, 0.5f, 1.0f };
433
434 glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
435 glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse0 );
436 glLightfv( GL_LIGHT0, GL_SPECULAR, specular0 );
437
438 const GLfloat diffuse12[] = { 0.7f, 0.7f, 0.7f, 1.0f };
439 const GLfloat specular12[] = { 0.7f, 0.7f, 0.7f, 1.0f };
440
441 // defines a directional light that points along the negative z-axis
442 GLfloat position[4] = { 0.0f, 0.0f, 1.0f, 0.0f };
443
444 // This makes a vector slight not perpendicular with XZ plane
445 const SFVEC3F vectorLight = SphericalToCartesian( glm::pi<float>() * 0.03f,
446 glm::pi<float>() * 0.25f );
447
448 position[0] = vectorLight.x;
449 position[1] = vectorLight.y;
450 position[2] = vectorLight.z;
451
452 glLightfv( GL_LIGHT1, GL_AMBIENT, ambient );
453 glLightfv( GL_LIGHT1, GL_DIFFUSE, diffuse12 );
454 glLightfv( GL_LIGHT1, GL_SPECULAR, specular12 );
455 glLightfv( GL_LIGHT1, GL_POSITION, position );
456
457 // defines a directional light that points along the positive z-axis
458 position[2] = -position[2];
459
460 glLightfv( GL_LIGHT2, GL_AMBIENT, ambient );
461 glLightfv( GL_LIGHT2, GL_DIFFUSE, diffuse12 );
462 glLightfv( GL_LIGHT2, GL_SPECULAR, specular12 );
463 glLightfv( GL_LIGHT2, GL_POSITION, position );
464
465 const GLfloat lmodel_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
466
467 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmodel_ambient );
468
469 glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
470}
471
472
474{
475 OglSetMaterial( m_materials.m_NonPlatedCopper, 1.0f );
476}
477
478
480{
481 glEnable( GL_POLYGON_OFFSET_FILL );
482 glPolygonOffset( -0.1f, -2.0f );
483 setLayerMaterial( aLayer_id );
484}
485
486
488{
489 glDisable( GL_POLYGON_OFFSET_FILL );
490}
491
492
493void RENDER_3D_OPENGL::renderBoardBody( bool aSkipRenderHoles )
494{
495 m_materials.m_EpoxyBoard.m_Diffuse = m_boardAdapter.m_BoardBodyColor;
496
497 // opacity to transparency
498 m_materials.m_EpoxyBoard.m_Transparency = 1.0f - m_boardAdapter.m_BoardBodyColor.a;
499
500 OglSetMaterial( m_materials.m_EpoxyBoard, 1.0f );
501
502 std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> board_disp_list_def = nullptr;
503
504 if( aSkipRenderHoles || !m_boardWithHoles )
505 board_disp_list_def = m_board;
506 else
507 board_disp_list_def = m_boardWithHoles;
508
509 if( board_disp_list_def )
510 {
511 // Constructs the actual OpenGL render list with correct GL context we're in
512 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_disp_list = board_disp_list_def->MakeOrGet() )
513 {
514 ogl_disp_list->ApplyScalePosition( -m_boardAdapter.GetBoardBodyThickness() / 2.0f,
515 m_boardAdapter.GetBoardBodyThickness() );
516
517 ogl_disp_list->SetItIsTransparent( true );
518 ogl_disp_list->DrawAll();
519 }
520 }
521
522 // Also render post-machining plugs (board material that remains after backdrill/counterbore/countersink)
523 if( !aSkipRenderHoles && m_postMachinePlugs )
524 {
525 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_disp_list = m_postMachinePlugs->MakeOrGet() )
526 {
527 ogl_disp_list->ApplyScalePosition( -m_boardAdapter.GetBoardBodyThickness() / 2.0f,
528 m_boardAdapter.GetBoardBodyThickness() );
529
530 ogl_disp_list->SetItIsTransparent( true );
531 ogl_disp_list->DrawAll();
532 }
533 }
534}
535
536
537static inline SFVEC4F premultiplyAlpha( const SFVEC4F& aInput )
538{
539 return SFVEC4F( aInput.r * aInput.a, aInput.g * aInput.a, aInput.b * aInput.a, aInput.a );
540}
541
542
543bool RENDER_3D_OPENGL::Redraw( bool aIsMoving )
544{
545 // Initialize OpenGL
547 {
548 if( !initializeOpenGL() )
549 return false;
550 }
551
553
554 const bool reloadRequested = m_reloadRequested;
555
556 if( reloadRequested )
557 {
558 std::unique_ptr<BUSY_INDICATOR> busy = CreateBusyIndicator();
559
561 m_activityReporter->Report( _( "Loading..." ) );
562
563 // Careful here!
564 // We are in the middle of rendering and the reload method may show
565 // a dialog box that requires the opengl context for a redraw.
566 //
567 // reload() runs outside m_renderMutex: it stops/joins the previous
568 // background worker, and that worker needs the mutex to publish
569 // intermediate results before it can exit.
571 {
572 reload();
573 } );
574 }
575
576 const GRID3D_TYPE gridType = static_cast<GRID3D_TYPE>( cfg.grid_type );
577
578 // Regenerate after reload (board size may have changed) or when the grid type setting changes.
579 if( reloadRequested || gridType != m_lastGridType )
580 {
581 m_lastGridType = gridType;
583 }
584
586
587 std::lock_guard<std::recursive_mutex> lock( m_renderMutex );
588
590
591 // Initial setup
592 glDepthFunc( GL_LESS );
593 glEnable( GL_CULL_FACE );
594 glFrontFace( GL_CCW ); // This is the OpenGL default
595 glEnable( GL_NORMALIZE ); // This allow OpenGL to normalize the normals after transformations
596 glViewport( 0, 0, m_windowSize.x, m_windowSize.y );
597
598 if( aIsMoving && cfg.opengl_AA_disableOnMove )
599 glDisable( GL_MULTISAMPLE );
600 else
601 glEnable( GL_MULTISAMPLE );
602
603 // clear color and depth buffers
604 glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
605 glClearDepth( 1.0f );
606 glClearStencil( 0x00 );
607 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
608
610
611 // Draw the background ( rectangle with color gradient)
613 premultiplyAlpha( m_boardAdapter.m_BgColorBot ) );
614
615 glEnable( GL_DEPTH_TEST );
616
617 // Set projection and modelview matrixes
618 glMatrixMode( GL_PROJECTION );
619 glLoadMatrixf( glm::value_ptr( m_camera.GetProjectionMatrix() ) );
620 glMatrixMode( GL_MODELVIEW );
621 glLoadIdentity();
622 glLoadMatrixf( glm::value_ptr( m_camera.GetViewMatrix() ) );
623
624 // Position the headlight
625 setLightFront( true );
626 setLightTop( true );
627 setLightBottom( true );
628
629 glEnable( GL_LIGHTING );
630
631 {
632 const SFVEC3F& cameraPos = m_camera.GetPos();
633
634 // Place the light at a minimum Z so the diffuse factor will not drop
635 // and the board will still look with good light.
636 float zpos;
637
638 if( cameraPos.z > 0.0f )
639 zpos = glm::max( cameraPos.z, 0.5f ) + cameraPos.z * cameraPos.z;
640 else
641 zpos = glm::min( cameraPos.z,-0.5f ) - cameraPos.z * cameraPos.z;
642
643 // This is a point light.
644 const GLfloat headlight_pos[] = { cameraPos.x, cameraPos.y, zpos, 1.0f };
645
646 glLightfv( GL_LIGHT0, GL_POSITION, headlight_pos );
647 }
648
649 bool skipThickness = aIsMoving && cfg.opengl_thickness_disableOnMove;
650 bool skipRenderHoles = aIsMoving && cfg.opengl_holes_disableOnMove;
651 bool skipRenderComplexHoles = aIsMoving && cfg.opengl_microvias_disableOnMove;
652 bool showThickness = !skipThickness;
653
654 std::bitset<LAYER_3D_END> layerFlags = m_boardAdapter.GetVisibleLayers();
655
657
658 if( !( skipRenderComplexHoles || skipRenderHoles ) && m_complexPlatedHoles )
659 {
660 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_disp_list = m_complexPlatedHoles->MakeOrGet() )
661 ogl_disp_list->DrawAll();
662 }
663
664 if( !skipRenderHoles && m_padHoles )
665 {
666 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_disp_list = m_padHoles->MakeOrGet() )
667 ogl_disp_list->DrawAll();
668 }
669
670 // Display copper and tech layers
671 for( MAP_OGL_DISP_LISTS::const_iterator ii = m_layers.begin(); ii != m_layers.end(); ++ii )
672 {
673 const PCB_LAYER_ID layer = ( PCB_LAYER_ID )( ii->first );
674 bool isSilkLayer = layer == F_SilkS || layer == B_SilkS;
675 bool isMaskLayer = layer == F_Mask || layer == B_Mask;
676 bool isPasteLayer = layer == F_Paste || layer == B_Paste;
677
678 // Mask layers are not processed here because they are a special case
679 if( isMaskLayer )
680 continue;
681
682 // Do not show inner layers when it is displaying the board and board body is opaque
683 // enough: the time to create inner layers can be *really significant*.
684 // So avoid creating them is they are not very visible
685 const double opacity_min = 0.8;
686
687 if( layerFlags.test( LAYER_3D_BOARD ) && m_boardAdapter.m_BoardBodyColor.a > opacity_min )
688 {
689 // generating internal copper layers is time consuming. so skip them
690 // if the board body is masking them (i.e. if the opacity is near 1.0)
691 // B_Cu is layer 2 and all inner layers are higher values
692 if( layer > B_Cu && IsCopperLayer( layer ) )
693 continue;
694 }
695
696 glPushMatrix();
697
698 std::shared_ptr<OPENGL_RENDER_LIST_DEFERRED> pLayerDispListDef = ii->second;
699 std::shared_ptr<OPENGL_RENDER_LIST> pLayerDispList = pLayerDispListDef->MakeOrGet();
700
701 if( IsCopperLayer( layer ) )
702 {
703 if( cfg.DifferentiatePlatedCopper() )
705 else
706 setLayerMaterial( layer );
707
708 std::shared_ptr<OPENGL_RENDER_LIST> anti_board = m_antiBoard ? m_antiBoard->MakeOrGet() : nullptr;
709
710 std::shared_ptr<OPENGL_RENDER_LIST> outerTH = nullptr;
711 std::shared_ptr<OPENGL_RENDER_LIST> viaHoles = nullptr;
712
713 if( !skipRenderHoles )
714 {
715 if( IsFrontLayer( layer ) )
716 outerTH = m_frontOuterThroughHoles ? m_frontOuterThroughHoles->MakeOrGet() : nullptr;
717 else
718 outerTH = m_backOuterThroughHoles ? m_backOuterThroughHoles->MakeOrGet() : nullptr;
719
720 viaHoles = m_outerLayerHoles[layer] ? m_outerLayerHoles[layer]->MakeOrGet() : nullptr;
721 }
722
723 if( anti_board )
724 anti_board->ApplyScalePosition( pLayerDispList );
725
726 if( outerTH )
727 outerTH->ApplyScalePosition( pLayerDispList );
728
729 pLayerDispList->DrawCulled( showThickness, outerTH, viaHoles, anti_board );
730
731 // Draw plated & offboard pads
732 if( layer == F_Cu && ( m_platedPadsFront || m_offboardPadsFront ) )
733 {
735
737 {
738 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_disp_list = m_platedPadsFront->MakeOrGet() )
739 ogl_disp_list->DrawCulled( showThickness, outerTH, viaHoles, anti_board );
740 }
741
743 {
744 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_disp_list = m_offboardPadsFront->MakeOrGet() )
745 ogl_disp_list->DrawCulled( showThickness, outerTH, viaHoles );
746 }
747 }
748 else if( layer == B_Cu && ( m_platedPadsBack || m_offboardPadsBack ) )
749 {
751
752 if( m_platedPadsBack )
753 {
754 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_disp_list = m_platedPadsBack->MakeOrGet() )
755 ogl_disp_list->DrawCulled( showThickness, outerTH, viaHoles, anti_board );
756 }
757
759 {
760 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_disp_list = m_offboardPadsBack->MakeOrGet() )
761 ogl_disp_list->DrawCulled( showThickness, outerTH, viaHoles );
762 }
763 }
764
766 }
767 else
768 {
769 setLayerMaterial( layer );
770
771 std::shared_ptr<OPENGL_RENDER_LIST> throughHolesOuter = nullptr;
772 std::shared_ptr<OPENGL_RENDER_LIST> anti_board = nullptr;
773 std::shared_ptr<OPENGL_RENDER_LIST> solder_mask = nullptr;
774
775 if( !skipRenderHoles )
776 {
777 if( isSilkLayer && cfg.clip_silk_on_via_annuli )
778 throughHolesOuter = m_outerThroughHoleRings ? m_outerThroughHoleRings->MakeOrGet() : nullptr;
779 else if( IsFrontLayer( layer ) )
780 throughHolesOuter = m_frontOuterThroughHoles ? m_frontOuterThroughHoles->MakeOrGet() : nullptr;
781 else
782 throughHolesOuter = m_backOuterThroughHoles ? m_backOuterThroughHoles->MakeOrGet() : nullptr;
783 }
784
785 if( isSilkLayer && cfg.show_off_board_silk )
786 anti_board = nullptr;
787 else if( LSET::PhysicalLayersMask().test( layer ) )
788 anti_board = m_antiBoard ? m_antiBoard->MakeOrGet() : nullptr;
789
790 if( isSilkLayer && cfg.subtract_mask_from_silk && !cfg.show_off_board_silk )
791 {
792 PCB_LAYER_ID maskLayer = ( layer == B_SilkS ) ? B_Mask : F_Mask;
793 solder_mask = m_layers[maskLayer] ? m_layers[maskLayer]->MakeOrGet() : nullptr;
794 }
795
796 if( throughHolesOuter )
797 throughHolesOuter->ApplyScalePosition( pLayerDispList );
798
799 if( anti_board )
800 anti_board->ApplyScalePosition( pLayerDispList );
801
802 if( solder_mask )
803 solder_mask->ApplyScalePosition( pLayerDispList );
804
805 // Offset non-copper layers slightly closer to the screen than soldermask to avoid Z-fighting.
806 glEnable( GL_POLYGON_OFFSET_FILL );
807 glPolygonOffset( 0.0f, -4.0f );
808
809 pLayerDispList->DrawCulled( showThickness, solder_mask, throughHolesOuter, anti_board );
810
811 glDisable( GL_POLYGON_OFFSET_FILL );
812 glPolygonOffset( 0.0f, 0.0f );
813 }
814
815 glPopMatrix();
816 }
817
818 glm::mat4 cameraViewMatrix;
819
820 glGetFloatv( GL_MODELVIEW_MATRIX, glm::value_ptr( cameraViewMatrix ) );
821
822 // Render 3D Models (Non-transparent)
823 renderOpaqueModels( cameraViewMatrix );
824
825 // Render extruded 3D bodies
826 {
828 const SFVEC3F extSelColor = m_boardAdapter.GetColor( extCfg.opengl_selection_color );
829
830 // Render extruded pad standoffs (metallic pins)
831 for( auto& [fp, renderListDef] : m_extrudedPadLists )
832 {
833 if( !renderListDef )
834 continue;
835
836 std::shared_ptr<OPENGL_RENDER_LIST> renderList = renderListDef->MakeOrGet();
837
838 if( !renderList )
839 continue;
840
841 bool highlight = false;
842
843 if( m_boardAdapter.m_IsBoardView )
844 {
845 if( fp->IsSelected() )
846 highlight = true;
847
848 if( extCfg.highlight_on_rollover && fp == m_currentRollOverItem )
849 highlight = true;
850 }
851
852 SMATERIAL mat = m_materials.m_Copper;
853 mat.m_Diffuse = SFVEC3F( 0.75f, 0.75f, 0.75f );
854 mat.m_Specular = SFVEC3F( 0.85f, 0.85f, 0.85f );
855 mat.m_Shininess = 0.6f * 128.0f;
856 mat.m_Transparency = 0.0f;
857
858 OglSetMaterial( mat, 1.0f, highlight, extSelColor );
859 renderList->DrawAll();
860 }
861
862 renderExtrudedBodies( false );
863 }
864
865 // Display board body
866 if( layerFlags.test( LAYER_3D_BOARD ) )
867 {
868 // Make the board body appear further from the screen
869 // to avoid Z-fighting with copper items.
870 glEnable( GL_POLYGON_OFFSET_FILL );
871 glPolygonOffset( 0.0f, 2.0f );
872
873 renderBoardBody( skipRenderHoles );
874
875 glDisable( GL_POLYGON_OFFSET_FILL );
876 glPolygonOffset( 0.0f, 0.0f );
877 }
878
879 // Display transparent mask layers
880 if( layerFlags.test( LAYER_3D_SOLDERMASK_TOP )
881 || layerFlags.test( LAYER_3D_SOLDERMASK_BOTTOM ) )
882 {
883 // Make the soldermask appear closer to the screen
884 // to avoid Z-fighting with copper items
885 glEnable( GL_POLYGON_OFFSET_FILL );
886 glPolygonOffset( 0.0f, -2.0f );
887
888 if( m_camera.GetPos().z > 0 )
889 {
890 if( layerFlags.test( LAYER_3D_SOLDERMASK_BOTTOM ) )
891 {
893 showThickness, skipRenderHoles );
894 }
895
896 if( layerFlags.test( LAYER_3D_SOLDERMASK_TOP ) )
897 {
898 renderSolderMaskLayer( F_Mask, m_boardAdapter.GetLayerBottomZPos( F_Mask ),
899 showThickness, skipRenderHoles );
900 }
901 }
902 else
903 {
904 if( layerFlags.test( LAYER_3D_SOLDERMASK_TOP ) )
905 {
906 renderSolderMaskLayer( F_Mask, m_boardAdapter.GetLayerBottomZPos( F_Mask ),
907 showThickness, skipRenderHoles );
908 }
909
910 if( layerFlags.test( LAYER_3D_SOLDERMASK_BOTTOM ) )
911 {
913 showThickness, skipRenderHoles );
914 }
915 }
916
917 glDisable( GL_POLYGON_OFFSET_FILL );
918 glPolygonOffset( 0.0f, 0.0f );
919 }
920
921 // Render 3D Models (Transparent)
922 // !TODO: this can be optimized. If there are no transparent models (or no opacity),
923 // then there is no need to make this function call.
924 glDepthMask( GL_FALSE );
925 glEnable( GL_BLEND );
926 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
927
928 // Enables Texture Env so it can combine model transparency with each footprint opacity
929 glEnable( GL_TEXTURE_2D );
930 glActiveTexture( GL_TEXTURE0 );
931
932 // Uses an existent texture so the glTexEnv operations will work.
933 glBindTexture( GL_TEXTURE_2D, m_circleTexture );
934
935 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
936 glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE );
937 glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE );
938
939 glTexEnvi( GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PRIMARY_COLOR );
940 glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR );
941
942 glTexEnvi( GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS );
943 glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR );
944
945 glTexEnvi( GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PRIMARY_COLOR );
946 glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA );
947 glTexEnvi( GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_CONSTANT );
948 glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA );
949
950 renderTransparentModels( cameraViewMatrix );
951
952 glDisable( GL_BLEND );
954
955 glEnable( GL_BLEND );
956 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
957
958 renderExtrudedBodies( true );
959
960 glDisable( GL_BLEND );
961
962 glDepthMask( GL_TRUE );
963
964 // Render Grid
965 if( cfg.grid_type != GRID3D_TYPE::NONE )
966 {
967 glDisable( GL_LIGHTING );
968
969 if( glIsList( m_grid ) )
970 glCallList( m_grid );
971
972 glEnable( GL_LIGHTING );
973 }
974
975 // Render 3D arrows
976 if( cfg.show_navigator )
977 m_spheres_gizmo->render3dSpheresGizmo( m_camera.GetRotationMatrix() );
978
979 // Return back to the original viewport (this is important if we want
980 // to take a screenshot after the render)
981 glViewport( 0, 0, m_windowSize.x, m_windowSize.y );
982
983 return false;
984}
985
986
988{
989 glEnable( GL_LINE_SMOOTH );
990 glShadeModel( GL_SMOOTH );
991
992 // 4-byte pixel alignment
993 glPixelStorei( GL_UNPACK_ALIGNMENT, 4 );
994
995 // Initialize the open GL texture to draw the filled semi-circle of the segments
997
998 if( !circleImage )
999 return false;
1000
1001 unsigned int circleRadius = ( SIZE_OF_CIRCLE_TEXTURE / 2 ) - 4;
1002
1003 circleImage->CircleFilled( ( SIZE_OF_CIRCLE_TEXTURE / 2 ) - 0,
1004 ( SIZE_OF_CIRCLE_TEXTURE / 2 ) - 0,
1005 circleRadius,
1006 0xFF );
1007
1008 IMAGE* circleImageBlured = new IMAGE( circleImage->GetWidth(), circleImage->GetHeight() );
1009
1010 circleImageBlured->EfxFilter_SkipCenter( circleImage, IMAGE_FILTER::GAUSSIAN_BLUR, circleRadius - 8 );
1011
1012 m_circleTexture = OglLoadTexture( *circleImageBlured );
1013
1014 delete circleImageBlured;
1015 circleImageBlured = nullptr;
1016
1017 delete circleImage;
1018 circleImage = nullptr;
1019
1020 init_lights();
1021
1022 // Use this mode if you want see the triangle lines (debug proposes)
1023 //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
1024 m_canvasInitialized = true;
1025
1026 return true;
1027}
1028
1029
1031{
1032 glEnable( GL_COLOR_MATERIAL );
1033 glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
1034
1035 const SFVEC4F ambient = SFVEC4F( 0.0f, 0.0f, 0.0f, 1.0f );
1036 const SFVEC4F diffuse = SFVEC4F( 0.0f, 0.0f, 0.0f, 1.0f );
1037 const SFVEC4F emissive = SFVEC4F( 0.0f, 0.0f, 0.0f, 1.0f );
1038 const SFVEC4F specular = SFVEC4F( 0.1f, 0.1f, 0.1f, 1.0f );
1039
1040 glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r );
1041 glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 96.0f );
1042
1043 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r );
1044 glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r );
1045 glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, &emissive.r );
1046}
1047
1048
1050{
1051#define DELETE_AND_FREE( ptr ) \
1052 { \
1053 ptr.reset(); \
1054 } \
1055
1056#define DELETE_AND_FREE_MAP( map ) \
1057 { \
1058 for( auto& [ layer, ptr ] : map ) \
1059 ptr.reset(); \
1060 \
1061 map.clear(); \
1062 }
1063
1064 if( m_canvasInitialized && !ORPHANED_GL_OBJECTS::Active() && glIsList( m_grid ) )
1065 glDeleteLists( m_grid, 1 );
1066
1067 m_grid = 0;
1068
1070
1075
1078
1079 for( std::shared_ptr<TRIANGLE_DISPLAY_LIST>& list : m_triangles )
1080 list.reset();
1081
1082 m_triangles.clear();
1083
1085
1086 m_3dModelMatrixMap.clear();
1087
1092
1096
1102
1106}
1107
1108
1110{
1111 std::vector<std::shared_ptr<void>> retired;
1112
1113 {
1114 std::lock_guard<std::recursive_mutex> lock( m_renderMutex );
1115 retired.swap( m_retiredRenderPtrs );
1116 }
1117}
1118
1119
1121 bool aShowThickness, bool aSkipRenderHoles )
1122{
1123 wxASSERT( (aLayerID == B_Mask) || (aLayerID == F_Mask) );
1124
1125 if( m_board )
1126 {
1127 std::shared_ptr<OPENGL_RENDER_LIST> board_list = m_board->MakeOrGet();
1128 std::shared_ptr<OPENGL_RENDER_LIST> solder_mask = m_layers[aLayerID] ? m_layers[aLayerID]->MakeOrGet()
1129 : nullptr;
1130 std::shared_ptr<OPENGL_RENDER_LIST> via_holes;
1131
1132 if( !aSkipRenderHoles )
1133 {
1134 if( IsFrontLayer( aLayerID ) )
1135 via_holes = m_frontOuterThroughHoles ? m_frontOuterThroughHoles->MakeOrGet() : nullptr;
1136 else
1137 via_holes = m_backOuterThroughHoles ? m_backOuterThroughHoles->MakeOrGet() : nullptr;
1138 }
1139
1140 if( via_holes )
1141 via_holes->ApplyScalePosition( aZPos, m_boardAdapter.GetNonCopperLayerThickness() );
1142
1143 board_list->ApplyScalePosition( aZPos, m_boardAdapter.GetNonCopperLayerThickness() );
1144
1145 setLayerMaterial( aLayerID );
1146 board_list->SetItIsTransparent( true );
1147 board_list->DrawCulled( aShowThickness, solder_mask, via_holes );
1148
1149 if( aLayerID == F_Mask && m_viaFrontCover )
1150 {
1151 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_draw_list = m_viaFrontCover->MakeOrGet() )
1152 {
1153 ogl_draw_list->ApplyScalePosition( aZPos, 4 * m_boardAdapter.GetNonCopperLayerThickness() );
1154 ogl_draw_list->DrawTop();
1155 }
1156 }
1157 else if( aLayerID == B_Mask && m_viaBackCover )
1158 {
1159 if( std::shared_ptr<OPENGL_RENDER_LIST> ogl_draw_list = m_viaBackCover->MakeOrGet() )
1160 {
1161 ogl_draw_list->ApplyScalePosition( aZPos, 4 * m_boardAdapter.GetNonCopperLayerThickness() );
1162 ogl_draw_list->DrawBot();
1163 }
1164 }
1165 }
1166}
1167
1168
1169void RENDER_3D_OPENGL::get3dModelsSelected( std::list<MODELTORENDER> &aDstRenderList, bool aGetTop,
1170 bool aGetBot, bool aRenderTransparentOnly,
1171 bool aRenderSelectedOnly )
1172{
1173 wxASSERT( ( aGetTop == true ) || ( aGetBot == true ) );
1174
1175 if( !m_boardAdapter.GetBoard() )
1176 return;
1177
1179
1180 // Go for all footprints
1181 for( FOOTPRINT* fp : m_boardAdapter.GetBoard()->Footprints() )
1182 {
1183 bool highlight = false;
1184
1185 if( m_boardAdapter.m_IsBoardView )
1186 {
1187 if( fp->IsSelected() )
1188 highlight = true;
1189
1191 highlight = true;
1192
1193 if( aRenderSelectedOnly != highlight )
1194 continue;
1195 }
1196
1197 if( !fp->Models().empty() || m_boardAdapter.ShowMissingModels() )
1198 {
1199 if( m_boardAdapter.IsFootprintShown( fp ) )
1200 {
1201 const bool isFlipped = fp->IsFlipped();
1202
1203 if( aGetTop == !isFlipped || aGetBot == isFlipped )
1204 get3dModelsFromFootprint( aDstRenderList, fp, aRenderTransparentOnly, highlight );
1205 }
1206 }
1207 }
1208}
1209
1210
1211void RENDER_3D_OPENGL::get3dModelsFromFootprint( std::list<MODELTORENDER> &aDstRenderList,
1212 const FOOTPRINT* aFootprint,
1213 bool aRenderTransparentOnly, bool aIsSelected )
1214{
1215 if( !aFootprint->Models().empty() )
1216 {
1217 const glm::mat4 fpMatrix = m_boardAdapter.GetFootprintMatrix( *aFootprint );
1218
1219 // The placeholder stands in for the whole footprint, so several missing models share one.
1220 bool placeholderAdded = false;
1221
1222 // Get the list of model files for this model
1223 for( const FP_3DMODEL& sM : aFootprint->Models() )
1224 {
1225 if( !sM.m_Show || sM.m_Filename.empty() )
1226 continue;
1227
1228 // Check if the model is present in our cache map
1229 auto cache_i = m_3dModelMap.find( sM.m_Filename );
1230
1231 if( cache_i == m_3dModelMap.end() )
1232 {
1233 if( !placeholderAdded )
1234 {
1235 renderPlaceholderForFootprint( aDstRenderList, fpMatrix, aFootprint, aRenderTransparentOnly,
1236 aIsSelected, aRenderTransparentOnly ? sM.m_Opacity : 1.0f );
1237 placeholderAdded = true;
1238 }
1239
1240 continue;
1241 }
1242
1243 if( const std::shared_ptr<MODEL_3D_DEFERRED>& modelPtrDef = cache_i->second )
1244 {
1245 std::shared_ptr<MODEL_3D> modelPtr = modelPtrDef->MakeOrGet();
1246
1247 if( !modelPtr )
1248 continue;
1249
1250 bool opaque = sM.m_Opacity >= 1.0;
1251
1252 if( ( !aRenderTransparentOnly && modelPtr->HasOpaqueMeshes() && opaque ) ||
1253 ( aRenderTransparentOnly && ( modelPtr->HasTransparentMeshes() || !opaque ) ) )
1254 {
1255 glm::mat4 modelworldMatrix = fpMatrix;
1256
1257 const SFVEC3F offset = SFVEC3F( sM.m_Offset.x, sM.m_Offset.y, sM.m_Offset.z );
1258 const SFVEC3F rotation = SFVEC3F( sM.m_Rotation.x, sM.m_Rotation.y,
1259 sM.m_Rotation.z );
1260 const SFVEC3F scale = SFVEC3F( sM.m_Scale.x, sM.m_Scale.y, sM.m_Scale.z );
1261
1262 std::vector<float> key = { offset.x, offset.y, offset.z,
1263 rotation.x, rotation.y, rotation.z,
1264 scale.x, scale.y, scale.z };
1265
1266 auto it = m_3dModelMatrixMap.find( key );
1267
1268 if( it != m_3dModelMatrixMap.end() )
1269 {
1270 modelworldMatrix *= it->second;
1271 }
1272 else
1273 {
1274 glm::mat4 mtx = CalcModelMatrix( offset, rotation, scale );
1275 m_3dModelMatrixMap[ key ] = mtx;
1276
1277 modelworldMatrix *= mtx;
1278 }
1279
1280 aDstRenderList.emplace_back( modelworldMatrix, modelPtr,
1281 aRenderTransparentOnly ? sM.m_Opacity : 1.0f,
1282 aRenderTransparentOnly,
1283 aFootprint->IsSelected() || aIsSelected );
1284 }
1285 }
1286 }
1287 }
1288 else
1289 {
1290 const glm::mat4 fpMatrix = m_boardAdapter.GetFootprintMatrix( *aFootprint );
1291
1292 renderPlaceholderForFootprint( aDstRenderList, fpMatrix, aFootprint, aRenderTransparentOnly, aIsSelected,
1293 1.0f );
1294 }
1295}
1296
1297
1298void RENDER_3D_OPENGL::renderPlaceholderForFootprint( std::list<MODELTORENDER>& aDstRenderList,
1299 const glm::mat4& aFpMatrix, const FOOTPRINT* aFootprint,
1300 bool aRenderTransparentOnly, bool aIsSelected, float aOpacity )
1301{
1302 if( !m_boardAdapter.ShowMissingModels() || !m_placeholderModel )
1303 return;
1304
1305 // Suppress placeholder if a valid extruded body was built
1306 if( m_extrudedBodyLists.count( aFootprint ) )
1307 return;
1308
1309 BOX2I localBox = CalcPlaceholderLocalBox( aFootprint );
1310
1311 float bboxW = std::abs( localBox.GetWidth() ) / pcbIUScale.IU_PER_MM * 0.9f;
1312 float bboxH = std::abs( localBox.GetHeight() ) / pcbIUScale.IU_PER_MM * 0.9f;
1313
1314 float scaleX = bboxW;
1315 float scaleY = bboxH;
1316 float scaleZ = std::min( bboxW, bboxH ) * 0.5f;
1317
1318 VECTOR2I localCenter = localBox.GetCenter();
1319 float offsetX = localCenter.x / pcbIUScale.IU_PER_MM;
1320 float offsetY = -localCenter.y / pcbIUScale.IU_PER_MM;
1321 float offsetZ = scaleZ * 0.5f;
1322
1323 if( aFootprint->IsFlipped() )
1324 offsetY = -offsetY;
1325
1326 glm::mat4 mtx = aFpMatrix;
1327 mtx = glm::translate( mtx, SFVEC3F( offsetX, offsetY, offsetZ ) );
1328 mtx = glm::scale( mtx, SFVEC3F( scaleX, scaleY, scaleZ ) );
1329
1330 bool placeholderOpaque = aOpacity >= 1.0;
1331
1332 if( ( !aRenderTransparentOnly && m_placeholderModel->HasOpaqueMeshes() && placeholderOpaque )
1333 || ( aRenderTransparentOnly && ( m_placeholderModel->HasTransparentMeshes() || !placeholderOpaque ) ) )
1334 {
1335 aDstRenderList.emplace_back( mtx, m_placeholderModel, aOpacity, aRenderTransparentOnly,
1336 aFootprint->IsSelected() || aIsSelected );
1337 }
1338}
1339
1340
1341void RENDER_3D_OPENGL::renderOpaqueModels( const glm::mat4 &aCameraViewMatrix )
1342{
1344
1345 const SFVEC3F selColor = m_boardAdapter.GetColor( cfg.opengl_selection_color );
1346
1347 glPushMatrix();
1348
1349 std::list<MODELTORENDER> renderList;
1350
1351 if( m_boardAdapter.m_IsBoardView )
1352 {
1353 renderList.clear();
1354
1355 get3dModelsSelected( renderList, true, true, false, true );
1356
1357 if( !renderList.empty() )
1358 {
1359 MODEL_3D::BeginDrawMulti( false );
1360
1361 for( const MODELTORENDER& mtr : renderList )
1362 renderModel( aCameraViewMatrix, mtr, selColor, nullptr );
1363
1365 }
1366 }
1367
1368 renderList.clear();
1369 get3dModelsSelected( renderList, true, true, false, false );
1370
1371 if( !renderList.empty() )
1372 {
1374
1375 for( const MODELTORENDER& mtr : renderList )
1376 renderModel( aCameraViewMatrix, mtr, selColor, nullptr );
1377
1379 }
1380
1381 glPopMatrix();
1382}
1383
1384
1385void RENDER_3D_OPENGL::renderExtrudedBodies( bool aTransparentPass )
1386{
1388 const SFVEC3F extSelColor = m_boardAdapter.GetColor( extCfg.opengl_selection_color );
1389
1390 for( auto& [fp, renderListDef] : m_extrudedBodyLists )
1391 {
1392 const EXTRUDED_3D_BODY* body = fp->GetBody() ? fp->GetBody()->GetExtruded() : nullptr;
1393
1394 if( !body )
1395 continue;
1396
1397 if( !renderListDef )
1398 continue;
1399
1400 std::shared_ptr<OPENGL_RENDER_LIST> renderList = renderListDef->MakeOrGet();
1401
1402 if( !renderList )
1403 continue;
1404
1405 bool highlight = false;
1406
1407 if( m_boardAdapter.m_IsBoardView )
1408 {
1409 if( fp->IsSelected() )
1410 highlight = true;
1411
1412 if( extCfg.highlight_on_rollover && fp == m_currentRollOverItem )
1413 highlight = true;
1414 }
1415
1416 KIGFX::COLOR4D c = body->m_color;
1417
1420
1421 if( ( c.a < 1.0 ) != aTransparentPass )
1422 continue;
1423
1424 SMATERIAL mat;
1425
1426 SFVEC3F diffuse( c.r, c.g, c.b );
1427 EXTRUSION_MATERIAL_PROPS props = GetMaterialProps( body->m_material, diffuse );
1428
1429 mat.m_Diffuse = diffuse;
1430 mat.m_Ambient = props.m_Ambient;
1431 mat.m_Specular = props.m_Specular;
1432 mat.m_Shininess = props.m_Shininess;
1433 mat.m_Emissive = SFVEC3F( 0.0f );
1434 mat.m_Transparency = 1.0f - c.a;
1435
1436 OglSetMaterial( mat, 1.0f, highlight, extSelColor );
1437 renderList->DrawAll();
1438
1439 auto pegIt = m_extrudedPegLists.find( fp );
1440
1441 if( pegIt != m_extrudedPegLists.end() && pegIt->second )
1442 {
1443 if( std::shared_ptr<OPENGL_RENDER_LIST> pegList = pegIt->second->MakeOrGet() )
1444 pegList->DrawAll();
1445 }
1446 }
1447}
1448
1449
1450void RENDER_3D_OPENGL::renderTransparentModels( const glm::mat4 &aCameraViewMatrix )
1451{
1453
1454 const SFVEC3F selColor = m_boardAdapter.GetColor( cfg.opengl_selection_color );
1455
1456 std::list<MODELTORENDER> renderListModels; // do not clear it until this function returns
1457
1458 if( m_boardAdapter.m_IsBoardView )
1459 {
1460 // Get Transparent Selected
1461 get3dModelsSelected( renderListModels, true, true, true, true );
1462 }
1463
1464 // Get Transparent Not Selected
1465 get3dModelsSelected( renderListModels, true, true, true, false );
1466
1467 if( renderListModels.empty() )
1468 return;
1469
1470 std::vector<std::pair<const MODELTORENDER *, float>> transparentModelList;
1471
1472 transparentModelList.reserve( renderListModels.size() );
1473
1474 // Calculate the distance to the camera for each model
1475 const SFVEC3F &cameraPos = m_camera.GetPos();
1476
1477 for( const MODELTORENDER& mtr : renderListModels )
1478 {
1479 const BBOX_3D& bBox = mtr.m_model->GetBBox();
1480 const SFVEC3F& bBoxCenter = bBox.GetCenter();
1481 const SFVEC3F bBoxWorld = mtr.m_modelWorldMat * glm::vec4( bBoxCenter, 1.0f );
1482
1483 const float distanceToCamera = glm::length( cameraPos - bBoxWorld );
1484
1485 transparentModelList.emplace_back( &mtr, distanceToCamera );
1486 }
1487
1488 // Sort from back to front
1489 std::sort( transparentModelList.begin(), transparentModelList.end(),
1490 [&]( std::pair<const MODELTORENDER *, float>& a,
1491 std::pair<const MODELTORENDER *, float>& b )
1492 {
1493 if( a.second != b.second )
1494 return a.second > b.second;
1495
1496 return a.first > b.first; // use pointers as a last resort
1497 } );
1498
1499 // Start rendering calls
1500 glPushMatrix();
1501
1502 bool isUsingColorInformation = !( transparentModelList.begin()->first->m_isSelected &&
1503 m_boardAdapter.m_IsBoardView );
1504
1505 MODEL_3D::BeginDrawMulti( isUsingColorInformation );
1506
1507 for( const std::pair<const MODELTORENDER *, float>& mtr : transparentModelList )
1508 {
1509 if( m_boardAdapter.m_IsBoardView )
1510 {
1511 // Toggle between using model color or the select color
1512 if( !isUsingColorInformation && !mtr.first->m_isSelected )
1513 {
1514 isUsingColorInformation = true;
1515
1516 glEnableClientState( GL_COLOR_ARRAY );
1517 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1518 glEnable( GL_COLOR_MATERIAL );
1519 }
1520 else if( isUsingColorInformation && mtr.first->m_isSelected )
1521 {
1522 isUsingColorInformation = false;
1523
1524 glDisableClientState( GL_COLOR_ARRAY );
1525 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1526 glDisable( GL_COLOR_MATERIAL );
1527 }
1528 }
1529
1530 // Render model, sort each individuall material group
1531 // by passing cameraPos
1532 renderModel( aCameraViewMatrix, *mtr.first, selColor, &cameraPos );
1533 }
1534
1536
1537 glPopMatrix();
1538}
1539
1540
1541void RENDER_3D_OPENGL::renderModel( const glm::mat4 &aCameraViewMatrix,
1542 const MODELTORENDER &aModelToRender,
1543 const SFVEC3F &aSelColor, const SFVEC3F *aCameraWorldPos )
1544{
1546
1547 const glm::mat4 modelviewMatrix = aCameraViewMatrix * aModelToRender.m_modelWorldMat;
1548
1549 glLoadMatrixf( glm::value_ptr( modelviewMatrix ) );
1550
1551 aModelToRender.m_model->Draw( aModelToRender.m_isTransparent, aModelToRender.m_opacity,
1552 aModelToRender.m_isSelected, aSelColor,
1553 &aModelToRender.m_modelWorldMat, aCameraWorldPos );
1554
1555 if( cfg.show_model_bbox )
1556 {
1557 const bool wasBlendEnabled = glIsEnabled( GL_BLEND );
1558
1559 if( !wasBlendEnabled )
1560 {
1561 glEnable( GL_BLEND );
1562 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1563 }
1564
1565 glDisable( GL_LIGHTING );
1566
1567 glLineWidth( 1 );
1568 aModelToRender.m_model->DrawBboxes();
1569
1570 glLineWidth( 4 );
1571 aModelToRender.m_model->DrawBbox();
1572
1573 glEnable( GL_LIGHTING );
1574
1575 if( !wasBlendEnabled )
1576 glDisable( GL_BLEND );
1577 }
1578}
1579
1580
1582{
1583 if( glIsList( m_grid ) )
1584 glDeleteLists( m_grid, 1 );
1585
1586 m_grid = 0;
1587
1588 if( aGridType == GRID3D_TYPE::NONE )
1589 return;
1590
1591 m_grid = glGenLists( 1 );
1592
1593 if( !glIsList( m_grid ) )
1594 return;
1595
1596 glNewList( m_grid, GL_COMPILE );
1597
1598 glEnable( GL_BLEND );
1599 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1600
1601 const double zpos = 0.0;
1602
1603 // Color of grid lines
1604 const SFVEC3F gridColor = m_boardAdapter.GetColor( DARKGRAY );
1605
1606 // Color of grid lines every 5 lines
1607 const SFVEC3F gridColor_marker = m_boardAdapter.GetColor( LIGHTBLUE );
1608 const double scale = m_boardAdapter.BiuTo3dUnits();
1609 const GLfloat transparency = 0.35f;
1610
1611 double griSizeMM = 0.0;
1612
1613 switch( aGridType )
1614 {
1615 case GRID3D_TYPE::GRID_1MM: griSizeMM = 1.0; break;
1616 case GRID3D_TYPE::GRID_2P5MM: griSizeMM = 2.5; break;
1617 case GRID3D_TYPE::GRID_5MM: griSizeMM = 5.0; break;
1618 case GRID3D_TYPE::GRID_10MM: griSizeMM = 10.0; break;
1619
1620 default:
1621 case GRID3D_TYPE::NONE: return;
1622 }
1623
1624 glNormal3f( 0.0, 0.0, 1.0 );
1625
1626 const VECTOR2I brd_size = m_boardAdapter.GetBoardSize();
1627 VECTOR2I brd_center_pos = m_boardAdapter.GetBoardPos();
1628
1629 brd_center_pos.y = -brd_center_pos.y;
1630
1631 const int xsize = std::max( brd_size.x, pcbIUScale.mmToIU( 100 ) ) * 1.2;
1632 const int ysize = std::max( brd_size.y, pcbIUScale.mmToIU( 100 ) ) * 1.2;
1633
1634 // Grid limits, in 3D units
1635 double xmin = ( brd_center_pos.x - xsize / 2 ) * scale;
1636 double xmax = ( brd_center_pos.x + xsize / 2 ) * scale;
1637 double ymin = ( brd_center_pos.y - ysize / 2 ) * scale;
1638 double ymax = ( brd_center_pos.y + ysize / 2 ) * scale;
1639 double zmin = pcbIUScale.mmToIU( -50 ) * scale;
1640 double zmax = pcbIUScale.mmToIU( 100 ) * scale;
1641
1642 // Set rasterised line width (min value = 1)
1643 glLineWidth( 1 );
1644
1645 // Draw horizontal grid centered on 3D origin (center of the board)
1646 for( int ii = 0; ; ii++ )
1647 {
1648 if( (ii % 5) )
1649 glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency );
1650 else
1651 glColor4f( gridColor_marker.r, gridColor_marker.g, gridColor_marker.b,
1652 transparency );
1653
1654 const int delta = KiROUND( ii * griSizeMM * pcbIUScale.IU_PER_MM );
1655
1656 if( delta <= xsize / 2 ) // Draw grid lines parallel to X axis
1657 {
1658 glBegin( GL_LINES );
1659 glVertex3f( (brd_center_pos.x + delta) * scale, -ymin, zpos );
1660 glVertex3f( (brd_center_pos.x + delta) * scale, -ymax, zpos );
1661 glEnd();
1662
1663 if( ii != 0 )
1664 {
1665 glBegin( GL_LINES );
1666 glVertex3f( (brd_center_pos.x - delta) * scale, -ymin, zpos );
1667 glVertex3f( (brd_center_pos.x - delta) * scale, -ymax, zpos );
1668 glEnd();
1669 }
1670 }
1671
1672 if( delta <= ysize / 2 ) // Draw grid lines parallel to Y axis
1673 {
1674 glBegin( GL_LINES );
1675 glVertex3f( xmin, -( brd_center_pos.y + delta ) * scale, zpos );
1676 glVertex3f( xmax, -( brd_center_pos.y + delta ) * scale, zpos );
1677 glEnd();
1678
1679 if( ii != 0 )
1680 {
1681 glBegin( GL_LINES );
1682 glVertex3f( xmin, -( brd_center_pos.y - delta ) * scale, zpos );
1683 glVertex3f( xmax, -( brd_center_pos.y - delta ) * scale, zpos );
1684 glEnd();
1685 }
1686 }
1687
1688 if( ( delta > ysize / 2 ) && ( delta > xsize / 2 ) )
1689 break;
1690 }
1691
1692 // Draw vertical grid on Z axis
1693 glNormal3f( 0.0, -1.0, 0.0 );
1694
1695 // Draw vertical grid lines (parallel to Z axis)
1696 double posy = -brd_center_pos.y * scale;
1697
1698 for( int ii = 0; ; ii++ )
1699 {
1700 if( (ii % 5) )
1701 glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency );
1702 else
1703 glColor4f( gridColor_marker.r, gridColor_marker.g, gridColor_marker.b,
1704 transparency );
1705
1706 const double delta = ii * griSizeMM * pcbIUScale.IU_PER_MM;
1707
1708 glBegin( GL_LINES );
1709 xmax = ( brd_center_pos.x + delta ) * scale;
1710
1711 glVertex3f( xmax, posy, zmin );
1712 glVertex3f( xmax, posy, zmax );
1713 glEnd();
1714
1715 if( ii != 0 )
1716 {
1717 glBegin( GL_LINES );
1718 xmin = ( brd_center_pos.x - delta ) * scale;
1719 glVertex3f( xmin, posy, zmin );
1720 glVertex3f( xmin, posy, zmax );
1721 glEnd();
1722 }
1723
1724 if( delta > xsize / 2.0f )
1725 break;
1726 }
1727
1728 // Draw horizontal grid lines on Z axis (parallel to X axis)
1729 for( int ii = 0; ; ii++ )
1730 {
1731 if( ii % 5 )
1732 glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency );
1733 else
1734 glColor4f( gridColor_marker.r, gridColor_marker.g, gridColor_marker.b, transparency );
1735
1736 const double delta = ii * griSizeMM * pcbIUScale.IU_PER_MM * scale;
1737
1738 if( delta <= zmax )
1739 {
1740 // Draw grid lines on Z axis (positive Z axis coordinates)
1741 glBegin( GL_LINES );
1742 glVertex3f( xmin, posy, delta );
1743 glVertex3f( xmax, posy, delta );
1744 glEnd();
1745 }
1746
1747 if( delta <= -zmin && ( ii != 0 ) )
1748 {
1749 // Draw grid lines on Z axis (negative Z axis coordinates)
1750 glBegin( GL_LINES );
1751 glVertex3f( xmin, posy, -delta );
1752 glVertex3f( xmax, posy, -delta );
1753 glEnd();
1754 }
1755
1756 if( ( delta > zmax ) && ( delta > -zmin ) )
1757 break;
1758 }
1759
1760 glDisable( GL_BLEND );
1761
1762 glEndList();
1763}
1764
1765
1767{
1768 // Unit cube: 1mm × 1mm × 1mm, centered at origin
1769 static SFVEC3F positions[24] = { // +Z (top)
1770 { -0.5f, -0.5f, 0.5f },
1771 { 0.5f, -0.5f, 0.5f },
1772 { 0.5f, 0.5f, 0.5f },
1773 { -0.5f, 0.5f, 0.5f },
1774
1775 // -Z (bottom)
1776 { -0.5f, 0.5f, -0.5f },
1777 { 0.5f, 0.5f, -0.5f },
1778 { 0.5f, -0.5f, -0.5f },
1779 { -0.5f, -0.5f, -0.5f },
1780
1781 // +X
1782 { 0.5f, -0.5f, -0.5f },
1783 { 0.5f, 0.5f, -0.5f },
1784 { 0.5f, 0.5f, 0.5f },
1785 { 0.5f, -0.5f, 0.5f },
1786
1787 // -X
1788 { -0.5f, -0.5f, 0.5f },
1789 { -0.5f, 0.5f, 0.5f },
1790 { -0.5f, 0.5f, -0.5f },
1791 { -0.5f, -0.5f, -0.5f },
1792
1793 // +Y
1794 { -0.5f, 0.5f, 0.5f },
1795 { 0.5f, 0.5f, 0.5f },
1796 { 0.5f, 0.5f, -0.5f },
1797 { -0.5f, 0.5f, -0.5f },
1798
1799 // -Y
1800 { -0.5f, -0.5f, -0.5f },
1801 { 0.5f, -0.5f, -0.5f },
1802 { 0.5f, -0.5f, 0.5f },
1803 { -0.5f, -0.5f, 0.5f }
1804 };
1805
1806 static SFVEC3F normals[24] = { // +Z
1807 { 0, 0, 1 },
1808 { 0, 0, 1 },
1809 { 0, 0, 1 },
1810 { 0, 0, 1 },
1811 // -Z
1812 { 0, 0, -1 },
1813 { 0, 0, -1 },
1814 { 0, 0, -1 },
1815 { 0, 0, -1 },
1816 // +X
1817 { 1, 0, 0 },
1818 { 1, 0, 0 },
1819 { 1, 0, 0 },
1820 { 1, 0, 0 },
1821 // -X
1822 { -1, 0, 0 },
1823 { -1, 0, 0 },
1824 { -1, 0, 0 },
1825 { -1, 0, 0 },
1826 // +Y
1827 { 0, 1, 0 },
1828 { 0, 1, 0 },
1829 { 0, 1, 0 },
1830 { 0, 1, 0 },
1831 // -Y
1832 { 0, -1, 0 },
1833 { 0, -1, 0 },
1834 { 0, -1, 0 },
1835 { 0, -1, 0 }
1836 };
1837
1838 static unsigned int indices[36] = {
1839 0, 1, 2, 0, 2, 3, // +Z
1840 4, 5, 6, 4, 6, 7, // -Z
1841 8, 9, 10, 8, 10, 11, // +X
1842 12, 13, 14, 12, 14, 15, // -X
1843 16, 17, 18, 16, 18, 19, // +Y
1844 20, 21, 22, 20, 22, 23 // -Y
1845 };
1846
1847 static SMATERIAL material = {
1848 SFVEC3F( 0.2f, 0.1f, 0.0f ), // ambient
1849 SFVEC3F( 1.0f, 0.5f, 0.0f ), // diffuse
1850 SFVEC3F( 0.0f, 0.0f, 0.0f ), // emissive
1851 SFVEC3F( 0.1f, 0.1f, 0.1f ), // specular
1852 0.1f, // shininess
1853 0.4f // transparency
1854 };
1855
1856 static SMESH mesh = { 24, positions, normals, nullptr, nullptr, 36, indices, 0 };
1857
1858 static S3DMODEL model = { 1, &mesh, 1, &material };
1859
1860 m_placeholderModel = std::make_shared<MODEL_3D>( model, MATERIAL_MODE::NORMAL );
1861}
GRID3D_TYPE
Grid types.
Definition 3d_enums.h:57
@ NORMAL
Use all material properties from model file.
Definition 3d_enums.h:75
glm::mat4 CalcModelMatrix(const SFVEC3F &aOffset, const SFVEC3F &aRotation, const SFVEC3F &aScale)
Build the model-to-footprint transform used by rendering and picking.
Definition 3d_math.cpp:34
Defines math related functions.
float mapf(float x, float in_min, float in_max, float out_min, float out_max)
Definition 3d_math.h:164
SFVEC3F SphericalToCartesian(float aInclination, float aAzimuth)
https://en.wikipedia.org/wiki/Spherical_coordinate_system
Definition 3d_math.h:74
EXTRUSION_MATERIAL_PROPS GetMaterialProps(EXTRUSION_MATERIAL aMaterial, const SFVEC3F &aDiffuse)
BOX2I CalcPlaceholderLocalBox(const FOOTPRINT *aFootprint)
Calculate a local space bounding box for a placeholder 3D model.
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
Helper class to handle information needed to display 3D board.
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr const Vec GetCenter() const
Definition box2.h:233
constexpr size_type GetHeight() const
Definition box2.h:218
A class used to derive camera objects from.
Definition camera.h:94
Implement a canvas based on a wxGLCanvas.
bool IsSelected() const
Definition eda_item.h:134
KIGFX::COLOR4D m_color
Definition pcb_3d_body.h:46
static KIGFX::COLOR4D GetDefaultColor(EXTRUSION_MATERIAL aMaterial)
Definition pcb_3d_body.h:54
EXTRUSION_MATERIAL m_material
Definition pcb_3d_body.h:47
bool IsFlipped() const
Definition footprint.h:620
std::vector< FP_3DMODEL > & Models()
Definition footprint.h:375
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:86
void CircleFilled(int aCx, int aCy, int aRadius, unsigned char aValue)
Definition image.cpp:169
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:523
unsigned int GetHeight() const
Definition image.h:210
unsigned int GetWidth() const
Definition image.h:209
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
double r
Red component.
Definition color4d.h:391
double g
Green component.
Definition color4d.h:392
double a
Alpha component.
Definition color4d.h:394
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:400
double b
Blue component.
Definition color4d.h:393
static const LSET & PhysicalLayersMask()
Return a mask holding all layers which are physically realized.
Definition lset.cpp:693
void DrawBbox() const
Draw main bounding box of the model.
Definition 3d_model.cpp:567
static void EndDrawMulti()
Cleanup render states after drawing multiple models.
Definition 3d_model.cpp:401
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:414
static void BeginDrawMulti(bool aUseColorInformation)
Set some basic render states before drawing multiple models.
Definition 3d_model.cpp:385
void DrawBboxes() const
Draw individual bounding boxes of each mesh.
Definition 3d_model.cpp:586
GL_CONTEXT_MANAGER * GetGLContextManager()
Definition pgm_base.h:114
std::unique_ptr< BUSY_INDICATOR > CreateBusyIndicator() const
Return a created busy indicator, if a factory has been set, else a null pointer.
RENDER_3D_BASE(BOARD_ADAPTER &aBoardAdapter, CAMERA &aCamera)
bool m_canvasInitialized
Flag if the canvas specific for this render was already initialized.
std::shared_ptr< REPORTER > m_activityReporter
wxSize m_windowSize
The window size that this camera is working.
BOARD_ADAPTER & m_boardAdapter
Settings reference in use for this render.
SPHERES_GIZMO::GizmoSphereSelection getSelectedGizmoSphere() const
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_offboardPadsBack
std::map< const FOOTPRINT *, std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > > m_extrudedBodyLists
GRID3D_TYPE m_lastGridType
Stores the last grid type.
std::tuple< int, int, int, int > getGizmoViewport() const
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_viaFrontCover
void renderOpaqueModels(const glm::mat4 &aCameraViewMatrix)
void StopBgWorker() override
Request stop and join any in-progress background loading.
void generate3dGrid(GRID3D_TYPE aGridType)
Create a 3D grid to an OpenGL display list.
void setLightFront(bool enabled)
std::shared_ptr< MODEL_3D > m_placeholderModel
bool Redraw(bool aIsMoving) override
Redraw the view.
MAP_OGL_DISP_LISTS m_layers
MAP_OGL_DISP_LISTS m_innerLayerHoles
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_postMachinePlugs
Board material plugs for backdrill/counterbore/countersink.
RENDER_3D_OPENGL(EDA_3D_CANVAS *aCanvas, BOARD_ADAPTER &aAdapter, CAMERA &aCamera)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_offboardPadsFront
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_complexPlatedHoles
MAP_OGL_DISP_LISTS m_outerLayerHoles
BOARD_ITEM * m_currentRollOverItem
void renderBoardBody(bool aSkipRenderHoles)
std::map< std::vector< float >, glm::mat4 > m_3dModelMatrixMap
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_backOuterThroughHoles
std::recursive_mutex m_renderMutex
LIST_TRIANGLES m_triangles
store pointers so can be deleted latter
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_platedPadsFront
void setLayerMaterial(PCB_LAYER_ID aLayerID)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_platedPadsBack
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_board
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_boardWithHoles
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...
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_antiBoard
std::map< wxString, std::shared_ptr< MODEL_3D_DEFERRED > > m_3dModelMap
void renderSolderMaskLayer(PCB_LAYER_ID aLayerID, float aZPos, bool aShowThickness, bool aSkipRenderHoles)
void renderTransparentModels(const glm::mat4 &aCameraViewMatrix)
void get3dModelsSelected(std::list< MODELTORENDER > &aDstRenderList, bool aGetTop, bool aGetBot, bool aRenderTransparentOnly, bool aRenderSelectedOnly)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_frontOuterThroughHoles
void setPlatedCopperAndDepthOffset(PCB_LAYER_ID aLayer_id)
void updateGizmoSelection(glm::mat4 aCameraRotationMatrix)
std::map< const FOOTPRINT *, std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > > m_extrudedPadLists
void SetCurWindowSize(const wxSize &aSize) override
Before each render, the canvas will tell the render what is the size of its windows,...
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_padHoles
EDA_3D_CANVAS * m_canvas
void renderPlaceholderForFootprint(std::list< MODELTORENDER > &aDstRenderList, const glm::mat4 &aFpMatrix, const FOOTPRINT *aFootprint, bool aRenderTransparentOnly, bool aIsSelected, float aOpacity)
std::vector< std::shared_ptr< void > > m_retiredRenderPtrs
SPHERES_GIZMO * m_spheres_gizmo
GLuint m_grid
oGL list that stores current grid
std::map< const FOOTPRINT *, std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > > m_extrudedPegLists
void get3dModelsFromFootprint(std::list< MODELTORENDER > &aDstRenderList, const FOOTPRINT *aFootprint, bool aRenderTransparentOnly, bool aIsSelected)
void handleGizmoMouseInput(int mouseX, int mouseY)
void setLightBottom(bool enabled)
void setGizmoViewport(int x, int y, int width, int height)
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_outerThroughHoleRings
std::shared_ptr< OPENGL_RENDER_LIST_DEFERRED > m_viaBackCover
void setLightTop(bool enabled)
Renders a set of colored spheres in 3D space that act as a directional orientation gizmo.
GizmoSphereSelection
Enum to indicate which sphere (direction) is selected.
@ LIGHTBLUE
Definition color4d.h:58
@ DARKGRAY
Definition color4d.h:42
#define DELETE_AND_FREE_MAP(map)
#define DELETE_AND_FREE(ptr)
#define _(s)
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
@ GAUSSIAN_BLUR
Definition image.h:61
int MapPCBLayerTo3DLayer(PCB_LAYER_ID aLayer)
Definition layer_id.cpp:355
@ LAYER_3D_USER_1
Definition layer_ids.h:602
@ LAYER_3D_SOLDERMASK_TOP
Definition layer_ids.h:591
@ LAYER_3D_SOLDERMASK_BOTTOM
Definition layer_ids.h:590
@ LAYER_3D_BOARD
Definition layer_ids.h:585
@ LAYER_3D_USER_45
Definition layer_ids.h:646
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
Definition layer_ids.h:847
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:744
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ F_CrtYd
Definition layer_ids.h:112
@ B_Adhes
Definition layer_ids.h:99
@ Edge_Cuts
Definition layer_ids.h:108
@ Dwgs_User
Definition layer_ids.h:103
@ F_Paste
Definition layer_ids.h:100
@ Cmts_User
Definition layer_ids.h:104
@ F_Adhes
Definition layer_ids.h:98
@ B_Mask
Definition layer_ids.h:94
@ B_Cu
Definition layer_ids.h:61
@ Eco1_User
Definition layer_ids.h:105
@ F_Mask
Definition layer_ids.h:93
@ B_Paste
Definition layer_ids.h:101
@ F_Fab
Definition layer_ids.h:115
@ Margin
Definition layer_ids.h:109
@ F_SilkS
Definition layer_ids.h:96
@ B_CrtYd
Definition layer_ids.h:111
@ Eco2_User
Definition layer_ids.h:106
@ B_SilkS
Definition layer_ids.h:97
@ F_Cu
Definition layer_ids.h:60
@ B_Fab
Definition layer_ids.h:114
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
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:91
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)
#define SIZE_OF_CIRCLE_TEXTURE
const int scale
Manage a bounding box defined by two SFVEC3F min max points.
Definition bbox_3d.h:39
SFVEC3F GetCenter() const
Return the center point of the bounding box.
Definition bbox_3d.cpp:128
bool DifferentiatePlatedCopper()
return true if platted copper aeras and non platted copper areas must be drawn using a different colo...
std::shared_ptr< MODEL_3D > m_model
Store the a model based on meshes and materials.
Definition c3dmodel.h:111
float m_Shininess
Definition c3dmodel.h:39
SFVEC3F m_Specular
Definition c3dmodel.h:38
SFVEC3F m_Ambient
Definition c3dmodel.h:35
float m_Transparency
1.0 is completely transparent, 0.0 completely opaque
Definition c3dmodel.h:40
SFVEC3F m_Emissive
Definition c3dmodel.h:37
SFVEC3F m_Diffuse
Default diffuse color if m_Color is NULL.
Definition c3dmodel.h:36
Per-vertex normal/color/texcoors structure.
Definition c3dmodel.h:77
KIBIS_MODEL * model
int delta
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
glm::vec3 SFVEC3F
Definition xv3d_types.h:40
glm::vec4 SFVEC4F
Definition xv3d_types.h:42