26#include "../raytracing/ray.h"
33 wxASSERT( aNrReservedTriangles > 0 );
38 m_vertexs.reserve( aNrReservedTriangles * 3 );
41 m_normals.reserve( aNrReservedTriangles * 3 );
97 wxASSERT( aNrReservedTriangles > 0 );
127 float zBot,
float zTop,
bool aInvertFaceDirection,
130 if( aContournPoints.size() >= 4 )
133 std::vector< SFVEC2F > contournNormals;
135 contournNormals.clear();
136 contournNormals.resize( aContournPoints.size() - 1 );
138 if( aInvertFaceDirection )
140 for(
unsigned int i = 0; i < ( aContournPoints.size() - 1 ); ++i )
142 const SFVEC2F& v0 = aContournPoints[i + 0];
143 const SFVEC2F&
v1 = aContournPoints[i + 1];
144 const SFVEC2F n = glm::normalize(
v1 - v0 );
146 contournNormals[i] =
SFVEC2F( n.y,-n.x );
151 for(
unsigned int i = 0; i < ( aContournPoints.size() - 1 ); ++i )
153 const SFVEC2F& v0 = aContournPoints[i + 0];
154 const SFVEC2F&
v1 = aContournPoints[i + 1];
155 const SFVEC2F n = glm::normalize(
v1 - v0 );
157 contournNormals[i] =
SFVEC2F( -n.y, n.x );
162 if( aInvertFaceDirection )
163 std::swap( zBot, zTop );
165 const unsigned int nContournsToProcess = ( aContournPoints.size() - 1 );
167 for(
unsigned int i = 0; i < nContournsToProcess; ++i )
172 lastNormal = contournNormals[i - 1];
174 lastNormal = contournNormals[nContournsToProcess - 1];
176 SFVEC2F n0 = contournNormals[i];
179 if( glm::dot( n0, lastNormal ) > 0.5f )
180 n0 = glm::normalize( n0 + lastNormal );
184 if( i < (nContournsToProcess - 1) )
185 nextNormal = contournNormals[i + 1];
187 nextNormal = contournNormals[0];
189 SFVEC2F n1 = contournNormals[i];
191 if( glm::dot( n1, nextNormal ) > 0.5f )
192 n1 = glm::normalize( n1 + nextNormal );
197 const SFVEC2F& v0 = aContournPoints[i + 0];
198 const SFVEC2F&
v1 = aContournPoints[i + 1];
220 float zTop,
double aBiuTo3Du,
221 bool aInvertFaceDirection,
224 std::vector< SFVEC2F >contournPoints;
226 contournPoints.clear();
227 contournPoints.reserve( outlinePath.
PointCount() + 2 );
233 contournPoints.push_back( lastV );
235 for(
unsigned int i = 1; i < (
unsigned int)outlinePath.
PointCount(); ++i )
244 contournPoints.push_back( vf );
249 if( lastV != contournPoints[0] )
250 contournPoints.push_back( contournPoints[0] );
257 float zTop,
double aBiuTo3Du,
258 bool aInvertFaceDirection,
265 unsigned int nrContournPointsToReserve = 0;
271 nrContournPointsToReserve += pathOutline.
PointCount();
273 for(
int h = 0; h < aPolySet.
HoleCount( i ); ++h )
277 nrContournPointsToReserve += hole.
PointCount();
293 for(
int h = 0; h < aPolySet.
HoleCount( i ); ++h )
304 GLuint aTextureIndexForSegEnds,
305 float aZBot,
float aZTop )
316 if( aTextureIndexForSegEnds )
318 wxASSERT( glIsTexture( aTextureIndexForSegEnds ) );
320 if( glIsTexture( aTextureIndexForSegEnds ) )
324 true, aTextureIndexForSegEnds );
328 false, aTextureIndexForSegEnds );
507 glClearStencil( 0x00 );
508 glClear( GL_STENCIL_BUFFER_BIT );
510 glEnable( GL_CULL_FACE );
511 glCullFace( GL_BACK );
513 glDisable( GL_DEPTH_TEST );
514 glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
515 glDepthMask( GL_FALSE );
516 glEnable( GL_STENCIL_TEST );
517 glStencilFunc( GL_ALWAYS, 1, 0 );
518 glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
520 if( aLayerToSubtractA )
523 if( aLayerToSubtractB )
526 if( aLayerToSubtractC )
529 if( aLayerToSubtractD )
532 glEnable(GL_DEPTH_TEST);
533 glDepthMask(GL_TRUE);
535 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
536 glStencilFunc( GL_EQUAL, 0, 1 );
537 glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
540 glDisable( GL_DEPTH_TEST );
541 glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
542 glDepthMask( GL_FALSE );
543 glEnable( GL_STENCIL_TEST );
544 glStencilFunc( GL_ALWAYS, 2, 0 );
545 glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
547 if( aLayerToSubtractA )
550 if( aLayerToSubtractB )
553 if( aLayerToSubtractC )
556 if( aLayerToSubtractD )
559 glEnable(GL_DEPTH_TEST);
560 glDepthMask(GL_TRUE);
561 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
562 glStencilFunc( GL_NOTEQUAL, 2, 0x03 );
563 glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
569 glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
571 glCullFace( GL_FRONT );
572 glStencilFunc( GL_GEQUAL, 3, 0x03 );
573 glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
574 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
578 if( aLayerToSubtractA )
582 glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
584 glCullFace( GL_BACK );
585 glDisable( GL_STENCIL_TEST );
591 wxASSERT( aZscale > FLT_EPSILON );
606 const TRIANGLE_LIST* aTriangleContainer,
bool aIsNormalUp, GLuint aTextureId )
const
608 wxASSERT( aTriangleContainer !=
nullptr );
610 wxASSERT( ( aTriangleContainer->
GetVertexSize() % 3 ) == 0 );
618 GLuint listIdx = glGenLists( 1 );
620 if( glIsList( listIdx ) )
625 for(
unsigned int i = 0; i < aTriangleContainer->
GetVertexSize(); i += 3 )
627 uvArray[i + 0] =
SFVEC2F( 1.0f, 0.0f );
628 uvArray[i + 1] =
SFVEC2F( 0.0f, 1.0f );
629 uvArray[i + 2] =
SFVEC2F( 0.0f, 0.0f );
632 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
633 glDisableClientState( GL_COLOR_ARRAY );
634 glDisableClientState( GL_NORMAL_ARRAY );
635 glEnableClientState( GL_VERTEX_ARRAY );
637 glTexCoordPointer( 2, GL_FLOAT, 0, uvArray );
639 glNewList( listIdx, GL_COMPILE );
641 glDisable( GL_COLOR_MATERIAL );
643 glEnable( GL_TEXTURE_2D );
644 glBindTexture( GL_TEXTURE_2D, aTextureId );
646 glAlphaFunc( GL_GREATER, 0.2f );
647 glEnable( GL_ALPHA_TEST );
649 glNormal3f( 0.0f, 0.0f, aIsNormalUp?1.0f:-1.0f );
651 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->
GetVertexSize() );
653 glBindTexture( GL_TEXTURE_2D, 0 );
654 glDisable( GL_TEXTURE_2D );
655 glDisable( GL_ALPHA_TEST );
656 glDisable( GL_BLEND );
660 glDisableClientState( GL_VERTEX_ARRAY );
661 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
673 bool aIsNormalUp )
const
675 wxASSERT( aTriangleContainer !=
nullptr );
677 wxASSERT( ( aTriangleContainer->
GetVertexSize() % 3 ) == 0 );
685 const GLuint listIdx = glGenLists( 1 );
687 if( glIsList( listIdx ) )
689 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
690 glDisableClientState( GL_COLOR_ARRAY );
691 glDisableClientState( GL_NORMAL_ARRAY );
692 glEnableClientState( GL_VERTEX_ARRAY );
695 glNewList( listIdx, GL_COMPILE );
699 glNormal3f( 0.0f, 0.0f, aIsNormalUp?1.0f:-1.0f );
701 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->
GetVertexSize() );
703 glDisable( GL_BLEND );
706 glDisableClientState( GL_VERTEX_ARRAY );
719 wxASSERT( aTriangleContainer !=
nullptr );
722 wxASSERT( ( aTriangleContainer->
GetVertexSize() % 3 ) == 0 );
735 const GLuint listIdx = glGenLists( 1 );
737 if( glIsList( listIdx ) )
739 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
740 glDisableClientState( GL_COLOR_ARRAY );
741 glEnableClientState( GL_NORMAL_ARRAY );
742 glEnableClientState( GL_VERTEX_ARRAY );
746 glNewList( listIdx, GL_COMPILE );
750 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->
GetVertexSize() );
752 glDisable( GL_BLEND );
755 glDisableClientState( GL_VERTEX_ARRAY );
756 glDisableClientState( GL_NORMAL_ARRAY );
777 glEnable( GL_BLEND );
778 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.
Store the OpenGL display lists to related with a layer.
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 DrawAllCameraCulledSubtractLayer(bool aDrawMiddle, const OPENGL_RENDER_LIST *aLayerToSubtractA=nullptr, const OPENGL_RENDER_LIST *aLayerToSubtractB=nullptr, const OPENGL_RENDER_LIST *aLayerToSubtractC=nullptr, const OPENGL_RENDER_LIST *aLayerToSubtractD=nullptr) 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 DrawAllCameraCulled(float zCameraPos, bool aDrawMiddle=true) const
Draw all layers if they are visible by the camera if camera position is above the layer.
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
Return the reference to aIndex-th outline in the set.
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
int OutlineCount() const
Return the number of vertices in a given outline/hole.
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.