Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::gfxutils::BufferToAttributeBinder< T > Class Template Reference

BufferToAttributeBinder is a simple interface to insert a set of Attributes containing BufferObjectElements into a AttributeArray, and also create the corresponding Elements in the BufferObject. More...

#include "buffertoattributebinder.h"

Public Member Functions

 BufferToAttributeBinder (const T &base_struct)
 
 ~BufferToAttributeBinder ()
 
void Apply (const gfx::ShaderInputRegistryPtr &reg, const gfx::AttributeArrayPtr &aa, const gfx::BufferObjectPtr &bo)
 
bool AreBindingsPacked (const gfx::ShaderInputRegistry &reg)
 Validates that the bindings within the binder are consistent with a packed struct, logging warning messages if they are not. More...
 
template<typename FieldType >
BufferToAttributeBinderBind (const FieldType &field, const std::string &attribute_name)
 
template<typename FieldType >
BufferToAttributeBinderBindAndNormalize (const FieldType &field, const std::string &attribute_name)
 
template<typename FieldType >
BufferToAttributeBinderBind (const FieldType &field, const std::string &attribute_name, unsigned int divisor)
 
template<typename FieldType >
BufferToAttributeBinderBindAndNormalize (const FieldType &field, const std::string &attribute_name, unsigned int divisor)
 

Detailed Description

template<typename T>
class ion::gfxutils::BufferToAttributeBinder< T >

BufferToAttributeBinder is a simple interface to insert a set of Attributes containing BufferObjectElements into a AttributeArray, and also create the corresponding Elements in the BufferObject.

Use BindAndNormalize() to bind a fixed-point Attribute that should have its data normalized, and Bind() otherwise.

Example Usage:

struct Vertex { ///< Vertex structure. Vector3f position; Vector3ui8 normal; int id; float temperature; }; Vertex v; BufferToAttributeBinder<Vertex> binder = BufferToAttributeBinder<Vertex>(v) .Bind(v.position, "aPosition") .BindAndNormalize(v.normal, "aNormal") .Bind(v.id, "aId") .Bind(v.temperature, "aTemperature"); ... ShaderInputRegistryPtr reg(new ShaderInputRegistry); AttributeArrayPtr vertex_array(new AttributeArray); BufferObjectPtr buffer_object(new BufferObject); ... (initialization of objects) binder.Apply(reg, vertex_array, buffer_object);

The same Binder can be used with other objects that need to share the same structure, as long as the registries are compatible (they must contain the attribute names passed to the binder through Bind()): ShaderInputRegistry reg2; AttributeArrayPtr vertex_array2(new AttributeArray); binder.Apply(reg2, vertex_array2, buffer_object);

A different BufferObject may also be used: BufferObjectPtr buffer_object2(new BufferObject); binder.Apply(reg2, vertex_array2, buffer_object2);

A simpler shorthand is possible if the binder is only needed for a single AttributeArray and BufferObject pair: ... ShaderInputRegistryPtr reg2(new ShaderInputRegistry); AttributeArrayPtr vertex_array(new AttributeArray); BufferObjectPtr buffer_object(new BufferObject); ... (initialization of objects) Vertex v; BufferToAttributeBinder<Vertex>(v) .Bind(v.position, "aPosition") .BindAndNormalize(v.normal, "aNormal") .Bind(v.id, "aId") .Bind(v.temperature, "aTemperature") .Apply(reg2, vertex_array, buffer_object);

Definition at line 101 of file buffertoattributebinder.h.

Constructor & Destructor Documentation

template<typename T >
ion::gfxutils::BufferToAttributeBinder< T >::BufferToAttributeBinder ( const T base_struct)
inlineexplicit

Definition at line 103 of file buffertoattributebinder.h.

References DCHECK.

template<typename T >
ion::gfxutils::BufferToAttributeBinder< T >::~BufferToAttributeBinder ( )
inline

Definition at line 108 of file buffertoattributebinder.h.

Member Function Documentation

template<typename T >
bool ion::gfxutils::BufferToAttributeBinder< T >::AreBindingsPacked ( const gfx::ShaderInputRegistry reg)
inline

Validates that the bindings within the binder are consistent with a packed struct, logging warning messages if they are not.

The passed registry is required to determine if the bindings are valid. Returns whether the struct is tightly packed. Note that this will log warnings and return false if called for a struct that contains fields not bound by this binder.

Definition at line 131 of file buffertoattributebinder.h.

References ion::gfx::ShaderInputRegistry::Contains(), LOG, name, offset, and ion::port::WARNING.

template<typename T >
template<typename FieldType >
BufferToAttributeBinder& ion::gfxutils::BufferToAttributeBinder< T >::Bind ( const FieldType &  field,
const std::string &  attribute_name 
)
inline
template<typename T >
template<typename FieldType >
BufferToAttributeBinder& ion::gfxutils::BufferToAttributeBinder< T >::Bind ( const FieldType &  field,
const std::string &  attribute_name,
unsigned int  divisor 
)
inline

Definition at line 179 of file buffertoattributebinder.h.

template<typename T >
template<typename FieldType >
BufferToAttributeBinder& ion::gfxutils::BufferToAttributeBinder< T >::BindAndNormalize ( const FieldType &  field,
const std::string &  attribute_name 
)
inline

Definition at line 173 of file buffertoattributebinder.h.

template<typename T >
template<typename FieldType >
BufferToAttributeBinder& ion::gfxutils::BufferToAttributeBinder< T >::BindAndNormalize ( const FieldType &  field,
const std::string &  attribute_name,
unsigned int  divisor 
)
inline

Definition at line 186 of file buffertoattributebinder.h.


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