KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef TRIANGLE_DISPLAY_LIST_H
22#define TRIANGLE_DISPLAY_LIST_H
23
24#include <kicad_gl/kiglad.h> // Must be included first
25
30#include <vector>
31#include <mutex>
32
33
34
39{
40public:
41
46 TRIANGLE_LIST( unsigned int aNrReservedTriangles, bool aReserveNormals );
47
51 void Reserve_More( unsigned int aNrReservedTriangles, bool aReserveNormals );
52
53 void AddTriangle( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3 );
54
55 void AddQuad( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3, const SFVEC3F& aV4 );
56
57 void AddNormal( const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3 );
58
59 void AddNormal( const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3,
60 const SFVEC3F& aN4 );
61
67 const float* GetVertexPointer() const { return (const float *)&m_vertexs[0].x; }
68
74 const float* GetNormalsPointer() const { return (const float*) &m_normals[0].x; }
75
76 unsigned int GetVertexSize() const { return (unsigned int) m_vertexs.size(); }
77
78 unsigned int GetNormalsSize() const { return (unsigned int) m_normals.size(); }
79
80private:
81 std::vector<SFVEC3F> m_vertexs;
82 std::vector<SFVEC3F> m_normals;
83};
84
85
90{
91public:
97 explicit TRIANGLE_DISPLAY_LIST( unsigned int aNrReservedTriangles );
98
100
107
108
109 void AddToMiddleContours( const SHAPE_LINE_CHAIN& outlinePath, float zBot, float zTop,
110 double aBiuTo3Du, bool aInvertFaceDirection,
111 const BVH_CONTAINER_2D* aThroughHoles = nullptr );
112
113 void AddToMiddleContours( const SHAPE_POLY_SET& aPolySet, float zBot, float zTop,
114 double aBiuTo3Du, bool aInvertFaceDirection,
115 const BVH_CONTAINER_2D* aThroughHoles = nullptr );
116
117 void AddToMiddleContours( const std::vector< SFVEC2F >& aContourPoints, float zBot,
118 float zTop, bool aInvertFaceDirection,
119 const BVH_CONTAINER_2D* aThroughHoles = nullptr );
120
122
128};
129
130
135{
136public:
146 OPENGL_RENDER_LIST( const TRIANGLE_DISPLAY_LIST& aLayerTriangles,
147 GLuint aTextureIndexForSegEnds, float aZBot, float aZTop );
148
153
157 void DrawTopAndMiddle() const;
158
162 void DrawBotAndMiddle() const;
163
167 void DrawTop() const;
168
172 void DrawBot() const;
173
177 void DrawMiddle() const;
178
182 void DrawAll( bool aDrawMiddle = true ) const;
183
192 void DrawCulled( bool aDrawMiddle, const std::shared_ptr<OPENGL_RENDER_LIST> aSubtractList = nullptr,
193 const std::shared_ptr<OPENGL_RENDER_LIST> bSubtractList = nullptr,
194 const std::shared_ptr<OPENGL_RENDER_LIST> cSubtractList = nullptr,
195 const std::shared_ptr<OPENGL_RENDER_LIST> dSubtractList = nullptr ) const;
196
197 void ApplyScalePosition( float aZposition, float aZscale );
198 void ApplyScalePosition( std::shared_ptr<OPENGL_RENDER_LIST> aOtherList );
199
201
202 void SetItIsTransparent( bool aSetTransparent );
203
204 float GetZBot() const { return m_zBot; }
205 float GetZTop() const { return m_zTop; }
206
207private:
208 GLuint generate_top_or_bot_seg_ends( const TRIANGLE_LIST* aTriangleContainer,
209 bool aIsNormalUp, GLuint aTextureId ) const;
210
211 GLuint generate_top_or_bot_triangles( const TRIANGLE_LIST* aTriangleContainer,
212 bool aIsNormalUp ) const;
213
214 GLuint generate_middle_triangles( const TRIANGLE_LIST* aTriangleContainer ) const;
215
216 void beginTransformation() const;
217 void endTransformation() const;
218
219 void setBlendfunction() const;
220
221private:
222 float m_zBot;
223 float m_zTop;
229
233
235};
236
237
242{
243public:
244 OPENGL_RENDER_LIST_DEFERRED( std::shared_ptr<TRIANGLE_DISPLAY_LIST> aLayerTriangles, GLuint aTextureIndexForSegEnds,
245 float aZBot, float aZTop, bool aTransparent = false ) :
246 m_layerTriangles( std::move( aLayerTriangles ) ),
247 m_textureIndexForSegEnds( aTextureIndexForSegEnds ),
248 m_zBot( aZBot ),
249 m_zTop( aZTop ),
250 m_defaultTransparent( aTransparent )
251 {
252 }
253
255
257 {
258 std::lock_guard<std::recursive_mutex> lock( m_mutex );
259
261 {
262 throw std::runtime_error( "Both OpenGL render list and layer triangles are null" );
263 }
264
265 if( !m_openglRenderList )
266 {
268 std::make_shared<OPENGL_RENDER_LIST>( *m_layerTriangles, m_textureIndexForSegEnds, m_zBot, m_zTop );
269
270 m_openglRenderList->SetItIsTransparent( m_defaultTransparent );
271 }
272 }
273
274 void Reset()
275 {
276 std::lock_guard<std::recursive_mutex> lock( m_mutex );
277
278 m_openglRenderList.reset();
279 m_layerTriangles.reset();
280 }
281
282 std::shared_ptr<OPENGL_RENDER_LIST> MakeOrGet()
283 {
284 std::lock_guard<std::recursive_mutex> lock( m_mutex );
285
286 MakeShared();
287 m_layerTriangles.reset();
288
289 return m_openglRenderList;
290 }
291
292private:
293 std::shared_ptr<OPENGL_RENDER_LIST> m_openglRenderList;
294 std::recursive_mutex m_mutex;
295
296 std::shared_ptr<TRIANGLE_DISPLAY_LIST> m_layerTriangles;
298 float m_zBot{ 0 };
299 float m_zTop{ 0 };
300 bool m_defaultTransparent{ false };
301};
302
303
304#endif // TRIANGLE_DISPLAY_LIST_H
std::shared_ptr< OPENGL_RENDER_LIST > m_openglRenderList
OPENGL_RENDER_LIST_DEFERRED(std::shared_ptr< TRIANGLE_DISPLAY_LIST > aLayerTriangles, GLuint aTextureIndexForSegEnds, float aZBot, float aZTop, bool aTransparent=false)
std::shared_ptr< OPENGL_RENDER_LIST > MakeOrGet()
std::shared_ptr< TRIANGLE_DISPLAY_LIST > m_layerTriangles
std::recursive_mutex m_mutex
GLuint generate_middle_triangles(const TRIANGLE_LIST *aTriangleContainer) const
float GetZBot() const
float GetZTop() const
void beginTransformation() const
void DrawMiddle() const
Call the display lists for the middle elements.
GLuint generate_top_or_bot_seg_ends(const TRIANGLE_LIST *aTriangleContainer, bool aIsNormalUp, GLuint aTextureId) const
void DrawTop() const
Call the display lists for the top elements.
GLuint m_layer_middle_contours_quads
void DrawCulled(bool aDrawMiddle, const std::shared_ptr< OPENGL_RENDER_LIST > aSubtractList=nullptr, const std::shared_ptr< OPENGL_RENDER_LIST > bSubtractList=nullptr, const std::shared_ptr< OPENGL_RENDER_LIST > cSubtractList=nullptr, const std::shared_ptr< OPENGL_RENDER_LIST > dSubtractList=nullptr) const
Draw all layers if they are visible by the camera if camera position is above the layer.
void DrawBot() const
Call the display lists for the bottom elements.
void ApplyScalePosition(float aZposition, float aZscale)
GLuint generate_top_or_bot_triangles(const TRIANGLE_LIST *aTriangleContainer, bool aIsNormalUp) const
void setBlendfunction() const
void DrawBotAndMiddle() const
Call the display lists for the bottom elements and middle contours.
void SetItIsTransparent(bool aSetTransparent)
void endTransformation() const
~OPENGL_RENDER_LIST()
Destroy this class while free the display lists from GPU memory.
OPENGL_RENDER_LIST(const TRIANGLE_DISPLAY_LIST &aLayerTriangles, GLuint aTextureIndexForSegEnds, float aZBot, float aZTop)
Create the display lists for a layer.
void DrawTopAndMiddle() const
Call the display lists for the top elements and middle contours.
void DrawAll(bool aDrawMiddle=true) const
Call to draw all the display lists.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
Store arrays of triangles to be used to create display lists.
TRIANGLE_LIST * m_layer_bot_segment_ends
void AddToMiddleContours(const SHAPE_LINE_CHAIN &outlinePath, float zBot, float zTop, double aBiuTo3Du, bool aInvertFaceDirection, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
TRIANGLE_LIST * m_layer_middle_contours_quads
TRIANGLE_LIST * m_layer_top_segment_ends
TRIANGLE_LIST * m_layer_bot_triangles
TRIANGLE_DISPLAY_LIST(unsigned int aNrReservedTriangles)
Initialize arrays with reserved triangles.
TRIANGLE_LIST * m_layer_top_triangles
bool IsLayersSizeValid()
Check if the vertex arrays of the layers are as expected.
Container to manage a vector of triangles.
void AddTriangle(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3)
const float * GetVertexPointer() const
Get the array of vertices.
std::vector< SFVEC3F > m_vertexs
vertex array
unsigned int GetNormalsSize() const
std::vector< SFVEC3F > m_normals
normals array
void AddQuad(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3, const SFVEC3F &aV4)
void AddNormal(const SFVEC3F &aN1, const SFVEC3F &aN2, const SFVEC3F &aN3)
unsigned int GetVertexSize() const
const float * GetNormalsPointer() const
Get the array of normals.
TRIANGLE_LIST(unsigned int aNrReservedTriangles, bool aReserveNormals)
void Reserve_More(unsigned int aNrReservedTriangles, bool aReserveNormals)
Reserve more triangles.
STL namespace.
glm::vec3 SFVEC3F
Definition xv3d_types.h:40