Caelum  0.6.3
Public Member Functions | Protected Member Functions | List of all members
Caelum::FastGpuParamRef Class Reference

An optimized reference to a gpu shared parameter. More...

#include <FastGpuParamRef.h>

Public Member Functions

 FastGpuParamRef ()
 Default constructor. Starts as unbound.
 
 FastGpuParamRef (Ogre::GpuProgramParametersSharedPtr paramsPtr, const Ogre::String &name)
 Create and bind.
 
void bind (Ogre::GpuProgramParametersSharedPtr paramsPtr, const Ogre::String &name, bool throwIfNotFound=false)
 Bind to a certain parameter. More...
 
void unbind ()
 Unbind ParamRef. More...
 
bool isBound () const
 Return if this param ref is bound to an actual param.
 
size_t getPhysicalIndex () const
 Return the physical index. Only valid if this->isBound().
 
void set (const Ogre::GpuProgramParametersSharedPtr &params, int val) const
 Set the value. More...
 
void set (const Ogre::GpuProgramParametersSharedPtr &params, Ogre::Real val) const
 Set the value. More...
 
void set (const Ogre::GpuProgramParametersSharedPtr &params, const Ogre::Vector3 &val) const
 Set the value. More...
 
void set (const Ogre::GpuProgramParametersSharedPtr &params, const Ogre::Vector4 &val) const
 Set the value. More...
 
void set (const Ogre::GpuProgramParametersSharedPtr &params, const Ogre::ColourValue &val) const
 Set the value. More...
 
void set (const Ogre::GpuProgramParametersSharedPtr &params, const Ogre::Matrix4 &val) const
 Set the value. More...
 

Protected Member Functions

template<typename ArgumentT >
void doSet (const Ogre::GpuProgramParametersSharedPtr &params, ArgumentT arg) const
 Set the value. More...
 
template<typename ArgumentT >
void doSet (const Ogre::GpuProgramParametersSharedPtr &params, ArgumentT arg, size_t count) const
 

Detailed Description

An optimized reference to a gpu shared parameter.

Profiling shows that GpuProgramParameters::_findNamedConstantDefinition is not free.

This class avoids hash lookups when updating. It's uses no additional memory than if you were to implement the same thing manually.

You must also keep the matching Ogre::GpuProgramParametersSharedPtr and send it whenever you call FastGpuParamRef::set. This is required to save memory in release mode. Debug mode checks the pointer you pass to set is the same as the pointer you called bind on; but uses more memory.

Also; please note that fetching gpu params from a material every frame is not free either.

Member Function Documentation

void Caelum::FastGpuParamRef::bind ( Ogre::GpuProgramParametersSharedPtr  paramsPtr,
const Ogre::String name,
bool  throwIfNotFound = false 
)

Bind to a certain parameter.

Parameters
paramsPtrparams to bind to. Can't be null; you must unbind explicitly.
nameThe name of the parameter to bind.
throwIfNotFoundArgument to GpuProgramParameters::_findNamedConstantDefinition.

If throwIfNotFound is false (the default) missing parameters are ignored and the param ref will remand unbound. Calling set will then have no effect.

void Caelum::FastGpuParamRef::unbind ( )

Unbind ParamRef.

If CAELUM_DEBUG_PARAM_REF is 1 this will also release the hold on GpuProgramParametersSharedPtr.

template<typename ArgumentT >
void Caelum::FastGpuParamRef::doSet ( const Ogre::GpuProgramParametersSharedPtr params,
ArgumentT  arg 
) const
inlineprotected

Set the value.

No effect if !this->isBound()

Parameters
paramsParameter pointer. Can't be null
argArgument to set.

Will check params pointer matches the bound pointer if #CAELUM_DEBUG_PARAM_REF. Otherwise a mismatched params pointer can result in memory corruption.

References Ogre::GpuProgramParameters::_writeRawConstant(), doSet(), and Ogre::SharedPtr< T >::getPointer().

void Caelum::FastGpuParamRef::set ( const Ogre::GpuProgramParametersSharedPtr params,
int  val 
) const
inline

Set the value.

No effect if !this->isBound()

Parameters
paramsParameter pointer. Can't be null
argArgument to set.

Will check params pointer matches the bound pointer if #CAELUM_DEBUG_PARAM_REF. Otherwise a mismatched params pointer can result in memory corruption.

void Caelum::FastGpuParamRef::set ( const Ogre::GpuProgramParametersSharedPtr params,
Ogre::Real  val 
) const
inline

Set the value.

No effect if !this->isBound()

Parameters
paramsParameter pointer. Can't be null
argArgument to set.

Will check params pointer matches the bound pointer if #CAELUM_DEBUG_PARAM_REF. Otherwise a mismatched params pointer can result in memory corruption.

void Caelum::FastGpuParamRef::set ( const Ogre::GpuProgramParametersSharedPtr params,
const Ogre::Vector3 val 
) const
inline

Set the value.

No effect if !this->isBound()

Parameters
paramsParameter pointer. Can't be null
argArgument to set.

Will check params pointer matches the bound pointer if #CAELUM_DEBUG_PARAM_REF. Otherwise a mismatched params pointer can result in memory corruption.

void Caelum::FastGpuParamRef::set ( const Ogre::GpuProgramParametersSharedPtr params,
const Ogre::Vector4 val 
) const
inline

Set the value.

No effect if !this->isBound()

Parameters
paramsParameter pointer. Can't be null
argArgument to set.

Will check params pointer matches the bound pointer if #CAELUM_DEBUG_PARAM_REF. Otherwise a mismatched params pointer can result in memory corruption.

void Caelum::FastGpuParamRef::set ( const Ogre::GpuProgramParametersSharedPtr params,
const Ogre::ColourValue val 
) const
inline

Set the value.

No effect if !this->isBound()

Parameters
paramsParameter pointer. Can't be null
argArgument to set.

Will check params pointer matches the bound pointer if #CAELUM_DEBUG_PARAM_REF. Otherwise a mismatched params pointer can result in memory corruption.

void Caelum::FastGpuParamRef::set ( const Ogre::GpuProgramParametersSharedPtr params,
const Ogre::Matrix4 val 
) const
inline

Set the value.

No effect if !this->isBound()

Parameters
paramsParameter pointer. Can't be null
argArgument to set.

Will check params pointer matches the bound pointer if #CAELUM_DEBUG_PARAM_REF. Otherwise a mismatched params pointer can result in memory corruption.


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