KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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 <kicad_gl/kiglad.h> // Must be included first
29
30#include "../render_3d_base.h"
31#include "layer_triangles.h"
32#include "3d_spheres_gizmo.h"
33
40
41#include "3d_model.h"
42
43#include "3d_cache/3d_info.h"
44
45#include <geometry/eda_angle.h>
46#include <pad.h> // For PAD_DRILL_POST_MACHINING_MODE
47
48#include <map>
49
50typedef std::map< PCB_LAYER_ID, OPENGL_RENDER_LIST* > MAP_OGL_DISP_LISTS;
51typedef std::list<TRIANGLE_DISPLAY_LIST* > LIST_TRIANGLES;
52
53#define SIZE_OF_CIRCLE_TEXTURE 1024
54
59{
60public:
61 explicit RENDER_3D_OPENGL( EDA_3D_CANVAS* aCanvas, BOARD_ADAPTER& aAdapter, CAMERA& aCamera );
62
64
65 void SetCurWindowSize( const wxSize& aSize ) override;
66 bool Redraw( bool aIsMoving, REPORTER* aStatusReporter, REPORTER* aWarningReporter ) override;
67
68 int GetWaitForEditingTimeOut() override;
69
70 void SetCurrentRollOverItem( BOARD_ITEM* aRollOverItem )
71 {
72 m_currentRollOverItem = aRollOverItem;
73 }
74
79 void handleGizmoMouseInput( int mouseX, int mouseY );
80 void setGizmoViewport( int x, int y, int width, int height );
81 std::tuple<int, int, int, int> getGizmoViewport() const;
84
85private:
86 OPENGL_RENDER_LIST* generateHoles( const LIST_OBJECT2D& aListHolesObject2d,
87 const SHAPE_POLY_SET& aPoly, float aZtop, float aZbot,
88 bool aInvertFaces,
89 const BVH_CONTAINER_2D* aThroughHoles = nullptr );
90
92 const SHAPE_POLY_SET* aPolyList, PCB_LAYER_ID aLayer,
93 const BVH_CONTAINER_2D* aThroughHoles = nullptr );
94
96
98 const SFVEC2F& v1, const SFVEC2F& v2, float top, float bot );
99
100 void addObjectTriangles( const RING_2D* aRing, TRIANGLE_DISPLAY_LIST* aDstLayer,
101 float aZtop, float aZbot );
102
103 void addObjectTriangles( const POLYGON_4PT_2D* aPoly, TRIANGLE_DISPLAY_LIST* aDstLayer,
104 float aZtop, float aZbot );
105
106 void addObjectTriangles( const FILLED_CIRCLE_2D* aCircle, TRIANGLE_DISPLAY_LIST* aDstLayer,
107 float aZtop, float aZbot );
108
109 void addObjectTriangles( const TRIANGLE_2D* aTri, TRIANGLE_DISPLAY_LIST* aDstLayer,
110 float aZtop, float aZbot );
111
112 void addObjectTriangles( const ROUND_SEGMENT_2D* aSeg, TRIANGLE_DISPLAY_LIST* aDstLayer,
113 float aZtop, float aZbot );
114
115 void renderSolderMaskLayer( PCB_LAYER_ID aLayerID, float aZPos, bool aShowThickness,
116 bool aSkipRenderHoles );
117
118 void renderBoardBody( bool aSkipRenderHoles );
119
120 void getLayerZPos( PCB_LAYER_ID aLayerID, float& aOutZtop, float& aOutZbot ) const;
121
122 void generateRing( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
123 unsigned int aNr_sides_per_circle,
124 std::vector< SFVEC2F >& aInnerContourResult,
125 std::vector< SFVEC2F >& aOuterContourResult, bool aInvertOrder );
126
127 void generateCylinder( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
128 float aZtop, float aZbot, unsigned int aNr_sides_per_circle,
129 TRIANGLE_DISPLAY_LIST* aDstLayer );
130
131 void generateInvCone( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
132 float aZtop, float aZbot, unsigned int aNr_sides_per_circle,
133 TRIANGLE_DISPLAY_LIST* aDstLayer, EDA_ANGLE aAngle );
134
135 void generateDisk( const SFVEC2F& aCenter, float aRadius, float aZ,
136 unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST* aDstLayer,
137 bool aTop );
138
139 void generateDimple( const SFVEC2F& aCenter, float aRadius, float aZ, float aDepth,
140 unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST* aDstLayer,
141 bool aTop );
142
143 void generateViasAndPads();
144
146 const SFVEC2F& aHoleCenter,
148 int aSizeIU,
149 int aDepthIU,
150 float aHoleInnerRadius,
151 float aZSurface,
152 bool aIsFront,
153 float aPlatingThickness3d,
154 float aUnitScale,
155 float* aZEnd );
156
157 void generateViaBarrels( float aPlatingThickness3d, float aUnitScale );
158
159 void generatePlatedHoleShells( int aPlatingThickness, float aUnitScale );
160
161 void generateViaCovers( float aPlatingThickness3d, float aUnitScale );
162
170 void load3dModels( REPORTER* aStatusReporter );
171
173 {
179
180 MODELTORENDER( glm::mat4 aModelWorldMat,
181 const MODEL_3D* aNodel,
182 float aOpacity,
183 bool aIsTransparent,
184 bool aIsSelected ) :
185 m_modelWorldMat( std::move( aModelWorldMat ) ),
186 m_model( aNodel ),
187 m_opacity( aOpacity ),
188 m_isTransparent( aIsTransparent ),
189 m_isSelected( aIsSelected )
190 {
191 }
192 };
193
194 void renderOpaqueModels( const glm::mat4 &aCameraViewMatrix );
195 void renderTransparentModels( const glm::mat4 &aCameraViewMatrix );
196
197 void renderModel( const glm::mat4 &aCameraViewMatrix, const MODELTORENDER &aModelToRender,
198 const SFVEC3F &aSelColor, const SFVEC3F *aCameraWorldPos );
199
200
201 void get3dModelsSelected( std::list<MODELTORENDER> &aDstRenderList, bool aGetTop, bool aGetBot,
202 bool aRenderTransparentOnly, bool aRenderSelectedOnly );
203
204 void get3dModelsFromFootprint( std::list<MODELTORENDER> &aDstRenderList,
205 const FOOTPRINT* aFootprint, bool aRenderTransparentOnly,
206 bool aIsSelected );
207
208 void setLightFront( bool enabled );
209 void setLightTop( bool enabled );
210 void setLightBottom( bool enabled );
211
217 void generate3dGrid( GRID3D_TYPE aGridType );
218
219 // Materials
220 void setupMaterials();
221
222 void setCopperMaterial();
224 void unsetDepthOffset();
225
226 void setLayerMaterial( PCB_LAYER_ID aLayerID );
227
228 bool initializeOpenGL();
230 const BVH_CONTAINER_2D* aThroughHoles = nullptr );
231
237 void backfillPostMachine();
238
239 void reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter );
240
241 void setArrowMaterial();
242
243 void freeAllLists();
244
245 struct
246 {
257
259
274
277
278 GLuint m_grid;
280
285
286 // Caches
287 std::map<wxString, MODEL_3D*> m_3dModelMap;
288 std::map<std::vector<float>, glm::mat4> m_3dModelMatrixMap;
289
291
295};
296
297#endif // RENDER_3D_OPENGL_H
GRID3D_TYPE
Grid types.
Definition 3d_enums.h:54
defines the basic data associated with a single 3D model.
A simplified non-intersecting 4 point polygon.
Helper class to handle information needed to display 3D board.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
A class used to derive camera objects from.
Definition camera.h:103
Implement a canvas based on a wxGLCanvas.
Store the OpenGL display lists to related with a layer.
Simple non-intersecting polygon with 4 points.
RENDER_3D_BASE(BOARD_ADAPTER &aBoardAdapter, CAMERA &aCamera)
OPENGL_RENDER_LIST * m_board
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)
void generateCylinder(const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, float aZtop, float aZbot, unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST *aDstLayer)
OPENGL_RENDER_LIST * m_outerThroughHoleRings
OPENGL_RENDER_LIST * m_offboardPadsFront
SPHERES_GIZMO::GizmoSphereSelection getSelectedGizmoSphere() const
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)
SHAPE_POLY_SET m_antiBoardPolys
The negative polygon representation of the board outline.
void load3dModels(REPORTER *aStatusReporter)
Load footprint models from the cache and load it to openGL lists in the form of MODEL_3D objects.
GRID3D_TYPE m_lastGridType
Stores the last grid type.
std::tuple< int, int, int, int > getGizmoViewport() const
OPENGL_RENDER_LIST * generateLayerList(const BVH_CONTAINER_2D *aContainer, const SHAPE_POLY_SET *aPolyList, PCB_LAYER_ID aLayer, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
OPENGL_RENDER_LIST * m_microviaHoles
void renderOpaqueModels(const glm::mat4 &aCameraViewMatrix)
OPENGL_RENDER_LIST * createBoard(const SHAPE_POLY_SET &aBoardPoly, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
void Load3dModelsIfNeeded()
Load footprint models if they are not already loaded, i.e.
void generate3dGrid(GRID3D_TYPE aGridType)
Create a 3D grid to an OpenGL display list.
void setLightFront(bool enabled)
void addObjectTriangles(const RING_2D *aRing, TRIANGLE_DISPLAY_LIST *aDstLayer, float aZtop, float aZbot)
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)
void generateInvCone(const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, float aZtop, float aZbot, unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST *aDstLayer, EDA_ANGLE aAngle)
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
void SetCurrentRollOverItem(BOARD_ITEM *aRollOverItem)
OPENGL_RENDER_LIST * m_viaFrontCover
OPENGL_RENDER_LIST * generateEmptyLayerList(PCB_LAYER_ID aLayer)
LIST_TRIANGLES m_triangles
store pointers so can be deleted latter
OPENGL_RENDER_LIST * m_outerViaThroughHoles
OPENGL_RENDER_LIST * m_outerThroughHoles
void setLayerMaterial(PCB_LAYER_ID aLayerID)
void generateViaCovers(float aPlatingThickness3d, float aUnitScale)
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...
SMATERIAL m_NonPlatedCopper
void generatePlatedHoleShells(int aPlatingThickness, float aUnitScale)
void renderSolderMaskLayer(PCB_LAYER_ID aLayerID, float aZPos, bool aShowThickness, bool aSkipRenderHoles)
void renderTransparentModels(const glm::mat4 &aCameraViewMatrix)
void generateDisk(const SFVEC2F &aCenter, float aRadius, float aZ, unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST *aDstLayer, bool aTop)
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.
bool appendPostMachiningGeometry(TRIANGLE_DISPLAY_LIST *aDstLayer, const SFVEC2F &aHoleCenter, PAD_DRILL_POST_MACHINING_MODE aMode, int aSizeIU, int aDepthIU, float aHoleInnerRadius, float aZSurface, bool aIsFront, float aPlatingThickness3d, float aUnitScale, float *aZEnd)
void setPlatedCopperAndDepthOffset(PCB_LAYER_ID aLayer_id)
OPENGL_RENDER_LIST * m_antiBoard
void getLayerZPos(PCB_LAYER_ID aLayerID, float &aOutZtop, float &aOutZbot) const
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
OPENGL_RENDER_LIST * m_padHoles
void addTopAndBottomTriangles(TRIANGLE_DISPLAY_LIST *aDst, const SFVEC2F &v0, const SFVEC2F &v1, const SFVEC2F &v2, float top, float bot)
SPHERES_GIZMO * m_spheres_gizmo
void generateViaBarrels(float aPlatingThickness3d, float aUnitScale)
GLuint m_grid
oGL list that stores current grid
OPENGL_RENDER_LIST * m_platedPadsBack
void generateDimple(const SFVEC2F &aCenter, float aRadius, float aZ, float aDepth, unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST *aDstLayer, bool aTop)
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 backfillPostMachine()
Create ring-shaped plugs for holes that have backdrill or post-machining.
void setLightTop(bool enabled)
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
Represent a set of closed polygons.
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.
std::list< OBJECT_2D * > LIST_OBJECT2D
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
STL namespace.
PAD_DRILL_POST_MACHINING_MODE
Definition padstack.h:76
std::list< TRIANGLE_DISPLAY_LIST * > LIST_TRIANGLES
std::map< PCB_LAYER_ID, OPENGL_RENDER_LIST * > MAP_OGL_DISP_LISTS
MODELTORENDER(glm::mat4 aModelWorldMat, const MODEL_3D *aNodel, float aOpacity, bool aIsTransparent, bool aIsSelected)
KIBIS top(path, &reporter)
VECTOR3I v1(5, 5, 5)
VECTOR2I v2(1, 0)
glm::vec2 SFVEC2F
Definition xv3d_types.h:42
glm::vec3 SFVEC3F
Definition xv3d_types.h:44