gpucalc::GLGLSLShaderSystem Class Reference

#include <gl_glsl_shader_system.h>

Inheritance diagram for gpucalc::GLGLSLShaderSystem:

Inheritance graph

List of all members.

Public Member Functions

void addAcceptableGraphicCoreID (const std::string &GraphicCoreID)
 Method for manual adding acceptable GraphicCore ID.
void bind (Shader *shader)
Uniformcreate (Texture *texture)
 Creates Uniform from texture.
Uniformcreate (const Data &data)
 creates Uniform variable.
Shadercreate (const std::string &ShaderName)
 Creates Shader object.
void destroy (Uniform *uniform)
 Deletes given Uniform.
void destroy (Shader *shader)
 Deletes Shader object.
ShadergetActiveShader () const
const std::string & getClassName () const
 Returns name of class of our object.
debugger::CodeInstructorgetCodeInstructor () const
 Returns CodeInstructor - special object, which allows to instruct shader with debugging symbols.
const std::string & getObjectName () const
 Returns name of our object.
ShadergetShaderByName (const std::string &Shadername) const
void getSpecificParameter (const std::string &ParameterName, void *ParameterValue)
 Method for obtaining some specific parameters, such as texture specific params, and so on.
UniformgetUniformByName (const std::string &UniformName) const
 GLGLSLShaderSystem ()
bool isAcceptCore (const GraphicCore *Core) const
 Check for GraphicCore acceptance.
bool isAcceptFileExtension (const std::string &FileExtension) const
 Check for correct file extension.
bool isLocked () const
 returns state of object.
bool isShaderCreated (const std::string &ShaderName) const
bool isUniformCreated (const std::string &Uniformname) const
virtual bool preCompile (const std::string &ShaderName, const std::string &ShaderSource, const std::string &Parameters="")
void start ()
 Perform initialization of ShaderSystem.
void stop ()
 Perform deinitialization of ShaderSystem.
void unbind (Shader *shader)
 ~GLGLSLShaderSystem ()

Protected Member Functions

void addSpecificParameter (const std::string &ParameterName, void *ParameterValue, size_t Size)
void lock ()
void unlock ()

Private Types

typedef std::set< std::string > AcceptableGraphicCoreIDset
typedef std::map< std::string,
Shader * > 
ShaderMap
typedef std::map< std::string,
Uniform * > 
UniformMap

Private Attributes

AcceptableGraphicCoreIDset mAcceptableGraphicCoreIDset
ShadermActiveShader
debugger::CodeInstructormCodeInstructor
bool mIsStarted
ShaderMap mShaderMap
UniformMap mUniformMap


Detailed Description

Definition at line 46 of file gl_glsl_shader_system.h.


Member Typedef Documentation

typedef std::set<std::string> gpucalc::GLGLSLShaderSystem::AcceptableGraphicCoreIDset [private]

Definition at line 131 of file gl_glsl_shader_system.h.

typedef std::map<std::string, Shader *> gpucalc::GLGLSLShaderSystem::ShaderMap [private]

Definition at line 123 of file gl_glsl_shader_system.h.

typedef std::map<std::string, Uniform *> gpucalc::GLGLSLShaderSystem::UniformMap [private]

Definition at line 127 of file gl_glsl_shader_system.h.


Constructor & Destructor Documentation

gpucalc::GLGLSLShaderSystem::GLGLSLShaderSystem (  ) 

Definition at line 50 of file gl_glsl_shader_system.cpp.

00050                                        : ShaderSystem(_GLGLSLShaderSystemObjectName), mShaderMap(), mUniformMap(), mAcceptableGraphicCoreIDset(),
00051   mIsStarted(false), mActiveShader(0), mCodeInstructor(0)
00052  {
00053        // mAcceptableGraphicCoreIDset.insert("GLGraphicCore"); // added standart gl graphic core
00054  }

gpucalc::GLGLSLShaderSystem::~GLGLSLShaderSystem (  ) 

Definition at line 57 of file gl_glsl_shader_system.cpp.

00058  {
00059   if (mIsStarted)
00060   {
00061    stop();
00062   }
00063 
00064   LogManager::getSingleton().logMessage(this, "Successfully destroyed.", LML_Normal);
00065  }


Member Function Documentation

void gpucalc::GLGLSLShaderSystem::addAcceptableGraphicCoreID ( const std::string &  GraphicCoreID  )  [virtual]

Method for manual adding acceptable GraphicCore ID.

This method is useful when we use specific GraphicCore with ID different from standart ids.

Implements gpucalc::ShaderSystem.

Definition at line 302 of file gl_glsl_shader_system.cpp.

00303  {
00304   mAcceptableGraphicCoreIDset.insert(GraphicCoreID);
00305  }

void gpucalc::Object::addSpecificParameter ( const std::string &  ParameterName,
void *  ParameterValue,
size_t  Size 
) [inline, protected, inherited]

Definition at line 254 of file object.h.

00255    {
00256     SpecificParametersMap::iterator i = mSpecificParameters.find(ParameterName);
00257     if (i != mSpecificParameters.end())
00258     {
00259      mSpecificParameters.erase(i);
00260     }
00261     mSpecificParameters[ParameterName] = Any(ParameterValue, Size);
00262    }

void gpucalc::GLGLSLShaderSystem::bind ( Shader shader  )  [virtual]

Implements gpucalc::ShaderSystem.

Definition at line 122 of file gl_glsl_shader_system.cpp.

00123  {
00124   assert(shader && "Shader does not created!!!");
00125   if (shader != mActiveShader)
00126   {
00127    GLGLSLShader * GLSLShader = static_cast<GLGLSLShader *>(shader);
00128    glUseProgramObjectARB(GLSLShader->mGLSLProgramID);
00129    mActiveShader = shader;
00130   }
00131  }

Uniform * gpucalc::GLGLSLShaderSystem::create ( Texture texture  )  [virtual]

Creates Uniform from texture.

Parameters:
texture - texture, from which we convert to our Uniform.

Implements gpucalc::ShaderSystem.

Definition at line 230 of file gl_glsl_shader_system.cpp.

00231  {
00232   assert(mIsStarted && "GLGLSLShaderSystem is not started!!!");
00233   UniformMap::iterator i = mUniformMap.find(texture->getObjectName());
00234   if (i != mUniformMap.end())
00235   {
00236    Except<ERR_DUPLICATE_ITEM>(this, "Uniform variable with name \"" + texture->getObjectName() + "\" already exists!",
00237     "GLGLSLShaderSystem::create()", __FILE__, __LINE__);
00238    return 0;
00239   }
00240   else
00241   {
00242    GLGLSLUniform * result = new GLGLSLUniform(texture->getObjectName());
00243    result->mSampler = texture;
00244    result->mUniformType = Uniform::UT_TEX_2;
00245    mUniformMap.insert(std::make_pair(texture->getObjectName(), result));
00246    LogManager::getSingleton().logMessage(this, "Uniform variable created from texture. Name is: " + texture->getObjectName(), LML_Trivial);
00247    return result;
00248   }
00249  }

Uniform * gpucalc::GLGLSLShaderSystem::create ( const Data data  )  [virtual]

creates Uniform variable.

Parameters:
data - represents data, from which we convert to our Uniform.

Implements gpucalc::ShaderSystem.

Definition at line 179 of file gl_glsl_shader_system.cpp.

00180  {
00181   assert(mIsStarted && "GLGLSLShaderSystem is not started!!!");
00182   UniformMap::iterator i = mUniformMap.find(data.getObjectName());
00183   if (i != mUniformMap.end())
00184   {
00185    Except<ERR_DUPLICATE_ITEM>(this, "Uniform variable with name \"" + data.getObjectName() + "\" already exists!",
00186     "GLGLSLShaderSystem::createUniform()", __FILE__, __LINE__);
00187   }
00188   else
00189   {
00190    GLGLSLUniform * result = new GLGLSLUniform(data.getObjectName());
00191    result->mPointer = data.pointer();
00192    result->mActualLengthGPU = data.getActualLengthCPU() / data.getNumberOfComponents();
00193    result->mNumberOfComponents = data.getNumberOfComponents();
00194    result->mTypeSize = data.getTypeSize();
00195 
00196    if (!data.isArray())
00197    {
00198     switch (data.getValueType())
00199     {
00200      case FloatType:
00201       result->mUniformType = static_cast<Uniform::UniformType>(
00202         Uniform::UT_FLOAT_1 + result->getNumberOfComponents() - 1);
00203       break;
00204 
00205      case IntType:
00206      case UnsignedIntType:
00207       result->mUniformType = static_cast<Uniform::UniformType>(
00208         Uniform::UT_INT_1 + result->getNumberOfComponents() - 1);
00209       break;
00210 
00211      default:
00212       Except<ERR_NOT_IMPLEMENTED>(this, "other ValueTypes is not implemented!",
00213        "GLGLSLShaderSystem::createUniform()", __FILE__, __LINE__);
00214       break;
00215     }
00216    }
00217    else
00218    {
00219     Except<ERR_INVALIDPARAMS>(this, "this method can work only with uniform data.", "GLGLSLShaderSystem::create()", __FILE__, __LINE__);
00220    }
00221 
00222    mUniformMap.insert(std::make_pair(data.getObjectName(), result));
00223    LogManager::getSingleton().logMessage(this, "Uniform variable created from data. Name is: " + data.getObjectName(), LML_Trivial);
00224    return result;
00225   }
00226   return 0;
00227  }

Shader * gpucalc::GLGLSLShaderSystem::create ( const std::string &  ShaderName  )  [virtual]

Creates Shader object.

Parameters:
ShaderName - name of our shader object.

Implements gpucalc::ShaderSystem.

Definition at line 68 of file gl_glsl_shader_system.cpp.

00069  {
00070   assert(mIsStarted && "GLGLSLShaderSystem is not started!!!");
00071   ShaderMap::iterator i = mShaderMap.find(ShaderName);
00072   if (i != mShaderMap.end())
00073   {
00074    Except<ERR_DUPLICATE_ITEM>(this, "Shader with name \"" + ShaderName + "\" already exists.", "GLGLSLShaderSystem::create()", __FILE__, __LINE__);
00075    return 0;
00076   }
00077   else
00078   {
00079    GLGLSLShader * Result = new GLGLSLShader(ShaderName, this);
00080    mShaderMap.insert(std::make_pair(ShaderName, Result));
00081    LogManager::getSingleton().logMessage(this, "Shader \"" + ShaderName + "\" succesfully created.", LML_Trivial);
00082    return Result;
00083   }
00084  }

void gpucalc::GLGLSLShaderSystem::destroy ( Uniform uniform  )  [virtual]

Deletes given Uniform.

Sometimes Uniform may contain pointers or smth else. This method does NOT delete it (pointers).

Implements gpucalc::ShaderSystem.

Definition at line 275 of file gl_glsl_shader_system.cpp.

00276  {
00277   assert(mIsStarted && "GLGLSLShaderSystem is not started!!!");
00278   std::string UniformName = uniform->getObjectName();
00279   if (!removeFromContainer(UniformName, mUniformMap))
00280   {
00281    Warning<ERR_INVALIDPARAMS>(this, "Uniform object \"" + UniformName + "\" was created outside GLGLSLShaderSystem!!! Destroying anyway.",
00282     "GLGLSLShaderSystem::destroy", __FILE__, __LINE__);
00283   }
00284   delete uniform;
00285   LogManager::getSingleton().logMessage(this, "Uniform object \"" + UniformName + "\" deleted", LML_Trivial);
00286  }

void gpucalc::GLGLSLShaderSystem::destroy ( Shader shader  )  [virtual]

Deletes Shader object.

This method removes shader from mShaderMap and delete it.

Implements gpucalc::ShaderSystem.

Definition at line 108 of file gl_glsl_shader_system.cpp.

00109  {
00110   assert(mIsStarted && "GLGLSLShaderSystem is not started!!!");
00111   std::string ShaderName = shader->getObjectName();
00112   if (!removeFromContainer(ShaderName, mShaderMap))
00113   {
00114    Warning<ERR_INVALIDPARAMS>(this, "Shader object \"" + ShaderName + "\" was created outside GLGLSLShaderSystem!!! Destroying anyway.",
00115             "GLGraphicCore::deleteFrameBuffer", __FILE__, __LINE__);
00116   }
00117   delete shader;
00118   LogManager::getSingleton().logMessage(this, ShaderName + " successfully deleted.", LML_Trivial);
00119  }

Shader* gpucalc::GLGLSLShaderSystem::getActiveShader (  )  const [inline, virtual]

Implements gpucalc::ShaderSystem.

Definition at line 96 of file gl_glsl_shader_system.h.

00097    {
00098     return mActiveShader;
00099    }

const std::string& gpucalc::Object::getClassName (  )  const [inline, inherited]

Returns name of class of our object.

Definition at line 92 of file object.h.

00093    {
00094     return mClassName;
00095    }

debugger::CodeInstructor * gpucalc::GLGLSLShaderSystem::getCodeInstructor (  )  const [virtual]

Returns CodeInstructor - special object, which allows to instruct shader with debugging symbols.

Implements gpucalc::ShaderSystem.

Definition at line 308 of file gl_glsl_shader_system.cpp.

00309  {
00310   return mCodeInstructor;
00311  }

const std::string& gpucalc::Object::getObjectName (  )  const [inline, inherited]

Returns name of our object.

Definition at line 101 of file object.h.

00102    {
00103     return mObjectName;
00104    }

Shader * gpucalc::GLGLSLShaderSystem::getShaderByName ( const std::string &  Shadername  )  const [virtual]

Implements gpucalc::ShaderSystem.

Definition at line 87 of file gl_glsl_shader_system.cpp.

00088  {
00089   assert(mIsStarted && "GLGLSLShaderSystem is not started!!!");
00090   ShaderMap::const_iterator i = mShaderMap.find(ShaderName);
00091   if (i != mShaderMap.end())
00092   {
00093    return i->second;
00094   }
00095   else
00096   {
00097    Except<ERR_ITEM_NOT_FOUND>(this, "Shader with name \"" + ShaderName + "\" cannot be found.", "GLGLSLShaderSystem::getShaderByName()", __FILE__, __LINE__);
00098   }
00099  }

void gpucalc::Object::getSpecificParameter ( const std::string &  ParameterName,
void *  ParameterValue 
) [inline, inherited]

Method for obtaining some specific parameters, such as texture specific params, and so on.

Parameters:
ParameterName - name of parameter, usually it similar to specific method of some object (for example, GLTextureID)
ParameterValue - contain value of named parameter, it must be allocated and have sufficient size.
Todo:
Think for better realization.

Definition at line 128 of file object.h.

00129    {
00130     SpecificParametersMap::iterator i = mSpecificParameters.find(ParameterName);
00131     if (i != mSpecificParameters.end())
00132     {
00133      i->second.copyValue(ParameterValue);
00134     }
00135     else
00136     {
00137      Except<ERR_ITEM_NOT_FOUND>(this, "Parameter \"" + ParameterName + "\" does not exists.", "Object::getSpecificParameter()", __FILE__, __LINE__);
00138     }
00139    }

Uniform * gpucalc::GLGLSLShaderSystem::getUniformByName ( const std::string &  UniformName  )  const [virtual]

Implements gpucalc::ShaderSystem.

Definition at line 252 of file gl_glsl_shader_system.cpp.

00253  {
00254   assert(mIsStarted && "GLGLSLShaderSystem is not started!!!");
00255   UniformMap::const_iterator i = mUniformMap.find(UniformName);
00256   if (i != mUniformMap.end())
00257   {
00258    return i->second;
00259   }
00260   else
00261   {
00262    Except<ERR_ITEM_NOT_FOUND>(this, "Uniform variable with name \"" + UniformName + "\" cannot be found!",
00263     "GLGLSLShaderSystem::getUniformByName()", __FILE__, __LINE__);
00264   }
00265  }

bool gpucalc::GLGLSLShaderSystem::isAcceptCore ( const GraphicCore Core  )  const [virtual]

Check for GraphicCore acceptance.

We need correct type of GraphicCore, because some shader systems cannot work with some graphic cores (DX core and GL system).

Implements gpucalc::ShaderSystem.

Definition at line 289 of file gl_glsl_shader_system.cpp.

00290  {
00291   return (mAcceptableGraphicCoreIDset.find(Core->getObjectName()) != mAcceptableGraphicCoreIDset.end());
00292  }

bool gpucalc::GLGLSLShaderSystem::isAcceptFileExtension ( const std::string &  FileExtension  )  const [virtual]

Check for correct file extension.

Implements gpucalc::ShaderSystem.

Definition at line 295 of file gl_glsl_shader_system.cpp.

00296  {
00298   return auxillary::StringUtil::toLower(FileExtension) == std::string("fglsl");
00299  }

bool gpucalc::Object::isLocked (  )  const [inline, inherited]

returns state of object.

If object is locked then we cannot change some state of it, because object is used in computation. If object is unlocked then we can change some state of it, object is not in computation.

Definition at line 113 of file object.h.

00114    {
00115     return mIsLocked;
00116    }

bool gpucalc::GLGLSLShaderSystem::isShaderCreated ( const std::string &  ShaderName  )  const [virtual]

Implements gpucalc::ShaderSystem.

Definition at line 102 of file gl_glsl_shader_system.cpp.

00103  {
00104   return (mShaderMap.find(ShaderName) != mShaderMap.end());
00105  }

bool gpucalc::GLGLSLShaderSystem::isUniformCreated ( const std::string &  Uniformname  )  const [virtual]

Implements gpucalc::ShaderSystem.

Definition at line 268 of file gl_glsl_shader_system.cpp.

00269  {
00270   assert(mIsStarted && "GLGLSLShaderSystem is not started!!!");
00271   return (mUniformMap.find(UniformName) != mUniformMap.end());
00272  }

void gpucalc::Object::lock (  )  [inline, protected, inherited]

Definition at line 265 of file object.h.

00266    {
00267     mIsLocked = true;
00268    }

bool gpucalc::ShaderSystem::preCompile ( const std::string &  ShaderName,
const std::string &  ShaderSource,
const std::string &  Parameters = "" 
) [virtual, inherited]

Definition at line 48 of file shader_system.cpp.

00049     {
00050         try
00051         {
00052             Shader * sh = create(ShaderName);
00053             sh->setSource(ShaderSource);
00054             sh->compile(Parameters);
00055             return true;
00056         }
00057         catch(const Exception & e)
00058         {
00059             LogManager::getSingleton().logMessage(this, "Precompilation failed, see log for details.", LML_Critical);
00060             return false;
00061         }
00062     }

void gpucalc::GLGLSLShaderSystem::start (  )  [virtual]

Perform initialization of ShaderSystem.

Implements gpucalc::ShaderSystem.

Definition at line 145 of file gl_glsl_shader_system.cpp.

00146  {
00147         if (mIsStarted) return;
00148   LogManager::getSingleton().logMessage(this, "---===========================================---");
00149   LogManager::getSingleton().logMessage(this, "---===    GL GLSL Shader system started    ===---");
00150   LogManager::getSingleton().logMessage(this, "---===========================================---");
00151   mIsStarted = true;
00152   this->addAcceptableGraphicCoreID("GLGraphicCore");
00153 
00154   if (debugger::Debugger::getSingletonPtr() != 0)
00155   {
00156    mCodeInstructor = new debugger::GLGLSLCodeInstructor();
00157   }
00158  }

void gpucalc::GLGLSLShaderSystem::stop (  )  [virtual]

Perform deinitialization of ShaderSystem.

Implements gpucalc::ShaderSystem.

Definition at line 161 of file gl_glsl_shader_system.cpp.

00162  {
00163   assert(mIsStarted && "GLGLSLShaderSystem is not started!!!");
00164   clearContainer(mShaderMap);
00165   clearContainer(mUniformMap);
00166 
00167   LogManager::getSingleton().logMessage(this, "---===========================================---");
00168   LogManager::getSingleton().logMessage(this, "---===    GL GLSL Shader system stopped    ===---");
00169   LogManager::getSingleton().logMessage(this, "---===========================================---");
00170   mIsStarted = false;
00171 
00172   if (debugger::Debugger::getSingletonPtr() != 0)
00173   {
00174    delete mCodeInstructor;
00175   }
00176  }

void gpucalc::GLGLSLShaderSystem::unbind ( Shader shader  )  [virtual]

Implements gpucalc::ShaderSystem.

Definition at line 134 of file gl_glsl_shader_system.cpp.

00135  {
00136   assert(shader && "Shader does not created!!!");
00137   if (shader == mActiveShader)
00138   {
00139    glUseProgramObjectARB(0);
00140    mActiveShader = 0;
00141   }
00142  }

void gpucalc::Object::unlock (  )  [inline, protected, inherited]

Definition at line 271 of file object.h.

00272    {
00273     mIsLocked = false;
00274    }


Member Data Documentation

Definition at line 132 of file gl_glsl_shader_system.h.

Definition at line 138 of file gl_glsl_shader_system.h.

Definition at line 141 of file gl_glsl_shader_system.h.

Definition at line 135 of file gl_glsl_shader_system.h.

Definition at line 124 of file gl_glsl_shader_system.h.

Definition at line 128 of file gl_glsl_shader_system.h.


The documentation for this class was generated from the following files:

Generated on Thu Mar 5 22:36:44 2009 for gpucalc by  doxygen 1.5.6