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 (C) 2015-2024 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
44typedef std::map< PCB_LAYER_ID, OPENGL_RENDER_LIST* > MAP_OGL_DISP_LISTS;
45typedef std::list<TRIANGLE_DISPLAY_LIST* > LIST_TRIANGLES;
46
47#define SIZE_OF_CIRCLE_TEXTURE 1024
48
53{
54public:
55 explicit RENDER_3D_OPENGL( EDA_3D_CANVAS* aCanvas, BOARD_ADAPTER& aAdapter, CAMERA& aCamera );
56
58
59 void SetCurWindowSize( const wxSize& aSize ) override;
60 bool Redraw( bool aIsMoving, REPORTER* aStatusReporter, REPORTER* aWarningReporter ) override;
61
62 int GetWaitForEditingTimeOut() override;
63
64 void SetCurrentRollOverItem( BOARD_ITEM* aRollOverItem )
65 {
66 m_currentRollOverItem = aRollOverItem;
67 }
68
73
74private:
75 OPENGL_RENDER_LIST* generateHoles( const LIST_OBJECT2D& aListHolesObject2d,
76 const SHAPE_POLY_SET& aPoly, float aZtop, float aZbot,
77 bool aInvertFaces,
78 const BVH_CONTAINER_2D* aThroughHoles = nullptr );
79
81 const SHAPE_POLY_SET* aPolyList, PCB_LAYER_ID aLayer,
82 const BVH_CONTAINER_2D* aThroughHoles = nullptr );
83
85
87 const SFVEC2F& v1, const SFVEC2F& v2, float top, float bot );
88
89 void addObjectTriangles( const RING_2D* aRing, TRIANGLE_DISPLAY_LIST* aDstLayer,
90 float aZtop, float aZbot );
91
92 void addObjectTriangles( const POLYGON_4PT_2D* aPoly, TRIANGLE_DISPLAY_LIST* aDstLayer,
93 float aZtop, float aZbot );
94
95 void addObjectTriangles( const FILLED_CIRCLE_2D* aCircle, TRIANGLE_DISPLAY_LIST* aDstLayer,
96 float aZtop, float aZbot );
97
98 void addObjectTriangles( const TRIANGLE_2D* aTri, TRIANGLE_DISPLAY_LIST* aDstLayer,
99 float aZtop, float aZbot );
100
101 void addObjectTriangles( const ROUND_SEGMENT_2D* aSeg, TRIANGLE_DISPLAY_LIST* aDstLayer,
102 float aZtop, float aZbot );
103
104 void renderSolderMaskLayer( PCB_LAYER_ID aLayerID, float aZPos, bool aShowThickness,
105 bool aSkipRenderHoles );
106
107 void renderBoardBody( bool aSkipRenderHoles );
108
109 void getLayerZPos( PCB_LAYER_ID aLayerID, float& aOutZtop, float& aOutZbot ) const;
110
111 void generateRing( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
112 unsigned int aNr_sides_per_circle,
113 std::vector< SFVEC2F >& aInnerContourResult,
114 std::vector< SFVEC2F >& aOuterContourResult, bool aInvertOrder );
115
116 void generateCylinder( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
117 float aZtop, float aZbot, unsigned int aNr_sides_per_circle,
118 TRIANGLE_DISPLAY_LIST* aDstLayer );
119
120 void generateViasAndPads();
121
129 void load3dModels( REPORTER* aStatusReporter );
130
132 {
138
139 MODELTORENDER( glm::mat4 aModelWorldMat,
140 const MODEL_3D* aNodel,
141 float aOpacity,
142 bool aIsTransparent,
143 bool aIsSelected ) :
144 m_modelWorldMat( std::move( aModelWorldMat ) ),
145 m_model( aNodel ),
146 m_opacity( aOpacity ),
147 m_isTransparent( aIsTransparent ),
148 m_isSelected( aIsSelected )
149 {
150 }
151 };
152
153 void renderOpaqueModels( const glm::mat4 &aCameraViewMatrix );
154 void renderTransparentModels( const glm::mat4 &aCameraViewMatrix );
155
156 void renderModel( const glm::mat4 &aCameraViewMatrix, const MODELTORENDER &aModelToRender,
157 const SFVEC3F &aSelColor, const SFVEC3F *aCameraWorldPos );
158
159
160 void get3dModelsSelected( std::list<MODELTORENDER> &aDstRenderList, bool aGetTop, bool aGetBot,
161 bool aRenderTransparentOnly, bool aRenderSelectedOnly );
162
163 void get3dModelsFromFootprint( std::list<MODELTORENDER> &aDstRenderList,
164 const FOOTPRINT* aFootprint, bool aRenderTransparentOnly,
165 bool aIsSelected );
166
167 void setLightFront( bool enabled );
168 void setLightTop( bool enabled );
169 void setLightBottom( bool enabled );
170
171 void render3dArrows();
172
178 void generate3dGrid( GRID3D_TYPE aGridType );
179
180 // Materials
181 void setupMaterials();
182
183 void setCopperMaterial();
185 void unsetDepthOffset();
186
187 void setLayerMaterial( PCB_LAYER_ID aLayerID );
188
189 bool initializeOpenGL();
191 const BVH_CONTAINER_2D* aThroughHoles = nullptr );
192 void reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter );
193
194 void setArrowMaterial();
195
196 void freeAllLists();
197
198 struct
199 {
210
212
226
229
230 GLuint m_grid;
232
235
236 // Caches
237 std::map<wxString, MODEL_3D*> m_3dModelMap;
238 std::map<std::vector<float>, glm::mat4> m_3dModelMatrixMap;
239
241
244};
245
246#endif // RENDER_3D_OPENGL_H
GRID3D_TYPE
Grid types.
Definition: 3d_enums.h:54
defines the basic data associated with a single 3D model.
Helper class to handle information needed to display 3D board.
Definition: board_adapter.h:73
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
A class used to derive camera objects from.
Definition: camera.h:103
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:51
Store the OpenGL display lists to related with a layer.
Simple non-intersecting polygon with 4 points.
This is a base class to hold data and functions for render targets.
Object to render the board using openGL.
OPENGL_RENDER_LIST * m_board
OPENGL_RENDER_LIST * m_vias
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
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.
OPENGL_RENDER_LIST * generateLayerList(const BVH_CONTAINER_2D *aContainer, const SHAPE_POLY_SET *aPolyList, PCB_LAYER_ID aLayer, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
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
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
void SetCurrentRollOverItem(BOARD_ITEM *aRollOverItem)
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)
OPENGL_RENDER_LIST * m_platedPadsFront
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 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)
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)
SMATERIAL m_GrayMaterial
GLuint m_grid
oGL list that stores current grid
OPENGL_RENDER_LIST * m_platedPadsBack
void get3dModelsFromFootprint(std::list< MODELTORENDER > &aDstRenderList, const FOOTPRINT *aFootprint, bool aRenderTransparentOnly, bool aIsSelected)
struct RENDER_3D_OPENGL::@2 m_materials
void setLightBottom(bool enabled)
void setLightTop(bool enabled)
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:72
Represent a set of closed polygons.
Store arrays of triangles to be used to create display lists.
std::list< OBJECT_2D * > LIST_OBJECT2D
Definition: container_2d.h:38
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
STL namespace.
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)
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