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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include "layer_triangles.h"
23#include "../raytracing/ray.h"
24#include <wx/debug.h> // For the wxASSERT
25#include <mutex>
26
27
28TRIANGLE_LIST::TRIANGLE_LIST( unsigned int aNrReservedTriangles, bool aReserveNormals )
29{
30 m_vertexs.clear();
31 m_normals.clear();
32
33 if( aNrReservedTriangles > 0 )
34 m_vertexs.reserve( aNrReservedTriangles * 3 );
35
36 if( aReserveNormals )
37 m_normals.reserve( aNrReservedTriangles * 3 );
38}
39
40
41void TRIANGLE_LIST::Reserve_More( unsigned int aNrReservedTriangles, bool aReserveNormals )
42{
43 m_vertexs.reserve( m_vertexs.size() + aNrReservedTriangles * 3 );
44
45 if( aReserveNormals )
46 m_normals.reserve( m_normals.size() + aNrReservedTriangles * 3 );
47}
48
49
50void TRIANGLE_LIST::AddQuad( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3,
51 const SFVEC3F& aV4 )
52{
53 m_vertexs.push_back( aV1 );
54 m_vertexs.push_back( aV2 );
55 m_vertexs.push_back( aV3 );
56
57 m_vertexs.push_back( aV3 );
58 m_vertexs.push_back( aV4 );
59 m_vertexs.push_back( aV1 );
60}
61
62
63void TRIANGLE_LIST::AddTriangle( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3 )
64{
65 m_vertexs.push_back( aV1 );
66 m_vertexs.push_back( aV2 );
67 m_vertexs.push_back( aV3 );
68}
69
70
71void TRIANGLE_LIST::AddNormal( const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3 )
72{
73 m_normals.push_back( aN1 );
74 m_normals.push_back( aN2 );
75 m_normals.push_back( aN3 );
76}
77
78void TRIANGLE_LIST::AddNormal( const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3,
79 const SFVEC3F& aN4 )
80{
81 m_normals.push_back( aN1 );
82 m_normals.push_back( aN2 );
83 m_normals.push_back( aN3 );
84
85 m_normals.push_back( aN3 );
86 m_normals.push_back( aN4 );
87 m_normals.push_back( aN1 );
88}
89
90
91TRIANGLE_DISPLAY_LIST::TRIANGLE_DISPLAY_LIST( unsigned int aNrReservedTriangles )
92{
93 m_layer_top_segment_ends = new TRIANGLE_LIST( aNrReservedTriangles, false );
94 m_layer_top_triangles = new TRIANGLE_LIST( aNrReservedTriangles, false );
95 m_layer_middle_contours_quads = new TRIANGLE_LIST( aNrReservedTriangles, true );
96 m_layer_bot_triangles = new TRIANGLE_LIST( aNrReservedTriangles, false );
97 m_layer_bot_segment_ends = new TRIANGLE_LIST( aNrReservedTriangles, false );
98}
99
100
118
119
120void TRIANGLE_DISPLAY_LIST::AddToMiddleContours( const std::vector<SFVEC2F>& aContourPoints,
121 float zBot, float zTop, bool aInvertFaceDirection,
122 const BVH_CONTAINER_2D* aThroughHoles )
123{
124 if( aContourPoints.size() >= 4 )
125 {
126 // Calculate normals of each segment of the contour
127 std::vector< SFVEC2F > contourNormals;
128
129 contourNormals.clear();
130 contourNormals.resize( aContourPoints.size() - 1 );
131
132 if( aInvertFaceDirection )
133 {
134 for( unsigned int i = 0; i < ( aContourPoints.size() - 1 ); ++i )
135 {
136 const SFVEC2F& v0 = aContourPoints[i + 0];
137 const SFVEC2F& v1 = aContourPoints[i + 1];
138 const SFVEC2F n = glm::normalize( v1 - v0 );
139
140 contourNormals[i] = SFVEC2F( n.y, -n.x );
141 }
142 }
143 else
144 {
145 for( unsigned int i = 0; i < ( aContourPoints.size() - 1 ); ++i )
146 {
147 const SFVEC2F& v0 = aContourPoints[i + 0];
148 const SFVEC2F& v1 = aContourPoints[i + 1];
149 const SFVEC2F n = glm::normalize( v1 - v0 );
150
151 contourNormals[i] = SFVEC2F( -n.y, n.x );
152 }
153 }
154
155
156 if( aInvertFaceDirection )
157 std::swap( zBot, zTop );
158
159 const unsigned int nContoursToProcess = ( aContourPoints.size() - 1 );
160
161 for( unsigned int i = 0; i < nContoursToProcess; ++i )
162 {
163 SFVEC2F lastNormal;
164
165 if( i > 0 )
166 lastNormal = contourNormals[i - 1];
167 else
168 lastNormal = contourNormals[nContoursToProcess - 1];
169
170 SFVEC2F n0 = contourNormals[i];
171
172 // Only interpolate the normal if the angle is closer
173 if( glm::dot( n0, lastNormal ) > 0.5f )
174 n0 = glm::normalize( n0 + lastNormal );
175
176 SFVEC2F nextNormal;
177
178 if( i < ( nContoursToProcess - 1) )
179 nextNormal = contourNormals[i + 1];
180 else
181 nextNormal = contourNormals[0];
182
183 SFVEC2F n1 = contourNormals[i];
184
185 if( glm::dot( n1, nextNormal ) > 0.5f )
186 n1 = glm::normalize( n1 + nextNormal );
187
188 const SFVEC3F n3d0 = SFVEC3F( n0.x, n0.y, 0.0f );
189 const SFVEC3F n3d1 = SFVEC3F( n1.x, n1.y, 0.0f );
190
191 const SFVEC2F& v0 = aContourPoints[i + 0];
192 const SFVEC2F& v1 = aContourPoints[i + 1];
193
194 if( aThroughHoles && aThroughHoles->IntersectAny( RAYSEG2D( v0, v1 ) ) )
195 {
196 continue;
197 }
198 else
199 {
200 std::lock_guard<std::mutex> lock( m_middle_layer_lock );
201 m_layer_middle_contours_quads->AddQuad( SFVEC3F( v0.x, v0.y, zTop ),
202 SFVEC3F( v1.x, v1.y, zTop ),
203 SFVEC3F( v1.x, v1.y, zBot ),
204 SFVEC3F( v0.x, v0.y, zBot ) );
205
206 m_layer_middle_contours_quads->AddNormal( n3d0, n3d1, n3d1, n3d0 );
207 }
208 }
209 }
210}
211
212
213void TRIANGLE_DISPLAY_LIST::AddToMiddleContours( const SHAPE_LINE_CHAIN& outlinePath, float zBot, float zTop,
214 double aBiuTo3Du, bool aInvertFaceDirection,
215 const BVH_CONTAINER_2D* aThroughHoles )
216{
217 std::vector<SFVEC2F> contourPoints;
218
219 contourPoints.clear();
220 contourPoints.reserve( outlinePath.PointCount() + 2 );
221
222 const VECTOR2I& firstV = outlinePath.CPoint( 0 );
223
224 SFVEC2F lastV = SFVEC2F( firstV.x * aBiuTo3Du, -firstV.y * aBiuTo3Du );
225
226 contourPoints.push_back( lastV );
227
228 for( unsigned int i = 1; i < (unsigned int)outlinePath.PointCount(); ++i )
229 {
230 const VECTOR2I& v = outlinePath.CPoint( i );
231
232 const SFVEC2F vf = SFVEC2F( v.x * aBiuTo3Du, -v.y * aBiuTo3Du );
233
234 if( vf != lastV ) // Do not add repeated points
235 {
236 lastV = vf;
237 contourPoints.push_back( vf );
238 }
239 }
240
241 // Add first position of the list to close the path.
242 if( lastV != contourPoints[0] )
243 contourPoints.push_back( contourPoints[0] );
244
245 AddToMiddleContours( contourPoints, zBot, zTop, aInvertFaceDirection, aThroughHoles );
246}
247
248
249void TRIANGLE_DISPLAY_LIST::AddToMiddleContours( const SHAPE_POLY_SET& aPolySet, float zBot, float zTop,
250 double aBiuTo3Du, bool aInvertFaceDirection,
251 const BVH_CONTAINER_2D* aThroughHoles )
252{
253 if( aPolySet.OutlineCount() == 0 )
254 return;
255
256 // Calculate an estimation of points to reserve
257 unsigned int nrContourPointsToReserve = 0;
258
259 for( int i = 0; i < aPolySet.OutlineCount(); ++i )
260 {
261 const SHAPE_LINE_CHAIN& pathOutline = aPolySet.COutline( i );
262
263 nrContourPointsToReserve += pathOutline.PointCount();
264
265 for( int h = 0; h < aPolySet.HoleCount( i ); ++h )
266 {
267 const SHAPE_LINE_CHAIN& hole = aPolySet.CHole( i, h );
268
269 nrContourPointsToReserve += hole.PointCount();
270 }
271 }
272
273 // Request to reserve more space
274 m_layer_middle_contours_quads->Reserve_More( nrContourPointsToReserve * 2, true );
275
276 for( int i = 0; i < aPolySet.OutlineCount(); i++ )
277 {
278 // Add outline
279 const SHAPE_LINE_CHAIN& pathOutline = aPolySet.COutline( i );
280
281 AddToMiddleContours( pathOutline, zBot, zTop, aBiuTo3Du, aInvertFaceDirection, aThroughHoles );
282
283 // Add holes for this outline
284 for( int h = 0; h < aPolySet.HoleCount( i ); ++h )
285 {
286 const SHAPE_LINE_CHAIN& hole = aPolySet.CHole( i, h );
287 AddToMiddleContours( hole, zBot, zTop, aBiuTo3Du, aInvertFaceDirection, aThroughHoles );
288 }
289 }
290}
291
292
294 GLuint aTextureIndexForSegEnds, float aZBot, float aZTop )
295{
296 m_zBot = aZBot;
297 m_zTop = aZTop;
298
304
305 if( aTextureIndexForSegEnds )
306 {
307 wxASSERT( glIsTexture( aTextureIndexForSegEnds ) );
308
309 if( glIsTexture( aTextureIndexForSegEnds ) )
310 {
312 true, aTextureIndexForSegEnds );
313
315 false, aTextureIndexForSegEnds );
316 }
317 }
318
320
322
323
324 if( aLayerTriangles.m_layer_middle_contours_quads->GetVertexSize() > 0 )
326
327 m_draw_it_transparent = false;
328 m_haveTransformation = false;
331}
332
333
335{
337 {
338 if( glIsList( m_layer_top_segment_ends ) )
339 glDeleteLists( m_layer_top_segment_ends, 1 );
340
341 if( glIsList( m_layer_top_triangles ) )
342 glDeleteLists( m_layer_top_triangles, 1 );
343
344 if( glIsList( m_layer_middle_contours_quads ) )
345 glDeleteLists( m_layer_middle_contours_quads, 1 );
346
347 if( glIsList( m_layer_bot_triangles ) )
348 glDeleteLists( m_layer_bot_triangles, 1 );
349
350 if( glIsList( m_layer_bot_segment_ends ) )
351 glDeleteLists( m_layer_bot_segment_ends, 1 );
352 }
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 std::shared_ptr<OPENGL_RENDER_LIST> aSubtractList,
461 const std::shared_ptr<OPENGL_RENDER_LIST> bSubtractList,
462 const std::shared_ptr<OPENGL_RENDER_LIST> cSubtractList,
463 const std::shared_ptr<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
557void OPENGL_RENDER_LIST::ApplyScalePosition( std::shared_ptr<OPENGL_RENDER_LIST> aOtherList )
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
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...
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.
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.
VECTOR3I v1(5, 5, 5)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
glm::vec2 SFVEC2F
Definition xv3d_types.h:38
glm::vec3 SFVEC3F
Definition xv3d_types.h:40