diff --git a/EE.kdevelop b/EE.kdevelop new file mode 100644 index 000000000..0c4a10a00 --- /dev/null +++ b/EE.kdevelop @@ -0,0 +1,225 @@ + + + + Martín Lucas Golini + spartanj@gmail.com + 1 + KDevCustomProject + C++ + + EE + . + false + + + + + + + executable + ./eetest + + + ./ + false + false + true + false + false + + + + *.java + *.h + *.H + *.hh + *.hxx + *.hpp + *.c + *.C + *.cc + *.cpp + *.c++ + *.cxx + Makefile + CMakeLists.txt + + + + make + + + + 0 + + + + default + + + + + + false + 4 + 0 + false + + + test + default + + + + + + + + + + + + + true + false + false + false + + + false + true + 10 + + + + + ada + ada_bugs_gcc + bash + bash_bugs + clanlib + fortran_bugs_gcc + gnome1 + gnustep + gtk + gtk_bugs + haskell + haskell_bugs_ghc + java_bugs_gcc + java_bugs_sun + kde2book + opengl + pascal_bugs_fp + php + php_bugs + perl + perl_bugs + python + python_bugs + qt-kdev3 + ruby + ruby_bugs + sdl + sw + w3c-dom-level2-html + w3c-svg + w3c-uaag10 + wxwidgets_bugs + + + Guide to the Qt Translation Tools + Qt Assistant Manual + Qt Designer Manual + Qt Reference Documentation + qmake User Guide + + + KDE Libraries (Doxygen) + + + + + + + + + + + + + false + 3 + 3 + /usr/lib/qt3 + EmbeddedKDevDesigner + /usr/lib/qt3/bin/qmake + /usr/lib/qt3/bin/designer + + + + true + true + true + 0 + 200 + 250 + false + 0 + true + true + false + std=_GLIBCXX_STD;__gnu_cxx=std + false + false + true + true + false + true + true + false + .; + + + + set + m_,_ + theValue + true + true + + + false + true + Vertical + + + std + automatic_%2Fhome%2Fprogramacion%2FEE + automatic_%2Fhome%2Fdownloads%2Ffiles%2FEE + automatic_%2Fhome%2Fprogramming%2FProjects%2FEE + + + + + .h + .cpp + + + + + + + + + + + + false + false + + + *.o,*.lo,CVS + false + + + diff --git a/ee.linux.cbp b/ee.linux.cbp new file mode 100644 index 000000000..e18b9f3ad --- /dev/null +++ b/ee.linux.cbp @@ -0,0 +1,239 @@ + + + + + + diff --git a/src/ee.h b/src/ee.h index b89eb3f2b..b083c7272 100755 --- a/src/ee.h +++ b/src/ee.h @@ -97,6 +97,7 @@ #ifdef EE_SHADERS #include "graphics/cshader.hpp" #include "graphics/cshaderprogram.hpp" + #include "graphics/cshaderprogrammanager.hpp" #endif using namespace EE::Graphics; diff --git a/src/graphics/cshaderprogram.cpp b/src/graphics/cshaderprogram.cpp index 20d77fb3c..1bf1e177e 100644 --- a/src/graphics/cshaderprogram.cpp +++ b/src/graphics/cshaderprogram.cpp @@ -1,15 +1,22 @@ #include "cshaderprogram.hpp" #include "../window/cengine.hpp" +#include "cshaderprogrammanager.hpp" using namespace EE::Window; namespace EE { namespace Graphics { -cShaderProgram::cShaderProgram() { +cShaderProgram::cShaderProgram( const std::string& name ) : + mGLId(0) +{ + AddToManager( name ); Init(); } -cShaderProgram::cShaderProgram( const std::vector& Shaders ) { +cShaderProgram::cShaderProgram( const std::vector& Shaders, const std::string& name ) : + mGLId(0) +{ + AddToManager( name ); Init(); AddShaders( Shaders ); @@ -17,8 +24,10 @@ cShaderProgram::cShaderProgram( const std::vector& Shaders ) { Link(); } - -cShaderProgram::cShaderProgram( const std::string& VertexShaderFile, const std::string& FragmentShaderFile ) { +cShaderProgram::cShaderProgram( const std::string& VertexShaderFile, const std::string& FragmentShaderFile, const std::string& name ) : + mGLId(0) +{ + AddToManager( name ); Init(); cVertexShader vs( VertexShaderFile ); @@ -39,10 +48,22 @@ cShaderProgram::~cShaderProgram() { mUniformLocations.clear(); mAttributeLocations.clear(); + + RemoveFromManager(); +} + +void cShaderProgram::AddToManager( const std::string& name ) { + Name( name ); + + cShaderProgramManager::Instance()->Add( this ); +} + +void cShaderProgram::RemoveFromManager() { + cShaderProgramManager::Instance()->Remove( this ); } void cShaderProgram::Init() { - if ( cEngine::instance()->ShadersSupported() ) { + if ( cEngine::instance()->ShadersSupported() && 0 == GetId() ) { mGLId = glCreateProgram(); mValid = false; mUniformLocations.clear(); @@ -50,12 +71,32 @@ void cShaderProgram::Init() { } } +void cShaderProgram::Reload() { + mGLId = 0; + + Init(); + + std::vector tmpShader = mShaders; + + mShaders.clear(); + + for ( eeUint i = 0; i < tmpShader.size(); i++ ) + AddShader( tmpShader[i] ); + + Link(); +} + void cShaderProgram::AddShader( cShader* Shader ) { if ( !Shader->IsValid() ) { cLog::instance()->Write( "cShaderProgram::AddShader(): Cannot add invalid shader" ); return; } - glAttachShader( GetId(), Shader->GetId() ); + + if ( 0 != GetId() ) { + glAttachShader( GetId(), Shader->GetId() ); + + mShaders.push_back( Shader ); + } } void cShaderProgram::AddShaders( const std::vector& Shaders ) { @@ -82,6 +123,7 @@ bool cShaderProgram::Link() { mUniformLocations.clear(); mAttributeLocations.clear(); } + return mValid; } @@ -158,4 +200,18 @@ bool cShaderProgram::SetUniform( const std::string& Name, Int32 Value ) { return ( Location >= 0 ); } +const std::string& cShaderProgram::Name() const { + return mName; +} + +void cShaderProgram::Name( const std::string& name ) { + mName = name; + + Uint32 NameCount = cShaderProgramManager::instance()->ExistsName( mName ); + + if ( 0 != NameCount || 0 == name.size() ) { + Name( name + intToStr( NameCount + 1 ) ); + } +} + }} diff --git a/src/graphics/cshaderprogram.hpp b/src/graphics/cshaderprogram.hpp index ff6d0f762..127561ae4 100644 --- a/src/graphics/cshaderprogram.hpp +++ b/src/graphics/cshaderprogram.hpp @@ -12,71 +12,86 @@ namespace EE { namespace Graphics { */ class EE_API cShaderProgram { public: - cShaderProgram(); - + cShaderProgram( const std::string& name = "" ); + /** Construct a program shader with a vector of shaders and link them. */ - cShaderProgram( const std::vector& Shaders ); - + cShaderProgram( const std::vector& Shaders, const std::string& name = "" ); + /** Constructor that creates a VertexShader from file and a Fragment Shader from file, and Link them. */ - cShaderProgram( const std::string& VertexShaderFile, const std::string& FragmentShaderFile ); - + cShaderProgram( const std::string& VertexShaderFile, const std::string& FragmentShaderFile, const std::string& name = "" ); + virtual ~cShaderProgram(); - + /** Add a new shader */ void AddShader( cShader* Shader ); - + /** Add a vector of shaders */ void AddShaders( const std::vector& Shaders ); - + virtual bool Link(); - + /** @return If the shader program is valid */ bool IsValid() const { return mValid; } - + /** @return THe link log */ std::string GetLinkLog() const { return mLinkLog; } - + /** Binds the shader program so that it will be used for anything that is rendered */ virtual void Bind() const; - + /** Unbind the program. Anything rendered after Unbind() call will be rendered using the fixed-function pipeline */ virtual void Unbind() const; - + /** @return The location of the location name */ Int32 UniformLocation( const std::string& Name ); - + /** @return The location of the attribute name */ Int32 AttributeLocation( const std::string& Name ); - + /** Clear the locations */ void InvalidateLocations(); - + /** Sets the uniform with the given name to the given value and returns true. * If there is no uniform with such name then false is returned. * Note that the program has to be bound before this method can be used. */ bool SetUniform( const std::string& Name, eeFloat Value ); - + /** @overload */ bool SetUniform( const std::string& Name, eeVector2f Value ); - + /** @overload */ bool SetUniform( const std::string& Name, eeVector3f Value ); - + /** @overload */ bool SetUniform( const std::string& Name, Int32 Value ); - + /** @return The id of the program (the handle) */ Uint32 GetId() const { return mGLId; } + + /** Reloads the shaders */ + void Reload(); + + /** @return Name of the shader program */ + const std::string& Name() const; + + /** Set the name of the shader program */ + void Name( const std::string& name ); protected: + std::string mName; Uint32 mGLId; bool mValid; std::string mLinkLog; - + + std::vector mShaders; std::map mUniformLocations; std::map mAttributeLocations; - + void Init(); + + void AddToManager( const std::string& name ); + + void RemoveFromManager(); }; }} diff --git a/src/graphics/cshaderprogrammanager.cpp b/src/graphics/cshaderprogrammanager.cpp new file mode 100644 index 000000000..f8af87b19 --- /dev/null +++ b/src/graphics/cshaderprogrammanager.cpp @@ -0,0 +1,70 @@ +#include "cshaderprogrammanager.hpp" + +namespace EE { namespace Graphics { + +cShaderProgramManager::cShaderProgramManager() +{ +} + +cShaderProgramManager::~cShaderProgramManager() +{ +} + +void cShaderProgramManager::Add( cShaderProgram * ShaderProgram ) { + Uint32 c = mShaders.count( ShaderProgram->Name() ); + + if ( 0 == c ) { + mShaders[ ShaderProgram->Name() ] = ShaderProgram; + } else { + ShaderProgram->Name( ShaderProgram->Name() + intToStr( c + 1 ) ); + + Add( ShaderProgram ); + } +} + +void cShaderProgramManager::Remove( cShaderProgram * ShaderProgram ) { + mShaders.erase( ShaderProgram->Name() ); +} + +Uint32 cShaderProgramManager::ExistsName( const std::string& name ) { + return mShaders.count( name ); +} + +cShaderProgram * cShaderProgramManager::GetByName( const std::string& Name ) { + std::map::iterator it = mShaders.find( Name ); + + if ( mShaders.end() != it ) { + return it->second; + } + + return NULL; +} + +cShaderProgram * cShaderProgramManager::GetById( Uint32 id ) { + std::map::iterator it; + + for ( it = mShaders.begin(); it != mShaders.end(); it++ ) { + cShaderProgram * sp = reinterpret_cast< cShaderProgram* > ( it->second ); + + if ( id == sp->GetId() ) + return sp; + } + + return NULL; +} + +eeUint cShaderProgramManager::Count() { + return mShaders.size(); +} + +void cShaderProgramManager::Reload() { + std::map::iterator it; + + for ( it = mShaders.begin(); it != mShaders.end(); it++ ) { + cShaderProgram * sp = reinterpret_cast< cShaderProgram* > ( it->second ); + + sp->Reload(); + } +} + +}} diff --git a/src/graphics/cshaderprogrammanager.hpp b/src/graphics/cshaderprogrammanager.hpp new file mode 100644 index 000000000..ecfca5f73 --- /dev/null +++ b/src/graphics/cshaderprogrammanager.hpp @@ -0,0 +1,35 @@ +#ifndef EE_GRAPHICSSHADERPROGRAMANAGER_HPP +#define EE_GRAPHICSSHADERPROGRAMANAGER_HPP + +#include "base.hpp" +#include "cshaderprogram.hpp" + +namespace EE { namespace Graphics { + +class EE_API cShaderProgramManager : public cSingleton { + friend class cSingleton; + public: + cShaderProgramManager(); + + virtual ~cShaderProgramManager(); + + void Add( cShaderProgram * ShaderProgram ); + + void Remove( cShaderProgram * ShaderProgram ); + + cShaderProgram * GetByName( const std::string& Name ); + + cShaderProgram * GetById( Uint32 id ); + + eeUint Count(); + + void Reload(); + + Uint32 ExistsName( const std::string& name ); + protected: + std::map mShaders; +}; + +}} + +#endif diff --git a/src/test/ee.cpp b/src/test/ee.cpp index d7995bec0..31cce07fc 100644 --- a/src/test/ee.cpp +++ b/src/test/ee.cpp @@ -1,7 +1,6 @@ #include "../ee.h" /** -@TODO Add a Shader Manager. @TODO Create a basic UI system. @TODO Add some Surface Grid class, to create special effects. ( waved texture, and stuff like that ) @TODO Add a generic Pak class (done), and add a cZip class for handling zip files (pending). @@ -172,7 +171,7 @@ void cEETest::Init() { cIniFile Ini( MyPath + "data/ee.ini" ); Ini.ReadFile(); - + mWidth = Ini.GetValueI( "EEPP", "Width", 800 ); mHeight = Ini.GetValueI( "EEPP", "Height", 600 ); int BitColor = Ini.GetValueI( "EEPP", "BitColor", 32); diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 9e7011621..826ddb6b6 100755 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -41,10 +41,10 @@ bool FileExists(const std::string& filepath) { } Uint32 eeGetTicks() { - return SDL_GetTicks(); + return SDL_GetTicks(); } -void eeSleep( const Uint32& ms ) { +void eeSleep( const Uint32& ms ) { SDL_Delay(ms); } @@ -83,7 +83,7 @@ std::string AppPath() { char szFilename[_MAX_DIR]; char szExt[_MAX_DIR]; std::wstring dllName( _MAX_DIR, 0 ); - + GetModuleFileName(0, &dllName[0], _MAX_PATH); std::string dllstrName( wstringTostring( dllName ) ); @@ -119,7 +119,7 @@ std::vector GetFilesInPath( const std::string& path ) { std::vector files; #ifdef EE_COMPILER_MSVC - #ifdef UNICODE + #ifdef UNICODE std::wstring mPath( stringTowstring( path ) ); if ( mPath[ mPath.size() - 1 ] == L'/' || mPath[ mPath.size() - 1 ] == L'\\' ) { @@ -130,16 +130,16 @@ std::vector GetFilesInPath( const std::string& path ) { WIN32_FIND_DATA findFileData; HANDLE hFind = FindFirstFile( mPath.c_str(), &findFileData ); - + if( hFind != INVALID_HANDLE_VALUE ) { std::wstring tmpstr( findFileData.cFileName ); if ( tmpstr != L"." && tmpstr != L".." ) files.push_back( wstringTostring( tmpstr ) ); - + while( FindNextFile(hFind, &findFileData ) ) { tmpstr = std::wstring( findFileData.cFileName ); - + if ( tmpstr != L"." && tmpstr != L".." ) files.push_back( std::string( wstringTostring( findFileData.cFileName ) ) ); } @@ -157,16 +157,16 @@ std::vector GetFilesInPath( const std::string& path ) { WIN32_FIND_DATA findFileData; HANDLE hFind = FindFirstFile( (LPCTSTR) mPath.c_str(), &findFileData ); - + if( hFind != INVALID_HANDLE_VALUE ) { std::string tmpstr( findFileData.cFileName ); if ( tmpstr != "." && tmpstr != ".." ) files.push_back( tmpstr ); - + while( FindNextFile(hFind, &findFileData ) ) { tmpstr = std::string( findFileData.cFileName ); - + if ( tmpstr != "." && tmpstr != ".." ) files.push_back( std::string( findFileData.cFileName ) ); } @@ -276,13 +276,13 @@ Uint32 MakeHash( const std::string& str ) { Uint32 MakeHash( const Int8* str ) { Uint32 hash = 5381 + *str; - + while( *str ) { hash = *str + ( hash << 6 ) + ( hash << 16 ) - hash; str++; } hash += *( str - 1 ); - + return hash; } diff --git a/src/window/cengine.cpp b/src/window/cengine.cpp index 3b726b977..b953e13c0 100755 --- a/src/window/cengine.cpp +++ b/src/window/cengine.cpp @@ -2,6 +2,7 @@ #include "cinput.hpp" #include "../graphics/ctexturefactory.hpp" #include "../graphics/cglobalbatchrenderer.hpp" +#include "../graphics/cshaderprogrammanager.hpp" #include "../ui/cuimanager.hpp" using namespace EE::Graphics; @@ -75,10 +76,10 @@ cEngine::~cEngine() { if ( mCursor != NULL ) { SDL_FreeCursor(mCursor); } - + cGlobalBatchRenderer::DestroySingleton(); cTextureFactory::DestroySingleton(); - + cInput::DestroySingleton(); SDL_Quit(); cLog::DestroySingleton(); @@ -148,7 +149,7 @@ bool cEngine::Init(const Uint32& Width, const Uint32& Height, const Uint8& BitCo mInitialWidth = mVideoInfo.Width; mInitialHeight = mVideoInfo.Height; - + mVideoInfo.WWidth = mVideoInfo.Width; mVideoInfo.WHeight = mVideoInfo.Height; @@ -187,22 +188,22 @@ bool cEngine::Init(const Uint32& Width, const Uint32& Height, const Uint8& BitCo mOldWinPos = GetWindowPosition(); mVideoInfo.SupARB_point = ( GetExtension("GL_ARB_point_parameters") && GetExtension("GL_ARB_point_sprite") ); - + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - + mDefaultView.SetView( 0, 0, mVideoInfo.Width, mVideoInfo.Height ); mCurrentView = &mDefaultView; - + ResetGL2D(); - + #ifdef EE_SHADERS mVideoInfo.SupShaders = GetExtension("GL_ARB_shading_language_100") && GetExtension("GL_ARB_shader_objects") && GetExtension("GL_ARB_vertex_shader") && GetExtension("GL_ARB_fragment_shader"); - + if ( mVideoInfo.SupShaders ) { glewInit(); } #endif - + SetWindowCaption("EEPP"); cLog::Instance()->Write( "Engine Initialized Succesfully.\nGL Vendor: " + GetVendor() + "\nGL Renderer: " + GetRenderer() + "\nGL Version: " + GetVersion() ); @@ -227,7 +228,7 @@ void cEngine::SetViewport( const Int32& x, const Int32& y, const Uint32& Width, void cEngine::SetView( const cView& View ) { mCurrentView = &View; - + eeRecti RView = mCurrentView->GetView(); SetViewport( RView.Left, RView.Top, RView.Right, RView.Bottom ); } @@ -243,24 +244,24 @@ const cView& cEngine::GetView() const { void cEngine::ResetGL2D() { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ALIGNMENT, 1); - + SetBackColor( mBackColor ); - + glShadeModel( GL_SMOOTH ); SetLineSmooth( mVideoInfo.LineSmooth ); - + glEnable( GL_TEXTURE_2D ); // Enable Textures - + SetView( mDefaultView ); - + glDisable( GL_DEPTH_TEST ); glDisable( GL_LIGHTING ); - + cTextureFactory::instance()->SetBlendFunc( ALPHA_BLENDONE ); // This is to fix a little bug on windows when the resolution change. I don't know why it happens, but this line fix it. cTextureFactory::instance()->SetBlendFunc( ALPHA_NORMAL ); - + glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - + glEnableClientState( GL_VERTEX_ARRAY ); glEnableClientState( GL_TEXTURE_COORD_ARRAY ); glEnableClientState( GL_COLOR_ARRAY ); @@ -298,10 +299,10 @@ void cEngine::LimitFps() { void cEngine::Display() { cGlobalBatchRenderer::instance()->Draw(); - + if ( mCurrentView->NeedUpdate() ) SetView( *mCurrentView ); - + glFlush(); SDL_GL_SwapBuffers(); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); @@ -332,7 +333,7 @@ void cEngine::ChangeRes( const Uint16& width, const Uint16& height, const bool& } mDefaultView.SetView( 0, 0, mVideoInfo.Width, mVideoInfo.Height ); - + SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); // Depth SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, (mVideoInfo.DoubleBuffering ? 1 : 0) ); SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, (mVideoInfo.VSync ? 1 : 0) ); // VSync @@ -343,12 +344,14 @@ void cEngine::ChangeRes( const Uint16& width, const Uint16& height, const bool& mVideoInfo.Screen = SDL_SetVideoMode( mVideoInfo.Width, mVideoInfo.Height, mVideoInfo.ColorDepth, mVideoInfo.Flags | SDL_FULLSCREEN ); ResetGL2D(); - + #if EE_PLATFORM == EE_PLATFORM_WIN32 || EE_PLATFORM == EE_PLATFORM_APPLE - if ( Reload ) + if ( Reload ) { cTextureFactory::instance()->ReloadAllTextures(); + cShaderProgramManager::instance()->Reload(); + } #endif - + if ( UI::cUIManager::Instance() != NULL ) UI::cUIManager::instance()->ResizeControl(); @@ -595,7 +598,7 @@ void cEngine::SetCursor( const Uint32& TexId, const eeVector2i& HotSpot ) { bool cEngine::SetIcon( const Uint32& FromTexId ) { cTexture* Tex = cTextureFactory::instance()->GetTexture( FromTexId ); - + if ( Tex ) { Int32 W = static_cast( Tex->Width() ); Int32 H = static_cast( Tex->Height() ); @@ -932,7 +935,7 @@ std::string cEngine::GetClipboardText() { if ( scrap ) eeSAFE_DELETE_ARRAY( scrap ); - + return tStr; } @@ -963,7 +966,7 @@ std::wstring cEngine::GetClipboardTextWStr() { if ( scrap ) eeSAFE_DELETE_ARRAY( scrap ); - + return tStr; }