Ion
|
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 ®, const gfx::AttributeArrayPtr &aa, const gfx::BufferObjectPtr &bo) |
bool | AreBindingsPacked (const gfx::ShaderInputRegistry ®) |
Validates that the bindings within the binder are consistent with a packed struct, logging warning messages if they are not. More... | |
template<typename FieldType > | |
BufferToAttributeBinder & | Bind (const FieldType &field, const std::string &attribute_name) |
template<typename FieldType > | |
BufferToAttributeBinder & | BindAndNormalize (const FieldType &field, const std::string &attribute_name) |
template<typename FieldType > | |
BufferToAttributeBinder & | Bind (const FieldType &field, const std::string &attribute_name, unsigned int divisor) |
template<typename FieldType > | |
BufferToAttributeBinder & | BindAndNormalize (const FieldType &field, const std::string &attribute_name, unsigned int divisor) |
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.
|
inlineexplicit |
Definition at line 103 of file buffertoattributebinder.h.
References DCHECK.
|
inline |
Definition at line 108 of file buffertoattributebinder.h.
|
inline |
Definition at line 110 of file buffertoattributebinder.h.
References DCHECK, ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::IsValid(), offset, ion::gfx::Attribute::SetDivisor(), ion::gfx::Attribute::SetFixedPointNormalized(), and type.
Referenced by ion::text::BasicBuilder::BindAttributes(), and ion::text::OutlineBuilder::BindAttributes().
|
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.
|
inline |
Definition at line 167 of file buffertoattributebinder.h.
Referenced by ion::text::BasicBuilder::BindAttributes(), and ion::text::OutlineBuilder::BindAttributes().
|
inline |
Definition at line 179 of file buffertoattributebinder.h.
|
inline |
Definition at line 173 of file buffertoattributebinder.h.
|
inline |
Definition at line 186 of file buffertoattributebinder.h.