diff --git a/Makefile.macosx b/Makefile.macosx
new file mode 100644
index 000000000..f91616707
--- /dev/null
+++ b/Makefile.macosx
@@ -0,0 +1,135 @@
+ifeq ($(DEBUGBUILD), yes)
+ DEBUGFLAGS = -g -DDEBUG -DEE_DEBUG
+else
+ DEBUGFLAGS = -O2 -s -DNDEBUG
+endif
+
+ifeq ($(STATIC), no)
+ BUILDFLAGS = -fPIC
+ LINKFLAGS = -shared
+else
+ BUILDFLAGS =
+ LINKFLAGS =
+endif
+
+export CC = gcc
+export CPP = g++
+
+ifeq ($(LLVM_BUILD), yes)
+export CC = llvm-gcc
+export CPP = llvm-g++
+endif
+
+export CFLAGS = -Wall $(DEBUGFLAGS) $(BUILDFLAGS)
+export CFLAGSEXT = $(DEBUGFLAGS) $(BUILDFLAGS)
+export LDFLAGS = $(LINKFLAGS)
+export LIBPATH = ./
+export VERSION = 0.6svn
+export CP = cp
+export LN = ln
+export LNFLAGS = -s -f
+export AR = ar
+export ARFLAGS = rcs
+export DESTDIR = /usr
+export DESTLIBDIR = $(DESTDIR)/lib
+export DESTINCDIR = $(DESTDIR)/include
+
+EXE = eetest
+EXEIV = eeiv
+
+SRCGLEW = $(wildcard ./src/helper/glew/*.c)
+SRCSOIL = $(wildcard ./src/helper/SOIL/*.c)
+SRCSTBVORBIS = $(wildcard ./src/helper/stb_vorbis/*.c)
+SRCHAIKUTTF = $(wildcard ./src/helper/haikuttf/*.cpp)
+SRCZIPUTILS = $(wildcard ./src/helper/zip_utils/*.cpp)
+
+SRCAUDIO = $(wildcard ./src/audio/*.cpp)
+SRCGAMING = $(wildcard ./src/gaming/*.cpp)
+SRCGRAPHICS = $(wildcard ./src/graphics/*.cpp)
+SRCMATH = $(wildcard ./src/math/*.cpp)
+SRCSYSTEM = $(wildcard ./src/system/*.cpp)
+SRCUI = $(wildcard ./src/ui/*.cpp)
+SRCUTILS = $(wildcard ./src/utils/*.cpp)
+SRCWINDOW = $(wildcard ./src/window/*.cpp)
+
+SRCTEST = $(wildcard ./src/test/*.cpp)
+SRCEEIV = $(wildcard ./src/eeiv/*.cpp)
+
+OBJGLEW = $(SRCGLEW:.c=.o)
+OBJHAIKUTTF = $(SRCHAIKUTTF:.cpp=.o)
+OBJSOIL = $(SRCSOIL:.c=.o)
+OBJSTBVORBIS = $(SRCSTBVORBIS:.c=.o)
+OBJZIPUTILS = $(SRCZIPUTILS:.cpp=.o)
+
+OBJAUDIO = $(SRCAUDIO:.cpp=.o)
+OBJGAMING = $(SRCGAMING:.cpp=.o)
+OBJGRAPHICS = $(SRCGRAPHICS:.cpp=.o)
+OBJMATH = $(SRCMATH:.cpp=.o)
+OBJSYSTEM = $(SRCSYSTEM:.cpp=.o)
+OBJUI = $(SRCUI:.cpp=.o)
+OBJUTILS = $(SRCUTILS:.cpp=.o)
+OBJWINDOW = $(SRCWINDOW:.cpp=.o)
+
+OBJHELPERS = $(OBJGLEW) $(OBJHAIKUTTF) $(OBJSOIL) $(OBJSTBVORBIS) $(OBJZIPUTILS)
+OBJMODULES = $(OBJUTILS) $(OBJMATH) $(OBJSYSTEM) $(OBJAUDIO) $(OBJWINDOW) $(OBJGRAPHICS) $(OBJGAMING) $(OBJUI)
+
+OBJTEST = $(SRCTEST:.cpp=.o)
+OBJEEIV = $(SRCEEIV:.cpp=.o)
+
+ifeq ($(STATIC), yes)
+ LIB = libeepp-s.a
+ LIBNAME = $(LIBPATH)/$(LIB)
+ INSTALL =
+else
+ LIB = libeepp.so
+ LIBNAME = $(LIBPATH)/$(LIB).$(VERSION)
+ INSTALL = && $(LN) $(LNFLAGS) $(DESTLIBDIR)/$(LIB).$(VERSION) $(DESTLIBDIR)/$(LIB)
+endif
+
+all: $(LIB)
+
+libeepp-s.a: $(OBJHELPERS) $(OBJMODULES)
+ $(AR) $(ARFLAGS) $(LIBNAME) $(OBJHELPERS) $(OBJMODULES)
+
+libeepp.so: $(OBJHELPERS) $(OBJMODULES)
+ $(CPP) $(LDFLAGS) -Wl,-soname,$(LIB).$(VERSION) -o $(LIBNAME) $(OBJHELPERS) $(OBJMODULES)-lfreetype -lSDL -lsndfile -framework OpenGL -framework GLUT -framework OpenAL -framework Cocoa -framework CoreFoundation
+
+$(OBJMODULES) $(OBJZIPUTILS) $(OBJHAIKUTTF): %.o: %.cpp
+ $(CPP) -o $@ -c $< $(CFLAGS) -I/usr/include/freetype2
+
+$(OBJGLEW) $(OBJSOIL) $(OBJSTBVORBIS): %.o: %.c
+ $(CC) -o $@ -c $< $(CFLAGSEXT) -DSTBI_FAILURE_USERMSG -I/usr/include/freetype2
+
+test: $(EXE)
+
+$(EXE): $(OBJHELPERS) $(OBJMODULES) $(OBJTEST)
+ $(CPP) -o ./$(EXE) $(OBJHELPERS) $(OBJMODULES) $(OBJTEST) $(LDFLAGS) -lfreetype -lSDL -lSDLmain -lsndfile -framework OpenGL -framework GLUT -framework OpenAL -framework Cocoa -framework CoreFoundation
+
+$(OBJTEST): %.o: %.cpp
+ $(CPP) -o $@ -c $< $(CFLAGS) -I/usr/include/freetype2
+
+eeiv: $(EXEIV)
+
+$(EXEIV): $(OBJHELPERS) $(OBJMODULES) $(OBJEEIV)
+ $(CPP) -o ./$(EXEIV) $(OBJHELPERS) $(OBJMODULES) $(OBJEEIV) $(LDFLAGS) -lfreetype -lSDL -lSDLmain -lsndfile -framework OpenGL -framework GLUT -framework OpenAL -framework Cocoa -framework CoreFoundation
+
+$(OBJEEIV): %.o: %.cpp
+ $(CPP) -o $@ -c $< $(CFLAGS) -I/usr/include/freetype2
+
+docs:
+ doxygen ./Doxyfile
+
+clean:
+ @rm -rf $(OBJHELPERS) $(OBJMODULES) $(OBJTEST) $(OBJEEIV)
+
+cleantemp:
+ @rm -rf $(OBJMODULES) $(OBJTEST) $(OBJEEIV)
+
+cleanall: clean
+ @rm -rf $(LIBNAME)
+ @rm -rf ./$(EXE)
+ @rm -rf ./$(EXEIV)
+ @rm -rf ./log.log
+
+install:
+ @($(CP) $(LIBNAME) $(DESTLIBDIR) $(INSTALL))
diff --git a/ee.linux.cbp b/ee.linux.cbp
index aa707598e..706f500b7 100644
--- a/ee.linux.cbp
+++ b/ee.linux.cbp
@@ -86,6 +86,8 @@
+
+
@@ -164,7 +166,7 @@
-
+
diff --git a/ee.win.cbp b/ee.win.cbp
index 7a457304e..c0577e81f 100644
--- a/ee.win.cbp
+++ b/ee.win.cbp
@@ -12,7 +12,6 @@
-
@@ -86,6 +85,8 @@
+
+
@@ -164,7 +165,7 @@
-
+
diff --git a/src/audio/csoundfiledefault.cpp b/src/audio/csoundfiledefault.cpp
index d5f24cb6b..144df3509 100755
--- a/src/audio/csoundfiledefault.cpp
+++ b/src/audio/csoundfiledefault.cpp
@@ -1,6 +1,7 @@
-#include "csoundfiledefault.hpp"
#ifndef EE_NO_SNDFILE
+#include "csoundfiledefault.hpp"
+
namespace EE { namespace Audio {
cSoundFileDefault::cSoundFileDefault() :
diff --git a/src/audio/csoundfiledefault.hpp b/src/audio/csoundfiledefault.hpp
index 583bf25eb..c62ed3608 100755
--- a/src/audio/csoundfiledefault.hpp
+++ b/src/audio/csoundfiledefault.hpp
@@ -1,8 +1,8 @@
+#ifndef EE_NO_SNDFILE
+
#ifndef EE_AUDIOCSOUNDFILEDEFAULT_H
#define EE_AUDIOCSOUNDFILEDEFAULT_H
-#ifndef EE_NO_SNDFILE
-
#include "base.hpp"
#include
#include "csoundfile.hpp"
diff --git a/src/audio/openal.hpp b/src/audio/openal.hpp
index 252949c78..1b94a2792 100755
--- a/src/audio/openal.hpp
+++ b/src/audio/openal.hpp
@@ -1,8 +1,14 @@
#ifndef EE_OPENAL_H
#define EE_OPENAL_H
+#if EE_PLATFORM == EE_PLATFORM_APPLE
+#include
+#include
+#else
#include
#include
+#endif
+
#include
#include
diff --git a/src/graphics/cimage.cpp b/src/graphics/cimage.cpp
new file mode 100644
index 000000000..5194cfd46
--- /dev/null
+++ b/src/graphics/cimage.cpp
@@ -0,0 +1,143 @@
+#include "cimage.hpp"
+
+namespace EE { namespace Graphics {
+
+cImage::cImage() :
+ mPixels(NULL),
+ mWidth(0),
+ mHeight(0),
+ mChannels(0),
+ mSize(0)
+{
+}
+
+cImage::cImage( const Uint8* data, const eeUint& Width, const eeUint& Height, const eeUint& Channels ) :
+ mPixels(NULL),
+ mWidth(Width),
+ mHeight(Height),
+ mChannels(Channels),
+ mSize(0)
+{
+ SetPixels( data );
+}
+
+cImage::cImage( const Uint32& Width, const Uint32& Height, const Uint32& Channels ) :
+ mPixels(NULL),
+ mWidth(Width),
+ mHeight(Height),
+ mChannels(Channels),
+ mSize(0)
+{
+ Create( Width, Height, Channels );
+}
+
+cImage::~cImage() {
+ ClearCache();
+}
+
+const Uint8* cImage::GetPixelsPtr() {
+ return reinterpret_cast (&mPixels[0]);
+}
+
+eeColorA cImage::GetPixel( const eeUint& x, const eeUint& y ) {
+ if ( mPixels == NULL || x > mWidth || y > mHeight ) {
+ return eeColorA::Black;
+ }
+
+ eeUint Pos = ( x + y * mWidth ) * mChannels;
+
+ if ( 4 == mChannels )
+ return eeColorA( mPixels[ Pos ], mPixels[ Pos + 1 ], mPixels[ Pos + 2 ], mPixels[ Pos + 3 ] );
+ else if ( 3 == mChannels )
+ return eeColorA( mPixels[ Pos ], mPixels[ Pos + 1 ], mPixels[ Pos + 2 ], 255 );
+ else if ( 2 == mChannels )
+ return eeColorA( mPixels[ Pos ], mPixels[ Pos + 1 ], 255, 255 );
+ else
+ return eeColorA( mPixels[ Pos ], 255, 255, 255 );
+}
+
+void cImage::SetPixel(const eeUint& x, const eeUint& y, const eeColorA& Color) {
+ if ( mPixels == NULL || x > mWidth || y > mHeight ) {
+ return;
+ }
+
+ eeUint Pos = ( x + y * mWidth ) * mChannels;
+
+ if ( mChannels >= 1 ) mPixels[ Pos ] = Color.R();
+ if ( mChannels >= 2 ) mPixels[ Pos + 1 ] = Color.G();
+ if ( mChannels >= 3 ) mPixels[ Pos + 2 ] = Color.B();
+ if ( mChannels >= 4 ) mPixels[ Pos + 3 ] = Color.A();
+}
+
+void cImage::Create( const Uint32& Width, const Uint32& Height, const Uint32& Channels ) {
+ mWidth = Width;
+ mHeight = Height;
+ mChannels = Channels;
+
+ Allocate( mWidth * mHeight * mChannels );
+}
+
+void cImage::SetPixels( const Uint8* data ) {
+ if ( data != NULL ) {
+ eeUint size = (eeUint)mWidth * (eeUint)mHeight * mChannels;
+
+ Allocate( size );
+
+ memcpy( reinterpret_cast( &mPixels[0] ), reinterpret_cast ( data ), size );
+ }
+}
+
+Uint8* cImage::GetPixels() const {
+ return mPixels;
+}
+
+void cImage::Allocate( const Uint32& size ) {
+ ClearCache();
+
+ mPixels = new unsigned char[ size ];
+ mSize = size;
+}
+
+eeUint cImage::Size() const {
+ return mSize;
+}
+
+void cImage::ClearCache() {
+ eeSAFE_DELETE_ARRAY( mPixels );
+}
+
+void cImage::Width( const eeUint& width ) {
+ mWidth = width;
+}
+
+eeUint cImage::Width() const {
+ return mWidth;
+}
+
+void cImage::Height( const eeUint& height ) {
+ mHeight = height;
+}
+
+eeUint cImage::Height() const {
+ return mHeight;
+}
+
+void cImage::Channels( const eeUint& channels ) {
+ mChannels = channels;
+}
+
+eeUint cImage::Channels() const {
+ return mChannels;
+}
+
+bool cImage::SaveToFile( const std::string& filepath, const EE_SAVETYPE& Format ) {
+ bool Res = false;
+
+ if ( NULL != mPixels && 0 != mWidth && 0 != mHeight && 0 != mChannels ) {
+ Res = 0 != ( SOIL_save_image ( filepath.c_str(), Format, (Int32)mWidth, (Int32)mHeight, mChannels, GetPixelsPtr() ) );
+ }
+
+ return Res;
+}
+
+}}
diff --git a/src/graphics/cimage.hpp b/src/graphics/cimage.hpp
new file mode 100644
index 000000000..24b449908
--- /dev/null
+++ b/src/graphics/cimage.hpp
@@ -0,0 +1,76 @@
+#ifndef EE_GRAPHICSCIMAGE_HPP
+#define EE_GRAPHICSCIMAGE_HPP
+
+#include "base.hpp"
+
+namespace EE { namespace Graphics {
+
+class cImage {
+ public:
+ cImage();
+
+ /** Copy a image data to create the image */
+ cImage( const Uint8* data, const eeUint& Width, const eeUint& Height, const eeUint& Channels );
+
+ /** Create an empty image */
+ cImage( const Uint32& Width, const Uint32& Height, const Uint32& Channels );
+
+ virtual ~cImage();
+
+ /** Create an empty image data */
+ void Create( const Uint32& Width, const Uint32& Height, const Uint32& Channels );
+
+ /** Return the pixel color from the image. \n You must have a copy of the image on local memory. For that you need to Lock the image first. */
+ virtual eeColorA GetPixel(const eeUint& x, const eeUint& y);
+
+ /** Set the pixel color to the image. \n You must have a copy of the image on local memory. For that you need to Lock the image first. */
+ virtual void SetPixel(const eeUint& x, const eeUint& y, const eeColorA& Color);
+
+ /** Assign a new array of pixels to the image in local memory ( it has to be exactly of the same size of the image ) */
+ virtual void SetPixels( const Uint8* data );
+
+ /** @return A pointer to the first pixel of the image. */
+ virtual const Uint8* GetPixelsPtr();
+
+ /** Return the pointer to the array containing the image */
+ Uint8 * GetPixels() const;
+
+ /** Set the image Width */
+ void Width( const eeUint& width );
+
+ /** @return The image Width */
+ eeUint Width() const;
+
+ /** Set the image Height */
+ void Height( const eeUint& height );
+
+ /** @return The image Height */
+ eeUint Height() const;
+
+ /** @return The number of channels used by the image */
+ eeUint Channels() const;
+
+ /** Set the number of channels of the image */
+ void Channels( const eeUint& channels );
+
+ /** Clears the current image cache if exists */
+ void ClearCache();
+
+ /** @return The Image Size on Memory (in bytes) */
+ eeUint Size() const;
+
+ /** Save the Image to a new File in a specific format */
+ virtual bool SaveToFile( const std::string& filepath, const EE_SAVETYPE& Format );
+ protected:
+ Uint8 * mPixels;
+ eeUint mWidth;
+ eeUint mHeight;
+ eeUint mChannels;
+ Uint32 mSize;
+
+ void Allocate( const Uint32& size );
+};
+
+}}
+
+#endif
diff --git a/src/graphics/cparticlesystem.cpp b/src/graphics/cparticlesystem.cpp
index b4c3c2a76..cfc23fafc 100755
--- a/src/graphics/cparticlesystem.cpp
+++ b/src/graphics/cparticlesystem.cpp
@@ -34,7 +34,7 @@ void cParticleSystem::Create(const EE_PARTICLE_EFFECT& Effect, const Uint32& Num
mSize = PartSize;
mHSize = mSize * 0.5f;
-
+
mAlphaDecay = AlphaDecay;
mXSpeed = XSpeed;
mYSpeed = YSpeed;
@@ -241,41 +241,41 @@ void cParticleSystem::Draw() {
glEnable( GL_POINT_SPRITE_ARB );
glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
glPointSize( mSize );
-
+
glColorPointer( 4, GL_FLOAT, sizeof(cParticle), reinterpret_cast( &mParticle[0] ) + sizeof(eeFloat) * 2 );
glVertexPointer( 2, GL_FLOAT, sizeof(cParticle), reinterpret_cast( &mParticle[0] ) );
-
+
glDrawArrays( GL_POINTS, 0, (GLsizei)mParticle.size() );
-
+
glDisable( GL_POINT_SPRITE_ARB );
} else {
+ cTexture * Tex = TF->GetTexture( mTexId );
+
+ if ( NULL == Tex )
+ return;
+
cParticle* P;
-
+
+ cBatchRenderer * BR = cGlobalBatchRenderer::instance();
+ BR->SetTexture( Tex );
+ BR->SetBlendFunc( ALPHA_BLENDONE );
+ BR->QuadsBegin();
+
for ( Uint32 i = 0; i < mParticle.size(); i++ ) {
P = &mParticle[i];
eeVector2f TL;
-
+
if ( P->Used() ) {
TL.x = P->X() - mHSize;
TL.y = P->Y() - mHSize;
- glBegin(GL_QUADS);
- glColor4f( P->R(), P->G(), P->B(), P->A() );
-
- glTexCoord2f(0, 0);
- glVertex2d( TL.x, TL.y );
-
- glTexCoord2f(0, 1);
- glVertex2d( TL.x, TL.y + mSize );
-
- glTexCoord2f(1, 1);
- glVertex2d( TL.x + mSize, TL.y + mSize );
-
- glTexCoord2f(1, 0);
- glVertex2d( TL.x + mSize, TL.y );
- glEnd();
+ /** FIXME: Optimize */
+ BR->QuadsSetColor( eeColorA( static_cast ( P->R() * 255 ), static_cast ( P->G() * 255 ), static_cast( P->B() * 255 ), static_cast( P->A() * 255 ) ) );
+ BR->BatchQuad( TL.x, TL.y, mSize, mSize );
}
}
+
+ BR->DrawOpt();
}
}
@@ -290,7 +290,7 @@ void cParticleSystem::Update( const eeFloat& Time ) {
P->Update(Elapsed * mTime);
// If not alive
- if ( P->A() <= 0.f || P->X() < -mSize || P->Y() < -mSize || P->X() > EE->GetWidth() || P->Y() > EE->GetHeight() ) {
+ if ( P->A() <= 0.f ) {
if ( !mLoop ) { // If not loop
if ( mLoops == 1 ) { // If left only one loop
P->Used(false);
diff --git a/src/graphics/cshader.cpp b/src/graphics/cshader.cpp
index 9b398e06b..d80e69c36 100644
--- a/src/graphics/cshader.cpp
+++ b/src/graphics/cshader.cpp
@@ -19,7 +19,7 @@ cShader::cShader( const Uint32& Type, const std::string& Filename ) {
fs.seekg ( 0, ios::end );
Int32 Length = fs.tellg();
fs.seekg ( 0, ios::beg );
- std::vector Buffer( Length + 1, 0 );
+ std::string Buffer( Length + 1, 0 );
fs.read( reinterpret_cast ( &Buffer[0] ), Length );
fs.close();
@@ -36,6 +36,20 @@ cShader::cShader( const Uint32& Type, const Uint8 * Data, const Uint32& DataSize
Compile();
}
+cShader::cShader( const Uint32& Type, cPack * Pack, const std::string& Filename ) {
+ Init( Type );
+
+ if ( NULL != Pack && Pack->IsOpen() && -1 != Pack->Exists( Filename ) ) {
+ std::vector TempData;
+
+ Pack->ExtractFileToMemory( Filename, TempData );
+
+ SetSource( reinterpret_cast ( &TempData[0] ), TempData.size() );
+ }
+
+ Compile();
+}
+
cShader::~cShader() {
if ( 0 != mGLId )
glDeleteShader( mGLId );
@@ -56,38 +70,38 @@ void cShader::Reload() {
Compile();
}
-void cShader::SetSource( const std::string& Source ) {
- std::vector _dst( Source.size(), 0 );
-
- memcpy( reinterpret_cast( &_dst[0] ), reinterpret_cast( &Source[0] ), Source.size() );
-
- SetSource( _dst );
-}
-
-void cShader::SetSource( const Uint8 * Data, const Uint32& DataSize ) {
- std::vector _dst( DataSize, 0 );
-
- memcpy( reinterpret_cast( &_dst[0] ), reinterpret_cast( &Data[0] ), DataSize );
-
- SetSource( _dst );
-}
-
-void cShader::SetSource( const std::vector& Source ) {
+void cShader::SetSource( const std::string& Source ) {
if ( IsCompiled() ) {
cLog::instance()->Write( "Can't set source for compiled shaders" );
return;
- }
+ }
- mSource = Source;
-
- const char * src = &Source[0];
+ mSource = Source;
+
+ const char * src = reinterpret_cast ( &Source[0] );
glShaderSource( mGLId, 1, &src, NULL );
}
+void cShader::SetSource( const Uint8 * Data, const Uint32& DataSize ) {
+ std::string _dst( DataSize, 0 );
+
+ memcpy( reinterpret_cast( &_dst[0] ), reinterpret_cast( &Data[0] ), DataSize );
+
+ SetSource( _dst );
+}
+
+void cShader::SetSource( const std::vector& Source ) {
+ std::string _dst( Source.size(), 0 );
+
+ memcpy( reinterpret_cast( &_dst[0] ), reinterpret_cast( &Source[0] ), Source.size() );
+
+ SetSource( _dst );
+}
+
bool cShader::Compile() {
if ( IsCompiled() ) {
- cLog::instance()->Write( " Can't compile a shader twice" );
+ cLog::instance()->Write( "Can't compile a shader twice" );
return false;
}
@@ -98,16 +112,17 @@ bool cShader::Compile() {
glGetShaderiv( GetId(), GL_COMPILE_STATUS, &Compiled );
mValid = 0 != Compiled;
- GLsizei logsize, logarraysize;
- glGetShaderiv( GetId(), GL_INFO_LOG_LENGTH, &logarraysize );
-
- mCompileLog.resize( logarraysize - 1 );
-
- glGetShaderInfoLog( GetId(), logarraysize, &logsize, reinterpret_cast( &mCompileLog[0] ) );
-
if ( !mValid ) {
+ GLsizei logsize, logarraysize;
+ glGetShaderiv( GetId(), GL_INFO_LOG_LENGTH, &logarraysize );
+
+ mCompileLog.resize( logarraysize - 1 );
+
+ glGetShaderInfoLog( GetId(), logarraysize, &logsize, reinterpret_cast( &mCompileLog[0] ) );
+
cLog::instance()->Write( "Couldn't compile shader. Log follows:" );
- cLog::instance()->Write( mCompileLog );
+ cLog::instance()->Write( mCompileLog );
+ cLog::instance()->Write( mSource );
} else {
cLog::instance()->Write( "Shader Loaded Succesfully" );
}
@@ -130,6 +145,11 @@ cVertexShader::cVertexShader( const Uint8 * Data, const Uint32& DataSize ) :
{
}
+cVertexShader::cVertexShader( cPack * Pack, const std::string& Filename ) :
+ cShader( GL_VERTEX_SHADER, Pack, Filename )
+{
+}
+
cFragmentShader::cFragmentShader() :
cShader(GL_FRAGMENT_SHADER)
{
@@ -145,4 +165,9 @@ cFragmentShader::cFragmentShader( const Uint8 * Data, const Uint32& DataSize ) :
{
}
+cFragmentShader::cFragmentShader( cPack * Pack, const std::string& Filename ) :
+ cShader( GL_FRAGMENT_SHADER, Pack, Filename )
+{
+}
+
}}
diff --git a/src/graphics/cshader.hpp b/src/graphics/cshader.hpp
index d4b18886a..09bcdec88 100644
--- a/src/graphics/cshader.hpp
+++ b/src/graphics/cshader.hpp
@@ -17,13 +17,16 @@ class EE_API cShader {
/** Create a type of shader from memory, and compile it. */
cShader( const Uint32& Type, const Uint8 * Data, const Uint32& DataSize );
+ /** Create a type of shader loaded from a pack file */
+ cShader( const Uint32& Type, cPack * Pack, const std::string& Filename );
+
virtual ~cShader();
/** Set the shader source */
void SetSource( const std::string& Source );
/** Set the shader source */
- void SetSource( const std::vector& Source );
+ void SetSource( const std::vector& Source );
/** Set the shader source */
void SetSource( const Uint8 * Data, const Uint32& DataSize );
@@ -54,7 +57,7 @@ class EE_API cShader {
bool mValid;
bool mCompiled;
std::string mCompileLog;
- std::vector mSource;
+ std::string mSource;
void Init( const Uint32& Type );
};
@@ -65,6 +68,7 @@ class EE_API cVertexShader : public cShader {
cVertexShader();
cVertexShader( const std::string& Filename );
cVertexShader( const Uint8 * Data, const Uint32& DataSize );
+ cVertexShader( cPack * Pack, const std::string& Filename );
};
/** @brief Prebuild Fragment Shader class */
@@ -73,6 +77,7 @@ class EE_API cFragmentShader : public cShader {
cFragmentShader();
cFragmentShader( const std::string& Filename );
cFragmentShader( const Uint8 * Data, const Uint32& DataSize );
+ cFragmentShader( cPack * Pack, const std::string& Filename );
};
}}
diff --git a/src/graphics/cshaderprogram.cpp b/src/graphics/cshaderprogram.cpp
index fb550d77a..3841b73ba 100644
--- a/src/graphics/cshaderprogram.cpp
+++ b/src/graphics/cshaderprogram.cpp
@@ -45,6 +45,29 @@ cShaderProgram::cShaderProgram( const std::string& VertexShaderFile, const std::
Link();
}
+cShaderProgram::cShaderProgram( cPack * Pack, const std::string& VertexShaderPath, const std::string& FragmentShaderPath, const std::string& name ) :
+ mGLId(0)
+{
+ AddToManager( name );
+ Init();
+
+ if ( NULL != Pack && Pack->IsOpen() && -1 != Pack->Exists( VertexShaderPath ) && -1 != Pack->Exists( FragmentShaderPath ) ) {
+ cVertexShader * vs = new cVertexShader( Pack, VertexShaderPath );
+ cFragmentShader * fs = new cFragmentShader( Pack, FragmentShaderPath );
+
+ if ( !vs->IsValid() || !fs->IsValid() ) {
+ eeSAFE_DELETE( vs );
+ eeSAFE_DELETE( fs );
+ return;
+ }
+
+ AddShader( vs );
+ AddShader( fs );
+
+ Link();
+ }
+}
+
cShaderProgram::cShaderProgram( const Uint8 * VertexShaderData, const Uint32& VertexShaderDataSize, const Uint8 * FragmentShaderData, const Uint32& FragmentShaderDataSize, const std::string& name ) :
mGLId(0)
{
diff --git a/src/graphics/cshaderprogram.hpp b/src/graphics/cshaderprogram.hpp
index 284760aa1..9fbdb2e3d 100644
--- a/src/graphics/cshaderprogram.hpp
+++ b/src/graphics/cshaderprogram.hpp
@@ -23,6 +23,9 @@ class EE_API cShaderProgram {
/** Constructor that creates a VertexShader from memory and a Fragment Shader from memory, and link them. */
cShaderProgram( const Uint8 * VertexShaderData, const Uint32& VertexShaderDataSize, const Uint8 * FragmentShaderData, const Uint32& FragmentShaderDataSize, const std::string& name = "" );
+ /** Constructor that creates the vertex shader and fragment shader from two files inside a pack */
+ cShaderProgram( cPack * Pack, const std::string& VertexShaderPath, const std::string& FragmentShaderPath, const std::string& name = "" );
+
virtual ~cShaderProgram();
/** Add a new shader */
diff --git a/src/graphics/ctexture.cpp b/src/graphics/ctexture.cpp
index 9f6c25a3d..0f2e812e8 100755
--- a/src/graphics/ctexture.cpp
+++ b/src/graphics/ctexture.cpp
@@ -4,23 +4,16 @@
namespace EE { namespace Graphics {
cTexture::cTexture() :
- mPixels(NULL),
+ cImage(),
mFilepath(""),
mId(0),
mTexture(0),
- mWidth(0),
- mHeight(0),
mImgWidth(0),
mImgHeight(0),
- mChannels(4),
- mMipmap(true),
- mModified(false),
- mColorKey(true),
+ mFlags(0),
+ mColorKey(eeRGB(true)),
mClampMode( EE_CLAMP_TO_EDGE ),
- mFilter( TEX_LINEAR ),
- mCompressedTexture(false),
- mLocked(false),
- mGrabed(false)
+ mFilter( TEX_LINEAR )
{
}
@@ -28,21 +21,19 @@ cTexture::cTexture( const cTexture& Copy ) :
mFilepath( Copy.mFilepath ),
mId( Copy.mId ),
mTexture( Copy.mTexture ),
- mWidth( Copy.mWidth ),
- mHeight( Copy.mHeight ),
mImgWidth( Copy.mImgWidth ),
mImgHeight( Copy.mImgHeight ),
- mChannels( Copy.mChannels ),
- mMipmap( Copy.mMipmap ),
- mModified( Copy.mModified ),
+ mFlags( Copy.mFlags ),
mColorKey( Copy.mColorKey ),
mClampMode( Copy.mClampMode ),
- mFilter( Copy.mFilter ),
- mCompressedTexture( Copy.mCompressedTexture ),
- mLocked( Copy.mLocked ),
- mGrabed ( Copy.mGrabed )
+ mFilter( Copy.mFilter )
{
- Pixels( reinterpret_cast( &Copy.mPixels[0] ) );
+ mWidth = Copy.mWidth;
+ mHeight = Copy.mHeight;
+ mChannels = Copy.mChannels;
+ mSize = Copy.mSize;
+
+ SetPixels( reinterpret_cast( &Copy.mPixels[0] ) );
}
cTexture::~cTexture() {
@@ -52,23 +43,21 @@ cTexture::~cTexture() {
cTexture& cTexture::operator =(const cTexture& Other) {
cTexture Temp(Other);
+ std::swap(mWidth, Temp.mWidth);
+ std::swap(mHeight, Temp.mHeight);
+ std::swap(mChannels, Temp.mChannels);
+ std::swap(mSize, Temp.mSize);
std::swap(mFilepath, Temp.mFilepath);
std::swap(mId, Temp.mId);
std::swap(mTexture, Temp.mTexture);
- std::swap(mWidth, Temp.mWidth);
- std::swap(mHeight, Temp.mHeight);
std::swap(mImgWidth, Temp.mImgWidth);
std::swap(mImgHeight, Temp.mImgHeight);
- std::swap(mMipmap, Temp.mMipmap);
- std::swap(mModified, Temp.mModified);
+ std::swap(mFlags, Temp.mFlags);
std::swap(mColorKey, Temp.mColorKey);
- std::swap(mLocked, Temp.mLocked);
std::swap(mFilter, Temp.mFilter);
std::swap(mClampMode, Temp.mClampMode);
- std::swap(mCompressedTexture, Temp.mCompressedTexture);
- std::swap(mGrabed, Temp.mGrabed);
- std::swap(mChannels, Temp.mChannels);
- Pixels( reinterpret_cast( &Temp.mPixels[0] ) );
+
+ SetPixels( reinterpret_cast( &Temp.mPixels[0] ) );
return *this;
}
@@ -79,54 +68,41 @@ void cTexture::DeleteTexture() {
glDeleteTextures(1, &Texture);
mTexture = 0;
- mModified = false;
- mLocked = false;
- mGrabed = false;
+ mFlags = 0;
ClearCache();
}
}
-cTexture::cTexture( const Uint32& texture, const eeInt& width, const eeInt& height, const eeInt& imgwidth, const eeInt& imgheight, const bool& UseMipmap, const eeUint& Channels, const std::string& filepath, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressedTexture, const Uint8* data ) {
- Create( texture, width, height, imgwidth, imgheight, UseMipmap, Channels, filepath, ColorKey, ClampMode, CompressedTexture, data );
+cTexture::cTexture( const Uint32& texture, const eeUint& width, const eeUint& height, const eeUint& imgwidth, const eeUint& imgheight, const bool& UseMipmap, const eeUint& Channels, const std::string& filepath, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressedTexture, const Uint32& MemSize, const Uint8* data ) {
+ Create( texture, width, height, imgwidth, imgheight, UseMipmap, Channels, filepath, ColorKey, ClampMode, CompressedTexture, MemSize, data );
}
-void cTexture::Create( const Uint32& texture, const eeInt& width, const eeInt& height, const eeInt& imgwidth, const eeInt& imgheight, const bool& UseMipmap, const eeUint& Channels, const std::string& filepath, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressedTexture, const Uint8* data ) {
- mFilepath = filepath;
- mId = MakeHash( mFilepath );
+void cTexture::Create( const Uint32& texture, const eeUint& width, const eeUint& height, const eeUint& imgwidth, const eeUint& imgheight, const bool& UseMipmap, const eeUint& Channels, const std::string& filepath, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressedTexture, const Uint32& MemSize, const Uint8* data ) {
+ mFilepath = filepath;
+ mId = MakeHash( mFilepath );
+ mTexture = texture;
+ mWidth = width;
+ mHeight = height;
+ mChannels = Channels;
+ mImgWidth = imgwidth;
+ mImgHeight = imgheight;
+ mSize = MemSize;
+ mColorKey = ColorKey;
+ mClampMode = ClampMode;
+ mFilter = TEX_LINEAR;
- mTexture = texture;
- mWidth = width;
- mHeight = height;
- mImgWidth = imgwidth;
- mImgHeight = imgheight;
- mMipmap = UseMipmap;
+ if ( UseMipmap )
+ mFlags |= TEX_FLAG_MIPMAP;
- mColorKey = ColorKey;
- mClampMode = ClampMode;
- mCompressedTexture = CompressedTexture;
- mChannels = Channels;
+ if ( CompressedTexture )
+ mFlags |= TEX_FLAG_COMPRESSED;
- mLocked = false;
- mGrabed = false;
-
- mFilter = TEX_LINEAR;
-
- Pixels(data);
+ SetPixels( data );
}
-void cTexture::Pixels( const Uint8* data ) {
- if ( data != NULL ) {
- eeUint size = (eeUint)mWidth * (eeUint)mHeight;
-
- Allocate( size );
-
- memcpy( reinterpret_cast( &mPixels[0] ), reinterpret_cast ( data ), size * mChannels );
- }
-}
-
-Uint8 * cTexture::Lock( const bool& ForceRGBA ) {
- if ( !mLocked ) {
+Uint8 * cTexture::iLock( const bool& ForceRGBA, const bool& KeepFormat ) {
+ if ( !( mFlags & TEX_FLAG_LOCKED ) ) {
if ( ForceRGBA )
mChannels = 4;
@@ -140,38 +116,51 @@ Uint8 * cTexture::Lock( const bool& ForceRGBA ) {
glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
- mWidth = (eeInt)width;
- mHeight = (eeInt)height;
- eeUint size = (eeUint)mWidth * (eeUint)mHeight;
+ mWidth = (eeUint)width;
+ mHeight = (eeUint)height;
+ GLint size = mWidth * mHeight * mChannels;
- Allocate( size );
+ if ( KeepFormat && ( mFlags & TEX_FLAG_COMPRESSED ) ) {
+ glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &mInternalFormat );
+ glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &size );
+ }
- Uint32 Channel = GL_RGBA;
+ Allocate( (eeUint)size );
- if ( 3 == mChannels )
- Channel = GL_RGB;
- else if ( 2 == mChannels )
- Channel = GL_LUMINANCE_ALPHA;
- else if ( 1 == mChannels )
- Channel = GL_ALPHA;
+ if ( KeepFormat && ( mFlags & TEX_FLAG_COMPRESSED ) ) {
+ glGetCompressedTexImage( GL_TEXTURE_2D, 0, reinterpret_cast (&mPixels[0]) );
+ } else {
+ Uint32 Channel = GL_RGBA;
- glGetTexImage( GL_TEXTURE_2D, 0, Channel, GL_UNSIGNED_BYTE, reinterpret_cast (&mPixels[0]) );
+ if ( 3 == mChannels )
+ Channel = GL_RGB;
+ else if ( 2 == mChannels )
+ Channel = GL_LUMINANCE_ALPHA;
+ else if ( 1 == mChannels )
+ Channel = GL_ALPHA;
+
+ glGetTexImage( GL_TEXTURE_2D, 0, Channel, GL_UNSIGNED_BYTE, reinterpret_cast (&mPixels[0]) );
+ }
if ( PreviousTexture != (GLint)mTexture )
glBindTexture(GL_TEXTURE_2D, PreviousTexture);
- mLocked = true;
+ mFlags |= TEX_FLAG_LOCKED;
}
return &mPixels[0];
}
+Uint8 * cTexture::Lock( const bool& ForceRGBA ) {
+ return iLock( ForceRGBA, false );
+}
+
bool cTexture::Unlock( const bool& KeepData, const bool& Modified ) {
- if ( mLocked ) {
+ if ( ( mFlags & TEX_FLAG_LOCKED ) ) {
Int32 width = 0, height = 0;
GLuint NTexId = 0;
- if ( Modified || mModified ) {
+ if ( Modified || ( mFlags & TEX_FLAG_MODIFIED ) ) {
GLint PreviousTexture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture);
@@ -181,9 +170,8 @@ bool cTexture::Unlock( const bool& KeepData, const bool& Modified ) {
glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
- Uint32 flags = mMipmap ? SOIL_FLAG_MIPMAPS : 0;
+ Uint32 flags = ( mFlags & TEX_FLAG_MIPMAP ) ? SOIL_FLAG_MIPMAPS : 0;
flags = (mClampMode == EE_CLAMP_REPEAT) ? (flags | SOIL_FLAG_TEXTURE_REPEATS) : flags;
- flags = (mCompressedTexture) ? ( flags | SOIL_FLAG_COMPRESS_TO_DXT ) : flags;
NTexId = SOIL_create_OGL_texture( reinterpret_cast(&mPixels[0]), &width, &height, mChannels, mTexture, flags );
@@ -192,14 +180,16 @@ bool cTexture::Unlock( const bool& KeepData, const bool& Modified ) {
if ( PreviousTexture != (GLint)mTexture )
glBindTexture(GL_TEXTURE_2D, PreviousTexture);
- mModified = false;
+ mFlags &= ~TEX_FLAG_MODIFIED;
+
+ if ( mFlags & TEX_FLAG_COMPRESSED )
+ mFlags &= ~TEX_FLAG_COMPRESSED;
}
- if (!KeepData) {
+ if ( !KeepData )
ClearCache();
- }
- mLocked = false;
+ mFlags &= ~TEX_FLAG_LOCKED;
if ( (eeInt)NTexId == mTexture || !Modified )
return true;
@@ -208,56 +198,31 @@ bool cTexture::Unlock( const bool& KeepData, const bool& Modified ) {
return false;
}
-const Uint8* cTexture::GetPixelsPtr() {
+const Uint8 * cTexture::GetPixelsPtr() {
if ( !LocalCopy() ) {
Lock();
Unlock(true);
}
- return reinterpret_cast (&mPixels[0]);
+ return cImage::GetPixelsPtr();
}
-eeColorA cTexture::GetPixel( const eeUint& x, const eeUint& y ) {
- if ( mPixels == NULL || (eeInt)x > mWidth || (eeInt)y > mHeight ) {
- return eeColorA::Black;
- }
+void cTexture::SetPixel( const eeUint& x, const eeUint& y, const eeColorA& Color ) {
+ cImage::SetPixel( x, y, Color );
- eeUint Pos = ( x + y * mWidth ) * mChannels;
-
- if ( 4 == mChannels )
- return eeColorA( mPixels[ Pos ], mPixels[ Pos + 1 ], mPixels[ Pos + 2 ], mPixels[ Pos + 3 ] );
- else if ( 3 == mChannels )
- return eeColorA( mPixels[ Pos ], mPixels[ Pos + 1 ], mPixels[ Pos + 2 ], 255 );
- else if ( 2 == mChannels )
- return eeColorA( mPixels[ Pos ], mPixels[ Pos + 1 ], 255, 255 );
- else
- return eeColorA( mPixels[ Pos ], 255, 255, 255 );
+ mFlags |= TEX_FLAG_MODIFIED;
}
-void cTexture::SetPixel(const eeUint& x, const eeUint& y, const eeColorA& Color) {
- if ( mPixels == NULL || (eeInt)x > mWidth || (eeInt)y > mHeight ) {
- return;
- }
-
- eeUint Pos = ( x + y * mWidth ) * mChannels;
-
- if ( mChannels >= 1 ) mPixels[ Pos ] = Color.R();
- if ( mChannels >= 2 ) mPixels[ Pos + 1 ] = Color.G();
- if ( mChannels >= 3 ) mPixels[ Pos + 2 ] = Color.B();
- if ( mChannels >= 4 ) mPixels[ Pos + 3 ] = Color.A();
-
- mModified = true;
-}
-
-bool cTexture::SaveToFile(const std::string& filepath, const EE_SAVETYPE& Format) {
+bool cTexture::SaveToFile( const std::string& filepath, const EE_SAVETYPE& Format ) {
bool Res = false;
- Lock();
+ if ( mTexture ) {
+ Lock();
- if (mTexture)
- Res = 0 != ( SOIL_save_image ( filepath.c_str(), Format, (Int32)mWidth, (Int32)mHeight, 4, GetPixelsPtr() ) );
+ Res = cImage::SaveToFile( filepath, Format );
- Unlock();
+ Unlock();
+ }
return Res;
}
@@ -275,7 +240,7 @@ void cTexture::SetTextureFilter(const EE_TEX_FILTER& filter) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (mFilter == TEX_LINEAR) ? GL_LINEAR : GL_NEAREST);
- if ( mMipmap )
+ if ( mFlags & TEX_FLAG_MIPMAP )
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (mFilter == TEX_LINEAR) ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST);
else
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (mFilter == TEX_LINEAR) ? GL_LINEAR : GL_NEAREST);
@@ -291,7 +256,7 @@ void cTexture::ReplaceColor(eeColorA ColorKey, eeColorA NewColor) {
eeUint Pos = 0;
- for ( eeInt i = 0; i < mWidth * mHeight; i++ ) {
+ for ( eeUint i = 0; i < mWidth * mHeight; i++ ) {
Pos = i * mChannels;
if ( mPixels[ Pos ] == ColorKey.R() && mPixels[ Pos + 1 ] == ColorKey.G() && mPixels[ Pos + 2 ] == ColorKey.B() && mPixels[ Pos + 3 ] == ColorKey.A() ) {
@@ -346,11 +311,6 @@ void cTexture::ApplyClampMode() {
}
}
-void cTexture::ClearCache() {
- eeSAFE_DELETE_ARRAY( mPixels );
-}
-
-
void cTexture::TexId( const Uint32& id ) {
mTexId = id;
}
@@ -359,40 +319,73 @@ const Uint32& cTexture::TexId() const {
return mTexId;
}
-void cTexture::Allocate( const Uint32& size ) {
- if ( eeARRAY_SIZE( mPixels ) != size ) {
- ClearCache();
-
- mPixels = new unsigned char[ size * mChannels ];
- }
-}
-
void cTexture::Reload() {
if ( LocalCopy() ) {
- Int32 width = mWidth;
- Int32 height = mHeight;
+ Int32 width = (Int32)mWidth;
+ Int32 height = (Int32)mHeight;
GLint PreviousTexture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture);
- Uint32 flags = mMipmap ? SOIL_FLAG_MIPMAPS : 0;
+ Uint32 flags = ( mFlags & TEX_FLAG_MIPMAP ) ? 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 );
+ if ( ( mFlags & TEX_FLAG_COMPRESSED ) ) {
+ if ( mTexture != PreviousTexture )
+ glBindTexture( GL_TEXTURE_2D, mTexture );
+
+ if ( Grabed() )
+ mTexture = SOIL_create_OGL_texture( reinterpret_cast ( &mPixels[0] ), &width, &height, mChannels, mTexture, flags | SOIL_FLAG_COMPRESS_TO_DXT );
+ else
+ glCompressedTexImage2D( mTexture, 0, mInternalFormat, width, height, 0, mSize, &mPixels[0] );
+ } else
+ mTexture = SOIL_create_OGL_texture( reinterpret_cast ( &mPixels[0] ), &width, &height, mChannels, mTexture, flags );
- glBindTexture(GL_TEXTURE_2D, PreviousTexture);
+ if ( mTexture != PreviousTexture )
+ glBindTexture(GL_TEXTURE_2D, PreviousTexture);
} else {
- Lock();
+ iLock(false,true);
Reload();
Unlock();
}
-}
+}
const Uint32& cTexture::Id() const {
return mId;
}
+void cTexture::Mipmap( const bool& UseMipmap ) {
+ if ( mFlags & TEX_FLAG_MIPMAP ) {
+ if ( !UseMipmap )
+ mFlags &= ~TEX_FLAG_MIPMAP;
+ } else {
+ if ( UseMipmap )
+ mFlags |= TEX_FLAG_MIPMAP;
+ }
+}
+
+bool cTexture::Mipmap() const {
+ return mFlags & TEX_FLAG_MIPMAP;
+}
+
+void cTexture::Grabed( const bool& isGrabed ) {
+ if ( mFlags & TEX_FLAG_GRABED ) {
+ if ( !isGrabed )
+ mFlags &= ~TEX_FLAG_GRABED;
+ } else {
+ if ( isGrabed )
+ mFlags |= TEX_FLAG_GRABED;
+ }
+}
+
+bool cTexture::Grabed() const {
+ return mFlags & TEX_FLAG_GRABED;
+}
+
+bool cTexture::Compressed() const {
+ return mFlags & TEX_FLAG_COMPRESSED;
+}
+
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) {
DrawEx( x, y, 0, 0, Angle, Scale, Color, Color, Color, Color, blend, Effect, ScaleCentered, texSector);
}
diff --git a/src/graphics/ctexture.hpp b/src/graphics/ctexture.hpp
index 57c323406..1b708a932 100755
--- a/src/graphics/ctexture.hpp
+++ b/src/graphics/ctexture.hpp
@@ -2,18 +2,28 @@
#define EE_GRAPHICSCTEXTURE_H
#include "base.hpp"
+#include "cimage.hpp"
namespace EE { namespace Graphics {
-class EE_API cTexture {
+#define TEX_FLAG_MIPMAP ( 1 << 0 )
+#define TEX_FLAG_MODIFIED ( 1 << 1 )
+#define TEX_FLAG_COMPRESSED ( 1 << 2 )
+#define TEX_FLAG_LOCKED ( 1 << 3 )
+#define TEX_FLAG_GRABED ( 1 << 4 )
+
+class EE_API cTexture : public cImage {
public:
cTexture();
- ~cTexture();
- cTexture( const Uint32& texture, const eeInt& width, const eeInt& height, const eeInt& imgwidth, const eeInt& imgheight, const bool& UseMipmap, const eeUint& Channels, const std::string& filepath, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressedTexture, const Uint8* data = NULL );
+ cTexture( const Uint32& texture, const eeUint& width, const eeUint& height, const eeUint& imgwidth, const eeUint& imgheight, const bool& UseMipmap, const eeUint& Channels, const std::string& filepath, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressedTexture, const Uint32& MemSize = 0, const Uint8* data = NULL );
+
cTexture( const cTexture& Copy );
+
cTexture& operator =(const cTexture& Other);
+ virtual ~cTexture();
+
/** Create the Texture
* @param texture The OpenGL Texture Id (texture handler)
* @param width The Texture Width
@@ -28,7 +38,7 @@ class EE_API cTexture {
* @param CompressedTexture The Texture was compressed on loading
* @param data The Texture (raw texture)
*/
- void Create( const Uint32& texture, const eeInt& width, const eeInt& height, const eeInt& imgwidth, const eeInt& imgheight, const bool& UseMipmap, const eeUint& Channels, const std::string& filepath, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressedTexture, const Uint8* data = NULL );
+ void Create( const Uint32& texture, const eeUint& width, const eeUint& height, const eeUint& imgwidth, const eeUint& imgheight, const bool& UseMipmap, const eeUint& Channels, const std::string& filepath, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressedTexture, const Uint32& MemSize = 0, const Uint8* data = NULL );
/** Set the OpenGL Texture Id (texture handler) */
void Texture( const Uint32& texture ) { mTexture = texture; }
@@ -36,9 +46,6 @@ class EE_API cTexture {
/** @return The OpenGL Texture Id (texture handler) */
Uint32 Texture() const { return mTexture; }
- /** @return The Texture Size on Memory (in bytes) */
- eeUint Size() const { return (eeUint)mWidth * (eeUint)mHeight * 4; }
-
/** @return The id of the texture ( that is the hash of the filename ) */
const Uint32& Id() const;
@@ -48,29 +55,17 @@ class EE_API cTexture {
/** @return The Texture File Path */
std::string Filepath() const { return mFilepath; }
- /** Set the Texture Width */
- void Width( const eeInt& width ) { mWidth = width; }
-
- /** @return The Texture Width */
- eeInt Width() const { return mWidth; }
-
- /** Set the Texture Height */
- void Height( const eeInt& height ) { mHeight = height; }
-
- /** @return The Texture Height */
- eeInt Height() const { return mHeight; }
-
/** @return The Image Width */
- eeInt ImgWidth() const { return mImgWidth; }
+ eeUint ImgWidth() const { return mImgWidth; }
/** @return The Image Height */
- eeInt ImgHeight() const { return mImgHeight; }
+ eeUint ImgHeight() const { return mImgHeight; }
/** Set if the Texture use Mipmaps */
- void Mipmap( const bool& UseMipmap ) { mMipmap = UseMipmap; }
+ void Mipmap( const bool& UseMipmap );
/** @return If the texture use Mipmaps */
- bool Mipmap() const { return mMipmap; }
+ bool Mipmap() const;
/** Set the Texture Color Key */
void ColorKey( const eeRGB& colorkey ) { mColorKey = colorkey; }
@@ -87,26 +82,17 @@ class EE_API cTexture {
/** Lock the Texture for direct access */
Uint8 * Lock( const bool& ForceRGBA = false );
- /** Return the pixel color from the texture. \n You must have a copy of the texture on local memory. For that you need to Lock the texture first. */
- eeColorA GetPixel(const eeUint& x, const eeUint& y);
-
- /** Set the pixel color to the texture. \n You must have a copy of the texture on local memory. For that you need to Lock the texture first. */
- void SetPixel(const eeUint& x, const eeUint& y, const eeColorA& Color);
-
/** Unlock the previously locked Texture */
bool Unlock(const bool& KeepData = false, const bool& Modified = false);
/** @return A pointer to the first pixel of the texture ( keeped with a local copy ). \n You must have a copy of the texture on local memory. For that you need to Lock the texture first. */
const Uint8* GetPixelsPtr();
- /** Assign a new array of pixels to the texture in local memory ( it has to be exactly of the same size of the texture ) */
- void Pixels( const Uint8* data );
-
/** Set the Texture Filter Mode */
void SetTextureFilter(const EE_TEX_FILTER& filter);
/** Save the Texture to a new File */
- bool SaveToFile(const std::string& filepath, const EE_SAVETYPE& Format);
+ bool SaveToFile( const std::string& filepath, const EE_SAVETYPE& Format );
/** Create an Alpha mask from a Color */
void CreateMaskFromColor(eeColorA ColorKey, Uint8 Alpha);
@@ -124,22 +110,16 @@ class EE_API cTexture {
void DeleteTexture();
/** Set if the Texture is Grabed */
- void Grabed( const bool& isGrabed ) { mGrabed = isGrabed; }
+ void Grabed( const bool& isGrabed );
/** @return If the texture is Grabed */
- bool Grabed() const { return mGrabed; }
+ bool Grabed() const;
/** @return The current texture filter */
EE_TEX_FILTER Filter() const { return mFilter; }
/** @return If the texture was compressed on load (DXT compression) */
- bool Compressed() const { return mCompressedTexture; };
-
- /** @return The number of channels used by the image */
- eeUint Channels() const { return mChannels; }
-
- /** Clears the current texture cache if exists */
- void ClearCache();
+ bool Compressed() const;
/** Render the texture on screen ( with less internal mess, a little bit faster way )
* @param x The x position on screen
@@ -221,35 +201,29 @@ class EE_API cTexture {
/** Reload the texture from the current local copy. */
void Reload();
- protected:
- Uint8 * mPixels;
+ void SetPixel( const eeUint& x, const eeUint& y, const eeColorA& Color );
+ protected:
std::string mFilepath;
Uint32 mId;
Uint32 mTexId;
GLint mTexture;
- eeInt mWidth;
- eeInt mHeight;
- eeInt mImgWidth;
- eeInt mImgHeight;
+ eeUint mImgWidth;
+ eeUint mImgHeight;
- eeUint mChannels;
-
- bool mMipmap;
- bool mModified;
+ Uint32 mFlags;
eeRGB mColorKey;
EE_CLAMP_MODE mClampMode;
EE_TEX_FILTER mFilter;
- bool mCompressedTexture;
- bool mLocked;
- bool mGrabed;
+ GLint mInternalFormat;
- void ApplyClampMode();
- void Allocate( const Uint32& size );
+ void ApplyClampMode();
+
+ Uint8 * iLock( const bool& ForceRGBA, const bool& KeepFormat );
};
}}
diff --git a/src/graphics/ctexturefactory.cpp b/src/graphics/ctexturefactory.cpp
index ba19300a5..9f163397b 100755
--- a/src/graphics/ctexturefactory.cpp
+++ b/src/graphics/ctexturefactory.cpp
@@ -50,7 +50,7 @@ Uint32 cTextureFactory::Load( const std::string& Filepath, const bool& Mipmap, c
return myTex.Id();
}
-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 ) {
+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, const Uint32& MemSize ) {
Lock();
cTexture * Tex = NULL;
@@ -68,7 +68,7 @@ Uint32 cTextureFactory::PushTexture( const std::string& Filepath, const Uint32&
Pos = FindFreeSlot();
Tex = mTextures[ Pos ] = new cTexture();
- Tex->Create( TexId, Width, Height, MyWidth, MyHeight, Mipmap, Channels, FPath, ColorKey, ClampMode, CompressTexture );
+ Tex->Create( TexId, Width, Height, MyWidth, MyHeight, Mipmap, Channels, FPath, ColorKey, ClampMode, CompressTexture, MemSize );
Tex->TexId( Pos );
if ( !ColorKey.voidRGB )
@@ -169,12 +169,21 @@ void cTextureFactory::GrabTextures() {
for ( Uint32 i = 1; i < mTextures.size(); i++ ) {
cTexture* Tex = GetTexture(i);
- if ( Tex ) {
- if ( !Tex->LocalCopy() ) {
- Tex->Lock();
- Tex->Unlock(true, false);
- Tex->Grabed(true);
- }
+ if ( Tex && !Tex->LocalCopy() ) {
+ Tex->Lock();
+ Tex->Grabed(true);
+ }
+ }
+}
+
+void cTextureFactory::UngrabTextures() {
+ for ( Uint32 i = 1; i < mTextures.size(); i++ ) {
+ cTexture* Tex = GetTexture(i);
+
+ if ( NULL != Tex && Tex->Grabed() ) {
+ Tex->Reload();
+ Tex->Unlock();
+ Tex->Grabed(false);
}
}
}
@@ -268,15 +277,20 @@ eeUint cTextureFactory::GetTexMemSize( const eeUint& TexId ) {
cTexture* Tex = mTextures[ TexId ];
if ( Tex != NULL ) {
- eeUint w = static_cast( Tex->Width() );
- eeUint h = static_cast( Tex->Height() );
- Size = ( w * h * Tex->Channels() );
+ eeUint w = Tex->Width();
+ eeUint h = Tex->Height();
+ eeUint c = Tex->Channels();
+
+ if ( 0 != Tex->Size() )
+ Size = Tex->Size();
+ else
+ Size = ( w * h * c );
if( Tex->Mipmap() ) {
- while(w > 2 && h > 2) {
+ while( w > 2 && h > 2 ) {
w>>=1;
h>>=1;
- Size += ( w * h * Tex->Channels() );
+ Size += ( w * h * c );
}
}
}
diff --git a/src/graphics/ctexturefactory.hpp b/src/graphics/ctexturefactory.hpp
index 32e6b8da2..42c051995 100755
--- a/src/graphics/ctexturefactory.hpp
+++ b/src/graphics/ctexturefactory.hpp
@@ -139,7 +139,10 @@ class EE_API cTextureFactory: public cSingleton, protected cMut
cTexture* GetTexture( const Uint32& TexId );
/** Get a local copy for all the textures */
- void GrabTextures();
+ void GrabTextures();
+
+ /** Reload all the grabed textures */
+ void UngrabTextures();
/** Allocate space for Textures (only works if EE_ALLOC_TEXTURES_ON_VECTOR is defined) */
void Allocate( const eeUint& size );
@@ -163,15 +166,16 @@ class EE_API cTextureFactory: public cSingleton, protected cMut
* @param ClampMode The Texture Clamp Mode
* @param CompressTexture The texture is compressed?
* @param LocalCopy If keep a local copy in memory of the texture
+ * @param MemSize The size of the texture in memory ( just if you need to specify the real size in memory, just usefull to calculate the total texture memory ).
*/
- 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, const Uint32& MemSize = 0 );
/** Return a texture by it file path name
* @param Name File path name
* @return The texture, NULL if not exists.
*/
cTexture * GetByName( const std::string& Name );
-
+
/** Return a texture by it hash path name
* @param Hash The file path hash
* @return The texture, NULL if not exists
@@ -190,7 +194,7 @@ class EE_API cTextureFactory: public cSingleton, protected cMut
std::vector mTextures;
eeUint mMemSize;
-
+
std::string mAppPath;
std::queue mVectorFreeSlots;
diff --git a/src/graphics/ctextureloader.cpp b/src/graphics/ctextureloader.cpp
index 3dd8c89e9..2c7175d23 100644
--- a/src/graphics/ctextureloader.cpp
+++ b/src/graphics/ctextureloader.cpp
@@ -1,5 +1,7 @@
#include "ctextureloader.hpp"
#include "ctexturefactory.hpp"
+#include "../helper/SOIL/stb_image.h"
+#include "../helper/SOIL/SOIL.h"
namespace EE { namespace Graphics {
@@ -27,7 +29,9 @@ cTextureLoader::cTextureLoader( const std::string& Filepath,
mPack(NULL),
mImagePtr(NULL),
mSize(0),
- mTexLoaded(false)
+ mTexLoaded(false),
+ mIsDDS(false),
+ mIsDDSCompressed(0)
{
}
@@ -56,7 +60,9 @@ cTextureLoader::cTextureLoader( const unsigned char * ImagePtr,
mPack(NULL),
mImagePtr(ImagePtr),
mSize(Size),
- mTexLoaded(false)
+ mTexLoaded(false),
+ mIsDDS(false),
+ mIsDDSCompressed(0)
{
}
@@ -85,7 +91,9 @@ cTextureLoader::cTextureLoader( cPack * Pack,
mPack(Pack),
mImagePtr(NULL),
mSize(0),
- mTexLoaded(false)
+ mTexLoaded(false),
+ mIsDDS(false),
+ mIsDDSCompressed(0)
{
}
@@ -117,7 +125,9 @@ cTextureLoader::cTextureLoader( const unsigned char * Pixels,
mPack(NULL),
mImagePtr(NULL),
mSize(0),
- mTexLoaded(false)
+ mTexLoaded(false),
+ mIsDDS(false),
+ mIsDDSCompressed(0)
{
}
@@ -128,7 +138,7 @@ cTextureLoader::~cTextureLoader() {
void cTextureLoader::Start() {
cObjectLoader::Start();
-
+
if ( TEX_LT_PATH == mLoadType )
LoadFromPath();
else if ( TEX_LT_MEM == mLoadType )
@@ -144,7 +154,20 @@ void cTextureLoader::Start() {
void cTextureLoader::LoadFromPath() {
if ( FileExists( mFilepath ) ) {
- mPixels = SOIL_load_image( mFilepath.c_str(), &mImgWidth, &mImgHeight, &mChannels, SOIL_LOAD_AUTO );
+ if ( GLEW_EXT_texture_compression_s3tc )
+ mIsDDS = 0 != stbi_dds_test_filename( mFilepath.c_str() );
+
+ if ( mIsDDS ) {
+ std::fstream fs ( mFilepath.c_str() , std::ios::in | std::ios::binary );
+ mSize = FileSize( mFilepath );
+ mPixels = (Uint8*) malloc( mSize );
+ fs.read( reinterpret_cast ( mPixels ), mSize );
+ fs.close();
+
+ stbi_dds_info_from_memory( mPixels, mSize, &mImgWidth, &mImgHeight, &mChannels, &mIsDDSCompressed );
+ } else {
+ mPixels = SOIL_load_image( mFilepath.c_str(), &mImgWidth, &mImgHeight, &mChannels, SOIL_LOAD_AUTO );
+ }
if ( NULL == mPixels )
cLog::instance()->Write( SOIL_last_result() );
@@ -163,7 +186,16 @@ void cTextureLoader::LoadFromPack() {
}
void cTextureLoader::LoadFromMemory() {
- mPixels = SOIL_load_image_from_memory( mImagePtr, mSize, &mImgWidth, &mImgHeight, &mChannels, SOIL_LOAD_AUTO );
+ if ( GLEW_EXT_texture_compression_s3tc )
+ mIsDDS = 0 != stbi_dds_test_memory( mImagePtr, mSize );
+
+ if ( mIsDDS ) {
+ mPixels = (Uint8*) malloc( mSize );
+ memcpy( mPixels, mImagePtr, mSize );
+ stbi_dds_info_from_memory( mPixels, mSize, &mImgWidth, &mImgHeight, &mChannels, &mIsDDSCompressed );
+ } else {
+ mPixels = SOIL_load_image_from_memory( mImagePtr, mSize, &mImgWidth, &mImgHeight, &mChannels, SOIL_LOAD_AUTO );
+ }
if ( NULL == mPixels )
cLog::instance()->Write( SOIL_last_result() );
@@ -185,12 +217,21 @@ void cTextureLoader::LoadFromPixels() {
GLint PreviousTexture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture);
- tTexId = SOIL_create_OGL_texture( mPixels, &width, &height, mChannels, SOIL_CREATE_NEW_ID, flags );
+ if ( mIsDDS )
+ tTexId = SOIL_direct_load_DDS_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 )
- mTexId = cTextureFactory::instance()->PushTexture( mFilepath, tTexId, mImgWidth, mImgHeight, width, height, mMipmap, mChannels, mColorKey, mClampMode, mCompressTexture, mLocalCopy );
+ if ( tTexId ) {
+ if ( mIsDDS && mIsDDSCompressed && mSize > 128 )
+ mSize -= 128; // Remove the header size
+ else
+ mSize = mWidth * mHeight * mChannels;
+
+ mTexId = cTextureFactory::instance()->PushTexture( mFilepath, tTexId, mImgWidth, mImgHeight, width, height, mMipmap, mChannels, mColorKey, mClampMode, mCompressTexture || mIsDDSCompressed, mLocalCopy, mSize );
+ }
if ( TEX_LT_PIXELS != mLoadType )
eeSAFE_FREE( mPixels );
diff --git a/src/graphics/ctextureloader.hpp b/src/graphics/ctextureloader.hpp
index fed8e1c84..3c7da3e8a 100644
--- a/src/graphics/ctextureloader.hpp
+++ b/src/graphics/ctextureloader.hpp
@@ -50,6 +50,8 @@ class EE_API cTextureLoader : public cObjectLoader {
void Start();
private:
bool mTexLoaded;
+ bool mIsDDS;
+ int mIsDDSCompressed;
void LoadFromPath();
void LoadFromMemory();
diff --git a/src/helper/SOIL/SOIL.c b/src/helper/SOIL/SOIL.c
index 2d326cea7..367660d14 100755
--- a/src/helper/SOIL/SOIL.c
+++ b/src/helper/SOIL/SOIL.c
@@ -81,17 +81,7 @@ int query_DXT_capability( void );
#define SOIL_RGBA_S3TC_DXT5 0x83F3
typedef void (APIENTRY * P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid * data);
P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC soilGlCompressedTexImage2D = NULL;
-unsigned int SOIL_direct_load_DDS(
- const char *filename,
- unsigned int reuse_texture_ID,
- int flags,
- int loading_as_cubemap );
-unsigned int SOIL_direct_load_DDS_from_memory(
- const unsigned char *const buffer,
- int buffer_length,
- unsigned int reuse_texture_ID,
- int flags,
- int loading_as_cubemap );
+
/* other functions */
unsigned int
SOIL_internal_create_OGL_texture
diff --git a/src/helper/SOIL/SOIL.h b/src/helper/SOIL/SOIL.h
index 5174a9023..54da535e7 100755
--- a/src/helper/SOIL/SOIL.h
+++ b/src/helper/SOIL/SOIL.h
@@ -425,7 +425,19 @@ const char*
(
void
);
+
+unsigned int SOIL_direct_load_DDS(
+ const char *filename,
+ unsigned int reuse_texture_ID,
+ int flags,
+ int loading_as_cubemap );
+unsigned int SOIL_direct_load_DDS_from_memory(
+ const unsigned char *const buffer,
+ int buffer_length,
+ unsigned int reuse_texture_ID,
+ int flags,
+ int loading_as_cubemap );
#ifdef __cplusplus
}
diff --git a/src/helper/SOIL/stb_image.h b/src/helper/SOIL/stb_image.h
index 2d635178f..85a22d292 100644
--- a/src/helper/SOIL/stb_image.h
+++ b/src/helper/SOIL/stb_image.h
@@ -328,8 +328,9 @@ extern int stbi_gif_info_from_file (FILE *f, int *x, int
#endif//STBI_TYPE_SPECIFIC_FUNCTIONS
-
-
+#ifndef STBI_NO_DDS
+#include "stbi_DDS.h"
+#endif
#ifdef __cplusplus
}
diff --git a/src/helper/SOIL/stbi_DDS.h b/src/helper/SOIL/stbi_DDS.h
index fe88e4b59..ccb5a3b9a 100755
--- a/src/helper/SOIL/stbi_DDS.h
+++ b/src/helper/SOIL/stbi_DDS.h
@@ -10,10 +10,18 @@ extern int stbi_dds_test_memory (stbi_uc const *buffer, int len);
extern stbi_uc *stbi_dds_load (char *filename, int *x, int *y, int *comp, int req_comp);
extern stbi_uc *stbi_dds_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
-#ifndef STBI_NO_STDIO
+#ifndef STBI_NO_STDIO
+extern int stbi_dds_test_filename (char const *filename);
extern int stbi_dds_test_file (FILE *f);
extern stbi_uc *stbi_dds_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
#endif
+
+extern int stbi_dds_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int *iscompressed);
+
+#ifndef STBI_NO_STDIO
+extern int stbi_dds_info (char const *filename, int *x, int *y, int *comp, int *iscompressed);
+extern int stbi_dds_info_from_file (FILE *f, int *x, int *y, int *comp, int *iscompressed);
+#endif
/*
//
diff --git a/src/helper/SOIL/stbi_DDS_c.h b/src/helper/SOIL/stbi_DDS_c.h
index 1cd3ddeab..bf2f18d1e 100755
--- a/src/helper/SOIL/stbi_DDS_c.h
+++ b/src/helper/SOIL/stbi_DDS_c.h
@@ -82,7 +82,18 @@ static int dds_test(stbi *s)
if (get32le(s) != 124) return 0;
return 1;
}
-#ifndef STBI_NO_STDIO
+#ifndef STBI_NO_STDIO
+
+int stbi_dds_test_filename (char const *filename)
+{
+ int r;
+ FILE *f = fopen(filename, "rb");
+ if (!f) return 0;
+ r = stbi_dds_test_file(f);
+ fclose(f);
+ return r;
+}
+
int stbi_dds_test_file (FILE *f)
{
stbi s;
@@ -264,7 +275,75 @@ void stbi_decode_DXT_color_block(
uncompressed[i+2] = decode_colors[idx+2];
}
// done
-}
+}
+
+static int dds_get_info( stbi *s, int *x, int *y, int *comp, int *iscompressed ) {
+ int flags;
+ DDS_header header;
+
+ if( sizeof( DDS_header ) != 128 )
+ {
+ return 0;
+ }
+
+ getn( s, (stbi_uc*)(&header), 128 );
+
+ if( header.dwMagic != (('D' << 0) | ('D' << 8) | ('S' << 16) | (' ' << 24)) ) return 0;
+ if( header.dwSize != 124 ) return 0;
+ flags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
+ if( (header.dwFlags & flags) != flags ) return 0;
+ if( header.sPixelFormat.dwSize != 32 ) return 0;
+ flags = DDPF_FOURCC | DDPF_RGB;
+ if( (header.sPixelFormat.dwFlags & flags) == 0 ) return 0;
+ if( (header.sCaps.dwCaps1 & DDSCAPS_TEXTURE) == 0 ) return 0;
+
+ int is_compressed = (header.sPixelFormat.dwFlags & DDPF_FOURCC) / DDPF_FOURCC;
+ int has_alpha = (header.sPixelFormat.dwFlags & DDPF_ALPHAPIXELS) / DDPF_ALPHAPIXELS;
+
+ *x = header.dwWidth;
+ *y = header.dwHeight;
+
+ if ( !is_compressed ) {
+ *comp = 3;
+
+ if ( has_alpha )
+ *comp = 4;
+ }
+ else
+ *comp = 4;
+
+ if ( iscompressed )
+ *iscompressed = is_compressed;
+
+ return 1;
+}
+
+int stbi_dds_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int *iscompressed)
+{
+ stbi s;
+ start_mem(&s,buffer, len);
+ return dds_get_info( &s, x, y, comp, iscompressed );
+}
+
+#ifndef STBI_NO_STDIO
+int stbi_dds_info(char const *filename, int *x, int *y, int *comp, int *iscompressed)
+{
+ int res;
+ FILE *f = fopen(filename, "rb");
+ if (!f) return 0;
+ res = stbi_dds_info_from_file( f, x, y, comp, iscompressed );
+ fclose(f);
+ return res;
+}
+
+int stbi_dds_info_from_file(FILE *f, int *x, int *y, int *comp, int *iscompressed)
+{
+ stbi s;
+ start_file(&s, f);
+ return dds_get_info( &s, x, y, comp, iscompressed );
+}
+#endif
+
static stbi_uc *dds_load(stbi *s, int *x, int *y, int *comp, int req_comp)
{
// all variables go up front
diff --git a/src/helper/haikuttf/hkbase.hpp b/src/helper/haikuttf/hkbase.hpp
index 44eb12aa5..fac9a8b70 100644
--- a/src/helper/haikuttf/hkbase.hpp
+++ b/src/helper/haikuttf/hkbase.hpp
@@ -3,10 +3,16 @@
#include
-#ifdef _MSC_VER
-#include "stdint.h"
-#else
-#include
+#include "sophist.h"
+typedef SOPHIST_int8 s8;
+typedef SOPHIST_uint8 u8;
+typedef SOPHIST_int16 s16;
+typedef SOPHIST_uint16 u16;
+typedef SOPHIST_int32 s32;
+typedef SOPHIST_uint32 u32;
+#ifdef SOPHIST_has_64
+typedef SOPHIST_int64 s64;
+typedef SOPHIST_uint64 u64;
#endif
#include
diff --git a/src/helper/haikuttf/hkfont.cpp b/src/helper/haikuttf/hkfont.cpp
index 2a07c1e88..b6b0d2cc0 100644
--- a/src/helper/haikuttf/hkfont.cpp
+++ b/src/helper/haikuttf/hkfont.cpp
@@ -77,7 +77,7 @@ void hkFont::CacheFlush() {
mScratch.Flush();
}
-FT_Error hkFont::GlyphFind( uint16_t ch, int want ) {
+FT_Error hkFont::GlyphFind( u16 ch, int want ) {
int retval = 0;
if( ch < mCacheSize ) {
@@ -95,7 +95,7 @@ FT_Error hkFont::GlyphFind( uint16_t ch, int want ) {
return retval;
}
-FT_Error hkFont::GlyphLoad( uint16_t ch, hkGlyph * cached, int want ) {
+FT_Error hkFont::GlyphLoad( u16 ch, hkGlyph * cached, int want ) {
FT_Face face;
FT_Error error;
FT_GlyphSlot glyph;
@@ -340,10 +340,10 @@ FT_Error hkFont::GlyphLoad( uint16_t ch, hkGlyph * cached, int want ) {
int col;
int offset;
int pixel;
- uint8_t* pixmap;
+ u8* pixmap;
for( row = dst->rows - 1; row >= 0; --row ) {
- pixmap = (uint8_t*) dst->buffer + row * dst->pitch;
+ pixmap = (u8*) dst->buffer + row * dst->pitch;
for( offset=1; offset <= mGlyphOverhang; ++offset ) {
for( col = dst->width - 1; col > 0; --col ) {
if( mono ) {
@@ -353,7 +353,7 @@ FT_Error hkFont::GlyphLoad( uint16_t ch, hkGlyph * cached, int want ) {
if( pixel > NUM_GRAYS - 1 ) {
pixel = NUM_GRAYS - 1;
}
- pixmap[col] = (uint8_t) pixel;
+ pixmap[col] = (u8) pixel;
}
}
}
@@ -376,7 +376,7 @@ FT_Error hkFont::GlyphLoad( uint16_t ch, hkGlyph * cached, int want ) {
return 0;
}
-unsigned char * hkFont::GlyphRender( uint16_t ch, uint32_t fg ) {
+unsigned char * hkFont::GlyphRender( u16 ch, u32 fg ) {
unsigned char * textbuf = NULL;
int row;
FT_Error error;
@@ -396,15 +396,15 @@ unsigned char * hkFont::GlyphRender( uint16_t ch, uint32_t fg ) {
if ( NULL == textbuf )
return NULL;
- uint32_t * buffu32 = reinterpret_cast ( &textbuf[0] );
+ u32 * buffu32 = reinterpret_cast ( &textbuf[0] );
memset( buffu32, fg, bitmap->width * bitmap->rows );
- const uint8_t* pixels = bitmap->buffer;
+ const u8* pixels = bitmap->buffer;
for ( int y = 0; y < bitmap->rows; y++ ) {
for ( int x = 0; x < bitmap->width; x++ ) {
- uint32_t index = (x + y * bitmap->width) * 4 + 3;
+ u32 index = (x + y * bitmap->width) * 4 + 3;
textbuf[ index ] = pixels[ x ];
}
@@ -425,7 +425,7 @@ unsigned char * hkFont::GlyphRender( uint16_t ch, uint32_t fg ) {
return textbuf;
}
-int hkFont::GlyphMetrics( uint16_t ch, int* minx, int* maxx, int* miny, int* maxy, int* advance ) {
+int hkFont::GlyphMetrics( u16 ch, int* minx, int* maxx, int* miny, int* maxy, int* advance ) {
FT_Error error;
error = GlyphFind( ch, CACHED_METRICS );
@@ -459,11 +459,11 @@ int hkFont::GlyphMetrics( uint16_t ch, int* minx, int* maxx, int* miny, int* max
return 0;
}
-void hkFont::InitLineMectrics( const unsigned char * textbuf, const int row, uint8_t **pdst, int *pheight, FT_Bitmap * bitmap ) {
- uint8_t *dst;
+void hkFont::InitLineMectrics( const unsigned char * textbuf, const int row, u8 **pdst, int *pheight, FT_Bitmap * bitmap ) {
+ u8 *dst;
int height;
- dst = (uint8_t *)textbuf;
+ dst = (u8 *)textbuf;
if( row > 0 )
dst += row * bitmap->pitch;
@@ -477,18 +477,18 @@ void hkFont::InitLineMectrics( const unsigned char * textbuf, const int row, uin
*pheight = height;
}
-void hkFont::DrawLine( const unsigned char * textbuf, const int row, const uint32_t color, FT_Bitmap * bitmap ) {
+void hkFont::DrawLine( const unsigned char * textbuf, const int row, const u32 color, FT_Bitmap * bitmap ) {
int line;
- uint32_t * dst_check = (uint32_t*)textbuf + bitmap->pitch / 4 * bitmap->rows;
- uint8_t * dst8; /* destination, byte version */
- uint32_t * dst;
+ u32 * dst_check = (u32*)textbuf + bitmap->pitch / 4 * bitmap->rows;
+ u8 * dst8; /* destination, byte version */
+ u32 * dst;
int height;
int col;
- uint32_t pixel = color | 0xFF000000;
+ u32 pixel = color | 0xFF000000;
InitLineMectrics( textbuf, row, &dst8, &height, bitmap );
- dst = (uint32_t *) dst8;
+ dst = (u32 *) dst8;
for ( line = height; line > 0 && dst < dst_check; --line ) {
for ( col = 0; col < bitmap->width; ++col )
diff --git a/src/helper/haikuttf/hkfont.hpp b/src/helper/haikuttf/hkfont.hpp
index 3126005a4..979686dbc 100644
--- a/src/helper/haikuttf/hkfont.hpp
+++ b/src/helper/haikuttf/hkfont.hpp
@@ -67,13 +67,13 @@ class hkFont {
hkFontManager * Manager() const { return mFm; }
- FT_Error GlyphFind( uint16_t ch, int want );
+ FT_Error GlyphFind( u16 ch, int want );
- FT_Error GlyphLoad( uint16_t ch, hkGlyph * cached, int want );
+ FT_Error GlyphLoad( u16 ch, hkGlyph * cached, int want );
- unsigned char * GlyphRender( uint16_t ch, uint32_t fg );
+ unsigned char * GlyphRender( u16 ch, u32 fg );
- int GlyphMetrics( uint16_t ch, int* minx, int* maxx, int* miny, int* maxy, int* advance );
+ int GlyphMetrics( u16 ch, int* minx, int* maxx, int* miny, int* maxy, int* advance );
void CacheFlush();
protected:
@@ -103,9 +103,9 @@ class hkFont {
int StrikeThroughTopRow();
- void DrawLine( const unsigned char * textbuf, const int row, const uint32_t color, FT_Bitmap * bitmap );
+ void DrawLine( const unsigned char * textbuf, const int row, const u32 color, FT_Bitmap * bitmap );
- void InitLineMectrics( const unsigned char * textbuf, const int row, uint8_t **pdst, int *pheight, FT_Bitmap * bitmap );
+ void InitLineMectrics( const unsigned char * textbuf, const int row, u8 **pdst, int *pheight, FT_Bitmap * bitmap );
};
}
diff --git a/src/helper/haikuttf/hkfontmanager.cpp b/src/helper/haikuttf/hkfontmanager.cpp
index 5f75f3115..29b0551e5 100644
--- a/src/helper/haikuttf/hkfontmanager.cpp
+++ b/src/helper/haikuttf/hkfontmanager.cpp
@@ -55,7 +55,7 @@ void hkFontManager::CloseFont( hkFont * Font ) {
}
}
-hkFont * hkFontManager::OpenFromMemory( const uint8_t* data, unsigned long size, int ptsize, long index, unsigned int glyphCacheSize ) {
+hkFont * hkFontManager::OpenFromMemory( const u8* data, unsigned long size, int ptsize, long index, unsigned int glyphCacheSize ) {
if ( Init() != 0)
return NULL;
diff --git a/src/helper/haikuttf/hkfontmanager.hpp b/src/helper/haikuttf/hkfontmanager.hpp
index efb6142e3..3932403fe 100644
--- a/src/helper/haikuttf/hkfontmanager.hpp
+++ b/src/helper/haikuttf/hkfontmanager.hpp
@@ -36,7 +36,7 @@ class hkFontManager {
void CloseFont( hkFont * Font );
- hkFont * OpenFromMemory( const uint8_t* data, unsigned long size, int ptsize, long index = 0, unsigned int glyphCacheSize = 256 );
+ hkFont * OpenFromMemory( const u8* data, unsigned long size, int ptsize, long index = 0, unsigned int glyphCacheSize = 256 );
hkFont * OpenFromFile( const char* filename, int ptsize, long index = 0, unsigned int glyphCacheSize = 256 );
diff --git a/src/helper/haikuttf/hkglyph.hpp b/src/helper/haikuttf/hkglyph.hpp
index c8af35c9f..1b1f360f0 100644
--- a/src/helper/haikuttf/hkglyph.hpp
+++ b/src/helper/haikuttf/hkglyph.hpp
@@ -41,8 +41,8 @@ class hkGlyph {
inline int Advance() const { return mAdvance; }
inline void Advance( int advance ) { mAdvance = advance; }
- inline uint16_t Cached() const { return mCached; }
- inline void Cached( uint16_t cached ) { mCached = cached; }
+ inline u16 Cached() const { return mCached; }
+ inline void Cached( u16 cached ) { mCached = cached; }
void Flush();
protected:
@@ -56,7 +56,7 @@ class hkGlyph {
int mMaxY;
int mOffsetY;
int mAdvance;
- uint16_t mCached;
+ u16 mCached;
};
}
diff --git a/src/helper/haikuttf/sophist.h b/src/helper/haikuttf/sophist.h
new file mode 100644
index 000000000..0e8ac5933
--- /dev/null
+++ b/src/helper/haikuttf/sophist.h
@@ -0,0 +1,180 @@
+/* sophist.h - 0.2 - public domain - Sean Barrett 2010
+** Knowledge drawn from Brian Hook's posh.h and http://predef.sourceforge.net
+** Sophist provides portable types; you typedef/#define them to your own names
+**
+** defines:
+** - SOPHIST_endian - either SOPHIST_little_endian or SOPHIST_big_endian
+** - SOPHIST_has_64 - either 0 or 1; if 0, int64 types aren't defined
+** - SOPHIST_pointer64 - either 0 or 1; if 1, pointer is 64-bit
+**
+** - SOPHIST_intptr, SOPHIST_uintptr - integer same size as pointer
+** - SOPHIST_int8, SOPHIST_uint8, SOPHIST_int16, SOPHIST_uint16
+** - SOPHIST_int32, SOPHIST_uint32, SOPHIST_int64, SOPHIST_uint64
+** - SOPHIST_int64_constant(number) - macros for creating 64-bit
+** - SOPHIST_uint64_constant(number) integer constants
+** - SOPHIST_printf_format64 - string for printf format for int64
+*/
+
+#ifndef __INCLUDE_SOPHIST_H__
+#define __INCLUDE_SOPHIST_H__
+
+#define SOPHIST_compiletime_assert(name,val) \
+ typedef int SOPHIST__assert##name[(val) ? 1 : -1]
+
+/* define a couple synthetic rules to make code more readable */
+#if (defined(__sparc__) || defined(__sparc)) && \
+ (defined(__arch64__) || defined(__sparcv9) || defined(__sparc_v9__))
+ #define SOPHIST_sparc64
+#endif
+
+#if (defined(linux) || defined(__linux__)) && \
+ (defined(__alpha)||defined(__alpha__)||defined(__x86_64__)||defined(_M_X64))
+ #define SOPHIST_linux64
+#endif
+
+/* basic types */
+typedef signed char SOPHIST_int8;
+typedef unsigned char SOPHIST_uint8;
+
+typedef signed short SOPHIST_int16;
+typedef unsigned short SOPHIST_uint16;
+
+#ifdef __palmos__
+ typedef signed long SOPHIST_int32;
+ typedef unsigned long SOPHIST_uint32;
+#else
+ typedef signed int SOPHIST_int32;
+ typedef unsigned int SOPHIST_uint32;
+#endif
+
+#if defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) \
+ || (defined(__alpha) && defined(__DECC))
+
+ typedef signed __int64 SOPHIST_int64;
+ typedef unsigned __int64 SOPHIST_uint64;
+ #define SOPHIST_has_64 1
+ #define SOPHIST_int64_constant(x) (x##i64)
+ #define SOPHIST_uint64_constant(x) (x##ui64)
+ #define SOPHIST_printf_format64 "I64"
+
+#elif defined(__LP64__) || defined(__powerpc64__) || defined(SOPHIST_sparc64)
+
+ typedef signed long SOPHIST_int64;
+ typedef unsigned long SOPHIST_uint64;
+
+ #define SOPHIST_has_64 1
+ #define SOPHIST_int64_constant(x) ((SOPHIST_int64) x)
+ #define SOPHIST_uint64_constant(x) ((SOPHIST_uint64) x)
+ #define SOPHIST_printf_format64 "l"
+
+#elif defined(_LONG_LONG) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) \
+ || defined(__GNUC__) || defined(__MWERKS__) || defined(__APPLE_CC__) \
+ || defined(sgi) || defined (__sgi) || defined(__sgi__) \
+ || defined(_CRAYC)
+
+ typedef signed long long SOPHIST_int64;
+ typedef unsigned long long SOPHIST_uint64;
+
+ #define SOPHIST_has_64 1
+ #define SOPHIST_int64_constant(x) (x##LL)
+ #define SOPHIST_uint64_constant(x) (x##ULL)
+ #define SOPHIST_printf_format64 "ll"
+#endif
+
+#ifndef SOPHIST_has_64
+#define SOPHIST_has_64 0
+#endif
+
+SOPHIST_compiletime_assert( int8 , sizeof(SOPHIST_int8 ) == 1);
+SOPHIST_compiletime_assert(uint16, sizeof(SOPHIST_int16) == 2);
+SOPHIST_compiletime_assert( int32, sizeof(SOPHIST_int32 ) == 4);
+SOPHIST_compiletime_assert(uint32, sizeof(SOPHIST_uint32) == 4);
+
+#if SOPHIST_has_64
+ SOPHIST_compiletime_assert( int64, sizeof(SOPHIST_int64 ) == 8);
+ SOPHIST_compiletime_assert(uint64, sizeof(SOPHIST_uint64) == 8);
+#endif
+
+/* determine whether pointers are 64-bit */
+
+#if defined(SOPHIST_linux64) || defined(SOPHIST_sparc64) \
+ || defined(__osf__) || (defined(_WIN64) && !defined(_XBOX)) \
+ || defined(__64BIT__) \
+ || defined(__LP64) || defined(__LP64__) || defined(_LP64) \
+ || defined(_ADDR64) || defined(_CRAYC) \
+
+ #define SOPHIST_pointer64 1
+
+ SOPHIST_compiletime_assert(pointer64, sizeof(void*) == 8);
+
+ typedef SOPHIST_int64 SOPHIST_intptr;
+ typedef SOPHIST_uint64 SOPHIST_uintptr;
+#else
+
+ #define SOPHIST_pointer64 0
+
+ SOPHIST_compiletime_assert(pointer64, sizeof(void*) <= 4);
+
+ /* do we care about pointers that are only 16-bit? */
+ typedef SOPHIST_int32 SOPHIST_intptr;
+ typedef SOPHIST_uint32 SOPHIST_uintptr;
+
+#endif
+
+SOPHIST_compiletime_assert(intptr, sizeof(SOPHIST_intptr) == sizeof(char *));
+
+/* enumerate known little endian cases; fallback to big-endian */
+
+#define SOPHIST_little_endian 1
+#define SOPHIST_big_endian 2
+
+#if defined(__386__) || defined(i386) || defined(__i386__) \
+ || defined(__X86) || defined(_M_IX86) \
+ || defined(_M_X64) || defined(__x86_64__) \
+ || defined(alpha) || defined(__alpha) || defined(__alpha__) \
+ || defined(_M_ALPHA) \
+ || defined(ARM) || defined(_ARM) || defined(__arm__) \
+ || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \
+ || defined(_WIN32_WCE) || defined(__NT__) \
+ || defined(__MIPSEL__)
+ #define SOPHIST_endian SOPHIST_little_endian
+#else
+ #define SOPHIST_endian SOPHIST_big_endian
+#endif
+
+#endif // __INCLUDE_SOPHIST_H__
+
+#ifdef SOPHIST_selftest
+#include
+#include
+int main(int argc, char **argv)
+{
+ int fail=0;
+ union {
+ SOPHIST_uint8 bytes[4];
+ SOPHIST_uint32 num;
+ } x;
+ #if SOPHIST_has_64
+ char buffer[32];
+ sprintf(buffer, "%016" SOPHIST_printf_format64 "x",
+ SOPHIST_uint64_constant(0x0123456789abcdef));
+ if (strcmp(buffer, "0123456789abcdef")) {
+ fail = 1; fputs("ERROR: 64-bit check failed.\n", stderr);
+ }
+ #endif
+
+ #if SOPHIST_endian == SOPHIST_little_endian
+ x.bytes[0] = 7; x.bytes[1] = 5; x.bytes[2] = 3; x.bytes[3] = 1;
+ #elif SOPHIST_endian == SOPHIST_big_endian
+ x.bytes[0] = 1; x.bytes[1] = 3; x.bytes[2] = 5; x.bytes[3] = 7;
+ #else
+ #error "Failure: endianness unknown!"
+ #endif
+ if (x.num != 0x01030507) {
+ fail = 1; fputs("ERROR: endian check failed.\n", stderr);
+ }
+
+ fputs(fail ? "Failed.\n" : "Passed.\n", stdout);
+ return 0;
+}
+#endif
diff --git a/src/helper/zip_utils/unzip.cpp b/src/helper/zip_utils/unzip.cpp
index dd70591f2..0c07864ac 100644
--- a/src/helper/zip_utils/unzip.cpp
+++ b/src/helper/zip_utils/unzip.cpp
@@ -2,7 +2,7 @@
#ifdef ZIP_STD
#include
#include
-#include
+#include
#include
#ifdef _MSC_VER
#include // microsoft puts it here
@@ -1692,7 +1692,7 @@ int inflate_blocks_free(inflate_blocks_statef *s, z_streamp z)
-extern const char inflate_copyright[] =
+const char inflate_copyright[] =
" inflate 1.1.3 Copyright 1995-1998 Mark Adler ";
// If you use the zlib library in a product, an acknowledgment is welcome
// in the documentation of your product. If for some reason you cannot
diff --git a/src/test/ee.cpp b/src/test/ee.cpp
index 6d3cbc6e6..299b9ec14 100644
--- a/src/test/ee.cpp
+++ b/src/test/ee.cpp
@@ -9,7 +9,7 @@
@TODO Encapsulate SDL and OpenGL ( and remove unnecessary dependencies ).
@TODO Add some Surface Grid class, to create special effects ( waved texture, and stuff like that ).
@TODO Support color cursors ( not only black and white cursors, that really sucks ) - Imposible with SDL 1.2
-@TODO Add Scripting support.
+@TODO Add Scripting support ( lua or squirrel ).
@TODO Add 2D physics support ( Box2D or Chipmunk wrapper ).
*/
@@ -188,6 +188,8 @@ class cEETest : private cThread {
cJoystickManager * JM;
eeFloat mAxisX;
eeFloat mAxisY;
+
+ Uint32 mFace;
};
@@ -319,7 +321,7 @@ void cEETest::CreateShaders() {
if ( mUseShaders ) {
mBlurFactor = 0.01f;
- mShaderProgram = new cShaderProgram( MyPath + "data/shader/blur.vert", MyPath + "data/shader/blur.frag" );
+ mShaderProgram = new cShaderProgram( &PAK, "shader/blur.vert", "shader/blur.frag" );
}
}
@@ -457,6 +459,34 @@ void cEETest::LoadTextures() {
Tiles[7] = TF->LoadFromPack( &PAK, "tiles/8.png", false, eeRGB(0,0,0) );
+ eeInt w, h;
+
+ mFace = TF->LoadFromPack( &PakTest, "adjutantportrait_l_static.dds" );
+ /** // DDS Lock/Unlock Test
+ cTexture * mFacePtr = TF->GetTexture( mFace );
+
+ if ( NULL != mFacePtr ) {
+ w = (eeInt)mFacePtr->Width();
+ h = (eeInt)mFacePtr->Height();
+
+ mFacePtr->Lock();
+
+ for ( y = 0; y < h; y++ ) {
+ for ( x = 0; x < w; x++ ) {
+ eeColorA tempC = mFacePtr->GetPixel( x, y );
+
+ tempC.Red = std::min( tempC.Red + 50, 255 );
+ tempC.Green = std::min( tempC.Green + 50, 255 );
+ tempC.Blue = std::min( tempC.Blue + 50, 255 );
+
+ eeColorA newC( tempC.R(), tempC.G(), tempC.B(), 255 );
+ mFacePtr->SetPixel( x, y, newC );
+ }
+ }
+
+ mFacePtr->Unlock(false,true);
+ }*/
+
SP.CreateAnimation();
for ( Int32 my = 0; my < 4; my++ )
@@ -476,8 +506,8 @@ void cEETest::LoadTextures() {
cTexture * Tex = TF->GetTexture(TN[2]);
Tex->Lock();
- eeInt w = Tex->Width();
- eeInt h = Tex->Height();
+ w = (eeInt)Tex->Width();
+ h = (eeInt)Tex->Height();
for ( y = 0; y < h; y++) {
for ( x = 0; x < w; x++) {
@@ -818,6 +848,10 @@ void cEETest::Render() {
TTF->SetText( mBuda );
TTF->Draw( 0.f, 50.f );
+ cTexture * TexFace = TF->GetTexture( mFace );
+ if ( TexFace )
+ TexFace->Draw( EE->GetWidth() - TexFace->Width() , EE->GetHeight() - TexFace->Height(), 0.f, 1.f, eeColorA(), ALPHA_DESTALPHA, RN_MIRROR );
+
FF2->SetText( L"FPS: " + toWStr( EE->FPS() ) );
FF2->Draw( EE->GetWidth() - FF2->GetTextWidth() - 15, 0 );
@@ -866,10 +900,10 @@ void cEETest::Input() {
if ( KM->AltPressed() && KM->IsKeyUp(KEY_M) && !Con.Active() )
EE->MaximizeWindow();
-/*
+
if ( KM->IsKeyUp(KEY_F4) )
TF->ReloadAllTextures();
-*/
+
if ( KM->AltPressed() && KM->IsKeyUp(KEY_RETURN) ) {
if ( EE->Windowed() ) {
EE->ChangeRes( EE->GetDeskWidth(), EE->GetDeskHeight(), false );
@@ -1073,8 +1107,8 @@ void cEETest::End() {
MySong.clear();
cLog::instance()->Save();
+
cEngine::DestroySingleton();
- cUIManager::DestroySingleton();
}
void cEETest::InputCallback(EE_Event* event) {
diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp
index f0fb26300..bc9a696a2 100755
--- a/src/utils/utils.cpp
+++ b/src/utils/utils.cpp
@@ -66,7 +66,7 @@ std::string AppPath() {
}
}
- throw CL_Error("get_exe_path failed");
+ return "./";
#elif EE_PLATFORM == EE_PLATFORM_LINUX
char exe_file[PATH_MAX + 1];
int size;
diff --git a/src/window/cengine.cpp b/src/window/cengine.cpp
index 404c6842b..7f4927251 100755
--- a/src/window/cengine.cpp
+++ b/src/window/cengine.cpp
@@ -102,9 +102,9 @@ cEngine::~cEngine() {
cInput::DestroySingleton();
- SDL_Quit();
-
cLog::DestroySingleton();
+
+ SDL_Quit();
}
bool cEngine::Init(const Uint32& Width, const Uint32& Height, const Uint8& BitColor, const bool& Windowed, const bool& Resizeable, const bool& VSync, const bool& DoubleBuffering, const bool& UseDesktopResolution, const bool& NoFrame ) {
@@ -209,7 +209,7 @@ bool cEngine::Init(const Uint32& Width, const Uint32& Height, const Uint8& BitCo
mGLEWinit = glewInit();
if ( GLEW_OK == mGLEWinit ) {
- mVideoInfo.SupARB_point = GL_VERSION_1_4 && GLEW_ARB_point_parameters && GLEW_ARB_point_sprite;
+ mVideoInfo.SupARB_point = GLEW_ARB_point_parameters && GLEW_ARB_point_sprite;
mVideoInfo.SupShaders = GLEW_ARB_shading_language_100 && GLEW_ARB_shader_objects && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader;
} else {
// die
@@ -335,19 +335,23 @@ void cEngine::ChangeRes( const Uint16& width, const Uint16& height, const bool&
cLog::instance()->Writef( "Switching from %s to %s. Width: %d Height %d.", mVideoInfo.Windowed == true ? "windowed" : "fullscreen", Windowed == true ? "windowed" : "fullscreen", width, height );
#if EE_PLATFORM == EE_PLATFORM_WIN32 || EE_PLATFORM == EE_PLATFORM_APPLE
+ #if EE_PLATFORM == EE_PLATFORM_WIN32
bool Reload = mVideoInfo.Windowed != Windowed;
+ #else
+ bool Reload = true;
+ #endif
if ( Reload )
cTextureFactory::instance()->GrabTextures();
#endif
mVideoInfo.Windowed = Windowed;
- mVideoInfo.Width = width;
- mVideoInfo.Height = height;
+ mVideoInfo.Width = width;
+ mVideoInfo.Height = height;
if ( Windowed ) {
- mVideoInfo.WWidth = width;
- mVideoInfo.WHeight = height;
+ mVideoInfo.WWidth = width;
+ mVideoInfo.WHeight = height;
}
mDefaultView.SetView( 0, 0, mVideoInfo.Width, mVideoInfo.Height );
@@ -365,7 +369,7 @@ void cEngine::ChangeRes( const Uint16& width, const Uint16& height, const bool&
#if EE_PLATFORM == EE_PLATFORM_WIN32 || EE_PLATFORM == EE_PLATFORM_APPLE
if ( Reload ) {
- cTextureFactory::instance()->ReloadAllTextures();
+ cTextureFactory::instance()->UngrabTextures();
cShaderProgramManager::instance()->Reload();
}
#endif
@@ -469,15 +473,7 @@ bool cEngine::TakeScreenshot( std::string filepath, const EE_SAVETYPE& Format )
}
while ( !find && FileNum < 10000 ) {
- if ( FileNum < 10 ) {
- TmpPath = filepath + "000" + intToStr(FileNum) + Ext;
- } else if ( FileNum < 100 ) {
- TmpPath = filepath + "00" + intToStr(FileNum) + Ext;
- } else if ( FileNum < 1000 ) {
- TmpPath = filepath + "0" + intToStr(FileNum) + Ext;
- } else {
- TmpPath = intToStr(FileNum) + Ext;
- }
+ TmpPath = StrFormated( "%s%05d%s", filepath.c_str(), FileNum, Ext.c_str() );
FileNum++;
@@ -579,8 +575,8 @@ SDL_Cursor* cEngine::CreateCursor( const Uint32& TexId, const eeVector2i& HotSpo
//see http://sdldoc.csn.ul.ie/sdlcreatecursor.php for documentation on
//the format that data has to be in to pass to SDL_CreateCursor
Tex->Lock();
- for( Int32 y = 0; y != Tex->Height(); ++y) {
- for( Int32 x = 0; x != Tex->Width(); ++x) {
+ for( eeUint y = 0; y != Tex->Height(); ++y) {
+ for( eeUint x = 0; x != Tex->Width(); ++x) {
Uint8 trans = 0;
Uint8 black = 0;
@@ -613,9 +609,10 @@ void cEngine::SetCursor( const Uint32& TexId, const eeVector2i& HotSpot ) {
bool cEngine::SetIcon( const Uint32& FromTexId ) {
cTexture* Tex = cTextureFactory::instance()->GetTexture( FromTexId );
- if ( Tex ) {
+ if ( NULL != Tex ) {
Int32 W = static_cast( Tex->Width() );
Int32 H = static_cast( Tex->Height() );
+
if ( ( W % 8 ) == 0 && ( H % 8 ) == 0 ) {
Tex->Lock();
const Uint8* Ptr = Tex->GetPixelsPtr();
@@ -647,6 +644,7 @@ bool cEngine::SetIcon( const Uint32& FromTexId ) {
SDL_WM_SetIcon(TempGlyphSheet, NULL);
SDL_FreeSurface(TempGlyphSheet);
+
return true;
}
}
@@ -943,13 +941,12 @@ std::string cEngine::GetClipboardText() {
tStr.assign( scrap, scraplen-1 );
}
+
+ eeSAFE_DELETE_ARRAY( scrap );
#elif EE_PLATFORM == EE_PLATFORM_APPLE
#warning cEngine::GetClipboardText() not implemented on Apple
#endif
- if ( scrap )
- eeSAFE_DELETE_ARRAY( scrap );
-
return tStr;
}
@@ -974,13 +971,12 @@ std::wstring cEngine::GetClipboardTextWStr() {
tStr[i] = y;
}
}
+
+ eeSAFE_DELETE_ARRAY( scrap );
#elif EE_PLATFORM == EE_PLATFORM_APPLE
#warning cEngine::GetClipboardTextWStr() not implemented on Apple
#endif
- if ( scrap )
- eeSAFE_DELETE_ARRAY( scrap );
-
return tStr;
}
diff --git a/src/window/cengine.hpp b/src/window/cengine.hpp
index 74d0f4f50..974353de0 100755
--- a/src/window/cengine.hpp
+++ b/src/window/cengine.hpp
@@ -100,7 +100,7 @@ class EE_API cEngine : public cSingleton {
* You can set only the path to save the files, like "screenshots/"
* @return False if failed, otherwise returns True
*/
- bool TakeScreenshot( std::string filepath = "", const EE_SAVETYPE& Format = EE_SAVE_TYPE_TGA );
+ bool TakeScreenshot( std::string filepath = "", const EE_SAVETYPE& Format = EE_SAVE_TYPE_PNG );
/** @return The resolutions that support the video card */
std::vector< std::pair > GetPossibleResolutions() const;