KiCad PCB EDA Suite
layer_triangles.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) 1992-2021 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 TRIANGLE_DISPLAY_LIST_H
26 #define TRIANGLE_DISPLAY_LIST_H
27 
28 #include "../../common_ogl/openGL_includes.h"
33 #include <vector>
34 #include <mutex>
35 
36 
37 typedef std::vector< SFVEC3F > SFVEC3F_VECTOR;
38 
39 
44 {
45 public:
46 
51  TRIANGLE_LIST( unsigned int aNrReservedTriangles, bool aReserveNormals );
52 
56  void Reserve_More( unsigned int aNrReservedTriangles, bool aReserveNormals );
57 
58  void AddTriangle( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3 );
59 
60  void AddQuad( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3, const SFVEC3F& aV4 );
61 
62  void AddNormal( const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3 );
63 
64  void AddNormal( const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3,
65  const SFVEC3F& aN4 );
66 
72  const float* GetVertexPointer() const { return (const float *)&m_vertexs[0].x; }
73 
79  const float* GetNormalsPointer() const { return (const float*) &m_normals[0].x; }
80 
81  unsigned int GetVertexSize() const { return (unsigned int) m_vertexs.size(); }
82 
83  unsigned int GetNormalsSize() const { return (unsigned int) m_normals.size(); }
84 
85 private:
88 };
89 
90 
95 {
96 public:
102  explicit TRIANGLE_DISPLAY_LIST( unsigned int aNrReservedTriangles );
103 
105 
111  bool IsLayersSizeValid();
112 
113 
114  void AddToMiddleContourns( const SHAPE_LINE_CHAIN& outlinePath, float zBot, float zTop,
115  double aBiuTo3Du, bool aInvertFaceDirection,
116  const BVH_CONTAINER_2D* aThroughHoles = nullptr );
117 
118  void AddToMiddleContourns( const SHAPE_POLY_SET& aPolySet, float zBot, float zTop,
119  double aBiuTo3Du, bool aInvertFaceDirection,
120  const BVH_CONTAINER_2D* aThroughHoles = nullptr );
121 
122  void AddToMiddleContourns( const std::vector< SFVEC2F >& aContournPoints, float zBot,
123  float zTop, bool aInvertFaceDirection,
124  const BVH_CONTAINER_2D* aThroughHoles = nullptr );
125 
127 
133 };
134 
135 
140 {
141 public:
151  OPENGL_RENDER_LIST( const TRIANGLE_DISPLAY_LIST& aLayerTriangles,
152  GLuint aTextureIndexForSegEnds, float aZBot, float aZTop );
153 
158 
162  void DrawTopAndMiddle() const;
163 
167  void DrawBotAndMiddle() const;
168 
172  void DrawTop() const;
173 
177  void DrawBot() const;
178 
182  void DrawMiddle() const;
183 
187  void DrawAll( bool aDrawMiddle = true ) const;
188 
197  void DrawAllCameraCulled( float zCameraPos, bool aDrawMiddle = true ) const;
198 
199  void DrawAllCameraCulledSubtractLayer( bool aDrawMiddle,
200  const OPENGL_RENDER_LIST* aLayerToSubtractA = nullptr,
201  const OPENGL_RENDER_LIST* aLayerToSubtractB = nullptr,
202  const OPENGL_RENDER_LIST* aLayerToSubtractC = nullptr,
203  const OPENGL_RENDER_LIST* aLayerToSubtractD = nullptr ) const;
204 
205  void ApplyScalePosition( float aZposition, float aZscale );
206 
208 
209  void SetItIsTransparent( bool aSetTransparent );
210 
211  float GetZBot() const { return m_zBot; }
212  float GetZTop() const { return m_zTop; }
213 
214 private:
215  GLuint generate_top_or_bot_seg_ends( const TRIANGLE_LIST* aTriangleContainer,
216  bool aIsNormalUp, GLuint aTextureId ) const;
217 
218  GLuint generate_top_or_bot_triangles( const TRIANGLE_LIST* aTriangleContainer,
219  bool aIsNormalUp ) const;
220 
221  GLuint generate_middle_triangles( const TRIANGLE_LIST* aTriangleContainer ) const;
222 
223  void beginTransformation() const;
224  void endTransformation() const;
225 
226  void setBlendfunction() const;
227 
228 private:
229  float m_zBot;
230  float m_zTop;
236 
240 
242 };
243 
244 #endif // TRIANGLE_DISPLAY_LIST_H
Container to manage a vector of triangles.
TRIANGLE_LIST(unsigned int aNrReservedTriangles, bool aReserveNormals)
unsigned int GetVertexSize() const
Store arrays of triangles to be used to create display lists.
void DrawBotAndMiddle() const
Call the display lists for the bottom elements and middle contours.
void DrawTop() const
Call the display lists for the top elements.
void DrawAllCameraCulledSubtractLayer(bool aDrawMiddle, const OPENGL_RENDER_LIST *aLayerToSubtractA=nullptr, const OPENGL_RENDER_LIST *aLayerToSubtractB=nullptr, const OPENGL_RENDER_LIST *aLayerToSubtractC=nullptr, const OPENGL_RENDER_LIST *aLayerToSubtractD=nullptr) const
float GetZBot() const
void DrawAllCameraCulled(float zCameraPos, bool aDrawMiddle=true) const
Draw all layers if they are visible by the camera if camera position is above the layer.
std::mutex m_middle_layer_lock
void beginTransformation() const
TRIANGLE_LIST * m_layer_middle_contourns_quads
void DrawTopAndMiddle() const
Call the display lists for the top elements and middle contours.
void Reserve_More(unsigned int aNrReservedTriangles, bool aReserveNormals)
Reserve more triangles.
bool IsLayersSizeValid()
Check if the vertex arrays of the layers are as expected.
TRIANGLE_LIST * m_layer_top_triangles
TRIANGLE_DISPLAY_LIST(unsigned int aNrReservedTriangles)
Initialize arrays with reserved triangles.
void DrawMiddle() const
Call the display lists for the middle elements.
void setBlendfunction() const
OPENGL_RENDER_LIST(const TRIANGLE_DISPLAY_LIST &aLayerTriangles, GLuint aTextureIndexForSegEnds, float aZBot, float aZTop)
Create the display lists for a layer.
const float * GetNormalsPointer() const
Get the array of normals.
unsigned int GetNormalsSize() const
Represent a set of closed polygons.
void AddQuad(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3, const SFVEC3F &aV4)
void AddTriangle(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3)
void ApplyScalePosition(float aZposition, float aZscale)
void AddToMiddleContourns(const SHAPE_LINE_CHAIN &outlinePath, float zBot, float zTop, double aBiuTo3Du, bool aInvertFaceDirection, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
TRIANGLE_LIST * m_layer_bot_triangles
void DrawAll(bool aDrawMiddle=true) const
Call to draw all the display lists.
SFVEC3F_VECTOR m_normals
normals array
Store the OpenGL display lists to related with a layer.
const float * GetVertexPointer() const
Get the array of vertices.
GLuint generate_top_or_bot_seg_ends(const TRIANGLE_LIST *aTriangleContainer, bool aIsNormalUp, GLuint aTextureId) const
void DrawBot() const
Call the display lists for the bottom elements.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
GLuint generate_middle_triangles(const TRIANGLE_LIST *aTriangleContainer) const
void SetItIsTransparent(bool aSetTransparent)
float GetZTop() const
GLuint generate_top_or_bot_triangles(const TRIANGLE_LIST *aTriangleContainer, bool aIsNormalUp) const
TRIANGLE_LIST * m_layer_bot_segment_ends
GLuint m_layer_middle_contourns_quads
void endTransformation() const
~OPENGL_RENDER_LIST()
Destroy this class while free the display lists from GPU memory.
void AddNormal(const SFVEC3F &aN1, const SFVEC3F &aN2, const SFVEC3F &aN3)
TRIANGLE_LIST * m_layer_top_segment_ends
SFVEC3F_VECTOR m_vertexs
vertex array
std::vector< SFVEC3F > SFVEC3F_VECTOR