From 2cc55ea68a9ceffdfafac910682cd4fda7ecff32 Mon Sep 17 00:00:00 2001 From: spartanj Date: Tue, 18 Jan 2011 04:43:40 -0300 Subject: [PATCH] I made some structural changes, and i'm trying to encapsulate a little the renderer to in a future implement an OpenGL3 render, and remove the fixed pipeline. --- src/base.hpp | 1 + src/gaming/base.hpp | 1 + src/gaming/cisomap.cpp | 8 +- src/graphics/base.hpp | 1 - src/graphics/cbatchrenderer.cpp | 16 +- src/graphics/cbatchrenderer.hpp | 1 + src/graphics/cconsole.cpp | 4 +- src/graphics/cfont.cpp | 28 ++-- src/graphics/cframebuffer.cpp | 13 +- src/graphics/cframebufferfbo.cpp | 4 +- src/graphics/cparticlesystem.cpp | 4 +- src/graphics/cshader.cpp | 38 ++--- src/graphics/cshaderprogram.cpp | 19 ++- src/graphics/cshaderprogram.hpp | 4 + src/graphics/ctextcache.cpp | 8 +- src/graphics/ctextcache.hpp | 1 + src/graphics/ctexturefactory.cpp | 20 +-- src/graphics/ctextureloader.cpp | 6 +- src/graphics/cvertexbuffer.cpp | 3 +- src/graphics/cvertexbufferogl.cpp | 4 +- src/graphics/cvertexbuffervbo.cpp | 4 +- src/graphics/glhelper.cpp | 136 --------------- src/graphics/glhelper.hpp | 48 +----- src/graphics/pixelperfect.cpp | 30 ++-- src/graphics/pixelperfect.hpp | 6 +- src/graphics/renderer/base.hpp | 9 + src/graphics/renderer/cgl.cpp | 191 ++++++++++++++++++++++ src/graphics/renderer/cgl.hpp | 97 +++++++++++ src/graphics/renderer/crenderergl.cpp | 47 ++++++ src/graphics/renderer/crenderergl.hpp | 38 +++++ src/graphics/renderer/crenderergl3.cpp | 145 ++++++++++++++++ src/graphics/renderer/crenderergl3.hpp | 54 ++++++ src/helper/chipmunk/cpBBTree.c | 150 ++++++++--------- src/helper/chipmunk/cpSpaceHash.c | 138 ++++++++-------- src/physics/base.hpp | 1 + src/physics/constraints/cdampedspring.cpp | 33 ++-- src/physics/cshapesegment.cpp | 4 +- src/test/ee.cpp | 4 +- src/ui/base.hpp | 1 + src/ui/cuicomplexcontrol.cpp | 2 +- src/ui/cuicontrolanim.cpp | 12 +- src/ui/cuigridcell.cpp | 3 +- src/ui/cuilistboxitem.cpp | 8 +- src/window/cengine.cpp | 20 +-- 44 files changed, 884 insertions(+), 481 deletions(-) create mode 100644 src/graphics/renderer/base.hpp create mode 100644 src/graphics/renderer/cgl.cpp create mode 100644 src/graphics/renderer/cgl.hpp create mode 100644 src/graphics/renderer/crenderergl.cpp create mode 100644 src/graphics/renderer/crenderergl.hpp create mode 100644 src/graphics/renderer/crenderergl3.cpp create mode 100644 src/graphics/renderer/crenderergl3.hpp diff --git a/src/base.hpp b/src/base.hpp index 3c2ce9548..2024c93db 100644 --- a/src/base.hpp +++ b/src/base.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "helper/PlusCallback/callback.hpp" diff --git a/src/gaming/base.hpp b/src/gaming/base.hpp index 0fb14beb9..408cd85ab 100644 --- a/src/gaming/base.hpp +++ b/src/gaming/base.hpp @@ -21,6 +21,7 @@ using namespace EE::Window; #include "../graphics/cshape.hpp" #include "../graphics/cfont.hpp" #include "../graphics/cprimitives.hpp" +#include "../graphics/glhelper.hpp" using namespace EE::Graphics; #endif diff --git a/src/gaming/cisomap.cpp b/src/gaming/cisomap.cpp index b58016287..aa9ae22ed 100755 --- a/src/gaming/cisomap.cpp +++ b/src/gaming/cisomap.cpp @@ -125,9 +125,9 @@ void cIsoMap::Draw() { eeColorA SC(50,50,50,100); cGlobalBatchRenderer::instance()->Draw(); - glLoadIdentity(); - glPushMatrix(); - glTranslatef( OffsetX, OffsetY, 0.0f ); + GLi->LoadIdentity(); + GLi->PushMatrix(); + GLi->Translatef( OffsetX, OffsetY, 0.0f ); for ( eeUint L = 0; L < MapLayers; L++ ) { for ( eeInt y = Ty; y < Ty2; y++ ) { @@ -180,7 +180,7 @@ void cIsoMap::Draw() { if ( L == 0 ) { cGlobalBatchRenderer::instance()->Draw(); - glPopMatrix(); + GLi->PopMatrix(); } } diff --git a/src/graphics/base.hpp b/src/graphics/base.hpp index bdfb85eaa..986a5c18c 100644 --- a/src/graphics/base.hpp +++ b/src/graphics/base.hpp @@ -28,7 +28,6 @@ using namespace EE::System; #include "renders.hpp" #ifdef EE_GLES - const GLubyte EE_GLES_INDICES [] = {0, 3, 1, 2}; #define EE_QUAD_VERTEX 6 #else #define EE_QUAD_VERTEX 4 diff --git a/src/graphics/cbatchrenderer.cpp b/src/graphics/cbatchrenderer.cpp index 9aa2b22ab..7c74090dd 100755 --- a/src/graphics/cbatchrenderer.cpp +++ b/src/graphics/cbatchrenderer.cpp @@ -105,15 +105,15 @@ void cBatchRenderer::Flush() { } if ( CreateMatrix ) { - glLoadIdentity(); - glPushMatrix(); + GLi->LoadIdentity(); + GLi->PushMatrix(); - glTranslatef( mPosition.x, mPosition.y, 0.0f); + GLi->Translatef( mPosition.x, mPosition.y, 0.0f); - glTranslatef( mCenter.x, mCenter.y, 0.0f); - glRotatef( mRotation, 0.0f, 0.0f, 1.0f ); - glScalef( mScale, mScale, 1.0f ); - glTranslatef( -mCenter.x, -mCenter.y, 0.0f); + GLi->Translatef( mCenter.x, mCenter.y, 0.0f); + GLi->Rotatef( mRotation, 0.0f, 0.0f, 1.0f ); + GLi->Scalef( mScale, mScale, 1.0f ); + GLi->Translatef( -mCenter.x, -mCenter.y, 0.0f); } glVertexPointer(2, GL_FLOAT, sizeof(eeVertex), reinterpret_cast ( &mVertex[0] ) ); @@ -130,7 +130,7 @@ void cBatchRenderer::Flush() { } if ( CreateMatrix ) - glPopMatrix(); + GLi->PopMatrix(); if ( mCurrentMode == DM_POINTS && mTexture > 0 ) { glDisable( GL_POINT_SPRITE_ARB ); diff --git a/src/graphics/cbatchrenderer.hpp b/src/graphics/cbatchrenderer.hpp index ef7a32a6b..8c4a65369 100755 --- a/src/graphics/cbatchrenderer.hpp +++ b/src/graphics/cbatchrenderer.hpp @@ -3,6 +3,7 @@ #include "base.hpp" #include "ctexture.hpp" +#include "glhelper.hpp" namespace EE { namespace Graphics { diff --git a/src/graphics/cconsole.cpp b/src/graphics/cconsole.cpp index aa788ba55..defe55011 100755 --- a/src/graphics/cconsole.cpp +++ b/src/graphics/cconsole.cpp @@ -1,5 +1,5 @@ #include "cconsole.hpp" - +#include "glhelper.hpp" #include "../audio/caudiolistener.hpp" #include "../window/cinput.hpp" #include "../window/cengine.hpp" @@ -493,7 +493,7 @@ void cConsole::CmdGetLog( const std::vector < std::wstring >& params ) { } void cConsole::CmdGetGpuExtensions() { - char *Exts = (char *)glGetString(GL_EXTENSIONS); + char *Exts = GLi->GetExtensions(); std::vector < std::wstring > tvec = SplitString( toWStr( std::string( Exts ) ), L' ' ); if ( tvec.size() > 0 ) { for ( eeUint i = 0; i < tvec.size(); i++ ) diff --git a/src/graphics/cfont.cpp b/src/graphics/cfont.cpp index f45488bac..fc3645d8d 100644 --- a/src/graphics/cfont.cpp +++ b/src/graphics/cfont.cpp @@ -155,16 +155,15 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con eeUint numvert = 0; if ( Angle != 0.0f || Scale != 1.0f ) { - glLoadIdentity(); - glPushMatrix(); + GLi->PushMatrix(); eeVector2f Center( cX + TextCache.GetTextWidth() * 0.5f, cY + TextCache.GetTextHeight() * 0.5f ); - glTranslatef( Center.x , Center.y, 0.f ); - glRotatef( Angle, 0.0f, 0.0f, 1.0f ); - glScalef( Scale, Scale, 1.0f ); - glTranslatef( -Center.x, -Center.y, 0.f ); + GLi->Translatef( Center.x , Center.y, 0.f ); + GLi->Rotatef( Angle, 0.0f, 0.0f, 1.0f ); + GLi->Scalef( Scale, Scale, 1.0f ); + GLi->Translatef( -Center.x, -Center.y, 0.f ); - glTranslatef( X, Y, 0.f ); + GLi->Translatef( X, Y, 0.f ); } std::vector& RenderCoords = TextCache.VertextCoords(); @@ -309,7 +308,7 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con #endif if ( Angle != 0.0f || Scale != 1.0f ) { - glPopMatrix(); + GLi->PopMatrix(); } } @@ -345,14 +344,13 @@ void cFont::SubDraw( const std::wstring& Text, const eeFloat& X, const eeFloat& eeUint numvert = 0; if ( Angle != 0.0f || Scale != 1.0f ) { - glLoadIdentity(); - glPushMatrix(); + GLi->PushMatrix(); eeVector2f Center( cX + GetTextWidth() * 0.5f, cY + GetTextHeight() * 0.5f ); - glTranslatef( Center.x , Center.y, 0.f ); - glRotatef( Angle, 0.0f, 0.0f, 1.0f ); - glScalef( Scale, Scale, 1.0f ); - glTranslatef( -Center.x, -Center.y, 0.f ); + GLi->Translatef( Center.x , Center.y, 0.f ); + GLi->Rotatef( Angle, 0.0f, 0.0f, 1.0f ); + GLi->Scalef( Scale, Scale, 1.0f ); + GLi->Translatef( -Center.x, -Center.y, 0.f ); } switch ( FontHAlignGet( Flags ) ) { @@ -479,7 +477,7 @@ void cFont::SubDraw( const std::wstring& Text, const eeFloat& X, const eeFloat& #endif if ( Angle != 0.0f || Scale != 1.0f ) - glPopMatrix(); + GLi->PopMatrix(); } void cFont::CacheWidth( const std::wstring& Text, std::vector& LinesWidth, eeFloat& CachedWidth, eeInt& NumLines ) { diff --git a/src/graphics/cframebuffer.cpp b/src/graphics/cframebuffer.cpp index ec4541c02..f522e6335 100644 --- a/src/graphics/cframebuffer.cpp +++ b/src/graphics/cframebuffer.cpp @@ -5,7 +5,6 @@ #include "cframebufferfbo.hpp" #include "cframebufferpbuffer.hpp" #include "cframebuffermanager.hpp" - using namespace EE::Graphics::Private; namespace EE { namespace Graphics { @@ -60,12 +59,12 @@ void cFrameBuffer::SetBufferView() { mPrevView = Window::cEngine::instance()->GetView(); - glMatrixMode( GL_PROJECTION ); - glLoadIdentity(); - glViewport( 0, 0, mWidth, mHeight ); - glOrtho( 0.0f, mWidth, 0.f, mHeight, -1000.0f, 1000.0f ); - glMatrixMode( GL_MODELVIEW ); - glLoadIdentity(); + GLi->MatrixMode( GL_PROJECTION ); + GLi->LoadIdentity(); + GLi->Viewport( 0, 0, mWidth, mHeight ); + GLi->Ortho( 0.0f, mWidth, 0.f, mHeight, -1000.0f, 1000.0f ); + GLi->MatrixMode( GL_MODELVIEW ); + GLi->LoadIdentity(); } void cFrameBuffer::RecoverView() { diff --git a/src/graphics/cframebufferfbo.cpp b/src/graphics/cframebufferfbo.cpp index f539700f8..7f97a0d9f 100644 --- a/src/graphics/cframebufferfbo.cpp +++ b/src/graphics/cframebufferfbo.cpp @@ -3,12 +3,10 @@ #include "../window/cengine.hpp" #include "glhelper.hpp" -using namespace EE::Graphics::Private; - namespace EE { namespace Graphics { bool cFrameBufferFBO::IsSupported() { - return 0 != cGL::instance()->IsExtension( EEGL_EXT_framebuffer_object ); + return 0 != GLi->IsExtension( EEGL_EXT_framebuffer_object ); } cFrameBufferFBO::cFrameBufferFBO() : diff --git a/src/graphics/cparticlesystem.cpp b/src/graphics/cparticlesystem.cpp index e3f0d82f7..66622fd09 100755 --- a/src/graphics/cparticlesystem.cpp +++ b/src/graphics/cparticlesystem.cpp @@ -1,8 +1,6 @@ #include "cparticlesystem.hpp" #include "glhelper.hpp" -using namespace EE::Graphics::Private; - namespace EE { namespace Graphics { cParticleSystem::cParticleSystem() : @@ -41,7 +39,7 @@ cParticleSystem::~cParticleSystem() { } void cParticleSystem::Create(const EE_PARTICLE_EFFECT& Effect, const Uint32& NumParticles, const Uint32& TexId, const eeFloat& X, const eeFloat& Y, const eeFloat& PartSize, const bool& AnimLoop, const Uint32& NumLoops, const eeColorAf& Color, const eeFloat& X2, const eeFloat& Y2, const eeFloat& AlphaDecay, const eeFloat& XSpeed, const eeFloat& YSpeed, const eeFloat& XAcceleration, const eeFloat& YAcceleration) { - mPointsSup = cGL::instance()->PointSpriteSupported(); + mPointsSup = GLi->PointSpriteSupported(); mEffect = Effect; mX = X; diff --git a/src/graphics/cshader.cpp b/src/graphics/cshader.cpp index d484fa77a..417dcd316 100644 --- a/src/graphics/cshader.cpp +++ b/src/graphics/cshader.cpp @@ -60,30 +60,30 @@ void cShader::Init( const Uint32& Type ) { mValid = false; mCompiled = false; mGLId = glCreateShader( mType ); -} - -void cShader::Reload() { - Init( mType ); - - SetSource( mSource ); - - Compile(); } -void cShader::SetSource( const std::string& Source ) { +void cShader::Reload() { + Init( mType ); + + SetSource( mSource ); + + Compile(); +} + +void cShader::SetSource( const std::string& Source ) { if ( IsCompiled() ) { cLog::instance()->Write( "Can't set source for compiled shaders" ); return; - } - - mSource = Source; - + } + + mSource = Source; + const char * src = reinterpret_cast ( &Source[0] ); glShaderSource( mGLId, 1, &src, NULL ); } -void cShader::SetSource( const Uint8 * Data, const Uint32& DataSize ) { +void cShader::SetSource( const Uint8 * Data, const Uint32& DataSize ) { std::string _dst( DataSize, 0 ); memcpy( reinterpret_cast( &_dst[0] ), reinterpret_cast( &Data[0] ), DataSize ); @@ -91,10 +91,10 @@ void cShader::SetSource( const Uint8 * Data, const Uint32& DataSize ) { SetSource( _dst ); } -void cShader::SetSource( const std::vector& Source ) { +void cShader::SetSource( const std::vector& Source ) { std::string _dst( Source.size(), 0 ); - - memcpy( reinterpret_cast( &_dst[0] ), reinterpret_cast( &Source[0] ), Source.size() ); + + memcpy( reinterpret_cast( &_dst[0] ), reinterpret_cast( &Source[0] ), Source.size() ); SetSource( _dst ); } @@ -121,7 +121,7 @@ bool cShader::Compile() { glGetShaderInfoLog( GetId(), logarraysize, &logsize, reinterpret_cast( &mCompileLog[0] ) ); cLog::instance()->Write( "Couldn't compile shader. Log follows:" ); - cLog::instance()->Write( mCompileLog ); + cLog::instance()->Write( mCompileLog ); cLog::instance()->Write( mSource ); } else { cLog::instance()->Write( "Shader Loaded Succesfully" ); @@ -151,7 +151,7 @@ cVertexShader::cVertexShader( cPack * Pack, const std::string& Filename ) : } cFragmentShader::cFragmentShader() : - cShader(GL_FRAGMENT_SHADER) + cShader( GL_FRAGMENT_SHADER ) { } diff --git a/src/graphics/cshaderprogram.cpp b/src/graphics/cshaderprogram.cpp index 34766fac3..4d1532590 100644 --- a/src/graphics/cshaderprogram.cpp +++ b/src/graphics/cshaderprogram.cpp @@ -3,8 +3,6 @@ #include "cglobalbatchrenderer.hpp" #include "glhelper.hpp" -using namespace EE::Graphics::Private; - namespace EE { namespace Graphics { cShaderProgram::cShaderProgram( const std::string& name ) : @@ -117,7 +115,7 @@ void cShaderProgram::RemoveFromManager() { } void cShaderProgram::Init() { - if ( cGL::instance()->ShadersSupported() && 0 == Handler() ) { + if ( GLi->ShadersSupported() && 0 == Handler() ) { mHandler = glCreateProgram(); mValid = false; mUniformLocations.clear(); @@ -258,6 +256,21 @@ bool cShaderProgram::SetUniform( const std::string& Name, Int32 Value ) { return ( Location >= 0 ); } +bool SetUniformMatrix( const Int32& Id, const eeFloat * Value ) { + glUniformMatrix4fv( Id, 1, false, Value ); + + return true; +} + +bool cShaderProgram::SetUniformMatrix( const std::string Name, const eeFloat * Value ) { + Int32 Location = UniformLocation( Name ); + + if ( Location >= 0 ) + glUniformMatrix4fv( Location, 1, false, Value ); + + return ( Location >= 0 ); +} + const std::string& cShaderProgram::Name() const { return mName; } diff --git a/src/graphics/cshaderprogram.hpp b/src/graphics/cshaderprogram.hpp index 3af2478e0..7d15ad703 100644 --- a/src/graphics/cshaderprogram.hpp +++ b/src/graphics/cshaderprogram.hpp @@ -72,6 +72,10 @@ class EE_API cShaderProgram { /** @overload */ bool SetUniform( const std::string& Name, Int32 Value ); + bool SetUniformMatrix( const std::string Name, const eeFloat * Value ); + + bool SetUniformMatrix( const Int32& Id, const eeFloat * Value ); + /** @return The id of the program (the handle) */ const Uint32& Handler() const { return mHandler; } diff --git a/src/graphics/ctextcache.cpp b/src/graphics/ctextcache.cpp index ce1d5d7a9..cba36bb1b 100644 --- a/src/graphics/ctextcache.cpp +++ b/src/graphics/ctextcache.cpp @@ -137,16 +137,16 @@ void cTextCache::Draw( const eeFloat& X, const eeFloat& Y, const Uint32& Flags, mCachedCoords = false; } + cGlobalBatchRenderer::instance()->Draw(); + if ( Angle != 0.0f || Scale != 1.0f ) { mFont->Draw( *this, X, Y, Flags, Scale, Angle, Effect ); } else { - cGlobalBatchRenderer::instance()->Draw(); - - glTranslatef( X, Y, 0.f ); + GLi->Translatef( X, Y, 0.f ); mFont->Draw( *this, 0, 0, Flags, Scale, Angle, Effect ); - glTranslatef( -X, -Y, 0.f ); + GLi->Translatef( -X, -Y, 0.f ); } } } diff --git a/src/graphics/ctextcache.hpp b/src/graphics/ctextcache.hpp index 732321f3d..f32eb3a87 100644 --- a/src/graphics/ctextcache.hpp +++ b/src/graphics/ctextcache.hpp @@ -3,6 +3,7 @@ #include "base.hpp" #include "fonthelper.hpp" +#include "glhelper.hpp" namespace EE { namespace Graphics { diff --git a/src/graphics/ctexturefactory.cpp b/src/graphics/ctexturefactory.cpp index e211b9882..ba5ba3f7c 100755 --- a/src/graphics/ctexturefactory.cpp +++ b/src/graphics/ctexturefactory.cpp @@ -2,8 +2,6 @@ #include "ctextureloader.hpp" #include "glhelper.hpp" -using namespace EE::Graphics::Private; - namespace EE { namespace Graphics { cTextureFactory::cTextureFactory() : @@ -101,15 +99,15 @@ Uint32 cTextureFactory::FindFreeSlot() { void cTextureFactory::Bind( const cTexture* Tex, const Uint32& TextureUnit ) { if( NULL != Tex && mCurrentTexture[ TextureUnit ] != (Int32)Tex->Handle() ) { - if ( cGL::instance()->IsExtension( EEGL_ARB_multitexture ) ) - glActiveTextureARB( GL_TEXTURE0_ARB + TextureUnit ); + if ( GLi->IsExtension( EEGL_ARB_multitexture ) ) + SetActiveTextureUnit( TextureUnit ); glBindTexture( GL_TEXTURE_2D, Tex->Handle() ); mCurrentTexture[ TextureUnit ] = Tex->Handle(); - if ( cGL::instance()->IsExtension( EEGL_ARB_multitexture ) ) - glActiveTextureARB( GL_TEXTURE0_ARB ); + if ( GLi->IsExtension( EEGL_ARB_multitexture ) ) + SetActiveTextureUnit( 0 ); } } @@ -267,16 +265,16 @@ void cTextureFactory::SetTextureConstantColor( const eeColorAf& Color ) { } void cTextureFactory::SetTextureEnv( const EE_TEXTURE_PARAM& Param, const Int32& Val ) { - GLenum lParam = (GLenum)cGL::instance()->GetTextureParamEnum( Param ); + GLenum lParam = (GLenum)GLi->GetTextureParamEnum( Param ); glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB ); if( Param == TEX_PARAM_COLOR_FUNC || Param == TEX_PARAM_ALPHA_FUNC ) { - glTexEnvi( GL_TEXTURE_ENV, lParam, cGL::instance()->GetTextureFuncEnum( (EE_TEXTURE_FUNC)Val ) ); + glTexEnvi( GL_TEXTURE_ENV, lParam, GLi->GetTextureFuncEnum( (EE_TEXTURE_FUNC)Val ) ); } else if( Param >= TEX_PARAM_COLOR_SOURCE_0 && Param <= TEX_PARAM_ALPHA_SOURCE_2 ) { - glTexEnvi( GL_TEXTURE_ENV, lParam, cGL::instance()->GetTextureSourceEnum( (EE_TEXTURE_SOURCE)Val ) ); + glTexEnvi( GL_TEXTURE_ENV, lParam, GLi->GetTextureSourceEnum( (EE_TEXTURE_SOURCE)Val ) ); } else if( Param >= TEX_PARAM_COLOR_OP_0 && Param <= TEX_PARAM_ALPHA_OP_2 ) { - glTexEnvi( GL_TEXTURE_ENV, lParam, cGL::instance()->GetTextureOpEnum( (EE_TEXTURE_OP)Val ) ); + glTexEnvi( GL_TEXTURE_ENV, lParam, GLi->GetTextureOpEnum( (EE_TEXTURE_OP)Val ) ); } else { glTexEnvi( GL_TEXTURE_ENV, lParam, Val ); } @@ -287,7 +285,7 @@ const EE_PRE_BLEND_FUNC& cTextureFactory::GetPreBlendFunc() const { } eeUint cTextureFactory::GetValidTextureSize(const eeUint& Size) { - if ( cGL::instance()->IsExtension( EEGL_ARB_texture_non_power_of_two ) ) + if ( GLi->IsExtension( EEGL_ARB_texture_non_power_of_two ) ) return Size; else return NextPowOfTwo(Size); diff --git a/src/graphics/ctextureloader.cpp b/src/graphics/ctextureloader.cpp index 0a7d958bc..c9ee0d326 100644 --- a/src/graphics/ctextureloader.cpp +++ b/src/graphics/ctextureloader.cpp @@ -5,8 +5,6 @@ #include "../helper/SOIL/SOIL.h" #include "glhelper.hpp" -using namespace EE::Graphics::Private; - namespace EE { namespace Graphics { cTextureLoader::cTextureLoader( const std::string& Filepath, @@ -156,7 +154,7 @@ void cTextureLoader::Start() { void cTextureLoader::LoadFromPath() { if ( FileExists( mFilepath ) ) { - if ( cGL::instance()->IsExtension( EEGL_EXT_texture_compression_s3tc ) ) + if ( GLi->IsExtension( EEGL_EXT_texture_compression_s3tc ) ) mIsDDS = 0 != stbi_dds_test_filename( mFilepath.c_str() ); if ( mIsDDS ) { @@ -188,7 +186,7 @@ void cTextureLoader::LoadFromPack() { } void cTextureLoader::LoadFromMemory() { - if ( cGL::instance()->IsExtension( EEGL_EXT_texture_compression_s3tc ) ) + if ( GLi->IsExtension( EEGL_EXT_texture_compression_s3tc ) ) mIsDDS = 0 != stbi_dds_test_memory( mImagePtr, mSize ); if ( mIsDDS ) { diff --git a/src/graphics/cvertexbuffer.cpp b/src/graphics/cvertexbuffer.cpp index 0624bb6bd..222855d11 100644 --- a/src/graphics/cvertexbuffer.cpp +++ b/src/graphics/cvertexbuffer.cpp @@ -3,13 +3,12 @@ #include "cvertexbuffervbo.hpp" #include "glhelper.hpp" #include "cvertexbuffermanager.hpp" - using namespace EE::Graphics::Private; namespace EE { namespace Graphics { cVertexBuffer * cVertexBuffer::Create( const Uint32& VertexFlags, EE_DRAW_MODE DrawType, const Int32& ReserveVertexSize, const Int32& ReserveIndexSize, EE_VBO_USAGE_TYPE UsageType ) { - if ( cGL::instance()->IsExtension( GLEW_ARB_vertex_buffer_object ) ) + if ( GLi->IsExtension( EEGL_ARB_vertex_buffer_object ) ) return eeNew( cVertexBufferVBO, ( VertexFlags, DrawType, ReserveVertexSize, ReserveIndexSize, UsageType ) ); return eeNew( cVertexBufferOGL, ( VertexFlags, DrawType, ReserveVertexSize, ReserveIndexSize, UsageType ) ); diff --git a/src/graphics/cvertexbufferogl.cpp b/src/graphics/cvertexbufferogl.cpp index 9b13999b6..fde5dc226 100644 --- a/src/graphics/cvertexbufferogl.cpp +++ b/src/graphics/cvertexbufferogl.cpp @@ -1,8 +1,6 @@ #include "cvertexbufferogl.hpp" #include "glhelper.hpp" -using namespace EE::Graphics::Private; - namespace EE { namespace Graphics { cVertexBufferOGL::cVertexBufferOGL( const Uint32& VertexFlags, EE_DRAW_MODE DrawType, const Int32& ReserveVertexSize, const Int32& ReserveIndexSize, EE_VBO_USAGE_TYPE UsageType ) : @@ -52,7 +50,7 @@ void cVertexBufferOGL::SetVertexStates() { } /// TEXTURES - if ( cGL::instance()->IsExtension( EEGL_ARB_multitexture ) ) { + if ( GLi->IsExtension( EEGL_ARB_multitexture ) ) { for ( Int32 i = 0; i < 5; i++ ) { if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_TEXTURE0 + i ) ) { glClientActiveTextureARB( GL_TEXTURE0_ARB + i ); diff --git a/src/graphics/cvertexbuffervbo.cpp b/src/graphics/cvertexbuffervbo.cpp index 92b610cc9..2771ee30a 100644 --- a/src/graphics/cvertexbuffervbo.cpp +++ b/src/graphics/cvertexbuffervbo.cpp @@ -1,8 +1,6 @@ #include "cvertexbuffervbo.hpp" #include "glhelper.hpp" -using namespace EE::Graphics::Private; - namespace EE { namespace Graphics { cVertexBufferVBO::cVertexBufferVBO( const Uint32& VertexFlags, EE_DRAW_MODE DrawType, const Int32& ReserveVertexSize, const Int32& ReserveIndexSize, EE_VBO_USAGE_TYPE UsageType ) : @@ -119,7 +117,7 @@ void cVertexBufferVBO::SetVertexStates() { } /// TEXTURES - if ( cGL::instance()->IsExtension( EEGL_ARB_multitexture ) ) { + if ( GLi->IsExtension( EEGL_ARB_multitexture ) ) { for ( Int32 i = 0; i < 5; i++ ) { if( VERTEX_FLAG_QUERY( mVertexFlags, VERTEX_FLAG_TEXTURE0 + i ) ) { glClientActiveTextureARB( GL_TEXTURE0_ARB + i ); diff --git a/src/graphics/glhelper.cpp b/src/graphics/glhelper.cpp index 655029ac9..58700c3f7 100644 --- a/src/graphics/glhelper.cpp +++ b/src/graphics/glhelper.cpp @@ -1,138 +1,2 @@ #include "glhelper.hpp" -namespace EE { namespace Graphics { namespace Private { - -cGL::cGL() : - mExtensions(0) -{ - -} - -cGL::~cGL() { - -} - -void cGL::WriteExtension( Uint8 Pos, Uint32 BitWrite ) { - Write32BitKey( &mExtensions, Pos, BitWrite ); -} - -void cGL::Init() { - bool glewOn = false; - - #ifdef EE_GLEW_AVAILABLE - glewOn = ( GLEW_OK == glewInit() ); - - if ( glewOn ) { - WriteExtension( EEGL_ARB_texture_non_power_of_two , GLEW_ARB_texture_non_power_of_two ); - WriteExtension( EEGL_ARB_point_parameters , GLEW_ARB_point_parameters ); - WriteExtension( EEGL_ARB_point_sprite , GLEW_ARB_point_sprite ); - WriteExtension( EEGL_ARB_shading_language_100 , GLEW_ARB_shading_language_100 ); - WriteExtension( EEGL_ARB_shader_objects , GLEW_ARB_shader_objects ); - WriteExtension( EEGL_ARB_vertex_shader , GLEW_ARB_vertex_shader ); - WriteExtension( EEGL_ARB_fragment_shader , GLEW_ARB_fragment_shader ); - WriteExtension( EEGL_EXT_framebuffer_object , GLEW_EXT_framebuffer_object ); - WriteExtension( EEGL_ARB_multitexture , GLEW_ARB_multitexture ); - WriteExtension( EEGL_EXT_texture_compression_s3tc , GLEW_EXT_texture_compression_s3tc ); - } - #endif - - if ( !glewOn ) { - WriteExtension( EEGL_ARB_texture_non_power_of_two , GetExtension( "GL_ARB_texture_non_power_of_two" ) ); - WriteExtension( EEGL_ARB_point_parameters , GetExtension( "GL_ARB_point_parameters" ) ); - WriteExtension( EEGL_ARB_point_sprite , GetExtension( "GL_ARB_point_sprite" ) ); - WriteExtension( EEGL_ARB_shading_language_100 , GetExtension( "GL_ARB_shading_language_100" ) ); - WriteExtension( EEGL_ARB_shader_objects , GetExtension( "GL_ARB_shader_objects" ) ); - WriteExtension( EEGL_ARB_vertex_shader , GetExtension( "GL_ARB_vertex_shader" ) ); - WriteExtension( EEGL_ARB_fragment_shader , GetExtension( "GL_ARB_fragment_shader" ) ); - WriteExtension( EEGL_EXT_framebuffer_object , GetExtension( "GL_EXT_framebuffer_object" ) ); - WriteExtension( EEGL_ARB_multitexture , GetExtension( "GL_ARB_multitexture" ) ); - WriteExtension( EEGL_EXT_texture_compression_s3tc , GetExtension( "GL_EXT_texture_compression_s3tc" ) ); - } -} - -Uint32 cGL::GetExtension( const char * name ) { -#ifdef EE_GLEW_AVAILABLE - return glewIsSupported( name ); -#else - char *Exts = (char *)glGetString(GL_EXTENSIONS); - - if ( strstr( Exts, name ) ) - return 1; - - return 0; -#endif -} - -bool cGL::IsExtension( Uint32 name ) { - return 0 != ( mExtensions & ( 1 << name ) ); -} - -bool cGL::PointSpriteSupported() { - return IsExtension( EEGL_ARB_point_parameters ) && IsExtension( EEGL_ARB_point_sprite ); -} - -bool cGL::ShadersSupported() { - return IsExtension( EEGL_ARB_shading_language_100 ) && IsExtension( EEGL_ARB_shader_objects ) && IsExtension( EEGL_ARB_vertex_shader ) && IsExtension( EEGL_ARB_fragment_shader ); -} - -Uint32 cGL::GetTextureParamEnum( const EE_TEXTURE_PARAM& Type ) { - switch( Type ) { - case TEX_PARAM_COLOR_FUNC: return GL_COMBINE_RGB_ARB; - case TEX_PARAM_ALPHA_FUNC: return GL_COMBINE_ALPHA_ARB; - case TEX_PARAM_COLOR_SOURCE_0: return GL_SOURCE0_RGB_ARB; - case TEX_PARAM_COLOR_SOURCE_1: return GL_SOURCE1_RGB_ARB; - case TEX_PARAM_COLOR_SOURCE_2: return GL_SOURCE2_RGB_ARB; - case TEX_PARAM_ALPHA_SOURCE_0: return GL_SOURCE0_ALPHA_ARB; - case TEX_PARAM_ALPHA_SOURCE_1: return GL_SOURCE1_ALPHA_ARB; - case TEX_PARAM_ALPHA_SOURCE_2: return GL_SOURCE2_ALPHA_ARB; - case TEX_PARAM_COLOR_OP_0: return GL_OPERAND0_RGB_ARB; - case TEX_PARAM_COLOR_OP_1: return GL_OPERAND1_RGB_ARB; - case TEX_PARAM_COLOR_OP_2: return GL_OPERAND2_RGB_ARB; - case TEX_PARAM_ALPHA_OP_0: return GL_OPERAND0_ALPHA_ARB; - case TEX_PARAM_ALPHA_OP_1: return GL_OPERAND1_ALPHA_ARB; - case TEX_PARAM_ALPHA_OP_2: return GL_OPERAND2_ALPHA_ARB; - case TEX_PARAM_COLOR_SCALE: return GL_RGB_SCALE_ARB; - case TEX_PARAM_ALPHA_SCALE: return GL_ALPHA_SCALE; - } - - return 0; -} - -Uint32 cGL::GetTextureFuncEnum( const EE_TEXTURE_FUNC& Type ) { - switch( Type ) { - case TEX_FUNC_MODULATE: return GL_MODULATE; - case TEX_FUNC_REPLACE: return GL_REPLACE; - case TEX_FUNC_ADD: return GL_ADD; - case TEX_FUNC_SUBSTRACT: return GL_SUBTRACT_ARB; - case TEX_FUNC_ADD_SIGNED: return GL_ADD_SIGNED_ARB; - case TEX_FUNC_INTERPOLATE: return GL_INTERPOLATE_ARB; - case TEX_FUNC_DOT3_RGB: return GL_DOT3_RGB_ARB; - case TEX_FUNC_DOT3_RGBA: return GL_DOT3_RGBA_ARB; - } - - return 0; -} - -Uint32 cGL::GetTextureSourceEnum( const EE_TEXTURE_SOURCE& Type ) { - switch( Type) { - case TEX_SRC_TEXTURE: return GL_TEXTURE; - case TEX_SRC_CONSTANT: return GL_CONSTANT_ARB; - case TEX_SRC_PRIMARY: return GL_PRIMARY_COLOR_ARB; - case TEX_SRC_PREVIOUS: return GL_PREVIOUS_ARB; - } - - return 0; -} - -Uint32 cGL::GetTextureOpEnum( const EE_TEXTURE_OP& Type ) { - switch( Type ) { - case TEX_OP_COLOR: return GL_SRC_COLOR; - case TEX_OP_ONE_MINUS_COLOR: return GL_ONE_MINUS_SRC_COLOR; - case TEX_OP_ALPHA: return GL_SRC_ALPHA; - case TEX_OP_ONE_MINUS_ALPHA: return GL_ONE_MINUS_SRC_ALPHA; - } - - return 0; -} - -}}} diff --git a/src/graphics/glhelper.hpp b/src/graphics/glhelper.hpp index 281525926..79cc3c275 100644 --- a/src/graphics/glhelper.hpp +++ b/src/graphics/glhelper.hpp @@ -1,52 +1,6 @@ #ifndef EE_GRAPHICSGLHELPER_HPP #define EE_GRAPHICSGLHELPER_HPP -#include "base.hpp" -#include "renders.hpp" - -namespace EE { namespace Graphics { namespace Private { - -#define EEGL_ARB_texture_non_power_of_two (0) -#define EEGL_ARB_point_parameters (1) -#define EEGL_ARB_point_sprite (2) -#define EEGL_ARB_shading_language_100 (3) -#define EEGL_ARB_shader_objects (4) -#define EEGL_ARB_vertex_shader (5) -#define EEGL_ARB_fragment_shader (6) -#define EEGL_EXT_framebuffer_object (7) -#define EEGL_ARB_multitexture (8) -#define EEGL_EXT_texture_compression_s3tc (9) - -class cGL : public tSingleton { - friend class tSingleton; - public: - cGL(); - - virtual ~cGL(); - - void Init(); - - Uint32 GetExtension( const char * name ); - - bool IsExtension( Uint32 name ); - - bool PointSpriteSupported(); - - bool ShadersSupported(); - - Uint32 GetTextureParamEnum( const EE_TEXTURE_PARAM& Type ); - - Uint32 GetTextureFuncEnum( const EE_TEXTURE_FUNC& Type ); - - Uint32 GetTextureSourceEnum( const EE_TEXTURE_SOURCE& Type ); - - Uint32 GetTextureOpEnum( const EE_TEXTURE_OP& Type ); - protected: - Uint32 mExtensions; - private: - void WriteExtension( Uint8 Pos, Uint32 BitWrite ); -}; - -}}} +#include "renderer/cgl.hpp" #endif diff --git a/src/graphics/pixelperfect.cpp b/src/graphics/pixelperfect.cpp index a51e6888e..6a7b418de 100644 --- a/src/graphics/pixelperfect.cpp +++ b/src/graphics/pixelperfect.cpp @@ -2,17 +2,12 @@ namespace EE { namespace Graphics { -#define COLLIDE_MAX(a,b) ((a > b) ? a : b) -#define COLLIDE_MIN(a,b) ((a < b) ? a : b) +bool PixelPerfectCollide( cTexture * Tex1, const Uint16& x1, const Uint16& y1, cTexture * Tex2, const Uint16& x2, const Uint16& y2, const eeRectu& Tex1_SrcRECT, const eeRectu& Tex2_SrcRECT ) { + eeASSERT( NULL != Tex1 && NULL != Tex2 ); -bool PixelPerfectCollide( const Uint32& TexId_1, const Uint16& x1, const Uint16& y1, const Uint32& TexId_2, const Uint16& x2, const Uint16& y2, const eeRectu& Tex1_SrcRECT, const eeRectu& Tex2_SrcRECT ) { - cTextureFactory* TF = cTextureFactory::instance(); Uint16 ax1, ay1, ax2, ay2, bx1, by1, bx2, by2; bool Collide = false; - - cTexture* Tex1 = TF->GetTexture(TexId_1); - cTexture* Tex2 = TF->GetTexture(TexId_2); - + ax1 = x1; ay1 = y1; if (Tex1_SrcRECT.Right != 0 && Tex1_SrcRECT.Bottom != 0) { @@ -39,10 +34,10 @@ bool PixelPerfectCollide( const Uint32& TexId_1, const Uint16& x1, const Uint16& Tex1->Lock(); Tex2->Lock(); - inter_x0 = COLLIDE_MAX(ax1,bx1); - inter_x1 = COLLIDE_MIN(ax2,bx2); - inter_y0 = COLLIDE_MAX(ay1,by1); - inter_y1 = COLLIDE_MIN(ay2,by2); + inter_x0 = eemax(ax1,bx1); + inter_x1 = eemin(ax2,bx2); + inter_y0 = eemax(ay1,by1); + inter_y1 = eemin(ay2,by2); eeColorA C1, C2; for(Uint16 y = inter_y0 ; y <= inter_y1 ; y++) { @@ -70,13 +65,12 @@ bool PixelPerfectCollide( const Uint32& TexId_1, const Uint16& x1, const Uint16& return Collide; } -bool PixelPerfectCollide( const Uint32& TexId_1, const Uint16& x1, const Uint16& y1, const Uint16& x2, const Uint16& y2, const eeRectu& Tex1_SrcRECT) { - cTextureFactory* TF = cTextureFactory::instance(); +bool PixelPerfectCollide( cTexture * Tex, const Uint16& x1, const Uint16& y1, const Uint16& x2, const Uint16& y2, const eeRectu& Tex1_SrcRECT) { + eeASSERT( NULL != Tex ); + Uint16 ax1, ay1, ax2, ay2; bool Collide = false; - - cTexture* Tex = TF->GetTexture(TexId_1); - + ax1 = x1; ay1 = y1; if (Tex1_SrcRECT.Right != 0 && Tex1_SrcRECT.Bottom != 0) { @@ -104,5 +98,5 @@ bool PixelPerfectCollide( const Uint32& TexId_1, const Uint16& x1, const Uint16& } return Collide; } - + }} diff --git a/src/graphics/pixelperfect.hpp b/src/graphics/pixelperfect.hpp index dd35f1dfe..7129d4c4a 100644 --- a/src/graphics/pixelperfect.hpp +++ b/src/graphics/pixelperfect.hpp @@ -17,7 +17,7 @@ namespace EE { namespace Graphics { * @warning Stress the CPU easily. \n Creates a copy of the texture on the app contex. \n It will not work with scaled or rotated textures. * @return True if collided */ -bool EE_API PixelPerfectCollide( const Uint32& TexId_1, const Uint16& x1, const Uint16& y1, const Uint32& TexId_2, const Uint16& x2, const Uint16& y2, const eeRectu& Tex1_SrcRECT = eeRectu(0,0,0,0), const eeRectu& Tex2_SrcRECT = eeRectu(0,0,0,0) ); +bool EE_API PixelPerfectCollide( cTexture * Tex1, const Uint16& x1, const Uint16& y1, cTexture * Tex2, const Uint16& x2, const Uint16& y2, const eeRectu& Tex1_SrcRECT = eeRectu(0,0,0,0), const eeRectu& Tex2_SrcRECT = eeRectu(0,0,0,0) ); /** Pixel Perfect Collition implementation between texture and a point * @param TexId_1 First Texture Id @@ -28,8 +28,8 @@ bool EE_API PixelPerfectCollide( const Uint32& TexId_1, const Uint16& x1, const * @param Tex1_SrcRECT The sector of the texture from TexId_1 that you are rendering, the sector you want to collide ( on cSprite the SprSrcRECT ) * @return True if collided */ -bool EE_API PixelPerfectCollide( const Uint32& TexId_1, const Uint16& x1, const Uint16& y1, const Uint16& x2, const Uint16& y2, const eeRectu& Tex1_SrcRECT = eeRectu(0,0,0,0) ); +bool EE_API PixelPerfectCollide( cTexture * Tex, const Uint16& x1, const Uint16& y1, const Uint16& x2, const Uint16& y2, const eeRectu& Tex1_SrcRECT = eeRectu(0,0,0,0) ); }} -#endif +#endif diff --git a/src/graphics/renderer/base.hpp b/src/graphics/renderer/base.hpp new file mode 100644 index 000000000..f74abbeeb --- /dev/null +++ b/src/graphics/renderer/base.hpp @@ -0,0 +1,9 @@ +#ifndef EE_GRAPHICS_RENDERER_BASE_HPP +#define EE_GRAPHICS_RENDERER_BASE_HPP + +#include "../base.hpp" +#include "../renders.hpp" + +//#define EE_GL3_ENABLED + +#endif diff --git a/src/graphics/renderer/cgl.cpp b/src/graphics/renderer/cgl.cpp new file mode 100644 index 000000000..8ead48507 --- /dev/null +++ b/src/graphics/renderer/cgl.cpp @@ -0,0 +1,191 @@ +#include "cgl.hpp" +#include "crenderergl.hpp" +#include "crenderergl3.hpp" + +namespace EE { namespace Graphics { + +cGL * GLi = NULL; + +cGL * cGL::ms_singleton = NULL; + +cGL * cGL::CreateSingleton() { + if ( ms_singleton == 0 ) { + #ifdef EE_GL3_ENABLED + /** Implement an OpenGL3 compilant renderer */ + if ( '3' == glGetString(GL_VERSION)[0] ) + ms_singleton = eeNew( cRendererGL3, () ); + else + #endif + ms_singleton = eeNew( cRendererGL, () ); + } + + return ms_singleton; +} + +cGL * cGL::ExistsSingleton() { + return ms_singleton; +} + +cGL * cGL::instance() { + return CreateSingleton(); +} + +void cGL::DestroySingleton() { + if( ms_singleton != 0 ) { + eeDelete( ms_singleton ); + ms_singleton = 0; + } +} + +cGL::cGL() : + mExtensions(0) +{ + GLi = this; +} + +cGL::~cGL() { + GLi = NULL; +} + +void cGL::WriteExtension( Uint8 Pos, Uint32 BitWrite ) { + Write32BitKey( &mExtensions, Pos, BitWrite ); +} + +void cGL::Init() { + bool glewOn = false; + + #ifdef EE_GLEW_AVAILABLE + glewOn = ( GLEW_OK == glewInit() ); + + if ( glewOn ) { + WriteExtension( EEGL_ARB_texture_non_power_of_two , GLEW_ARB_texture_non_power_of_two ); + WriteExtension( EEGL_ARB_point_parameters , GLEW_ARB_point_parameters ); + WriteExtension( EEGL_ARB_point_sprite , GLEW_ARB_point_sprite ); + WriteExtension( EEGL_ARB_shading_language_100 , GLEW_ARB_shading_language_100 ); + WriteExtension( EEGL_ARB_shader_objects , GLEW_ARB_shader_objects ); + WriteExtension( EEGL_ARB_vertex_shader , GLEW_ARB_vertex_shader ); + WriteExtension( EEGL_ARB_fragment_shader , GLEW_ARB_fragment_shader ); + WriteExtension( EEGL_EXT_framebuffer_object , GLEW_EXT_framebuffer_object ); + WriteExtension( EEGL_ARB_multitexture , GLEW_ARB_multitexture ); + WriteExtension( EEGL_EXT_texture_compression_s3tc , GLEW_EXT_texture_compression_s3tc ); + WriteExtension( EEGL_ARB_vertex_buffer_object , GLEW_ARB_vertex_buffer_object ); + } + else + #endif + { + WriteExtension( EEGL_ARB_texture_non_power_of_two , GetExtension( "GL_ARB_texture_non_power_of_two" ) ); + WriteExtension( EEGL_ARB_point_parameters , GetExtension( "GL_ARB_point_parameters" ) ); + WriteExtension( EEGL_ARB_point_sprite , GetExtension( "GL_ARB_point_sprite" ) ); + WriteExtension( EEGL_ARB_shading_language_100 , GetExtension( "GL_ARB_shading_language_100" ) ); + WriteExtension( EEGL_ARB_shader_objects , GetExtension( "GL_ARB_shader_objects" ) ); + WriteExtension( EEGL_ARB_vertex_shader , GetExtension( "GL_ARB_vertex_shader" ) ); + WriteExtension( EEGL_ARB_fragment_shader , GetExtension( "GL_ARB_fragment_shader" ) ); + WriteExtension( EEGL_EXT_framebuffer_object , GetExtension( "GL_EXT_framebuffer_object" ) ); + WriteExtension( EEGL_ARB_multitexture , GetExtension( "GL_ARB_multitexture" ) ); + WriteExtension( EEGL_EXT_texture_compression_s3tc , GetExtension( "GL_EXT_texture_compression_s3tc" ) ); + WriteExtension( EEGL_ARB_vertex_buffer_object , GetExtension( "GL_ARB_vertex_buffer_object" ) ); + } +} + +Uint32 cGL::GetExtension( const char * name ) { +#ifdef EE_GLEW_AVAILABLE + return glewIsSupported( name ); +#else + char *Exts = (char *)glGetString(GL_EXTENSIONS); + + if ( strstr( Exts, name ) ) + return 1; + + return 0; +#endif +} + +bool cGL::IsExtension( Uint32 name ) { + return 0 != ( mExtensions & ( 1 << name ) ); +} + +bool cGL::PointSpriteSupported() { + return IsExtension( EEGL_ARB_point_parameters ) && IsExtension( EEGL_ARB_point_sprite ); +} + +bool cGL::ShadersSupported() { + return IsExtension( EEGL_ARB_shading_language_100 ) && IsExtension( EEGL_ARB_shader_objects ) && IsExtension( EEGL_ARB_vertex_shader ) && IsExtension( EEGL_ARB_fragment_shader ); +} + +Uint32 cGL::GetTextureParamEnum( const EE_TEXTURE_PARAM& Type ) { + switch( Type ) { + case TEX_PARAM_COLOR_FUNC: return GL_COMBINE_RGB_ARB; + case TEX_PARAM_ALPHA_FUNC: return GL_COMBINE_ALPHA_ARB; + case TEX_PARAM_COLOR_SOURCE_0: return GL_SOURCE0_RGB_ARB; + case TEX_PARAM_COLOR_SOURCE_1: return GL_SOURCE1_RGB_ARB; + case TEX_PARAM_COLOR_SOURCE_2: return GL_SOURCE2_RGB_ARB; + case TEX_PARAM_ALPHA_SOURCE_0: return GL_SOURCE0_ALPHA_ARB; + case TEX_PARAM_ALPHA_SOURCE_1: return GL_SOURCE1_ALPHA_ARB; + case TEX_PARAM_ALPHA_SOURCE_2: return GL_SOURCE2_ALPHA_ARB; + case TEX_PARAM_COLOR_OP_0: return GL_OPERAND0_RGB_ARB; + case TEX_PARAM_COLOR_OP_1: return GL_OPERAND1_RGB_ARB; + case TEX_PARAM_COLOR_OP_2: return GL_OPERAND2_RGB_ARB; + case TEX_PARAM_ALPHA_OP_0: return GL_OPERAND0_ALPHA_ARB; + case TEX_PARAM_ALPHA_OP_1: return GL_OPERAND1_ALPHA_ARB; + case TEX_PARAM_ALPHA_OP_2: return GL_OPERAND2_ALPHA_ARB; + case TEX_PARAM_COLOR_SCALE: return GL_RGB_SCALE_ARB; + case TEX_PARAM_ALPHA_SCALE: return GL_ALPHA_SCALE; + } + + return 0; +} + +Uint32 cGL::GetTextureFuncEnum( const EE_TEXTURE_FUNC& Type ) { + switch( Type ) { + case TEX_FUNC_MODULATE: return GL_MODULATE; + case TEX_FUNC_REPLACE: return GL_REPLACE; + case TEX_FUNC_ADD: return GL_ADD; + case TEX_FUNC_SUBSTRACT: return GL_SUBTRACT_ARB; + case TEX_FUNC_ADD_SIGNED: return GL_ADD_SIGNED_ARB; + case TEX_FUNC_INTERPOLATE: return GL_INTERPOLATE_ARB; + case TEX_FUNC_DOT3_RGB: return GL_DOT3_RGB_ARB; + case TEX_FUNC_DOT3_RGBA: return GL_DOT3_RGBA_ARB; + } + + return 0; +} + +Uint32 cGL::GetTextureSourceEnum( const EE_TEXTURE_SOURCE& Type ) { + switch( Type) { + case TEX_SRC_TEXTURE: return GL_TEXTURE; + case TEX_SRC_CONSTANT: return GL_CONSTANT_ARB; + case TEX_SRC_PRIMARY: return GL_PRIMARY_COLOR_ARB; + case TEX_SRC_PREVIOUS: return GL_PREVIOUS_ARB; + } + + return 0; +} + +Uint32 cGL::GetTextureOpEnum( const EE_TEXTURE_OP& Type ) { + switch( Type ) { + case TEX_OP_COLOR: return GL_SRC_COLOR; + case TEX_OP_ONE_MINUS_COLOR: return GL_ONE_MINUS_SRC_COLOR; + case TEX_OP_ALPHA: return GL_SRC_ALPHA; + case TEX_OP_ONE_MINUS_ALPHA: return GL_ONE_MINUS_SRC_ALPHA; + } + + return 0; +} + +char * cGL::GetExtensions() { + return (char *)glGetString( GL_EXTENSIONS ); +} + +void cGL::Viewport( GLint x, GLint y, GLsizei width, GLsizei height ) { + glViewport( x, y, width, height ); +} + +void cGL::Disable ( GLenum cap ) { + glDisable( cap ); +} + +void cGL::Enable( GLenum cap ) { + glEnable( cap ); +} + +}} diff --git a/src/graphics/renderer/cgl.hpp b/src/graphics/renderer/cgl.hpp new file mode 100644 index 000000000..4cd48ee24 --- /dev/null +++ b/src/graphics/renderer/cgl.hpp @@ -0,0 +1,97 @@ +#ifndef EE_GRAPHICS_CGL_HPP +#define EE_GRAPHICS_CGL_HPP + +#include "base.hpp" + +namespace EE { namespace Graphics { + +enum EEGL_extensions { + EEGL_ARB_texture_non_power_of_two = 0, + EEGL_ARB_point_parameters, + EEGL_ARB_point_sprite, + EEGL_ARB_shading_language_100, + EEGL_ARB_shader_objects, + EEGL_ARB_vertex_shader, + EEGL_ARB_fragment_shader, + EEGL_EXT_framebuffer_object, + EEGL_ARB_multitexture, + EEGL_EXT_texture_compression_s3tc, + EEGL_ARB_vertex_buffer_object +}; + +enum EEGL_version { + GLv_2, + GLv_3, + GLv_ES +}; + +class cGL { + static cGL * ms_singleton; + public: + static cGL * CreateSingleton(); + + static cGL * ExistsSingleton(); + + static cGL * instance(); + + static void DestroySingleton(); + + cGL(); + + virtual ~cGL(); + + virtual void Init(); + + Uint32 GetExtension( const char * name ); + + bool IsExtension( Uint32 name ); + + bool PointSpriteSupported(); + + bool ShadersSupported(); + + Uint32 GetTextureParamEnum( const EE_TEXTURE_PARAM& Type ); + + Uint32 GetTextureFuncEnum( const EE_TEXTURE_FUNC& Type ); + + Uint32 GetTextureSourceEnum( const EE_TEXTURE_SOURCE& Type ); + + Uint32 GetTextureOpEnum( const EE_TEXTURE_OP& Type ); + + char * GetExtensions(); + + void Viewport ( GLint x, GLint y, GLsizei width, GLsizei height ); + + void Disable ( GLenum cap ); + + void Enable( GLenum cap ); + + virtual EEGL_version Version() = 0; + + virtual void PushMatrix() = 0; + + virtual void PopMatrix() = 0; + + virtual void LoadIdentity() = 0; + + virtual void Translatef( GLfloat x, GLfloat y, GLfloat z ) = 0; + + virtual void Rotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ) = 0; + + virtual void Scalef( GLfloat x, GLfloat y, GLfloat z ) = 0; + + virtual void MatrixMode (GLenum mode) = 0; + + virtual void Ortho ( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar ) = 0; + + protected: + Uint32 mExtensions; + private: + void WriteExtension( Uint8 Pos, Uint32 BitWrite ); +}; + +extern cGL * GLi; + +}} + +#endif diff --git a/src/graphics/renderer/crenderergl.cpp b/src/graphics/renderer/crenderergl.cpp new file mode 100644 index 000000000..bd1068c90 --- /dev/null +++ b/src/graphics/renderer/crenderergl.cpp @@ -0,0 +1,47 @@ +#include "crenderergl.hpp" + +namespace EE { namespace Graphics { + +cRendererGL::cRendererGL() { +} + +cRendererGL::~cRendererGL() { +} + +EEGL_version cRendererGL::Version() { + return GLv_2; +} + +void cRendererGL::PushMatrix() { + glPushMatrix(); +} + +void cRendererGL::PopMatrix() { + glPopMatrix(); +} + +void cRendererGL::LoadIdentity() { + glLoadIdentity(); +} + +void cRendererGL::Translatef( GLfloat x, GLfloat y, GLfloat z ) { + glTranslatef( x, y, z ); +} + +void cRendererGL::Rotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ) { + glRotatef( angle, x, y, z ); +} + +void cRendererGL::Scalef( GLfloat x, GLfloat y, GLfloat z ) { + glScalef( x,y, z ); +} + +void cRendererGL::MatrixMode(GLenum mode) { + glMatrixMode( mode ); +} + +void cRendererGL::Ortho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar ) { + glOrtho( left, right, bottom, top, zNear, zFar ); +} + +}} diff --git a/src/graphics/renderer/crenderergl.hpp b/src/graphics/renderer/crenderergl.hpp new file mode 100644 index 000000000..83b3015d6 --- /dev/null +++ b/src/graphics/renderer/crenderergl.hpp @@ -0,0 +1,38 @@ +#ifndef EE_GRAPHICS_CRENDERERGL_HPP +#define EE_GRAPHICS_CRENDERERGL_HPP + +#include "cgl.hpp" + +namespace EE { namespace Graphics { + +class cRendererGL : public cGL { + public: + cRendererGL(); + + ~cRendererGL(); + + EEGL_version Version(); + + void PushMatrix(); + + void PopMatrix(); + + void LoadIdentity(); + + void Translatef( GLfloat x, GLfloat y, GLfloat z ); + + void Rotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ); + + void Scalef( GLfloat x, GLfloat y, GLfloat z ); + + void MatrixMode (GLenum mode); + + void Ortho ( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar ); + + protected: + +}; + +}} + +#endif diff --git a/src/graphics/renderer/crenderergl3.cpp b/src/graphics/renderer/crenderergl3.cpp new file mode 100644 index 000000000..c75e19784 --- /dev/null +++ b/src/graphics/renderer/crenderergl3.cpp @@ -0,0 +1,145 @@ +#include "crenderergl3.hpp" + +#ifdef EE_GL3_ENABLED + +namespace EE { namespace Graphics { + +const GLchar *g_vertexShader[] = {"#version 130\n", + "uniform mat4 glm_ProjectionMatrix;\n", // replaces deprecated gl_ProjectionMatrix see http://www.lighthouse3d.com/opengl/glsl/index.php?minimal + "uniform mat4 glm_ModelViewMatrix;\n", // replaces deprecated gl_ModelViewMatrix + "in vec4 dgl_Vertex;\n", // replaces deprecated gl_Vertex + "in vec4 dgl_Color;\n", // replaces deprecated gl_Color + "invariant out vec4 Color;\n", // to fragment shader + "void main(void)\n", + "{\n", + " Color = dgl_Color;\n", + " gl_Position = glm_ProjectionMatrix*glm_ModelViewMatrix*dgl_Vertex;\n", // replaces deprecated ftransform() see http://www.songho.ca/opengl/gl_transform.html + " gl_TexCoord[0] = gl_MultiTexCoord0;\n", + "}\n" +}; + +const GLchar *g_fragmentShader[] = {"#version 130\n", + "invariant in vec4 Color;\n", // from vertex shader + "out vec4 dgl_FragColor;\n", // replaces deprecated gl_FragColor + "void main(void)\n", + "{\n", + " dgl_FragColor = Color;\n", // gl_FragColor is deprecated + "}\n" +}; + +cRendererGL3::cRendererGL3() : + shader_id(0), + glm_ProjectionMatrix_id(0), + glm_ModelViewMatrix_id(0), + mCurrentMode(0) +{ + glm_ProjectionMatrix.push ( glm::mat4( 1.0f ) ); // identity matrix + glm_ModelViewMatrix.push ( glm::mat4( 1.0f ) ); // identity matrix +} + +cRendererGL3::~cRendererGL3() { +} + +EEGL_version cRendererGL3::Version() { + return GLv_3; +} + +void cRendererGL3::Init() { + cGL::Init(); + + // compile Vertex shader + GLuint m_vxShaderId = glCreateShader(GL_VERTEX_SHADER); + GLsizei nlines_vx = sizeof(g_vertexShader)/sizeof(const GLchar*); + glShaderSource( m_vxShaderId, nlines_vx, (const GLchar**)g_vertexShader, NULL ); + glCompileShader( m_vxShaderId ); + + // compile Fragment shader + GLuint m_fgShaderId = glCreateShader(GL_FRAGMENT_SHADER); + GLsizei nlines_fg = sizeof(g_fragmentShader)/sizeof(const GLchar*); + glShaderSource( m_fgShaderId, nlines_fg, (const GLchar**)g_fragmentShader, NULL ); + glCompileShader( m_fgShaderId ); + + // link shaders + shader_id = glCreateProgram(); + glAttachShader( shader_id, m_vxShaderId ); + glAttachShader( shader_id, m_fgShaderId ); + glLinkProgram( shader_id ); + + //hooks from CPU to GPU + //define Uniform hooks + glm_ProjectionMatrix_id = glGetUniformLocation(shader_id, "glm_ProjectionMatrix"); + glm_ModelViewMatrix_id = glGetUniformLocation(shader_id, "glm_ModelViewMatrix"); + + // finally, use the shader for rendering + glUseProgram(shader_id); // select the shaders program +} + +void cRendererGL3::PushMatrix() { + mCurMatrix->push( mCurMatrix->top() ); + UpdateMatrix(); +} + +void cRendererGL3::PopMatrix() { + mCurMatrix->pop(); + UpdateMatrix(); +} + +void cRendererGL3::UpdateMatrix() { + switch ( mCurrentMode ) { + case GL_PROJECTION: + { + glUniformMatrix4fv( glm_ProjectionMatrix_id, 1, false, &glm_ProjectionMatrix.top()[0][0] ); + break; + } + case GL_MODELVIEW: + { + glUniformMatrix4fv( glm_ModelViewMatrix_id, 1, false, &glm_ModelViewMatrix.top()[0][0] ); + break; + } + } +} + +void cRendererGL3::LoadIdentity() { + mCurMatrix->top() = glm::mat4(1.0); + UpdateMatrix(); +} + +void cRendererGL3::Translatef( GLfloat x, GLfloat y, GLfloat z ) { + mCurMatrix->top() *= glm::translate( glm::vec3( x, y, z ) ); + UpdateMatrix(); +} + +void cRendererGL3::Rotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ) { + mCurMatrix->top() *= glm::rotate( angle, glm::vec3( x, y, z ) ); + UpdateMatrix(); +} + +void cRendererGL3::Scalef( GLfloat x, GLfloat y, GLfloat z ) { + mCurMatrix->top() *= glm::scale( glm::vec3( x, y, z ) ); + UpdateMatrix(); +} + +void cRendererGL3::MatrixMode(GLenum mode) { + mCurrentMode = mode; + + switch ( mCurrentMode ) { + case GL_PROJECTION: + { + mCurMatrix = &glm_ProjectionMatrix; + break; + } + case GL_MODELVIEW: + { + mCurMatrix = &glm_ModelViewMatrix; + break; + } + } +} + +void cRendererGL3::Ortho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar ) { + mCurMatrix->top() = glm::ortho( left, right, bottom, top , zNear, zFar ); +} + +}} + +#endif diff --git a/src/graphics/renderer/crenderergl3.hpp b/src/graphics/renderer/crenderergl3.hpp new file mode 100644 index 000000000..c9b9d8fe9 --- /dev/null +++ b/src/graphics/renderer/crenderergl3.hpp @@ -0,0 +1,54 @@ +#ifndef EE_GRAPHICS_CRENDERERGL3_HPP +#define EE_GRAPHICS_CRENDERERGL3_HPP + +#ifdef EE_GL3_ENABLED + +#include "cgl.hpp" + +#include //OpenGL Mathematics (GLM). A C++ mathematics library for 3D graphics. +#include + +namespace EE { namespace Graphics { + +class cRendererGL3 : public cGL { + public: + cRendererGL3(); + + ~cRendererGL3(); + + EEGL_version Version(); + + void Init(); + + void PushMatrix(); + + void PopMatrix(); + + void LoadIdentity(); + + void Translatef( GLfloat x, GLfloat y, GLfloat z ); + + void Rotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ); + + void Scalef( GLfloat x, GLfloat y, GLfloat z ); + + void MatrixMode (GLenum mode); + + void Ortho ( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar ); + protected: + GLuint shader_id; + std::stack glm_ProjectionMatrix; // cpu-side + GLint glm_ProjectionMatrix_id; // cpu-side hook to shader uniform + std::stack glm_ModelViewMatrix; // cpu-side + GLint glm_ModelViewMatrix_id; // cpu-side hook to shader uniform + GLenum mCurrentMode; + std::stack* mCurMatrix; + + void UpdateMatrix(); +}; + +}} + +#endif + +#endif diff --git a/src/helper/chipmunk/cpBBTree.c b/src/helper/chipmunk/cpBBTree.c index f6f78e85a..9e684880c 100644 --- a/src/helper/chipmunk/cpBBTree.c +++ b/src/helper/chipmunk/cpBBTree.c @@ -11,14 +11,14 @@ typedef struct Pair Pair; struct cpBBTree { cpSpatialIndex spatialIndex; cpBBTreeVelocityFunc velocityFunc; - + cpHashSet *leaves; Node *root; - + Node *pooledNodes; Pair *pooledPairs; cpArray *allocatedBuffers; - + cpTimestamp stamp; }; @@ -26,11 +26,11 @@ struct Node { void *obj; cpBB bb; Node *parent; - + union { // Internal nodes struct { Node *a, *b; }; - + // Leaves struct { cpTimestamp stamp; @@ -59,13 +59,13 @@ static inline cpBB GetBB(cpBBTree *tree, void *obj) { cpBB bb = tree->spatialIndex.bbfunc(obj); - + cpBBTreeVelocityFunc velocityFunc = tree->velocityFunc; if(velocityFunc){ cpFloat coef = 0.1f; cpFloat x = (bb.r - bb.l)*coef; cpFloat y = (bb.t - bb.b)*coef; - + cpVect v = cpvmult(velocityFunc(obj), 0.1f); return cpBBNew(bb.l + cpfmin(-x, v.x), bb.b + cpfmin(-y, v.y), bb.r + cpfmax(x, v.x), bb.t + cpfmax(y, v.y)); } else { @@ -115,7 +115,7 @@ static Pair * PairFromPool(cpBBTree *tree) { Pair *pair = tree->pooledPairs; - + if(pair){ tree->pooledPairs = pair->a.next; return pair; @@ -123,10 +123,10 @@ PairFromPool(cpBBTree *tree) // Pool is exhausted, make more int count = CP_BUFFER_BYTES/sizeof(Pair); cpAssert(count, "Buffer size is too small."); - + Pair *buffer = (Pair *)cpmalloc(CP_BUFFER_BYTES); cpArrayPush(tree->allocatedBuffers, buffer); - + // push all but the first one, return the first instead for(int i=1; ia.leaf == thread.leaf) next->a.prev = prev; else next->b.prev = prev; } - + if(prev){ if(prev->a.leaf == thread.leaf) prev->a.next = next; else prev->b.next = next; } else { @@ -155,7 +155,7 @@ PairsClear(Node *leaf, cpBBTree *tree) { Pair *pair = leaf->pairs; leaf->pairs = NULL; - + while(pair){ if(pair->a.leaf == leaf){ Pair *next = pair->a.next; @@ -176,15 +176,15 @@ PairInsert(Node *a, Node *b, cpBBTree *tree) { Pair *pair = PairFromPool(tree); Pair *nextA = a->pairs, *nextB = b->pairs; - + if(nextA){ if(nextA->a.leaf == a) nextA->a.prev = pair; else nextA->b.prev = pair; } - + if(nextB){ if(nextB->a.leaf == b) nextB->a.prev = pair; else nextB->b.prev = pair; } - + (*pair) = (Pair){{NULL, a, nextA},{NULL, b, nextB}}; a->pairs = b->pairs = pair; } @@ -203,7 +203,7 @@ static Node * NodeFromPool(cpBBTree *tree) { Node *node = tree->pooledNodes; - + if(node){ tree->pooledNodes = node->parent; return node; @@ -211,10 +211,10 @@ NodeFromPool(cpBBTree *tree) // Pool is exhausted, make more int count = CP_BUFFER_BYTES/sizeof(Node); cpAssert(count, "Buffer size is too small."); - + Node *buffer = (Node *)cpmalloc(CP_BUFFER_BYTES); cpArrayPush(tree->allocatedBuffers, buffer); - + // push all but the first one, return the first instead for(int i=1; iobj = NULL; node->bb = cpBBmerge(a->bb, b->bb); node->parent = NULL; - + NodeSetA(node, a); NodeSetB(node, b); - + return node; } @@ -267,7 +267,7 @@ NodeReplaceChild(Node *parent, Node *child, Node *value, cpBBTree *tree) { cpAssert(!NodeIsLeaf(parent), "Cannot replace child of a leaf."); cpAssert(child == parent->a || child == parent->b, "Node is not a child of parent."); - + if(parent->a == child){ NodeRecycle(tree, parent->a); NodeSetA(parent, value); @@ -275,7 +275,7 @@ NodeReplaceChild(Node *parent, Node *child, Node *value, cpBBTree *tree) NodeRecycle(tree, parent->b); NodeSetB(parent, value); } - + for(Node *node=parent; node; node = node->parent){ node->bb = cpBBmerge(node->a->bb, node->b->bb); } @@ -293,16 +293,16 @@ SubtreeInsert(Node *subtree, Node *leaf, cpBBTree *tree) } else { cpFloat cost_a = cpBBArea(subtree->b->bb) + cpBBMergedArea(subtree->a->bb, leaf->bb); cpFloat cost_b = cpBBArea(subtree->a->bb) + cpBBMergedArea(subtree->b->bb, leaf->bb); - + // cpFloat cost_a = cpBBProximity(subtree->a->bb, leaf->bb); // cpFloat cost_b = cpBBProximity(subtree->b->bb, leaf->bb); - + if(cost_b < cost_a){ NodeSetB(subtree, SubtreeInsert(subtree->b, leaf, tree)); } else { NodeSetA(subtree, SubtreeInsert(subtree->a, leaf, tree)); } - + subtree->bb = cpBBmerge(subtree->bb, leaf->bb); return subtree; } @@ -397,7 +397,7 @@ MarkLeaf(Node *leaf, MarkContext *context) if(leaf->stamp == GetStamp(tree)){ Node *staticRoot = context->staticRoot; if(staticRoot) MarkLeafQuery(staticRoot, leaf, cpFalse, context); - + for(Node *node = leaf; node->parent; node = node->parent){ if(node == node->parent->a){ MarkLeafQuery(node->parent->b, leaf, cpTrue, context); @@ -437,11 +437,11 @@ LeafNew(cpBBTree *tree, void *obj, cpBB bb) Node *node = NodeFromPool(tree); node->obj = obj; node->bb = GetBB(tree, obj); - + node->parent = NULL; node->stamp = 0; node->pairs = NULL; - + return node; } @@ -450,19 +450,19 @@ LeafUpdate(Node *leaf, cpBBTree *tree) { Node *root = tree->root; cpBB bb = tree->spatialIndex.bbfunc(leaf->obj); - + if(!cpBBcontainsBB(leaf->bb, bb)){ leaf->bb = GetBB(tree, leaf->obj); - + root = SubtreeRemove(root, leaf, tree); tree->root = SubtreeInsert(root, leaf, tree); - + PairsClear(leaf, tree); leaf->stamp = GetStamp(tree); - + return cpTrue; } - + return cpFalse; } @@ -510,17 +510,17 @@ cpSpatialIndex * cpBBTreeInit(cpBBTree *tree, cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex) { cpSpatialIndexInit((cpSpatialIndex *)tree, &klass, bbfunc, staticIndex); - + tree->velocityFunc = NULL; - + tree->leaves = cpHashSetNew(0, (cpHashSetEqlFunc)leafSetEql, NULL); tree->root = NULL; - + tree->pooledNodes = NULL; tree->allocatedBuffers = cpArrayNew(0); - + tree->stamp = 0; - + return (cpSpatialIndex *)tree; } @@ -531,7 +531,7 @@ cpBBTreeSetVelocityFunc(cpSpatialIndex *index, cpBBTreeVelocityFunc func) cpAssertWarn(cpFalse, "Ignoring cpBBTreeSetVelocityFunc() call to non-tree spatial index."); return; } - + ((cpBBTree *)index)->velocityFunc = func; } @@ -545,7 +545,7 @@ static void cpBBTreeDestroy(cpBBTree *tree) { cpHashSetFree(tree->leaves); - + cpArrayFreeEach(tree->allocatedBuffers, cpfree); cpArrayFree(tree->allocatedBuffers); } @@ -556,10 +556,10 @@ static void cpBBTreeInsert(cpBBTree *tree, void *obj, cpHashValue hashid) { Node *leaf = cpHashSetInsert(tree->leaves, hashid, obj, tree, (cpHashSetTransFunc)leafSetTrans); - + Node *root = tree->root; tree->root = SubtreeInsert(root, leaf, tree); - + leaf->stamp = GetStamp(tree); LeafAddPairs(leaf, tree); IncrementStamp(tree); @@ -569,7 +569,7 @@ static void cpBBTreeRemove(cpBBTree *tree, void *obj, cpHashValue hashid) { Node *leaf = cpHashSetRemove(tree->leaves, hashid, obj); - + tree->root = SubtreeRemove(tree->root, leaf, tree); PairsClear(leaf, tree); NodeRecycle(tree, leaf); @@ -587,17 +587,17 @@ static void cpBBTreeReindexQuery(cpBBTree *tree, cpSpatialIndexQueryCallback func, void *data) { if(!tree->root) return; - + // LeafUpdate() may modify tree->root. Don't cache it. cpHashSetEach(tree->leaves, (cpHashSetIterFunc)LeafUpdate, tree); - + cpSpatialIndex *staticIndex = tree->spatialIndex.staticIndex; Node *staticRoot = (staticIndex && staticIndex->klass == &klass ? ((cpBBTree *)staticIndex)->root : NULL); - + MarkContext context = {tree, staticRoot, func, data}; MarkSubtree(tree->root, &context); if(staticIndex && !staticRoot) cpSpatialIndexCollideStatic((cpSpatialIndex *)tree, staticIndex, func, data); - + IncrementStamp(tree); } @@ -663,18 +663,18 @@ cpBBTreeEach(cpBBTree *tree, cpSpatialIndexIterator func, void *data) static cpSpatialIndexClass klass = { (cpSpatialIndexDestroyFunc)cpBBTreeDestroy, - + (cpSpatialIndexCountFunc)cpBBTreeCount, (cpSpatialIndexEachFunc)cpBBTreeEach, - + (cpSpatialIndexContainsFunc)cpBBTreeContains, (cpSpatialIndexInsertFunc)cpBBTreeInsert, (cpSpatialIndexRemoveFunc)cpBBTreeRemove, - + (cpSpatialIndexReindexFunc)cpBBTreeReindex, (cpSpatialIndexReindexObjectFunc)cpBBTreeReindexObject, (cpSpatialIndexReindexQueryFunc)cpBBTreeReindexQuery, - + (cpSpatialIndexPointQueryFunc)cpBBTreePointQuery, (cpSpatialIndexSegmentQueryFunc)cpBBTreeSegmentQuery, (cpSpatialIndexQueryFunc)cpBBTreeQuery, @@ -701,14 +701,14 @@ partitionNodes(cpBBTree *tree, Node **nodes, int count) } else if(count == 2) { return NodeNew(tree, nodes[0], nodes[1]); } - + // Find the AABB for these nodes cpBB bb = nodes[0]->bb; for(int i=1; ibb); - + // Split it on it's longest axis cpBool splitWidth = (bb.r - bb.l > bb.t - bb.b); - + // Sort the bounds and use the median as the splitting point cpFloat bounds[count*2]; if(splitWidth){ @@ -722,14 +722,14 @@ partitionNodes(cpBBTree *tree, Node **nodes, int count) bounds[2*i + 1] = nodes[i]->bb.t; } } - + qsort(bounds, count*2, sizeof(cpFloat), (int (*)(const void *, const void *))cpfcompare); cpFloat split = (bounds[count - 1] + bounds[count])*0.5f; // use the medain as the split - + // Generate the child BBs cpBB a = bb, b = bb; if(splitWidth) a.r = b.l = split; else a.t = b.b = split; - + // Partition the nodes int right = count; for(int left=0; left < right;){ @@ -743,13 +743,13 @@ partitionNodes(cpBBTree *tree, Node **nodes, int count) left++; } } - + if(right == count){ Node *node = NULL; for(int i=0; iopath; -// +// // while(!NodeIsLeaf(node)){ // node = (path&(1<a : node->b); // bit = (bit + 1)&(sizeof(unsigned int)*8 - 1); // } -// +// // root = subtreeRemove(root, node, tree); // tree->root = subtreeInsert(root, node, tree); // } @@ -783,17 +783,17 @@ cpBBTreeOptimize(cpSpatialIndex *index) cpAssertWarn(cpFalse, "Ignoring cpBBTreeOptimize() call to non-tree spatial index."); return; } - + cpBBTree *tree = (cpBBTree *)index; Node *root = tree->root; if(!root) return; - + int count = cpBBTreeCount(tree); Node *nodes[count]; Node **cursor = nodes; - + cpHashSetEach(tree->leaves, (cpHashSetIterFunc)fillNodeArray, &cursor); - + SubtreeRecycle(tree, root); tree->root = partitionNodes(tree, nodes, count); } @@ -804,7 +804,7 @@ cpBBTreeOptimize(cpSpatialIndex *index) #ifdef CP_BBTREE_DEBUG_DRAW #include #include -#include +//#include static void NodeRender(Node *node, int depth) @@ -813,22 +813,22 @@ NodeRender(Node *node, int depth) NodeRender(node->a, depth + 1); NodeRender(node->b, depth + 1); } - + cpBB bb = node->bb; - -// GLfloat v = depth/2.0f; + +// GLfloat v = depth/2.0f; // glColor3f(1.0f - v, v, 0.0f); glLineWidth(cpfmax(5.0f - depth, 1.0f)); glBegin(GL_LINES); { glVertex2f(bb.l, bb.b); glVertex2f(bb.l, bb.t); - + glVertex2f(bb.l, bb.t); glVertex2f(bb.r, bb.t); - + glVertex2f(bb.r, bb.t); glVertex2f(bb.r, bb.b); - + glVertex2f(bb.r, bb.b); glVertex2f(bb.l, bb.b); }; glEnd(); @@ -840,7 +840,7 @@ cpBBTreeRenderDebug(cpSpatialIndex *index){ cpAssertWarn(cpFalse, "Ignoring cpBBTreeRenderDebug() call to non-tree spatial index."); return; } - + cpBBTree *tree = (cpBBTree *)index; if(tree->root) NodeRender(tree->root, 0); } diff --git a/src/helper/chipmunk/cpSpaceHash.c b/src/helper/chipmunk/cpSpaceHash.c index b6c1abb64..a75128b4b 100644 --- a/src/helper/chipmunk/cpSpaceHash.c +++ b/src/helper/chipmunk/cpSpaceHash.c @@ -1,15 +1,15 @@ /* Copyright (c) 2007 Scott Lembcke - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -30,17 +30,17 @@ typedef struct cpHandle cpHandle; struct cpSpaceHash { cpSpatialIndex spatialIndex; - + int numcells; cpFloat celldim; - + cpSpaceHashBin **table; cpHashSet *handleSet; - + cpSpaceHashBin *pooledBins; cpArray *pooledHandles; cpArray *allocatedBuffers; - + cpTimestamp stamp; }; @@ -59,7 +59,7 @@ cpHandleInit(cpHandle *hand, void *obj) hand->obj = obj; hand->retain = 0; hand->stamp = 0; - + return hand; } @@ -81,16 +81,16 @@ handleSetTrans(void *obj, cpSpaceHash *hash) // handle pool is exhausted, make more int count = CP_BUFFER_BYTES/sizeof(cpHandle); cpAssert(count, "Buffer size is too small."); - + cpHandle *buffer = (cpHandle *)cpmalloc(CP_BUFFER_BYTES); cpArrayPush(hash->allocatedBuffers, buffer); - + for(int i=0; ipooledHandles, buffer + i); } - + cpHandle *hand = cpHandleInit((cpHandle *)cpArrayPop(hash->pooledHandles), obj); cpHandleRetain(hand); - + return hand; } @@ -114,13 +114,13 @@ clearTableCell(cpSpaceHash *hash, int idx) cpSpaceHashBin *bin = hash->table[idx]; while(bin){ cpSpaceHashBin *next = bin->next; - + cpHandleRelease(bin->handle, hash->pooledHandles); recycleBin(hash, bin); - + bin = next; } - + hash->table[idx] = NULL; } @@ -135,7 +135,7 @@ static inline cpSpaceHashBin * getEmptyBin(cpSpaceHash *hash) { cpSpaceHashBin *bin = hash->pooledBins; - + if(bin){ hash->pooledBins = bin->next; return bin; @@ -143,10 +143,10 @@ getEmptyBin(cpSpaceHash *hash) // Pool is exhausted, make more int count = CP_BUFFER_BYTES/sizeof(cpSpaceHashBin); cpAssert(count, "Buffer size is too small."); - + cpSpaceHashBin *buffer = (cpSpaceHashBin *)cpmalloc(CP_BUFFER_BYTES); cpArrayPush(hash->allocatedBuffers, buffer); - + // push all but the first one, return the first instead for(int i=1; itable); - + hash->numcells = numcells; hash->table = (cpSpaceHashBin **)cpcalloc(numcells, sizeof(cpSpaceHashBin *)); } @@ -177,18 +177,18 @@ cpSpatialIndex * cpSpaceHashInit(cpSpaceHash *hash, cpFloat celldim, int numcells, cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex) { cpSpatialIndexInit((cpSpatialIndex *)hash, &klass, bbfunc, staticIndex); - + cpSpaceHashAllocTable(hash, next_prime(numcells)); hash->celldim = celldim; - + hash->handleSet = cpHashSetNew(0, (cpHashSetEqlFunc)handleSetEql, NULL); hash->pooledHandles = cpArrayNew(0); - + hash->pooledBins = NULL; hash->allocatedBuffers = cpArrayNew(0); - + hash->stamp = 1; - + return (cpSpatialIndex *)hash; } @@ -202,13 +202,13 @@ static void cpSpaceHashDestroy(cpSpaceHash *hash) { clearTable(hash); - + cpHashSetFree(hash->handleSet); - + cpArrayFreeEach(hash->allocatedBuffers, cpfree); cpArrayFree(hash->allocatedBuffers); cpArrayFree(hash->pooledHandles); - + cpfree(hash->table); } @@ -221,7 +221,7 @@ containsHandle(cpSpaceHashBin *bin, cpHandle *hand) if(bin->handle == hand) return cpTrue; bin = bin->next; } - + return cpFalse; } @@ -250,13 +250,13 @@ hashHandle(cpSpaceHash *hash, cpHandle *hand, cpBB bb) int r = floor_int(bb.r/dim); int b = floor_int(bb.b/dim); int t = floor_int(bb.t/dim); - + int n = hash->numcells; for(int i=l; i<=r; i++){ for(int j=b; j<=t; j++){ int idx = hash_func(i,j,n); cpSpaceHashBin *bin = hash->table[idx]; - + // Don't add an object twice to the same cell. if(containsHandle(bin, hand)) continue; @@ -283,11 +283,11 @@ static void cpSpaceHashRehashObject(cpSpaceHash *hash, void *obj, cpHashValue hashid) { cpHandle *hand = (cpHandle *)cpHashSetRemove(hash->handleSet, hashid, obj); - + if(hand){ hand->obj = NULL; cpHandleRelease(hand, hash->pooledHandles); - + cpSpaceHashInsert(hash, obj, hashid); } } @@ -309,7 +309,7 @@ static void cpSpaceHashRemove(cpSpaceHash *hash, void *obj, cpHashValue hashid) { cpHandle *hand = (cpHandle *)cpHashSetRemove(hash->handleSet, hashid, obj); - + if(hand){ hand->obj = NULL; cpHandleRelease(hand, hash->pooledHandles); @@ -337,17 +337,17 @@ remove_orphaned_handles(cpSpaceHash *hash, cpSpaceHashBin **bin_ptr) while(bin){ cpHandle *hand = bin->handle; cpSpaceHashBin *next = bin->next; - + if(!hand->obj){ // orphaned handle, unlink and recycle the bin (*bin_ptr) = bin->next; recycleBin(hash, bin); - + cpHandleRelease(hand, hash->pooledHandles); } else { bin_ptr = &bin->next; } - + bin = next; } } @@ -361,7 +361,7 @@ query_helper(cpSpaceHash *hash, cpSpaceHashBin **bin_ptr, void *obj, cpSpatialIn for(cpSpaceHashBin *bin = *bin_ptr; bin; bin = bin->next){ cpHandle *hand = bin->handle; void *other = hand->obj; - + if(hand->stamp == hash->stamp || obj == other){ continue; } else if(other){ @@ -381,7 +381,7 @@ cpSpaceHashPointQuery(cpSpaceHash *hash, cpVect point, cpSpatialIndexQueryCallba { cpFloat dim = hash->celldim; int idx = hash_func(floor_int(point.x/dim), floor_int(point.y/dim), hash->numcells); // Fix by ShiftZ - + query_helper(hash, &hash->table[idx], &point, func, data); hash->stamp++; } @@ -395,17 +395,17 @@ cpSpaceHashQuery(cpSpaceHash *hash, void *obj, cpBB bb, cpSpatialIndexQueryCallb int r = floor_int(bb.r/dim); int b = floor_int(bb.b/dim); int t = floor_int(bb.t/dim); - + int n = hash->numcells; cpSpaceHashBin **table = hash->table; - + // Iterate over the cells and query them. for(int i=l; i<=r; i++){ for(int j=b; j<=t; j++){ query_helper(hash, &table[hash_func(i,j,n)], obj, func, data); } } - + hash->stamp++; } @@ -434,26 +434,26 @@ queryRehash_helper(cpHandle *hand, queryRehashContext *context) int r = floor_int(bb.r/dim); int b = floor_int(bb.b/dim); int t = floor_int(bb.t/dim); - + cpSpaceHashBin **table = hash->table; for(int i=l; i<=r; i++){ for(int j=b; j<=t; j++){ int idx = hash_func(i,j,n); cpSpaceHashBin *bin = table[idx]; - + if(containsHandle(bin, hand)) continue; - + cpHandleRetain(hand); // this MUST be done first in case the object is removed in func() query_helper(hash, &bin, obj, func, data); - + cpSpaceHashBin *newBin = getEmptyBin(hash); newBin->handle = hand; newBin->next = bin; table[idx] = newBin; } } - + // Increment the stamp for each object hashed. hash->stamp++; } @@ -462,10 +462,10 @@ static void cpSpaceHashReindexQuery(cpSpaceHash *hash, cpSpatialIndexQueryCallback func, void *data) { clearTable(hash); - + queryRehashContext context = {hash, func, data}; cpHashSetEach(hash->handleSet, (cpHashSetIterFunc)queryRehash_helper, &context); - + cpSpatialIndexCollideStatic((cpSpatialIndex *)hash, hash->spatialIndex.staticIndex, func, data); } @@ -473,12 +473,12 @@ static inline cpFloat segmentQuery_helper(cpSpaceHash *hash, cpSpaceHashBin **bin_ptr, void *obj, cpSpatialIndexSegmentQueryCallback func, void *data) { cpFloat t = 1.0f; - + restart: for(cpSpaceHashBin *bin = *bin_ptr; bin; bin = bin->next){ cpHandle *hand = bin->handle; void *other = hand->obj; - + // Skip over certain conditions if(hand->stamp == hash->stamp){ continue; @@ -492,7 +492,7 @@ segmentQuery_helper(cpSpaceHash *hash, cpSpaceHashBin **bin_ptr, void *obj, cpSp goto restart; // GCC not smart enough/able to tail call an inlined function. } } - + return t; } @@ -502,7 +502,7 @@ cpSpaceHashSegmentQuery(cpSpaceHash *hash, void *obj, cpVect a, cpVect b, cpFloa { a = cpvmult(a, 1.0f/hash->celldim); b = cpvmult(b, 1.0f/hash->celldim); - + int cell_x = floor_int(a.x), cell_y = floor_int(a.y); cpFloat t = 0; @@ -525,15 +525,15 @@ cpSpaceHashSegmentQuery(cpSpaceHash *hash, void *obj, cpVect a, cpVect b, cpFloa y_inc = -1; temp_v = (a.y - cpffloor(a.y)); } - + // Division by zero is *very* slow on ARM cpFloat dx = cpfabs(b.x - a.x), dy = cpfabs(b.y - a.y); cpFloat dt_dx = (dx ? 1.0f/dx : INFINITY), dt_dy = (dy ? 1.0f/dy : INFINITY); - + // fix NANs in horizontal directions cpFloat next_h = (temp_h ? temp_h*dt_dx : dt_dx); cpFloat next_v = (temp_v ? temp_v*dt_dy : dt_dy); - + int n = hash->numcells; cpSpaceHashBin **table = hash->table; @@ -551,7 +551,7 @@ cpSpaceHashSegmentQuery(cpSpaceHash *hash, void *obj, cpVect a, cpVect b, cpFloa next_h += dt_dx; } } - + hash->stamp++; } @@ -564,9 +564,9 @@ cpSpaceHashResize(cpSpaceHash *hash, cpFloat celldim, int numcells) cpAssertWarn(cpFalse, "Ignoring cpSpaceHashResize() call to non-cpSpaceHash spatial index."); return; } - + clearTable(hash); - + hash->celldim = celldim; cpSpaceHashAllocTable(hash, next_prime(numcells)); } @@ -585,18 +585,18 @@ cpSpaceHashContains(cpSpaceHash *hash, void *obj, cpHashValue hashid) static cpSpatialIndexClass klass = { (cpSpatialIndexDestroyFunc)cpSpaceHashDestroy, - + (cpSpatialIndexCountFunc)cpSpaceHashCount, (cpSpatialIndexEachFunc)cpSpaceHashEach, (cpSpatialIndexContainsFunc)cpSpaceHashContains, - + (cpSpatialIndexInsertFunc)cpSpaceHashInsert, (cpSpatialIndexRemoveFunc)cpSpaceHashRemove, - + (cpSpatialIndexReindexFunc)cpSpaceHashRehash, (cpSpatialIndexReindexObjectFunc)cpSpaceHashRehashObject, (cpSpatialIndexReindexQueryFunc)cpSpaceHashReindexQuery, - + (cpSpatialIndexPointQueryFunc)cpSpaceHashPointQuery, (cpSpatialIndexSegmentQueryFunc)cpSpaceHashSegmentQuery, (cpSpatialIndexQueryFunc)cpSpaceHashQuery, @@ -608,7 +608,7 @@ static cpSpatialIndexClass klass = { #ifdef CP_BBTREE_DEBUG_DRAW #include #include -#include +//#include void cpSpaceHashRenderDebug(cpSpatialIndex *index) @@ -617,26 +617,26 @@ cpSpaceHashRenderDebug(cpSpatialIndex *index) cpAssertWarn(cpFalse, "Ignoring cpSpaceHashRenderDebug() call to non-spatial hash spatial index."); return; } - + cpSpaceHash *hash = (cpSpaceHash *)index; cpBB bb = cpBBNew(-320, -240, 320, 240); - + cpFloat dim = hash->celldim; int n = hash->numcells; - + int l = (int)floor(bb.l/dim); int r = (int)floor(bb.r/dim); int b = (int)floor(bb.b/dim); int t = (int)floor(bb.t/dim); - + for(int i=l; i<=r; i++){ for(int j=b; j<=t; j++){ int cell_count = 0; - + int index = hash_func(i,j,n); for(cpSpaceHashBin *bin = hash->table[index]; bin; bin = bin->next) cell_count++; - + GLfloat v = 1.0f - (GLfloat)cell_count/10.0f; glColor3f(v,v,v); glRectf(i*dim, j*dim, (i + 1)*dim, (j + 1)*dim); diff --git a/src/physics/base.hpp b/src/physics/base.hpp index 55fb397ce..82202ff31 100644 --- a/src/physics/base.hpp +++ b/src/physics/base.hpp @@ -30,6 +30,7 @@ using namespace EE::Window; #include "../graphics/cprimitives.hpp" #include "../graphics/cbatchrenderer.hpp" #include "../graphics/cglobalbatchrenderer.hpp" +#include "../graphics/glhelper.hpp" #endif diff --git a/src/physics/constraints/cdampedspring.cpp b/src/physics/constraints/cdampedspring.cpp index 4fdc8a0c5..8b68ece28 100644 --- a/src/physics/constraints/cdampedspring.cpp +++ b/src/physics/constraints/cdampedspring.cpp @@ -65,23 +65,26 @@ void cDampedSpring::Draw() { cVect delta = b - a; glVertexPointer(2, GL_FLOAT, 0, springVAR); - glPushMatrix(); { - GLfloat x = a.x; - GLfloat y = a.y; - GLfloat cos = delta.x; - GLfloat sin = delta.y; - GLfloat s = 1.0f / cpvlength( tocpv( delta ) ); + GLi->PushMatrix(); - const GLfloat matrix[] = { - cos, sin, 0.0f, 0.0f, - -sin*s, cos*s, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - x, y, 0.0f, 1.0f, - }; + GLfloat x = a.x; + GLfloat y = a.y; + GLfloat cos = delta.x; + GLfloat sin = delta.y; + GLfloat s = 1.0f / cpvlength( tocpv( delta ) ); - glMultMatrixf(matrix); - glDrawArrays(GL_LINE_STRIP, 0, springVAR_count); - } glPopMatrix(); + const GLfloat matrix[] = { + cos, sin, 0.0f, 0.0f, + -sin*s, cos*s, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + x, y, 0.0f, 1.0f, + }; + + glMultMatrixf(matrix); + + glDrawArrays(GL_LINE_STRIP, 0, springVAR_count); + + GLi->PopMatrix(); #endif } diff --git a/src/physics/cshapesegment.cpp b/src/physics/cshapesegment.cpp index 38703d0c8..a9ae03a6c 100644 --- a/src/physics/cshapesegment.cpp +++ b/src/physics/cshapesegment.cpp @@ -60,7 +60,7 @@ void cShapeSegment::Draw( cSpace * space ) { glDisableClientState( GL_COLOR_ARRAY ); glVertexPointer(3, GL_FLOAT, 0, pillVAR); - glPushMatrix(); + GLi->PushMatrix(); cVect d = b - a; cVect r = d * ( seg->CP_PRIVATE(r) / cpvlength( tocpv( d ) ) ); @@ -84,7 +84,7 @@ void cShapeSegment::Draw( cSpace * space ) { glColor3f( 0.4f, 0.4f, 0.4f ); glDrawArrays( GL_LINE_LOOP, 0, pillVAR_count ); - glPopMatrix(); + GLi->PopMatrix(); glEnableClientState( GL_TEXTURE_COORD_ARRAY ); glEnableClientState( GL_COLOR_ARRAY ); diff --git a/src/test/ee.cpp b/src/test/ee.cpp index 6fe154cd6..e00a76685 100644 --- a/src/test/ee.cpp +++ b/src/test/ee.cpp @@ -1,10 +1,8 @@ #include "../ee.h" /** -@TODO Create a basic UI system ( add basic controls, add skinning support ). @TODO Add some Surface Grid class, to create special effects ( waved texture, and stuff like that ). @TODO Add Scripting support ( lua or squirrel ). -@TODO Add 2D physics support ( Box2D or Chipmunk wrapper ). @TODO Encapsulate SDL and OpenGL ( and remove unnecessary dependencies ). @TODO Support color cursors ( not only black and white cursors, that really sucks ) - Imposible with SDL 1.2 */ @@ -1369,7 +1367,7 @@ void cEETest::Render() { ColRR1, ColRR2, ColRR3, ColRR4 ); - mEEText.Draw( 0.f, (eeFloat)EE->GetHeight() - mEEText.GetTextHeight(), FONT_DRAW_CENTER ); + mEEText.Draw( 0.f, (eeFloat)EE->GetHeight() - mEEText.GetTextHeight(), FONT_DRAW_CENTER, 1.f, Ang ); mInfoText.Draw( 6.f, 6.f ); diff --git a/src/ui/base.hpp b/src/ui/base.hpp index 3f8c6fe42..4243f6245 100644 --- a/src/ui/base.hpp +++ b/src/ui/base.hpp @@ -28,6 +28,7 @@ using namespace EE::Window; #include "../graphics/csprite.hpp" #include "../graphics/cfont.hpp" #include "../graphics/cprimitives.hpp" +#include "../graphics/glhelper.hpp" using namespace EE::Graphics; #endif diff --git a/src/ui/cuicomplexcontrol.cpp b/src/ui/cuicomplexcontrol.cpp index 87c2f8bce..dfbc96fc1 100644 --- a/src/ui/cuicomplexcontrol.cpp +++ b/src/ui/cuicomplexcontrol.cpp @@ -17,7 +17,7 @@ cUIComplexControl::~cUIComplexControl() { } void cUIComplexControl::Update() { - if ( NULL != mTooltip && mTooltip->Text().size() ) { + if ( mVisible && NULL != mTooltip && mTooltip->Text().size() ) { if ( IsMouseOverMeOrChilds() ) { eeVector2i Pos = cUIManager::instance()->GetMousePos(); Pos.x += cUIThemeManager::instance()->CursorSize().x; diff --git a/src/ui/cuicontrolanim.cpp b/src/ui/cuicontrolanim.cpp index 584c3a6f3..ffddae61f 100644 --- a/src/ui/cuicontrolanim.cpp +++ b/src/ui/cuicontrolanim.cpp @@ -69,19 +69,19 @@ void cUIControlAnim::Alpha( const eeFloat& alpha ) { void cUIControlAnim::MatrixSet() { if ( mScale != 1.f || mAngle != 0.f ) { cGlobalBatchRenderer::instance()->Draw(); - glPushMatrix(); + GLi->PushMatrix(); eeVector2f Center( mScreenPos.x + mSize.Width() * 0.5f, mScreenPos.y + mSize.Height() * 0.5f ); - glTranslatef( Center.x , Center.y, 0.f ); - glRotatef( mAngle, 0.0f, 0.0f, 1.0f ); - glScalef( mScale, mScale, 1.0f ); - glTranslatef( -Center.x, -Center.y, 0.f ); + GLi->Translatef( Center.x , Center.y, 0.f ); + GLi->Rotatef( mAngle, 0.0f, 0.0f, 1.0f ); + GLi->Scalef( mScale, mScale, 1.0f ); + GLi->Translatef( -Center.x, -Center.y, 0.f ); } } void cUIControlAnim::MatrixUnset() { if ( mScale != 1.f || mAngle != 0.f ) { cGlobalBatchRenderer::instance()->Draw(); - glPopMatrix(); + GLi->PopMatrix(); } } diff --git a/src/ui/cuigridcell.cpp b/src/ui/cuigridcell.cpp index c9e94e563..dd8e68e2a 100644 --- a/src/ui/cuigridcell.cpp +++ b/src/ui/cuigridcell.cpp @@ -78,8 +78,9 @@ void cUIGridCell::Update() { } if ( IsMouseOverMeOrChilds() ) { - if ( Flags & EE_BUTTONS_WUWD && MyParent->VerticalScrollBar()->Visible() ) + if ( Flags & EE_BUTTONS_WUWD && MyParent->VerticalScrollBar()->Visible() ) { MyParent->VerticalScrollBar()->Slider()->ManageClick( Flags ); + } } } diff --git a/src/ui/cuilistboxitem.cpp b/src/ui/cuilistboxitem.cpp index 6ff03a008..3900dd21c 100644 --- a/src/ui/cuilistboxitem.cpp +++ b/src/ui/cuilistboxitem.cpp @@ -66,6 +66,8 @@ void cUIListBoxItem::Select() { } void cUIListBoxItem::Update() { + cUITextBox::Update(); + if ( mEnabled && mVisible ) { cUIListBox * LBParent = reinterpret_cast ( Parent()->Parent() ); Uint32 Flags = cUIManager::instance()->GetInput()->ClickTrigger(); @@ -74,12 +76,12 @@ void cUIListBoxItem::Update() { Alpha( LBParent->Alpha() ); if ( IsMouseOver() ) { - if ( Flags & EE_BUTTONS_WUWD && LBParent->VerticalScrollBar()->Visible() ) + if ( Flags & EE_BUTTONS_WUWD && LBParent->VerticalScrollBar()->Visible() ) { LBParent->VerticalScrollBar()->Slider()->ManageClick( Flags ); + //LBParent->UpdateScroll( true ); + } } } - - cUITextBox::Update(); } Uint32 cUIListBoxItem::OnMouseExit( const eeVector2i& Pos, const Uint32 Flags ) { diff --git a/src/window/cengine.cpp b/src/window/cengine.cpp index 430d2297c..1f77e040b 100755 --- a/src/window/cengine.cpp +++ b/src/window/cengine.cpp @@ -115,7 +115,7 @@ cEngine::~cEngine() { Audio::cAudioListener::DestroySingleton(); - Graphics::Private::cGL::DestroySingleton(); + Graphics::cGL::DestroySingleton(); cLog::DestroySingleton(); @@ -215,16 +215,16 @@ bool cEngine::Init(const Uint32& Width, const Uint32& Height, const Uint8& BitCo SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE , 8); } - cGL::instance()->Init(); + SetWindowCaption("EEPP"); GetMainContext(); mDefaultView.SetView( 0, 0, mVideoInfo.Width, mVideoInfo.Height ); mCurrentView = &mDefaultView; - Setup2D(); + cGL::instance()->Init(); - SetWindowCaption("EEPP"); + Setup2D(); cLog::instance()->Write( "Engine Initialized Succesfully.\nGL Vendor: " + GetVendor() + "\nGL Renderer: " + GetRenderer() + "\nGL Version: " + GetVersion() ); @@ -238,14 +238,14 @@ bool cEngine::Init(const Uint32& Width, const Uint32& Height, const Uint8& BitCo } void cEngine::SetViewport( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height ) { - glMatrixMode( GL_PROJECTION ); - glLoadIdentity(); + GLi->MatrixMode( GL_PROJECTION ); + GLi->LoadIdentity(); - glViewport( x, GetHeight() - Height - y, Width, Height ); - glOrtho( 0.0f, Width, Height, 0.0f, -1000.0f, 1000.0f ); + GLi->Viewport( x, GetHeight() - Height - y, Width, Height ); + GLi->Ortho( 0.0f, Width, Height, 0.0f, -1000.0f, 1000.0f ); - glMatrixMode( GL_MODELVIEW ); - glLoadIdentity(); + GLi->MatrixMode( GL_MODELVIEW ); + GLi->LoadIdentity(); } void cEngine::SetView( const cView& View ) {