KiCad PCB EDA Suite
Loading...
Searching...
No Matches
layer_triangles.cpp
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, 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#include "layer_triangles.h"
26#include "../raytracing/ray.h"
27#include <wx/debug.h> // For the wxASSERT
28#include <mutex>
29
30
31TRIANGLE_LIST::TRIANGLE_LIST( unsigned int aNrReservedTriangles, bool aReserveNormals )
32{
33 m_vertexs.clear();
34 m_normals.clear();
35
36 if( aNrReservedTriangles > 0 )
37 m_vertexs.reserve( aNrReservedTriangles * 3 );
38
39 if( aReserveNormals )
40 m_normals.reserve( aNrReservedTriangles * 3 );
41}
42
43
44void TRIANGLE_LIST::Reserve_More( unsigned int aNrReservedTriangles, bool aReserveNormals )
45{
46 m_vertexs.reserve( m_vertexs.size() + aNrReservedTriangles * 3 );
47
48 if( aReserveNormals )
49 m_normals.reserve( m_normals.size() + aNrReservedTriangles * 3 );
50}
51
52
53void TRIANGLE_LIST::AddQuad( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3,
54 const SFVEC3F& aV4 )
55{
56 m_vertexs.push_back( aV1 );
57 m_vertexs.push_back( aV2 );
58 m_vertexs.push_back( aV3 );
59
60 m_vertexs.push_back( aV3 );
61 m_vertexs.push_back( aV4 );
62 m_vertexs.push_back( aV1 );
63}
64
65
66void TRIANGLE_LIST::AddTriangle( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3 )
67{
68 m_vertexs.push_back( aV1 );
69 m_vertexs.push_back( aV2 );
70 m_vertexs.push_back( aV3 );
71}
72
73
74void TRIANGLE_LIST::AddNormal( const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3 )
75{
76 m_normals.push_back( aN1 );
77 m_normals.push_back( aN2 );
78 m_normals.push_back( aN3 );
79}
80
81void TRIANGLE_LIST::AddNormal( const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3,
82 const SFVEC3F& aN4 )
83{
84 m_normals.push_back( aN1 );
85 m_normals.push_back( aN2 );
86 m_normals.push_back( aN3 );
87
88 m_normals.push_back( aN3 );
89 m_normals.push_back( aN4 );
90 m_normals.push_back( aN1 );
91}
92
93
94TRIANGLE_DISPLAY_LIST::TRIANGLE_DISPLAY_LIST( unsigned int aNrReservedTriangles )
95{
96 m_layer_top_segment_ends = new TRIANGLE_LIST( aNrReservedTriangles, false );
97 m_layer_top_triangles = new TRIANGLE_LIST( aNrReservedTriangles, false );
98 m_layer_middle_contours_quads = new TRIANGLE_LIST( aNrReservedTriangles, true );
99 m_layer_bot_triangles = new TRIANGLE_LIST( aNrReservedTriangles, false );
100 m_layer_bot_segment_ends = new TRIANGLE_LIST( aNrReservedTriangles, false );
101}
102
103
121
122
123void TRIANGLE_DISPLAY_LIST::AddToMiddleContours( const std::vector<SFVEC2F>& aContourPoints,
124 float zBot, float zTop, bool aInvertFaceDirection,
125 const BVH_CONTAINER_2D* aThroughHoles )
126{
127 if( aContourPoints.size() >= 4 )
128 {
129 // Calculate normals of each segment of the contour
130 std::vector< SFVEC2F > contourNormals;
131
132 contourNormals.clear();
133 contourNormals.resize( aContourPoints.size() - 1 );
134
135 if( aInvertFaceDirection )
136 {
137 for( unsigned int i = 0; i < ( aContourPoints.size() - 1 ); ++i )
138 {
139 const SFVEC2F& v0 = aContourPoints[i + 0];
140 const SFVEC2F& v1 = aContourPoints[i + 1];
141 const SFVEC2F n = glm::normalize( v1 - v0 );
142
143 contourNormals[i] = SFVEC2F( n.y, -n.x );
144 }
145 }
146 else
147 {
148 for( unsigned int i = 0; i < ( aContourPoints.size() - 1 ); ++i )
149 {
150 const SFVEC2F& v0 = aContourPoints[i + 0];
151 const SFVEC2F& v1 = aContourPoints[i + 1];
152 const SFVEC2F n = glm::normalize( v1 - v0 );
153
154 contourNormals[i] = SFVEC2F( -n.y, n.x );
155 }
156 }
157
158
159 if( aInvertFaceDirection )
160 std::swap( zBot, zTop );
161
162 const unsigned int nContoursToProcess = ( aContourPoints.size() - 1 );
163
164 for( unsigned int i = 0; i < nContoursToProcess; ++i )
165 {
166 SFVEC2F lastNormal;
167
168 if( i > 0 )
169 lastNormal = contourNormals[i - 1];
170 else
171 lastNormal = contourNormals[nContoursToProcess - 1];
172
173 SFVEC2F n0 = contourNormals[i];
174
175 // Only interpolate the normal if the angle is closer
176 if( glm::dot( n0, lastNormal ) > 0.5f )
177 n0 = glm::normalize( n0 + lastNormal );
178
179 SFVEC2F nextNormal;
180
181 if( i < ( nContoursToProcess - 1) )
182 nextNormal = contourNormals[i + 1];
183 else
184 nextNormal = contourNormals[0];
185
186 SFVEC2F n1 = contourNormals[i];
187
188 if( glm::dot( n1, nextNormal ) > 0.5f )
189 n1 = glm::normalize( n1 + nextNormal );
190
191 const SFVEC3F n3d0 = SFVEC3F( n0.x, n0.y, 0.0f );
192 const SFVEC3F n3d1 = SFVEC3F( n1.x, n1.y, 0.0f );
193
194 const SFVEC2F& v0 = aContourPoints[i + 0];
195 const SFVEC2F& v1 = aContourPoints[i + 1];
196
197 if( aThroughHoles && aThroughHoles->IntersectAny( RAYSEG2D( v0, v1 ) ) )
198 {
199 continue;
200 }
201 else
202 {
203 std::lock_guard<std::mutex> lock( m_middle_layer_lock );
204 m_layer_middle_contours_quads->AddQuad( SFVEC3F( v0.x, v0.y, zTop ),
205 SFVEC3F( v1.x, v1.y, zTop ),
206 SFVEC3F( v1.x, v1.y, zBot ),
207 SFVEC3F( v0.x, v0.y, zBot ) );
208
209 m_layer_middle_contours_quads->AddNormal( n3d0, n3d1, n3d1, n3d0 );
210 }
211 }
212 }
213}
214
215
216void TRIANGLE_DISPLAY_LIST::AddToMiddleContours( const SHAPE_LINE_CHAIN& outlinePath, float zBot, float zTop,
217 double aBiuTo3Du, bool aInvertFaceDirection,
218 const BVH_CONTAINER_2D* aThroughHoles )
219{
220 std::vector<SFVEC2F> contourPoints;
221
222 contourPoints.clear();
223 contourPoints.reserve( outlinePath.PointCount() + 2 );
224
225 const VECTOR2I& firstV = outlinePath.CPoint( 0 );
226
227 SFVEC2F lastV = SFVEC2F( firstV.x * aBiuTo3Du, -firstV.y * aBiuTo3Du );
228
229 contourPoints.push_back( lastV );
230
231 for( unsigned int i = 1; i < (unsigned int)outlinePath.PointCount(); ++i )
232 {
233 const VECTOR2I& v = outlinePath.CPoint( i );
234
235 const SFVEC2F vf = SFVEC2F( v.x * aBiuTo3Du, -v.y * aBiuTo3Du );
236
237 if( vf != lastV ) // Do not add repeated points
238 {
239 lastV = vf;
240 contourPoints.push_back( vf );
241 }
242 }
243
244 // Add first position of the list to close the path.
245 if( lastV != contourPoints[0] )
246 contourPoints.push_back( contourPoints[0] );
247
248 AddToMiddleContours( contourPoints, zBot, zTop, aInvertFaceDirection, aThroughHoles );
249}
250
251
252void TRIANGLE_DISPLAY_LIST::AddToMiddleContours( const SHAPE_POLY_SET& aPolySet, float zBot, float zTop,
253 double aBiuTo3Du, bool aInvertFaceDirection,
254 const BVH_CONTAINER_2D* aThroughHoles )
255{
256 if( aPolySet.OutlineCount() == 0 )
257 return;
258
259 // Calculate an estimation of points to reserve
260 unsigned int nrContourPointsToReserve = 0;
261
262 for( int i = 0; i < aPolySet.OutlineCount(); ++i )
263 {
264 const SHAPE_LINE_CHAIN& pathOutline = aPolySet.COutline( i );
265
266 nrContourPointsToReserve += pathOutline.PointCount();
267
268 for( int h = 0; h < aPolySet.HoleCount( i ); ++h )
269 {
270 const SHAPE_LINE_CHAIN& hole = aPolySet.CHole( i, h );
271
272 nrContourPointsToReserve += hole.PointCount();
273 }
274 }
275
276 // Request to reserve more space
277 m_layer_middle_contours_quads->Reserve_More( nrContourPointsToReserve * 2, true );
278
279 for( int i = 0; i < aPolySet.OutlineCount(); i++ )
280 {
281 // Add outline
282 const SHAPE_LINE_CHAIN& pathOutline = aPolySet.COutline( i );
283
284 AddToMiddleContours( pathOutline, zBot, zTop, aBiuTo3Du, aInvertFaceDirection, aThroughHoles );
285
286 // Add holes for this outline
287 for( int h = 0; h < aPolySet.HoleCount( i ); ++h )
288 {
289 const SHAPE_LINE_CHAIN& hole = aPolySet.CHole( i, h );
290 AddToMiddleContours( hole, zBot, zTop, aBiuTo3Du, aInvertFaceDirection, aThroughHoles );
291 }
292 }
293}
294
295
297 GLuint aTextureIndexForSegEnds, float aZBot, float aZTop )
298{
299 m_zBot = aZBot;
300 m_zTop = aZTop;
301
307
308 if( aTextureIndexForSegEnds )
309 {
310 wxASSERT( glIsTexture( aTextureIndexForSegEnds ) );
311
312 if( glIsTexture( aTextureIndexForSegEnds ) )
313 {
315 true, aTextureIndexForSegEnds );
316
318 false, aTextureIndexForSegEnds );
319 }
320 }
321
323
325
326
327 if( aLayerTriangles.m_layer_middle_contours_quads->GetVertexSize() > 0 )
329
330 m_draw_it_transparent = false;
331 m_haveTransformation = false;
334}
335
336
338{
339 if( glIsList( m_layer_top_segment_ends ) )
340 glDeleteLists( m_layer_top_segment_ends, 1 );
341
342 if( glIsList( m_layer_top_triangles ) )
343 glDeleteLists( m_layer_top_triangles, 1 );
344
345 if( glIsList( m_layer_middle_contours_quads ) )
346 glDeleteLists( m_layer_middle_contours_quads, 1 );
347
348 if( glIsList( m_layer_bot_triangles ) )
349 glDeleteLists( m_layer_bot_triangles, 1 );
350
351 if( glIsList( m_layer_bot_segment_ends ) )
352 glDeleteLists( m_layer_bot_segment_ends, 1 );
353
359}
360
361
363{
365
366 if( glIsList( m_layer_middle_contours_quads ) )
367 glCallList( m_layer_middle_contours_quads );
368
369 if( glIsList( m_layer_top_triangles ) )
370 glCallList( m_layer_top_triangles );
371
372 if( glIsList( m_layer_top_segment_ends ) )
373 glCallList( m_layer_top_segment_ends );
374
376}
377
378
380{
382
383 if( glIsList( m_layer_middle_contours_quads ) )
384 glCallList( m_layer_middle_contours_quads );
385
386 if( glIsList( m_layer_bot_triangles ) )
387 glCallList( m_layer_bot_triangles );
388
389 if( glIsList( m_layer_bot_segment_ends ) )
390 glCallList( m_layer_bot_segment_ends );
391
393}
394
395
397{
399
400 if( glIsList( m_layer_top_triangles ) )
401 glCallList( m_layer_top_triangles );
402
403 if( glIsList( m_layer_top_segment_ends ) )
404 glCallList( m_layer_top_segment_ends );
405
407}
408
409
411{
413
414 if( glIsList( m_layer_bot_triangles ) )
415 glCallList( m_layer_bot_triangles );
416
417 if( glIsList( m_layer_bot_segment_ends ) )
418 glCallList( m_layer_bot_segment_ends );
419
421}
422
423
425{
427
428 if( glIsList( m_layer_middle_contours_quads ) )
429 glCallList( m_layer_middle_contours_quads );
430
432}
433
434
435void OPENGL_RENDER_LIST::DrawAll( bool aDrawMiddle ) const
436{
438
439 if( aDrawMiddle )
440 if( glIsList( m_layer_middle_contours_quads ) )
441 glCallList( m_layer_middle_contours_quads );
442
443 if( glIsList( m_layer_top_triangles ) )
444 glCallList( m_layer_top_triangles );
445
446 if( glIsList( m_layer_bot_triangles ) )
447 glCallList( m_layer_bot_triangles );
448
449 if( glIsList( m_layer_top_segment_ends ) )
450 glCallList( m_layer_top_segment_ends );
451
452 if( glIsList( m_layer_bot_segment_ends ) )
453 glCallList( m_layer_bot_segment_ends );
454
456}
457
458
459void OPENGL_RENDER_LIST::DrawCulled( bool aDrawMiddle,
460 const OPENGL_RENDER_LIST* aSubtractList,
461 const OPENGL_RENDER_LIST* bSubtractList,
462 const OPENGL_RENDER_LIST* cSubtractList,
463 const OPENGL_RENDER_LIST* dSubtractList ) const
464{
465 glClearStencil( 0x00 );
466 glClear( GL_STENCIL_BUFFER_BIT );
467
468 glEnable( GL_CULL_FACE );
469 glCullFace( GL_BACK );
470
471 glDisable( GL_DEPTH_TEST );
472 glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
473 glDepthMask( GL_FALSE );
474 glEnable( GL_STENCIL_TEST );
475 glStencilFunc( GL_ALWAYS, 1, 0 );
476 glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
477
478 if( aSubtractList )
479 aSubtractList->DrawBot();
480
481 if( bSubtractList )
482 bSubtractList->DrawBot();
483
484 if( cSubtractList )
485 cSubtractList->DrawBot();
486
487 if( dSubtractList )
488 dSubtractList->DrawBot();
489
490 glEnable( GL_DEPTH_TEST );
491 glDepthMask( GL_TRUE );
492
493 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
494 glStencilFunc( GL_EQUAL, 0, 1 );
495 glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
496 DrawBot();
497
498 glDisable( GL_DEPTH_TEST );
499 glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
500 glDepthMask( GL_FALSE );
501 glEnable( GL_STENCIL_TEST );
502 glStencilFunc( GL_ALWAYS, 2, 0 );
503 glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
504
505 if( aSubtractList )
506 aSubtractList->DrawTop();
507
508 if( bSubtractList )
509 bSubtractList->DrawTop();
510
511 if( cSubtractList )
512 cSubtractList->DrawTop();
513
514 if( dSubtractList )
515 dSubtractList->DrawTop();
516
517 glEnable( GL_DEPTH_TEST );
518 glDepthMask( GL_TRUE );
519 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
520 glStencilFunc( GL_NOTEQUAL, 2, 0x03 );
521 glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
522 DrawTop();
523
524 if( aDrawMiddle )
525 DrawMiddle();
526
527 glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
528
529 glCullFace( GL_FRONT );
530 glStencilFunc( GL_GEQUAL, 3, 0x03 );
531 glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
532 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
533
534 if( aDrawMiddle )
535 {
536 if( aSubtractList )
537 aSubtractList->DrawMiddle();
538 }
539
540 glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
541
542 glCullFace( GL_BACK );
543 glDisable( GL_STENCIL_TEST );
544}
545
546
547void OPENGL_RENDER_LIST::ApplyScalePosition( float aZposition, float aZscale )
548{
549 wxCHECK2( aZscale > FLT_EPSILON, aZscale = FLT_EPSILON + 1 );
550
551 m_zPositionTransformation = aZposition;
552 m_zScaleTransformation = aZscale;
554}
555
556
558{
559 ApplyScalePosition( aOtherList->GetZBot(), aOtherList->GetZTop() - aOtherList->GetZBot() );
560}
561
562
563void OPENGL_RENDER_LIST::SetItIsTransparent( bool aSetTransparent )
564{
565 m_draw_it_transparent = aSetTransparent;
566}
567
568
570 const TRIANGLE_LIST* aTriangleContainer, bool aIsNormalUp, GLuint aTextureId ) const
571{
572 wxCHECK( aTriangleContainer != nullptr, 0 );
573
574 wxASSERT( ( aTriangleContainer->GetVertexSize() % 3 ) == 0 );
575
576 // Top and Bot don't have normals array stored in container
577 wxASSERT( aTriangleContainer->GetNormalsSize() == 0 );
578
579 if( ( aTriangleContainer->GetVertexSize() > 0 )
580 && ( ( aTriangleContainer->GetVertexSize() % 3 ) == 0 ) )
581 {
582 GLuint listIdx = glGenLists( 1 );
583
584 if( glIsList( listIdx ) )
585 {
586 // Prepare an array of UV text coordinates
587 SFVEC2F* uvArray = new SFVEC2F[aTriangleContainer->GetVertexSize()];
588
589 for( unsigned int i = 0; i < aTriangleContainer->GetVertexSize(); i += 3 )
590 {
591 uvArray[i + 0] = SFVEC2F( 1.0f, 0.0f );
592 uvArray[i + 1] = SFVEC2F( 0.0f, 1.0f );
593 uvArray[i + 2] = SFVEC2F( 0.0f, 0.0f );
594 }
595
596 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
597 glDisableClientState( GL_COLOR_ARRAY );
598 glDisableClientState( GL_NORMAL_ARRAY );
599 glEnableClientState( GL_VERTEX_ARRAY );
600 glVertexPointer( 3, GL_FLOAT, 0, aTriangleContainer->GetVertexPointer() );
601 glTexCoordPointer( 2, GL_FLOAT, 0, uvArray );
602
603 glNewList( listIdx, GL_COMPILE );
604
605 glDisable( GL_COLOR_MATERIAL );
606
607 glEnable( GL_TEXTURE_2D );
608 glBindTexture( GL_TEXTURE_2D, aTextureId );
609
610 glAlphaFunc( GL_GREATER, 0.2f );
611 glEnable( GL_ALPHA_TEST );
612
613 glNormal3f( 0.0f, 0.0f, aIsNormalUp?1.0f:-1.0f );
614
615 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->GetVertexSize() );
616
617 glBindTexture( GL_TEXTURE_2D, 0 );
618 glDisable( GL_TEXTURE_2D );
619 glDisable( GL_ALPHA_TEST );
620 glDisable( GL_BLEND );
621
622 glEndList();
623
624 glDisableClientState( GL_VERTEX_ARRAY );
625 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
626
627 delete [] uvArray;
628 return listIdx;
629 }
630 }
631
632 return 0;
633}
634
635
637 bool aIsNormalUp ) const
638{
639 wxCHECK( aTriangleContainer != nullptr, 0 );
640
641 wxASSERT( ( aTriangleContainer->GetVertexSize() % 3 ) == 0 );
642
643 // Top and Bot dint have normals array stored in container
644 wxASSERT( aTriangleContainer->GetNormalsSize() == 0 );
645
646 if( ( aTriangleContainer->GetVertexSize() > 0 )
647 && ( ( aTriangleContainer->GetVertexSize() % 3 ) == 0 ) )
648 {
649 const GLuint listIdx = glGenLists( 1 );
650
651 if( glIsList( listIdx ) )
652 {
653 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
654 glDisableClientState( GL_COLOR_ARRAY );
655 glDisableClientState( GL_NORMAL_ARRAY );
656 glEnableClientState( GL_VERTEX_ARRAY );
657 glVertexPointer( 3, GL_FLOAT, 0, aTriangleContainer->GetVertexPointer() );
658
659 glNewList( listIdx, GL_COMPILE );
660
662
663 glNormal3f( 0.0f, 0.0f, aIsNormalUp?1.0f:-1.0f );
664
665 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->GetVertexSize() );
666
667 glDisable( GL_BLEND );
668 glEndList();
669
670 glDisableClientState( GL_VERTEX_ARRAY );
671
672 return listIdx;
673 }
674 }
675
676 return 0;
677}
678
679
681 const TRIANGLE_LIST* aTriangleContainer ) const
682{
683 wxCHECK( aTriangleContainer != nullptr, 0 );
684
685 // We expect that it is a multiple of 3 vertex
686 wxASSERT( ( aTriangleContainer->GetVertexSize() % 3 ) == 0 );
687
688 // We expect that it is a multiple of 6 vertex (because we expect to add quads)
689 wxASSERT( (aTriangleContainer->GetVertexSize() % 6 ) == 0 );
690
691 // We expect that there are normals with same size as vertex
692 wxASSERT( aTriangleContainer->GetNormalsSize() == aTriangleContainer->GetVertexSize() );
693
694 if( ( aTriangleContainer->GetVertexSize() > 0 )
695 && ( ( aTriangleContainer->GetVertexSize() % 3 ) == 0 )
696 && ( ( aTriangleContainer->GetVertexSize() % 6 ) == 0 )
697 && ( aTriangleContainer->GetNormalsSize() == aTriangleContainer->GetVertexSize() ) )
698 {
699 const GLuint listIdx = glGenLists( 1 );
700
701 if( glIsList( listIdx ) )
702 {
703 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
704 glDisableClientState( GL_COLOR_ARRAY );
705 glEnableClientState( GL_NORMAL_ARRAY );
706 glEnableClientState( GL_VERTEX_ARRAY );
707 glVertexPointer( 3, GL_FLOAT, 0, aTriangleContainer->GetVertexPointer() );
708 glNormalPointer( GL_FLOAT, 0, aTriangleContainer->GetNormalsPointer() );
709
710 glNewList( listIdx, GL_COMPILE );
711
713
714 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->GetVertexSize() );
715
716 glDisable( GL_BLEND );
717 glEndList();
718
719 glDisableClientState( GL_VERTEX_ARRAY );
720 glDisableClientState( GL_NORMAL_ARRAY );
721
722 return listIdx;
723 }
724 }
725
726 return 0;
727}
728
729
731{
733 {
734 glPopMatrix();
735 }
736}
737
738
740{
741 glEnable( GL_BLEND );
742 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
743}
744
745
747{
749 {
750 glPushMatrix();
751 glTranslatef( 0.0f, 0.0f, m_zPositionTransformation );
752 glScalef( 1.0f, 1.0f, m_zScaleTransformation );
753 }
754}
755
756// LocalWords: EDA Luzeiro txt MERCHANTABILITY wxASSERT normals fo
bool IntersectAny(const RAYSEG2D &aSegRay) const override
Intersect and check if a segment ray hits a object or is inside it.
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 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 DrawCulled(bool aDrawMiddle, const OPENGL_RENDER_LIST *aSubtractList=nullptr, const OPENGL_RENDER_LIST *bSubtractList=nullptr, const OPENGL_RENDER_LIST *cSubtractList=nullptr, const OPENGL_RENDER_LIST *dSubtractList=nullptr) const
Draw all layers if they are visible by the camera if camera position is above the layer.
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...
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
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
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.
SFVEC3F_VECTOR m_normals
normals array
unsigned int GetNormalsSize() const
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
SFVEC3F_VECTOR m_vertexs
vertex array
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.
VECTOR3I v1(5, 5, 5)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
glm::vec2 SFVEC2F
Definition xv3d_types.h:42
glm::vec3 SFVEC3F
Definition xv3d_types.h:44