KiCad PCB EDA Suite
render_3d_opengl.h
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-2016 Mario Luzeiro <[email protected]>
5  * Copyright (C) 2015-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef RENDER_3D_OPENGL_H
26 #define RENDER_3D_OPENGL_H
27 
28 #include "../render_3d_base.h"
29 #include "layer_triangles.h"
30 
31 #include "../raytracing/shapes2D/polygon_2d.h"
32 #include "../raytracing/shapes2D/triangle_2d.h"
33 #include "../raytracing/shapes2D/4pt_polygon_2d.h"
34 #include "../raytracing/shapes2D/filled_circle_2d.h"
35 #include "../raytracing/shapes2D/ring_2d.h"
36 #include "../raytracing/shapes2D/round_segment_2d.h"
37 
38 #include "3d_model.h"
39 
40 #include "3d_cache/3d_info.h"
41 
42 #include <map>
43 
44 
45 typedef std::map< PCB_LAYER_ID, OPENGL_RENDER_LIST* > MAP_OGL_DISP_LISTS;
46 typedef std::list<TRIANGLE_DISPLAY_LIST* > LIST_TRIANGLES;
47 typedef std::map< wxString, MODEL_3D* > MAP_3DMODEL;
48 
49 #define SIZE_OF_CIRCLE_TEXTURE 1024
50 
55 {
56 public:
57  explicit RENDER_3D_OPENGL( EDA_3D_CANVAS* aCanvas, BOARD_ADAPTER& aAdapter, CAMERA& aCamera );
58 
60 
61  void SetCurWindowSize( const wxSize& aSize ) override;
62  bool Redraw( bool aIsMoving, REPORTER* aStatusReporter, REPORTER* aWarningReporter ) override;
63 
64  int GetWaitForEditingTimeOut() override;
65 
66  void SetCurrentRollOverItem( BOARD_ITEM* aRollOverItem )
67  {
68  m_currentRollOverItem = aRollOverItem;
69  }
70 
74  void Load3dModelsIfNeeded();
75 
76 private:
77  OPENGL_RENDER_LIST* generateHoles( const LIST_OBJECT2D& aListHolesObject2d,
78  const SHAPE_POLY_SET& aPoly, float aZtop,
79  float aZbot, bool aInvertFaces,
80  const BVH_CONTAINER_2D* aThroughHoles = nullptr );
81 
83  const SHAPE_POLY_SET* aPolyList,
84  PCB_LAYER_ID aLayerId,
85  const BVH_CONTAINER_2D* aThroughHoles = nullptr );
86 
88 
90  const SFVEC2F& v1, const SFVEC2F& v2, float top, float bot );
91 
92  void addObjectTriangles( const RING_2D* aRing, TRIANGLE_DISPLAY_LIST* aDstLayer,
93  float aZtop, float aZbot );
94 
95  void addObjectTriangles( const POLYGON_4PT_2D* aPoly, TRIANGLE_DISPLAY_LIST* aDstLayer,
96  float aZtop, float aZbot );
97 
98  void addObjectTriangles( const FILLED_CIRCLE_2D* aFilledCircle,
99  TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop, float aZbot );
100 
101  void addObjectTriangles( const TRIANGLE_2D* aTri, TRIANGLE_DISPLAY_LIST* aDstLayer,
102  float aZtop, float aZbot );
103 
104  void addObjectTriangles( const ROUND_SEGMENT_2D* aSeg,
105  TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop, float aZbot );
106 
107  void renderSolderMaskLayer( PCB_LAYER_ID aLayerID, float aZPosition,
108  bool aDrawMiddleSegments, bool aSkipRenderHoles );
109 
110  void renderBoardBody( bool aSkipRenderHoles );
111 
112  void getLayerZPos( PCB_LAYER_ID aLayerID, float& aOutZtop, float& aOutZbot ) const;
113 
114  void generateRing( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
115  unsigned int aNr_sides_per_circle,
116  std::vector< SFVEC2F >& aInnerContourResult,
117  std::vector< SFVEC2F >& aOuterContourResult, bool aInvertOrder );
118 
119  void generateCylinder( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
120  float aZtop, float aZbot, unsigned int aNr_sides_per_circle,
121  TRIANGLE_DISPLAY_LIST* aDstLayer );
122 
123  void generateViasAndPads();
124 
132  void load3dModels( REPORTER* aStatusReporter );
133 
139  void render3dModels( bool aRenderTopOrBot, bool aRenderTransparentOnly );
140 
141  void render3dModelsSelected( bool aRenderTopOrBot, bool aRenderTransparentOnly,
142  bool aRenderSelectedOnly );
143 
144  void renderFootprint( const FOOTPRINT* aFootprint, bool aRenderTransparentOnly,
145  bool aIsSelected );
146 
147  void setLightFront( bool enabled );
148  void setLightTop( bool enabled );
149  void setLightBottom( bool enabled );
150 
151  void render3dArrows();
152 
158  void generate3dGrid( GRID3D_TYPE aGridType );
159 
160  // Materials
161  void setupMaterials();
162 
163  void setCopperMaterial();
165  void unsetDepthOffset();
166 
167  void setLayerMaterial( PCB_LAYER_ID aLayerID );
168  SFVEC4F getLayerColor( PCB_LAYER_ID aLayerID );
169 
170  bool initializeOpenGL();
171  OPENGL_RENDER_LIST* createBoard( const SHAPE_POLY_SET& aBoardPoly,
172  const BVH_CONTAINER_2D* aThroughHoles = nullptr );
173  void reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter );
174 
175  void setArrowMaterial();
176 
177  void freeAllLists();
178 
179  struct
180  {
190  } m_materials;
191 
203 
206 
207  GLuint m_grid;
209 
212 
214 
216 
218 };
220 
221 #endif // RENDER_3D_OPENGL_H
OPENGL_RENDER_LIST * m_platedPadsBack
OPENGL_RENDER_LIST * m_antiBoard
void setLightFront(bool enabled)
VECTOR2I v2(1, 0)
Test suite for KiCad math code.
Object to render the board using openGL.
OPENGL_RENDER_LIST * m_board
void addTopAndBottomTriangles(TRIANGLE_DISPLAY_LIST *aDst, const SFVEC2F &v0, const SFVEC2F &v1, const SFVEC2F &v2, float top, float bot)
void Load3dModelsIfNeeded()
Load footprint models if they are not already loaded, i.e.
void load3dModels(REPORTER *aStatusReporter)
Load footprint models from the cache and load it to openGL lists in the form of MODEL_3D objects.
Store arrays of triangles to be used to create display lists.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
OPENGL_RENDER_LIST * m_outerViaThroughHoles
OPENGL_RENDER_LIST * m_boardWithHoles
std::map< wxString, MODEL_3D * > MAP_3DMODEL
glm::vec4 SFVEC4F
Definition: xv3d_types.h:46
LIST_TRIANGLES m_triangles
store pointers so can be deleted latter
MAP_OGL_DISP_LISTS m_innerLayerHoles
OPENGL_RENDER_LIST * generateEmptyLayerList(PCB_LAYER_ID aLayerId)
void getLayerZPos(PCB_LAYER_ID aLayerID, float &aOutZtop, float &aOutZbot) const
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:48
MAP_OGL_DISP_LISTS m_layers
BOARD_ITEM * m_currentRollOverItem
OPENGL_RENDER_LIST * m_outerThroughHoles
std::list< TRIANGLE_DISPLAY_LIST * > LIST_TRIANGLES
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:70
defines the basic data associated with a single 3D model.
SHAPE_POLY_SET m_antiBoardPolys
The negative polygon representation of the board outline.
struct RENDER_3D_OPENGL::@2 m_materials
A class used to derive camera objects from.
Definition: camera.h:77
OPENGL_RENDER_LIST * m_vias
void reload(REPORTER *aStatusReporter, REPORTER *aWarningReporter)
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
void setLightBottom(bool enabled)
void generateRing(const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, unsigned int aNr_sides_per_circle, std::vector< SFVEC2F > &aInnerContourResult, std::vector< SFVEC2F > &aOuterContourResult, bool aInvertOrder)
Represent a set of closed polygons.
MAP_OGL_DISP_LISTS m_outerLayerHoles
GLuint m_grid
oGL list that stores current grid
OPENGL_RENDER_LIST * m_outerThroughHoleRings
SMATERIAL m_NonPlatedCopper
void setPlatedCopperAndDepthOffset(PCB_LAYER_ID aLayer_id)
OPENGL_RENDER_LIST * createBoard(const SHAPE_POLY_SET &aBoardPoly, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
void renderFootprint(const FOOTPRINT *aFootprint, bool aRenderTransparentOnly, bool aIsSelected)
void setLightTop(bool enabled)
OPENGL_RENDER_LIST * m_padHoles
This is a base class to hold data and functions for render targets.
GRID3D_TYPE
Grid types.
Definition: 3d_enums.h:99
OPENGL_RENDER_LIST * m_platedPadsFront
void SetCurWindowSize(const wxSize &aSize) override
Before each render, the canvas will tell the render what is the size of its windows,...
Store the OpenGL display lists to related with a layer.
Simple non-intersecting polygon with 4 points.
void addObjectTriangles(const RING_2D *aRing, TRIANGLE_DISPLAY_LIST *aDstLayer, float aZtop, float aZbot)
void generate3dGrid(GRID3D_TYPE aGridType)
Create a 3D grid to an OpenGL display list.
void renderBoardBody(bool aSkipRenderHoles)
void generateCylinder(const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, float aZtop, float aZbot, unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST *aDstLayer)
void setLayerMaterial(PCB_LAYER_ID aLayerID)
GRID3D_TYPE m_lastGridType
Stores the last grid type.
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
RENDER_3D_OPENGL(EDA_3D_CANVAS *aCanvas, BOARD_ADAPTER &aAdapter, CAMERA &aCamera)
void SetCurrentRollOverItem(BOARD_ITEM *aRollOverItem)
std::list< OBJECT_2D * > LIST_OBJECT2D
Definition: container_2d.h:36
OPENGL_RENDER_LIST * generateHoles(const LIST_OBJECT2D &aListHolesObject2d, const SHAPE_POLY_SET &aPoly, float aZtop, float aZbot, bool aInvertFaces, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
SMATERIAL m_GrayMaterial
std::map< PCB_LAYER_ID, OPENGL_RENDER_LIST * > MAP_OGL_DISP_LISTS
MAP_3DMODEL m_3dModelMap
void render3dModels(bool aRenderTopOrBot, bool aRenderTransparentOnly)
Helper class to handle information needed to display 3D board.
Definition: board_adapter.h:68
bool Redraw(bool aIsMoving, REPORTER *aStatusReporter, REPORTER *aWarningReporter) override
Redraw the view.
void render3dModelsSelected(bool aRenderTopOrBot, bool aRenderTransparentOnly, bool aRenderSelectedOnly)
OPENGL_RENDER_LIST * generateLayerList(const BVH_CONTAINER_2D *aContainer, const SHAPE_POLY_SET *aPolyList, PCB_LAYER_ID aLayerId, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
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 aZPosition, bool aDrawMiddleSegments, bool aSkipRenderHoles)
SFVEC4F getLayerColor(PCB_LAYER_ID aLayerID)