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 "../render_3d_base.h"
29#include "layer_triangles.h"
30#include "3d_spheres_gizmo.h"
31
38
39#include "3d_model.h"
40
41#include "3d_cache/3d_info.h"
42
43#include <geometry/eda_angle.h>
44
45#include <map>
46
47typedef std::map< PCB_LAYER_ID, OPENGL_RENDER_LIST* > MAP_OGL_DISP_LISTS;
48typedef std::list<TRIANGLE_DISPLAY_LIST* > LIST_TRIANGLES;
49
50#define SIZE_OF_CIRCLE_TEXTURE 1024
51
56{
57public:
58 explicit RENDER_3D_OPENGL( EDA_3D_CANVAS* aCanvas, BOARD_ADAPTER& aAdapter, CAMERA& aCamera );
59
61
62 void SetCurWindowSize( const wxSize& aSize ) override;
63 bool Redraw( bool aIsMoving, REPORTER* aStatusReporter, REPORTER* aWarningReporter ) override;
64
65 int GetWaitForEditingTimeOut() override;
66
67 void SetCurrentRollOverItem( BOARD_ITEM* aRollOverItem )
68 {
69 m_currentRollOverItem = aRollOverItem;
70 }
71
76 void handleGizmoMouseInput( int mouseX, int mouseY );
77 void setGizmoViewport( int x, int y, int width, int height );
78 std::tuple<int, int, int, int> getGizmoViewport() const;
81
82private:
83 OPENGL_RENDER_LIST* generateHoles( const LIST_OBJECT2D& aListHolesObject2d,
84 const SHAPE_POLY_SET& aPoly, float aZtop, float aZbot,
85 bool aInvertFaces,
86 const BVH_CONTAINER_2D* aThroughHoles = nullptr );
87
89 const SHAPE_POLY_SET* aPolyList, PCB_LAYER_ID aLayer,
90 const BVH_CONTAINER_2D* aThroughHoles = nullptr );
91
93
95 const SFVEC2F& v1, const SFVEC2F& v2, float top, float bot );
96
97 void addObjectTriangles( const RING_2D* aRing, TRIANGLE_DISPLAY_LIST* aDstLayer,
98 float aZtop, float aZbot );
99
100 void addObjectTriangles( const POLYGON_4PT_2D* aPoly, TRIANGLE_DISPLAY_LIST* aDstLayer,
101 float aZtop, float aZbot );
102
103 void addObjectTriangles( const FILLED_CIRCLE_2D* aCircle, TRIANGLE_DISPLAY_LIST* aDstLayer,
104 float aZtop, float aZbot );
105
106 void addObjectTriangles( const TRIANGLE_2D* aTri, TRIANGLE_DISPLAY_LIST* aDstLayer,
107 float aZtop, float aZbot );
108
109 void addObjectTriangles( const ROUND_SEGMENT_2D* aSeg, TRIANGLE_DISPLAY_LIST* aDstLayer,
110 float aZtop, float aZbot );
111
112 void renderSolderMaskLayer( PCB_LAYER_ID aLayerID, float aZPos, bool aShowThickness,
113 bool aSkipRenderHoles );
114
115 void renderBoardBody( bool aSkipRenderHoles );
116
117 void getLayerZPos( PCB_LAYER_ID aLayerID, float& aOutZtop, float& aOutZbot ) const;
118
119 void generateRing( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
120 unsigned int aNr_sides_per_circle,
121 std::vector< SFVEC2F >& aInnerContourResult,
122 std::vector< SFVEC2F >& aOuterContourResult, bool aInvertOrder );
123
124 void generateCylinder( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
125 float aZtop, float aZbot, unsigned int aNr_sides_per_circle,
126 TRIANGLE_DISPLAY_LIST* aDstLayer );
127
128 void generateInvCone( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
129 float aZtop, float aZbot, unsigned int aNr_sides_per_circle,
130 TRIANGLE_DISPLAY_LIST* aDstLayer, EDA_ANGLE aAngle );
131
132 void generateDisk( const SFVEC2F& aCenter, float aRadius, float aZ,
133 unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST* aDstLayer,
134 bool aTop );
135
136 void generateDimple( const SFVEC2F& aCenter, float aRadius, float aZ, float aDepth,
137 unsigned int aNr_sides_per_circle, TRIANGLE_DISPLAY_LIST* aDstLayer,
138 bool aTop );
139
140 void generateViasAndPads();
141
143 const SFVEC2F& aHoleCenter,
145 int aSizeIU,
146 int aDepthIU,
147 float aHoleInnerRadius,
148 float aZSurface,
149 bool aIsFront,
150 float aPlatingThickness3d,
151 float aUnitScale,
152 float* aZEnd );
153
154 void generateViaBarrels( float aPlatingThickness3d, float aUnitScale );
155
156 void generatePlatedHoleShells( int aPlatingThickness, float aUnitScale );
157
158 void generateViaCovers( float aPlatingThickness3d, float aUnitScale );
159
167 void load3dModels( REPORTER* aStatusReporter );
168
170 {
176
177 MODELTORENDER( glm::mat4 aModelWorldMat,
178 const MODEL_3D* aNodel,
179 float aOpacity,
180 bool aIsTransparent,
181 bool aIsSelected ) :
182 m_modelWorldMat( std::move( aModelWorldMat ) ),
183 m_model( aNodel ),
184 m_opacity( aOpacity ),
185 m_isTransparent( aIsTransparent ),
186 m_isSelected( aIsSelected )
187 {
188 }
189 };
190
191 void renderOpaqueModels( const glm::mat4 &aCameraViewMatrix );
192 void renderTransparentModels( const glm::mat4 &aCameraViewMatrix );
193
194 void renderModel( const glm::mat4 &aCameraViewMatrix, const MODELTORENDER &aModelToRender,
195 const SFVEC3F &aSelColor, const SFVEC3F *aCameraWorldPos );
196
197
198 void get3dModelsSelected( std::list<MODELTORENDER> &aDstRenderList, bool aGetTop, bool aGetBot,
199 bool aRenderTransparentOnly, bool aRenderSelectedOnly );
200
201 void get3dModelsFromFootprint( std::list<MODELTORENDER> &aDstRenderList,
202 const FOOTPRINT* aFootprint, bool aRenderTransparentOnly,
203 bool aIsSelected );
204
205 void setLightFront( bool enabled );
206 void setLightTop( bool enabled );
207 void setLightBottom( bool enabled );
208
214 void generate3dGrid( GRID3D_TYPE aGridType );
215
216 // Materials
217 void setupMaterials();
218
219 void setCopperMaterial();
221 void unsetDepthOffset();
222
223 void setLayerMaterial( PCB_LAYER_ID aLayerID );
224
225 bool initializeOpenGL();
227 const BVH_CONTAINER_2D* aThroughHoles = nullptr );
228
234 void backfillPostMachine();
235
236 void reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter );
237
238 void setArrowMaterial();
239
240 void freeAllLists();
241
242 struct
243 {
254
256
271
274
275 GLuint m_grid;
277
282
283 // Caches
284 std::map<wxString, MODEL_3D*> m_3dModelMap;
285 std::map<std::vector<float>, glm::mat4> m_3dModelMatrixMap;
286
288
292};
293
294#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:83
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