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
32#include "../raytracing/shapes2D/polygon_2d.h"
33#include "../raytracing/shapes2D/triangle_2d.h"
34#include "../raytracing/shapes2D/4pt_polygon_2d.h"
35#include "../raytracing/shapes2D/filled_circle_2d.h"
36#include "../raytracing/shapes2D/ring_2d.h"
37#include "../raytracing/shapes2D/round_segment_2d.h"
38
39#include "3d_model.h"
40
41#include "3d_cache/3d_info.h"
42
43#include <map>
44
45typedef std::map< PCB_LAYER_ID, OPENGL_RENDER_LIST* > MAP_OGL_DISP_LISTS;
46typedef std::list<TRIANGLE_DISPLAY_LIST* > LIST_TRIANGLES;
47
48#define SIZE_OF_CIRCLE_TEXTURE 1024
49
54{
55public:
56 explicit RENDER_3D_OPENGL( EDA_3D_CANVAS* aCanvas, BOARD_ADAPTER& aAdapter, CAMERA& aCamera );
57
59
60 void SetCurWindowSize( const wxSize& aSize ) override;
61 bool Redraw( bool aIsMoving, REPORTER* aStatusReporter, REPORTER* aWarningReporter ) override;
62
63 int GetWaitForEditingTimeOut() override;
64
65 void SetCurrentRollOverItem( BOARD_ITEM* aRollOverItem )
66 {
67 m_currentRollOverItem = aRollOverItem;
68 }
69
74 void handleGizmoMouseInput( int mouseX, int mouseY );
75 void setGizmoViewport( int x, int y, int width, int height );
76 std::tuple<int, int, int, int> getGizmoViewport() const;
79
80private:
81 OPENGL_RENDER_LIST* generateHoles( const LIST_OBJECT2D& aListHolesObject2d,
82 const SHAPE_POLY_SET& aPoly, float aZtop, float aZbot,
83 bool aInvertFaces,
84 const BVH_CONTAINER_2D* aThroughHoles = nullptr );
85
87 const SHAPE_POLY_SET* aPolyList, PCB_LAYER_ID aLayer,
88 const BVH_CONTAINER_2D* aThroughHoles = nullptr );
89
91
93 const SFVEC2F& v1, const SFVEC2F& v2, float top, float bot );
94
95 void addObjectTriangles( const RING_2D* aRing, TRIANGLE_DISPLAY_LIST* aDstLayer,
96 float aZtop, float aZbot );
97
98 void addObjectTriangles( const POLYGON_4PT_2D* aPoly, TRIANGLE_DISPLAY_LIST* aDstLayer,
99 float aZtop, float aZbot );
100
101 void addObjectTriangles( const FILLED_CIRCLE_2D* aCircle, TRIANGLE_DISPLAY_LIST* aDstLayer,
102 float aZtop, float aZbot );
103
104 void addObjectTriangles( const TRIANGLE_2D* aTri, TRIANGLE_DISPLAY_LIST* aDstLayer,
105 float aZtop, float aZbot );
106
107 void addObjectTriangles( const ROUND_SEGMENT_2D* aSeg, TRIANGLE_DISPLAY_LIST* aDstLayer,
108 float aZtop, float aZbot );
109
110 void renderSolderMaskLayer( PCB_LAYER_ID aLayerID, float aZPos, bool aShowThickness,
111 bool aSkipRenderHoles );
112
113 void renderBoardBody( bool aSkipRenderHoles );
114
115 void getLayerZPos( PCB_LAYER_ID aLayerID, float& aOutZtop, float& aOutZbot ) const;
116
117 void generateRing( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
118 unsigned int aNr_sides_per_circle,
119 std::vector< SFVEC2F >& aInnerContourResult,
120 std::vector< SFVEC2F >& aOuterContourResult, bool aInvertOrder );
121
122 void generateCylinder( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
123 float aZtop, float aZbot, unsigned int aNr_sides_per_circle,
124 TRIANGLE_DISPLAY_LIST* aDstLayer );
125
126 void generateViasAndPads();
127
135 void load3dModels( REPORTER* aStatusReporter );
136
138 {
144
145 MODELTORENDER( glm::mat4 aModelWorldMat,
146 const MODEL_3D* aNodel,
147 float aOpacity,
148 bool aIsTransparent,
149 bool aIsSelected ) :
150 m_modelWorldMat( std::move( aModelWorldMat ) ),
151 m_model( aNodel ),
152 m_opacity( aOpacity ),
153 m_isTransparent( aIsTransparent ),
154 m_isSelected( aIsSelected )
155 {
156 }
157 };
158
159 void renderOpaqueModels( const glm::mat4 &aCameraViewMatrix );
160 void renderTransparentModels( const glm::mat4 &aCameraViewMatrix );
161
162 void renderModel( const glm::mat4 &aCameraViewMatrix, const MODELTORENDER &aModelToRender,
163 const SFVEC3F &aSelColor, const SFVEC3F *aCameraWorldPos );
164
165
166 void get3dModelsSelected( std::list<MODELTORENDER> &aDstRenderList, bool aGetTop, bool aGetBot,
167 bool aRenderTransparentOnly, bool aRenderSelectedOnly );
168
169 void get3dModelsFromFootprint( std::list<MODELTORENDER> &aDstRenderList,
170 const FOOTPRINT* aFootprint, bool aRenderTransparentOnly,
171 bool aIsSelected );
172
173 void setLightFront( bool enabled );
174 void setLightTop( bool enabled );
175 void setLightBottom( bool enabled );
176
182 void generate3dGrid( GRID3D_TYPE aGridType );
183
184 // Materials
185 void setupMaterials();
186
187 void setCopperMaterial();
189 void unsetDepthOffset();
190
191 void setLayerMaterial( PCB_LAYER_ID aLayerID );
192
193 bool initializeOpenGL();
195 const BVH_CONTAINER_2D* aThroughHoles = nullptr );
196 void reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter );
197
198 void setArrowMaterial();
199
200 void freeAllLists();
201
202 struct
203 {
214
216
230
233
234 GLuint m_grid;
236
239
240 // Caches
241 std::map<wxString, MODEL_3D*> m_3dModelMap;
242 std::map<std::vector<float>, glm::mat4> m_3dModelMatrixMap;
243
245
249};
250
251#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 * 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
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
SPHERES_GIZMO * m_spheres_gizmo
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 handleGizmoMouseInput(int mouseX, int mouseY)
void setLightBottom(bool enabled)
void setGizmoViewport(int x, int y, int width, int height)
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
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