mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-06-04 20:46:29 +03:00
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:
@@ -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;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 ) );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user