36 if( aNrReservedTriangles > 0 )
37 m_vertexs.reserve( aNrReservedTriangles * 3 );
40 m_normals.reserve( aNrReservedTriangles * 3 );
124 float zBot,
float zTop,
bool aInvertFaceDirection,
127 if( aContournPoints.size() >= 4 )
130 std::vector< SFVEC2F > contournNormals;
132 contournNormals.clear();
133 contournNormals.resize( aContournPoints.size() - 1 );
135 if( aInvertFaceDirection )
137 for(
unsigned int i = 0; i < ( aContournPoints.size() - 1 ); ++i )
139 const SFVEC2F& v0 = aContournPoints[i + 0];
140 const SFVEC2F&
v1 = aContournPoints[i + 1];
141 const SFVEC2F n = glm::normalize(
v1 - v0 );
143 contournNormals[i] =
SFVEC2F( n.y,-n.x );
148 for(
unsigned int i = 0; i < ( aContournPoints.size() - 1 ); ++i )
150 const SFVEC2F& v0 = aContournPoints[i + 0];
151 const SFVEC2F&
v1 = aContournPoints[i + 1];
152 const SFVEC2F n = glm::normalize(
v1 - v0 );
154 contournNormals[i] =
SFVEC2F( -n.y, n.x );
159 if( aInvertFaceDirection )
160 std::swap( zBot, zTop );
162 const unsigned int nContournsToProcess = ( aContournPoints.size() - 1 );
164 for(
unsigned int i = 0; i < nContournsToProcess; ++i )
169 lastNormal = contournNormals[i - 1];
171 lastNormal = contournNormals[nContournsToProcess - 1];
173 SFVEC2F n0 = contournNormals[i];
176 if( glm::dot( n0, lastNormal ) > 0.5f )
177 n0 = glm::normalize( n0 + lastNormal );
181 if( i < (nContournsToProcess - 1) )
182 nextNormal = contournNormals[i + 1];
184 nextNormal = contournNormals[0];
186 SFVEC2F n1 = contournNormals[i];
188 if( glm::dot( n1, nextNormal ) > 0.5f )
189 n1 = glm::normalize( n1 + nextNormal );
194 const SFVEC2F& v0 = aContournPoints[i + 0];
195 const SFVEC2F&
v1 = aContournPoints[i + 1];
217 float zTop,
double aBiuTo3Du,
218 bool aInvertFaceDirection,
221 std::vector< SFVEC2F >contournPoints;
223 contournPoints.clear();
224 contournPoints.reserve( outlinePath.
PointCount() + 2 );
230 contournPoints.push_back( lastV );
232 for(
unsigned int i = 1; i < (
unsigned int)outlinePath.
PointCount(); ++i )
241 contournPoints.push_back( vf );
246 if( lastV != contournPoints[0] )
247 contournPoints.push_back( contournPoints[0] );
254 float zTop,
double aBiuTo3Du,
255 bool aInvertFaceDirection,
262 unsigned int nrContournPointsToReserve = 0;
268 nrContournPointsToReserve += pathOutline.
PointCount();
270 for(
int h = 0; h < aPolySet.
HoleCount( i ); ++h )
274 nrContournPointsToReserve += hole.
PointCount();
290 for(
int h = 0; h < aPolySet.
HoleCount( i ); ++h )
301 GLuint aTextureIndexForSegEnds,
302 float aZBot,
float aZTop )
313 if( aTextureIndexForSegEnds )
315 wxASSERT( glIsTexture( aTextureIndexForSegEnds ) );
317 if( glIsTexture( aTextureIndexForSegEnds ) )
321 true, aTextureIndexForSegEnds );
325 false, aTextureIndexForSegEnds );
477 glClearStencil( 0x00 );
478 glClear( GL_STENCIL_BUFFER_BIT );
480 glEnable( GL_CULL_FACE );
481 glCullFace( GL_BACK );
483 glDisable( GL_DEPTH_TEST );
484 glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
485 glDepthMask( GL_FALSE );
486 glEnable( GL_STENCIL_TEST );
487 glStencilFunc( GL_ALWAYS, 1, 0 );
488 glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
502 glEnable( GL_DEPTH_TEST );
503 glDepthMask( GL_TRUE );
505 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
506 glStencilFunc( GL_EQUAL, 0, 1 );
507 glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
510 glDisable( GL_DEPTH_TEST );
511 glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
512 glDepthMask( GL_FALSE );
513 glEnable( GL_STENCIL_TEST );
514 glStencilFunc( GL_ALWAYS, 2, 0 );
515 glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
529 glEnable( GL_DEPTH_TEST );
530 glDepthMask( GL_TRUE );
531 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
532 glStencilFunc( GL_NOTEQUAL, 2, 0x03 );
533 glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
539 glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
541 glCullFace( GL_FRONT );
542 glStencilFunc( GL_GEQUAL, 3, 0x03 );
543 glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
544 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
552 glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
554 glCullFace( GL_BACK );
555 glDisable( GL_STENCIL_TEST );
561 wxCHECK2( aZscale > FLT_EPSILON, aZscale = FLT_EPSILON + 1 );
582 const TRIANGLE_LIST* aTriangleContainer,
bool aIsNormalUp, GLuint aTextureId )
const
584 wxCHECK( aTriangleContainer !=
nullptr, 0 );
586 wxASSERT( ( aTriangleContainer->
GetVertexSize() % 3 ) == 0 );
594 GLuint listIdx = glGenLists( 1 );
596 if( glIsList( listIdx ) )
601 for(
unsigned int i = 0; i < aTriangleContainer->
GetVertexSize(); i += 3 )
603 uvArray[i + 0] =
SFVEC2F( 1.0f, 0.0f );
604 uvArray[i + 1] =
SFVEC2F( 0.0f, 1.0f );
605 uvArray[i + 2] =
SFVEC2F( 0.0f, 0.0f );
608 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
609 glDisableClientState( GL_COLOR_ARRAY );
610 glDisableClientState( GL_NORMAL_ARRAY );
611 glEnableClientState( GL_VERTEX_ARRAY );
613 glTexCoordPointer( 2, GL_FLOAT, 0, uvArray );
615 glNewList( listIdx, GL_COMPILE );
617 glDisable( GL_COLOR_MATERIAL );
619 glEnable( GL_TEXTURE_2D );
620 glBindTexture( GL_TEXTURE_2D, aTextureId );
622 glAlphaFunc( GL_GREATER, 0.2f );
623 glEnable( GL_ALPHA_TEST );
625 glNormal3f( 0.0f, 0.0f, aIsNormalUp?1.0f:-1.0f );
627 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->
GetVertexSize() );
629 glBindTexture( GL_TEXTURE_2D, 0 );
630 glDisable( GL_TEXTURE_2D );
631 glDisable( GL_ALPHA_TEST );
632 glDisable( GL_BLEND );
636 glDisableClientState( GL_VERTEX_ARRAY );
637 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
649 bool aIsNormalUp )
const
651 wxCHECK( aTriangleContainer !=
nullptr, 0 );
653 wxASSERT( ( aTriangleContainer->
GetVertexSize() % 3 ) == 0 );
661 const GLuint listIdx = glGenLists( 1 );
663 if( glIsList( listIdx ) )
665 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
666 glDisableClientState( GL_COLOR_ARRAY );
667 glDisableClientState( GL_NORMAL_ARRAY );
668 glEnableClientState( GL_VERTEX_ARRAY );
671 glNewList( listIdx, GL_COMPILE );
675 glNormal3f( 0.0f, 0.0f, aIsNormalUp?1.0f:-1.0f );
677 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->
GetVertexSize() );
679 glDisable( GL_BLEND );
682 glDisableClientState( GL_VERTEX_ARRAY );
695 wxCHECK( aTriangleContainer !=
nullptr, 0 );
698 wxASSERT( ( aTriangleContainer->
GetVertexSize() % 3 ) == 0 );
711 const GLuint listIdx = glGenLists( 1 );
713 if( glIsList( listIdx ) )
715 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
716 glDisableClientState( GL_COLOR_ARRAY );
717 glEnableClientState( GL_NORMAL_ARRAY );
718 glEnableClientState( GL_VERTEX_ARRAY );
722 glNewList( listIdx, GL_COMPILE );
726 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->
GetVertexSize() );
728 glDisable( GL_BLEND );
731 glDisableClientState( GL_VERTEX_ARRAY );
732 glDisableClientState( GL_NORMAL_ARRAY );
753 glEnable( GL_BLEND );
754 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
GLuint m_layer_middle_contourns_quads
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
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
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
void AddToMiddleContourns(const SHAPE_LINE_CHAIN &outlinePath, float zBot, float zTop, double aBiuTo3Du, bool aInvertFaceDirection, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
TRIANGLE_LIST * m_layer_middle_contourns_quads
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.
VECTOR2< int32_t > VECTOR2I