EgtGraphics 1.8l1 :
- velocizzato caricamento texture, specie se jpeg.
This commit is contained in:
+15
-10
@@ -15,9 +15,9 @@
|
||||
#include "stdafx.h"
|
||||
#include "Scene.h"
|
||||
#include "TextureMgr.h"
|
||||
#include "\EgtDev\Include\EGnStringUtils.h"
|
||||
#include "\EgtDev\Include\EgtStringConverter.h"
|
||||
#include "\EgtDev\Extern\FreeImage\Include\FreeImage.h"
|
||||
#include "/EgtDev/Include/EGnStringUtils.h"
|
||||
#include "/EgtDev/Include/EgtStringConverter.h"
|
||||
#include "/EgtDev/Extern/FreeImage/Include/FreeImage.h"
|
||||
|
||||
using namespace std ;
|
||||
|
||||
@@ -82,11 +82,11 @@ TextureMgr::LoadTexture( const string& sName, const string& sFile,
|
||||
if ( ! ReadImage( sFile, pDib))
|
||||
return false ;
|
||||
|
||||
// se necessario, converto l'immagine a 32 bit per pixel (BGRA)
|
||||
// se necessario, converto l'immagine a 24 bit per pixel (BGR)
|
||||
int bitsPerPixel = FreeImage_GetBPP( pDib) ;
|
||||
if ( bitsPerPixel != 32) {
|
||||
if ( bitsPerPixel != 24) {
|
||||
FIBITMAP* pTmpDib = pDib ;
|
||||
pDib = FreeImage_ConvertTo32Bits( pTmpDib) ;
|
||||
pDib = FreeImage_ConvertTo24Bits( pTmpDib) ;
|
||||
FreeImage_Unload( pTmpDib) ;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ TextureMgr::LoadTexture( const string& sName, const string& sFile,
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) ;
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) ;
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, nWidth, nHeight,
|
||||
0, GL_BGRA, GL_UNSIGNED_BYTE, FreeImage_GetBits( pDib)) ;
|
||||
0, GL_BGR, GL_UNSIGNED_BYTE, FreeImage_GetBits( pDib)) ;
|
||||
// libero l'immagine originaria
|
||||
FreeImage_Unload( pDib) ;
|
||||
|
||||
@@ -347,11 +347,16 @@ TextureMgr::ReadImage( const string& sFile, FIBITMAP*& pDib)
|
||||
// se non determinata, esco con errore
|
||||
if ( nFif == FIF_UNKNOWN)
|
||||
return false ;
|
||||
|
||||
// se formato Jpeg, impostazione flag per eventuale scalatura immagine già in lettura
|
||||
int nFlag = 0 ;
|
||||
if ( nFif == FIF_JPEG)
|
||||
nFlag = ( m_nMaxLinPix / 2) << 16 ;
|
||||
|
||||
// carico l'immagine
|
||||
pDib = nullptr ;
|
||||
if ( FreeImage_FIFSupportsReading( nFif))
|
||||
pDib = FreeImage_LoadU( nFif, stringtoW( sFile)) ;
|
||||
pDib = FreeImage_LoadU( nFif, stringtoW( sFile), nFlag) ;
|
||||
if ( pDib == nullptr)
|
||||
return false ;
|
||||
|
||||
@@ -380,7 +385,7 @@ TextureMgr::TestImageWithOpenGL( FIBITMAP*& pDib)
|
||||
int nNewW = int( nWidth / dCoeff) ;
|
||||
int nNewH = int( nHeight / dCoeff) ;
|
||||
FIBITMAP* pTmpDib = pDib ;
|
||||
pDib = FreeImage_Rescale( pTmpDib, nNewW, nNewH, FILTER_BILINEAR) ;
|
||||
pDib = FreeImage_Rescale( pTmpDib, nNewW, nNewH, FILTER_BOX) ;
|
||||
FreeImage_Unload( pTmpDib) ;
|
||||
nWidth = nNewW ;
|
||||
nHeight = nNewH ;
|
||||
@@ -397,7 +402,7 @@ TextureMgr::TestImageWithOpenGL( FIBITMAP*& pDib)
|
||||
|
||||
// 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)) ;
|
||||
0, GL_BGR, GL_UNSIGNED_BYTE, FreeImage_GetBits( pDib)) ;
|
||||
int nW ;
|
||||
glGetTexLevelParameteriv( GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &nW) ;
|
||||
if ( nW == 0) {
|
||||
|
||||
Reference in New Issue
Block a user