33 if( aNrReservedTriangles > 0 )
34 m_vertexs.reserve( aNrReservedTriangles * 3 );
37 m_normals.reserve( aNrReservedTriangles * 3 );
121 float zBot,
float zTop,
bool aInvertFaceDirection,
124 if( aContourPoints.size() >= 4 )
127 std::vector< SFVEC2F > contourNormals;
129 contourNormals.clear();
130 contourNormals.resize( aContourPoints.size() - 1 );
132 if( aInvertFaceDirection )
134 for(
unsigned int i = 0; i < ( aContourPoints.size() - 1 ); ++i )
136 const SFVEC2F& v0 = aContourPoints[i + 0];
137 const SFVEC2F&
v1 = aContourPoints[i + 1];
138 const SFVEC2F n = glm::normalize(
v1 - v0 );
140 contourNormals[i] =
SFVEC2F( n.y, -n.x );
145 for(
unsigned int i = 0; i < ( aContourPoints.size() - 1 ); ++i )
147 const SFVEC2F& v0 = aContourPoints[i + 0];
148 const SFVEC2F&
v1 = aContourPoints[i + 1];
149 const SFVEC2F n = glm::normalize(
v1 - v0 );
151 contourNormals[i] =
SFVEC2F( -n.y, n.x );
156 if( aInvertFaceDirection )
157 std::swap( zBot, zTop );
159 const unsigned int nContoursToProcess = ( aContourPoints.size() - 1 );
161 for(
unsigned int i = 0; i < nContoursToProcess; ++i )
166 lastNormal = contourNormals[i - 1];
168 lastNormal = contourNormals[nContoursToProcess - 1];
170 SFVEC2F n0 = contourNormals[i];
173 if( glm::dot( n0, lastNormal ) > 0.5f )
174 n0 = glm::normalize( n0 + lastNormal );
178 if( i < ( nContoursToProcess - 1) )
179 nextNormal = contourNormals[i + 1];
181 nextNormal = contourNormals[0];
183 SFVEC2F n1 = contourNormals[i];
185 if( glm::dot( n1, nextNormal ) > 0.5f )
186 n1 = glm::normalize( n1 + nextNormal );
191 const SFVEC2F& v0 = aContourPoints[i + 0];
192 const SFVEC2F&
v1 = aContourPoints[i + 1];
214 double aBiuTo3Du,
bool aInvertFaceDirection,
217 std::vector<SFVEC2F> contourPoints;
219 contourPoints.clear();
220 contourPoints.reserve( outlinePath.
PointCount() + 2 );
226 contourPoints.push_back( lastV );
228 for(
unsigned int i = 1; i < (
unsigned int)outlinePath.
PointCount(); ++i )
237 contourPoints.push_back( vf );
242 if( lastV != contourPoints[0] )
243 contourPoints.push_back( contourPoints[0] );
250 double aBiuTo3Du,
bool aInvertFaceDirection,
257 unsigned int nrContourPointsToReserve = 0;
263 nrContourPointsToReserve += pathOutline.
PointCount();
265 for(
int h = 0; h < aPolySet.
HoleCount( i ); ++h )
269 nrContourPointsToReserve += hole.
PointCount();
281 AddToMiddleContours( pathOutline, zBot, zTop, aBiuTo3Du, aInvertFaceDirection, aThroughHoles );
284 for(
int h = 0; h < aPolySet.
HoleCount( i ); ++h )
294 GLuint aTextureIndexForSegEnds,
float aZBot,
float aZTop )
305 if( aTextureIndexForSegEnds )
307 wxASSERT( glIsTexture( aTextureIndexForSegEnds ) );
309 if( glIsTexture( aTextureIndexForSegEnds ) )
312 true, aTextureIndexForSegEnds );
315 false, aTextureIndexForSegEnds );
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
465 glClearStencil( 0x00 );
466 glClear( GL_STENCIL_BUFFER_BIT );
468 glEnable( GL_CULL_FACE );
469 glCullFace( GL_BACK );
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 );
479 aSubtractList->DrawBot();
482 bSubtractList->DrawBot();
485 cSubtractList->DrawBot();
488 dSubtractList->DrawBot();
490 glEnable( GL_DEPTH_TEST );
491 glDepthMask( GL_TRUE );
493 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
494 glStencilFunc( GL_EQUAL, 0, 1 );
495 glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
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 );
506 aSubtractList->DrawTop();
509 bSubtractList->DrawTop();
512 cSubtractList->DrawTop();
515 dSubtractList->DrawTop();
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 );
527 glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
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 );
537 aSubtractList->DrawMiddle();
540 glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
542 glCullFace( GL_BACK );
543 glDisable( GL_STENCIL_TEST );
549 wxCHECK2( aZscale > FLT_EPSILON, aZscale = FLT_EPSILON + 1 );
559 ApplyScalePosition( aOtherList->GetZBot(), aOtherList->GetZTop() - aOtherList->GetZBot() );
570 const TRIANGLE_LIST* aTriangleContainer,
bool aIsNormalUp, GLuint aTextureId )
const
572 wxCHECK( aTriangleContainer !=
nullptr, 0 );
574 wxASSERT( ( aTriangleContainer->
GetVertexSize() % 3 ) == 0 );
582 GLuint listIdx = glGenLists( 1 );
584 if( glIsList( listIdx ) )
589 for(
unsigned int i = 0; i < aTriangleContainer->
GetVertexSize(); i += 3 )
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 );
596 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
597 glDisableClientState( GL_COLOR_ARRAY );
598 glDisableClientState( GL_NORMAL_ARRAY );
599 glEnableClientState( GL_VERTEX_ARRAY );
601 glTexCoordPointer( 2, GL_FLOAT, 0, uvArray );
603 glNewList( listIdx, GL_COMPILE );
605 glDisable( GL_COLOR_MATERIAL );
607 glEnable( GL_TEXTURE_2D );
608 glBindTexture( GL_TEXTURE_2D, aTextureId );
610 glAlphaFunc( GL_GREATER, 0.2f );
611 glEnable( GL_ALPHA_TEST );
613 glNormal3f( 0.0f, 0.0f, aIsNormalUp?1.0f:-1.0f );
615 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->
GetVertexSize() );
617 glBindTexture( GL_TEXTURE_2D, 0 );
618 glDisable( GL_TEXTURE_2D );
619 glDisable( GL_ALPHA_TEST );
620 glDisable( GL_BLEND );
624 glDisableClientState( GL_VERTEX_ARRAY );
625 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
637 bool aIsNormalUp )
const
639 wxCHECK( aTriangleContainer !=
nullptr, 0 );
641 wxASSERT( ( aTriangleContainer->
GetVertexSize() % 3 ) == 0 );
649 const GLuint listIdx = glGenLists( 1 );
651 if( glIsList( listIdx ) )
653 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
654 glDisableClientState( GL_COLOR_ARRAY );
655 glDisableClientState( GL_NORMAL_ARRAY );
656 glEnableClientState( GL_VERTEX_ARRAY );
659 glNewList( listIdx, GL_COMPILE );
663 glNormal3f( 0.0f, 0.0f, aIsNormalUp?1.0f:-1.0f );
665 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->
GetVertexSize() );
667 glDisable( GL_BLEND );
670 glDisableClientState( GL_VERTEX_ARRAY );
683 wxCHECK( aTriangleContainer !=
nullptr, 0 );
686 wxASSERT( ( aTriangleContainer->
GetVertexSize() % 3 ) == 0 );
699 const GLuint listIdx = glGenLists( 1 );
701 if( glIsList( listIdx ) )
703 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
704 glDisableClientState( GL_COLOR_ARRAY );
705 glEnableClientState( GL_NORMAL_ARRAY );
706 glEnableClientState( GL_VERTEX_ARRAY );
710 glNewList( listIdx, GL_COMPILE );
714 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->
GetVertexSize() );
716 glDisable( GL_BLEND );
719 glDisableClientState( GL_VERTEX_ARRAY );
720 glDisableClientState( GL_NORMAL_ARRAY );
741 glEnable( GL_BLEND );
742 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 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 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 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