KiCad PCB EDA Suite
clayer_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 <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2016 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 CLAYER_TRIANGLES_H_
31 #define CLAYER_TRIANGLES_H_
32 
33 #include "../../common_ogl/openGL_includes.h"
37 #include <vector>
38 #include <mutex>
39 
40 
41 typedef std::vector< SFVEC3F > SFVEC3F_VECTOR;
42 
43 
48 {
49 
50 public:
51 
58  CLAYER_TRIANGLE_CONTAINER( unsigned int aNrReservedTriangles, bool aReserveNormals );
59 
64  void Reserve_More( unsigned int aNrReservedTriangles, bool aReserveNormals );
65 
72  void AddTriangle( const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3 );
73 
81  void AddQuad( const SFVEC3F &aV1,
82  const SFVEC3F &aV2,
83  const SFVEC3F &aV3,
84  const SFVEC3F &aV4 );
85 
92  void AddNormal( const SFVEC3F &aN1, const SFVEC3F &aN2, const SFVEC3F &aN3 );
93 
100  void AddNormal( const SFVEC3F &aN1,
101  const SFVEC3F &aN2,
102  const SFVEC3F &aN3,
103  const SFVEC3F &aN4 );
104 
109  const float *GetVertexPointer() const { return (const float *)&m_vertexs[0].x; }
110 
115  const float *GetNormalsPointer() const { return (const float *)&m_normals[0].x; }
116 
121  unsigned int GetVertexSize() const { return (unsigned int)m_vertexs.size(); }
122 
127  unsigned int GetNormalsSize() const { return (unsigned int)m_normals.size(); }
128 
129 private:
132 };
133 
134 
140 {
141 public:
146  explicit CLAYER_TRIANGLES( unsigned int aNrReservedTriangles );
147 
151  ~CLAYER_TRIANGLES();
152 
158  bool IsLayersSizeValid();
159 
160 
161  void AddToMiddleContourns( const SHAPE_LINE_CHAIN &outlinePath,
162  float zBot,
163  float zTop,
164  double aBiuTo3Du,
165  bool aInvertFaceDirection );
166 
167  void AddToMiddleContourns( const SHAPE_POLY_SET &aPolySet,
168  float zBot,
169  float zTop,
170  double aBiuTo3Du,
171  bool aInvertFaceDirection );
172 
173  void AddToMiddleContourns( const std::vector< SFVEC2F > &aContournPoints,
174  float zBot,
175  float zTop,
176  bool aInvertFaceDirection );
177 
179 
185 };
186 
187 
193 {
194 public:
204  CLAYERS_OGL_DISP_LISTS( const CLAYER_TRIANGLES &aLayerTriangles,
205  GLuint aTextureIndexForSegEnds,
206  float aZBot,
207  float aZTop );
208 
214 
219  void DrawTopAndMiddle() const;
220 
225  void DrawBotAndMiddle() const;
226 
230  void DrawTop() const;
231 
235  void DrawBot() const;
236 
241  void DrawMiddle() const;
242 
246  void DrawAll( bool aDrawMiddle = true ) const;
247 
254  void DrawAllCameraCulled( float zCameraPos, bool aDrawMiddle = true ) const;
255 
256  void DrawAllCameraCulledSubtractLayer( const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractA,
257  const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractB,
258  bool aDrawMiddle = true ) const;
259 
260  void ApplyScalePosition( float aZposition, float aZscale );
261 
262  void ClearScalePosition() { m_haveTransformation = false; }
263 
264  void SetItIsTransparent( bool aSetTransparent );
265 
266  float GetZBot() const { return m_zBot; }
267  float GetZTop() const { return m_zTop; }
268 
269 private:
270  GLuint generate_top_or_bot_seg_ends( const CLAYER_TRIANGLE_CONTAINER * aTriangleContainer,
271  bool aIsNormalUp,
272  GLuint aTextureId ) const;
273 
274  GLuint generate_top_or_bot_triangles( const CLAYER_TRIANGLE_CONTAINER * aTriangleContainer,
275  bool aIsNormalUp ) const;
276 
277  GLuint generate_middle_triangles( const CLAYER_TRIANGLE_CONTAINER * aTriangleContainer ) const;
278 
279  void beginTransformation() const;
280  void endTransformation() const;
281 
282  void setBlendfunction() const;
283 
284 private:
285  float m_zBot;
286  float m_zTop;
292 
296 
298 };
299 
300 #endif // CLAYER_TRIANGLES_H_
The CLAYER_TRIANGLES class stores arrays of triangles to be used to create display lists...
const float * GetVertexPointer() const
GetVertexPointer - Get the array of vertexes.
CLAYER_TRIANGLE_CONTAINER(unsigned int aNrReservedTriangles, bool aReserveNormals)
CLAYER_TRIANGLE_CONTAINER.
std::mutex m_middle_layer_lock
The CLAYER_TRIANGLE_CONTAINER class stores an manage vector of triangles.
Class SHAPE_POLY_SET.
CLAYER_TRIANGLE_CONTAINER * m_layer_top_triangles
CLAYER_TRIANGLE_CONTAINER * m_layer_middle_contourns_quads
SFVEC3F_VECTOR m_vertexs
vertex array
const float * GetNormalsPointer() const
GetNormalsPointer - Get the array of normals.
void AddNormal(const SFVEC3F &aN1, const SFVEC3F &aN2, const SFVEC3F &aN3)
AddNormal.
void AddTriangle(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3)
AddTriangle.
unsigned int GetNormalsSize() const
GetNormalsSize.
The CLAYERS_OGL_DISP_LISTS class stores the openGL display lists to related with a layer...
void Reserve_More(unsigned int aNrReservedTriangles, bool aReserveNormals)
Reserve_More - reserve more triangles.
CLAYER_TRIANGLE_CONTAINER * m_layer_bot_segment_ends
unsigned int GetVertexSize() const
GetVertexSize.
std::vector< SFVEC3F > SFVEC3F_VECTOR
CLAYER_TRIANGLE_CONTAINER * m_layer_bot_triangles
Class SHAPE_LINE_CHAIN.
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
CLAYER_TRIANGLE_CONTAINER * m_layer_top_segment_ends
SFVEC3F_VECTOR m_normals
normals array
void AddQuad(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3, const SFVEC3F &aV4)
AddQuad.