From 8b6e34cb1fde7989f1f5b97a6cf06b3f8a41d159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Tue, 20 Aug 2013 16:47:27 -0300 Subject: [PATCH] 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. --- include/eepp/graphics/cimage.hpp | 3 +++ projects/linux/ee.creator.user | 2 +- src/eepp/graphics/cimage.cpp | 13 +++++++++++++ src/eepp/graphics/ctexture.cpp | 15 +++------------ src/eepp/graphics/cttffont.cpp | 7 ++++--- src/eepp/helper/haikuttf/hkfont.cpp | 6 +++--- src/eepp/system/cclock.cpp | 4 ++-- src/eepp/system/ccondition.cpp | 4 ++-- src/eepp/system/cmutex.cpp | 4 ++-- src/examples/fonts/fonts.cpp | 2 +- 10 files changed, 34 insertions(+), 26 deletions(-) diff --git a/include/eepp/graphics/cimage.hpp b/include/eepp/graphics/cimage.hpp index aaa9058bc..99f9966f9 100644 --- a/include/eepp/graphics/cimage.hpp +++ b/include/eepp/graphics/cimage.hpp @@ -32,6 +32,9 @@ class EE_API cImage { /** @return The save type from a given extension ( example: "png" => SAVE_TYPE_PNG ) */ static EE_SAVE_TYPE ExtensionToSaveType( const std::string& Extension ); + /** @return Convert the number of channels to a pixel format */ + static EE_PIXEL_FORMAT ChannelsToPixelFormat( const Uint32& channels ); + /** @return True if success to get the info. * @param path the image path * @param width the var to store the image width diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 8a3ad2f74..28f3086b4 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/src/eepp/graphics/cimage.cpp b/src/eepp/graphics/cimage.cpp index a13e352fc..cd03e799d 100644 --- a/src/eepp/graphics/cimage.cpp +++ b/src/eepp/graphics/cimage.cpp @@ -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; diff --git a/src/eepp/graphics/ctexture.cpp b/src/eepp/graphics/ctexture.cpp index 1ae349415..9e2f6ae54 100755 --- a/src/eepp/graphics/ctexture.cpp +++ b/src/eepp/graphics/ctexture.cpp @@ -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 { diff --git a/src/eepp/graphics/cttffont.cpp b/src/eepp/graphics/cttffont.cpp index b72ac3eec..cebaef84d 100755 --- a/src/eepp/graphics/cttffont.cpp +++ b/src/eepp/graphics/cttffont.cpp @@ -47,7 +47,7 @@ bool cTTFFont::LoadFromMemory( Uint8* TTFData, const eeUint& TTFDataSize, const mFont = hkFontManager::instance()->OpenFromMemory( reinterpret_cast(&TTFData[0]), TTFDataSize, Size, 0, NumCharsToGen ); - if ( OutlineSize ) { + if ( OutlineSize && OutlineFreetype == DefaultOutlineMethod ) { mFontOutline = hkFontManager::instance()->OpenFromMemory( reinterpret_cast(&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 diff --git a/src/eepp/helper/haikuttf/hkfont.cpp b/src/eepp/helper/haikuttf/hkfont.cpp index 0d34adc0e..0b8d59c88 100644 --- a/src/eepp/helper/haikuttf/hkfont.cpp +++ b/src/eepp/helper/haikuttf/hkfont.cpp @@ -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 ); diff --git a/src/eepp/system/cclock.cpp b/src/eepp/system/cclock.cpp index d16fcb2de..e58e85f21 100755 --- a/src/eepp/system/cclock.cpp +++ b/src/eepp/system/cclock.cpp @@ -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() { diff --git a/src/eepp/system/ccondition.cpp b/src/eepp/system/ccondition.cpp index e57fd0848..cf5382cd0 100644 --- a/src/eepp/system/ccondition.cpp +++ b/src/eepp/system/ccondition.cpp @@ -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() { diff --git a/src/eepp/system/cmutex.cpp b/src/eepp/system/cmutex.cpp index 251376acf..09acf5b71 100755 --- a/src/eepp/system/cmutex.cpp +++ b/src/eepp/system/cmutex.cpp @@ -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() { diff --git a/src/examples/fonts/fonts.cpp b/src/examples/fonts/fonts.cpp index c00da0fc5..cac244e1c 100644 --- a/src/examples/fonts/fonts.cpp +++ b/src/examples/fonts/fonts.cpp @@ -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 ) );