diff --git a/ee.linux.cbp b/ee.linux.cbp
index e9e600c14..3b9656363 100644
--- a/ee.linux.cbp
+++ b/ee.linux.cbp
@@ -130,12 +130,12 @@
-
+
-
-
-
+
+
+
diff --git a/src/base.hpp b/src/base.hpp
index a0813a049..664b6e5c4 100644
--- a/src/base.hpp
+++ b/src/base.hpp
@@ -94,10 +94,10 @@ namespace EE {
typedef float eeFloat; //! The internal floating point used on EE++. \n This can help to improve compatibility with some platforms. \n And helps for an easy change from single precision to double precision.
typedef double eeDouble; //! The internal double floating point. It's only used when the engine needs some very high precision floating point ( for example the timer )
typedef unsigned long eeUint;
- typedef signed long eeInt;
+ typedef signed long eeInt;
const eeFloat PI = 3.141592654f;
- const eeFloat TwoPI = 6.283185308f;
+ const eeFloat TwoPI = 6.283185308f;
const eeFloat PId180 = PI / 180.f;
const eeFloat d180PI = 180.f / PI;
diff --git a/src/gaming/cisomap.cpp b/src/gaming/cisomap.cpp
index 828c22994..a8c8158b2 100755
--- a/src/gaming/cisomap.cpp
+++ b/src/gaming/cisomap.cpp
@@ -165,7 +165,7 @@ void cIsoMap::Draw() {
}
} else {
if ( T->Layers[L] > 0 ) {
- cTexture* Tex = TF->GetTexture( T->Layers[L] );
+ cTexture * Tex = TF->GetTexture( T->Layers[L] );
if ( T != NULL ) {
eeVector2f TileCenter( T->Q.V[1].x + (T->Q.V[3].x - T->Q.V[1].x) * 0.5f, T->Q.V[0].y + (T->Q.V[2].y - T->Q.V[0].y) * 0.5f );
@@ -177,11 +177,11 @@ void cIsoMap::Draw() {
if ( Intersect( ScreenAABB, ShadowAABB ) ) {
//AABB ShadowAABB_RECT( OffsetX + ObjPos.x, OffsetY + TileCenter.y - Tex->Height(), OffsetX + TileCenter.x + Tex->Width(), OffsetY + TileCenter.y );
//PR.DrawRectangle( ShadowAABB_RECT, 0, 1, DRAW_LINE );
- TF->DrawEx( T->Layers[L], OffsetX + ObjPos.x, OffsetY + ObjPos.y, (eeFloat)Tex->ImgWidth(), (eeFloat)Tex->ImgHeight(), 0, 1, SC, SC, SC, SC, ALPHA_NORMAL, RN_ISOMETRIC );
+ Tex->DrawEx( OffsetX + ObjPos.x, OffsetY + ObjPos.y, (eeFloat)Tex->ImgWidth(), (eeFloat)Tex->ImgHeight(), 0, 1, SC, SC, SC, SC, ALPHA_NORMAL, RN_ISOMETRIC );
}
if ( Intersect( ScreenAABB, LayerAABB ) ) {
- TF->DrawEx( T->Layers[L], OffsetX + TileCenter.x - (eeFloat)Tex->ImgWidth() * 0.5f, OffsetY + TileCenter.y - (eeFloat)Tex->ImgHeight(), (eeFloat)Tex->ImgWidth(), (eeFloat)Tex->ImgHeight(), 0, 1, eeColorA(T->Color[0]), eeColorA(T->Color[1]), eeColorA(T->Color[2]), eeColorA(T->Color[3]) );
+ Tex->DrawEx( OffsetX + TileCenter.x - (eeFloat)Tex->ImgWidth() * 0.5f, OffsetY + TileCenter.y - (eeFloat)Tex->ImgHeight(), (eeFloat)Tex->ImgWidth(), (eeFloat)Tex->ImgHeight(), 0, 1, eeColorA(T->Color[0]), eeColorA(T->Color[1]), eeColorA(T->Color[2]), eeColorA(T->Color[3]) );
}
}
}
diff --git a/src/graphics/cbatchrenderer.cpp b/src/graphics/cbatchrenderer.cpp
index 3211d3be2..351fa0352 100755
--- a/src/graphics/cbatchrenderer.cpp
+++ b/src/graphics/cbatchrenderer.cpp
@@ -7,12 +7,12 @@ void cBatchRenderer::Init() {
QuadsBegin();
}
-cBatchRenderer::cBatchRenderer() : mNumVertex(0), mTexture(0), mBlend(ALPHA_NORMAL), mCurrentMode(EE_GL_QUADS), mRotation(0.0f), mScale(1.0f), mPosition(0.0f, 0.0f), mCenter(0.0f, 0.0f), mForceRendering(true) {
+cBatchRenderer::cBatchRenderer() : mNumVertex(0), mTexture(NULL), mBlend(ALPHA_NORMAL), mCurrentMode(EE_GL_QUADS), mRotation(0.0f), mScale(1.0f), mPosition(0.0f, 0.0f), mCenter(0.0f, 0.0f), mForceRendering(true) {
AllocVertexs( 4 );
Init();
}
-cBatchRenderer::cBatchRenderer( const eeUint& Prealloc ) : mNumVertex(0), mTexture(0), mBlend(ALPHA_NORMAL), mCurrentMode(EE_GL_QUADS), mRotation(0.0f), mScale(1.0f), mPosition(0.0f, 0.0f), mCenter(0.0f, 0.0f), mForceRendering(true) {
+cBatchRenderer::cBatchRenderer( const eeUint& Prealloc ) : mNumVertex(0), mTexture(NULL), mBlend(ALPHA_NORMAL), mCurrentMode(EE_GL_QUADS), mRotation(0.0f), mScale(1.0f), mPosition(0.0f, 0.0f), mCenter(0.0f, 0.0f), mForceRendering(true) {
AllocVertexs( Prealloc );
Init();
}
@@ -34,11 +34,11 @@ void cBatchRenderer::Draw() {
Flush();
}
-void cBatchRenderer::SetTexture( const Uint32& TexId ) {
- if ( mTexture != TexId )
+void cBatchRenderer::SetTexture( const cTexture * Tex ) {
+ if ( mTexture != Tex )
Flush();
- mTexture = TexId;
+ mTexture = Tex;
}
void cBatchRenderer::SetBlendFunc( const EE_RENDERALPHAS& Blend ) {
@@ -64,17 +64,17 @@ void cBatchRenderer::Flush() {
bool CreateMatrix = ( mRotation || mScale != 1.0f || mPosition.x || mPosition.y );
- if ( mTexture > 0 )
+ if ( NULL != mTexture )
cTextureFactory::instance()->Bind( mTexture );
else
glDisable( GL_TEXTURE_2D );
cTextureFactory::instance()->SetBlendFunc( mBlend );
- if ( mCurrentMode == EE_GL_POINTS && mTexture > 0 ) {
+ if ( mCurrentMode == EE_GL_POINTS && NULL != mTexture ) {
glEnable( GL_POINT_SPRITE_ARB );
glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
- glPointSize( cTextureFactory::instance()->GetTextureWidth( mTexture ) );
+ glPointSize( mTexture->Width() );
}
if ( CreateMatrix ) {
diff --git a/src/graphics/cbatchrenderer.hpp b/src/graphics/cbatchrenderer.hpp
index f54e06d67..eeb7950bb 100755
--- a/src/graphics/cbatchrenderer.hpp
+++ b/src/graphics/cbatchrenderer.hpp
@@ -2,6 +2,7 @@
#define EE_GRAPHICSCBATCHRENDERER_H
#include "base.hpp"
+#include "ctexture.hpp"
namespace EE { namespace Graphics {
@@ -29,7 +30,7 @@ class cBatchRenderer {
void AllocVertexs( const eeUint& size );
/** Set the current texture to render on the batch ( if you change the texture and you have batched something, this will be renderer immediately ) */
- void SetTexture( const Uint32& TexId );
+ void SetTexture( const cTexture * Tex );
/** Set the blending functions to use on the batch */
void SetBlendFunc( const EE_RENDERALPHAS& Blend );
@@ -186,7 +187,7 @@ class cBatchRenderer {
eeVertex * mTVertex;
eeUint mNumVertex;
- Uint32 mTexture;
+ const cTexture * mTexture;
EE_RENDERALPHAS mBlend;
eeTexCoord mTexCoord[4];
diff --git a/src/graphics/cconsole.cpp b/src/graphics/cconsole.cpp
index 6060da715..7f1acbffc 100755
--- a/src/graphics/cconsole.cpp
+++ b/src/graphics/cconsole.cpp
@@ -94,13 +94,18 @@ void cConsole::AddCommand( const std::string& Command, ConsoleCallback CB ) {
void cConsole::Draw() {
if ( mEnabled ) {
Fade();
+
if ( mY > 0.0f ) {
if ( mTexId == 0 ) {
mPri.SetColor( eeColorA( mConColor.R(), mConColor.G(), mConColor.B(), static_cast(mA) ) );
mPri.DrawRectangle( 0.0f, 0.0f, mWidth, mY );
} else {
eeRGBA C( mConColor.R(), mConColor.G(), mConColor.B(), static_cast(mA) );
- cTextureFactory::instance()->DrawEx( mTexId, 0.0f, 0.0f, mWidth, mY, 0.0f, 1.0f, C, C, C, C );
+
+ cTexture * Tex = cTextureFactory::instance()->GetTexture( mTexId );
+
+ if ( NULL != Tex )
+ Tex->DrawEx( 0.0f, 0.0f, mWidth, mY, 0.0f, 1.0f, C, C, C, C );
}
mPri.SetColor( eeColorA( mConLineColor.R(), mConLineColor.G(), mConLineColor.B(), static_cast(mA) ) );
mPri.DrawRectangle( 0.0f, mY, mWidth, 4.0f );
diff --git a/src/graphics/cprimitives.cpp b/src/graphics/cprimitives.cpp
index ff6580d91..d3afba588 100755
--- a/src/graphics/cprimitives.cpp
+++ b/src/graphics/cprimitives.cpp
@@ -12,7 +12,7 @@ cPrimitives::cPrimitives() {
cPrimitives::~cPrimitives() {}
void cPrimitives::DrawRoundedRectangle(const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeColorA& TopLeft, const eeColorA& BottomLeft, const eeColorA& BottomRight, const eeColorA& TopRight, const eeFloat& Angle, const eeFloat& Scale, const EE_FILLMODE& fillmode, const EE_RENDERALPHAS& blend, const eeFloat& lineWidth, const eeUint& Corners ) {
- BR->SetTexture( 0 );
+ BR->SetTexture( NULL );
BR->SetBlendFunc( blend );
eeUint i;
@@ -91,7 +91,7 @@ void cPrimitives::DrawRectangle(const eeFloat& x, const eeFloat& y, const eeFloa
return;
}
- BR->SetTexture( 0 );
+ BR->SetTexture( NULL );
BR->SetBlendFunc( blend );
switch(fillmode) {
@@ -134,7 +134,7 @@ void cPrimitives::DrawRectangle(const eeFloat& x, const eeFloat& y, const eeFloa
void cPrimitives::DrawLine(const eeFloat& x, const eeFloat& y, const eeFloat& x2, const eeFloat& y2, const eeFloat& lineWidth) {
BR->SetLineWidth( lineWidth );
- BR->SetTexture( 0 );
+ BR->SetTexture( NULL );
BR->LinesBegin();
BR->LinesSetColor( mColor );
@@ -146,7 +146,7 @@ void cPrimitives::DrawLine(const eeFloat& x, const eeFloat& y, const eeFloat& x2
void cPrimitives::DrawPoint( const eeFloat& x, const eeFloat& y, const eeFloat& pointSize ) {
BR->SetPointSize( pointSize );
- BR->SetTexture( 0 );
+ BR->SetTexture( NULL );
BR->PointsBegin();
BR->PointSetColor( mColor );
@@ -159,7 +159,7 @@ void cPrimitives::DrawCircle( const eeFloat& x, const eeFloat& y, const eeFloat&
if(points < 6) points = 6;
eeFloat angle_shift = 360 / static_cast(points);
- BR->SetTexture( 0 );
+ BR->SetTexture( NULL );
switch( fillmode ) {
case DRAW_LINE:
@@ -185,7 +185,7 @@ void cPrimitives::DrawCircle( const eeFloat& x, const eeFloat& y, const eeFloat&
}
void cPrimitives::DrawTriangle(const eeFloat& x1, const eeFloat& y1, const eeFloat& x2, const eeFloat& y2, const eeFloat& x3, const eeFloat& y3, const eeColorA& Color1, const eeColorA& Color2, const eeColorA& Color3, const EE_FILLMODE& fillmode, const EE_RENDERALPHAS& blend, const eeFloat& lineWidth) {
- BR->SetTexture( 0 );
+ BR->SetTexture( NULL );
BR->SetBlendFunc( blend );
switch(fillmode) {
@@ -213,7 +213,7 @@ void cPrimitives::DrawTriangle(const eeFloat& x1, const eeFloat& y1, const eeFlo
}
void cPrimitives::DrawQuad( const eeFloat& x1, const eeFloat& y1, const eeFloat& x2, const eeFloat& y2, const eeFloat& x3, const eeFloat& y3, const eeFloat& x4, const eeFloat& y4, const eeColorA& Color1, const eeColorA& Color2, const eeColorA& Color3, const eeColorA& Color4, const EE_FILLMODE& fillmode, const EE_RENDERALPHAS& blend, const eeFloat& lineWidth, const eeFloat& OffsetX, const eeFloat& OffsetY ) {
- BR->SetTexture( 0 );
+ BR->SetTexture( NULL );
BR->SetBlendFunc( blend );
switch(fillmode) {
@@ -237,7 +237,7 @@ void cPrimitives::DrawQuad( const eeFloat& x1, const eeFloat& y1, const eeFloat&
}
void cPrimitives::DrawPolygon(const eePolygon2f& p, const EE_FILLMODE& fillmode, const EE_RENDERALPHAS& blend, const eeFloat& lineWidth) {
- BR->SetTexture( 0 );
+ BR->SetTexture( NULL );
BR->SetBlendFunc( blend );
switch(fillmode) {
diff --git a/src/graphics/cscrollparallax.cpp b/src/graphics/cscrollparallax.cpp
index d00b3a2c1..5c249277b 100755
--- a/src/graphics/cscrollparallax.cpp
+++ b/src/graphics/cscrollparallax.cpp
@@ -14,13 +14,18 @@ cScrollParallax::cScrollParallax( const Uint32& TexId, const eeFloat& DestX, con
}
bool cScrollParallax::Create(const Uint32& TexId, const eeFloat& DestX, const eeFloat& DestY, const eeFloat& DestWidth, const eeFloat& DestHeight, const eeRecti& SrcRECT, const eeRGBA& Color, const Uint8& Alpha, const EE_RENDERALPHAS& Effect ) {
+ cTexture * Tex = TF->GetTexture( TexId );
+
+ if ( NULL == Tex )
+ return false;
+
mSrcRECT = SrcRECT;
if ( mSrcRECT.Bottom == 0 && mSrcRECT.Right == 0 ) {
mSrcRECT.Left = 0;
mSrcRECT.Top = 0;
- mSrcRECT.Right = (Int32)TF->GetTextureWidth( TexId );
- mSrcRECT.Bottom = (Int32)TF->GetTextureHeight( TexId );
+ mSrcRECT.Right = (Int32)Tex->Width();
+ mSrcRECT.Bottom = (Int32)Tex->Height();
}
mWidth = static_cast ( mSrcRECT.Right - mSrcRECT.Left );
@@ -40,6 +45,7 @@ bool cScrollParallax::Create(const Uint32& TexId, const eeFloat& DestX, const ee
mSpr.Color( Color );
mSpr.Alpha( Alpha );
mSpr.SetRenderAlphas( Effect );
+
return true;
}
diff --git a/src/graphics/cscrollparallax.hpp b/src/graphics/cscrollparallax.hpp
index ddf4589b4..e6957e936 100755
--- a/src/graphics/cscrollparallax.hpp
+++ b/src/graphics/cscrollparallax.hpp
@@ -2,6 +2,7 @@
#define EE_GRAPHICSCSCROLLPARALLAX_H
#include "base.hpp"
+#include "ctexture.hpp"
#include "ctexturefactory.hpp"
#include "csprite.hpp"
@@ -50,7 +51,7 @@ class EE_API cScrollParallax {
*/
void Draw( const eeFloat& XDirVel, const eeFloat& YDirVel );
private:
- cTextureFactory* TF;
+ cTextureFactory * TF;
cSprite mSpr;
eeRecti mSrcRECT;
diff --git a/src/graphics/cshape.cpp b/src/graphics/cshape.cpp
index d25cea99a..6366230bc 100644
--- a/src/graphics/cshape.cpp
+++ b/src/graphics/cshape.cpp
@@ -64,7 +64,7 @@ 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 ) :
+cShape::cShape( const Uint32& TexId, const eeRecti& SrcRect, const eeFloat& DestWidth, const eeFloat& DestHeight, const eeFloat& OffsetX, const eeFloat& OffsetY, const std::string& Name ) :
mName( Name ),
mId( MakeHash( mName ) ),
mTexId( TexId ),
@@ -156,11 +156,13 @@ void cShape::OffsetY( const eeFloat& offsety ) {
}
void cShape::Draw( const eeFloat& X, const eeFloat& Y, const eeRGBA& Color, const eeFloat& Angle, const eeFloat& Scale, const EE_RENDERALPHAS& Blend, const EE_RENDERTYPE& Effect, const bool& ScaleRendered ) {
- cTextureFactory::Instance()->DrawEx( mTexId, X + mOffSetX, Y + mOffSetY, mDestWidth, mDestHeight, Angle, Scale, Color, Color, Color, Color, Blend, Effect, ScaleRendered, mSrcRect );
+ if ( NULL != mTexture )
+ mTexture->DrawEx( X + mOffSetX, Y + mOffSetY, mDestWidth, mDestHeight, Angle, Scale, Color, Color, Color, Color, Blend, Effect, ScaleRendered, mSrcRect );
}
void cShape::Draw( const eeFloat& X, const eeFloat& Y, const eeFloat& Angle, const eeFloat& Scale, const eeRGBA& Color0, const eeRGBA& Color1, const eeRGBA& Color2, const eeRGBA& Color3, const EE_RENDERALPHAS& Blend, const EE_RENDERTYPE& Effect, const bool& ScaleRendered ) {
- cTextureFactory::Instance()->DrawEx( mTexId, X + mOffSetX, Y + mOffSetY, mDestWidth, mDestHeight, Angle, Scale, Color0, Color1, Color2, Color3, Blend, Effect, ScaleRendered, mSrcRect );
+ if ( NULL != mTexture )
+ mTexture->DrawEx( X + mOffSetX, Y + mOffSetY, mDestWidth, mDestHeight, Angle, Scale, Color0, Color1, Color2, Color3, Blend, Effect, ScaleRendered, mSrcRect );
}
cTexture * cShape::GetTexture() {
@@ -169,7 +171,7 @@ cTexture * cShape::GetTexture() {
void cShape::ReplaceColor(eeColorA ColorKey, eeColorA NewColor) {
mTexture->Lock();
-
+
for ( eeInt y = mSrcRect.Top; y < mSrcRect.Bottom; y++ ) {
for ( eeInt x = mSrcRect.Left; x < mSrcRect.Right; x++ ) {
if ( mTexture->GetPixel( x, y ) == ColorKey )
@@ -194,7 +196,7 @@ void cShape::CacheAlphaMask() {
mAlpha = new Uint8[ ( mSrcRect.Right - mSrcRect.Left ) * ( mSrcRect.Bottom - mSrcRect.Top ) ];
mTexture->Lock();
-
+
eeInt rY = 0;
eeInt rX = 0;
eeInt rW = mSrcRect.Right - mSrcRect.Left;
@@ -218,7 +220,7 @@ void cShape::CacheColors() {
mPixels = new eeColorA[ ( mSrcRect.Right - mSrcRect.Left ) * ( mSrcRect.Bottom - mSrcRect.Top ) ];
mTexture->Lock();
-
+
eeInt rY = 0;
eeInt rX = 0;
eeInt rW = mSrcRect.Right - mSrcRect.Left;
diff --git a/src/graphics/csprite.cpp b/src/graphics/csprite.cpp
index 700433ee1..0d3b57eab 100755
--- a/src/graphics/csprite.cpp
+++ b/src/graphics/csprite.cpp
@@ -165,7 +165,7 @@ void cSprite::Update( const eeFloat& x, const eeFloat& y, const eeFloat& Scale,
Uint32 cSprite::GetTexture(const eeUint& FrameNum, const eeUint& SubFrameNum) {
if ( FrameNum < Frame.size() && SubFrameNum < mFrameData.SubFrames )
return Frame[FrameNum].Spr[SubFrameNum]->Texture();
-
+
return 0;
}
@@ -180,7 +180,7 @@ bool cSprite::CreateStatic(const Uint32& TexId, const eeFloat& DestWidth, const
mFrameData.SubFrames = 1;
mAnimated = false;
eeUint id = FramePos();
-
+
return AddSubFrame(TexId, id, 0, DestWidth, DestHeight, offSetX, offSetY, TexSector);
}
@@ -208,6 +208,11 @@ eeUint cSprite::AddFrame(const Uint32& TexId, const eeFloat& DestWidth, const ee
}
bool cSprite::AddSubFrame(const Uint32& TexId, const eeUint& NumFrame, const eeUint& NumSubFrame, const eeFloat& DestWidth, const eeFloat& DestHeight, const eeFloat& offSetX, const eeFloat& offSetY, const eeRecti& TexSector) {
+ cTexture * Tex = cTextureFactory::instance()->GetTexture( TexId );
+
+ if ( NULL == Tex )
+ return false;
+
eeUint NF, NSF;
if ( NumFrame >= Frame.size() )
@@ -232,8 +237,8 @@ bool cSprite::AddSubFrame(const Uint32& TexId, const eeUint& NumFrame, const eeU
if ( TexSector.Right > 0 && TexSector.Bottom > 0 )
S->SrcRect( TexSector );
else
- S->SrcRect( eeRecti( 0, 0, (Int32)cTextureFactory::instance()->GetTextureWidth(TexId), (Int32)cTextureFactory::instance()->GetTextureHeight(TexId) ) );
-
+ S->SrcRect( eeRecti( 0, 0, (Int32)Tex->Width(), (Int32)Tex->Height() ) );
+
if ( DestWidth > 0 )
S->DestWidth( DestWidth );
else
@@ -246,7 +251,7 @@ bool cSprite::AddSubFrame(const Uint32& TexId, const eeUint& NumFrame, const eeU
S->OffsetX( offSetX );
S->OffsetY( offSetY );
-
+
return true;
}
diff --git a/src/graphics/ctexture.cpp b/src/graphics/ctexture.cpp
index b40c62745..0b03d86c7 100755
--- a/src/graphics/ctexture.cpp
+++ b/src/graphics/ctexture.cpp
@@ -1,24 +1,25 @@
#include "ctexture.hpp"
+#include "cglobalbatchrenderer.hpp"
namespace EE { namespace Graphics {
-cTexture::cTexture() :
- mFilepath(""),
+cTexture::cTexture() :
+ mFilepath(""),
mId(0),
- mTexture(0),
- mWidth(0),
- mHeight(0),
- mImgWidth(0),
- mImgHeight(0),
- mChannels(4),
- mMipmap(true),
- mModified(false),
- mColorKey(true),
- mClampMode( EE_CLAMP_TO_EDGE ),
- mFilter( TEX_LINEAR ),
- mCompressedTexture(false),
- mLocked(false),
- mGrabed(false),
+ mTexture(0),
+ mWidth(0),
+ mHeight(0),
+ mImgWidth(0),
+ mImgHeight(0),
+ mChannels(4),
+ mMipmap(true),
+ mModified(false),
+ mColorKey(true),
+ mClampMode( EE_CLAMP_TO_EDGE ),
+ mFilter( TEX_LINEAR ),
+ mCompressedTexture(false),
+ mLocked(false),
+ mGrabed(false),
mPixels(NULL)
{
}
@@ -68,7 +69,7 @@ cTexture& cTexture::operator =(const cTexture& Other) {
std::swap(mGrabed, Temp.mGrabed);
std::swap(mChannels, Temp.mChannels);
Pixels( reinterpret_cast( Temp.mPixels ) );
-
+
return *this;
}
@@ -76,12 +77,12 @@ void cTexture::DeleteTexture() {
if ( mTexture ) {
GLuint Texture = static_cast(mTexture);
glDeleteTextures(1, &Texture);
-
+
mTexture = 0;
mModified = false;
mLocked = false;
mGrabed = false;
-
+
eeSAFE_DELETE_ARRAY( mPixels );
}
}
@@ -93,14 +94,14 @@ cTexture::cTexture( const Uint32& texture, const eeInt& width, const eeInt& heig
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 );
-
+
mTexture = texture;
mWidth = width;
mHeight = height;
mImgWidth = imgwidth;
mImgHeight = imgheight;
mMipmap = UseMipmap;
-
+
mColorKey = ColorKey;
mClampMode = ClampMode;
mCompressedTexture = CompressedTexture;
@@ -110,17 +111,17 @@ void cTexture::Create( const Uint32& texture, const eeInt& width, const eeInt& h
mGrabed = false;
mFilter = TEX_LINEAR;
-
+
Pixels(data);
}
void cTexture::Pixels( const Uint8* data ) {
if ( data != NULL ) {
eeSAFE_DELETE_ARRAY( mPixels );
-
+
eeUint size = (eeUint)mWidth * (eeUint)mHeight;
mPixels = new eeColorA[ size ];
-
+
memcpy( reinterpret_cast( mPixels ), reinterpret_cast ( data ), size );
}
}
@@ -139,7 +140,7 @@ eeColorA* cTexture::Lock() {
mWidth = (eeInt)width;
mHeight = (eeInt)height;
-
+
if ( !( eeARRAY_SIZE( mPixels ) >= (eeUint)width * (eeUint)height ) ) {
eeSAFE_DELETE_ARRAY( mPixels );
eeUint size = (eeUint)mWidth * (eeUint)mHeight;
@@ -264,11 +265,11 @@ void cTexture::SetTextureFilter(const EE_TEX_FILTER& filter) {
void cTexture::ReplaceColor(eeColorA ColorKey, eeColorA NewColor) {
Lock();
-
+
for ( eeInt i = 0; i < mWidth * mHeight; i++ )
if ( mPixels[i] == ColorKey )
mPixels[i] = NewColor;
-
+
Unlock(false, true);
}
@@ -317,4 +318,217 @@ void cTexture::ClearCache() {
eeSAFE_DELETE_ARRAY( mPixels );
}
+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);
+}
+
+void cTexture::DrawFast( const eeFloat& x, const eeFloat& y, const eeFloat& Angle, const eeFloat& Scale, const eeColorA& Color, const EE_RENDERALPHAS &blend, const eeFloat &width, const eeFloat &height ) {
+ cBatchRenderer * BR = cGlobalBatchRenderer::instance();
+
+ eeFloat w = width, h = height;
+ if (!w) w = (eeFloat)ImgWidth();
+ if (!h) h = (eeFloat)ImgHeight();
+
+ BR->SetTexture( this );
+ BR->SetBlendFunc( blend );
+
+ BR->QuadsBegin();
+ BR->QuadsSetColor( Color );
+
+ if ( ClampMode() == EE_CLAMP_REPEAT )
+ BR->QuadsSetSubsetFree( 0, 0, 0, height / h, width / w, height / h, width / w, 0 );
+
+ BR->BatchQuadEx( x, y, w, h, Angle, Scale );
+
+ BR->DrawOpt();
+}
+
+void cTexture::DrawEx( const eeFloat &x, const eeFloat &y, const eeFloat &width, const eeFloat &height, const eeFloat &Angle, const eeFloat &Scale, const eeColorA& Color0, const eeColorA& Color1, const eeColorA& Color2, const eeColorA& Color3, const EE_RENDERALPHAS &blend, const EE_RENDERTYPE &Effect, const bool &ScaleCentered, const eeRecti& texSector) {
+ cBatchRenderer * BR = cGlobalBatchRenderer::instance();
+
+ bool renderdiv = true;
+ eeFloat mx = x;
+ eeFloat my = y;
+ eeFloat iwidth, iheight;
+
+ eeRecti Sector = texSector;
+
+ eeFloat w = (eeFloat)ImgWidth();
+ eeFloat h = (eeFloat)ImgHeight();
+
+ if (Sector.Right == 0 && Sector.Bottom == 0) {
+ Sector.Left = 0;
+ Sector.Top = 0;
+ Sector.Right = ImgWidth();
+ Sector.Bottom = ImgHeight();
+ }
+
+ if (!width && !height) {
+ iwidth = static_cast (Sector.Right - Sector.Left);
+ iheight = static_cast (Sector.Bottom - Sector.Top);
+ } else {
+ iwidth = width;
+ iheight = height;
+ }
+
+ if ( Scale != 1.0f ) {
+ if ( ScaleCentered ) {
+ eeFloat halfW = w * 0.5f;
+ eeFloat halfH = h * 0.5f;
+ mx = mx + halfW - halfW * Scale;
+ my = my + halfH - halfH * Scale;
+ }
+ iwidth *= Scale;
+ iheight *= Scale;
+ }
+
+ if ( Sector.Left == 0 && Sector.Top == 0 && Sector.Right == w && Sector.Bottom == h )
+ renderdiv = false;
+
+ BR->SetTexture( this );
+ BR->SetBlendFunc( blend );
+
+ BR->QuadsBegin();
+ BR->QuadsSetColorFree( Color0, Color1, Color2, Color3 );
+
+ if ( Effect <= 3 ) {
+ if ( ClampMode() == EE_CLAMP_REPEAT ) {
+ if ( Effect == RN_NORMAL )
+ BR->QuadsSetSubsetFree( 0, 0, 0, height / h, width / w, height / h, width / w, 0 );
+ else if ( Effect == RN_MIRROR )
+ BR->QuadsSetSubsetFree( width / w, 0, width / w, height / h, 0, height / h, 0, 0 );
+ else if ( RN_FLIP )
+ BR->QuadsSetSubsetFree( 0, height / h, 0, 0, width / w, 0, width / w, height / h );
+ else
+ BR->QuadsSetSubsetFree( width / w, height / h, width / w, 0, 0, 0, 0, height / h );
+ } else {
+ if ( Effect == RN_NORMAL ) {
+ if ( renderdiv )
+ BR->QuadsSetSubsetFree( Sector.Left / w, Sector.Top / h, Sector.Left / w, Sector.Bottom / h, Sector.Right / w, Sector.Bottom / h, Sector.Right / w, Sector.Top / h );
+ } else if ( Effect == RN_MIRROR ) {
+ if ( renderdiv )
+ BR->QuadsSetSubsetFree( Sector.Right / w, Sector.Top / h, Sector.Right / w, Sector.Bottom / h, Sector.Left / w, Sector.Bottom / h, Sector.Left / w, Sector.Top / h );
+ else
+ BR->QuadsSetSubsetFree( 1, 0, 1, 1, 0, 1, 0, 0 );
+ } else if ( Effect == RN_FLIP ) {
+ if ( renderdiv )
+ BR->QuadsSetSubsetFree( Sector.Left / w, Sector.Bottom / h, Sector.Left / w, Sector.Top / h, Sector.Right / w, Sector.Top / h, Sector.Right / w, Sector.Bottom / h );
+ else
+ BR->QuadsSetSubsetFree( 0, 1, 0, 0, 1, 0, 1, 1 );
+ } else if ( Effect == RN_FLIPMIRROR ) {
+ if ( renderdiv )
+ BR->QuadsSetSubsetFree( Sector.Right / w, Sector.Bottom / h, Sector.Right / w, Sector.Top / h, Sector.Left / w, Sector.Top / h, Sector.Left / w, Sector.Bottom / h );
+ else
+ BR->QuadsSetSubsetFree( 1, 1, 1, 0, 0, 0, 0, 1 );
+ }
+ }
+
+ BR->BatchQuad( mx, my, iwidth, iheight, Angle );
+ } else {
+ eeRectf TmpR( mx, my, mx + iwidth, my + iheight );
+ eeQuad2f Q = eeQuad2f( eeVector2f( TmpR.Left, TmpR.Top ), eeVector2f( TmpR.Left, TmpR.Bottom ), eeVector2f( TmpR.Right, TmpR.Bottom ), eeVector2f( TmpR.Right, TmpR.Top ) );
+
+ if ( Effect == RN_ISOMETRIC ) {
+ Q.V[0].x += ( TmpR.Right - TmpR.Left );
+ Q.V[1].y -= ( ( TmpR.Bottom - TmpR.Top ) * 0.5f );
+ Q.V[3].x += ( TmpR.Right - TmpR.Left );
+ Q.V[3].y += ( ( TmpR.Bottom - TmpR.Top ) * 0.5f );
+ } else if ( Effect == RN_ISOMETRICVERTICAL ) {
+ Q.V[0].y -= ( ( TmpR.Bottom - TmpR.Top ) * 0.5f );
+ Q.V[1].y -= ( ( TmpR.Bottom - TmpR.Top ) * 0.5f );
+ } else if ( Effect == RN_ISOMETRICVERTICALNEGATIVE ) {
+ Q.V[2].y -= ( ( TmpR.Bottom - TmpR.Top ) * 0.5f );
+ Q.V[3].y -= ( ( TmpR.Bottom - TmpR.Top ) * 0.5f );
+ }
+ if ( Angle != 0.0f ) {
+ eeVector2f Center = eeVector2f ( TmpR.Left + (TmpR.Right - TmpR.Left) * 0.5f , TmpR.Top + (TmpR.Bottom - TmpR.Top) * 0.5f );
+ Q.Rotate( Angle, Center );
+ }
+
+ BR->BatchQuadFree( Q[0].x, Q[0].y, Q[1].x, Q[1].y, Q[2].x, Q[2].y, Q[3].x, Q[3].y );
+ }
+
+ BR->DrawOpt();
+}
+
+void cTexture::DrawQuad( const eeQuad2f& Q, const eeFloat &offsetx, const eeFloat &offsety, const eeFloat &Angle, const eeFloat &Scale, const eeColorA& Color, const EE_RENDERALPHAS &blend, const eeRecti& texSector) {
+ DrawQuadEx( Q, offsetx, offsety, Angle, Scale, Color, Color, Color, Color, blend, texSector);
+}
+
+void cTexture::DrawQuadEx( const eeQuad2f& Q, const eeFloat &offsetx, const eeFloat &offsety, const eeFloat &Angle, const eeFloat &Scale, const eeColorA& Color0, const eeColorA& Color1, const eeColorA& Color2, const eeColorA& Color3, const EE_RENDERALPHAS &blend, const eeRecti& texSector ) {
+ cBatchRenderer * BR = cGlobalBatchRenderer::instance();
+
+ bool renderdiv = true;
+ eeQuad2f mQ = Q;
+ eeFloat MinX = mQ.V[0].x, MaxX = mQ.V[0].x, MinY = mQ.V[0].y, MaxY = mQ.V[0].y;
+ eeVector2f QCenter;
+
+ eeRecti Sector = texSector;
+
+ eeFloat w = (eeFloat)ImgWidth();
+ eeFloat h = (eeFloat)ImgHeight();
+
+ if (Sector.Right == 0 && Sector.Bottom == 0) {
+ Sector.Left = 0;
+ Sector.Top = 0;
+ Sector.Right = ImgWidth();
+ Sector.Bottom = ImgHeight();
+ }
+
+ if ( Sector.Left == 0 && Sector.Top == 0 && Sector.Right == w && Sector.Bottom == h )
+ renderdiv = false;
+
+ BR->SetTexture( this );
+ BR->SetBlendFunc( blend );
+
+ BR->QuadsBegin();
+ BR->QuadsSetColorFree( Color0, Color1, Color2, Color3 );
+
+ if ( Angle != 0 || Scale != 1.0f || ClampMode() == EE_CLAMP_REPEAT ) {
+ for (Uint8 i = 1; i < 4; i++ ) {
+ if ( MinX > Q.V[i].x ) MinX = Q.V[i].x;
+ if ( MaxX < Q.V[i].x ) MaxX = Q.V[i].x;
+ if ( MinY > Q.V[i].y ) MinY = Q.V[i].y;
+ if ( MaxY < Q.V[i].y ) MaxY = Q.V[i].y;
+ }
+
+ QCenter.x = MinX + ( MaxX - MinX ) * 0.5f;
+ QCenter.y = MinY + ( MaxY - MinY ) * 0.5f;
+ }
+
+ if ( Scale != 1.0f ) {
+ for (Uint8 i = 0; i < 4; i++ ) {
+ if ( mQ.V[i].x < QCenter.x )
+ mQ.V[i].x = QCenter.x - fabs(QCenter.x - mQ.V[i].x) * Scale;
+ else
+ mQ.V[i].x = QCenter.x + fabs(QCenter.x - mQ.V[i].x) * Scale;
+
+ if ( mQ.V[i].y < QCenter.y )
+ mQ.V[i].y = QCenter.y - fabs(QCenter.y - mQ.V[i].y) * Scale;
+ else
+ mQ.V[i].y = QCenter.y + fabs(QCenter.y - mQ.V[i].y) * Scale;
+ }
+ }
+
+ if ( Angle != 0.0f )
+ mQ.Rotate( Angle, QCenter );
+
+ if ( ClampMode() == EE_CLAMP_REPEAT )
+ BR->QuadsSetSubsetFree( 0, 0, 0, (MaxY - MinY) / h, ( MaxX - MinX ) / w, (MaxY - MinY) / h, ( MaxX - MinX ) / w, 0 );
+ else if ( renderdiv )
+ BR->QuadsSetSubsetFree( Sector.Left / w, Sector.Top / h, Sector.Left / w, Sector.Bottom / h, Sector.Right / w, Sector.Bottom / h, Sector.Right / w, Sector.Top / h );
+
+ BR->BatchQuadFreeEx( offsetx + mQ[0].x, offsety + mQ[0].y, offsetx + mQ[1].x, offsety + mQ[1].y, offsetx + mQ[2].x, offsety + mQ[2].y, offsetx + mQ[3].x, offsety + mQ[3].y );
+
+ BR->DrawOpt();
+}
+
+void cTexture::TexId( const Uint32& id ) {
+ mTexId = id;
+}
+
+const Uint32& cTexture::TexId() const {
+ return mTexId;
+}
+
}}
diff --git a/src/graphics/ctexture.hpp b/src/graphics/ctexture.hpp
index 09f16d44b..af3214e89 100755
--- a/src/graphics/ctexture.hpp
+++ b/src/graphics/ctexture.hpp
@@ -125,45 +125,123 @@ class EE_API cTexture {
/** @return If the texture is Grabed */
bool Grabed() const { return mGrabed; }
-
+
/** @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();
+
+ /** Render the texture on screen ( with less internal mess, a little bit faster way )
+ * @param x The x position on screen
+ * @param y The y position on screen
+ * @param Angle The Angle of the texture rendered
+ * @param Scale The Scale factor of the rendered texture
+ * @param Color The texture color
+ * @param blend Set the Blend Mode ( default ALPHA_NORMAL )
+ * @param width The width of the texture rendered
+ * @param height The height of the texture rendered
+ */
+ void DrawFast( const eeFloat& x, const eeFloat& y, const eeFloat& Angle = 0.0f, const eeFloat& Scale = 1.0f, const eeColorA& Color = eeColorA(), const EE_RENDERALPHAS &blend = ALPHA_NORMAL, const eeFloat &width = 0, const eeFloat &height = 0 );
+
+ /** Render the texture on screen
+ * @param x The x position on screen
+ * @param y The y position on screen
+ * @param width The width of the texture rendered ( when Scale = 1, otherwise this width will be scaled like width * Scale )
+ * @param height The height of the texture rendered ( when Scale = 1, otherwise this height will be scaled like height * Scale )
+ * @param Angle The Angle of the texture rendered
+ * @param Scale The Scale factor of the rendered texture
+ * @param Color The texture color
+ * @param blend Set the Blend Mode ( default ALPHA_NORMAL )
+ * @param Effect Set the Render Effect ( default RN_NORMAL, no effect )
+ * @param ScaleCentered If true the texture will be scaled centered, otherwise will be scale from the Top - Left Corner
+ * @param texSector The texture sector to render. You can render only a part of the texture. ( default render all the texture )
+ */
+ void Draw( const eeFloat &x, const eeFloat &y, const eeFloat &Angle = 0, const eeFloat &Scale = 1.0f, const eeColorA& Color = eeColorA(255,255,255,255), const EE_RENDERALPHAS &blend = ALPHA_NORMAL, const EE_RENDERTYPE &Effect = RN_NORMAL, const bool &ScaleCentered = true, const eeRecti& texSector = eeRecti(0,0,0,0) );
+
+ /** Render the texture on screen. Extended because can set the vertex colors individually
+ * @param x The x position on screen
+ * @param y The y position on screen
+ * @param width The width of the texture rendered ( when Scale = 1, otherwise this width will be scaled like width * Scale )
+ * @param height The height of the texture rendered ( when Scale = 1, otherwise this height will be scaled like height * Scale )
+ * @param Angle The Angle of the texture rendered
+ * @param Scale The Scale factor of the rendered texture
+ * @param Color0 The Left - Top vertex color
+ * @param Color1 The Left - Bottom vertex color
+ * @param Color2 The Right - Bottom vertex color
+ * @param Color3 The Right - Top vertex color
+ * @param blend Set the Blend Mode ( default ALPHA_NORMAL )
+ * @param Effect Set the Render Effect ( default RN_NORMAL, no effect )
+ * @param ScaleCentered If true the texture will be scaled centered, otherwise will be scale from the Top - Left Corner
+ * @param texSector The texture sector to render. You can render only a part of the texture. ( default render all the texture )
+ */
+ void DrawEx( const eeFloat &x, const eeFloat &y, const eeFloat &width = 0.0f, const eeFloat &height = 0.0f, const eeFloat &Angle = 0, const eeFloat &Scale = 1.0f, const eeColorA& Color0 = eeColorA(255,255,255,255), const eeColorA& Color1 = eeColorA(255,255,255,255), const eeColorA& Color2 = eeColorA(255,255,255,255), const eeColorA& Color3 = eeColorA(255,255,255,255), const EE_RENDERALPHAS &blend = ALPHA_NORMAL, const EE_RENDERTYPE &Effect = RN_NORMAL, const bool &ScaleCentered = true, const eeRecti& texSector = eeRecti(0,0,0,0) );
+
+ /** Render a GL_QUAD on Screen
+ * @param Q The eeQuad2f
+ * @param offsetx The Offset X applyed to all the coordinates on eeQuad2f
+ * @param offsety The Offset Y applyed to all the coordinates on eeQuad2f
+ * @param Angle The Angle of the eeQuad2f rendered
+ * @param Scale The Scale of the eeQuad2f rendered
+ * @param Color The eeQuad2f color
+ * @param blend Set the Blend Mode ( default ALPHA_NORMAL )
+ * @param texSector The texture sector to render. You can render only a part of the texture. ( default render all the texture )
+ */
+ void DrawQuad( const eeQuad2f& Q, const eeFloat &offsetx = 0.0f, const eeFloat &offsety = 0.0f, const eeFloat &Angle = 0.0f, const eeFloat &Scale = 1.0f, const eeColorA& Color = eeColorA(255,255,255,255), const EE_RENDERALPHAS &blend = ALPHA_NORMAL, const eeRecti& texSector = eeRecti(0,0,0,0) );
+
+ /** Render a GL_QUAD on Screen
+ * @param Q The eeQuad2f
+ * @param offsetx The Offset X applyed to all the coordinates on eeQuad2f
+ * @param offsety The Offset X applyed to all the coordinates on eeQuad2f
+ * @param Angle The Angle of the eeQuad2f rendered
+ * @param Scale The Scale of the eeQuad2f rendered
+ * @param Color0 The Left - Top vertex color
+ * @param Color1 The Left - Bottom vertex color
+ * @param Color2 The Right - Bottom vertex color
+ * @param Color3 The Right - Top vertex color
+ * @param blend Set the Blend Mode ( default ALPHA_NORMAL )
+ * @param texSector The texture sector to render. You can render only a part of the texture. ( default render all the texture )
+ */
+ void DrawQuadEx( const eeQuad2f& Q, const eeFloat &offsetx = 0.0f, const eeFloat &offsety = 0.0f, const eeFloat &Angle = 0.0f, const eeFloat &Scale = 1.0f, const eeColorA& Color0 = eeColorA(255,255,255,255), const eeColorA& Color1 = eeColorA(255,255,255,255), const eeColorA& Color2 = eeColorA(255,255,255,255), const eeColorA& Color3 = eeColorA(255,255,255,255), const EE_RENDERALPHAS &blend = ALPHA_NORMAL, const eeRecti& texSector = eeRecti(0,0,0,0) );
+
+ /** Set the texture factory internal id of the texture */
+ void TexId( const Uint32& id );
+
+ /** @return The texture factory internal id of the texture */
+ const Uint32& TexId() const;
protected:
- std::string mFilepath;
-
- Uint32 mId;
-
- GLint mTexture;
-
- eeInt mWidth;
- eeInt mHeight;
- eeInt mImgWidth;
- eeInt mImgHeight;
-
- eeUint mChannels;
-
- bool mMipmap;
- bool mModified;
- eeRGB mColorKey;
-
- EE_CLAMP_MODE mClampMode;
- EE_TEX_FILTER mFilter;
- bool mCompressedTexture;
-
- bool mLocked;
- bool mGrabed;
-
- eeColorA* mPixels;
-
+ std::string mFilepath;
+
+ Uint32 mId;
+ Uint32 mTexId;
+ GLint mTexture;
+
+ eeInt mWidth;
+ eeInt mHeight;
+ eeInt mImgWidth;
+ eeInt mImgHeight;
+
+ eeUint mChannels;
+
+ bool mMipmap;
+ bool mModified;
+ eeRGB mColorKey;
+
+ EE_CLAMP_MODE mClampMode;
+ EE_TEX_FILTER mFilter;
+ bool mCompressedTexture;
+
+ bool mLocked;
+ bool mGrabed;
+
+ eeColorA* mPixels;
+
void ApplyClampMode();
};
diff --git a/src/graphics/ctexturefactory.cpp b/src/graphics/ctexturefactory.cpp
index f6e99c3bf..f194d508f 100755
--- a/src/graphics/ctexturefactory.cpp
+++ b/src/graphics/ctexturefactory.cpp
@@ -5,7 +5,12 @@ using namespace EE::Window;
namespace EE { namespace Graphics {
-cTextureFactory::cTextureFactory() : mCurrentTexture(0), mIsCalcPowOfTwo(false), mNextKey(1), mMemSize(0) {
+cTextureFactory::cTextureFactory() :
+ mCurrentTexture(0),
+ mIsCalcPowOfTwo(false),
+ mNextKey(0),
+ mMemSize(0)
+{
mTextures.clear();
Log = cLog::instance();
@@ -29,102 +34,47 @@ void cTextureFactory::BindPrev( const GLint& PreviousTexture ) {
mCurrentTexture = PreviousTexture;
}
-eeUint 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 flags = mipmap ? SOIL_FLAG_MIPMAPS : 0;
- Uint32 TexId;
+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 );
- int width = (int)Width;
- int height = (int)Height;
+ Uint32 TexId = LoadFromPixels( reinterpret_cast ( &tmpTex[0] ), Width, Height, 4, mipmap, eeRGB(true), ClampMode, CompressTexture, KeepLocalCopy );
- flags = (ClampMode == EE_CLAMP_REPEAT) ? (flags | SOIL_FLAG_TEXTURE_REPEATS) : flags;
- flags = (CompressTexture) ? ( flags | SOIL_FLAG_COMPRESS_TO_DXT ) : flags;
+ tmpTex.clear();
- GLint PreviousTexture = GetPrevTex();
- TexId = SOIL_create_OGL_texture( reinterpret_cast( &tmpTex[0] ), &width, &height, SOIL_LOAD_RGBA, SOIL_CREATE_NEW_ID, flags);
- BindPrev( PreviousTexture );
-
- if ( TexId ) {
- tmpTex.clear();
- Log->Write( "Empty Texture created." );
- return PushTexture("", TexId, width, height, width, height, mipmap, SOIL_LOAD_RGBA, eeRGB(true), ClampMode, CompressTexture, 0, KeepLocalCopy);
- }
-
- Log->Write( SOIL_last_result() );
-
- return 0;
+ return TexId;
}
-eeUint cTextureFactory::Load( const std::string& filepath, const bool& mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture ) {
- return iLoad(filepath, mipmap, ColorKey, ClampMode, CompressTexture, 0);
+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 );
}
-eeUint cTextureFactory::iLoad( const std::string& filepath, const bool& mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const Uint32& TexPos ) {
- int ImgWidth, ImgHeight, ImgChannels;
- Uint32 flags = mipmap ? SOIL_FLAG_MIPMAPS : 0;
+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;
- Uint32 TexId = 0;
-
- if ( FileExists( filepath ) ) {
- unsigned char* PixelsPtr = SOIL_load_image(filepath.c_str(), &ImgWidth, &ImgHeight, &ImgChannels, SOIL_LOAD_AUTO);
-
- eeInt RealImgWidth = ImgWidth;
- eeInt RealImgHeight = ImgHeight;
-
- if (PixelsPtr) {
- flags = (ClampMode == EE_CLAMP_REPEAT) ? (flags | SOIL_FLAG_TEXTURE_REPEATS) : flags;
- flags = (CompressTexture) ? ( flags | SOIL_FLAG_COMPRESS_TO_DXT ) : flags;
-
- GLint PreviousTexture = GetPrevTex();
- TexId = SOIL_create_OGL_texture(PixelsPtr, &ImgWidth, &ImgHeight, ImgChannels, ( ( TexPos==0 ) ? SOIL_CREATE_NEW_ID : GetTexture(TexPos)->Texture() ), flags);
-
- SOIL_free_image_data(PixelsPtr);
- BindPrev( PreviousTexture );
-
- Log->Write( "Texture " + filepath + " loaded." );
-
- return PushTexture(filepath, TexId, ImgWidth, ImgHeight, RealImgWidth, RealImgHeight, mipmap, static_cast( ImgChannels ), ColorKey, ClampMode, CompressTexture, TexPos );
- } else {
- Log->Write( SOIL_last_result() );
- }
- }
-
- return 0;
-}
-
-eeUint cTextureFactory::LoadFromPixels( const unsigned char* Surface, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const bool& mipmap, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) {
- return iLoadFromPixels( Surface, Width, Height, Channels, mipmap, ClampMode, CompressTexture, KeepLocalCopy );
-}
-
-eeUint cTextureFactory::iLoadFromPixels( const unsigned char* Surface, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const bool& mipmap, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy, const Uint32& TexPos ) {
- Uint32 cTexId = 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();
- cTexId = SOIL_create_OGL_texture(Surface, &width, &height, Channels, ( ( TexPos==0 ) ? SOIL_CREATE_NEW_ID : GetTexture(TexPos)->Texture() ), flags);
+ tTexId = SOIL_create_OGL_texture(Surface, &width, &height, Channels, ( ( TexPos==0 ) ? SOIL_CREATE_NEW_ID : GetTexture(TexPos)->Texture() ), flags);
BindPrev( PreviousTexture );
- if (cTexId) {
- Log->Write( "Texture loaded from memory ( RAW format )." );
+ if ( tTexId )
+ return iPushTexture( FileName, tTexId, Width, Height, width, height, mipmap, static_cast( Channels ), ColorKey, ClampMode, CompressTexture, KeepLocalCopy, TexPos );
- return PushTexture("", cTexId, width, height, width, height, mipmap, static_cast( Channels ), eeRGB(true), ClampMode, CompressTexture, TexPos, KeepLocalCopy);
- }
} else {
Log->Write( SOIL_last_result() );
}
-
+
return 0;
}
-eeUint 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 ) {
+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 ) )
@@ -133,49 +83,54 @@ eeUint cTextureFactory::LoadFromPack( cPack* Pack, const std::string& FilePackPa
return 0;
}
-eeUint 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 ) {
- Uint32 cTexId = 0;
+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);
+ unsigned char * PixelsPtr = SOIL_load_image_from_memory(Surface, Size, &ImgWidth, &ImgHeight, &ImgChannels, SOIL_LOAD_AUTO);
- eeInt RealImgWidth = ImgWidth;
- eeInt RealImgHeight = ImgHeight;
-
- if (PixelsPtr) {
- 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();
- cTexId = SOIL_create_OGL_texture(PixelsPtr, &ImgWidth, &ImgHeight, ImgChannels, SOIL_CREATE_NEW_ID, flags);
-
- SOIL_free_image_data(PixelsPtr);
- BindPrev( PreviousTexture );
-
- if (cTexId) {
- Log->Write( "Texture loaded from memory." );
-
- return PushTexture("", cTexId, ImgWidth, ImgHeight, RealImgWidth, RealImgHeight, mipmap, static_cast( ImgChannels ), ColorKey, ClampMode, CompressTexture, 0, KeepLocalCopy);
- }
- } else
+ if ( NULL != PixelsPtr )
+ return LoadFromPixels( PixelsPtr, ImgWidth, ImgHeight, ImgChannels, mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy );
+ else
Log->Write( SOIL_last_result() );
return 0;
}
-eeUint 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 Uint32& TexPos, const bool& LocalCopy ) {
- Uint32 Pos = mNextKey;
- eeInt MyWidth = ImgWidth;
- eeInt MyHeight = ImgHeight;
+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 );
+}
- if (TexPos != 0) {
+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 )
+ return iLoadFromPixels( PixelsPtr, ImgWidth, ImgHeight, ImgChannels, mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy, filepath, TexPos );
+ 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 = mNextKey;
+ eeInt MyWidth = ImgWidth;
+ eeInt MyHeight = ImgHeight;
+
+ if ( TexPos != 0 ) {
Pos = TexPos;
- cTexture* Tex = GetTexture(TexPos);
+ Tex = GetTexture( TexPos );
// Recover the real image size
- if ( Tex && TexId == Tex->Texture() ) {
+ if ( NULL != Tex && TexId == Tex->Texture() ) {
Tex->Width( Width );
Tex->Height( Height );
@@ -184,16 +139,19 @@ eeUint cTextureFactory::PushTexture(const std::string& filepath, const Uint32& T
mMemSize -= GetTexMemSize( TexPos );
}
- } else
+ } else {
mNextKey++;
+ }
- if ( mNextKey >= mTextures.size() )
+ if ( Pos == mTextures.size() ) {
mTextures.push_back( new cTexture() );
- else if ( mTextures[ mNextKey ] == NULL )
- mTextures[ mNextKey ] = new cTexture();
+ } else if ( mTextures[ Pos ] == NULL ) {
+ mTextures[ Pos ] = new cTexture();
+ }
- cTexture* Tex = GetTexture(Pos);
+ Tex = GetTexture( Pos );
Tex->Create( TexId, Width, Height, MyWidth, MyHeight, Mipmap, Channels, filepath, ColorKey, ClampMode, CompressTexture );
+ Tex->TexId( Pos );
if ( !ColorKey.voidRGB )
Tex->CreateMaskFromColor( eeColor( ColorKey.R(), ColorKey.G(), ColorKey.B() ) , 0 );
@@ -209,239 +167,14 @@ eeUint cTextureFactory::PushTexture(const std::string& filepath, const Uint32& T
}
void cTextureFactory::Bind( const cTexture* Tex ) {
- if( mCurrentTexture != (Int32)Tex->Texture() ) {
+ if( NULL != Tex && mCurrentTexture != (Int32)Tex->Texture() ) {
glBindTexture( GL_TEXTURE_2D, Tex->Texture() );
mCurrentTexture = Tex->Texture();
}
}
void cTextureFactory::Bind( const Uint32& TexId ) {
- if (TexId < 1) return;
- cTexture* Tex = GetTexture(TexId);
-
- if( mCurrentTexture != (Int32)Tex->Texture() ) {
- glBindTexture( GL_TEXTURE_2D, Tex->Texture() );
- mCurrentTexture = Tex->Texture();
- }
-}
-
-void cTextureFactory::Draw(const Uint32 &TexId, 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(TexId, x, y, 0, 0, Angle, Scale, Color, Color, Color, Color, blend, Effect, ScaleCentered, texSector);
-}
-
-void cTextureFactory::DrawFast( const Uint32& TexId, const eeFloat& x, const eeFloat& y, const eeFloat& Angle, const eeFloat& Scale, const eeColorA& Color, const EE_RENDERALPHAS &blend, const eeFloat &width, const eeFloat &height ) {
- cTexture* Tex = GetTexture(TexId);
- eeFloat w = width, h = height;
- if (!w) w = (eeFloat)Tex->ImgWidth();
- if (!h) h = (eeFloat)Tex->ImgHeight();
-
- BR->SetTexture( TexId );
- BR->SetBlendFunc( blend );
-
- BR->QuadsBegin();
- BR->QuadsSetColor( Color );
-
- if ( Tex->ClampMode() == EE_CLAMP_REPEAT )
- BR->QuadsSetSubsetFree( 0, 0, 0, height / h, width / w, height / h, width / w, 0 );
-
- BR->BatchQuadEx( x, y, w, h, Angle, Scale );
-
- BR->DrawOpt();
-}
-
-void cTextureFactory::DrawEx(const Uint32 &TexId, const eeFloat &x, const eeFloat &y, const eeFloat &width, const eeFloat &height, const eeFloat &Angle, const eeFloat &Scale, const eeColorA& Color0, const eeColorA& Color1, const eeColorA& Color2, const eeColorA& Color3, const EE_RENDERALPHAS &blend, const EE_RENDERTYPE &Effect, const bool &ScaleCentered, const eeRecti& texSector) {
- bool renderdiv = true;
- eeFloat mx = x;
- eeFloat my = y;
- eeFloat iwidth, iheight;
-
- eeRecti Sector = texSector;
- cTexture* Tex = GetTexture(TexId);
-
- eeFloat w = (eeFloat)Tex->ImgWidth();
- eeFloat h = (eeFloat)Tex->ImgHeight();
-
- if (Sector.Right == 0 && Sector.Bottom == 0) {
- Sector.Left = 0;
- Sector.Top = 0;
- Sector.Right = Tex->ImgWidth();
- Sector.Bottom = Tex->ImgHeight();
- }
-
- if (!width && !height) {
- iwidth = static_cast (Sector.Right - Sector.Left);
- iheight = static_cast (Sector.Bottom - Sector.Top);
- } else {
- iwidth = width;
- iheight = height;
- }
-
- if ( Scale != 1.0f ) {
- if ( ScaleCentered ) {
- eeFloat halfW = w * 0.5f;
- eeFloat halfH = h * 0.5f;
- mx = mx + halfW - halfW * Scale;
- my = my + halfH - halfH * Scale;
- }
- iwidth *= Scale;
- iheight *= Scale;
- }
-
- if ( Sector.Left == 0 && Sector.Top == 0 && Sector.Right == w && Sector.Bottom == h )
- renderdiv = false;
-
- BR->SetTexture( TexId );
- BR->SetBlendFunc( blend );
-
- BR->QuadsBegin();
- BR->QuadsSetColorFree( Color0, Color1, Color2, Color3 );
-
- if ( Effect <= 3 ) {
- if ( Tex->ClampMode() == EE_CLAMP_REPEAT ) {
- if ( Effect == RN_NORMAL )
- BR->QuadsSetSubsetFree( 0, 0, 0, height / h, width / w, height / h, width / w, 0 );
- else if ( Effect == RN_MIRROR )
- BR->QuadsSetSubsetFree( width / w, 0, width / w, height / h, 0, height / h, 0, 0 );
- else if ( RN_FLIP )
- BR->QuadsSetSubsetFree( 0, height / h, 0, 0, width / w, 0, width / w, height / h );
- else
- BR->QuadsSetSubsetFree( width / w, height / h, width / w, 0, 0, 0, 0, height / h );
- } else {
- if ( Effect == RN_NORMAL ) {
- if ( renderdiv )
- BR->QuadsSetSubsetFree( Sector.Left / w, Sector.Top / h, Sector.Left / w, Sector.Bottom / h, Sector.Right / w, Sector.Bottom / h, Sector.Right / w, Sector.Top / h );
- } else if ( Effect == RN_MIRROR ) {
- if ( renderdiv )
- BR->QuadsSetSubsetFree( Sector.Right / w, Sector.Top / h, Sector.Right / w, Sector.Bottom / h, Sector.Left / w, Sector.Bottom / h, Sector.Left / w, Sector.Top / h );
- else
- BR->QuadsSetSubsetFree( 1, 0, 1, 1, 0, 1, 0, 0 );
- } else if ( Effect == RN_FLIP ) {
- if ( renderdiv )
- BR->QuadsSetSubsetFree( Sector.Left / w, Sector.Bottom / h, Sector.Left / w, Sector.Top / h, Sector.Right / w, Sector.Top / h, Sector.Right / w, Sector.Bottom / h );
- else
- BR->QuadsSetSubsetFree( 0, 1, 0, 0, 1, 0, 1, 1 );
- } else if ( Effect == RN_FLIPMIRROR ) {
- if ( renderdiv )
- BR->QuadsSetSubsetFree( Sector.Right / w, Sector.Bottom / h, Sector.Right / w, Sector.Top / h, Sector.Left / w, Sector.Top / h, Sector.Left / w, Sector.Bottom / h );
- else
- BR->QuadsSetSubsetFree( 1, 1, 1, 0, 0, 0, 0, 1 );
- }
- }
-
- BR->BatchQuad( mx, my, iwidth, iheight, Angle );
- } else {
- eeRectf TmpR( mx, my, mx + iwidth, my + iheight );
- eeQuad2f Q = eeQuad2f( eeVector2f( TmpR.Left, TmpR.Top ), eeVector2f( TmpR.Left, TmpR.Bottom ), eeVector2f( TmpR.Right, TmpR.Bottom ), eeVector2f( TmpR.Right, TmpR.Top ) );
-
- if ( Effect == RN_ISOMETRIC ) {
- Q.V[0].x += ( TmpR.Right - TmpR.Left );
- Q.V[1].y -= ( ( TmpR.Bottom - TmpR.Top ) * 0.5f );
- Q.V[3].x += ( TmpR.Right - TmpR.Left );
- Q.V[3].y += ( ( TmpR.Bottom - TmpR.Top ) * 0.5f );
- } else if ( Effect == RN_ISOMETRICVERTICAL ) {
- Q.V[0].y -= ( ( TmpR.Bottom - TmpR.Top ) * 0.5f );
- Q.V[1].y -= ( ( TmpR.Bottom - TmpR.Top ) * 0.5f );
- } else if ( Effect == RN_ISOMETRICVERTICALNEGATIVE ) {
- Q.V[2].y -= ( ( TmpR.Bottom - TmpR.Top ) * 0.5f );
- Q.V[3].y -= ( ( TmpR.Bottom - TmpR.Top ) * 0.5f );
- }
- if ( Angle != 0.0f ) {
- eeVector2f Center = eeVector2f ( TmpR.Left + (TmpR.Right - TmpR.Left) * 0.5f , TmpR.Top + (TmpR.Bottom - TmpR.Top) * 0.5f );
- Q.Rotate( Angle, Center );
- }
-
- BR->BatchQuadFree( Q[0].x, Q[0].y, Q[1].x, Q[1].y, Q[2].x, Q[2].y, Q[3].x, Q[3].y );
- }
-
- BR->DrawOpt();
-}
-
-void cTextureFactory::DrawQuad(const Uint32 &TexId, const eeQuad2f& Q, const eeFloat &offsetx, const eeFloat &offsety, const eeFloat &Angle, const eeFloat &Scale, const eeColorA& Color, const EE_RENDERALPHAS &blend, const eeRecti& texSector) {
- DrawQuadEx(TexId, Q, offsetx, offsety, Angle, Scale, Color, Color, Color, Color, blend, texSector);
-}
-
-void cTextureFactory::DrawQuadEx(const Uint32 &TexId, const eeQuad2f& Q, const eeFloat &offsetx, const eeFloat &offsety, const eeFloat &Angle, const eeFloat &Scale, const eeColorA& Color0, const eeColorA& Color1, const eeColorA& Color2, const eeColorA& Color3, const EE_RENDERALPHAS &blend, const eeRecti& texSector ) {
- bool renderdiv = true;
- eeQuad2f mQ = Q;
- eeFloat MinX = mQ.V[0].x, MaxX = mQ.V[0].x, MinY = mQ.V[0].y, MaxY = mQ.V[0].y;
- eeVector2f QCenter;
-
- eeRecti Sector = texSector;
- cTexture* Tex = GetTexture(TexId);
-
- eeFloat w = (eeFloat)Tex->ImgWidth();
- eeFloat h = (eeFloat)Tex->ImgHeight();
-
- if (Sector.Right == 0 && Sector.Bottom == 0) {
- Sector.Left = 0;
- Sector.Top = 0;
- Sector.Right = Tex->ImgWidth();
- Sector.Bottom = Tex->ImgHeight();
- }
-
- if ( Sector.Left == 0 && Sector.Top == 0 && Sector.Right == w && Sector.Bottom == h )
- renderdiv = false;
-
- BR->SetTexture( TexId );
- BR->SetBlendFunc( blend );
-
- BR->QuadsBegin();
- BR->QuadsSetColorFree( Color0, Color1, Color2, Color3 );
-
- if ( Angle != 0 || Scale != 1.0f || Tex->ClampMode() == EE_CLAMP_REPEAT ) {
- for (Uint8 i = 1; i < 4; i++ ) {
- if ( MinX > Q.V[i].x ) MinX = Q.V[i].x;
- if ( MaxX < Q.V[i].x ) MaxX = Q.V[i].x;
- if ( MinY > Q.V[i].y ) MinY = Q.V[i].y;
- if ( MaxY < Q.V[i].y ) MaxY = Q.V[i].y;
- }
-
- QCenter.x = MinX + ( MaxX - MinX ) * 0.5f;
- QCenter.y = MinY + ( MaxY - MinY ) * 0.5f;
- }
-
- if ( Scale != 1.0f ) {
- for (Uint8 i = 0; i < 4; i++ ) {
- if ( mQ.V[i].x < QCenter.x )
- mQ.V[i].x = QCenter.x - fabs(QCenter.x - mQ.V[i].x) * Scale;
- else
- mQ.V[i].x = QCenter.x + fabs(QCenter.x - mQ.V[i].x) * Scale;
-
- if ( mQ.V[i].y < QCenter.y )
- mQ.V[i].y = QCenter.y - fabs(QCenter.y - mQ.V[i].y) * Scale;
- else
- mQ.V[i].y = QCenter.y + fabs(QCenter.y - mQ.V[i].y) * Scale;
- }
- }
-
- if ( Angle != 0.0f )
- mQ.Rotate( Angle, QCenter );
-
- if ( Tex->ClampMode() == EE_CLAMP_REPEAT )
- BR->QuadsSetSubsetFree( 0, 0, 0, (MaxY - MinY) / h, ( MaxX - MinX ) / w, (MaxY - MinY) / h, ( MaxX - MinX ) / w, 0 );
- else if ( renderdiv )
- BR->QuadsSetSubsetFree( Sector.Left / w, Sector.Top / h, Sector.Left / w, Sector.Bottom / h, Sector.Right / w, Sector.Bottom / h, Sector.Right / w, Sector.Top / h );
-
- BR->BatchQuadFreeEx( offsetx + mQ[0].x, offsety + mQ[0].y, offsetx + mQ[1].x, offsety + mQ[1].y, offsetx + mQ[2].x, offsety + mQ[2].y, offsetx + mQ[3].x, offsety + mQ[3].y );
-
- BR->DrawOpt();
-}
-
-Uint32 cTextureFactory::GetTextureId(const Uint32& TexId) {
- return GetTexture(TexId)->Texture();
-}
-
-eeFloat cTextureFactory::GetTextureWidth(const Uint32& TexId) {
- return (eeFloat)GetTexture(TexId)->Width();
-
-}
-
-eeFloat cTextureFactory::GetTextureHeight(const Uint32& TexId) {
- return (eeFloat)GetTexture(TexId)->Height();
-}
-
-std::string cTextureFactory::GetTexturePath(const Uint32& TexId) {
- return GetTexture(TexId)->Filepath();
+ Bind( GetTexture( TexId ) );
}
void cTextureFactory::UnloadTextures() {
@@ -461,13 +194,13 @@ void cTextureFactory::UnloadTextures() {
bool cTextureFactory::Remove( const Uint32& TexId ) {
if ( TexId < mTextures.size() && TexId > 0 ) {
mMemSize -= GetTexMemSize( TexId );
-
+
delete mTextures[ TexId ];
mTextures[ TexId ] = NULL;
-
+
if ( mCurrentTexture == (Int32)TexId )
mCurrentTexture = 0;
-
+
return true;
}
return false;
@@ -482,7 +215,7 @@ Uint32 cTextureFactory::Reload( const Uint32& TexId, const std::string& filepath
cTexture* Tex = GetTexture(TexId);
if ( Tex->LocalCopy() )
- Id = iLoadFromPixels( Tex->GetPixelsPtr(), (int)Tex->Width(), (int)Tex->Height(), SOIL_LOAD_RGBA, Tex->Mipmap(), Tex->ClampMode(), Tex->Compressed(), ( Tex->LocalCopy() && !Tex->Grabed() ), TexId );
+ 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 );
@@ -490,13 +223,12 @@ Uint32 cTextureFactory::Reload( const Uint32& TexId, const std::string& filepath
}
}
-Uint32 cTextureFactory::GetCurrentTexture() const {
+GLint cTextureFactory::GetCurrentTexture() const {
return mCurrentTexture;
}
-void cTextureFactory::SetCurrentTexture(const Uint32& TexId) {
- if ( TextureIdExists( TexId ) )
- mCurrentTexture = GetTexture(TexId)->Texture();
+void cTextureFactory::SetCurrentTexture( const GLint& TexId ) {
+ mCurrentTexture = TexId;
}
void cTextureFactory::ReloadAllTextures() {
@@ -504,7 +236,7 @@ void cTextureFactory::ReloadAllTextures() {
for ( Uint32 i = 1; i < mTextures.size(); i++ ) {
cTexture* Tex = GetTexture(i);
if ( Tex ) {
- if ( Tex->Filepath() != "" || Tex->LocalCopy() )
+ if ( ( Tex->Filepath() != "" && FileExists( Tex->Filepath() ) ) || Tex->LocalCopy() )
Reload(i);
else {
Tex->Lock();
@@ -593,28 +325,27 @@ eeUint cTextureFactory::GetValidTextureSize(const eeUint& Size) {
return NextPowOfTwo(Size);
}
-bool cTextureFactory::SaveImage(const std::string& filepath, const EE_SAVETYPE& Format, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const unsigned char* data) {
+bool cTextureFactory::SaveImage( const std::string& filepath, const EE_SAVETYPE& Format, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const unsigned char* data ) {
return 0 != SOIL_save_image ( filepath.c_str(), Format, Width, Height, Channels, data );
}
bool cTextureFactory::TextureIdExists( const Uint32& TexId ) {
- return ( TexId < mTextures.size() && TexId > 0 );
+ return ( TexId < mTextures.size() && TexId > 0 && NULL != mTextures[ TexId ] );
}
-cTexture* cTextureFactory::GetTexture( const Uint32& TexId ) {
+cTexture * cTextureFactory::GetTexture( const Uint32& TexId ) {
return mTextures[TexId];
}
void cTextureFactory::Allocate( const eeUint& size ) {
if ( size > mTextures.size() ) {
- mTextures.resize( size+1, NULL ); // 0 will be always null, so we add 1
- Log->Write( "Texture space allocated" );
+ mTextures.resize( size, NULL );
}
}
eeUint cTextureFactory::GetTexMemSize( const eeUint& TexId ) {
eeUint Size = 0;
-
+
if ( TexId < mTextures.size() && TexId > 0 ) {
cTexture* Tex = mTextures[ TexId ];
@@ -631,10 +362,10 @@ eeUint cTextureFactory::GetTexMemSize( const eeUint& TexId ) {
}
}
}
-
+
return Size;
}
-
+
return 0;
}
diff --git a/src/graphics/ctexturefactory.hpp b/src/graphics/ctexturefactory.hpp
index af0668bcb..e0cc5921a 100755
--- a/src/graphics/ctexturefactory.hpp
+++ b/src/graphics/ctexturefactory.hpp
@@ -20,22 +20,25 @@ class EE_API cTextureFactory: public cSingleton {
* @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
*/
- eeUint 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 Width Texture Width
* @param Height Texture Height
* @param Channels Texture Number of Channels (in bytes)
* @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 )
* @param KeepLocalCopy Keep the array data copy. ( usefull if want to reload the texture )
+ * @param FileName A filename to recognize the texture ( the path in case that was loaded from outside the texture factory ).
* @return Internal Texture Id
*/
- eeUint LoadFromPixels( const unsigned char* Surface, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const bool& mipmap = false, const EE_CLAMP_MODE& ClampMode = EE_CLAMP_TO_EDGE, const bool& CompressTexture = false, const bool& KeepLocalCopy = false );
+ 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("") );
/** Load a texture from Pack
* @param Pack Pointer to the pack instance
@@ -46,8 +49,8 @@ class EE_API cTextureFactory: public cSingleton {
* @param KeepLocalCopy Keep the array data copy. ( usefull if want to reload the texture )
* @return Internal Texture Id
*/
- eeUint 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 Size The size of the texture ( Width * Height * BytesPerPixel )
@@ -55,9 +58,10 @@ class EE_API cTextureFactory: public cSingleton {
* @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
*/
- eeUint 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* 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 );
/** Load a Texture from a file path
* @param filepath The path for the texture
@@ -65,9 +69,10 @@ class EE_API cTextureFactory: public cSingleton {
* @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
*/
- eeUint 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 );
+ 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
@@ -94,82 +99,10 @@ class EE_API cTextureFactory: public cSingleton {
*/
void Bind( const Uint32& TexId );
- /** Render the texture on screen ( with less internal mess, a little bit faster way )
- * @param TexId The internal Texture Id
- * @param x The x position on screen
- * @param y The y position on screen
- * @param Angle The Angle of the texture rendered
- * @param Scale The Scale factor of the rendered texture
- * @param Color The texture color
- * @param blend Set the Blend Mode ( default ALPHA_NORMAL )
- * @param width The width of the texture rendered
- * @param height The height of the texture rendered
+ /** Bind the the Texture indicated. This is usefull if you are rendering a texture outside this class.
+ * @param Tex The Texture Pointer
*/
- void DrawFast( const Uint32& TexId, const eeFloat& x, const eeFloat& y, const eeFloat& Angle = 0.0f, const eeFloat& Scale = 1.0f, const eeColorA& Color = eeColorA(), const EE_RENDERALPHAS &blend = ALPHA_NORMAL, const eeFloat &width = 0, const eeFloat &height = 0 );
-
- /** Render the texture on screen
- * @param TexId The internal Texture Id
- * @param x The x position on screen
- * @param y The y position on screen
- * @param width The width of the texture rendered ( when Scale = 1, otherwise this width will be scaled like width * Scale )
- * @param height The height of the texture rendered ( when Scale = 1, otherwise this height will be scaled like height * Scale )
- * @param Angle The Angle of the texture rendered
- * @param Scale The Scale factor of the rendered texture
- * @param Color The texture color
- * @param blend Set the Blend Mode ( default ALPHA_NORMAL )
- * @param Effect Set the Render Effect ( default RN_NORMAL, no effect )
- * @param ScaleCentered If true the texture will be scaled centered, otherwise will be scale from the Top - Left Corner
- * @param texSector The texture sector to render. You can render only a part of the texture. ( default render all the texture )
- */
- void Draw( const Uint32 &TexId, const eeFloat &x, const eeFloat &y, const eeFloat &Angle = 0, const eeFloat &Scale = 1.0f, const eeColorA& Color = eeColorA(255,255,255,255), const EE_RENDERALPHAS &blend = ALPHA_NORMAL, const EE_RENDERTYPE &Effect = RN_NORMAL, const bool &ScaleCentered = true, const eeRecti& texSector = eeRecti(0,0,0,0) );
-
- /** Render the texture on screen. Extended because can set the vertex colors individually
- * @param TexId The internal Texture Id
- * @param x The x position on screen
- * @param y The y position on screen
- * @param width The width of the texture rendered ( when Scale = 1, otherwise this width will be scaled like width * Scale )
- * @param height The height of the texture rendered ( when Scale = 1, otherwise this height will be scaled like height * Scale )
- * @param Angle The Angle of the texture rendered
- * @param Scale The Scale factor of the rendered texture
- * @param Color0 The Left - Top vertex color
- * @param Color1 The Left - Bottom vertex color
- * @param Color2 The Right - Bottom vertex color
- * @param Color3 The Right - Top vertex color
- * @param blend Set the Blend Mode ( default ALPHA_NORMAL )
- * @param Effect Set the Render Effect ( default RN_NORMAL, no effect )
- * @param ScaleCentered If true the texture will be scaled centered, otherwise will be scale from the Top - Left Corner
- * @param texSector The texture sector to render. You can render only a part of the texture. ( default render all the texture )
- */
- void DrawEx( const Uint32 &TexId, const eeFloat &x, const eeFloat &y, const eeFloat &width = 0.0f, const eeFloat &height = 0.0f, const eeFloat &Angle = 0, const eeFloat &Scale = 1.0f, const eeColorA& Color0 = eeColorA(255,255,255,255), const eeColorA& Color1 = eeColorA(255,255,255,255), const eeColorA& Color2 = eeColorA(255,255,255,255), const eeColorA& Color3 = eeColorA(255,255,255,255), const EE_RENDERALPHAS &blend = ALPHA_NORMAL, const EE_RENDERTYPE &Effect = RN_NORMAL, const bool &ScaleCentered = true, const eeRecti& texSector = eeRecti(0,0,0,0) );
-
- /** Render a GL_QUAD on Screen
- * @param TexId The internal Texture Id
- * @param Q The eeQuad2f
- * @param offsetx The Offset X applyed to all the coordinates on eeQuad2f
- * @param offsety The Offset Y applyed to all the coordinates on eeQuad2f
- * @param Angle The Angle of the eeQuad2f rendered
- * @param Scale The Scale of the eeQuad2f rendered
- * @param Color The eeQuad2f color
- * @param blend Set the Blend Mode ( default ALPHA_NORMAL )
- * @param texSector The texture sector to render. You can render only a part of the texture. ( default render all the texture )
- */
- void DrawQuad( const Uint32 &TexId, const eeQuad2f& Q, const eeFloat &offsetx = 0.0f, const eeFloat &offsety = 0.0f, const eeFloat &Angle = 0.0f, const eeFloat &Scale = 1.0f, const eeColorA& Color = eeColorA(255,255,255,255), const EE_RENDERALPHAS &blend = ALPHA_NORMAL, const eeRecti& texSector = eeRecti(0,0,0,0) );
-
- /** Render a GL_QUAD on Screen
- * @param TexId The internal Texture Id
- * @param Q The eeQuad2f
- * @param offsetx The Offset X applyed to all the coordinates on eeQuad2f
- * @param offsety The Offset X applyed to all the coordinates on eeQuad2f
- * @param Angle The Angle of the eeQuad2f rendered
- * @param Scale The Scale of the eeQuad2f rendered
- * @param Color0 The Left - Top vertex color
- * @param Color1 The Left - Bottom vertex color
- * @param Color2 The Right - Bottom vertex color
- * @param Color3 The Right - Top vertex color
- * @param blend Set the Blend Mode ( default ALPHA_NORMAL )
- * @param texSector The texture sector to render. You can render only a part of the texture. ( default render all the texture )
- */
- void DrawQuadEx( const Uint32 &TexId, const eeQuad2f& Q, const eeFloat &offsetx = 0.0f, const eeFloat &offsety = 0.0f, const eeFloat &Angle = 0.0f, const eeFloat &Scale = 1.0f, const eeColorA& Color0 = eeColorA(255,255,255,255), const eeColorA& Color1 = eeColorA(255,255,255,255), const eeColorA& Color2 = eeColorA(255,255,255,255), const eeColorA& Color3 = eeColorA(255,255,255,255), const EE_RENDERALPHAS &blend = ALPHA_NORMAL, const eeRecti& texSector = eeRecti(0,0,0,0) );
+ void Bind( const cTexture* Tex );
/**
* @param TexId The internal Texture Id
@@ -178,32 +111,14 @@ class EE_API cTextureFactory: public cSingleton {
Uint32 GetTextureId( const Uint32& TexId );
/**
- * @return The real current texture id (OpenGL Texture Id)
+ * @return The real current texture id (OpenGL Texture Id)
*/
- Uint32 GetCurrentTexture() const;
+ GLint GetCurrentTexture() const;
/** Set the current internal texture id. This will set the TexId as the current texture binded.
* @param TexId The internal Texture Id
*/
- void SetCurrentTexture( const Uint32& TexId );
-
- /**
- * @param TexId The internal Texture Id
- * @return The Texture Width
- */
- eeFloat GetTextureWidth( const Uint32 &TexId );
-
- /**
- * @param TexId The internal Texture Id
- * @return The Texture Height
- */
- eeFloat GetTextureHeight( const Uint32& TexId );
-
- /**
- * @param TexId The internal Texture Id
- * @return The Texture Path
- */
- std::string GetTexturePath( const Uint32& TexId );
+ void SetCurrentTexture( const GLint& TexId );
/** Returns the number of textures loaded */
Uint32 GetNumTextures() const { return mTextures.size(); }
@@ -233,43 +148,62 @@ class EE_API cTextureFactory: public cSingleton {
/** Get a local copy for all the textures */
void GrabTextures();
-
+
/** Allocate space for Textures (only works if EE_ALLOC_TEXTURES_ON_VECTOR is defined) */
void Allocate( const eeUint& size );
/** @return The memory used by the textures (in bytes) */
eeUint MemorySize() { return mMemSize; }
-
+
/** @return The texture size in memory (in bytes) */
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 TexId The OpenGL Texture Id
+ * @param Width Texture Width
+ * @param Height Texture Height
+ * @param ImgWidth Image Width.
+ * @param ImgHeight Image Height
+ * @param Mipmap Tell if the texture has mipmaps
+ * @param Channels Texture number of Channels ( bytes per pixel )
+ * @param ColorKey The transparent color key for the texture
+ * @param ClampMode The Texture Clamp Mode
+ * @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 );
protected:
cTextureFactory();
~cTextureFactory();
-
+
cLog* Log;
-
+
GLint mCurrentTexture;
EE_RENDERALPHAS mLastBlend;
-
+
bool mPowOfTwo, mIsCalcPowOfTwo;
-
+
std::vector mTextures;
-
+
Uint32 mNextKey;
eeUint mMemSize;
-
+
cGlobalBatchRenderer* BR;
-
- eeUint iLoadFromPixels( const unsigned char* Surface, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const bool& mipmap, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy, const Uint32& TexPos = 0 );
- eeUint iLoad( const std::string& filepath, const bool& mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const Uint32& TexPos = 0 );
-
+
+ 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();
-
- eeUint 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 Uint32& TexPos = 0, const bool& LocalCopy = false );
- void Bind( const cTexture* Tex );
-
+
GLint GetPrevTex();
+
void BindPrev( const GLint& Prev );
+
+
};
}}
diff --git a/src/graphics/ctexturefont.cpp b/src/graphics/ctexturefont.cpp
index 89fed4e60..0f2e60744 100755
--- a/src/graphics/ctexturefont.cpp
+++ b/src/graphics/ctexturefont.cpp
@@ -10,9 +10,11 @@ cTextureFont::~cTextureFont() {
}
bool cTextureFont::Load( const Uint32& TexId, const eeUint& StartChar, const eeUint& Spacing, const bool& VerticalDraw, const eeUint& TexColumns, const eeUint& TexRows, const Uint16& NumChars ) {
+ cTexture * Tex = TF->GetTexture( TexId );
+
mTexId = TexId;
-
- if ( TF->TextureIdExists( TexId ) ) {
+
+ if ( NULL != Tex ) {
mTexColumns = TexColumns;
mTexRows = TexRows;
mStartChar = StartChar;
@@ -21,8 +23,8 @@ bool cTextureFont::Load( const Uint32& TexId, const eeUint& StartChar, const eeU
mtX = ( 1 / static_cast( mTexColumns ) );
mtY = ( 1 / static_cast( mTexRows ) );
- mFWidth = ( TF->GetTextureWidth(mTexId) / mTexColumns );
- mFHeight = ( TF->GetTextureHeight(mTexId) / mTexRows );
+ mFWidth = ( Tex->Width() / mTexColumns );
+ mFHeight = ( Tex->Height() / mTexRows );
mHeight = mSize = (eeUint)mFHeight;
mVerticalDraw = VerticalDraw;
@@ -33,30 +35,32 @@ bool cTextureFont::Load( const Uint32& TexId, const eeUint& StartChar, const eeU
mSpacing = Spacing;
BuildFont();
- cLog::instance()->Write( "Texture Font " + TF->GetTexturePath( TexId ) + " loaded." );
+
+ cLog::instance()->Write( "Texture Font " + Tex->Filepath() + " loaded." );
+
return true;
}
-
- cLog::instance()->Write( "Failed to load Texture Font " + TF->GetTexturePath( TexId ) );
-
+
+ cLog::instance()->Write( "Failed to load Texture Font " );
+
return false;
}
void cTextureFont::BuildFont() {
eeFloat cX = 0, cY = 0;
-
+
mTexCoords.resize( mNumChars );
mGlyphs.resize( mNumChars );
TF->Bind( mTexId );
-
+
for (eeUint i = 0; i < mNumChars; i++) {
if ( i >= mStartChar ) {
cX = (eeFloat)( (i-mStartChar) % mTexColumns ) / (eeFloat)mTexColumns;
cY = (eeFloat)( (i-mStartChar) / mTexColumns ) / (eeFloat)mTexRows;
-
+
mGlyphs[i].Advance = mSpacing;
-
+
mTexCoords[i].TexCoords[0] = cX;
mTexCoords[i].TexCoords[1] = cY;
mTexCoords[i].TexCoords[2] = cX;
@@ -80,21 +84,23 @@ void cTextureFont::BuildFont() {
void cTextureFont::BuildFontFromDat() {
eeFloat Top, Bottom;
eeRectf tR;
-
- mTexCoords.resize( mNumChars );
-
- TF->Bind( mTexId );
-
- for (eeUint i = 0; i < mNumChars; i++) {
- tR.Left = (eeFloat)mGlyphs[i].CurX / TF->GetTextureWidth(mTexId);
- tR.Top = (eeFloat)mGlyphs[i].CurY / TF->GetTextureHeight(mTexId);
- tR.Right = (eeFloat)(mGlyphs[i].CurX + mGlyphs[i].CurW) / TF->GetTextureWidth(mTexId);
- tR.Bottom = (eeFloat)(mGlyphs[i].CurY + mGlyphs[i].CurH) / TF->GetTextureHeight(mTexId);
+ mTexCoords.resize( mNumChars );
+
+ cTexture * Tex = TF->GetTexture( mTexId );
+
+ TF->Bind( Tex );
+
+ for (eeUint i = 0; i < mNumChars; i++) {
+ tR.Left = (eeFloat)mGlyphs[i].CurX / Tex->Width();
+ tR.Top = (eeFloat)mGlyphs[i].CurY / Tex->Height();
+
+ tR.Right = (eeFloat)(mGlyphs[i].CurX + mGlyphs[i].CurW) / Tex->Width();
+ tR.Bottom = (eeFloat)(mGlyphs[i].CurY + mGlyphs[i].CurH) / Tex->Height();
Top = mFHeight - mGlyphs[i].GlyphH - mGlyphs[i].MinY;
Bottom = mFHeight + mGlyphs[i].GlyphH - mGlyphs[i].MaxY;
-
+
mTexCoords[i].TexCoords[0] = tR.Left;
mTexCoords[i].TexCoords[1] = tR.Top;
mTexCoords[i].TexCoords[2] = tR.Left;
@@ -153,35 +159,35 @@ bool cTextureFont::Load( const Uint32& TexId, const std::string& CoordinatesDatP
bool cTextureFont::LoadFromPack( cPack* Pack, const std::string& FilePackPath, const Uint32& TexId, const bool& VerticalDraw ) {
std::vector TmpData;
-
+
if ( Pack->IsOpen() && Pack->ExtractFileToMemory( FilePackPath, TmpData ) )
return LoadFromMemory( TexId, reinterpret_cast (&TmpData[0]), TmpData.size(), VerticalDraw );
-
+
return false;
}
bool cTextureFont::LoadFromMemory( const Uint32& TexId, const Uint8* CoordData, const eeUint& CoordDataSize, const bool& VerticalDraw ) {
mTexId = TexId;
-
+
if ( mTexId>0 ) {
mVerticalDraw = VerticalDraw;
-
+
if ( CoordData != NULL ) {
mNumChars = static_cast ( ( CoordDataSize - 2 ) / 32 );
-
+
mGlyphs.resize( mNumChars );
-
+
// Read the number of the first char represented on the texture
mStartChar = CoordData[0];
-
+
// Read the default size of every char
mFWidth = CoordData[1];
mFHeight = CoordData[1];
mHeight = mSize = (Uint32)mFHeight;
-
+
// Read every char coordinates
memcpy( reinterpret_cast (&mGlyphs[0]), reinterpret_cast (&CoordData[2]), sizeof(eeGlyph) * mNumChars );
-
+
BuildFontFromDat();
mLoadedCoords = true;
return true;
diff --git a/src/graphics/cttffont.cpp b/src/graphics/cttffont.cpp
index 11ac32cc5..1abf6ecc1 100755
--- a/src/graphics/cttffont.cpp
+++ b/src/graphics/cttffont.cpp
@@ -17,12 +17,12 @@ cTTFFont::~cTTFFont() {
bool cTTFFont::LoadFromPack( cPack* Pack, const std::string& FilePackPath, const eeUint& Size, EE_TTF_FONTSTYLE Style, const bool& VerticalDraw, const Uint16& NumCharsToGen, const eeColor& FontColor, const Uint8& OutlineSize, const eeColor& OutlineColor ) {
std::vector TmpData;
-
+
if ( Pack->IsOpen() && Pack->ExtractFileToMemory( FilePackPath, TmpData ) )
return LoadFromMemory( reinterpret_cast (&TmpData[0]), TmpData.size(), Size, Style, VerticalDraw, NumCharsToGen, FontColor, OutlineSize, OutlineColor );
-
+
TmpData.clear();
-
+
return false;
}
@@ -95,7 +95,7 @@ bool cTTFFont::iLoad(const eeUint& Size, EE_TTF_FONTSTYLE Style, const bool& Ver
amask = 0xff000000;
#endif
SDL_Surface* TempGlyphSheet = SDL_CreateRGBSurface(SDL_SWSURFACE, (eeInt)mTexWidth, (eeInt)mTexHeight, 32, bmask, gmask, rmask, amask);
-
+
CurrentPos.x = OutlineSize;
CurrentPos.y = OutlineSize;
@@ -139,10 +139,10 @@ bool cTTFFont::iLoad(const eeUint& Size, EE_TTF_FONTSTYLE Style, const bool& Ver
GlyphRect.h += OutlineSize;
TempGlyph.Advance += OutlineSize;
-
+
Top = static_cast ( mSize - GlyphRect.h - TempGlyph.MinY );
Bottom = static_cast ( mSize + GlyphRect.h - TempGlyph.MaxY );
-
+
// Translate the Glyph coordinates to the new texture coordinates
TempGlyph.MinX -= OutlineSize;
TempGlyph.MinY -= OutlineSize;
@@ -174,16 +174,16 @@ bool cTTFFont::iLoad(const eeUint& Size, EE_TTF_FONTSTYLE Style, const bool& Ver
// Recover the Alpha channel
SDL_LockSurface(TempGlyphSheet);
-
+
eeUint ssize = TempGlyphSheet->w * TempGlyphSheet->h * 4;
-
+
for (eeUint i=0; i(TempGlyphSheet->pixels))[i+3] = (static_cast(TempGlyphSheet->pixels))[i+2];
(static_cast(TempGlyphSheet->pixels))[i+2] = FontColor.B();
(static_cast(TempGlyphSheet->pixels))[i+1] = FontColor.G();
(static_cast(TempGlyphSheet->pixels))[i+0] = FontColor.R();
}
-
+
SDL_UnlockSurface(TempGlyphSheet);
const unsigned char* Ptr = reinterpret_cast(TempGlyphSheet->pixels);
@@ -193,7 +193,7 @@ bool cTTFFont::iLoad(const eeUint& Size, EE_TTF_FONTSTYLE Style, const bool& Ver
// Check if need to create the outline
cTexture* Tex = TF->GetTexture( mTexId );
-
+
if ( OutlineSize && Tex ) {
eeColorA P, R;
Uint32 Pos = 0;
@@ -247,9 +247,9 @@ bool cTTFFont::iLoad(const eeUint& Size, EE_TTF_FONTSTYLE Style, const bool& Ver
//Close the font
TTF_CloseFont(mFont);
-
+
RebuildFromGlyphs();
-
+
cLog::instance()->Write( "TTF Font " + mFilepath + " loaded." );
return true;
} catch (...) {
@@ -261,21 +261,23 @@ bool cTTFFont::iLoad(const eeUint& Size, EE_TTF_FONTSTYLE Style, const bool& Ver
void cTTFFont::RebuildFromGlyphs() {
eeFloat Top, Bottom;
eeRectf tR;
-
- mTexCoords.resize( mNumChars );
-
- TF->Bind( mTexId );
-
- for (eeUint i = 0; i < mNumChars; i++) {
- tR.Left = (eeFloat)mGlyphs[i].CurX / TF->GetTextureWidth(mTexId);
- tR.Top = (eeFloat)mGlyphs[i].CurY / TF->GetTextureHeight(mTexId);
- tR.Right = (eeFloat)(mGlyphs[i].CurX + mGlyphs[i].CurW) / TF->GetTextureWidth(mTexId);
- tR.Bottom = (eeFloat)(mGlyphs[i].CurY + mGlyphs[i].CurH) / TF->GetTextureHeight(mTexId);
+ mTexCoords.resize( mNumChars );
+
+ cTexture * Tex = TF->GetTexture( mTexId );
+
+ TF->Bind( Tex );
+
+ for (eeUint i = 0; i < mNumChars; i++) {
+ tR.Left = (eeFloat)mGlyphs[i].CurX / Tex->Width();
+ tR.Top = (eeFloat)mGlyphs[i].CurY / Tex->Height();
+
+ tR.Right = (eeFloat)(mGlyphs[i].CurX + mGlyphs[i].CurW) / Tex->Width();
+ tR.Bottom = (eeFloat)(mGlyphs[i].CurY + mGlyphs[i].CurH) / Tex->Height();
Top = (eeFloat)mSize - mGlyphs[i].GlyphH - mGlyphs[i].MinY;
Bottom = (eeFloat)mSize + mGlyphs[i].GlyphH - mGlyphs[i].MaxY;
-
+
mTexCoords[i].TexCoords[0] = tR.Left;
mTexCoords[i].TexCoords[1] = tR.Top;
mTexCoords[i].TexCoords[2] = tR.Left;
@@ -351,7 +353,7 @@ void cTTFFont::MakeOutline( Uint8 *in, Uint8 *out, Int16 w, Int16 h) {
c = in[index];
}
}
-
+
out[ y * w + x ] = c;
}
}
diff --git a/src/helper/SOIL/SOIL.c b/src/helper/SOIL/SOIL.c
index fc70ae9c8..af5693425 100755
--- a/src/helper/SOIL/SOIL.c
+++ b/src/helper/SOIL/SOIL.c
@@ -31,7 +31,7 @@
#endif
#include "SOIL.h"
-#include "stb_image_aug.h"
+#include "stb_image.h"
#include "image_helper.h"
#include "image_DXT.h"
diff --git a/src/helper/SOIL/stb_image_aug.c b/src/helper/SOIL/stb_image.c
similarity index 99%
rename from src/helper/SOIL/stb_image_aug.c
rename to src/helper/SOIL/stb_image.c
index 21439f59e..d3de6a50b 100755
--- a/src/helper/SOIL/stb_image_aug.c
+++ b/src/helper/SOIL/stb_image.c
@@ -65,7 +65,7 @@
on 'test' only check type, not whether we support this variant
*/
-#include "stb_image_aug.h"
+#include "stb_image.h"
#ifndef STBI_NO_HDR
#include /* ldexp */
@@ -105,7 +105,7 @@ typedef unsigned char validate_uint32[sizeof(uint32)==4];
#endif
#ifndef STBI_NO_DDS
-#include "stbi_DDS_aug.h"
+#include "stbi_DDS.h"
#endif
/* I (JLD) want full messages for SOIL */
@@ -3753,5 +3753,5 @@ int stbi_write_tga(char const *filename, int x, int y, int comp, void *data)
// add in my DDS loading support
#ifndef STBI_NO_DDS
-#include "stbi_DDS_aug_c.h"
+#include "stbi_DDS_c.h"
#endif
diff --git a/src/helper/SOIL/stb_image_aug.h b/src/helper/SOIL/stb_image.h
similarity index 100%
rename from src/helper/SOIL/stb_image_aug.h
rename to src/helper/SOIL/stb_image.h
diff --git a/src/helper/SOIL/stbi_DDS_aug.h b/src/helper/SOIL/stbi_DDS.h
similarity index 100%
rename from src/helper/SOIL/stbi_DDS_aug.h
rename to src/helper/SOIL/stbi_DDS.h
diff --git a/src/helper/SOIL/stbi_DDS_aug_c.h b/src/helper/SOIL/stbi_DDS_c.h
similarity index 100%
rename from src/helper/SOIL/stbi_DDS_aug_c.h
rename to src/helper/SOIL/stbi_DDS_c.h
diff --git a/src/test/ee.cpp b/src/test/ee.cpp
index ea2655087..86cbf7126 100644
--- a/src/test/ee.cpp
+++ b/src/test/ee.cpp
@@ -1,10 +1,16 @@
#include "../ee.h"
/**
-@TODO Create a basic UI system.
-@TODO Add some Surface Grid class, to create special effects. ( waved texture, and stuff like that )
+@TODO Create a asynchronous resource loader ( at least for textures ).
+@TODO Create a basic UI system ( add basic controls, add skinning support ).
+@TODO Add support for Joysticks.
+@TODO Create a Vertex Buffer Object class ( with and without GL_ARB_vertex_buffer_object ).
+@TODO Add support for Frame Buffer Object and to switch rendering to FBO and Screen.
@TODO Support multitexturing.
-@TODO Create a asynchronous resource loader - Check if this is posible right now
+@TODO Create a texture packer tool ( pack various textures into one texture ).
+@TODO Remove SDL_ttf dependency, use Free Type directly.
+@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
*/
@@ -88,7 +94,10 @@ class cEETest : private cThread {
Uint32 lasttick;
std::vector TN;
+ std::vector TNP;
+
std::vector Tiles;
+
eeVector2i Mouse;
eeVector2f Mousef;
@@ -139,6 +148,7 @@ class cEETest : private cThread {
cWaypoints WP;
Int32 PartsNum;
Uint32 Cursor[2];
+ cTexture * CursorP[2];
std::string mInfo;
bool MultiViewportMode;
@@ -364,15 +374,21 @@ void cEETest::CmdSetPartsNum ( const std::vector < std::wstring >& params ) {
void cEETest::LoadTextures() {
Uint32 i;
- TF->Allocate(0);
+ TF->Allocate(40);
+
TN.resize(12);
+ TNP.resize(12);
+
Tiles.resize(10);
- for ( i = 0; i <= 7; i++ )
+ for ( i = 0; i <= 7; i++ ) {
TN[i] = TF->LoadFromPack( &PAK, toStr(i+1) + ".png", ( (i+1) == 7 ) ? true : false, eeRGB(true), ( (i+1) == 4 ) ? EE_CLAMP_REPEAT : EE_CLAMP_TO_EDGE );
+ TNP[i] = TF->GetTexture( TN[i] );
+ }
- for ( i = 0; i <= 6; i++ )
+ for ( i = 0; i <= 6; i++ ) {
Tiles[i] = TF->LoadFromPack( &PAK, "tiles/" + toStr(i+1) + ".png", true );
+ }
Tiles[7] = TF->LoadFromPack( &PAK, "tiles/8.png", false, eeRGB(0,0,0) );
@@ -383,10 +399,12 @@ void cEETest::LoadTextures() {
SP.AddFrame( TN[4], 0, 0, 0, 0, eeRecti( mx * 64, my * 64, mx * 64 + 64, my * 64 + 64 ) );
TN[8] = TF->LoadFromPack( &PAK, "conchars.png", false, eeRGB(0,0,0) );
+ TNP[8] = TF->GetTexture( TN[8] );
FF.Load( TN[8], 32 );
TN[9] = TF->LoadFromPack( &PAK, "ProggySquareSZ.png" );
+ TNP[9] = TF->GetTexture( TN[9] );
FF2.LoadFromPack( &PAK, "ProggySquareSZ.dat", TN[9] );
@@ -417,7 +435,9 @@ void cEETest::LoadTextures() {
Tex->Unlock(false, true);
Cursor[0] = TF->LoadFromPack( &PAK, "cursor.png" );
+ CursorP[0] = TF->GetTexture( Cursor[0] );
Cursor[1] = TF->LoadFromPack( &PAK, "cursor.tga" );
+ CursorP[1] = TF->GetTexture( Cursor[1] );
EE->ShowCursor(false);
@@ -499,13 +519,12 @@ void cEETest::ParticlesThread() {
}
void cEETest::Screen2() {
- eeFloat PlanetX = HWidth - TF->GetTextureWidth(TN[6]) * 0.5f;
- eeFloat PlanetY = HHeight - TF->GetTextureHeight(TN[6]) * 0.5f;
+ eeFloat PlanetX = HWidth - TNP[6]->Width() * 0.5f;
+ eeFloat PlanetY = HHeight - TNP[6]->Height() * 0.5f;
ang+=et * 0.1f;
ang = (ang>=360) ? ang = 0 : ang;
-
if (scale>=1.5f) {
scale = 1.5f;
side = true;
@@ -515,7 +534,7 @@ void cEETest::Screen2() {
}
scale = (!side) ? scale+=et * 0.00025f : scale -=et * 0.00025f;
- Batch.SetTexture( TN[2] );
+ Batch.SetTexture( TNP[2] );
Batch.QuadsBegin();
Batch.QuadsSetColor( eeColorA(150,150,150,100) );
Batch.QuadsSetSubset( 0.0f, 0.0f, 0.5f, 0.5f );
@@ -556,17 +575,17 @@ void cEETest::Screen2() {
}
#endif
- TF->DrawFast(TN[6], PlanetX, PlanetY, ang, scale);
+ TNP[6]->DrawFast( PlanetX, PlanetY, ang, scale);
#ifdef EE_SHADERS
if ( mUseShaders )
mShaderProgram->Unbind();
#endif
- TF->Draw(TN[3], HWidth - 128, HHeight, 0, 1, eeColorA(255,255,255,150), ALPHA_NORMAL, RN_ISOMETRIC);
- TF->Draw(TN[3], HWidth - 128, HHeight - 128, 0, 1, eeColorA(255,255,255,50), ALPHA_NORMAL, RN_ISOMETRIC);
- TF->Draw(TN[3], HWidth - 128, HHeight, 0, 1, eeColorA(255,255,255,50), ALPHA_NORMAL, RN_ISOMETRICVERTICAL);
- TF->Draw(TN[3], HWidth, HHeight, 0, 1, eeColorA(255,255,255,50), ALPHA_NORMAL, RN_ISOMETRICVERTICALNEGATIVE);
+ TNP[3]->Draw( HWidth - 128, HHeight, 0, 1, eeColorA(255,255,255,150), ALPHA_NORMAL, RN_ISOMETRIC);
+ TNP[3]->Draw( HWidth - 128, HHeight - 128, 0, 1, eeColorA(255,255,255,50), ALPHA_NORMAL, RN_ISOMETRIC);
+ TNP[3]->Draw( HWidth - 128, HHeight, 0, 1, eeColorA(255,255,255,50), ALPHA_NORMAL, RN_ISOMETRICVERTICAL);
+ TNP[3]->Draw( HWidth, HHeight, 0, 1, eeColorA(255,255,255,50), ALPHA_NORMAL, RN_ISOMETRICVERTICALNEGATIVE);
alpha = (!aside) ? alpha+=et * 0.1f : alpha -=et * 0.1f;
if (alpha>=255) {
@@ -578,7 +597,7 @@ void cEETest::Screen2() {
}
eeColorA Col(255,255,255,(int)alpha);
- TF->DrawEx(TN[1], (eeFloat)EE->GetWidth() - 128.f, (eeFloat)EE->GetHeight() - 128.f, 128.f, 128.f, ang, 1, Col, Col, Col, Col, ALPHA_BLENDONE, RN_FLIPMIRROR);
+ TNP[1]->DrawEx( (eeFloat)EE->GetWidth() - 128.f, (eeFloat)EE->GetHeight() - 128.f, 128.f, 128.f, ang, 1, Col, Col, Col, Col, ALPHA_BLENDONE, RN_FLIPMIRROR);
SP.UpdatePos(alpha,alpha);
SP.Draw();
@@ -638,7 +657,7 @@ void cEETest::Screen2() {
PR.DrawRectangle(Mousef.x - 80.f, Mousef.y - 80.f, 160.f, 160.f, 45.f, 1.f, DRAW_LINE);
PR.DrawLine( eeVector2f(0.f, 0.f), eeVector2f( (eeFloat)EE->GetWidth(), (eeFloat)EE->GetHeight() ) );
- TF->DrawQuadEx( TN[3], eeQuad2f( eeVector2f(0.f, 0.f), eeVector2f(0.f, 100.f), eeVector2f(150.f, 150.f), eeVector2f(200.f, 150.f) ), 0.0f, 0.0f, ang, scale, eeColorA(220, 240, 0, 125), eeColorA(100, 0, 240, 125), eeColorA(250, 50, 25, 125), eeColorA(50, 150, 150, 125) );
+ TNP[3]->DrawQuadEx( eeQuad2f( eeVector2f(0.f, 0.f), eeVector2f(0.f, 100.f), eeVector2f(150.f, 150.f), eeVector2f(200.f, 150.f) ), 0.0f, 0.0f, ang, scale, eeColorA(220, 240, 0, 125), eeColorA(100, 0, 240, 125), eeColorA(250, 50, 25, 125), eeColorA(50, 150, 150, 125) );
WP.Update( et );
PR.SetColor( eeColorA(0, 255, 0, 255) );
@@ -659,7 +678,7 @@ void cEETest::Screen3() {
}
AnimVal = (!AnimSide) ? AnimVal+=et * 0.1f : AnimVal -=et * 0.1f;
- Batch.SetTexture( TN[3] );
+ Batch.SetTexture( TNP[3] );
Batch.LineLoopBegin();
for ( eeFloat j = 0; j < 360; j++ ) {
Batch.BatchLineLoop( HWidth + 350 * sinAng(j), HHeight + 350 * cosAng(j), HWidth + AnimVal * sinAng(j+1), HHeight + AnimVal * cosAng(j+1) );
@@ -749,7 +768,7 @@ void cEETest::Render() {
Con.Draw();
if ( Screen < 2 )
- TF->Draw( Cursor[ Screen ], Mousef.x, Mousef.y );
+ CursorP[ Screen ]->Draw( Mousef.x, Mousef.y );
}
void cEETest::Input() {
@@ -890,7 +909,7 @@ void cEETest::Input() {
SP.ReverseAnim( !SP.ReverseAnim() );
if ( KM->MouseLeftPressed() )
- TF->DrawEx( TN[3], 0.f, 0.f, (eeFloat)EE->GetWidth(), (eeFloat)EE->GetHeight() );
+ TNP[3]->DrawEx( 0.f, 0.f, (eeFloat)EE->GetWidth(), (eeFloat)EE->GetHeight() );
if ( !KM->MouseRightPressed() )
DrawBack = false;
diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp
index 60819ed97..b73c2f9f3 100755
--- a/src/utils/utils.cpp
+++ b/src/utils/utils.cpp
@@ -3,6 +3,7 @@
#if EE_PLATFORM == EE_PLATFORM_APPLE
#include
+ #include
#elif EE_PLATFORM == EE_PLATFORM_WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
@@ -10,6 +11,7 @@
#include
#elif EE_PLATFORM == EE_PLATFORM_LINUX
#include
+ #include
#endif
#if EE_PLATFORM == EE_PLATFORM_WIN32
@@ -275,15 +277,20 @@ Uint32 MakeHash( const std::string& str ) {
}
Uint32 MakeHash( const Int8* str ) {
- Uint32 hash = 5381 + *str;
+ if ( NULL != str ) {
+ Uint32 hash = 5381 + *str;
- while( *str ) {
- hash = *str + ( hash << 6 ) + ( hash << 16 ) - hash;
- str++;
+ while( *str ) {
+ hash = *str + ( hash << 6 ) + ( hash << 16 ) - hash;
+ str++;
+ }
+
+ hash += *( str - 1 );
+
+ return hash;
}
- hash += *( str - 1 );
- return hash;
+ return 0;
}
bool FileGet( const std::string& path, std::vector& data ) {
@@ -321,4 +328,38 @@ bool FileCopy( const std::string& src, const std::string& dst ) {
return false;
}
+eeInt GetNumCPUs() {
+ eeInt nprocs = -1;
+
+ #if EE_PLATFORM == EE_PLATFORM_WIN32
+ SYSTEM_INFO info;
+ GetSystemInfo(&info);
+
+ nprocs = (eeInt) info.dwNumberOfProcessors;
+ #elif EE_PLATFORM == EE_PLATFORM_LINUX
+ nprocs = sysconf(_SC_NPROCESSORS_ONLN);
+ #elif EE_PLATFORM == EE_PLATFORM_APPLE
+ int mib[2];
+ size_t len;
+ int maxproc = 1;
+
+ mib[0] = CTL_HW;
+ mib[1] = HW_NCPU;
+ len = sizeof(maxproc);
+
+ // sysctl != 0 == error
+ if ( sysctl(mib, 2, &maxproc, &len, NULL, NULL == -1) )
+ return 1;
+
+ nprocs = maxproc;
+ #else
+ #warning GetNumCPUs not implemented for this platform
+ #endif
+
+ if ( nprocs < 0 )
+ nprocs = 1;
+
+ return nprocs;
+}
+
}}
diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp
index d7b490c27..dd9069431 100755
--- a/src/utils/utils.hpp
+++ b/src/utils/utils.hpp
@@ -56,6 +56,9 @@ namespace EE { namespace Utils {
* @return If success.
*/
bool FileCopy( const std::string& src, const std::string& dst );
+
+ /** @return The Number of CPUs of the system. */
+ eeInt GetNumCPUs();
}
}