Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
attribute.cc
Go to the documentation of this file.
1 
18 #include "ion/gfx/attribute.h"
19 
20 #include "ion/base/logging.h"
21 
22 namespace ion {
23 namespace gfx {
24 
26  return "attribute";
27 }
28 
30  switch (type) {
31  case kFloatAttribute: return "Float";
32  case kFloatVector2Attribute: return "FloatVector2";
33  case kFloatVector3Attribute: return "FloatVector3";
34  case kFloatVector4Attribute: return "FloatVector4";
35  case kFloatMatrix2x2Attribute: return "FloatMatrix2x2";
36  case kFloatMatrix3x3Attribute: return "FloatMatrix3x3";
37  case kFloatMatrix4x4Attribute: return "FloatMatrix4x4";
38  case kBufferObjectElementAttribute: return "BufferObjectElement";
39  default: return "<UNKNOWN>";
40  }
41 }
42 
43 template <typename T>
46  CHECK(false) <<"Unspecialized attribute GetTypeByValue() called.";
47  return kFloatAttribute;
48 }
50 template <> ION_API
51 Attribute::ValueType Attribute::GetTypeByValue<float>() {
52  return kFloatAttribute;
53 }
54 template <> ION_API
55 Attribute::ValueType Attribute::GetTypeByValue<math::VectorBase2f>() {
57 }
58 template <> ION_API
59 Attribute::ValueType Attribute::GetTypeByValue<math::VectorBase3f>() {
61 }
62 template <> ION_API
63 Attribute::ValueType Attribute::GetTypeByValue<math::VectorBase4f>() {
65 }
66 template <> ION_API
67 Attribute::ValueType Attribute::GetTypeByValue<math::Matrix2f>() {
69 }
70 template <> ION_API
71 Attribute::ValueType Attribute::GetTypeByValue<math::Matrix3f>() {
73 }
74 template <> ION_API
75 Attribute::ValueType Attribute::GetTypeByValue<math::Matrix4f>() {
77 }
78 template <> ION_API
79 Attribute::ValueType Attribute::GetTypeByValue<BufferObjectElement>() {
81 }
82 
83 bool Attribute::operator==(const Attribute& other) const {
84  if (&GetRegistry() == &other.GetRegistry() &&
86  GetType() == other.GetType() &&
87  normalize_ == other.normalize_) {
89  bool equal = true;
90  switch (GetType()) {
91  case kFloatAttribute:
92  equal = GetValue<float>() == other.GetValue<float>();
93  break;
95  equal = math::VectorBase2f::AreValuesEqual(
96  GetValue<math::VectorBase2f>(),
97  other.GetValue<math::VectorBase2f>());
98  break;
100  equal = math::VectorBase3f::AreValuesEqual(
101  GetValue<math::VectorBase3f>(),
102  other.GetValue<math::VectorBase3f>());
103  break;
105  equal = math::VectorBase4f::AreValuesEqual(
106  GetValue<math::VectorBase4f>(),
107  other.GetValue<math::VectorBase4f>());
108  break;
110  equal = GetValue<math::Matrix2f>() == other.GetValue<math::Matrix2f>();
111  break;
113  equal = GetValue<math::Matrix3f>() == other.GetValue<math::Matrix3f>();
114  break;
116  equal = GetValue<math::Matrix4f>() == other.GetValue<math::Matrix4f>();
117  break;
118  default: // kBufferObjectElementAttribute.
119  equal = GetValue<BufferObjectElement>().buffer_object.Get() ==
120  other.GetValue<BufferObjectElement>().buffer_object.Get() &&
121  GetValue<BufferObjectElement>().spec_index ==
123  break;
124  }
125  return equal;
126  } else {
127  return false;
128  }
129 }
130 
131 } // namespace gfx
132 } // namespace ion
static ValueType GetTypeByValue()
Returns the type for a templated value type.
Definition: attribute.cc:44
#define CHECK(expr)
Definition: logging.h:323
AttributeType
The AttributeType enum defines all supported attribute shader argument types.
Definition: attribute.h:33
std::string type
Definition: printer.cc:353
Matrix< 3, float > Matrix3f
Definition: matrix.h:369
const ShaderInputRegistry & GetRegistry() const
Returns the ShaderInputRegistry the shader input is defined in.
Definition: shaderinput.h:63
Structure for clients to use to encapsulate Elements.
Definition: bufferobject.h:378
The Matrix class defines a square N-dimensional matrix.
Definition: matrix.h:35
size_t GetIndexInRegistry() const
Returns the index of the shader input within the registry.
Definition: shaderinput.h:67
Copyright 2016 Google Inc.
static const char * GetShaderInputTypeName()
Returns a string containing "attribute".
Definition: attribute.cc:25
bool operator==(const Attribute &other) const
Definition: attribute.cc:83
const T & GetValue() const
If this instance contains a value of type T, this returns a const reference to it.
Definition: shaderinput.h:85
Scalar types.
Definition: attribute.h:35
static const char * GetValueTypeName(const ValueType type)
Returns a string representing a attribute type.
Definition: attribute.cc:29
ValueType GetType() const
Returns the type of the shader input.
Definition: shaderinput.h:80