From 076c74488fd0e642fb104f86ea65e3c91bc18b6b Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Fri, 23 Aug 2024 19:00:57 +0200 Subject: [PATCH] EgtGraphics : - migliorata gestione oggetti senza visualizzazione - migliorata gestione errori di visualizzazione. --- ObjEGrGraphics.h | 1 + ObjMultiGraphics.cpp | 16 ++++++++++++++-- ObjMultiGraphics.h | 1 + ObjNewGraphics.cpp | 9 +++++++++ ObjNewGraphics.h | 1 + ObjOldGraphics.cpp | 9 +++++++++ ObjOldGraphics.h | 1 + SceneGeom.cpp | 22 ++++++++++++---------- 8 files changed, 48 insertions(+), 12 deletions(-) diff --git a/ObjEGrGraphics.h b/ObjEGrGraphics.h index 894b290..d3b555d 100644 --- a/ObjEGrGraphics.h +++ b/ObjEGrGraphics.h @@ -33,6 +33,7 @@ class ObjEGrGraphics : public IObjGraphics virtual Scene* GetScene( void) = 0 ; virtual bool SetCurrent( int nCurr) { return false ; } virtual void Clear( void) = 0 ; + virtual bool Validate( void) = 0 ; virtual bool AddColor( const Color& colC) = 0 ; virtual bool AddMaterial( const Color& colAmb, const Color& colDiff, const Color& colSpec, float fShin) = 0 ; diff --git a/ObjMultiGraphics.cpp b/ObjMultiGraphics.cpp index 60e1059..f85c7ab 100644 --- a/ObjMultiGraphics.cpp +++ b/ObjMultiGraphics.cpp @@ -51,8 +51,8 @@ void ObjMultiGraphics::SetScene( Scene* pScene) { m_pScene = pScene ; - for ( size_t i = 0 ; i < m_vOEGR.size() ; ++ i) - m_vOEGR[i]->SetScene( pScene) ; + for ( auto& pOEGR : m_vOEGR) + pOEGR->SetScene( pScene) ; } //---------------------------------------------------------------------------- @@ -77,6 +77,18 @@ ObjMultiGraphics::Clear( void) m_vOEGR[m_nCurr]->Clear() ; } +//---------------------------------------------------------------------------- +bool +ObjMultiGraphics::Validate( void) +{ + if ( ! m_bValid) { + if ( m_nCurr < 0 || m_nCurr >= int( m_vOEGR.size())) + return false ; + m_bValid = m_vOEGR[m_nCurr]->Validate() ; + } + return m_bValid ; +} + //---------------------------------------------------------------------------- bool ObjMultiGraphics::AddColor( const Color& colC) diff --git a/ObjMultiGraphics.h b/ObjMultiGraphics.h index a5e68b1..dd61214 100644 --- a/ObjMultiGraphics.h +++ b/ObjMultiGraphics.h @@ -32,6 +32,7 @@ class ObjMultiGraphics : public ObjEGrGraphics { return m_pScene ; } bool SetCurrent( int nCurr) override ; void Clear( void) override ; + bool Validate( void) override ; bool AddColor( const Color& colC) override ; bool AddMaterial( const Color& colAmb, const Color& colDiff, const Color& colSpec, float fShin) override ; diff --git a/ObjNewGraphics.cpp b/ObjNewGraphics.cpp index f150b92..5832bbf 100644 --- a/ObjNewGraphics.cpp +++ b/ObjNewGraphics.cpp @@ -52,6 +52,15 @@ ObjNewGraphics::Clear( void) m_nCurrMode = GL_NONE ; } +//---------------------------------------------------------------------------- +bool +ObjNewGraphics::Validate( void) +{ + if ( ! m_bValid) + m_bValid = m_ngaVect.empty() ; + return m_bValid ; +} + //---------------------------------------------------------------------------- bool ObjNewGraphics::AddColor( const Color& colC) diff --git a/ObjNewGraphics.h b/ObjNewGraphics.h index 56800f0..e3e6221 100644 --- a/ObjNewGraphics.h +++ b/ObjNewGraphics.h @@ -70,6 +70,7 @@ class ObjNewGraphics : public ObjEGrGraphics Scene* GetScene( void) override { return m_pScene ; } void Clear( void) override ; + bool Validate( void) override ; bool AddColor( const Color& colC) override ; bool AddMaterial( const Color& colAmb, const Color& colDiff, const Color& colSpec, float fShin) override ; diff --git a/ObjOldGraphics.cpp b/ObjOldGraphics.cpp index 7ea4c5e..799133c 100644 --- a/ObjOldGraphics.cpp +++ b/ObjOldGraphics.cpp @@ -48,6 +48,15 @@ ObjOldGraphics::Clear( void) m_nCurrMode = GL_NONE ; } +//---------------------------------------------------------------------------- +bool +ObjOldGraphics::Validate( void) +{ + if ( ! m_bValid) + m_bValid = m_ogaVect.empty() ; + return m_bValid ; +} + //---------------------------------------------------------------------------- bool ObjOldGraphics::AddColor( const Color& colC) diff --git a/ObjOldGraphics.h b/ObjOldGraphics.h index c799ba4..aa05447 100644 --- a/ObjOldGraphics.h +++ b/ObjOldGraphics.h @@ -75,6 +75,7 @@ class ObjOldGraphics : public ObjEGrGraphics Scene* GetScene( void) override { return m_pScene ; } void Clear( void) override ; + bool Validate( void) override ; bool AddColor( const Color& colC) override ; bool AddMaterial( const Color& colAmb, const Color& colDiff, const Color& colSpec, float fShin) override ; diff --git a/SceneGeom.cpp b/SceneGeom.cpp index 5d09eff..9503bc4 100644 --- a/SceneGeom.cpp +++ b/SceneGeom.cpp @@ -384,13 +384,12 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj) // superficie con visualizzazione standard bool bTwoColors = ( pSTM->GetMaxTFlag() > 0) ; if ( ! bTwoColors) { - // Imposto indice blocco corrente - if ( pGraphics->SetCurrent( 0)) - pGraphics->Clear() ; // recupero il materiale Material mMat ; if ( ! iIter.GetCalcMaterial( mMat)) mMat.Set( m_colDef) ; + // Imposto indice blocco corrente + pGraphics->SetCurrent( 0) ; // pulisco pGraphics->Clear() ; // se ci sono triangoli @@ -416,6 +415,8 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj) } pGraphics->EndTriangles() ; } + else + pGraphics->Validate() ; } // altrimenti superficie con due colori else { @@ -448,8 +449,10 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj) if ( pGraphics->SetCurrent( j)) pGraphics->Clear() ; // se non ci sono triangoli, passo oltre - if ( nTri[j] == 0) + if ( nTri[j] == 0) { + pGraphics->Validate() ; continue ; + } // assegno materiali pGraphics->AddColor( cCol[j]) ; // per wireframe pGraphics->AddMaterial( mMat[j].GetAmbient(), mMat[j].GetDiffuse(), @@ -830,6 +833,7 @@ Scene::DrawAlphaSurfVector( void) []( const AlphaSurf& a, const AlphaSurf&b) { return a.dZmax < b.dZmax ; }) ; // eseguo visualizzazione + bool bOk = true ; for ( const auto& AlphaSurf : m_vAlphaSurf) { // imposto matrice MODELVIEW double Matrix[OGLMAT_DIM] ; @@ -837,15 +841,13 @@ Scene::DrawAlphaSurfVector( void) glPushMatrix() ; glLoadMatrixd( Matrix) ; // eseguo visualizzazione - bool bOk = AlphaSurf.pGraph->Draw( AlphaSurf.nStat, AlphaSurf.nMark, true, - AlphaSurf.bSurf, AlphaSurf.nAlpha, AlphaSurf.bShowAux) ; + if ( ! AlphaSurf.pGraph->Draw( AlphaSurf.nStat, AlphaSurf.nMark, true, + AlphaSurf.bSurf, AlphaSurf.nAlpha, AlphaSurf.bShowAux)) + bOk = false ; // ripristino matrice glPopMatrix() ; - // in caso di errore, esco - if ( ! bOk) - return false ; } - return true ; + return bOk ; } //----------------------------------------------------------------------------