dtCore::ShaderProgram Class Reference

This class represents a single shader or rendering effect. More...

#include <shaderprogram.h>

List of all members.

Public Member Functions

 ShaderProgram (const std::string &name)
 Construct an empty shader.
const std::string & GetName () const
 Gets the name currently assigned to this shader.
void AddVertexShader (const std::string &fileName)
 This method adds a shader source meant for vertex processing from the specified file name.
const std::vector< std::string > & GetVertexShaders () const
 Gets the vertex shaders file names.
const std::string & GetVertexCacheKey ()
 Gets the vertex cache key.
const std::string & GetFragmentCacheKey ()
 Gets the fragment cache key.
void AddFragmentShader (const std::string &fileName)
 This method adds a shader source meant for fragment processing from the specified file name.
const std::vector< std::string > & GetFragmentShaders () const
 Gets the fragment shaders file names.
void AddParameter (ShaderParameter &newParam)
 Binds a shader parameter to this shader.
void RemoveParameter (ShaderParameter &param)
 Removes an existing parameter from the shader.
void RemoveParameter (const std::string &name)
 Removes an existing parameter from this shader.
void RemoveAllParameters ()
 Clears this shaders list of parameters.
const ShaderParameterFindParameter (const std::string &name) const
 Looks up a shader parameter with the given name.
ShaderParameterFindParameter (const std::string &name)
 Looks up a shader parameter with the given name.
unsigned int GetNumParameters () const
 Gets the number of parameters currently attached to this shader.
void GetParameterList (std::vector< dtCore::RefPtr< ShaderParameter > > &toFill) const
 Fills the specified vector with all the shader parameters currently attached to this shader.
virtual void Update ()
 Updates any parameter state which may have changed on this shader since the last update.
const osg::Program * GetShaderProgram () const
 Gets a pointer to the actual shader program constructed by the shader source code.
osg::Program * GetShaderProgram ()
 Gets a pointer to the actual shader program constructed by the shader source code.
void Reset ()
 Removes all shader source and compiler programs from this shader object.
void SetDirty (bool flag)
 Marks this shader as dirty and informs its parent shader group that one of the shaders it contains has been marked as dirty.
bool IsDirty () const
 Gets whether ot not this shader is dirty.
dtCore::ShaderProgramClone () const
 Makes a deep copy of the shader and all its parameters.

Protected Member Functions

virtual ~ShaderProgram ()
 Destroys this shader object.
ShaderProgramoperator= (const ShaderProgram &rhs)
 Hidden copy constructor and assignment operator.
 ShaderProgram (const ShaderProgram &rhs)

Friends

class ShaderManager
class ShaderGroup


Detailed Description

This class represents a single shader or rendering effect.

It contains a vertex shader, fragment shader, and any sort of library shader support code that may exist.

Note:
Although it contains methods for setting vertex and fragment programs, the shader itself could support fixed function effects as well; however it is tailored towards the programmable pipeline.

If you are using this class, you should also be using the ShaderManager. If so, be sure you are modifying an instance of a Shader as opposed to a template.

Each shader has a list of parameters associated with it. These may be used by the shader and or the objects using the shader in any way they see fit.


Constructor & Destructor Documentation

dtCore::ShaderProgram::ShaderProgram ( const std::string &  name  ) 

Construct an empty shader.

Parameters:
name Name to assign the new shader. Shader names must be unique.

dtCore::ShaderProgram::~ShaderProgram (  )  [protected, virtual]

Destroys this shader object.

dtCore::ShaderProgram::ShaderProgram ( const ShaderProgram rhs  )  [protected]


Member Function Documentation

const std::string& dtCore::ShaderProgram::GetName (  )  const [inline]

Gets the name currently assigned to this shader.

Returns:
The shader's name.

void dtCore::ShaderProgram::AddVertexShader ( const std::string &  fileName  ) 

This method adds a shader source meant for vertex processing from the specified file name.

Parameters:
fileName The path of the shader file source. This must be either the full path or a path relative to the Delta3d path list.

const std::vector<std::string>& dtCore::ShaderProgram::GetVertexShaders (  )  const [inline]

Gets the vertex shaders file names.

Returns:
A Vector that contains a set of strings that represent the different vertex file names

const std::string & dtCore::ShaderProgram::GetVertexCacheKey (  ) 

Gets the vertex cache key.

Returns:
The vertex cache key used to identify a certain shader group

const std::string & dtCore::ShaderProgram::GetFragmentCacheKey (  ) 

Gets the fragment cache key.

Returns:
The fragment cache key used to identify a certain shader group

void dtCore::ShaderProgram::AddFragmentShader ( const std::string &  fileName  ) 

This method adds a shader source meant for fragment processing from the specified file name.

Parameters:
fileName The path of the shader file source. This must be either the full path or a path relative to the Delta3d path list.

const std::vector<std::string>& dtCore::ShaderProgram::GetFragmentShaders (  )  const [inline]

Gets the fragment shaders file names.

Returns:
A Vector that contains a set of strings that represent the different fragment file names

void dtCore::ShaderProgram::AddParameter ( ShaderParameter newParam  ) 

Binds a shader parameter to this shader.

Parameters:
newParam The new shader parameter to bind or attach to the shader.
Note:
An exception is thrown if a parameter with the same name already exists on the shader.

void dtCore::ShaderProgram::RemoveParameter ( ShaderParameter param  ) 

Removes an existing parameter from the shader.

Parameters:
param The parameter to remove. This results in a no-op if the parameter to remove is not owned by this shader.

void dtCore::ShaderProgram::RemoveParameter ( const std::string &  name  ) 

Removes an existing parameter from this shader.

Parameters:
name The name of the shader parameter to remove. If this parameter is not currently owned by this shader, this method is a no-op.

void dtCore::ShaderProgram::RemoveAllParameters (  ) 

Clears this shaders list of parameters.

Note:
This does not mean that any shaders and its parameters bound to a render state are cleared, just this shader instance.

const ShaderParameter * dtCore::ShaderProgram::FindParameter ( const std::string &  name  )  const

Looks up a shader parameter with the given name.

(Const version).

Returns:
A const pointer to the shader parameter or NULL if it could not be found.

ShaderParameter * dtCore::ShaderProgram::FindParameter ( const std::string &  name  ) 

Looks up a shader parameter with the given name.

(Non-const version).

Returns:
A pointer to the shader parameter or NULL if it could not be found.

unsigned int dtCore::ShaderProgram::GetNumParameters (  )  const [inline]

Gets the number of parameters currently attached to this shader.

Returns:
The parameter count.

void dtCore::ShaderProgram::GetParameterList ( std::vector< dtCore::RefPtr< ShaderParameter > > &  toFill  )  const

Fills the specified vector with all the shader parameters currently attached to this shader.

Parameters:
toFill The vector to fill. Note, this is cleared first.

void dtCore::ShaderProgram::Update (  )  [virtual]

Updates any parameter state which may have changed on this shader since the last update.

Note:
This does not rebind any changed shader sources. In order to rebind, the ShaderManager's AssignShaderFromTemplate method must be called.
See also:
ShaderManager::AssignShaderFromTemplate

const osg::Program* dtCore::ShaderProgram::GetShaderProgram (  )  const [inline]

Gets a pointer to the actual shader program constructed by the shader source code.

Returns:
A pointer to the shader program. This may be shared amoungst many renderable objects.

osg::Program* dtCore::ShaderProgram::GetShaderProgram (  )  [inline]

Gets a pointer to the actual shader program constructed by the shader source code.

Returns:
A pointer to the shader program. This may be shared amoungst many renderable objects. Either put this in a RefPtr or don't hold onto it.

void dtCore::ShaderProgram::Reset (  ) 

Removes all shader source and compiler programs from this shader object.

void dtCore::ShaderProgram::SetDirty ( bool  flag  ) 

Marks this shader as dirty and informs its parent shader group that one of the shaders it contains has been marked as dirty.

Parameters:
flag True to set dirty, false to clear the dirty bit.

bool dtCore::ShaderProgram::IsDirty (  )  const [inline]

Gets whether ot not this shader is dirty.

Returns:
True if dirty, false otherwise.

dtCore::ShaderProgram * dtCore::ShaderProgram::Clone (  )  const

Makes a deep copy of the shader and all its parameters.

Used when a user assigns a shader to a node using ShaderManager::AssignShaderFromTempalte.

Returns:
the cloned shader instance with cloned parameters.

ShaderProgram & dtCore::ShaderProgram::operator= ( const ShaderProgram rhs  )  [protected]

Hidden copy constructor and assignment operator.


Friends And Related Function Documentation

friend class ShaderManager [friend]

friend class ShaderGroup [friend]


http://www.delta3d.org
2.0.0 generated 14 Feb 2008