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

A UniformBlock is a grouping of uniforms that can be easily shared between multiple Nodes; changing a Uniform in a UniformBlock will thus automatically change it for all Nodes that share the block. More...

#include "uniformblock.h"

Inheritance diagram for ion::gfx::UniformBlock:
Collaboration diagram for ion::gfx::UniformBlock:

Public Types

enum  Changes { kNumChanges = kNumBaseChanges }
 Changes that affect this resource. More...
 
enum  BaseChanges {
  kLabelChanged,
  kResourceChanged,
  kNumBaseChanges
}
 All ResourceHolders derived from this should start their own change enums from kNumBaseChanges. More...
 

Public Member Functions

 UniformBlock ()
 
void SetResource (size_t index, ResourceKey key, ResourceBase *resource) const
 Sets the resource at the passed index and key. More...
 
ResourceBaseGetResource (size_t index, ResourceKey key) const
 Returns the Resource at the given index and key, or NULL if no resource was previously set at that location. More...
 
int GetResourceCount () const
 Returns the number of resources that this holder holds. More...
 
size_t GetGpuMemoryUsed () const
 Returns the total amount of GPU memory used by this Holder's resource. More...
 
const std::string & GetLabel () const
 Returns/sets the label of this. More...
 
void SetLabel (const std::string &label)
 
void AddReceiver (Notifier *receiver)
 Adds a Notifier to be notified. More...
 
void RemoveReceiver (Notifier *receiver)
 Removes a Notifier to be notified. More...
 
size_t GetReceiverCount () const
 Returns the number of Notifiers that will be notified. More...
 
const AllocatorPtr & GetAllocator () const
 Returns the Allocator that was used for the instance. More...
 
const AllocatorPtr & GetNonNullAllocator () const
 Return our allocator, or the default allocator if the instance was declared on the stack. More...
 
const AllocatorPtr & GetAllocatorForLifetime (AllocationLifetime lifetime) const
 Convenience function that returns the Allocator to use to allocate an object with a specific lifetime. More...
 
void * operator new (size_t size)
 The standard no-parameter new operator uses the default Allocator. More...
 
void * operator new (size_t size, AllocationLifetime lifetime)
 This overloaded version of the new operator uses the AllocationManager's default Allocator for the specified lifetime. More...
 
void * operator new (size_t size, const AllocatorPtr &allocator)
 This overloaded version of the new operator takes the Allocator to use directly as a parameter. More...
 
void * operator new (size_t size, const AllocatorPtr &allocator, void *ptr)
 Special operator new for using placement new with Allocatables. More...
 
void * operator new (size_t size, void *ptr)
 The placement new operator is defined conventionally. More...
 
void operator delete (void *ptr)
 Define the delete operator to use specialized functions dealing with an Allocator. More...
 
void operator delete (void *ptr, AllocationLifetime lifetime)
 Windows requires these (or it issues C4291 warnings). More...
 
void operator delete (void *ptr, const AllocatorPtr &allocator)
 
void operator delete (void *ptr, void *ptr2)
 The placement delete operator does nothing, as usual. More...
 
int GetRefCount () const
 GetRefCount() is part of the interface necessary for SharedPtr. More...
 
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 Types

typedef WeakReferentPtr< NotifierNotifierPtr
 
typedef AllocVector< NotifierPtrNotifierPtrVector
 

Protected Member Functions

 ~UniformBlock () override
 The destructor is protected because all base::Referent classes must have protected or private destructors. More...
 
void OnChanged (int bit) const
 Forwards OnChanged to all resources. More...
 
const NotifierPtrVectorGetReceivers () const
 Returns the set of Notifiers that will be notified. More...
 
void Notify () const
 Notifies all contained Notifiers by calling their OnNotify(). More...
 
virtual void OnNotify (const Notifier *notifier)
 Subclasses can override this to provide custom behavior on notifications. More...
 

Detailed Description

A UniformBlock is a grouping of uniforms that can be easily shared between multiple Nodes; changing a Uniform in a UniformBlock will thus automatically change it for all Nodes that share the block.

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

Todo:
(user): Actually support the following text in Ion. In OpenGL 3.1+/ES3+, UniformBlocks also share the same storage buffer object, even across multiple shader programs; simplifying the sending of uniform values to GL for multiple programs. This can vastly increase the speed of switching large sets of uniforms at once since the cost is only the const of a single value change.

Definition at line 39 of file uniformblock.h.

Member Typedef Documentation

Definition at line 49 of file notifier.h.

typedef AllocVector<NotifierPtr> ion::base::Notifier::NotifierPtrVector
protectedinherited

Definition at line 50 of file notifier.h.

Member Enumeration Documentation

All ResourceHolders derived from this should start their own change enums from kNumBaseChanges.

Enumerator
kLabelChanged 
kResourceChanged 
kNumBaseChanges 

Definition at line 56 of file resourceholder.h.

Changes that affect this resource.

Enumerator
kNumChanges 

Definition at line 42 of file uniformblock.h.

Constructor & Destructor Documentation

ion::gfx::UniformBlock::UniformBlock ( )
Todo:
(user): Support interface blocks and buffer-backed UniformBlocks; make UniformBlocks require a block name and possibly require a BufferObject in the constructor.

Definition at line 23 of file uniformblock.cc.

ion::gfx::UniformBlock::~UniformBlock ( )
overrideprotected

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

Definition at line 25 of file uniformblock.cc.

Member Function Documentation

void ion::base::Notifier::AddReceiver ( Notifier receiver)
inherited

Adds a Notifier to be notified.

Does nothing if the receiver is NULL or is already in the receiver vector.

Definition at line 25 of file notifier.cc.

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

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 ( )
inlineinherited

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)
inlineinherited

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.

const AllocatorPtr& ion::base::Allocatable::GetAllocator ( ) const
inlineinherited

Returns the Allocator that was used for the instance.

This will be NULL if the instance was declared on the stack or created with normal placement new.

Definition at line 68 of file allocatable.h.

References allocator_.

Referenced by ion::base::DataContainer::CreateAndCopy(), ion::text::DynamicFontImage::FindContainingImageDataIndex(), and ion::text::DynamicFontImage::FindImageDataIndex().

const AllocatorPtr& ion::base::Allocatable::GetAllocatorForLifetime ( AllocationLifetime  lifetime) const
inlineinherited
size_t ion::gfx::ResourceHolder::GetGpuMemoryUsed ( ) const
inlineinherited

Returns the total amount of GPU memory used by this Holder's resource.

Definition at line 78 of file resourceholder.h.

const std::string& ion::gfx::ResourceHolder::GetLabel ( ) const
inlineinherited

Returns/sets the label of this.

Definition at line 89 of file resourceholder.h.

const AllocatorPtr& ion::base::Allocatable::GetNonNullAllocator ( ) const
inlineinherited

Return our allocator, or the default allocator if the instance was declared on the stack.

Definition at line 72 of file allocatable.h.

References allocator_, and ion::base::AllocationManager::GetNonNullAllocator().

size_t ion::base::Notifier::GetReceiverCount ( ) const
inherited

Returns the number of Notifiers that will be notified.

Definition at line 71 of file notifier.cc.

const Notifier::NotifierPtrVector & ion::base::Notifier::GetReceivers ( ) const
protectedinherited

Returns the set of Notifiers that will be notified.

Definition at line 77 of file notifier.cc.

int ion::base::Shareable::GetRefCount ( ) const
inlineinherited

GetRefCount() is part of the interface necessary for SharedPtr.

Definition at line 34 of file shareable.h.

Referenced by ion::base::Notifier::RemoveReceiver().

ResourceBase * ion::gfx::ResourceHolder::GetResource ( size_t  index,
ResourceKey  key 
) const
inherited

Returns the Resource at the given index and key, or NULL if no resource was previously set at that location.

Definition at line 122 of file resourceholder.cc.

int ion::gfx::ResourceHolder::GetResourceCount ( ) const
inlineinherited

Returns the number of resources that this holder holds.

Note that this is not necessarily the number of indices that have non-NULL resources. This can be used as a fast trivial check to see if the holder has any resources.

Definition at line 73 of file resourceholder.h.

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

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
inlineinherited
bool ion::gfx::UniformHolder::IsEnabled ( ) const
inlineinherited

Definition at line 138 of file uniformholder.h.

void ion::base::Notifier::Notify ( ) const
protectedinherited

Notifies all contained Notifiers by calling their OnNotify().

Any receivers that have been destroyed will be removed from the vector of receivers.

Definition at line 81 of file notifier.cc.

References ion::base::SharedPtr< T >::Get().

void ion::gfx::ResourceHolder::OnChanged ( int  bit) const
inlineprotectedinherited

Forwards OnChanged to all resources.

Definition at line 326 of file resourceholder.h.

void ion::base::Notifier::OnNotify ( const Notifier notifier)
protectedvirtualinherited

Subclasses can override this to provide custom behavior on notifications.

Definition at line 96 of file notifier.cc.

void ion::base::Allocatable::operator delete ( void *  ptr)
inlineinherited

Define the delete operator to use specialized functions dealing with an Allocator.

Definition at line 109 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
AllocationLifetime  lifetime 
)
inlineinherited

Windows requires these (or it issues C4291 warnings).

Definition at line 112 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
const AllocatorPtr allocator 
)
inlineinherited

Definition at line 113 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
void *  ptr2 
)
inlineinherited

The placement delete operator does nothing, as usual.

Definition at line 118 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size)
inlineinherited

The standard no-parameter new operator uses the default Allocator.

Definition at line 84 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
AllocationLifetime  lifetime 
)
inlineinherited

This overloaded version of the new operator uses the AllocationManager's default Allocator for the specified lifetime.

Definition at line 88 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
const AllocatorPtr allocator 
)
inlineinherited

This overloaded version of the new operator takes the Allocator to use directly as a parameter.

If the Allocator pointer is NULL, this uses the default Allocator.

Definition at line 95 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
const AllocatorPtr allocator,
void *  ptr 
)
inlineinherited

Special operator new for using placement new with Allocatables.

Definition at line 100 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
void *  ptr 
)
inlineinherited

The placement new operator is defined conventionally.

Definition at line 105 of file allocatable.h.

void ion::base::Notifier::RemoveReceiver ( Notifier receiver)
inherited

Removes a Notifier to be notified.

Does nothing if the receiver is NULL or not in the set of receivers.

Definition at line 38 of file notifier.cc.

References ion::base::Shareable::GetRefCount().

Referenced by ion::gfx::AttributeArray::~AttributeArray().

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

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 
)
inlineinherited

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().

void ion::gfx::ResourceHolder::SetLabel ( const std::string &  label)
inlineinherited

Definition at line 90 of file resourceholder.h.

void ion::gfx::ResourceHolder::SetResource ( size_t  index,
ResourceKey  key,
ResourceBase resource 
) const
inherited

Sets the resource at the passed index and key.

The size of the internal vector is automatically managed so that it has the smallest possible size.

Definition at line 51 of file resourceholder.cc.

References DCHECK, DCHECK_EQ, ion::gfx::ResourceBase::GetKey(), and ion::gfx::ResourceBase::OnChanged().

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

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 
)
inlineinherited

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 
)
inlineinherited

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 
)
inlineinherited

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: