Ion
|
A Uniform instance represents a uniform shader argument. More...
#include "uniform.h"
Public Types | |
typedef UniformValueType | HolderType |
typedef UniformType | 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 | |
Uniform () | |
The default constructor creates an invalid Uniform instance, which should never be used as is. More... | |
~Uniform () | |
void | MergeValuesFrom (const Uniform &replacement) |
Merges the value of this with replacement if both have the same type. More... | |
bool | operator== (const Uniform &other) const |
bool | operator!= (const Uniform &other) const |
template<> | |
ION_API Uniform::ValueType | GetTypeByValue () |
Specialize for each supported type. More... | |
template<> | |
ION_API Uniform::ValueType | GetTypeByValue () |
template<> | |
ION_API Uniform::ValueType | GetTypeByValue () |
template<> | |
ION_API Uniform::ValueType | GetTypeByValue () |
template<> | |
ION_API Uniform::ValueType | GetTypeByValue () |
bool | IsValid () const |
Returns true if this is a valid instance created by a ShaderInputRegistry. More... | |
const ShaderInputRegistry & | GetRegistry () 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... | |
const T & | GetValue () const |
If this instance contains a value of type T, this returns a const reference to it. More... | |
const T & | GetValueAt (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... | |
bool | Is () const |
If this instance contains a value of type T, this returns true, otherwise it returns false. More... | |
bool | IsArrayOf () const |
If this instance contains an array of values of type T, this returns true, otherwise it returns false. More... | |
bool | SetValue (const T &value) |
If this instance contains a value of type T, this changes it to the new value. More... | |
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... | |
Static Public Member Functions | |
static const char * | GetShaderInputTypeName () |
Returns a string containing "uniform". More... | |
static const char * | GetValueTypeName (const ValueType type) |
Returns a string representing a uniform type. More... | |
template<typename T > | |
static ValueType | GetTypeByValue () |
Returns the type for a templated value type. More... | |
static Tag | GetTag () |
Returns the tag for this input type. More... | |
static bool | GetMerged (const Uniform &base, const Uniform &replacement, Uniform *merged) |
Merges replacement and base into merged. More... | |
Protected Member Functions | |
void | SetNewStamp () |
Assigns a new stamp to this Input. More... | |
void | Init (const ShaderInputRegistry ®istry, 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... | |
void | InitArray (const ShaderInputRegistry ®istry, 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::AllocatorPtr & | GetArrayAllocator () const |
Returns the allocator used to make array allocations. More... | |
Static Protected Member Functions | |
static uint64 | GetNewStamp () |
Returns atomically post-incremented stamp. More... | |
A Uniform instance represents a uniform shader argument.
A Variant is used to store the actual type-specific value, and the interface is based on that. The Uniform class is designed to be lightweight enough that instances can be copied quickly, so they can be stored in vectors, used in stacks, and so on.
|
inherited |
Definition at line 52 of file shaderinput.h.
|
inherited |
Definition at line 53 of file shaderinput.h.
|
inherited |
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.
|
inline |
|
inlineprotectedinherited |
Returns the allocator used to make array allocations.
Definition at line 207 of file shaderinput.h.
|
inlineinherited |
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.
|
inlineinherited |
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.
|
inlineinherited |
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 MergeValuesFrom(), and operator==().
|
static |
Merges replacement and base into merged.
Returns true if a merge was needed, false otherwise in which case replacement completely replaces base.
Definition at line 225 of file uniform.cc.
References ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetArrayIndex(), ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetCount(), ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetIndexInRegistry(), ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetRegistry(), ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetType(), ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::IsValid(), ion::gfx::kCubeMapTextureUniform, ion::gfx::kFloatUniform, ion::gfx::kFloatVector2Uniform, ion::gfx::kFloatVector3Uniform, ion::gfx::kFloatVector4Uniform, ion::gfx::kIntUniform, ion::gfx::kIntVector2Uniform, ion::gfx::kIntVector3Uniform, ion::gfx::kIntVector4Uniform, ion::gfx::kMatrix2x2Uniform, ion::gfx::kMatrix3x3Uniform, ion::gfx::kMatrix4x4Uniform, ion::gfx::kTextureUniform, ion::gfx::kUnsignedIntUniform, ion::gfx::kUnsignedIntVector2Uniform, ion::gfx::kUnsignedIntVector3Uniform, and ion::gfx::kUnsignedIntVector4Uniform.
Referenced by MergeValuesFrom().
|
staticprotectedinherited |
Returns atomically post-incremented stamp.
Definition at line 24 of file shaderinput.cc.
Referenced by ion::gfx::ShaderInput< UniformValueType, UniformType >::SetNewStamp().
|
inlineinherited |
Returns the ShaderInputRegistry the shader input is defined in.
This will crash if called on an invalid instance.
Definition at line 63 of file shaderinput.h.
Referenced by MergeValuesFrom(), and operator==().
|
inlineinherited |
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.
|
static |
Returns a string containing "uniform".
Definition at line 74 of file uniform.cc.
|
inlineinherited |
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.
|
inlinestatic |
|
inlineinherited |
Returns the type of the shader input.
This should not be called on an invalid instance.
Definition at line 80 of file shaderinput.h.
Referenced by MergeValuesFrom(), and operator==().
|
static |
Returns the type for a templated value type.
This is instantiated for all supported types
Definition at line 101 of file uniform.cc.
References CHECK, and ion::gfx::kIntUniform.
ION_API Uniform::ValueType ion::gfx::Uniform::GetTypeByValue | ( | ) |
Specialize for each supported type.
Definition at line 107 of file uniform.cc.
References ion::gfx::kFloatUniform.
ION_API Uniform::ValueType ion::gfx::Uniform::GetTypeByValue | ( | ) |
Definition at line 110 of file uniform.cc.
References ion::gfx::kIntUniform.
ION_API Uniform::ValueType ion::gfx::Uniform::GetTypeByValue | ( | ) |
Definition at line 113 of file uniform.cc.
References ion::gfx::kUnsignedIntUniform.
ION_API Uniform::ValueType ion::gfx::Uniform::GetTypeByValue | ( | ) |
Definition at line 117 of file uniform.cc.
References ion::gfx::kCubeMapTextureUniform.
ION_API Uniform::ValueType ion::gfx::Uniform::GetTypeByValue | ( | ) |
Definition at line 121 of file uniform.cc.
References ion::gfx::kTextureUniform.
|
inlineinherited |
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.
|
inlineinherited |
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.
|
static |
Returns a string representing a uniform type.
Definition at line 78 of file uniform.cc.
References ion::gfx::kCubeMapTextureUniform, ion::gfx::kFloatUniform, ion::gfx::kFloatVector2Uniform, ion::gfx::kFloatVector3Uniform, ion::gfx::kFloatVector4Uniform, ion::gfx::kIntUniform, ion::gfx::kIntVector2Uniform, ion::gfx::kIntVector3Uniform, ion::gfx::kIntVector4Uniform, ion::gfx::kMatrix2x2Uniform, ion::gfx::kMatrix3x3Uniform, ion::gfx::kMatrix4x4Uniform, ion::gfx::kTextureUniform, ion::gfx::kUnsignedIntUniform, ion::gfx::kUnsignedIntVector2Uniform, ion::gfx::kUnsignedIntVector3Uniform, and ion::gfx::kUnsignedIntVector4Uniform.
|
inlineprotectedinherited |
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.
References ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::SetNewStamp(), and type.
|
inlineprotectedinherited |
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.
References ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::SetNewStamp(), and type.
|
inlineinherited |
If this instance contains a value of type T, this returns true, otherwise it returns false.
Definition at line 105 of file shaderinput.h.
|
inlineinherited |
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.
|
inlineinherited |
Returns true if this is a valid instance created by a ShaderInputRegistry.
If this returns false, most of the other methods should not be called.
Definition at line 59 of file shaderinput.h.
void ion::gfx::Uniform::MergeValuesFrom | ( | const Uniform & | replacement | ) |
Merges the value of this with replacement if both have the same type.
This is useful for merging partial array uniforms. replacement will replace values in this if the array ranges overlap.
Definition at line 211 of file uniform.cc.
References ion::gfx::ShaderInput< UniformValueType, UniformType >::GetIndexInRegistry(), ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetIndexInRegistry(), GetMerged(), ion::gfx::ShaderInput< UniformValueType, UniformType >::GetRegistry(), ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetRegistry(), ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetType(), and ion::gfx::ShaderInput< UniformValueType, UniformType >::GetType().
Definition at line 309 of file uniform.cc.
References CHECK_UNIFORMS_EQUAL, CHECK_VECTOR_UNIFORMS_EQUAL, ion::gfx::ShaderInput< UniformValueType, UniformType >::GetIndexInRegistry(), ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetIndexInRegistry(), ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetRegistry(), ion::gfx::ShaderInput< UniformValueType, UniformType >::GetRegistry(), ion::gfx::ShaderInput< UniformValueType, UniformType >::GetType(), ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetType(), ion::gfx::kCubeMapTextureUniform, ion::gfx::kFloatUniform, ion::gfx::kFloatVector2Uniform, ion::gfx::kFloatVector3Uniform, ion::gfx::kFloatVector4Uniform, ion::gfx::kIntUniform, ion::gfx::kIntVector2Uniform, ion::gfx::kIntVector3Uniform, ion::gfx::kIntVector4Uniform, ion::gfx::kMatrix2x2Uniform, ion::gfx::kMatrix3x3Uniform, ion::gfx::kMatrix4x4Uniform, ion::gfx::kTextureUniform, ion::gfx::kUnsignedIntUniform, ion::gfx::kUnsignedIntVector2Uniform, ion::gfx::kUnsignedIntVector3Uniform, and ion::gfx::kUnsignedIntVector4Uniform.
|
inlineprotectedinherited |
Assigns a new stamp to this Input.
Definition at line 161 of file shaderinput.h.
References ion::gfx::ShaderInputBase::GetNewStamp().
|
inlineinherited |
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.
References ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::SetNewStamp().
|
inlineinherited |
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.
References ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::SetNewStamp().