32 if( aNrReservedTriangles > 0 )
33 m_vertexs.reserve( aNrReservedTriangles * 3 );
36 m_normals.reserve( aNrReservedTriangles * 3 );
120 float zBot,
float zTop,
bool aInvertFaceDirection,
123 if( aContourPoints.size() >= 4 )
126 std::vector< SFVEC2F > contourNormals;
128 contourNormals.clear();
129 contourNormals.resize( aContourPoints.size() - 1 );
131 if( aInvertFaceDirection )
133 for(
unsigned int i = 0; i < ( aContourPoints.size() - 1 ); ++i )
135 const SFVEC2F& v0 = aContourPoints[i + 0];
136 const SFVEC2F&
v1 = aContourPoints[i + 1];
137 const SFVEC2F n = glm::normalize(
v1 - v0 );
139 contourNormals[i] =
SFVEC2F( n.y, -n.x );
144 for(
unsigned int i = 0; i < ( aContourPoints.size() - 1 ); ++i )
146 const SFVEC2F& v0 = aContourPoints[i + 0];
147 const SFVEC2F&
v1 = aContourPoints[i + 1];
148 const SFVEC2F n = glm::normalize(
v1 - v0 );
150 contourNormals[i] =
SFVEC2F( -n.y, n.x );
155 if( aInvertFaceDirection )
156 std::swap( zBot, zTop );
158 const unsigned int nContoursToProcess = ( aContourPoints.size() - 1 );
160 for(
unsigned int i = 0; i < nContoursToProcess; ++i )
165 lastNormal = contourNormals[i - 1];
167 lastNormal = contourNormals[nContoursToProcess - 1];
169 SFVEC2F n0 = contourNormals[i];
172 if( glm::dot( n0, lastNormal ) > 0.5f )
173 n0 = glm::normalize( n0 + lastNormal );
177 if( i < ( nContoursToProcess - 1) )
178 nextNormal = contourNormals[i + 1];
180 nextNormal = contourNormals[0];
182 SFVEC2F n1 = contourNormals[i];
184 if( glm::dot( n1, nextNormal ) > 0.5f )
185 n1 = glm::normalize( n1 + nextNormal );
190 const SFVEC2F& v0 = aContourPoints[i + 0];
191 const SFVEC2F&
v1 = aContourPoints[i + 1];
213 double aBiuTo3Du,
bool aInvertFaceDirection,
216 std::vector<SFVEC2F> contourPoints;
218 contourPoints.clear();
219 contourPoints.reserve( outlinePath.
PointCount() + 2 );
225 contourPoints.push_back( lastV );
227 for(
unsigned int i = 1; i < (
unsigned int)outlinePath.
PointCount(); ++i )
236 contourPoints.push_back( vf );
241 if( lastV != contourPoints[0] )
242 contourPoints.push_back( contourPoints[0] );
249 double aBiuTo3Du,
bool aInvertFaceDirection,
256 unsigned int nrContourPointsToReserve = 0;
262 nrContourPointsToReserve += pathOutline.
PointCount();
264 for(
int h = 0; h < aPolySet.
HoleCount( i ); ++h )
268 nrContourPointsToReserve += hole.
PointCount();
280 AddToMiddleContours( pathOutline, zBot, zTop, aBiuTo3Du, aInvertFaceDirection, aThroughHoles );
283 for(
int h = 0; h < aPolySet.
HoleCount( i ); ++h )
293 GLuint aTextureIndexForSegEnds,
float aZBot,
float aZTop )
304 if( aTextureIndexForSegEnds )
306 wxASSERT( glIsTexture( aTextureIndexForSegEnds ) );
308 if( glIsTexture( aTextureIndexForSegEnds ) )
311 true, aTextureIndexForSegEnds );
314 false, aTextureIndexForSegEnds );
461 glClearStencil( 0x00 );
462 glClear( GL_STENCIL_BUFFER_BIT );
464 glEnable( GL_CULL_FACE );
465 glCullFace( GL_BACK );
467 glDisable( GL_DEPTH_TEST );
468 glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
469 glDepthMask( GL_FALSE );
470 glEnable( GL_STENCIL_TEST );
471 glStencilFunc( GL_ALWAYS, 1, 0 );
472 glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
486 glEnable( GL_DEPTH_TEST );
487 glDepthMask( GL_TRUE );
489 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
490 glStencilFunc( GL_EQUAL, 0, 1 );
491 glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
494 glDisable( GL_DEPTH_TEST );
495 glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
496 glDepthMask( GL_FALSE );
497 glEnable( GL_STENCIL_TEST );
498 glStencilFunc( GL_ALWAYS, 2, 0 );
499 glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
513 glEnable( GL_DEPTH_TEST );
514 glDepthMask( GL_TRUE );
515 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
516 glStencilFunc( GL_NOTEQUAL, 2, 0x03 );
517 glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
523 glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
525 glCullFace( GL_FRONT );
526 glStencilFunc( GL_GEQUAL, 3, 0x03 );
527 glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
528 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
536 glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
538 glCullFace( GL_BACK );
539 glDisable( GL_STENCIL_TEST );
545 wxCHECK2( aZscale > FLT_EPSILON, aZscale = FLT_EPSILON + 1 );
566 const TRIANGLE_LIST* aTriangleContainer,
bool aIsNormalUp, GLuint aTextureId )
const
568 wxCHECK( aTriangleContainer !=
nullptr, 0 );
570 wxASSERT( ( aTriangleContainer->
GetVertexSize() % 3 ) == 0 );
578 GLuint listIdx = glGenLists( 1 );
580 if( glIsList( listIdx ) )
585 for(
unsigned int i = 0; i < aTriangleContainer->
GetVertexSize(); i += 3 )
587 uvArray[i + 0] =
SFVEC2F( 1.0f, 0.0f );
588 uvArray[i + 1] =
SFVEC2F( 0.0f, 1.0f );
589 uvArray[i + 2] =
SFVEC2F( 0.0f, 0.0f );
592 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
593 glDisableClientState( GL_COLOR_ARRAY );
594 glDisableClientState( GL_NORMAL_ARRAY );
595 glEnableClientState( GL_VERTEX_ARRAY );
597 glTexCoordPointer( 2, GL_FLOAT, 0, uvArray );
599 glNewList( listIdx, GL_COMPILE );
601 glDisable( GL_COLOR_MATERIAL );
603 glEnable( GL_TEXTURE_2D );
604 glBindTexture( GL_TEXTURE_2D, aTextureId );
606 glAlphaFunc( GL_GREATER, 0.2f );
607 glEnable( GL_ALPHA_TEST );
609 glNormal3f( 0.0f, 0.0f, aIsNormalUp?1.0f:-1.0f );
611 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->
GetVertexSize() );
613 glBindTexture( GL_TEXTURE_2D, 0 );
614 glDisable( GL_TEXTURE_2D );
615 glDisable( GL_ALPHA_TEST );
616 glDisable( GL_BLEND );
620 glDisableClientState( GL_VERTEX_ARRAY );
621 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
633 bool aIsNormalUp )
const
635 wxCHECK( aTriangleContainer !=
nullptr, 0 );
637 wxASSERT( ( aTriangleContainer->
GetVertexSize() % 3 ) == 0 );
645 const GLuint listIdx = glGenLists( 1 );
647 if( glIsList( listIdx ) )
649 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
650 glDisableClientState( GL_COLOR_ARRAY );
651 glDisableClientState( GL_NORMAL_ARRAY );
652 glEnableClientState( GL_VERTEX_ARRAY );
655 glNewList( listIdx, GL_COMPILE );
659 glNormal3f( 0.0f, 0.0f, aIsNormalUp?1.0f:-1.0f );
661 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->
GetVertexSize() );
663 glDisable( GL_BLEND );
666 glDisableClientState( GL_VERTEX_ARRAY );
679 wxCHECK( aTriangleContainer !=
nullptr, 0 );
682 wxASSERT( ( aTriangleContainer->
GetVertexSize() % 3 ) == 0 );
695 const GLuint listIdx = glGenLists( 1 );
697 if( glIsList( listIdx ) )
699 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
700 glDisableClientState( GL_COLOR_ARRAY );
701 glEnableClientState( GL_NORMAL_ARRAY );
702 glEnableClientState( GL_VERTEX_ARRAY );
706 glNewList( listIdx, GL_COMPILE );
710 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->
GetVertexSize() );
712 glDisable( GL_BLEND );
715 glDisableClientState( GL_VERTEX_ARRAY );
716 glDisableClientState( GL_NORMAL_ARRAY );
737 glEnable( GL_BLEND );
738 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
bool IntersectAny(const RAYSEG2D &aSegRay) const override
Intersect and check if a segment ray hits a object or is inside it.
float m_zPositionTransformation
GLuint generate_middle_triangles(const TRIANGLE_LIST *aTriangleContainer) const
bool m_haveTransformation
bool m_draw_it_transparent
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
GLuint m_layer_bot_segment_ends
void DrawTop() const
Call the display lists for the top elements.
GLuint m_layer_bot_triangles
GLuint m_layer_middle_contours_quads
void DrawBot() const
Call the display lists for the bottom elements.
void ApplyScalePosition(float aZposition, float aZscale)
GLuint m_layer_top_triangles
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.
float m_zScaleTransformation
OPENGL_RENDER_LIST(const TRIANGLE_DISPLAY_LIST &aLayerTriangles, GLuint aTextureIndexForSegEnds, float aZBot, float aZTop)
Create the display lists for a layer.
GLuint m_layer_top_segment_ends
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
std::mutex m_middle_layer_lock
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.
VECTOR2< int32_t > VECTOR2I