diff --git a/EgtGraphics.rc b/EgtGraphics.rc index 6e51cab..87e7ef6 100644 Binary files a/EgtGraphics.rc and b/EgtGraphics.rc differ diff --git a/Scene.h b/Scene.h index a0a16fe..05156db 100644 --- a/Scene.h +++ b/Scene.h @@ -170,12 +170,14 @@ class Scene : public IEGrScene return true ; } bool GetPlaneSnapPoint( const Point3d& ptWin, const Plane3d& plPlane, Point3d& ptSel) const override ; // Texture + bool SetTextureMaxLinPixels( int nMaxLinPix) override ; bool LoadTexture( const std::string& sName, const std::string& sFile, double dMMxPix, double dDimX, double dDimY, int nRepeat) override ; bool UnloadTexture( const std::string& sName) override ; bool UnloadAllTextures( void) override ; bool ExistsTexture( const std::string& sName) const override ; bool GetTexturePixels( const std::string& sName, int& nWidth, int& nHeight) const override ; + bool GetTextureImagePixels( const std::string& sName, int& nWidth, int& nHeight) const override ; bool GetTextureDimensions( const std::string& sName, double& dDimX, double& dDimY) const override ; bool ChangeTextureDimensions( const std::string& sName, double dDimX, double dDimY) override ; // Image diff --git a/SceneTexture.cpp b/SceneTexture.cpp index b6751bb..78108f7 100644 --- a/SceneTexture.cpp +++ b/SceneTexture.cpp @@ -17,6 +17,14 @@ using namespace std ; + +//---------------------------------------------------------------------------- +bool +Scene::SetTextureMaxLinPixels( int nMaxLinPix) +{ + return m_TextMgr.SetTextureMaxLinPixels( nMaxLinPix) ; +} + //---------------------------------------------------------------------------- bool Scene::LoadTexture( const string& sName, const string& sFile, @@ -53,6 +61,13 @@ Scene::GetTexturePixels( const string& sName, int& nWidth, int& nHeight) const return m_TextMgr.GetPixels( sName, nWidth, nHeight) ; } +//---------------------------------------------------------------------------- +bool +Scene::GetTextureImagePixels( const string& sName, int& nWidth, int& nHeight) const +{ + return m_TextMgr.GetImagePixels( sName, nWidth, nHeight) ; +} + //---------------------------------------------------------------------------- bool Scene::GetTextureDimensions( const string& sName, double& dDimX, double& dDimY) const diff --git a/TextureMgr.cpp b/TextureMgr.cpp index c22149a..cdb1e5e 100644 --- a/TextureMgr.cpp +++ b/TextureMgr.cpp @@ -25,6 +25,7 @@ using namespace std ; TextureMgr::TextureMgr( void) { m_pScene = nullptr ; + m_nMaxLinPix = 16384 ; } //---------------------------------------------------------------------------- @@ -50,6 +51,14 @@ TextureMgr::Clear( void) return true ; } +//---------------------------------------------------------------------------- +bool +TextureMgr::SetTextureMaxLinPixels( int nMaxLinPix) +{ + m_nMaxLinPix = max( nMaxLinPix, 128) ; + return true ; +} + //---------------------------------------------------------------------------- bool TextureMgr::LoadTexture( const string& sName, const string& sFile, @@ -137,7 +146,7 @@ TextureMgr::LoadTexture( const string& sName, const string& sFile, } // salvo i dati - TextureData textData( sFile, dDimX, dDimY, nWidth, nHeight, nTexName, nRepeat) ; + TextureData textData( sFile, dDimX, dDimY, nWidth, nHeight, nOriWidth, nOriHeight, nTexName, nRepeat) ; m_umTextData.emplace( sName, textData) ; return true ; @@ -222,7 +231,7 @@ TextureMgr::LoadCalcTexture( const string& sName, } // salvo i dati - TextureData textData( "", dDimX, dDimY, IMG_WIDTH, IMG_HEIGHT, nTexName, nRepeat) ; + TextureData textData( "", dDimX, dDimY, IMG_WIDTH, IMG_HEIGHT, 0, 0, nTexName, nRepeat) ; m_umTextData.emplace( sName, textData) ; return true ; @@ -270,6 +279,20 @@ TextureMgr::GetPixels( const string& sName, int& nWidth, int& nHeight) const return true ; } +//---------------------------------------------------------------------------- +bool +TextureMgr::GetImagePixels( const string& sName, int& nWidth, int& nHeight) const +{ + // ricerca della texture di nome dato + auto iIter = m_umTextData.find( sName) ; + if ( iIter == m_umTextData.end()) + return false ; + // restituisco le dimensioni in pixel dell'immagine da cui è stata derivata la texture + nWidth = iIter->second.nImgWidth ; + nHeight = iIter->second.nImgHeight ; + return true ; +} + //---------------------------------------------------------------------------- bool TextureMgr::GetDimensions( const string& sName, double& dDimX, double& dDimY) const @@ -351,6 +374,18 @@ TextureMgr::TestImageWithOpenGL( FIBITMAP*& pDib) int nWidth = FreeImage_GetWidth( pDib) ; int nHeight = FreeImage_GetHeight( pDib) ; + // verifico di non superare la massima dimensione ammessa + if ( nWidth > m_nMaxLinPix || nHeight > m_nMaxLinPix) { + double dCoeff = max( nWidth / double( m_nMaxLinPix), nHeight / double( m_nMaxLinPix)) ; + int nNewW = int( nWidth / dCoeff) ; + int nNewH = int( nHeight / dCoeff) ; + FIBITMAP* pTmpDib = pDib ; + pDib = FreeImage_Rescale( pTmpDib, nNewW, nNewH, FILTER_BILINEAR) ; + FreeImage_Unload( pTmpDib) ; + nWidth = nNewW ; + nHeight = nNewH ; + } + // verifico sia caricabile da OpenGL corrente glTexImage2D( GL_PROXY_TEXTURE_2D, 0, GL_RGBA, nWidth, nHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, FreeImage_GetBits( pDib)) ; diff --git a/TextureMgr.h b/TextureMgr.h index fdc95dd..48cfbd2 100644 --- a/TextureMgr.h +++ b/TextureMgr.h @@ -25,13 +25,15 @@ struct TextureData { double dDimY ; int nWidth ; int nHeight ; + int nImgWidth ; + int nImgHeight ; unsigned int nTexId ; int nRepeat ; TextureData( void) - : dDimX( 0), dDimY( 0), nWidth( 0), nHeight( 0), nTexId( 0), nRepeat( 0) {} - TextureData( std::string sF, double dX, double dY, int nW, int nH, unsigned int nT, int nR) - : sFile( sF), dDimX( dX), dDimY( dY), nWidth( nW), nHeight( nH), nTexId( nT), nRepeat( nR) {} + : dDimX( 0), dDimY( 0), nWidth( 0), nHeight( 0), nImgWidth( 0), nImgHeight( 0), nTexId( 0), nRepeat( 0) {} + TextureData( std::string sF, double dX, double dY, int nW, int nH, int nImgW, int nImgH, unsigned int nT, int nR) + : sFile( sF), dDimX( dX), dDimY( dY), nWidth( nW), nHeight( nH), nImgWidth( nImgW), nImgHeight( nImgH), nTexId( nT), nRepeat( nR) {} } ; typedef std::unordered_map STRTEXTD_UMAP ; @@ -48,10 +50,12 @@ class TextureMgr void SetScene( Scene* pScene) { m_pScene = pScene ; } bool Clear( void) ; + bool SetTextureMaxLinPixels( int nMaxLinPix) ; bool LoadTexture( const std::string& sName, const std::string& sPath, double dMMxPix, double dDimX, double dDimY, int nRepeat) ; bool Exists( const std::string& sName) const ; bool GetPixels( const std::string& sName, int& nWidth, int& nHeight) const ; + bool GetImagePixels( const std::string& sName, int& nWidth, int& nHeight) const ; bool GetDimensions( const std::string& sName, double& dDimX, double& dDimY) const ; bool ChangeDimensions( const std::string& sName, double dDimX, double dDimY) ; bool UnloadTexture( const std::string& sName) ; @@ -65,5 +69,6 @@ class TextureMgr private : Scene* m_pScene ; // puntatore alla scena + int m_nMaxLinPix ; // massima dimensione lineare in pixel STRTEXTD_UMAP m_umTextData ; // dati delle textures } ; \ No newline at end of file