All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
VertexBindingElement.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Graphics.h"
6 
7 namespace Eegeo
8 {
9  namespace Rendering
10  {
15  {
16  public:
17  VertexBindingElement(GLuint attribIndex, GLint numOfFields, GLenum dataType, GLboolean normalized, GLsizei stride, GLint offset)
18  : m_attribIndex(attribIndex)
19  , m_numOfFields(numOfFields)
20  , m_dataType(dataType)
21  , m_stride(stride)
22  , m_offset(offset)
23  , m_normalized(normalized)
24  {
25  }
26 
27  void Bind() const
28  {
29  Eegeo_GL(glEnableVertexAttribArray(m_attribIndex));
30  Eegeo_GL(glVertexAttribPointer(m_attribIndex,
31  m_numOfFields,
32  m_dataType,
33  m_normalized,
34  m_stride,
35  static_cast<char*>(nullptr) + m_offset
36  ));
37  }
38 
39  void Unbind() const
40  {
41  Eegeo_GL(glDisableVertexAttribArray(m_attribIndex));
42  }
43 
44  inline bool operator== (const VertexBindingElement& other) const
45  {
46  return
47  (
48  (m_attribIndex == other.m_attribIndex)
49  && (m_numOfFields == other.m_numOfFields)
50  && (m_dataType == other.m_dataType)
51  && (m_stride == other.m_stride)
52  && (m_offset == other.m_offset)
53  && (m_normalized == other.m_normalized)
54  );
55  }
56 
57  inline bool operator!= (const VertexBindingElement& other) const
58  {
59  return
60  (
61  (m_attribIndex != other.m_attribIndex)
62  || (m_numOfFields != other.m_numOfFields)
63  || (m_dataType != other.m_dataType)
64  || (m_stride != other.m_stride)
65  || (m_offset != other.m_offset)
66  || (m_normalized != other.m_normalized)
67  );
68  }
69 
70  inline bool operator< (const VertexBindingElement& other) const
71  {
72  if(m_attribIndex == other.m_attribIndex)
73  {
74  if(m_numOfFields == other.m_numOfFields)
75  {
76  if(m_dataType == other.m_dataType)
77  {
78  if(m_stride == other.m_stride)
79  {
80  if (m_offset == other.m_offset)
81  {
82  return m_normalized < other.m_normalized;
83  }
84  else
85  {
86  return m_offset < other.m_offset;
87  }
88  }
89  else
90  {
91  return m_stride < other.m_stride;
92  }
93  }
94  else
95  {
96  return m_dataType < other.m_dataType;
97  }
98  }
99  else
100  {
101  return m_numOfFields < other.m_numOfFields;
102  }
103  }
104  else
105  {
106  return m_attribIndex < other.m_attribIndex;
107  }
108  }
109 
110  private:
111  GLuint m_attribIndex;
112  GLint m_numOfFields;
113  GLenum m_dataType;
114  GLsizei m_stride;
115  GLint m_offset;
116  GLboolean m_normalized;
117  };
118  }
119 }