KiCad PCB EDA Suite
c3d_render_ogl_legacy.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 <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2020 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 
30 #ifndef C3D_RENDER_OGL_LEGACY_H_
31 #define C3D_RENDER_OGL_LEGACY_H_
32 
33 #include "../c3d_render_base.h"
34 #include "clayer_triangles.h"
35 
36 #include "../3d_render_raytracing/shapes2D/cpolygon2d.h"
37 #include "../3d_render_raytracing/shapes2D/ctriangle2d.h"
38 #include "../3d_render_raytracing/shapes2D/cpolygon4pts2d.h"
39 #include "../3d_render_raytracing/shapes2D/cfilledcircle2d.h"
40 #include "../3d_render_raytracing/shapes2D/cring2d.h"
41 #include "../3d_render_raytracing/shapes2D/croundsegment2d.h"
42 
43 #include "c_ogl_3dmodel.h"
44 
45 #include "3d_cache/3d_info.h"
46 
47 #include <map>
48 
49 
50 typedef std::map< PCB_LAYER_ID, CLAYERS_OGL_DISP_LISTS* > MAP_OGL_DISP_LISTS;
51 typedef std::list<CLAYER_TRIANGLES * > LIST_TRIANGLES;
52 typedef std::map< wxString, C_OGL_3DMODEL * > MAP_3DMODEL;
53 
54 #define SIZE_OF_CIRCLE_TEXTURE 1024
55 
60 {
61 public:
62  explicit C3D_RENDER_OGL_LEGACY( BOARD_ADAPTER& aAdapter, CCAMERA& aCamera );
63 
65 
66  // Imported from C3D_RENDER_BASE
67  void SetCurWindowSize( const wxSize &aSize ) override;
68  bool Redraw( bool aIsMoving, REPORTER* aStatusReporter, REPORTER* aWarningReporter ) override;
69 
70  int GetWaitForEditingTimeOut() override;
71 
72  void SetCurrentIntersectedBoardItem( BOARD_ITEM* aCurrentIntersectedBoardItem ) { m_currentIntersectedBoardItem = aCurrentIntersectedBoardItem; }
73 
74 private:
75  bool initializeOpenGL();
77  void reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter );
78 
80 
90 
91  // User for body render
93 
96  //CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_through_holes_vias_inner; // Not in use
97 
98  // This is for pads holes of the footprints
99  //CLAYERS_OGL_DISP_LISTS* m_ogl_disp_list_vias_and_pad_holes_inner_contourn_and_caps;
101 
102  LIST_TRIANGLES m_triangles; // store pointers so can be deleted latter
103 
105 
107 
109 
112 
114 
116 
117 private:
119  const SHAPE_POLY_SET &aPoly,
120  float aZtop,
121  float aZbot,
122  bool aInvertFaces );
123 
125  const SHAPE_POLY_SET *aPolyList,
126  PCB_LAYER_ID aLayerId );
127 
129  const SFVEC2F &v0,
130  const SFVEC2F &v1,
131  const SFVEC2F &v2,
132  float top,
133  float bot );
134 
135  void add_object_to_triangle_layer( const CRING2D *aRing,
136  CLAYER_TRIANGLES *aDstLayer,
137  float aZtop,
138  float aZbot );
139 
140  void add_object_to_triangle_layer( const CPOLYGON4PTS2D *aPoly,
141  CLAYER_TRIANGLES *aDstLayer,
142  float aZtop,
143  float aZbot );
144 
145  void add_object_to_triangle_layer( const CFILLEDCIRCLE2D *aFilledCircle,
146  CLAYER_TRIANGLES *aDstLayer,
147  float aZtop,
148  float aZbot );
149 
150  void add_object_to_triangle_layer( const CTRIANGLE2D *aTri,
151  CLAYER_TRIANGLES *aDstLayer,
152  float aZtop,
153  float aZbot );
154 
156  CLAYER_TRIANGLES *aDstLayer,
157  float aZtop,
158  float aZbot );
159 
160  void render_solder_mask_layer( PCB_LAYER_ID aLayerID,
161  float aZPosition,
162  bool aDrawMiddleSegments,
163  bool aSkipRenderHoles );
164 
165  void render_board_body( bool aSkipRenderHoles );
166 
167  void get_layer_z_pos( PCB_LAYER_ID aLayerID,
168  float &aOutZtop,
169  float &aOutZbot ) const;
170 
171  void generate_ring_contour( const SFVEC2F &aCenter,
172  float aInnerRadius,
173  float aOuterRadius,
174  unsigned int aNr_sides_per_circle,
175  std::vector< SFVEC2F > &aInnerContourResult,
176  std::vector< SFVEC2F > &aOuterContourResult,
177  bool aInvertOrder );
178 
179  void generate_cylinder( const SFVEC2F &aCenter,
180  float aInnerRadius,
181  float aOuterRadius,
182  float aZtop,
183  float aZbot,
184  unsigned int aNr_sides_per_circle,
185  CLAYER_TRIANGLES *aDstLayer );
186 
188 
189  void load_3D_models( REPORTER* aStatusReporter );
190 
197  void render_3D_models( bool aRenderTopOrBot, bool aRenderTransparentOnly );
198 
199  void render_3D_models_selected( bool aRenderTopOrBot, bool aRenderTransparentOnly, bool aRenderSelectedOnly );
200 
201  void render_3D_module( const MODULE* module, bool aRenderTransparentOnly, bool aIsSelected );
202 
203  void setLight_Front( bool enabled );
204  void setLight_Top( bool enabled );
205  void setLight_Bottom( bool enabled );
206 
207  void render_3D_arrows();
208 
209  void generate_new_3DGrid( GRID3D_TYPE aGridType );
210 
211  // Materials
212  void setupMaterials();
213 
214  void setCopperMaterial();
216  void unsetDepthOffset();
217 
218  struct
219  {
229  }m_materials;
230 
231  void set_layer_material( PCB_LAYER_ID aLayerID );
233 };
234 
235 #endif // C3D_RENDER_OGL_LEGACY_H_
236 
void generate_ring_contour(const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, unsigned int aNr_sides_per_circle, std::vector< SFVEC2F > &aInnerContourResult, std::vector< SFVEC2F > &aOuterContourResult, bool aInvertOrder)
MAP_OGL_DISP_LISTS m_ogl_disp_lists_layers
CLAYERS_OGL_DISP_LISTS * m_ogl_disp_lists_platedPads_F_Cu
void generate_new_3DGrid(GRID3D_TYPE aGridType)
void add_object_to_triangle_layer(const CRING2D *aRing, CLAYER_TRIANGLES *aDstLayer, float aZtop, float aZbot)
implement a legacy 3dmodel render
The CLAYER_TRIANGLES class stores arrays of triangles to be used to create display lists.
void render_3D_models_selected(bool aRenderTopOrBot, bool aRenderTransparentOnly, bool aRenderSelectedOnly)
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void render_3D_module(const MODULE *module, bool aRenderTransparentOnly, bool aIsSelected)
MAP_OGL_DISP_LISTS m_ogl_disp_lists_layers_holes_outer
CLAYERS_OGL_DISP_LISTS * m_ogl_disp_lists_platedPads_B_Cu
void render_3D_models(bool aRenderTopOrBot, bool aRenderTransparentOnly)
render_3D_models
glm::vec4 SFVEC4F
Definition: xv3d_types.h:49
CLAYERS_OGL_DISP_LISTS * generateLayerListFromContainer(const CBVHCONTAINER2D *aContainer, const SHAPE_POLY_SET *aPolyList, PCB_LAYER_ID aLayerId)
Class CCAMERA is a virtual class used to derive CCAMERA objects from.
Definition: ccamera.h:79
CLAYERS_OGL_DISP_LISTS * m_ogl_disp_list_anti_board
CLAYERS_OGL_DISP_LISTS * m_ogl_disp_list_through_holes_outer_ring
REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
defines the basic data associated with a single 3D model.
void setLight_Top(bool enabled)
GRID3D_TYPE m_last_grid_type
Stores the last grid computed.
void render_solder_mask_layer(PCB_LAYER_ID aLayerID, float aZPosition, bool aDrawMiddleSegments, bool aSkipRenderHoles)
int GetWaitForEditingTimeOut() override
GetWaitForEditingTimeOut - Give the interface the time (in ms) that it should wait for editing or mov...
CLAYERS_OGL_DISP_LISTS * m_ogl_disp_list_through_holes_outer
void setPlatedCopperAndDepthOffset(PCB_LAYER_ID aLayer_id)
void get_layer_z_pos(PCB_LAYER_ID aLayerID, float &aOutZtop, float &aOutZbot) const
PCB_LAYER_ID
A quick note on layer IDs:
void setLight_Front(bool enabled)
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
std::list< CLAYER_TRIANGLES * > LIST_TRIANGLES
void setLight_Bottom(bool enabled)
SHAPE_POLY_SET.
CLAYERS_OGL_DISP_LISTS * createBoard(SHAPE_POLY_SET aBoardPoly)
void SetCurWindowSize(const wxSize &aSize) override
SetCurWindowSize - Before each render, the canvas will tell the render what is the size of its window...
void load_3D_models(REPORTER *aStatusReporter)
CLAYERS_OGL_DISP_LISTS * m_ogl_disp_list_through_holes_vias_outer
BOARD_ITEM * m_currentIntersectedBoardItem
struct C3D_RENDER_OGL_LEGACY::@0 m_materials
void reload(REPORTER *aStatusReporter, REPORTER *aWarningReporter)
GRID3D_TYPE
Grid types.
Definition: 3d_enums.h:98
CLAYERS_OGL_DISP_LISTS * m_ogl_disp_list_via
GLuint m_ogl_disp_list_grid
oGL list that stores current grid
std::map< PCB_LAYER_ID, CLAYERS_OGL_DISP_LISTS * > MAP_OGL_DISP_LISTS
MAP_OGL_DISP_LISTS m_ogl_disp_lists_layers_holes_inner
The CLAYERS_OGL_DISP_LISTS class stores the openGL display lists to related with a layer.
std::map< wxString, C_OGL_3DMODEL * > MAP_3DMODEL
The C3D_RENDER_OGL_LEGACY class render the board using openGL legacy mode.
CLAYERS_OGL_DISP_LISTS * generate_holes_display_list(const LIST_OBJECT2D &aListHolesObject2d, const SHAPE_POLY_SET &aPoly, float aZtop, float aZbot, bool aInvertFaces)
CLAYERS_OGL_DISP_LISTS * m_ogl_disp_list_through_holes_outer_with_npth
This handles simple polygons with 4 points.
std::list< COBJECT2D * > LIST_OBJECT2D
Definition: ccontainer2d.h:37
bool Redraw(bool aIsMoving, REPORTER *aStatusReporter, REPORTER *aWarningReporter) override
Redraw - Ask to redraw the view.
CLAYERS_OGL_DISP_LISTS * m_ogl_disp_list_board
void SetCurrentIntersectedBoardItem(BOARD_ITEM *aCurrentIntersectedBoardItem)
SFVEC4F get_layer_color(PCB_LAYER_ID aLayerID)
CLAYERS_OGL_DISP_LISTS * m_ogl_disp_list_vias_and_pad_holes_outer_contourn_and_caps
void set_layer_material(PCB_LAYER_ID aLayerID)
C3D_RENDER_OGL_LEGACY(BOARD_ADAPTER &aAdapter, CCAMERA &aCamera)
void add_triangle_top_bot(CLAYER_TRIANGLES *aDst, const SFVEC2F &v0, const SFVEC2F &v1, const SFVEC2F &v2, float top, float bot)
CLAYERS_OGL_DISP_LISTS * m_ogl_disp_list_pads_holes
Class BOARD_ADAPTER Helper class to handle information needed to display 3D board.
Definition: board_adapter.h:68
void render_board_body(bool aSkipRenderHoles)
void generate_cylinder(const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, float aZtop, float aZbot, unsigned int aNr_sides_per_circle, CLAYER_TRIANGLES *aDstLayer)
This is a base class to hold data and functions for render targets.