Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::gfx::ShaderInput< ValueHolderType, ValueEnumType > Class Template Reference

A ShaderInput instance represents a general shader input. More...

#include "shaderinput.h"

Inheritance diagram for ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >:
Collaboration diagram for ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >:

Public Types

typedef ValueHolderType HolderType
 
typedef ValueEnumType ValueType
 
enum  Tag {
  kUniform,
  kAttribute
}
 This is only used to determine the type of a ShaderInputRegistry::Spec since Attributes and Uniforms share the space of names. More...
 

Public Member Functions

 ~ShaderInput ()
 
bool IsValid () const
 Returns true if this is a valid instance created by a ShaderInputRegistry. More...
 
const ShaderInputRegistryGetRegistry () const
 Returns the ShaderInputRegistry the shader input is defined in. More...
 
size_t GetIndexInRegistry () const
 Returns the index of the shader input within the registry. More...
 
size_t GetRegistryId () const
 Returns the id of the owning registry. More...
 
size_t GetArrayIndex () const
 Returns the array index of this input; by default this is 0. More...
 
ValueType GetType () const
 Returns the type of the shader input. More...
 
template<typename T >
const TGetValue () const
 If this instance contains a value of type T, this returns a const reference to it. More...
 
template<typename T >
const TGetValueAt (size_t i) const
 If this instance contains an array of values of type T with a length smaller than the passed index, this returns a const reference to the element at i. More...
 
size_t GetCount () const
 Returns the number of elements in the held type. More...
 
template<typename T >
bool Is () const
 If this instance contains a value of type T, this returns true, otherwise it returns false. More...
 
template<typename T >
bool IsArrayOf () const
 If this instance contains an array of values of type T, this returns true, otherwise it returns false. More...
 
template<typename T >
bool SetValue (const T &value)
 If this instance contains a value of type T, this changes it to the new value. More...
 
template<typename T >
bool SetValueAt (size_t i, const T &value)
 If this instance contains a array of values of type T with a length larger than i, this changes the element at i to the new value. More...
 
uint64 GetStamp () const
 Returns the stamp of the input. More...
 

Protected Member Functions

 ShaderInput ()
 The default constructor creates an invalid ShaderInput instance, which should never be used as is. More...
 
void SetNewStamp ()
 Assigns a new stamp to this Input. More...
 
template<typename T >
void Init (const ShaderInputRegistry &registry, size_t registry_id, size_t index_in_registry, size_t array_index, ValueType type, const T &value)
 Initializes the ShaderInput to a valid state. More...
 
template<typename T >
void InitArray (const ShaderInputRegistry &registry, size_t registry_id, size_t index_in_registry, size_t array_index, ValueType type, const T *values, size_t count, const base::AllocatorPtr &allocator)
 Initializes the ShaderInput to a valid state. More...
 
const base::AllocatorPtrGetArrayAllocator () const
 Returns the allocator used to make array allocations. More...
 

Static Protected Member Functions

static uint64 GetNewStamp ()
 Returns atomically post-incremented stamp. More...
 

Friends

class ShaderInputRegistry
 

Detailed Description

template<typename ValueHolderType, typename ValueEnumType>
class ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >

A ShaderInput instance represents a general shader input.

Definition at line 50 of file shaderinput.h.

Member Typedef Documentation

template<typename ValueHolderType, typename ValueEnumType>
typedef ValueHolderType ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::HolderType

Definition at line 52 of file shaderinput.h.

template<typename ValueHolderType, typename ValueEnumType>
typedef ValueEnumType ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::ValueType

Definition at line 53 of file shaderinput.h.

Member Enumeration Documentation

This is only used to determine the type of a ShaderInputRegistry::Spec since Attributes and Uniforms share the space of names.

Enumerator
kUniform 
kAttribute 

Definition at line 35 of file shaderinput.h.

Constructor & Destructor Documentation

template<typename ValueHolderType, typename ValueEnumType>
ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::~ShaderInput ( )
inline

Definition at line 55 of file shaderinput.h.

template<typename ValueHolderType, typename ValueEnumType>
ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::ShaderInput ( )
inlineprotected

The default constructor creates an invalid ShaderInput instance, which should never be used as is.

IsValid() will return false for such an instance.

Definition at line 151 of file shaderinput.h.

Member Function Documentation

template<typename ValueHolderType, typename ValueEnumType>
const base::AllocatorPtr& ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetArrayAllocator ( ) const
inlineprotected

Returns the allocator used to make array allocations.

Definition at line 207 of file shaderinput.h.

template<typename ValueHolderType, typename ValueEnumType>
size_t ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetArrayIndex ( ) const
inline

Returns the array index of this input; by default this is 0.

An array index is specified in the input name with square brackets, e.g., uMyArray[2] has an index of 2.

Definition at line 76 of file shaderinput.h.

Referenced by ion::gfx::Uniform::GetMerged().

template<typename ValueHolderType, typename ValueEnumType>
size_t ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetCount ( ) const
inline

Returns the number of elements in the held type.

This is 0 if this holds only a scalar value.

Definition at line 99 of file shaderinput.h.

Referenced by ion::gfx::Uniform::GetMerged().

template<typename ValueHolderType, typename ValueEnumType>
size_t ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetIndexInRegistry ( ) const
inline

Returns the index of the shader input within the registry.

This should not be called on an invalid instance.

Definition at line 67 of file shaderinput.h.

Referenced by ion::gfx::AttributeArray::AddAttribute(), ion::gfx::Uniform::GetMerged(), ion::gfx::UniformHolder::GetUniformIndex(), ion::gfx::Uniform::MergeValuesFrom(), ion::gfx::Attribute::operator==(), and ion::gfx::Uniform::operator==().

uint64 ion::gfx::ShaderInputBase::GetNewStamp ( )
staticprotectedinherited

Returns atomically post-incremented stamp.

Definition at line 24 of file shaderinput.cc.

Referenced by ion::gfx::ShaderInput< UniformValueType, UniformType >::SetNewStamp().

template<typename ValueHolderType, typename ValueEnumType>
const ShaderInputRegistry& ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetRegistry ( ) const
inline
template<typename ValueHolderType, typename ValueEnumType>
size_t ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetRegistryId ( ) const
inline

Returns the id of the owning registry.

This value will not be useful if called on an invalid instance.

Definition at line 71 of file shaderinput.h.

template<typename ValueHolderType, typename ValueEnumType>
uint64 ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetStamp ( ) const
inline

Returns the stamp of the input.

The stamp is a global counter which is advanced any time a ShaderInput is modified. Two Uniforms with the same stamp are guaranteed to have the same values. Two Uniforms with different stamps may or may not have the same value.

Definition at line 145 of file shaderinput.h.

template<typename ValueHolderType, typename ValueEnumType>
ValueType ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetType ( ) const
inline
template<typename ValueHolderType, typename ValueEnumType>
template<typename T >
const T& ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetValue ( ) const
inline

If this instance contains a value of type T, this returns a const reference to it.

Otherwise, it returns an InvalidReference. This should not be called on an invalid instance.

Definition at line 85 of file shaderinput.h.

Referenced by ion::gfx::AttributeArray::AddAttribute(), ion::gfx::Attribute::operator==(), ion::gfx::AttributeArray::ReplaceAttribute(), ion::text::Builder::UpdateFontImageTextureUniform(), and ion::gfx::AttributeArray::~AttributeArray().

template<typename ValueHolderType, typename ValueEnumType>
template<typename T >
const T& ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetValueAt ( size_t  i) const
inline

If this instance contains an array of values of type T with a length smaller than the passed index, this returns a const reference to the element at i.

Otherwise, it returns an InvalidReference. This should not be called on an invalid instance.

Definition at line 93 of file shaderinput.h.

template<typename ValueHolderType, typename ValueEnumType>
template<typename T >
void ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::Init ( const ShaderInputRegistry registry,
size_t  registry_id,
size_t  index_in_registry,
size_t  array_index,
ValueType  type,
const T value 
)
inlineprotected

Initializes the ShaderInput to a valid state.

This is passed the ShaderInputRegistry containing the shader input definition, its index within that registry, the type, and the initial value. The value is assumed to be consistent with the registered type. This function is private because only the ShaderInputRegistry class can create valid instances, enforcing type consistency.

Definition at line 170 of file shaderinput.h.

template<typename ValueHolderType, typename ValueEnumType>
template<typename T >
void ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::InitArray ( const ShaderInputRegistry registry,
size_t  registry_id,
size_t  index_in_registry,
size_t  array_index,
ValueType  type,
const T values,
size_t  count,
const base::AllocatorPtr allocator 
)
inlineprotected

Initializes the ShaderInput to a valid state.

This is passed the ShaderInputRegistry containing the shader input definition, its index within that registry, the type, and the initial set of values (or NULL to not set values). The value is assumed to be consistent with the registered type. This function is private because only the ShaderInputRegistry class can create valid instances, enforcing type consistency.

Definition at line 189 of file shaderinput.h.

template<typename ValueHolderType, typename ValueEnumType>
template<typename T >
bool ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::Is ( ) const
inline

If this instance contains a value of type T, this returns true, otherwise it returns false.

Definition at line 105 of file shaderinput.h.

template<typename ValueHolderType, typename ValueEnumType>
template<typename T >
bool ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::IsArrayOf ( ) const
inline

If this instance contains an array of values of type T, this returns true, otherwise it returns false.

Definition at line 111 of file shaderinput.h.

template<typename ValueHolderType, typename ValueEnumType>
bool ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::IsValid ( ) const
inline
template<typename ValueHolderType, typename ValueEnumType>
void ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::SetNewStamp ( )
inlineprotected
template<typename ValueHolderType, typename ValueEnumType>
template<typename T >
bool ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::SetValue ( const T value)
inline

If this instance contains a value of type T, this changes it to the new value.

Otherwise, it does nothing but return false. This should not be called on an invalid instance.

Definition at line 118 of file shaderinput.h.

template<typename ValueHolderType, typename ValueEnumType>
template<typename T >
bool ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::SetValueAt ( size_t  i,
const T value 
)
inline

If this instance contains a array of values of type T with a length larger than i, this changes the element at i to the new value.

Otherwise, it does nothing but return false. This should not be called on an invalid instance.

Definition at line 131 of file shaderinput.h.

Friends And Related Function Documentation

template<typename ValueHolderType, typename ValueEnumType>
friend class ShaderInputRegistry
friend

Definition at line 223 of file shaderinput.h.


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