EgtGraphics 1.8h2 :
- aggiunte a Scene SetTextureMaxLinPixels e GetTextureImagePixels - aggiunte a TextureMgr SetTextureMaxLinPixels e GetImagePixels.
This commit is contained in:
+37
-2
@@ -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)) ;
|
||||
|
||||
Reference in New Issue
Block a user