GteVertexFormat.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
9 #include <LowLevel/GteLogger.h>
11 using namespace gte;
12 
13 
15  :
16  mNumAttributes(0),
17  mVertexSize(0)
18 {
19 }
20 
21 bool VertexFormat::Bind(VASemantic semantic, DFType type, unsigned int unit)
22 {
24  {
25  // Validate the inputs.
26  if (semantic == VA_COLOR)
27  {
28  if (unit >= VA_MAX_COLOR_UNITS)
29  {
30  LogError("Invalid color unit.");
31  return false;
32  }
33  }
34  else if (semantic == VA_TEXCOORD)
35  {
36  if (unit >= VA_MAX_TCOORD_UNITS)
37  {
38  LogError("Invalid texture unit.");
39  return false;
40  }
41  }
42  else
43  {
44  if (unit > 0)
45  {
46  LogError("Invalid semantic unit.");
47  return false;
48  }
49  }
50 
51  // Accept the attribute.
52  Attribute& attribute = mAttributes[mNumAttributes];
53  attribute.semantic = semantic;
54  attribute.type = type;
55  attribute.unit = unit;
56  attribute.offset = mVertexSize;
58 
59  // Advance the offset.
61  return true;
62  }
63 
64  LogError("Exceeded maximum attributes.");
65  return false;
66 }
67 
68 unsigned int VertexFormat::GetVertexSize() const
69 {
70  return mVertexSize;
71 }
72 
74 {
75  return mNumAttributes;
76 }
77 
78 bool VertexFormat::GetAttribute(int i, VASemantic& semantic, DFType& type,
79  unsigned int& unit, unsigned int& offset) const
80 {
81  if (0 <= i && i < mNumAttributes)
82  {
83  Attribute const& attribute = mAttributes[i];
84  semantic = attribute.semantic;
85  type = attribute.type;
86  unit = attribute.unit;
87  offset = attribute.offset;
88  return true;
89  }
90 
91  LogError("Invalid index " + std::to_string(i) + ".");
92  return false;
93 }
94 
95 int VertexFormat::GetIndex(VASemantic semantic, unsigned int unit) const
96 {
97  for (int i = 0; i < mNumAttributes; ++i)
98  {
99  Attribute const& attribute = mAttributes[i];
100  if (attribute.semantic == semantic && attribute.unit == unit)
101  {
102  return i;
103  }
104  }
105 
106  return -1;
107 }
108 
109 DFType VertexFormat::GetType(int i) const
110 {
111  if (0 <= i && i < mNumAttributes)
112  {
113  return mAttributes[i].type;
114  }
115 
116  LogError("Invalid index " + std::to_string(i) + ".");
117  return DF_UNKNOWN;
118 }
119 
120 unsigned int VertexFormat::GetOffset(int i) const
121 {
122  if (0 <= i && i < mNumAttributes)
123  {
124  return mAttributes[i].offset;
125  }
126 
127  LogError("Invalid index " + std::to_string(i) + ".");
128  return 0xFFFFFFFFu;
129 }
130 
132  :
133  semantic(VA_NO_SEMANTIC),
134  type(DF_UNKNOWN),
135  unit(0),
136  offset(0)
137 {
138 }
139 
VA_TEXCOORD
VA_NO_SEMANTIC
VA_MAX_TCOORD_UNITS
unsigned int GetVertexSize() const
VA_MAX_ATTRIBUTES
bool Bind(VASemantic semantic, DFType type, unsigned int unit)
bool GetAttribute(int i, VASemantic &semantic, DFType &type, unsigned int &unit, unsigned int &offset) const
int GetIndex(VASemantic semantic, unsigned int unit) const
#define LogError(message)
Definition: GteLogger.h:92
static unsigned int GetNumBytesPerStruct(DFType type)
unsigned int GetOffset(int i) const
VA_COLOR
int GetNumAttributes() const
DFType GetType(int i) const
GLintptr offset
Definition: glcorearb.h:660
Attribute mAttributes[VA_MAX_ATTRIBUTES]
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:103
unsigned int mVertexSize
DF_UNKNOWN
Definition: GteDataFormat.h:20


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:02