Added PVR support ( but i need to rework the texture loader, it's horrible ).

Fixed a minor memory leak.
This commit is contained in:
Martín Lucas Golini
2013-01-25 02:29:19 -03:00
parent 67fbab0e15
commit ced581742c
6 changed files with 91 additions and 34 deletions
+3 -1
View File
@@ -114,10 +114,12 @@ class EE_API cTextureLoader : public cObjectLoader {
private:
bool mTexLoaded;
bool mIsDDS;
int mIsDDSCompressed;
bool mIsPVR;
int mIsCompressed;
cTimeElapsed mTE;
void LoadFile();
void LoadFromPath();
void LoadFromMemory();
void LoadFromPack();
+2 -2
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by Qt Creator 2.6.1, 2013-01-25T00:06:43. -->
<!-- Written by Qt Creator 2.6.1, 2013-01-25T02:27:57. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
@@ -48,7 +48,7 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">{388e5431-b31b-42b3-b9ad-9002d279d75d}</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">10</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
@@ -14,4 +14,3 @@ cGlobalTextureAtlas::~cGlobalTextureAtlas() {
}
}}
+85 -29
View File
@@ -15,6 +15,8 @@
namespace EE { namespace Graphics {
/** @TODO: Fix the cTextureLoader mess. */
namespace IOCb
{
// stb_image callbacks that operate on a cIOStream
@@ -81,7 +83,8 @@ cTextureLoader::cTextureLoader( cIOStream& Stream,
mColorKey(NULL),
mTexLoaded(false),
mIsDDS(false),
mIsDDSCompressed(0)
mIsPVR(false),
mIsCompressed(0)
{
}
cTextureLoader::cTextureLoader( const std::string& Filepath,
@@ -110,7 +113,8 @@ cTextureLoader::cTextureLoader( const std::string& Filepath,
mColorKey(NULL),
mTexLoaded(false),
mIsDDS(false),
mIsDDSCompressed(0)
mIsPVR(false),
mIsCompressed(0)
{
}
@@ -141,7 +145,8 @@ cTextureLoader::cTextureLoader( const unsigned char * ImagePtr,
mColorKey(NULL),
mTexLoaded(false),
mIsDDS(false),
mIsDDSCompressed(0)
mIsPVR(false),
mIsCompressed(0)
{
}
@@ -172,7 +177,8 @@ cTextureLoader::cTextureLoader( cPack * Pack,
mColorKey(NULL),
mTexLoaded(false),
mIsDDS(false),
mIsDDSCompressed(0)
mIsPVR(false),
mIsCompressed(0)
{
}
@@ -206,7 +212,8 @@ cTextureLoader::cTextureLoader( const unsigned char * Pixels,
mColorKey(NULL),
mTexLoaded(false),
mIsDDS(false),
mIsDDSCompressed(0)
mIsPVR(false),
mIsCompressed(0)
{
}
@@ -237,21 +244,37 @@ void cTextureLoader::Start() {
LoadFromPixels();
}
void cTextureLoader::LoadFile() {
cIOStreamFile fs( mFilepath , std::ios::in | std::ios::binary );
mSize = FileSystem::FileSize( mFilepath );
mPixels = (Uint8*) eeMalloc( mSize );
fs.Read( reinterpret_cast<char*> ( mPixels ), mSize );
}
void cTextureLoader::LoadFromPath() {
if ( FileSystem::FileExists( mFilepath ) ) {
if ( GLi->IsExtension( EEGL_EXT_texture_compression_s3tc ) )
mIsDDS = 0 != stbi_dds_test_filename( mFilepath.c_str() );
if ( !mIsDDS )
mIsPVR = 0 != stbi_pvr_test_filename( mFilepath.c_str() );
if ( mIsDDS ) {
cIOStreamFile fs( mFilepath , std::ios::in | std::ios::binary );
mSize = FileSystem::FileSize( mFilepath );
mPixels = (Uint8*) eeMalloc( mSize );
fs.Read( reinterpret_cast<char*> ( mPixels ), mSize );
stbi_dds_info_from_memory( mPixels, mSize, &mImgWidth, &mImgHeight, &mChannels, &mIsDDSCompressed );
LoadFile();
stbi_dds_info_from_memory( mPixels, mSize, &mImgWidth, &mImgHeight, &mChannels, &mIsCompressed );
} else if ( mIsPVR ) {
// If the PVR is valid, and the pvrtc extension is present or it's not compressed ( so it doesn't need the extension )
// means that it can be upload directly to the GPU.
if ( stbi_pvr_info_from_path( mFilepath.c_str(), &mImgWidth, &mImgHeight, &mChannels, &mIsCompressed ) &&
( !mIsCompressed || GLi->IsExtension( EEGL_IMG_texture_compression_pvrtc ) ) )
{
LoadFile();
stbi_pvr_info_from_memory( mPixels, mSize, &mImgWidth, &mImgHeight, &mChannels, &mIsCompressed );
} else {
mIsPVR = false;
mPixels = stbi_load( mFilepath.c_str(), &mImgWidth, &mImgHeight, &mChannels, STBI_default );
}
} else {
mPixels = stbi_load( mFilepath.c_str(), &mImgWidth, &mImgHeight, &mChannels, STBI_default );
}
@@ -259,13 +282,11 @@ void cTextureLoader::LoadFromPath() {
if ( NULL == mPixels ) {
cLog::instance()->Write( "Filed to load: " + mFilepath + " Reason: " + std::string( stbi_failure_reason() ) );
if ( !mIsDDS ) {
if ( !mIsDDS && !mIsPVR ) {
mPixels = jpgd::decompress_jpeg_image_from_file( mFilepath.c_str(), &mImgWidth, &mImgHeight, &mChannels, 3 );
if ( NULL != mPixels ) {
cLog::instance()->Write( "Loaded: " + mFilepath + " using jpeg-compressor." );
} else {
}
}
}
@@ -295,10 +316,23 @@ void cTextureLoader::LoadFromMemory() {
if ( GLi->IsExtension( EEGL_EXT_texture_compression_s3tc ) )
mIsDDS = 0 != stbi_dds_test_memory( mImagePtr, mSize );
if ( !mIsDDS )
mIsPVR = 0 != stbi_pvr_test_memory( mImagePtr, mSize );
if ( mIsDDS ) {
mPixels = (Uint8*) eeMalloc( mSize );
memcpy( mPixels, mImagePtr, mSize );
stbi_dds_info_from_memory( mPixels, mSize, &mImgWidth, &mImgHeight, &mChannels, &mIsDDSCompressed );
stbi_dds_info_from_memory( mPixels, mSize, &mImgWidth, &mImgHeight, &mChannels, &mIsCompressed );
} else if ( mIsPVR ) {
if ( stbi_pvr_info_from_memory( mImagePtr, mSize, &mImgWidth, &mImgHeight, &mChannels, &mIsCompressed ) &&
( !mIsCompressed || GLi->IsExtension( EEGL_IMG_texture_compression_pvrtc ) ) )
{
mPixels = (Uint8*) eeMalloc( mSize );
memcpy( mPixels, mImagePtr, mSize );
} else {
mIsPVR = false;
mPixels = stbi_load_from_memory( mImagePtr, mSize, &mImgWidth, &mImgHeight, &mChannels, STBI_default );
}
} else {
mPixels = stbi_load_from_memory( mImagePtr, mSize, &mImgWidth, &mImgHeight, &mChannels, STBI_default );
}
@@ -306,7 +340,7 @@ void cTextureLoader::LoadFromMemory() {
if ( NULL == mPixels ) {
cLog::instance()->Write( stbi_failure_reason() );
if ( !mIsDDS ) {
if ( !mIsDDS && !mIsPVR ) {
mPixels = jpgd::decompress_jpeg_image_from_memory( mImagePtr, mSize, &mImgWidth, &mImgHeight, &mChannels, 3 );
if ( NULL != mPixels ) {
@@ -328,15 +362,33 @@ void cTextureLoader::LoadFromStream() {
if ( GLi->IsExtension( EEGL_EXT_texture_compression_s3tc ) )
mIsDDS = 0 != stbi_dds_test_callbacks( &callbacks, mStream );
if ( !mIsDDS )
mIsPVR = 0 != stbi_pvr_test_callbacks( &callbacks, mStream );
if ( mIsDDS ) {
mSize = mStream->GetSize();
mPixels = (Uint8*) eeMalloc( mSize );
mStream->Seek( 0 );
mStream->Read( reinterpret_cast<char*> ( mPixels ), mSize );
mStream->Seek( 0 );
stbi_dds_info_from_callbacks( &callbacks, mStream, &mImgWidth, &mImgHeight, &mChannels, &mIsDDSCompressed );
stbi_dds_info_from_callbacks( &callbacks, mStream, &mImgWidth, &mImgHeight, &mChannels, &mIsCompressed );
mStream->Seek( 0 );
} else if ( mIsPVR ) {
// If the PVR is valid, and the pvrtc extension is present or it's not compressed ( so it doesn't need the extension )
// means that it can be upload directly to the GPU.
if ( stbi_pvr_info_from_callbacks( &callbacks, mStream, &mImgWidth, &mImgHeight, &mChannels, &mIsCompressed ) &&
( !mIsCompressed || GLi->IsExtension( EEGL_IMG_texture_compression_pvrtc ) ) )
{
mSize = mStream->GetSize();
mPixels = (Uint8*) eeMalloc( mSize );
mStream->Seek( 0 );
mStream->Read( reinterpret_cast<char*> ( mPixels ), mSize );
mStream->Seek( 0 );
} else {
mIsPVR = false;
mPixels = stbi_load( mFilepath.c_str(), &mImgWidth, &mImgHeight, &mChannels, STBI_default );
}
mStream->Seek( 0 );
} else {
mStream->Seek( 0 );
@@ -347,7 +399,7 @@ void cTextureLoader::LoadFromStream() {
if ( NULL == mPixels ) {
cLog::instance()->Write( stbi_failure_reason() );
if ( !mIsDDS ) {
if ( !mIsDDS && !mIsPVR ) {
jpeg::jpeg_decoder_stream_steam stream( mStream );
mPixels = jpgd::decompress_jpeg_image_from_stream( &stream, &mImgWidth, &mImgHeight, &mChannels, 3 );
@@ -373,15 +425,18 @@ void cTextureLoader::LoadFromPixels() {
GLint PreviousTexture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture);
if ( mIsDDS )
if ( mIsDDS ) {
tTexId = SOIL_direct_load_DDS_from_memory( mPixels, mSize, SOIL_CREATE_NEW_ID, flags, 0 );
else
} else if ( mIsPVR ) {
tTexId = SOIL_direct_load_PVR_from_memory( mPixels, mSize, SOIL_CREATE_NEW_ID, flags, 0 );
} else {
tTexId = SOIL_create_OGL_texture( mPixels, &width, &height, mChannels, SOIL_CREATE_NEW_ID, flags );
}
glBindTexture(GL_TEXTURE_2D, PreviousTexture);
if ( tTexId ) {
if ( mIsDDS && mIsDDSCompressed && mSize > 128 ) {
if ( mIsDDS && mIsCompressed && mSize > 128 ) {
mSize -= 128; // Remove the header size
} else {
mWidth = width;
@@ -389,7 +444,7 @@ void cTextureLoader::LoadFromPixels() {
mSize = mWidth * mHeight * mChannels;
}
mTexId = cTextureFactory::instance()->PushTexture( mFilepath, tTexId, mImgWidth, mImgHeight, width, height, mMipmap, mChannels, mClampMode, mCompressTexture || mIsDDSCompressed, mLocalCopy, mSize );
mTexId = cTextureFactory::instance()->PushTexture( mFilepath, tTexId, mImgWidth, mImgHeight, width, height, mMipmap, mChannels, mClampMode, mCompressTexture || mIsCompressed, mLocalCopy, mSize );
cLog::instance()->Write( "Texture " + mFilepath + " loaded in " + String::ToStr( mTE.Elapsed() ) + " ms." );
@@ -400,7 +455,7 @@ void cTextureLoader::LoadFromPixels() {
}
if ( TEX_LT_PIXELS != mLoadType ) {
if ( mIsDDS ) {
if ( mIsDDS || mIsPVR ) {
eeFree( mPixels );
} else {
if ( mPixels )
@@ -471,7 +526,8 @@ void cTextureLoader::Reset() {
mSize = 0;
mTexLoaded = false;
mIsDDS = false;
mIsDDSCompressed = 0;
mIsPVR = false;
mIsCompressed = 0;
}
}}
-1
View File
@@ -12,7 +12,6 @@ SINGLETON_DECLARE_IMPLEMENTATION(cPhysicsManager)
cPhysicsManager::cPhysicsManager() :
mMemoryManager( false )
{
cpInitChipmunk();
}
cPhysicsManager::~cPhysicsManager() {
+1
View File
@@ -47,6 +47,7 @@ cEngine::cEngine() :
mBackend( NULL ),
mWindow( NULL )
{
cTextureAtlasManager::CreateSingleton();
}
cEngine::~cEngine() {