Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::gfx::UniformHolder Class Reference

A UniformHolder is a base class for an object that holds Uniforms. More...

#include "uniformholder.h"

Inheritance diagram for ion::gfx::UniformHolder:

Public Member Functions

size_t AddUniform (const Uniform &uniform)
 Adds a uniform to this and returns an index that can be used to refer to the uniform. More...
 
bool ReplaceUniform (size_t index, const Uniform &uniform)
 Replaces the uniform at an index with the passed value, if the index is valid. More...
 
bool RemoveUniformByName (const std::string &name)
 Removes the uniform with the passed name if it exists. More...
 
void ClearUniforms ()
 Clears the vector of uniforms in this. More...
 
const base::AllocVector
< Uniform > & 
GetUniforms () const
 Gets the vector of uniforms. More...
 
template<typename T >
bool SetUniformValue (size_t index, const T &value)
 Sets the value of the uniform at an index if the index is valid. More...
 
template<typename T >
bool SetUniformValueAt (size_t index, size_t array_index, const T &value)
 Sets the value of the array uniform at an index if the index is valid. More...
 
size_t GetUniformIndex (const std::string &name) const
 Returns the index of the uniform this with the given name, if it exists. More...
 
template<typename T >
bool SetUniformByName (const std::string &name, const T &value)
 Convenience function to set the value of a uniform specified by name. More...
 
template<typename T >
bool SetUniformByNameAt (const std::string &name, size_t array_index, const T &value)
 Convenience function to set the value of an element of an array uniform designated by name. More...
 
void Enable (bool enable)
 Enables or disables the UniformHolder. More...
 
bool IsEnabled () const
 

Protected Member Functions

 UniformHolder (const base::AllocatorPtr &alloc)
 The constructor is protected because this is a base class. More...
 
virtual ~UniformHolder ()
 The destructor is protected because all base::Referent classes must have protected or private destructors. More...
 

Detailed Description

A UniformHolder is a base class for an object that holds Uniforms.

Note that adding a Uniform adds a copy of the instance; to modify a uniform value use ReplaceUniform() or SetUniformValue[At]().

The ShaderInputRegistry of any Uniform added to a UniformHolder should have a longer lifetime than the holder. If not, then if the Uniforms are used after their creating registry has been destroyed (recall that Uniforms hold only a pointer, not refptr to their registry) they will dereference freed memory.

Definition at line 39 of file uniformholder.h.

Constructor & Destructor Documentation

ion::gfx::UniformHolder::UniformHolder ( const base::AllocatorPtr alloc)
explicitprotected

The constructor is protected because this is a base class.

It requires an allocator to use for its vector of uniforms.

Definition at line 25 of file uniformholder.cc.

ion::gfx::UniformHolder::~UniformHolder ( )
protectedvirtual

The destructor is protected because all base::Referent classes must have protected or private destructors.

Definition at line 28 of file uniformholder.cc.

Member Function Documentation

size_t ion::gfx::UniformHolder::AddUniform ( const Uniform uniform)
inline

Adds a uniform to this and returns an index that can be used to refer to the uniform.

Note that this index is invalid if ClearUniforms() is ever used, and may refer to a different uniform if the uniform is ever replaced with ReplaceUniform(). Returns base::kInvalidIndex if an attempt is made to add an invalid uniform.

Definition at line 46 of file uniformholder.h.

References ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::IsValid(), and ion::base::kInvalidIndex.

Referenced by ion::text::BasicBuilder::UpdateUniforms(), and ion::text::OutlineBuilder::UpdateUniforms().

void ion::gfx::UniformHolder::ClearUniforms ( )
inline

Clears the vector of uniforms in this.

Definition at line 78 of file uniformholder.h.

Referenced by ion::text::BasicBuilder::UpdateUniforms(), and ion::text::OutlineBuilder::UpdateUniforms().

void ion::gfx::UniformHolder::Enable ( bool  enable)
inline

Enables or disables the UniformHolder.

Disabled holders are skipped over during rendering; their values are not sent to OpenGL. UniformHolders are enabled by default.

Definition at line 137 of file uniformholder.h.

size_t ion::gfx::UniformHolder::GetUniformIndex ( const std::string &  name) const

Returns the index of the uniform this with the given name, if it exists.

The Uniform must have been added with AddUniform() or ReplaceUniform(). If no uniform with the name exists in this then returns ion::base::kInvalidIndex. Note that this is a relatively slow operation and should be used sparingly.

Definition at line 30 of file uniformholder.cc.

References DCHECK, ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetIndexInRegistry(), ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetRegistry(), ion::gfx::ShaderInputRegistry::GetSpecs(), ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::IsValid(), and ion::base::kInvalidIndex.

const base::AllocVector<Uniform>& ion::gfx::UniformHolder::GetUniforms ( ) const
inline
bool ion::gfx::UniformHolder::IsEnabled ( ) const
inline

Definition at line 138 of file uniformholder.h.

bool ion::gfx::UniformHolder::RemoveUniformByName ( const std::string &  name)
inline

Removes the uniform with the passed name if it exists.

Returns true iff the uniform existed and hence got removed. Note that this will change the indices of other uniforms within the holder.

Definition at line 69 of file uniformholder.h.

References ion::base::kInvalidIndex.

bool ion::gfx::UniformHolder::ReplaceUniform ( size_t  index,
const Uniform uniform 
)
inline

Replaces the uniform at an index with the passed value, if the index is valid.

Returns if the replacement is successful.

Definition at line 57 of file uniformholder.h.

References ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::IsValid().

template<typename T >
bool ion::gfx::UniformHolder::SetUniformByName ( const std::string &  name,
const T value 
)
inline

Convenience function to set the value of a uniform specified by name.

This returns false if there is no uniform with that name or the value type does not match.

Definition at line 113 of file uniformholder.h.

References ion::base::kInvalidIndex, and value.

template<typename T >
bool ion::gfx::UniformHolder::SetUniformByNameAt ( const std::string &  name,
size_t  array_index,
const T value 
)
inline

Convenience function to set the value of an element of an array uniform designated by name.

This returns false if:

  • There is no uniform matching name.
  • Value type 'T' does not match the uniform array type.
  • array_index exceeds the size of the uniform array.

Definition at line 125 of file uniformholder.h.

References ion::base::kInvalidIndex.

template<typename T >
bool ion::gfx::UniformHolder::SetUniformValue ( size_t  index,
const T value 
)
inline

Sets the value of the uniform at an index if the index is valid.

Returns true if the index is valid and the set was successful (i.e., T is a valid type for the selected uniform), and false otherwise.

Definition at line 86 of file uniformholder.h.

Referenced by ion::text::Builder::UpdateFontImageTextureUniform(), ion::text::BasicBuilder::UpdateUniforms(), and ion::text::OutlineBuilder::UpdateUniforms().

template<typename T >
bool ion::gfx::UniformHolder::SetUniformValueAt ( size_t  index,
size_t  array_index,
const T value 
)
inline

Sets the value of the array uniform at an index if the index is valid.

Returns true if the index is valid and the set was successful (i.e., T is a valid type for the selected uniform), and false otherwise.

Definition at line 95 of file uniformholder.h.


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