Added a shader program manager.

This commit is contained in:
spartanj
2010-06-26 21:54:02 -03:00
parent f6c1ba01de
commit dc93fa9638
10 changed files with 713 additions and 70 deletions

225
EE.kdevelop Normal file
View File

@@ -0,0 +1,225 @@
<?xml version = '1.0'?>
<kdevelop>
<general>
<author>Martín Lucas Golini</author>
<email>spartanj@gmail.com</email>
<version>1</version>
<projectmanagement>KDevCustomProject</projectmanagement>
<primarylanguage>C++</primarylanguage>
<ignoreparts/>
<projectname>EE</projectname>
<projectdirectory>.</projectdirectory>
<absoluteprojectpath>false</absoluteprojectpath>
<description/>
<defaultencoding/>
<versioncontrol/>
</general>
<kdevcustomproject>
<run>
<directoryradio>executable</directoryradio>
<mainprogram>./eetest</mainprogram>
<programargs/>
<globaldebugarguments/>
<globalcwd>./</globalcwd>
<useglobalprogram>false</useglobalprogram>
<terminal>false</terminal>
<autocompile>true</autocompile>
<autoinstall>false</autoinstall>
<autokdesu>false</autokdesu>
<envvars/>
</run>
<filetypes>
<filetype>*.java</filetype>
<filetype>*.h</filetype>
<filetype>*.H</filetype>
<filetype>*.hh</filetype>
<filetype>*.hxx</filetype>
<filetype>*.hpp</filetype>
<filetype>*.c</filetype>
<filetype>*.C</filetype>
<filetype>*.cc</filetype>
<filetype>*.cpp</filetype>
<filetype>*.c++</filetype>
<filetype>*.cxx</filetype>
<filetype>Makefile</filetype>
<filetype>CMakeLists.txt</filetype>
</filetypes>
<blacklist/>
<build>
<buildtool>make</buildtool>
<builddir/>
</build>
<other>
<prio>0</prio>
<otherbin/>
<defaulttarget/>
<otheroptions/>
<selectedenvironment>default</selectedenvironment>
<environments>
<default/>
</environments>
</other>
<make>
<abortonerror>false</abortonerror>
<numberofjobs>4</numberofjobs>
<prio>0</prio>
<dontact>false</dontact>
<makebin/>
<defaulttarget/>
<makeoptions>test</makeoptions>
<selectedenvironment>default</selectedenvironment>
<environments>
<default/>
</environments>
</make>
</kdevcustomproject>
<kdevdebugger>
<general>
<dbgshell/>
<gdbpath/>
<configGdbScript/>
<runShellScript/>
<runGdbScript/>
<breakonloadinglibs>true</breakonloadinglibs>
<separatetty>false</separatetty>
<floatingtoolbar>false</floatingtoolbar>
<raiseGDBOnStart>false</raiseGDBOnStart>
</general>
<display>
<staticmembers>false</staticmembers>
<demanglenames>true</demanglenames>
<outputradix>10</outputradix>
</display>
</kdevdebugger>
<kdevdoctreeview>
<ignoretocs>
<toc>ada</toc>
<toc>ada_bugs_gcc</toc>
<toc>bash</toc>
<toc>bash_bugs</toc>
<toc>clanlib</toc>
<toc>fortran_bugs_gcc</toc>
<toc>gnome1</toc>
<toc>gnustep</toc>
<toc>gtk</toc>
<toc>gtk_bugs</toc>
<toc>haskell</toc>
<toc>haskell_bugs_ghc</toc>
<toc>java_bugs_gcc</toc>
<toc>java_bugs_sun</toc>
<toc>kde2book</toc>
<toc>opengl</toc>
<toc>pascal_bugs_fp</toc>
<toc>php</toc>
<toc>php_bugs</toc>
<toc>perl</toc>
<toc>perl_bugs</toc>
<toc>python</toc>
<toc>python_bugs</toc>
<toc>qt-kdev3</toc>
<toc>ruby</toc>
<toc>ruby_bugs</toc>
<toc>sdl</toc>
<toc>sw</toc>
<toc>w3c-dom-level2-html</toc>
<toc>w3c-svg</toc>
<toc>w3c-uaag10</toc>
<toc>wxwidgets_bugs</toc>
</ignoretocs>
<ignoreqt_xml>
<toc>Guide to the Qt Translation Tools</toc>
<toc>Qt Assistant Manual</toc>
<toc>Qt Designer Manual</toc>
<toc>Qt Reference Documentation</toc>
<toc>qmake User Guide</toc>
</ignoreqt_xml>
<ignoredoxygen>
<toc>KDE Libraries (Doxygen)</toc>
</ignoredoxygen>
</kdevdoctreeview>
<kdevfilecreate>
<filetypes/>
<useglobaltypes>
<type ext="ui" />
<type ext="cpp" />
<type ext="h" />
</useglobaltypes>
</kdevfilecreate>
<kdevcppsupport>
<qt>
<used>false</used>
<version>3</version>
<includestyle>3</includestyle>
<root>/usr/lib/qt3</root>
<designerintegration>EmbeddedKDevDesigner</designerintegration>
<qmake>/usr/lib/qt3/bin/qmake</qmake>
<designer>/usr/lib/qt3/bin/designer</designer>
<designerpluginpaths/>
</qt>
<codecompletion>
<automaticCodeCompletion>true</automaticCodeCompletion>
<automaticArgumentsHint>true</automaticArgumentsHint>
<automaticHeaderCompletion>true</automaticHeaderCompletion>
<codeCompletionDelay>0</codeCompletionDelay>
<argumentsHintDelay>200</argumentsHintDelay>
<headerCompletionDelay>250</headerCompletionDelay>
<showOnlyAccessibleItems>false</showOnlyAccessibleItems>
<completionBoxItemOrder>0</completionBoxItemOrder>
<howEvaluationContextMenu>true</howEvaluationContextMenu>
<showCommentWithArgumentHint>true</showCommentWithArgumentHint>
<statusBarTypeEvaluation>false</statusBarTypeEvaluation>
<namespaceAliases>std=_GLIBCXX_STD;__gnu_cxx=std</namespaceAliases>
<processPrimaryTypes>false</processPrimaryTypes>
<processFunctionArguments>false</processFunctionArguments>
<preProcessAllHeaders>true</preProcessAllHeaders>
<parseMissingHeadersExperimental>true</parseMissingHeadersExperimental>
<resolveIncludePathsUsingMakeExperimental>false</resolveIncludePathsUsingMakeExperimental>
<alwaysParseInBackground>true</alwaysParseInBackground>
<usePermanentCaching>true</usePermanentCaching>
<alwaysIncludeNamespaces>false</alwaysIncludeNamespaces>
<includePaths>.;</includePaths>
</codecompletion>
<creategettersetter>
<prefixGet/>
<prefixSet>set</prefixSet>
<prefixVariable>m_,_</prefixVariable>
<parameterName>theValue</parameterName>
<inlineGet>true</inlineGet>
<inlineSet>true</inlineSet>
</creategettersetter>
<splitheadersource>
<enabled>false</enabled>
<synchronize>true</synchronize>
<orientation>Vertical</orientation>
</splitheadersource>
<references>
<pcs>std</pcs>
<pcs>automatic_%2Fhome%2Fprogramacion%2FEE</pcs>
<pcs>automatic_%2Fhome%2Fdownloads%2Ffiles%2FEE</pcs>
<pcs>automatic_%2Fhome%2Fprogramming%2FProjects%2FEE</pcs>
</references>
</kdevcppsupport>
<cppsupportpart>
<filetemplates>
<interfacesuffix>.h</interfacesuffix>
<implementationsuffix>.cpp</implementationsuffix>
</filetemplates>
</cppsupportpart>
<kdevdocumentation>
<projectdoc>
<docsystem/>
<docurl/>
<usermanualurl/>
</projectdoc>
</kdevdocumentation>
<kdevfileview>
<groups>
<hidenonprojectfiles>false</hidenonprojectfiles>
<hidenonlocation>false</hidenonlocation>
</groups>
<tree>
<hidepatterns>*.o,*.lo,CVS</hidepatterns>
<hidenonprojectfiles>false</hidenonprojectfiles>
</tree>
</kdevfileview>
</kdevelop>

239
ee.linux.cbp Normal file
View File

@@ -0,0 +1,239 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="ee" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="eetest" prefix_auto="1" extension_auto="1" />
<Option object_output="." />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-pg" />
<Add option="-g" />
</Compiler>
<Linker>
<Add option="-pg" />
</Linker>
</Target>
<Target title="Release">
<Option output="eetest" prefix_auto="1" extension_auto="1" />
<Option object_output="." />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-march=core2" />
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Linker>
<Add library="GL" />
<Add library="GLU" />
<Add library="freetype" />
<Add library="sndfile" />
<Add library="X11" />
<Add library="SDL" />
<Add library="openal" />
</Linker>
<Unit filename="src/audio/base.hpp" />
<Unit filename="src/audio/caudiodevice.cpp" />
<Unit filename="src/audio/caudiodevice.hpp" />
<Unit filename="src/audio/caudiolistener.cpp" />
<Unit filename="src/audio/caudiolistener.hpp" />
<Unit filename="src/audio/caudioresource.cpp" />
<Unit filename="src/audio/caudioresource.hpp" />
<Unit filename="src/audio/cmusic.cpp" />
<Unit filename="src/audio/cmusic.hpp" />
<Unit filename="src/audio/csound.cpp" />
<Unit filename="src/audio/csound.hpp" />
<Unit filename="src/audio/csoundbuffer.cpp" />
<Unit filename="src/audio/csoundbuffer.hpp" />
<Unit filename="src/audio/csoundfile.cpp" />
<Unit filename="src/audio/csoundfile.hpp" />
<Unit filename="src/audio/csoundfiledefault.cpp" />
<Unit filename="src/audio/csoundfiledefault.hpp" />
<Unit filename="src/audio/csoundfileogg.cpp" />
<Unit filename="src/audio/csoundfileogg.hpp" />
<Unit filename="src/audio/csoundstream.cpp" />
<Unit filename="src/audio/csoundstream.hpp" />
<Unit filename="src/audio/openal.hpp" />
<Unit filename="src/audio/tsoundmanager.hpp" />
<Unit filename="src/base.hpp" />
<Unit filename="src/ee.h" />
<Unit filename="src/gaming/base.hpp" />
<Unit filename="src/gaming/cisomap.cpp" />
<Unit filename="src/gaming/cisomap.hpp" />
<Unit filename="src/gaming/clight.cpp" />
<Unit filename="src/gaming/clight.hpp" />
<Unit filename="src/graphics/base.hpp" />
<Unit filename="src/graphics/cbatchrenderer.cpp" />
<Unit filename="src/graphics/cbatchrenderer.hpp" />
<Unit filename="src/graphics/cconsole.cpp" />
<Unit filename="src/graphics/cconsole.hpp" />
<Unit filename="src/graphics/cfont.cpp" />
<Unit filename="src/graphics/cfont.hpp" />
<Unit filename="src/graphics/cglobalbatchrenderer.cpp" />
<Unit filename="src/graphics/cglobalbatchrenderer.hpp" />
<Unit filename="src/graphics/cparticle.cpp" />
<Unit filename="src/graphics/cparticle.hpp" />
<Unit filename="src/graphics/cparticlesystem.cpp" />
<Unit filename="src/graphics/cparticlesystem.hpp" />
<Unit filename="src/graphics/cprimitives.cpp" />
<Unit filename="src/graphics/cprimitives.hpp" />
<Unit filename="src/graphics/cscrollparallax.cpp" />
<Unit filename="src/graphics/cscrollparallax.hpp" />
<Unit filename="src/graphics/cshader.cpp" />
<Unit filename="src/graphics/cshader.hpp" />
<Unit filename="src/graphics/cshaderprogram.cpp" />
<Unit filename="src/graphics/cshaderprogram.hpp" />
<Unit filename="src/graphics/cshaderprogrammanager.cpp" />
<Unit filename="src/graphics/cshaderprogrammanager.hpp" />
<Unit filename="src/graphics/cshape.cpp" />
<Unit filename="src/graphics/cshape.hpp" />
<Unit filename="src/graphics/cshapemanager.cpp" />
<Unit filename="src/graphics/cshapemanager.hpp" />
<Unit filename="src/graphics/csprite.cpp" />
<Unit filename="src/graphics/csprite.hpp" />
<Unit filename="src/graphics/ctextcache.cpp" />
<Unit filename="src/graphics/ctextcache.hpp" />
<Unit filename="src/graphics/ctexture.cpp" />
<Unit filename="src/graphics/ctexture.hpp" />
<Unit filename="src/graphics/ctexturefactory.cpp" />
<Unit filename="src/graphics/ctexturefactory.hpp" />
<Unit filename="src/graphics/ctexturefont.cpp" />
<Unit filename="src/graphics/ctexturefont.hpp" />
<Unit filename="src/graphics/cttffont.cpp" />
<Unit filename="src/graphics/cttffont.hpp" />
<Unit filename="src/graphics/fonthelper.hpp" />
<Unit filename="src/graphics/pixelperfect.cpp" />
<Unit filename="src/graphics/pixelperfect.hpp" />
<Unit filename="src/graphics/renders.hpp" />
<Unit filename="src/helper/SDL_ttf/SDL_ttf.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="src/helper/SDL_ttf/SDL_ttf.h" />
<Unit filename="src/helper/SOIL/SOIL.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="src/helper/SOIL/SOIL.h" />
<Unit filename="src/helper/SOIL/image_DXT.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="src/helper/SOIL/image_DXT.h" />
<Unit filename="src/helper/SOIL/image_helper.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="src/helper/SOIL/image_helper.h" />
<Unit filename="src/helper/SOIL/stb_image_aug.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="src/helper/SOIL/stb_image_aug.h" />
<Unit filename="src/helper/SOIL/stbi_DDS_aug.h" />
<Unit filename="src/helper/SOIL/stbi_DDS_aug_c.h" />
<Unit filename="src/helper/fastevents/fastevents.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="src/helper/fastevents/fastevents.h" />
<Unit filename="src/helper/glew/glew.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="src/helper/glew/glew.h" />
<Unit filename="src/helper/glew/glxew.h" />
<Unit filename="src/helper/glew/wglew.h" />
<Unit filename="src/helper/stb_vorbis/stb_vorbis.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="src/helper/stb_vorbis/stb_vorbis.h" />
<Unit filename="src/math/base.hpp" />
<Unit filename="src/math/math.cpp" />
<Unit filename="src/math/math.hpp" />
<Unit filename="src/system/base.hpp" />
<Unit filename="src/system/cinifile.cpp" />
<Unit filename="src/system/cinifile.hpp" />
<Unit filename="src/system/clog.cpp" />
<Unit filename="src/system/clog.hpp" />
<Unit filename="src/system/cmutex.cpp" />
<Unit filename="src/system/cmutex.hpp" />
<Unit filename="src/system/cpack.cpp" />
<Unit filename="src/system/cpack.hpp" />
<Unit filename="src/system/cpak.cpp" />
<Unit filename="src/system/cpak.hpp" />
<Unit filename="src/system/crc4.cpp" />
<Unit filename="src/system/crc4.hpp" />
<Unit filename="src/system/cthread.cpp" />
<Unit filename="src/system/cthread.hpp" />
<Unit filename="src/system/ctimeelapsed.cpp" />
<Unit filename="src/system/ctimeelapsed.hpp" />
<Unit filename="src/system/ctimer.cpp" />
<Unit filename="src/system/ctimer.hpp" />
<Unit filename="src/system/singleton.hpp" />
<Unit filename="src/test/ee.cpp" />
<Unit filename="src/ui/base.hpp" />
<Unit filename="src/ui/cuicontrol.cpp" />
<Unit filename="src/ui/cuicontrol.hpp" />
<Unit filename="src/ui/cuicontrolanim.cpp" />
<Unit filename="src/ui/cuicontrolanim.hpp" />
<Unit filename="src/ui/cuidragable.cpp" />
<Unit filename="src/ui/cuidragable.hpp" />
<Unit filename="src/ui/cuievent.cpp" />
<Unit filename="src/ui/cuievent.hpp" />
<Unit filename="src/ui/cuieventkey.cpp" />
<Unit filename="src/ui/cuieventkey.hpp" />
<Unit filename="src/ui/cuigfx.cpp" />
<Unit filename="src/ui/cuigfx.hpp" />
<Unit filename="src/ui/cuimanager.cpp" />
<Unit filename="src/ui/cuimanager.hpp" />
<Unit filename="src/ui/cuimessage.cpp" />
<Unit filename="src/ui/cuimessage.hpp" />
<Unit filename="src/ui/cuitextbox.cpp" />
<Unit filename="src/ui/cuitextbox.hpp" />
<Unit filename="src/ui/cuitextinput.cpp" />
<Unit filename="src/ui/cuitextinput.hpp" />
<Unit filename="src/ui/uihelper.cpp" />
<Unit filename="src/ui/uihelper.hpp" />
<Unit filename="src/utils/base.hpp" />
<Unit filename="src/utils/cinterpolation.cpp" />
<Unit filename="src/utils/cinterpolation.hpp" />
<Unit filename="src/utils/colors.hpp" />
<Unit filename="src/utils/cperlinnoise.cpp" />
<Unit filename="src/utils/cperlinnoise.hpp" />
<Unit filename="src/utils/cwaypoints.cpp" />
<Unit filename="src/utils/cwaypoints.hpp" />
<Unit filename="src/utils/easing.cpp" />
<Unit filename="src/utils/easing.hpp" />
<Unit filename="src/utils/helper.hpp" />
<Unit filename="src/utils/polygon2.hpp" />
<Unit filename="src/utils/rect.hpp" />
<Unit filename="src/utils/string.cpp" />
<Unit filename="src/utils/string.hpp" />
<Unit filename="src/utils/utils.cpp" />
<Unit filename="src/utils/utils.hpp" />
<Unit filename="src/utils/vector2.hpp" />
<Unit filename="src/utils/vector3.hpp" />
<Unit filename="src/window/base.hpp" />
<Unit filename="src/window/cengine.cpp" />
<Unit filename="src/window/cengine.hpp" />
<Unit filename="src/window/cinput.cpp" />
<Unit filename="src/window/cinput.hpp" />
<Unit filename="src/window/cinputtextbuffer.cpp" />
<Unit filename="src/window/cinputtextbuffer.hpp" />
<Unit filename="src/window/cview.cpp" />
<Unit filename="src/window/cview.hpp" />
<Extensions>
<envvars />
<code_completion />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@@ -97,6 +97,7 @@
#ifdef EE_SHADERS
#include "graphics/cshader.hpp"
#include "graphics/cshaderprogram.hpp"
#include "graphics/cshaderprogrammanager.hpp"
#endif
using namespace EE::Graphics;

View File

@@ -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<cShader*>& Shaders ) {
cShaderProgram::cShaderProgram( const std::vector<cShader*>& Shaders, const std::string& name ) :
mGLId(0)
{
AddToManager( name );
Init();
AddShaders( Shaders );
@@ -17,8 +24,10 @@ cShaderProgram::cShaderProgram( const std::vector<cShader*>& 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<cShader*> 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<cShader*>& 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 ) );
}
}
}}

View File

@@ -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<cShader*>& Shaders );
cShaderProgram( const std::vector<cShader*>& 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<cShader*>& 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<cShader*> mShaders;
std::map<std::string, Int32> mUniformLocations;
std::map<std::string, Int32> mAttributeLocations;
void Init();
void AddToManager( const std::string& name );
void RemoveFromManager();
};
}}

View File

@@ -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<std::string, cShaderProgram*>::iterator it = mShaders.find( Name );
if ( mShaders.end() != it ) {
return it->second;
}
return NULL;
}
cShaderProgram * cShaderProgramManager::GetById( Uint32 id ) {
std::map<std::string, cShaderProgram*>::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<std::string, cShaderProgram*>::iterator it;
for ( it = mShaders.begin(); it != mShaders.end(); it++ ) {
cShaderProgram * sp = reinterpret_cast< cShaderProgram* > ( it->second );
sp->Reload();
}
}
}}

View File

@@ -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<cShaderProgramManager> {
friend class cSingleton<cShaderProgramManager>;
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<std::string, cShaderProgram*> mShaders;
};
}}
#endif

View File

@@ -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);

View File

@@ -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<std::string> GetFilesInPath( const std::string& path ) {
std::vector<std::string> 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<std::string> 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<std::string> 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;
}

View File

@@ -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<Int32>( Tex->Width() );
Int32 H = static_cast<Int32>( 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;
}