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 
39 
40 typedef std::vector< SFVEC3F > SFVEC3F_VECTOR;
41 
42 
47 {
48 
49 public:
50 
57  CLAYER_TRIANGLE_CONTAINER( unsigned int aNrReservedTriangles, bool aReserveNormals );
58 
63  void Reserve_More( unsigned int aNrReservedTriangles, bool aReserveNormals );
64 
71  void AddTriangle( const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3 );
72 
80  void AddQuad( const SFVEC3F &aV1,
81  const SFVEC3F &aV2,
82  const SFVEC3F &aV3,
83  const SFVEC3F &aV4 );
84 
91  void AddNormal( const SFVEC3F &aN1, const SFVEC3F &aN2, const SFVEC3F &aN3 );
92 
99  void AddNormal( const SFVEC3F &aN1,
100  const SFVEC3F &aN2,
101  const SFVEC3F &aN3,
102  const SFVEC3F &aN4 );
103 
108  const float *GetVertexPointer() const { return (const float *)&m_vertexs[0].x; }
109 
114  const float *GetNormalsPointer() const { return (const float *)&m_normals[0].x; }
115 
120  unsigned int GetVertexSize() const { return (unsigned int)m_vertexs.size(); }
121 
126  unsigned int GetNormalsSize() const { return (unsigned int)m_normals.size(); }
127 
128 private:
131 };
132 
133 
139 {
140 public:
145  explicit CLAYER_TRIANGLES( unsigned int aNrReservedTriangles );
146 
151 
157  bool IsLayersSizeValid();
158 
159 
160  void AddToMiddleContourns( const SHAPE_LINE_CHAIN &outlinePath,
161  float zBot,
162  float zTop,
163  double aBiuTo3Du,
164  bool aInvertFaceDirection );
165 
166  void AddToMiddleContourns( const SHAPE_POLY_SET &aPolySet,
167  float zBot,
168  float zTop,
169  double aBiuTo3Du,
170  bool aInvertFaceDirection );
171 
172  void AddToMiddleContourns( const std::vector< SFVEC2F > &aContournPoints,
173  float zBot,
174  float zTop,
175  bool aInvertFaceDirection );
176 
182 };
183 
184 
190 {
191 public:
201  CLAYERS_OGL_DISP_LISTS( const CLAYER_TRIANGLES &aLayerTriangles,
202  GLuint aTextureIndexForSegEnds,
203  float aZBot,
204  float aZTop );
205 
211 
216  void DrawTopAndMiddle() const;
217 
222  void DrawBotAndMiddle() const;
223 
227  void DrawTop() const;
228 
232  void DrawBot() const;
233 
238  void DrawMiddle() const;
239 
243  void DrawAll( bool aDrawMiddle = true ) const;
244 
251  void DrawAllCameraCulled( float zCameraPos, bool aDrawMiddle = true ) const;
252 
253  void DrawAllCameraCulledSubtractLayer( const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractA,
254  const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractB,
255  bool aDrawMiddle = true ) const;
256 
257  void ApplyScalePosition( float aZposition, float aZscale );
258 
260 
261  void SetItIsTransparent( bool aSetTransparent );
262 
263  float GetZBot() const { return m_zBot; }
264  float GetZTop() const { return m_zTop; }
265 
266 private:
267  GLuint generate_top_or_bot_seg_ends( const CLAYER_TRIANGLE_CONTAINER * aTriangleContainer,
268  bool aIsNormalUp,
269  GLuint aTextureId ) const;
270 
271  GLuint generate_top_or_bot_triangles( const CLAYER_TRIANGLE_CONTAINER * aTriangleContainer,
272  bool aIsNormalUp ) const;
273 
274  GLuint generate_middle_triangles( const CLAYER_TRIANGLE_CONTAINER * aTriangleContainer ) const;
275 
276  void beginTransformation() const;
277  void endTransformation() const;
278 
279  void setBlendfunction() const;
280 
281 private:
282  float m_zBot;
283  float m_zTop;
289 
293 
295 };
296 
297 #endif // CLAYER_TRIANGLES_H_
The CLAYER_TRIANGLES class stores arrays of triangles to be used to create display lists...
GLuint generate_middle_triangles(const CLAYER_TRIANGLE_CONTAINER *aTriangleContainer) const
GLuint generate_top_or_bot_seg_ends(const CLAYER_TRIANGLE_CONTAINER *aTriangleContainer, bool aIsNormalUp, GLuint aTextureId) const
void DrawTopAndMiddle() const
DrawTopAndMiddle - This function calls the display lists for the top elements and middle contourns...
const float * GetVertexPointer() const
GetVertexPointer - Get the array of vertexes.
void DrawMiddle() const
DrawMiddle - This function calls the display lists for the middle elements.
CLAYER_TRIANGLE_CONTAINER(unsigned int aNrReservedTriangles, bool aReserveNormals)
CLAYER_TRIANGLE_CONTAINER.
void ApplyScalePosition(float aZposition, float aZscale)
~CLAYER_TRIANGLES()
~CLAYER_TRIANGLES - Free containers
CLAYER_TRIANGLES(unsigned int aNrReservedTriangles)
CLAYER_TRIANGLES - initialize arrays with reserved triangles.
The CLAYER_TRIANGLE_CONTAINER class stores an manage vector of triangles.
Class SHAPE_POLY_SET.
CLAYERS_OGL_DISP_LISTS(const CLAYER_TRIANGLES &aLayerTriangles, GLuint aTextureIndexForSegEnds, float aZBot, float aZTop)
CLAYERS_OGL_DISP_LISTS - Creates the display lists for a layer.
CLAYER_TRIANGLE_CONTAINER * m_layer_top_triangles
~CLAYERS_OGL_DISP_LISTS()
~CLAYERS_OGL_DISP_LISTS - Destroy this class while free the display lists from GPU mem ...
void DrawTop() const
DrawTop - This function calls the display lists for the top elements.
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.
void AddToMiddleContourns(const SHAPE_LINE_CHAIN &outlinePath, float zBot, float zTop, double aBiuTo3Du, bool aInvertFaceDirection)
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.
void DrawBot() const
DrawBot - This function calls the display lists for the botton elements.
void DrawAllCameraCulledSubtractLayer(const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractA, const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractB, bool aDrawMiddle=true) const
bool IsLayersSizeValid()
IsLayersSizeValid - check if the vertex arrays of the layers are as expected.
CLAYER_TRIANGLE_CONTAINER * m_layer_bot_segment_ends
unsigned int GetVertexSize() const
GetVertexSize.
void DrawBotAndMiddle() const
DrawBotAndMiddle - This function calls the display lists for the botton elements and middle contourns...
std::vector< SFVEC3F > SFVEC3F_VECTOR
GLuint generate_top_or_bot_triangles(const CLAYER_TRIANGLE_CONTAINER *aTriangleContainer, bool aIsNormalUp) const
void DrawAllCameraCulled(float zCameraPos, bool aDrawMiddle=true) const
DrawAllCameraCulled - Draw all layers if they are visible by the camera.
CLAYER_TRIANGLE_CONTAINER * m_layer_bot_triangles
Class SHAPE_LINE_CHAIN.
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
void SetItIsTransparent(bool aSetTransparent)
void beginTransformation() const
CLAYER_TRIANGLE_CONTAINER * m_layer_top_segment_ends
void DrawAll(bool aDrawMiddle=true) const
DrawAll - This function calls all the display lists.
SFVEC3F_VECTOR m_normals
normals array
void AddQuad(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3, const SFVEC3F &aV4)
AddQuad.