diff --git a/EgtGraphics.rc b/EgtGraphics.rc index 9d4c3a1..c1992fb 100644 Binary files a/EgtGraphics.rc and b/EgtGraphics.rc differ diff --git a/GraphObjs.h b/GraphObjs.h index 3e023e0..b08debd 100644 --- a/GraphObjs.h +++ b/GraphObjs.h @@ -13,6 +13,7 @@ #pragma once +#include "/EgtDev/Include/EGKPoint3d.h" #include #include @@ -20,9 +21,13 @@ // Definizione di Vert3f class Vert3f { public : + Vert3f( const Point3d& ptP) : x( (float)ptP.x), y( (float)ptP.y), z( (float)ptP.z) {} Vert3f( double dX, double dY, double dZ) : x( (float)dX), y( (float)dY), z( (float)dZ) {} Vert3f( void) : x( 0), y( 0), z( 0) {} - void Set( double dX, double dY, double dZ) { x = (float)dX ; y = (float)dY ; z = (float)dZ ;} + void Set( const Point3d& ptP) + { x = (float)ptP.x ; y = (float)ptP.y ; z = (float)ptP.z ; } + void Set( double dX, double dY, double dZ) + { x = (float)dX ; y = (float)dY ; z = (float)dZ ; } const Vert3f& operator =( const Vert3f& ptSrc) { if ( &ptSrc != this) { x = ptSrc.x , y = ptSrc.y , z = ptSrc.z ; } diff --git a/ObjEGrGraphics.h b/ObjEGrGraphics.h index d0db8da..1782fe8 100644 --- a/ObjEGrGraphics.h +++ b/ObjEGrGraphics.h @@ -19,6 +19,7 @@ class Scene ; class Color ; class PolyLine ; +class Triangle3d ; //---------------------------------------------------------------------------- class ObjEGrGraphics : public IObjGraphics @@ -31,8 +32,8 @@ class ObjEGrGraphics : public IObjGraphics virtual bool AddColor( const Color& colC) = 0 ; virtual bool AddPoint( const Point3d& ptP) = 0 ; virtual bool AddPolyLine( const PolyLine& PL) = 0 ; - virtual bool StartTriangles( void) = 0 ; - virtual bool AddTriangle( const Point3d& ptP0, const Point3d& ptP1, const Point3d& ptP2) = 0 ; + virtual bool StartTriangles( int nNum) = 0 ; + virtual bool AddTriangle( const Triangle3d& Tria) = 0 ; virtual bool EndTriangles( void) = 0 ; virtual bool Draw( int nStat, int nMark) = 0 ; } ; diff --git a/ObjNewGraphics.cpp b/ObjNewGraphics.cpp index 0e4cd68..1ebbfec 100644 --- a/ObjNewGraphics.cpp +++ b/ObjNewGraphics.cpp @@ -18,6 +18,7 @@ #include "GraphObjs.h" #include "/EgtDev/Include/EGkPolyLine.h" #include "/EgtDev/Include/EGkGdbConst.h" +#include "/EgtDev/Include/EGKTriangle3d.h" //--------------------------- Macro ------------------------------------------ @@ -36,6 +37,7 @@ void ObjNewGraphics::Reset( void) { m_bValid = false ; + m_nCurrMode = GL_NONE ; } //---------------------------------------------------------------------------- @@ -45,6 +47,7 @@ ObjNewGraphics::Clear( void) DeleteVaoVbo() ; m_ngaList.clear() ; m_bValid = false ; + m_nCurrMode = GL_NONE ; } //---------------------------------------------------------------------------- @@ -60,7 +63,6 @@ ObjNewGraphics::AddPoint( const Point3d& ptP) { if ( m_pScene == nullptr || ! m_pScene->MakeCurrent()) return false ; - // definisco i buffer per la scheda grafica e vi inserisco i nuovi vertici unsigned int nVaoId ; glGenVertexArrays( 1, &nVaoId) ; @@ -76,7 +78,7 @@ ObjNewGraphics::AddPoint( const Point3d& ptP) } glBindBuffer( GL_ARRAY_BUFFER, nVboId) ; glBufferData( GL_ARRAY_BUFFER, 1 * SIZEV3F, NULL, GL_STATIC_DRAW) ; - Vert3f v3V( ptP.x, ptP.y, ptP.z) ; + Vert3f v3V( ptP) ; glBufferSubData( GL_ARRAY_BUFFER, 0, SIZEV3F, &v3V) ; int nCount = 1 ; glVertexPointer( 3, GL_FLOAT, 0, ((void*)(0))) ; @@ -96,7 +98,6 @@ ObjNewGraphics::AddPolyLine( const PolyLine& PL) { if ( m_pScene == nullptr || ! m_pScene->MakeCurrent()) return false ; - // definisco i buffer per la scheda grafica e vi inserisco i nuovi vertici unsigned int nVaoId ; glGenVertexArrays( 1, &nVaoId) ; @@ -116,7 +117,7 @@ ObjNewGraphics::AddPolyLine( const PolyLine& PL) Vert3f v3V ; int nCount = 0 ; for ( bool bFound = PL.GetFirstPoint( ptP) ; bFound ; bFound = PL.GetNextPoint( ptP)) { - v3V.Set( ptP.x, ptP.y, ptP.z) ; + v3V.Set( ptP) ; glBufferSubData( GL_ARRAY_BUFFER, nCount * SIZEV3F, SIZEV3F, &v3V) ; ++ nCount ; } @@ -131,6 +132,80 @@ ObjNewGraphics::AddPolyLine( const PolyLine& PL) return true ; } +//---------------------------------------------------------------------------- +bool +ObjNewGraphics::StartTriangles( int nNum) +{ + if ( m_pScene == nullptr || ! m_pScene->MakeCurrent()) + return false ; + // modo corrente deve essere nullo + if ( m_nCurrMode != GL_NONE) + return false ; + // inizializzo emissione triangoli + unsigned int nVaoId ; + glGenVertexArrays( 1, &nVaoId) ; + if ( nVaoId == 0) + return false ; + glBindVertexArray( nVaoId) ; + unsigned int nVboId ; + glGenBuffers( 1, &nVboId) ; + if ( nVboId == 0) { + glBindVertexArray( 0) ; + glDeleteVertexArrays( 1, &nVaoId) ; + return false ; + } + glBindBuffer( GL_ARRAY_BUFFER, nVboId) ; + glBufferData( GL_ARRAY_BUFFER, 3 * nNum * SIZEV3F, NULL, GL_STATIC_DRAW) ; + // aggiungo i dati in lista + AddVerts( GL_TRIANGLES, 0, nVaoId, nVboId) ; + // dichiaro modo triangoli + m_nCurrMode = GL_TRIANGLES ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +ObjNewGraphics::AddTriangle( const Triangle3d& Tria) +{ + if ( m_pScene == nullptr || ! m_pScene->MakeCurrent()) + return false ; + // modo corrente deve essere triangoli + if ( m_nCurrMode != GL_TRIANGLES) + return false ; + // recupero il conteggio dei vertici + int nCount = m_ngaList.back().m_nCount ; + // emetto i vertici del triangolo + for ( int i = 0 ; i < 3 ; ++ i) { + Vert3f v3V( Tria.GetP( i)) ; + glBufferSubData( GL_ARRAY_BUFFER, nCount * SIZEV3F, SIZEV3F, &v3V) ; + ++ nCount ; + } + // aggiorno il conteggio + m_ngaList.back().m_nCount = nCount ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +ObjNewGraphics::EndTriangles( void) +{ + if ( m_pScene == nullptr || ! m_pScene->MakeCurrent()) + return false ; + // modo corrente deve essere triangoli + if ( m_nCurrMode != GL_TRIANGLES) + return false ; + // termino il modo triangoli + glVertexPointer( 3, GL_FLOAT, 0, ((void*)(0))) ; + glEnableClientState( GL_VERTEX_ARRAY) ; + glBindVertexArray( 0) ; + // dichiaro modalità standard + m_nCurrMode = GL_NONE ; + // dichiaro valida la grafica + m_bValid = true ; + + return true ; +} + //---------------------------------------------------------------------------- bool ObjNewGraphics::Draw( int nStat, int nMark) diff --git a/ObjNewGraphics.h b/ObjNewGraphics.h index 67fb092..7c6ab0a 100644 --- a/ObjNewGraphics.h +++ b/ObjNewGraphics.h @@ -69,12 +69,9 @@ class ObjNewGraphics : public ObjEGrGraphics virtual bool AddColor( const Color& colC) ; virtual bool AddPoint( const Point3d& ptP) ; virtual bool AddPolyLine( const PolyLine& PL) ; - virtual bool StartTriangles( void) - { return false ; } - virtual bool AddTriangle( const Point3d& ptP0, const Point3d& ptP1, const Point3d& ptP2) - { return false ; } - virtual bool EndTriangles( void) - { return false ; } + virtual bool StartTriangles( int nNum) ; + virtual bool AddTriangle( const Triangle3d& Tria) ; + virtual bool EndTriangles( void) ; virtual bool Draw( int nStat, int nMark) ; public : @@ -99,14 +96,10 @@ class ObjNewGraphics : public ObjEGrGraphics return AddNewGrAtom( nga) ; } private : - Scene* m_pScene ; // puntatore alla scena - bool m_bValid ; // flag + Scene* m_pScene ; // puntatore alla scena + bool m_bValid ; // flag + int m_nCurrMode ; // modo corrente NGALIST m_ngaList ; // lista di atomi per nuova grafica - - //int m_nMode ; // modo di utilizzo dei vertici - //int m_nCount ; // numero di vertici nel VBO - //unsigned int m_nVaoId ; // Id del VAO - //unsigned int m_nVboId ; // Id del VBO } ; //---------------------------------------------------------------------------- diff --git a/ObjOldGraphics.cpp b/ObjOldGraphics.cpp index cdd5be8..4d9ee4f 100644 --- a/ObjOldGraphics.cpp +++ b/ObjOldGraphics.cpp @@ -18,6 +18,7 @@ #include "/EgtDev/Include/EGkColor.h" #include "/EgtDev/Include/EGkPolyLine.h" #include "/EgtDev/Include/EGkGdbConst.h" +#include "/EgtDev/Include/EGKTriangle3d.h" //---------------------------------------------------------------------------- ObjOldGraphics::~ObjOldGraphics( void) @@ -30,6 +31,7 @@ void ObjOldGraphics::Reset( void) { m_bValid = false ; + m_nCurrMode = GL_NONE ; } //---------------------------------------------------------------------------- @@ -38,6 +40,7 @@ ObjOldGraphics::Clear( void) { m_ogaList.clear() ; m_bValid = false ; + m_nCurrMode = GL_NONE ; } //---------------------------------------------------------------------------- @@ -57,7 +60,7 @@ ObjOldGraphics::AddPoint( const Point3d& ptP) // start AddStart( GL_POINTS) ; // inserisco il nuovo vertice - AddVert3f( ptP.x, ptP.y, ptP.z) ; + AddVert3f( ptP) ; // fine AddEnd() ; // dichiaro valida la grafica @@ -78,7 +81,7 @@ ObjOldGraphics::AddPolyLine( const PolyLine& PL) // inserisco i nuovi vertici Point3d ptP ; for ( bool bFound = PL.GetFirstPoint( ptP) ; bFound ; bFound = PL.GetNextPoint( ptP)) - AddVert3f( ptP.x, ptP.y, ptP.z) ; + AddVert3f( ptP) ; // fine AddEnd() ; // dichiaro valida la grafica @@ -89,7 +92,7 @@ ObjOldGraphics::AddPolyLine( const PolyLine& PL) //---------------------------------------------------------------------------- bool -ObjOldGraphics::StartTriangles( void) +ObjOldGraphics::StartTriangles( int nNum) { // modo corrente deve essere nullo if ( m_nCurrMode != GL_NONE) @@ -102,15 +105,15 @@ ObjOldGraphics::StartTriangles( void) //---------------------------------------------------------------------------- bool -ObjOldGraphics::AddTriangle( const Point3d& ptP0, const Point3d& ptP1, const Point3d& ptP2) +ObjOldGraphics::AddTriangle( const Triangle3d& Tria) { // modo corrente deve essere triangoli if ( m_nCurrMode != GL_TRIANGLES) return false ; // emetto i vertici del triangolo - AddVert3f( ptP0.x, ptP0.y, ptP0.z) ; - AddVert3f( ptP1.x, ptP1.y, ptP1.z) ; - AddVert3f( ptP2.x, ptP2.y, ptP2.z) ; + AddVert3f( Tria.GetP( 0)) ; + AddVert3f( Tria.GetP( 1)) ; + AddVert3f( Tria.GetP( 2)) ; return true ; } diff --git a/ObjOldGraphics.h b/ObjOldGraphics.h index 4cf01ed..0e7187c 100644 --- a/ObjOldGraphics.h +++ b/ObjOldGraphics.h @@ -15,6 +15,7 @@ #include "ObjEGrGraphics.h" #include "OpenGL.h" +#include "/EgtDev/Include/EGkPoint3d.h" #include class Color ; @@ -71,8 +72,8 @@ class ObjOldGraphics : public ObjEGrGraphics virtual bool AddColor( const Color& colC) ; virtual bool AddPoint( const Point3d& ptP) ; virtual bool AddPolyLine( const PolyLine& PL) ; - virtual bool StartTriangles( void) ; - virtual bool AddTriangle( const Point3d& ptP0, const Point3d& ptP1, const Point3d& ptP2) ; + virtual bool StartTriangles( int nNum) ; + virtual bool AddTriangle( const Triangle3d& Tria) ; virtual bool EndTriangles( void) ; virtual bool Draw( int nStat, int nMark) ; @@ -89,10 +90,10 @@ class ObjOldGraphics : public ObjEGrGraphics oga.m_nType = OldGrAtom::START ; oga.m_nMode = nMode ; return AddOldGrAtom( oga) ; } - bool AddVert3f( double dX, double dY, double dZ) + bool AddVert3f( const Point3d& ptP) { OldGrAtom oga ; oga.m_nType = OldGrAtom::VERT ; - oga.m_fX = float( dX) ; oga.m_fY = float( dY) ; oga.m_fZ = float( dZ) ; + oga.m_fX = float( ptP.x) ; oga.m_fY = float( ptP.y) ; oga.m_fZ = float( ptP.z) ; return AddOldGrAtom( oga) ; } bool AddColor( float fRed, float fGreen, float fBlue, float fAlpha = 1) { OldGrAtom oga ; @@ -105,9 +106,9 @@ class ObjOldGraphics : public ObjEGrGraphics return AddOldGrAtom( oga) ; } private : - Scene* m_pScene ; // puntatore alla scena - bool m_bValid ; // flag - int m_nCurrMode ; // modo corrente + Scene* m_pScene ; // puntatore alla scena + bool m_bValid ; // flag + int m_nCurrMode ; // modo corrente OGALIST m_ogaList ; // lista di atomi per vecchia grafica } ; diff --git a/SceneGeom.cpp b/SceneGeom.cpp index 29cccc2..c5775d9 100644 --- a/SceneGeom.cpp +++ b/SceneGeom.cpp @@ -260,13 +260,13 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nObjStat, int nObjMark) // impostazioni iniziali pGraphics->Clear() ; pGraphics->AddColor( cCol) ; - pGraphics->StartTriangles() ; + pGraphics->StartTriangles( pSTM->GetTriangleNum()) ; // ciclo sui triangoli della superficie - Point3d ptP0, ptP1, ptP2 ; - int nId = pSTM->GetFirstTriangle( ptP0, ptP1, ptP2) ; + Triangle3d Tria ; + int nId = pSTM->GetFirstTriangle( Tria) ; while ( nId != -1) { - pGraphics->AddTriangle( ptP0, ptP1, ptP2) ; - nId = pSTM->GetNextTriangle( nId, ptP0, ptP1, ptP2) ; + pGraphics->AddTriangle( Tria) ; + nId = pSTM->GetNextTriangle( nId, Tria) ; } pGraphics->EndTriangles() ; }