Added cImage::ChannelsToPixelFormat.

Fixed cTexture::Update ( it wasn't taking care of the pixel format ).
Fixed cTTFFont memory leak ( it wasn't assigning the correct image size ).
Untracked some new and delete operations that doesn't need to be tracked.
This commit is contained in:
Martín Lucas Golini
2013-08-20 16:47:27 -03:00
parent 90222e6445
commit 8b6e34cb1f
10 changed files with 34 additions and 26 deletions

View File

@@ -48,6 +48,19 @@ EE_SAVE_TYPE cImage::ExtensionToSaveType( const std::string& Extension ) {
return saveType;
}
EE_PIXEL_FORMAT cImage::ChannelsToPixelFormat( const Uint32& channels ) {
EE_PIXEL_FORMAT pf = PF_RGBA;;
if ( 3 == channels )
pf = PF_RGB;
else if ( 2 == channels )
pf = PF_RG;
else if ( 1 == channels )
pf = PF_RED;
return pf;
}
bool cImage::GetInfo( const std::string& path, int * width, int * height, int * channels ) {
bool res = stbi_info( path.c_str(), width, height, channels ) != 0;

View File

@@ -353,25 +353,16 @@ void cTexture::Update( const Uint8* pixels, Uint32 width, Uint32 height, Uint32
if ( NULL != pixels && mTexture && x + width <= mWidth && y + height <= mHeight ) {
cTextureSaver saver( mTexture );
glTexSubImage2D( GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels );
glTexSubImage2D( GL_TEXTURE_2D, 0, x, y, width, height, (GLenum)pf, GL_UNSIGNED_BYTE, pixels );
}
}
void cTexture::Update( const Uint8* pixels ) {
Update( pixels, mWidth, mHeight );
Update( pixels, mWidth, mHeight, 0, 0, ChannelsToPixelFormat( mChannels ) );
}
void cTexture::Update( cImage *image, Uint32 x, Uint32 y ) {
EE_PIXEL_FORMAT pf = PF_RGBA;;
if ( 3 == image->Channels() )
pf = PF_RGB;
else if ( 2 == image->Channels() )
pf = PF_RG;
else if ( 1 == image->Channels() )
pf = PF_RED;
Update( image->GetPixelsPtr(), image->Width(), image->Height(), x, y, pf );
Update( image->GetPixelsPtr(), image->Width(), image->Height(), x, y, ChannelsToPixelFormat( image->Channels() ) );
}
const Uint32& cTexture::HashName() const {

View File

@@ -47,7 +47,7 @@ bool cTTFFont::LoadFromMemory( Uint8* TTFData, const eeUint& TTFDataSize, const
mFont = hkFontManager::instance()->OpenFromMemory( reinterpret_cast<Uint8*>(&TTFData[0]), TTFDataSize, Size, 0, NumCharsToGen );
if ( OutlineSize ) {
if ( OutlineSize && OutlineFreetype == DefaultOutlineMethod ) {
mFontOutline = hkFontManager::instance()->OpenFromMemory( reinterpret_cast<Uint8*>(&TTFData[0]), TTFDataSize, Size, 0, NumCharsToGen );
mFontOutline->Outline( OutlineSize );
}
@@ -63,7 +63,7 @@ bool cTTFFont::Load( const std::string& Filepath, const eeUint& Size, EE_TTF_FON
mFont = hkFontManager::instance()->OpenFromFile( Filepath.c_str(), Size, 0, NumCharsToGen );
if ( OutlineSize ) {
if ( OutlineSize && OutlineFreetype == DefaultOutlineMethod ) {
mFontOutline = hkFontManager::instance()->OpenFromFile( Filepath.c_str(), Size, 0, NumCharsToGen );
mFontOutline->Outline( OutlineSize );
}
@@ -130,7 +130,7 @@ bool cTTFFont::iLoad( const eeUint& Size, EE_TTF_FONT_STYLE Style, const Uint16&
// Find the best size for the texture ( aprox )
// Totally wild guessing, but it's working
Int32 tWildGuessW = ( mAscent + PixelSep );
Int32 tWildGuessW = ( mAscent + PixelSep + OutlineSize );
Int32 tWildGuessH = tWildGuessW;
ReqSize = mNumChars * tWildGuessW * tWildGuessH;
@@ -156,6 +156,7 @@ bool cTTFFont::iLoad( const eeUint& Size, EE_TTF_FONT_STYLE Style, const Uint16&
Uint32 * TexGlyph;
Uint32 w = (Uint32)mTexWidth;
//Uint32 h = (Uint32)mTexHeight;
eeColorA fFontColor( FontColor );
//Loop through all chars

View File

@@ -30,9 +30,9 @@ hkFont::hkFont( hkFontManager * FontManager, unsigned int CacheSize ) :
hkFont::~hkFont() {
CacheFlush();
if ( NULL != Face() ) {
FT_Done_Face( Face() );
Face( NULL );
if ( NULL != mFace ) {
FT_Done_Face( mFace );
mFace = NULL;
}
hkSAFE_DELETE_ARRAY( mCache );

View File

@@ -4,13 +4,13 @@
namespace EE { namespace System {
cClock::cClock() :
mClockImpl( eeNew( Platform::cClockImpl, () ) )
mClockImpl( new Platform::cClockImpl() )
{
Restart();
}
cClock::~cClock() {
eeSAFE_DELETE( mClockImpl );
delete mClockImpl;
}
void cClock::Restart() {

View File

@@ -9,12 +9,12 @@ const bool cCondition::AutoUnlock = true;
const bool cCondition::ManualUnlock = false;
cCondition::cCondition( int value ) :
mCondImpl( eeNew( cConditionImpl, ( value ) ) )
mCondImpl( new cConditionImpl( value ) )
{
}
cCondition::~cCondition() {
eeSAFE_DELETE( mCondImpl );
delete mCondImpl;
}
void cCondition::Lock() {

View File

@@ -4,12 +4,12 @@
namespace EE { namespace System {
cMutex::cMutex() :
mMutexImpl( eeNew( Platform::cMutexImpl, () ) )
mMutexImpl( new Platform::cMutexImpl() )
{
}
cMutex::~cMutex() {
eeSAFE_DELETE( mMutexImpl );
delete mMutexImpl;
}
void cMutex::Lock() {

View File

@@ -94,7 +94,7 @@ EE_MAIN_FUNC int main (int argc, char * argv [])
// Draw the text on screen
TTF->Draw( win->GetWidth() * 0.5f - TTF->GetTextWidth() * 0.5f, YPos );
TTFO->Draw( win->GetWidth() * 0.5f - TTF->GetTextWidth() * 0.5f, ( YPos += TTF->GetTextHeight() + 24 ) );
TTFO->Draw( win->GetWidth() * 0.5f - TTFO->GetTextWidth() * 0.5f, ( YPos += TTF->GetTextHeight() + 24 ) );
TTF2->Draw( win->GetWidth() * 0.5f - TTF2->GetTextWidth() * 0.5f, ( YPos += TTF->GetTextHeight() + 24 ) );