diff --git a/ee.linux.cbp b/ee.linux.cbp
index 5f848ca7c..fc92d6197 100644
--- a/ee.linux.cbp
+++ b/ee.linux.cbp
@@ -108,6 +108,8 @@
+
+
@@ -146,6 +148,7 @@
+
@@ -164,6 +167,8 @@
+
+
@@ -220,10 +225,14 @@
+
+
+
+
diff --git a/src/ee.h b/src/ee.h
index 4c387ab78..49d5b58a1 100755
--- a/src/ee.h
+++ b/src/ee.h
@@ -56,6 +56,7 @@
#include "system/cpak.hpp"
#include "system/czip.hpp"
#include "system/crc4.hpp"
+ #include "system/cobjectloader.hpp"
using namespace EE::System;
// Audio
@@ -82,6 +83,7 @@
// Graphics
#include "graphics/renders.hpp"
#include "graphics/ctexture.hpp"
+ #include "graphics/ctextureloader.hpp"
#include "graphics/ctexturefactory.hpp"
#include "graphics/cshape.hpp"
#include "graphics/cshapemanager.hpp"
diff --git a/src/graphics/base.hpp b/src/graphics/base.hpp
index c7890736d..4918af0d5 100644
--- a/src/graphics/base.hpp
+++ b/src/graphics/base.hpp
@@ -27,6 +27,4 @@ using namespace EE::System;
#include "renders.hpp"
-//#define ALLOC_VECTORS
-
#endif
diff --git a/src/graphics/cshape.cpp b/src/graphics/cshape.cpp
index b244d5689..4bec164ab 100644
--- a/src/graphics/cshape.cpp
+++ b/src/graphics/cshape.cpp
@@ -5,10 +5,8 @@
namespace EE { namespace Graphics {
cShape::cShape() :
- #ifndef ALLOC_VECTORS
mPixels(NULL),
mAlpha(NULL),
- #endif
mId(0),
mTexId(0),
mTexture(NULL),
@@ -22,10 +20,8 @@ cShape::cShape() :
}
cShape::cShape( const Uint32& TexId, const std::string& Name ) :
- #ifndef ALLOC_VECTORS
mPixels(NULL),
mAlpha(NULL),
- #endif
mName( Name ),
mId( MakeHash( mName ) ),
mTexId( TexId ),
@@ -39,10 +35,8 @@ cShape::cShape( const Uint32& TexId, const std::string& Name ) :
}
cShape::cShape( const Uint32& TexId, const eeRecti& SrcRect, const std::string& Name ) :
- #ifndef ALLOC_VECTORS
mPixels(NULL),
mAlpha(NULL),
- #endif
mName( Name ),
mId( MakeHash( mName ) ),
mTexId( TexId ),
@@ -56,10 +50,8 @@ cShape::cShape( const Uint32& TexId, const eeRecti& SrcRect, const std::string&
}
cShape::cShape( const Uint32& TexId, const eeRecti& SrcRect, const eeFloat& DestWidth, const eeFloat& DestHeight, const std::string& Name ) :
- #ifndef ALLOC_VECTORS
mPixels(NULL),
mAlpha(NULL),
- #endif
mName( Name ),
mId( MakeHash( mName ) ),
mTexId( TexId ),
@@ -73,10 +65,8 @@ cShape::cShape( const Uint32& TexId, const eeRecti& SrcRect, const eeFloat& Dest
}
cShape::cShape( const Uint32& TexId, const eeRecti& SrcRect, const eeFloat& DestWidth, const eeFloat& DestHeight, const eeFloat& OffsetX, const eeFloat& OffsetY, const std::string& Name ) :
- #ifndef ALLOC_VECTORS
mPixels(NULL),
mAlpha(NULL),
- #endif
mName( Name ),
mId( MakeHash( mName ) ),
mTexId( TexId ),
@@ -126,18 +116,10 @@ eeRecti cShape::SrcRect() const {
void cShape::SrcRect( const eeRecti& Rect ) {
mSrcRect = Rect;
- #ifndef ALLOC_VECTORS
if ( NULL != mPixels )
- #else
- if ( mPixels.size() )
- #endif
CacheColors();
- #ifndef ALLOC_VECTORS
if ( NULL != mAlpha )
- #else
- if ( mAlpha.size() )
- #endif
CacheAlphaMask();
}
@@ -211,13 +193,8 @@ void cShape::CreateMaskFromColor(eeColor ColorKey, Uint8 Alpha) {
void cShape::CacheAlphaMask() {
Uint32 size = ( mSrcRect.Right - mSrcRect.Left ) * ( mSrcRect.Bottom - mSrcRect.Top );
- #ifndef ALLOC_VECTORS
eeSAFE_DELETE_ARRAY( mAlpha );
mAlpha = new Uint8[ size ];
- #else
- mAlpha.clear();
- mAlpha.resize( size );
- #endif
mTexture->Lock();
@@ -241,13 +218,8 @@ void cShape::CacheAlphaMask() {
void cShape::CacheColors() {
Uint32 size = ( mSrcRect.Right - mSrcRect.Left ) * ( mSrcRect.Bottom - mSrcRect.Top ) ;
- #ifndef ALLOC_VECTORS
eeSAFE_DELETE_ARRAY( mPixels );
mPixels = new eeColorA[ size ];
- #else
- mPixels.clear();
- mPixels.resize( size );
- #endif
mTexture->Lock();
@@ -272,18 +244,10 @@ Uint8 cShape::GetAlphaAt( const Int32& X, const Int32& Y ) {
if ( mTexture->LocalCopy() )
return mTexture->GetPixel( mSrcRect.Left + X, mSrcRect.Right + Y ).A();
- #ifndef ALLOC_VECTORS
if ( NULL != mAlpha )
- #else
- if ( mAlpha.size() )
- #endif
return mAlpha[ X + Y * ( mSrcRect.Right - mSrcRect.Left ) ];
- #ifndef ALLOC_VECTORS
if ( NULL != mPixels )
- #else
- if ( mPixels.size() )
- #endif
return mPixels[ X + Y * ( mSrcRect.Right - mSrcRect.Left ) ].A();
CacheAlphaMask();
@@ -295,11 +259,7 @@ eeColorA cShape::GetColorAt( const Int32& X, const Int32& Y ) {
if ( mTexture->LocalCopy() )
return mTexture->GetPixel( mSrcRect.Left + X, mSrcRect.Right + Y );
- #ifndef ALLOC_VECTORS
if ( NULL != mPixels )
- #else
- if ( mPixels.size() )
- #endif
return mPixels[ X + Y * ( mSrcRect.Right - mSrcRect.Left ) ];
CacheColors();
@@ -308,11 +268,7 @@ eeColorA cShape::GetColorAt( const Int32& X, const Int32& Y ) {
}
void cShape::SetColorAt( const Int32& X, const Int32& Y, const eeColorA& Color ) {
- #ifndef ALLOC_VECTORS
if ( NULL != mPixels )
- #else
- if ( mPixels.size() )
- #endif
mPixels[ X + Y * ( mSrcRect.Right - mSrcRect.Left ) ] = Color;
else {
CacheColors();
@@ -321,13 +277,8 @@ void cShape::SetColorAt( const Int32& X, const Int32& Y, const eeColorA& Color )
}
void cShape::ClearCache() {
- #ifndef ALLOC_VECTORS
eeSAFE_DELETE_ARRAY( mPixels );
eeSAFE_DELETE_ARRAY( mAlpha );
- #else
- mPixels.clear();
- mAlpha.clear();
- #endif
}
eeColorA * cShape::Lock() {
@@ -337,11 +288,7 @@ eeColorA * cShape::Lock() {
}
bool cShape::Unlock( const bool& KeepData, const bool& Modified ) {
- #ifndef ALLOC_VECTORS
if ( NULL != mPixels ) {
- #else
- if ( mPixels.size() ) {
- #endif
if ( Modified ) {
GLint PreviousTexture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture);
@@ -356,11 +303,7 @@ bool cShape::Unlock( const bool& KeepData, const bool& Modified ) {
}
if ( !KeepData ) {
- #ifndef ALLOC_VECTORS
eeSAFE_DELETE_ARRAY( mPixels );
- #else
- mPixels.clear();
- #endif
}
return true;
@@ -378,11 +321,7 @@ eeSize cShape::Size() {
}
const Uint8* cShape::GetPixelsPtr() {
- #ifndef ALLOC_VECTORS
if ( mPixels == NULL ) {
- #else
- if ( !mPixels.size() ) {
- #endif
Lock();
Unlock(true);
}
diff --git a/src/graphics/cshape.hpp b/src/graphics/cshape.hpp
index 12f311019..79fc16f66 100644
--- a/src/graphics/cshape.hpp
+++ b/src/graphics/cshape.hpp
@@ -87,14 +87,8 @@ class EE_API cShape {
bool SaveToFile(const std::string& filepath, const EE_SAVETYPE& Format);
protected:
- #ifndef ALLOC_VECTORS
eeColorA * mPixels;
Uint8 * mAlpha;
- #else
- std::vector mPixels;
- std::vector mAlpha;
- #endif
-
std::string mName;
Uint32 mId;
Uint32 mTexId;
diff --git a/src/graphics/ctexture.cpp b/src/graphics/ctexture.cpp
index 0bd0163b4..0eeb4c39a 100755
--- a/src/graphics/ctexture.cpp
+++ b/src/graphics/ctexture.cpp
@@ -4,9 +4,7 @@
namespace EE { namespace Graphics {
cTexture::cTexture() :
- #ifndef ALLOC_VECTORS
mPixels(NULL),
- #endif
mFilepath(""),
mId(0),
mTexture(0),
@@ -143,11 +141,7 @@ eeColorA* cTexture::Lock() {
mHeight = (eeInt)height;
eeUint size = (eeUint)mWidth * (eeUint)mHeight;
- #ifndef ALLOC_VECTORS
if ( eeARRAY_SIZE( mPixels ) != size ) {
- #else
- if ( mPixels.size() != size ) {
- #endif
Allocate( size );
}
@@ -180,7 +174,7 @@ bool cTexture::Unlock(const bool& KeepData, const bool& Modified) {
Uint32 flags = mMipmap ? SOIL_FLAG_MIPMAPS : 0;
flags = (mClampMode == EE_CLAMP_REPEAT) ? (flags | SOIL_FLAG_TEXTURE_REPEATS) : flags;
- NTexId = SOIL_create_OGL_texture( reinterpret_cast(&mPixels[0]), &width, &height, SOIL_LOAD_RGBA, mTexture, flags);
+ NTexId = SOIL_create_OGL_texture( reinterpret_cast(&mPixels[0]), &width, &height, SOIL_LOAD_RGBA, mTexture, flags);
mChannels = 4;
SetTextureFilter(mFilter);
@@ -213,24 +207,15 @@ const Uint8* cTexture::GetPixelsPtr() {
}
const eeColorA& cTexture::GetPixel(const eeUint& x, const eeUint& y) {
- #ifndef ALLOC_VECTORS
if ( mPixels == NULL || (eeInt)x > mWidth || (eeInt)y > mHeight ) {
- #else
- if ( !mPixels.size() || (eeInt)x > mWidth || (eeInt)y > mHeight ) {
- #endif
return eeColorA::Black;
}
-
return mPixels[ x + y * (Uint32)mWidth ];
}
void cTexture::SetPixel(const eeUint& x, const eeUint& y, const eeColorA& Color) {
- #ifndef ALLOC_VECTORS
if ( mPixels == NULL || (eeInt)x > mWidth || (eeInt)y > mHeight ) {
- #else
- if ( !mPixels.size() || (eeInt)x > mWidth || (eeInt)y > mHeight ) {
- #endif
return;
}
@@ -297,11 +282,7 @@ void cTexture::CreateMaskFromColor(eeColor ColorKey, Uint8 Alpha) {
}
bool cTexture::LocalCopy() {
- #ifndef ALLOC_VECTORS
return ( mPixels != NULL );
- #else
- return mPixels.size() != 0;
- #endif
}
void cTexture::ClampMode( const EE_CLAMP_MODE& clampmode ) {
@@ -334,11 +315,7 @@ void cTexture::ApplyClampMode() {
}
void cTexture::ClearCache() {
- #ifndef ALLOC_VECTORS
eeSAFE_DELETE_ARRAY( mPixels );
- #else
- mPixels.clear();
- #endif
}
void cTexture::Draw( const eeFloat &x, const eeFloat &y, const eeFloat &Angle, const eeFloat &Scale, const eeColorA& Color, const EE_RENDERALPHAS &blend, const EE_RENDERTYPE &Effect, const bool &ScaleCentered, const eeRecti& texSector) {
@@ -557,11 +534,25 @@ const Uint32& cTexture::TexId() const {
void cTexture::Allocate( const Uint32& size ) {
ClearCache();
- #ifndef ALLOC_VECTORS
mPixels = new eeColorA[ size ];
- #else
- mPixels.resize( size );
- #endif
+}
+
+void cTexture::Reload() {
+ if ( LocalCopy() ) {
+ Int32 width = mWidth;
+ Int32 height = mHeight;
+
+ GLint PreviousTexture;
+ glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture);
+
+ Uint32 flags = mMipmap ? SOIL_FLAG_MIPMAPS : 0;
+ flags = (mClampMode == EE_CLAMP_REPEAT) ? (flags | SOIL_FLAG_TEXTURE_REPEATS) : flags;
+ flags = (mCompressedTexture) ? ( flags | SOIL_FLAG_COMPRESS_TO_DXT ) : flags;
+
+ mTexture = SOIL_create_OGL_texture( reinterpret_cast ( &mPixels[0] ), &width, &height, mChannels, mTexture, flags );
+
+ glBindTexture(GL_TEXTURE_2D, PreviousTexture);
+ }
}
}}
diff --git a/src/graphics/ctexture.hpp b/src/graphics/ctexture.hpp
index 03584fe63..0f9b38c82 100755
--- a/src/graphics/ctexture.hpp
+++ b/src/graphics/ctexture.hpp
@@ -215,13 +215,12 @@ class EE_API cTexture {
/** @return The texture factory internal id of the texture */
const Uint32& TexId() const;
+
+ /** Reload the texture from the current local copy. */
+ void Reload();
protected:
- #ifndef ALLOC_VECTORS
eeColorA * mPixels;
- #else
- std::vector mPixels;
- #endif
-
+
std::string mFilepath;
Uint32 mId;
diff --git a/src/graphics/ctexturefactory.cpp b/src/graphics/ctexturefactory.cpp
index 81b567eef..20937b9d8 100755
--- a/src/graphics/ctexturefactory.cpp
+++ b/src/graphics/ctexturefactory.cpp
@@ -1,5 +1,6 @@
#include "ctexturefactory.hpp"
#include "../window/cengine.hpp"
+#include "ctextureloader.hpp"
using namespace EE::Window;
@@ -12,142 +13,53 @@ cTextureFactory::cTextureFactory() :
{
mTextures.clear();
mTextures.push_back( NULL );
-
- Log = cLog::instance();
-
- BR = cGlobalBatchRenderer::instance();
}
cTextureFactory::~cTextureFactory() {
UnloadTextures();
}
-GLint cTextureFactory::GetPrevTex() {
- GLint PreviousTexture;
- glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture);
- return PreviousTexture;
-}
-
-void cTextureFactory::BindPrev( const GLint& PreviousTexture ) {
- glBindTexture(GL_TEXTURE_2D, PreviousTexture);
- mCurrentTexture = PreviousTexture;
-}
-
-Uint32 cTextureFactory::CreateEmptyTexture( const eeUint& Width, const eeUint& Height, const eeColorA& DefaultColor, const bool& mipmap, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) {
+Uint32 cTextureFactory::CreateEmptyTexture( const eeUint& Width, const eeUint& Height, const eeColorA& DefaultColor, const bool& Mipmap, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) {
std::vector tmpTex( Width * Height, DefaultColor );
- return LoadFromPixels( reinterpret_cast ( &tmpTex[0] ), Width, Height, 4, mipmap, eeRGB(true), ClampMode, CompressTexture, KeepLocalCopy );
+ return LoadFromPixels( reinterpret_cast ( &tmpTex[0] ), Width, Height, 4, Mipmap, eeRGB(true), ClampMode, CompressTexture, KeepLocalCopy );
}
-Uint32 cTextureFactory::LoadFromPixels( const unsigned char* Surface, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const bool& mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy, const std::string& FileName ) {
- return iLoadFromPixels( Surface, Width, Height, Channels, mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy, FileName );
+Uint32 cTextureFactory::LoadFromPixels( const unsigned char * Pixels, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const bool& Mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy, const std::string& FileName ) {
+ cTextureLoader myTex( Pixels, Width, Height, Channels, Mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy, FileName );
+ myTex.Load();
+ return myTex.TexId();
}
-Uint32 cTextureFactory::iLoadFromPixels( const unsigned char* Surface, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const bool& mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy, const std::string& FileName, const Uint32& TexPos ) {
- Uint32 tTexId = 0;
-
- if ( NULL != Surface ) {
- int width = Width;
- int height = Height;
-
- Uint32 flags = mipmap ? SOIL_FLAG_MIPMAPS : 0;
-
- flags = (ClampMode == EE_CLAMP_REPEAT) ? (flags | SOIL_FLAG_TEXTURE_REPEATS) : flags;
- flags = (CompressTexture) ? ( flags | SOIL_FLAG_COMPRESS_TO_DXT ) : flags;
-
- GLint PreviousTexture = GetPrevTex();
- tTexId = SOIL_create_OGL_texture(Surface, &width, &height, Channels, ( ( TexPos==0 ) ? SOIL_CREATE_NEW_ID : GetTexture(TexPos)->Texture() ), flags);
- BindPrev( PreviousTexture );
-
- if ( tTexId )
- return iPushTexture( FileName, tTexId, Width, Height, width, height, mipmap, static_cast( Channels ), ColorKey, ClampMode, CompressTexture, KeepLocalCopy, TexPos );
-
- } else {
- Log->Write( SOIL_last_result() );
- }
-
- return 0;
+Uint32 cTextureFactory::LoadFromPack( cPack* Pack, const std::string& FilePackPath, const bool& Mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) {
+ cTextureLoader myTex( Pack, FilePackPath, Mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy );
+ myTex.Load();
+ return myTex.TexId();
}
-Uint32 cTextureFactory::LoadFromPack( cPack* Pack, const std::string& FilePackPath, const bool& mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) {
- std::vector TmpData;
-
- if ( Pack->IsOpen() && Pack->ExtractFileToMemory( FilePackPath, TmpData ) )
- return LoadFromMemory( reinterpret_cast (&TmpData[0]), TmpData.size(), mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy );
-
- return 0;
+Uint32 cTextureFactory::LoadFromMemory( const unsigned char * ImagePtr, const eeUint& Size, const bool& Mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) {
+ cTextureLoader myTex( ImagePtr, Size, Mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy );
+ myTex.Load();
+ return myTex.TexId();
}
-Uint32 cTextureFactory::LoadFromMemory( const unsigned char* Surface, const eeUint& Size, const bool& mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) {
- int ImgWidth, ImgHeight, ImgChannels;
-
- unsigned char * PixelsPtr = SOIL_load_image_from_memory(Surface, Size, &ImgWidth, &ImgHeight, &ImgChannels, SOIL_LOAD_AUTO);
-
- if ( NULL != PixelsPtr ) {
- Uint32 Result = LoadFromPixels( PixelsPtr, ImgWidth, ImgHeight, ImgChannels, mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy );
-
- SOIL_free_image_data( PixelsPtr );
-
- return Result;
- } else
- Log->Write( SOIL_last_result() );
-
- return 0;
+Uint32 cTextureFactory::Load( const std::string& Filepath, const bool& Mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) {
+ cTextureLoader myTex( Filepath, Mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy );
+ myTex.Load();
+ return myTex.TexId();
}
-Uint32 cTextureFactory::Load( const std::string& filepath, const bool& mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) {
- return iLoad( filepath, mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy, 0 );
-}
+Uint32 cTextureFactory::PushTexture( const std::string& Filepath, const Uint32& TexId, const eeUint& Width, const eeUint& Height, const eeUint& ImgWidth, const eeUint& ImgHeight, const bool& Mipmap, const eeUint& Channels, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& LocalCopy ) {
+ Lock();
-Uint32 cTextureFactory::iLoad( const std::string& filepath, const bool& mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy, const Uint32& TexPos ) {
- int ImgWidth, ImgHeight, ImgChannels;
-
- if ( FileExists( filepath ) ) {
- unsigned char * PixelsPtr = SOIL_load_image(filepath.c_str(), &ImgWidth, &ImgHeight, &ImgChannels, SOIL_LOAD_AUTO);
-
- if ( NULL != PixelsPtr ) {
- Uint32 Result = iLoadFromPixels( PixelsPtr, ImgWidth, ImgHeight, ImgChannels, mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy, filepath, TexPos );
-
- SOIL_free_image_data( PixelsPtr );
-
- return Result;
- } else
- Log->Write( SOIL_last_result() );
- }
-
- return 0;
-}
-
-Uint32 cTextureFactory::PushTexture( const std::string& filepath, const Uint32& TexId, const eeUint& Width, const eeUint& Height, const eeUint& ImgWidth, const eeUint& ImgHeight, const bool& Mipmap, const eeUint& Channels, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& LocalCopy ) {
- return iPushTexture( filepath, TexId, Width, Height, ImgWidth, ImgHeight, Mipmap, Channels, ColorKey, ClampMode, CompressTexture, LocalCopy );
-}
-
-Uint32 cTextureFactory::iPushTexture( const std::string& filepath, const Uint32& TexId, const eeUint& Width, const eeUint& Height, const eeUint& ImgWidth, const eeUint& ImgHeight, const bool& Mipmap, const eeUint& Channels, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& LocalCopy, const Uint32& TexPos ) {
cTexture * Tex = NULL;
Uint32 Pos;
eeInt MyWidth = ImgWidth;
eeInt MyHeight = ImgHeight;
- if ( TexPos != 0 ) {
- Pos = TexPos;
- Tex = GetTexture( TexPos );
+ Pos = FindFreeSlot();
+ Tex = mTextures[ Pos ] = new cTexture();
- // Recover the real image size
- if ( NULL != Tex && TexId == Tex->Texture() ) {
- Tex->Width( Width );
- Tex->Height( Height );
-
- MyWidth = Tex->ImgWidth();
- MyHeight = Tex->ImgHeight();
-
- mMemSize -= GetTexMemSize( TexPos );
- }
- } else {
- Pos = FindFreeSlot();
-
- Tex = mTextures[ Pos ] = new cTexture();
- }
-
- Tex->Create( TexId, Width, Height, MyWidth, MyHeight, Mipmap, Channels, filepath, ColorKey, ClampMode, CompressTexture );
+ Tex->Create( TexId, Width, Height, MyWidth, MyHeight, Mipmap, Channels, Filepath, ColorKey, ClampMode, CompressTexture );
Tex->TexId( Pos );
if ( !ColorKey.voidRGB )
@@ -160,6 +72,8 @@ Uint32 cTextureFactory::iPushTexture( const std::string& filepath, const Uint32&
mMemSize += GetTexMemSize( Pos );
+ Unlock();
+
return Pos;
}
@@ -191,14 +105,13 @@ void cTextureFactory::Bind( const Uint32& TexId ) {
void cTextureFactory::UnloadTextures() {
try {
for ( Uint32 i = 1; i < mTextures.size(); i++ )
- if ( mTextures[i] != NULL )
- delete mTextures[i];
+ eeSAFE_DELETE( mTextures[i] );
mTextures.clear();
- Log->Write( "Textures Unloaded." );
+ cLog::instance()->Write( "Textures Unloaded." );
} catch (...) {
- Log->Write("An error ocurred on: UnloadTextures.");
+ cLog::instance()->Write("An error ocurred on: UnloadTextures.");
}
}
@@ -221,23 +134,6 @@ bool cTextureFactory::Remove( const Uint32& TexId ) {
return false;
}
-Uint32 cTextureFactory::Reload( const Uint32& TexId, const std::string& filepath, const bool& mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture ) {
- Uint32 Id = 0;
- if ( !filepath.empty() ) {
- Id = iLoad(filepath, mipmap, ColorKey, ClampMode, CompressTexture, TexId);
- return Id;
- } else {
- cTexture* Tex = GetTexture(TexId);
-
- if ( Tex->LocalCopy() )
- Id = iLoadFromPixels( Tex->GetPixelsPtr(), (int)Tex->Width(), (int)Tex->Height(), SOIL_LOAD_RGBA, Tex->Mipmap(), Tex->ColorKey(), Tex->ClampMode(), Tex->Compressed(), ( Tex->LocalCopy() && !Tex->Grabed() ), Tex->Filepath(), TexId );
- else
- Id = iLoad( Tex->Filepath(), Tex->Mipmap(), Tex->ColorKey(), Tex->ClampMode(), Tex->Compressed(), TexId );
-
- return Id;
- }
-}
-
GLint cTextureFactory::GetCurrentTexture() const {
return mCurrentTexture;
}
@@ -250,27 +146,29 @@ void cTextureFactory::ReloadAllTextures() {
try {
for ( Uint32 i = 1; i < mTextures.size(); i++ ) {
cTexture* Tex = GetTexture(i);
+
if ( Tex ) {
- if ( ( Tex->Filepath() != "" && FileExists( Tex->Filepath() ) ) || Tex->LocalCopy() )
- Reload(i);
+ if ( Tex->LocalCopy() )
+ Tex->Reload();
else {
Tex->Lock();
- Reload(i);
+ Tex->Reload();
Tex->Unlock(false, false);
}
}
}
- Log->Write("Textures Reloaded.");
+ cLog::instance()->Write("Textures Reloaded.");
} catch (...) {
- Log->Write("An error ocurred on: ReloadAllTextures.");
+ cLog::instance()->Write("An error ocurred on: ReloadAllTextures.");
}
}
void cTextureFactory::GrabTextures() {
for ( Uint32 i = 1; i < mTextures.size(); i++ ) {
cTexture* Tex = GetTexture(i);
+
if ( Tex ) {
- if ( !( Tex->Filepath() != "" || Tex->LocalCopy() ) ) {
+ if ( !Tex->LocalCopy() ) {
Tex->Lock();
Tex->Unlock(true, false);
Tex->Grabed(true);
diff --git a/src/graphics/ctexturefactory.hpp b/src/graphics/ctexturefactory.hpp
index 6f987dd2b..4318db7f2 100755
--- a/src/graphics/ctexturefactory.hpp
+++ b/src/graphics/ctexturefactory.hpp
@@ -4,6 +4,7 @@
#include "base.hpp"
#include "ctexture.hpp"
#include "cglobalbatchrenderer.hpp"
+#include "../system/cmutex.hpp"
namespace EE { namespace Graphics {
@@ -12,7 +13,7 @@ namespace EE { namespace Graphics {
class cGlobalBatchRenderer;
/** @brief The Texture Manager Class. Here we do all the textures stuff. (Singleton Class) */
-class EE_API cTextureFactory: public cSingleton {
+class EE_API cTextureFactory: public cSingleton, protected cMutex {
friend class cSingleton;
public:
/** Create an empty texture
@@ -25,14 +26,14 @@ class EE_API cTextureFactory: public cSingleton {
* @param KeepLocalCopy Keep the array data copy. ( usefull if want to reload the texture )
* @return Internal Texture Id
*/
- Uint32 CreateEmptyTexture( const eeUint& Width, const eeUint& Height, const eeColorA& DefaultColor = eeColorA(0,0,0,255), const bool& mipmap = false, const EE_CLAMP_MODE& ClampMode = EE_CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
+ Uint32 CreateEmptyTexture( const eeUint& Width, const eeUint& Height, const eeColorA& DefaultColor = eeColorA(0,0,0,255), const bool& Mipmap = false, const EE_CLAMP_MODE& ClampMode = EE_CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
/** Loads a RAW Texture from Memory
- * @param Surface The Texture array
+ * @param Pixels The Texture array
* @param Width Texture Width
* @param Height Texture Height
* @param Channels Texture Number of Channels (in bytes)
- * @param mipmap Create Mipmap?
+ * @param Mipmap Create Mipmap?
* @param ColorKey Color key for the texture ( eeRGB(true) for none )
* @param ClampMode Defines the CLAMP MODE
* @param CompressTexture If use the DXT compression on the texture loading ( if the card can display them, will convert RGB to DXT1, RGBA to DXT5 )
@@ -40,30 +41,30 @@ class EE_API cTextureFactory: public cSingleton {
* @param FileName A filename to recognize the texture ( the path in case that was loaded from outside the texture factory ).
* @return Internal Texture Id
*/
- Uint32 LoadFromPixels( const unsigned char* Surface, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const bool& mipmap = false, const eeRGB& ColorKey = eeRGB(true), const EE_CLAMP_MODE& ClampMode = EE_CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, const std::string& FileName = std::string("") );
+ Uint32 LoadFromPixels( const unsigned char * Pixels, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const bool& Mipmap = false, const eeRGB& ColorKey = eeRGB(true), const EE_CLAMP_MODE& ClampMode = EE_CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, const std::string& FileName = std::string("") );
/** Load a texture from Pack
* @param Pack Pointer to the pack instance
* @param FilePackPath The path of the file inside the pack
- * @param mipmap Create Mipmap?
+ * @param Mipmap Create Mipmap?
* @param ClampMode Defines the CLAMP MODE
* @param CompressTexture If use the DXT compression on the texture loading ( if the card can display them, will convert RGB to DXT1, RGBA to DXT5 )
* @param KeepLocalCopy Keep the array data copy. ( usefull if want to reload the texture )
* @return Internal Texture Id
*/
- Uint32 LoadFromPack( cPack* Pack, const std::string& FilePackPath, const bool& mipmap = false, const eeRGB& ColorKey = eeRGB(true), const EE_CLAMP_MODE& ClampMode = EE_CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
+ Uint32 LoadFromPack( cPack* Pack, const std::string& FilePackPath, const bool& Mipmap = false, const eeRGB& ColorKey = eeRGB(true), const EE_CLAMP_MODE& ClampMode = EE_CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
/** Load a texture from memory (RGBA Format)
- * @param Surface The image data in RAM just as if it were still in a file
+ * @param ImagePtr The image data in RAM just as if it were still in a file
* @param Size The size of the texture ( Width * Height * BytesPerPixel )
- * @param mipmap Use mipmaps?
+ * @param Mipmap Use mipmaps?
* @param ColorKey The ColorKey for the texture
* @param ClampMode Defines the CLAMP MODE
* @param CompressTexture If use the DXT compression on the texture loading ( if the card can display them, will convert RGB to DXT1, RGBA to DXT5 )
* @param KeepLocalCopy Keep the array data copy. ( usefull if want to reload the texture )
* @return The internal Texture Id
*/
- Uint32 LoadFromMemory( const unsigned char* Surface, const eeUint& Size, const bool& mipmap = false, const eeRGB& ColorKey = eeRGB(true), const EE_CLAMP_MODE& ClampMode = EE_CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
+ Uint32 LoadFromMemory( const unsigned char* ImagePtr, const eeUint& Size, const bool& Mipmap = false, const eeRGB& ColorKey = eeRGB(true), const EE_CLAMP_MODE& ClampMode = EE_CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
/** Load a Texture from a file path
* @param filepath The path for the texture
@@ -74,18 +75,7 @@ class EE_API cTextureFactory: public cSingleton {
* @param KeepLocalCopy Keep the array data copy. ( usefull if want to reload the texture )
* @return The internal Texture Id
*/
- Uint32 Load( const std::string& filepath, const bool& mipmap = false, const eeRGB& ColorKey = eeRGB(true), const EE_CLAMP_MODE& ClampMode = EE_CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
-
- /** Reload a Texture Id
- * @param TexId The internal Texture Id
- * @param filepath If filepath is empty reload the same texture, otherwise loads a new texture on the Texture Id slot
- * @param mipmap Use mipmaps?
- * @param ColorKey The ColorKey for the texture
- * @param ClampMode Defines the CLAMP MODE
- * @param CompressTexture If use the DXT compression on the texture loading ( if the card can display them, will convert RGB to DXT1, RGBA to DXT5 )
- * @return Returns the Texture Id
- */
- Uint32 Reload( const Uint32& TexId, const std::string& filepath = "", const bool& mipmap = false, const eeRGB& ColorKey = eeRGB(true), const EE_CLAMP_MODE& ClampMode = EE_CLAMP_TO_EDGE, const bool& CompressTexture = false );
+ Uint32 Load( const std::string& Filepath, const bool& mipmap = false, const eeRGB& ColorKey = eeRGB(true), const EE_CLAMP_MODE& ClampMode = EE_CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
/** Remove and Unload the Texture Id
* @param TexId
@@ -161,7 +151,7 @@ class EE_API cTextureFactory: public cSingleton {
eeUint GetTexMemSize( const eeUint& TexId );
/** It's possible to create textures outside the texture factory loader, but the library will need to know of this texture, so it's necessary to push the texture to the factory.
- * @param filepath The Texture path ( if exists )
+ * @param Filepath The Texture path ( if exists )
* @param TexId The OpenGL Texture Id
* @param Width Texture Width
* @param Height Texture Height
@@ -174,13 +164,11 @@ class EE_API cTextureFactory: public cSingleton {
* @param CompressTexture The texture is compressed?
* @param LocalCopy If keep a local copy in memory of the texture
*/
- Uint32 PushTexture( const std::string& filepath, const Uint32& TexId, const eeUint& Width, const eeUint& Height, const eeUint& ImgWidth, const eeUint& ImgHeight, const bool& Mipmap, const eeUint& Channels, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& LocalCopy = false );
+ Uint32 PushTexture( const std::string& Filepath, const Uint32& TexId, const eeUint& Width, const eeUint& Height, const eeUint& ImgWidth, const eeUint& ImgHeight, const bool& Mipmap, const eeUint& Channels, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& LocalCopy = false );
protected:
cTextureFactory();
~cTextureFactory();
- cLog* Log;
-
GLint mCurrentTexture;
EE_RENDERALPHAS mLastBlend;
@@ -193,20 +181,8 @@ class EE_API cTextureFactory: public cSingleton {
std::queue mVectorFreeSlots;
- cGlobalBatchRenderer* BR;
-
- Uint32 iLoadFromPixels( const unsigned char* Surface, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const bool& mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy, const std::string& FileName, const Uint32& TexPos = 0 );
-
- Uint32 iLoad( const std::string& filepath, const bool& mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy, const Uint32& TexPos = 0 );
-
- Uint32 iPushTexture( const std::string& filepath, const Uint32& TexId, const eeUint& Width, const eeUint& Height, const eeUint& ImgWidth, const eeUint& ImgHeight, const bool& Mipmap, const eeUint& Channels, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& LocalCopy = false, const Uint32& TexPos = 0 );
-
void UnloadTextures();
- GLint GetPrevTex();
-
- void BindPrev( const GLint& Prev );
-
Uint32 FindFreeSlot();
};
diff --git a/src/graphics/ctextureloader.cpp b/src/graphics/ctextureloader.cpp
new file mode 100644
index 000000000..aa477848d
--- /dev/null
+++ b/src/graphics/ctextureloader.cpp
@@ -0,0 +1,214 @@
+#include "ctextureloader.hpp"
+#include "ctexturefactory.hpp"
+
+namespace EE { namespace Graphics {
+
+cTextureLoader::cTextureLoader( const std::string& Filepath,
+ const bool& Mipmap,
+ const eeRGB& ColorKey,
+ const EE_CLAMP_MODE& ClampMode,
+ const bool& CompressTexture,
+ const bool& KeepLocalCopy
+) : cObjectLoader(),
+ mLoadType(TEX_LT_PATH),
+ mPixels(NULL),
+ mTexId(0),
+ mImgWidth(0),
+ mImgHeight(0),
+ mFilepath(Filepath),
+ mWidth(0),
+ mHeight(0),
+ mMipmap(Mipmap),
+ mChannels(0),
+ mColorKey(ColorKey),
+ mClampMode(ClampMode),
+ mCompressTexture(CompressTexture),
+ mLocalCopy(KeepLocalCopy),
+ mPack(NULL),
+ mImagePtr(NULL),
+ mSize(0),
+ mTexLoaded(false)
+{
+}
+
+cTextureLoader::cTextureLoader( const unsigned char * ImagePtr,
+ const eeUint& Size,
+ const bool& Mipmap,
+ const eeRGB& ColorKey,
+ const EE_CLAMP_MODE& ClampMode,
+ const bool& CompressTexture,
+ const bool& KeepLocalCopy
+) : cObjectLoader(),
+ mLoadType(TEX_LT_MEM),
+ mPixels(NULL),
+ mTexId(0),
+ mImgWidth(0),
+ mImgHeight(0),
+ mFilepath(""),
+ mWidth(0),
+ mHeight(0),
+ mMipmap(Mipmap),
+ mChannels(0),
+ mColorKey(ColorKey),
+ mClampMode(ClampMode),
+ mCompressTexture(CompressTexture),
+ mLocalCopy(KeepLocalCopy),
+ mPack(NULL),
+ mImagePtr(ImagePtr),
+ mSize(Size),
+ mTexLoaded(false)
+{
+}
+
+cTextureLoader::cTextureLoader( cPack * Pack,
+ const std::string& FilePackPath,
+ const bool& Mipmap ,
+ const eeRGB& ColorKey,
+ const EE_CLAMP_MODE& ClampMode,
+ const bool& CompressTexture,
+ const bool& KeepLocalCopy
+) : cObjectLoader(),
+ mLoadType(TEX_LT_PACK),
+ mPixels(NULL),
+ mTexId(0),
+ mImgWidth(0),
+ mImgHeight(0),
+ mFilepath(FilePackPath),
+ mWidth(0),
+ mHeight(0),
+ mMipmap(Mipmap),
+ mChannels(0),
+ mColorKey(ColorKey),
+ mClampMode(ClampMode),
+ mCompressTexture(CompressTexture),
+ mLocalCopy(KeepLocalCopy),
+ mPack(Pack),
+ mImagePtr(NULL),
+ mSize(0),
+ mTexLoaded(false)
+{
+}
+
+cTextureLoader::cTextureLoader( const unsigned char * Pixels,
+ const eeUint& Width,
+ const eeUint& Height,
+ const eeUint& Channels,
+ const bool& Mipmap,
+ const eeRGB& ColorKey,
+ const EE_CLAMP_MODE& ClampMode,
+ const bool& CompressTexture,
+ const bool& KeepLocalCopy,
+ const std::string& FileName
+) : cObjectLoader(),
+ mLoadType(TEX_LT_PIXELS),
+ mPixels( const_cast ( Pixels ) ),
+ mTexId(0),
+ mImgWidth(Width),
+ mImgHeight(Height),
+ mFilepath(FileName),
+ mWidth(0),
+ mHeight(0),
+ mMipmap(Mipmap),
+ mChannels(Channels),
+ mColorKey(ColorKey),
+ mClampMode(ClampMode),
+ mCompressTexture(CompressTexture),
+ mLocalCopy(KeepLocalCopy),
+ mPack(NULL),
+ mImagePtr(NULL),
+ mSize(0),
+ mTexLoaded(false)
+{
+}
+
+cTextureLoader::~cTextureLoader() {
+ if ( NULL != mPixels )
+ SOIL_free_image_data( mPixels );
+}
+
+void cTextureLoader::Start() {
+ if ( TEX_LT_PATH == mLoadType )
+ LoadFromPath();
+ else if ( TEX_LT_MEM == mLoadType )
+ LoadFromMemory();
+ else if ( TEX_LT_PACK == mLoadType )
+ LoadFromPack();
+
+ mTexLoaded = true;
+
+ if ( !mThreaded )
+ LoadFromPixels();
+}
+
+void cTextureLoader::LoadFromPath() {
+ if ( FileExists( mFilepath ) ) {
+ mPixels = SOIL_load_image( mFilepath.c_str(), &mImgWidth, &mImgHeight, &mChannels, SOIL_LOAD_AUTO );
+
+ if ( NULL == mPixels )
+ cLog::instance()->Write( SOIL_last_result() );
+ }
+}
+
+void cTextureLoader::LoadFromPack() {
+ std::vector TmpData;
+
+ if ( NULL != mPack && mPack->IsOpen() && mPack->ExtractFileToMemory( mFilepath, TmpData ) ) {
+ mImagePtr = reinterpret_cast (&TmpData[0]);
+ mSize = TmpData.size();
+
+ LoadFromMemory();
+ }
+}
+
+void cTextureLoader::LoadFromMemory() {
+ mPixels = SOIL_load_image_from_memory( mImagePtr, mSize, &mImgWidth, &mImgHeight, &mChannels, SOIL_LOAD_AUTO );
+
+ if ( NULL == mPixels )
+ cLog::instance()->Write( SOIL_last_result() );
+}
+
+void cTextureLoader::LoadFromPixels() {
+ if ( mTexLoaded && !mLoaded ) {
+ Uint32 tTexId = 0;
+
+ if ( NULL != mPixels ) {
+ int width = mImgWidth;
+ int height = mImgHeight;
+
+ Uint32 flags = mMipmap ? SOIL_FLAG_MIPMAPS : 0;
+
+ flags = ( mClampMode == EE_CLAMP_REPEAT) ? (flags | SOIL_FLAG_TEXTURE_REPEATS) : flags;
+ flags = ( mCompressTexture ) ? ( flags | SOIL_FLAG_COMPRESS_TO_DXT ) : flags;
+
+ GLint PreviousTexture;
+ glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture);
+
+ tTexId = SOIL_create_OGL_texture( mPixels, &width, &height, mChannels, SOIL_CREATE_NEW_ID, flags );
+
+ glBindTexture(GL_TEXTURE_2D, PreviousTexture);
+
+ if ( tTexId )
+ mTexId = cTextureFactory::instance()->PushTexture( mFilepath, tTexId, mImgWidth, mImgHeight, width, height, mMipmap, mChannels, mColorKey, mClampMode, mCompressTexture, mLocalCopy );
+
+ if ( TEX_LT_PIXELS != mLoadType )
+ SOIL_free_image_data( mPixels );
+
+ mPixels = NULL;
+
+ } else
+ cLog::instance()->Write( SOIL_last_result() );
+
+ mLoaded = true;
+ }
+}
+
+void cTextureLoader::Update() {
+ LoadFromPixels();
+}
+
+const Uint32& cTextureLoader::TexId() const {
+ return mTexId;
+}
+
+}}
+
diff --git a/src/graphics/ctextureloader.hpp b/src/graphics/ctextureloader.hpp
new file mode 100644
index 000000000..77aaab872
--- /dev/null
+++ b/src/graphics/ctextureloader.hpp
@@ -0,0 +1,63 @@
+#ifndef EE_GRAPHICSCTEXTURELOADER
+#define EE_GRAPHICSCTEXTURELOADER
+
+#include "base.hpp"
+#include "../system/cobjectloader.hpp"
+
+namespace EE { namespace Graphics {
+
+#define TEX_LT_PATH (1)
+#define TEX_LT_MEM (2)
+#define TEX_LT_PACK (3)
+#define TEX_LT_PIXELS (4)
+
+class cTextureLoader : public cObjectLoader {
+ public:
+ cTextureLoader( const std::string& Filepath, const bool& Mipmap = false, const eeRGB& ColorKey = eeRGB(true), const EE_CLAMP_MODE& ClampMode = EE_CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
+
+ cTextureLoader( const unsigned char * ImagePtr, const eeUint& Size, const bool& Mipmap = false, const eeRGB& ColorKey = eeRGB(true), const EE_CLAMP_MODE& ClampMode = EE_CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
+
+ cTextureLoader( cPack * Pack, const std::string& FilePackPath, const bool& Mipmap = false, const eeRGB& ColorKey = eeRGB(true), const EE_CLAMP_MODE& ClampMode = EE_CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
+
+ cTextureLoader( const unsigned char * Pixels, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const bool& Mipmap = false, const eeRGB& ColorKey = eeRGB(true), const EE_CLAMP_MODE& ClampMode = EE_CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false, const std::string& FileName = std::string("") );
+
+ ~cTextureLoader();
+
+ void Update();
+
+ const Uint32& TexId() const;
+ protected:
+ Uint32 mLoadType; // From memory, from path, from pack
+ Uint8 * mPixels; // Texture Info
+ Uint32 mTexId;
+ Int32 mImgWidth;
+ Int32 mImgHeight;
+
+ std::string mFilepath;
+ eeUint mWidth;
+ eeUint mHeight;
+ bool mMipmap;
+ Int32 mChannels;
+ eeRGB mColorKey;
+ EE_CLAMP_MODE mClampMode;
+ bool mCompressTexture;
+ bool mLocalCopy;
+ cPack * mPack;
+
+ const Uint8 * mImagePtr;
+ Uint32 mSize;
+
+ void Start();
+ private:
+ bool mTexLoaded;
+
+ void LoadFromPath();
+ void LoadFromMemory();
+ void LoadFromPack();
+ void LoadFromPixels();
+};
+
+}}
+
+#endif
+
diff --git a/src/system/cobjectloader.cpp b/src/system/cobjectloader.cpp
new file mode 100644
index 000000000..3b84a2ee1
--- /dev/null
+++ b/src/system/cobjectloader.cpp
@@ -0,0 +1,51 @@
+#include "cobjectloader.hpp"
+
+namespace EE { namespace System {
+
+cObjectLoader::cObjectLoader():
+ mObjType(0xFFFFFFFF),
+ mLoaded(false),
+ mThreaded(false)
+{
+}
+
+cObjectLoader::~cObjectLoader()
+{
+}
+
+void cObjectLoader::Load() {
+ Launch();
+}
+
+void cObjectLoader::Launch() {
+ if ( mThreaded )
+ cThread::Launch();
+ else
+ Run();
+}
+
+void cObjectLoader::Start() {
+
+}
+
+void cObjectLoader::Update() {
+
+}
+
+bool cObjectLoader::IsLoaded() {
+ return mLoaded;
+}
+
+bool cObjectLoader::Threaded() const {
+ return mThreaded;
+}
+
+void cObjectLoader::Threaded( const bool& threaded ) {
+ mThreaded = threaded;
+}
+
+void cObjectLoader::Run() {
+ Start();
+}
+
+}}
diff --git a/src/system/cobjectloader.hpp b/src/system/cobjectloader.hpp
new file mode 100644
index 000000000..be6bee763
--- /dev/null
+++ b/src/system/cobjectloader.hpp
@@ -0,0 +1,40 @@
+#ifndef EE_SYSTEMCOBJECTLOADER
+#define EE_SYSTEMCOBJECTLOADER
+
+#include "base.hpp"
+#include "cthread.hpp"
+
+namespace EE { namespace System {
+
+class cObjectLoader : cThread {
+ public:
+ cObjectLoader();
+
+ ~cObjectLoader();
+
+ void Load();
+
+ virtual void Update();
+
+ void Launch();
+
+ virtual bool IsLoaded();
+
+ bool Threaded() const;
+
+ void Threaded( const bool& threaded );
+ protected:
+ Uint32 mObjType; // Texture Loader Object Type
+ bool mLoaded;
+ bool mThreaded;
+
+ virtual void Start();
+ private:
+ virtual void Run();
+};
+
+}}
+
+#endif
+
+
diff --git a/src/system/cthread.cpp b/src/system/cthread.cpp
index 03d47df31..981e03ca8 100755
--- a/src/system/cthread.cpp
+++ b/src/system/cthread.cpp
@@ -40,7 +40,7 @@ void cThread::Run() {
}
int cThread::ThreadFunc(void* UserData) {
- // The sfThread instance is stored in the user data
+ // The cThread instance is stored in the user data
cThread* ThreadToRun = reinterpret_cast(UserData);
// Forward to the instance
diff --git a/src/system/cthread.hpp b/src/system/cthread.hpp
index 688aba720..a65f611b1 100755
--- a/src/system/cthread.hpp
+++ b/src/system/cthread.hpp
@@ -14,7 +14,7 @@ class EE_API cThread {
virtual ~cThread();
/** Launch the thread */
- void Launch();
+ virtual void Launch();
/** Wait the thread until end */
void Wait();
diff --git a/src/test/ee.cpp b/src/test/ee.cpp
index fa1825920..41b5e96c0 100644
--- a/src/test/ee.cpp
+++ b/src/test/ee.cpp
@@ -171,6 +171,8 @@ class cEETest : private cThread {
eeInt mHeight;
std::wstring mBuda;
+
+ cTextureLoader * mTexLoader;
};
@@ -346,6 +348,10 @@ void cEETest::Init() {
mBuda = L"El mono ve el pez en el agua y sufre. Piensa que su mundo es el único que existe, el mejor, el real. Sufre porque es bueno y tiene compasión, lo ve y piensa: \"Pobre se está ahogando no puede respirar\". Y lo saca, lo saca y se queda tranquilo, por fin lo salvé. Pero el pez se retuerce de dolor y muere. Por eso te mostré el sueño, es imposible meter el mar en tu cabeza, que es un balde.\nPowered by Text Shrinker =)";
TTF.ShrinkText( mBuda, 400 );
+ mTexLoader = new cTextureLoader( MyPath + "data/test.jpg" );
+ mTexLoader->Threaded(true);
+ mTexLoader->Load();
+
Launch();
} else {
cout << "Failed to start EE++" << endl;
@@ -686,6 +692,14 @@ void cEETest::Screen3() {
}
void cEETest::Render() {
+ mTexLoader->Update();
+
+ if ( mTexLoader->IsLoaded() ) {
+ cTexture * TexLoaded = TF->GetTexture( mTexLoader->TexId() );
+
+ TexLoaded->Draw( 0, 0 );
+ }
+
HWidth = EE->GetWidth() * 0.5f;
HHeight = EE->GetHeight() * 0.5f;
@@ -942,6 +956,8 @@ void cEETest::Process() {
}
void cEETest::End() {
+ delete mTexLoader;
+
Wait();
Mus.Stop();
diff --git a/src/window/cengine.cpp b/src/window/cengine.cpp
index d8a7b5d31..2f09f477c 100755
--- a/src/window/cengine.cpp
+++ b/src/window/cengine.cpp
@@ -212,11 +212,11 @@ bool cEngine::Init(const Uint32& Width, const Uint32& Height, const Uint8& BitCo
SetWindowCaption("EEPP");
- cLog::Instance()->Write( "Engine Initialized Succesfully.\nGL Vendor: " + GetVendor() + "\nGL Renderer: " + GetRenderer() + "\nGL Version: " + GetVersion() );
+ cLog::instance()->Write( "Engine Initialized Succesfully.\nGL Vendor: " + GetVendor() + "\nGL Renderer: " + GetRenderer() + "\nGL Version: " + GetVersion() );
mInit = true;
return true;
} catch (...) {
- cLog::Instance()->Write( "Error on cEngine::Init" );
+ cLog::instance()->Write( "Error on cEngine::Init" );
return false;
}
}