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 );
480 glClearStencil( 0x00 );
481 glClear( GL_STENCIL_BUFFER_BIT );
483 glEnable( GL_CULL_FACE );
484 glCullFace( GL_BACK );
486 glDisable( GL_DEPTH_TEST );
487 glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
488 glDepthMask( GL_FALSE );
489 glEnable( GL_STENCIL_TEST );
490 glStencilFunc( GL_ALWAYS, 1, 0 );
491 glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
505 glEnable(GL_DEPTH_TEST);
506 glDepthMask(GL_TRUE);
508 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
509 glStencilFunc( GL_EQUAL, 0, 1 );
510 glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
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, 2, 0 );
518 glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
532 glEnable(GL_DEPTH_TEST);
533 glDepthMask(GL_TRUE);
534 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
535 glStencilFunc( GL_NOTEQUAL, 2, 0x03 );
536 glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
542 glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
544 glCullFace( GL_FRONT );
545 glStencilFunc( GL_GEQUAL, 3, 0x03 );
546 glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
547 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
555 glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
557 glCullFace( GL_BACK );
558 glDisable( GL_STENCIL_TEST );
564 wxCHECK2( aZscale > FLT_EPSILON, aZscale = FLT_EPSILON + 1 );
585 const TRIANGLE_LIST* aTriangleContainer,
bool aIsNormalUp, GLuint aTextureId )
const
587 wxASSERT( aTriangleContainer !=
nullptr );
589 wxASSERT( ( aTriangleContainer->
GetVertexSize() % 3 ) == 0 );
597 GLuint listIdx = glGenLists( 1 );
599 if( glIsList( listIdx ) )
604 for(
unsigned int i = 0; i < aTriangleContainer->
GetVertexSize(); i += 3 )
606 uvArray[i + 0] =
SFVEC2F( 1.0f, 0.0f );
607 uvArray[i + 1] =
SFVEC2F( 0.0f, 1.0f );
608 uvArray[i + 2] =
SFVEC2F( 0.0f, 0.0f );
611 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
612 glDisableClientState( GL_COLOR_ARRAY );
613 glDisableClientState( GL_NORMAL_ARRAY );
614 glEnableClientState( GL_VERTEX_ARRAY );
616 glTexCoordPointer( 2, GL_FLOAT, 0, uvArray );
618 glNewList( listIdx, GL_COMPILE );
620 glDisable( GL_COLOR_MATERIAL );
622 glEnable( GL_TEXTURE_2D );
623 glBindTexture( GL_TEXTURE_2D, aTextureId );
625 glAlphaFunc( GL_GREATER, 0.2f );
626 glEnable( GL_ALPHA_TEST );
628 glNormal3f( 0.0f, 0.0f, aIsNormalUp?1.0f:-1.0f );
630 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->
GetVertexSize() );
632 glBindTexture( GL_TEXTURE_2D, 0 );
633 glDisable( GL_TEXTURE_2D );
634 glDisable( GL_ALPHA_TEST );
635 glDisable( GL_BLEND );
639 glDisableClientState( GL_VERTEX_ARRAY );
640 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
652 bool aIsNormalUp )
const
654 wxASSERT( aTriangleContainer !=
nullptr );
656 wxASSERT( ( aTriangleContainer->
GetVertexSize() % 3 ) == 0 );
664 const GLuint listIdx = glGenLists( 1 );
666 if( glIsList( listIdx ) )
668 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
669 glDisableClientState( GL_COLOR_ARRAY );
670 glDisableClientState( GL_NORMAL_ARRAY );
671 glEnableClientState( GL_VERTEX_ARRAY );
674 glNewList( listIdx, GL_COMPILE );
678 glNormal3f( 0.0f, 0.0f, aIsNormalUp?1.0f:-1.0f );
680 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->
GetVertexSize() );
682 glDisable( GL_BLEND );
685 glDisableClientState( GL_VERTEX_ARRAY );
698 wxASSERT( aTriangleContainer !=
nullptr );
701 wxASSERT( ( aTriangleContainer->
GetVertexSize() % 3 ) == 0 );
714 const GLuint listIdx = glGenLists( 1 );
716 if( glIsList( listIdx ) )
718 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
719 glDisableClientState( GL_COLOR_ARRAY );
720 glEnableClientState( GL_NORMAL_ARRAY );
721 glEnableClientState( GL_VERTEX_ARRAY );
725 glNewList( listIdx, GL_COMPILE );
729 glDrawArrays( GL_TRIANGLES, 0, aTriangleContainer->
GetVertexSize() );
731 glDisable( GL_BLEND );
734 glDisableClientState( GL_VERTEX_ARRAY );
735 glDisableClientState( GL_NORMAL_ARRAY );
756 glEnable( GL_BLEND );
757 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 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.